Exemple #1
0
/**
 * Smarty {block} function plugin
 *
 * Type:     function<br>
 * Name:     block<br>
 * Purpose:  Loads in a CMS block from the database<br>
 * @author Nathan Gardner <*****@*****.**>
 * @param array
 * @param Smarty
 */
function smarty_function_block($params, &$smarty)
{
    if (!empty($params['identifier'])) {
        $objBlock = new BlocksModel();
        $blockId = $objBlock->getBlockId($params['identifier']);
        if (!empty($blockId)) {
            $blockInfo = $objBlock->loadBlock($blockId);
            return $smarty->fetch('fromstring:' . $blockInfo['code']);
        } else {
            return 'ERROR: Unknown block identifier';
        }
    } else {
        return 'ERROR: Must pass block identifier';
    }
}
 public function init()
 {
     $blocks = BlocksModel::model()->cache(Yii::app()->controller->cacheTime)->enabled()->findAll();
     if (!empty($blocks)) {
         foreach ($blocks as $row) {
             if (!isset($this->data[$row['position']])) {
                 $this->data[$row['position']] = array();
             }
             $this->data[$row['position']][$row['id']] = array('blockID' => $row['id'], 'blockPOS' => $row['position'], 'modules' => $row['modules'], 'access' => $row['access'], 'widget' => $row['widget'], 'name' => $row['name'], 'content' => $row['content']);
         }
     }
 }
 public function actionUpdate($new = false)
 {
     $model = $new === true ? new BlocksModel() : BlocksModel::model()->findByPk($_GET['id']);
     if (isset($model)) {
         $this->pageName = Yii::t('app', 'BLOCKS');
         $this->breadcrumbs = array($this->pageName => Yii::app()->createUrl('admin/core/blocks'), $new === true ? Yii::t('app', 'CREATE', 1) : Yii::t('app', 'UPDATE', 1));
         if (isset($_POST['BlocksModel'])) {
             $model->attributes = $_POST['BlocksModel'];
             if (!empty($model->modules)) {
                 $model->modules = implode(',', $_POST['BlocksModel']['modules']);
             }
             if ($model->validate()) {
                 if ($_POST['BlocksModel']['expire'] == 0) {
                     $model->expire = 0;
                 } else {
                     $model->expire = time() + $_POST['BlocksModel']['expire'] * 86400;
                 }
                 if ($model->widget) {
                     Yii::import('app.blocks_settings.*');
                     $manager = new BlockSystemManager();
                     $system = $manager->getSystemClass($model->widget);
                     if ($system) {
                         $system->saveSettings($model->widget, $_POST);
                     } else {
                     }
                 }
                 $model->save();
                 //$this->refresh();
             }
         } else {
         }
         if (!empty($model->modules)) {
             $modules = explode(',', $model->modules);
             foreach ($modules as $mod) {
                 $mods[] = $mod;
             }
             $model->modules = $mods;
         }
         $this->render('update', array('model' => $model));
     } else {
         throw new CHttpException(404);
     }
 }
Exemple #4
0
 function actionDeleteBlock($params = '')
 {
     if (!empty($params['block_id'])) {
         $objBlocks = new BlocksModel();
         $objBlocks->deleteBlock($params['block_id']);
         $this->messages[] = array('type' => 'success', 'message' => 'Block has been deleted.');
     } else {
         $this->messages[] = array('type' => 'error', 'message' => 'Unknown block to delete.');
     }
     $this->actionBlocks();
 }