source: branches/feature-module-update/html/tb/index.php @ 15079

Revision 15079, 7.3 KB checked in by nanasess, 17 years ago (diff)

svn:mime-type application/x-httpd-php; charset=UTF-8 設定

  • Property svn:mime-type set to application/x-httpd-php; charset=UTF-8
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    // データの登録
189    $table = "dtb_trackback";
190    $ret = $objQuery->insert($table, $arrData);
191    return $ret;
192}
193
194/*
195 * スパムフィルター
196 *
197 * @param $arrData トラックバックデータ
198 * @param $run フィルターフラグ(true:使用する false:使用しない)
199 * @return $ret 結果
200 */
201function lfSpamFilter($arrData, $run = false) {
202    $ret = true;
203   
204    // フィルター処理
205    if ($run) {
206    }
207    return $ret;
208}
209
210/*
211 * OKレスポンスを返す
212 *
213 * @param void なし
214 * @return void なし
215 */
216function IfResponseOk() {
217    header("Content-type: text/xml");
218    print("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
219    print("<response>");
220    print("<error>0</error>");
221    print("</response>");
222    exit();
223}
224
225/*
226 * NGレスポンスを返す
227 *
228 * @param void なし
229 * @return void なし
230 */
231function IfResponseNg() {
232    header("Content-type: text/xml");
233    print("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
234    print("<response>");
235    print("<error>1</error>");
236    print("<message>The error message</message>");
237    print("</response>");
238    exit();
239}
240
241/*
242 * トラックバックRSSを返す
243 *
244 * @param $product_id 商品コード
245 * @return void なし
246 */
247function IfResponseRss($product_id) {
248    global $objQuery;
249   
250    $retProduct = $objQuery->select("*", "dtb_products", "product_id = ?", array($product_id));
251   
252    if (count($retProduct) > 0) {
253        header("Content-type: text/xml");
254        print("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
255        print("<response>");
256        print("<error>0</error>");
257        print("<rss version=\"0.91\">");
258        print("<channel>");
259        print("<title>" . $retProduct[0]["name"] . "</title>");
260        print("<link>");
261        print(SITE_URL . "products/detail.php?product_id=" . $product_id);
262        print("</link>");
263        print("<description>");
264        print($retProduct[0]["main_comment"]);
265        print("</description>");
266        print("<language>ja-jp</language>");
267        print("</channel>");
268        print("</rss>");
269        print("</response>");
270        exit();
271    }
272}
273
274//-----------------------------------------------------------------------------------------------------------------------------------
275?>
Note: See TracBrowser for help on using the repository browser.