Ejemplo n.º 1
0
 /** static, this places the icon into the www/tmp, so that you can refer to
     it with <img src=, returns true if there is an icon for this object */
 function cacheIcon($id)
 {
     global $cachedir;
     $cacheTimeout = 2 * 60;
     // 2 minutes
     if (!$id) {
         raiseError("missing id");
     }
     $fname = "{$cachedir}/" . $id . '.png';
     if (is_readable($fname)) {
         $stat = stat($fname);
         if (time() - $stat['mtime'] <= $cacheTimeout) {
             return true;
         }
     }
     $icon = sotf_Blob::findBlob($id, 'icon');
     if (!$icon) {
         return false;
     }
     // TODO: cache cleanup!
     ////debug("cache: ". filesize($fname) ."==" . strlen($icon));
     if (is_readable($fname) && filesize($fname) == strlen($icon)) {
         return true;
     }
     debug("cached icon for", $id);
     sotf_Utils::save($fname, $icon);
     return true;
 }
 /** Gets icon of the thing. Returns binary string containing the logo. */
 function getIcon()
 {
     return sotf_Blob::findBlob($this->id, 'icon');
 }
Ejemplo n.º 3
0
 /** static, this places the icon into the www/tmp, so that you can refer to
     it with <img src=, returns true if there is an icon for this object */
 function cacheIcon($id)
 {
     global $config;
     $cacheTimeout = 10 * 60;
     // 10 minutes
     if (!$id) {
         raiseError("missing id");
     }
     $fname = $config['cacheDir'] . "/" . $id . '.png';
     if (is_readable($fname)) {
         $stat = stat($fname);
         if (time() - $stat['mtime'] <= $cacheTimeout) {
             return true;
         } else {
             debug("cached icon of {$id} expired");
             if (!unlink($fname)) {
                 clearstatcache();
                 if (file_exists($fname)) {
                     logError("Could not delete {$fname}");
                 }
             }
         }
     }
     $icon = sotf_Blob::findBlob($id, 'icon');
     if (!$icon) {
         return false;
     }
     debug("cached icon of {$id} for ", $forId);
     sotf_Utils::save($fname, $icon);
     return true;
 }