/** * Check the path of the img, return full path of image if the requested image is found * */ function __construct() { global $dataDir; if (!isset($_GET['w']) || !isset($_GET['h']) || !isset($_GET['img'])) { self::Send404(); //dies } $img = $_GET['img']; $height = $_GET['h']; $width = $_GET['w']; $index = $_GET['i']; if (!is_numeric($height) || !is_numeric($width)) { self::Send404(); //dies } $img = \gp\tool\Files::NoNull($img); //check file path if (strpos($img, './') !== false || strpos($img, '%2f') !== false || strpos($img, '%2F') !== false) { return false; } //make sure the index is set gp_resized::SetIndex(); if (!isset(self::$index[$index])) { self::Send404(); //dies } //if the image has been renamed, redirect to the new name $index_img = self::$index[$index]; if ($index_img != $img) { $path = \gp\tool::GetDir('/include/image.php', false) . '?i=' . $index . '&w=' . $width . '&h=' . $height . '&img=' . rawurlencode($index_img); \gp\tool::Redirect($path); } $info = self::ImageInfo($img, $width, $height); $folder = $dataDir . '/data/_resized/' . $info['index']; $full_path = $folder . '/' . $info['name']; //if it exists return true if (file_exists($full_path)) { header('Cache-Control: public, max-age=5184000'); //60 days //attempt to send 304 $stats = lstat($full_path); if ($stats) { \gp\tool::Send304(\gp\tool::GenEtag($stats['mtime'], $stats['size'])); } header('Content-Transfer-Encoding: binary'); header('Content-Type: ' . $info['ctype']); readfile($full_path); die; } //redirect to next largest image if available $usage = self::GetUsage($info['index']); foreach ($usage as $size => $data) { if (!$data['uses']) { continue; } list($use_width, $use_height) = explode('x', $size); if ($use_width >= $width && $use_height > $height || $use_width > $width && $use_height >= $height) { $path = \gp\tool::GetDir('/include/image.php', false) . '?i=' . $index . '&w=' . $use_width . '&h=' . $use_height . '&img=' . rawurlencode($img); \gp\tool::Redirect($path); //dies } } //redirect to full size image $original = \gp\tool::GetDir('/data/_uploaded' . $img, false); \gp\tool::Redirect($original); //dies }
public static function RunOut() { global $page; $page->RunScript(); //prepare the admin content if (\gp\tool::LoggedIn()) { \gp\admin\Tools::AdminHtml(); } //decide how to send the content self::Prep(); switch (\gp\tool::RequestType()) { // <a data-cmd="admin_box"> case 'flush': self::Flush(); break; // remote request // file browser // remote request // file browser case 'body': \gp\tool::CheckTheme(); self::BodyAsHTML(); break; case 'admin': self::AdminHtml(); break; // <a data-cmd="gpajax"> // <a data-cmd="gpabox"> // <input data-cmd="gpabox"> // <a data-cmd="gpajax"> // <a data-cmd="gpabox"> // <input data-cmd="gpabox"> case 'json': \gp\tool::CheckTheme(); \gp\tool\Output\Ajax::Response(); break; case 'content': self::Content(); break; default: \gp\tool::CheckTheme(); self::Template(); break; } // if logged in, don't send 304 response if (\gp\tool::LoggedIn()) { //empty edit links if there isn't a layout if (!$page->gpLayout) { self::$editlinks = ''; } return; } // attempt to send 304 response if ($page->fileModTime > 0) { global $wbMessageBuffer; $len = strlen(self::$head_content) + strlen(self::$head_js) + ob_get_length(); if (count($wbMessageBuffer)) { $len += strlen(json_encode($wbMessageBuffer)); } \gp\tool::Send304(\gp\tool::GenEtag($page->fileModTime, $len)); } }