Dotclear

source: plugins/atReply/index.php @ 2908

Revision 2908, 7.9 KB checked in by Moe, 13 years ago (diff)

@ Reply 1.6.1: changed plugin permissions (closes #611)

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

Sites map