source: branches/comu/html/sitemap.php @ 15125

Revision 15125, 8.5 KB checked in by nanasess, 17 years ago (diff)

モバイル対応で新規追加

  • Property svn:keywords set to Id Revision Date
RevLine 
[15125]1<?php
2/**
3 *
4 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
5 *
6 * http://www.lockon.co.jp/
7 *
8 */
9
10/**
11 * Sitemap¥×¥í¥È¥³¥ë ¥Õ¥¡¥¤¥ëÀ¸À®¥â¥¸¥å¡¼¥ë.
12 * PHP versions 4 and 5
13 *
14 * <pre>
15 * ¤³¤Î¥â¥¸¥å¡¼¥ë¤Ï Sitemap¥×¥í¥È¥³¥ë¤ËÂбþ¤·¤¿ XML¥Õ¥¡¥¤¥ë¤ò½ÐÎϤ¹¤ë.
16 * EC-CUBE ¥¤¥ó¥¹¥È¡¼¥ë¥Ç¥£¥ì¥¯¥È¥ê¤Î html¥Ç¥£¥ì¥¯¥È¥ê¤ØÇÛÃÖ¤¹¤ë¤³¤È¤Ë¤è¤êÆ°ºî¤¹¤ë.
17 *
18 * ¤³¤Î¥â¥¸¥å¡¼¥ë¤Ë¤è¤ê, °Ê²¼¤Î¥Ú¡¼¥¸¤Î¥µ¥¤¥È¥Þ¥Ã¥×¤¬À¸À®¤µ¤ì¤ë.
19 * 1. $staticURL ¤Ç»ØÄꤷ¤¿¥Ú¡¼¥¸
20 * 2. ´ÉÍý²èÌ̤Υǥ¶¥¤¥ó´ÉÍý¤«¤éÀ¸À®¤·¤¿¥Ú¡¼¥¸
21 * 3. ¸ø³«¤µ¤ì¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î¾¦ÉÊ°ìÍ÷¥Ú¡¼¥¸
22 * 4. ¸ø³«¤µ¤ì¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î¾¦Éʾܺ٥ڡ¼¥¸
23 * 5. html/mobile °Ê²¼¤Î¾åµ­¥Ú¡¼¥¸
24 *
25 * ¤³¤Î¥â¥¸¥å¡¼¥ë¤òÀßÃÖ¸å, ³Æ¸¡º÷¥¨¥ó¥¸¥ó¤Ë¥µ¥¤¥È¥Þ¥Ã¥×¤òÅÐÏ¿¤¹¤ë¤³¤È¤Ë¤è¤ê, ¸¡º÷¥¨¥ó¥¸¥ó¤Î
26 * ¥¤¥ó¥Ç¥Ã¥¯¥¹²½¤¬Â¥¿Ê¤µ¤ì¤ë.
27 * </pre>
28 * @see https://www.google.com/webmasters/tools/siteoverview?hl=ja
29 * @see https://siteexplorer.search.yahoo.com/mysites
30 *
31 * @author Kentaro Ohkouchi
32 * @version $Id$
33 */
34require_once("require.php");
35// --------------------------------------------------------------------- ½é´üÀßÄê
36// :TODO: filemtime ´Ø¿ô¤ò»È¤¨¤Ð¡¢ÀÅŪ¤Ê¥Ú¡¼¥¸¤Î¹¹¿·»þ´Ö¤â¼èÆÀ¤¹¤ë¤è¤¦¤Ë¤Ç¤­¤½¤¦
37//
38// ưŪ¤ËÀ¸À®¤µ¤ì¤Ê¤¤¥Ú¡¼¥¸¤òÇÛÎó¤Ç»ØÄê
39$staticURL = array(SITE_URL, MOBILE_SITE_URL, SITE_URL . "rss/index.php");
40// :TODO: ³Æ¥Ú¡¼¥¸¤Î changefreq ¤ä priority ¤ò»ØÄê¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë
41// ----------------------------------------------------------------------------
42
43// ----------------------------------------------------------------------------
44// }}}
45// {{{ View Logic
46
47/**
48 * Sitemap ¤Î <url /> ¤òÀ¸À®¤¹¤ë.
49 *
50 * @param string $loc ¥Ú¡¼¥¸¤Î URL ¢¨É¬¿Ü
51 * @param string $lastmod ¥Õ¥¡¥¤¥ë¤ÎºÇ½ª¹¹¿·Æü YYYY-MM-DD or  W3C Datetime ·Á¼°
52 * @param string $changefreq ¥Ú¡¼¥¸¤Î¹¹¿·ÉÑÅÙ
53 * @param double $priority URL ¤ÎÍ¥ÀèÅÙ
54 * @return Sitemap ·Á¼°¤Î <url />
55 * @see https://www.google.com/webmasters/tools/docs/ja/protocol.html#xmlTagDefinitions
56 */
57function createSitemap($loc, $lastmod = "", $changefreq = "", $priority = "") {
58    printf("\t<url>\n");
59    printf("\t\t<loc>%s</loc>\n", htmlentities($loc, ENT_QUOTES, "UTF-8"));
60    if (!empty($lastmod)) {
61        printf("\t\t<lastmod>%s</lastmod>\n", $lastmod);
62    }
63    if (!empty($changefreq)) {
64        printf("\t\t<changefreq>%s</changefreq>\n", $changefreq);
65    }
66    if(!empty($priority)) {
67        printf("\t\t<priority>%01.1f</priority>\n", $priority);
68    }
69    printf("\t</url>\n");
70}
71
72$objQuery = new SC_Query();
73
74//¥­¥ã¥Ã¥·¥å¤·¤Ê¤¤(Ç°¤Î¤¿¤á)
75header("Paragrama: no-cache");
76
77//XML¥Æ¥­¥¹¥È
78header("Content-type: application/xml; charset=utf-8");
79
80// ɬ¤º UTF-8 ¤È¤·¤Æ½ÐÎÏ
81mb_http_output("UTF-8");
82ob_start('mb_output_handler');
83
84print("<?xml version='1.0' encoding='UTF-8'?>\n");
85print("<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>\n");
86
87// ----------------------------------------------------------------------------
88// }}}
89// {{{ Controller Logic
90
91// ÀÅŪ¤Ê¥Ú¡¼¥¸¤ò½èÍý
92foreach($staticURL as $url) {
93    createSitemap($url, '', 'daily', 1.0);
94}
95// ¥Ú¡¼¥¸¤Î¥Ç¡¼¥¿¤ò¼èÆÀ
96$objPageData = new LC_PageLayout;
97
98// TOP¥Ú¡¼¥¸¤ò½èÍý
99$topPage = getTopPage($objPageData->arrPageList);
100createSitemap($topPage[0]['url'], date2W3CDatetime($topPage[0]['update_date']),
101                'daily', 1.0);
102
103// ÊÔ½¸²Äǽ¥Ú¡¼¥¸¤ò½èÍý
104$editablePages = getEditablePage($objPageData->arrPageList);
105foreach($editablePages as $editablePage) {
106    createSitemap($editablePage['url'], date2W3CDatetime($editablePage['update_date']));
107}
108
109// ¾¦ÉÊ°ìÍ÷¥Ú¡¼¥¸¤ò½èÍý
110$products = getAllProducts();
111foreach($products as $product) {
112    createSitemap($product['url'], '', 'daily');
113}
114$mobileProducts = getAllProducts(true);
115foreach($mobileProducts as $mobileProduct) {
116    createSitemap($mobileProduct['url'], '', 'daily');
117}
118
119// ¾¦Éʾܺ٥ڡ¼¥¸¤ò½èÍý
120$details = getAllDetail();
121foreach($details as $detail) {
122    createSitemap($detail['url'], date2W3CDatetime($detail['update_date']));
123}
124$mobileDetails = getAllDetail(true);
125foreach($mobileDetails as $mobileDetail) {
126    createSitemap($mobileDetail['url'], date2W3CDatetime($mobileDetail['update_date']));
127}
128
129print("</urlset>\n");
130
131// ----------------------------------------------------------------------------
132// }}}
133// {{{ Model Logic
134
135/**
136 * TOP¥Ú¡¼¥¸¤Î¾ðÊó¤ò¼èÆÀ
137 *
138 * @param array $pageData ¤¹¤Ù¤Æ¤Î¥Ú¡¼¥¸¾ðÊó¤ÎÇÛÎó
139 * @return TOP¥Ú¡¼¥¸¤Î¾ðÊó
140 */
141function getTopPage($pageData) {
142    $arrRet = array();
143    foreach($pageData as $page) {
144        if ($page['page_id'] == "1") {
145            $page['url'] = SITE_URL . $page['url'];
146            $arrRet[0] = $page;
147            return $arrRet;
148        }
149    }
150}
151
152/**
153 * ¤¹¤Ù¤Æ¤ÎÊÔ½¸²Äǽ¥Ú¡¼¥¸¤Î¾ðÊó¤ò¼èÆÀ¤¹¤ë.
154 *
155 * @param array $pageData ¤¹¤Ù¤Æ¤Î¥Ú¡¼¥¸¾ðÊó¤ÎÇÛÎó
156 * @return ÊÔ½¸²Äǽ¥Ú¡¼¥¸
157 */
158function getEditablePage($pageData) {
159    $arrRet = array();
160    $i = 0;
161    foreach($pageData as $page) {
162        if ($page['page_id'] > 4) {
163            $arrRet[$i] = $page;
164            $i++;
165        }
166    }
167    return $arrRet;
168}
169
170/**
171 * date·Á¼°¤Îʸ»úÎó¤ò W3C Datetime ·Á¼°¤ËÊÑ´¹¤·¤Æ½ÐÎϤ¹¤ë.
172 *
173 * @param date $date ÊÑ´¹¤¹¤ëÆüÉÕ
174 */
175function date2W3CDatetime($date) {
176    $arr = array();
177    // Àµµ¬É½¸½¤Çʸ»úÎó¤òÃê½Ð
178    ereg("^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})",
179        $date, $arr);
180    // :TODO: time zone ¤â¼èÆÀ¤¹¤ë¤Ù¤­...
181    return sprintf("%04d-%02d-%02dT%02d:%02d:%02d+09:00",
182            $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6]);
183}
184
185// ----------------------------------------------------------------------------
186// }}}
187// {{{ DB Access Objects
188
189/**
190 * ¥Ú¡¼¥¸¥Ç¡¼¥¿¤ò°·¤¦¥¯¥é¥¹.
191 */
192class LC_PageLayout {
193
194    var $arrPageData;       // ¥Ú¡¼¥¸¥Ç¡¼¥¿³ÊǼÍÑ
195    var $arrPageList;       // ¥Ú¡¼¥¸¥Ç¡¼¥¿³ÊǼÍÑ
196
197    /**
198     * ¥³¥ó¥¹¥È¥é¥¯¥¿.
199     */
200    function LC_PageLayout() {
201        $this->arrPageList = $this->getPageData();
202    }
203
204    /**
205     * ¥Ö¥í¥Ã¥¯¾ðÊó¤ò¼èÆÀ¤¹¤ë.
206     *
207     * @param string $where WHERE¶ç
208     * @param array  $arrVal WHERE¶ç¤ÎÃͤò³ÊǼ¤·¤¿ÇÛÎó
209     * @return ¥Ö¥í¥Ã¥¯¾ðÊó
210     */
211    function getPageData($where = '', $arrVal = ''){
212        $objDBConn = new SC_DbConn;     // DBÁàºî¥ª¥Ö¥¸¥§¥¯¥È
213        $sql = "";                      // ¥Ç¡¼¥¿¼èÆÀSQLÀ¸À®ÍÑ
214        $arrRet = array();              // ¥Ç¡¼¥¿¼èÆÀÍÑ
215
216        // SQLÀ¸À®(url ¤È update_date °Ê³°¤ÏÉÔÍס©)
217        $sql .= " SELECT";
218        $sql .= " page_id";             // ¥Ú¡¼¥¸ID
219        $sql .= " ,page_name";          // ̾¾Î
220        $sql .= " ,url";                // URL
221        $sql .= " ,php_dir";            // phpÊݸÀè¥Ç¥£¥ì¥¯¥È¥ê
222        $sql .= " ,tpl_dir";            // tplÊݸÀè¥Ç¥£d¥ì¥¯¥È¥ê
223        $sql .= " ,filename";           // ¥Õ¥¡¥¤¥ë̾¾Î
224        $sql .= " ,header_chk ";        // ¥Ø¥Ã¥À¡¼»ÈÍÑFLG
225        $sql .= " ,footer_chk ";        // ¥Õ¥Ã¥¿¡¼»ÈÍÑFLG
226        $sql .= " ,author";             // author¥¿¥°
227        $sql .= " ,description";        // description¥¿¥°
228        $sql .= " ,keyword";            // keyword¥¿¥°
229        $sql .= " ,update_url";         // ¹¹¿·URL
230        $sql .= " ,create_date";        // ¥Ç¡¼¥¿ºîÀ®Æü
231        $sql .= " ,update_date";        // ¥Ç¡¼¥¿¹¹¿·Æü
232        $sql .= " FROM ";
233        $sql .= "     dtb_pagelayout";
234
235        // where¶ç¤Î»ØÄ꤬¤¢¤ì¤ÐÄɲÃ
236        if ($where != '') {
237            $sql .= " WHERE " . $where;
238        }
239
240        $sql .= " ORDER BY  page_id";
241
242        $arrRet = $objDBConn->getAll($sql, $arrVal);
243
244        $this->arrPageData = $arrRet;
245
246        return $arrRet;
247    }
248}
249
250/**
251 * ¤¹¤Ù¤Æ¤Î¾¦ÉÊ°ìÍ÷¥Ú¡¼¥¸¤ò¼èÆÀ¤¹¤ë.
252 *
253 * @param boolean $isMobile ¥â¥Ð¥¤¥ë¥Ú¡¼¥¸¤ò¼èÆÀ¤¹¤ë¾ì¹ç true
254 * @return ¸¡º÷¥¨¥ó¥¸¥ó¤«¤é¥¢¥¯¥»¥¹²Äǽ¤Ê¾¦ÉÊ°ìÍ÷¥Ú¡¼¥¸¤Î¾ðÊó
255 */
256function getAllProducts($isMobile = false) {
257    $conn = new SC_DBConn();
258    $sql = "SELECT category_id FROM dtb_category WHERE del_flg = 0";
259    $result = $conn->getAll($sql);
260
261    $mobile = "";
262    if ($isMobile) {
263        $mobile = "mobile/";
264    }
265
266    $arrRet = array();
267    for ($i = 0; $i < count($result); $i++) {
268        // :TODO: ¥«¥Æ¥´¥ê¤ÎºÇ½ª¹¹¿·Æü¤ò¼èÆÀ¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë
269        $page = array("url" => SITE_URL . sprintf("%sproducts/list.php?category_id=%d", $mobile, $result[$i]['category_id']));
270        $arrRet[$i] = $page;
271    }
272    return $arrRet;
273}
274
275/**
276 * ¤¹¤Ù¤Æ¤Î¾¦Éʾܺ٥ڡ¼¥¸¤ò¼èÆÀ¤¹¤ë.
277 *
278 * @param boolean $isMobile ¥â¥Ð¥¤¥ë¥Ú¡¼¥¸¤ò¼èÆÀ¤¹¤ë¾ì¹ç true
279 * @return ¸¡º÷¥¨¥ó¥¸¥ó¤«¤é¥¢¥¯¥»¥¹²Äǽ¤Ê¾¦Éʾܺ٥ڡ¼¥¸¤Î¾ðÊó
280 */
281function getAllDetail($isMobile = false) {
282    $conn = new SC_DBConn();
283    $sql = "SELECT product_id, update_date FROM dtb_products WHERE del_flg = 0 AND status = 1";
284    $result = $conn->getAll($sql);
285
286    $mobile = "";
287    if ($isMobile) {
288        $mobile = "mobile/";
289    }
290
291    $arrRet = array();
292    for ($i = 0; $i < count($result); $i++) {
293        $page = array("url" => SITE_URL. sprintf("%sproducts/detail.php?product_id=%d", $mobile, $result[$i]['product_id']),
294                        "update_date" => $result[$i]['update_date']);
295        $arrRet[$i] = $page;
296    }
297    return $arrRet;
298}
299?>
Note: See TracBrowser for help on using the repository browser.