[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/includes/ -> cmtclasses.php (source)

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