diff --git a/.htaccess b/.htaccess index 70df031..cf009bf 100644 --- a/.htaccess +++ b/.htaccess @@ -15,6 +15,9 @@ AddDefaultCharset utf-8 RewriteCond %{REQUEST_URI} ^/admin RewriteRule ^admin(.*) /backend/web/$1 [L] + RewriteCond %{REQUEST_FILENAME} robots.txt + RewriteRule . /frontend/web/index.php [L] + # if a directory or a file of the uploads folder exists, use the request directly RewriteCond %{REQUEST_URI} ^/storage RewriteCond %{REQUEST_FILENAME} !-f diff --git a/backend/config/main.php b/backend/config/main.php index 0fa8aa9..9b04722 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -17,7 +17,8 @@ 'controllerMap' => [ 'profile' => 'artbox\core\controllers\ProfileController', 'page' => 'artbox\core\controllers\PageController', - 'seo' => 'artbox\core\controllers\AliasController', + 'alias' => 'artbox\core\controllers\AliasController', + 'seo' => 'artbox\core\controllers\SeoController', 'feedback' => 'artbox\core\controllers\FeedbackController', ], 'modules' => [ diff --git a/backend/controllers/SettingsController.php b/backend/controllers/SettingsController.php index 02f710d..3be3b99 100755 --- a/backend/controllers/SettingsController.php +++ b/backend/controllers/SettingsController.php @@ -31,8 +31,8 @@ 'allow' => true, ], [ - 'allow' => true, - 'roles' => [ '@' ], + 'allow' => true, + 'roles' => [ '@' ], ], ], ], @@ -62,15 +62,20 @@ ); } + /** + * Action that intended to change Robots.txt of website + * + * @return string + */ public function actionRobots() { $model = $this->findSettings(); $model->scenario = Settings::SCENARIO_ROBOTS; - + if ($model->load(\Yii::$app->request->post()) && $model->save()) { \Yii::$app->session->setFlash('success', \Yii::t('core', 'Robots saved')); } - + return $this->render( 'robots', [ @@ -78,6 +83,28 @@ ] ); } + + /** + * Action that intended to change Google Analytics, Yandex Metrics and Tag Manager codes. + * + * @return string + */ + public function actionCodes() + { + $model = $this->findSettings(); + $model->scenario = Settings::SCENARIO_CODES; + + if ($model->load(\Yii::$app->request->post()) && $model->save()) { + \Yii::$app->session->setFlash('success', \Yii::t('core', 'Codes saved successfully')); + } + + return $this->render( + 'codes', + [ + 'model' => $model, + ] + ); + } /** * Find site settings diff --git a/backend/views/layouts/main.php b/backend/views/layouts/main.php index 007a51d..23ac713 100755 --- a/backend/views/layouts/main.php +++ b/backend/views/layouts/main.php @@ -157,7 +157,7 @@ 'items' => [ [ 'label' => \Yii::t('core', 'Seo pages'), - 'url' => [ 'seo/index' ], + 'url' => [ 'alias/index' ], 'icon' => 'file-text', ], [ @@ -165,6 +165,16 @@ 'url' => [ 'settings/robots' ], 'icon' => 'android', ], + [ + 'label' => \Yii::t('core', 'Codes'), + 'url' => [ 'settings/codes' ], + 'icon' => 'code', + ], + [ + 'label' => \Yii::t('core', 'Sitemap'), + 'url' => [ 'seo/sitemap' ], + 'icon' => 'map-signs', + ], ], ], ] diff --git a/backend/views/settings/codes.php b/backend/views/settings/codes.php new file mode 100755 index 0000000..2808998 --- /dev/null +++ b/backend/views/settings/codes.php @@ -0,0 +1,50 @@ +title = Yii::t('core', 'Codes'); + + $this->params[ 'breadcrumbs' ][] = $this->title; +?> + + $this->title, + 'toolbar' => false, + ] +); ?> + +
+ + field($model, 'ga_code') + ->textInput(); + + echo $form->field($model, 'ya_code') + ->textInput(); + + echo $form->field($model, 'tag_manager') + ->textInput(); + + echo Html::submitButton( + \Yii::t('core', 'Save'), + [ + 'class' => 'btn btn-primary', + ] + ); + ActiveForm::end(); + ?> + +
+ + diff --git a/backend/views/settings/robots.php b/backend/views/settings/robots.php index 003c839..7a0af7d 100755 --- a/backend/views/settings/robots.php +++ b/backend/views/settings/robots.php @@ -29,7 +29,7 @@ echo $form->field($model, 'robots') ->label(false) - ->textarea(); + ->textarea([ 'rows' => 15 ]); echo Html::submitButton( \Yii::t('core', 'Save'), diff --git a/common/config/settings.php b/common/config/settings.php index ee69344..73e2ce0 100755 --- a/common/config/settings.php +++ b/common/config/settings.php @@ -5,18 +5,14 @@ return [ 'id' => '1', 'name' => 'Admin321', 'description' => 'Site administrator', - 'analytics' => ' - -', 'analytics_key' => '119240817', - 'robots' => 'TEst 321', + 'robots' => 'User-agent: Google +Disallow: + +User-agent: * +Disallow: /', + 'ga_code' => 'TEst', + 'ya_code' => 'TEst 2', + 'tag_manager' => 'TEst 3', ], ]; \ No newline at end of file diff --git a/common/models/Settings.php b/common/models/Settings.php index 852854e..8d7f069 100755 --- a/common/models/Settings.php +++ b/common/models/Settings.php @@ -11,13 +11,16 @@ * @property string $name * @property string $id * @property string $description - * @property string $analytics * @property string $analytics_key * @property string $robots + * @property string $ga_code + * @property string $ya_code + * @property string $tag_manager */ class Settings extends ActiveRecord { const SCENARIO_ROBOTS = 'robots'; + const SCENARIO_CODES = 'codes'; private static $instance; @@ -30,6 +33,11 @@ parent::scenarios(), [ self::SCENARIO_ROBOTS => [ 'robots' ], + self::SCENARIO_CODES => [ + 'ga_code', + 'ya_code', + 'tag_manager', + ], ] ); } @@ -45,9 +53,11 @@ 'name', 'description', 'id', - 'analytics', 'analytics_key', 'robots', + 'ga_code', + 'ya_code', + 'tag_manager', ], 'string', ], @@ -71,9 +81,11 @@ 'id' => Yii::t('core', 'ID'), 'name' => Yii::t('core', 'Name'), 'description' => Yii::t('core', 'Description'), - 'analytics' => Yii::t('core', 'Google Analytics Code'), 'analytics_key' => Yii::t('core', 'Google Analytics Key'), 'robots' => Yii::t('core', 'Robots'), + 'ga_code' => Yii::t('core', 'Google analytics code'), + 'ya_code' => Yii::t('core', 'Yandex metrics code'), + 'tag_manager' => Yii::t('core', 'Tag Manager code'), ]; } diff --git a/frontend/config/main.php b/frontend/config/main.php index 4cb1a25..fc991cc 100644 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -47,6 +47,7 @@ return [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ + '\/robots.txt' => 'site/robots', ], ], ], diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 519d575..5aa25e7 100644 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -1,6 +1,7 @@ $model, ]); } + + public function actionRobots() + { + $response = \Yii::$app->response; + /** + * @var Settings $settings + */ + $settings = Settings::find() + ->one(); + $temp = tmpfile(); + fwrite($temp, $settings->robots); + $meta = stream_get_meta_data($temp); + $response->format = $response::FORMAT_RAW; + $response->headers->set('Content-Type', 'text/plain'); + return $this->renderFile($meta[ 'uri' ]); + } } -- libgit2 0.21.4