<?php namespace qg; qg::on('action', function () { // use 'render' ? would be .5 miliseconds slower :( if (strpos(appRequestUri, 'dbFile/') === 0) { $request = substr(appRequestUri, 7); dbFile::output($request); } File::uploadListener(); if (isset($_GET['qgha'])) { $ok = hashAction::fire($_GET['qgha']); } if (isset(G()->ASK['serverInterface'])) { foreach (G()->ASK['serverInterface'] as $id => $vs) { $ret['serverInterface'][$id] = Api::call($vs['fn'], $vs['args']); } Answer($ret); } }); /* qg::on('deliverHtml', function() { html::addJSFile(sysURL.'core/js/c1.js','core'); // old ie $matches = preg_match('/MSIE ([0-9.]+)/',$_SERVER['HTTP_USER_AGENT'], $match); if (isset($match[1]) && $match[1] < 9) { html::addJSFile(sysURL.'core/js/jQuery1.js','core'); } else { html::addJSFile(sysURL.'core/js/jQuery.js','core');
function FileAdd($path, $name = '') { $F = dbFile::add($path); $this->addDbFile($F, $name); return $F; }
$rotations = array('3' => 180, '6' => -90, '8' => 90); if (!isset($rotations[$ori])) { return; } $image = imagecreatefromjpeg($filename); $image = imagerotate($image, $rotations[$ori], 0); imagejpeg($image, $filename, 94); }; $Page = Page(isset($_POST['cmspid']) ? $_POST['cmspid'] : $_GET['cmspid']); if ($Page->access() > 1) { $_FILES['cmsPageFile']['name'] = str_replace('%', '%25', $_FILES['cmsPageFile']['name']); $image_fix_orientation($_FILES['cmsPageFile']['tmp_name']); if (isset($_GET['replace']) && $_GET['replace']) { $File = $Page->File($_GET['replace']); } else { $File = dbFile::add(); $Page->addDbFile($File); } $File->replaceFromUpload($_FILES['cmsPageFile']); $res = array('id' => (string) $File, 'url' => $File->url() . '/' . $File->vs['name']); Answer($res); } } if (isset($_GET['qgCms_page_files_as_zip'])) { $P = Page($_GET['qgCms_page_files_as_zip']); if (!$P->access() > 1) { exit('no access'); } if (!$P->Files()) { exit('no files'); }
static function output($request) { $x = explode('/', $request); $id = (int) array_shift($x); $name = array_pop($x); $param = array(); foreach ($x as $value) { $y = explode('-', $value, 2); $param[$y[0]] = isset($y[1]) ? $y[1] : true; } $File = $RequestedFile = new dbFile($id); if (!$File->exists()) { header("HTTP/1.1 404 Not Found"); exit; } if (!$File->access()) { header("HTTP/1.1 401 Unauthorized"); exit; } header("HTTP/1.1 200 OK"); // Header $mime = $File->mime() ? $File->mime() : extensionToMime($File->extension()); header('Content-Type: ' . $mime); header("Last-Modified: " . gmdate("D, d M Y H:i:s", $File->mtime()) . " GMT"); header("Pragma: private"); header("Expires: Mon, 26 Jul 2030 05:00:00 GMT"); header("Cache-Control: store, cache, max-age=100000, must-revalidate"); if (Image::able($File->path)) { if (1 || isset($param['h']) || isset($param['w'])) { $w = isset($param['w']) ? (int) $param['w'] : 0; $h = isset($param['h']) ? (int) $param['h'] : 0; if (isset($_COOKIE['q1_dpr']) && $_COOKIE['q1_dpr'] > 1) { if (isset($param['dpr']) ? $param['dpr'] : G()->SET['qg']['dbFile_dpr_dependent']->v) { $w *= (double) $_COOKIE['q1_dpr']; $h *= (double) $_COOKIE['q1_dpr']; } } $w = min($w, 9000); $h = min($h, 9000); $q = (int) isset($param['q']) ? $param['q'] : 92; $max = isset($param['max']) ? (bool) $param['max'] : false; $vpos = (int) isset($param['vpos']) ? $param['vpos'] : 20; $hpos = (int) isset($param['hpos']) ? $param['hpos'] : 50; $zoom = (int) isset($param['zoom']) ? $param['zoom'] : 0; $type = str_replace('image/', '', $File->mime()); $nFile = new File(appPATH . 'cache/pri/dbfile_img_' . sha1($request . '|' . $w . '|' . $h)); if (!$nFile->exists() || $File->mtime() > $nFile->mtime()) { $Img = new Image($File->path); if ($w == 0 && $h == 0) { $w = $Img->x(); } if ($max || $h == 0 || $w == 0) { $Img = $Img->getResized($w, $h, true); } else { $Img = $Img->getAutoCroped($w, $h, $vpos, $hpos, $zoom); } qg::fire('qg::dbfile-image', array('Img' => &$Img, 'id' => $id, 'param' => $param)); $Img->saveAs($nFile->path, $type, $q); } header('Content-Type: image/' . $type); $File = $nFile; } //header("Pragma: public"); // Emails! header("Pragma: private"); // required } elseif (preg_match('/\\.pdf$/', $name) || $File->mime() == 'application/pdf') { header('Content-Type: application/pdf'); header('Content-Disposition: inline; filename="' . $RequestedFile->name() . '";'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } if (isset($param['as']) && ($param['as'] = 'text')) { header("Content-Type: text/html"); } if (isset($param['dl'])) { header('Pragma: public'); // required! header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private', false); // required for certain browsers header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename="' . $RequestedFile->name() . '";'); header('Content-Transfer-Encoding: binary'); } $etag = 'qg' . $File->mtime(); if (!isset($_SERVER['HTTP_IF_NONE_MATCH']) || $_SERVER['HTTP_IF_NONE_MATCH'] !== $etag) { header('ETag: ' . $etag); /* rangeDownload http://mobiforge.com/developing/story/content-delivery-mobile-devices */ header('Content-Length: ' . $File->size()); flush(); while (ob_get_level()) { ob_end_flush(); } $File->read(); } else { header("HTTP/1.1 304 Not Modified"); } D()->query("UPDATE log SET file_id = " . $id . " WHERE id = " . liveLog::$id); exit; }