More lengthy description of what ContentWidget does and why it's fantastic.

Usage Examples

Author: Charlie Powell (charlie@evalagency.com)
Inheritance: extends Widget_2_1
Example #1
0
 public function init()
 {
     parent::init();
     if ($this->params['widget']->title == '') {
         $this->params['widget']->title = ' ';
     }
 }
Example #2
0
 public function init()
 {
     parent::init();
     $ids = explode(',', $this->params['page']->path);
     $pages = Page::model()->findAll(array('condition' => 't.`id` IN (' . $this->params['page']->path . ')', 'order' => '`path` DESC'));
     $parents = array();
     foreach ($pages as $p) {
         $parents[$p->id] = $p;
     }
     unset($pages);
     $links = array();
     foreach ($ids as $id) {
         if ($id == 0 || $id == 1) {
             continue;
         }
         $links[$parents[$id]->title] = array('view/index', 'pageId' => $parents[$id]->id, 'alias' => $parents[$id]->alias, 'url' => $parents[$id]->url);
     }
     if ($this->params['page']->id != 1) {
         $links[] = $this->params['page']->title;
     } else {
         $links[] = '';
     }
     $this->params['links'] = $links;
     $this->params['separator'] = $this->params['content']->separator ? $this->params['content']->separator : self::DEFAULT_SEPARATOR;
     $this->params['homeLink'] = $parents ? CHtml::link($parents[1]->title, array('view/index', 'pageId' => $parents[1]->id, 'alias' => $parents[1]->alias, 'url' => $parents[1]->url)) : $this->params['page']->title;
 }
Example #3
0
 public function init()
 {
     parent::init();
     $image = $this->params['content']->image;
     $image['filename'] = ImageHelper::resizeDown($image['filename'], $this->params['content']->width, $this->params['content']->height);
     $this->params['content']->image = $image;
 }
Example #4
0
 public function init()
 {
     parent::init();
     $this->params['formButtons'] = array('login' => array('type' => 'submit', 'label' => Yii::t('UnitLogin.main', 'Login'), 'title' => Yii::t('UnitLogin.main', 'Login')));
     $this->params['doRemember'] = Yii::app()->request->getPost('RememberForm') !== null;
     if ($this->proccessRequest()) {
         if ($this->params['doRemember']) {
             $this->params['doneRemember'] = true;
         } else {
             Yii::app()->controller->refresh();
         }
     }
     if (Yii::app()->request->getParam('authcode') !== null) {
         $user = User::model()->find('`authcode`=:authcode', array('authcode' => Yii::app()->request->getParam('authcode')));
         if ($user) {
             $identity = new AuthCodeIdentity(Yii::app()->request->getParam('authcode'));
             $identity->authenticate();
             if ($identity->errorCode === UserIdentity::ERROR_NONE) {
                 Yii::app()->user->login($identity);
             }
             $user->saveAttributes(array('authcode' => '', 'askfill' => true));
             Yii::app()->controller->refresh();
         }
     }
 }
Example #5
0
 public function init()
 {
     parent::init();
     $id = __CLASS__ . $this->params['content']->id;
     $this->params['profileVar'] = $this->urlParam('view');
     $blank = true;
     if (Yii::app()->request->getParam($this->params['profileVar']) !== null) {
         $profile = User::model()->findByPk(intval(Yii::app()->request->getParam($this->params['profileVar'])));
         if ($profile) {
             $this->params['details'] = Yii::app()->controller->widget('zii.widgets.CDetailView', array('data' => $profile, 'attributes' => $this->makeFields($this->params['content']->displayed_fields, $profile)), true);
             $this->params['profile'] = $profile->getAttributes();
             if (Yii::app()->user->hasRole($profile->send_message) && $profile->id != $this->params['user']->id && $profile->email) {
                 $vm = new VirtualModel($this->params['content']->feedback_form, 'FieldSet');
                 $config = $vm->formMap;
                 $config['id'] = sprintf('%x', crc32(serialize(array_keys($this->params['content']->feedback_form))));
                 $config['buttons'] = array('send' => array('type' => 'submit', 'label' => Yii::t('UnitProfiles.main', 'Send')));
                 $config['activeForm'] = Form::ajaxify($config['id']);
                 $config['activeForm']['clientOptions']['validationUrl'] = '/?r=view/widget&pageWidgetId=' . $this->params['pageWidget']->id . '&' . $this->params['profileVar'] . '=' . $profile->id;
                 $config['activeForm']['clientOptions']['afterValidate'] = "js:function(f,d,h){if (!h) {return true;}}";
                 $form = new Form($config, $vm);
                 if (Yii::app()->request->getParam('ajax-validate') !== null) {
                     echo CActiveForm::validate($vm);
                     Yii::app()->end();
                 }
                 if ($form->submitted('send')) {
                     $vm = $form->model;
                     if ($form->validate()) {
                         $cfg = ContentUnit::loadConfig();
                         $viewFileDir = $cfg['UnitProfiles'] . '.profiles.templates.mail.';
                         $labels = $vm->attributeLabels();
                         foreach ($vm->getAttributes() as $attr => $value) {
                             $tpldata['fields'][$labels[$attr]] = $value;
                         }
                         $tpldata['profile'] = $profile->getAttributes();
                         $tpldata['settings'] = Yii::app()->settings->model->getAttributes();
                         $tpldata['page'] = $this->params['content']->getWidgetPageArray();
                         $registerModel = ModelRegister::model()->find('widget_id > 0');
                         $registerWidget = new WidgetRegister();
                         if ($registerUnit) {
                             $tpldata['profileEditUrl'] = $registerModel->getWidgetUrl();
                             $tpldata['profileEditUrlParams'] = $registerWidget->urlParam('do') . '=edit';
                         }
                         Yii::app()->messenger->send('email', $profile->email, '[' . $_SERVER['HTTP_HOST'] . '] ' . Yii::t('UnitProfiles.main', 'Feedback form'), Yii::app()->controller->renderPartial($viewFileDir . 'feedback', $tpldata, true));
                         Yii::app()->user->setFlash('UnitProfilesSend-permanent', Yii::t('UnitProfiles.main', 'Your message was successfully sent'));
                         Yii::app()->controller->refresh();
                     }
                 }
                 $this->params['feedbackForm'] = $form->render();
             }
         } else {
             $this->params['error'] = Yii::t('UnitProfiles.main', 'Profile not found');
         }
         $blank = false;
     }
     if ($blank) {
         $this->prepareTable();
     }
 }
Example #6
0
 public function init()
 {
     parent::init();
     $model = $this->params['content']->page ? Page::model()->findByPk($this->params['content']->page) : $this->params['page'];
     $this->params['title'] = $this->params['widget']->title ? $this->params['widget']->title : $model->title;
     $id = $this->params['content']->recursive ? $model->id : $model->parent_id;
     $this->params['items'] = array();
     if ($id) {
         $this->params['items'] = $this->getTree($id, $this->params, $this->params['content']->recursive, true);
     }
     $this->params['count_items'] = count($this->params['items']);
     $this->params['pager'] = $this->renderPager($this->params['count_items'], $model->childrenCount, $this->pageNumber, $this->params['content']->per_page);
 }
Example #7
0
 public function init()
 {
     parent::init();
     $keys = array_keys($this->params['content']->images);
     $image = $this->params['content']->images[$keys[rand(0, count($keys) - 1)]];
     $image['filename'] = ImageHelper::resizeDown($image['filename'], $this->params['content']->width, $this->params['content']->height);
     $this->params['image'] = $image;
     if (isset($image['data'][Yii::app()->language . '_caption'])) {
         $this->params['caption'] = $image['data'][Yii::app()->language . '_caption'];
     } else {
         $this->params['caption'] = $this->params['widget']->title;
     }
 }
Example #8
0
 public function init()
 {
     parent::init();
     $viewParam = $this->urlParam('view');
     if (Yii::app()->request->getQuery($viewParam) !== null) {
         $this->params['url'] = $this->params['content']->getWidgetUrl(true);
         $this->params['entry'] = ModelBlog_Entry::model()->findByPk(intval(Yii::app()->request->getQuery($viewParam)));
         $this->params['templateType'] = 'entry';
     } else {
         ModelBlog_Entry::model()->setPopulateMode(false);
         $entries = ModelBlog_Entry::model()->public()->selectPage($this->pageNumber, $this->params['content']->per_page)->findAll('blog_id = :id', array(':id' => $this->params['content']->id));
         ModelBlog_Entry::model()->setPopulateMode(true);
         $this->params['entries'] = array();
         foreach ($entries as $entry) {
             $entry['url'] = $this->params['content']->getWidgetUrl(true, self::entryUrlParams($entry));
             $entry['image'] = unserialize($entry['image']);
             $this->params['entries'][] = $entry;
         }
         $this->params['pager'] = $this->renderPager(count($entries), $this->params['content']->itemsCount, $this->pageNumber, $this->params['content']->per_page);
     }
 }
Example #9
0
 public function init()
 {
     parent::init();
     $this->params['items'] = array();
     // Сейчас функция нацелена на виджеты, но нужно переделать на модели.
     // Правда, тогда не ясно в каком виде выводить полученную информацию.
     // Где взять шаблоны?
     if (Yii::$classMap[$this->params['content']->class_name] && method_exists($this->params['content']->class_name, 'feedItem')) {
         $rule = $this->params['content']->makeRule();
         $modelClass = $this->params['content']->class_name;
         $feed = call_user_func(array($this->params['content']->class_name, 'feedItem'));
         eval("\$items = {$modelClass}::model()->{$rule}findAll();");
         foreach ($items as $itemSource) {
             $item = $itemSource->attributes;
             foreach ($feed as $element => $attribute) {
                 if ($attribute) {
                     $item[$element] = $itemSource->{$attribute};
                 }
             }
             $this->params['items'][] = $item;
         }
     }
 }
Example #10
0
 public function init()
 {
     parent::init();
     $this->params['areaId'] = 'widget' . $this->params['widget']->id . 'ModelArea_items';
     $this->params['pageWidgets'] = PageWidget::model()->findAll(array('condition' => '`area` = :area', 'params' => array('area' => $this->params['areaId']), 'with' => array('widget'), 'order' => '`order`'));
 }
Example #11
0
 public function init()
 {
     parent::init();
     if (Yii::app()->request->getQuery($this->urlParam('do')) !== null) {
         $this->params['doParam'] = Yii::app()->request->getQuery($this->urlParam('do'));
     }
     if (($this->params['isGuest'] || $this->params['editMode']) && $this->params['doParam'] != 'edit') {
         $model = new User('register');
         $makeForm = $model->makeForm('register', $this->params['content']->fields, $this->params['content']->fields_req);
         $this->params['formElements'] = $makeForm['elements'];
         $this->params['formRules'] = $makeForm['rules'];
         if (Yii::app()->request->getParam('ajax-validate') !== null) {
             echo CActiveForm::validate($model);
             Yii::app()->end();
         }
         if ($this->proccessRequest()) {
             if ($this->params['content']->is_emailauth_req) {
                 $this->params['waitingAuthCode'] = true;
             } else {
                 $this->params['justRegistered'] = true;
             }
         }
         if (Yii::app()->request->getParam('authocode')) {
             $user = User::model()->find('`authcode`=:authcode', array('authcode' => Yii::app()->request->getParam('authocode')));
             if ($user) {
                 $identity = new AuthCodeIdentity(Yii::app()->request->getParam('authocode'));
                 $identity->authenticate();
                 if ($identity->errorCode === UserIdentity::ERROR_NONE) {
                     Yii::app()->user->login($identity);
                 }
                 $user->saveAttributes(array('active' => true, 'authcode' => ''));
                 $cfg = ContentUnit::loadConfig();
                 $viewFileDir = $cfg['UnitRegister'] . '.register.templates.mail.';
                 $tpldata = array('model' => $user, 'settings' => Yii::app()->settings->model->getAttributes(), 'page' => $this->params['content']->getWidgetPageArray());
                 if ($this->params['content']->notify_user) {
                     // send 'to_user_notify' mail
                     Yii::app()->messenger->send('email', $user->email, Yii::t('UnitRegister.main', 'Registration completed'), Yii::app()->controller->renderPartial($viewFileDir . 'to_user_notify', $tpldata, true));
                 }
                 $this->params['confirmedAuthCode'] = true;
                 unset($_REQUEST['authcode']);
             } else {
                 $this->params['faultAuthCode'] = true;
             }
         }
     } else {
         if ($this->params['isGuest']) {
             $this->params['accessDenied'] = true;
         } else {
             $makeForm = $this->params['user']->makeForm('update', $this->params['content']->profile_fields, $this->params['content']->profile_fields_req);
             $this->params['formElements'] = $makeForm['elements'];
             $this->params['formRules'] = $makeForm['rules'];
             $profileModel = ModelProfiles::model()->find('widget_id > 0');
             $profileWidget = new WidgetProfiles();
             if ($profileModel) {
                 $this->params['profileWidgetUrl'] = $profileModel->getWidgetUrl();
             }
             $this->params['profileWidgetUrlParams'] = $profileWidget->urlParam('view') . '=' . $this->params['user']->id;
             if (Yii::app()->request->getParam('ajax-validate') !== null) {
                 echo CActiveForm::validate($this->params['user']);
                 Yii::app()->end();
             }
             if (Yii::app()->request->getPost('User') !== null) {
                 $this->params['user']->attributes = Yii::app()->request->getPost('User');
                 if ($this->params['user']->save()) {
                     Yii::app()->user->setFlash('save-permanent', Yii::t('UnitRegister.main', 'Profile edited successfully'));
                     Yii::app()->controller->refresh();
                 }
             }
         }
     }
 }
Example #12
0
 public function init()
 {
     parent::init();
     $this->params['q'] = Yii::app()->request->getQuery('q');
 }
Example #13
0
 public function init()
 {
     parent::init();
     $this->params['tree'] = Page::model()->getTree();
 }
Example #14
0
, CClientScript::POS_READY);
        }
    }
    $this->renderPartial('/toolbars', compact('model', 'language'));
    ?>

<div class="cms-hidden">

    <div id="cms-pagewidget-add" class="cms-splash cms-pagewidget-add">
        <h3><?php 
    echo Yii::t('cms', 'Add widget');
    ?>
</h3>
        <ul>
        <?php 
    $units = ContentWidget::getInstalledWidgets();
    $units_count = count($units);
    $i = 0;
    foreach ($units as $unit) {
        $i++;
        foreach ($unit['widgets'] as $widget) {
            $modelClassName = call_user_func(array($widget['className'], 'modelClassName'));
            $model = CActiveRecord::model($modelClassName);
            if (!$model->isMaxLimitReached()) {
                ?>
<li><a class="cms-button cms-btn-pagewidget-create" id="cms-button-create-<?php 
                echo $widget['className'];
                ?>
" title="<?php 
                echo $widget['name'];
                ?>
Example #15
0
 public function init()
 {
     parent::init();
     $this->params['languages'] = I18nActiveRecord::getLangs();
 }
Example #16
0
 public function init()
 {
     parent::init();
     $this->params['video'] = WidgetVideo::getHtmlByUrl($this->params['content']->video, $this->params['content']->width, $this->params['content']->height, $this->params['widget']->title);
 }