Annotation of /mambo/branches/4.6/mambots/content/mosloadposition.php
Parent Directory
|
Revision Log
Revision 129 - (view) (download)
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | * @version $Id: mosloadposition.php,v 1.1 2005/07/22 01:57:49 eddieajau Exp $ | ||
| 4 : | * @package Mambo | ||
| 5 : | * @copyright (C) 2000 - 2005 Miro International Pty Ltd | ||
| 6 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | * Mambo is Free Software | ||
| 8 : | */ | ||
| 9 : | |||
| 10 : | /** ensure this file is being included by a parent file */ | ||
| 11 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 12 : | |||
| 13 : | $_MAMBOTS->registerFunction( 'onPrepareContent', 'botMosLoadPosition' ); | ||
| 14 : | |||
| 15 : | /** | ||
| 16 : | * Mambot that loads module positions within content | ||
| 17 : | */ | ||
| 18 : | csouza | 129 | function botMosLoadPosition( $published, &$row, &$cparams, $page=0, $params ) { |
| 19 : | root | 1 | global $database; |
| 20 : | |||
| 21 : | // expression to search for | ||
| 22 : | $regex = '/{mosloadposition\s*.*?}/i'; | ||
| 23 : | |||
| 24 : | // find all instances of mambot and put in $matches | ||
| 25 : | preg_match_all( $regex, $row->text, $matches ); | ||
| 26 : | |||
| 27 : | // Number of mambots | ||
| 28 : | $count = count( $matches[0] ); | ||
| 29 : | |||
| 30 : | // mambot only processes if there are any instances of the mambot in the text | ||
| 31 : | if ( $count ) { | ||
| 32 : | |||
| 33 : | $style = $params->def( 'style', -2 ); | ||
| 34 : | |||
| 35 : | processPositions( $row, $matches, $count, $regex, $style ); | ||
| 36 : | } | ||
| 37 : | } | ||
| 38 : | |||
| 39 : | function processPositions ( &$row, &$matches, $count, $regex, $style ) { | ||
| 40 : | global $database; | ||
| 41 : | |||
| 42 : | $query = "SELECT position" | ||
| 43 : | . "\n FROM #__template_positions" | ||
| 44 : | . "\n ORDER BY position" | ||
| 45 : | ; | ||
| 46 : | $database->setQuery( $query ); | ||
| 47 : | $positions = $database->loadResultArray(); | ||
| 48 : | |||
| 49 : | for ( $i=0; $i < $count; $i++ ) { | ||
| 50 : | $load = str_replace( 'mosloadposition', '', $matches[0][$i] ); | ||
| 51 : | $load = str_replace( '{', '', $load ); | ||
| 52 : | $load = str_replace( '}', '', $load ); | ||
| 53 : | $load = trim( $load ); | ||
| 54 : | |||
| 55 : | foreach ( $positions as $position ) { | ||
| 56 : | if ( $position == @$load ) { | ||
| 57 : | $modules = loadPosition( $load, $style ); | ||
| 58 : | $row->text = preg_replace( '{'. $matches[0][$i] .'}', $modules, $row->text ); | ||
| 59 : | break; | ||
| 60 : | } | ||
| 61 : | } | ||
| 62 : | } | ||
| 63 : | |||
| 64 : | // removes tags without matching module positions | ||
| 65 : | $row->text = preg_replace( $regex, '', $row->text ); | ||
| 66 : | } | ||
| 67 : | |||
| 68 : | function loadPosition( $position, $style=-2 ) { | ||
| 69 : | $modules = ''; | ||
| 70 : | if ( mosCountModules( $position ) ) { | ||
| 71 : | ob_start(); | ||
| 72 : | mosLoadModules ( $position, $style ); | ||
| 73 : | $modules = ob_get_contents(); | ||
| 74 : | ob_end_clean(); | ||
| 75 : | } | ||
| 76 : | |||
| 77 : | return $modules; | ||
| 78 : | } | ||
| 79 : |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

