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