示例#1
0
文件: Cms.php 项目: skeeks-cms/cms
 public function init()
 {
     parent::init();
     //Название проекта.
     if (!$this->appName) {
         $this->appName = \Yii::$app->name;
     } else {
         \Yii::$app->name = $this->appName;
     }
     //Язык
     if ($this->languageCode) {
         \Yii::$app->language = $this->languageCode;
     } else {
         $this->languageCode = \Yii::$app->language;
     }
     if (\Yii::$app instanceof Application) {
     } else {
         $this->relatedHandlers = ArrayHelper::merge([PropertyTypeText::className() => ['class' => PropertyTypeText::className()], PropertyTypeNumber::className() => ['class' => PropertyTypeNumber::className()], PropertyTypeList::className() => ['class' => PropertyTypeList::className()], PropertyTypeFile::className() => ['class' => PropertyTypeFile::className()], PropertyTypeTree::className() => ['class' => PropertyTypeTree::className()], PropertyTypeElement::className() => ['class' => PropertyTypeElement::className()], UserPropertyTypeDate::className() => ['class' => UserPropertyTypeDate::className()], UserPropertyTypeComboText::className() => ['class' => UserPropertyTypeComboText::className()], UserPropertyTypeColor::className() => ['class' => UserPropertyTypeColor::className()], UserPropertyTypeSelectFile::className() => ['class' => UserPropertyTypeSelectFile::className()]], $this->relatedHandlers);
         //web init
         if (!$this->noImageUrl) {
             $this->noImageUrl = CmsAsset::getAssetUrl('img/image-not-found.jpg');
         }
         \Yii::$app->view->on(View::EVENT_BEGIN_PAGE, function (Event $e) {
             if (!\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
                 \Yii::$app->response->getHeaders()->setDefault('X-Powered-CMS', $this->descriptor->name . " {$this->descriptor->homepage}");
                 /**
                  * @var $view View
                  */
                 $view = $e->sender;
                 if (!isset($view->metaTags[self::$_huck])) {
                     $view->registerMetaTag(["name" => base64_decode(self::$_huck), "content" => $this->descriptor->name . " — {$this->descriptor->homepage}"], self::$_huck);
                 }
                 if (!isset($view->metaTags['cmsmagazine'])) {
                     $view->registerMetaTag(["name" => 'cmsmagazine', "content" => "7170fe3a42c6f80cd95fd8bce765333d"], 'cmsmagazine');
                 }
             }
         });
         \Yii::$app->user->on(\yii\web\User::EVENT_AFTER_LOGIN, function (UserEvent $e) {
             $e->identity->logged_at = \Yii::$app->formatter->asTimestamp(time());
             $e->identity->save(false);
             if (\Yii::$app->admin->requestIsAdmin) {
                 \Yii::$app->user->identity->updateLastAdminActivity();
             }
         });
     }
 }
示例#2
0
文件: Cms.php 项目: Liv1020/cms
 /**
  * Продолжение инициализации только в случае работы web приложения
  */
 protected function _initWeb()
 {
     if (!$this->noImageUrl) {
         $this->noImageUrl = CmsAsset::getAssetUrl('img/image-not-found.jpg');
     }
     if ($this->debugEnabled === self::BOOL_Y) {
         /**
          * @var $debugModule \yii\debug\Module
          */
         $debugModule = \Yii::$app->getModule('debug');
         $debugModule->allowedIPs = explode(',', $this->debugAllowedIPs);
         $debugModule->bootstrap(\Yii::$app);
     }
     if ($this->enabledHttpAuth == self::BOOL_Y) {
         $this->_goHttpAuth();
     }
     //Выполнение агентов на хитах, должны быть  включены в настройка, нужна system.
     if ($this->enabledHitAgents == self::BOOL_Y) {
         $key = 'Agents';
         Yii::beginProfile($key);
         $data = \Yii::$app->cache->get($key);
         if ($data === false) {
             $result = \Yii::$app->console->execute("cd " . ROOT_DIR . '; php yii cms/utils/agents-execute;');
             \Yii::$app->cache->set($key, '1', (int) $this->hitAgentsInterval);
         }
         Yii::endProfile($key);
     }
     /**
      * Генерация SEO метатегов.
      * */
     \Yii::$app->view->on(View::EVENT_BEGIN_PAGE, function (Event $e) {
         if (!\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
             \Yii::$app->response->getHeaders()->setDefault('X-Powered-CMS', $this->moduleCms->descriptor->toString());
             /**
              * @var $view View
              */
             $view = $e->sender;
             if (!isset($view->metaTags[self::$_huck])) {
                 $view->registerMetaTag(["name" => base64_decode(self::$_huck), "content" => $this->moduleCms->descriptor->toString()], self::$_huck);
             }
         }
     });
     \Yii::$app->user->on(\yii\web\User::EVENT_AFTER_LOGIN, function (UserEvent $e) {
         $e->identity->logged_at = \Yii::$app->formatter->asTimestamp(time());
         $e->identity->save(false);
         if ($this->moduleAdmin()->requestIsAdmin()) {
             \Yii::$app->user->identity->updateLastAdminActivity();
         }
     });
     \Yii::$app->on(AdminController::EVENT_INIT, function (AdminInitEvent $e) {
         //Если http авторизация на сайте отключена а в админке включена
         if ($this->enabledHttpAuth == self::BOOL_N && $this->enabledHttpAuthAdmin == self::BOOL_Y && $this->moduleAdmin()->requestIsAdmin()) {
             $this->_goHttpAuth();
         }
         if ($e->controller instanceof AdminModelEditorController) {
             $e->controller->eventActions = ArrayHelper::merge($e->controller->eventActions, ['related-properties' => ['class' => AdminOneModelRelatedPropertiesAction::className(), 'name' => 'Дополнительные свойства', "icon" => "glyphicon glyphicon-plus-sign"]]);
         }
         if ($e->controller instanceof AdminModelEditorController) {
             $e->controller->eventActions = ArrayHelper::merge($e->controller->eventActions, ['system' => ['class' => AdminOneModelSystemAction::className(), 'name' => 'Системные данные', "icon" => "glyphicon glyphicon-cog", "priority" => 9999]]);
         }
     });
 }