Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskonsite-архив-перенесен
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitry Korolev
taskonsite-архив-перенесен
Commits
4113e5d5
Commit
4113e5d5
authored
Mar 21, 2016
by
Олег Гиммельшпах
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#1097 - Создать Sitemap специально для яндекс
parent
8c62d8cc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
3 deletions
+41
-3
common/modules/blog/models/Post.php
common/modules/blog/models/Post.php
+17
-0
frontend/config/main.php
frontend/config/main.php
+1
-0
frontend/modules/sitemap/Sitemap.php
frontend/modules/sitemap/Sitemap.php
+2
-2
frontend/modules/sitemap/views/default/index.php
frontend/modules/sitemap/views/default/index.php
+21
-1
No files found.
common/modules/blog/models/Post.php
View file @
4113e5d5
...
@@ -11,6 +11,7 @@ use common\modules\blog\models\PostTag;
...
@@ -11,6 +11,7 @@ use common\modules\blog\models\PostTag;
use
common\modules\users\models\User
;
use
common\modules\users\models\User
;
use
common\models\MetaTags
;
use
common\models\MetaTags
;
use
common\modules\sessions\models\SessionUrl
;
use
common\modules\sessions\models\SessionUrl
;
use
frontend\modules\sitemap\behaviors\SitemapBehavior
;
/**
/**
* This is the model class for table "posts".
* This is the model class for table "posts".
...
@@ -95,6 +96,22 @@ class Post extends \common\components\ActiveRecordModel
...
@@ -95,6 +96,22 @@ class Post extends \common\components\ActiveRecordModel
'folder'
=>
'/uploads/blog/'
,
'folder'
=>
'/uploads/blog/'
,
'field'
=>
'preview'
'field'
=>
'preview'
],
],
'sitemap'
=>
[
'class'
=>
SitemapBehavior
::
className
(),
'scope'
=>
function
(
$model
)
{
/** @var \yii\db\ActiveQuery $model */
$model
->
select
([
'url'
,
'updated_at'
]);
$model
->
andWhere
([
'active'
=>
1
]);
},
'dataClosure'
=>
function
(
$model
)
{
return
[
'loc'
=>
Url
::
to
(
'blog/'
.
$model
->
url
),
'lastmod'
=>
date
(
'c'
,
$model
->
updated_at
),
'changefreq'
=>
SitemapBehavior
::
CHANGEFREQ_DAILY
,
'priority'
=>
0.5
];
}
],
];
];
}
}
...
...
frontend/config/main.php
View file @
4113e5d5
...
@@ -31,6 +31,7 @@ return [
...
@@ -31,6 +31,7 @@ return [
'models'
=>
[
'models'
=>
[
// your models
// your models
'common\modules\content\models\CoContent'
,
'common\modules\content\models\CoContent'
,
'common\modules\blog\models\Post'
,
],
],
'urls'
=>
[
'urls'
=>
[
// // your additional urls
// // your additional urls
...
...
frontend/modules/sitemap/Sitemap.php
View file @
4113e5d5
...
@@ -59,7 +59,7 @@ class Sitemap extends Module
...
@@ -59,7 +59,7 @@ class Sitemap extends Module
* @return string
* @return string
* @throws \yii\base\InvalidConfigException
* @throws \yii\base\InvalidConfigException
*/
*/
public
function
buildSitemap
(
$
links
=
false
)
public
function
buildSitemap
(
$
google
=
false
)
{
{
$urls
=
$this
->
urls
;
$urls
=
$this
->
urls
;
...
@@ -86,7 +86,7 @@ class Sitemap extends Module
...
@@ -86,7 +86,7 @@ class Sitemap extends Module
$sitemapData
=
$this
->
createControllerByID
(
'default'
)
->
renderPartial
(
'index'
,
[
$sitemapData
=
$this
->
createControllerByID
(
'default'
)
->
renderPartial
(
'index'
,
[
'urls'
=>
$urls
,
'urls'
=>
$urls
,
'langs'
=>
$langs
,
'langs'
=>
$langs
,
'
links'
=>
$links
'
google'
=>
$google
]);
]);
$this
->
cacheProvider
->
set
(
$this
->
cacheKey
,
$sitemapData
,
$this
->
cacheExpire
);
$this
->
cacheProvider
->
set
(
$this
->
cacheKey
,
$sitemapData
,
$this
->
cacheExpire
);
...
...
frontend/modules/sitemap/views/default/index.php
View file @
4113e5d5
...
@@ -17,7 +17,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
...
@@ -17,7 +17,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
<url>
<url>
<loc>
<?=
yii\helpers\Url
::
to
(
$url
[
'loc'
],
true
)
?>
</loc>
<loc>
<?=
yii\helpers\Url
::
to
(
$url
[
'loc'
],
true
)
?>
</loc>
<?php
if
(
$
links
&&
$langs
)
:
<?php
if
(
$
google
&&
$langs
)
:
foreach
(
$langs
as
$lang
)
:
?>
foreach
(
$langs
as
$lang
)
:
?>
<xhtml:link
rel=
"alternate"
hreflang=
"
<?=
$lang
->
url
?>
"
href=
"
<?=
yii\helpers\Url
::
to
((
!
$lang
->
default
?
'/'
.
$lang
->
url
:
''
)
.
(
$url
[
'loc'
]
==
'/'
?
''
:
'/'
.
$url
[
'loc'
]),
true
)
?>
"
/>
<xhtml:link
rel=
"alternate"
hreflang=
"
<?=
$lang
->
url
?>
"
href=
"
<?=
yii\helpers\Url
::
to
((
!
$lang
->
default
?
'/'
.
$lang
->
url
:
''
)
.
(
$url
[
'loc'
]
==
'/'
?
''
:
'/'
.
$url
[
'loc'
]),
true
)
?>
"
/>
<?php
endforeach
;
<?php
endforeach
;
...
@@ -74,5 +74,25 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
...
@@ -74,5 +74,25 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
<?php
endforeach
;
<?php
endforeach
;
endif
;
?>
endif
;
?>
</url>
</url>
<?php
if
(
!
$google
&&
$langs
)
:
foreach
(
$langs
as
$lang
)
:
if
(
!
$lang
->
default
)
:
?>
<url>
<loc>
<?=
yii\helpers\Url
::
to
(
'/'
.
$lang
->
url
.
(
$url
[
'loc'
]
==
'/'
?
''
:
'/'
.
$url
[
'loc'
]),
true
)
?>
</loc>
<?php
if
(
isset
(
$url
[
'lastmod'
]))
:
?>
<lastmod>
<?=
is_string
(
$url
[
'lastmod'
])
?
$url
[
'lastmod'
]
:
date
(
DATE_W3C
,
$url
[
'lastmod'
])
?>
</lastmod>
<?php
endif
;
?>
<?php
if
(
isset
(
$url
[
'changefreq'
]))
:
?>
<changefreq>
<?=
$url
[
'changefreq'
]
?>
</changefreq>
<?php
endif
;
?>
<?php
if
(
isset
(
$url
[
'priority'
]))
:
?>
<priority>
<?=
$url
[
'priority'
]
?>
</priority>
<?php
endif
;
?>
</url>
<?php
endif
;
?>
<?php
endforeach
;
?>
<?php
endif
;
?>
<?php
endforeach
;
?>
<?php
endforeach
;
?>
</urlset>
</urlset>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment