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