PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/4.8/mambots/content/mosloadposition.php

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