Dotclear

source: plugins/muppet/index.php @ 2485

Revision 2485, 7.0 KB checked in by Osku, 3 years ago (diff)

muppet - 0.6.1

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

Sites map