Example #1
0
 /**
  * @param array $options
  * @return JO_Response
  */
 public static function getInstance($options = array())
 {
     if (self::$_instance == null) {
         self::$_instance = new self($options);
     }
     return self::$_instance;
 }
Example #2
0
 public function __construct($view)
 {
     $response = JO_Response::getInstance();
     $response->addHeader('Cache-Control: no-cache, must-revalidate');
     $response->addHeader('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     $response->addHeader('Content-type: application/xml');
     $response->setLevel(9);
     $this->data = $this->array_transform($view->getAll());
 }
Example #3
0
 public static function getCachingPage($tables = array())
 {
     $db = JO_Db::getDefaultAdapter();
     $options = array('livetime' => 86400);
     JO_Registry::set('static_cache_options', serialize($options));
     JO_Registry::set('static_cache_enable', true);
     $cache = new JO_Cache_Static($options);
     $cache_make_time = $cache->getCacheFileMTime();
     if (!$cache_make_time) {
         return false;
     }
     $config_data = $db->getConfig();
     $query1 = '';
     foreach ($tables as $k => $table) {
         $table = str_replace('`', '', $table);
         $query1 .= $query1 ? ' OR ' : '';
         if (strpos($table, '.') !== false) {
             $query1 .= "(`TABLE_SCHEMA`='" . array_shift(explode('.', $table)) . "' AND `TABLE_NAME`='" . end(explode('.', $table)) . "')";
         } else {
             if (isset($config_data['dbname'])) {
                 $query1 .= "(";
                 if ($config_data['dbname']) {
                     $query1 .= "`TABLE_SCHEMA`='" . $config_data['dbname'] . "' AND ";
                 }
                 $query1 .= "`TABLE_NAME`='" . $table . "')";
             }
         }
     }
     if ($query1) {
         $query1 = "(" . $query1 . ") AND `UPDATE_TIME`>'" . date("Y-m-d H:i:s", $cache_make_time) . "'";
         $r = $db->fetchRow("SELECT UPDATE_TIME FROM " . self::$info_table . " WHERE {$query1} ORDER BY UPDATE_TIME DESC LIMIT 1");
         if ($r && strtotime($r['UPDATE_TIME']) >= $cache->getCacheFileMTime()) {
             return false;
         } else {
             if (date('Ymd', $cache->getCacheFileMTime()) < date('Ymd')) {
                 return false;
             }
             $response = JO_Response::getInstance();
             $md5_file = md5_file($cache->getCacheFile());
             $response->addHeader("Etag: " . $md5_file);
             $response->addHeader("Last-Modified: " . gmdate("D, d M Y H:i:s", $cache_make_time) . " GMT");
             $response->addHeader("Pragma: public");
             $response->addHeader("Cache-store: server");
             $response->appendBody($cache->get(), 9);
             exit;
         }
     }
 }
Example #4
0
 public function _initHeaders()
 {
     $response = JO_Response::getInstance();
     $response->addHeader('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
     $response->addHeader('Access-Control-Allow-Origin: *');
 }
Example #5
0
 /**
  * @return JO_Response
  */
 public function getResponse()
 {
     if ($this->response == null) {
         $this->setResponse(JO_Response::getInstance());
     }
     return $this->response;
 }
Example #6
0
 public function dispatch($controller = null, $action = null, $params = array())
 {
     $this->setHelpersPath();
     $controller = $controller ? $controller : $this->getRequest()->getController();
     $response = JO_Response::getInstance();
     if (!$this->isDispatchable($controller) && $this->isDispatchable('error')) {
         $controller = 'error';
         $action = 'error404';
     }
     if ($this->isDispatchable($controller)) {
         JO_Loader::setIncludePaths(array($this->getDispatchDirectory()));
         $className = $this->formatControllerName($controller);
         JO_Loader::loadFile($this->classToFilename($className), null, true);
         $controller_instance = new $className($this->getRequest());
         if (!$controller_instance instanceof JO_Action) {
             require_once 'JO/Exception.php';
             throw new JO_Exception('Controller "' . $className . '" is not an instance of JO_Action');
         }
         $action = $action ? $action : $this->getRequest()->getAction();
         // by default, buffer output
         $disableOb = $this->getParam('disableOutputBuffering');
         $obLevel = ob_get_level();
         if (empty($disableOb)) {
             ob_start();
         }
         try {
             $controller_instance->dispatch($controller, $action, $params);
         } catch (Exception $e) {
             // Clean output buffer on error
             $curObLevel = ob_get_level();
             if ($curObLevel > $obLevel) {
                 do {
                     ob_get_clean();
                     $curObLevel = ob_get_level();
                 } while ($curObLevel > $obLevel);
             }
             throw $e;
         }
         if (empty($disableOb)) {
             $content = ob_get_clean();
             $response->appendBody($content);
         }
         // Destroy the page controller instance and reflection objects
         $controller_instance = null;
     } else {
         $controller_instance = new JO_Action();
         $controller_instance->dispatch($controller, 'error404');
         // Destroy the page controller instance and reflection objects
         $controller_instance = null;
         //			require_once 'JO/Exception.php';
         //			throw new JO_Exception(
         //				'Controller "' . $controller . '" is not found'
         //			);
     }
 }
Example #7
0
 public function _initCompresion()
 {
     JO_Response::getInstance()->setLevel(9);
 }
Example #8
0
 /**
  * Save to file
  *
  * @param string $content The minified data.
  * @param string $path The path to save the minified data to.
  */
 public function save($content, $path)
 {
     if (@file_put_contents($path, $content) === false) {
         throw new JO_Minify_Exception('The file "' . $path . '" could not be opened. Check if PHP has enough permissions.');
     }
     try {
         $gzdata = gzencode($content, JO_Response::getInstance()->getLevel());
         file_put_contents($path . '.gz', $gzdata);
     } catch (JO_Exception $e) {
     }
 }