Beispiel #1
0
/**
* Get the lastest time the folder or one of its descendants has been modified.
* @param string $dir
*    An absolute path to a folder.
* @param int $depth
*    0 for current folder only, 1 for current and children, n (>1) for descandants until the given limit, -1 for all descendants.
*/
function get_folder_last_modified($dir, $depth = 0)
{
    $mtime = filemtime($dir);
    if ($depth != 0) {
        // scan directory for last modified descandant folder
        if ($dh = @opendir($dir)) {
            while (($entry = readdir($dh)) !== false) {
                if ($entry != '.' && $entry != '..' && is_dir($dir . DIRECTORY_SEPARATOR . $entry)) {
                    $mtime = max($mtime, get_folder_last_modified($dir . DIRECTORY_SEPARATOR . $entry, $depth - 1));
                }
            }
            closedir($dh);
        }
    }
    return $mtime;
}
Beispiel #2
0
 /**
  * Fetches cached content for the specified directory and parameters.
  * @param string $imagebase
  *    Base for computing image folder hash, typically an absolute file system path to the image or the directory where the images reside.
  * @param $params
  *    Parameters that affect how the gallery is to be displayed.
  */
 public function getCachedContent($imagebase, SIGPlusGalleryParameters $params)
 {
     if ($this->config->contentcache) {
         // use cache folder
         $cachekey = $this->getCacheKey($imagebase, $params);
         $cachefile = $this->getCachedContentPath($cachekey, $params->linkage == 'inline' ? '.html' : '.js');
         if (is_file($cachefile)) {
             // content available in cache only if cache file exists
             if (is_remote_path($imagebase)) {
                 return $cachekey;
             } elseif (is_dir($imagebase)) {
                 // check if directory or labels file has changed
                 $labelsfile = $this->getLabelsFilePath($imagebase, $params->labels);
                 if (filemtime($cachefile) >= get_folder_last_modified($imagebase, $params->depth) && ($labelsfile === false || filemtime($cachefile) >= filemtime($labelsfile))) {
                     return $cachekey;
                 }
             } elseif (is_file($imagebase)) {
                 // check if file has changed
                 if (filemtime($cachefile) >= filemtime($imagebase)) {
                     return $cachekey;
                 }
             }
         }
     }
     return false;
 }