Code Search for Developers
 
 
  

ajax.php from ECP (EliteCore Project) at Krugle


Show ajax.php syntax highlighted

<?php
if (!defined('TINYAJAX_PATH'))
	define('TINYAJAX_PATH', 'ext/tinyajax_095');
require_once (TINYAJAX_PATH . '/TinyAjax.php');

class NoAjaxException extends Exception {
};

class Ajax {
	private static $tinyajax = null;
	private static $export = array ();
	private static $clientExport = array ();
	private static $tabsBuffer = array ();
	private static $tab = null;
	private static $clientCall = false;
	private static $ajaxFunction = null;
	private static $loadOnDemand = array ();

	static function isClientCall() {
		if (isset ($_POST["rs"]) || self :: $clientCall === true) {
			self :: $clientCall = true;
			return true;
		} else {
			return false;
		}
	}

	private static function _processTabsBuffer() {
		if (sizeof(self :: $tabsBuffer)) {
			$JavaScriptOnDemand = array ();
			foreach (self :: $tabsBuffer as $behavior) {
				if ($behavior[0] == 'TabJS') {
					$JavaScriptOnDemand[] = $behavior;
				} else {
					self :: $tab->add($behavior);
				}
			}
			foreach ($JavaScriptOnDemand as $behavior) {
				self :: $tab->add($behavior);
			}
		}

	}

	public static function ThrowException() {
		if (Ajax :: isClientCall()) {
			self :: _processTabsBuffer();
			throw new AjaxFlushException(self :: $tab->getString());
		} else {
			throw new NoAjaxException;
		}
	}

	public static function getBehaviorsNum() {
		return sizeof(self :: $tabsBuffer);
	}

	public static function sendNewContent() {
		if (self :: $ajaxFunction === null)
			self :: Init();
		if (self :: isClientCall() && self :: $ajaxFunction == 'SendContent')
			return true;
		else
			return false;
	}

	public static function loadOnDemand($script) {
		self :: $loadOnDemand[] = $script;
	}

	public static function getScriptsOnDemand() {
		return self :: $loadOnDemand;
	}

	public static function Init() {
		global $Config;

		if (self :: $tinyajax !== null)
			return self :: $tinyajax;

		self :: isClientCall();
		if (isset ($_POST["rs"])) {
			self :: $ajaxFunction = $_POST["rs"];
		}
		self :: $tinyajax = new TinyAjax(true);
		self :: $tinyajax->setRequestType("POST");
		self :: $tinyajax->setRequestUri($Config->getMaster() . 'index.php');
		self :: $tab = new TinyAjaxBehavior(true);

		self :: Export('ECP->VerifyUser', array (
			'callFunction'
		));
		self :: Export('ECP->VerifyCode', 'verify_code');
		self :: Export('ECP->SendContent', array (
			'_ecp_number',
			'_link',
			'_content',
			'_template_file'
		));
		self :: Export('ECP->GetPage', 'location');
		return self :: $tinyajax;
	}
	public static function Export($methodName, $sourceId = null, $callback = null, $class = null) {
		if ($class != null && is_object($class) && $class instanceof Module) {
			if (method_exists($class, $methodName)) {
				$methodName = $class->getInstance() . '->' . $methodName;
			}
		}
		$object = new stdClass();
		$object->functionName = $methodName;
		$object->sourceId = serialize($sourceId);
		$object->callback = $callback;
		$object->className = $class;
		self :: $export[] = $object;
	}
	private static function clientExported($object) {
		foreach (self :: $clientExport as $export) {
			if ($export->functionName == $object->functionName && $export->sourceId == $object->sourceId && $export->callback == $object->callback && $export->className == $object->className) {
				return true;
			}
		}
		return false;
	}
	public static function Process($clientProcess = false) {
		global $XCS;

		$TA = new TA();
		$TA->addQuery(TA :: SELECT, "ecp_engine_ajax");
		$TA->Execute();
		while ($command = $TA->Result()->FetchObject()) {
			if (empty ($command->sourceId))
				$command->sourceId = null;
			if (empty ($command->callback))
				$command->callback = null;
			if (empty ($command->className))
				$command->className = null;
			self :: $clientExport[] = $command;
		}
		$TA->removeQuery();
		if (!$clientProcess) {
			foreach (self :: $export as $command) {
				if (!self :: clientExported($command)) {
					$TA->addQuery(TA :: DELETE, "ecp_engine_ajax");
					$TA->WHERE("`functionName`='" . $command->functionName . "'");
					$TA->LIMIT(1);
					$TA->addQuery(TA :: INSERT, "ecp_engine_ajax");
					$TA->addParam('functionName', TA :: STRING, $command->functionName);
					$TA->addParam('sourceId', TA :: STRING, $command->sourceId);
					$TA->addParam('className', TA :: STRING, $command->className);
					$object = explode("->", $command->functionName);
					if (sizeof($object) == 2 && strpos($object[1], 'on') === 0) {
						$command->jshandler = substr($object[1], 2);
						$command->jshandler = ucfirst($object[0]) . $command->jshandler;
						$TA->addParam('jshandler', TA :: STRING, $command->jshandler);
						$command->callback = ucfirst($object[0]);
					}
					$TA->addParam('callback', TA :: STRING, $command->callback);
				}
			}
		}
		foreach (self :: $clientExport as $command) {
			if (false !== (strpos($command->functionName, '->'))) {
				$object = explode("->", $command->functionName);
				if ($object[0] == 'XCS') {
					global $XCS;
					$command->className = $XCS;
				} else
					if ($object[0] == 'ECP') {
						global $ECP;
						$command->className = $ECP;
					} else {
						try {
							$command->className = ModulesManager :: loadModule($object[0]);
						} catch (NoModuleException $e) {
						}
					}
				if (isset ($command->className->object)) {
					$command->className = $command->className->object;
				} else
					if (!$command->className) {
						global ${ $object[0] };
						$command->className = ${$object[0]};
					}
				$command->functionName = $object[1];
			}
			$unserialized = unserialize($command->sourceId);
			if ($unserialized !== false) {
				$command->sourceId = $unserialized;
			}
			self :: $tinyajax->exportFunction($command->functionName, $command->sourceId, null, $command->className, $command->jshandler, $command->callback);

		}
		self :: $tinyajax->process();
		if (!$clientProcess && sizeof(self :: $export)) {
			$TA->Execute();
			return true;
		}
		if ($clientProcess) {
			self :: drawJavascript();
			exit;
		}
	}

	public static function getFunctionNameByJSHandler($jshandler) {
		$TA = new TA();
		$TA->addQuery(TA :: SELECT, "ecp_engine_ajax");
		$TA->addParam('functionName');
		$TA->WHERE("`jshandler`='" . $jshandler . "'");
		$TA->LIMIT(1);
		$TA->Execute();
		$func_name = $TA->Result()->FetchObject()->functionName;
		$object = explode("->", $func_name);
		if (sizeof($object) == 2)
			return $object[1];
		else
			return $func_name;
	}

	public static function getJavascript() {
		$content = self :: $tinyajax->getJavaScript();
		return $content;
	}

	public static function drawJavascript() {
		self :: $tinyajax->drawJavaScript(true, false);
	}

	public static function getPostData() {
		if (Ajax :: isClientCall()) {
			if (isset ($_POST['rsargs'])) {
				$rsargs = $_POST['rsargs'];
				if ($rsargs[sizeof($rsargs) - 1] == 'post_data') {
					$encodedPostData = $rsargs[sizeof($rsargs) - 2];
					return TinyAjax :: getPostData($encodedPostData);
				}
			}
		}
		return $_POST;
	}

	public static function Action($behavior) {
		if (!self :: isClientCall()) {
			throw new NoAjaxException;
		}
		self :: $tabsBuffer[] = $behavior;
	}

	public static function ReturnValue($value = false) {
		if (self :: isClientCall()) {
			return self :: $tab->getString();
		} else {
			return $value;
		}
	}
	public static function getActionIdsFromMethod($method) {
		$myMethod = new XCSReflectionMethod($method);
		return self :: getActionIds($myMethod->getLines());
	}
	private static function getActionIds($lines) {
		$ids = array ();

		foreach ($lines as $line) {
			if (false !== strpos($line, "Ajax :: InnerHTMLe('") && false === strpos($line, "//") && false !== strpos($line, "',")) {
				$source = explode("'", $line);
				if (isset ($source[1]))
					$ids[] = $source[1];
			}
		}

		return $ids;

	}
	public static function getActionIdsFromFile($file) {
		return self :: getActionIds(file($file));
	}
	static function generateID($action, $prefix = false) {
		if ($prefix === false)
			$prefix = 'ajax';
		return $prefix . '_' . String :: removeSpecialChars($action, '');
	}
	/**
	 * Sets new $content to automaticaly generated element container.
	 *
	 */
	static function InnerHTMLe($id, $content) {
		if (strpos($id, '$') !== false) {
			if (Renderer :: getFlag('currentModule'))
				$prefix = Renderer :: getFlag('currentModule')->getBase();
			else
				$prefix = false;

			$id = self :: generateID($id, $prefix);
		}
		$id = self :: generateID($id, false);
		self :: Action(TabInnerHTML :: getBehavior($id, $content));
	}
	/**
	 * Sets new $content to element by $id.
	 */
	static function InnerHTML($id, $content) {
		self :: Action(TabInnerHTML :: getBehavior($id, $content));
	}
	static function setValue($id, $content) {
		self :: Action(TabSetValue :: getBehavior($id, $content));
	}
	static function getClientFunction() {
		return self :: $ajaxFunction;
	}
}
?>



See more files for this project here

ECP (EliteCore Project)

EliteCore Project is a PHP5.1/Javascript/AJAX/XHTML/CSS framework for creating WEB 2.0 applications and services.The basic open-source instalation can be also used as an interactive personal page or BLOG.This project uses the latest features available.

Project homepage: http://sourceforge.net/projects/elitecore
Programming language(s): JavaScript,PHP,XML
License: cpl

  debug/
    content.php
  exceptions/
    ajaxflush.php
    nomodule.php
    undefineddata.php
  interface/
    encryption.php
    form.php
    module_class.php
    session_interface.php
  renderers/
    default.php
  sql/
    mysql.php
    mysqli.php
  themes/
    ECP/
      accept.png
      add.png
      alt_star.gif
      anchor.png
      arrow_refresh.png
      asterisk_orange.png
      asterisk_yellow.png
      attach.png
      back.png
      cog_error.png
      cog_go.png
      comment.png
      comment_add.png
      comment_delete.png
      comment_edit.png
      comments.png
      comments_add.png
      comments_delete.png
      control_play_blue.png
      drive.png
      gnome-fs-directory.png
      gnome-mime-audio.png
      layers.png
      layout.png
      layout_add.png
      layout_content.png
      layout_delete.png
      layout_edit.png
      layout_error.png
      layout_header.png
      layout_link.png
      layout_sidebar.png
      lightbulb.png
      lightbulb_add.png
      lightbulb_delete.png
      lightbulb_off.png
      lightning.png
      lightning_add.png
      lightning_delete.png
      lightning_go.png
      link.png
      link_add.png
      link_break.png
      link_delete.png
      link_edit.png
      link_error.png
      link_go.png
      lock.png
      lock_add.png
      lock_break.png
      lock_delete.png
      lock_edit.png
      lock_go.png
      lock_open.png
      newspaper.png
      newspaper_add.png
      newspaper_delete.png
      newspaper_go.png
      newspaper_link.png
      note.gif
      note.png
      note_add.png
      note_delete.gif
      note_delete.png
      note_edit.png
      note_error.png
      note_go.png
      note_new.gif
      overlays.png
      package.png
      package_add.png
      package_delete.png
      package_go.png
      package_green.png
      package_link.png
      page.gif
      page.png
      page_add.png
      page_attach.png
      page_code.png
      page_copy.png
      page_delete.png
      page_edit.png
      page_error.png
      page_excel.png
      page_find.png
      page_gear.png
      page_go.png
      page_green.png
      page_key.png
      page_lightning.png
      page_link.png
      page_paintbrush.png
      page_paste.png
      page_red.png
      page_refresh.png
      page_save.png
      page_white.png
      pencil.png
      pencil_add.png
      pencil_delete.png
      pencil_go.png
      photo.png
      photo_add.png
      photo_delete.png
      photo_link.png
      photos.png
      picture.png
      picture_add.png
      picture_delete.png
      picture_edit.png
      picture_empty.png
      picture_error.png
      picture_go.png
      picture_key.png
      picture_link.png
      picture_save.png
      pictures.png
      plugin.png
      plugin_add.png
      plugin_delete.png
      plugin_disabled.png
      plugin_edit.png
      plugin_error.png
      plugin_go.png
      plugin_link.png
      report.png
      report_add.png
      report_delete.png
      report_disk.png
      report_edit.png
      report_go.png
      report_key.png
      report_link.png
      report_magnify.png
      report_picture.png
      report_user.png
      report_word.png
      script.png
      script_add.png
      script_code.png
      script_code_red.png
      script_delete.png
      script_edit.png
      script_error.png
      script_gear.png
      script_go.png
      script_key.png
      script_lightning.png
      script_link.png
      script_palette.png
      script_save.png
      star.png
      star_rating.gif
      stop.png
      style.png
      text_align_center.png
      text_align_justify.png
      text_align_left.png
      text_align_right.png
      text_allcaps.png
      text_bold.png
      text_columns.png
      text_dropcaps.png
      text_heading_1.png
      text_heading_2.png
      text_heading_3.png
      text_heading_4.png
      text_heading_5.png
      text_heading_6.png
      text_horizontalrule.png
      text_indent.png
      text_indent_remove.png
      text_italic.png
      text_kerning.png
      text_letter_omega.png
      text_letterspacing.png
      text_linespacing.png
      text_list_bullets.png
      text_list_numbers.png
      text_lowercase.png
      text_padding_bottom.png
      text_padding_left.png
      text_padding_right.png
      text_padding_top.png
      text_replace.png
      text_signature.png
      text_smallcaps.png
      text_strikethrough.png
      text_subscript.png
      text_superscript.png
      text_underline.png
      text_uppercase.png
      textfield.png
      textfield_add.png
      textfield_delete.png
      textfield_key.png
      textfield_rename.png
      tux.png
      vert_star.gif
    ECP.xml
  Icon.php
  Location.php
  Module.php
  ModulesManager.php
  MusicTags.php
  Page.php
  XHTMLParser.php
  XMLForms.php
  ajax.php
  author.html
  cache.php
  config.php
  date.php
  db.php
  debug.php
  ecp-full.php
  ecp-mini.php
  engine.php
  events.php
  filesystem.php
  footer.html
  i18n.php
  mailer.php
  main.css
  mcrypt.php
  mime.php
  mod_rewrite.php
  perspective.php
  rc4.php
  reflection.php
  session_passport.php
  storage.php
  string.php
  template.php
  texy.php
  user.php
  user_cache.php
  wysiwyg_texy.php
  xhtml_form.php
  xtea.php