Dotclear

source: plugins/atReply/index.php @ 2746

Revision 2746, 7.7 KB checked in by Moe, 13 years ago (diff)

@ Reply 1.6:

  • added setting to automatically subscribe to comments email of replied comments (closes #496)
  • used array() with form::*() to remove multiple id="" on pages
Line 
1<?php
2# ***** BEGIN LICENSE BLOCK *****
3#
4# This file is part of @ Reply, a plugin for Dotclear 2
5# Copyright (C) 2008,2009,2010 Moe (http://gniark.net/) and buns
6#
7# @ Reply 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# @ Reply 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 @ Reply for WordPress :
24# <http://iyus.info/at-reply-petit-plugin-wordpress-inspire-par-twitter/>
25#
26# ***** END LICENSE BLOCK *****
27
28if (!defined('DC_CONTEXT_ADMIN')) {return;}
29
30$settings =& $core->blog->settings;
31
32try
33{
34     if (!empty($_POST['saveconfig']))
35     {
36          $active = $settings->atreply_active;
37         
38          $color = trim($_POST['atreply_color']);
39         
40          $settings->setNameSpace('atreply');
41          $settings->put('atreply_active',!empty($_POST['atreply_active']),
42               'boolean','Enable @ Reply');
43          if (!empty($_POST['atreply_active']))
44          {
45               # from commentsWikibar/index.php
46               $settings->put('wiki_comments',true,'boolean');
47          }
48         
49          $settings->put('atreply_display_title',!empty($_POST['atreply_display_title']),
50               'boolean','Display a text when the cursor is hovering the arrow');
51          $settings->put('atreply_color',$color,
52               'string','@ Reply arrow\'s color');
53          $settings->put('atreply_append',!empty($_POST['atreply_append']),
54               'boolean','Append replies to appropriate comments');
55          $settings->put('atreply_show_switch',!empty($_POST['atreply_show_switch']),
56               'boolean','Display a switch to toggle threading');
57
58          $settings->put('atreply_subscribe_replied_comment',
59               !empty($_POST['atreply_subscribe_replied_comment']),
60               'boolean','Subscribe replied comments to "Subscribe to comments"');
61         
62          # inspired by lightbox/admin.php
63          $settings->setNameSpace('system');
64         
65          # if there is a color
66          if (!empty($color))
67          {
68               # create the image
69               
70               # inspired by blowupConfig/lib/class.blowup.config.php
71               $color = sscanf($color,'#%2X%2X%2X');
72     
73               $red = $color[0];
74               $green = $color[1];
75               $blue = $color[2]; 
76     
77               $dir = path::real($core->blog->public_path.'/atReply',false);
78               files::makeDir($dir,true);
79               $file_path = $dir.'/reply.png';
80     
81               # create the image
82               $img = imagecreatefrompng(dirname(__FILE__).'/img/transparent_16x16.png');
83     
84               $source = imagecreatefrompng(dirname(__FILE__).'/img/reply.png');
85               imagealphablending($source,true);
86     
87               # copy image pixel per pixel, changing color but not the alpha channel
88               for ($x=0;$x <= 15;$x++)
89               {
90                    for ($y=0;$y <= 15;$y++)
91                    {
92                         $rgb = imagecolorat($source,$x,$y);
93                         $rgba = $rgb;
94                         $r = ($rgb >> 16) & 0xFF;
95                         $g = ($rgb >> 8) & 0xFF;
96                         $b = $rgb & 0xFF;
97     
98                         # alpha is an undocumented feature, see
99                         # http://php.net/manual/en/function.imagecolorat.php#79116
100                         $alpha = ($rgba & 0x7F000000) >> 24;
101     
102                         if ($r > 0)
103                         {
104                              imageline($img,$x,$y,$x,$y,
105                                   imagecolorallocatealpha($img,$red,$green,$blue,$alpha));
106                         }
107                    }
108               }
109               
110               imagedestroy($source);
111     
112               imagesavealpha($img,true);
113               if (is_writable($dir))
114               {
115                    imagepng($img,$file_path);
116               }
117               else
118               {
119                    throw new Exception(sprintf(__('%s is not writable'),$dir));
120               }
121               imagedestroy($img);
122          }
123         
124          # only update the blog if the setting have changed
125          if ($active == empty($_POST['atreply_active']))
126          {
127               $core->blog->triggerBlog();
128               
129               # delete the cache directory
130               $core->emptyTemplatesCache();
131          }
132         
133          http::redirect($p_url.'&saveconfig=1');
134     }
135}
136catch (Exception $e)
137{
138     $core->error->add($e->getMessage());
139}
140
141if (isset($_GET['saveconfig']))
142{
143     $msg = __('Configuration successfully updated.');
144}
145
146$image_url = $core->blog->getQmarkURL().'pf=atReply/img/reply.png';
147
148# personalized image
149if (strlen($core->blog->settings->atreply_color) > 1)
150{
151     $personalized_image = $core->blog->settings->public_url.
152          '/atReply/reply.png';
153     
154     if (file_exists(path::fullFromRoot($settings->public_path,
155          DC_ROOT).'/atReply/reply.png'))
156     {
157          $image_url = $personalized_image;
158         
159          if (substr($settings->public_url,0,1) == '/')
160          {
161               # public_path is located at the root of the website
162               $image_url = $core->blog->host.'/'.$personalized_image;
163          }
164          elseif (substr($settings->public_url,0,4) == 'http')
165          {
166               $image_url = $personalized_image;
167          } else {
168               $image_url = $core->blog->url.$personalized_image;
169          }
170     }
171}
172
173?><html>
174<head>
175     <title><?php echo(('@ Reply')); ?></title>
176     <?php echo(dcPage::jsColorPicker()); ?>
177</head>
178<body>
179
180     <h2><?php echo html::escapeHTML($core->blog->name).' &rsaquo; '.('@ Reply'); ?></h2>
181     
182     <?php 
183          if (!empty($msg)) {echo '<p class="message">'.$msg.'</p>';}
184     ?>
185     
186     <form method="post" action="<?php echo $p_url; ?>">
187          <fieldset>
188               <legend><?php echo(__('@ Reply')); ?></legend>
189               
190               <p><?php echo(form::checkbox('atreply_active',1,
191                    $settings->atreply_active)); ?>
192                    <label class="classic" for="atreply_active">
193                         <?php echo(__('Add arrows to easily reply to comments on the blog')); ?>
194                    </label>
195               </p>
196               <p class="form-note">
197                    <?php
198                         # from commentsWikibar/index.php
199                         echo(' '.__('Activating this plugin also enforces wiki syntax in blog comments.')); ?>
200               </p>
201
202               <p><?php echo(form::checkbox('atreply_display_title',1,
203                    $settings->atreply_display_title)); ?>
204                    <label class="classic" for="atreply_display_title">
205                         <?php echo(__('Display a text when the cursor is hovering the arrow')); ?>
206                    </label>
207               </p>
208               
209               <p><?php echo(form::checkbox('atreply_append',1,
210                    $settings->atreply_append)); ?>
211                    <label class="classic" for="atreply_append">
212                         <?php echo(__('Append replies to appropriate comments')); ?>
213                    </label>
214               </p>
215               
216               <p><?php echo(form::checkbox('atreply_show_switch',1,
217                    $settings->atreply_show_switch)); ?>
218                    <label class="classic" for="atreply_show_switch">
219                         <?php echo(__('Display a switch to toggle threading')); ?>
220                    </label>
221               </p>
222               <p class="form-note">
223                    <?php printf(__('Requires %s.'),
224                         __('Append replies to appropriate comments')); ?>
225               </p>
226
227               <p><?php echo(form::checkbox('atreply_subscribe_replied_comment',1,
228                    $settings->atreply_subscribe_replied_comment)); ?>
229                    <label class="classic" for="atreply_subscribe_replied_comment">
230                         <?php printf(__('When clicking on the "%s" button in a comment list of the administration, subscribe to comments the email address of the replied comment with the %s plugin'),
231                              __('reply to this comment'),__('Subscribe to comments')); ?>
232                    </label>
233               </p>
234               <p class="form-note">
235                    <?php printf(__('Requires the %s plugin.'),
236                         __('Subscribe to comments')); ?>
237               </p>
238               
239               <p>
240                    <label class="classic" for="atreply_color">
241                         <?php echo(__('Create an image with another color')); ?>
242                    </label>
243                    <?php echo(form::field('atreply_color',7,7,
244                         $settings->atreply_color,'colorpicker')); ?>
245               </p>
246               <p class="form-note">
247                    <?php echo(__('Leave blank to disable this feature.').' '.
248                         __('The default image will be used.')); ?>
249               </p>
250               
251               <?php echo('<p>'.__('Preview:').' <img src="'.$image_url.
252                    '" alt="reply.png" /></p>'); ?>
253          </fieldset>
254          <p><?php echo $core->formNonce(); ?></p>
255          <p><input type="submit" name="saveconfig" value="<?php echo __('Save configuration'); ?>" /></p>
256     </form>
257
258</body>
259</html>
Note: See TracBrowser for help on using the repository browser.

Sites map