Example #1
0
 /**
  * @param \yii\web\UrlManager $manager
  * @param string $route
  * @param array $params
  * @return bool|string
  */
 public function createUrl($manager, $route, $params)
 {
     if (!isset($params[$this->languageParam]) || !$params[$this->languageParam]) {
         $params[$this->languageParam] = I18N::getCurrentLanguageSlug();
     }
     return parent::createUrl($manager, $route, $params);
 }
 public function actionIndex($slug, $languageSlug = null)
 {
     /**
      * @var Page $page
      */
     $pageClass = Module::getInstance()->pageModelClass;
     $page = $pageClass::findBySlug($slug);
     $language = null;
     if ($languageSlug) {
         $language = I18N::getLanguageBySlug($languageSlug);
     }
     if (!$language) {
         $language = I18N::getCurrentLanguage();
     }
     Yii::$app->language = $language['locale'];
     if (!$page) {
         throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
     }
     $page->setLanguage($language['locale']);
     if (!$page->hasTranslation() && $page->default_language) {
         $page->setLanguage($page->default_language);
     }
     if (!$page->hasTranslation()) {
         throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
     }
     switch ($page->status) {
         case Page::STATUS_ACTIVE:
             break;
         case Page::STATUS_AUTH_ONLY:
             if (Yii::$app->user->getIsGuest()) {
                 throw new ForbiddenHttpException(Yii::t('maddoger/website', 'You must be authenticated to view this page.'));
             }
             break;
         case Page::STATUS_HIDDEN:
             if (!Yii::$app->user->getIsGuest() && Yii::$app->user->can('website.page.viewHiddenPages')) {
                 break;
             }
             throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
         default:
             throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
     }
     if ($page->layout !== null && !empty($page->layout)) {
         $this->layout = $page->layout;
     } else {
         /**
          * @var $this->module Module
          */
         $this->layout = Module::getInstance()->getConfiguration()->defaultLayout ?: null;
     }
     return $this->render(Module::getInstance()->pageView, ['model' => $page]);
 }
 public function actionIndex()
 {
     $model = Config::getConfig(Module::className());
     if ($model->load(Yii::$app->request->post())) {
         //$validate = $model->validate();
         foreach (I18N::getAvailableLanguages() as $language) {
             $modelI18n = $model->getTranslation($language['locale']);
             $modelI18n->load(Yii::$app->request->post());
         }
         if ($model->save()) {
             Yii::$app->session->addFlash('success', Yii::t('maddoger/website', 'Saved.'));
             return $this->refresh();
         }
     }
     return $this->render('index', ['model' => $model]);
 }
Example #4
0
 /**
  * @return string
  * @throws ErrorException
  */
 public function run()
 {
     /**
      * @var PageModel $page
      */
     if (!Module::getInstance()) {
         if (!Yii::$app->getModule($this->moduleId)) {
             throw new ErrorException('Module "' . $this->moduleId . '" not found.');
         }
     }
     $pageClass = Module::getInstance()->pageModelClass;
     if (is_int($this->page)) {
         $page = $pageClass::findOne($this->page);
     } elseif (is_string($this->page)) {
         $page = $pageClass::findBySlug($this->page);
     } else {
         throw new InvalidParamException('Invalid page identifier.');
     }
     $language = $this->language;
     if ($language) {
         if (!is_array($language)) {
             $language = I18N::getLanguageByLocale($language);
         }
     } else {
         $language = I18N::getCurrentLanguage();
     }
     if (!$page) {
         return null;
     }
     $page->setLanguage($language['locale']);
     if (!$page->hasTranslation() && $page->default_language) {
         $page->setLanguage($page->default_language);
     }
     if (!$page->hasTranslation()) {
         return null;
     }
     $content = $this->view ? $this->render($this->view, ['model' => $page]) : $page->text;
     if ($this->title) {
         $options = $this->titleOptions;
         $tag = ArrayHelper::remove($options, 'tag', 'h2');
         $content = Html::tag($tag, is_string($this->title) ? $this->title : $page->title, $options) . $content;
     }
     $options = $this->options;
     $tag = ArrayHelper::remove($options, 'tag', 'div');
     return Html::tag($tag, $content, $options);
 }
Example #5
0
<?php

/* @var $this yii\web\View */
use maddoger\core\i18n\I18N;
use maddoger\website\backend\Module as BackendModule;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $model maddoger\website\common\models\Page */
$this->title = Yii::t('maddoger/website', 'Configuration');
$availableLanguages = I18N::getAvailableLanguages();
$activeLanguage = $availableLanguages[0]['locale'];
$layouts = BackendModule::getInstance()->getConfiguration()->layouts;
$layouts = $layouts ? array_merge(['' => Yii::t('maddoger/website', 'Default')], $layouts) : ['' => Yii::t('maddoger/website', 'Default')];
$textFormats = BackendModule::getInstance()->textFormats;
$textFormats = array_merge(['' => Yii::t('maddoger/website', 'Default')], $textFormats ? ArrayHelper::getColumn($textFormats, 'label', true) : []);
?>
<div class="page-update">

    <div class="page-form">

        <?php 
$form = ActiveForm::begin();
?>
        <div class="row">
            <div class="col-md-6">

                <div class="nav-tabs-custom" id="translations">
                    <ul class="nav nav-tabs">
                        <li class="header"><?php 
echo Yii::t('maddoger/website', 'SEO');
Example #6
0
 /**
  * @param null $language
  * @return string
  */
 public function getUrl($language = null)
 {
     if (!$language) {
         $language = $this->language;
     }
     $languages = I18N::getAvailableLanguages();
     $url = count($languages) > 1 ? $this->urlWithLanguageTemplate : $this->urlTemplate;
     $languageArray = I18N::getLanguageByLocale($language);
     $url = strtr($url, ['{slug}' => ltrim($this->slug, '/'), '{languageLocale}' => $languageArray['locale'], '{languageSlug}' => $languageArray['slug']]);
     $url = preg_replace('/([^:])\\/{2,}/', '$1/', $url);
     return Url::to($url);
 }
Example #7
0
 /**
  * Load model from backup
  * @param Page $model
  * @return bool if success
  */
 protected function loadBackup($model)
 {
     $data = Yii::$app->session->get('WEBSITE_PAGE_BACKUP_' . $model->id);
     if ($data && $model->load($data)) {
         $isDirty = count($model->getDirtyAttributes(['slug'])) > 0;
         foreach (I18N::getAvailableLanguages() as $language) {
             $modelI18n = $model->getTranslation($language['locale'], true);
             if ($modelI18n->load($data)) {
                 //Meta data
                 if ($modelI18n->meta_data && isset($modelI18n->meta_data['name']) && isset($modelI18n->meta_data['value'])) {
                     $metaData = array_filter(array_combine($modelI18n->meta_data['name'], $modelI18n->meta_data['value']));
                     if ($metaData) {
                         ksort($metaData);
                         $modelI18n->meta_data = $metaData;
                     } else {
                         $modelI18n->meta_data = null;
                     }
                 } else {
                     $modelI18n->meta_data = null;
                 }
                 $isDirty = $isDirty || count($modelI18n->getDirtyAttributes()) > 0;
             }
         }
         if ($isDirty) {
             if (isset($data['time'])) {
                 return $data['time'];
             } else {
                 return 0;
             }
         }
     }
     return false;
 }
 public function run()
 {
     /**
      * @var Page $page
      */
     if (!Module::getInstance()) {
         if (!Yii::$app->getModule($this->moduleId)) {
             throw new ErrorException('Module "' . $this->moduleId . '" not found.');
         }
     }
     $pageClass = Module::getInstance()->pageModelClass;
     if (is_int($this->page)) {
         $page = $pageClass::findOne($this->page);
     } elseif (is_string($this->page)) {
         $page = $pageClass::findBySlug($this->page);
     } else {
         throw new InvalidParamException('Invalid page identifier.');
     }
     $language = $this->language;
     if ($language) {
         if (!is_array($language)) {
             $language = I18N::getLanguageByLocale($language);
         }
     } else {
         $language = I18N::getCurrentLanguage();
     }
     Yii::$app->language = $language['locale'];
     if (!$page) {
         throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
     }
     $page->setLanguage($language['locale']);
     if (!$page->hasTranslation() && $page->default_language) {
         $page->setLanguage($page->default_language);
     }
     if (!$page->hasTranslation()) {
         throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
     }
     switch ($page->status) {
         case Page::STATUS_ACTIVE:
             break;
         case Page::STATUS_AUTH_ONLY:
             if (Yii::$app->user->getIsGuest()) {
                 throw new ForbiddenHttpException(Yii::t('maddoger/website', 'You must be authenticated to view this page.'));
             }
             break;
         case Page::STATUS_HIDDEN:
             if (!Yii::$app->user->getIsGuest() && Yii::$app->user->can('website.page.viewHiddenPages')) {
                 break;
             }
             throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
         default:
             throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
     }
     if ($page->layout !== null && !empty($page->layout)) {
         $this->controller->layout = $page->layout;
     } else {
         /**
          * @var $this ->module WebsiteModule
          */
         if (Module::getInstance()->config->defaultLayout) {
             $this->controller->layout = Module::getInstance()->config->defaultLayout;
         }
     }
     return $this->controller->render($this->view ?: Module::getInstance()->pageView, ['model' => $page]);
 }
Example #9
0
    ?>
                        <br/>
                        <?php 
    echo $this->render('_items', ['menu' => $menu, 'items' => $menu->getChildren()->with(['children', 'page'])->all()]);
    ?>
                        <br/>
                        <hr/>
                        <h4><?php 
    echo Yii::t('maddoger/website', 'Menu settings');
    ?>
</h4>
                        <?php 
    echo $form->field($menu, 'slug', ['options' => ['class' => 'form-group form-group-sm']])->textInput()->hint(Yii::t('maddoger/website', 'You insert the menu to a template using it.'));
    ?>
                        <?php 
    echo $form->field($menu, 'language', ['options' => ['class' => 'form-group form-group-sm']])->dropDownList(array_merge(['' => '-'], I18N::getAvailableLanguagesList()))->hint(Yii::t('maddoger/website', 'The menu is for one language.'));
    ?>
                        <?php 
    echo $form->field($menu, 'css_class', ['options' => ['class' => 'form-group form-group-sm']])->textInput()->hint(Yii::t('maddoger/website', 'The menu UL element will receive this class.'));
    ?>
                        <?php 
    echo $form->field($menu, 'element_id', ['options' => ['class' => 'form-group form-group-sm']])->textInput()->hint(Yii::t('maddoger/website', 'The menu UL element will receive this ID.'));
    ?>
                    <?php 
}
?>
                </div>
                <div class="panel-footer clearfix">
                    <?php 
if (!$menu->isNewRecord) {
    echo Html::a(Yii::t('maddoger/website', 'Delete menu'), ['delete', 'id' => $menu->id], ['data-method' => 'post', 'data-confirm' => Yii::t('maddoger/website', 'Are you sure want to delete this menu?'), 'class' => 'text-danger']);