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

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

r15064 から svn cp
とりあえず暫定コミット.

  • UTF-8 に変更
  • slib.php, glib.php のクラス化
  • LC_Page の抽象化(一部)
RevLine 
[12157]1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8/*
[15078]9 * トラックバック受信
[12157]10 *
[15078]11 * [1]なるべく多くのブログに対応できるように、GET/POST に関わらず受信する
12 * [2]RSSの要求はGETで__modeパラメータがrssの場合のみ対応する(商品情報を返す)
13 * [3]文字コードは指定がなければautoで対応する
14 * [4]スパムは、オリジナル(好み)のアルゴリズムで対応できるようにしておく
[12157]15 */
16
17require_once("../require.php");
18
19$objQuery = new SC_Query();
20$objFormParam = new SC_FormParam();
21
[15078]22// トラックバック機能の稼働状況チェック
[12157]23if (sfGetSiteControlFlg(SITE_CONTROL_TRACKBACK) != 1) {
24    // NG
25    IfResponseNg();
26    exit();
27}
28
[15078]29// パラメータ情報の初期化
[12157]30lfInitParam();
31
[15078]32// エンコード設定(サーバ環境によって変更)
[12157]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
[15078]42// POSTデータの取得とエンコード変換
[12157]43
[15078]44// ブログ名
[12157]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
[15078]51// ブログ記事URL
[12157]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    /*
[15078]58     * RSS目的ではないGETリクエストを制御(livedoor blog)
59     * _rssパラメータでのGETリクエストを制御(Yahoo blog)
[12157]60     */
61    if (isset($_GET["__mode"]) && isset($_GET["pid"])) {
62        if ($_GET["__mode"] == "rss") {
63            IfResponseRss($_GET["pid"]);
64        }
65    }
66    exit();
67}
68
[15078]69// ブログ記事タイトル
[12157]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
[15078]76// ブログ記事内容
[12157]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
[15078]92// 入力文字の変換
[12157]93$objFormParam->convParam();
94$arrData = $objFormParam->getHashArray();
95
[15078]96// エラーチェック(トラックバックが成り立たないので、URL以外も必須とする)
[12157]97$objPage->arrErr = lfCheckError();
98
[15078]99// エラーがない場合はデータを更新
[12157]100if(count($objPage->arrErr) == 0) {
101   
[15078]102    // 商品コードの取得(GET)
[12157]103    if (isset($_GET["pid"])) {
104        $product_id = $_GET["pid"];
105
[15078]106        // 商品データの存在確認
[12157]107        $table = "dtb_products";
108        $where = "product_id = ?";
109
[15078]110        // 商品データが存在する場合はトラックバックデータの更新
[12157]111        if (sfDataExists($table, $where, array($product_id))) {
112            $arrData["product_id"] = $product_id;
113           
[15078]114            // データの更新
[12157]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/*
[15078]131 * パラメータ情報の初期化
[12157]132 *
[15078]133 * @param void なし
134 * @return void なし
[12157]135 */
136function lfInitParam() {
137    global $objFormParam;
138    $objFormParam->addParam("URL", "url", URL_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
[15078]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"));
[12157]142}
143
144/*
[15078]145 * 入力内容のチェック
[12157]146 *
[15078]147 * @param void なし
148 * @return $objErr->arrErr エラーメッセージ
[12157]149 */
150function lfCheckError() {
151    global $objFormParam;
152   
[15078]153    // 入力データを渡す。
[12157]154    $arrRet =  $objFormParam->getHashArray();
155    $objErr = new SC_CheckError($arrRet);
156    $objErr->arrErr = $objFormParam->checkError();
157   
158    return $objErr->arrErr;
159}
160
161/*
[15078]162 * 更新処理
[12157]163 *
[15078]164 * @param $arrData トラックバックデータ
165 * @return $ret 結果
[12157]166 */
167function lfEntryTrackBack($arrData) {
168    global $objQuery;
169
[15078]170    // ログ
[12157]171    $log_path = DATA_PATH . "logs/tb_result.log";
172
[15078]173    // スパムフィルター
[12157]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
[14327]183    if(!isset($arrData['url'])){
184        $arrData['url'] = '';
185    }elseif(!isset($arrData['excerpt'])){
186        $arrData['excerpt'] = '';
187    }
[15078]188    // データの登録
[12157]189    $table = "dtb_trackback";
190    $ret = $objQuery->insert($table, $arrData);
191    return $ret;
192}
193
194/*
[15078]195 * スパムフィルター
[12157]196 *
[15078]197 * @param $arrData トラックバックデータ
198 * @param $run フィルターフラグ(true:使用する false:使用しない)
199 * @return $ret 結果
[12157]200 */
201function lfSpamFilter($arrData, $run = false) {
202    $ret = true;
203   
[15078]204    // フィルター処理
[12157]205    if ($run) {
206    }
207    return $ret;
208}
209
210/*
[15078]211 * OKレスポンスを返す
[12157]212 *
[15078]213 * @param void なし
214 * @return void なし
[12157]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/*
[15078]226 * NGレスポンスを返す
[12157]227 *
[15078]228 * @param void なし
229 * @return void なし
[12157]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/*
[15078]242 * トラックバックRSSを返す
[12157]243 *
[15078]244 * @param $product_id 商品コード
245 * @return void なし
[12157]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.