/plugin_J10/plugin_jumi.php

http://jumi.googlecode.com/ · PHP · 75 lines · 45 code · 8 blank · 22 comment · 5 complexity · 7c67778ab3c151ddf356e98ed7ff12b2 MD5 · raw file

  1. <?php
  2. /**
  3. * @version $Id: plugin_jumi.php 3 2008-10-23 13:31:15Z martin2hajek $
  4. * @package Joomla! 1.0.X or Mambo_4.5.X
  5. * @copyright (c) 2008 Martin Hajek
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. *
  8. * Usage
  9. * {jumi [pathname] [arg1] [arg2] ... [argN]}
  10. * where pathname is the pathname of the file to be included and [arg1] ... [argN] are optional arguments.
  11. * It depends on your included php file if it handles jumi argumets, that can be accessed by $jumi[] array in a php script.
  12. *
  13. * There is also Jumi module. You can find it, as well as demo, manuals, tips and tricks at http://jumi.vedeme.cz
  14. */
  15. //do not remove this line
  16. defined( '_VALID_MOS' ) or die( 'Restricted access' );
  17. $_MAMBOTS->registerFunction( 'onPrepareContent', 'plugJumi' );
  18. function plugJumi( $published, &$row, &$params, $page=0 ) {
  19. global $mosConfig_absolute_path, $database;
  20. // expression to search for
  21. $regex = '/{(jumi)\s*(.*?)}/i';
  22. // if not publish then output empty string
  23. if (!$published ) {
  24. $row->text = preg_replace( $regex, '', $row->text );
  25. return;
  26. }
  27. // find all instances of mambot and put in $matches
  28. $matches = array();
  29. preg_match_all( $regex, $row->text, $matches, PREG_SET_ORDER );
  30. // cycle through all bots. Bot text will be in $dummy[2]
  31. foreach ($matches as $dummy) {
  32. //read arguments from bot text and put them into the array $jumi
  33. $mms=array();
  34. $jumi="";
  35. preg_match_all('/\[.*?\]/', $dummy[2], $mms);
  36. if ($mms) { //at the least one argument found
  37. foreach ($mms as $i=>$mm) {
  38. $jumi = preg_replace("/\[|]/", "", $mm);
  39. }
  40. }
  41. //The first argument must be the file pathname
  42. $incl_file=array_shift($jumi);
  43. $output = "You must supply the file pathname into the <b>first Jumi argument at the least!</b>";
  44. if ( $incl_file ) { //if the string $incl_file is nonempty try to include the file else $output "You must supply ...
  45. //get plugin parameters
  46. $query = "SELECT id FROM #__mambots WHERE element = 'plugin_jumi' AND folder = 'content'";
  47. $database->setQuery( $query );
  48. $id = $database->loadResult();
  49. $mambot = new mosMambot( $database );
  50. $mambot->load( $id );
  51. $param =& new mosParameters( $mambot->params );
  52. $incl_file = $param->def('default_absolute_path',$mosConfig_absolute_path) . '/' . $incl_file;
  53. if (is_readable($incl_file)) {// if the file is readable then include it else $output "The file ...
  54. ob_start();
  55. include($incl_file);
  56. $output = str_replace( '$' , '\$' , ob_get_contents()); //fixed joomla bug
  57. ob_end_clean();
  58. } else {
  59. $output = "The file <b>".$incl_file."</b> cannot be included!<br />It does not exist or is not readable.";
  60. }
  61. }
  62. // final replacing of $regex (i.e. jumi) in $row->text by $output
  63. $row->text = preg_replace($regex, $output, $row->text, 1);
  64. }
  65. return true;
  66. }
  67. ?>