Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. <?php
  2. /**
  3. * @version $Id: loadmodule.php 10381 2008-06-01 03:35:53Z pasamio $
  4. * @package Joomla
  5. * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  6. * @license 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( '_JEXEC' ) or die( 'Restricted access' );
  16.  
  17. $mainframe->registerEvent( 'onPrepareContent', 'plgContentLoadModule' );
  18. die();
  19.  
  20. /**
  21. * Plugin that loads module positions within content
  22. */
  23. function plgContentLoadModule( &$row, &$params, $page=0 )
  24. {
  25. $db =& JFactory::getDBO();
  26. // simple performance check to determine whether bot should process further
  27. if ( JString::strpos( $row->text, 'loadposition' ) === false ) {
  28. return true;
  29. }
  30.  
  31. // Get plugin info
  32. $plugin =& JPluginHelper::getPlugin('content', 'loadmodule');
  33.  
  34. // expression to search for
  35. $regex = '/{loadposition\s*.*?}/i';
  36.  
  37. $pluginParams = new JParameter( $plugin->params );
  38.  
  39. // check whether plugin has been unpublished
  40. if ( !$pluginParams->get( 'enabled', 1 ) ) {
  41. $row->text = preg_replace( $regex, '', $row->text );
  42. return true;
  43. }
  44.  
  45. // find all instances of plugin and put in $matches
  46. preg_match_all( $regex, $row->text, $matches );
  47.  
  48. // Number of plugins
  49. $count = count( $matches[0] );
  50.  
  51. // plugin only processes if there are any instances of the plugin in the text
  52. if ( $count ) {
  53. // Get plugin parameters
  54. $style = $pluginParams->def( 'style', -2 );
  55.  
  56. plgContentProcessPositions( $row, $matches, $count, $regex, $style );
  57. }
  58. }
  59.  
  60. function plgContentProcessPositions ( &$row, &$matches, $count, $regex, $style )
  61. {
  62. for ( $i=0; $i < $count; $i++ )
  63. {
  64. $load = str_replace( 'loadposition', '', $matches[0][$i] );
  65. $load = str_replace( '{', '', $load );
  66. $load = str_replace( '}', '', $load );
  67. $load = trim( $load );
  68.  
  69. $modules = plgContentLoadPosition( $load, $style );
  70. $row->text = preg_replace( '{'. $matches[0][$i] .'}', $modules, $row->text );
  71. }
  72.  
  73. // removes tags without matching module positions
  74. $row->text = preg_replace( $regex, '', $row->text );
  75. }
  76.  
  77. function plgContentLoadPosition( $position, $style=-2 )
  78. {
  79. $document = &JFactory::getDocument();
  80. $renderer = $document->loadRenderer('module');
  81. $params = array('style'=>$style);
  82.  
  83. $contents = '';
  84. foreach (JModuleHelper::getModules($position) as $mod) {
  85. $contents .= $renderer->render($mod, $params);
  86. }
  87. return $contents;
  88. }
Add Comment
Please, Sign In to add comment