/** * Right handler routed * * handles chain call $ajax->someApi->uploader(); * * @param unknown_type $value */ function callbackHandler($sender, $receiver, $setting) { switch ($setting) { case 'postCallback': $event = CoreEvents::$cache[$receiver->id]; $callback = CoreEvents::$cache[$sender->id]; $event['postCallback'][$sender->id] = $callback; $sender->delete(); $callbacks = CoreEvents::processScache($event['postCallback']); $callbacks = CoreEvents::mkArray($callbacks, 'json', true); $event['postCallback'] = "<cjax>{$callbacks}</cjax>"; CoreEvents::$cache[$receiver->id] = $event; CoreEvents::simpleCommit(); break; } }
/** * CJAX is bein called from within a child directory then you will need to specify * the url where CJAX is located (eg. http://yoursite.com/cjax) * * @param string $Path [CJAX URL] */ function path($path) { self::$path = $path; }
/** * * Updates parameters using plugin class */ public function set($setting, $value, $instance_id = null) { if (plugin::isAborted($this->loading)) { return; } $params = range('a', 'z'); if (!in_array($setting, $params)) { return $this->setVar($setting, $value); } if (!is_null($instance_id)) { $item = CoreEvents::$cache[$instance_id]; $item['data'][$setting] = $value; CoreEvents::UpdateCache($instance_id, $item); } else { if (!isset(self::$_instances_ids[$this->loading])) { return; } $instances = self::$_instances_ids[$this->loading]; if (!$instances) { return false; } if (count($instances) == 1) { return $this->set($setting, $value, implode($instances)); } foreach ($instances as $v) { $this->set($setting, $value, $v); } } }
protected function _response($response) { if ($response && (is_array($response) || is_object($response))) { header('Content-type: application/json; charset=utf-8'); print CoreEvents::json_encode($response); } }
public function flush() { CoreEvents::$lastCache = array(); CoreEvents::$cache = array(); }
/** * Advanced Callback Handler * * Pushes an API to be a part of another API or Plugin instead of running on its own, * then you may access that other callback in plugins through this.callback * * If your rightHandler is a callback, you may create a custom handler for that callback, * mainly micmic the functionality in core/classes/xmlItem.php on function __set() case 'callback' * * */ function callbackHandler($xmlObj_from, $xmlObj_to, $setting) { $event = CoreEvents::$cache[$xmlObj_from->id]; $callback = CoreEvents::$cache[$xmlObj_to->id]; //pusha a copy of the API as callback $event['callback'][$xmlObj_from->id] = $callback; //deletes the API $xmlObj_from->delete(); //process //do changes to $event //push changes CoreEvents::$cache[$xmlObj_to->id] = $event; //commit changes CoreEvents::simpleCommit(); return true; }
function delete() { if (!is_null($this->id)) { CoreEvents::removeExecCache($this->id); } }
/** * get an instance of CJAX * with singleton pattern * @return CJAX_FRAMEWORK OBJECT */ public static function getInstance() { if (self::$CJAX) { return self::$CJAX; } CoreEvents::errorHandlingConfig(); $ajax = new CJAX_FRAMEWORK(); if (!defined('JSON_FORCE_OBJECT')) { define('JSON_FORCE_OBJECT', 16); } if (!isset($ajax->format) || !$ajax->format) { $ajax->format = new cjaxFormat(); $config = new ext(); if (file_exists($f = CJAX_HOME . '/' . 'config.php')) { include $f; if (isset($config)) { $config = new ext($config); } } $ajax->config = $config; $ajax->initiate($ajax); if (!$ajax->isAjaxRequest()) { //$ajax->flushCache(); if (defined('AJAX_CD')) { @setcookie('AJAX_CD', AJAX_CD, null, '/'); } else { //@setcookie ('AJAX_CD', null, time()-(3600*1000),'/'); } } else { if (isset($_COOKIE['AJAX_CD']) && !defined('AJAX_CD')) { define('AJAX_CD', $_COOKIE['AJAX_CD']); } if (!function_exists('cleanInput')) { function cleanInput($input) { return $input; } } } } if ($ajax->config->camelize === null) { if (version_compare($ajax->version, '>', '5.0-RC2')) { $ajax->config->camelize = true; } } if ($ajax->config->ip_debug) { if (is_array($ajax->config->ip_debug)) { if (in_array(@$_SERVER['REMOTE_ADDR'], $ajax->config->ip_debug)) { $ajax->config->ip_debug = false; } } else { if (@$_SERVER['REMOTE_ADDR'] != $ajax->config->ip_debug) { $ajax->config->ip_debug = false; } } } if ($ajax->config->caching) { if (isset($_SERVER['REQUEST_URI'])) { $ajax->crc32 = crc32($_SERVER['REQUEST_URI']); $cache = $ajax->readCache('cjax-' . $ajax->crc32); $ajax->caching = $cache; } } if ($ajax->config->debug) { @ini_set('display_errors', 1); @ini_set('log_errors', 1); } if (!($js_dir = $ajax->config->js_path)) { if (@is_dir('cjax/')) { $js_dir = "cjax/core/js/"; } else { if (@is_dir('core/js/')) { $js_dir = "core/js/"; } else { if (@is_dir('../cjax')) { $js_dir = "../cjax/core/js/"; } else { if (@is_dir('../../cjax')) { $js_dir = "../../cjax/core/js/"; } else { if (@is_dir('../../../cjax')) { $js_dir = "../../../cjax/core/js/"; } else { die("Cannot find the correct path to Js directory."); } } } } } $error = error_get_last(); if ($error && preg_match('%.*(open_basedir).*File\\(([^\\)]+)%', $error['message'], $match)) { die(sprintf('Restriction <b>open_basedir</b> is turned on. File or directory %s will not be accessible while this setting is on due to security directory range.', $match[2])); } } $ajax->js($js_dir); return self::$CJAX = $ajax; }
/** * Bind events to elements * * @param $selector * @param $actions * @param $event */ function Exec($selector, $actions, $event = "click") { if (!self::getCache()) { return false; } if (is_array($selector)) { $selector = implode('|', $selector); } if ($event) { if (substr($event, 0, 2) != "on" && $event != 'click') { $event = "on{$event}"; } $this->event = $event; } $_actions = array(); if ($actions && is_array($actions)) { $cache = CoreEvents::$cache; foreach ($actions as $k => $v) { if (is_object($v) && (is_a($v, 'xmlItem') || is_a($v, 'plugin'))) { if (is_a($v, 'plugin')) { $v->element_id = $selector; $v->xml->element_id = $selector; if (method_exists($v, 'onEvent')) { call_user_method('onEvent', $v, $selector); } } $_actions[$v->id] = $v->xml(); if (isset(CoreEvents::$callbacks[$v->id]) && CoreEvents::$callbacks[$v->id]) { $_actions[$v->id]['callback'] = CoreEvents::processScache(CoreEvents::$callbacks[$v->id]); $_actions[$v->id]['callback'] = CoreEvents::mkArray($v[$v->id], 'json', true); } $v->delete(); } else { if (is_object($v)) { //some functions return the ajax object? continue; } $_actions[$v] = CoreEvents::$cache[$v]; unset(CoreEvents::$cache[$v]); } } return $this->AddEventTo($selector, $_actions, $event); } if (is_a($actions, 'xmlItem') || is_a($actions, 'plugin')) { if (is_a($actions, 'plugin')) { $actions->element_id = $selector; $actions->xml->element_id = $selector; if (method_exists($actions, 'onEvent')) { call_user_method('onEvent', $actions, $selector); } } $item = $actions->xml(); $item['event'] = $event; if (isset(CoreEvents::$callbacks[$actions->id]) && CoreEvents::$callbacks[$actions->id]) { $item['callback'] = CoreEvents::processScache(CoreEvents::$callbacks[$actions->id]); $item['callback'] = CoreEvents::mkArray($item['callback'], 'json', true); } $actions->delete(); return $this->AddEventTo($selector, array($actions->id => $item), $event); } else { $_actions = CoreEvents::$cache[$actions]; $_actions['event'] = $event; $this->removeLastCache(1); return $this->AddEventTo($selector, array($actions => $_actions), $event); } }