Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezmodulehandler.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezmodulehandler.php 9798 2003-04-09 13:09:07Z jhe $
5 //
6 // Definition of eZModuleHandler class
7 //
8 // Created on: <18-Apr-2001 13:23:01 amos>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
55 // include_once( "ezsession/classes/ezpreferences.php" );
56 // include_once( "ezuser/classes/ezpermission.php" );
57
58 class eZModuleHandler
59 {
60
65 static public function activeTab()
66 {
67 $preferences = new eZPreferences();
68 $module_tab = eZModuleHandler::hasTab();
69 $user_module_tab = $preferences->variable( "ModuleTab" );
70 if ( $module_tab and !is_bool( $user_module_tab ) )
71 {
72 $module_tab = $user_module_tab == "enabled";
73 }
74 return $module_tab;
75 }
76
81 static public function hasTab()
82 {
83 $ini =& eZINI::instance( 'site.ini' );
84 $module_tab = $ini->variable( "site", "ModuleTab" ) == "enabled";
85 return $module_tab;
86 }
87
92 static public function setActiveTab( $active )
93 {
94 $preferences = new eZPreferences();
95 $preferences->setVariable( "ModuleTab", $active ? "enabled" : "disabled" );
96 }
97
102 static public function useSingleModule()
103 {
104 $preferences = new eZPreferences();
105 $single_module = $preferences->variable( "SingleModule" );
106 if ( !is_bool( $single_module ) )
107 {
108 $single_module = $single_module == "enabled";
109 }
110 else
111 {
112 $single_module = true;
113 }
114 return $single_module;
115 }
116
121 static public function all()
122 {
123 $return_array = array();
124 $ini =& eZINI::instance( 'site.ini' );
125 $allModules = explode(";", $ini->variable( "site", "EnabledModules" ) );
126 $user =& eZUser::currentUser();
127 foreach ( $allModules as $moduleItem )
128 {
129 if ( eZPermission::checkPermission( $user, $moduleItem, "ModuleEdit" ) )
130 $return_array[] = $moduleItem;
131 }
132 return $return_array;
133 }
134
139 static public function active()
140 {
141 $ini =& eZINI::instance( 'site.ini' );
142 $preferences = new eZPreferences();
143 if ( !eZModuleHandler::activeTab() )
144 {
145 $modules =& $preferences->variableArray( "EnabledModules" );
146 $site_modules =& eZModuleHandler::all();
147 if ( $modules )
148 {
149 $modules = array_intersect( $modules, $site_modules );
150 $extra_modules = array_diff( $site_modules, $modules );
151 $modules = array_merge( $modules, $extra_modules );
152 $modules = array_diff( $modules, array( "" ) );
153 }
154 else
155 {
156 $modules = array_diff( $site_modules, array( "" ) );
157 }
158 return $modules;
159 }
160 else
161 {
162 return $preferences->variableArray( "EnabledModules" );
163 }
164 }
165
170 static public function isOpen( $module )
171 {
172 $preferences = new eZPreferences();
173 $menuStatus =& $preferences->variable( strtolower( $module ) . "_status" );
174 return $menuStatus == "open" || empty( $menuStatus );
175 }
176
181 static public function setOpen( $module, $open = true )
182 {
183 $preferences = new eZPreferences();
184 $preferences->setVariable( strtolower( $module ) . "_status", $open ? "open" : "closed" );
185 }
186
193 static public function toggle( $module )
194 {
195 $preferences = new eZPreferences();
196 eZModuleHandler::setOpen( $module, !eZModuleHandler::isOpen( $module ) );
197 }
198
203 static public function setActive( $modules )
204 {
205 $preferences = new eZPreferences();
206 $preferences->setVariable( "EnabledModules", $modules );
207 }
208
214 static public function append( $modules, $module )
215 {
216 return array_unique( array_merge( $modules, array( $module ) ) );
217 }
218
224 static public function remove( $modules, $module )
225 {
226 return array_diff( $modules, array( $module ) );
227 }
228
235 static public function moveUp( &$modules, $module, &$moved_module )
236 {
237 $module = strtolower( $module );
238 reset( $modules );
239 $i = 0;
240 $moved_module = false;
241 foreach( $modules as $key => $module_name )
242 {
243 $module_low =& strtolower( $module_name );
244 if ( !empty( $module_name ) and $module == $module_low )
245 {
246 $pos = $i;
247 if ( $i > 0 )
248 {
249 $pos_above = $i - 1;
250 $module_above = $modules[$pos_above];
251 $modules[$pos_above] = $module_name;
252 $modules[$pos] = $module_above;
253 $moved_module = true;
254 break;
255 }
256 else
257 {
258 $module_item = array_shift( $modules );
259 $modules = array_merge( $modules, array( $module_item ) );
260 $moved_module = true;
261 break;
262 }
263 }
264 $i++;
265 }
266 }
267
274 static public function moveDown( &$modules, $module, &$moved_module )
275 {
276 $module = strtolower( $module );
277 reset( $modules );
278 $i = 0;
279 $moved_module = false;
280 foreach( $modules as $key => $module_name )
281 {
282 $module_low =& strtolower( $module_name );
283 if ( !empty( $module_name ) and $module == $module_low )
284 {
285 $pos = $i;
286 if ( $i < count( $modules ) - 1 )
287 {
288 $pos_below = $i + 1;
289 $module_below = $modules[$pos_below];
290 $modules[$pos_below] = $module_name;
291 $modules[$pos] = $module_below;
292 $moved_module = true;
293 break;
294 }
295 else
296 {
297 $module_item = array_pop( $modules );
298 $modules = array_merge( $modules, array( $module_item ) );
299 $moved_module = true;
300 break;
301 }
302 }
303 $i++;
304 }
305 }
306 }
307
308 ?>
$single_module
$single_module
Definition: activate.php:33
$i
$i
Definition: admin/adlist.php:91
$modules
foreach( $categories as $category) $modules
Definition: bugedit.php:496
eZModuleHandler
Definition: ezmodulehandler.php:59
eZModuleHandler\append
static append( $modules, $module)
Definition: ezmodulehandler.php:214
eZModuleHandler\useSingleModule
static useSingleModule()
Definition: ezmodulehandler.php:102
eZModuleHandler\moveDown
static moveDown(&$modules, $module, &$moved_module)
Definition: ezmodulehandler.php:274
eZModuleHandler\setActiveTab
static setActiveTab( $active)
Definition: ezmodulehandler.php:92
eZModuleHandler\toggle
static toggle( $module)
Definition: ezmodulehandler.php:193
eZModuleHandler\active
static active()
Definition: ezmodulehandler.php:139
eZModuleHandler\activeTab
static activeTab()
Definition: ezmodulehandler.php:65
eZModuleHandler\moveUp
static moveUp(&$modules, $module, &$moved_module)
Definition: ezmodulehandler.php:235
eZModuleHandler\all
static all()
Definition: ezmodulehandler.php:121
eZModuleHandler\setActive
static setActive( $modules)
Definition: ezmodulehandler.php:203
eZModuleHandler\setOpen
static setOpen( $module, $open=true)
Definition: ezmodulehandler.php:181
eZModuleHandler\hasTab
static hasTab()
Definition: ezmodulehandler.php:81
eZModuleHandler\isOpen
static isOpen( $module)
Definition: ezmodulehandler.php:170
eZPermission\checkPermission
static checkPermission( $user, $moduleName, $permissionName)
Definition: ezpermission.php:430
eZPreferences
Definition: ezpreferences.php:62
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$preferences
$preferences
Definition: classes/admin/linklist.php:186
$ini
$ini
Definition: classes/admin/linklist.php:64
$module
$module
Definition: classes/admin/linkselect.php:219
$module_tab
$module_tab
Definition: settings.php:41
$user
$user
Definition: user/adlist.php:39
$active
$active
Definition: user/pollist.php:57
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.