Dotclear

source: plugins/contribute/index.php @ 3098

Revision 3098, 13.0 KB checked in by Moe, 11 years ago (diff)

Contribute 1.0-alpha35:

  • fixed bug with Contribute entries display
  • fixed bug with empty URLs saved
Line 
1<?php 
2# ***** BEGIN LICENSE BLOCK *****
3#
4# This file is part of Contribute, a plugin for Dotclear 2
5# Copyright (C) 2008,2009,2010 Moe (http://gniark.net/)
6#
7# Contribute 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# Contribute 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 License
17# along with this program; if not, see <http://www.gnu.org/licenses/>.
18#
19# Icon (icon.png) is from Silk Icons :
20# <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$core->blog->settings->addNamespace('contribute');
29$settings =& $core->blog->settings->contribute;
30
31try
32{
33     if (!empty($_POST['saveconfig']))
34     {
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         
94          http::redirect($p_url.'&saveconfig=1');
95     }
96}
97catch (Exception $e)
98{
99     $core->error->add($e->getMessage());
100}
101
102if (isset($_GET['saveconfig']))
103{
104     $msg = __('Configuration successfully updated.');
105}
106
107$formaters_combo = array();
108$formaters_combo[''] = '';
109
110# Formaters combo
111foreach ($core->getFormaters() as $v) {
112     $formaters_combo[$v] = $v;
113}
114
115# get the users list
116$users= array();
117
118# get users with usage permission
119foreach ($core->getBlogPermissions($core->blog->id,true)
120     as $user_id => $infos)
121{
122     $name = $user_id.' '.((strlen($infos['displayname']) > 1) ?
123          '('.$infos['displayname'].') ' : '').
124          $infos['firstname'].' '.$infos['name'];
125     
126     $users[$name.(($user_id == $core->auth->userID())
127          ? ' ('.__('me').')' : '')] = $user_id;
128}
129
130# get the posts list
131$posts = array();
132$rs = $core->blog->getPosts();
133
134$posts[''] = '';
135while ($rs->fetch())
136{
137     $posts[html::escapeHTML($rs->post_title)] = $rs->post_id;
138}
139unset($rs);
140
141$default_post_url = 'post.php?id='.$settings->contribute_default_post;
142
143$author_format = $settings->contribute_author_format;
144
145if (empty($author_format)) {$author_format = __('%s (contributor)');}
146
147?>
148<html>
149<head>
150     <title><?php echo(__('Contribute')); ?></title>
151     <script type="text/javascript">
152     //<![CDATA[
153       $(document).ready(function () {
154          $('#contribute_default_post').change( function() {
155               $('#edit-post').attr({href:'post.php?id='+$(this).val()});
156          });
157          $('#contribute_default_post').change( function() {
158               if ($(this).val() == '') {
159                    $('#contribute_format').attr('disabled','');
160               } else {
161                    $('#contribute_format').attr('disabled','disabled');
162               }
163          });
164          });
165     //]]>
166  </script>
167</head>
168<body>
169
170     <h2><?php echo html::escapeHTML($core->blog->name).' &rsaquo; '.__('Contribute'); ?></h2>
171     
172     <?php 
173          if (!empty($msg)) {echo '<p class="message">'.$msg.'</p>';}
174     ?>
175     
176     <form method="post" action="<?php echo http::getSelfURI(); ?>">
177          <fieldset>
178               <legend><?php echo(__('General settings')); ?></legend>
179               <p>
180                    <?php echo(
181                    form::checkbox('contribute_active',1,
182                         $settings->contribute_active)); ?>
183                    <label class="classic" for="contribute_active">
184                    <?php echo(__('Allow visitors to contribute to your blog')); ?>
185                    </label>
186               </p>
187               
188               <p>
189                    <label for="contribute_user">
190                    <?php echo(__('Owner of the posts:').
191                    form::combo('contribute_user',$users,$settings->contribute_user)); ?>
192                    </label>
193               </p>
194               <p class="form-note">
195                    <?php echo(__('Only the users with the following permissions on this blog are shown:')); ?>
196               </p>
197               <ul>
198                    <li class="form-note" style="color:#f60;"><!-- usage --><?php echo(__('manage their own entries and comments')); ?></li>
199               </ul>
200               
201               <p>
202                    <label for="contribute_email_notification">
203                    <?php echo(__('Send emails to these email addresses when a new post is submitted:').
204                    form::field('contribute_email_notification',80,255,
205                         $settings->contribute_email_notification)); ?>
206                    </label>
207               </p>
208               <p class="form-note">
209                    <?php echo(__('You can enter several email addresses by separating these by a comma (<kbd>,</kbd>).').' '.
210                    __('Leave blank to disable this feature.')); ?>
211               </p>
212               
213               <p>
214                    <?php echo(
215                    form::checkbox('contribute_enable_antispam',1,
216                         $settings->contribute_enable_antispam)); ?>
217                    <label class="classic" for="contribute_enable_antispam">
218                    <?php echo(__('Enable antispam.').
219                         ' '.
220                         sprintf(__('It requires the %s plugin.'),
221                              __('Antispam'))); ?>
222                    </label>
223               </p>
224          </fieldset>
225         
226          <fieldset>
227               <legend><?php echo(__('Form')); ?></legend>
228               <p class="area">
229                    <label><?php echo(__('Help:').
230                         form::textarea('contribute_help',80,10,
231                         html::escapeHTML(base64_decode($settings->contribute_help)))); ?>
232                    </label>
233               </p>
234               <p>
235                    <label for="contribute_default_post">
236                    <?php echo(__('Default post:').
237                    form::combo('contribute_default_post',$posts,
238                         $settings->contribute_default_post)); ?>
239                    </label>
240                    <?php if ($settings->contribute_default_post)
241                    {
242                         printf('<a href="%1$s" id="edit-post">%2$s</a>',$default_post_url,
243                              __('edit this post'));
244                    }
245                    ?>
246               </p>
247               <p class="form-note">
248                    <?php echo(__('Select an existing post or create a new post, then select it.')).' ';
249                    printf(__('The post can be %s or %s.'),__('pending'),
250                    __('unpublished')).' ';
251                    echo(__('The form will be filled with the values of this post.').' '.
252                    __('Leave blank to disable this feature.')); ?>
253               </p>
254               
255               <p>
256                    <label for="contribute_format">
257                    <?php echo(__('Text formating (only if no default post is selected):').
258                    form::combo('contribute_format',$formaters_combo,
259                         $settings->contribute_format)); ?>
260                    </label>
261               </p>
262               <p class="form-note">
263                    <?php echo(__('Contributors will be able to choose the format.').' '.
264                         __('Some formats may be unavailable on the blog.').' '.
265                         __('Leave blank to disable this feature.')); ?>
266               </p>
267               
268               <h3><?php echo(__('Allow contributors to:')); ?></h3>
269               <p>
270                    <?php echo(form::checkbox('contribute_allow_excerpt',1,
271                         $settings->contribute_allow_excerpt)); ?>
272                    <label class="classic" for="contribute_allow_excerpt">
273                    <?php echo(__('write an excerpt')); ?>
274                    </label>
275               </p>
276               
277               <p>
278                    <?php echo(form::checkbox('contribute_allow_category',1,
279                         $settings->contribute_allow_category)); ?>
280                    <label class="classic" for="contribute_allow_category">
281                    <?php echo(__('choose the category')); ?>
282                    </label>
283               </p>
284               
285               <p>
286                    <?php echo(form::checkbox('contribute_allow_tags',1,
287                         $settings->contribute_allow_tags)); ?>
288                    <label class="classic" for="contribute_allow_tags">
289                    <?php echo(__('choose the tags')); ?>
290                    </label>
291               </p>
292               
293               <p>
294                    <?php echo(form::checkbox('contribute_allow_new_tags',1,
295                         $settings->contribute_allow_new_tags)); ?>
296                    <label class="classic" for="contribute_allow_new_tags">
297                    <?php echo(__('add new tags (only if tags are allowed)')); ?>
298                    </label>
299               </p>
300                         
301               <p>
302                    <?php echo(form::checkbox('contribute_allow_notes',1,
303                         $settings->contribute_allow_notes)); ?>
304                    <label class="classic" for="contribute_allow_notes">
305                    <?php echo(__('write notes')); ?>
306                    </label>
307               </p>
308               
309               <p>
310                    <?php echo(form::checkbox('contribute_allow_author',1,
311                         $settings->contribute_allow_author)); ?>
312                    <label class="classic" for="contribute_allow_author">
313                    <?php echo(__('enter their name, email address and website URL')); ?>
314                    </label>
315               </p>
316               
317               <p>
318                    <?php echo(form::checkbox('contribute_require_name_email',1,
319                         $settings->contribute_require_name_email)); ?>
320                    <label class="classic" for="contribute_require_name_email">
321                    <?php echo(__('require name and email (only if name, email address and website URL are allowed)')); ?>
322                    </label>
323               </p>
324          </fieldset>
325         
326          <fieldset>
327               <legend><?php echo(__('Display')); ?></legend>
328               <p>
329                    <label for="contribute_author_format">
330                    <?php echo(__('Display of the author name on the blog:').' '.__('(%s is the author name or nickname)').
331                    form::field('contribute_author_format',80,80,$author_format)); ?>
332                    </label>
333               </p>
334               <p class="form-note">
335                    <?php echo(__('Leave blank to disable this feature.')); ?>
336               </p>
337          </fieldset>   
338         
339          <fieldset>
340               <legend><?php echo(__('My Meta')); ?></legend>
341               <p>
342                    <?php echo(form::checkbox('contribute_allow_mymeta',1,
343                         $settings->contribute_allow_mymeta)); ?>
344                    <label class="classic" for="contribute_allow_mymeta">
345                    <?php printf(__('Allow contributors to choose %s values.'),
346                         __('My Meta'));
347                         echo(' ');
348                         printf(__('It requires the %s plugin.'),__('My Meta'));
349                    ?>
350                    </label>
351               </p>
352               
353               <?php
354                    if ($core->plugins->moduleExists('mymeta'))
355                    {
356                         $mymeta = new myMeta($core);
357                         $rs_values = contribute::getMyMeta($mymeta,true);
358                         
359                         if (!$rs_values->isEmpty())
360                         {
361                              while ($rs_values->fetch())
362                              {
363                                   if ($rs_values->isStart())
364                                   {
365                                        echo('<hr /><h3>'.
366                                        sprintf(__('Enable these %s values:'),__('My Meta')).
367                                        '</h3>');
368                                   }
369                                   
370                                   if ($rs_values->type == 'section') {echo '<h4>';}
371                                   else {echo '<p>';}
372                                   
373                                   echo(form::checkbox(
374                                        array('mymeta_values[]','mymeta_'.$rs_values->id),
375                                        $rs_values->id,$rs_values->active).
376                                   '<label class="classic" for="mymeta_'.$rs_values->id.'">'.
377                                   $rs_values->prompt.
378                                   '</label>');
379                                   
380                                   if ($rs_values->type == 'section') {echo '</h4>';}
381                                   else {echo '</p>';}
382                              }
383                         }
384                         unset($rs_values);
385                    }
386               ?>
387          </fieldset>
388                   
389          <p><?php echo $core->formNonce(); ?></p>
390          <p><input type="submit" name="saveconfig" value="<?php echo __('Save configuration'); ?>" /></p>
391     </form>
392     
393     <?php
394          $meta = new dcMeta($core);
395
396          # from dcMeta->getPostsByMeta()
397          $params = array();
398          $params['from'] = ', '.$core->prefix.'meta'.' META ';
399          $params['sql'] = 'AND META.post_id = P.post_id '; 
400          $params['sql'] .= "AND META.meta_type = '".
401                    $core->con->escape('contribute_public_url')."' ";
402         
403          $rs = $core->blog->getPosts($params);
404         
405          if ($rs->isEmpty())
406          {
407               print('<p>'.__("No Contribute entry.").'</p>');
408          }
409          else
410          {
411               while($rs->fetch())
412               {
413                    if ($rs->isStart())
414                    {
415                         print('<h3>'.__("Contribute entries").'</h3>');
416                         print('<ul>');
417                    }
418                   
419                    print('<li><a href="'.
420                         $core->getPostAdminURL($rs->post_type,$rs->post_id).'">'.
421                         $rs->post_title.'</a></li>');
422                   
423                    if ($rs->isEnd())
424                    {
425                         print('</ul>');
426                    }
427               }
428          }
429     ?>
430     <hr />
431     
432     <p>
433          <?php printf(__('URL of the %s page:'),__('Contribute')); ?>
434          <br />
435          <code><?php echo($core->blog->url.$core->url->getBase('contribute')); ?></code>
436          <br />
437          <a href="<?php echo($core->blog->url.$core->url->getBase('contribute')); ?>">
438          <?php printf(__('View the %s page'),__('Contribute')); ?></a>   
439     </p>
440
441</body>
442</html>
Note: See TracBrowser for help on using the repository browser.

Sites map