Skip to content

Commit

Permalink
expack:
Browse files Browse the repository at this point in the history
- リファクタリングを実行。
-- conf/conf.inc.php の処理の一部を lib/bootstrap.php に移動。
-- conf/conf.inc.php でロードされているクラスファイルを
   別の箇所でもロードしていたのを削除。
- 書き込みCookieの保存などにP2KeyValueStoreを使うようにした。
-- TODO: P2KeyValueStoreを直接使っている箇所をクラスに切り出す。
- 板ごとに「Beで書き込む」「公式p2で書き込む」を記憶するようにした。
- host,bbs,key,lsにHTMLの特殊文字が含まれていないか
  常にチェックするようにした。
- Login::$_user_u を使うべき箇所で Login::$_user を使っていたのを修正。
- iPhone用スタイルシートのtypoを修正。


git-svn-id: http://svn.sourceforge.jp/svnroot/p2-php/p2ex/trunk@767 a8256b1f-a225-0410-95af-91ab0afbf006
  • Loading branch information
rsk committed Jan 9, 2010
1 parent f3d98c8 commit b06af88
Show file tree
Hide file tree
Showing 42 changed files with 1,238 additions and 1,128 deletions.
1,135 changes: 227 additions & 908 deletions conf/conf.inc.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion conf/conf_admin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
// ----------------------------------------------------------------------
// {{{ 拡張パック

require_once P2_CONF_DIR . '/conf_admin_ex.inc.php';
include P2_CONF_DIR . '/conf_admin_ex.inc.php';

// }}}

Expand Down
4 changes: 3 additions & 1 deletion conf/ip_emobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
* @link http://whois.nic.ad.jp/cgi-bin/whois_gw
*/

$host = '/\\.pool\\.e(?:mnet|-?mobile)\\.ne\\.jp$/';
$host = '/\\.pool\\.e(?:mnet|-mobile)\\.ne\\.jp$/';

$band = array(
'60.254.192.0/18', // JPNIC Whois Gateway
'114.48.0.0/14', // JPNIC Whois Gateway
'117.55.0.0/17', // JPNIC Whois Gateway
//'117.55.1.224/27', // http://developer.emnet.ne.jp/ipaddress.html
'119.72.0.0/16', // JPNIC Whois Gateway
);

/*
Expand Down
2 changes: 1 addition & 1 deletion css/iphone.css
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ div.res:not(.aborned) {
div.res.aborned {
margin: 0;
padding: 0;
fonr-size: xx-small;
font-size: xx-small;
line-height: 100%;
}

Expand Down
1 change: 0 additions & 1 deletion edit_user_font.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
$current_fontconfig = array('enabled' => false, 'custom' => array());
}
} else {
require_once P2_LIB_DIR . '/FileCtl.php';
FileCtl::make_datafile($_conf['expack.skin.fontconfig_path'], $_conf['expack.skin.fontconfig_perm']);
$current_fontconfig = array('enabled' => false, 'custom' => array());
}
Expand Down
1 change: 0 additions & 1 deletion info_js.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

require_once './conf/conf.inc.php';
require_once P2_LIB_DIR . '/P2Util.php';
require_once P2_LIB_DIR . '/Thread.php';

$_login->authorize(); // ユーザ認証
Expand Down
2 changes: 0 additions & 2 deletions lib/BbsMap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
require_once P2_LIB_DIR . '/P2Util.php';
require_once P2_LIB_DIR . '/FileCtl.php';

// {{{ BbsMap

Expand Down
1 change: 0 additions & 1 deletion lib/BrdCtl.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

require_once P2_LIB_DIR . '/FileCtl.php';
require_once P2_LIB_DIR . '/BrdMenu.php';

// {{{ BrdCtl
Expand Down
2 changes: 0 additions & 2 deletions lib/BrdMenu.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

require_once P2_LIB_DIR . '/FileCtl.php';

// {{{ BrdMenu

/**
Expand Down
1 change: 0 additions & 1 deletion lib/HostCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// アクセス元ホストをチェックする関数群クラス

require_once P2_CONF_DIR . '/conf_hostcheck.php';
require_once P2_LIB_DIR . '/FileCtl.php';
require_once P2_LIB_DIR . '/P2KeyValueStore.php';

// {{{ HostCheck
Expand Down
1 change: 0 additions & 1 deletion lib/Login.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

require_once P2_LIB_DIR . '/FileCtl.php';
require_once P2_LIB_DIR . '/Session.php';

// {{{ Login
Expand Down
99 changes: 66 additions & 33 deletions lib/P2Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class P2Client
/**
* Cookieを保存するSQLite3データベースのファイル名
*/
const COOKIE_STORE_NAME = 'p2_2ch_net_cookie.sq3';
const COOKIE_STORE_NAME = 'p2_2ch_net_cookies.sqlite3';

/**
* 公式P2のURIと各エントリポイント
Expand Down Expand Up @@ -53,6 +53,7 @@ class P2Client
* HTTPリクエストの固定パラメータ
*/
const REQUEST_DATA_CHARACTER_SET_DETECTION_HINT = '◎◇';
const REQUEST_DATA_LS_LAST1_NO_FIRST = 'l1n';

/**
* 読み込み正否判定のための文字列
Expand Down Expand Up @@ -135,6 +136,7 @@ public function __construct($loginId, $loginPass, $cookieSaveDir, $ignoreCookieA

if ($cookieManager = $cookieStore->get($loginId)) {
if (!$cookieManager instanceof HTTP_Client_CookieManager) {
$cookieStore->delete($loginId);
throw new Exception('Cannot restore the cookie manager.');
}
} else {
Expand Down Expand Up @@ -236,12 +238,7 @@ public function login($uri = null, array $data = array(),
*/
public function readThread($host, $bbs, $key, $ls = '1', &$response = null)
{
$getData = array(
self::REQUEST_PARAMETER_HOST => rawurlencode($host),
self::REQUEST_PARAMETER_BBS => rawurlencode($bbs),
self::REQUEST_PARAMETER_KEY => rawurlencode($key),
self::REQUEST_PARAMETER_LS => rawurlencode($ls),
);
$getData = $this->setupGetData($host, $bbs, $key, $ls);
$uri = self::P2_ROOT_URI . self::SCRIPT_NAME_READ;
$response = $this->httpGet($uri, $getData, true);
$dom = new P2DOM($response['body']);
Expand Down Expand Up @@ -280,7 +277,9 @@ public function downloadDat($host, $bbs, $key, &$response = null)
// スレッドの有無を確かめるため、まず read.php を叩く。
// dat落ち後にホストが移転した場合、移転後のホスト名でアクセスしても
// スレッド情報を取得できなかったとのメッセージが表示される。
$html = $this->readThread($host, $bbs, $key, 'l1n', $response);
$html = $this->readThread($host, $bbs, $key,
self::REQUEST_DATA_LS_LAST1_NO_FIRST,
$response);
if ($html === null) {
return null;
}
Expand All @@ -300,11 +299,7 @@ public function downloadDat($host, $bbs, $key, &$response = null)
}

// datを取得する。
$getData = array(
self::REQUEST_PARAMETER_HOST => rawurlencode($host),
self::REQUEST_PARAMETER_BBS => rawurlencode($bbs),
self::REQUEST_PARAMETER_KEY => rawurlencode($key),
);
$getData = $this->setupGetData($host, $bbs, $key);
$uri = self::P2_ROOT_URI . self::SCRIPT_NAME_DAT;
$response = $this->httpGet($uri, $getData, true);

Expand Down Expand Up @@ -338,7 +333,9 @@ public function post($host, $bbs, $key, $name, $mail, $message,
// csrfIdを取得し、かつ公式p2の既読を最新の状態にするため、まず read.php を叩く。
// 通信量を節約できるように ls=l1n としている。
// popup=1 は書き込み後のページにリダイレクトさせないため。
$html = $this->readThread($host, $bbs, $key, 'l1n', $response);
$html = $this->readThread($host, $bbs, $key,
self::REQUEST_DATA_LS_LAST1_NO_FIRST,
$response);
if ($html === null) {
return false;
}
Expand All @@ -349,21 +346,8 @@ public function post($host, $bbs, $key, $name, $mail, $message,
throw new P2Exception('Post form not found.');
}

$uri = self::P2_ROOT_URI . self::SCRIPT_NAME_POST;

// Cookie確認後のPOSTでの文字化け予防のため
// URLエンコード済みの値を用意しておいて再代入する。
$hintEncoded = rawurlencode(self::REQUEST_DATA_CHARACTER_SET_DETECTION_HINT);
$nameEncoded = rawurlencode($name);
$mailEncoded = rawurlencode($mail);
$messageEncoded = rawurlencode($message);

// POSTするデータを用意。
$postData = $this->getFormValues($dom, $form);
$postData[self::REQUEST_PARAMETER_CHARACTER_SET_DETECTION_HINT] = $hintEncoded;
$postData[self::REQUEST_PARAMETER_NAME] = $nameEncoded;
$postData[self::REQUEST_PARAMETER_MAIL] = $mailEncoded;
$postData[self::REQUEST_PARAMETER_MESSAGE] = $messageEncoded;
$postData = $this->setupPostData($dom, $form, $name, $mail, $message);
$postData[self::REQUEST_PARAMETER_POPUP] = '1';
if ($beRes) {
$postData[self::REQUEST_PARAMETER_BERES] = '1';
Expand All @@ -372,6 +356,7 @@ public function post($host, $bbs, $key, $name, $mail, $message,
}

// POST実行。
$uri = self::P2_ROOT_URI . self::SCRIPT_NAME_POST;
$response = $this->httpPost($uri, $postData, true);

// Cookie確認の場合は再POST。
Expand All @@ -383,11 +368,7 @@ public function post($host, $bbs, $key, $name, $mail, $message,
$expression = './/form[contains(@action, "' . self::SCRIPT_NAME_POST . '")]';
$result = $dom->query($expression);
if ($result instanceof DOMNodeList && $result->length > 0) {
$postData = $this->getFormValues($dom, $result->item(0));
$postData[self::REQUEST_PARAMETER_CHARACTER_SET_DETECTION_HINT] = $hintEncoded;
$postData[self::REQUEST_PARAMETER_NAME] = $nameEncoded;
$postData[self::REQUEST_PARAMETER_MAIL] = $mailEncoded;
$postData[self::REQUEST_PARAMETER_MESSAGE] = $messageEncoded;
$postData = $this->setupPostData($dom, $result->item(0), $name, $mail, $message);
$response = $this->httpPost($uri, $postData, true);
} else {
return false;
Expand Down Expand Up @@ -515,6 +496,58 @@ protected function getFormValues(P2DOM $dom, DOMElement $form,
return $data;
}

// }}}
// {{{ setupGetData()

/**
* スレッドを読むための共通パラメータの配列を生成する
*
* @param string $host
* @param string $bbs
* @param string $key
* @return array
*/
protected function setupGetData($host, $bbs, $key, $ls = null)
{
$data = array(
self::REQUEST_PARAMETER_HOST => rawurlencode($host),
self::REQUEST_PARAMETER_BBS => rawurlencode($bbs),
self::REQUEST_PARAMETER_KEY => rawurlencode($key),
);
if ($ls !== null) {
$data[self::REQUEST_PARAMETER_LS] = rawurlencode($ls);
}

return $data;
}

// }}}
// {{{ setupPostData()

/**
* スレッドに書き込むための共通パラメータの配列を生成する
*
* @param P2DOM $dom
* @param DOMElement $form
* @param string $key
* @param string $name
* @param string $mail
* @param string $message
* @return array
*/
protected function setupPostData(P2DOM $dom, DOMElement $form,
$name, $mail, $message)
{
$data = $this->getFormValues($dom, $form);
$data[self::REQUEST_PARAMETER_CHARACTER_SET_DETECTION_HINT] =
rawurlencode(self::REQUEST_DATA_CHARACTER_SET_DETECTION_HINT);
$data[self::REQUEST_PARAMETER_NAME] = rawurlencode($name);
$data[self::REQUEST_PARAMETER_MAIL] = rawurlencode($mail);
$data[self::REQUEST_PARAMETER_MESSAGE] = rawurlencode($message);

return $data;
}

// }}}
}

Expand Down
3 changes: 0 additions & 3 deletions lib/P2HttpExt.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
* rep2expack feat. pecl_http
*/

require_once P2_LIB_DIR . '/FileCtl.php';
require_once P2_LIB_DIR . '/P2Util.php';

// {{{ CONSTANTS

define('P2HTTPEXT_DEBUG', 0);
Expand Down
Loading

0 comments on commit b06af88

Please sign in to comment.