コード例 #1
0
ファイル: uploads.php プロジェクト: OptimalInternet/uCore
 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);
     }
 }
コード例 #2
0
ファイル: forms.class.php プロジェクト: OptimalInternet/uCore
 public function ParseRewrite($caseSensative = false)
 {
     if ($this->rewriteMapping === NULL) {
         return FALSE;
     }
     if (get_class($this) !== utopia::GetCurrentModule()) {
         return FALSE;
     }
     $uuid = $this->GetUUID();
     if (is_array($uuid)) {
         $uuid = reset($uuid);
     }
     $sections = utopia::GetRewriteURL();
     $sections = preg_replace('/^' . preg_quote($uuid, '/') . '\\/?/', '', $sections);
     $sections = explode('/', $sections);
     if (!$sections) {
         return FALSE;
     }
     $return = array('uuid' => $uuid);
     foreach ($sections as $key => $value) {
         $replace = array();
         if (!array_key_exists($key, $this->rewriteMapping)) {
             continue;
         }
         $map = $this->rewriteMapping[$key];
         // generate preg for section
         if (preg_match_all('/{([a-zA-Z0-9_]+)}/', $map, $matches)) {
             foreach ($matches[1] as $match) {
                 $map = str_replace('{' . $match . '}', '(.*)', $map);
                 $replace[] = $match;
             }
         }
         if (preg_match('/' . $map . '/', $value, $matches)) {
             unset($matches[0]);
             foreach ($matches as $key => $match) {
                 $return[$replace[$key - 1]] = $match;
             }
         }
     }
     // TODO: named filters not being picked up
     $_GET = array_merge($return, $_GET);
     $_REQUEST = array_merge($return, $_REQUEST);
     return $return;
 }