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); } }
/** * Get path to cache file * * @param $identifiers Unique information about this data, used to generate hash * @return absolute path to cache file */ private static function getPath($identifiers) { $cachePath = PATH_ABS_CORE . '.cache/'; $checksum = utopia::checksum($identifiers); $cachePath .= substr($checksum, 0, 3) . '/' . substr($checksum, 3, 3) . '/'; if (!file_exists($cachePath)) { mkdir($cachePath, 0777, true); } return $cachePath . $checksum; }
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); }
public function AssertTable() { if ($this->isDisabled) { return; } if ($this->isInitialised === TRUE) { return false; } $this->isInitialised = true; $this->_SetupFields(); if (empty($this->fields)) { return; } if (!$this->engine) { $this->engine = MYSQL_ENGINE; } $oldTable = isset($this->tablename) ? $this->tablename : NULL; $this->tablename = TABLE_PREFIX . get_class($this); // checksum $tableExists = self::TableExists($this->tablename); $renamed = false; if (!$tableExists && $oldTable && self::TableExists($oldTable)) { $stm = database::query('RENAME TABLE `' . $oldTable . '` TO `' . $this->tablename . '`'); $tableExists = $stm->rowCount ? true : false; $renamed = true; } $checksum = utopia::checksum(array($oldTable, $this->tablename, $this->engine, $this->fields, $this->primary, $this->unique, $this->index, $this->customscript)); if (!$tableExists) { // create table try { $this->CreateTable(); } catch (Exception $e) { if ($e->getCode() == 1050) { $tableExists = true; } else { throw $e; } } } if ($tableExists) { // checksum if (!$renamed && self::checksumValid($this->tablename, $checksum)) { return; } $stm = database::query('SHOW FULL COLUMNS FROM `' . $this->tablename . '`'); if ($stm) { $fullColumns = $stm->fetchAll(); } // update table $this->RefreshTable($fullColumns); } if ($this->customscript) { database::query($this->customscript); } self::addChecksum($this->tablename, $checksum); //database::query('INSERT INTO `__table_checksum` VALUES (?,?) ON DUPLICATE KEY UPDATE `checksum` = ?',array($this->tablename,$checksum,$checksum)); }
public static function csv() { $obj = utopia::GetInstance(utopia::GetCurrentModule()); $title = $obj->GetTitle(); $fields = $obj->fields; $layoutSections = $obj->layoutSections; $fullOut = ''; // field headers $out = array(); foreach ($fields as $fieldAlias => $fieldData) { if (!$fieldData['visiblename']) { continue; } $out[] = $fieldData['visiblename']; } $fullOut .= '"' . join('","', $out) . "\"\n"; // rows $dataset = $obj->GetDataset(); $pk = $obj->GetPrimaryKey(); $i = 0; while ($row = $dataset->fetch()) { $i++; $out = array(); foreach ($fields as $fieldAlias => $fieldData) { if (!$fieldData['visiblename']) { continue; } $data = strip_tags(trim($obj->PreProcess($fieldAlias, $row[$fieldAlias], $row[$pk]))); if (empty($data)) { $data = ''; } $out[] = preg_replace('/"/', '""', $data); } $fullOut .= '"' . join('","', $out) . "\"\n"; } $etag = utopia::checksum($fullOut); utopia::Cache_Output($fullOut, $etag, 'text/csv', $title . '.csv'); }
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()); }
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()); }