Revision [6847]

This is an old revision of PageIndexByLetterSuggestion made by JavaWoman on 2005-03-22 23:03:38.

 

Suggestion for Allowing Columns on Wikka Pageindex action


I try to made adjustment to pageindex action to allow column such on category. The following code is what I've came up with, also including tweaking on the index_header.

Please comment. Thx.

<?php
if ($pages = $this->LoadAllPages())
{
    if (!isset($col)) $col = 1;
    if (isset($_REQUEST["letter"])) $requested_letter = $_REQUEST["letter"]; else $requested_letter = '';
    if (!$requested_letter && isset($letter)) $requested_letter = strtoupper($letter);
    $cached_username = $this->GetUserName();
    $link = $this->href("", "", "letter=");
    $index_header = "<strong>" . (($requested_letter != '') ? "<a href='$link'>All</a>" : "All") . "</strong>&nbsp;\n";
    $user_owns_pages = false;
    $index_output = "";
    $current_character = "";
    $character_changed = false;
    $char_count = 0;

    foreach ($pages as $page) {
        $firstChar = strtoupper($page["tag"][0]);
        if (!preg_match("/[A-Za-z]/", $firstChar)) $firstChar = "#";
        if ($firstChar != $current_character) {
            $current_character = $firstChar;
            $character_changed = true;
            $char_index[$current_character] = 0;
        }
        $char_index[$firstChar]++;
        if ($requested_letter == '' || $firstChar == $requested_letter && $character_changed)
            $character_changed = false;
    }

    $current_character = "";
    $character_changed = false;
   
    $index_output .= "<table width=\"100%\" border=\"0\">\n";
    foreach ($pages as $page)
    {
        $page_owner = $page["owner"];
        // $this->CachePage($page);

        $firstChar = strtoupper($page["tag"][0]);
        if (!preg_match("/[A-Za-z]/", $firstChar)) $firstChar = "#";
        if ($firstChar != $current_character) {
            $index_header .= "<strong>" .
                (($requested_letter != '' && $firstChar == $requested_letter) ?
                $firstChar : "<a href='$link$firstChar'>$firstChar</a>") .
                "</strong>&nbsp;\n";
            $current_character = $firstChar;
            $character_changed = true;
        }
        if ($requested_letter == '' || $firstChar == $requested_letter) {
            if ($character_changed) {
                $char_count = 0;
                $index_output .= "<tr><td>&nbsp;</td></tr>\n";
                $index_output .= "<tr><td><strong>$firstChar</strong></td></tr>\n<tr>\n";
                $character_changed = false;
            }
            if ($char_count == $col)  {
                $index_output .= "</tr>\n<tr>";
                $char_count = 0;
            }
            $index_output .= '<td>' . $this->Link($page["tag"]);

            if ($cached_username == $page_owner) {                      
                $index_output .= "*";
                $user_owns_pages = true;
            } elseif ($page_owner != '(Public)' && $page_owner != '') {
                $index_output .= " . . . . Owner: ".$page_owner;
            }
            $index_output .= "</td>\n";
            $char_count++;
        }
    }
    $index_output .= "</tr>\n</table>";
    $index_header .= "<br />";
    if ($user_owns_pages) $index_output .= "<br />\n* Indicates a page that you own.<br />\n";    
    print $index_header.$index_output;
} else {
    print("<em>No pages found.</em>");
}
?>
There are 5 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki