Fixed wrong URL in extension: Gravatar
[vanilla-miry.git] / extensions / Gravatar / default.php
blob534aa87ca6bb6cff2c3e823629887d6b6b48cd27
1 <?php
2 /**
3 Extension Name: Gravatar
4 Extension Url: http://vanillaforums.org/get/335
5 Description: Add gravatar icon to discussion
6 Version: 0.1.2
7 Author: Dinoboff
8 Author Url: http://lussumo.com/community/account/2469/
10 * @package Extensions
11 * @subpackage Gravatar
16 /**
17 * Change definition of IconNotes and Icon in the dictionary.
19 $Context->SetDefinition('Gravatar_Icon', 'Icon');
20 $Context->SetDefinition(
21 'Gravatar_IconNotes',
22 'You can enter any valid URL to an image here, such as: <strong>http://www.mywebsite.com/myicon.jpg</strong>.
23 An icon will appear next to your name in discussion comments and on your account page.
24 We will try to get your icon from <a href="http://site.gravatar.com/">Gravatar</a>. If an icon
25 is associated to your email address on <a href="http://site.gravatar.com/">Gravatar</a>,
26 You do not need to enter anything.'
29 $Context->Dictionary['IconNotes'] = $Context->GetDefinition('Gravatar_IconNotes');
30 $Context->Dictionary['Icon'] = $Context->GetDefinition('Gravatar_Icon');
32 /**
33 * Create gravatar request URL to fletch the image associated to an email
35 * @param string $Email
36 * @param string $DefaultIconUrl
37 * @param array $ArgOption
38 * @return string
39 * @todo update documentation about new setting (GRAVATAR_URL) and about GRAVATAR_DEFAULT_ICON default value.
41 function Gravatar_GetGravatarUrl($Email, $DefaultIconUrl='', $ArgOptions = array())
43 $DefaultOptions = array(
44 'GRAVATAR_URL' => 'http://www.gravatar.com/avatar/%s?s=%s&r=%s&d=%s',
45 'GRAVATAR_RATING' => 'PG',
46 'GRAVATAR_SIZE' => 32,
47 'GRAVATAR_DEFAULT_ICON' => '',
49 $Options = array_merge($DefaultOptions,$ArgOptions);
51 $DefaultIconUrl = ForceString($DefaultIconUrl, $Options['GRAVATAR_DEFAULT_ICON']);
52 $DefaultIconUrl = urlencode($DefaultIconUrl);
54 return sprintf(
55 $Options['GRAVATAR_URL'],
56 md5($Email),
57 $Options['GRAVATAR_SIZE'],
58 $Options['GRAVATAR_RATING'],
59 $DefaultIconUrl
63 /**
64 * Delegation for the CommentManager::GetCommentBuilder() CommentBuilder_PreWhere delegation.
65 * We need the author email.
67 * @param CommentManager $ComentManager
69 function Gravatar_AddEmailToCommentBuilder(&$ComentManager)
71 $s = &$ComentManager->DelegateParameters['SqlBuilder'];
72 $s->AddSelect('Email', 'a', 'AuthEmail');
75 /**
76 * Function to add to Comment::GetPropertiesFromDataSet() PreAssignAuthRoleIcon delegation.
78 * @param Comment $Comment
80 function Gravatar_SetAuthIconToGravatarUrl(&$Comment)
82 $DataSet = $Comment->DelegateParameters['DataSet'];
83 $Email = ForceString(@$DataSet['AuthEmail'], '');
85 if ($Email) {
86 $Comment->AuthIcon = Gravatar_GetGravatarUrl($Email, $Comment->AuthIcon, $Comment->Context->Configuration);
90 /**
91 * Function to add to Account::Account() Constructor delegation
93 * @param Account $Account
95 function Gravatar_SetUserDisplayIconToGravatarUrl(&$Account)
97 // Don't overwrite the DisplayIcon property if a Role Icon should be displayed
98 if (empty($Account->User->RoleIcon)) {
99 $Account->User->DisplayIcon = Gravatar_GetGravatarUrl(
100 $Account->User->Email,
101 $Account->User->DisplayIcon,
102 $Account->Context->Configuration
108 * Add delegations
110 $Context->AddToDelegate('CommentManager', 'CommentBuilder_PreWhere', 'Gravatar_AddEmailToCommentBuilder');
111 $Context->AddToDelegate('Account', 'Constructor', 'Gravatar_SetUserDisplayIconToGravatarUrl');
112 // for Vanilla 1.1.4-a
113 $Context->AddToDelegate('Comment', 'PreAssignAuthRoleIcon', 'Gravatar_SetAuthIconToGravatarUrl');
114 // for Vanilla 1.1.5-rc1+
115 $Context->AddToDelegate('Comment', 'PostGetPropertiesFromDataSet', 'Gravatar_SetAuthIconToGravatarUrl');