Source for file cmtclasses.php

Documentation is available at cmtclasses.php

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

Documentation generated on Mon, 05 May 2008 16:17:57 +0400 by phpDocumentor 1.4.0