Location: PHPKode > projects > Simple Way to Usenet > swun/libs/core/themes/tfeats/tfeat_ajax.class.php
<?php
/**
 *  
 * @author  Benjamin Gillissen <hide@address.com>
 * 
 *	**************************************************************

	Copyright (C) 2009  Benjamin Gillissen
	
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details at:
	http://www.gnu.org/copyleft/gpl.html

 *	**************************************************************
 */
/* used to output the javascript needed by ajax and catch the ajax request.
 * 
 */ 
class tfeat_ajax {
	
	const PROFILE = FALSE;
	
	public function __construct(){ }
	
	public static function implent(){
		self::deps();
		if ( ajax::isAjaxReq() ){
			ajax::ProcessReq();
			exit;
		}
		errors::raise(count(ajax::getRegistred())." Ajax function registred", CORE_LOG_DEBUG, 'AJAX');
		return TRUE; 
	}
	
	private static function deps(){
		$funcs = ajax::getRegistred();
		$src='';
		foreach($funcs as $k => &$func){
			$src .= "xajax_$func = function() { return xajax.request( { xjxfun: '$func' }, { parameters: arguments } ); };\n";
		}
		thm_mediaq::append_js_string($src);
		$src = 'try { if (undefined == xajax.config) xajax.config = {}; } catch (e) { xajax = {}; xajax.config = {}; };
xajax.config.requestURI = "'.ajax::URI.'";
xajax.config.statusMessages = false;
xajax.config.waitCursor = true;
xajax.config.version = "xajax 0.5 Beta 4";
xajax.config.legacy = false;
xajax.config.defaultMode = "asynchronous";
xajax.config.defaultMethod = "POST"';
		thm_mediaq::append_js_string($src);
		thm_mediaq::append_js_file(browsing::basedir().'/xajax_js/xajax_core.js');
		$src='window.setTimeout(
 function() {
  var scriptExists = false;
  try { if (xajax.isLoaded) scriptExists = true; }
  catch (e) {}
  if (!scriptExists) {
   alert("Error: the xajax Javascript component could not be included. Perhaps the URL is incorrect?\nURL: /xajax_js/xajax_core.js");
  }
 }, 2000);';
		thm_mediaq::append_js_string($src);
	}
}
return TRUE;
Return current item: Simple Way to Usenet