PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/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
16//do not remove this line
17defined( '_VALID_MOS' ) or die( 'Restricted access' );
18
19$_MAMBOTS->registerFunction( 'onPrepareContent', 'plugJumi' );
20
21function plugJumi( $published, &$row, &$params, $page=0  ) {
22	global $mosConfig_absolute_path, $database;
23
24 	// expression to search for
25 	$regex = '/{(jumi)\s*(.*?)}/i';
26
27	// if not publish then output empty string
28 	if (!$published ) {
29		$row->text = preg_replace( $regex, '', $row->text );
30		return;
31	}
32
33	// find all instances of mambot and put in $matches
34	$matches = array();
35	preg_match_all( $regex, $row->text, $matches, PREG_SET_ORDER );
36	
37	// cycle through all bots. Bot text will be in $dummy[2]
38	foreach ($matches as $dummy) {
39
40		//read arguments from bot text and put them into the array $jumi 
41		$mms=array();
42		$jumi="";
43		preg_match_all('/\[.*?\]/', $dummy[2], $mms);
44		if ($mms) { //at the least one argument found
45			foreach ($mms as $i=>$mm) {
46				$jumi = preg_replace("/\[|]/", "", $mm);
47			}
48		}
49		//The first argument must be the file pathname
50		$incl_file=array_shift($jumi);
51		$output = "You must supply the file pathname into the <b>first Jumi argument at the least!</b>"; 			
52		if ( $incl_file ) { //if the string $incl_file is nonempty try to include the file else $output "You must supply ...
53         //get plugin parameters
54         $query = "SELECT id FROM #__mambots WHERE element = 'plugin_jumi' AND folder = 'content'";
55         $database->setQuery( $query );
56         $id = $database->loadResult();
57         $mambot = new mosMambot( $database );
58         $mambot->load( $id );
59         $param =& new mosParameters( $mambot->params );  
60			$incl_file = $param->def('default_absolute_path',$mosConfig_absolute_path) . '/' . $incl_file;
61         if (is_readable($incl_file)) {// if the file is readable then include it else $output "The file ...	
62				ob_start();
63				include($incl_file);
64				$output = str_replace( '$' , '\$' , ob_get_contents()); //fixed joomla bug
65				ob_end_clean();
66			} else {
67				$output = "The file <b>".$incl_file."</b> cannot be included!<br />It does not exist or is not readable."; 
68			}
69		}
70		// final replacing of $regex (i.e. jumi) in $row->text by $output 
71		$row->text = preg_replace($regex, $output, $row->text, 1);
72	}
73	return true;
74}
75?>