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