Subversion Repositories travelsized

Rev

Rev 480 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?PHP
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This file is part of Travelsized CMS
 *              A content management system with modules, based on wiki syntax
 *
 * Author: Dan Jensen <admin@leinir.dk>
 * Copyright 2003/2004
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The GNU General Public License is available at: http://www.gnu.org/copyleft/
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


function parse_images($page_data)
{
        global $setup_folder, $systemOptions;
        $loopcontrol = 0;
        $lastBegin = -1;
        while(true)
        {
                $begpos = strpos( $page_data, "{", $lastBegin + 1 ); //where does the first image begin
                if( $begpos === false )
                        break; //all images have been created, no need to check more
                $lastBegin = $begpos;
                $endpos = strpos( $page_data, "}", $begpos ); //image end tag
               
                $currentData = substr( $page_data, $begpos, $endpos - $begpos + 1);
               
                $parameters = explode( "||", substr( $currentData, 1, strlen($currentData) - 2 ) );
               
                $width = $alignment = $alttext = $imagesrc = "";
                if( count($parameters) > 1 )
                {
                        $imagesrc .= $parameters[0];
                        $alttext .= $parameters[1];
                        if( count($parameters) > 2 )
                        {
                                $alignment .= " style=\"float: ";
                                if( count($parameters) > 3 )
                                {
                                        $alignment .= $parameters[3];
                                        if( is_numeric($parameters[2]) )
                                                $width .= " width=\"" . $parameters[2] . "\"";
                                }
                                else
                                        $alignment .= $parameters[2];
                                $alignment .= ";\"";
                        }
                }
                else
                        continue;
               
                $imageData = "<img src=\"" . siteURL(true) . "$setup_folder/files/$imagesrc\" alt=\"$alttext\"" . $width . $alignment . " />";
               
                $page_data = str_replace( $currentData, $imageData, $page_data );
               
                //loop infinity control, there should never be more than 1000 links on one page anyway
                if ($loopcontrol ++ > 1000)
                        break;
        }
        return $page_data;
}

function parse_wikilinks($page_data) {
        global $setup_folder, $language, $page_id, $systemOptions;

        $loopcontrol = 0;
        while (true) {
                $begpos = strpos($page_data, "(("); //where does the first wiki link begin
                if ($begpos === false) break; //all wiki links have been created, no need to check more
                $midpos = strpos($page_data, "||", $begpos); //does it have different target and title?
                $endpos = strpos($page_data, "))", $begpos); //wiki link end tag
               
                // Error checking
                if ($endpos === false) {
                        return "<p>There was an error while parsing the wiki links. This means that you have forgotten to end a wiki link somewhere. Please correct this. Bellow is the output of the page data that was attempted parsed.</p><hr />" . $page_data;
                }

                if ($midpos && $midpos < $endpos) {
                        $temp_page = substr($page_data, $begpos + 2, $midpos - ($begpos + 2));
                        $temp_link = substr($page_data, $midpos + 2, $endpos - ($midpos + 2));
                } else {
                        $temp_page = substr($page_data, $begpos + 2, $endpos - ($begpos + 2));
                        $temp_link = $temp_page;
                }

                // If the link is a picture, parse it!
                $temp_link = preg_replace("/{([^<\}\{]+)\|\|([^<\}\{]+)\|\|([^<\}\{]+)\|\|([^<\}\{]+)}/is", "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/files/$1\" alt=\"$2\" width=\"$3\" align=\"$4\" />", $temp_link); //make {filename||title||width||alignment} into image tags
                $temp_link = preg_replace("/{([^<\}\{]+)\|\|([^<\}\{]+)\|\|([^<\}\{]+)}/is", "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/files/$1\" alt=\"$2\" align=\"$3\" />", $temp_link); //make {filename||title||alignment} into image tags
                $temp_link = preg_replace("/{([^<\}\{]+)\|\|([^<\}\{]+)}/is", "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/files/$1\" alt=\"$2\" />", $temp_link); //make {filename||title} into image tags

                $temp_id = getpage_id($setup_folder, $temp_page);

                if( $systemOptions["humanurls"] == 1 )
                        $starttag = "<a title=\"$temp_page\" href=\"" . globalIDtoURL("content/$language/" . urlencode($temp_page) ) . "\">";
                else
                {
                        if ($temp_id && $temp_id > -1) {
                                if (is_array($temp_id)) { //If more than one page was returned with this name, search
                                        $starttag = "<a title=\"$temp_page\" href=\"" . globalIDtoURL("content/$language/" . urlencode($temp_page) ) . "\">";
                                } else { //otherwise link directly to it
                                        $starttag = "<a title=\"$temp_page\" href=\"" . globalIDtoURL("content/$language/$temp_id") . "\">";
                                }
                        } else {
                                $starttag = "<a title=\"$temp_page\" href=\"" . globalIDtoURL("content/$language/" . urlencode($temp_page) ) . "\">";
                        }
                }
               
                $temp = substr($page_data, 0, $begpos);
                if ($temp_id != $page_id) { // Only link if this is not the same page
                        $temp .= "$starttag$temp_link</a>";
                } else {
                        $temp .= $temp_link;
                }
                $temp .= substr($page_data, $endpos + 2);
                $page_data = $temp;
                if ($loopcontrol ++ > 1000) break; //loop infinity control, there should never be more than 1000 links on one page anyway
        }
        return $page_data;
}

function parse_externallinks($page_data) {
        global $setup_folder, $language, $systemOptions;

        $loopcontrol = 0;
        while (true)
        {
                $begpos = strpos($page_data, "[["); //where does the first external link begin
                if ($begpos === false) break; //all external links have been created, no need to check more
                $midpos = strpos($page_data, "||", $begpos); //does it have different target and title? [[url||title]]
                $secpos = strpos($page_data, "||", $midpos + 1); //does it have a tooltip specified? [[url||tooltip||title]]
                $endpos = strpos($page_data, "]]", $begpos); //external link end tag

                // Error checking
                if ($endpos === false) {
                        return "<p>" . i18n("There was an error while parsing the external links. This means that you have forgotten to end an external link somewhere. Please correct this. Bellow is the output of the page data that was attempted parsed.") . "</p><hr />" . $page_data;
                }
               
                //check if there is a different target and title and act accordingly
                $temp_page = $temp_tip = $temp_link = "";
                if ($secpos and $secpos < $endpos)
                {
                        $temp_page = substr($page_data, $begpos + 2, $midpos - ($begpos + 2));
                        $temp_tip  = substr($page_data, $midpos + 2, $secpos - ($midpos + 2));
                        $temp_link = substr($page_data, $secpos + 2, $endpos - ($secpos + 2));
                }
                else if ($midpos and $midpos < $endpos)
                {
                        $temp_page = substr($page_data, $begpos + 2, $midpos - ($begpos + 2));
                        $temp_tip  = $temp_page;
                        $temp_link = substr($page_data, $midpos + 2, $endpos - ($midpos + 2));
                }
                else
                {
                        $temp_page = substr($page_data, $begpos + 2, $endpos - ($begpos + 2));
                        $temp_link = $temp_page;
                }

                //If protocol isn't present, make it
                //Supported protocols: http, mailto
                if (strpos($temp_page, ":") < 1)
                {
                        if (strpos($temp_page, "@") > 1)//mailto
                                $temp_page = "mailto:$temp_page";
                        else//Last resort, http
                                $temp_page = "http://$temp_page";
                }
                $starttag = "<a href=\"$temp_page\" title=\"$temp_tip\" target=\"_new\">";
               
                $externalHint = "";
                if( array_key_exists( "hideexternalhint", $systemOptions ) && $systemOptions["hideexternalhint"] != 1 )
                        $externalHint = "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/images/external.png\" width=\"7\" height=\"11\" alt=\"-\" />";
               
                $temp = substr($page_data, 0, $begpos);
                $temp .= "$starttag$temp_link$externalHint</a>";
                $temp .= substr($page_data, $endpos + 2);
                $page_data = $temp;
               
                //loop infinity control, there should never be more than 1000 links on one page anyway
                if ($loopcontrol++ > 1000)
                        break;
        }
        return $page_data;
}

// Thanks to dennismp on www.experten.dk for the original version of this function
// (which unfortunately didn't work with multipple tables)
function parse_tables($page_data)
{
        //No tables, no need to run through and take time doing that.
        if( !strstr($page_data, "<p >//</p >") )
                return $page_data;
       
        $lines = explode("\n", $page_data);
        $page_data = ""; //reinitialize
        $inTable = false;
        $firstRow = true;
       
        foreach($lines as $line)
        {
                switch($line)
                {
                case "<p >//</p >": //Table begin and end tag
                case "<p >//>></p >": //Table begin with right align
                        //Table has already been started, that means this is is an end tag
                        if ($inTable)
                        {
                                $page_data .= " </tr>\n</table>\n";
                                $inTable = false;
                        }
                        else
                        {
                                if( $line == "<p >//</p >" )
                                        $page_data .= "<table class=\"wikitable\">\n";
                                else if( $line == "<p >//>></p >" )
                                        $page_data .= "<table style=\"float: right;\" class=\"wikitable wikitableright\">\n";
                                       
                                $inTable = true;
                                $firstRow = true; //The table has begun, make sure the next row is marked as the first
                        }
                        break;
                case "<p >/</p >":
                        if ($firstRow)
                        {
                                $page_data .= " <tr class=\"wikitable\">\n";
                                $firstRow = false;
                        }
                        else
                        {
                                $page_data .= " </tr><tr class=\"wikitable\">\n";
                        }
                        break;
                default:
                        //If we're in a table, this is a cell
                        if( $inTable )
                        {
                                if( substr($line, 0, 3) == "<h2" )
                                {
                                        $page_data .= "         <th class=\"wikitable\">" . preg_replace("/<h2 name=\"[\d]+-[\d]+\">([^<]+)<\/h2>/is", "<p class=\"wikitable\">$1</p >", $line) . "</th>\n";
                                }
                                else
                                {
                                        $replace[] = "<p >||";
                                        $with[] = "<p class=\"wikitable wikicenteralign\">";
                                       
                                        $replace[] = "<p >>>";
                                        $with[] = "<p class=\"wikitable wikirightalign\">";
                                       
                                        $replace[] = "<p >";
                                        $with[] = "<p class=\"wikitable\">";
                                       
                                        $page_data .= "         <td class=\"wikitable\">" . str_replace( $replace, $with, $line ) . "</td>\n";
                                }
                        }
                        //Otherwise it's a normal line, do nothing with it
                        else
                        {
                                $page_data .= $line . "\n";
                        }
                }
        }
       
        // If we're still in a table, it means a table was not ended. Tell the user!
        if( $inTable )
                $page_data = "<p >" . i18n("There was an error during table generation. Please check to make sure you ended the last table correctly. Bellow is the output of the page:") . "</p ><hr />" . $page_data . "</table>";
       
        return $page_data;
}

function parse_profilelinks($page_data, $module = "") {
        global $setup_folder, $language;
       
        if( $page_data == "%%%%" ) // This means there was no username passed...
                return i18n("Nobody");
       
        if( $module != "" )
                $module = "/$module";
       
        $loopcontrol = 0;
        while (true) {
                $begpos = strpos($page_data, "%%"); //where does the first profile link begin
                if ($begpos === false) break; //all profile links have been created, no need to check more
                $midpos = strpos($page_data, "||", $begpos); //does it have different target and title?
                $endpos = strpos($page_data, "%%", $begpos + 2); //profile link end tag
               
                // Error checking
                if ($endpos === false) {
                        return "<p>" . i18n("There was an error while parsing the profile links. This means that you have forgotten to end a profile link somewhere. Please correct this. Bellow is the output of the page data that was attempted parsed.") . "</p><hr />" . $page_data;
                }
               
                if ($midpos && $midpos < $endpos) { // Then we're showing something else as the link title that is not the user's name
                        $temp_title = substr($page_data, $begpos + 2, $midpos - ($begpos + 2));
                        $temp_id = substr($page_data, $midpos + 2, $endpos - ($midpos + 2));
                       
                        $temp_fullname = $temp_title;

                        // If the link is a picture, parse it!
                        $temp_title = preg_replace("/{([^<\}\{]+)\|\|([^<\}\{]+)\|\|([^<\}\{]+)\|\|([^<\}\{]+)}/is", "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/files/$1\" alt=\"$2\" width=\"$3\" align=\"$4\" />", $temp_title); //make {filename||title||width||alignment} into image tags
                        $temp_title = preg_replace("/{([^<\}\{]+)\|\|([^<\}\{]+)\|\|([^<\}\{]+)}/is", "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/files/$1\" alt=\"$2\" align=\"$3\" />", $temp_title); //make {filename||title||alignment} into image tags
                        $temp_title = preg_replace("/{([^<\}\{]+)\|\|([^<\}\{]+)}/is", "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/files/$1\" alt=\"$2\" />", $temp_title); //make {filename||title} into image tags
                } else {
                        $temp_title = substr($page_data, $begpos + 2, $endpos - ($begpos + 2));
                        $temp_id = $temp_title;
                        $temp_fullname = getUserInfo($temp_id, "name");
                        if ($temp_fullname !=  i18n("No ##0## information\n", array("username")) && $temp_fullname != i18n("Unknown user"))
                        {
                            $temp_title = $temp_fullname;
                            $temp_fullname = "<img src=\"" . siteURL(true) . getAvatarThumbnail( $temp_id, true ) . "\" alt=\"$temp_fullname\" /><small>&nbsp;</small>" . $temp_title;
                        }
                }

                $starttag = "<a class=\"profile_link\" title=\"$temp_title\" href=\"" . globalIDtoURL("user/$temp_id" . $module) . "\">";
                $temp = substr($page_data, 0, $begpos);
                $temp .= "$starttag$temp_fullname</a>";
                $temp .= substr($page_data, $endpos + 2);
                $page_data = $temp;
                if ($loopcontrol ++ > 1000) die("Loop infinity control has noticed more than 1000 loops - something is wrong!"); //loop infinity control, there should never be more than 1000 links on one page anyway
        }
        return $page_data;
}

function parse_userlist_control($page_data)
{
        if ( !array_key_exists("userlist_per_page", $_REQUEST ) && isAuth() )
                $userlist_per_page = getUserInfo(currentUser(), "userlist_per_page");
        else if( isAuth() )
        {
                saveUserInfo(currentUser(), "userlist_per_page", $_REQUEST["userlist_per_page"]);
                $userlist_per_page = $_REQUEST["userlist_per_page"];
        }
        else
                $userlist_per_page = 9; // Default
       
        if( !array_key_exists("userlist_list_style", $_REQUEST ) && isAuth() )
                $userlist_list_style = getUserInfo(currentUser(), "userlist_list_style");
        else if( isAuth() )
        {
                saveUserInfo(currentUser(), "userlist_list_style", $_REQUEST["userlist_list_style"]);
                $userlist_list_style = $_REQUEST["userlist_list_style"];
        }
        else
                $userlist_list_style = "threeup"; // Default

        $current_3 = $current_9 = $current_27 = $current_99 = "";
        switch ($userlist_per_page) {
        case 3:
                $current_3 = " selected"; break;
        case 27:
                $current_27 = " selected"; break;
        case 99:
                $current_99 = " selected"; break;
        case 9:
        default:
                $current_9 = " selected";
        }
       
        $current_description = $current_bigtable = $current_table = $current_heading = $current_paragraph = $current_shortparagraph = $current_list = $current_shortlist = $current_threeup = "";
        switch ($userlist_list_style) {
        case "description":
                $current_description = " selected"; break;
        case "bigtable":
                $current_bigtable = " selected"; break;
        case "table":
                $current_table = " selected"; break;
        case "heading":
                $current_heading = " selected"; break;
        case "paragraph":
                $current_paragraph = " selected"; break;
        case "shortparagraph":
                $current_shortparagraph = " selected"; break;
        case "list":
                $current_list = " selected"; break;
        case "shortlist":
                $current_shortlist = " selected"; break;
        case "threeup":
        default:
                $current_threeup = " selected";
        }
       
        if( array_key_exists( "userlist_search", $_POST) )
                $searchterm = stripslashes($_POST["userlist_search"]);
        else
                $searchterm = "";

        $userlist_controller = "
        <form class=\"userlist_controller\" name=\"userlist_controller\" action=\""
. thisPageURL() . "\" method=\"post\">
        <span class=\"userlist_per_page_header\">"
. i18n("Users per page:") . "</span>
        <select name=\"userlist_per_page\" class=\"userlist_per_page\" onchange=\"document.userlist_controller.submit();\">
        <option value=\"3\"$current_3>3</option>
        <option value=\"9\"$current_9>9</option>
        <option value=\"27\"$current_27>27</option>
        <option value=\"99\"$current_99>99</option>
        </select>
        <span class=\"userlist_list_style_header\">"
. i18n("Listing style") . "</span>
        <select name=\"userlist_list_style\" class=\"userlist_list_style\">
        <option value=\"threeup\"$current_threeup>"
. i18n("Three-up") . "</option>
        <option value=\"description\"$current_description>"
. i18n("Description") . "</option>
        <option value=\"bigtable\"$current_bigtable>"
. i18n("Big table") . "</option>
        <option value=\"table\"$current_table>"
. i18n("Table") . "</option>
        <option value=\"heading\"$current_heading>"
. i18n("Headings") . "</option>
        <option value=\"paragraph\"$current_paragraph>"
. i18n("Paragraph") . "</option>
        <option value=\"shortparagraph\"$current_shortparagraph>"
. i18n("Short paragraph") . "</option>
        <option value=\"list\"$current_list>"
.i18n("List") . "</option>
        <option value=\"shortlist\"$current_shortlist>"
. i18n("Short list") . "</option>
        </select>
        <span class=\"userlist_search_header\">"
. i18n("Search user##0##:", array( drawCommand( i18n("?"), i18n("Syntax help for userlist search"), globalIDtoURL("help/userlist/search"), "", "_blank" ) ) ) . "</span>
        <input type=\"text\" name=\"userlist_search\" class=\"userlist_search\" value=\"$searchterm\" />
        <input type=\"submit\" value=\""
. i18n("Apply") . "\" class=\"userlist_apply\" /></form>";

        return str_replace("\userlist_controller()", $userlist_controller, $page_data);
}

function parse_userlists($page_data, $is_menu_menu, $userlist = "", $module = "") {
        global $setup_folder, $language, $page_id, $userinfo_folder, $viewUser;
       
        if( $module == "" )
                $module = "view";
       
        $loopcontrol = 0;
        while (true)
        {
                $begpos = strpos($page_data, "\userlist("); //where does the first profile list begin
                if ($begpos === false) break; //all profile lists have been created, no need to check more
                $midpos = strpos($page_data, ",", $begpos); //does it contain both a list type and limit?
                $endpos = strpos($page_data, ")", $begpos + 1); //profile list end tag
               
                // Error checking
                if ($endpos === false) {
                        return "<p>" . i18n("There was an error while parsing the userlists. This means that you have forgotten to end a userlist entry somewhere. Please correct this. Bellow is the output of the page data that was attempted parsed.") . "</p><hr />" . $page_data;
                }

                if ($midpos && $midpos < $endpos)
                {
                        $listtype = substr($page_data, $begpos + 10, $midpos - ($begpos + 10));
                        $listlimit = substr($page_data, $midpos + 1, $endpos - ($midpos + 1));
                }
                else
                {
                        $listtype  = substr($page_data, $begpos + 10, $endpos - ($begpos + 10));
                        $listlimit = 0;
                }
               
                if (!$is_menu_menu && isAuth())
                {
                        if( getUserInfo( currentUser(), "userlist_list_style" ) != i18n("No ##0## information\n", array("userlist_list_style")))
                                $listtype = getUserInfo(currentUser(), "userlist_list_style");
                        if( getUserInfo( currentUser(), "userlist_per_page" ) != i18n("No ##0## information\n", array("userlist_per_page")))
                                $listlimit = getUserInfo(currentUser(), "userlist_per_page");
                }
               
                if( array_key_exists( "userlist_list_style", $_REQUEST ) && $_REQUEST["userlist_list_style"] != "")
                        $listtype = $_REQUEST["userlist_list_style"];
                if( array_key_exists( "userlist_per_page", $_REQUEST ) && $_REQUEST["userlist_per_page"] != "" )
                        $listlimit = $_REQUEST["userlist_per_page"];
               
                if ($listlimit == "" || $listlimit == -1)
                        $listlimit = 9;
                if ($listtype == "")
                        $listtype = "shortparagraph";
               
                if( !is_array($userlist) )
                        $userlist = allUsersArray();
               
                // A search has been requested, act on it!
                if( array_key_exists( "userlist_search", $_POST ) && $_POST["userlist_search"] != "" )
                {
                        $searchterm = stripslashes($_POST["userlist_search"]);
                        $foundUsers = array();
                        foreach( $userlist as $key => $value )
                                if( strpos( $value, $searchterm ) !== false  || strpos( getUserInfo( $value, "name", " " ), $searchterm ) !== false )
                                        $foundUsers[] = $value;
                        $userlist = $foundUsers;
                }
               
                if ($viewUser != "")
                        $userid = "&amp;user_id=" . $viewUser;
                if ($listlimit > 0)
                {
                        $usercount = count($userlist);
                        $userlist = array_chunk($userlist, $listlimit);
                        $userlist_count = count($userlist);
                       
                        if( array_key_exists( "userlist_page", $_REQUEST ) && $_REQUEST["userlist_page"] != "" )
                                $userlist_page = $_REQUEST["userlist_page"];
                        else
                                $userlist_page = 0;
                       
                        $listpage = "&amp;userlist_page=$userlist_page";
                        $userlist_numberofpages = count($userlist);
                        $userlist = $userlist[$userlist_page];
                        $navigation = "<form name=\"profilelist_navigation\" action=\"" . thispageurl() . "\" method=\"post\"><p class=\"profilelist_navigation\">";
                       
                        if ($userlist_page > 0) {
                                $navigation .= "<a href=\"" . thisPageURL( false, true, array( "userlist_page" => "0" ) ) . "\" class=\"profilelist_navigation\"><img src=\"" . siteURL(true) . "$setup_folder/images/nav-first.png\" border=\"0\" class=\"profilelist_navigation\" width=\"10\" height=\"10\" alt=\"|&lt;\" /></a><a
                                                href=\""
. thisPageURL( false, true, array( "userlist_page" => ($userlist_page - 1) ) ) . "\" class=\"profilelist_navigation\"><img src=\"" . siteURL(true) . "$setup_folder/images/nav-prev.png\" border=\"0\" class=\"profilelist_navigation\" width=\"10\" height=\"10\" alt=\"&lt;\" /></a>";
                        } else {
                                $navigation .= "<img src=\"" . siteURL(true) . "$setup_folder/images/nav-first.png\" border=\"0\" class=\"profilelist_navigation\" width=\"10\" height=\"10\" alt=\"|&lt;\" /><img src=\"" . siteURL(true) . "$setup_folder/images/nav-prev.png\" border=\"0\" class=\"profilelist_navigation\" width=\"10\" height=\"10\" alt=\"&lt;\" />";
                        }              
                       
                        $currentbegin = ($userlist_page * $listlimit) + 1;
                        $currentend = ($userlist_page * $listlimit) +  $listlimit;
                        if ($currentend > $usercount) $currentend = $usercount;
                        if ($userlist_count > 0) {
                                $navigation .= "<select class=\"userlist_pageselector\" name=\"userlist_page\" onchange=\"document.profilelist_navigation.submit();\">";
                                for ($i = 0; $i < $userlist_count; $i++) {
                                        if ($currentbegin == (($i * $listlimit) + 1)) {
                                                $navigation .= "<option value=\"$i\" selected>" . (($i * $listlimit) + 1) . "-" . (($i * $listlimit) + $listlimit) . "</option>";
                                        } else {
                                                $navigation .= "<option value=\"$i\">" . (($i * $listlimit) + 1) . "-" . (($i * $listlimit) + $listlimit) . "</option>";
                                        }
                                }
                                $navigation .= "</select>/$usercount";
                        }
                       
                        if ($userlist_page < ($userlist_count - 1)) {
                                $navigation .= "<a href=\"" . thisPageURL( false, true, array( "userlist_page" => ($userlist_page + 1) ) ) . "\" class=\"profilelist_navigation\"><img src=\"" . siteURL(true) . "$setup_folder/images/nav-next.png\" border=\"0\" class=\"profilelist_navigation\" width=\"10\" height=\"10\" alt=\"&gt;\" /></a><a
                                        href=\""
. thisPageURL( false, true, array( "userlist_page" => ($userlist_count - 1) ) ) . "\" class=\"profilelist_navigation\"><img src=\"" . siteURL(true) . "$setup_folder/images/nav-last.png\" border=\"0\" class=\"profilelist_navigation\" width=\"10\" height=\"10\" alt=\"&gt;|\" /></a>";
                        } else {
                                $navigation .= "<img src=\"" . siteURL(true) . "$setup_folder/images/nav-next.png\" border=\"0\" class=\"profilelist_navigation\" width=\"10\" height=\"10\" alt=\"&gt;\" /><img src=\"" . siteURL(true) . "$setup_folder/images/nav-last.png\" border=\"0\" class=\"profilelist_navigation\" width=\"10\" height=\"10\" alt=\"&gt;|\" />";
                        }
                       
                        $navigation .= "</p ></form>";
                       
                } else {
                        $navigation = "<p class=\"profilelist_navigation\">" . i18n("Users") . ": " . count($userlist) . "</p>"; // No navigation controls needed, since we are showing all user entries, just show number of users
                }

                $tempdata = $navigation; // reinitialize variable for new run
                if( count( $userlist ) > 0 )
                {
                        switch (strtolower($listtype)) {
                        case "shortlist":
                                $tempdata .= "
                                <ul class=\"profile_list\">"
;
                                foreach($userlist as $key => $value) {
                                        $tempdata .= "
                                        <li><a class=\"profile_list\" href=\""
. globalIDtoURL("user/$value/$module") . "\">$value</a></li>";
                                }
                                $tempdata .= "
                                </ul>"
;
                                break;
                        case "list":
                                $tempdata .= "
                                <ul class=\"profile_list\">"
;
                                foreach($userlist as $key => $value) {
                                        $tempdata .= "
                                        <li><a class=\"profile_list\" href=\""
. globalIDtoURL("user/$value/$module") . "\">" . getUserInfo($value, "name") . " ($value)</a></li>";
                                }
                                $tempdata .= "
                                </ul>"
;
                                break;
                        case "shortparagraph":
                                foreach($userlist as $key => $value) {
                                        $tempdata .= "
                                        <p ><a class=\"profile_list\" href=\""
. globalIDtoURL("user/$value/$module") . "\">$value</a></p >";
                                }
                                break;
                        case "paragraph":
                                foreach($userlist as $key => $value) {
                                        $tempdata .= "
                                        <p ><a class=\"profile_list\" href=\""
. globalIDtoURL("user/$value/$module") . "\">" . getUserInfo($value, "name") . " ($value)</a></p >";
                                }
                                break;
                        case "heading":
                                foreach($userlist as $key => $value) {
                                        $avatarfile = getAvatar($value);
                                        $avatarthumbfile = getAvatarThumbnail($value);
                                        list($avatarwidth,$avatarheight) = getAvatarThumbSize($value);
                                        $avatarfile = siteURL(true) . $avatarfile;
                                        $avatarthumbfile = siteURL(true) . $avatarthumbfile;
                                       
                                        $profile = getUserInfo($value, "profile");
                                        $profile = substr($profile, 0, strposnth($profile, "\n", 3));
                                        if ($profile == "")
                                                $profile = getUserInfo($value, "profile");
                                       
                                        $tempdata .= "
                                        <table width=\"100%\"><tr class=\"profile_list\"><td class=\"profile_list\">
                                        <h3 class=\"profilelist_heading\"><a href=\"$avatarfile\" target=\"_blank\"><img border=\"0\" class=\"profile_avatar\" src=\"$avatarthumbfile\" width=\"$avatarwidth\" height=\"$avatarheight\" alt=\""
. i18n("##0##'s avatar", array(getUserInfo($value, "name"))) . "\" /></a>
                                        <a class=\"profile_list\" href=\""
. globalIDtoURL("user/$value/$module") . "\">" . getUserInfo($value, "name") . " ($value)</a></h3>
                                        "
. parse_page_data($profile) . "
                                        </td></tr></table>"
;
                                }
                                break;
                        case "threeup":
                                $tempdata .= "
                                <table class=\"profile_list\" width=\"100%\">"
;
                                $i = 0;
                                foreach($userlist as $key => $value) {
                                        $avatarfile = getAvatar($value);
                                        $avatarthumbfile = getAvatarThumbnail($value);
                                        list($avatarwidth,$avatarheight) = getAvatarThumbSize($value);
                                        $avatarfile = siteURL(true) . $avatarfile;
                                        $avatarthumbfile = siteURL(true) . $avatarthumbfile;
                                       
                                        if ($i == 0) {
                                                $i = 1;
                                                $tempdata .= "
                                                <tr class=\"profile_list\">
                                                        <td width=\"33%\" class=\"profile_list\">
                                                        <a class=\"profile_list\" href=\""
. globalIDtoURL("user/$value/$module") . "\">
                                                                <div class=\"profile_list\">
                                                                        <img border=\"0\" src=\"$avatarthumbfile\" width=\"$avatarwidth\" height=\"$avatarheight\" alt=\""
. i18n("##0##'s avatar", array(getUserInfo($value, "name"))) . "\" />
                                                                        <br />"
. getUserInfo($value, "name") . " ($value)
                                                                </div>
                                                        </a>
                                                        </td>"
;
                                        } else if ($i == 1) {
                                                $i = 2;
                                                $tempdata .= "
                                                        <td width=\"34%\" class=\"profile_list\">
                                                        <a class=\"profile_list\" href=\""
. globalIDtoURL("user/$value/$module") . "\">
                                                                <div class=\"profile_list\">
                                                                        <img border=\"0\" src=\"$avatarthumbfile\" width=\"$avatarwidth\" height=\"$avatarheight\" alt=\""
. i18n("##0##'s avatar", array(getUserInfo($value, "name"))) . "\" />
                                                                        <br />"
. getUserInfo($value, "name") . " ($value)
                                                                </div>
                                                        </a>
                                                        </td>"
;
                                        } else {
                                                $i = 0;
                                                $tempdata .= "
                                                        <td width=\"33%\" class=\"profile_list\">
                                                        <a class=\"profile_list\" href=\""
. globalIDtoURL("user/$value/$module") . "\">
                                                                <div class=\"profile_list\">
                                                                        <img border=\"0\" src=\"$avatarthumbfile\" width=\"$avatarwidth\" height=\"$avatarheight\" alt=\""
. i18n("##0##'s avatar", array(getUserInfo($value, "name"))) . "\" />
                                                                        <br />"
. getUserInfo($value, "name") . " ($value)
                                                                </div>
                                                        </a>
                                                        </td>
                                                </tr>"
;
                                        }
                                }
                                if ($i == 2) $tempdata .= "<td class=\"profile_list\">&nbsp;</td>";
                                if ($i == 1) $tempdata .= "<td class=\"profile_list\">&nbsp;</td><td class=\"profile_list\">&nbsp;</td>";
                                $tempdata .= "
                                </table>"
;
                                break;
                        case "table":
                                $tempdata .= "
                                <table class=\"profile_list\" width=\"100%\">"
;
                                foreach($userlist as $key => $value) {
                                        $avatarfile = getAvatar($value);
                                        $avatarthumbfile = getAvatarThumbnail($value);
                                        list($avatarwidth,$avatarheight) = getAvatarThumbSize($value);
                                        $avatarfile = siteURL(true) . $avatarfile;
                                        $avatarthumbfile = siteURL(true) . $avatarthumbfile;
                                       
                                        $profile = getUserInfo($value, "profile");
                                        $profile = substr($profile, 0, strposnth($profile, "\n", 3));
                                        if ($profile == "")
                                                $profile = getUserInfo($value, "profile");
                                       
                                        $tempdata .= "
                                        <tr class=\"profile_list\">
                                        <th class=\"profile_list\"><a class=\"profile_list\" href=\""
. globalIDtoURL("user/$value/$module") . "\">" . getUserInfo($value, "name") . " ($value)</a></th>
                                        <th class=\"profile_list\">"
. getUserInfo($value, "email") . "</th>
                                        </tr><tr class=\"profile_list\"><td class=\"profile_list\" colspan=\"2\">
                                        <a href=\"$avatarfile\" target=\"_blank\"><img border=\"0\" class=\"profile_avatar\" src=\"$avatarthumbfile\" width=\"$avatarwidth\" height=\"$avatarheight\" alt=\""
. i18n("##0##'s avatar", array(getUserInfo($value, "name"))) . "\" /></a>
                                        "
. parse_page_data($profile) . "
                                        </td>
                                        </tr>"
;
                                }
                                $tempdata .= "
                                </table>"
;
                                break;
                        case "bigtable":
                                $tempdata .= "
                                <table class=\"profile_list\" width=\"100%\">"
;
                                foreach($userlist as $key => $value) {
                                        $avatarfile = getAvatar($value);
                                        $avatarthumbfile = getAvatarThumbnail($value);
                                        list($avatarwidth,$avatarheight) = getAvatarThumbSize($value);
                                        $avatarfile = siteURL(true) . $avatarfile;
                                        $avatarthumbfile = siteURL(true) . $avatarthumbfile;
                                       
                                        $profile = getUserInfo($value, "profile");
                                       
                                        $tempdata .= "
                                        <tr class=\"profile_list\">
                                        <th class=\"profile_list\"><a class=\"profile_list\" href=\""
. globalIDtoURL("user/$value/$module") . "\">" . getUserInfo($value, "name") . " ($value)</a></th>
                                        <th class=\"profile_list\">"
. getUserInfo($value, "email") . "</th>
                                        </tr><tr class=\"profile_list\"><td class=\"profile_list\" colspan=\"2\">
                                        <a href=\"$avatarfile\" target=\"_blank\"><img border=\"0\" class=\"profile_avatar\" src=\"$avatarthumbfile\" width=\"$avatarwidth\" height=\"$avatarheight\" alt=\""
. i18n("##0##'s avatar", array(getUserInfo($value, "name"))) . "\" /></a>
                                        "
. parse_page_data($profile) . "
                                        </td>
                                        </tr>"
;
                                }
                                $tempdata .= "
                                </table>"
;
                                break;
                        case "description":
                        default:
                                $tempdata .= "
                                <dl class=\"profile_list\">"
;
                                foreach($userlist as $key => $value) {
                                        $profile = getUserInfo($value, "profile");
                                        $profile = substr($profile, 0, strposnth($profile, "\n", 3));
                                        if ($profile == "")
                                                $profile = getUserInfo($value, "profile");
                                       
                                        $tempdata .= "
                                        <dt class=\"profile_list\"><a class=\"profile_list\" href=\""
. globalIDtoURL("user/$value/$module") . "\">" . getUserInfo($value, "name") . " ($value)</a></dt>
                                        <dd class=\"profile_list\">"
. parse_page_data($profile) . "</dd>";
                                }
                                $tempdata .= "
                                </dl>"
;
                        }
                }
                else
                {
                        $tempdata .= renderInformationBox( i18n("No users"), i18n("There were no users found fitting your request.") );
                }

                if (substr($page_data, $begpos - 4, 4) == "<p >" && substr($page_data, $endpos + 1, 5) == "</p >") {
                        $page_data = substr($page_data, 0, $begpos - 4) . $tempdata . substr($page_data, $endpos + 6);
                } else {
                        $page_data = substr($page_data, 0, $begpos) . $tempdata . substr($page_data, $endpos + 1);
                }
                if ($loopcontrol ++ > 1000) die("Loop control spotted an error in the page data!"); //loop infinity control, there should never be more than 1000 links on one page anyway
        }
        return $page_data;
}

function parse_preformatted($page_data)
{
        if (!strstr($page_data, "<p >:")) return $page_data; //No tables, no need to run through and take time doing that.
        $lines = explode("\n", $page_data);
        $page_data = ""; //reinitialize
        $inPre = false;
        foreach($lines as $line)
        {
                if( substr( $line, 0, 5 ) == "<p >:" )
                {
                        if( !$inPre )
                        {
                                $page_data .= "<pre class=\"wikipre\">\n";
                                $inPre = true;
                        }
                        $page_data .= substr( $line, 5, -5 ) . "\n";
                }
                else if( $inPre && substr( $line, 0, 5 ) != "<p >:" )
                {
                        $page_data .= "</pre>\n" . $line . "\n";
                        $inPre = false;
                }
                else
                        $page_data .= $line . "\n";
        }
       
        // If we're still in a table, it means a table was not ended. Tell the user!
        if ($inTable) $page_data = "<p >" . i18n("There was an error during table generation. Please check to make sure you ended the last table correctly. Bellow is the output of the page:") . "</p ><hr />" . $page_data . "</table>";
       
        return $page_data;
}

function parse_updates($page_data)
{
        global $subscriptions;
       
        $loopcontrol = 0;
        $lastBegin = -1;
        while(true)
        {
                $begpos = strpos( $page_data, "\\updates(", $lastBegin + 1 ); //where does the first update listing begin
                if( $begpos === false )
                        break; //all update listings have been created, no need to check more
                $lastBegin = $begpos;
                $endpos = strpos( $page_data, ")", $begpos ); //end tag
               
                $currentData = substr( $page_data, $begpos, $endpos - $begpos + 1);
               
                $parameters = explode( "||", substr( $currentData, 9, strlen($currentData) - 10 ) );
               
                $limit = (is_numeric($parameters[0]) && $parameters[0] > 0) ? $parameters[0] : 10;
               
                $rendered = "";
                if( count( $subscriptions->updates ) > 0 )
                {
                        krsort($subscriptions->updates);
                        $counter = 1;
                        $rendered .= "<div class=\"updates_tiles\">";
                        foreach( $subscriptions->updates as $key => $value )
                        {
                                if( !userAllows( $value["owner"], $value["viewLevel"] ) )
                                        continue;
                                if( $counter++ > $limit )
                                        break;
                               
                                $thumbData = getGlobalIDThumbnail( $value["globalID"] );
                                $authorAndTime = i18n( "By ##0## on ##1##", array( parse_profilelinks( "%%" . $value["owner"] . "%%" ), formatTime( $value["timestamp"] ) ) );
                                $thumbnailURI = getGlobalIDThumbnail($value["globalID"]);
                               
                                $rendered .= "<div class=\"updates_tile\"><a
                                        href=\""
. globalIDtoURL( $value["globalID"] ) . "\" class=\"updates_tile\"><img class=\"updates_tile\" src=\"" . $thumbData["uri"] . "\" width=\"" . $thumbData["width"] . "\" height=\"" . $thumbData["height"] . "\" alt=\"" . $value["subject"] . "\"
                                        /></a><span class=\"updates_authorandtime\">$authorAndTime</span></div>"
;
                               
                        }
                        if( $limit < count($subscriptions->updates) )
                                $rendered .= "<div class=\"updates_more\">" . drawCommand( i18n("More updates ##0##", array("&raquo;") ), i18n("Show the full updates page"), globalIDtoURL("updates") ) . "</div>";
                        $rendered .= "</div>";
                }
                else
                        $rendered .= renderInformationBox( i18n("No updates"), i18n("Sorry, there are currently no updates to show you - please wait for someone to upload images to a gallery, a document to documents, an entry in a discussion, or make a comment, or better yet - do so yourself!") );
               
                $page_data = str_replace( $currentData, $rendered, $page_data );
               
                //loop infinity control, there should never be more than 1000 updates on one page anyway
                if ($loopcontrol ++ > 1000)
                        break;
        }
       
        return $page_data;
}

// BEGIN Copied list code {
/*
The following code was created by Keith Devens of www.keithdevent.com, and modified for use here
*/


global $markup_list_types, $markup_list_subtypes;
$markup_list_types = array("*" => "ul", "+" => "ul", "-" => "ul", "#" => "ol");
$markup_list_subtypes = array("1" => "decimal", "a" => "lower-alpha", "A" => "upper-alpha", "i" => "lower-roman", "I" => "upper-roman", "~" => "none");
define("MARKUP_STATE_LIST",       1);

function parse_lists($page_data) {
    global $markup_list_types;
    $str_arr = explode("\n", $page_data);
    $line_count = count($str_arr);
    $list_level = 0;
    $previous_list_stack = array();
        $current_state = "";
    for($n = 0; $n<$line_count; $n++)
        {
        $line = $str_arr[$n];
        $previous_state = $current_state;
        $current_state = "";
        $prepend = "";
        $append = "";
       
        if(preg_match("/^\<p \>((?:(?:[*+-]~?|#[1aAiI]?)\s*)+) \s?(.*)$/", $line, $matches)){
            $current_state = MARKUP_STATE_LIST;
            preg_match_all("/((\<p \>)*)[*+-]~?|#[1aAiI]?/", $matches[1], $list_begins);
        }
        if(    $previous_state == MARKUP_STATE_LIST  and $current_state != MARKUP_STATE_LIST) {$prepend .= end_lists(count($list_begins[0]), $list_begins[0]); $previous_list_stack = array();}
   
        if($current_state == MARKUP_STATE_LIST){ #lists
#            echo "<br>List begins is: <br>";
#            verbatim($list_begins, true);
           $line = list_item($previous_list_stack, $list_begins[0], $matches[2]);
        }
        $str_arr[$n] = $prepend . $line . $append;
    }
    $line = "";
    #end any remaining states
   if(    $current_state == MARKUP_STATE_LIST) {$line .= end_lists(count($list_begins[0]), $list_begins[0]); $previous_list_stack = array();}
    return implode("\n", $str_arr);
}

function print_list_item($depth, $text, $end_list_first = false){
    return ($end_list_first ? "</li>\n" : "") . str_repeat("\t", $depth) . "<li>$text";
}
function start_lists(&$previous_list_stack, $new_list_stack){
#function start_lists($current_depth, $list_stack, &$previous_list_stack, $text){
   global $markup_list_types, $markup_list_subtypes;
    #copy from list stack to previous list stack, starting at current depth
   $output = "";
    $new_list_level = count($new_list_stack);
    $n = count($previous_list_stack);
    if($n > 0){$output .= "\n";}
    for(;$n < $new_list_level; $n++){
        $list_type = $new_list_stack[$n];
        $output .= str_repeat("\t", $n) . "<" . $markup_list_types[$list_type{0}] . " " .
            ($list_type{1} ? " style=\"list-style-type: {$markup_list_subtypes[$list_type{1}]}\"" : "") .
        ">\n";
        if($n+1 < $new_list_level){
            $output .= str_repeat("\t", $n) . "<li>\n";
        }
        $previous_list_stack[$n] = $list_type;
    }
    return $output;
}
function end_lists($how_many, &$previous_list_stack){
    global $markup_list_types;
    #pop $how_many lists of the previous_list_stack
   $output = "</li>\n";
    $previous_count = count($previous_list_stack);
    $n = 0;
    while($n++ < $how_many){
        $previous_count--;
        $list_type = array_pop($previous_list_stack);
        $list_type = $list_type{0};
        /* Turn off error reporting here, because str_repeat will toss out an error if $previous_count == 0 */
        $errorlevel=error_reporting();
        error_reporting(1);
        $output .= str_repeat("\t", $previous_count) . "</$markup_list_types[$list_type]>\n";
        error_reporting($errorlevel);
        /* Turn error reporting back on */
        if($previous_count > 0){
            $output .= str_repeat("\t", $previous_count) . "</li>\n";
        }
    }
    if($previous_count == 0){
        $output .= "\n";
    }
    return $output;
}
function list_item(&$previous_list_stack, $new_list_stack, $text){
    $previous_depth = count($previous_list_stack);
    $new_depth      = count($new_list_stack);
    $line = "";

    if($previous_depth > $new_depth){
        #we're going down in levels
       $line .= end_lists($previous_depth - $new_depth, $previous_list_stack);
        $ended_lists = true;
    }
    #now, new depth will be >= previous depth
   if($previous_list_stack == $new_list_stack){
        #if the new list spec was a "subset" of the other, then you're good to just print out a list item
       $line .= print_list_item($new_depth, $text, ($ended_lists ? false : true));
    }else{
        #the new list is different than the old list
       #start at the beginning of both lists (since they're now the same size)
       # and go until you find a difference
       $n = 0;
        while($n < $previous_depth){
            if($previous_list_stack[$n] != $new_list_stack[$n]){
                #you found the start of the differences
               #pop the old list until you're at the current level
               $line .= end_lists($previous_depth - $n, $previous_list_stack);
                #now you can just add on the new list stack stuff
               break;
            }else{
                $n++;
            }
        }
        $line .= start_lists($previous_list_stack, $new_list_stack);
        $line .= print_list_item($new_depth, $text);
    }
    return $line;
}
// END Copied list code }

?>