/
responsesitemap.gtw
99 lines (64 loc) · 3.11 KB
/
responsesitemap.gtw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
~~LANG:FR@frman:responsesitemap~~
jResponseSitemap allow you to generate a [[http://sitemaps.org/|sitemap]], used by search engines like Google.
Retrieve the response object in the controller:
<code php>
$resp = $this->getResponse('sitemap');
</code>
You have then a @@C@jResponseSitemap@@ object in @@V@$resp@@.
===== Restrictions in a sitemap =====
* A sitemap file cannot contain more than 50 000 URLs.
* A sitemap index file cannot declare more than 1000 sitemap files.
===== Manual generation =====
Creation of a sitemap is done by adding each URLs you want to declare in the file:
<code php>
$resp->addUrl($loc, $lastmod, $changefreq, $priority);
</code>
* @@V@$loc@@: URL of the page
* @@V@$lastmod@@: date of the last modification of the page. format: Y-m-d.
* @@V@$changefreq@@: Frequency of the page modifications (only these value: always, hourly, daily, weekly, monthly, yearly, never)
* @@V@$priority@@: priority of the url beside other URL you declare.
Only @@V@$loc@@ is required.
Example:
<code php>
$resp->addUrl(jUrl::get('module~home:index'));
$resp->addUrl(jUrl::get('module~contact:index'), null, 'weekly', 1);
</code>
===== Automatic generation from the urls.xml file =====
This behavior is only possible if you use the significant url engine.
You just have to call one method:
<code php>
$resp->importFromUrlsXml();
return $resp;
</code>
===== Index generation =====
If you have a big web site, it is prefered to have many files, and declare them in an index. You declare by calling this method:
<code php>
$resp->addSitemap($loc, $lastmod)
</code>
* @@V@$loc@@: URL of a sitemap
* @@V@$lastmod@@: date of the last modification of the page. format: Y-m-d.
Only @@V@$loc@@ is required.
It means that you have to create as many action as you want to generate sitemap files, and declare their URL in the urls.xml file. In an other action, you generate the index. You can call @@jUrl::get@@ for each sitemap and assign this value to @@$loc@@
<code php>
$resp->addSitemap(jUrl::get('mymodule~sitemap:s1');
$resp->addSitemap(jUrl::get('mymodule~sitemap:s2');
$resp->addSitemap(jUrl::get('mymodule~sitemap:s3');
$resp->addSitemap(jUrl::get('mymodule~sitemap:s4');
return $resp;
</code>
(s1, s2, s3 and s4 are actions where you generate a sitemap).
===== Registering your sitemap into search engines =====
To give the address of your sitemap to search engines, you can do it manually by filling the corresponding form on the web site of the search engine.
You can also do it automatically, by giving the URL of the registration process of the search engine, to the @@M@ping()@@ method:
<code php>
$sitemapurl = jUrl::get('mymodule~sitemap:index');
$url = 'http'. (empty($_SERVER['HTTPS']) ? '' : 's') .'://'. $_SERVER['HTTP_HOST'] . urlencode($sitemapurl);
// google
$resp->ping('http://www.google.com/webmasters/tools/ping?sitemap=' . $url);
// yahoo
$resp->ping('http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=YahooDemo&url=' . $url);
// Live
$resp->ping('http://webmaster.live.com/ping.aspx?siteMap='.$url);
// Ask
$resp->ping('http://submissions.ask.com/ping?sitemap=' . $url);
</code>