Ejemplo n.º 1
0
 /**
  * 公式p2で(dat取得権限がない場合はモリタポを消費して)datを取得する
  *
  * @param void
  * @return bool
  */
 protected function _downloadDat2chMoritapo()
 {
     global $_conf;
     // datをダウンロード
     try {
         $client = P2Util::getP2Client();
         $body = $client->downloadDat($this->host, $this->bbs, $this->key, $response);
         // DEBUG
         /*
         $GLOBALS['_downloadDat2chMoritapo_response_dump'] = '<pre>' . htmlspecialchars(print_r($response, true)) . '</pre>';
         register_shutdown_function(create_function('', 'echo $GLOBALS[\'_downloadDat2chMoritapo_response_dump\'];'));
         */
     } catch (P2Exception $e) {
         p2die($e->getMessage());
     }
     // データ検証その1
     if (!$body || strpos($body, '<>') === false && strpos($body, ',') === false) {
         return $this->_downloadDat2chMoritapoNotFound();
     }
     // 改行位置を検出
     $posCR = strpos($body, "\r");
     $posLF = strpos($body, "\n");
     if ($posCR === false && $posLF === false) {
         $pos = strlen($body);
     } elseif ($posCR === false) {
         $pos = $posLF;
     } elseif ($posLF === false) {
         $pos = $posCR;
     } else {
         $pos = min($posLF, $posCR);
     }
     // 1行目の取得とデータ検証その2
     $firstLine = rtrim(substr($body, 0, $pos));
     if (strpos($firstLine, '<>') !== false) {
         $this->dat_type = '2ch';
     } elseif (strpos($firstLine, ',') !== false) {
         $this->dat_type = '2ch_old';
     } else {
         return $this->_downloadDat2chMoritapoNotFound();
     }
     // データ検証その3 (タイトル = $ar[4])
     $ar = $this->explodeDatLine($firstLine);
     if (count($ar) < 5) {
         return $this->_downloadDat2chMoritapoNotFound();
     }
     // ローカルdatに書き込み
     FileCtl::make_datafile($this->keydat, $_conf['dat_perm']);
     if (FileCtl::file_write_contents($this->keydat, $body) === false) {
         p2die('cannot write file. downloadDat2chMoritapo()');
     }
     return true;
 }
Ejemplo n.º 2
0
/**
 * 公式p2でレスを書き込む
 *
 * @return boolean 書き込み成功なら true、失敗なら false
 */
function postIt2($host, $bbs, $key, $FROM, $mail, $MESSAGE)
{
    if (P2Util::isHostBe2chNet($host) || !empty($_REQUEST['beres'])) {
        $beRes = true;
    } else {
        $beRes = false;
    }
    try {
        $posted = P2Util::getP2Client()->post($host, $bbs, $key, $FROM, $mail, $MESSAGE, $beRes, $response);
    } catch (P2Exception $e) {
        p2die('公式p2ポスト失敗', $e->getMessage());
    }
    if ($posted) {
        $reload = empty($_POST['from_read_new']);
        showPostMsg(true, '書きこみが終わりました。', $reload);
    } else {
        $result_msg = '公式p2ポスト失敗</p>' . '<pre>' . htmlspecialchars($response['body'], ENT_QUOTES, 'Shift_JIS') . '</pre>' . '<p>-';
        showPostMsg(false, $result_msg, false);
    }
    return $posted;
}