source: branches/dev/html/tb/index.php @ 11981

Revision 11981, 6.9 KB checked in by inoue, 15 years ago (diff)

トラックバックRSS

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