Dotclear

source: plugins/subscribeToComments/inc/lib.subscribeToComments.tpl.php @ 2294

Revision 2294, 8.0 KB checked in by Moe, 13 years ago (diff)

Subscribe to comments 1.3.2 :

  • limited subscribers list to the current blog (closes #461)
  • moved _public.php classes in inc/
  • switched to GPL v2
  • PHP 5.3 compatibility ?
Line 
1<?php 
2# ***** BEGIN LICENSE BLOCK *****
3#
4# This file is part of Subscribe to comments, a plugin for Dotclear 2
5# Copyright (C) 2008,2009,2010 Moe (http://gniark.net/)
6#
7# Subscribe to comments is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License v2.0
9# as published by the Free Software Foundation.
10#
11# Subscribe to comments is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public
17# License along with this program. If not, see
18# <http://www.gnu.org/licenses/>.
19#
20# Icon (icon.png) and images are from Silk Icons :
21# <http://www.famfamfam.com/lab/icons/silk/>
22#
23# Inspired by Subscribe to Comments for WordPress :
24# <http://txfx.net/code/wordpress/subscribe-to-comments/>
25#
26# ***** END LICENSE BLOCK *****
27
28if (!defined('DC_RC_PATH')) {return;}
29
30/**
31@ingroup Subscribe to comments
32@brief Template
33*/
34class subscribeToCommentsTpl
35{
36     /**
37     check the box on post.html if a cookie is present
38     @return   <b>string</b> PHP block
39     */
40     public static function formChecked()
41     {
42          return("<?php ".
43          "if (isset(\$_POST['subscribeToComments'])) {echo(' checked=\"checked\" ');}".
44          "elseif (isset(\$_COOKIE['subscribetocomments']))".
45          "{echo(' checked=\"checked\" ');}".
46          " ?>");
47     }
48
49     /**
50     get link from post.html to subscriptions page
51     @return   <b>string</b> text and PHP block
52     */
53     public static function formLink()
54     {
55          global $core;
56
57          if ($core->blog->settings->subscribetocomments_active)
58          {
59               return("<?php echo(subscribeToComments::url().".
60               "((\$core->blog->settings->url_scan == 'query_string') ? '&amp;' : '?').".
61               "'post_id='.\$_ctx->posts->post_id); ?>");
62          }
63     }
64         
65     /**
66     if there is a message
67     @param    attr <b>array</b>   Attribute
68     @param    content   <b>string</b>  Content
69     @return   <b>string</b> PHP block
70     */
71     public static function ifMessage($attr,$content)
72     {
73          return
74          "<?php if (\$_ctx->subscribeToComments->message !== null) : ?>"."\n".
75          $content.
76          "<?php endif; ?>";
77     }
78
79     /**
80     display a message
81     @return   <b>string</b> PHP block
82     */
83     public static function message()
84     {
85          return("<?php if (\$_ctx->subscribeToComments->message !== null) :"."\n".
86          "echo(\$_ctx->subscribeToComments->message);".
87          "endif; ?>");
88     }
89
90     /**
91     get nonce
92     @return   <b>string</b> Nonce
93     */
94     public static function getNonce()
95     {
96          return "<?php echo(crypt::hmac(DC_MASTER_KEY,session_id())); ?>";
97     }
98
99     /**
100     if it's a post
101     @param    attr <b>array</b>   Attribute
102     @param    content   <b>string</b>  Content
103     @return   <b>string</b> PHP block
104     */
105     public static function entryIf($attr,$content)
106     {
107          return
108          "<?php if ((isset(\$_GET['post_id'])) AND ".
109          "(is_numeric(\$_GET['post_id']))) : "."\n".
110          "\$_ctx->posts = \$core->blog->getPosts(".
111          "array('no_content' => true, 'post_id' => \$_GET['post_id'],".
112          "'post_open_comment' => 1,".
113          "'post_type' => subscribeToComments::getAllowedPostTypes())".
114          "); "."\n".
115          "if (!\$_ctx->posts->isEmpty()) : ?>"."\n".
116          $content.
117          "<?php unset(\$_ctx->posts); ".
118          "endif;"."\n".
119          "endif; ?>";
120     }
121
122     /**
123     if user is not logged in
124     @param    attr <b>array</b>   Attribute
125     @param    content   <b>string</b>  Content
126     @return   <b>string</b> PHP block
127     */
128     public static function loggedIfNot($attr,$content)
129     {
130          return('<?php if (!$_ctx->subscribeToComments->checkCookie) : ?>'."\n".
131          $content."\n".
132          "<?php endif; ?>");
133     }
134
135     /**
136     if user is logged in
137     @param    attr <b>array</b>   Attribute
138     @param    content   <b>string</b>  Content
139     @return   <b>string</b> PHP block
140     */
141     public static function loggedIf($attr,$content)
142     {
143          return('<?php if ($_ctx->subscribeToComments->checkCookie) : ?>'."\n".
144          $content."\n".
145          "<?php endif; ?>");
146     }
147
148     /**
149     if user is not blocked
150     @param    attr <b>array</b>   Attribute
151     @param    content   <b>string</b>  Content
152     @return   <b>string</b> PHP block
153     */
154     public static function blockedIfNot($attr,$content)
155     {
156          return('<?php if (!$_ctx->subscribeToComments->blocked) : ?>'."\n".
157          $content."\n".
158          "<?php endif; ?>");
159     }
160
161     /**
162     if user is blocked
163     @param    attr <b>array</b>   Attribute
164     @param    content   <b>string</b>  Content
165     @return   <b>string</b> PHP block
166     */
167     public static function blockedIf($attr,$content)
168     {
169          return('<?php if ($_ctx->subscribeToComments->blocked) : ?>'."\n".
170          $content."\n".
171          "<?php endif; ?>");
172     }
173
174     /**
175     loop on posts
176     @param    attr <b>array</b>   Attribute
177     @param    content   <b>string</b>  Content
178     @return   <b>string</b> PHP block
179     */
180     public static function entries($attr,$content)
181     {
182          return("<?php ".
183          '$_ctx->meta = new dcMeta($core);'.
184          "\$_ctx->posts = \$_ctx->meta->getPostsByMeta(array(".
185          "'meta_type' => 'subscriber','meta_id' => ".
186          "subscriber::getCookie('id'),".
187          "'no_content' => true,".
188          "'post_type' => subscribeToComments::getAllowedPostTypes()));".
189          "if (!\$_ctx->posts->isEmpty()) :"."\n".
190          "while (\$_ctx->posts->fetch()) : ?>"."\n".
191          $content.
192          "<?php endwhile; "."\n".
193          " endif;"."\n".
194          'unset($_ctx->meta);'.
195          "unset(\$_ctx->posts); ?>");
196     }
197
198     /**
199     get email address
200     @return   <b>string</b> PHP block
201     */
202     public static function email()
203     {
204          return('<?php echo($_ctx->subscribeToComments->email); ?>');     
205     }
206
207     /**
208     get the URL of the subscriptions page
209     @return   <b>string</b> URL
210     */
211     public static function url()
212     {
213          return("<?php echo(subscribeToComments::url()); ?>");
214     }
215
216     /**
217     display checkbox to subscribe to comments
218     */
219     public static function publicCommentFormAfterContent()
220     {
221          global $_ctx;
222
223          if (subscribeToComments::getPost($_ctx->posts->post_id) == false)
224          {return;}
225
226          $checked = null;
227
228          # if checkbox is unchecked, don't check it
229          if (isset($_POST['subscribeToComments'])) 
230               {$checked = true;}
231          elseif (isset($_COOKIE['subscribetocomments']))
232               {$checked = true;}
233          if ($checked) {$checked =  ' checked="checked" ';}
234
235          $logged = 
236          (subscriber::checkCookie())
237          ?
238               $logged = ' (<strong><a href="'.subscribeToComments::url().'">'.
239                    __('Logged in').'</a></strong>)'
240          : '';
241
242          echo '<p>'.
243          '<label><input type="checkbox" name="subscribeToComments" '.
244          'id="subscribeToComments"'.$checked.' /> '.
245          __('Receive following comments by email').'</label>'.
246          $logged.
247          '</p>';
248     }
249     
250     /**
251     display a CSS rule for default themes
252     */
253     public static function publicHeadContent()
254     {
255          echo '<style type="text/css" media="screen">'."\n".
256          '#comment-form #subscribeToComments '.
257          '{width:auto;border:0;margin:0 5px 0 140px;}'."\n".
258          '</style>';
259     }
260
261     /**
262     add tpl code after the <tpl:EntryIf comments_active="1">...</tpl:EntryIf> tag
263     @param    core <b>core</b>    Dotclear core
264     @param    b    <b>array</b>   tag
265     @param    attr <b>array</b>   attributes
266     */
267     public static function templateAfterBlock($core,$b,$attr)
268     {
269          global $_ctx;
270
271          if ($core->url->type == 'feed') {return;}
272
273          if ($b == 'EntryIf' && isset($attr['comments_active'])
274               && $attr['comments_active'] == 1 && !isset($attr['pings_active']))
275          {
276               if ((!is_numeric($_ctx->posts->post_id)) OR
277               (subscribeToComments::getPost($_ctx->posts->post_id) == false))
278               {
279                    return;
280               }
281               # else
282               return 
283               '<?php if (($core->blog->settings->subscribetocomments_active) &&
284                    $_ctx->posts->commentsActive()) : ?>
285                    <div id="subscribetocomments_block">
286                         <h3><?php echo __("Subscribe to comments"); ?></h3>
287                         <p>
288                              <a href="<?php echo(subscribeToComments::url().
289                              (($core->blog->settings->url_scan == "query_string") ? "&amp;" : "?").
290                              "post_id=".$_ctx->posts->post_id); ?>">
291                                   <!-- # If the subscriber is logged in -->
292                                   <?php if (subscriber::checkCookie()) : ?>
293                                        <?php echo __("Subscribe to receive following comments by email or manage subscriptions"); ?>
294                                   <?php endif; ?>
295                                   <!-- # If the subscriber is not logged in -->
296                                   <?php if (!subscriber::checkCookie()) : ?>
297                                        <?php echo __("Subscribe to receive following comments by email"); ?>
298                                   <?php endif; ?>
299                              </a>
300                         </p>
301                    </div>
302               <?php endif; ?>';
303               # strings
304               __("Subscribe to receive following comments by email or manage subscriptions");
305               __("Subscribe to receive following comments by email");
306          }
307     }
308}
309
310?>
Note: See TracBrowser for help on using the repository browser.

Sites map