Example #1
0
 function RunModule()
 {
     $uuid = $this->GetUUID();
     if (is_array($uuid)) {
         $uuid = reset($uuid);
     }
     $sections = utopia::GetRewriteURL();
     $sections = preg_replace('/^' . preg_quote($uuid, '/') . '\\/?/', '', $sections);
     // shift uuid off the start
     if (!$sections) {
         utopia::PageNotFound();
     }
     $path = urldecode(PATH_UPLOADS . '/' . $sections);
     $path = parse_url($path, PHP_URL_PATH);
     $path = realpath($path);
     if (stripos($path, PATH_UPLOADS) === FALSE || !file_exists($path)) {
         utopia::PageNotFound();
     }
     utopia::CancelTemplate();
     $cType = utopia::GetMimeType($path);
     $fileName = pathinfo($path, PATHINFO_BASENAME);
     $fileMod = filemtime($path);
     $fileSize = filesize($path);
     $w = isset($_GET['w']) ? $_GET['w'] : NULL;
     $h = isset($_GET['h']) ? $_GET['h'] : NULL;
     if (stripos($cType, 'image/') !== FALSE && ($w || $h)) {
         $idents = array($_SERVER['REQUEST_URI'], $fileMod, $fileSize, $w, $h);
         $etag = utopia::checksum($idents);
         utopia::Cache_Check($etag, $cType, $fileName);
         $cacheFile = uCache::retrieve($idents);
         if ($cacheFile) {
             $output = file_get_contents($cacheFile);
         } else {
             $output = file_get_contents($path);
         }
         // check w and h
         $img = imagecreatefromstring($output);
         $img = utopia::constrainImage($img, $w, $h);
         $ext = pathinfo($path, PATHINFO_EXTENSION);
         ob_start();
         if (function_exists(strtolower("image{$ext}"))) {
             call_user_func("image{$ext}", $img);
         } else {
             imagepng($img);
             $cType = 'image/png';
             $fileName = str_replace(".{$ext}", '.png', $fileName);
         }
         $output = ob_get_clean();
         imagedestroy($img);
         // only need to cache the resized versions
         uCache::store($idents, $output);
         utopia::Cache_Output($output, $etag, $cType, $fileName);
     } else {
         header('Content-Type: ' . $cType);
         self::resumableOutput($path);
     }
 }
Example #2
0
 function RunModule()
 {
     if (!isset($_REQUEST['module']) || !class_exists($_REQUEST['module']) || !isset($_REQUEST['pk']) || !isset($_REQUEST['field'])) {
         utopia::PageNotFound();
     }
     $obj = utopia::GetInstance($_REQUEST['module']);
     try {
         $rec = $obj->LookupRecord($_REQUEST['pk'], true);
     } catch (Exception $e) {
         utopia::PageNotFound();
     }
     if (!$rec || !isset($rec[$_REQUEST['field']])) {
         utopia::PageNotFound();
     }
     utopia::CancelTemplate();
     $data = $rec[$_REQUEST['field']];
     $table = $obj->fields[$_REQUEST['field']]['vtable']['tModule'];
     $tableField = $obj->fields[$_REQUEST['field']]['field'];
     $fieldType = $obj->GetFieldType($_REQUEST['field']);
     $filename = isset($_REQUEST['filename']) ? $_REQUEST['filename'] : $rec[$_REQUEST['field'] . '_filename'];
     $filetype = $rec[$_REQUEST['field'] . '_filetype'];
     $width = isset($_GET['w']) ? $_GET['w'] : NULL;
     $height = isset($_GET['h']) ? $_GET['h'] : NULL;
     $isImg = preg_match('/^image\\//', $filetype);
     if ($isImg && ($width || $height)) {
         $filetype = 'image/png';
     }
     $idents = array($table, $tableField, strlen($data), $width, $height, $isImg);
     $etag = utopia::checksum($idents);
     $attach = 'inline';
     if (isset($_REQUEST['attach'])) {
         $attach = $_REQUEST['attach'];
     }
     utopia::Cache_Check($etag, $filetype, $filename, 0, 2592000, $attach);
     $cacheFile = uCache::retrieve($idents);
     if ($cacheFile) {
         $data = file_get_contents($cacheFile);
     }
     if ($isImg && ($width || $height) && $cacheFile === FALSE) {
         $src = imagecreatefromstring($data);
         $img = utopia::constrainImage($src, $width, $height);
         //    Image output
         ob_start();
         imagepng($img);
         imagedestroy($img);
         $data = ob_get_clean();
         // only need to cache the resized versions
         uCache::store($idents, $data);
     }
     utopia::Cache_Output($data, $etag, $filetype, $filename, 0, 2592000, $attach);
 }
Example #3
0
 public static function addChecksum($table, $checksum)
 {
     self::initChecksums();
     self::$tableChecksum[$table] = $checksum;
     $file = '';
     foreach (self::$tableChecksum as $k => $v) {
         $file .= $k . ' = ' . $v . PHP_EOL;
     }
     uCache::store('__table_checksum', $file);
 }
Example #4
0
 public function RunModule()
 {
     utopia::CancelTemplate();
     clearstatcache();
     $uStr = '';
     self::$includeFiles = array_unique(self::$includeFiles);
     foreach (self::$includeFiles as $filename) {
         //does it exist?
         if (!file_exists($filename)) {
             continue;
         }
         $uStr .= $filename . filemtime($filename) . '-' . filesize($filename);
     }
     $identifiers = array($_SERVER['REQUEST_URI'], $uStr, count(self::$includeFiles), PATH_REL_CORE);
     $etag = utopia::checksum($identifiers);
     utopia::Cache_Check($etag, 'text/css', $this->GetUUID());
     $out = uCache::retrieve($identifiers);
     if ($out) {
         $out = file_get_contents($out);
     } else {
         $out = self::BuildCSS(true);
         uCache::store($identifiers, $out);
     }
     utopia::Cache_Output($out, $etag, 'text/css', $this->GetUUID());
 }
Example #5
0
 public function RunModule()
 {
     utopia::CancelTemplate();
     clearstatcache();
     $uStr = '';
     foreach (self::$includeFiles as $info) {
         if (!file_exists($info['path'])) {
             continue;
         }
         $uStr .= $info['path'] . filemtime($info['path']) . '-' . filesize($info['path']);
     }
     $identifiers = array($_SERVER['REQUEST_URI'], $uStr, self::$includeFiles, self::GetJavascriptConstants(), self::$includeText, PATH_REL_CORE);
     $etag = utopia::checksum($identifiers);
     utopia::Cache_Check($etag, 'text/javascript', $this->GetUUID());
     $out = uCache::retrieve($identifiers);
     if ($out) {
         $out = file_get_contents($out);
     } else {
         $out = self::BuildJavascript(true);
         uCache::store($identifiers, $out);
     }
     utopia::Cache_Output($out, $etag, 'text/javascript', $this->GetUUID());
 }