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