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 |
---|
25 | require_once(CLASS_PATH . "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 | */ |
---|
39 | class 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_PATH . "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_PATH . "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 | $ret = $objQuery->insert($table, $arrData); |
---|
241 | return $ret; |
---|
242 | } |
---|
243 | |
---|
244 | /* |
---|
245 | * スパムフィルター |
---|
246 | * |
---|
247 | * @param $arrData トラックバックデータ |
---|
248 | * @param $run フィルターフラグ(true:使用する false:使用しない) |
---|
249 | * @return $ret 結果 |
---|
250 | */ |
---|
251 | function lfSpamFilter($arrData, $run = false) { |
---|
252 | $ret = true; |
---|
253 | |
---|
254 | // フィルター処理 |
---|
255 | if ($run) { |
---|
256 | } |
---|
257 | return $ret; |
---|
258 | } |
---|
259 | |
---|
260 | /* |
---|
261 | * OKレスポンスを返す |
---|
262 | * |
---|
263 | * @param void なし |
---|
264 | * @return void なし |
---|
265 | */ |
---|
266 | function IfResponseOk() { |
---|
267 | header("Content-type: text/xml"); |
---|
268 | print("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"); |
---|
269 | print("<response>"); |
---|
270 | print("<error>0</error>"); |
---|
271 | print("</response>"); |
---|
272 | exit(); |
---|
273 | } |
---|
274 | |
---|
275 | /* |
---|
276 | * NGレスポンスを返す |
---|
277 | * |
---|
278 | * @param void なし |
---|
279 | * @return void なし |
---|
280 | */ |
---|
281 | function IfResponseNg() { |
---|
282 | header("Content-type: text/xml"); |
---|
283 | print("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"); |
---|
284 | print("<response>"); |
---|
285 | print("<error>1</error>"); |
---|
286 | print("<message>The error message</message>"); |
---|
287 | print("</response>"); |
---|
288 | exit(); |
---|
289 | } |
---|
290 | |
---|
291 | /* |
---|
292 | * トラックバックRSSを返す |
---|
293 | * |
---|
294 | * @param $product_id 商品コード |
---|
295 | * @return void なし |
---|
296 | */ |
---|
297 | function IfResponseRss($product_id, &$objQuery) { |
---|
298 | |
---|
299 | $retProduct = $objQuery->select("*", "dtb_products", "product_id = ?", array($product_id)); |
---|
300 | |
---|
301 | if (count($retProduct) > 0) { |
---|
302 | header("Content-type: text/xml"); |
---|
303 | print("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"); |
---|
304 | print("<response>"); |
---|
305 | print("<error>0</error>"); |
---|
306 | print("<rss version=\"0.91\">"); |
---|
307 | print("<channel>"); |
---|
308 | print("<title>" . $retProduct[0]["name"] . "</title>"); |
---|
309 | print("<link>"); |
---|
310 | print(SITE_URL . "products/detail.php?product_id=" . $product_id); |
---|
311 | print("</link>"); |
---|
312 | print("<description>"); |
---|
313 | print($retProduct[0]["main_comment"]); |
---|
314 | print("</description>"); |
---|
315 | print("<language>ja-jp</language>"); |
---|
316 | print("</channel>"); |
---|
317 | print("</rss>"); |
---|
318 | print("</response>"); |
---|
319 | exit(); |
---|
320 | } |
---|
321 | } |
---|
322 | } |
---|
323 | ?> |
---|