Source for file cmtclasses.php
Documentation is available at cmtclasses.php
* Some Components, Modules, Mambots and Templates classes
* @author Mambo Foundation Inc see README.php
* @copyright Mambo Foundation Inc.
* See COPYRIGHT.php for copyright notices and details.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see
* Mambo is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2 of the
* Singleton class to handle with current component
* This class controls the start, end and send output buffer from current component
* stores the output from current component
* Return a reference to current handler
* This function returns a reference to current component handler, if none handler exists,
* <code>$c_handler =& mosComponentHandler::getInstance();</code>
* @return object reference to current singleton Handler
* Returns the admin parameters from a component
* This function returns a reference to specified component in $name param, if none parameters
* are founded it returns null.
* @return object mosParameters object with parameters, null if none was founded.
$query =
"SELECT a.params, a.option"
.
"\n FROM #__components AS a"
.
"\n WHERE a.name = '$name'"
$database->setQuery( $query );
// load the row from the db table
if ($database->loadObject($row)) {
// get params definitions
* Writes the output from current component
* This function send to client browser the outputs from the component, it's
* called by mosMainBody() global function.
// message passed via the url
echo
"\n<div class=\"message\">$mosmsg</div>";
// Alternative if "popmessages" - apparently never implemented
// echo "\n<script language=\"javascript\">alert('$mosmsg');</script>";
* Start the use of buffer
* This function start the use of buffers to components output
* This function ends the use of buffers to components output, all outputs
* are stored in $this->_buffer
* Components database table class
* This class can be used to gain access to #_components database table
/** @var int Primary key */
/** @var string component name*/
/** @var string component link*/
/** @var int parent menu*/
/** @var string component admin link*/
/** @var string alternative text for admin menu*/
/** @var string component option id*/
/** @var string image from admin menu*/
/** @var int 1 core component ,0 others */
/** @var string component parameters*/
* mosComponent class Contructor
function mosComponent() {
$this->mosDBTable( '#__components', 'id', $db );
* Abstract component common base class for both user and admin sides
* Since 4.6 version a new way to develop components based in MVC pattern was included,
* this requires that each component should to create a instance from mosComponentUserManager
* to user(frontend) side and a instance from mosComponentAdminManager to admin(backend) side,
* both classes are derived from this abstract class
/** @var string component name */
/** @var int current magic quotes value, used to restore it */
/** @var string component version*/
/** @var string option from URL*/
* mosComponentManager Class contructor
* This constructor initiates all necessary members, clear all magic quotes if
* is present and load the language from component
* @param string component name
* @param string component version
function mosComponentManager ($component_name, $version) {
$this->text_name =
$component_name;
$mosConfig_absolute_path =
mamboCore::get('mosConfig_absolute_path');
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');
else if (file_exists($mosConfig_absolute_path.
"/components/$cname/language/english.php")) require_once($mosConfig_absolute_path.
"/components/$cname/language/english.php");
* remove magic quotes from Superglobals arrays
* This function removes the magic quotes if is present in $_REQUEST, $_GET
function noMagicQuotes () {
// Yes? Strip the added slashes
$_REQUEST =
& $this->remove_magic_quotes($_REQUEST);
$_GET =
& $this->remove_magic_quotes($_GET);
$_POST =
& $this->remove_magic_quotes($_POST);
* remove magic quotes and slashes from a array
* This function removes the magic quotes if is present in passed array
* @param array array to strip quotes and slashes
* @return array reference to converted array
function &remove_magic_quotes ($array) {
foreach ($array as $k =>
$v) {
if (is_array($v)) $array[$k] =
$this->remove_magic_quotes($v);
* restore magic quotes from old value
* This function restore the old value of magic_quotes_runtime
function restore_magic_quotes () {
* checks for a method in a class
* This function returns TRUE when $method is a member of $object
* @param object Reference to the object
* @param string method name that is looking for
* @return bool TRUE when $method exits
if (is_callable(array(&$object, $method))) return true;
* Component base controller for user(frontend) side
* Since 4.6 version a new way to develop components based in MVC pattern was included,
* this requires that each component should to create a instance from mosComponentUserManager
* to user(frontend) side.
* mosComponentUserManager Class contructor
* This constructor initiates all necessary members, sets the title to browser,
* creates a new instance of the correct class and calls the action to do, finally
* restore the magic quotes to it initial state
* @param string component name
* @param string variable used as control
* @param array array whin alternavite names to actions methods
* @param string default action to do
* @param string browser title to show when the component is in use
* @param string component version
function mosComponentUserManager ($component_name, $control_name, $alternatives, $default, $title, $version) {
$mainframe->SetPageTitle($title);
$func =
mosGetParam ($_REQUEST, $control_name, $default);
if (isset
($alternatives[$func])) $method =
$alternatives[$func];
$classname =
$this->plugin_name.
'_'.
$method.
'_Controller';
$controller =
& new $classname($this);
if (is_callable(array(&$controller,$method))) $controller->$method($func);
$this->restore_magic_quotes();
* Loads and returns a class for render HTML (view Object)
* This function load a class for view html an associated controller is passed
* @param string HTML view class name
* @param object reference to controller object
* @param int list of items to show
* @return mixed a instance to the HTML class, FALSE if the class is not founded
if (class_exists($name)) return new $name ($controller, $this->limit, $clist);
* Component base controller for admin side
* Since 4.6 version a new way to develop components based in MVC pattern was included,
* this requires that each component should to create a instance from mosComponentAdminManager
* to admin(backend) side.
/** @var string action executed */
/** @var string task executed */
/** @var int init offset to admin list*/
/** @var int quantity of elements to show in list*/
/** @var mixed id or id's of selected objects in admin list */
/** @var array order positions for all items */
/** @var int first element of cfid */
* mosComponentAdminManager Class contructor
* This constructor initiates all necessary members with values passed trought REQUEST
* creates a new instance of the correct class and calls the task to do, finally
* restore the magic quotes to it initial state.
* @param string component name
* @param string component version
function mosComponentAdminManager ($component_name, $version) {
$default_limit =
$mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', 20 );
$controller =
& new $name($this);
$task =
$this->task.
'Task';
if (is_callable(array(&$controller, 'getRequestData'))) $controller->getRequestData();
if (is_callable(array(&$controller,$task))) $controller->$task();
$this->restore_magic_quotes();
* Checks that at least one item selected
* @param string alert message
echo
"<script> alert('".
$text.
"'); window.history.go(-1);</script>\n";
* returns the class name from the current action
* @return string class name from the current action
* Loads and returns a class for render HTML (view Object)
* This function load a class for view html an associated controller is passed
* @param string HTML view class name
* @param object reference to controller object
* @param int list of items to show
* @return mixed a instance to the HTML class, FALSE if the class is not founded
$controller->makePageNav($this, $total_items);
* Abstract component base class for admin side component controller logic (not used yet)
* @todo This class is not used yet
/** @var string action executed */
/** @var string curren user */
/** @var object Page navigation Object */
/** @var string curren root path */
/** @var string curren language */
* mosComponentAdminControllers Class contructor
function mosComponentAdminControllers ($admin) {
* Creates a mosPageNav object
* @param object component name
require_once(mamboCore::get('mosConfig_absolute_path').
'/administrator/includes/pageNavigation.php');
* Template database table class
* This class can be used to gain access to #_templates database table
* @todo This class is not used yet
/** @var int table primary key */
* mosTemplate Class contructor
* Init a mosDBTable object.
* @param object &$database reference to current database object
function mosTemplate( &$database ) {
$this->mosDBTable( '#__templates', 'id', $database );
* Mambot database table class
* This class can be used to gain access to #_mambots database table
/** @var int table primary key */
/** @var string mambot name */
/** @var string element name */
/** @var string mambot kind */
/** @var int access level 0 public, 1 registered, 2 special */
/** @var int order lower first*/
/** @var int 1 published, 0 unpublished */
/** @var int 1 core mambots ,0 others */
/** @var int 1 admin mambot, 0 user mambot*/
/** @var int id from the user that checkout, 0 checkin */
/** @var datetime date and time from checkout*/
/** @var string mambot parameters */
* mosMambot Class contructor
* Init a mosDBTable object.
* @param object reference to current database object
function mosMambot( &$db ) {
$this->mosDBTable( '#__mambots', 'id', $db );
* Singleton class to handle with modules
* This class loads, counts and caches modules for both sides, user and admin
* @var object current database object
* @var object modules cached
* @var array unpublished modules
var $_unpublished =
null;
* @var bool TRUE when admin modules are loaded
* mosModuleHandler Class contructor
* Init the database object.
function mosModuleHandler () {
* Returns a reference to current handler
* This function returns a reference to current modules handler, if none handler exists,
* @return object reference to current singleton Handler
* Caches some modules information
* This function cache all modules, a $isAdmin bool value can be passed to select
* the side (user/admin) by default user modules are loaded.
* @param bool TRUE when admin modules will loaded
function initModules($isAdmin=
false) {
if (!isset
($this->_modules) OR $isAdmin !=
$this->_isAdmin) {
$this->_isAdmin =
$isAdmin;
$query =
"SELECT id, title, module, position, content, showtitle, params, published"
.
"\n FROM #__modules AS m"
.
"\n WHERE m.published = '1'"
.
"\n AND (m.client_id = 1)"
.
"\n ORDER BY m.ordering";
$query =
"SELECT id, title, module, position, content, showtitle, params, published, m.access, m.groups"
.
"\nFROM #__modules AS m, #__modules_menu AS mm"
.
"\nWHERE m.access <= '$my->gid' AND m.client_id='0'"
.
"\nAND mm.moduleid=m.id"
.
"\nAND (mm.menuid = '$Itemid' OR mm.menuid = '0')"
$this->_db->setQuery( $query );
$modules =
$this->_db->loadObjectList();
foreach ($modules as $module) {
if (!$isAdmin) $canAccess =
$this->canAccess($module, $my->gid);
if ($module->published ==
1 &&
$canAccess ==
1) $this->_modules[$module->position][] =
$module;
else $this->_unpublished[] =
$module;
* Returns the number of modules in a specified position, this method is called by
* mosCountModules global function
* @param string The template position
* @param bool TRUE when admin modules will loaded
$this->initModules($isAdmin);
return isset
($this->_modules[$position]) ?
count($this->_modules[$position]) :
0;
* Returns a array with modules that match whit $name, when $unpublished is TRUE
* unpublished modules are returned too.
* @param string Name of module required
* @param bool TRUE when admin modules will loaded
* @param bool TRUE whish to include unpublished modules too
* @return array array with all modules that match
function &getByName( $name, $isAdmin=
false, $unpublished=
false ) {
$this->initModules($isAdmin);
foreach ($this->_modules as $position) {
foreach ($position as $module) if ($module->module ==
$name) $modules[] =
$module;
if ($unpublished AND $this->_unpublished) foreach ($this->_unpublished as $module) if ($module->module ==
$name) $modules[] =
$module;
* Loads all published modules from a specified position, a $style can be passed
* to change the style of output
* @param string The position
* @param int The style. 0=normal(default), 1=horiz, -1=no wrapper
* @param bool TRUE when admin modules will loaded
function mosLoadModules( $position=
'left', $style=
0, $isAdmin=
false ) {
echo
'<div style="height:50px;background-color:#eee;margin:2px;padding:10px;border:1px solid #f00;color:#700;">';
require_once( mamboCore::get('mosConfig_absolute_path').
'/includes/frontend.html.php');
$this->initModules($isAdmin);
if (isset
($this->_modules[$position] )) $modules =
$this->_modules[$position];
echo
"<table cellspacing=\"1\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
$prepend =
($style ==
1) ?
"<td valign=\"top\">\n" :
'';
$postpend =
($style ==
1) ?
"</td>\n" :
'';
foreach ($modules as $module) {
if ((substr("$module->module",0,4))==
"mod_") $modfunc =
'module2';
else $modfunc =
'module';
if ($params->get('cache') ==
1 AND mamboCore::get('mosConfig_caching') ==
1) {
$cache->call("modules_html::$modfunc", $module, $params, $Itemid, $style );
else modules_html::$modfunc($module, $params, $Itemid, $style, $count);
if ($style ==
1) echo
"</tr>\n</table>\n";
* Loads admin modules from a specified position,a $style can be passed
* to change the style of output
* @param string The position
* @param int The style 0 = no style(default), 1 = tabbed, 2 = use div
$this->initModules(true);
if (isset
($this->_modules[$position] )) $modules =
$this->_modules[$position];
foreach ($modules as $module) {
$tabs->startPane( 'modules-' .
$position );
foreach ($modules as $module) {
$editAllComponents =
$acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' );
// $authoriser = new mosAuthoriser($database);
// $editAllComponents = $authoriser->checkPermission('mosUser', $my->id, 'edit', 'editAllComponents', 0);
// special handling for components module
if ( $module->module !=
'mod_components' ||
( $module->module ==
'mod_components' &&
$editAllComponents ) ) {
$tabs->startTab( T_($module->title), 'module' .
$module->id );
foreach ($modules as $module) {
* @param object a module object
* @param int an array of groups
if($module->access ==
2) {
$groups =
explode(',',$module->groups);
* Modules database table class
* This class can be used to gain access to #_modules database table
* To load all modules in a object..
* $row = new mosModule();
* $query = "SELECT * FROM #_modules";
* $database =& mamboDatabase::getInstance();
* $database->setQuery( $query );
* if ($database->loadObject($row)) {
/** @var int Primary key */
/** @var string module title */
/** @var bool TRUE show title, FALSE hide title*/
/** @var string content to custom modules*/
/** @var int order lower first*/
/** @var string template position*/
/** @var int id from the user that checkout, 0 checkin */
/** @var int date and time from checkout */
/** @var bool TRUE published, FALSE unpublished*/
/** @var string module name*/
/** @var int num of news from newsfeed modules*/
/** @var int access level 0 public, 1 registered, 2 special */
/** @var string module parameters*/
/** @var int 1 core mambots ,0 others */
/** @var int 1 admin module, 0 user module*/
/** @var string group access*/
* mosModule Class contructor
* Init a mosDBTable object.
* @param object reference to current database object
function mosModule( &$db ) {
$this->mosDBTable( '#__modules', 'id', $db );
* overloaded check function
$this->_error =
T_('Your Module must contain a title.');
// limitation has been removed
// check for existing title
//$this->_db->setQuery( "SELECT id FROM #__modules"
//. "\nWHERE title='$this->title'"
// check for module of same name
//$xid = intval( $this->_db->loadResult() );
//if ($xid && $xid != intval( $this->id )) {
// $this->_error = "There is a module already with that name, please try again.";
Documentation generated on Mon, 05 May 2008 16:17:57 +0400 by phpDocumentor 1.4.0