コード例 #1
0
ファイル: pixmicat.php プロジェクト: Kennyl/pixmicat
function searchCategory()
{
    $PIO = PMCLibrary::getPIOInstance();
    $FileIO = PMCLibrary::getFileIOInstance();
    $PTE = PMCLibrary::getPTEInstance();
    $PMS = PMCLibrary::getPMSInstance();
    $category = isset($_GET['c']) ? strtolower(strip_tags(trim($_GET['c']))) : '';
    // 搜尋之類別標籤
    if (!$category) {
        error(_T('category_nokeyword'));
    }
    $category_enc = urlencode($category);
    $category_md5 = md5($category);
    $page = isset($_GET['p']) ? @intval($_GET['p']) : 1;
    if ($page < 1) {
        $page = 1;
    }
    // 目前瀏覽頁數
    $isrecache = isset($_GET['recache']);
    // 是否強制重新生成快取
    // 利用Session快取類別標籤出現篇別以減少負擔
    session_start();
    // 啟動Session
    if (!isset($_SESSION['loglist_' . $category_md5]) || $isrecache) {
        $loglist = $PIO->searchCategory($category);
        $_SESSION['loglist_' . $category_md5] = serialize($loglist);
    } else {
        $loglist = unserialize($_SESSION['loglist_' . $category_md5]);
    }
    $loglist_count = count($loglist);
    $page_max = ceil($loglist_count / PAGE_DEF);
    if ($page > $page_max) {
        $page = $page_max;
    }
    // 總頁數
    // 分割陣列取出適當範圍作分頁之用
    $loglist_cut = array_slice($loglist, PAGE_DEF * ($page - 1), PAGE_DEF);
    // 取出特定範圍文章
    $loglist_cut_count = count($loglist_cut);
    $dat = '';
    head($dat);
    $links = '[<a href="' . PHP_SELF2 . '?' . time() . '">' . _T('return') . '</a>][<a href="' . PHP_SELF . '?mode=category&amp;c=' . $category_enc . '&amp;recache=1">' . _T('category_recache') . '</a>]';
    $PMS->useModuleMethods('LinksAboveBar', array(&$links, 'category'));
    $dat .= "<div>{$links}</div>\n";
    for ($i = 0; $i < $loglist_cut_count; $i++) {
        $posts = $PIO->fetchPosts($loglist_cut[$i]);
        // 取得文章內容
        $dat .= arrangeThread($PTE, $posts[0]['resto'] ? $posts[0]['resto'] : $posts[0]['no'], null, $posts, 0, $loglist_cut[$i], array(), array(), false, false, false);
        // 逐個輸出 (引用連結不顯示)
    }
    $dat .= '<table style="border: 1px solid gray"><tr>';
    if ($page > 1) {
        $dat .= '<td><form action="' . PHP_SELF . '?mode=category&amp;c=' . $category_enc . '&amp;p=' . ($page - 1) . '" method="post"><div><input type="submit" value="' . _T('prev_page') . '" /></div></form></td>';
    } else {
        $dat .= '<td style="white-space: nowrap;">' . _T('first_page') . '</td>';
    }
    $dat .= '<td>';
    for ($i = 1; $i <= $page_max; $i++) {
        if ($i == $page) {
            $dat .= "[<b>" . $i . "</b>] ";
        } else {
            $dat .= '[<a href="' . PHP_SELF . '?mode=category&amp;c=' . $category_enc . '&amp;p=' . $i . '">' . $i . '</a>] ';
        }
    }
    $dat .= '</td>';
    if ($page < $page_max) {
        $dat .= '<td><form action="' . PHP_SELF . '?mode=category&amp;c=' . $category_enc . '&amp;p=' . ($page + 1) . '" method="post"><div><input type="submit" value="' . _T('next_page') . '" /></div></form></td>';
    } else {
        $dat .= '<td style="white-space: nowrap;">' . _T('last_page') . '</td>';
    }
    $dat .= '</tr></table>' . "\n";
    foot($dat);
    echo $dat;
}
コード例 #2
0
ファイル: mod_tag.php プロジェクト: Kennyl/pixmicat_modules
 function ModulePage()
 {
     global $PIO, $PTE;
     if (!isset($_GET['do'])) {
         // 沒有 "do" 指令,舊的 tag 連接
         if (!isset($_GET['no'])) {
             die('[Error] not enough parameter.');
         }
         if (!isset($_POST['tag'])) {
             $post = $PIO->fetchPosts($_GET['no']);
             if (!count($post)) {
                 die('[Error] Post does not exist.');
             }
             $pte_vals = array('{$TITLE}' => TITLE, '{$RESTO}' => '');
             $dat = $PTE->ParseBlock('HEADER', $pte_vals);
             $dat .= '</head><body id="main">';
             $dat .= '<form action="' . $this->mypage . '&amp;no=' . $_GET['no'] . '" method="POST">Tag: <input type="text" name="tag" value="' . htmlentities(substr(str_replace('&#44;', ',', $post[0]['category']), 1, -1), ENT_QUOTES, 'UTF-8') . '" size="28" /><input type="submit" name="submit" value="Tag!" /></form>';
             echo $dat . "</body></html>";
         } else {
             $Tag = CleanStr($_POST['tag']);
             if ($_SERVER['REQUEST_METHOD'] != 'POST') {
                 error(_T('regist_notpost'));
             }
             // 非正規POST方式
             $post = $PIO->fetchPosts($_GET['no']);
             $parentNo = $post[0]['resto'] ? $post[0]['resto'] : $post[0]['no'];
             $threads = array_flip($PIO->fetchThreadList());
             $threadPage = floor($threads[$parentNo] / PAGE_DEF);
             if (!count($post)) {
                 die('[Error] Post does not exist.');
             }
             $ss = method_exists($PIO, '_replaceComma') ? '&#44;' : ',';
             // Dirty implement
             $category = explode(',', $Tag);
             // 把標籤拆成陣列
             $category = $ss . implode($ss, array_map('trim', $category)) . $ss;
             // 去空白再合併為單一字串 (左右含,便可以直接以,XX,形式搜尋)
             $PIO->updatePost($_GET['no'], array('category' => $category));
             $PIO->dbCommit();
             if (STATIC_HTML_UNTIL == -1 || $threadPage <= STATIC_HTML_UNTIL) {
                 updatelog(0, $threadPage, true);
             }
             // 僅更新討論串出現那頁
             deleteCache(array($parentNo));
             // 刪除討論串舊快取
             if (isset($_POST['ajaxmode'])) {
                 echo $Tag;
             } else {
                 header('HTTP/1.1 302 Moved Temporarily');
                 header('Location: ' . fullURL() . PHP_SELF2 . '?' . time());
             }
         }
     } else {
         // 有 "do" 指令,查看下一步
         if ($_GET['do'] == "search") {
             // 搜尋符合標籤的主題
             global $PTE, $PIO, $PMS, $FileIO, $language;
             $category = isset($_GET['c']) ? strtolower(strip_tags(trim($_GET['c']))) : '';
             // 搜尋之類別標籤
             if (!$category) {
                 error(_T('category_nokeyword'));
             }
             $category_enc = urlencode($category);
             $category_md5 = md5($category);
             $page = isset($_GET['p']) ? @intval($_GET['p']) : 1;
             if ($page < 1) {
                 $page = 1;
             }
             // 目前瀏覽頁數
             $isrecache = isset($_GET['recache']);
             // 是否強制重新生成快取
             // 利用Session快取類別標籤出現篇別以減少負擔
             session_start();
             // 啟動Session
             if (!isset($_SESSION['loglist_' . $category_md5]) || $isrecache) {
                 $loglist = $PIO->searchCategory($category);
                 $_SESSION['loglist_' . $category_md5] = serialize($loglist);
             } else {
                 $loglist = unserialize($_SESSION['loglist_' . $category_md5]);
             }
             $loglist_count = count($loglist);
             if (!$loglist_count) {
                 error(_T('category_notfound'));
             }
             $page_max = ceil($loglist_count / PAGE_DEF);
             if ($page > $page_max) {
                 $page = $page_max;
             }
             // 總頁數
             // 分割陣列取出適當範圍作分頁之用
             $loglist_cut = array_slice($loglist, PAGE_DEF * ($page - 1), PAGE_DEF);
             // 取出特定範圍文章
             $loglist_cut_count = count($loglist_cut);
             $dat = '';
             head($dat);
             $links = '[<a href="' . PHP_SELF2 . '?' . time() . '">' . _T('return') . '</a>][<a href="' . PHP_SELF . '?mode=module&amp;load=mod_tag&amp;do=search&amp;c=' . $category_enc . '&amp;recache=1">' . _T('category_recache') . '</a>]';
             $PMS->useModuleMethods('LinksAboveBar', array(&$links, 'category'));
             $dat .= "<div>{$links}</div>\n";
             for ($i = 0; $i < $loglist_cut_count; $i++) {
                 $tID = $loglist_cut[$i];
                 $tree_count = $PIO->postCount($tID) - 1;
                 // 討論串回應個數
                 $RES_start = $tree_count - RE_DEF + 1;
                 if ($RES_start < 1) {
                     $RES_start = 1;
                 }
                 // 開始
                 $RES_amount = RE_DEF;
                 // 取幾個
                 $hiddenReply = $RES_start - 1;
                 // 被隱藏回應
                 // $RES_start, $RES_amount 拿去算新討論串結構 (分頁後, 部分回應隱藏)
                 $tree = $PIO->fetchPostList($tID);
                 // 整個討論串樹狀結構
                 $tree_cut = array_slice($tree, $RES_start, $RES_amount);
                 array_unshift($tree_cut, $tID);
                 // 取出特定範圍回應
                 $posts = $PIO->fetchPosts($tree_cut);
                 // 取得文章架構內容
                 $dat .= arrangeThread($PTE, $tree, $tree_cut, $posts, $hiddenReply, 0, array(), array(), false, false, false);
             }
             $dat .= '<table border="1"><tr>';
             if ($page > 1) {
                 $dat .= '<td><form action="' . PHP_SELF . '?mode=module&amp;load=mod_tag&amp;do=search&amp;c=' . $category_enc . '&amp;p=' . ($page - 1) . '" method="post"><div><input type="submit" value="' . _T('prev_page') . '" /></div></form></td>';
             } else {
                 $dat .= '<td style="white-space: nowrap;">' . _T('first_page') . '</td>';
             }
             $dat .= '<td>';
             for ($i = 1; $i <= $page_max; $i++) {
                 if ($i == $page) {
                     $dat .= "[<b>" . $i . "</b>] ";
                 } else {
                     $dat .= '[<a href="' . PHP_SELF . '?mode=module&amp;load=mod_tag&amp;do=search&amp;c=' . $category_enc . '&amp;p=' . $i . '">' . $i . '</a>] ';
                 }
             }
             $dat .= '</td>';
             if ($page < $page_max) {
                 $dat .= '<td><form action="' . PHP_SELF . '?mode=module&amp;load=mod_tag&amp;do=search&amp;c=' . $category_enc . '&amp;p=' . ($page + 1) . '" method="post"><div><input type="submit" value="' . _T('next_page') . '" /></div></form></td>';
             } else {
                 $dat .= '<td style="white-space: nowrap;">' . _T('last_page') . '</td>';
             }
             $dat .= '</tr></table>' . "\n";
             foot($dat);
             echo $dat;
         } else {
             if ($_GET['do'] == "cloud") {
                 // 建立 tag cloud?
                 // blah blah blah
             } else {
                 // 不知道該如何處理的 "do" 指令
                 echo "スクリプトはTranslation Server Errorに免費の午餐を食べています!<br />";
                 echo "...你想表達什麼?";
             }
         }
     }
 }