Exemplo n.º 1
0
 /**
  *
  * @access	public
  *
  * @return	bool
  *
  */
 public static function notifyObservers($event = 'default', $arg = null, $className = 'XOAD_Observable')
 {
     if (empty($GLOBALS['_XOAD_OBSERVERS'])) {
         return true;
     }
     $globalObservers =& $GLOBALS['_XOAD_OBSERVERS'];
     $className = strtolower($className);
     if (empty($globalObservers[$className])) {
         return true;
     }
     $returnValue = true;
     foreach ($globalObservers[$className] as $observer) {
         $eventValue = $observer->updateObserver($event, $arg);
         if (XOAD_Utilities::getType($eventValue) == 'bool') {
             $returnValue &= $eventValue;
         }
     }
     return $returnValue;
 }
Exemplo n.º 2
0
 /**
  *
  * @access	public
  *
  * @return	void
  *
  */
 public function setMethodsMap($methodsMap)
 {
     $methodsMapType = XOAD_Utilities::getType($methodsMap);
     if ($methodsMapType == 'string') {
         $this->methodsMap = array(XOAD_Utilities::caseConvert($methodsMap) => $methodsMap);
     } else {
         if ($methodsMapType == 's_array' || $methodsMapType == 'a_array') {
             $map = array();
             foreach ($methodsMap as $method) {
                 $map[XOAD_Utilities::caseConvert($method)] = $method;
             }
             $this->methodsMap = $map;
         } else {
             $this->methodsMap = null;
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Registers a custom client control.
  *
  * <p>Each control includes a JS file that defines the class that
  * will handle the control. Additionally, you can attach a server class and
  * a HTML code.</p>
  *
  * @access	public
  *
  * @param	string	$tagPrefix	The tag prefix for the control, required.
  * @param	mixed	$tagName	The tag name for the control, required.
  * @param	string	$jsFile		The relative path to the JS file that
  * 								defines the class that will handle the
  * 								control, required.
  * @param	string	$phpFile	The relative/absolute path to the PHP file
  * 								that defines the server class that is
  * 								associated with the control, optional.
  * @param	string	$url		The callback URL for the server class,
  * 								optional.
  * @param	string	$htmlFile	The relative/absolute path to the HTML file
  * 								that defines the code that is associated
  * 								with the control, optional.
  *
  * @return	string	HTML code to register the custom control.
  *
  * @static
  *
  */
 public static function register($tagPrefix = 'xoad', $tagName = null, $jsFile = null, $phpFile = null, $url = null, $htmlFile = null)
 {
     if (empty($phpFile) && empty($jsFile)) {
         return null;
     }
     if (XOAD_Utilities::getType($tagName) == 's_array') {
         $returnValue = '';
         foreach ($tagName as $name) {
             $returnValue .= XOAD_Controls::register($tagPrefix, $name, $jsFile, $phpFile, $url, $htmlFile);
         }
         return $returnValue;
     }
     if (XOAD_Utilities::getType($tagName) == 'a_array') {
         $returnValue = '';
         foreach ($tagName as $prefix => $name) {
             $returnValue .= XOAD_Controls::register($prefix, $name, $jsFile, $phpFile, $url, $htmlFile);
         }
         return $returnValue;
     }
     if (empty($tagPrefix) || empty($tagName)) {
         return null;
     }
     $registerAttribute = $tagName == '@';
     $controlName = strtolower($tagPrefix) . ':' . strtolower($tagName);
     if (!$registerAttribute && in_array($controlName, $GLOBALS['_XOAD_CONTROLS_LIST'])) {
         return null;
     }
     $phpControlName = $tagPrefix . '_Controls_' . $tagName;
     $jsControlName = $tagPrefix . '.controls.' . $tagName;
     $includeScript = '';
     $returnValue = '';
     if (!empty($phpFile)) {
         require_once XOAD_Controls::getFileName($phpFile);
         if (empty($url)) {
             $url = XOAD_Utilities::getRequestUrl();
         }
         $phpObject = new $phpControlName();
         XOAD_Client::privateMethods($phpObject, array('getJSCode', 'getHtmlCode'));
         $returnValue .= XOAD_Client::register($phpControlName, $url) . ';';
     }
     if (!empty($jsFile)) {
         if (!in_array($jsFile, $GLOBALS['_XOAD_CONTROLS_SCRIPT'])) {
             $includeScript .= '<script type="text/javascript" src="' . htmlspecialchars($jsFile) . '"></script>';
             $GLOBALS['_XOAD_CONTROLS_SCRIPT'][] = $jsFile;
         }
     } else {
         if (isset($phpObject) && method_exists($phpObject, 'getJSCode')) {
             $returnValue .= $phpObject->getJSCode($jsControlName, $phpControlName);
         }
     }
     $controlHtml = null;
     if (!empty($htmlFile)) {
         $controlHtml = @join(null, @file(XOAD_Controls::getFileName($htmlFile)));
     } else {
         if (isset($phpObject) && method_exists($phpObject, 'getHtmlCode')) {
             $controlHtml = $phpObject->getHtmlCode($jsControlName, $phpControlName);
         }
     }
     if (!$registerAttribute) {
         $returnValue .= 'xoad.controls.list[' . sizeof($GLOBALS['_XOAD_CONTROLS_LIST']) . '] = {';
         $returnValue .= 'tagName:' . XOAD_Client::register($controlName);
         if (!empty($jsFile)) {
             $returnValue .= ',clientClass:' . XOAD_Client::register($jsControlName);
         }
         if (!empty($phpFile)) {
             $returnValue .= ',serverClass:' . XOAD_Client::register($phpControlName);
         }
         if (!empty($controlHtml)) {
             $returnValue .= ',html:' . XOAD_Client::register($controlHtml);
         }
         $returnValue .= '};';
     }
     if (!empty($returnValue)) {
         $returnValue = '<script type="text/javascript">' . $returnValue . '</script>';
     }
     $returnValue = $includeScript . $returnValue;
     $GLOBALS['_XOAD_CONTROLS_LIST'][] = $controlName;
     return $returnValue;
 }
Exemplo n.º 4
0
 /**
  * Assigns methods map to the class meta data.
  *
  * @param	object	$var		The object where the meta data is stored.
  *
  * @param	array	$methodsMap	The class methods map.
  *
  * @return	void
  *
  * @static
  *
  */
 public static function mapMethods(&$var, $methodsMap)
 {
     if (XOAD_Utilities::getType($var) != 'object') {
         return false;
     }
     if (!isset($var->xoadMeta)) {
         require_once XOAD_BASE . '/classes/Meta.class.php';
         $var->xoadMeta = new XOAD_Meta();
     }
     $var->xoadMeta->setMethodsMap($methodsMap);
     return true;
 }
Exemplo n.º 5
0
 /**
  * This method should be called from each successor to add
  * common data to the event.
  *
  * <p>When you call this method you should pass an associative
  * array that contains the event data. This method will populate
  * it with the missing information and will check the validity of
  * the presented.</p>
  *
  * @access	public
  *
  * @return	bool	true on success, false otherwise
  *
  */
 public function postMultipleEvents(&$event)
 {
     if (!isset($event['time']) || $event['time'] === null) {
         $event['time'] = XOAD_Utilities::getMicroTime();
     }
     if (!isset($event['lifetime']) || $event['lifetime'] === null) {
         $event['lifetime'] = XOAD_EVENTS_LIFETIME;
     }
     if (isset($event['sender']) && $event['sender'] !== null) {
         if (XOAD_Utilities::getType($event['sender']) != 'object') {
             return false;
         }
         if (strcasecmp($event['className'], get_class($event['sender'])) != 0) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 6
0
 /**
  * Adds specified classes to the denied classes map.
  *
  * <p>Example:</p>
  * <code>
  * <?php
  *
  * class AllowedClass
  * {
  * 	function call() { return 'AllowedClass->call()'; }
  * }
  *
  * class DeniedClass
  * {
  * 	function call() { return 'DeniedClass->call()'; }
  * }
  *
  * require_once('xoad.php');
  *
  * XOAD_Server::denyClasses('DeniedClass');
  *
  * if (XOAD_Server::runServer()) {
  *
  * 	exit;
  * }
  *
  * ?>
  * <?= XOAD_Utilities::header() ?>
  *
  * <script type="text/javascript">
  *
  * var allowedClass = <?= XOAD_Client::register(new AllowedClass()) ?>;
  *
  * var deniedClass = <?= XOAD_Client::register(new DeniedClass()) ?>;
  *
  * alert(allowedClass.call());
  *
  * // This line will throw an exception.
  * // DeniedClass is in the denied classes list.
  * alert(deniedClass.call());
  *
  * </script>
  * </code>
  *
  * @access	public
  *
  * @param	mixed	$classes	The classes that can NOT be accessed
  *								within a callback request.
  *
  * @return	void
  *
  * @static
  *
  */
 public static function denyClasses($classes)
 {
     $classesType = XOAD_Utilities::getType($classes);
     if (!isset($GLOBALS['_XOAD_SERVER_DENIED_CLASSES'])) {
         $GLOBALS['_XOAD_SERVER_DENIED_CLASSES'] = array();
     }
     $deniedClasses =& $GLOBALS['_XOAD_SERVER_DENIED_CLASSES'];
     if ($classesType == 'string') {
         $deniedClasses[] = strtolower($classes);
     } else {
         if ($classesType == 's_array' || $classesType == 'a_array') {
             foreach ($classes as $class) {
                 $deniedClasses[] = strtolower($class);
             }
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Serializes a PHP variable into a {@link http://www.json.org JSON} string.
  *
  * <p>Example:</p>
  * <code>
  * <script type="text/javascript">
  * <?php require_once('xoad.php'); ?>
  *
  * var arr = <?= XOAD_Serializer::serialize(array(1, 2, "string", array("Nested"))) ?>;
  *
  * alert(arr);
  *
  * </script>
  * </code>
  *
  * @access	public
  *
  * @param	mixed	$var	Variable to serialize.
  *
  * @return	string	{@link http://www.json.org JSON} string that
  *					represents the variable.
  *
  * @static
  *
  */
 public static function serialize(&$var)
 {
     $type = XOAD_Utilities::getType($var);
     if ($type == 'bool') {
         if ($var) {
             return "true";
         } else {
             return "false";
         }
     } else {
         if ($type == 'int') {
             return sprintf('%d', $var);
         } else {
             if ($type == 'float') {
                 return sprintf('%f', $var);
             } else {
                 if ($type == 'string') {
                     if (strlen($var) >= strlen(XOAD_SERIALIZER_SKIP_STRING)) {
                         if (strcasecmp(substr($var, 0, strlen(XOAD_SERIALIZER_SKIP_STRING)), XOAD_SERIALIZER_SKIP_STRING) == 0) {
                             return substr($var, strlen(XOAD_SERIALIZER_SKIP_STRING), strlen($var) - strlen(XOAD_SERIALIZER_SKIP_STRING));
                         }
                     }
                     // This code is based on morris_hirsch's
                     // comment in utf8_decode function documentation.
                     //
                     // http://bg.php.net/utf8_decode
                     //
                     // Thank you.
                     //
                     $ascii = '';
                     $length = strlen($var);
                     for ($iterator = 0; $iterator < $length; $iterator++) {
                         $char = $var[$iterator];
                         $charCode = ord($char);
                         if ($charCode == 0x8) {
                             $ascii .= '\\b';
                         } else {
                             if ($charCode == 0x9) {
                                 $ascii .= '\\t';
                             } else {
                                 if ($charCode == 0xa) {
                                     $ascii .= '\\n';
                                 } else {
                                     if ($charCode == 0xc) {
                                         $ascii .= '\\f';
                                     } else {
                                         if ($charCode == 0xd) {
                                             $ascii .= '\\r';
                                         } else {
                                             if ($charCode == 0x22 || $charCode == 0x2f || $charCode == 0x5c) {
                                                 $ascii .= '\\' . $var[$iterator];
                                             } else {
                                                 if ($charCode < 128) {
                                                     $ascii .= $char;
                                                 } else {
                                                     if ($charCode >> 5 == 6) {
                                                         $byteOne = $charCode & 31;
                                                         $iterator++;
                                                         $char = $var[$iterator];
                                                         $charCode = ord($char);
                                                         $byteTwo = $charCode & 63;
                                                         $charCode = $byteOne * 64 + $byteTwo;
                                                         $ascii .= sprintf('\\u%04s', dechex($charCode));
                                                     } else {
                                                         if ($charCode >> 4 == 14) {
                                                             $byteOne = $charCode & 31;
                                                             $iterator++;
                                                             $char = $var[$iterator];
                                                             $charCode = ord($char);
                                                             $byteTwo = $charCode & 63;
                                                             $iterator++;
                                                             $char = $var[$iterator];
                                                             $charCode = ord($char);
                                                             $byteThree = $charCode & 63;
                                                             $charCode = ($byteOne * 64 + $byteTwo) * 64 + $byteThree;
                                                             $ascii .= sprintf('\\u%04s', dechex($charCode));
                                                         } else {
                                                             if ($charCode >> 3 == 30) {
                                                                 $byteOne = $charCode & 31;
                                                                 $iterator++;
                                                                 $char = $var[$iterator];
                                                                 $charCode = ord($char);
                                                                 $byteTwo = $charCode & 63;
                                                                 $iterator++;
                                                                 $char = $var[$iterator];
                                                                 $charCode = ord($char);
                                                                 $byteThree = $charCode & 63;
                                                                 $iterator++;
                                                                 $char = $var[$iterator];
                                                                 $charCode = ord($char);
                                                                 $byteFour = $charCode & 63;
                                                                 $charCode = (($byteOne * 64 + $byteTwo) * 64 + $byteThree) * 64 + $byteFour;
                                                                 $ascii .= sprintf('\\u%04s', dechex($charCode));
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     return '"' . $ascii . '"';
                 } else {
                     if ($type == 's_array') {
                         $index = 0;
                         $length = sizeof($var);
                         $returnValue = '[';
                         foreach ($var as $value) {
                             $returnValue .= XOAD_Serializer::serialize($value);
                             if ($index < $length - 1) {
                                 $returnValue .= ',';
                             }
                             $index++;
                         }
                         $returnValue .= ']';
                         return $returnValue;
                     } else {
                         if ($type == 'a_array') {
                             $index = 0;
                             $length = sizeof($var);
                             $returnValue = '{';
                             foreach ($var as $key => $value) {
                                 $returnValue .= XOAD_Serializer::serialize($key);
                                 $returnValue .= ':';
                                 $returnValue .= XOAD_Serializer::serialize($value);
                                 if ($index < $length - 1) {
                                     $returnValue .= ',';
                                 }
                                 $index++;
                             }
                             $returnValue .= '}';
                             return $returnValue;
                         } else {
                             if ($type == 'object') {
                                 $objectVars = get_object_vars($var);
                                 return XOAD_Serializer::serialize($objectVars);
                             }
                         }
                     }
                 }
             }
         }
     }
     return "null";
 }