Dotclear

source: plugins/muppet/_admin.php @ 2485

Revision 2485, 3.5 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
17if (!empty($my_types))
18{
19     $_menu['Muppet'] = new dcMenu('muppet-menu',__('Content'));
20     foreach ($my_types as $k => $v)
21     {
22          $plural = empty($v['plural']) ? $v['name'].'s' : $v['plural'];
23          $pattern = '/p=muppet&type='.$k.'.*?$/';
24          $_menu['Muppet']->addItem(ucfirst($plural),
25                    'plugin.php?p=muppet&amp;type='.$k.'&amp;list=all',
26                    'index.php?pf=muppet/img/'.$v['icon'],
27                    preg_match($pattern,$_SERVER['REQUEST_URI']),
28                    $core->auth->check('contentadmin,'.$v['perm'],$core->blog->id));
29          $core->auth->setPermissionType($v['perm'],sprintf(__('manage the %s'),$plural));
30     }
31     $core->addBehavior('adminPageHTMLHead',array('muppetBehaviors','adminPageHTMLHead'));
32}
33$core->addBehavior('adminPostsActionsCombo',array('muppetBehaviors','adminPostsActionsCombo'));
34$core->addBehavior('adminPostsActions',array('muppetBehaviors','adminPostsActions'));
35$core->addBehavior('adminPostsActionsContent',array('muppetBehaviors','adminPostsActionsContent'));
36
37$_menu['Plugins']->addItem(__('My types'),'plugin.php?p=muppet','index.php?pf=muppet/icon.png',
38          (preg_match('/plugin.php\?p=muppet(&.*)?/',$_SERVER['REQUEST_URI']))
39          && (!preg_match('/type/',$_SERVER['REQUEST_URI'])),
40          $core->auth->check('contentadmin',$core->blog->id));
41
42class muppetBehaviors
43{
44     public static function adminPostsActionsCombo($args)
45     {
46          global $core;
47          if ($core->auth->check('admin',$core->blog->id)) {
48               $args[0][__('Move')] = array(__('Change post type') => 'settype');
49          }
50     }
51     
52     public static function adminPostsActions($core,$posts,$action,$redir)
53     {
54          if ($action == 'settype' && isset($_POST['posttype']))
55          {
56               $newposttype = $_POST['posttype'];
57               try
58               {
59                    if ((!muppet::typeExists($newposttype)) && ($newposttype != 'post')) {
60                         throw new Exception(__('Something wrong happened...'));
61                    }
62               
63                    while ($posts->fetch())
64                    {
65                         $cur = $core->con->openCursor($core->prefix.'post');
66                         $cur->post_type = $newposttype;
67                         $cur->update('WHERE post_id = '.(integer) $posts->post_id);
68                    }
69               
70                    http::redirect($redir);
71               }
72               catch (Exception $e)
73               {
74                    $core->error->add($e->getMessage());
75               }
76          }
77     }
78     
79     public static function adminPostsActionsContent($core,$action,$hidden_fields)
80     {
81          if ($action == 'settype')
82          {
83               $default = array(__('Entry') => 'post');
84               $types = array();
85         
86               $ty = muppet::getPostTypes();
87               foreach ($ty as $k =>$v) {
88                    $types= array_merge($types, array(ucfirst($v['name'])=> $k));
89               }
90
91               $types  = array_merge($default,$types);
92         
93               echo
94               '<h2>'.__('Select post type for these entries').'</h2>'.
95               '<form action="posts_actions.php" method="post">'.
96               '<p><label class="classic">'.__('Choose post type:').' '.
97               form::combo('posttype',$types).
98               '</label> '.
99         
100               $hidden_fields.
101               $core->formNonce().
102               form::hidden(array('action'),'settype').
103               '<input type="submit" value="'.__('save').'" /></p>'.
104               '</form>';
105          }
106     }
107
108     public static function adminPageHTMLHead()
109     {
110          echo '<script type="text/javascript" src="index.php?pf=muppet/js/menu.js"></script>';
111     }
112}
113?>
Note: See TracBrowser for help on using the repository browser.

Sites map