Dotclear

source: plugins/subscribeToComments/_admin.php @ 2294

Revision 2294, 5.0 KB checked in by Moe, 14 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.
5# Copyright (C) 2008,2009,2010 Moe (http://gniark.net/)
6#
7# Subscribe to comments is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3 of the License, or
10# (at your option) any later version.
11#
12# Subscribe to comments is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20# Icon (icon.png) is from Silk Icons : http://www.famfamfam.com/lab/icons/silk/
21#
22# Inspired by http://txfx.net/code/wordpress/subscribe-to-comments/
23#
24# ***** END LICENSE BLOCK *****
25
26if (!defined('DC_CONTEXT_ADMIN')) {return;}
27
28$_menu['Plugins']->addItem(__('Subscribe to comments'),
29     'plugin.php?p=subscribeToComments',
30     'index.php?pf=subscribeToComments/icon.png',
31     preg_match('/plugin.php\?p=subscribeToComments(&.*)?$/',$_SERVER['REQUEST_URI']),
32     $core->auth->check('admin',$core->blog->id));
33
34if ($core->blog->settings->subscribetocomments_active)
35{
36     $core->addBehavior('coreAfterCommentCreate',array('subscribeToComments',
37          'coreAfterCommentCreate'));
38     # when a comment is published
39     $core->addBehavior('coreAfterCommentUpdate',array('subscribeToComments',
40          'coreAfterCommentUpdate'));
41     $core->addBehavior('adminAfterCommentDesc',array('subscribeToCommentsAdmin',
42          'adminAfterCommentDesc'));
43}
44
45# import/Export
46# from /dotclear/plugins/metadata/_admin.php, modified
47
48$core->addBehavior('exportFull',
49     array('subscribeToCommentsAdmin','exportFull'));
50$core->addBehavior('exportSingle',
51     array('subscribeToCommentsAdmin','exportSingle'));
52$core->addBehavior('importInit',
53     array('subscribeToCommentsAdmin','importInit'));
54$core->addBehavior('importSingle',
55     array('subscribeToCommentsAdmin','importSingle'));
56$core->addBehavior('importFull',
57     array('subscribeToCommentsAdmin','importFull'));
58
59/**
60@ingroup Subscribe to comments
61@brief Admin
62*/
63class subscribeToCommentsAdmin
64{
65     protected static $delete = true;
66     
67     /**
68     display informations on the admin comment form
69     @param    rs <b>recordset</b> Recordset
70     @return   <b>string</b>  String
71     */
72     public static function adminAfterCommentDesc($rs)
73     {
74          global $core;
75
76          # ignore trackbacks
77          if ($rs->comment_trackback == 1) {return;}
78
79          $rs = $core->con->select(
80               'SELECT notification_sent FROM '.$core->prefix.'comment '.
81               'WHERE (comment_id = '.$core->con->escape($rs->comment_id).') '.
82               'AND (notification_sent = 1);'
83          );
84          if ($rs->isEmpty())
85          {
86               $string = sprintf(
87                    __('<img src="images/check-off.png" alt="%1$s" title="%1$s" /> Notification email not sent, click on <strong>%2$s</strong>.'),
88                    __('not sent'),__('save'));
89          }
90          else
91          {
92               $string = sprintf(
93                    __('<img src="images/check-on.png" alt="%1$s" title="%1$s" /> Notification email sent.'),
94                    __('sent'));
95          }
96          return('<p><strong>'.__('Subscribe to comments:').'</strong> '.$string.'</p>');
97     }
98     
99     public static function exportFull(&$core,&$exp)
100     {
101          $exp->exportTable('comment_subscriber');
102     }
103     
104     public static function exportSingle(&$core,&$exp,$blog_id)
105     {
106          $exp->export('comment_subscriber',
107               'SELECT id, email, user_key, temp_key, temp_expire, status '.
108               'FROM '.$core->prefix.'comment_subscriber');
109     }
110     
111     public static function importInit(&$bk,&$core)
112     {
113          $bk->cur_comment_subscriber =
114               $core->con->openCursor($core->prefix.'comment_subscriber');
115     }
116     
117     public static function importFull(&$line,&$bk,&$core)
118     {   
119          if (self::$delete) {
120               $core->con->execute('DELETE FROM '.$core->prefix.'comment_subscriber');
121               self::$delete = false;
122          }
123
124          if ($line->__name == 'comment_subscriber')
125          {
126               $bk->cur_comment_subscriber->clean();
127               
128               $bk->cur_comment_subscriber->id = (integer) $line->id;
129               $bk->cur_comment_subscriber->email = (string) $line->email;
130               $bk->cur_comment_subscriber->user_key = (string) $line->user_key;
131               $bk->cur_comment_subscriber->temp_key = (string) $line->temp_key;
132               $bk->cur_comment_subscriber->temp_expire = (string) $line->temp_expire;
133               $bk->cur_comment_subscriber->status = (integer) $line->status;
134                             
135               $bk->cur_comment_subscriber->insert();
136          }
137     }
138     
139     public static function importSingle(&$line,&$bk,&$core)
140     {
141          if ($line->__name == 'comment_subscriber')
142          {
143               $cur = $core->con->openCursor($core->prefix.'comment_subscriber');
144               $cur->id = $line->id;
145               $cur->email = $line->email;
146               $cur->user_key = $line->user_key;
147               $cur->temp_key = $line->temp_key;
148               $cur->temp_expire = $line->temp_expire;
149               $cur->status = $line->status;
150               
151               $rs = $core->con->select('SELECT id FROM '.
152                    $core->prefix.'comment_subscriber '.
153                    'WHERE (email = \''.$line->email.'\');');
154               if ($rs->isEmpty())
155               {
156                    $cur->insert();
157               }
158               else
159               {
160                    # if the email already exist, update it
161                    $cur->update('WHERE (email = \''.$core->con->escape($line->email).'\')');
162               }
163          }
164     }
165}
166?>
Note: See TracBrowser for help on using the repository browser.

Sites map