forked from azzagazz/author_gravatar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.driver.php
executable file
·70 lines (60 loc) · 2.43 KB
/
extension.driver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
if(!defined("__IN_SYMPHONY__")) die("<h2>Error</h2><p>You cannot directly access this file</p>");
Class extension_author_gravatar extends Extension {
public function getSubscribedDelegates() {
return array(
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'appendAssets'
)
);
}
public function appendAssets($context) {
$author = null;
if (is_callable(array('Symphony', 'Author'))) {
$author = Symphony::Author();
} else {
$author = Administration::instance()->Author;
}
// add stylesheet with changes to header
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/author_gravatar/assets/author_gravatar.admin.css', 'screen', 100);
// create gravatar image
$img = new XMLElement('img', null, array(
'src' => $this->getGravatar($author->get('email'), 30),
'class' => 'gravatar'
));
// create anchor element as parent to the gravatar image
$a = new XMLElement('a', $img, array(
'href' => SYMPHONY_URL . '/system/authors/edit/' . $author->get('id') . '/',
'data-id' => $author->get('id'),
'data-name' => $author->get('first_name'),
'data-type' => $author->get('user_type'),
'class' => 'gravatar'
));
// append anchor / gravatar image to backend header element
Administration::instance()->Page->Header->appendChild($a);
}
/**
* Get either a Gravatar URL or complete image tag for a specified email address.
* @param string $email The email address
* @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]
* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
* @param boole $img True to return a complete IMG tag False for just the URL
* @param array $atts Optional, additional key/value attributes to include in the IMG tag
* @return String containing either just a URL or a complete image tag
*/
public static function getGravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
$url = '//www.gravatar.com/avatar/';
$url .= md5( strtolower( trim( $email ) ) );
$url .= "?s=$s&d=$d&r=$r";
if ( $img ) {
$url = '<img src="' . $url . '"';
foreach ( $atts as $key => $val )
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
}
return $url;
}
}