~quam-plures-core/quam-plures/fix-auto_p_plugin

« back to all changes in this revision

Viewing changes to qp_plugins/comment_gravatars_plugin/_comment_gravatars.plugin.php

  • Committer: EdB
  • Date: 2013-03-18 19:30:14 UTC
  • mfrom: (7602.1.58 quam-plures)
  • Revision ID: 1912webworks@gmail.com-20130318193014-qogr0c0lwd5ix8lj
quam-plures/qp5_colls-blogs_chaps-cats

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/**
3
 
 * This file implements the CommentGravatars plugin for Quam Plures
4
 
 *
5
 
 * This plugin displays a commentator's gravatar (Globally Recognized Avatar) if they've registered for a
6
 
 * free account with gravatar.com. If not, it displays one of three uniquely generated
7
 
 * avatars (identicons, wavatars or monsterids -- your choice).
8
 
 *
9
 
 * Designed as a no muss, no fuss way to add avatars to the comments of your blog without having
10
 
 * to bother with uploading files or doing any template coding.
11
 
 *
12
 
 * Works for registered users of your blog as well as visitors.'
13
 
 *
14
 
 * Quam Plures - {@link http://quamplures.net/}
15
 
 * Released under GNU GPL License - {@link http://quamplures.net/license.html}
16
 
 * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
17
 
 *
 
3
 * This file implements the CommentGravatars plugin
 
4
 *
 
5
 * This plugin displays a commentator's gravatar (Globally Recognized Avatar) if
 
6
 * they've registered for a free account with gravatar.com. If not, it displays
 
7
 * one of three uniquely generated avatars (identicons, wavatars or monsterids
 
8
 * -- your choice).
 
9
 *
 
10
 * Designed as a no muss, no fuss way to add avatars to the comments of your blog
 
11
 * without having to bother with uploading files or doing any template coding.
 
12
 *
 
13
 * @author {@link http://wonderwinds.com/ Ed Bennett}
 
14
 * @author {@link http://www.bushleaguecritic.com/ Bush League Critic}
 
15
 * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
 
16
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
18
17
 * @package plugins
19
18
 * @subpackage CommentGravatars
20
19
 */
21
 
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
 
20
if(!defined('QP_MAIN_INIT')) die('fail');
22
21
 
23
22
/**
24
23
 * @package plugins
33
32
        var $group = 'comments';
34
33
        var $number_of_installs = 1;
35
34
        var $priority = 50;
36
 
        var $version = '0.1';
37
 
 
 
35
        var $version = '1.0';
38
36
 
39
37
        /**
40
38
         * @see Plugin::PluginInit()
42
40
        function PluginInit( & $params )
43
41
        {
44
42
                $this->name = $this->T_('Comment Gravatars');
45
 
                $this->short_desc = $this->T_( 'Simple plugin to display avatars/gravatars for people leaving comments' );
46
 
                $this->long_desc = $this->T_( '<p>This plugin displays a commentator\'s gravatar (Globally Recognized Avatar) if they\'ve registered for a
 
43
                $this->short_desc = $this->T_('Simple plugin to display avatars/gravatars for people leaving comments');
 
44
                $this->long_desc = $this->T_('<p>This plugin displays a commentator\'s gravatar (Globally Recognized Avatar) if they\'ve registered for a
47
45
 free account with gravatar.com. If not, it displays one of three uniquely generated avatars (identicons, wavatars or monsterids
48
46
 -- your choice).</p><p>Designed for a no muss, no fuss way to add avatars to the comments of your blog without having to bother
49
 
 with uploading files or doing any template coding.</p><p>Works for registered users of your blog as well as visitors.</p>' );
 
47
 with uploading files or doing any template coding.</p><p>Works for registered users of your blog as well as visitors.</p>');
50
48
        }
51
49
 
52
50
 
73
71
                        ),
74
72
                        'test_start' => array(
75
73
                                'label' => $this->T_('Avatar Preview'),
 
74
                                'type' => 'layout',
76
75
                                'layout' => 'begin_fieldset',
77
76
                        ),
78
77
                        'test' => array(
90
89
 
91
90
 
92
91
        /**
 
92
         * @see Plugin::GetDefaultBlogSettings()
 
93
         */
 
94
        function GetDefaultBlogSettings( & $params )
 
95
        {
 
96
                $blog_settings = array(
 
97
                        'enable_avatars' => array(
 
98
                                'label' => $this->T_('Enable Comment Avatars'),
 
99
                                'type' => 'checkbox',
 
100
                                'defaultvalue' => 1,
 
101
                                'note' => sprintf( $this->T_('Check this to enable the %s plugin for this blog.'), $this->name ),
 
102
                        ),
 
103
                        'no_gravatar' => array(
 
104
                                'label' => $this->T_('No Gravatar'),
 
105
                                'type' => 'select',
 
106
                                'options' => array(
 
107
                                        'identicon' => $this->T_('Uniquely generated fractal glyph (Identicons)'),
 
108
                                        'monsterid' => $this->T_('Uniquely generated monster (Monsterids)'),
 
109
                                        'wavatar' => $this->T_('Uniquely generated face (Wavatars)'),
 
110
                                        'default' => $this->T_('Gravatar default (Blue \'G\')'),
 
111
                                ),
 
112
                                'defaultvalue' => 'identicon',
 
113
                                'note' => sprintf( $this->T_('What to display if commentator isn\'t registered at %s'), 'gravatar.com' ),
 
114
                        ),
 
115
                        'gravatar_justify' => array(
 
116
                                'label' => $this->T_('Display Avatar'),
 
117
                                'type' => 'select',
 
118
                                'options' => array(
 
119
                                        'float:left' => $this->T_('Left of the comment'),
 
120
                                        'float:right' => $this->T_('Right of the comment'),
 
121
                                ),
 
122
                                'defaultvalue' => 'float:left',
 
123
                                'note' => $this->T_('Place the gravatar to the left or right of the comment'),
 
124
                        ),
 
125
                        'gravatar_size' => array(
 
126
                                'label' => $this->T_('Avatar Size'),
 
127
                                'type' => 'select',
 
128
                                'options' => array(
 
129
                                        '40' => $this->T_('40x40 Pixels'),
 
130
                                        '60' => $this->T_('60x60 Pixels'),
 
131
                                        '80' => $this->T_('80x80 Pixels'),
 
132
                                ),
 
133
                                'defaultvalue' => '60',
 
134
                                'note' => $this->T_('What size gravatar image to display'),
 
135
                        ),
 
136
                        'gravatar_rating' => array(
 
137
                                'label' => $this->T_('Gravatar Rating'),
 
138
                                'type' => 'select',
 
139
                                'options' => array(
 
140
                                        'g' => $this->T_('G-Rated gravatars'),
 
141
                                        'pg' => $this->T_('PG/G-Rated gravatars'),
 
142
                                        'r' => $this->T_('R/PG/G-Rated gravatars'),
 
143
                                        'x' => $this->T_('X/R/PG/G-Rated gravatars'),
 
144
                                ),
 
145
                                'defaultvalue' => 'g',
 
146
                                'note' => $this->T_('Limit the explicitness of commentators gravatars'),
 
147
                        ),
 
148
                );
 
149
                return $blog_settings;
 
150
        }
 
151
 
 
152
 
 
153
        /**
93
154
         * This is what makes it all go.
94
155
         */
95
156
        function display_gravatar( $params )
97
158
                // Get the settings from the params and plugin settings
98
159
                $tmp_Blog = $params['Comment']->Item->get_Blog();
99
160
                $params = array_merge( array(
100
 
                                'random' => $this->get_coll_setting( 'no_gravatar', $tmp_Blog ),
101
 
                                'rating' => $this->get_coll_setting( 'gravatar_rating', $tmp_Blog ),
102
 
                                'before' => '<div style="'.$this->get_coll_setting( 'gravatar_justify', $tmp_Blog ).'">',
 
161
                                'random' => $this->get_blog_setting( 'no_gravatar', $tmp_Blog ),
 
162
                                'rating' => $this->get_blog_setting( 'gravatar_rating', $tmp_Blog ),
 
163
                                'before' => '<div style="'.$this->get_blog_setting( 'gravatar_justify', $tmp_Blog ).'">',
103
164
                                'after' => '</div>',
104
 
                                'size' => $this->get_coll_setting( 'gravatar_size', $tmp_Blog ),
 
165
                                'size' => $this->get_blog_setting( 'gravatar_size', $tmp_Blog ),
105
166
                                'gravatar_title' => ( empty( $params['Comment']->author_User ) ? $params['Comment']->author : $params['Comment']->author_User->get_preferred_name() ),
106
167
                                'gravatar_email' => ( empty( $params['Comment']->author_User ) ? $params['Comment']->author_email : $params['Comment']->author_User->email ),
107
168
                        ), $params );
109
170
                // Build the url to retrieve the correct gravatar from gravatar.com.
110
171
                $url = 'http://www.gravatar.com/avatar.php?gravatar_id='.md5( $params['gravatar_email'] );
111
172
                $url .= '&amp;rating='.urlencode( $params['rating'] );
112
 
                if ($params['random'] != 'default') {
 
173
                if( $params['random'] != 'default' )
 
174
                {
113
175
                        // If the email address isn't registered at gravatar.com;
114
176
                        // Return one of three styles of uniquely generated 'identicons'.
115
177
                        $url .= '&amp;default='.urlencode( $params['random'] );
166
228
        {
167
229
                $url = $url = 'http://www.gravatar.com/avatar.php?gravatar_id='.md5( $this->Settings->get( 'test' ) );
168
230
                $url .= $url .= '&amp;rating='.urlencode( 'g' );
169
 
                if ( $this->Settings->get( 'no_gravatar' ) != 'default' ) {
 
231
                if( $this->Settings->get( 'no_gravatar' ) != 'default' )
 
232
                {
170
233
                        $url .= '&amp;default='.urlencode( $this->Settings->get( 'no_gravatar' ) );
171
234
                }
172
235
                $result =
187
250
 
188
251
 
189
252
        /**
190
 
         * @see Plugin::GetDefaultBlogSettings()
191
 
         */
192
 
        function GetDefaultBlogSettings( & $params )
193
 
        {
194
 
                return array(
195
 
                        'enable_avatars' => array(
196
 
                                'label' => $this->T_('Enable Comment Avatars'),
197
 
                                'type' => 'checkbox',
198
 
                                'defaultvalue' => 1,
199
 
                                'note' => sprintf( $this->T_('Check this to enable the %s plugin for this blog.'), $this->name ),
200
 
                        ),
201
 
                        'no_gravatar' => array(
202
 
                                'label' => $this->T_('No Gravatar'),
203
 
                                'type' => 'select',
204
 
                                'defaultvalue' => 'identicon',
205
 
                                'options' => array(
206
 
                                        'identicon' => $this->T_('Uniquely generated fractal glyph (Identicons)'),
207
 
                                        'monsterid' => $this->T_('Uniquely generated monster (Monsterids)'),
208
 
                                        'wavatar' => $this->T_('Uniquely generated face (Wavatars)'),
209
 
                                        'default' => $this->T_('Gravatar default (Blue \'G\')'),
210
 
                                ),
211
 
                                'note' => sprintf($this->T_('What to display if commentator isn\'t registered at %s'),
212
 
                                        'gravatar.com' ),
213
 
                        ),
214
 
                        'gravatar_justify' => array(
215
 
                                'label' => $this->T_('Display Avatar'),
216
 
                                'type' => 'select',
217
 
                                'defaultvalue' => 'float:left',
218
 
                                'options' => array(
219
 
                                        'float:left' => $this->T_('Left of the comment'),
220
 
                                        'float:right' => $this->T_('Right of the comment'),
221
 
                                ),
222
 
                                'note' => $this->T_('Place the gravatar to the left or right of the comment'),
223
 
                        ),
224
 
                        'gravatar_size' => array(
225
 
                                'label' => $this->T_('Avatar Size'),
226
 
                                'type' => 'select',
227
 
                                'defaultvalue' => '60',
228
 
                                'options' => array(
229
 
                                        '40' => $this->T_('40x40 Pixels'),
230
 
                                        '60' => $this->T_('60x60 Pixels'),
231
 
                                        '80' => $this->T_('80x80 Pixels'),
232
 
                                ),
233
 
                                'note' => $this->T_('What size gravatar image to display'),
234
 
                        ),
235
 
                        'gravatar_rating' => array(
236
 
                                'label' => $this->T_('Gravatar Rating'),
237
 
                                'type' => 'select',
238
 
                                'defaultvalue' => 'g',
239
 
                                'options' => array(
240
 
                                        'g' => $this->T_('G-Rated gravatars'),
241
 
                                        'pg' => $this->T_('PG/G-Rated gravatars'),
242
 
                                        'r' => $this->T_('R/PG/G-Rated gravatars'),
243
 
                                        'x' => $this->T_('X/R/PG/G-Rated gravatars'),
244
 
                                ),
245
 
                                'note' => $this->T_('Limit the explicitness of commentators gravatars'),
246
 
                        ),
247
 
                );
248
 
        }
249
 
 
250
 
 
251
 
        /**
252
253
         * @see Plugin::FilterCommentContent()
253
254
         */
254
255
        function FilterCommentContent( & $params )
255
256
        {
256
 
                if ( ! $this->get_coll_setting( 'enable_avatars', $params['Comment']->Item->get_Blog() ) )
 
257
                if( ! $this->get_blog_setting( 'enable_avatars', $params['Comment']->Item->get_Blog() ) )
257
258
                {
258
259
                        return;
259
260
                }