Ejemplo n.º 1
0
 function parse($html = null, $blockName = 'document', $blockParams = null)
 {
     if (empty($blockParams['id'])) {
         if (preg_match('/^[a-zA-Z0-9_.-]+$/', $html)) {
             $blockParams['id'] = parent::parse($html);
             $html = null;
         } else {
             return;
         }
     }
     $id = $blockParams['id'];
     $cacheKey = empty($blockParams['cacheKey']) ? 'default' : $blockParams['cacheKey'];
     $data = SlConfigure::read2("Block.{$id}");
     if ($data) {
         $id = r('.', '-', $id);
         $this->vars = array('id' => $id, 'title' => false);
         $defaults = SlConfigure::read2('Block.defaults');
         $blocks = array();
         foreach ($data as $key => $block) {
             if ($block) {
                 if (!is_array($block)) {
                     $block = array('body' => $block);
                 }
                 $block = Set::merge($defaults, $block);
                 if (empty($block['id'])) {
                     $block['id'] = "{$id}-{$key}";
                 }
                 if (!empty($block['cache']) && !is_array($block['cache'])) {
                     $block['cache'] = array('time' => $block['cache']);
                 }
                 if (!empty($block['cache_time'])) {
                     $block['cache']['time'] = $block['cache_time'];
                 }
                 if (isset($block['cache']['time']) && is_numeric($block['cache']['time'])) {
                     $block['cache']['time'] += time();
                 }
                 if (!empty($block['cache']['spread'])) {
                     if (!is_numeric($block['cache']['time'])) {
                         $block['cache']['time'] = strtotime($block['cache']['time'], time());
                     }
                     $block['cache']['time'] += mt_rand(-$block['cache']['spread'], $block['cache']['spread']);
                 }
                 if (!empty($block['cache']) && empty($block['cache']['key'])) {
                     $block['cache']['key'] = $block['id'] . '-' . md5(serialize($block) . SlConfigure::read('I18n.lang'));
                 }
                 if (!empty($block['cache']['time'])) {
                     $cacheFile = 'views/block_' . $cacheKey . '_' . $block['cache']['key'];
                     $cache = cache($cacheFile, null, $block['cache']['time']);
                     if (is_string($cache)) {
                         $blocks[] = unserialize($cache);
                         continue;
                     }
                 }
                 // dynamic block (from custom controller)
                 if (!empty($block['url'])) {
                     $block['body'] = Sl::requestAction($block['url']);
                     if (!isset($block['title'])) {
                         $block['title'] = SlConfigure::read('View.lastRenderTitle');
                     }
                 } elseif (!empty($block['body'])) {
                     $block['body'] = parent::parse($block['body']);
                 } else {
                     continue;
                 }
                 $blocks[] = $block;
                 // update cache
                 if (!empty($block['cache']['time'])) {
                     // we don't wanna cache administrative stuff
                     if (!strpos($block['body'], 'sl-node-actions')) {
                         cache($cacheFile, serialize($block), $block['cache']['time']);
                     }
                 }
             }
         }
         if (empty($blocks)) {
             return;
         }
         $this->blocks["loop"]->params[0] = $blocks;
         return parent::parse($html, $blockName);
     }
 }
Ejemplo n.º 2
0
 /**
  * Redirects to given $url, after turning off $this->autoRender.
  * Script execution is halted after the redirect.
  *
  * @param mixed $url A string or array-based URL pointing to another location within the app, or an absolute URL
  * @param integer $status Optional HTTP status code (eg: 404)
  * @access public
  * @link http://book.cakephp.org/view/425/redirect
  */
 public function redirect($url, $status = null, $useReferer = true)
 {
     if ($useReferer) {
         $ref = SlSession::read('Routing.ref');
         if ($ref) {
             SlSession::delete('Routing.ref');
             if (Sl::url($ref) !== Sl::url()) {
                 $url = $ref;
             }
         }
     }
     // cyclic check
     if (Sl::url($url) === Sl::url()) {
         die('Infinite redirection loop detected.');
     }
     // code inspired from RequestHandlerComponent
     if ($this->RequestHandler->isAjax()) {
         foreach ($_POST as $key => $val) {
             unset($_POST[$key]);
         }
         echo Sl::requestAction($url, array('requested' => false));
         $this->_stop();
     }
     // show a human readable redirect message allowing debug output to be read
     if (headers_sent() || $this->output && Configure::read()) {
         $url = h(SL::url($url));
         if (empty($status)) {
             $status = 'null';
         }
         echo "<p style='background: #ff7; color: #000; padding: 1em;'>Redirect to <a href='{$url}'>{$url}</a> (code: {$status}) cancelled.</p>";
         while (ob_get_level()) {
             ob_end_flush();
         }
         $this->_stop();
     }
     parent::redirect(Sl::url($url, true), $status);
 }
Ejemplo n.º 3
0
 function parse($html, $blockName = 'document', $blockParams = null)
 {
     return Sl::requestAction(trim(parent::parse($html)), (array) $blockParams);
 }