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); } }
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); }