Source for file mosloadposition.php

Documentation is available at mosloadposition.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @author Mambo Foundation Inc see README.php
  5. @copyright Mambo Foundation Inc.
  6. *  See COPYRIGHT.php for copyright notices and details.
  7. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see
  8. *  LICENSE.php
  9. *  Mambo is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU General Public License
  11. *  as published by the Free Software Foundation; version 2 of the
  12. *  License.
  13. */ 
  14.  
  15. /** ensure this file is being included by a parent file */
  16. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  17.  
  18. $_MAMBOTS->registerFunction'onPrepareContent''botMosLoadPosition' );
  19.  
  20. /**
  21. * Mambot that loads module positions within content
  22. */
  23. function botMosLoadPosition$published&$row&$cparams$page=0$params {
  24.     global $database;
  25.     
  26.      // expression to search for
  27.      $regex '/{mosloadposition\s*.*?}/i';
  28.       
  29.     if (is_callable(array($row'getText'))) $localtext $row->getText();
  30.     else $localtext $row->text;
  31.      // find all instances of mambot and put in $matches
  32.     preg_match_all$regex$localtext$matches );
  33.     
  34.     // Number of mambots
  35.      $count count$matches[0);
  36.  
  37.      // mambot only processes if there are any instances of the mambot in the text
  38.      if $count {
  39.      
  40.         // load mambot params info
  41.         /*$query = "SELECT id FROM #__mambots WHERE element = 'mosloadposition' AND folder = 'content'";
  42.         $database->setQuery( $query );
  43.         $id     = $database->loadResult();
  44.         $mambot = new mosMambot( $database );
  45.         $mambot->load( $id );*/
  46.         $mambots =mosMambotHandler::getInstance();
  47.         $mambot =$mambots->getBot('mosloadposition','content');
  48.         $params =new mosParameters( (isset($mambot->params)?$mambot->params:'') );
  49.         
  50.         $style    $params->def'style'-);
  51.  
  52.          processPositions$localtext$matches$count$regex$style );
  53.     }
  54.     // Save the results of processing
  55.     if (is_callable(array($row'saveText'))) $row->saveText($localtext);
  56.     else $row->text $localtext;
  57.  
  58. }
  59.  
  60. function processPositions &$text&$matches$count$regex$style {
  61.     global $database;
  62.     
  63.     $query "SELECT position"
  64.     . "\n FROM #__template_positions"
  65.     . "\n ORDER BY position"
  66.     ;
  67.     $database->setQuery$query );
  68.      $positions     $database->loadResultArray();
  69.  
  70.      for $i=0$i $count$i++ {
  71.          $load str_replace'mosloadposition'''$matches[0][$i);
  72.          $load str_replace'{'''$load );
  73.          $load str_replace'}'''$load );
  74.          $load trim$load );
  75.         
  76.         foreach $positions as $position {
  77.              if $position == @$load {                     
  78.                 $modules    loadPosition$load$style );                    
  79.                 $text     preg_replace'{'$matches[0][$i.'}'$modules$text );
  80.                 break;            
  81.              }                 
  82.          }
  83.      }
  84.  
  85.       // removes tags without matching module positions
  86.     $text preg_replace$regex''$text );
  87. }
  88.  
  89. function loadPosition$position$style=-{
  90.     $modules '';
  91.     if mosCountModules$position ) ) {
  92.         ob_start();
  93.         mosLoadModules $position$style );
  94.         $modules ob_get_contents();
  95.         ob_end_clean();
  96.     }
  97.  
  98.     return $modules;
  99. }

Documentation generated on Mon, 05 May 2008 16:21:31 +0400 by phpDocumentor 1.4.0