[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/mambots/content/ -> mosloadposition.php (source)

   1  <?php
   2  /**
   3  * @version $Id: mosloadposition.php 5875 2006-11-28 23:31:00Z facedancer $
   4  * @package Joomla
   5  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
   6  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  */
  13  
  14  // no direct access
  15  defined( '_VALID_MOS' ) or die( 'Restricted access' );
  16  
  17  $_MAMBOTS->registerFunction( 'onPrepareContent', 'botMosLoadPosition' );
  18  
  19  /**
  20  * Mambot that loads module positions within content
  21  */
  22  function botMosLoadPosition( $published, &$row, &$params, $page=0 ) {
  23      global $database, $_MAMBOTS;
  24  
  25      // simple performance check to determine whether bot should process further
  26      if ( strpos( $row->text, 'mosloadposition' ) === false ) {
  27          return true;
  28      }
  29  
  30       // expression to search for
  31       $regex = '/{mosloadposition\s*.*?}/i';
  32  
  33       // check whether mambot has been unpublished
  34      if ( !$published ) {
  35          $row->text = preg_replace( $regex, '', $row->text );
  36          return true;
  37      }
  38  
  39      // find all instances of mambot and put in $matches
  40      preg_match_all( $regex, $row->text, $matches );
  41  
  42      // Number of mambots
  43       $count = count( $matches[0] );
  44  
  45       // mambot only processes if there are any instances of the mambot in the text
  46       if ( $count ) {
  47          // check if param query has previously been processed
  48          if ( !isset($_MAMBOTS->_content_mambot_params['mosloadposition']) ) {
  49              // load mambot params info
  50              $query = "SELECT params"
  51              . "\n FROM #__mambots"
  52              . "\n WHERE element = 'mosloadposition'"
  53              . "\n AND folder = 'content'"
  54              ;
  55              $database->setQuery( $query );
  56              $database->loadObject($mambot);
  57  
  58              // save query to class variable
  59              $_MAMBOTS->_content_mambot_params['mosloadposition'] = $mambot;
  60          }
  61  
  62          // pull query data from class variable
  63          $mambot = $_MAMBOTS->_content_mambot_params['mosloadposition'];
  64  
  65           $botParams = new mosParameters( $mambot->params );
  66  
  67           $style    = $botParams->def( 'style', -2 );
  68  
  69           processPositions( $row, $matches, $count, $regex, $style );
  70      }
  71  }
  72  
  73  function processPositions ( &$row, &$matches, $count, $regex, $style ) {
  74      global $database;
  75  
  76      $query = "SELECT position"
  77      . "\n FROM #__template_positions"
  78      . "\n ORDER BY position"
  79      ;
  80      $database->setQuery( $query );
  81       $positions     = $database->loadResultArray();
  82  
  83       for ( $i=0; $i < $count; $i++ ) {
  84           $load = str_replace( 'mosloadposition', '', $matches[0][$i] );
  85           $load = str_replace( '{', '', $load );
  86           $load = str_replace( '}', '', $load );
  87           $load = trim( $load );
  88  
  89          foreach ( $positions as $position ) {
  90               if ( $position == @$load ) {
  91                  $modules    = loadPosition( $load, $style );
  92                  $row->text     = str_replace($matches[0][$i], $modules, $row->text);
  93                  break;
  94               }
  95           }
  96       }
  97  
  98        // removes tags without matching module positions
  99      $row->text = preg_replace( $regex, '', $row->text );
 100  }
 101  
 102  function loadPosition( $position, $style=-2 ) {
 103      $modules = '';
 104      if ( mosCountModules( $position ) ) {
 105          ob_start();
 106          mosLoadModules ( $position, $style );
 107          $modules = ob_get_contents();
 108          ob_end_clean();
 109      }
 110  
 111      return $modules;
 112  }
 113  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics