function CheckLastModified() { //echo "\n\n/*\n"; //print_r($_SERVER); //echo "\n*/"; if (gp_dev_combine) { return; } if ($this->last_modified == 0) { return; } // use extended max-age value header('Cache-Control: public, max-age=5184000'); //60 days //attempt to send an 304 response $etag = common::GenEtag($this->last_modified, $this->content_length); common::Send304($etag); }
static function RunOut() { global $page; $page->RunScript(); //decide how to send the content self::Prep(); switch (common::RequestType()) { // <a data-cmd="admin_box"> case 'flush': self::Flush(); break; // remote request // file browser // remote request // file browser case 'body': common::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': common::CheckTheme(); includeFile('tool/ajax.php'); gpAjax::Response(); break; case 'content': self::Content(); break; default: common::CheckTheme(); self::Template(); break; } //if logged in, prepare the admin content and don't send 304 response if (common::LoggedIn()) { admin_tools::AdminHtml(); //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, $gp_head_content; $len = strlen($gp_head_content) + ob_get_length(); if (count($wbMessageBuffer)) { $len += strlen(serialize($wbMessageBuffer)); } common::Send304(common::GenEtag($page->fileModTime, $len)); } }
/** * Generate an etag from the filemtime and filesize of each file * @param array $files * */ static function FilesEtag($files) { $modified = 0; $content_length = 0; foreach ($files as $file) { $content_length += @filesize($file); $modified = max($modified, @filemtime($file)); } return common::GenEtag($modified, $content_length); }
/** * Generate a file with all of the combined content * */ static function GenerateFile($files, $type) { global $dataDir; //get etag $modified = $content_length = 0; $full_paths = array(); foreach ($files as $file) { $full_path = gp_combine::CheckFile($file); if ($full_path === false) { continue; } gp_combine::FileStat_Static($full_path, $modified, $content_length); $full_paths[$file] = $full_path; } //check css imports if ($type == 'css') { $had_imported = false; $import_data = array(); $imported_file = $dataDir . '/data/_cache/import_info.php'; if (file_exists($imported_file)) { include_once $imported_file; } foreach ($full_paths as $file => $full_path) { if (!isset($import_data[$full_path])) { continue; } $had_imported = true; foreach ($import_data[$full_path] as $imported_full) { gp_combine::FileStat_Static($imported_full, $modified, $content_length); } unset($import_data[$full_path]); } } //check to see if file exists $etag = common::GenEtag(json_encode($files), $modified, $content_length); $cache_relative = '/data/_cache/combined_' . $etag . '.' . $type; $cache_file = $dataDir . $cache_relative; if (file_exists($cache_file)) { // change modified time to extend cache if (time() - filemtime($cache_file) > 604800) { touch($cache_file); } return $cache_relative; } //create file if ($type == 'js') { ob_start(); common::jsStart(); foreach ($full_paths as $full_path) { readfile($full_path); echo ";\n"; } $combined_content = ob_get_clean(); } else { $imports = $combined_content = ''; $new_imported = array(); foreach ($full_paths as $file => $full_path) { $temp = new gp_combine_css($file); $combined_content .= "\n/* " . $file . " */\n"; $combined_content .= $temp->content; $imports .= $temp->imports; if (count($temp->imported)) { $new_imported[$full_path] = $temp->imported; } } $combined_content = $imports . $combined_content; //save imported data if (count($new_imported) || $had_imported) { if (count($new_imported)) { $import_data = $new_imported + $import_data; } gpFiles::SaveData($imported_file, 'import_data', $import_data); } } if (!gpFiles::Save($cache_file, $combined_content)) { return false; } includeFile('admin/admin_tools.php'); admin_tools::CleanCache(); return $cache_relative; }
/** * 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 = gpFiles::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 = common::GetDir('/include/image.php', false) . '?i=' . $index . '&w=' . $width . '&h=' . $height . '&img=' . rawurlencode($index_img); common::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) { common::Send304(common::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 = common::GetDir('/include/image.php', false) . '?i=' . $index . '&w=' . $use_width . '&h=' . $use_height . '&img=' . rawurlencode($img); common::Redirect($path); //dies } } //redirect to full size image $original = common::GetDir('/data/_uploaded' . $img, false); common::Redirect($original); //dies }
function RunOut() { global $page, $gp_head_content; $page->RunScript(); //decide how to send the content gpOutput::Prep(); $req = ''; if (isset($_REQUEST['gpreq'])) { $req = $_REQUEST['gpreq']; } switch ($req) { // <a name="admin_box"> case 'flush': gpOutput::Flush(); break; // remote request // file browser // remote request // file browser case 'body': common::CheckTheme(); gpOutput::BodyAsHTML(); break; // <a name="gpajax"> // <a name="gpajax"> case 'json': common::CheckTheme(); includeFile('tool/ajax.php'); gpAjax::Response(); break; case 'content': gpOutput::Content(); break; default: common::CheckTheme(); gpOutput::Template(); break; } //if logged in, prepare the admin content and don't send 304 response if (common::LoggedIn()) { admin_tools::AdminHtml(); return; } /* attempt to send 304 response */ if ($page->fileModTime > 0) { $len = strlen($gp_head_content) + ob_get_length(); common::Send304(common::GenEtag($page->fileModTime, $len)); } }