Exemplo n.º 1
0
 public function block($id, $params = array())
 {
     if ($id && wa()->appExists('site')) {
         wa('site');
         $model = new siteBlockModel();
         $block = $model->getById($id);
         if (!$block && strpos($id, '.') !== false) {
             list($app_id, $id) = explode('.', $id);
             $path = $this->getConfig()->getAppsPath($app_id, 'lib/config/site.php');
             if (file_exists($path)) {
                 $site_config = (include $path);
                 if (isset($site_config['blocks'][$id])) {
                     if (!is_array($site_config['blocks'][$id])) {
                         $block = array('content' => $site_config['blocks'][$id]);
                     } else {
                         $block = $site_config['blocks'][$id];
                     }
                 }
             }
         }
         if ($block) {
             try {
                 $this->view->assign($params);
                 return $this->view->fetch('string:' . $block['content']);
             } catch (Exception $e) {
                 if (waSystemConfig::isDebug()) {
                     return '<pre class="error">' . htmlentities($e->getMessage(), ENT_QUOTES, 'utf-8') . "</pre>";
                 } else {
                     waLog::log($e->__toString());
                     return '<div class="error">' . _ws('Syntax error at block') . ' ' . $id . '</div>';
                 }
             }
         }
     }
     return '';
 }