Dotclear

source: plugins/muppet/index.php @ 2339

Revision 2339, 6.6 KB checked in by Osku, 3 years ago (diff)

Muppet 0.5.3 : minor fix.

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of muppet, a plugin for Dotclear 2.
5#
6# Copyright (c) 2010 Osku and contributors
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11#
12# -- END LICENSE BLOCK ------------------------------------
13if (!defined('DC_CONTEXT_ADMIN')) { return; }
14
15$my_types = muppet::getPostTypes();
16
17$type = (!empty($_REQUEST['type'])) ? $_REQUEST['type'] : '';
18$id = (!empty($_REQUEST['id'])) ? $_REQUEST['id'] : '';
19$list = (!empty($_REQUEST['list'])) ? $_REQUEST['list'] : '';
20$edit = (!empty($_REQUEST['edit'])) ? $_REQUEST['edit'] : '';
21
22$newtype = $name = $plural = '';
23$counts = array();
24$icon = 'image-1.png';
25
26if (!empty($type))
27{
28     if (empty($list))
29     {
30          include dirname(__FILE__).'/item.php';
31     }
32     else
33     {
34          include dirname(__FILE__).'/list.php';
35     }
36     return;
37}
38
39if (!$core->auth->check('admin',$core->blog->id)) { return; }
40
41$add_type = false;
42$icons = array();
43
44for ($i = 1; $i <= 20; $i++) {
45     $icons= array_merge($icons, array(sprintf('- %s -',$i) => sprintf('image-%s.png',$i)));
46}
47
48if (!empty($_POST['typeadd']))
49{
50     $type = mb_strtolower($_POST['newtype']);
51     $newtype = $_POST['newtype'];
52     $name = trim($_POST['name']);
53     $plural = trim($_POST['plural']);
54     $icon = $_POST['icon'];
55
56     if (!preg_match('/^([a-z]{2,})$/',$type))
57     {
58          $core->error->add(__('Post type must contain at least 2 letters (only letters).'));
59     }
60
61     if (muppet::typeIsExcluded($type))
62     {
63          $core->error->add(__('This post type is aleady used by another plugin.'));
64     }
65
66     //if (!preg_match('/^\w+(\s*\w+)?$/',$name))
67     if (empty($name))
68     {
69          $core->error->add(__('Name should be a nice word.'));
70     }
71
72     $values = array(
73          'name' =>  mb_strtolower($name),
74          'plural' => mb_strtolower($plural),
75          'icon' => $_POST['icon']
76     );
77
78     if (!$core->error->flag())
79     {
80          muppet::setNewPostType($type,$values);
81          http::redirect($p_url.'&msg=saved');
82     }
83}
84if (!empty($_POST['typedel']))
85{
86     $type = mb_strtolower($_POST['newtype']);
87     
88     if (!$core->error->flag())
89     {
90          muppet::removePostType($type);
91          http::redirect($p_url.'&msg=deleted');
92     }
93}
94
95if (!empty($_POST['getinfo']))
96{
97     $counts = muppet::getInBasePostTypesCounter();
98}
99
100# Messages - thanks JcDenis for the method :-)
101$msg = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : '';
102$msg_list = array(
103     'saved' => __('Configuration successfully saved.'),
104     'deleted' => __('Post type successuflly removed.')
105);
106
107if (isset($msg_list[$msg])) {
108     $msg = sprintf('<p class="message">%s</p>',$msg_list[$msg]);
109}
110
111if (!empty($edit) || $core->error->flag())
112{
113     $add_type = true;
114}
115
116?>
117<html>
118<head>
119     <title><?php echo __('Muppet'); ?></title>
120     <?php echo dcPage::jsLoad('index.php?pf=muppet/js/misc.js'); ?>
121     <?php if (!$add_type) {
122          echo dcPage::jsLoad('index.php?pf=muppet/js/form.js');
123     }?>
124     <script type="text/javascript">
125     //<![CDATA[
126       <?php echo dcPage::jsVar('dotclear.icon_base_url','index.php?pf=muppet/img/');?>
127     //]]>
128     </script>
129     <style type="text/css">
130          img.icon {vertical-align:middle;}
131          span.hot {color:#009966}
132          input.delete {color:#FF0000;}
133          a.none{border:none;}
134          div.post {border-right:1px dotted #cecfca;margin: 0 20px 10px 0;}
135          dl.list dd{margin-left:1em;padding:5px;}
136     </style>
137</head>
138<body>
139<?php
140echo
141'<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; '.__('Supplementary post types').'</h2>';
142echo $msg;
143echo '<h3>'.__('My post types').'</h3>';
144if (empty($my_types))
145{
146     echo '<p>'.__('No type has been defined yet.').'</p>';
147}
148else
149{
150     foreach ($my_types as $k => $v)
151     {
152          $plural = empty($v['plural']) ? $v['name'].'s' : $v['plural'];
153          $redir = 'plugin.php?p=muppet&amp;edit=';
154         
155          echo
156          '<div class="post" style="width:180px; float:left;">'.
157          '<h4><a class="none" href="'.$redir.$k.'"><img src="images/edit-mini.png" alt="" title="'.__('edit this post type').'" /></a>&nbsp;'.sprintf(__('Type: <span class="hot">%s</span>'),$k).'</h4>'.
158          '<dl class="list">'.
159          '<dt>'.__('Name:').'</dt><dd>'.$v['name'].'&nbsp;('.$plural.')</dd>'.
160          '<dt>'.__('Menu image:').'</dt><dd><img src="index.php?pf=muppet/img/'.$v['icon'].'" alt="'.$v['icon'].'" /></dd>'.
161          '<dt>'.__('Permission:').'</dt><dd>'.sprintf(__('manage the %s'),$plural).'</dd>'.
162          '</dl>'.
163          '</div>';
164     }
165}
166
167$legend = __('Create a new post type');
168$label_add = __('Create');
169
170if (!empty($edit))
171{
172     if (array_key_exists($edit,$my_types))
173     {
174          $newtype = $edit;
175          $name = $my_types[$edit]['name'];
176          $plural = $my_types[$edit]['plural'];
177          $icon = $my_types[$edit]['icon'];
178          $legend = __('Modify a post type');
179          $label_add = __('Save');
180     }
181}
182
183$preview_icon = '<img class="icon" src="index.php?pf=muppet/img/'.$icon.'" alt="'.$icon.'" title="'.$icon.'" id="icon-preview" />';
184
185
186if (!$add_type) {
187     echo '<div class="clear" id="new-type"><p><a class="new" id="muppet-control" href="#">'.
188     __('Create a new post type').'</a></p></div>';
189}
190
191echo
192'<div class="clear">'.
193'<form action="'.$p_url.'" method="post" id="add-post-type">'.
194'<fieldset>'.
195'<legend>'.$legend .'</legend>'.
196'<p><label class="required" title="'.__('Required field').'">'.__('Type:').' '.
197form::field('newtype',30,255,$newtype).'</label></p>'.
198'<p><label class="required" title="'.__('Required field').'">'.__('Name:').' '.
199form::field('name',30,255,$name).'</label></p>'.
200'<p><label class="" title="'.__('Required field').'">'.__('Plural form:').' '.
201form::field('plural',30,255,$plural).'</label></p>'.
202''.
203'<p><label class="classic required" title="'.__('Required field').'">'.__('Image:').' '.
204form::combo('icon',$icons,$icon).'</label>'.$preview_icon.'</p>'.
205'<p>'.form::hidden(array('p'),'muppet').
206$core->formNonce().
207'<input type="submit" name="typeadd" value="'.$label_add.'" />&nbsp;';
208echo (!empty($edit)) ? '<input type="submit" class="delete"  name="typedel" value="'.__('Delete').'" />' : '';
209echo '</p>'.
210'</fieldset>'.
211'</form></div>';
212
213if (empty($counts))
214{
215     echo
216     '<form action="'.$p_url.'" method="post" id="get-infos">'.
217     '<h3>'.__('Statistics').'</h3>'.
218     '<p><input type="submit" name="getinfo" value="'.__('Retrieve types from database').'" /> '.
219     $core->formNonce().
220     form::hidden(array('p'),'muppet').'</p>'.
221     '</form>';
222}
223else
224{
225     $line = '';
226     foreach ($counts as $k => $v)
227     {
228          $t = ($v == 1 )? __('%s post') : __('%s posts');
229          $line .= '<li>'.sprintf($t,$v).'&nbsp;'.sprintf(__('with type <strong>%s</strong>.'),$k).'</li>';
230     }
231     echo 
232     '<div class="col">'.
233     '<h3>'.__('Statistics').'</h3>'.
234     '<ul>'.$line.'</ul>'.
235     '</div>';
236}
237
238?>
239</body>
240</html>
Note: See TracBrowser for help on using the repository browser.

Sites map