Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
007d01d4
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
17
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
007d01d4
编写于
3月 25, 2017
作者:
R
root
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fecshop sitemap xml文件的生成部分
上级
2b3d7517
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
363 addition
and
0 deletion
+363
-0
app/console/config/modules/Sitemap.php
app/console/config/modules/Sitemap.php
+16
-0
app/console/modules/Sitemap/Module.php
app/console/modules/Sitemap/Module.php
+28
-0
app/console/modules/Sitemap/controllers/XmlController.php
app/console/modules/Sitemap/controllers/XmlController.php
+57
-0
config/services/Sitemap.php
config/services/Sitemap.php
+47
-0
services/Sitemap.php
services/Sitemap.php
+160
-0
services/Url.php
services/Url.php
+36
-0
shell/sitemapGeneral.sh
shell/sitemapGeneral.sh
+19
-0
未找到文件。
app/console/config/modules/Sitemap.php
0 → 100644
浏览文件 @
007d01d4
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
?>
<?php
return
[
'sitemap'
=>
[
'class'
=>
'\fecshop\app\console\modules\Sitemap\Module'
,
],
];
app/console/modules/Sitemap/Module.php
0 → 100644
浏览文件 @
007d01d4
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\app\console\modules\Sitemap
;
use
Yii
;
use
fecshop\app\console\modules\ConsoleModule
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
Module
extends
ConsoleModule
{
public
$blockNamespace
;
public
function
init
()
{
# ´ָ
$nameSpace
=
__NAMESPACE__
;
$this
->
controllerNamespace
=
$nameSpace
.
'\\controllers'
;
$this
->
blockNamespace
=
$nameSpace
.
'\\block'
;
parent
::
init
();
}
}
app/console/modules/Sitemap/controllers/XmlController.php
0 → 100644
浏览文件 @
007d01d4
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\app\console\modules\Sitemap\controllers
;
use
Yii
;
use
yii\base\InlineAction
;
use
yii\console\Controller
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
XmlController
extends
Controller
{
public
function
actionBegin
(){
Yii
::
$service
->
sitemap
->
beginSiteMap
();
}
# 首页
public
function
actionHome
(){
Yii
::
$service
->
sitemap
->
home
();
}
# 分类页面的页面总数
public
function
actionCategorypagecount
(){
echo
Yii
::
$service
->
sitemap
->
categorypagecount
();
}
# 生成分类页面
public
function
actionCategory
(
$pageNum
){
Yii
::
$service
->
sitemap
->
category
(
$pageNum
);
}
# 产品页面的页面总数
public
function
actionProductpagecount
(){
echo
Yii
::
$service
->
sitemap
->
productpagecount
();
}
# 生成产品页面
public
function
actionProduct
(
$pageNum
){
Yii
::
$service
->
sitemap
->
product
(
$pageNum
);
}
# cms page页面的页面总数
public
function
actionCmspagepagecount
(){
echo
Yii
::
$service
->
sitemap
->
cmspagepagecount
();
}
# 生成cms page页面的sitemap
public
function
actionCmspage
(
$pageNum
){
Yii
::
$service
->
sitemap
->
cmspage
(
$pageNum
);
}
public
function
actionEnd
(){
Yii
::
$service
->
sitemap
->
endSiteMap
();
}
}
\ No newline at end of file
config/services/Sitemap.php
0 → 100644
浏览文件 @
007d01d4
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
return
[
'sitemap'
=>
[
'class'
=>
'fecshop\services\Sitemap'
,
'sitemapConfig'
=>
[
/**
* 对于下面的设置,您可能感觉很啰嗦,域名作为store的key,在store service中已经设置,
* 为什么需要在这里重新搞一套呢? 这样做是为了更加的灵活
*
*/
# appfront入口
'appfront'
=>
[
# store的key(域名),
'fecshop.appfront.fancyecommerce.com'
=>
[
'https'
=>
false
,
# false代表使用http,true代表使用https
'sitemapDir'
=>
'@appfront/web/sitemap.xml'
,
# sitemap存放的地址
'showScriptName'
=>
true
,
# 是否显示index.php ,譬如http://www.fecshop.com/index.php/xxxxxx,当nginx没有设置重写,这里需要设置为true,这样url中会存在index.php,否则会404
# 这个设置对seo来说,设置为false最合适,也就是隐藏 url中index.php ,这种设置需要开启nginx的url重写
],
# store的key(域名)
'fecshop.appfront.fancyecommerce.com/fr'
=>
[
'https'
=>
false
,
# false代表使用http,true代表使用https
'sitemapDir'
=>
'@appfront/web/fr/sitemap.xml'
,
# sitemap存放的地址
'showScriptName'
=>
true
,
],
'fecshop.appfront.es.fancyecommerce.com'
=>
[
'https'
=>
false
,
# false代表使用http,true代表使用https
'sitemapDir'
=>
'@appfront/web/sitemap_es.xml'
,
'showScriptName'
=>
true
,
],
'fecshop.appfront.fancyecommerce.com/cn'
=>
[
'https'
=>
false
,
# false代表使用http,true代表使用https
'sitemapDir'
=>
'@appfront/web/sitemap_cn.xml'
,
'showScriptName'
=>
true
,
],
]
],
],
];
\ No newline at end of file
services/Sitemap.php
浏览文件 @
007d01d4
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\services
;
use
Yii
;
use
yii\base\InvalidValueException
;
use
yii\base\InvalidConfigException
;
use
fec\helpers\CSession
;
use
fec\helpers\CUrl
;
/**
* Shipping services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
Sitemap
extends
Service
{
public
$numPerPage
=
100
;
public
$sitemapConfig
;
protected
$currentDate
;
// = date('Y-m-d');
protected
function
initSiteMap
(){
$this
->
currentDate
=
date
(
'Y-m-d'
);
}
protected
function
actionBeginSiteMap
(){
$this
->
initSiteMap
();
if
(
is_array
(
$this
->
sitemapConfig
)
&&
!
empty
(
$this
->
sitemapConfig
)){
foreach
(
$this
->
sitemapConfig
as
$appIn
=>
$store
){
if
(
is_array
(
$store
)
&&
!
empty
(
$store
)){
foreach
(
$store
as
$domain
=>
$info
){
$sitemapDir
=
(
isset
(
$info
[
'sitemapDir'
])
&&
$info
[
'sitemapDir'
])
?
$info
[
'sitemapDir'
]
:
''
;
if
(
$sitemapDir
){
$sitemapAbsoluteDir
=
Yii
::
getAlias
(
$sitemapDir
);
$xmlFile
=
fopen
(
$sitemapAbsoluteDir
,
'w'
)
or
die
(
"Unable to open file!"
);
if
(
file_exists
(
$sitemapAbsoluteDir
)){
$str
=
'<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="gss.xsl"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
'
;
fwrite
(
$xmlFile
,
$str
);
}
fclose
(
$xmlFile
);
}
}
}
}
}
}
protected
function
actionEndSiteMap
(){
echo
'111'
.
"
\n
"
;
$this
->
initSiteMap
();
if
(
is_array
(
$this
->
sitemapConfig
)
&&
!
empty
(
$this
->
sitemapConfig
)){
foreach
(
$this
->
sitemapConfig
as
$appIn
=>
$store
){
if
(
is_array
(
$store
)
&&
!
empty
(
$store
)){
foreach
(
$store
as
$domain
=>
$info
){
if
(
$sitemapDir
){
$sitemapAbsoluteDir
=
Yii
::
getAlias
(
$sitemapDir
);
$xmlFile
=
fopen
(
$sitemapAbsoluteDir
,
'a'
)
or
die
(
"Unable to open file!"
);
if
(
file_exists
(
$sitemapAbsoluteDir
)){
$str
=
'</urlset>'
;
//echo '111'."\n";
fwrite
(
$xmlFile
,
$str
);
}
fclose
(
$xmlFile
);
}
}
}
}
}
}
protected
function
actionHome
(){
$this
->
initSiteMap
();
if
(
is_array
(
$this
->
sitemapConfig
)
&&
!
empty
(
$this
->
sitemapConfig
)){
foreach
(
$this
->
sitemapConfig
as
$appIn
=>
$store
){
if
(
is_array
(
$store
)
&&
!
empty
(
$store
)){
foreach
(
$store
as
$domain
=>
$info
){
$https
=
$info
[
'https'
];
$showScriptName
=
$info
[
'showScriptName'
];
$sitemapDir
=
(
isset
(
$info
[
'sitemapDir'
])
&&
$info
[
'sitemapDir'
])
?
$info
[
'sitemapDir'
]
:
''
;
if
(
$sitemapDir
){
$sitemapAbsoluteDir
=
Yii
::
getAlias
(
$sitemapDir
);
$xmlFile
=
fopen
(
$sitemapAbsoluteDir
,
'a'
)
or
die
(
"Unable to open file!"
);
if
(
file_exists
(
$sitemapAbsoluteDir
)){
$home_url
=
Yii
::
$service
->
url
->
getUrlByDomain
(
''
,[],
$https
,
$domain
,
$showScriptName
);
$str
=
'<url><loc>'
.
$home_url
.
'</loc><lastmod>'
.
$this
->
currentDate
.
'</lastmod></url>'
;
fwrite
(
$xmlFile
,
$str
);
}
fclose
(
$xmlFile
);
}
}
}
}
}
}
protected
function
actionCategorypagecount
(){
$this
->
initSiteMap
();
$coll
=
Yii
::
$service
->
category
->
coll
(
$filter
);
$count
=
$coll
[
'count'
];
echo
ceil
(
$count
/
$this
->
numPerPage
);
}
protected
function
actionCategory
(
$pageNum
){
$this
->
initSiteMap
();
if
(
is_array
(
$this
->
sitemapConfig
)
&&
!
empty
(
$this
->
sitemapConfig
)){
foreach
(
$this
->
sitemapConfig
as
$appIn
=>
$store
){
if
(
is_array
(
$store
)
&&
!
empty
(
$store
)){
foreach
(
$store
as
$domain
=>
$info
){
$https
=
$info
[
'https'
];
$showScriptName
=
$info
[
'showScriptName'
];
$sitemapDir
=
(
isset
(
$info
[
'sitemapDir'
])
&&
$info
[
'sitemapDir'
])
?
$info
[
'sitemapDir'
]
:
''
;
if
(
$sitemapDir
){
$sitemapAbsoluteDir
=
Yii
::
getAlias
(
$sitemapDir
);
$xmlFile
=
fopen
(
$sitemapAbsoluteDir
,
'a'
)
or
die
(
"Unable to open file!"
);
if
(
file_exists
(
$sitemapAbsoluteDir
)){
$filter
=
[
'numPerPage'
=>
$this
->
numPerPage
,
'pageNum'
=>
$pageNum
,
'asArray'
=>
true
,
];
$coll
=
Yii
::
$service
->
category
->
coll
(
$filter
);
$data
=
$coll
[
'coll'
];
if
(
is_array
(
$data
)
&&
!
empty
(
$data
)){
foreach
(
$data
as
$one
){
$category_url_key
=
$one
[
'url_key'
];
$category_url
=
Yii
::
$service
->
url
->
getUrlByDomain
(
$category_url_key
,[],
false
,
$domain
,
$showScriptName
);
$str
=
'<url><loc>'
.
$category_url
.
'</loc><lastmod>'
.
$this
->
currentDate
.
'</lastmod></url>'
;
fwrite
(
$xmlFile
,
$str
);
}
}
}
fclose
(
$xmlFile
);
}
}
}
}
}
}
protected
function
actionProduct
(){
}
protected
function
actionCmspage
(){
}
}
\ No newline at end of file
services/Url.php
浏览文件 @
007d01d4
...
...
@@ -144,6 +144,42 @@ class Url extends Service
return
Yii
::
$service
->
url
->
rewrite
->
getOriginUrl
(
$urlKey
);
}
/**
* @property $url_key | String urlKey的值
* @property $params | Array 。url里面个各个参数
* @property https | boolean 是否使用https的方式
* @property $domain | String , 相应的域名,譬如www.fecshop.com
* 通过传入domain的方式得到相应的url
* 该功能一般是在脚本中通过各个域名的传入得到相应的url,譬如sitemap的生成就是应用了这个方法得到
* 产品和分类的url。
*/
protected
function
actionGetUrlByDomain
(
$url_key
,
$params
=
[],
$https
=
false
,
$domain
,
$showScriptName
=
false
){
$first_str
=
substr
(
$url_key
,
0
,
1
);
if
(
$first_str
==
'/'
){
$jg
=
''
;
}
else
{
$jg
=
'/'
;
}
$baseUrl
=
''
;
if
(
$https
){
$baseUrl
=
'https://'
.
$domain
;
}
else
{
$baseUrl
=
'http://'
.
$domain
;
}
if
(
$showScriptName
){
$baseUrl
.
=
'/index.php'
;
}
if
(
is_array
(
$params
)
&&
!
empty
(
$params
)){
$arr
=
[];
foreach
(
$params
as
$k
=>
$v
){
$arr
[]
=
$k
.
'='
.
$v
;
}
return
$baseUrl
.
$jg
.
$url_key
.
'?'
.
implode
(
'&'
,
$arr
);
}
return
$url_key
?
$baseUrl
.
$jg
.
$url_key
:
$baseUrl
;
}
/**
* @property $path|String, for example about-us.html, fashion-handbag/women.html
* genarate current store url by path.
...
...
shell/sitemapGeneral.sh
0 → 100644
浏览文件 @
007d01d4
#!/bin/sh
Cur_Dir
=
$(
cd
`
dirname
$0
`
;
pwd
)
$Cur_Dir
/../../../../yii sitemap/xml/begin
$Cur_Dir
/../../../../yii sitemap/xml/home
categoryPageCount
=
`
$Cur_Dir
/../../../../yii sitemap/xml/categorypagecount
`
echo
"There are
$categoryPageCount
page product to process"
for
((
i
=
1
;
i<
=
$categoryPageCount
;
i++
))
do
$Cur_Dir
/../../../../yii sitemap/xml/category
$i
echo
"Page
$i
done"
done
$Cur_Dir
/../../../../yii sitemap/xml/end
echo
'end success'
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录