source: branches/beta/html/tb/index.php @ 14676

Revision 14676, 7.0 KB checked in by adati, 16 years ago (diff)

1.4.0a-betaのマージ

Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8/*
9 * ¥È¥é¥Ã¥¯¥Ð¥Ã¥¯¼õ¿®
10 *
11 * [1]¤Ê¤ë¤Ù¤¯Â¿¤¯¤Î¥Ö¥í¥°¤ËÂбþ¤Ç¤­¤ë¤è¤¦¤Ë¡¢GET/POST ¤Ë´Ø¤ï¤é¤º¼õ¿®¤¹¤ë
12 * [2]RSS¤ÎÍ×µá¤ÏGET¤Ç__mode¥Ñ¥é¥á¡¼¥¿¤¬rss¤Î¾ì¹ç¤Î¤ßÂбþ¤¹¤ë(¾¦ÉʾðÊó¤òÊÖ¤¹)
13 * [3]ʸ»ú¥³¡¼¥É¤Ï»ØÄ꤬¤Ê¤±¤ì¤Ðauto¤ÇÂбþ¤¹¤ë
14 * [4]¥¹¥Ñ¥à¤Ï¡¢¥ª¥ê¥¸¥Ê¥ë(¹¥¤ß)¤Î¥¢¥ë¥´¥ê¥º¥à¤ÇÂбþ¤Ç¤­¤ë¤è¤¦¤Ë¤·¤Æ¤ª¤¯
15 */
16
17require_once("../require.php");
18
19$objQuery = new SC_Query();
20$objFormParam = new SC_FormParam();
21
22// ¥È¥é¥Ã¥¯¥Ð¥Ã¥¯µ¡Ç½¤Î²ÔƯ¾õ¶·¥Á¥§¥Ã¥¯
23if (sfGetSiteControlFlg(SITE_CONTROL_TRACKBACK) != 1) {
24    // NG
25    IfResponseNg();
26    exit();
27}
28
29// ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½
30lfInitParam();
31
32// ¥¨¥ó¥³¡¼¥ÉÀßÄê(¥µ¡¼¥Ð´Ä¶­¤Ë¤è¤Ã¤ÆÊѹ¹)
33$beforeEncode = "auto";
34$afterEncode = mb_internal_encoding();
35
36if (isset($_POST["charset"])) {
37    $beforeEncode = $_POST["charset"];
38} else if (isset($_GET["charset"])) {
39    $beforeEncode = $_GET["charset"];
40}
41
42// POST¥Ç¡¼¥¿¤Î¼èÆÀ¤È¥¨¥ó¥³¡¼¥ÉÊÑ´¹
43
44// ¥Ö¥í¥°Ì¾
45if (isset($_POST["blog_name"])) {
46    $arrData["blog_name"] = trim(mb_convert_encoding($_POST["blog_name"], $afterEncode, $beforeEncode));
47} else if (isset($_GET["blog_name"])) {
48    $arrData["blog_name"] = trim(mb_convert_encoding($_GET["blog_name"], $afterEncode, $beforeEncode));
49}
50
51// ¥Ö¥í¥°µ­»öURL
52if (isset($_POST["url"])) {
53    $arrData["url"] = trim(mb_convert_encoding($_POST["url"], $afterEncode, $beforeEncode));
54} else if (isset($_GET["url"])) {
55    $arrData["url"] = trim(mb_convert_encoding($_GET["url"], $afterEncode, $beforeEncode));
56} else {
57    /*
58     * RSSÌÜŪ¤Ç¤Ï¤Ê¤¤GET¥ê¥¯¥¨¥¹¥È¤òÀ©¸æ(livedoor blog)
59     * _rss¥Ñ¥é¥á¡¼¥¿¤Ç¤ÎGET¥ê¥¯¥¨¥¹¥È¤òÀ©¸æ(Yahoo blog)
60     */
61    if (isset($_GET["__mode"]) && isset($_GET["pid"])) {
62        if ($_GET["__mode"] == "rss") {
63            IfResponseRss($_GET["pid"]);
64        }
65    }
66    exit();
67}
68
69// ¥Ö¥í¥°µ­»ö¥¿¥¤¥È¥ë
70if (isset($_POST["title"])) {
71    $arrData["title"] = trim(mb_convert_encoding($_POST["title"], $afterEncode, $beforeEncode));
72} else if (isset($_GET["title"])) {
73    $arrData["title"] = trim(mb_convert_encoding($_GET["title"], $afterEncode, $beforeEncode));
74}
75
76// ¥Ö¥í¥°µ­»öÆâÍÆ
77if (isset($_POST["excerpt"])) {
78    $arrData["excerpt"] = trim(mb_convert_encoding($_POST["excerpt"], $afterEncode, $beforeEncode));
79} else if (isset($_GET["excerpt"])) {
80    $arrData["excerpt"] = trim(mb_convert_encoding($_GET["excerpt"], $afterEncode, $beforeEncode));
81}
82
83$log_path = DATA_PATH . "logs/tb_result.log";
84gfPrintLog("request data start -----", $log_path);
85foreach($arrData as $key => $val) {
86    gfPrintLog( "\t" . $key . " => " . $val, $log_path);
87}
88gfPrintLog("request data end   -----", $log_path);
89
90$objFormParam->setParam($arrData);
91
92// ÆþÎÏʸ»ú¤ÎÊÑ´¹
93$objFormParam->convParam();
94$arrData = $objFormParam->getHashArray();
95
96// ¥¨¥é¡¼¥Á¥§¥Ã¥¯(¥È¥é¥Ã¥¯¥Ð¥Ã¥¯¤¬À®¤êΩ¤¿¤Ê¤¤¤Î¤Ç¡¢URL°Ê³°¤âɬ¿Ü¤È¤¹¤ë)
97$objPage->arrErr = lfCheckError();
98
99// ¥¨¥é¡¼¤¬¤Ê¤¤¾ì¹ç¤Ï¥Ç¡¼¥¿¤ò¹¹¿·
100if(count($objPage->arrErr) == 0) {
101   
102    // ¾¦ÉÊ¥³¡¼¥É¤Î¼èÆÀ(GET)
103    if (isset($_GET["pid"])) {
104        $product_id = $_GET["pid"];
105
106        // ¾¦Éʥǡ¼¥¿¤Î¸ºß³Îǧ
107        $table = "dtb_products";
108        $where = "product_id = ?";
109
110        // ¾¦Éʥǡ¼¥¿¤¬Â¸ºß¤¹¤ë¾ì¹ç¤Ï¥È¥é¥Ã¥¯¥Ð¥Ã¥¯¥Ç¡¼¥¿¤Î¹¹¿·
111        if (sfDataExists($table, $where, array($product_id))) {
112            $arrData["product_id"] = $product_id;
113           
114            // ¥Ç¡¼¥¿¤Î¹¹¿·
115            if (lfEntryTrackBack($arrData) == 1) {
116                IfResponseOk();
117            }
118        } else {
119            gfPrintLog("--- PRODUCT NOT EXISTS : " . $product_id, $log_path);
120        }
121    }
122}
123
124// NG
125IfResponseNg();
126exit();
127
128//----------------------------------------------------------------------------------------------------
129
130/*
131 * ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½
132 *
133 * @param void ¤Ê¤·
134 * @return void ¤Ê¤·
135 */
136function lfInitParam() {
137    global $objFormParam;
138    $objFormParam->addParam("URL", "url", URL_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
139    $objFormParam->addParam("¥Ö¥í¥°¥¿¥¤¥È¥ë", "blog_name", MTEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
140    $objFormParam->addParam("µ­»ö¥¿¥¤¥È¥ë", "title", MTEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
141    $objFormParam->addParam("µ­»öÆâÍÆ", "excerpt", MLTEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
142}
143
144/*
145 * ÆþÎÏÆâÍƤΥÁ¥§¥Ã¥¯
146 *
147 * @param void ¤Ê¤·
148 * @return $objErr->arrErr ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸
149 */
150function lfCheckError() {
151    global $objFormParam;
152   
153    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
154    $arrRet =  $objFormParam->getHashArray();
155    $objErr = new SC_CheckError($arrRet);
156    $objErr->arrErr = $objFormParam->checkError();
157   
158    return $objErr->arrErr;
159}
160
161/*
162 * ¹¹¿·½èÍý
163 *
164 * @param $arrData ¥È¥é¥Ã¥¯¥Ð¥Ã¥¯¥Ç¡¼¥¿
165 * @return $ret ·ë²Ì
166 */
167function lfEntryTrackBack($arrData) {
168    global $objQuery;
169
170    // ¥í¥°
171    $log_path = DATA_PATH . "logs/tb_result.log";
172
173    // ¥¹¥Ñ¥à¥Õ¥£¥ë¥¿¡¼
174    if (lfSpamFilter($arrData)) {
175        $arrData["status"] = TRACKBACK_STATUS_NOT_VIEW;
176    } else {
177        $arrData["status"] = TRACKBACK_STATUS_SPAM;
178    }
179
180    $arrData["create_date"] = "now()";
181    $arrData["update_date"] = "now()";
182   
183    if(!isset($arrData['url'])){
184        $arrData['url'] = '';
185    }elseif(!isset($arrData['excerpt'])){
186        $arrData['excerpt'] = '';
187    }
188    if(!isset($arrData['url'])){
189        $arrData['url'] = '';
190    }elseif(!isset($arrData['excerpt'])){
191        $arrData['excerpt'] = '';
192    }
193    // ¥Ç¡¼¥¿¤ÎÅÐÏ¿
194    $table = "dtb_trackback";
195    $ret = $objQuery->insert($table, $arrData);
196    return $ret;
197}
198
199/*
200 * ¥¹¥Ñ¥à¥Õ¥£¥ë¥¿¡¼
201 *
202 * @param $arrData ¥È¥é¥Ã¥¯¥Ð¥Ã¥¯¥Ç¡¼¥¿
203 * @param $run ¥Õ¥£¥ë¥¿¡¼¥Õ¥é¥°(true:»ÈÍѤ¹¤ë false:»ÈÍѤ·¤Ê¤¤)
204 * @return $ret ·ë²Ì
205 */
206function lfSpamFilter($arrData, $run = false) {
207    $ret = true;
208   
209    // ¥Õ¥£¥ë¥¿¡¼½èÍý
210    if ($run) {
211    }
212    return $ret;
213}
214
215/*
216 * OK¥ì¥¹¥Ý¥ó¥¹¤òÊÖ¤¹
217 *
218 * @param void ¤Ê¤·
219 * @return void ¤Ê¤·
220 */
221function IfResponseOk() {
222    header("Content-type: text/xml");
223    print("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
224    print("<response>");
225    print("<error>0</error>");
226    print("</response>");
227    exit();
228}
229
230/*
231 * NG¥ì¥¹¥Ý¥ó¥¹¤òÊÖ¤¹
232 *
233 * @param void ¤Ê¤·
234 * @return void ¤Ê¤·
235 */
236function IfResponseNg() {
237    header("Content-type: text/xml");
238    print("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
239    print("<response>");
240    print("<error>1</error>");
241    print("<message>The error message</message>");
242    print("</response>");
243    exit();
244}
245
246/*
247 * ¥È¥é¥Ã¥¯¥Ð¥Ã¥¯RSS¤òÊÖ¤¹
248 *
249 * @param $product_id ¾¦ÉÊ¥³¡¼¥É
250 * @return void ¤Ê¤·
251 */
252function IfResponseRss($product_id) {
253    global $objQuery;
254   
255    $retProduct = $objQuery->select("*", "dtb_products", "product_id = ?", array($product_id));
256   
257    if (count($retProduct) > 0) {
258        header("Content-type: text/xml");
259        print("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
260        print("<response>");
261        print("<error>0</error>");
262        print("<rss version=\"0.91\">");
263        print("<channel>");
264        print("<title>" . $retProduct[0]["name"] . "</title>");
265        print("<link>");
266        print(SITE_URL . "products/detail.php?product_id=" . $product_id);
267        print("</link>");
268        print("<description>");
269        print($retProduct[0]["main_comment"]);
270        print("</description>");
271        print("<language>ja-jp</language>");
272        print("</channel>");
273        print("</rss>");
274        print("</response>");
275        exit();
276    }
277}
278
279//-----------------------------------------------------------------------------------------------------------------------------------
280?>
Note: See TracBrowser for help on using the repository browser.