Dotclear

source: plugins/eventdata/class.eventdata.php @ 986

Revision 986, 4.3 KB checked in by JcDenis, 14 years ago (diff)

eventdata: fix language, add unlisted categories option

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of eventdata, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009 JC Denis and contributors
6# jcdenis@gdwd.com
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11# -- END LICENSE BLOCK ------------------------------------
12
13class eventdata Extends dcEvent
14{
15     protected $core;
16     public $url = '';
17     public $path = '';
18
19     protected $settings_available = array(
20          'event_option_active' => 'boolean',
21          'event_option_menu' => 'boolean',
22          'event_option_public' => 'boolean',
23          'event_perm_pst' => 'boolean',
24          'event_perm_cat' => 'boolean',
25          'event_perm_tpl' => 'boolean',
26          'event_perm_adm' => 'boolean',
27          'event_tpl_title' => 'string',
28          'event_tpl_desc' => 'string',
29          'event_tpl_url' => 'string',
30          'event_tpl_dis_bhv' => 'boolean',
31          'event_tpl_theme' => 'string',
32          'event_tpl_cats' => 'string',
33          'event_no_cats' => 'string'
34     );
35     protected $permissions_available = array(
36          'pst' => array('admin','admin,usage,contentadmin,eventdata'),
37          'cat' => array('admin','admin,categories,eventdata'),
38          'tpl' => array('admin','admin,eventdata'),
39          'adm' => array('admin','admin,eventdata')
40     );
41
42     public function __construct(&$core)
43     {
44          $this->core =& $core;
45          parent::__construct($core);
46
47          $this->url = 'plugin.php?p=eventdata';
48          $this->path = array_pop(explode(PATH_SEPARATOR, DC_PLUGINS_ROOT.'/eventdata'));
49
50          self::getSettings();
51     }
52
53     public function getSettings()
54     {
55          $this->S = new arrayObject();
56          foreach($this->settings_available AS $s => $t) {
57               $this->S->$s = $this->core->blog->settings->{$s};
58          }
59          return $this->S;
60     }
61
62     public function setSettings($args)
63     {
64          $done = 0;
65          $this->core->blog->settings->setNameSpace('eventdata');
66          foreach($args AS $k => $v) {
67               if (array_key_exists($k,$this->settings_available)) {
68                    $this->core->blog->settings->put($k,$v,$this->settings_available[$k]);
69                    $done = 1;
70               }
71          }
72          if ($done) {
73               $this->core->blog->triggerBlog();
74               self::getSettings();
75          }
76     }
77
78     public function checkPerm($name)
79     {
80          return isset($this->S->{'event_perm_'.$name}) && ($this->core->auth->check($this->permissions_available[$name][$this->S->{'event_perm_'.$name}],$this->core->blog->id)
81               || $this->core->auth->isSuperAdmin()) ? true : false;
82     }
83
84     public function getThemes($type='all')
85     {
86          $tpl = $thm = $tpl_dirs = array();
87
88          # Template
89          if ($type !='themes') {
90               $dir = $this->path.'/default-templates/';
91               if ($dir && is_dir($dir) && is_readable($dir)) {           
92                    $d = dir($dir);
93                    while (($f = $d->read()) !== false) {
94                         if (is_dir($dir.'/'.$f) && !preg_match('/^\./',$f)) {
95                              $tpl_dirs[] = $f;
96                         }
97                    }
98               }
99               foreach($tpl_dirs AS $v) {
100                    $k = str_replace('eventdata-','',$v);
101                    $tpl[$k] = array(
102                         'name' => $k,
103                         'template_exists' => true,
104                         'template_file' => (file_exists($dir.$v.'/events.html') ? 
105                              $dir.$v.'/events.html' : ''),
106                         'theme_exists' => false,
107                         'theme_file' => '',
108                         'selected' => false
109                    );
110               }
111               if ($type == 'templates') return $tpl;
112          }
113          # Theme
114          if ($type !='templates') {
115               $themes = new dcThemes($this->core);
116               $themes->loadModules($this->core->blog->themes_path,null);
117               $tpl_thm = $themes->getModules();
118               foreach($tpl_thm AS $v => $p) {
119                    $thm[$v] = array(
120                         'name' => $p['name'],
121                         'template_exists' => false,
122                         'template_file' => '',
123                         'theme_exists' => true,
124                         'theme_file' => (file_exists($p['root'].'/tpl/events.html') ? 
125                              $p['root'].'/tpl/events.html' : ''),
126                         'selected' => $this->core->blog->settings->theme == $v ? true : false
127                    );
128               }
129               if ($type == 'themes') return $thm;
130          }
131          # All
132          if ($type !='templates' && $type != 'themes') {
133               foreach($thm AS $k => $v) {
134                    $tpl[$k] = array(
135                         'name' => $v['name'],
136                         'template_exists' => isset($tpl[$k]['template_exists']) ? $tpl[$k]['template_exists'] : '',
137                         'template_file' => isset($tpl[$k]['template_file']) ? $tpl[$k]['template_file'] : '',
138                         'theme_exists' => $v['theme_exists'],
139                         'theme_file' => $v['theme_file'],
140                         'selected' => $v['selected']);
141               }
142               return $tpl;
143          }
144          return null;
145     }
146}
147
148?>
Note: See TracBrowser for help on using the repository browser.

Sites map