Esempio n. 1
0
 public function __toString()
 {
     if (JO_Registry::isRegistered('static_cache_options') && JO_Registry::forceGet('static_cache_enable')) {
         $options = (array) unserialize(JO_Registry::get('static_cache_options'));
         $cache_object = new JO_Cache_Static($options);
         $cache_object->add(false, $this->data);
     }
     return $this->data;
 }
Esempio n. 2
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;
         }
     }
 }
Esempio n. 3
0
 /**
  * @param string $action
  */
 public function dispatch($controller, $action, $param = '')
 {
     $request = $this->getRequest();
     if ($action == 'error404') {
         $request->setParams(array('controller' => 'error', 'action' => 'error404'));
     }
     $name = $controller;
     $view = $this->initView();
     $this->preDispatch();
     if (null === $this->_classMethods) {
         $this->_classMethods = get_class_methods($this);
     }
     $script = $action;
     $action = $action . 'Action';
     $throw = '';
     if (in_array($action, $this->_classMethods)) {
         //			ob_start(array(new JO_Error, 'error_handler'));
         ob_start(array(new JO_Error(), 'fatal_error_handler'));
         $this->{$action}($param);
     } else {
         $displayExceptions = JO_Front::getInstance()->getParam('displayExceptions');
         if ($displayExceptions) {
             $throw = $this->call_error($action);
             $layout = JO_Layout::getInstance();
             $layout->content = '<pre>' . $throw . '<pre>';
             $response = $layout->response();
             return $this->getResponse()->appendBody($response);
         } else {
             if ($this->getRequest()->getForwarded() != 'error') {
                 $this->forward('error', 'error404');
             } else {
                 $this->forward('JO_Action', 'error404');
             }
         }
     }
     $this->postDispatch();
     if (!$this->getInvokeArg('noViewRenderer')) {
         $layout = JO_Layout::getInstance();
         if ($this->view_change) {
             $script = $this->view_change;
         }
         $layout->content = $view->render($script, $script == 'error404' ? 'error' : $name);
         if (JO_Registry::forceGet('viewSetCallback')) {
             $layout->content = call_user_func(JO_Registry::forceGet('viewSetCallback'), $layout->content);
         } elseif ($this->response_callback) {
             $layout->content = call_user_func($this->response_callback, $layout->content);
         }
         if ($this->isChildren) {
             return $layout->content;
         } elseif ($this->noLayout) {
             return $this->getResponse()->appendBody($layout->content);
         } else {
             $response = $layout->response();
             if ($this->response_callback) {
                 $response = call_user_func($this->response_callback, $response);
             }
             if (JO_Registry::isRegistered('static_cache_options') && JO_Registry::forceGet('static_cache_enable')) {
                 $options = (array) unserialize(JO_Registry::get('static_cache_options'));
                 $cache_object = new JO_Cache_Static($options);
                 $cache_object->add(false, $response);
             }
             return $this->getResponse()->appendBody($response);
         }
     }
 }