source: branches/comu-euc/html/ror.php @ 17157

Revision 17157, 10.9 KB checked in by homan, 18 years ago (diff)

RORサイトマップ動的生成モジュール追加(html/ror.php)

Line 
1<?php
2/**
3 * Copyright(c) 2000-2008 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8/**
9 * ROR Sitemap¥×¥í¥È¥³¥ë ¥Õ¥¡¥¤¥ëÀ¸À®¥â¥¸¥å¡¼¥ë
10 * PHP4(PHP5¤Ç¤âưºî¤¹¤ë¤È»×¤ï¤ì¤Þ¤¹)
11 *
12 * (1)¥â¥¸¥å¡¼¥ë³µÍ×
13 *    ¤³¤Î¥â¥¸¥å¡¼¥ë¤Ï ROR Sitemap¥×¥í¥È¥³¥ë¤ËÂбþ¤·¤¿ XML¥Õ¥¡¥¤¥ë¤ò½ÐÎϤ¹¤ë¡£
14 *    ROR¤È¤ÏResources of a Resource¤Îά¤Ç¡¢Á´¤Æ¤Î¥µ¡¼¥Á¥¨¥ó¥¸¥ó¤ËÂФ·¤Æ»È¤¨¤ë¥µ¥¤¥È¥Þ¥Ã¥×¡£
15 *    see) http://www.rorweb.com/
16 *
17 *
18 * (2)¤³¤Î¥â¥¸¥å¡¼¥ë¤Ë¤Ç¤­¤ë¤³¤È
19 *    ¤³¤Î¥â¥¸¥å¡¼¥ë¤Ë¤è¤ê¡¢°Ê²¼¤Î¥Ú¡¼¥¸¤Î¥µ¥¤¥È¥Þ¥Ã¥×¤¬À¸À®¤µ¤ì¤ë¡£
20 *    1. $staticURL ¤Ç»ØÄꤷ¤¿¥Ú¡¼¥¸
21 *    2. ´ÉÍý²èÌ̤Υǥ¶¥¤¥ó´ÉÍý¤«¤éÀ¸À®¤·¤¿ÀÅŪ¥Ú¡¼¥¸
22 *    3. ¸ø³«¤µ¤ì¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î¾¦ÉʰìÍ÷¥Ú¡¼¥¸
23 *    4. ¸ø³«¤µ¤ì¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î¾¦Éʾܺ٥ڡ¼¥¸
24 *
25 * (3)»ÈÍÑÊýË¡
26 *    EC-CUBE ¥¤¥ó¥¹¥È¡¼¥ë¥Ç¥£¥ì¥¯¥È¥ê¤Î html¥Ç¥£¥ì¥¯¥È¥êľ²¼¤ØÇÛÃÖ¤¹¤ë¤³¤È¤Ë¤è¤êưºî¤¹¤ë¡£
27 *    ÀßÃָ塢meta¥¿¥°¤Ç°Ê²¼¤Î¤è¤¦¤ËÅÐÏ¿¤¹¤ë¤È¡¢³Æ¸¡º÷¥¨¥ó¥¸¥ó¤Î¥¯¥í¡¼¥é¡¼¤Ë
28 *    ¼«Æ°Åª¤Ë½¦¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤ë¡£
29 *    ex) <link rel="alternate" type="application/rss+xml" title="ROR" href="http://your-site.com/ror.php" />
30 *
31 *    ¤Þ¤¿¡¢¥µ¥¤¥È¥Þ¥Ã¥×¤òÅÐÏ¿¤¹¤ë¤³¤È¤Ë¤è¤ê, ¸¡º÷¥¨¥ó¥¸¥ó¤Î¥¤¥ó¥Ç¥Ã¥¯¥¹²½¤¬Â¥¿Ê¤µ¤ì¤ë¡£
32 *    see) https://www.google.com/webmasters/tools/siteoverview?hl=ja
33 *    see) https://siteexplorer.search.yahoo.com/mysites
34 *
35 * @author Kentaro Ohkouchi
36 * @modified Issei Homan
37 */
38
39require_once("require.php");
40$objSiteInfo = new SC_SiteInfo();
41
42//ŹÊÞ¾ðÊó¤ò¥»¥Ã¥È
43$arrSiteInfo = $objSiteInfo->data;
44
45// ưŪ¤ËÀ¸À®¤µ¤ì¤Ê¤¤¥Ú¡¼¥¸¤òÇÛÎó¤Ç»ØÄê
46$staticURL = array("RSS Feeds" => SITE_URL."rss/index.php");
47
48// ----------------------------------------------------------------------------
49// }}}
50// {{{ View Logic
51
52/**
53 * <item /> ¤òÀ¸À®¤¹¤ë.
54 *
55 * @param string $title      ¥Ú¡¼¥¸¥¿¥¤¥È¥ë
56 * @param string $link       ¥Ú¡¼¥¸¤Î URL ¢¨É¬¿Ü
57 * @param string $desc       ³µÍסÊû¡Ë¾¦ÉʰìÍ÷¥³¥á¥ó¥È
58 * @param string $descLong   ³µÍסÊĹ¡Ë¾¦Éʾܺ٥ᥤ¥ó¥³¥á¥ó¥È
59 * @param string $keywords   ¥«¥ó¥Þ¶èÀڤꥭ¡¼¥ï¡¼¥É comment3
60 * @param string $updated    ¥Õ¥¡¥¤¥ë¤ÎºÇ½ª¹¹¿·Æü YYYY-MM-DD or W3C Datetime ·Á¼°
61 * @param string $period     ¥Ú¡¼¥¸¤Î¹¹¿·ÉÑÅÙ
62 * @param string $image      ¥á¥¤¥ó²èÁü main_image
63 * @param string $imageLarge ³ÈÂç¥á¥¤¥ó²èÁü main_large_image
64 * @param int    $sort       ¥½¡¼¥ÈÃÍ
65 * @return Sitemap ·Á¼°¤Î <item />
66 * see) http://www.rorweb.com/
67 */
68function createSitemap($title = "", $link, $desc = "", $descLong = "", $keywords = "", $updated = "", $period = "", $image = "", $imageLarge = "", $sort = "") {
69    printf("\t<item>\n");
70    if (!empty($title)) {
71        printf("\t\t<title>%s</title>\n", mb_convert_encoding($title, "UTF-8", "EUC-JP"));
72    }
73    printf("\t\t<link>%s</link>\n", htmlentities($link, ENT_QUOTES, "UTF-8"));
74    if (!empty($desc)) {
75        printf("\t\t<description><![CDATA[%s]]></description>\n", mb_convert_encoding($desc, "UTF-8", "EUC-JP"));
76    }
77    if (!empty($descLong)) {
78        printf("\t\t<ror:descLong><![CDATA[%s]]></ror:descLong>\n", mb_convert_encoding($descLong, "UTF-8", "EUC-JP"));
79    }
80    if (!empty($keywords)) {
81        printf("\t\t<ror:keywords><![CDATA[%s]]></ror:keywords>\n", mb_convert_encoding($keywords, "UTF-8", "EUC-JP"));
82    }
83    if (!empty($updated)) {
84        printf("\t\t<ror:updated>%s</ror:updated>\n", $updated);
85    }
86    if (!empty($period)) {
87        printf("\t\t<ror:updatePeriod>%s</ror:updatePeriod>\n", $period);
88    }
89    if (!empty($image)) {
90        printf("\t\t<ror:image>%s</ror:image>\n", $image);
91    }
92    if (!empty($imageLarge)) {
93        printf("\t\t<ror:imageLarge>%s</ror:imageLarge>\n", $imageLarge);
94    }
95    if(!empty($sort)) {
96        printf("\t\t<ror:sortOrder>%d</ror:sortOrder>\n", $sort);
97    }
98    printf("\t\t<ror:resourceOf>SiteMap</ror:resourceOf>\n");
99    printf("\t</item>\n");
100}
101
102$objQuery = new SC_Query();
103
104//¥­¥ã¥Ã¥·¥å¤·¤Ê¤¤(ǰ¤Î¤¿¤á)
105header("Paragrama: no-cache");
106
107//XML¥Æ¥­¥¹¥È½ÐÎÏ
108header("Content-type: application/xml; charset=utf-8");
109
110// ɬ¤º UTF-8 ¤È¤·¤Æ½ÐÎÏ
111mb_http_output("UTF-8");
112ob_start('mb_output_handler');
113
114print("<?xml version='1.0' encoding='UTF-8'?>\n");
115print("<rss version='2.0' xmlns:ror='http://rorweb.com/0.1/'>\n");
116print("<channel>\n");
117print("<title>".mb_convert_encoding($arrSiteInfo['shop_name'], "UTF-8", "EUC-JP")."</title>\n");
118print("<link>".$arrSiteInfo['law_url']."/</link>\n");
119
120// ----------------------------------------------------------------------------
121// }}}
122// {{{ Controller Logic
123
124// ÀÅŪ¤Ê¥Ú¡¼¥¸¤ò½èÍý
125foreach($staticURL as $key => $url) {
126    createSitemap($key, $url, '', '', '', '', 'daily', '', '', 1);
127}
128// ¥Ú¡¼¥¸¤Î¥Ç¡¼¥¿¤ò¼èÆÀ
129$objPageData = new LC_PageLayout;
130
131// TOP¥Ú¡¼¥¸¤ò½èÍý
132$topPage = getTopPage($objPageData->arrPageList);
133createSitemap($topPage[0]['page_name'], $topPage[0]['url'], '', '', '', date2W3CDatetime($topPage[0]['update_date']),'daily', '', '', 1);
134
135// ÊÔ½¸²Äǽ¥Ú¡¼¥¸¤ò½èÍý
136$editablePages = getEditablePage($objPageData->arrPageList);
137foreach($editablePages as $editablePage) {
138    createSitemap($editablePage['page_name'], $editablePage['url'], '', '', '', date2W3CDatetime($editablePage['update_date']), '', '', '', 2);
139}
140
141// ¾¦ÉʰìÍ÷¥Ú¡¼¥¸¤ò½èÍý
142$products = getAllProducts();
143foreach($products as $product) {
144    createSitemap($product['title'], $product['url'], '', '', '', '', 'daily', '', '', 2);
145}
146
147// ¾¦Éʾܺ٥ڡ¼¥¸¤ò½èÍý
148$details = getAllDetail();
149foreach($details as $detail) {
150    createSitemap($detail['title'], $detail['url'], $detail['desc'], $detail['descLong'], $detail['keywords'], date2W3CDatetime($detail['update_date']), 'weekly', $detail['image'], $detail['imageLarge'], 3);
151}
152
153print("</channel>\n");
154print("</rss>\n");
155
156// ----------------------------------------------------------------------------
157// }}}
158// {{{ Model Logic
159
160/**
161 * TOP¥Ú¡¼¥¸¤Î¾ðÊó¤ò¼èÆÀ
162 *
163 * @param array $pageData ¤¹¤Ù¤Æ¤Î¥Ú¡¼¥¸¾ðÊó¤ÎÇÛÎó
164 * @return TOP¥Ú¡¼¥¸¤Î¾ðÊó
165 */
166function getTopPage($pageData) {
167    $arrRet = array();
168    foreach($pageData as $page) {
169        if ($page['page_id'] == "1") {
170            $page['url'] = SITE_URL . $page['url'];
171            $arrRet[0] = $page;
172            return $arrRet;
173        }
174    }
175}
176
177/**
178 * ¤¹¤Ù¤Æ¤ÎÊÔ½¸²Äǽ¥Ú¡¼¥¸¤Î¾ðÊó¤ò¼èÆÀ¤¹¤ë.
179 *
180 * @param array $pageData ¤¹¤Ù¤Æ¤Î¥Ú¡¼¥¸¾ðÊó¤ÎÇÛÎó
181 * @return ÊÔ½¸²Äǽ¥Ú¡¼¥¸
182 */
183function getEditablePage($pageData) {
184    $arrRet = array();
185    $i = 0;
186    foreach($pageData as $page) {
187        if ($page['page_id'] > 4) {
188            $arrRet[$i] = $page;
189            $i++;
190        }
191    }
192    return $arrRet;
193}
194
195/**
196 * date·Á¼°¤Îʸ»úÎó¤ò W3C Datetime ·Á¼°¤ËÊÑ´¹¤·¤Æ½ÐÎϤ¹¤ë.
197 *
198 * @param date $date ÊÑ´¹¤¹¤ëÆüÉÕ
199 */
200function date2W3CDatetime($date) {
201    $arr = array();
202    // Àµµ¬É½¸½¤Çʸ»úÎó¤òÃê½Ð
203    ereg("^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})",
204        $date, $arr);
205    // :TODO: time zone ¤â¼èÆÀ¤¹¤ë¤Ù¤­...
206    return sprintf("%04d-%02d-%02dT%02d:%02d:%02d+09:00",
207            $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6]);
208}
209
210// ----------------------------------------------------------------------------
211// }}}
212// {{{ DB Access Objects
213
214/**
215 * ¥Ú¡¼¥¸¥Ç¡¼¥¿¤ò°·¤¦¥¯¥é¥¹.
216 */
217class LC_PageLayout {
218
219    var $arrPageData;       // ¥Ú¡¼¥¸¥Ç¡¼¥¿³ÊǼÍÑ
220    var $arrPageList;       // ¥Ú¡¼¥¸¥Ç¡¼¥¿³ÊǼÍÑ
221
222    /**
223     * ¥³¥ó¥¹¥È¥é¥¯¥¿.
224     */
225    function LC_PageLayout() {
226        $this->arrPageList = $this->getPageData();
227    }
228
229    /**
230     * ¥Ö¥í¥Ã¥¯¾ðÊó¤ò¼èÆÀ¤¹¤ë.
231     *
232     * @param string $where WHERE¶ç
233     * @param array  $arrVal WHERE¶ç¤ÎÃͤò³ÊǼ¤·¤¿ÇÛÎó
234     * @return ¥Ö¥í¥Ã¥¯¾ðÊó
235     */
236    function getPageData($where = '', $arrVal = ''){
237        $objDBConn = new SC_DbConn;
238        $sql = "";
239        $arrRet = array();
240
241        // SQLÀ¸À®(url ¤È update_date °Ê³°¤ÏÉÔÍס©)
242        $sql .= " SELECT";
243        $sql .= " page_id";      // ¥Ú¡¼¥¸ID
244        $sql .= " ,page_name";   // ̾¾Î
245        $sql .= " ,url";         // URL
246        $sql .= " ,php_dir";     // phpÊݸÀè¥Ç¥£¥ì¥¯¥È¥ê
247        $sql .= " ,tpl_dir";     // tplÊݸÀè¥Ç¥£d¥ì¥¯¥È¥ê
248        $sql .= " ,filename";    // ¥Õ¥¡¥¤¥ë̾¾Î
249        $sql .= " ,header_chk "; // ¥Ø¥Ã¥À¡¼»ÈÍÑFLG
250        $sql .= " ,footer_chk "; // ¥Õ¥Ã¥¿¡¼»ÈÍÑFLG
251        $sql .= " ,author";      // author¥¿¥°
252        $sql .= " ,description"; // description¥¿¥°
253        $sql .= " ,keyword";     // keyword¥¿¥°
254        $sql .= " ,update_url";  // ¹¹¿·URL
255        $sql .= " ,create_date"; // ¥Ç¡¼¥¿ºîÀ®Æü
256        $sql .= " ,update_date"; // ¥Ç¡¼¥¿¹¹¿·Æü
257        $sql .= " FROM ";
258        $sql .= " dtb_pagelayout";
259
260        // where¶ç¤Î»ØÄ꤬¤¢¤ì¤ÐÄɲÃ
261        if ($where != '') {
262            $sql .= " WHERE " . $where;
263        }
264
265        $sql .= " ORDER BY page_id";
266
267        $arrRet = $objDBConn->getAll($sql, $arrVal);
268
269        $this->arrPageData = $arrRet;
270
271        return $arrRet;
272    }
273}
274
275/**
276 * ¤¹¤Ù¤Æ¤Î¾¦ÉʰìÍ÷¥Ú¡¼¥¸¤ò¼èÆÀ¤¹¤ë.
277 *
278 * @param boolean $isMobile ¥â¥Ð¥¤¥ë¥Ú¡¼¥¸¤ò¼èÆÀ¤¹¤ë¾ì¹ç true
279 * @return ¸¡º÷¥¨¥ó¥¸¥ó¤«¤é¥¢¥¯¥»¥¹²Äǽ¤Ê¾¦ÉʰìÍ÷¥Ú¡¼¥¸¤Î¾ðÊó
280 */
281function getAllProducts() {
282    $conn = new SC_DBConn();
283    $sql = "SELECT category_id, category_name FROM dtb_category WHERE del_flg = 0";
284    $result = $conn->getAll($sql);
285
286    $arrRet = array();
287    for ($i = 0; $i < count($result); $i++) {
288        // :TODO: ¥«¥Æ¥´¥ê¤ÎºÇ½ª¹¹¿·Æü¤ò¼èÆÀ¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë
289        $page = array("title" => $result[$i]['category_name'], "url" => SITE_URL . sprintf("products/list.php?category_id=%d", $result[$i]['category_id']));
290        $arrRet[$i] = $page;
291    }
292    return $arrRet;
293}
294
295/**
296 * ¤¹¤Ù¤Æ¤Î¾¦Éʾܺ٥ڡ¼¥¸¤ò¼èÆÀ¤¹¤ë.
297 *
298 * @param boolean $isMobile ¥â¥Ð¥¤¥ë¥Ú¡¼¥¸¤ò¼èÆÀ¤¹¤ë¾ì¹ç true
299 * @return ¸¡º÷¥¨¥ó¥¸¥ó¤«¤é¥¢¥¯¥»¥¹²Äǽ¤Ê¾¦Éʾܺ٥ڡ¼¥¸¤Î¾ðÊó
300 */
301function getAllDetail() {
302    $conn = new SC_DBConn();
303    $sql = "SELECT product_id, name, comment3, main_comment, main_list_comment, ".
304           "main_image, main_large_image, update_date FROM dtb_products ".
305           "WHERE del_flg = 0 AND status = 1";
306    $result = $conn->getAll($sql);
307
308    $arrRet = array();
309    for ($i = 0; $i < count($result); $i++) {
310        (file_exists(IMAGE_SAVE_DIR . $result[$i]["main_image"])) ? $dir = IMAGE_SAVE_URL_RSS : $dir = IMAGE_TEMP_URL_RSS;
311        $image = $dir . $result[$i]["main_image"];
312        (file_exists(IMAGE_SAVE_DIR . $result[$i]["main_large_image"])) ? $dir = IMAGE_SAVE_URL_RSS : $dir = IMAGE_TEMP_URL_RSS;
313        $imageLarge = $dir . $result[$i]["main_large_image"];
314
315        $page = array(
316            "title"       => $result[$i]['name'],
317            "desc"        => $result[$i]['main_list_comment'],
318            "descLong"    => $result[$i]['main_comment'],
319            "keywords"    => $result[$i]['comment3'],
320            "url"         => SITE_URL. sprintf("products/detail.php?product_id=%d", $result[$i]['product_id']),
321            "update_date" => $result[$i]['update_date'],
322            "image"       => $image,
323            "imageLarge"  => $imageLarge
324        );
325        $arrRet[$i] = $page;
326    }
327    return $arrRet;
328}
329?>
Note: See TracBrowser for help on using the repository browser.