Dotclear

source: plugins/atReply/index.php @ 1608

Revision 1608, 6.7 KB checked in by Moe, 14 years ago (diff)

fixed various typos for inspired by

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

Sites map