Example #1
0
 /**
  * Generate a page cache id
  *
  * @return  string  MD5 Hash : page cache id
  *
  * @since   11.1
  * @todo    Discuss whether this should be coupled to a data hash or a request
  * hash ... perhaps hashed with a serialized request
  */
 protected function _makeId()
 {
     return JCache::makeId();
 }
Example #2
0
 /**
  * Generate a view cache id.
  *
  * @param   object  &$view   The view object to cache output for
  * @param   string  $method  The method name to cache for the view object
  *
  * @return  string  MD5 Hash : view cache id
  *
  * @since   11.1
  */
 protected function _makeId(&$view, $method)
 {
     return md5(serialize(array(JCache::makeId(), get_class($view), $method)));
 }
 /**
  * Default task. Assigns a model to the view and asks the view to render
  * itself.
  *
  * YOU MUST NOT USETHIS TASK DIRECTLY IN A URL. It is supposed to be
  * used ONLY inside your code. In the URL, use task=browse instead.
  *
  * @param   bool    $cachable   Is this view cacheable?
  * @param   bool    $urlparams  Add your safe URL parameters (see further down in the code)
  * @param   string  $tpl        The name of the template file to parse
  *
  * @return  bool
  */
 public function display($cachable = false, $urlparams = false, $tpl = null)
 {
     $document = F0FPlatform::getInstance()->getDocument();
     if ($document instanceof JDocument) {
         $viewType = $document->getType();
     } else {
         $viewType = $this->input->getCmd('format', 'html');
     }
     $view = $this->getThisView();
     // Get/Create the model
     if ($model = $this->getThisModel()) {
         // Push the model into the view (as default)
         $view->setModel($model, true);
     }
     // Set the layout
     $view->setLayout(is_null($this->layout) ? 'default' : $this->layout);
     // Display the view
     $conf = F0FPlatform::getInstance()->getConfig();
     if (F0FPlatform::getInstance()->isFrontend() && $cachable && $viewType != 'feed' && $conf->get('caching') >= 1) {
         // Get a JCache object
         $option = $this->input->get('option', 'com_foobar', 'cmd');
         $cache = JFactory::getCache($option, 'view');
         // Set up a cache ID based on component, view, task and user group assignment
         $user = F0FPlatform::getInstance()->getUser();
         if ($user->guest) {
             $groups = array();
         } else {
             $groups = $user->groups;
         }
         // Set up safe URL parameters
         if (!is_array($urlparams)) {
             $urlparams = array('option' => 'CMD', 'view' => 'CMD', 'task' => 'CMD', 'format' => 'CMD', 'layout' => 'CMD', 'id' => 'INT');
         }
         if (is_array($urlparams)) {
             $app = JFactory::getApplication();
             $registeredurlparams = null;
             if (version_compare(JVERSION, '3.0', 'ge')) {
                 if (property_exists($app, 'registeredurlparams')) {
                     $registeredurlparams = $app->registeredurlparams;
                 }
             } else {
                 $registeredurlparams = $app->get('registeredurlparams');
             }
             if (empty($registeredurlparams)) {
                 $registeredurlparams = new stdClass();
             }
             foreach ($urlparams as $key => $value) {
                 // Add your safe url parameters with variable type as value {@see JFilterInput::clean()}.
                 $registeredurlparams->{$key} = $value;
             }
             if (version_compare(JVERSION, '3.0', 'ge')) {
                 $app->registeredurlparams = $registeredurlparams;
             } else {
                 $app->set('registeredurlparams', $registeredurlparams);
             }
         }
         // Create the cache ID after setting the registered URL params, as they are used to generate the ID
         $cacheId = md5(serialize(array(JCache::makeId(), $view->getName(), $this->doTask, $groups)));
         // Get the cached view or cache the current view
         $cache->get($view, 'display', $cacheId);
     } else {
         // Display without caching
         $view->display($tpl);
     }
     return true;
 }
Example #4
0
File: page.php Project: akksi/jcg
 /**
  * Generate a page cache id
  *
  * @todo	TODO: Discuss whether this should be coupled to a data hash or a request hash ... perhaps hashed with a serialized request
  *
  * @return	string	MD5 Hash : page cache id
  * @since	1.6
  */
 private function _makeId()
 {
     //return md5(JRequest::getURI());
     return JCache::makeId();
 }
Example #5
0
 /**
  * Generate a page cache id
  *
  * @todo    Discuss whether this should be coupled to a data hash or a request
  *          hash ... perhaps hashed with a serialized request
  *
  * @return  string   MD5 Hash : page cache id
  *
  * @since   11.1
  */
 protected function _makeId()
 {
     //return md5(JRequest::getURI());
     return JCache::makeId();
 }
Example #6
0
 /**
  * Typical view method for MVC based architecture
  *
  * This function is provide as a default implementation, in most cases
  * you will need to override it in your own controllers.
  *
  * @param   boolean  $cachable   If true, the view output will be cached
  * @param   array    $urlparams  An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  *
  * @return  JController  A JController object to support chaining.
  *
  * @since   11.1
  */
 public function display($cachable = false, $urlparams = false)
 {
     $document = JFactory::getDocument();
     $viewType = $document->getType();
     $viewName = JRequest::getCmd('view', $this->default_view);
     $viewLayout = JRequest::getString('layout', 'default');
     $view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath, 'layout' => $viewLayout));
     // Get/Create the model
     if ($model = $this->getModel($viewName)) {
         // Push the model into the view (as default)
         $view->setModel($model, true);
     }
     $view->assignRef('document', $document);
     $conf = JFactory::getConfig();
     // Display the view
     if ($cachable && $viewType != 'feed' && $conf->get('caching') >= 1) {
         $option = JRequest::getCmd('option');
         //$cache = JFactory::getCache($option, 'view');
         if (is_array($urlparams)) {
             $app = JFactory::getApplication();
             if (!empty($app->registeredurlparams)) {
                 $registeredurlparams = $app->registeredurlparams;
             } else {
                 $registeredurlparams = new stdClass();
             }
             foreach ($urlparams as $key => $value) {
                 // Add your safe url parameters with variable type as value {@see JFilterInput::clean()}.
                 $registeredurlparams->{$key} = $value;
             }
             $app->registeredurlparams = $registeredurlparams;
         }
         //$cache->get($view, 'display');
         $id = md5(serialize(array(\JCache::makeId(), get_class($view), 'display')));
         $data = \Cache::get($option . '.' . $id);
         if (!$data || empty($data)) {
             //$content = $view->loadTemplate();
             ob_start();
             ob_implicit_flush(false);
             $view->display();
             $content = ob_get_contents();
             ob_end_clean();
             $data = array('content' => $content, 'head' => Document::getHeadData());
             \Cache::put($option . '.' . $id, $data, \Config::get('cachetime'));
         }
         echo $data['content'];
         Document::setHeadData($data['head']);
     } else {
         $view->display();
     }
     return $this;
 }
 /**
  * Default task. Assigns a model to the view and asks the view to render
  * itself.
  *
  * YOU MUST NOT USETHIS TASK DIRECTLY IN A URL. It is supposed to be
  * used ONLY inside your code. In the URL, use task=browse instead.
  *
  * @param   bool  $cachable   Is this view cacheable?
  * @param   bool  $urlparams  Add your safe URL parameters (see further down in the code)
  *
  * @return  void
  */
 public function display($cachable = false, $urlparams = false)
 {
     $document = JFactory::getDocument();
     $viewType = $document->getType();
     $view = $this->getThisView();
     // Get/Create the model
     if ($model = $this->getThisModel()) {
         // Push the model into the view (as default)
         $view->setModel($model, true);
     }
     // Set the layout
     $view->setLayout(is_null($this->layout) ? 'default' : $this->layout);
     // Display the view
     $conf = JFactory::getConfig();
     list($isCli, ) = FOFDispatcher::isCliAdmin();
     if (!$isCli && JFactory::getApplication()->isSite() && $cachable && $viewType != 'feed' && $conf->get('caching') >= 1) {
         // Get a JCache object
         $option = $this->input->get('option', 'com_foobar', 'cmd');
         $cache = JFactory::getCache($option, 'view');
         // Set up a cache ID based on component, view, task and user group assignment
         $user = JFactory::getUser();
         if ($user->guest) {
             $groups = array();
         } else {
             $groups = $user->groups;
         }
         $cacheId = md5(serialize(array(JCache::makeId(), $view->getName(), $this->doTask, $groups)));
         // Set up safe URL parameters
         if (is_array($urlparams)) {
             $app = JFactory::getApplication();
             $registeredurlparams = $app->get('registeredurlparams');
             if (empty($registeredurlparams)) {
                 $registeredurlparams = new stdClass();
             }
             foreach ($urlparams as $key => $value) {
                 // Add your safe url parameters with variable type as value {@see JFilterInput::clean()}.
                 $registeredurlparams->{$key} = $value;
             }
             $app->set('registeredurlparams', $registeredurlparams);
         }
         // Get the cached view or cache the current view
         $cache->get($view, 'display', $cacheId);
     } else {
         // Display without caching
         $view->display();
     }
     return true;
 }
Example #8
0
 /**
  * Default task. Assigns a model to the view and asks the view to render
  * itself.
  *
  * YOU MUST NOT USE THIS TASK DIRECTLY IN A URL. It is supposed to be
  * used ONLY inside your code. In the URL, use task=browse instead.
  *
  * @param   bool    $cachable   Is this view cacheable?
  * @param   bool    $urlparams  Add your safe URL parameters (see further down in the code)
  * @param   string  $tpl        The name of the template file to parse
  *
  * @return  void
  */
 public function display($cachable = false, $urlparams = false, $tpl = null)
 {
     $document = $this->container->platform->getDocument();
     if ($document instanceof \JDocument) {
         $viewType = $document->getType();
     } else {
         $viewType = $this->input->getCmd('format', 'html');
     }
     $view = $this->getView();
     $view->setTask($this->task);
     $view->setDoTask($this->doTask);
     // Get/Create the model
     if ($model = $this->getModel()) {
         // Push the model into the view (as default)
         $view->setDefaultModel($model);
     }
     // Set the layout
     if (!is_null($this->layout)) {
         $view->setLayout($this->layout);
     }
     $conf = $this->container->platform->getConfig();
     if ($this->container->platform->isFrontend() && $cachable && $viewType != 'feed' && $conf->get('caching') >= 1) {
         // Get a JCache object
         $option = $this->input->get('option', 'com_foobar', 'cmd');
         $cache = \JFactory::getCache($option, 'view');
         // Set up a cache ID based on component, view, task and user group assignment
         $user = $this->container->platform->getUser();
         if ($user->guest) {
             $groups = array();
         } else {
             $groups = $user->groups;
         }
         $importantParameters = array();
         // Set up safe URL parameters
         if (!is_array($urlparams)) {
             $urlparams = array('option' => 'CMD', 'view' => 'CMD', 'task' => 'CMD', 'format' => 'CMD', 'layout' => 'CMD', 'id' => 'INT');
         }
         if (is_array($urlparams)) {
             /** @var \JApplicationCms $app */
             $app = \JFactory::getApplication();
             $registeredurlparams = null;
             if (!empty($app->registeredurlparams)) {
                 $registeredurlparams = $app->registeredurlparams;
             } else {
                 $registeredurlparams = new \stdClass();
             }
             foreach ($urlparams as $key => $value) {
                 // Add your safe url parameters with variable type as value {@see JFilterInput::clean()}.
                 $registeredurlparams->{$key} = $value;
                 // Add the URL-important parameters into the array
                 $importantParameters[$key] = $this->input->get($key, null, $value);
             }
             $app->registeredurlparams = $registeredurlparams;
         }
         // Create the cache ID after setting the registered URL params, as they are used to generate the ID
         $cacheId = md5(serialize(array(\JCache::makeId(), $view->getName(), $this->doTask, $groups, $importantParameters)));
         // Get the cached view or cache the current view
         $cache->get($view, 'display', $cacheId);
     } else {
         // Display without caching
         $view->display($tpl);
     }
 }