Пример #1
0
 public function runServe(TBGRequest $request)
 {
     if (!TBGContext::isMinifyEnabled()) {
         $itemarray = array($request['g'] => explode(',', base64_decode($request['files'])));
         if (array_key_exists('js', $itemarray)) {
             header('Content-type: text/javascript');
             foreach ($itemarray['js'] as $file) {
                 $ext = substr($file, -2);
                 if ($ext == 'js' && file_exists($file) && strpos(realpath($file), THEBUGGENIE_PATH) !== false) {
                     echo file_get_contents($file);
                 }
             }
         } else {
             header('Content-type: text/css');
             foreach ($itemarray['css'] as $file) {
                 $ext = substr($file, -3);
                 if ($ext == 'css' && file_exists($file) && strpos(realpath($file), THEBUGGENIE_PATH) !== false) {
                     echo file_get_contents($file);
                 }
             }
         }
         exit;
     }
     $this->getResponse()->setDecoration(TBGResponse::DECORATE_NONE);
     define('MINIFY_MIN_DIR', dirname(__FILE__) . '/../../../core/min');
     // load config
     require MINIFY_MIN_DIR . '/config.php';
     // setup include path
     set_include_path($min_libPath . PATH_SEPARATOR . get_include_path());
     require 'Minify.php';
     Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
     Minify::setCache(isset($min_cachePath) ? $min_cachePath : '', $min_cacheFileLocking);
     if ($min_documentRoot) {
         $_SERVER['DOCUMENT_ROOT'] = $min_documentRoot;
     } elseif (0 === mb_stripos(PHP_OS, 'win')) {
         Minify::setDocRoot();
         // IIS may need help
     }
     $min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks;
     if ($min_allowDebugFlag && isset($_GET['debug'])) {
         $min_serveOptions['debug'] = true;
     }
     if ($min_errorLogger) {
         require_once 'Minify/Logger.php';
         if (true === $min_errorLogger) {
             require_once 'FirePHP.php';
             Minify_Logger::setLogger(FirePHP::getInstance(true));
         } else {
             Minify_Logger::setLogger($min_errorLogger);
         }
     }
     // check for URI versioning
     if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) {
         $min_serveOptions['maxAge'] = 31536000;
     }
     $itemarray = array($request['g'] => explode(',', base64_decode($request['files'])));
     $min_serveOptions['minApp']['groups'] = $itemarray;
     ob_end_clean();
     $data = Minify::serve('MinApp', $min_serveOptions);
     header_remove('Pragma');
     foreach ($data['headers'] as $name => $val) {
         header($name . ': ' . $val);
     }
     header('HTTP/1.1 ' . $data['statusCode']);
     if ($data['statusCode'] != 304) {
         echo $data['content'];
     }
     exit;
 }