Dotclear

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

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

Sites map