Пример #1
0
 public function allowed_sections_model()
 {
     $sections = new CmsSection();
     if ($ids = $this->allowed_sections_ids()) {
         $sections->filter(array("id" => $ids));
     }
     return $sections;
 }
Пример #2
0
 /**
  * ajax filter function - takes the incoming string, matches against columns 
  * and outputs view of the matching data
  */
 public function filters()
 {
     $this->use_layout = false;
     $sect = new CmsSection();
     $this->all_sections = $sect->filter("title LIKE '%{$fil}%'")->tree();
     $this->use_view = "_section_list";
     $this->all_sections_partial = $this->render_partial("section_list");
 }
 /** SECTIONS **/
 private function section($index)
 {
     if ($this->cms_section && $this->cms_section->primval && $this->section_stack[$index]) {
         $section = new CmsSection();
         return $section->filter("url", $this->section_stack[$index])->first();
     } else {
         return false;
     }
 }
Пример #4
0
 /**
  * Ajax function - removes an association between a section and a user
  * makes a view with new data
  **/
 public function remove_section()
 {
     $this->use_layout = false;
     $this->model = new $this->model_class(WaxUrl::get("id"));
     $section = new CmsSection(Request::get("sect"));
     $this->model->allowed_sections->unlink($section);
     $sect = new CmsSection();
     $this->all_sections = $sect->all();
     $this->use_view = "_list_sections";
 }
Пример #5
0
 public function sitemap()
 {
     $this->base_url = 'http://' . $_SERVER['HTTP_HOST'];
     $section = new CmsSection();
     $this->sections = $section->all();
     $content = new CmsContent("published");
     $this->pages = $content->all();
     if ($this->use_format == "xml") {
         header("Content-type: application/xml");
         $this->use_layout = false;
     }
 }
Пример #6
0
 public function get_content($section_title, $params = array(), $model = "CmsContent")
 {
     $section = new CmsSection();
     $sec = $section->find_by_title($section_title);
     if (!$sec) {
         $sec = $section->find_by_url($section_title);
     }
     if (!$sec) {
         $sec = $section->find($section_title);
     }
     $content = new $model();
     return $content->published_content($sec->url, $sec->id, $params);
 }
 /**
  * sort out submenus, set up actions, find all sections
  * handle posts etc
  * @return void
  */
 public function controller_global()
 {
     unset($this->sub_links["index"]);
     unset($this->sub_links["create"]);
     $this->type = $this->action;
     if ($this->type == "index") {
         $this->type = "general";
     }
     $this->action = "edit";
     $this->all_cms_modules = CmsApplication::get_modules();
     $section = new CmsSection();
     $this->all_cms_sections = $section->all();
     $this->options_setup();
     $this->handle_post();
     $this->variable_setup();
 }
Пример #8
0
 public function related()
 {
     $this->use_layout = false;
     $this->use_view = "_related_list";
     $this->article_offset = 0;
     if (Request::post('page_number') && Request::post('section')) {
         $page = parse_url(Request::post('page_number'));
         $page = str_replace("page=", "", $page['query']);
         if ($page && Request::post('section')) {
             $this->this_page = $page;
             $section = new CmsSection();
             $content = new CmsContent("published");
             $this->cms_section = $section->filter(array('url' => Request::post('section')))->first();
             if ($this->cms_section->id) {
                 $this->cms_section_id = $this->cms_section->id;
                 $this->cms_content = $content->filter(array('cms_section_id' => $this->cms_section_id))->order('published DESC')->page($this->this_page, $this->per_page);
             }
         }
     }
 }
Пример #9
0
	<fieldset style="width: 45%">
		<legend><?php 
echo Yii::t('admin', 'Routes');
?>
</legend>
		<?php 
$this->widget('application.components.widgets.TabularInput.TabularInputWidget', array('id' => 'routesForm', 'form' => $form, 'models' => $cmsAliasRoutes, 'layout' => array('_route' => new CmsAliasRoute()), 'template' => 'noheader-noborder'));
?>
	</fieldset>

	<div class="row">
		<?php 
echo $form->labelEx($cmsAlias, 'section_id');
?>
		<?php 
echo $form->dropDownList($cmsAlias, 'section_id', CHtml::listData(CmsSection::model()->findAll(), 'id', 'name'), array('empty' => ''));
?>
		<?php 
echo $form->error($cmsAlias, 'section_id');
?>
	</div>
	
	<div class="row">
		<?php 
echo $form->labelEx($cmsAlias, 'allow_children');
?>
		<?php 
echo $form->checkbox($cmsAlias, 'allow_children');
?>
		<?php 
echo $form->error($cmsAlias, 'allow_children');
Пример #10
0
 public function afterValidate()
 {
     if ($this->isNewRecord) {
         $auth = Yii::app()->authManager;
         $module = Yii::createComponent('application.modules.' . $this->module . '.' . ucfirst($this->module) . 'Module', null, null);
         if (!$module->instantiable && CmsSection::model()->findAllByAttributes(array('module' => $this->module)) != null) {
             $this->addError('module', Yii::t('admin', 'Ce module ne peut être instancié.'));
         }
     }
     return parent::afterValidate();
 }
Пример #11
0
 public function find_most_commented($section = "1", $since = "7", $limit = "10")
 {
     $content = new CmsContent();
     $sections = new CmsSection();
     if ($section && !is_numeric($section)) {
         $section = $sections->filter(array('url' => $section))->first()->id;
     }
     $sql = "SELECT *, count(attached_id) as counter FROM `cms_comment` RIGHT JOIN cms_content ON attached_id=cms_content.id WHERE cms_comment.status=1 AND `time` > date_sub(now(), INTERVAL '{$since}' DAY)";
     if ($section) {
         $sql .= " AND cms_section_id={$section}";
     }
     $sql .= " GROUP BY attached_id ORDER BY counter DESC LIMIT {$limit}";
     return $content->find_by_sql($sql);
 }
Пример #12
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id, $ml = false)
 {
     if ($ml) {
         $model = CmsSection::model()->multilang()->findByPk((int) $id);
     } else {
         $model = CmsSection::model()->findByPk((int) $id);
     }
     if ($model === null) {
         throw new CHttpException(404, 'The requested post does not exist.');
     }
     return $model;
 }
Пример #13
0
 /**
  * Takes the url passed in and tries to find a section with a matching url
  * - if finds one, set the cms_section & return true
  * - if it finds more than one, then reverse stack, traverse back looking for matching parents & return true
  * - return false 
  * @param String $url 
  * @return Boolean
  */
 protected function find_section($url, $parent = false)
 {
     $section = new CmsSection();
     if ($parent) {
         $section->filter(array('parent_id' => $parent));
     }
     $res = $section->filter(array('url' => $url))->all();
     if (count($res) == 1) {
         $this->cms_section = $res[0];
         return true;
     } elseif (count($res) > 1) {
         $stack = array_reverse($this->section_stack);
         //if empty, add home section
         if (!count($stack)) {
             $stack[] = "home";
         }
         foreach ($res as $result) {
             if ($result->parent->url == $stack[0]) {
                 $this->cms_section = $result;
             }
         }
         return true;
     } else {
         return false;
     }
 }
Пример #14
0
 public function actions()
 {
     $formSettings = array('redirect' => $this->createUrl('admin'), 'forms' => array('id' => 'mainForm', 'varName' => 'contentPage', 'models' => 'ContentPage', 'forms' => array('id' => 'blocsForm', 'blocs' => 'content', 'varName' => 'blocs'), 'onAfterSetAttributes' => function ($event) {
         if (Yii::app()->user->id != 'Admin-1' && isset($this->module->layouts)) {
             $model = $event->params['model'];
             if ($model->layout == '') {
                 foreach ($this->module->layouts as $layoutName => $layoutTitle) {
                     $model->layout = $layoutName;
                     break;
                 }
             }
         }
     }, 'onBeforeSave' => function ($event) {
         $model = $event->params['model'];
         if ($model->isNewRecord) {
             $alias = new CmsAlias();
             foreach (Yii::app()->languageManager->languages as $language => $fullLanguage) {
                 if ($language === Yii::app()->sourceLanguage) {
                     $suffix = '';
                 } else {
                     $suffix = '_' . $language;
                 }
                 $alias->{'alias' . $suffix} = AdminHelper::generateUrlStr($model->{'title' . $suffix}, $alias, 'alias', null, $language);
                 $alias->{'title' . $suffix} = $model->{'title' . $suffix};
             }
             $alias->section_id = CmsSection::model()->findByAttributes(array('module' => 'content'))->id;
             $alias->allow_children = 1;
             $alias->attributes = $_POST['CmsAlias'];
             $root = CmsAlias::model()->roots()->find();
             $alias->appendTo($root);
             $aliasRoute = new CmsAliasRoute();
             $aliasRoute->route = 'content';
             $aliasRoute->alias_id = $alias->primaryKey;
             $aliasRoute->save();
             $model->alias_id = $alias->primaryKey;
         } else {
             $alias = CmsAlias::model()->multilang()->findByPk($model->alias->id);
             $alias->attributes = $_POST['CmsAlias'];
             foreach (Yii::app()->languageManager->languages as $language => $fullLanguage) {
                 if ($language === Yii::app()->sourceLanguage) {
                     $suffix = '';
                 } else {
                     $suffix = '_' . $language;
                 }
                 $alias->{'alias' . $suffix} = AdminHelper::generateUrlStr($model->{'title' . $suffix}, $alias, 'alias', $alias->id, $language);
                 $alias->{'title' . $suffix} = $model->{'title' . $suffix};
             }
         }
         if ($alias->location != 'nochange') {
             $decode = CJSON::decode($_POST['CmsAlias']['location']);
             $to = CmsAlias::model()->findByPk((int) $decode['to']);
             $action = $decode['action'];
             switch ($action) {
                 case 'child':
                     $alias->moveAsLast($to);
                     break;
                 case 'before':
                     if ($to->isRoot()) {
                         $alias->moveAsRoot();
                     } else {
                         $alias->moveBefore($to);
                     }
                     break;
                 case 'after':
                     if ($to->isRoot()) {
                         $alias->moveAsRoot();
                     } else {
                         $alias->moveAfter($to);
                     }
                     break;
             }
         } else {
             $alias->saveNode();
         }
     }));
     return array('create' => array('class' => 'application.components.actions.Create', 'formSettings' => $formSettings), 'update' => array('class' => 'application.components.actions.Update', 'formSettings' => $formSettings), 'delete' => array('class' => 'application.components.actions.Delete', 'modelClass' => 'ContentPage'), 'admin' => array('class' => 'application.components.actions.Admin', 'modelClass' => 'ContentPage'));
 }
Пример #15
0
 public function init()
 {
     $app = Yii::app();
     // register dropbox autoload
     /*
     spl_autoload_unregister(array('YiiBase','autoload'));
     require_once 'protected/vendors/dropbox-sdk-php/lib/Dropbox/autoload.php';
     spl_autoload_register(array('YiiBase','autoload'));
     */
     $app->languageManager->restrictLanguage(Yii::app()->sourceLanguage);
     $app->urlManager->cancelAliasResolution = true;
     $app->user->loginUrl = array('/admin/login');
     // There are two WebUser to not have conflicts, one for the front-end and one for the back-end, this sets it to the back-end
     Yii::app()->setComponent('user', Yii::app()->userBack);
     // Checking access
     if (isset($this->module->id) && in_array($this->module->id, $app->cms->modules)) {
         if ($this->module->instantiable == true && isset($_GET['section_id'])) {
             if (!($app->cms->currentSectionId = CmsSection::model()->findByPk($_GET['section_id'])->id)) {
                 throw new CHttpException(404, 'The requested section does not exist.');
             }
             if (!$app->user->checkAccess('adminSectionId-' . $app->cms->currentSectionId)) {
                 $app->user->loginRequired();
             }
         } else {
             if (!$app->user->checkAccess('adminModule-' . strtolower(substr(get_class($this->module), 0, strrpos(get_class($this->module), 'Module'))))) {
                 $app->user->loginRequired();
             }
         }
     }
     // Setting up ckeditor
     $ckContentCss = array('/css/admin/ck-bootstrap.css', '/css/framework.css', '/css/project.css', '/css/blocs.css', '/css/admin/ckeditor.css');
     if (isset(Yii::app()->params['googleFont'])) {
         array_unshift($ckContentCss, Yii::app()->params['googleFont']);
     }
     $this->ckeditor = 'vendors/ckeditor/ckeditor.php';
     $this->ckBasePath = Yii::app()->baseUrl . '/vendors/ckeditor/';
     $this->ckEditorConfig = array('width' => '100%', 'height' => '400px', 'language' => $app->language, 'uiColor' => '#cae0ec', 'bodyId' => 'content', 'bodyClass' => 'ckeditor section-bloc bloc-editor', 'forcePasteAsPlainText' => true, 'disableReadonlyStyling' => true, 'startupShowBorders' => false, 'resize_enabled' => true, 'filebrowserUploadUrl' => $this->createUrl('/admin/ckeditorupload', array('type' => 'file')), 'filebrowserImageUploadUrl' => $this->createUrl('/admin/ckeditorupload', array('type' => 'image')), 'contentsCss' => $ckContentCss, 'format_tags' => 'p;h2;h3;h4', 'stylesSet' => 'my_styles:/javascript/ckstyles.js', 'toolbar' => 'Full', 'toolbar_Full' => array(array('Bold', 'Italic', 'Strike', 'Subscript', 'Superscript'), array('NumberedList', 'BulletedList', 'Outdent', 'Indent', 'Table'), array('Link', 'Unlink', 'Anchor', 'Image', 'MediaEmbed'), array('Format', 'Styles'), array('Cut', 'Copy', 'PasteText'), array('Undo', 'Redo', '-', 'SelectAll', 'RemoveFormat', 'Source')));
     $this->ckEditorConfigSimple = array('width' => '100%', 'height' => '200px', 'uiColor' => '#cae0ec', 'language' => $app->language, 'bodyId' => 'content', 'bodyClass' => 'ckeditor section-bloc bloc-editor', 'forcePasteAsPlainText' => true, 'disableReadonlyStyling' => true, 'startupShowBorders' => false, 'resize_enabled' => true, 'contentsCss' => $ckContentCss, 'format_tags' => 'p;h2;h3;h4', 'stylesSet' => 'my_styles:/javascript/ckstyles.js', 'toolbar' => 'Full', 'toolbar_Full' => array(array('Bold', 'Italic', 'Strike', 'Subscript', 'Superscript'), array('Link', 'Unlink'), array('Undo', 'Redo')));
     // Loading up js libraries
     //$app->clientScript->registerCoreScript('jquery');
     //$app->clientScript->registerCoreScript('jquery.ui');
     //$app->clientScript->registerCssFile(Yii::app()->request->baseUrl.'/css/jqueryui/backTheme/jquery-ui.css');
     //$app->clientScript->registerScript('jqueryDatepickerLanguage', "$.datepicker.setDefaults($.datepicker.regional['".Yii::app()->language."']);", CClientScript::POS_READY);
     //$app->clientScript->registerScriptFile($app->clientScript->getCoreScriptUrl().'/jui/js/jquery-ui-i18n.min.js');
     // Styling form buttons with jQuery
     /*
     $app->clientScript->registerScript('inputButtons', "
     	$('input:submit, input:button').button();
     ", CClientScript::POS_READY);
     */
     // Setting up the menu
     foreach (CmsSection::model()->findAll() as $section) {
         if (in_array($section->module, $app->cms->modules)) {
             $className = $section->module . 'Module';
             $moduleMenu = $className::getAdminMenu();
             foreach ($moduleMenu as $moduleMenuItem) {
                 $moduleMenuItem['label'] = str_replace('{sectionName}', $section->name, $moduleMenuItem['label']);
                 $moduleMenuItem['url']['section_id'] = $section->id;
                 $moduleMenuItem['icon'] = $moduleMenuItem['icon'];
                 if (isset($moduleMenuItem['subMenu'])) {
                     foreach ($moduleMenuItem['subMenu'] as $key => $moduleSubMenuItem) {
                         $moduleMenuItem['subMenu'][$key]['url']['section_id'] = $section->id;
                     }
                 }
                 $this->mainMenu[] = $moduleMenuItem;
             }
         }
     }
     return parent::init();
 }
Пример #16
0
 /**
  * Ajax Filter list view
  */
 public function filter()
 {
     $this->model->filter(array("status" => array(0, 1)));
     if (Request::post("section")) {
         $section = new CmsSection(Request::post("section"));
         foreach ($section->tree() as $section) {
             $section_ids[] = $section->primval;
         }
         $this->model->filter(array("cms_section_id" => $section_ids));
     }
     parent::filter();
 }