Dotclear

source: plugins/contribute/index.php @ 1594

Revision 1594, 12.2 KB checked in by Moe, 13 years ago (diff)

Contribute 1.0-alpha21 :

  • fixed bug with smilies (fixes #240)
Line 
1<?php 
2# ***** BEGIN LICENSE BLOCK *****
3#
4# This file is part of Contribute.
5# Copyright 2008,2009 Moe (http://gniark.net/)
6#
7# Contribute 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# Contribute 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# ***** END LICENSE BLOCK *****
23
24if (!defined('DC_CONTEXT_ADMIN')) { return; }
25
26l10n::set(dirname(__FILE__).'/locales/'.$_lang.'/admin');
27
28$settings =& $core->blog->settings;
29
30try
31{
32     if (!empty($_POST['saveconfig']))
33     {
34          $settings->setNameSpace('contribute');
35          $settings->put('contribute_active',!empty($_POST['contribute_active']),
36               'boolean','Enable Contribute');
37          $settings->put('contribute_user',$_POST['contribute_user'],
38               'string', 'user');
39          $settings->put('contribute_email_notification',
40               $_POST['contribute_email_notification'],
41               'string', 'email notification');
42          $settings->put('contribute_enable_antispam',
43               !empty($_POST['contribute_enable_antispam']),
44               'boolean', 'Enable antispam');
45         
46          $settings->put('contribute_help',
47               base64_encode($_POST['contribute_help']),'String','Help');
48          $settings->put('contribute_default_post',
49               $_POST['contribute_default_post'],'integer','Default post');
50          $settings->put('contribute_format',$_POST['contribute_format'],
51               'string','Post format');
52         
53          $settings->put('contribute_allow_excerpt',
54               !empty($_POST['contribute_allow_excerpt']),
55               'boolean','Allow contributors to write an excerpt');
56          $settings->put('contribute_allow_category',
57               !empty($_POST['contribute_allow_category']),
58               'boolean','Allow contributors to choose the category');
59          $settings->put('contribute_allow_tags',
60               !empty($_POST['contribute_allow_tags']),
61               'boolean','Allow contributors to choose the tags');
62          $settings->put('contribute_allow_new_tags',
63               !empty($_POST['contribute_allow_new_tags']),
64               'boolean','Allow contributors to add new tags');
65         
66          $settings->put('contribute_allow_notes',
67               !empty($_POST['contribute_allow_notes']),
68               'boolean','Allow contributors to write notes');
69          $settings->put('contribute_allow_author',
70               !empty($_POST['contribute_allow_author']),
71               'boolean','Allow contributors to enter their name, email address and website URL');
72          $settings->put('contribute_require_name_email',
73               !empty($_POST['contribute_require_name_email']),
74               'boolean','require name and email');
75         
76          $settings->put('contribute_author_format',
77               (!empty($_POST['contribute_author_format'])
78                    ? $_POST['contribute_author_format'] : '%s'),
79               'string','Author format');
80         
81          $settings->put('contribute_allow_mymeta',
82               !empty($_POST['contribute_allow_mymeta']),
83               'boolean','Allow contributors to choose My Meta values');
84         
85          $mymeta_values = array();
86          if (!empty($_POST['mymeta_values']))
87          {
88               $mymeta_values = $_POST['mymeta_values'];
89          }
90          $mymeta_values = base64_encode(serialize($mymeta_values));
91          $settings->put('contribute_mymeta_values',$mymeta_values,'string',
92               'Active My Meta values');
93          # inspirated by lightbox/admin.php
94          $settings->setNameSpace('system');
95         
96          http::redirect($p_url.'&saveconfig=1');
97     }
98}
99catch (Exception $e)
100{
101     $core->error->add($e->getMessage());
102}
103
104if (isset($_GET['saveconfig']))
105{
106     $msg = __('Configuration successfully updated.');
107}
108
109$formaters_combo = array();
110$formaters_combo[''] = '';
111
112# Formaters combo
113foreach ($core->getFormaters() as $v) {
114     $formaters_combo[$v] = $v;
115}
116
117# get the users list
118$users= array();
119
120# get users with usage permission
121foreach ($core->getBlogPermissions($core->blog->id,true)
122     as $user_id => $infos)
123{
124     $name = $user_id.' '.((strlen($infos['displayname']) > 1) ?
125          '('.$infos['displayname'].') ' : '').
126          $infos['firstname'].' '.$infos['name'];
127     
128     $users[$name.(($user_id == $core->auth->userID())
129          ? ' ('.__('me').')' : '')] = $user_id;
130}
131
132# get the posts list
133$posts = array();
134$rs = $core->blog->getPosts();
135
136$posts[''] = '';
137while ($rs->fetch())
138{
139     $posts[html::escapeHTML($rs->post_title)] = $rs->post_id;
140}
141unset($rs);
142
143$default_post_url = 'post.php?id='.$settings->contribute_default_post;
144
145$author_format = $settings->contribute_author_format;
146
147if (empty($author_format)) {$author_format = __('%s (contributor)');}
148
149?>
150<html>
151<head>
152     <title><?php echo(__('Contribute')); ?></title>
153     <script type="text/javascript">
154     //<![CDATA[
155       $(document).ready(function () {
156          $('#contribute_default_post').change( function() {
157               $('#edit-post').attr({href:'post.php?id='+$(this).val()});
158          });
159         
160          $('#contribute_default_post').change( function() {
161               if ($(this).val() == '') {
162                    $('#contribute_format').attr('disabled','');
163               } else {
164                    $('#contribute_format').attr('disabled','disabled');
165               }
166          });
167          });
168     //]]>
169  </script>
170</head>
171<body>
172
173     <h2><?php echo html::escapeHTML($core->blog->name).' &rsaquo; '.__('Contribute'); ?></h2>
174     
175     <?php 
176          if (!empty($msg)) {echo '<p class="message">'.$msg.'</p>';}
177     ?>
178     
179     <form method="post" action="<?php echo http::getSelfURI(); ?>">
180          <fieldset>
181               <legend><?php echo(__('General settings')); ?></legend>
182               <p>
183                    <?php echo(
184                    form::checkbox('contribute_active',1,
185                         $settings->contribute_active)); ?>
186                    <label class="classic" for="contribute_active">
187                    <?php echo(__('Allow visitors to contribute to your blog')); ?>
188                    </label>
189               </p>
190               
191               <p>
192                    <label for="contribute_user">
193                    <?php echo(__('Owner of the posts:').
194                    form::combo('contribute_user',$users,$settings->contribute_user)); ?>
195                    </label>
196               </p>
197               <p class="form-note">
198                    <?php echo(__('Only the users with the following permissions on this blog are shown:')); ?>
199               </p>
200               <ul class="form-note">
201                    <li><!-- usage --><?php echo(__('manage their own entries and comments')); ?></li>
202               </ul>
203               
204               <p>
205                    <label for="contribute_email_notification">
206                    <?php echo(__('Send emails to these email adresses when a new post is submitted:').
207                    form::field('contribute_email_notification',80,255,
208                         $settings->contribute_email_notification)); ?>
209                    </label>
210               </p>
211               <p class="form-note">
212                    <?php echo(__('You can enter several email adresses by separating these by a comma (<code>,</code>).').' '.
213                    __('Leave empty to cancel this feature.')); ?>
214               </p>
215               
216               <p>
217                    <?php echo(
218                    form::checkbox('contribute_enable_antispam',1,
219                         $settings->contribute_enable_antispam)); ?>
220                    <label class="classic" for="contribute_enable_antispam">
221                    <?php echo(__('Enable antispam.').
222                         ' '.
223                         sprintf(__('It requires the %s plugin.'),
224                              __('Antispam'))); ?>
225                    </label>
226               </p>
227          </fieldset>
228         
229          <fieldset>
230               <legend><?php echo(__('Form')); ?></legend>
231               <p class="area">
232                    <label><?php echo(__('Help:').
233                         form::textarea('contribute_help',80,10,
234                         html::escapeHTML(base64_decode($settings->contribute_help)))); ?>
235                    </label>
236               </p>
237               <p>
238                    <label for="contribute_default_post">
239                    <?php echo(__('Default post:').
240                    form::combo('contribute_default_post',$posts,
241                         $settings->contribute_default_post)); ?>
242                    </label>
243                    <?php if ($settings->contribute_default_post)
244                    {
245                         printf('<a href="%1$s" id="edit-post">%2$s</a>',$default_post_url,
246                              __('edit this post'));
247                    }
248                    ?>
249               </p>
250               <p class="form-note">
251                    <?php echo(__('Select an existing post or create a new post, then select it.')).' ';
252                    printf(__('The post can be %s or %s.'),__('pending'),
253                    __('unpublished')).' ';
254                    echo(__('The form will be filled with the values of this post.').' '.
255                    __('Leave empty to cancel this feature.')); ?>
256               </p>
257               
258               <p>
259                    <label for="contribute_format">
260                    <?php echo(__('Text formating (only if no default post is selected):').
261                    form::combo('contribute_format',$formaters_combo,
262                         $settings->contribute_format)); ?>
263                    </label>
264               </p>
265               <p class="form-note">
266                    <?php echo(__('Contributors will be able to choose the format.').' '.
267                         __('Some formats may be unavailable on the blog.').' '.
268                         __('Leave empty to cancel this feature.')); ?>
269               </p>
270               
271               <h3><?php echo(__('Allow contributors to:')); ?></h3>
272               <p>
273                    <?php echo(form::checkbox('contribute_allow_excerpt',1,
274                         $settings->contribute_allow_excerpt)); ?>
275                    <label class="classic" for="contribute_allow_excerpt">
276                    <?php echo(__('write an excerpt')); ?>
277                    </label>
278               </p>
279               
280               <p>
281                    <?php echo(form::checkbox('contribute_allow_category',1,
282                         $settings->contribute_allow_category)); ?>
283                    <label class="classic" for="contribute_allow_category">
284                    <?php echo(__('choose the category')); ?>
285                    </label>
286               </p>
287               
288               <p>
289                    <?php echo(form::checkbox('contribute_allow_tags',1,
290                         $settings->contribute_allow_tags)); ?>
291                    <label class="classic" for="contribute_allow_tags">
292                    <?php echo(__('choose the tags')); ?>
293                    </label>
294               </p>
295               
296               <p>
297                    <?php echo(form::checkbox('contribute_allow_new_tags',1,
298                         $settings->contribute_allow_new_tags)); ?>
299                    <label class="classic" for="contribute_allow_new_tags">
300                    <?php echo(__('add new tags (only if tags are allowed)')); ?>
301                    </label>
302               </p>
303                         
304               <p>
305                    <?php echo(form::checkbox('contribute_allow_notes',1,
306                         $settings->contribute_allow_notes)); ?>
307                    <label class="classic" for="contribute_allow_notes">
308                    <?php echo(__('write notes')); ?>
309                    </label>
310               </p>
311               
312               <p>
313                    <?php echo(form::checkbox('contribute_allow_author',1,
314                         $settings->contribute_allow_author)); ?>
315                    <label class="classic" for="contribute_allow_author">
316                    <?php echo(__('enter their name, email address and website URL')); ?>
317                    </label>
318               </p>
319               
320               <p>
321                    <?php echo(form::checkbox('contribute_require_name_email',1,
322                         $settings->contribute_require_name_email)); ?>
323                    <label class="classic" for="contribute_require_name_email">
324                    <?php echo(__('require name and email (only if name, email address and website URL are allowed)')); ?>
325                    </label>
326               </p>
327          </fieldset>
328         
329          <fieldset>
330               <legend><?php echo(__('Display')); ?></legend>
331               <p>
332                    <label for="contribute_author_format">
333                    <?php echo(__('Display of the author name on the blog:').' '.__('(%s is the author name or nickname)').
334                    form::field('contribute_author_format',80,80,$author_format)); ?>
335                    </label>
336               </p>
337               <p class="form-note">
338                    <?php echo(__('Leave empty to cancel this feature.')); ?>
339               </p>
340          </fieldset>   
341         
342          <fieldset>
343               <legend><?php echo(__('My Meta')); ?></legend>
344               <p>
345                    <?php echo(form::checkbox('contribute_allow_mymeta',1,
346                         $settings->contribute_allow_mymeta)); ?>
347                    <label class="classic" for="contribute_allow_mymeta">
348                    <?php printf(__('Allow contributors to choose %s values.'),
349                         __('My Meta'));
350                         echo(' ');
351                         printf(__('It requires the %s plugin.'),
352                              __('My Meta')); ?>
353                    </label>
354               </p>
355               
356               <?php
357                    if ($core->plugins->moduleExists('mymeta'))
358                    {
359                         $mymeta = new myMeta($core);
360                         $rs_values = contribute::getMyMeta($mymeta,true);
361                         
362                         if (!$rs_values->isEmpty())
363                         {
364                              while ($rs_values->fetch())
365                              {
366                                   if ($rs_values->isStart())
367                                   {
368                                        echo('<hr />');
369                                        printf(__('Enable these %s values:'),__('My Meta'));
370                                   }
371                                   echo('<p>'.form::checkbox(
372                                        array('mymeta_values[]','mymeta_'.$rs_values->id),
373                                        $rs_values->id,$rs_values->active).
374                                   '<label class="classic" for="mymeta_'.$rs_values->id.'">'.
375                                   $rs_values->prompt.
376                                   '</label></p>');
377                                   if ($rs_values->isEnd())
378                                   {
379                                        //echo('<hr />');
380                                   }
381                              }
382                         }
383                         unset($rs_values);
384                    }
385               ?>
386          </fieldset>
387                   
388          <p><?php echo $core->formNonce(); ?></p>
389          <p><input type="submit" name="saveconfig" value="<?php echo __('Save configuration'); ?>" /></p>
390     </form>
391     
392     <hr />
393     
394     <p>
395          <?php printf(__('URL of the %s page:'),__('Contribute')); ?>
396          <br />
397          <code><?php echo($core->blog->url.$core->url->getBase('contribute')); ?></code>
398          <br />
399          <a href="<?php echo($core->blog->url.$core->url->getBase('contribute')); ?>">
400          <?php printf(__('View the %s page'),__('Contribute')); ?></a>   
401     </p>
402
403</body>
404</html>
Note: See TracBrowser for help on using the repository browser.

Sites map