/** * This function is very useful to use with clients like PhoneGap which can * intercept URLs and load whatever locally cached files are stored in their bundle. * The urls for these files will be relative to the cache base url. * (See Q_Uri::cacheBaseUrl function). * In this case, the client is supposed to send the timestamp of when the * cache it is using was generated. * This function checks the current contents of the Q/config/Q/urls.php file, * generated by scripts/Q/urls.php script. * If the url's timestamp there is newer than the Q_Request::cacheTimestamp() * (which the client can set by setting the 'Q_ct' field in the querystring) * then that means the server has a newer version of the file, so the passed * $url is used instead. * Otherwise, the url relative to cacheBaseUrl is used, making the client * load the locally cached version. */ static function cachedUrl($url) { $timestamp = Q_Request::cacheTimestamp(); if (empty($timestamp)) { return $url; } $urlRelativeToBase = substr($url, strlen(Q_Request::baseUrl())); $fileTimestamp = isset(Q_Uri::$urls[$urlRelativeToBase]) ? Q_Uri::$urls[$urlRelativeToBase] : null; if (isset($fileTimestamp) and $fileTimestamp <= $timestamp and self::$cacheBaseUrl) { return self::$cacheBaseUrl . $urlRelativeToBase; } return $url; }
/** * This function is very useful to use with clients like PhoneGap which can * intercept URLs and load whatever locally cached files are stored in their bundle. * The urls for these files will be relative to the cache base url. * (See Q_Uri::cacheBaseUrl function). * In this case, the client is supposed to send the timestamp of when the * cache it is using was generated. * This function checks the current contents of the Q/config/Q/urls.php file, * generated by scripts/Q/urls.php script. * If the url's timestamp there is newer than the Q_Request::cacheTimestamp() * (which the client can set by setting the 'Q_ct' field in the querystring) * then that means the server has a newer version of the file, so the passed * $url is used instead. * Otherwise, the url relative to cacheBaseUrl is used, making the client * load the locally cached version. */ static function cachedUrl($url) { $timestamp = Q_Request::cacheTimestamp(); if (empty($timestamp)) { return $url; } $urlRelativeToBase = substr($url, strlen(Q_Request::baseUrl(false, true))); $parts = explode('/', $urlRelativeToBase); $parts[] = null; $tree = new Q_Tree(Q_Uri::$urls); $fileTimestamp = call_user_func_array(array($tree, 'get'), $parts); if (isset($fileTimestamp) and $fileTimestamp <= $timestamp and self::$cacheBaseUrl) { return self::$cacheBaseUrl . $urlRelativeToBase; } return $url; }