示例#1
0
 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));
     }
 }
示例#2
0
 /**
  * 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
 }
示例#3
0
 /**
  * Generate a file with all of the combined content
  *
  */
 public static function GenerateFile($files, $type)
 {
     global $dataDir;
     //get etag
     $modified = $content_length = 0;
     $full_paths = array();
     foreach ($files as $file) {
         $full_path = self::CheckFile($file);
         if ($full_path === false) {
             continue;
         }
         self::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) {
                 self::FileStat_Static($imported_full, $modified, $content_length);
             }
             unset($import_data[$full_path]);
         }
     }
     //check to see if file exists
     $etag = \gp\tool::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();
         \gp\tool::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\tool\Output\CombineCss($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;
             }
             \gp\tool\Files::SaveData($imported_file, 'import_data', $import_data);
         }
     }
     if (!\gp\tool\Files::Save($cache_file, $combined_content)) {
         return false;
     }
     \gp\admin\Tools::CleanCache();
     return $cache_relative;
 }