Ejemplo n.º 1
0
 public function replaceLinkToHTML($url, $str)
 {
     $this->setup();
     $src = false;
     foreach ($this->data as $v) {
         if (preg_match('{' . $v['match'] . '}', $url)) {
             $src = @preg_replace('{' . $v['match'] . '}', $v['replace'], $url);
             if (strstr($v['replace'], '$ime_url')) {
                 $src = str_replace('$ime_url', P2Util::throughIme($url), $src);
             }
             if (strstr($v['replace'], '$str')) {
                 $src = str_replace('$str', $str, $src);
             }
             break;
         }
     }
     return $src;
 }
Ejemplo n.º 2
0
    p2die('スレッドの指定が変です。');
}
// スレッド情報
$aThread->readDat($aThread->keydat);
$first = $aThread->explodeDatLine($aThread->datlines[0]);
$ttitle = trim($first[4]);
$ttitle_en = base64_encode($ttitle);
$moto_url = $aThread->getMotoThread(true);
$moto_url_k = $aThread->getMotoThread();
if ($moto_url != $moto_url_k) {
    $moto_url_k_ht = sprintf('<input type="text" name="dummy_moto_url_k" value="%s"><br>', hs($moto_url_k));
}
// 投稿フォーム <a>
$post_link_atag = _getPostLinkATag($aThread, $ttitle_en);
// 元スレへ <a>
$moto_link_atag = P2View::tagA(P2Util::throughIme($moto_url_k), '元スレ');
// 指定番号のレスをパース
$p = $resid - 1;
if (isset($aThread->datlines[$p])) {
    $resar = $aThread->explodeDatLine($aThread->datlines[$p]);
    // $resar[2]: 2006/10/20(金) 11:46:08 ID:YS696rnVP BE:32616498-DIA(30003)"
    $name_txt = trim(strip_tags($resar[0]));
    $mail_txt = trim(strip_tags($resar[1]));
    if (strstr($resar[2], 'ID:')) {
        //$id_preg = 'ID: ?([0-9A-Za-z\/.+?]+)([.,]|†)?';
        $id_preg = 'ID: ?([0-9A-Za-z\\/.+?]+)(,|†)?';
        $date_txt = preg_replace('/ ?' . $id_preg . '.*$/', '', $resar[2]);
        $id_txt = preg_replace('/^.*' . $id_preg . '.*$/', 'ID:$1', $resar[2]);
        $id_ht = sprintf('<input type="text" name="dummy_id" value="%s"><br>', hs($id_txt));
    } elseif (strstr($resar[2], 'HOST:')) {
        $id_preg = 'HOST: ?([0-9A-Za-z.,_\\-<>]+)';
Ejemplo n.º 3
0
 function plugin_viewImage($url, $purl, $html)
 {
     global $_conf;
     // 表示制限
     if (!isset($GLOBALS['pre_thumb_limit']) && isset($_conf['pre_thumb_limit'])) {
         $GLOBALS['pre_thumb_limit'] = $_conf['pre_thumb_limit'];
     }
     if (!$_conf['preview_thumbnail'] || empty($GLOBALS['pre_thumb_limit'])) {
         return false;
     }
     if (preg_match('{^https?://.+?\\.(jpe?g|gif|png)$}i', $url) && empty($purl['query'])) {
         //$picto_url = 'http://pic.to/' . $purl['host'] . $purl['path'];
         $picto_url = 'http://' . $purl['host'] . $purl['path'];
         //書き換えどころ 080728
         $picto_tag = '<a href="' . hs($picto_url) . '" target="_blank"><img src="' . hs($url) . '"></a> ';
         if ($_conf['through_ime']) {
             $link_url = P2Util::throughIme($url);
             $picto_url = P2Util::throughIme($picto_url);
         } else {
             $link_url = $url;
         }
         // $html は URLを表現しているが、hが欠けていたりする
         return sprintf('%s<a href="%s">%s</a>', $picto_tag, hs($link_url), $html);
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * 画像ポップアップ変換
  *
  * @access  private
  * @return  string|false  HTML
  */
 function plugin_viewImage($url, $purl, $html)
 {
     global $_conf;
     if (preg_match('{^https?://.+?\\.(jpe?g|gif|png)$}i', $url) && empty($purl['query'])) {
         $picto_url = 'http://pic.to/' . $purl['host'] . $purl['path'];
         if ($_conf['through_ime']) {
             $link_url = P2Util::throughIme($url);
             $picto_url = P2Util::throughIme($picto_url);
         } else {
             $link_url = $url;
         }
         $picto_tag = sprintf('<a href="%s">(ピ)</a> ', hs($picto_url));
         return $picto_tag . sprintf('<a href="%s">%s</a>', hs($link_url), $html);
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * SETTING.TXT をダウンロードして、パースして、キャッシュする
  *
  * @access  public
  * @return  true|null|false  成功|更新なし(キャッシュ)|失敗
  */
 function downloadSettingTxt()
 {
     global $_conf;
     $perm = $_conf['dl_perm'] ? $_conf['dl_perm'] : 0606;
     FileCtl::mkdirFor($this->setting_txt);
     // 板ディレクトリが無ければ作る
     $modified = null;
     if (file_exists($this->setting_srd) && file_exists($this->setting_txt)) {
         // 更新しない場合は、その場で抜けてしまう
         if (!empty($_GET['norefresh']) || isset($_REQUEST['word'])) {
             return null;
             // キャッシュが新しい場合も抜ける
         } elseif ($this->isSettingSrdCacheFresh()) {
             return null;
         }
         $modified = gmdate('D, d M Y H:i:s', filemtime($this->setting_txt)) . ' GMT';
     }
     // DL
     /*
     // PHP5
     if (!class_exists('HTTP_Request', false)) {
         require 'HTTP/Request.php';
     }
     */
     require_once 'HTTP/Request.php';
     $params = array();
     $params['timeout'] = $_conf['fsockopen_time_limit'];
     if ($_conf['proxy_use']) {
         $params['proxy_host'] = $_conf['proxy_host'];
         $params['proxy_port'] = $_conf['proxy_port'];
     }
     $req = new HTTP_Request($this->url, $params);
     $modified && $req->addHeader('If-Modified-Since', $modified);
     $req->addHeader('User-Agent', 'Monazilla/1.00 (' . $_conf['p2uaname'] . '/' . $_conf['p2version'] . ')');
     $response = $req->sendRequest();
     $error_msg = null;
     if (PEAR::isError($response)) {
         $error_msg = $response->getMessage();
     } else {
         $code = $req->getResponseCode();
         if ($code == 302) {
             // ホストの移転を追跡
             require_once P2_LIB_DIR . '/BbsMap.php';
             $new_host = BbsMap::getCurrentHost($this->host, $this->bbs);
             if ($new_host != $this->host) {
                 $aNewSettingTxt = new SettingTxt($new_host, $this->bbs);
                 return $aNewSettingTxt->downloadSettingTxt();
             }
         }
         if (!($code == 200 || $code == 206 || $code == 304)) {
             //var_dump($req->getResponseHeader());
             $error_msg = $code;
         }
     }
     // DLエラー
     if (strlen($error_msg)) {
         P2Util::pushInfoHtml(sprintf('<div>Error: %s<br>p2 info - %s に接続できませんでした。</div>', hs($error_msg), P2View::tagA(P2Util::throughIme($this->url), hs($this->url), array('target' => $_conf['ext_win_target']))));
         touch($this->setting_txt);
         // DL失敗した場合(404)も touch する
         touch($this->setting_srd);
         return false;
     }
     $body = $req->getResponseBody();
     // DL成功して かつ 更新されていたら保存
     if ($body && $code != 304) {
         // したらば or be.2ch.net ならEUCをSJISに変換
         if (P2Util::isHostJbbsShitaraba($this->host) || P2Util::isHostBe2chNet($this->host)) {
             $body = mb_convert_encoding($body, 'SJIS-win', 'eucJP-win');
         }
         if (false === FileCtl::filePutRename($this->setting_txt, $body)) {
             die('Error: cannot write file');
         }
         chmod($this->setting_txt, $perm);
         // パースして
         if (!$this->setSettingArrayFromSettingTxt()) {
             return false;
         }
         // srd保存する
         if (!$this->saveSettingSrd($this->setting_array)) {
             return false;
         }
     } else {
         // touchすることで更新インターバルが効くので、しばらく再チェックされなくなる
         touch($this->setting_txt);
         // 同時にキャッシュもtouchしないと、setting_txtとsetting_srdで更新時間がずれて、
         // 毎回ここまで処理が来る(サーバへのヘッダリクエストが飛ぶ)場合がある。
         touch($this->setting_srd);
     }
     return true;
 }
Ejemplo n.º 6
0
/**
 * rep2 - タイトルページ
 */
require_once __DIR__ . '/../init.php';
$_login->authorize();
// ユーザ認証
//=========================================================
// 変数
//=========================================================
if (!empty($GLOBALS['pref_dir_realpath_failed_msg'])) {
    P2Util::pushInfoHtml('<p>' . $GLOBALS['pref_dir_realpath_failed_msg'] . '</p>');
}
$p2web_url_r = P2Util::throughIme($_conf['p2web_url']);
$expack_url_r = P2Util::throughIme($_conf['expack.web_url']);
$expack_dl_url_r = P2Util::throughIme($_conf['expack.download_url']);
$expack_hist_url_r = P2Util::throughIme($_conf['expack.history_url']);
// {{{ データ保存ディレクトリのパーミッションの注意を喚起する
P2Util::checkDirWritable($_conf['dat_dir']);
$checked_dirs[] = $_conf['dat_dir'];
// チェック済みのディレクトリを格納する配列に
// まだチェックしていなければ
if (!in_array($_conf['idx_dir'], $checked_dirs)) {
    P2Util::checkDirWritable($_conf['idx_dir']);
    $checked_dirs[] = $_conf['idx_dir'];
}
if (!in_array($_conf['pref_dir'], $checked_dirs)) {
    P2Util::checkDirWritable($_conf['pref_dir']);
    $checked_dirs[] = $_conf['pref_dir'];
}
// }}}
//=========================================================
Ejemplo n.º 7
0
 /**
  * ImageCache2サムネイル変換
  *
  * @param   string $url
  * @param   array $purl
  * @param   string $str
  * @return  string|false
  */
 public function plugin_imageCache2($url, $purl, $str)
 {
     global $_conf;
     global $pre_thumb_unlimited, $pre_thumb_ignore_limit, $pre_thumb_limit;
     static $serial = 0;
     if (P2Util::isUrlWikipediaJa($url)) {
         return false;
     }
     if (preg_match('{^https?://.+?\\.(jpe?g|gif|png)$}i', $purl[0]) && empty($purl['query'])) {
         // 準備
         $serial++;
         $thumb_id = 'thumbs' . $serial . $this->thumb_id_suffix;
         $tmp_thumb = './img/ic_load.png';
         $url_ht = $url;
         $url = $purl[0];
         $url_en = rawurlencode($url);
         $img_id = null;
         $icdb = new IC2_DataObject_Images();
         // r=0:リンク;r=1:リダイレクト;r=2:PHPで表示
         // t=0:オリジナル;t=1:PC用サムネイル;t=2:携帯用サムネイル;t=3:中間イメージ
         $img_url = 'ic2.php?r=1&amp;uri=' . $url_en;
         $thumb_url = 'ic2.php?r=1&amp;t=1&amp;uri=' . $url_en;
         // DBに画像情報が登録されていたとき
         if ($icdb->get($url)) {
             $img_id = $icdb->id;
             // ウィルスに感染していたファイルのとき
             if ($icdb->mime == 'clamscan/infected') {
                 return "<img class=\"thumbnail\" src=\"./img/x04.png\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\"> <s>{$str}</s>";
             }
             // あぼーん画像のとき
             if ($icdb->rank < 0) {
                 return "<img class=\"thumbnail\" src=\"./img/x01.png\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\"> <s>{$str}</s>";
             }
             // オリジナルがキャッシュされているときは画像を直接読み込む
             $_img_url = $this->thumbnailer->srcPath($icdb->size, $icdb->md5, $icdb->mime);
             if (file_exists($_img_url)) {
                 $img_url = $_img_url;
                 $cached = true;
             } else {
                 $cached = false;
             }
             // サムネイルが作成されていているときは画像を直接読み込む
             $_thumb_url = $this->thumbnailer->thumbPath($icdb->size, $icdb->md5, $icdb->mime);
             if (file_exists($_thumb_url)) {
                 $thumb_url = $_thumb_url;
                 // 自動スレタイメモ機能がONでスレタイが記録されていないときはDBを更新
                 if (!is_null($this->img_memo) && strpos($icdb->memo, $this->img_memo) === false) {
                     $update = new IC2_DataObject_Images();
                     if (!is_null($icdb->memo) && strlen($icdb->memo) > 0) {
                         $update->memo = $this->img_memo . ' ' . $icdb->memo;
                     } else {
                         $update->memo = $this->img_memo;
                     }
                     $update->whereAddQuoted('uri', '=', $url);
                     $update->update();
                 }
             }
             // サムネイルの画像サイズ
             $thumb_size = $this->thumbnailer->calc($icdb->width, $icdb->height);
             $thumb_size = preg_replace('/(\\d+)x(\\d+)/', 'width="$1" height="$2"', $thumb_size);
             $tmp_thumb = './img/ic_load1.png';
             $orig_img_url = $img_url;
             $orig_thumb_url = $thumb_url;
             // 画像がキャッシュされていないとき
             // 自動スレタイメモ機能がONならクエリにUTF-8エンコードしたスレタイを含める
         } else {
             // 画像がブラックリストorエラーログにあるか確認
             if (false !== ($errcode = $icdb->ic2_isError($url))) {
                 return "<img class=\"thumbnail\" src=\"./img/{$errcode}.png\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\"> <s>{$str}</s>";
             }
             $cached = false;
             $orig_img_url = $img_url;
             $orig_thumb_url = $thumb_url;
             $img_url .= $this->img_memo_query;
             $thumb_url .= $this->img_memo_query;
             $thumb_size = '';
             $tmp_thumb = './img/ic_load2.png';
         }
         // キャッシュされておらず、表示数制限が有効のとき
         if (!$cached && !$pre_thumb_unlimited && !$pre_thumb_ignore_limit) {
             // 表示制限を超えていたら、表示しない
             // 表示制限を超えていなければ、表示制限カウンタを下げる
             if ($pre_thumb_limit <= 0) {
                 $show_thumb = false;
             } else {
                 $show_thumb = true;
                 $pre_thumb_limit--;
             }
         } else {
             $show_thumb = true;
         }
         // 表示モード
         if ($show_thumb) {
             $img_tag = "<img class=\"thumbnail\" src=\"{$thumb_url}\" {$thumb_size} hspace=\"4\" vspace=\"4\" align=\"middle\">";
             if ($_conf['iframe_popup']) {
                 $view_img = $this->imageHtmlPopup($img_url, $img_tag, $str);
             } else {
                 $view_img = "<a href=\"{$img_url}\"{$_conf['ext_win_target_at']}>{$img_tag}{$str}</a>";
             }
         } else {
             $img_tag = "<img id=\"{$thumb_id}\" class=\"thumbnail\" src=\"{$tmp_thumb}\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\">";
             $view_img = "<a href=\"{$img_url}\" onclick=\"return loadThumb('{$thumb_url}','{$thumb_id}')\"{$_conf['ext_win_target_at']}>{$img_tag}</a><a href=\"{$img_url}\"{$_conf['ext_win_target_at']}>{$str}</a>";
         }
         // ソースへのリンクをime付きで表示
         if ($_conf['expack.ic2.enabled'] && $_conf['expack.ic2.through_ime']) {
             $ime_url = P2Util::throughIme($url);
             if ($_conf['iframe_popup'] == 3) {
                 $ime_mark = '<img src="img/ime.png" width="22" height="12" alt="">';
             } else {
                 $ime_mark = '[ime]';
             }
             $view_img .= " <a class=\"img_through_ime\" href=\"{$ime_url}\"{$_conf['ext_win_target_at']}>{$ime_mark}</a>";
         }
         $view_img .= '<img class="ic2-info-opener" src="img/s2a.png" width="16" height="16" onclick="ic2info.show(' . ($img_id ? $img_id : "'{$url_ht}'") . ', event)">';
         return $view_img;
     }
     return false;
 }
Ejemplo n.º 8
0
function rss_print_content($item, $num, $count)
{
    $item = array_map('trim', $item);
    // 変数の初期化
    $date_ht = '';
    $subject_ht = '';
    $creator_ht = '';
    $description_ht = '';
    $prev_item_ht = '';
    $next_item_ht = '';
    // リンク
    $item_title = p2h($item['title'], false);
    // タイトル
    $link_orig = P2Util::throughIme($item['link']);
    // トピック
    if (isset($item['dc:subject'])) {
        $subject_ht = $item['dc:subject'];
    }
    // 文責
    if (isset($item['dc:creator']) && $item['dc:creator'] !== '') {
        $creator_ht = "<b class=\"name\">" . trim($item['dc:creator']) . "</b>:";
    }
    // 日時
    if (!empty($item['dc:date'])) {
        $date_ht = rss_format_date($item['dc:date']);
    } elseif (!empty($item['dc:pubdate'])) {
        $date_ht = rss_format_date($item['dc:pubdate']);
    }
    // 概要
    if (isset($item['content:encoded']) && $item['content:encoded'] !== '') {
        $description_ht = rss_desc_converter($item['content:encoded']);
    } elseif (isset($item['description']) && $item['description'] !== '') {
        $description_ht = rss_desc_converter($item['description']);
    }
    // 前後の概要へジャンプ
    if ($count != 0) {
        $prev_item_num = $num - 1;
        $next_item_num = $num + 1;
        if ($prev_item_num != 0) {
            $prev_item_ht = "<a href=\"#it{$prev_item_num}\">▲</a>";
        }
        if ($next_item_num <= $count) {
            $next_item_ht = "<a href=\"#it{$next_item_num}\">▼</a>";
        }
    }
    // 表示
    echo <<<EOP
<table id="it{$num}" width="100%">
    <tr>
        <td align="left"><h3 class="thread_title">{$item_title}</h3></td>
        <td align="right" nowrap>{$prev_item_ht} {$next_item_ht}</td>
    </tr>
</table>
<div style="margin:0.5em">{$creator_ht}{$date_ht} <a href="{$link_orig}">[LINK]</a></div>
<div style="margin:1em 1em 1em 2em">
{$description_ht}
</div>
<div style="text-align:right"><a href="#it{$num}">▲</a></div>

EOP;
    if ($count != 0 && $num != $count) {
        echo "\n<hr style=\"margin:20px 0px\">\n\n";
    }
}
Ejemplo n.º 9
0
Archivo: title.php Proyecto: poppen/p2
<?php

// p2 -  タイトルページ(PC用)
require_once './conf/conf.inc.php';
require_once P2_LIB_DIR . '/FileCtl.php';
$_login->authorize();
// ユーザ認証
//=========================================================
// 変数
//=========================================================
$p2web_url_r = P2Util::throughIme($_conf['p2web_url']);
// {{{ データ保存ディレクトリのパーミッションの注意を喚起する
P2Util::checkDirWritable($_conf['dat_dir']);
$checked_dirs[] = $_conf['dat_dir'];
// チェック済みのディレクトリを格納する配列に
// まだチェックしていなければ
if (!in_array($_conf['idx_dir'], $checked_dirs)) {
    P2Util::checkDirWritable($_conf['idx_dir']);
    $checked_dirs[] = $_conf['idx_dir'];
}
if (!in_array($_conf['pref_dir'], $checked_dirs)) {
    P2Util::checkDirWritable($_conf['pref_dir']);
    $checked_dirs[] = $_conf['pref_dir'];
}
// }}}
//=========================================================
// 前処理
//=========================================================
// ●ID 2ch オートログイン
if ($array = P2Util::readIdPw2ch()) {
    list($login2chID, $login2chPW, $autoLogin2ch) = $array;
Ejemplo n.º 10
0
    function plugin_linkNicoNico($url, $purl, $str)
    {
        global $_conf;
        // http://www.nicovideo.jp/watch?v=utbrYUJt9CSl0
        // http://www.nicovideo.jp/watch/utvWwAM30N0No
        /*
        <div style="width:318px; border:solid 1px #CCCCCC;"><iframe src="http://www.nicovideo.jp/thumb?v=utvWwAM30N0No" width="100%" height="198" scrolling="no" border="0" frameborder="0"></iframe></div>
        */
        if (preg_match('{^http://www\\.nicovideo\\.jp/watch(?:/|(?:\\?v=))([0-9a-zA-Z_-]+)}', $url, $m)) {
            $url = P2Util::throughIme($url);
            $id = $m[1];
            $ids = str_replace('sm', '', $id);
            return <<<EOP
<a href="mailto:?subject=rep2iPhone からニコニコ&body=http:%2F%2Fwww.nicovideo.jp%2Fwatch%2F{$id}"><img class="nico" src="http://tn-skr2.smilevideo.jp/smile?i={$ids}"></a>
<a href="{$url}" target="_blank">{$str}</a>
EOP;
        }
        return FALSE;
    }
Ejemplo n.º 11
0
Archivo: P2Util.php Proyecto: poppen/p2
 /**
  * ファイルをダウンロード保存する
  *
  * @access  public
  * @param   $options  array('disp_error' => true, 'use_tmp_file' => false, 'modified' = null)
  * @return  WapResponse|false
  */
 function fileDownload($url, $localfile, $options = array())
 {
     global $_conf;
     $me = __CLASS__ . '::' . __FUNCTION__ . '()';
     $disp_error = isset($options['disp_error']) ? $options['disp_error'] : true;
     $use_tmp_file = isset($options['use_tmp_file']) ? $options['use_tmp_file'] : false;
     $modified = isset($options['modified']) ? $options['modified'] : null;
     if (strlen($localfile) == 0) {
         trigger_error("{$me}, localfile is null", E_USER_WARNING);
         return false;
     }
     $perm = isset($_conf['dl_perm']) ? $_conf['dl_perm'] : 0606;
     // {{{ modifiedの指定
     // 指定なし(null)なら、ファイルの更新時間
     if (is_null($modified) && file_exists($localfile)) {
         $modified = gmdate("D, d M Y H:i:s", filemtime($localfile)) . " GMT";
         // UNIX TIME
     } elseif (is_numeric($modified)) {
         $modified = gmdate("D, d M Y H:i:s", $modified) . " GMT";
         // 日付時間文字列
     } elseif (is_string($modified)) {
         // $modified はそのまま
     } else {
         // modified ヘッダはなし
         $modified = false;
     }
     // }}}
     // DL
     require_once P2_LIB_DIR . '/wap.class.php';
     $wap_ua = new WapUserAgent();
     $wap_ua->setTimeout($_conf['fsockopen_time_limit']);
     $wap_req = new WapRequest();
     $wap_req->setUrl($url);
     $modified and $wap_req->setModified($modified);
     if ($_conf['proxy_use']) {
         $wap_req->setProxy($_conf['proxy_host'], $_conf['proxy_port']);
     }
     $wap_res = $wap_ua->request($wap_req);
     if (!$wap_res or !$wap_res->is_success() && $disp_error) {
         $url_t = P2Util::throughIme($wap_req->url);
         $atag = P2View::tagA($url_t, hs($wap_req->url), array('target' => $_conf['ext_win_target']));
         $msgHtml = sprintf('<div>Error: %s %s<br>p2 info - %s に接続できませんでした。</div>', hs($wap_res->code), hs($wap_res->message), $atag);
         P2Util::pushInfoHtml($msgHtml);
     }
     // 更新されていたらファイルに保存
     if ($wap_res->is_success() && $wap_res->code != '304') {
         if ($use_tmp_file) {
             if (!is_dir($_conf['tmp_dir'])) {
                 if (!FileCtl::mkdirR($_conf['tmp_dir'])) {
                     die("Error: {$me}, cannot mkdir.");
                     return false;
                 }
             }
             if (false === FileCtl::filePutRename($localfile, $wap_res->content)) {
                 trigger_error("{$me}, FileCtl::filePutRename() return false. " . $localfile, E_USER_WARNING);
                 die("Error:  {$me}, cannot write file.");
                 return false;
             }
         } else {
             if (false === file_put_contents($localfile, $wap_res->content, LOCK_EX)) {
                 die("Error:  {$me}, cannot write file.");
                 return false;
             }
         }
         chmod($localfile, $perm);
     }
     return $wap_res;
 }
Ejemplo n.º 12
0
 /**
  * subject.txtをダウンロードする
  *
  * @return string subject.txt の中身
  */
 public function downloadSubject()
 {
     global $_conf;
     if ($this->storage === 'file') {
         FileCtl::mkdirFor($this->subject_file);
         // 板ディレクトリが無ければ作る
         if (file_exists($this->subject_file)) {
             if (!empty($_REQUEST['norefresh']) || empty($_REQUEST['refresh']) && isset($_REQUEST['word'])) {
                 return;
                 // 更新しない場合は、その場で抜けてしまう
             } elseif (!empty($GLOBALS['expack.subject.multi-threaded-download.done'])) {
                 return;
                 // 並列ダウンロード済の場合も抜ける
             } elseif (empty($_POST['newthread']) and $this->isSubjectTxtFresh()) {
                 return;
                 // 新規スレ立て時でなく、更新が新しい場合も抜ける
             }
             $modified = http_date(filemtime($this->subject_file));
         } else {
             $modified = false;
         }
     }
     // DL
     $params = array();
     $params['timeout'] = $_conf['http_conn_timeout'];
     $params['readTimeout'] = array($_conf['http_read_timeout'], 0);
     if ($_conf['proxy_use']) {
         $params['proxy_host'] = $_conf['proxy_host'];
         $params['proxy_port'] = $_conf['proxy_port'];
     }
     $req = new HTTP_Request($this->subject_url, $params);
     $modified && $req->addHeader("If-Modified-Since", $modified);
     $req->addHeader('User-Agent', "Monazilla/1.00 ({$_conf['p2ua']})");
     $response = $req->sendRequest();
     if (PEAR::isError($response)) {
         $error_msg = $response->getMessage();
     } else {
         $code = $req->getResponseCode();
         if ($code == 302) {
             // ホストの移転を追跡
             $new_host = BbsMap::getCurrentHost($this->host, $this->bbs);
             if ($new_host != $this->host) {
                 $aNewSubjectTxt = new SubjectTxt($new_host, $this->bbs);
                 $body = $aNewSubjectTxt->downloadSubject();
                 return $body;
             }
         }
         if (!($code == 200 || $code == 206 || $code == 304)) {
             //var_dump($req->getResponseHeader());
             $error_msg = $code;
         }
     }
     if (isset($error_msg) && strlen($error_msg) > 0) {
         $url_t = P2Util::throughIme($this->subject_url);
         $info_msg_ht = "<p class=\"info-msg\">Error: {$error_msg}<br>";
         $info_msg_ht .= "rep2 info: <a href=\"{$url_t}\"{$_conf['ext_win_target_at']}>{$this->subject_url}</a> に接続できませんでした。</p>";
         P2Util::pushInfoHtml($info_msg_ht);
         $body = '';
     } else {
         $body = $req->getResponseBody();
     }
     // ■ DL成功して かつ 更新されていたら
     if ($body && $code != "304") {
         // したらば or be.2ch.net ならEUCをSJISに変換
         if (P2Util::isHostJbbsShitaraba($this->host) || P2Util::isHostBe2chNet($this->host)) {
             $body = mb_convert_encoding($body, 'CP932', 'CP51932');
         }
         if (FileCtl::file_write_contents($this->subject_file, $body) === false) {
             p2die('cannot write file');
         }
     } else {
         // touchすることで更新インターバルが効くので、しばらく再チェックされなくなる
         // (変更がないのに修正時間を更新するのは、少し気が進まないが、ここでは特に問題ないだろう)
         if ($this->storage === 'file') {
             touch($this->subject_file);
         }
     }
     return $body;
 }
Ejemplo n.º 13
0
 /**
  * _pushInfo系メソッド用にURLをアンカーに変換する
  *
  * @param   string  $url
  * @return  string
  */
 protected static function _urlToAnchor($url)
 {
     global $_conf;
     return sprintf('<a href="%s"%s>%s</a>', P2Util::throughIme($url), $_conf['ext_win_target_at'], p2h($url));
 }
Ejemplo n.º 14
0
 /**
  * >>1のみをプレビュー表示するためのHTMLを取得する(オンザフライに対応)
  *
  * @access  public
  * @return  string|false
  */
 function previewOne()
 {
     global $_conf, $ptitle_ht;
     if (!($this->host && $this->bbs && $this->key)) {
         return false;
     }
     $first_line = '';
     // ローカルdatから取得
     if (is_readable($this->keydat)) {
         $fd = fopen($this->keydat, "rb");
         $first_line = fgets($fd, 32800);
         fclose($fd);
     }
     if ($first_line) {
         // be.2ch.net ならEUC→SJIS変換
         if (P2Util::isHostBe2chNet($this->host)) {
             $first_line = mb_convert_encoding($first_line, 'SJIS-win', 'eucJP-win');
         }
         $first_datline = rtrim($first_line);
         if (strstr($first_datline, "<>")) {
             $datline_sepa = "<>";
         } else {
             $datline_sepa = ",";
             $this->dat_type = "2ch_old";
         }
         $d = explode($datline_sepa, $first_datline);
         $this->setTtitle($d[4]);
         // 便宜上
         if (!$this->readnum) {
             $this->readnum = 1;
         }
     }
     // ローカルdatなければオンラインから
     if (!$first_line) {
         $url = $this->getDatUrl($this->host, $this->bbs, $this->key);
         $purl = parse_url($url);
         $purl['query'] = isset($purl['query']) ? '?' . $purl['query'] : '';
         // プロキシ
         if ($_conf['proxy_use']) {
             $send_host = $_conf['proxy_host'];
             $send_port = $_conf['proxy_port'];
             $send_path = $url;
         } else {
             $send_host = $purl['host'];
             $send_port = isset($purl['port']) ? $purl['port'] : null;
             $send_path = $purl['path'] . $purl['query'];
         }
         // デフォルトを80
         !$send_port and $send_port = 80;
         $request = 'GET ' . $send_path . " HTTP/1.0\r\n";
         $request .= "Host: " . $purl['host'] . "\r\n";
         $request .= 'User-Agent: ' . P2Util::getP2UA($withMonazilla = true) . "\r\n";
         // $request .= "Range: bytes={$from_bytes}-\r\n";
         // Basic認証用のヘッダ
         if (isset($purl['user']) && isset($purl['pass'])) {
             $request .= "Authorization: Basic " . base64_encode($purl['user'] . ":" . $purl['pass']) . "\r\n";
         }
         $request .= "Connection: Close\r\n";
         $request .= "\r\n";
         // WEBサーバへ接続
         $fp = fsockopen($send_host, $send_port, $errno, $errstr, $_conf['fsockopen_time_limit']);
         if (!$fp) {
             P2Util::pushInfoHtml(sprintf('<p>サーバ接続エラー: %s (%s)<br>p2 info - %s に接続できませんでした。</p>', $errstr, $errno, P2View::tagA(P2Util::throughIme($url), hs($url), array('target' => $_conf['ext_win_target']))));
             $this->diedat = true;
             return false;
         }
         // HTTPリクエスト送信
         fputs($fp, $request);
         // HTTPヘッダレスポンスを取得する
         $h = $this->freadHttpHeader($fp);
         if ($h === false) {
             fclose($fp);
             $this->_pushInfoHtmlFreadHttpHeaderError($url);
             $this->diedat = true;
             return false;
         }
         // {{{ HTTPコードをチェック
         $code = $h['code'];
         // Partial Content
         if ($code == "200") {
             // OK。何もしない
             // 予期しないHTTPコード。なかったと判断する
         } else {
             fclose($fp);
             $this->previewOneNotFound();
             return false;
         }
         // }}}
         if (isset($h['headers']['Content-Length'])) {
             if (preg_match("/^([0-9]+)/", $h['headers']['Content-Length'], $matches)) {
                 $onbytes = $h['headers']['Content-Length'];
             }
         }
         // bodyを一行目だけ読む
         $first_line = fgets($fp, 32800);
         fclose($fp);
         // be.2ch.net ならEUC→SJIS変換
         if (P2Util::isHostBe2chNet($this->host)) {
             $first_line = mb_convert_encoding($first_line, 'SJIS-win', 'eucJP-win');
         }
         $first_datline = rtrim($first_line);
         if (strstr($first_datline, '<>')) {
             $datline_sepa = '<>';
         } else {
             $datline_sepa = ',';
             $this->dat_type = '2ch_old';
         }
         $d = explode($datline_sepa, $first_datline);
         $this->setTtitle($d[4]);
         $this->onthefly = true;
     }
     // 厳密にはオンザフライではないが、個人にとっては(既読記録がされないという意味で)オンザフライ
     if (!$this->isKitoku()) {
         $this->onthefly = true;
     }
     $body = '';
     if (!empty($this->onthefly)) {
         // PC
         if (UA::isPC()) {
             $body .= '<div><span class="onthefly">プレビュー</span></div>';
             // 携帯
         } else {
             $body .= '<div><font size="-1" color="#00aa00">プレビュー</font></div>';
         }
     }
     UA::isPC() and $body .= '<dl>';
     require_once P2_LIB_DIR . '/ShowThread.php';
     // PC
     if (UA::isPC()) {
         require_once P2_LIB_DIR . '/ShowThreadPc.php';
         $aShowThread = new ShowThreadPc($this);
         // 携帯
     } else {
         require_once P2_LIB_DIR . '/ShowThreadK.php';
         $aShowThread = new ShowThreadK($this);
     }
     $body .= $aShowThread->transRes($first_line, 1);
     // 1を表示
     UA::isPC() and $body .= "</dl>\n";
     return $body;
 }
Ejemplo n.º 15
0
        <input type="hidden" name="login2ch" value="in">
        <input type="submit" name="submit" value="再{$login_st}する">
    </form>

EOFORM;
    } else {
        $form_now_log = "<p>現在、{$login_st}していません</p>";
    }
}
if ($autoLogin2ch) {
    $autoLogin2ch_checked = ' checked="checked"';
} else {
    $autoLogin2ch_checked = '';
}
$tora3_url = "http://2ch.tora3.net/";
$tora3_url_r = P2Util::throughIme($tora3_url);
if (!$_conf['ktai']) {
    $id_input_size_at = " size=\"30\"";
    $pass_input_size_at = " size=\"24\"";
}
// プリント =================================
echo "<div id=\"login_status\">";
echo $form_now_log;
echo "</div>";
if ($_conf['ktai']) {
    echo "<hr>";
}
echo <<<EOFORM
<form id="login_with_id" method="POST" action="{$_SERVER['SCRIPT_NAME']}" target="_self">
    {$_conf['k_input_ht']}
    ID: <input type="text" name="login2chID" value="{$login2chID}"{$id_input_size_at}><br>
Ejemplo n.º 16
0
    <th class="ti">勢い</th>
</tr>
</thead>
<tbody>
<?php 
    $R = true;
    foreach ($threads as $o => $t) {
        $new = '';
        $turl = sprintf('%s?host=%s&amp;bbs=%s&amp;key=%d', $_conf['read_php'], $t->host, $t->bbs, $t->tkey);
        $burl = sprintf('%s?host=%s&amp;bbs=%s&amp;itaj_en=%s&amp;word=%s', $_conf['subject_php'], $t->host, $t->bbs, UrlSafeBase64::encode($t->ita), $htm['query_en']);
        if (P2Util::isHostMachiBbs($t->host)) {
            $ourl = sprintf('http://%s/bbs/read.cgi/%s/%s/', $t->host, $t->bbs, $t->tkey);
        } else {
            $ourl = sprintf('http://%s/test/read.cgi/%s/%s/', $t->host, $t->bbs, $t->tkey);
        }
        $iurl = P2Util::throughIme($ourl);
        $aThread = new Thread();
        $aThread->setThreadPathInfo($t->host, $t->bbs, $t->tkey);
        if ($aThread->getThreadInfoFromIdx() && $aThread->isKitoku()) {
            $rnum = max($t->resnum, $aThread->readnum);
            $nnum = max(0, $rnum - $aThread->readnum);
        } else {
            $rnum = $t->resnum;
            $nnum = '';
        }
        ?>
<tr class="<?php 
        echo $R ? 'r1 r_odd' : 'r2 r_even';
        $R = !$R;
        ?>
">
Ejemplo n.º 17
0
    $atom_chk = '';
}
if ($mtime) {
    $mtime_q = '&amp;mt=' . $mtime;
} else {
    $mtime_q = '';
}
// }}}
// {{{ 見出し
reset($items);
$i = 0;
echo "<ol>\n";
foreach ($items as $item) {
    $item = array_map('trim', $item);
    $item_title = p2h($item['title'], false);
    $link_orig = P2Util::throughIme($item['link']);
    // jigブラウザWEB http://bwXXXX.jig.jp/fweb/?_jig_=
    $view_jig = '';
    /*
    $link_jig = 'http://bwXXXX.jig.jp/fweb/?_jig_=' . rawurlencode($item['link']);
    $view_jig = ' <a href="' . P2Util::throughIme($link_jig) . '">jW</a>';
    */
    if (isset($item['content:encoded']) && $item['content:encoded'] !== '' || isset($item['description']) && $item['description'] !== '') {
        echo "<li><a href=\"read_rss.php?xml={$xml_en}&amp;title_en={$title_en}&amp;num={$i}{$atom_q}{$mtime_q}\">{$item_title}</a></li>\n";
    } else {
        echo "<li>{$item_title} <a href=\"{$link_orig}\">直</a>{$view_jig}</li>\n";
    }
    $i++;
}
echo "</ol>\n";
// }}}
Ejemplo n.º 18
0
 /**
  * YourFileHost変換プラグイン
  *
  * @param   string  $url
  * @param   array   $purl
  * @param   string  $html
  * @return  string|false  HTML
  */
 function plugin_linkYourFileHost($url, $purl, $html)
 {
     global $_conf;
     // http://www.yourfilehost.com/media.php?cat=video&file=hogehoge.wmv
     if (preg_match('{^http://www\\.yourfilehost\\.com/media\\.php\\?cat=video&file=([0-9A-Za-z_\\-\\.]+)}', $url, $m)) {
         $link_url = $_conf['through_ime'] ? P2Util::throughIme($url) : $url;
         if ($_conf['iframe_popup']) {
             $linkHtml = $this->iframePopup($link_url, $html, array('target' => $_conf['bbs_win_target']));
         } else {
             $linkHtml = P2View::tagA($link_url, $html, array('target' => $_conf['ext_win_target']));
         }
         $dl_url1 = "http://getyourfile.dyndns.tv/video?url=" . rawurlencode($url);
         $dl_url2 = "http://yourfilehostwmv.com/video?url=" . rawurlencode($url);
         if ($_conf['through_ime']) {
             $dl_url1 = P2Util::throughIme($dl_url1);
             $dl_url2 = P2Util::throughIme($dl_url2);
         }
         $dl_url1_atag = P2View::tagA($dl_url1, hs('GetYourFile'), array('target' => $_conf['ext_win_target']));
         $dl_url2_atag = P2View::tagA($dl_url2, hs('GetWMV'), array('target' => $_conf['ext_win_target']));
         return "{$linkHtml} [{$dl_url1_atag}][{$dl_url2_atag}]";
     }
     return FALSE;
 }
Ejemplo n.º 19
0
 /**
  * _pushInfo系メソッド用にURLをアンカーに変換する
  *
  * @param   string  $url
  * @return  string
  */
 protected static function _urlToAnchor($url)
 {
     global $_conf;
     return sprintf('<a href="%s"%s>%s</a>', P2Util::throughIme($url), $_conf['ext_win_target_at'], htmlspecialchars($url, ENT_QUOTES));
 }
Ejemplo n.º 20
0
    /**
     * ニコニコ動画変換プラグイン
     *
     * @access  private
     * @return  string|false
     */
    function plugin_linkNicoNico($url, $purl, $str)
    {
        global $_conf;
        // http://www.nicovideo.jp/watch?v=utbrYUJt9CSl0
        // http://www.nicovideo.jp/watch/utvWwAM30N0No
        /*
        <div style="width:318px; border:solid 1px #CCCCCC;"><iframe src="http://www.nicovideo.jp/thumb?v=utvWwAM30N0No" width="100%" height="198" scrolling="no" border="0" frameborder="0"></iframe></div>
        */
        if (preg_match('{^http://www\\.nicovideo\\.jp/watch(?:/|(?:\\?v=))([0-9a-zA-Z_-]+)}', $url, $m)) {
            $url = P2Util::throughIme($url);
            $id = $m[1];
            return <<<EOP
<div style="width:318px; border:solid 1px #CCCCCC;"><iframe src="http://www.nicovideo.jp/thumb?v={$id}" width="100%" height="198" scrolling="no" border="0" frameborder="0"></iframe></div>
EOP;
        }
        return FALSE;
    }
Ejemplo n.º 21
0
 /**
  * 画像リンク変換
  */
 public function plugin_viewImage($url, $purl, $str)
 {
     global $_conf;
     if (P2Util::isUrlWikipediaJa($url)) {
         return false;
     }
     if (preg_match('{^https?://.+?\\.(jpe?g|gif|png)$}i', $url) && empty($purl['query'])) {
         $picto_url = 'http://pic.to/' . $purl['host'] . $purl['path'];
         $picto_tag = '<a href="' . $picto_url . '">(ピ)</a> ';
         if ($_conf['through_ime']) {
             $link_url = P2Util::throughIme($purl[0]);
             $picto_url = P2Util::throughIme($picto_url);
         } else {
             $link_url = $url;
         }
         return "{$picto_tag}<a href=\"{$link_url}\">{$str}</a>";
     }
     return false;
 }
Ejemplo n.º 22
0
 /**
  * 置換画像URL+ImageCache2
  */
 public function plugin_replaceImageUrl($url, $purl, $str)
 {
     static $serial = 0;
     global $_conf;
     global $pre_thumb_unlimited, $pre_thumb_ignore_limit, $pre_thumb_limit;
     // +Wiki
     global $replaceImageUrlCtl;
     $url = $purl[0];
     $replaced = $replaceImageUrlCtl->replaceImageUrl($url);
     if (!$replaced[0]) {
         return false;
     }
     foreach ($replaced as $v) {
         $url_en = rawurlencode($v['url']);
         $url_ht = p2h($v['url']);
         $ref_en = $v['referer'] ? '&amp;ref=' . rawurlencode($v['referer']) : '';
         // 準備
         $serial++;
         $thumb_id = 'thumbs' . $serial . $this->thumb_id_suffix;
         $tmp_thumb = './img/ic_load.png';
         $icdb = new ImageCache2_DataObject_Images();
         // r=0:リンク;r=1:リダイレクト;r=2:PHPで表示
         // t=0:オリジナル;t=1:PC用サムネイル;t=2:携帯用サムネイル;t=3:中間イメージ
         // +Wiki
         $img_url = 'ic2.php?r=1&amp;uri=' . $url_en . $ref_en;
         $thumb_url = 'ic2.php?r=1&amp;t=1&amp;uri=' . $url_en . $ref_en;
         // お気にスレ自動画像ランク
         $rank = null;
         if ($_conf['expack.ic2.fav_auto_rank']) {
             $rank = $this->getAutoFavRank();
             if ($rank !== null) {
                 $thumb_url .= '&rank=' . $rank;
             }
         }
         // DBに画像情報が登録されていたとき
         if ($icdb->get($v['url'])) {
             // ウィルスに感染していたファイルのとき
             if ($icdb->mime == 'clamscan/infected') {
                 $result .= "<img class=\"thumbnail\" src=\"./img/x04.png\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\">";
                 continue;
             }
             // あぼーん画像のとき
             if ($icdb->rank < 0) {
                 $result .= "<img class=\"thumbnail\" src=\"./img/x01.png\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\">";
                 continue;
             }
             // オリジナルがキャッシュされているときは画像を直接読み込む
             $_img_url = $this->thumbnailer->srcUrl($icdb->size, $icdb->md5, $icdb->mime);
             if (file_exists($_img_url)) {
                 $img_url = $_img_url;
                 $cached = true;
             } else {
                 $cached = false;
             }
             // サムネイルが作成されていているときは画像を直接読み込む
             $_thumb_url = $this->thumbnailer->thumbUrl($icdb->size, $icdb->md5, $icdb->mime);
             if (file_exists($_thumb_url)) {
                 $thumb_url = $_thumb_url;
                 // 自動スレタイメモ機能がONでスレタイが記録されていないときはDBを更新
                 if (!is_null($this->img_memo) && strpos($icdb->memo, $this->img_memo) === false) {
                     $update = new ImageCache2_DataObject_Images();
                     if (!is_null($icdb->memo) && strlen($icdb->memo) > 0) {
                         $update->memo = $this->img_memo . ' ' . $icdb->memo;
                     } else {
                         $update->memo = $this->img_memo;
                     }
                     $update->whereAddQuoted('uri', '=', $v['url']);
                 }
                 // expack.ic2.fav_auto_rank_override の設定とランク条件がOKなら
                 // お気にスレ自動画像ランクを上書き更新
                 if ($rank !== null && self::isAutoFavRankOverride($icdb->rank, $rank)) {
                     if ($update === null) {
                         $update = new ImageCache2_DataObject_Images();
                         $update->whereAddQuoted('uri', '=', $v['url']);
                     }
                     $update->rank = $rank;
                 }
                 if ($update !== null) {
                     $update->update();
                 }
             }
             // サムネイルの画像サイズ
             $thumb_size = $this->thumbnailer->calc($icdb->width, $icdb->height);
             $thumb_size = preg_replace('/(\\d+)x(\\d+)/', 'width="$1" height="$2"', $thumb_size);
             $tmp_thumb = './img/ic_load1.png';
             $orig_img_url = $img_url;
             $orig_thumb_url = $thumb_url;
             // 画像がキャッシュされていないとき
             // 自動スレタイメモ機能がONならクエリにUTF-8エンコードしたスレタイを含める
         } else {
             // 画像がブラックリストorエラーログにあるか確認
             if (false !== ($errcode = $icdb->ic2_isError($v['url']))) {
                 $result .= "<img class=\"thumbnail\" src=\"./img/{$errcode}.png\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\">";
                 continue;
             }
             $cached = false;
             $orig_img_url = $img_url;
             $orig_thumb_url = $thumb_url;
             $img_url .= $this->img_memo_query;
             $thumb_url .= $this->img_memo_query;
             $thumb_size = '';
             $tmp_thumb = './img/ic_load2.png';
         }
         // キャッシュされておらず、表示数制限が有効のとき
         if (!$cached && !$pre_thumb_unlimited && !$pre_thumb_ignore_limit) {
             // 表示制限を超えていたら、表示しない
             // 表示制限を超えていなければ、表示制限カウンタを下げる
             if ($pre_thumb_limit <= 0) {
                 $show_thumb = false;
             } else {
                 $show_thumb = true;
                 $pre_thumb_limit--;
             }
         } else {
             $show_thumb = true;
         }
         // 表示モード
         if ($show_thumb) {
             $img_tag = "<img class=\"thumbnail\" src=\"{$thumb_url}\" {$thumb_size} hspace=\"4\" vspace=\"4\" align=\"middle\">";
             if ($_conf['iframe_popup']) {
                 $view_img = $this->imageHtmlPopup($img_url, $img_tag, '');
             } else {
                 $view_img = "<a href=\"{$img_url}\"{$_conf['ext_win_target_at']}>{$img_tag}</a>";
             }
         } else {
             $img_tag = "<img id=\"{$thumb_id}\" class=\"thumbnail\" src=\"{$tmp_thumb}\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\">";
             $view_img = "<a href=\"{$img_url}\" onclick=\"return loadThumb('{$thumb_url}','{$thumb_id}')\"{$_conf['ext_win_target_at']}>{$img_tag}</a><a href=\"{$img_url}\"{$_conf['ext_win_target_at']}></a>";
         }
         $view_img .= '<img class="ic2-info-opener" src="img/s2a.png" width="16" height="16" onclick="ic2info.show(' . "'{$url_ht}', event)\">";
         $result .= $view_img;
     }
     // ソースへのリンクをime付きで表示
     $ime_url = P2Util::throughIme($url);
     $result .= "<a class=\"img_through_ime\" href=\"{$ime_url}\"{$_conf['ext_win_target_at']}>{$str}</a>";
     return $result;
 }
Ejemplo n.º 23
0
function rss_print_content_k($item, $num, $count)
{
    global $_conf, $xml_en, $channel, $ch_title;
    $item = array_map('trim', $item);
    // 変数の初期化
    $date_ht = '';
    $subject_ht = '';
    $creator_ht = '';
    $description_ht = '';
    $prev_item_ht = '';
    $next_item_ht = '';
    // タイトル
    $item_title = htmlspecialchars($item['title'], ENT_QUOTES, 'Shift_JIS', false);
    // リンク
    $link_orig = P2Util::throughIme($item['link']);
    // jigブラウザWEB http://bwXXXX.jig.jp/fweb/?_jig_=
    $view_jig = '';
    /*
    $link_jig = 'http://bwXXXX.jig.jp/fweb/?_jig_=' . rawurlencode($item['link']);
    $view_jig = ' <a href="' . P2Util::throughIme($link_jig) . '">jW</a>';
    */
    // トピック
    if (isset($item['dc:subject'])) {
        $subject_ht = $item['dc:subject'];
    }
    // 文責
    if (isset($item['dc:creator']) && $item['dc:creator'] !== '') {
        $creator_ht = $item['dc:creator'];
    }
    // 日時
    if (!empty($item['dc:date'])) {
        $date_ht = rss_format_date($item['dc:date']);
    } elseif (!empty($item['dc:pubdate'])) {
        $date_ht = rss_format_date($item['dc:pubdate']);
    }
    // 概要
    if (isset($item['content:encoded']) && $item['content:encoded'] !== '') {
        $description_ht = rss_desc_converter($item['content:encoded']);
    } elseif (isset($item['description']) && $item['description'] !== '') {
        $description_ht = rss_desc_converter($item['description']);
    }
    // 前後の概要へのリンク
    $prev_item_num = $num - 1;
    $next_item_num = $num + 1;
    if ($prev_item_num >= 0) {
        $prev_item_ht = "<a href=\"read_rss.php?xml={$xml_en}&amp;num={$prev_item_num}\"{$_conf['k_accesskey_at']['prev']}>{$_conf['k_accesskey_st']['prev']}前</a>";
    }
    if ($next_item_num <= $count) {
        $next_item_ht = "<a href=\"read_rss.php?xml={$xml_en}&amp;num={$next_item_num}\"{$_conf['k_accesskey_at']['next']}>{$_conf['k_accesskey_st']['next']}次</a>";
    }
    // 表示
    if ($_conf['iphone']) {
        echo <<<EOP
<h3>{$item_title}</h3>
<div>{$creator_ht}{$date_ht} <a href="{$link_orig}">直</a>{$view_jig}</div>
<hr>
<div>{$description_ht}</div>
<hr>
<div class="read-footer">{$prev_item_ht} {$next_item_ht}<br>
<a href="subject_rss.php?xml={$xml_en}">{$ch_title}</a><br>
{$_conf['k_to_index_ht']}
</div>

EOP;
    } else {
        echo <<<EOP
<h3>{$item_title}</h3>
<div>{$creator_ht}{$date_ht} <a href="{$link_orig}">直</a>{$view_jig}</div>
<hr>
<div>{$description_ht}</div>
<hr>
<div>{$prev_item_ht} {$next_item_ht}<br>
<a href="subject_rss.php?xml={$xml_en}"{$_conf['k_accesskey_at'][5]}>{$_conf['k_accesskey_st'][5]}{$ch_title}</a><br>
<a href="menu_k.php?view=rss"{$_conf['k_accesskey_at'][9]}>{$_conf['k_accesskey_st'][9]}RSS</a>
{$_conf['k_to_index_ht']}
</div>

EOP;
    }
}
Ejemplo n.º 24
0
 $ttitle_ht = htmlspecialchars($ttitle, ENT_QUOTES);
 $url_txt = $aThread->getMotoThread(true);
 $url_k_txt = $aThread->getMotoThread();
 if ($quote) {
     $url_txt .= $resid;
     $url_k_txt .= $resid;
 }
 if ($url_txt != $url_k_txt) {
     $url_k_ht = "<input type=\"text\" name=\"url_k_txt\" value=\"{$url_k_txt}\"><br>";
 }
 // 投稿フォームへのリンク
 $post_url = "post_form.php?host={$host}&amp;bbs={$bbs}&amp;key={$key}";
 $post_url .= "&amp;rescount={$aThread->rescount}&amp;ttitle_en={$ttitle_en}&amp;b=k";
 $post_link = "<a href=\"{$post_url}\">レス</a> ";
 // 元スレへのリンク
 $moto_link = '<a href="' . P2Util::throughIme($url_k_txt) . '">元スレ</a> ';
 // 指定番号のレスをパース
 $p = $resid - 1;
 if (isset($aThread->datlines[$p])) {
     $resar = $aThread->explodeDatLine($aThread->datlines[$p]);
     $name_txt = trim(strip_tags($resar[0]));
     $mail_txt = trim(strip_tags($resar[1]));
     if (strpos($resar[2], 'ID:') !== false) {
         $date_txt = preg_replace('/ ?ID: ?([0-9A-Za-z\\/.+?]+)([.,]|†)?.*$/', '', $resar[2]);
         $id_txt = preg_replace('/^.*ID: ?([0-9A-Za-z\\/.+?]+)([.,]|†)?.*$/', 'ID:$1', $resar[2]);
         $id_ht = "<input type=\"text\" name=\"id_txt\" value=\"{$id_txt}\"><br>";
     } else {
         $date_txt = $resar[2];
     }
     $msg_txt = trim(strip_tags($resar[3], '<br>'));
     if ($quote) {
Ejemplo n.º 25
0
 /**
  * SETTING.TXT をダウンロードして、パースして、キャッシュする
  *
  * @return boolean 実行成否
  */
 public function downloadSettingTxt()
 {
     global $_conf;
     // まちBBS・したらば は SETTING.TXT が存在しないものとする
     if (P2Util::isHostMachiBbs($this->_host) || P2Util::isHostJbbsShitaraba($this->_host)) {
         return false;
     }
     FileCtl::mkdirFor($this->_setting_txt);
     // 板ディレクトリが無ければ作る
     if (file_exists($this->_setting_srd) && file_exists($this->_setting_txt)) {
         // 更新しない場合は、その場で抜けてしまう
         if (!empty($_GET['norefresh']) || isset($_REQUEST['word'])) {
             return true;
             // キャッシュが新しい場合も抜ける
         } elseif ($this->isCacheFresh()) {
             return true;
         }
         $modified = http_date(filemtime($this->_setting_txt));
     } else {
         $modified = false;
     }
     // DL
     $params = array();
     $params['timeout'] = $_conf['http_conn_timeout'];
     $params['readTimeout'] = array($_conf['http_read_timeout'], 0);
     if ($_conf['proxy_use']) {
         $params['proxy_host'] = $_conf['proxy_host'];
         $params['proxy_port'] = $_conf['proxy_port'];
     }
     $req = new HTTP_Request($this->_url, $params);
     $modified && $req->addHeader('If-Modified-Since', $modified);
     $req->addHeader('User-Agent', "Monazilla/1.00 ({$_conf['p2ua']})");
     $response = $req->sendRequest();
     if (PEAR::isError($response)) {
         $error_msg = $response->getMessage();
     } else {
         $code = $req->getResponseCode();
         if ($code == 302) {
             // ホストの移転を追跡
             $new_host = BbsMap::getCurrentHost($this->_host, $this->_bbs);
             if ($new_host != $this->_host) {
                 $aNewSettingTxt = new SettingTxt($new_host, $this->_bbs);
                 $body = $aNewSettingTxt->downloadSettingTxt();
                 return true;
             }
         }
         if (!($code == 200 || $code == 206 || $code == 304)) {
             //var_dump($req->getResponseHeader());
             $error_msg = $code;
         }
     }
     // DLエラー
     if (isset($error_msg) && strlen($error_msg) > 0) {
         $url_t = P2Util::throughIme($this->_url);
         $info_msg_ht = "<p class=\"info-msg\">Error: {$error_msg}<br>";
         $info_msg_ht .= "rep2 info: <a href=\"{$url_t}\"{$_conf['ext_win_target_at']}>{$this->_url}</a> に接続できませんでした。</p>";
         P2Util::pushInfoHtml($info_msg_ht);
         touch($this->_setting_txt);
         // DL失敗した場合も touch
         return false;
     }
     $body = $req->getResponseBody();
     // DL成功して かつ 更新されていたら保存
     if ($body && $code != '304') {
         // したらば or be.2ch.net ならEUCをSJISに変換
         if (P2Util::isHostJbbsShitaraba($this->_host) || P2Util::isHostBe2chNet($this->_host)) {
             $body = mb_convert_encoding($body, 'CP932', 'CP51932');
         }
         if (FileCtl::file_write_contents($this->_setting_txt, $body) === false) {
             p2die('cannot write file');
         }
         // パースしてキャッシュを保存する
         if (!$this->cacheParsedSettingTxt()) {
             return false;
         }
     } else {
         // touchすることで更新インターバルが効くので、しばらく再チェックされなくなる
         touch($this->_setting_txt);
         // 同時にキャッシュもtouchしないと、_setting_txtと_setting_srdで更新時間がずれ、
         // 毎回ここまで処理が来る(サーバへのヘッダリクエストが飛ぶ)場合がある。
         touch($this->_setting_srd);
     }
     return true;
 }
Ejemplo n.º 26
0
/**
 * 無効タグ属性などを消去するコールバック関数
 */
function rss_desc_tag_cleaner($tag)
{
    global $_conf;
    $element = strtolower($tag[1]);
    $attributes = trim($tag[2]);
    $close = trim($tag[3]);
    // HTML 4.01形式で表示するので無視
    // 終了タグなら
    if (!$attributes || substr($element, 0, 1) == '/') {
        return '<' . $element . '>';
    }
    $tag = '<' . $element;
    if (preg_match_all('/(?:^| )([A-Za-z\\-]+)\\s*=\\s*("[^"]*"|\'[^\']*\'|\\w[^ ]*)(?: |$)/', $attributes, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $attr) {
            $key = strtolower($attr[1]);
            $value = $attr[2];
            // JavaScriptイベントハンドラ・スタイルシート・ターゲットなどの属性は禁止
            if (preg_match('/^(on[a-z]+|style|class|id|target)$/', $key)) {
                continue;
            }
            // 値の引用符を削除
            $q = substr($value, 0, 1);
            if ($q == "'") {
                $value = str_replace('"', '&quot;', substr($value, 1, -1));
            } elseif ($q == '"') {
                $value = substr($value, 1, -1);
            }
            // 属性で分岐
            switch ($key) {
                case 'href':
                    if ($element != 'a' || preg_match('/^javascript:/i', $value)) {
                        break;
                        // a要素以外はhref属性禁止
                    }
                    if (preg_match('|^[^/:]*/|', $value)) {
                        $value = rss_url_rel_to_abs($value);
                    }
                    return '<a href="' . P2Util::throughIme($value) . '"' . $_conf['ext_win_target_at'] . '>';
                case 'src':
                    if ($element != 'img' || preg_match('/^javascript:/i', $value)) {
                        break;
                        // img要素以外はsrc属性禁止
                    }
                    if (preg_match('|^[^/:]*/|', $value)) {
                        $value = rss_url_rel_to_abs($value);
                    }
                    if (P2_RSS_IMAGECACHE_AVAILABLE) {
                        $image = rss_get_image($value, $GLOBALS['channel']['title']);
                        if ($image[3] != P2_IMAGECACHE_OK) {
                            if ($_conf['ktai']) {
                                // あぼーん画像 - 携帯
                                switch ($image[3]) {
                                    case P2_IMAGECACHE_ABORN:
                                        return '[p2:あぼーん画像]';
                                    case P2_IMAGECACHE_BROKEN:
                                        return '[p2:壊]';
                                        // これと
                                    // これと
                                    case P2_IMAGECACHE_LARGE:
                                        return '[p2:大]';
                                        // これは現状では無効
                                    // これは現状では無効
                                    case P2_IMAGECACHE_VIRUS:
                                        return '[p2:ウィルス警告]';
                                    default:
                                        return '[p2:unknown error]';
                                        // 予備
                                }
                            } else {
                                // あぼーん画像 - PC
                                return "<img src=\"{$image[0][0]}\" {$image[0][1]}>";
                            }
                        } elseif ($_conf['ktai']) {
                            // インライン表示 - 携帯(PC用サムネイルサイズ)
                            return "<img src=\"{$image[1][0]}\" {$image[1][1]}>";
                        } else {
                            // インライン表示 - PC(フルサイズ)
                            return "<img src=\"{$image[0][0]}\" {$image[0][1]}>";
                        }
                    }
                    // イメージキャッシュが無効のとき画像は表示しない
                    break '';
                case 'alt':
                    if ($element == 'img' && !P2_RSS_IMAGECACHE_AVAILABLE) {
                        return ' [img:' . $value . ']';
                        // 画像はalt属性を代わりに表示
                    }
                    $tag .= ' ="' . $value . '"';
                    break;
                case 'width':
                case 'height':
                    // とりあえず無視
                    break;
                default:
                    $tag .= ' ="' . $value . '"';
            }
        }
        // endforeach
        // 要素で最終確認
        switch ($element) {
            // href属性がなかったa要素
            case 'a':
                return '<a>';
                // alt属性がなかったimg要素
            // alt属性がなかったimg要素
            case 'img':
                return '';
        }
    }
    // endif
    $tag .= '>';
    return $tag;
}
Ejemplo n.º 27
0
 /**
  * subject.txtをダウンロードする
  *
  * @access  public
  * @return  array|null|false  subject.txtの配列データ(eaccelerator, apc用)、またはnullを返す。
  *                            失敗した場合はfalseを返す。
  */
 function downloadSubject()
 {
     global $_conf;
     static $spentDlTime_ = 0;
     // DL所要合計時間
     $perm = isset($_conf['dl_perm']) ? $_conf['dl_perm'] : 0606;
     $modified = false;
     if ($this->storage == 'file') {
         FileCtl::mkdirFor($this->subject_file);
         // 板ディレクトリが無ければ作る
         if (file_exists($this->subject_file)) {
             // ファイルキャッシュがあれば、DL制限時間をかける
             if (UA::isK()) {
                 $dlSubjectTotalLimitTime = $_conf['dlSubjectTotalLimitTimeM'];
             } else {
                 $dlSubjectTotalLimitTime = $_conf['dlSubjectTotalLimitTime'];
             }
             if ($dlSubjectTotalLimitTime and $spentDlTime_ > $dlSubjectTotalLimitTime) {
                 return null;
             }
             // 条件によって、キャッシュを適用する
             // subject.php でrefresh指定がある時は、キャッシュを適用しない
             if (!(basename($_SERVER['SCRIPT_NAME']) == $_conf['subject_php'] && !empty($_REQUEST['refresh']))) {
                 // キャッシュ適用指定時は、その場で抜ける
                 if (!empty($_GET['norefresh']) || isset($_REQUEST['word'])) {
                     return null;
                     // 並列ダウンロード済の場合も抜ける
                 } elseif (!empty($GLOBALS['expack.subject.multi-threaded-download.done'])) {
                     return null;
                     // 新規スレ立て時以外で、キャッシュが新鮮な場合も抜ける
                 } elseif (empty($_POST['newthread']) and $this->isSubjectTxtFresh()) {
                     return null;
                 }
             }
             $modified = gmdate("D, d M Y H:i:s", filemtime($this->subject_file)) . " GMT";
         }
     }
     $dlStartTime = $this->microtimeFloat();
     // DL
     require_once 'HTTP/Request.php';
     $params = array();
     $params['timeout'] = $_conf['fsockopen_time_limit'];
     if ($_conf['proxy_use']) {
         $params['proxy_host'] = $_conf['proxy_host'];
         $params['proxy_port'] = $_conf['proxy_port'];
     }
     $req = new HTTP_Request($this->subject_url, $params);
     $modified && $req->addHeader('If-Modified-Since', $modified);
     $req->addHeader('User-Agent', sprintf('Monazilla/1.00 (%s/%s)', $_conf['p2uaname'], $_conf['p2version']));
     $response = $req->sendRequest();
     $error_msg = null;
     if (PEAR::isError($response)) {
         $error_msg = $response->getMessage();
     } else {
         $code = $req->getResponseCode();
         if ($code == 302) {
             // ホストの移転を追跡
             require_once P2_LIB_DIR . '/BbsMap.php';
             $new_host = BbsMap::getCurrentHost($this->host, $this->bbs);
             if ($new_host != $this->host) {
                 $aNewSubjectTxt = new SubjectTxt($new_host, $this->bbs);
                 return $aNewSubjectTxt->downloadSubject();
             }
         }
         if (!($code == 200 || $code == 206 || $code == 304)) {
             //var_dump($req->getResponseHeader());
             $error_msg = $code;
         }
     }
     if (!is_null($error_msg) && strlen($error_msg) > 0) {
         $attrs = array();
         if ($_conf['ext_win_target']) {
             $attrs['target'] = $_conf['ext_win_target'];
         }
         $atag = P2View::tagA(P2Util::throughIme($this->subject_url), hs($this->subject_url), $attrs);
         $msg_ht = sprintf('<div>Error: %s<br>p2 info - %s に接続できませんでした。</div>', hs($error_msg), $atag);
         P2Util::pushInfoHtml($msg_ht);
         $body = '';
     } else {
         $body = $req->getResponseBody();
     }
     $dlEndTime = $this->microtimeFloat();
     $dlTime = $dlEndTime - $dlStartTime;
     $spentDlTime_ += $dlTime;
     // DL成功して かつ 更新されていたら
     if ($body && $code != '304') {
         // したらば or be.2ch.net ならEUCをSJISに変換
         if (P2Util::isHostJbbsShitaraba($this->host) || P2Util::isHostBe2chNet($this->host)) {
             $body = mb_convert_encoding($body, 'SJIS-win', 'eucJP-win');
         }
         // eaccelerator or apcに保存する場合
         if ($this->storage == 'eaccelerator' || $this->storage == 'apc') {
             $cache_key = "{$this->host}/{$this->bbs}";
             $cont = rtrim($body);
             $lines = explode("\n", $cont);
             if ($this->storage == 'eaccelerator') {
                 eaccelerator_lock($cache_key);
                 eaccelerator_put($cache_key, $lines, $_conf['sb_dl_interval']);
                 eaccelerator_unlock($cache_key);
             } else {
                 apc_store($cache_key, $lines, $_conf['sb_dl_interval']);
             }
             return $lines;
             // ファイルに保存する場合
         } else {
             if (false === FileCtl::filePutRename($this->subject_file, $body)) {
                 // 保存に失敗はしても、既存のキャッシュが読み込めるならよしとしておく
                 if (is_readable($this->subject_file)) {
                     return null;
                 } else {
                     die("Error: cannot write file");
                     return false;
                 }
             }
             chmod($this->subject_file, $perm);
         }
     } else {
         // touchすることで更新インターバルが効くので、しばらく再チェックされなくなる
         // (変更がないのに修正時間を更新するのは、少し気が進まないが、ここでは特に問題ないだろう)
         if ($this->storage == 'file') {
             touch($this->subject_file);
         }
     }
     return null;
 }