Commit 15b8e84d1a68dd9d1d953bf07b6fbf0d1bb243c8
1 parent
3e16e218
Different Seo tasks
Showing
10 changed files
with
139 additions
and
22 deletions
Show diff stats
.htaccess
@@ -15,6 +15,9 @@ AddDefaultCharset utf-8 | @@ -15,6 +15,9 @@ AddDefaultCharset utf-8 | ||
15 | RewriteCond %{REQUEST_URI} ^/admin | 15 | RewriteCond %{REQUEST_URI} ^/admin |
16 | RewriteRule ^admin(.*) /backend/web/$1 [L] | 16 | RewriteRule ^admin(.*) /backend/web/$1 [L] |
17 | 17 | ||
18 | + RewriteCond %{REQUEST_FILENAME} robots.txt | ||
19 | + RewriteRule . /frontend/web/index.php [L] | ||
20 | + | ||
18 | # if a directory or a file of the uploads folder exists, use the request directly | 21 | # if a directory or a file of the uploads folder exists, use the request directly |
19 | RewriteCond %{REQUEST_URI} ^/storage | 22 | RewriteCond %{REQUEST_URI} ^/storage |
20 | RewriteCond %{REQUEST_FILENAME} !-f | 23 | RewriteCond %{REQUEST_FILENAME} !-f |
backend/config/main.php
@@ -17,7 +17,8 @@ | @@ -17,7 +17,8 @@ | ||
17 | 'controllerMap' => [ | 17 | 'controllerMap' => [ |
18 | 'profile' => 'artbox\core\controllers\ProfileController', | 18 | 'profile' => 'artbox\core\controllers\ProfileController', |
19 | 'page' => 'artbox\core\controllers\PageController', | 19 | 'page' => 'artbox\core\controllers\PageController', |
20 | - 'seo' => 'artbox\core\controllers\AliasController', | 20 | + 'alias' => 'artbox\core\controllers\AliasController', |
21 | + 'seo' => 'artbox\core\controllers\SeoController', | ||
21 | 'feedback' => 'artbox\core\controllers\FeedbackController', | 22 | 'feedback' => 'artbox\core\controllers\FeedbackController', |
22 | ], | 23 | ], |
23 | 'modules' => [ | 24 | 'modules' => [ |
backend/controllers/SettingsController.php
@@ -31,8 +31,8 @@ | @@ -31,8 +31,8 @@ | ||
31 | 'allow' => true, | 31 | 'allow' => true, |
32 | ], | 32 | ], |
33 | [ | 33 | [ |
34 | - 'allow' => true, | ||
35 | - 'roles' => [ '@' ], | 34 | + 'allow' => true, |
35 | + 'roles' => [ '@' ], | ||
36 | ], | 36 | ], |
37 | ], | 37 | ], |
38 | ], | 38 | ], |
@@ -62,15 +62,20 @@ | @@ -62,15 +62,20 @@ | ||
62 | ); | 62 | ); |
63 | } | 63 | } |
64 | 64 | ||
65 | + /** | ||
66 | + * Action that intended to change Robots.txt of website | ||
67 | + * | ||
68 | + * @return string | ||
69 | + */ | ||
65 | public function actionRobots() | 70 | public function actionRobots() |
66 | { | 71 | { |
67 | $model = $this->findSettings(); | 72 | $model = $this->findSettings(); |
68 | $model->scenario = Settings::SCENARIO_ROBOTS; | 73 | $model->scenario = Settings::SCENARIO_ROBOTS; |
69 | - | 74 | + |
70 | if ($model->load(\Yii::$app->request->post()) && $model->save()) { | 75 | if ($model->load(\Yii::$app->request->post()) && $model->save()) { |
71 | \Yii::$app->session->setFlash('success', \Yii::t('core', 'Robots saved')); | 76 | \Yii::$app->session->setFlash('success', \Yii::t('core', 'Robots saved')); |
72 | } | 77 | } |
73 | - | 78 | + |
74 | return $this->render( | 79 | return $this->render( |
75 | 'robots', | 80 | 'robots', |
76 | [ | 81 | [ |
@@ -78,6 +83,28 @@ | @@ -78,6 +83,28 @@ | ||
78 | ] | 83 | ] |
79 | ); | 84 | ); |
80 | } | 85 | } |
86 | + | ||
87 | + /** | ||
88 | + * Action that intended to change Google Analytics, Yandex Metrics and Tag Manager codes. | ||
89 | + * | ||
90 | + * @return string | ||
91 | + */ | ||
92 | + public function actionCodes() | ||
93 | + { | ||
94 | + $model = $this->findSettings(); | ||
95 | + $model->scenario = Settings::SCENARIO_CODES; | ||
96 | + | ||
97 | + if ($model->load(\Yii::$app->request->post()) && $model->save()) { | ||
98 | + \Yii::$app->session->setFlash('success', \Yii::t('core', 'Codes saved successfully')); | ||
99 | + } | ||
100 | + | ||
101 | + return $this->render( | ||
102 | + 'codes', | ||
103 | + [ | ||
104 | + 'model' => $model, | ||
105 | + ] | ||
106 | + ); | ||
107 | + } | ||
81 | 108 | ||
82 | /** | 109 | /** |
83 | * Find site settings | 110 | * Find site settings |
backend/views/layouts/main.php
@@ -157,7 +157,7 @@ | @@ -157,7 +157,7 @@ | ||
157 | 'items' => [ | 157 | 'items' => [ |
158 | [ | 158 | [ |
159 | 'label' => \Yii::t('core', 'Seo pages'), | 159 | 'label' => \Yii::t('core', 'Seo pages'), |
160 | - 'url' => [ 'seo/index' ], | 160 | + 'url' => [ 'alias/index' ], |
161 | 'icon' => 'file-text', | 161 | 'icon' => 'file-text', |
162 | ], | 162 | ], |
163 | [ | 163 | [ |
@@ -165,6 +165,16 @@ | @@ -165,6 +165,16 @@ | ||
165 | 'url' => [ 'settings/robots' ], | 165 | 'url' => [ 'settings/robots' ], |
166 | 'icon' => 'android', | 166 | 'icon' => 'android', |
167 | ], | 167 | ], |
168 | + [ | ||
169 | + 'label' => \Yii::t('core', 'Codes'), | ||
170 | + 'url' => [ 'settings/codes' ], | ||
171 | + 'icon' => 'code', | ||
172 | + ], | ||
173 | + [ | ||
174 | + 'label' => \Yii::t('core', 'Sitemap'), | ||
175 | + 'url' => [ 'seo/sitemap' ], | ||
176 | + 'icon' => 'map-signs', | ||
177 | + ], | ||
168 | ], | 178 | ], |
169 | ], | 179 | ], |
170 | ] | 180 | ] |
1 | +<?php | ||
2 | + /** | ||
3 | + * @var View $this | ||
4 | + * @var Settings $model | ||
5 | + */ | ||
6 | + | ||
7 | + use common\models\Settings; | ||
8 | + use artbox\gentelella\widgets\XPanel; | ||
9 | + use yii\bootstrap\ActiveForm; | ||
10 | + use yii\bootstrap\Html; | ||
11 | + use yii\web\View; | ||
12 | + | ||
13 | + $this->title = Yii::t('core', 'Codes'); | ||
14 | + | ||
15 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
16 | +?> | ||
17 | + | ||
18 | +<?php $panel = XPanel::begin( | ||
19 | + [ | ||
20 | + 'title' => $this->title, | ||
21 | + 'toolbar' => false, | ||
22 | + ] | ||
23 | +); ?> | ||
24 | + | ||
25 | +<div class="settings-form"> | ||
26 | + | ||
27 | + <?php | ||
28 | + $form = ActiveForm::begin(); | ||
29 | + | ||
30 | + echo $form->field($model, 'ga_code') | ||
31 | + ->textInput(); | ||
32 | + | ||
33 | + echo $form->field($model, 'ya_code') | ||
34 | + ->textInput(); | ||
35 | + | ||
36 | + echo $form->field($model, 'tag_manager') | ||
37 | + ->textInput(); | ||
38 | + | ||
39 | + echo Html::submitButton( | ||
40 | + \Yii::t('core', 'Save'), | ||
41 | + [ | ||
42 | + 'class' => 'btn btn-primary', | ||
43 | + ] | ||
44 | + ); | ||
45 | + ActiveForm::end(); | ||
46 | + ?> | ||
47 | + | ||
48 | +</div> | ||
49 | + | ||
50 | +<?php $panel::end(); ?> |
backend/views/settings/robots.php
@@ -29,7 +29,7 @@ | @@ -29,7 +29,7 @@ | ||
29 | 29 | ||
30 | echo $form->field($model, 'robots') | 30 | echo $form->field($model, 'robots') |
31 | ->label(false) | 31 | ->label(false) |
32 | - ->textarea(); | 32 | + ->textarea([ 'rows' => 15 ]); |
33 | 33 | ||
34 | echo Html::submitButton( | 34 | echo Html::submitButton( |
35 | \Yii::t('core', 'Save'), | 35 | \Yii::t('core', 'Save'), |
common/config/settings.php
@@ -5,18 +5,14 @@ return [ | @@ -5,18 +5,14 @@ return [ | ||
5 | 'id' => '1', | 5 | 'id' => '1', |
6 | 'name' => 'Admin321', | 6 | 'name' => 'Admin321', |
7 | 'description' => 'Site administrator', | 7 | 'description' => 'Site administrator', |
8 | - 'analytics' => '<!-- Google Analytics --> | ||
9 | -<script> | ||
10 | - (function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){ | ||
11 | - (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | ||
12 | - m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | ||
13 | - })(window,document,\'script\',\'https://www.google-analytics.com/analytics.js\',\'ga\'); | ||
14 | - | ||
15 | - ga(\'create\', \'UA-54355086-1\', \'auto\'); | ||
16 | - ga(\'send\', \'pageview\'); | ||
17 | -</script> | ||
18 | -<!-- End Google Analytics -->', | ||
19 | 'analytics_key' => '119240817', | 8 | 'analytics_key' => '119240817', |
20 | - 'robots' => 'TEst 321', | 9 | + 'robots' => 'User-agent: Google |
10 | +Disallow: | ||
11 | + | ||
12 | +User-agent: * | ||
13 | +Disallow: /', | ||
14 | + 'ga_code' => 'TEst', | ||
15 | + 'ya_code' => 'TEst 2', | ||
16 | + 'tag_manager' => 'TEst 3', | ||
21 | ], | 17 | ], |
22 | ]; | 18 | ]; |
23 | \ No newline at end of file | 19 | \ No newline at end of file |
common/models/Settings.php
@@ -11,13 +11,16 @@ | @@ -11,13 +11,16 @@ | ||
11 | * @property string $name | 11 | * @property string $name |
12 | * @property string $id | 12 | * @property string $id |
13 | * @property string $description | 13 | * @property string $description |
14 | - * @property string $analytics | ||
15 | * @property string $analytics_key | 14 | * @property string $analytics_key |
16 | * @property string $robots | 15 | * @property string $robots |
16 | + * @property string $ga_code | ||
17 | + * @property string $ya_code | ||
18 | + * @property string $tag_manager | ||
17 | */ | 19 | */ |
18 | class Settings extends ActiveRecord | 20 | class Settings extends ActiveRecord |
19 | { | 21 | { |
20 | const SCENARIO_ROBOTS = 'robots'; | 22 | const SCENARIO_ROBOTS = 'robots'; |
23 | + const SCENARIO_CODES = 'codes'; | ||
21 | 24 | ||
22 | private static $instance; | 25 | private static $instance; |
23 | 26 | ||
@@ -30,6 +33,11 @@ | @@ -30,6 +33,11 @@ | ||
30 | parent::scenarios(), | 33 | parent::scenarios(), |
31 | [ | 34 | [ |
32 | self::SCENARIO_ROBOTS => [ 'robots' ], | 35 | self::SCENARIO_ROBOTS => [ 'robots' ], |
36 | + self::SCENARIO_CODES => [ | ||
37 | + 'ga_code', | ||
38 | + 'ya_code', | ||
39 | + 'tag_manager', | ||
40 | + ], | ||
33 | ] | 41 | ] |
34 | ); | 42 | ); |
35 | } | 43 | } |
@@ -45,9 +53,11 @@ | @@ -45,9 +53,11 @@ | ||
45 | 'name', | 53 | 'name', |
46 | 'description', | 54 | 'description', |
47 | 'id', | 55 | 'id', |
48 | - 'analytics', | ||
49 | 'analytics_key', | 56 | 'analytics_key', |
50 | 'robots', | 57 | 'robots', |
58 | + 'ga_code', | ||
59 | + 'ya_code', | ||
60 | + 'tag_manager', | ||
51 | ], | 61 | ], |
52 | 'string', | 62 | 'string', |
53 | ], | 63 | ], |
@@ -71,9 +81,11 @@ | @@ -71,9 +81,11 @@ | ||
71 | 'id' => Yii::t('core', 'ID'), | 81 | 'id' => Yii::t('core', 'ID'), |
72 | 'name' => Yii::t('core', 'Name'), | 82 | 'name' => Yii::t('core', 'Name'), |
73 | 'description' => Yii::t('core', 'Description'), | 83 | 'description' => Yii::t('core', 'Description'), |
74 | - 'analytics' => Yii::t('core', 'Google Analytics Code'), | ||
75 | 'analytics_key' => Yii::t('core', 'Google Analytics Key'), | 84 | 'analytics_key' => Yii::t('core', 'Google Analytics Key'), |
76 | 'robots' => Yii::t('core', 'Robots'), | 85 | 'robots' => Yii::t('core', 'Robots'), |
86 | + 'ga_code' => Yii::t('core', 'Google analytics code'), | ||
87 | + 'ya_code' => Yii::t('core', 'Yandex metrics code'), | ||
88 | + 'tag_manager' => Yii::t('core', 'Tag Manager code'), | ||
77 | ]; | 89 | ]; |
78 | } | 90 | } |
79 | 91 |
frontend/config/main.php
frontend/controllers/SiteController.php
1 | <?php | 1 | <?php |
2 | namespace frontend\controllers; | 2 | namespace frontend\controllers; |
3 | 3 | ||
4 | +use common\models\Settings; | ||
4 | use Yii; | 5 | use Yii; |
5 | use yii\base\InvalidParamException; | 6 | use yii\base\InvalidParamException; |
6 | use yii\web\BadRequestHttpException; | 7 | use yii\web\BadRequestHttpException; |
@@ -210,4 +211,20 @@ class SiteController extends Controller | @@ -210,4 +211,20 @@ class SiteController extends Controller | ||
210 | 'model' => $model, | 211 | 'model' => $model, |
211 | ]); | 212 | ]); |
212 | } | 213 | } |
214 | + | ||
215 | + public function actionRobots() | ||
216 | + { | ||
217 | + $response = \Yii::$app->response; | ||
218 | + /** | ||
219 | + * @var Settings $settings | ||
220 | + */ | ||
221 | + $settings = Settings::find() | ||
222 | + ->one(); | ||
223 | + $temp = tmpfile(); | ||
224 | + fwrite($temp, $settings->robots); | ||
225 | + $meta = stream_get_meta_data($temp); | ||
226 | + $response->format = $response::FORMAT_RAW; | ||
227 | + $response->headers->set('Content-Type', 'text/plain'); | ||
228 | + return $this->renderFile($meta[ 'uri' ]); | ||
229 | + } | ||
213 | } | 230 | } |