source: branches/version-2_5-dev/data/class/pages/tb/LC_Page_TrackBack.php @ 19943

Revision 19943, 10.4 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある)

  • パラメータサフィックスの変更 *_URL_PATH → *_URLPATH
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Date Revision
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once(CLASS_REALDIR . "pages/LC_Page.php");
26
27/**
28 * トラックバック のページクラス.
29 *
30 * [1]なるべく多くのブログに対応できるように、GET/POST に関わらず受信する
31 * [2]RSSの要求はGETで__modeパラメータがrssの場合のみ対応する(商品情報を返す)
32 * [3]文字コードは指定がなければautoで対応する
33 * [4]スパムは、オリジナル(好み)のアルゴリズムで対応できるようにしておく
34 *
35 * @package Page
36 * @author LOCKON CO.,LTD.
37 * @version $Id$
38 */
39class LC_Page_TrackBack extends LC_Page {
40
41    // }}}
42    // {{{ functions
43
44    /**
45     * Page を初期化する.
46     *
47     * @return void
48     */
49    function init() {
50        parent::init();
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
59        // トラックバック機能の稼働状況チェック
60        if (SC_Utils_Ex::sfGetSiteControlFlg(SITE_CONTROL_TRACKBACK) != 1) {
61            // NG
62            $this->IfResponseNg();
63            exit();
64        }
65
66        $objQuery = new SC_Query();
67        $objFormParam = new SC_FormParam();
68
69
70        // パラメータ情報の初期化
71        $this->lfInitParam($objFormParam);
72
73        // エンコード設定(サーバ環境によって変更)
74        $beforeEncode = "auto";
75        $afterEncode = mb_internal_encoding();
76
77        if (isset($_POST["charset"])) {
78            $beforeEncode = $_POST["charset"];
79        } else if (isset($_GET["charset"])) {
80            $beforeEncode = $_GET["charset"];
81        }
82
83        // POSTデータの取得とエンコード変換
84
85        // ブログ名
86        if (isset($_POST["blog_name"])) {
87            $arrData["blog_name"] = trim(mb_convert_encoding($_POST["blog_name"], $afterEncode, $beforeEncode));
88        } else if (isset($_GET["blog_name"])) {
89            $arrData["blog_name"] = trim(mb_convert_encoding($_GET["blog_name"], $afterEncode, $beforeEncode));
90        }
91
92        // ブログ記事URL
93        if (isset($_POST["url"])) {
94            $arrData["url"] = trim(mb_convert_encoding($_POST["url"], $afterEncode, $beforeEncode));
95        } else if (isset($_GET["url"])) {
96            $arrData["url"] = trim(mb_convert_encoding($_GET["url"], $afterEncode, $beforeEncode));
97        } else {
98            /*
99             * RSS目的ではないGETリクエストを制御(livedoor blog)
100             * _rssパラメータでのGETリクエストを制御(Yahoo blog)
101             */
102            if (isset($_GET["__mode"]) && isset($_GET["pid"])) {
103                if ($_GET["__mode"] == "rss") {
104                    $this->IfResponseRss($_GET["pid"]);
105                }
106            }
107            exit();
108        }
109
110        // ブログ記事タイトル
111        if (isset($_POST["title"])) {
112            $arrData["title"] = trim(mb_convert_encoding($_POST["title"], $afterEncode, $beforeEncode));
113        } else if (isset($_GET["title"])) {
114            $arrData["title"] = trim(mb_convert_encoding($_GET["title"], $afterEncode, $beforeEncode));
115        }
116
117        // ブログ記事内容
118        if (isset($_POST["excerpt"])) {
119            $arrData["excerpt"] = trim(mb_convert_encoding($_POST["excerpt"], $afterEncode, $beforeEncode));
120        } else if (isset($_GET["excerpt"])) {
121            $arrData["excerpt"] = trim(mb_convert_encoding($_GET["excerpt"], $afterEncode, $beforeEncode));
122        }
123
124        $log_path = DATA_REALDIR . "logs/tb_result.log";
125        GC_Utils_Ex::gfPrintLog("request data start -----", $log_path);
126        foreach($arrData as $key => $val) {
127            GC_Utils_Ex::gfPrintLog( "\t" . $key . " => " . $val, $log_path);
128        }
129        GC_Utils_Ex::gfPrintLog("request data end   -----", $log_path);
130
131        $objFormParam->setParam($arrData);
132
133        // 入力文字の変換
134        $objFormParam->convParam();
135        $arrData = $objFormParam->getHashArray();
136
137        // エラーチェック(トラックバックが成り立たないので、URL以外も必須とする)
138        $this->arrErr = $this->lfCheckError($objFormParam);
139
140        // エラーがない場合はデータを更新
141        if(count($this->arrErr) == 0) {
142
143            // 商品コードの取得(GET)
144            if (isset($_GET["pid"])) {
145                $product_id = $_GET["pid"];
146
147                // 商品データの存在確認
148                $table = "dtb_products";
149                $where = "product_id = ?";
150
151                $objDb = new SC_Helper_DB_Ex();
152                // 商品データが存在する場合はトラックバックデータの更新
153                if ($objDb->sfDataExists($table, $where, array($product_id))) {
154                    $arrData["product_id"] = $product_id;
155
156                    // データの更新
157                    if ($this->lfEntryTrackBack($arrData, $objQuery) == 1) {
158                        $this->IfResponseOk();
159                    }
160                } else {
161                    GC_Utils_Ex::gfPrintLog("--- PRODUCT NOT EXISTS : " . $product_id, $log_path);
162                }
163            }
164        }
165        foreach($this->arrErr as $key => $val) {
166            GC_Utils_Ex::gfPrintLog( "\t" . $key . " => " . $val, $log_path);
167        }
168        // NG
169        $this->IfResponseNg();
170        exit();
171    }
172
173    /**
174     * デストラクタ.
175     *
176     * @return void
177     */
178    function destroy() {
179        parent::destroy();
180    }
181
182    /*
183     * パラメータ情報の初期化
184     *
185     * @param void なし
186     * @return void なし
187     */
188    function lfInitParam(&$objFormParam) {
189
190        $objFormParam->addParam("URL", "url", URL_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
191        $objFormParam->addParam("ブログタイトル", "blog_name", MTEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
192        $objFormParam->addParam("記事タイトル", "title", MTEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
193        $objFormParam->addParam("記事内容", "excerpt", MLTEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
194    }
195
196    /*
197     * 入力内容のチェック
198     *
199     * @param void なし
200     * @return $objErr->arrErr エラーメッセージ
201     */
202    function lfCheckError(&$objFormParam) {
203
204        // 入力データを渡す。
205        $arrRet =  $objFormParam->getHashArray();
206        $objErr = new SC_CheckError($arrRet);
207        $objErr->arrErr = $objFormParam->checkError();
208
209        return $objErr->arrErr;
210    }
211
212    /*
213     * 更新処理
214     *
215     * @param $arrData トラックバックデータ
216     * @return $ret 結果
217     */
218    function lfEntryTrackBack($arrData, &$objQuery) {
219
220        // ログ
221        $log_path = DATA_REALDIR . "logs/tb_result.log";
222
223        // スパムフィルター
224        if ($this->lfSpamFilter($arrData)) {
225            $arrData["status"] = TRACKBACK_STATUS_NOT_VIEW;
226        } else {
227            $arrData["status"] = TRACKBACK_STATUS_SPAM;
228        }
229
230        $arrData["create_date"] = "now()";
231        $arrData["update_date"] = "now()";
232
233        if(!isset($arrData['url'])){
234            $arrData['url'] = '';
235        }elseif(!isset($arrData['excerpt'])){
236            $arrData['excerpt'] = '';
237        }
238        // データの登録
239        $table = "dtb_trackback";
240        $arrData['trackback_id'] = $objQuery->nextVal('dtb_trackback_trackback_id');
241        $ret = $objQuery->insert($table, $arrData);
242        return $ret;
243    }
244
245    /*
246     * スパムフィルター
247     *
248     * @param $arrData トラックバックデータ
249     * @param $run フィルターフラグ(true:使用する false:使用しない)
250     * @return $ret 結果
251     */
252    function lfSpamFilter($arrData, $run = false) {
253        $ret = true;
254
255        // フィルター処理
256        if ($run) {
257        }
258        return $ret;
259    }
260
261    /*
262     * OKレスポンスを返す
263     *
264     * @param void なし
265     * @return void なし
266     */
267    function IfResponseOk() {
268        header("Content-type: text/xml");
269        print("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
270        print("<response>");
271        print("<error>0</error>");
272        print("</response>");
273        exit();
274    }
275
276    /*
277     * NGレスポンスを返す
278     *
279     * @param void なし
280     * @return void なし
281     */
282    function IfResponseNg() {
283        header("Content-type: text/xml");
284        print("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
285        print("<response>");
286        print("<error>1</error>");
287        print("<message>The error message</message>");
288        print("</response>");
289        exit();
290    }
291
292    /*
293     * トラックバックRSSを返す
294     *
295     * @param $product_id 商品コード
296     * @return void なし
297     */
298    function IfResponseRss($product_id, &$objQuery) {
299
300        $retProduct = $objQuery->select("*", "dtb_products", "product_id = ?", array($product_id));
301
302        if (count($retProduct) > 0) {
303            header("Content-type: text/xml");
304            print("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
305            print("<response>");
306            print("<error>0</error>");
307            print("<rss version=\"0.91\">");
308            print("<channel>");
309            print("<title>" . $retProduct[0]["name"] . "</title>");
310            print("<link>");
311            print(HTTP_URL . substr(P_DETAIL_URLPATH, strlen(URL_PATH)) . $product_id);
312            print("</link>");
313            print("<description>");
314            print($retProduct[0]["main_comment"]);
315            print("</description>");
316            print("<language>ja-jp</language>");
317            print("</channel>");
318            print("</rss>");
319            print("</response>");
320            exit();
321        }
322    }
323}
324?>
Note: See TracBrowser for help on using the repository browser.