| 1 |
<?php |
<?php |
| 2 |
/** |
/** |
| 3 |
* @version $Id: mosloadposition.php,v 1.1 2005/07/22 01:57:49 eddieajau Exp $ |
* @package Mambo Open Source |
| 4 |
* @package Mambo |
* @copyright (C) 2005 - 2007 Mambo Foundation Inc. |
|
* @copyright (C) 2000 - 2005 Miro International Pty Ltd |
|
| 5 |
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL |
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL |
| 6 |
|
* |
| 7 |
|
* Mambo was originally developed by Miro (www.miro.com.au) in 2000. Miro assigned the copyright in Mambo to The Mambo Foundation in 2005 to ensure |
| 8 |
|
* that Mambo remained free Open Source software owned and managed by the community. |
| 9 |
* Mambo is Free Software |
* Mambo is Free Software |
| 10 |
*/ |
*/ |
| 11 |
|
|
| 17 |
/** |
/** |
| 18 |
* Mambot that loads module positions within content |
* Mambot that loads module positions within content |
| 19 |
*/ |
*/ |
| 20 |
function botMosLoadPosition( $published, &$row, &$params, $page=0 ) { |
function botMosLoadPosition( $published, &$row, &$cparams, $page=0, $params ) { |
| 21 |
global $database; |
global $database; |
| 22 |
|
|
| 23 |
// expression to search for |
// expression to search for |
| 24 |
$regex = '/{mosloadposition\s*.*?}/i'; |
$regex = '/{mosloadposition\s*.*?}/i'; |
| 25 |
|
|
| 26 |
|
if (is_callable(array($row, 'getText'))) $localtext = $row->getText(); |
| 27 |
|
else $localtext = $row->text; |
| 28 |
// find all instances of mambot and put in $matches |
// find all instances of mambot and put in $matches |
| 29 |
preg_match_all( $regex, $row->text, $matches ); |
preg_match_all( $regex, $localtext, $matches ); |
| 30 |
|
|
| 31 |
// Number of mambots |
// Number of mambots |
| 32 |
$count = count( $matches[0] ); |
$count = count( $matches[0] ); |
| 33 |
|
|
| 34 |
// mambot only processes if there are any instances of the mambot in the text |
// mambot only processes if there are any instances of the mambot in the text |
| 35 |
if ( $count ) { |
if ( $count ) { |
| 36 |
|
|
| 37 |
// load mambot params info |
// load mambot params info |
| 38 |
$query = "SELECT id FROM #__mambots WHERE element = 'mosloadmodule' AND folder = 'content'"; |
$query = "SELECT id FROM #__mambots WHERE element = 'mosloadposition' AND folder = 'content'"; |
| 39 |
$database->setQuery( $query ); |
$database->setQuery( $query ); |
| 40 |
$id = $database->loadResult(); |
$id = $database->loadResult(); |
| 41 |
$mambot = new mosMambot( $database ); |
$mambot = new mosMambot( $database ); |
| 44 |
|
|
| 45 |
$style = $params->def( 'style', -2 ); |
$style = $params->def( 'style', -2 ); |
| 46 |
|
|
| 47 |
processPositions( $row, $matches, $count, $regex, $style ); |
processPositions( $localtext, $matches, $count, $regex, $style ); |
| 48 |
} |
} |
| 49 |
|
// Save the results of processing |
| 50 |
|
if (is_callable(array($row, 'saveText'))) $row->saveText($localtext); |
| 51 |
|
else $row->text = $localtext; |
| 52 |
|
|
| 53 |
} |
} |
| 54 |
|
|
| 55 |
function processPositions ( &$row, &$matches, $count, $regex, $style ) { |
function processPositions ( &$text, &$matches, $count, $regex, $style ) { |
| 56 |
global $database; |
global $database; |
| 57 |
|
|
| 58 |
$query = "SELECT position" |
$query = "SELECT position" |
| 71 |
foreach ( $positions as $position ) { |
foreach ( $positions as $position ) { |
| 72 |
if ( $position == @$load ) { |
if ( $position == @$load ) { |
| 73 |
$modules = loadPosition( $load, $style ); |
$modules = loadPosition( $load, $style ); |
| 74 |
$row->text = preg_replace( '{'. $matches[0][$i] .'}', $modules, $row->text ); |
$text = preg_replace( '{'. $matches[0][$i] .'}', $modules, $text ); |
| 75 |
break; |
break; |
| 76 |
} |
} |
| 77 |
} |
} |
| 78 |
} |
} |
| 79 |
|
|
| 80 |
// removes tags without matching module positions |
// removes tags without matching module positions |
| 81 |
$row->text = preg_replace( $regex, '', $row->text ); |
$text = preg_replace( $regex, '', $text ); |
| 82 |
} |
} |
| 83 |
|
|
| 84 |
function loadPosition( $position, $style=-2 ) { |
function loadPosition( $position, $style=-2 ) { |