Dotclear

source: plugins/muppet/inc/class.setting.muppet.php @ 2313

Revision 2313, 2.7 KB checked in by Osku, 3 years ago (diff)

New plugin : muppet

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 ------------------------------------
13
14class muppet
15{
16     public static function setting()
17     {
18          global $core;
19          return muppetSettings($core);
20     }
21     
22     public static function getPostTypes()
23     {
24          $s = self::setting();
25          return @unserialize($s->muppet_types);
26     }
27
28     public static function getExcludePostTypes()
29     {
30          $s = self::setting();
31          return @unserialize($s->muppet_excludes);
32     }
33
34     public static function typeIsExcluded($type)
35     {
36          $s = self::setting();
37          $excluded = self::getExcludePostTypes();
38          if (array_key_exists($type,array_flip($excluded)))
39          {
40               return true;
41          }
42          else
43          {
44               return false;
45          }
46     }
47
48     public static function typeExists($type)
49     {
50          $s = self::setting();
51          $my_types = self::getPostTypes();
52          if (array_key_exists($type,$my_types))
53          {
54               return true;
55          }
56          else
57          {
58               return false;
59          }
60     }
61     
62     public static function setNewPostType($type,$values)
63     {
64          $s = self::setting();
65          $current_types = self::getPostTypes();
66          $current_types[$type] = array(
67               'name' => $values['name'],
68               'plural' => $values['plural'],
69               'icon' => $values['icon'],
70               'perm' => 'manage'.$type
71          );
72          $s->put('muppet_types',serialize($current_types),'string','My supplementary post types');
73     }
74     
75     public static function updateAllPostType($types)
76     {
77          $s = self::setting();
78          $current_types = array();
79         
80          foreach ($types as $k => $v)
81          {
82               if (!empty($v['name']))
83               {
84                    $current_types[$k] = array(
85                         'name' => $v['name'],
86                         'plural' => $v['plural'],
87                         'icon' => $v['icon'],
88                         'perm' => 'manage'.$k
89                    );
90               }
91          }
92         
93          $s->put('muppet_types',serialize($current_types),'string','My supplementary post types');
94     }
95
96
97     public static function removePostType($type)
98     {
99          global $core;
100          $s = muppetSettings($core);
101          $current_types = self::getPostTypes();
102          unset($current_types[$type]);
103          $s->put('muppet_types',serialize($current_types),'string','My supplementary post types');
104     }
105
106     public static function getInBasePostTypesCounter()
107     {
108          global $core;
109
110          $strReq =
111          'SELECT P.post_type, COUNT(P.post_id) AS nb_post '.
112          'FROM '.$core->prefix.'post P '.
113          "WHERE P.blog_id = '".$core->con->escape($core->blog->id)."' ".
114          'GROUP BY P.post_type ';
115
116          $rs = $core->con->select($strReq);
117          $counters = array();
118          while ($rs->fetch()) {
119               $counters[$rs->post_type] = $rs->nb_post;
120          }
121          return $counters;
122     }
123}
124?>
Note: See TracBrowser for help on using the repository browser.

Sites map