From 9af79e71c667ccdd4add84bec20ae5cc5186a0ac Mon Sep 17 00:00:00 2001 From: yarik Date: Thu, 30 Mar 2017 16:47:05 +0300 Subject: [PATCH] Sitemap and slugbehavior fix --- backend/config/main.php | 6 +++--- backend/controllers/SitemapController.php | 24 +++++++++++++++++++++++- backend/views/settings/_codes_tab.php | 12 ++++++++++++ backend/views/settings/_contact_tab.php | 34 ++++++++++++++++++++++++++++++++++ backend/views/settings/_main_tab.php | 22 ++++++++++++++++++++++ backend/views/settings/_social_tab.php | 20 ++++++++++++++++++++ backend/views/settings/settings.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++------------ backend/views/sitemap/index.php | 25 +++++++++++++++++++++++++ backend/views/sitemap/update.php | 42 +++++++++++++++++++++++++++++++++++++++--- common/components/Sitemap.php | 39 +++++++++++++++++++++++++++++++++------ common/config/SitemapDynamic.php | 9 +++++---- common/config/SitemapStatic.php | 13 ++++++++++--- common/config/settings.php | 33 ++++++++++++++++++++++++--------- common/models/Settings.php | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- common/models/SitemapDynamic.php | 13 +++++++++---- common/models/SitemapStatic.php | 10 +++++++--- composer.lock | 4 ++-- frontend/web/sitemap.xml | 1 + 18 files changed, 416 insertions(+), 60 deletions(-) create mode 100644 backend/views/settings/_codes_tab.php create mode 100644 backend/views/settings/_contact_tab.php create mode 100644 backend/views/settings/_main_tab.php create mode 100644 backend/views/settings/_social_tab.php create mode 100644 frontend/web/sitemap.xml diff --git a/backend/config/main.php b/backend/config/main.php index eb1490f..31570fc 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -1,7 +1,7 @@ [], ], 'urlManagerFrontend' => [ - 'class' => UrlManager::className(), + 'class' => SeoUrlManager::className(), 'baseUrl' => '/', 'enablePrettyUrl' => true, 'showScriptName' => false, @@ -111,7 +111,7 @@ 'conditions' => [ [ 'in_menu' => 1 ], ], - 'url' => 'site/page', + 'url' => 'page/view', ], ], ], diff --git a/backend/controllers/SitemapController.php b/backend/controllers/SitemapController.php index 0ad1fa2..39e96fe 100755 --- a/backend/controllers/SitemapController.php +++ b/backend/controllers/SitemapController.php @@ -156,6 +156,7 @@ if (isset( $old_entity_models[ $entity_model->entity ] )) { $entity_model->status = $old_entity_models[ $entity_model->entity ]->status; $entity_model->priority = $old_entity_models[ $entity_model->entity ]->priority; + $entity_model->frequency = $old_entity_models[ $entity_model->entity ]->frequency; } } // ***** <<< End @@ -190,7 +191,7 @@ "[$count]url", [ 'options' => [ - 'class' => 'form-group col-xs-8 col-sm-9', + 'class' => 'form-group col-xs-5 col-sm-6', ], ] ) @@ -198,6 +199,27 @@ ->render(); $content .= $form->field( $model, + "[$count]frequency", + [ + 'options' => [ + 'class' => 'form-group col-xs-3 col-sm-3', + ], + ] + ) + ->dropDownList( + [ + 'always' => 'always', + 'hourly' => 'hourly', + 'daily' => 'daily', + 'weekly' => 'weekly', + 'monthly' => 'monthly', + 'yearly' => 'yearly', + 'never' => 'never', + ] + ) + ->render(); + $content .= $form->field( + $model, "[$count]priority", [ 'options' => [ diff --git a/backend/views/settings/_codes_tab.php b/backend/views/settings/_codes_tab.php new file mode 100644 index 0000000..a43789a --- /dev/null +++ b/backend/views/settings/_codes_tab.php @@ -0,0 +1,12 @@ +field($model, 'analytics_key') + ->textInput(); \ No newline at end of file diff --git a/backend/views/settings/_contact_tab.php b/backend/views/settings/_contact_tab.php new file mode 100644 index 0000000..e81acbe --- /dev/null +++ b/backend/views/settings/_contact_tab.php @@ -0,0 +1,34 @@ +field($model, 'phone') + ->textInput() + ->hint(\Yii::t('core', 'Contact phone for website')); + echo $form->field($model, 'phone2') + ->textInput() + ->hint(\Yii::t('core', 'Contact phone for website')); + echo $form->field($model, 'email') + ->textInput() + ->hint(\Yii::t('core', 'Contact email for website')); + echo $form->field($model, 'skype') + ->textInput(); + echo $form->field($model, 'house') + ->textInput(); + echo $form->field($model, 'street') + ->textInput(); + echo $form->field($model, 'office') + ->textInput(); + echo $form->field($model, 'city') + ->textInput(); + echo $form->field($model, 'lat') + ->textInput(); + echo $form->field($model, 'lon') + ->textInput(); + \ No newline at end of file diff --git a/backend/views/settings/_main_tab.php b/backend/views/settings/_main_tab.php new file mode 100644 index 0000000..da1a81e --- /dev/null +++ b/backend/views/settings/_main_tab.php @@ -0,0 +1,22 @@ +field($model, 'name') + ->textInput(); + echo $form->field($model, 'logo') + ->widget( + \noam148\imagemanager\components\ImageManagerInputWidget::className(), + [ + 'showPreview' => true, + 'showDeletePickedImageConfirm' => false, + ] + ); + echo $form->field($model, 'about') + ->textarea(); \ No newline at end of file diff --git a/backend/views/settings/_social_tab.php b/backend/views/settings/_social_tab.php new file mode 100644 index 0000000..80c161c --- /dev/null +++ b/backend/views/settings/_social_tab.php @@ -0,0 +1,20 @@ +field($model, 'facebook') + ->textInput(); + echo $form->field($model, 'vk') + ->textInput(); + echo $form->field($model, 'google') + ->textInput(); + echo $form->field($model, 'twitter') + ->textInput(); + echo $form->field($model, 'ok') + ->textInput(); \ No newline at end of file diff --git a/backend/views/settings/settings.php b/backend/views/settings/settings.php index 115796f..e2525df 100755 --- a/backend/views/settings/settings.php +++ b/backend/views/settings/settings.php @@ -8,6 +8,7 @@ use artbox\gentelella\widgets\XPanel; use yii\bootstrap\ActiveForm; use yii\bootstrap\Html; + use yii\bootstrap\Tabs; use yii\web\View; $this->title = 'Settings'; @@ -26,19 +27,57 @@ field($model, 'id') - ->textInput(); - - echo $form->field($model, 'name') - ->textInput(); - - echo $form->field($model, 'description') - ->textInput(); - echo $form->field($model, 'analytics_key') - ->textInput(); - + echo Tabs::widget( + [ + 'options' => [ + 'class' => 'bar_tabs', + ], + 'items' => [ + [ + 'label' => \Yii::t('core', 'Main'), + 'content' => $this->render( + '_main_tab', + [ + 'model' => $model, + 'form' => $form, + ] + ), + ], + [ + 'label' => \Yii::t('core', 'Contact'), + 'content' => $this->render( + '_contact_tab', + [ + 'model' => $model, + 'form' => $form, + ] + ), + ], + [ + 'label' => \Yii::t('core', 'Social'), + 'content' => $this->render( + '_social_tab', + [ + 'model' => $model, + 'form' => $form, + ] + ), + ], + [ + 'label' => \Yii::t('core', 'Codes'), + 'content' => $this->render( + '_codes_tab', + [ + 'model' => $model, + 'form' => $form, + ] + ), + ], + ], + ] + ); + echo Html::submitButton( 'Save', [ diff --git a/backend/views/sitemap/index.php b/backend/views/sitemap/index.php index 4ec692a..45bbae1 100644 --- a/backend/views/sitemap/index.php +++ b/backend/views/sitemap/index.php @@ -1,5 +1,6 @@ title = \Yii::t('core', 'Sitemap'); $this->params[ 'breadcrumbs' ][] = $this->title; + /** + * @var Sitemap $sitemap + */ + $sitemap = \Yii::$app->get('sitemap'); ?>
'btn btn-app ajax', + 'data' => [ + 'need-reload' => !$sitemap->checkFileExist(), + ], ] ); ?>
checkFileExist()) { + echo Html::tag( + 'div', + Html::a( + \Yii::t('core', 'View generated sitemap.xml'), + $sitemap->getUrl(), + [ + 'target' => '_blank', + ] + ), + [ + 'class' => 'row text-right', + ] + ); + } + ?> + diff --git a/backend/views/sitemap/update.php b/backend/views/sitemap/update.php index 9a386bf..3666492 100644 --- a/backend/views/sitemap/update.php +++ b/backend/views/sitemap/update.php @@ -36,12 +36,31 @@ "[$index]url", [ 'options' => [ - 'class' => 'form-group col-xs-8 col-sm-9', + 'class' => 'form-group col-xs-5 col-sm-6', ], ] ) ->textInput() . $form->field( $model, + "[$index]frequency", + [ + 'options' => [ + 'class' => 'form-group col-xs-3 col-sm-3', + ], + ] + ) + ->dropDownList( + [ + 'always' => 'always', + 'hourly' => 'hourly', + 'daily' => 'daily', + 'weekly' => 'weekly', + 'monthly' => 'monthly', + 'yearly' => 'yearly', + 'never' => 'never', + ] + ) . $form->field( + $model, "[$index]priority", [ 'options' => [ @@ -49,7 +68,7 @@ ], ] ) - ->textInput() . Html::icon( + ->textInput() . Html::icon( 'minus', [ 'class' => 'col-xs-1 field-group-remove', @@ -85,7 +104,7 @@ $entity_model) { ?> -
+
field($entity_model, "[$index]frequency") + ->label(false) + ->dropDownList( + [ + 'always' => 'always', + 'hourly' => 'hourly', + 'daily' => 'daily', + 'weekly' => 'weekly', + 'monthly' => 'monthly', + 'yearly' => 'yearly', + 'never' => 'never', + ] + ); + ?> +
+
+ field($entity_model, "[$index]priority") ->label(false) ->input( diff --git a/common/components/Sitemap.php b/common/components/Sitemap.php index c4bfd25..64bf031 100644 --- a/common/components/Sitemap.php +++ b/common/components/Sitemap.php @@ -6,14 +6,38 @@ use yii\base\Object; use yii\db\ActiveRecord; use yii\helpers\Html; - use yii\helpers\Url; + use yii\web\UrlManager; class Sitemap extends Object { public $entities = []; public $path = '@frontend/web/sitemap.xml'; + public $url = 'sitemap.xml'; /** + * Get absolute url to sitemap.xml + * + * @return string + */ + public function getUrl(): string + { + /** + * @var UrlManager $urlManager + */ + $urlManager = \Yii::$app->get('urlManagerFrontend'); + return $urlManager->createAbsoluteUrl('/' . $this->url); + } + + /** + * Check whether sitemap.xml exist + * + * @return bool + */ + public function checkFileExist(): bool + { + return file_exists(\Yii::getAlias($this->path)); + } + /** * Generate sitemap XML in $path * * @return bool @@ -47,6 +71,10 @@ */ public function generateOneShot(): string { + /** + * @var UrlManager $urlManager + */ + $urlManager = \Yii::$app->get('urlManagerFrontend'); $content = ''; $content .= ''; /** @@ -60,7 +88,7 @@ 'url', Html::tag('loc', $item->url) . Html::tag('lastmod', date('Y-m-d')) . Html::tag( 'changefreq', - 'monthly' + $item->frequency ) . Html::tag('priority', $item->priority) ); } @@ -100,16 +128,15 @@ 'url', Html::tag( 'loc', - Url::to( + $urlManager->createAbsoluteUrl( [ $entity[ 'url' ], 'id' => $record->getAttribute('id'), - ], - true + ] ) ) . Html::tag('lastmod', date('Y-m-d')) . Html::tag( 'changefreq', - 'monthly' + $model->frequency ) . Html::tag('priority', $model->priority) ); } diff --git a/common/config/SitemapDynamic.php b/common/config/SitemapDynamic.php index b90b5a0..66c4ee0 100644 --- a/common/config/SitemapDynamic.php +++ b/common/config/SitemapDynamic.php @@ -2,9 +2,10 @@ return [ 1 => [ - 'entity' => 'artbox\\core\\models\\Page', - 'status' => '1', - 'priority' => '0.6', - 'id' => 1, + 'entity' => 'artbox\\core\\models\\Page', + 'status' => '1', + 'frequency' => 'hourly', + 'priority' => '0.7', + 'id' => 1, ], ]; \ No newline at end of file diff --git a/common/config/SitemapStatic.php b/common/config/SitemapStatic.php index 17cea76..9a70227 100644 --- a/common/config/SitemapStatic.php +++ b/common/config/SitemapStatic.php @@ -2,8 +2,15 @@ return [ 1 => [ - 'url' => 'http://www.artbox.dev/', - 'priority' => '1', - 'id' => 1, + 'url' => 'http://www.artbox.dev/', + 'frequency' => 'monthly', + 'priority' => '1', + 'id' => 1, + ], + 2 => [ + 'url' => 'http://www.artbox.dev/site/contacts', + 'frequency' => 'monthly', + 'priority' => '0.7', + 'id' => 2, ], ]; \ No newline at end of file diff --git a/common/config/settings.php b/common/config/settings.php index 73e2ce0..20feb28 100755 --- a/common/config/settings.php +++ b/common/config/settings.php @@ -2,17 +2,32 @@ return [ 1 => [ - 'id' => '1', - 'name' => 'Admin321', - 'description' => 'Site administrator', + 'phone' => '+38 (044) 593-73-76', + 'phone2' => '+38 (098) 468-07-64', + 'skype' => 'artwebstudio', + 'email' => 'artweb.ua@gmail.com', + 'house' => '1-М', + 'street' => 'пр. М. Бажана', + 'office' => '25', + 'city' => 'Киев', + 'country' => '', + 'lat' => '50.409382', + 'lon' => '30.646391', + 'facebook' => 'https://www.facebook.com/ArtWeb.ua/', + 'vk' => 'https://vk.com/artwebua', + 'ok' => 'https://ok.ru/artwebua', + 'google' => 'https://plus.google.com/+ArtwebUaAgency', + 'twitter' => 'https://twitter.com/ArtWeb_ua', + 'name' => 'Artweb', + 'logo' => '2', + 'about' => 'Строим бизнес в онлайне', 'analytics_key' => '119240817', 'robots' => 'User-agent: Google Disallow: - -User-agent: * -Disallow: /', - 'ga_code' => 'TEst', - 'ya_code' => 'TEst 2', - 'tag_manager' => 'TEst 3', +', + 'ga_code' => '796967', + 'ya_code' => '08908908', + 'tag_manager' => '', + 'id' => 1, ], ]; \ No newline at end of file diff --git a/common/models/Settings.php b/common/models/Settings.php index 8d7f069..442d201 100755 --- a/common/models/Settings.php +++ b/common/models/Settings.php @@ -1,6 +1,7 @@ ImageManager::className(), + 'targetAttribute' => 'id', + ], + [ + [ + 'logo', + ], + 'filter', + 'filter' => function ($value) { + if (empty( $value )) { + return null; + } else { + return $value; + } + }, + ], ]; } @@ -78,14 +148,30 @@ public function attributeLabels() { return [ - 'id' => Yii::t('core', 'ID'), - 'name' => Yii::t('core', 'Name'), - 'description' => Yii::t('core', 'Description'), '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'), + 'phone' => Yii::t('core', 'Phone'), + 'phone2' => Yii::t('core', 'Additional phone'), + 'skype' => Yii::t('core', 'Skype'), + 'name' => Yii::t('core', 'Company name'), + 'email' => Yii::t('core', 'Email'), + 'house' => Yii::t('core', 'House'), + 'street' => Yii::t('core', 'Street'), + 'office' => Yii::t('core', 'Office'), + 'city' => Yii::t('core', 'City'), + 'country' => Yii::t('core', 'Country'), + 'lat' => Yii::t('core', 'Latitude'), + 'lon' => Yii::t('core', 'Longitude'), + 'facebook' => Yii::t('core', 'Facebook'), + 'vk' => Yii::t('core', 'VK'), + 'google' => Yii::t('core', 'Google'), + 'twitter' => Yii::t('core', 'Twitter'), + 'logo' => Yii::t('core', 'Company logo'), + 'about' => Yii::t('core', 'About us'), + 'ok' => Yii::t('core', 'Odnoklassniki'), ]; } diff --git a/common/models/SitemapDynamic.php b/common/models/SitemapDynamic.php index 2ecb05b..7d01f94 100644 --- a/common/models/SitemapDynamic.php +++ b/common/models/SitemapDynamic.php @@ -12,6 +12,7 @@ * @property string $entity * @property bool $status * @property float $priority + * @property string $frequency */ class SitemapDynamic extends ActiveRecord { @@ -37,6 +38,7 @@ 'entity', 'status', 'priority', + 'frequency', ]; } @@ -59,6 +61,7 @@ 'entity', 'status', 'priority', + 'frequency', ], 'required', ], @@ -71,6 +74,7 @@ [ [ 'entity', + 'frequency', ], 'string', ], @@ -91,10 +95,11 @@ public function attributeLabels() { return [ - 'id' => Yii::t('core', 'ID'), - 'entity' => Yii::t('core', 'Model'), - 'status' => Yii::t('core', 'Status'), - 'priority' => Yii::t('core', 'Priority'), + 'id' => Yii::t('core', 'ID'), + 'entity' => Yii::t('core', 'Model'), + 'status' => Yii::t('core', 'Status'), + 'priority' => Yii::t('core', 'Priority'), + 'frequency' => Yii::t('core', 'Frequency'), ]; } diff --git a/common/models/SitemapStatic.php b/common/models/SitemapStatic.php index 16af9a3..24b3be0 100644 --- a/common/models/SitemapStatic.php +++ b/common/models/SitemapStatic.php @@ -11,6 +11,7 @@ * @property int $id * @property string $url * @property float $priority + * @property string $frequency */ class SitemapStatic extends ActiveRecord { @@ -31,6 +32,7 @@ 'id', 'url', 'priority', + 'frequency', ]; } @@ -66,6 +68,7 @@ [ [ 'url', + 'frequency', ], 'string', ], @@ -78,9 +81,10 @@ public function attributeLabels() { return [ - 'id' => Yii::t('core', 'ID'), - 'url' => Yii::t('core', 'Url'), - 'priority' => Yii::t('core', 'Priority'), + 'id' => Yii::t('core', 'ID'), + 'url' => Yii::t('core', 'Url'), + 'priority' => Yii::t('core', 'Priority'), + 'frequency' => Yii::t('core', 'Frequency'), ]; } diff --git a/composer.lock b/composer.lock index 83654df..71926cd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "36eb0ae581bcd3b79ac784abbb046108", - "content-hash": "51847bf92742211dfa7159261b54c33b", + "hash": "c2e977cd213cebff0ae0575975d20974", + "content-hash": "ca665ed7c0e1bd63947fab086b435a30", "packages": [ { "name": "2amigos/yii2-tinymce-widget", diff --git a/frontend/web/sitemap.xml b/frontend/web/sitemap.xml new file mode 100644 index 0000000..4f5f6d7 --- /dev/null +++ b/frontend/web/sitemap.xml @@ -0,0 +1 @@ +http://www.artbox.dev/2017-03-30monthly1http://www.artbox.dev/site/contacts2017-03-30monthly0.7http://www.artbox.dev/en/text-en2017-03-30hourly0.7 \ No newline at end of file -- libgit2 0.21.4