public function execute()
 {
     $id = waRequest::post('id');
     $model = new siteBlockModel();
     $block = $model->getById($id);
     if ($block) {
         $model->deleteById($id);
         $this->logAction('block_delete');
     }
 }
 public function execute()
 {
     $id = waRequest::get('id');
     $info = waRequest::post('info');
     if (!preg_match("/^[a-z0-9\\._]+\$/i", $info['id'])) {
         $this->errors = array(_w('Only latin characters, numbers and underscore symbol are allowed.'), 'input[name="info[id]"]');
         return;
     }
     $model = new siteBlockModel();
     if ($id) {
         try {
             $model->updateById($id, $info);
             $this->log('block_edit');
             if ($id != $info['id']) {
                 $info['old_id'] = $id;
             }
             $this->response($info);
         } catch (Exception $e) {
             if ($model->getById($info['id'])) {
                 $this->errors = array(_w('Block with id "%s" already exists', null, null, $info['id']));
             } else {
                 throw $e;
             }
         }
     } else {
         try {
             $model->add($info);
             $this->log('block_add');
             $this->response($info);
         } catch (Exception $e) {
             if ($model->getById($info['id'])) {
                 $this->errors = array(_w('Block with id "%s" already exists', null, null, $info['id']));
             } else {
                 throw $e;
             }
         }
     }
     if ($this->getConfig()->getOption('cache_time')) {
         waSystem::getInstance()->getView()->clearAllCache();
     }
 }
/**
 * @param $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_wa_block($params, &$smarty)
{
    if (isset($params['id']) && $params['id'] && wa()->appExists('site')) {
        wa('site');
        $model = new siteBlockModel();
        $block = $model->getById($params['id']);
        unset($params['id']);
        if ($params) {
            $smarty->assign('params', $params);
        }
        if ($block) {
            return $smarty->fetch('string:' . $block['content']);
        }
    }
    return '';
}
예제 #4
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 '';
 }