*/ require_once('HTTP/Client.php'); class DeleteMixiDiary { /** * mixiの基本URL */ const BASE_URL = 'http://mixi.jp'; /** * HTTP_Clientオブジェクト * * @return HTTP_Client */ private $_client; /** * 初期化処理 * * @return void */ public function __construct() { // HTTP_Clientの初期化 $this->_client = new HTTP_Client(); } /** * mixiにログインする * * @param string $email * @param string $password * @return boolean */ public function login($email = MIXI_EMAIL, $password = MIXI_PASSWORD) { $params = array( 'next_url' => '/home.pl', 'email' => $email, 'password' => $password, ); $this->_client->post(self::BASE_URL.'/login.pl', $params); $response = $this->_client->currentResponse(); // self::printDebug($response); if (preg_match("'/check\.pl'", $response['body'])) { return true; } return false; } /** * 日記ID一覧を取得する * * @return mixed */ public function getDiaryIdList() { $data = array(); $this->_client->get(self::BASE_URL.'/list_diary.pl'); $response = $this->_client->currentResponse(); // self::printDebug($response['body']); // HTMLからdiary_idを抜き取る if (preg_match_all('//', $response['body'], $matches)) { return $matches[1]; } return false; } /** * * @param $diary_id * @return void */ public function deleteDiary($diary_id) { // 確認画面の表示 $this->_client->post(self::BASE_URL.'/delete_diary.pl?id='.$diary_id, array()); $response = $this->_client->currentResponse(); // post_keyの取得 if (preg_match('//', $response['body'], $matches)) { $post_key = $matches[1]; } // 削除 $params = array( 'submit' => 'confirm', 'post_key' => $post_key, ); $this->_client->post(self::BASE_URL.'/delete_diary.pl?id='.$diary_id, $params); $response = $this->_client->currentResponse(); echo sprintf("deleted: diary_id = %d
\n", $diary_id); } /** * デバッグプリント * * @param mixed $data * @return void */ static public function printDebug($data) { mb_convert_variables('SJIS-win', 'EUC-jp', $data); print_r($data); } } /** * Application Entry Point */ $obj = new DeleteMixiDiary(); $obj->login(); while ($diary_ids = $obj->getDiaryIdList()) { foreach($diary_ids as $diary_id) { sleep(1); $obj->deleteDiary($diary_id); } } ?>