| 1 |
<?php |
<?php |
| 2 |
/** |
/** |
| 3 |
* Component handler class |
* Some Components, Modules, Mambots and Templates classes |
| 4 |
* @package Mambo |
* @package Mambo |
| 5 |
|
* @copyright (C) 2005 - 2006 Mambo Foundation Inc. |
| 6 |
|
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL |
| 7 |
|
* @author Mambo Foundation Inc see README.php |
| 8 |
*/ |
*/ |
| 9 |
|
|
| 10 |
|
/** |
| 11 |
|
* Singleton class to handle with current component |
| 12 |
|
* |
| 13 |
|
* This class controls the start, end and send output buffer from current component |
| 14 |
|
* @package Mambo |
| 15 |
|
* @acces public |
| 16 |
|
*/ |
| 17 |
|
|
| 18 |
class mosComponentHandler { |
class mosComponentHandler { |
| 19 |
|
/** |
| 20 |
|
* stores the output from current component |
| 21 |
|
* |
| 22 |
|
* @acces private |
| 23 |
|
* @var string |
| 24 |
|
*/ |
| 25 |
var $_buffer = ''; |
var $_buffer = ''; |
| 26 |
|
/** |
| 27 |
|
* Return a reference to current handler |
| 28 |
|
* |
| 29 |
|
* This function returns a reference to current component handler, if none handler exists, |
| 30 |
|
* it creates one. |
| 31 |
|
* |
| 32 |
|
* Example of use: |
| 33 |
|
* |
| 34 |
|
* <code>$c_handler =& mosComponentHandler::getInstance();</code> |
| 35 |
|
* |
| 36 |
|
* @acces public |
| 37 |
|
* @return object reference to current singleton Handler |
| 38 |
|
*/ |
| 39 |
function &getInstance () { |
function &getInstance () { |
| 40 |
static $instance; |
static $instance; |
| 41 |
if (!is_object($instance)) $instance = new mosComponentHandler(); |
if (!is_object($instance)) $instance = new mosComponentHandler(); |
| 42 |
return $instance; |
return $instance; |
| 43 |
} |
} |
| 44 |
|
|
| 45 |
|
/** |
| 46 |
|
* Returns the admin parameters from a component |
| 47 |
|
* |
| 48 |
|
* This function returns a reference to specified component in $name param, if none parameters |
| 49 |
|
* are founded it returns null. |
| 50 |
|
* |
| 51 |
|
* @acces public |
| 52 |
|
* @return object mosParameters object with parameters, null if none was founded. |
| 53 |
|
*/ |
| 54 |
function &getParamsByName ($name) { |
function &getParamsByName ($name) { |
| 55 |
$params = null; |
$params = null; |
| 56 |
$row = new mosComponent(); |
$row = new mosComponent(); |
| 69 |
return $params; |
return $params; |
| 70 |
} |
} |
| 71 |
|
|
| 72 |
|
/** |
| 73 |
|
* Writes the output from current component |
| 74 |
|
* |
| 75 |
|
* This function send to client browser the outputs from the component, it's |
| 76 |
|
* called by mosMainBody() global function. |
| 77 |
|
* |
| 78 |
|
* @acces private |
| 79 |
|
*/ |
| 80 |
function mosMainBody() { |
function mosMainBody() { |
| 81 |
// message passed via the url |
// message passed via the url |
| 82 |
$mosmsg = mosGetParam($_REQUEST, 'mosmsg', ''); |
$mosmsg = mosGetParam($_REQUEST, 'mosmsg', ''); |
| 89 |
// echo "\n<script language=\"javascript\">alert('$mosmsg');</script>"; |
// echo "\n<script language=\"javascript\">alert('$mosmsg');</script>"; |
| 90 |
} |
} |
| 91 |
|
|
| 92 |
|
/** |
| 93 |
|
* Start the use of buffer |
| 94 |
|
* |
| 95 |
|
* This function start the use of buffers to components output |
| 96 |
|
* |
| 97 |
|
* @acces private |
| 98 |
|
*/ |
| 99 |
function startBuffer () { |
function startBuffer () { |
| 100 |
$this->_buffer = ''; |
$this->_buffer = ''; |
| 101 |
ob_start(); |
ob_start(); |
| 102 |
} |
} |
| 103 |
|
|
| 104 |
|
/** |
| 105 |
|
* Ends the use of buffer |
| 106 |
|
* |
| 107 |
|
* This function ends the use of buffers to components output, all outputs |
| 108 |
|
* are stored in $this->_buffer |
| 109 |
|
* |
| 110 |
|
* @acces private |
| 111 |
|
*/ |
| 112 |
function endBuffer () { |
function endBuffer () { |
| 113 |
$this->_buffer = ob_get_contents(); |
$this->_buffer = ob_get_contents(); |
| 114 |
ob_end_clean(); |
ob_end_clean(); |
| 115 |
} |
} |
| 116 |
|
|
| 117 |
} |
} |
| 118 |
|
|
| 119 |
/** |
/** |
| 120 |
* Component database table class |
* Components database table class |
| 121 |
|
* |
| 122 |
|
* This class can be used to gain access to #_components database table |
| 123 |
|
* |
| 124 |
* @package Mambo |
* @package Mambo |
| 125 |
|
* @access public |
| 126 |
*/ |
*/ |
| 127 |
class mosComponent extends mosDBTable { |
class mosComponent extends mosDBTable { |
| 128 |
/** @var int Primary key */ |
/** @var int Primary key */ |
| 129 |
var $id=null; |
var $id=null; |
| 130 |
/** @var string */ |
/** @var string component name*/ |
| 131 |
var $name=null; |
var $name=null; |
| 132 |
/** @var string */ |
/** @var string component link*/ |
| 133 |
var $link=null; |
var $link=null; |
| 134 |
/** @var int */ |
/** @var int menu id*/ |
| 135 |
var $menuid=null; |
var $menuid=null; |
| 136 |
/** @var int */ |
/** @var int parent menu*/ |
| 137 |
var $parent=null; |
var $parent=null; |
| 138 |
/** @var string */ |
/** @var string component admin link*/ |
| 139 |
var $admin_menu_link=null; |
var $admin_menu_link=null; |
| 140 |
/** @var string */ |
/** @var string alternative text for admin menu*/ |
| 141 |
var $admin_menu_alt=null; |
var $admin_menu_alt=null; |
| 142 |
/** @var string */ |
/** @var string component option id*/ |
| 143 |
var $option=null; |
var $option=null; |
| 144 |
/** @var string */ |
/** @var string order*/ |
| 145 |
var $ordering=null; |
var $ordering=null; |
| 146 |
/** @var string */ |
/** @var string image from admin menu*/ |
| 147 |
var $admin_menu_img=null; |
var $admin_menu_img=null; |
| 148 |
/** @var int */ |
/** @var int 1 core component ,0 others */ |
| 149 |
var $iscore=null; |
var $iscore=null; |
| 150 |
/** @var string */ |
/** @var string component parameters*/ |
| 151 |
var $params=null; |
var $params=null; |
| 152 |
|
|
| 153 |
/** |
/** |
| 154 |
* @param database A database connector object |
* mosComponent class Contructor |
| 155 |
|
* @access private |
| 156 |
*/ |
*/ |
| 157 |
function mosComponent() { |
function mosComponent() { |
| 158 |
$db = mamboDatabase::getInstance(); |
$db = mamboDatabase::getInstance(); |
| 159 |
$this->mosDBTable( '#__components', 'id', $db ); |
$this->mosDBTable( '#__components', 'id', $db ); |
| 160 |
} |
} |
| 161 |
} |
} |
| 162 |
|
|
| 163 |
/** |
/** |
| 164 |
* Component common base class for both user and admin sides |
* Abstract component common base class for both user and admin sides |
| 165 |
|
* |
| 166 |
|
* Since 4.6 version a new way to develop components based in MVC pattern was included, |
| 167 |
|
* this requires that each component should to create a instance from mosComponentUserManager |
| 168 |
|
* to user(frontend) side and a instance from mosComponentAdminManager to admin(backend) side, |
| 169 |
|
* both classes are derived from this abstract class |
| 170 |
|
* |
| 171 |
* @package Mambo |
* @package Mambo |
| 172 |
|
* @access public |
| 173 |
*/ |
*/ |
| 174 |
class mosComponentManager { |
class mosComponentManager { |
| 175 |
|
/** @var string component name */ |
| 176 |
var $plugin_name = ''; |
var $plugin_name = ''; |
| 177 |
var $magic_quotes_value = 0; |
var $magic_quotes_value = 0; |
| 178 |
|
/** @var int current magic quotes value, used to restore it */ |
| 179 |
|
var $magic_quotes_restore = ''; |
| 180 |
|
/** @var string component version*/ |
| 181 |
|
var $plugin_version = ''; |
| 182 |
|
/** @var string option from URL*/ |
| 183 |
|
var $option = ''; |
| 184 |
|
|
| 185 |
|
/** |
| 186 |
|
* mosComponentManager Class contructor |
| 187 |
|
* |
| 188 |
|
* This constructor initiates all necessary members, clear all magic quotes if |
| 189 |
|
* is present and load the language from component |
| 190 |
|
* |
| 191 |
|
* @access private |
| 192 |
|
* @param string component name |
| 193 |
|
* @param string component version |
| 194 |
|
*/ |
| 195 |
|
function mosComponentManager ($component_name, $version) { |
| 196 |
|
$this->text_name = $component_name; |
| 197 |
|
$this->plugin_name = strtolower(str_replace(' ', '', $component_name)); |
| 198 |
|
$this->plugin_version = $version; |
| 199 |
|
$this->option = mamboCore::get('option'); |
| 200 |
|
$this->magic_quotes_restore = get_magic_quotes_runtime(); |
| 201 |
|
$this->noMagicQuotes(); |
| 202 |
|
$cname = 'com_'.$this->plugin_name; |
| 203 |
|
$mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path'); |
| 204 |
|
if(file_exists($mosConfig_absolute_path."/components/$cname/language/".mamboCore::get('mosConfig_lang').'.php')) require_once($mosConfig_absolute_path."/components/$cname/language/".mamboCore::get('mosConfig_lang').'.php'); |
| 205 |
|
else if (file_exists($mosConfig_absolute_path."/components/$cname/language/english.php")) require_once($mosConfig_absolute_path."/components/$cname/language/english.php"); |
| 206 |
|
|
| 207 |
|
} |
| 208 |
|
|
| 209 |
|
/** |
| 210 |
|
* remove magic quotes from Superglobals arrays |
| 211 |
|
* |
| 212 |
|
* This function removes the magic quotes if is present in $_REQUEST, $_GET |
| 213 |
|
* and $_POST arrays |
| 214 |
|
* |
| 215 |
|
* @access private |
| 216 |
|
*/ |
| 217 |
function noMagicQuotes () { |
function noMagicQuotes () { |
| 218 |
// Is magic quotes on? |
// Is magic quotes on? |
| 219 |
if (get_magic_quotes_gpc()) { |
if (get_magic_quotes_gpc()) { |
| 222 |
$_GET =& $this->remove_magic_quotes($_GET); |
$_GET =& $this->remove_magic_quotes($_GET); |
| 223 |
$_POST =& $this->remove_magic_quotes($_POST); |
$_POST =& $this->remove_magic_quotes($_POST); |
| 224 |
} |
} |
| 225 |
$this->magic_quotes_value = set_magic_quotes_runtime(0); |
set_magic_quotes_runtime(0); |
| 226 |
|
$this->magic_quotes_value = 0; |
| 227 |
} |
} |
| 228 |
|
|
| 229 |
|
/** |
| 230 |
|
* remove magic quotes and slashes from a array |
| 231 |
|
* |
| 232 |
|
* This function removes the magic quotes if is present in passed array |
| 233 |
|
* |
| 234 |
|
* @access private |
| 235 |
|
* @param array array to strip quotes and slashes |
| 236 |
|
* @return array reference to converted array |
| 237 |
|
*/ |
| 238 |
function &remove_magic_quotes ($array) { |
function &remove_magic_quotes ($array) { |
| 239 |
foreach ($array as $k => $v) { |
foreach ($array as $k => $v) { |
| 240 |
if (is_array($v)) $array[$k] = $this->remove_magic_quotes($v); |
if (is_array($v)) $array[$k] = $this->remove_magic_quotes($v); |
| 243 |
return $array; |
return $array; |
| 244 |
} |
} |
| 245 |
|
|
| 246 |
|
/** |
| 247 |
|
* restore magic quotes from old value |
| 248 |
|
* |
| 249 |
|
* This function restore the old value of magic_quotes_runtime |
| 250 |
|
* |
| 251 |
|
* @access private |
| 252 |
|
*/ |
| 253 |
function restore_magic_quotes () { |
function restore_magic_quotes () { |
| 254 |
set_magic_quotes_runtime($this->magic_quotes_value); |
set_magic_quotes_runtime($this->magic_quotes_restore); |
| 255 |
} |
} |
| 256 |
|
|
| 257 |
|
/** |
| 258 |
|
* checks for a method in a class |
| 259 |
|
* |
| 260 |
|
* This function returns TRUE when $method is a member of $object |
| 261 |
|
* |
| 262 |
|
* @access public |
| 263 |
|
* @param object Reference to the object |
| 264 |
|
* @param string method name that is looking for |
| 265 |
|
* @return bool TRUE when $method exits |
| 266 |
|
*/ |
| 267 |
function checkCallable (&$object, $method) { |
function checkCallable (&$object, $method) { |
| 268 |
if (is_callable(array(&$object, $method))) return true; |
if (is_callable(array(&$object, $method))) return true; |
| 269 |
$name = get_class($object); |
$name = get_class($object); |
| 272 |
} |
} |
| 273 |
|
|
| 274 |
} |
} |
| 275 |
|
|
| 276 |
/** |
/** |
| 277 |
* Component base logic for user side |
* Component base controller for user(frontend) side |
| 278 |
|
* |
| 279 |
|
* Since 4.6 version a new way to develop components based in MVC pattern was included, |
| 280 |
|
* this requires that each component should to create a instance from mosComponentUserManager |
| 281 |
|
* to user(frontend) side. |
| 282 |
|
* |
| 283 |
* @package Mambo |
* @package Mambo |
| 284 |
|
* @access public |
| 285 |
*/ |
*/ |
| 286 |
class mosComponentUserManager extends mosComponentManager { |
class mosComponentUserManager extends mosComponentManager { |
|
var $option = ''; |
|
| 287 |
|
|
| 288 |
function mosComponentUserManager ($component, $control_name, $alternatives, $default, $title) { |
/** |
| 289 |
$this->plugin_name = $component; |
* mosComponentUserManager Class contructor |
| 290 |
$this->option = mamboCore::get('option'); |
* |
| 291 |
$this->noMagicQuotes(); |
* This constructor initiates all necessary members, sets the title to browser, |
| 292 |
|
* creates a new instance of the correct class and calls the action to do, finally |
| 293 |
|
* restore the magic quotes to it initial state |
| 294 |
|
* |
| 295 |
|
* @access private |
| 296 |
|
* @param string component name |
| 297 |
|
* @param string variable used as control |
| 298 |
|
* @param array array whin alternavite names to actions methods |
| 299 |
|
* @param string default action to do |
| 300 |
|
* @param string browser title to show when the component is in use |
| 301 |
|
* @param string component version |
| 302 |
|
*/ |
| 303 |
|
function mosComponentUserManager ($component_name, $control_name, $alternatives, $default, $title, $version) { |
| 304 |
|
mosComponentManager::mosComponentManager($component_name, $version); |
| 305 |
$mainframe =& mosMainFrame::getInstance(); |
$mainframe =& mosMainFrame::getInstance(); |
| 306 |
$mainframe->SetPageTitle($title); |
$mainframe->SetPageTitle($title); |
| 307 |
$func = mosGetParam ($_REQUEST, $control_name, $default); |
$func = mosGetParam ($_REQUEST, $control_name, $default); |
| 308 |
if (isset($alternatives[$func])) $method = $alternatives[$func]; |
if (isset($alternatives[$func])) $method = $alternatives[$func]; |
| 309 |
else $method = $func; |
else $method = $func; |
| 310 |
$classname = $component.'_'.$method.'_Controller'; |
$classname = $this->plugin_name.'_'.$method.'_Controller'; |
| 311 |
if (class_exists($classname)) { |
if (class_exists($classname)) { |
| 312 |
$controller =& new $classname($this); |
$controller =& new $classname($this); |
| 313 |
if (is_callable(array(&$controller,$method))) $controller->$method($func); |
if (is_callable(array(&$controller,$method))) $controller->$method($func); |
| 314 |
else trigger_error (sprintf(T_('Component %s error: attempt to use non-existent method %s in %s'), $component, $method, $controller)); |
else trigger_error (sprintf(T_('Component %s error: attempt to use non-existent method %s in %s'), $this->plugin_name, $method, $controller)); |
| 315 |
} |
} |
| 316 |
else trigger_error("Component $component error: attempt to use non-existent class $classname"); |
else trigger_error(sprintf(T_('Component %s error: attempt to use non-existent class %s'), $this->plugin_name, $classname)); |
| 317 |
$this->restore_magic_quotes(); |
$this->restore_magic_quotes(); |
| 318 |
} |
} |
| 319 |
|
|
| 320 |
|
/** |
| 321 |
|
* Loads and returns a class for render HTML (view Object) |
| 322 |
|
* |
| 323 |
|
* This function load a class for view html an associated controller is passed |
| 324 |
|
* |
| 325 |
|
* @access public |
| 326 |
|
* @param string HTML view class name |
| 327 |
|
* @param object reference to controller object |
| 328 |
|
* @param int not used |
| 329 |
|
* @param int list of items to show |
| 330 |
|
* @return mixed a instance to the HTML class, FALSE if the class is not founded |
| 331 |
|
*/ |
| 332 |
function newHTMLClassCheck ($name, &$controller, $total_items, $clist) { |
function newHTMLClassCheck ($name, &$controller, $total_items, $clist) { |
| 333 |
if (class_exists($name)) return new $name ($controller, $this->limit, $clist); |
if (class_exists($name)) return new $name ($controller, $this->limit, $clist); |
| 334 |
trigger_error("Component $this->plugin_name error: attempt to use non-existent class ".$name); |
trigger_error(sprintf(T_('Component %s error: attempt to use non-existent class %s'), $this->plugin_name, $name)); |
| 335 |
return false; |
return false; |
| 336 |
} |
} |
| 337 |
|
|
| 338 |
} |
} |
| 339 |
|
|
| 340 |
/** |
/** |
| 341 |
* Component base logic for admin side |
* Component base controller for admin side |
| 342 |
|
* |
| 343 |
|
* Since 4.6 version a new way to develop components based in MVC pattern was included, |
| 344 |
|
* this requires that each component should to create a instance from mosComponentAdminManager |
| 345 |
|
* to admin(backend) side. |
| 346 |
|
* |
| 347 |
* @package Mambo |
* @package Mambo |
| 348 |
|
* @access public |
| 349 |
*/ |
*/ |
| 350 |
class mosComponentAdminManager extends mosComponentManager { |
class mosComponentAdminManager extends mosComponentManager { |
| 351 |
|
/** @var string action executed */ |
| 352 |
var $act = ''; |
var $act = ''; |
| 353 |
|
/** @var string task executed */ |
| 354 |
var $task = ''; |
var $task = ''; |
| 355 |
|
/** @var int init offset to admin list*/ |
| 356 |
var $limitstart = 0; |
var $limitstart = 0; |
| 357 |
|
/** @var int quantity of elements to show in list*/ |
| 358 |
var $limit = 0; |
var $limit = 0; |
| 359 |
|
/** @var mixed id or id's of selected objects in admin list */ |
| 360 |
var $cfid = 0; |
var $cfid = 0; |
| 361 |
|
/** @var array order positions for all items */ |
| 362 |
var $order = 0; |
var $order = 0; |
| 363 |
|
/** @var int first element of cfid */ |
| 364 |
var $currid = 0; |
var $currid = 0; |
| 365 |
|
|
| 366 |
function mosComponentAdminManager ($plugin_name) { |
/** |
| 367 |
$this->plugin_name = $plugin_name; |
* mosComponentAdminManager Class contructor |
| 368 |
$this->noMagicQuotes(); |
* |
| 369 |
if ($this->act = mosGetParam ($_REQUEST, 'act', strtolower(str_replace(' ', '_', $plugin_name)))); |
* This constructor initiates all necessary members with values passed trought REQUEST |
| 370 |
if ($this->task = mosGetParam($_REQUEST, 'task', 'list')); |
* creates a new instance of the correct class and calls the task to do, finally |
| 371 |
else $this->task = 'list'; |
* restore the magic quotes to it initial state. |
| 372 |
|
* |
| 373 |
|
* @param string component name |
| 374 |
|
* @param string component version |
| 375 |
|
* @access private |
| 376 |
|
*/ |
| 377 |
|
function mosComponentAdminManager ($component_name, $version) { |
| 378 |
|
mosComponentManager::mosComponentManager($component_name, $version); |
| 379 |
|
$this->act = mosGetParam ($_REQUEST, 'act', $this->plugin_name); |
| 380 |
|
$this->task = mosGetParam($_REQUEST, 'task', 'list'); |
| 381 |
$mainframe = mosMainFrame::getInstance(); |
$mainframe = mosMainFrame::getInstance(); |
| 382 |
$default_limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', 20 ); |
$default_limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', 20 ); |
| 383 |
$this->limit = intval( mosGetParam( $_REQUEST, 'limit', $default_limit ) ); |
$this->limit = intval( mosGetParam( $_REQUEST, 'limit', $default_limit ) ); |
| 399 |
$this->restore_magic_quotes(); |
$this->restore_magic_quotes(); |
| 400 |
} |
} |
| 401 |
|
|
| 402 |
|
/** |
| 403 |
|
* Checks that at least one item selected |
| 404 |
|
* |
| 405 |
|
* @param string alert message |
| 406 |
|
* @access public |
| 407 |
|
*/ |
| 408 |
function check_selection ($text) { |
function check_selection ($text) { |
| 409 |
if (!is_array($this->cfid) OR count( $this->cfid ) < 1) { |
if (!is_array($this->cfid) OR count( $this->cfid ) < 1) { |
| 410 |
echo "<script> alert('".$text."'); window.history.go(-1);</script>\n"; |
echo "<script> alert('".$text."'); window.history.go(-1);</script>\n"; |
| 412 |
} |
} |
| 413 |
} |
} |
| 414 |
|
|
| 415 |
|
/** |
| 416 |
|
* returns the class name from the current action |
| 417 |
|
* |
| 418 |
|
* @return string class name from the current action |
| 419 |
|
* @access public |
| 420 |
|
*/ |
| 421 |
function getAction () { |
function getAction () { |
| 422 |
$actname = strtoupper(substr($this->act,0,1)).strtolower(substr($this->act,1)); |
$actname = strtoupper(substr($this->act,0,1)).strtolower(substr($this->act,1)); |
| 423 |
return strtolower($this->plugin_name).'Admin'.$actname; |
return strtolower($this->plugin_name).'Admin'.$actname; |
| 424 |
} |
} |
| 425 |
|
|
| 426 |
|
/** |
| 427 |
|
* Loads and returns a class for render HTML (view Object) |
| 428 |
|
* |
| 429 |
|
* This function load a class for view html an associated controller is passed |
| 430 |
|
* |
| 431 |
|
* @access public |
| 432 |
|
* @param string HTML view class name |
| 433 |
|
* @param object reference to controller object |
| 434 |
|
* @param int |
| 435 |
|
* @param int list of items to show |
| 436 |
|
* @return mixed a instance to the HTML class, FALSE if the class is not founded |
| 437 |
|
*/ |
| 438 |
function newHTMLClassCheck ($name, &$controller, $total_items, $clist) { |
function newHTMLClassCheck ($name, &$controller, $total_items, $clist) { |
| 439 |
$controller->makePageNav($this, $total_items); |
$controller->makePageNav($this, $total_items); |
| 440 |
if (class_exists($name)) return new $name ($controller, $this->limit, $clist); |
if (class_exists($name)) return new $name ($controller, $this->limit, $clist); |
| 443 |
} |
} |
| 444 |
|
|
| 445 |
} |
} |
| 446 |
|
|
| 447 |
/** |
/** |
| 448 |
* Component base class for admin side component controller logic |
* Abstract component base class for admin side component controller logic (not used yet) |
| 449 |
|
* |
| 450 |
* @package Mambo |
* @package Mambo |
| 451 |
|
* @access public |
| 452 |
|
* @todo This class is not used yet |
| 453 |
*/ |
*/ |
| 454 |
class mosComponentAdminControllers { |
class mosComponentAdminControllers { |
| 455 |
|
/** @var string action executed */ |
| 456 |
var $admin = ''; |
var $admin = ''; |
| 457 |
|
/** @var string curren user */ |
| 458 |
var $user = ''; |
var $user = ''; |
| 459 |
|
/** @var object Page navigation Object */ |
| 460 |
var $pageNav = ''; |
var $pageNav = ''; |
| 461 |
|
/** @var string curren root path */ |
| 462 |
|
var $rootPath = ''; |
| 463 |
|
/** @var string curren language */ |
| 464 |
|
var $language = ''; |
| 465 |
|
|
| 466 |
|
/** |
| 467 |
|
* mosComponentAdminControllers Class contructor |
| 468 |
|
* |
| 469 |
|
* @param object $admin |
| 470 |
|
* @access private |
| 471 |
|
*/ |
| 472 |
function mosComponentAdminControllers ($admin) { |
function mosComponentAdminControllers ($admin) { |
| 473 |
$this->admin = $admin; |
$this->admin = $admin; |
| 474 |
$this->user = mamboCore::get('currentUser'); |
$this->user = mamboCore::get('currentUser'); |
| 475 |
|
$this->rootPath = mamboCore::get('mosConfig_absolute_path'); |
| 476 |
|
$this->language = mamboCore::get('mosConfig_lang'); |
| 477 |
} |
} |
| 478 |
|
|
| 479 |
|
/** |
| 480 |
|
* Creates a mosPageNav object |
| 481 |
|
* |
| 482 |
|
* @param object component name |
| 483 |
|
* @param int not used |
| 484 |
|
* @access public |
| 485 |
|
*/ |
| 486 |
function makePageNav (&$admin, $total) { |
function makePageNav (&$admin, $total) { |
| 487 |
require_once(mamboCore::get('mosConfig_absolute_path').'/administrator/includes/pageNavigation.php'); |
require_once(mamboCore::get('mosConfig_absolute_path').'/administrator/includes/pageNavigation.php'); |
| 488 |
$this->pageNav =& new mosPageNav( $total, $admin->limitstart, $admin->limit ); |
$this->pageNav =& new mosPageNav( $total, $admin->limitstart, $admin->limit ); |
| 491 |
} |
} |
| 492 |
|
|
| 493 |
/** |
/** |
| 494 |
* Template Table Class |
* Template database table class |
| 495 |
|
* |
| 496 |
|
* This class can be used to gain access to #_templates database table |
| 497 |
* |
* |
|
* Provides access to the mos_templates table |
|
| 498 |
* @package Mambo |
* @package Mambo |
| 499 |
|
* @access public |
| 500 |
|
* @todo This class is not used yet |
| 501 |
*/ |
*/ |
| 502 |
|
|
| 503 |
class mosTemplate extends mosDBTable { |
class mosTemplate extends mosDBTable { |
| 504 |
/** @var int */ |
/** @var int table primary key */ |
| 505 |
var $id=null; |
var $id=null; |
| 506 |
/** @var string */ |
/** @var string is act*/ |
| 507 |
var $cur_template=null; |
var $cur_template=null; |
| 508 |
/** @var int */ |
/** @var int */ |
| 509 |
var $col_main=null; |
var $col_main=null; |
| 510 |
|
|
| 511 |
/** |
/** |
| 512 |
* @param database A database connector object |
* mosTemplate Class contructor |
| 513 |
|
* |
| 514 |
|
* Init a mosDBTable object. |
| 515 |
|
* |
| 516 |
|
* @param object &$database reference to current database object |
| 517 |
|
* @access private |
| 518 |
*/ |
*/ |
| 519 |
function mosTemplate( &$database ) { |
function mosTemplate( &$database ) { |
| 520 |
$this->mosDBTable( '#__templates', 'id', $database ); |
$this->mosDBTable( '#__templates', 'id', $database ); |
| 522 |
} |
} |
| 523 |
|
|
| 524 |
/** |
/** |
| 525 |
* Class mosMambot |
* Mambot database table class |
| 526 |
|
* |
| 527 |
|
* This class can be used to gain access to #_mambots database table |
| 528 |
|
* |
| 529 |
* @package Mambo |
* @package Mambo |
| 530 |
|
* @access public |
| 531 |
*/ |
*/ |
| 532 |
class mosMambot extends mosDBTable { |
class mosMambot extends mosDBTable { |
| 533 |
/** @var int */ |
/** @var int table primary key */ |
| 534 |
var $id=null; |
var $id=null; |
| 535 |
/** @var varchar */ |
/** @var string mambot name */ |
| 536 |
var $name=null; |
var $name=null; |
| 537 |
/** @var varchar */ |
/** @var string element name */ |
| 538 |
var $element=null; |
var $element=null; |
| 539 |
/** @var varchar */ |
/** @var string mambot kind */ |
| 540 |
var $folder=null; |
var $folder=null; |
| 541 |
/** @var tinyint unsigned */ |
/** @var int access level 0 public, 1 registered, 2 special */ |
| 542 |
var $access=null; |
var $access=null; |
| 543 |
/** @var int */ |
/** @var int order lower first*/ |
| 544 |
var $ordering=null; |
var $ordering=null; |
| 545 |
/** @var tinyint */ |
/** @var int 1 published, 0 unpublished */ |
| 546 |
var $published=null; |
var $published=null; |
| 547 |
/** @var tinyint */ |
/** @var int 1 core mambots ,0 others */ |
| 548 |
var $iscore=null; |
var $iscore=null; |
| 549 |
/** @var tinyint */ |
/** @var int 1 admin mambot, 0 user mambot*/ |
| 550 |
var $client_id=null; |
var $client_id=null; |
| 551 |
/** @var int unsigned */ |
/** @var int id from the user that checkout, 0 checkin */ |
| 552 |
var $checked_out=null; |
var $checked_out=null; |
| 553 |
/** @var datetime */ |
/** @var datetime date and time from checkout*/ |
| 554 |
var $checked_out_time=null; |
var $checked_out_time=null; |
| 555 |
/** @var text */ |
/** @var string mambot parameters */ |
| 556 |
var $params=null; |
var $params=null; |
| 557 |
|
|
| 558 |
|
/** |
| 559 |
|
* mosMambot Class contructor |
| 560 |
|
* |
| 561 |
|
* Init a mosDBTable object. |
| 562 |
|
* |
| 563 |
|
* @param object reference to current database object |
| 564 |
|
* @access private |
| 565 |
|
*/ |
| 566 |
function mosMambot( &$db ) { |
function mosMambot( &$db ) { |
| 567 |
$this->mosDBTable( '#__mambots', 'id', $db ); |
$this->mosDBTable( '#__mambots', 'id', $db ); |
| 568 |
} |
} |
| 569 |
} |
} |
| 570 |
|
|
| 571 |
|
/** |
| 572 |
|
* Singleton class to handle with modules |
| 573 |
|
* |
| 574 |
|
* This class loads, counts and caches modules for both sides, user and admin |
| 575 |
|
* |
| 576 |
|
* @package Mambo |
| 577 |
|
* @acces public |
| 578 |
|
*/ |
| 579 |
class mosModuleHandler { |
class mosModuleHandler { |
| 580 |
|
/** |
| 581 |
|
* @var object current database object |
| 582 |
|
* @access private |
| 583 |
|
*/ |
| 584 |
var $_db = null; |
var $_db = null; |
| 585 |
|
/** |
| 586 |
|
* @var object modules cached |
| 587 |
|
* @access private |
| 588 |
|
*/ |
| 589 |
var $_modules = null; |
var $_modules = null; |
| 590 |
|
/** |
| 591 |
|
* @var array unpublished modules |
| 592 |
|
* @access private |
| 593 |
|
*/ |
| 594 |
|
var $_unpublished = null; |
| 595 |
|
/** |
| 596 |
|
* @var bool TRUE when admin modules are loaded |
| 597 |
|
* @access private |
| 598 |
|
*/ |
| 599 |
|
var $_isAdmin = null; |
| 600 |
|
|
| 601 |
|
/** |
| 602 |
|
* mosModuleHandler Class contructor |
| 603 |
|
* |
| 604 |
|
* Init the database object. |
| 605 |
|
* |
| 606 |
|
* @access private |
| 607 |
|
*/ |
| 608 |
function mosModuleHandler () { |
function mosModuleHandler () { |
| 609 |
$this->_db =& mamboDatabase::getInstance(); |
$this->_db =& mamboDatabase::getInstance(); |
| 610 |
} |
} |
| 611 |
|
|
| 612 |
|
/** |
| 613 |
|
* Returns a reference to current handler |
| 614 |
|
* |
| 615 |
|
* This function returns a reference to current modules handler, if none handler exists, |
| 616 |
|
* it creates one. |
| 617 |
|
* |
| 618 |
|
* @acces public |
| 619 |
|
* @return object reference to current singleton Handler |
| 620 |
|
*/ |
| 621 |
function &getInstance () { |
function &getInstance () { |
| 622 |
static $instance; |
static $instance; |
| 623 |
if (!is_object($instance)) $instance = new mosModuleHandler(); |
if (!is_object($instance)) $instance = new mosModuleHandler(); |
| 625 |
} |
} |
| 626 |
|
|
| 627 |
/** |
/** |
| 628 |
* Cache some modules information |
* Caches some modules information |
| 629 |
* @return array |
* |
| 630 |
|
* This function cache all modules, a $isAdmin bool value can be passed to select |
| 631 |
|
* the side (user/admin) by default user modules are loaded. |
| 632 |
|
* |
| 633 |
|
* @access private |
| 634 |
|
* @param bool TRUE when admin modules will loaded |
| 635 |
*/ |
*/ |
| 636 |
function initModules($isAdmin=false) { |
function initModules($isAdmin=false) { |
| 637 |
if (!isset($this->_modules)) { |
$my = mamboCore::get('currentUser'); |
| 638 |
|
if (!isset($this->_modules) OR $isAdmin != $this->_isAdmin) { |
| 639 |
|
$this->_isAdmin = $isAdmin; |
| 640 |
if ($isAdmin) { |
if ($isAdmin) { |
| 641 |
$query = "SELECT id, title, module, position, content, showtitle, params" |
$query = "SELECT id, title, module, position, content, showtitle, params, published" |
| 642 |
. "\n FROM #__modules AS m" |
. "\n FROM #__modules AS m" |
| 643 |
. "\n WHERE m.published = '1'" |
. "\n WHERE m.published = '1'" |
| 644 |
. "\n AND (m.client_id = 1)" |
. "\n AND (m.client_id = 1)" |
| 645 |
. "\n ORDER BY m.ordering"; |
. "\n ORDER BY m.ordering"; |
| 646 |
} |
} |
| 647 |
else { |
else { |
|
$my = mamboCore::get('currentUser'); |
|
| 648 |
$Itemid = mamboCore::get('Itemid'); |
$Itemid = mamboCore::get('Itemid'); |
| 649 |
$query = "SELECT id, title, module, position, content, showtitle, params" |
$query = "SELECT id, title, module, position, content, showtitle, params, published, m.access, m.groups" |
| 650 |
."\nFROM #__modules AS m, #__modules_menu AS mm" |
."\nFROM #__modules AS m, #__modules_menu AS mm" |
| 651 |
. "\nWHERE m.published='1' AND m.access <= '$my->gid' AND m.client_id='0'" |
. "\nWHERE m.access <= '$my->gid' AND m.client_id='0'" |
| 652 |
. "\nAND mm.moduleid=m.id" |
. "\nAND mm.moduleid=m.id" |
| 653 |
. "\nAND (mm.menuid = '$Itemid' OR mm.menuid = '0')" |
. "\nAND (mm.menuid = '$Itemid' OR mm.menuid = '0')" |
| 654 |
. "\nORDER BY ordering"; |
. "\nORDER BY ordering"; |
| 656 |
$this->_db->setQuery( $query ); |
$this->_db->setQuery( $query ); |
| 657 |
$modules = $this->_db->loadObjectList(); |
$modules = $this->_db->loadObjectList(); |
| 658 |
foreach ($modules as $module) { |
foreach ($modules as $module) { |
| 659 |
$this->_modules[$module->position][] = $module; |
if (!$isAdmin) $canAccess = $this->canAccess($module, $my->gid); |
| 660 |
|
else $canAccess = 1; |
| 661 |
|
if ($module->published == 1 && $canAccess == 1) $this->_modules[$module->position][] = $module; |
| 662 |
|
else $this->_unpublished[] = $module; |
| 663 |
} |
} |
| 664 |
} |
} |
| 665 |
} |
} |
| 666 |
/** |
/** |
| 667 |
* @param string THe template position |
* Returns the number of modules in a specified position, this method is called by |
| 668 |
|
* mosCountModules global function |
| 669 |
|
* |
| 670 |
|
* @access public |
| 671 |
|
* @param string The template position |
| 672 |
|
* @param bool TRUE when admin modules will loaded |
| 673 |
*/ |
*/ |
| 674 |
function mosCountModules( $position='left', $isAdmin=false ) { |
function mosCountModules( $position='left', $isAdmin=false ) { |
| 675 |
$this->initModules($isAdmin); |
$this->initModules($isAdmin); |
| 677 |
} |
} |
| 678 |
|
|
| 679 |
/** |
/** |
| 680 |
|
* Returns a array with modules that match whit $name, when $unpublished is TRUE |
| 681 |
|
* unpublished modules are returned too. |
| 682 |
|
* |
| 683 |
|
* @access public |
| 684 |
* @param string Name of module required |
* @param string Name of module required |
| 685 |
|
* @param bool TRUE when admin modules will loaded |
| 686 |
|
* @param bool TRUE whish to include unpublished modules too |
| 687 |
|
* @return array array with all modules that match |
| 688 |
*/ |
*/ |
| 689 |
function &getByName( $name, $isAdmin=false ) { |
function &getByName( $name, $isAdmin=false, $unpublished=false ) { |
| 690 |
$this->initModules($isAdmin); |
$this->initModules($isAdmin); |
| 691 |
$modules = array(); |
$modules = array(); |
| 692 |
foreach ($this->_modules as $position) { |
foreach ($this->_modules as $position) { |
| 693 |
foreach ($position as $module) if ($module->module == $name) $modules[] = $module; |
foreach ($position as $module) if ($module->module == $name) $modules[] = $module; |
| 694 |
} |
} |
| 695 |
|
if ($unpublished AND $this->_unpublished) foreach ($this->_unpublished as $module) if ($module->module == $name) $modules[] = $module; |
| 696 |
return $modules; |
return $modules; |
| 697 |
} |
} |
| 698 |
|
|
| 699 |
/** |
/** |
| 700 |
|
* Loads all published modules from a specified position, a $style can be passed |
| 701 |
|
* to change the style of output |
| 702 |
|
* |
| 703 |
* @param string The position |
* @param string The position |
| 704 |
* @param int The style. 0=normal, 1=horiz, -1=no wrapper |
* @param int The style. 0=normal(default), 1=horiz, -1=no wrapper |
| 705 |
|
* @param bool TRUE when admin modules will loaded |
| 706 |
*/ |
*/ |
| 707 |
function mosLoadModules( $position='left', $style=0, $isAdmin=false ) { |
function mosLoadModules( $position='left', $style=0, $isAdmin=false ) { |
| 708 |
$Itemid = mamboCore::get('Itemid'); |
$Itemid = mamboCore::get('Itemid'); |
| 745 |
} |
} |
| 746 |
|
|
| 747 |
/** |
/** |
| 748 |
* Loads admin modules via module position |
* Loads admin modules from a specified position,a $style can be passed |
| 749 |
|
* to change the style of output |
| 750 |
|
* |
| 751 |
* @param string The position |
* @param string The position |
| 752 |
* @param int 0 = no style, 1 = tabbed |
* @param int The style 0 = no style(default), 1 = tabbed, 2 = use div |
| 753 |
*/ |
*/ |
| 754 |
function mosLoadAdminModules( $position='left', $style=0 ) { |
function mosLoadAdminModules( $position='left', $style=0 ) { |
| 755 |
global $my, $acl; |
global $my, $acl; |
| 798 |
break; |
break; |
| 799 |
} |
} |
| 800 |
} |
} |
| 801 |
|
/** |
| 802 |
|
* Module access check |
| 803 |
|
* |
| 804 |
|
* Used in |
| 805 |
|
* |
| 806 |
|
* @param object a module object |
| 807 |
|
* @param int an array of groups |
| 808 |
|
*/ |
| 809 |
|
function canAccess($module, $gid) { |
| 810 |
|
if($module->access == 2) { |
| 811 |
|
$groups = explode(',',$module->groups); |
| 812 |
|
if(count($groups) > 0) { |
| 813 |
|
if (in_array($gid, $groups)) { |
| 814 |
|
return 1; |
| 815 |
|
} else { |
| 816 |
|
return 0; |
| 817 |
|
} |
| 818 |
|
} |
| 819 |
|
} |
| 820 |
|
return 1; |
| 821 |
|
} |
| 822 |
} |
} |
| 823 |
|
|
| 824 |
/** |
/** |
| 825 |
* Module database table class |
* Modules database table class |
| 826 |
|
* |
| 827 |
|
* This class can be used to gain access to #_modules database table |
| 828 |
|
* |
| 829 |
|
* Example of use: |
| 830 |
|
* |
| 831 |
|
* To load all modules in a object.. |
| 832 |
|
* |
| 833 |
|
* <code> |
| 834 |
|
* $row = new mosModule(); |
| 835 |
|
* $query = "SELECT * FROM #_modules"; |
| 836 |
|
* $database =& mamboDatabase::getInstance(); |
| 837 |
|
* $database->setQuery( $query ); |
| 838 |
|
* if ($database->loadObject($row)) { |
| 839 |
|
* ... |
| 840 |
|
* } |
| 841 |
|
* </code> |
| 842 |
* @package Mambo |
* @package Mambo |
| 843 |
|
* @access public |
| 844 |
*/ |
*/ |
| 845 |
class mosModule extends mosDBTable { |
class mosModule extends mosDBTable { |
| 846 |
/** @var int Primary key */ |
/** @var int Primary key */ |
| 847 |
var $id=null; |
var $id=null; |
| 848 |
/** @var string */ |
/** @var string module title */ |
| 849 |
var $title=null; |
var $title=null; |
| 850 |
/** @var string */ |
/** @var bool TRUE show title, FALSE hide title*/ |
| 851 |
var $showtitle=null; |
var $showtitle=null; |
| 852 |
/** @var int */ |
/** @var string content to custom modules*/ |
| 853 |
var $content=null; |
var $content=null; |
| 854 |
/** @var int */ |
/** @var int order lower first*/ |
| 855 |
var $ordering=null; |
var $ordering=null; |
| 856 |
/** @var string */ |
/** @var string template position*/ |
| 857 |
var $position=null; |
var $position=null; |
| 858 |
/** @var boolean */ |
/** @var int id from the user that checkout, 0 checkin */ |
| 859 |
var $checked_out=null; |
var $checked_out=null; |
| 860 |
/** @var time */ |
/** @var int date and time from checkout */ |
| 861 |
var $checked_out_time=null; |
var $checked_out_time=null; |
| 862 |
/** @var boolean */ |
/** @var bool TRUE published, FALSE unpublished*/ |
| 863 |
var $published=null; |
var $published=null; |
| 864 |
/** @var string */ |
/** @var string module name*/ |
| 865 |
var $module=null; |
var $module=null; |
| 866 |
/** @var int */ |
/** @var int num of news from newsfeed modules*/ |
| 867 |
var $numnews=null; |
var $numnews=null; |
| 868 |
/** @var int */ |
/** @var int access level 0 public, 1 registered, 2 special */ |
| 869 |
var $access=null; |
var $access=null; |
| 870 |
/** @var string */ |
/** @var string module parameters*/ |
| 871 |
var $params=null; |
var $params=null; |
| 872 |
/** @var string */ |
/** @var int 1 core mambots ,0 others */ |
| 873 |
var $iscore=null; |
var $iscore=null; |
| 874 |
/** @var string */ |
/** @var int 1 admin module, 0 user module*/ |
| 875 |
var $client_id=null; |
var $client_id=null; |
| 876 |
|
/** @var string group access*/ |
| 877 |
|
var $groups=null; |
| 878 |
|
|
| 879 |
/** |
/** |
| 880 |
* @param database A database connector object |
* mosModule Class contructor |
| 881 |
|
* |
| 882 |
|
* Init a mosDBTable object. |
| 883 |
|
* |
| 884 |
|
* @param object reference to current database object |
| 885 |
|
* @access private |
| 886 |
*/ |
*/ |
| 887 |
function mosModule( &$db ) { |
function mosModule( &$db ) { |
| 888 |
$this->mosDBTable( '#__modules', 'id', $db ); |
$this->mosDBTable( '#__modules', 'id', $db ); |
| 889 |
} |
} |
| 890 |
// overloaded check function |
|
| 891 |
|
/** |
| 892 |
|
* overloaded check function |
| 893 |
|
* |
| 894 |
|
* @access private |
| 895 |
|
*/ |
| 896 |
function check() { |
function check() { |
| 897 |
// check for valid name |
// check for valid name |
| 898 |
if (trim( $this->title ) == '') { |
if (trim( $this->title ) == '') { |