Location: PHPKode > scripts > PQuery > inc.pquery.class.php
<?php
/**
 *  Created by: Roland Burda (hide@address.com)
 *  Date: 		2010.01.26 - 15:10 (Budapest)
 *  Version:	v1.0
 *
 *  Based on 'zQuery php-class'...
 **/
 
/**
 *  How to use? It is verry simple!
 *  Just take a look at the 'index.php'...
 *
 *  function write_jquery() 
 *  	includes the jquery javascript; this is a regular jquery minified plus other javascript to process the whole thing
 *  	
 *  function pjq($jq)
 *  	let execute some extra javascript
 *  	
 *  function pget($process_url, $question='', $resp='', $on_done='')
 *  	calls javascript funtion for processing $_GET data
 *  	1st argument is the .php file that will process the data
 *  	2nd argument is (optional) the question will be asked.
 *  	3rd argument is (optional) the given $resp (e.g. DIV or SPAN tag) for response output.
 *  	4rd argument is (optional) the function name with parameters. It will be called after the main job is done.
 *  	
 *  function ppost($process_url, $form_id, $question='', $resp='', $on_done='')
 *  	calls javascript funtion for processing $_POST data
 *  	1st argument is the .php file that will process the data
 *  	2nd argument is the id of the form to process
 *  	3rd argument is (optional) the question will be asked.
 *  	4rd argument is (optional) the given $resp (e.g. DIV or SPAN tag) for response output.
 *  	5rd argument is (optional) the function name with parameters. It will be called after the main job is done.
 *  	
 *  function pload($url, $tagid)
 *  	if called, dumps to screen inside the given $tagid (e.g. DIV or SPAN tag) the data outputted by the file given as $URL
 *  	
 *  function pdebug()
 *  	if called, dumps to screen the values inside $_SESSION, $_POST and $_GET
 **/

class pquery {

	// Variables
	var $jquery = 'pquery-1.4.js';
	var $debug = FALSE;
	
	/**
	 * Write jQuery script to page header
	 **/
	function write_jquery() {
		
		echo('<script language="javascript" src="'.$this->jquery.'"></script>').chr(10);
		
	}
	
	/**
	 * Write extra js to page header
	 **/
	function pjq($jq) {
		
		echo('<script language="javascript">'.chr(10).'<!--'.stripslashes($jq).'// -->'.chr(10).'</script>').chr(10);
		
	}
	
	/**
	 * Write $.get call
	 **/
	function pget($process_url, $question='', $resp='', $on_done='') {
		
		// change space string to '+'
		$process_url = str_replace(" ","+",$process_url);
		
		// encode function (BASE64)
		if($on_done != '') $on_done = base64_encode($on_done);
		
		echo("$.getdata('{$process_url}', '{$question}', '{$resp}', '{$on_done}')");
		
	}
	
	/**
	 * Write $.post call
	 **/
	function ppost($process_url, $form_id, $question='', $resp='', $on_done='') {
		
		// change space string to '+'
		$process_url = str_replace(" ","+",$process_url);
		
		// encode function (BASE64)
		if($on_done != '') $on_done = base64_encode($on_done);
		
		echo("$.postdata('{$process_url}', '{$form_id}', '{$question}', '{$resp}', '{$on_done}')");
		
	}
	
	/**
	 * Load content to page element - dynamic
	 **/
	function pload($url, $tagid) {
	
		// two lines below for avoiding IE caching
		(strpos($url, '?') !== false) ? $join = '&pqnr=' : $join = '?pqnr=';
		
		$nr = rand(1,1000);
		
		// change space string to '+'
		$url = str_replace(" ","+",$url);
		
		echo("$.lodata('{$url}{$join}{$nr}', '{$tagid}')");
		
	}	
	
	/**
	 * Load content to page element - static
	 **/
	function pload_static($url, $tagid) {
		
		// two lines below for avoiding IE caching
		(strpos($url, '?') !== false) ? $join = '&pqnr=' : $join = '?pqnr=';
		
		$nr = rand(1,1000);
		
		// change space string to '+'
		$url = str_replace(" ","+",$url);
		
		echo('<script language="javascript">'.chr(10).'$(document).ready(function() {'.chr(10).'$("#'.$tagid.'").load("'.$url.$join.$nr.'");'.chr(10).'});'.chr(10).'</script>').chr(10);
		
	}
	
	/**
	 * Debugging on/of
	 **/
	function pdebug_onoff($flag) {
		
		if($flag == TRUE) $this->debug = TRUE;
		
	}
	
	/**
	 * Debugging
	 **/
	function pdebug() {
		if($this->debug == TRUE):
		
			echo('<p>Debugging mode is ON; if you do not want it remove in the code: ->pdebug_onoff(TRUE)</p>');
			echo('<pre style="text-align: left; background-color: #fff; font-family: Arial; font-size: 12px; padding:2px; line-height:20px; letter-spacing:1px;">');
			echo('<strong>SESSION</strong>').chr(10);
			print_r($_SESSION);
			echo('<br />').chr(10);
			echo('<strong>POST</strong>').chr(10);
			print_r($_POST);
			echo('<br />').chr(10);
			echo('<strong>GET</strong>').chr(10);
			print_r($_GET);
			echo('</pre>');
		
		endif;
	}

}
?>
Return current item: PQuery