Exemplo n.º 1
0
 /**
  * If cached data exists for $name within $cacheFor, if $return is true, return the cached data, otherwise print it to the output buffer.
  * @param $name String The unique name underwhich the cached data is expected to be stored
  * @param $cacheFor String A string-representation of a point in the past, best expressed in terms of minutes, hours, days, weeks, or months, e.g., "1 minute" or "2 days" - anything that strtotime() can understand.
  * @param $return boolean When true, if cached data is found, that cached data is returned by the function instead of being printed to the output buffer
  * @return When no data is cached under $name or when cached data is older than $cacheFor, returns false; otherwise, returns data according to the value of $return.
  */
 static function cached($name, $cacheFor = 0, $return = false)
 {
     clAPI::trace("Looking for cached content <b>{$name}</b> no older than <b>{$cacheFor}</b>.");
     if (empty($name)) {
         return false;
     }
     if (($content = self::getCacheUnlessIsOldOrDoesNotExist($name, $cacheFor)) === false) {
         if (!$return) {
             self::$currentNameQueue[] = $name;
             ob_start();
         }
         return false;
     } else {
         if ($return) {
             return $content;
         } else {
             echo $content;
             return true;
         }
     }
 }
Exemplo n.º 2
0
 function get($path = null, $limit = null, $forceReturnWrapper = false)
 {
     if ($path) {
         clAPI::trace("Searching for <b>&quot;{$path}&quot;</b>");
     }
     if ($path === null) {
         return $forceReturnWrapper ? $this : $this->__value;
     }
     $node = $this;
     foreach (split('\\/', $path) as $childName) {
         $index = $attribute = null;
         if (preg_match('/^@(.*)?$/', $childName, $matches)) {
             // attribute only
             $childName = null;
             $attribute = $matches[1];
             clAPI::trace("Searching for attribute named {$attribute}");
         } else {
             if (preg_match('/(.*)\\[(\\d+)\\](@(.*))?$/', $childName, $matches)) {
                 // array request with/out attribute
                 $childName = $matches[1];
                 $index = (int) $matches[2];
                 $attribute = isset($matches[4]) ? $matches[4] : null;
                 clAPI::trace("Searching for element <b>{$childName}" . '[' . "{$index}]</b>" . ($attribute ? ", attribute <b>{$attribute}</b>" : ''));
             } else {
                 if (preg_match('/([^@]+)(@(.*))?$/', $childName, $matches)) {
                     // element request with/out attribute
                     $childName = $matches[1];
                     $attribute = isset($matches[3]) ? $matches[3] : null;
                     clAPI::trace("Searching for element <b>{$childName}</b>" . ($attribute ? ", attribute <b>{$attribute}</b>" : ''));
                 }
             }
         }
         if (!$childName && $attribute) {
             /*
             if (!isset($node->__attributes[$attribute])) {
             	clAPI::error("<b>$node->__name</b> does not have an attribute named <b>$attribute</b>");
             	return null;
             }
             */
             return isset($node->__attributes[$attribute]) ? $node->__attributes[$attribute] : null;
         }
         if ($childName && is_array($node)) {
             clAPI::error("You are looking for <b>{$childName}</b> in an array of elements, which isn't possible");
             return null;
         } else {
             if (!isset($node->__children[$childName])) {
                 clAPI::error("{$childName} is not a child of {$node->__name}");
                 return null;
             } else {
                 $node = $node->__children[$childName];
                 if ($index !== null) {
                     if (!is_array($node)) {
                         clAPI::error("{$node->__name} is not an array of elements or {$index} does not exist");
                         return null;
                     } else {
                         $node = $node[$index];
                     }
                 }
                 if ($attribute !== null) {
                     /* this won't work because sometimes feeds just drop the attribute definition... boo.
                     			if (!count($node->__attributes)) {
                     				clAPI::error("$childName does not have any attributes");
                     				return null;
                     			}
                     			
                     			if (!isset($node->__attributes[$attribute])) {
                     				clAPI::error("$node->__name does not have an attribute named $attribute");
                     				return null;
                     			}
                     			*/
                     return isset($node->__attributes[$attribute]) ? $node->__attributes[$attribute] : null;
                 }
             }
         }
     }
     if (is_object($node)) {
         if (!count($node->__children) && !$forceReturnWrapper) {
             return $node->__value;
         } else {
             return $node;
         }
     } else {
         if (is_array($node) && is_numeric($limit)) {
             return array_slice($node, 0, $limit);
         } else {
             return $node;
         }
     }
 }