00001 <?PHP
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 function parse_wikilinks($page_data) {
00018         global $setup_folder, $language, $page_id, $systemOptions;
00019 
00020         while (true) {
00021                 $begpos = strpos($page_data, "(("); 
00022                 if ($begpos === false) break; 
00023                 $midpos = strpos($page_data, "||", $begpos); 
00024                 $endpos = strpos($page_data, "))", $begpos); 
00025                 
00026                 
00027                 if ($endpos === false) {
00028                         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;
00029                 }
00030 
00031                 if ($midpos && $midpos < $endpos) {
00032                         $temp_page = substr($page_data, $begpos + 2, $midpos - ($begpos + 2));
00033                         $temp_link = substr($page_data, $midpos + 2, $endpos - ($midpos + 2));
00034                 } else {
00035                         $temp_page = substr($page_data, $begpos + 2, $endpos - ($begpos + 2));
00036                         $temp_link = $temp_page;
00037                 }
00038 
00039                 
00040                 $temp_link = preg_replace("/{([^<\}\{]+)\|\|([^<\}\{]+)\|\|([^<\}\{]+)\|\|([^<\}\{]+)}/is", "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/files/$1\" alt=\"$2\" width=\"$3\" align=\"$4\" />", $temp_link); 
00041                 $temp_link = preg_replace("/{([^<\}\{]+)\|\|([^<\}\{]+)\|\|([^<\}\{]+)}/is", "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/files/$1\" alt=\"$2\" align=\"$3\" />", $temp_link); 
00042                 $temp_link = preg_replace("/{([^<\}\{]+)\|\|([^<\}\{]+)}/is", "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/files/$1\" alt=\"$2\" />", $temp_link); 
00043 
00044                 $temp_id = getpage_id($setup_folder, $temp_page);
00045 
00046                 if( $systemOptions["humanurls"] == 1 )
00047                         $starttag = "<a title=\"$temp_page\" href=\"" . globalIDtoURL("content/$language/" . urlencode($temp_page) ) . "\">";
00048                 else
00049                 {
00050                         if ($temp_id && $temp_id > -1) {
00051                                 if (is_array($temp_id)) { 
00052                                         $starttag = "<a title=\"$temp_page\" href=\"" . globalIDtoURL("content/$language/" . urlencode($temp_page) ) . "\">";
00053                                 } else { 
00054                                         $starttag = "<a title=\"$temp_page\" href=\"" . globalIDtoURL("content/$language/$temp_id") . "\">";
00055                                 }
00056                         } else {
00057                                 $starttag = "<a title=\"$temp_page\" href=\"" . globalIDtoURL("content/$language/" . urlencode($temp_page) ) . "\">";
00058                         }
00059                 }
00060                 
00061                 $temp = substr($page_data, 0, $begpos);
00062                 if ($temp_id != $page_id) { 
00063                         $temp .= "$starttag$temp_link</a>";
00064                 } else {
00065                         $temp .= $temp_link;
00066                 }
00067                 $temp .= substr($page_data, $endpos + 2);
00068                 $page_data = $temp;
00069                 if ($loopcontrol ++ > 1000) break; 
00070         }
00071         return $page_data;
00072 }
00073 
00074 function parse_externallinks($page_data) {
00075         global $setup_folder, $language;
00076 
00077         while (true) {
00078                 $begpos = strpos($page_data, "[["); 
00079                 if ($begpos === false) break; 
00080                 $midpos = strpos($page_data, "||", $begpos); 
00081                 $secpos = strpos($page_data, "||", $midpos + 1); 
00082                 $endpos = strpos($page_data, "]]", $begpos); 
00083 
00084                 
00085                 if ($endpos === false) {
00086                         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;
00087                 }
00088                 
00089                 
00090                 if ($secpos and $secpos < $endpos) {
00091                         $temp_page = substr($page_data, $begpos + 2, $midpos - ($begpos + 2));
00092                         $temp_tip  = substr($page_data, $midpos + 2, $secpos - ($midpos + 2));
00093                         $temp_link = substr($page_data, $secpos + 2, $endpos - ($secpos + 2));
00094                 } else if ($midpos and $midpos < $endpos) {
00095                         $temp_page = substr($page_data, $begpos + 2, $midpos - ($begpos + 2));
00096                         $temp_tip  = $temp_page;
00097                         $temp_link = substr($page_data, $midpos + 2, $endpos - ($midpos + 2));
00098                 } else {
00099                         $temp_page = substr($page_data, $begpos + 2, $endpos - ($begpos + 2));
00100                         $temp_link = $temp_page;
00101                 }
00102 
00103                 
00104                 
00105                 if (strpos($temp_page, ":") < 1) {
00106                         if (strpos($temp_page, "@") > 1) { 
00107                                 $temp_page = "mailto:$temp_page";
00108                         } else { 
00109                                 $temp_page = "http://$temp_page";
00110                         }
00111                 }
00112                 $starttag = "<a href=\"$temp_page\" title=\"$temp_tip\" target=\"_new\">";
00113 
00114                 $temp = substr($page_data, 0, $begpos);
00115                 $temp .= "$starttag$temp_link<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/images/external.png\" width=\"7\" height=\"11\" alt=\"-\" /></a>";
00116                 $temp .= substr($page_data, $endpos + 2);
00117                 $page_data = $temp;
00118                 if ($loopcontrol ++ > 1000) break; 
00119         }
00120         return $page_data;
00121 }
00122 
00123 
00124 
00125 function parse_tables($page_data)
00126 {
00127         
00128         if( !strstr($page_data, "<p >//</p >") )
00129                 return $page_data;
00130         
00131         $lines = explode("\n", $page_data);
00132         $page_data = ""; 
00133         $inTable = false;
00134         $firstRow = true;
00135         
00136         foreach($lines as $line)
00137         {
00138                 switch($line)
00139                 {
00140                 case "<p >//</p >": 
00141                 case "<p >//>></p >": 
00142                         
00143                         if ($inTable)
00144                         {
00145                                 $page_data .= " </tr>\n</table>\n";
00146                                 $inTable = false;
00147                         }
00148                         else
00149                         {
00150                                 if( $line == "<p >//</p >" )
00151                                         $page_data .= "<table class=\"wikitable\">\n";
00152                                 else if( $line == "<p >//>></p >" )
00153                                         $page_data .= "<table style=\"float: right;\" class=\"wikitable wikitableright\">\n";
00154                                         
00155                                 $inTable = true;
00156                                 $firstRow = true; 
00157                         }
00158                         break;
00159                 case "<p >/</p >":
00160                         if ($firstRow)
00161                         {
00162                                 $page_data .= " <tr class=\"wikitable\">\n";
00163                                 $firstRow = false;
00164                         }
00165                         else
00166                         {
00167                                 $page_data .= " </tr><tr class=\"wikitable\">\n";
00168                         }
00169                         break;
00170                 default:
00171                         
00172                         if( $inTable )
00173                         {
00174                                 if( substr($line, 0, 3) == "<h2" )
00175                                 {
00176                                         $page_data .= "         <th class=\"wikitable\">" . preg_replace("/<h2 name=\"[\d]+-[\d]+\">([^<]+)<\/h2>/is", "<p class=\"wikitable\">$1</p >", $line) . "</th>\n";
00177                                 }
00178                                 else
00179                                 {
00180                                         $replace[] = "<p >||";
00181                                         $with[] = "<p class=\"wikitable wikicenteralign\">";
00182                                         
00183                                         $replace[] = "<p >>>";
00184                                         $with[] = "<p class=\"wikitable wikirightalign\">";
00185                                         
00186                                         $replace[] = "<p >";
00187                                         $with[] = "<p class=\"wikitable\">";
00188                                         
00189                                         $page_data .= "         <td class=\"wikitable\">" . str_replace( $replace, $with, $line ) . "</td>\n";
00190                                 }
00191                         }
00192                         
00193                         else
00194                         {
00195                                 $page_data .= $line . "\n";
00196                         }
00197                 }
00198         }
00199         
00200         
00201         if( $inTable )
00202                 $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>";
00203         
00204         return $page_data;
00205 }
00206 
00207 function parse_profilelinks($page_data, $module = "") {
00208         global $setup_folder, $language;
00209         
00210         if( $page_data == "%%%%" ) 
00211                 return i18n("Nobody");
00212         
00213         if( $module != "" )
00214                 $module = "/$module";
00215         
00216         while (true) {
00217                 $begpos = strpos($page_data, "%%"); 
00218                 if ($begpos === false) break; 
00219                 $midpos = strpos($page_data, "||", $begpos); 
00220                 $endpos = strpos($page_data, "%%", $begpos + 2); 
00221                 
00222                 
00223                 if ($endpos === false) {
00224                         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;
00225                 }
00226                 
00227                 if ($midpos && $midpos < $endpos) { 
00228                         $temp_title = substr($page_data, $begpos + 2, $midpos - ($begpos + 2));
00229                         $temp_id = substr($page_data, $midpos + 2, $endpos - ($midpos + 2));
00230                         
00231                         $temp_fullname = $temp_title;
00232 
00233                         
00234                         $temp_title = preg_replace("/{([^<\}\{]+)\|\|([^<\}\{]+)\|\|([^<\}\{]+)\|\|([^<\}\{]+)}/is", "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/files/$1\" alt=\"$2\" width=\"$3\" align=\"$4\" />", $temp_title); 
00235                         $temp_title = preg_replace("/{([^<\}\{]+)\|\|([^<\}\{]+)\|\|([^<\}\{]+)}/is", "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/files/$1\" alt=\"$2\" align=\"$3\" />", $temp_title); 
00236                         $temp_title = preg_replace("/{([^<\}\{]+)\|\|([^<\}\{]+)}/is", "<img border=\"0\" src=\"" . siteURL(true) . "$setup_folder/files/$1\" alt=\"$2\" />", $temp_title); 
00237                 } else {
00238                         $temp_title = substr($page_data, $begpos + 2, $endpos - ($begpos + 2));
00239                         $temp_id = $temp_title;
00240                         $temp_fullname = getUserInfo($temp_id, "name");
00241                         if ($temp_fullname !=  i18n("No ##0## information\n", array($which_info)) && $temp_fullname != i18n("Unknown user"))
00242                         {
00243                             $temp_title = $temp_fullname;
00244                             $temp_fullname = "<img src=\"" . siteURL(true) . getAvatarThumbnail( $temp_id, true ) . "\" alt=\"$temp_fullname\" /><small> </small>" . $temp_title;
00245                         }
00246                 }
00247 
00248                 $starttag = "<a class=\"profile_link\" title=\"$temp_title\" href=\"" . globalIDtoURL("user/$temp_id" . $module) . "\">";
00249                 $temp = substr($page_data, 0, $begpos);
00250                 $temp .= "$starttag$temp_fullname</a>";
00251                 $temp .= substr($page_data, $endpos + 2);
00252                 $page_data = $temp;
00253                 if ($loopcontrol ++ > 1000) die("Loop infinity control has noticed more than 1000 loops - something is wrong!"); 
00254         }
00255         return $page_data;
00256 }
00257 
00258 function parse_userlist_control($page_data) {
00259 
00260         if ($_REQUEST["userlist_per_page"] == "" && isAuth()) {
00261                 $userlist_per_page = getUserInfo(currentUser(), "userlist_per_page");
00262         } else if (isAuth()) {
00263                 saveUserInfo(currentUser(), "userlist_per_page", $_REQUEST["userlist_per_page"]);
00264                 $userlist_per_page = $_REQUEST["userlist_per_page"];
00265         } else {
00266                 $userlist_per_page = 9; 
00267         }
00268         if ($_REQUEST["userlist_list_style"] == "" && isAuth()) {
00269                 $userlist_list_style = getUserInfo(currentUser(), "userlist_list_style");
00270         } else if (isAuth()) {
00271                 saveUserInfo(currentUser(), "userlist_list_style", $_REQUEST["userlist_list_style"]);
00272                 $userlist_list_style = $_REQUEST["userlist_list_style"];
00273         } else {
00274                 $userlist_list_style = "threeup"; 
00275         }
00276 
00277         switch ($userlist_per_page) {
00278         case 3:
00279                 $current_3 = " selected"; break;
00280         case 27:
00281                 $current_27 = " selected"; break;
00282         case 99:
00283                 $current_99 = " selected"; break;
00284         case 9:
00285         default:
00286                 $current_9 = " selected";
00287         }
00288         
00289         switch ($userlist_list_style) {
00290         case "description":
00291                 $current_description = " selected"; break;
00292         case "bigtable":
00293                 $current_bigtable = " selected"; break;
00294         case "table":
00295                 $current_table = " selected"; break;
00296         case "heading":
00297                 $current_heading = " selected"; break;
00298         case "paragraph":
00299                 $current_paragraph = " selected"; break;
00300         case "shortparagraph":
00301                 $current_shortparagraph = " selected"; break;
00302         case "list":
00303                 $current_list = " selected"; break;
00304         case "shortlist":
00305                 $current_shortlist = " selected"; break;
00306         case "threeup":
00307         default:
00308                 $current_threeup = " selected";
00309         }
00310         
00311         $searchterm = stripslashes($_POST["userlist_search"]);
00312 
00313         $userlist_controller = "
00314         <form class=\"userlist_controller\" name=\"userlist_controller\" action=\"" . thisPageURL() . "\" method=\"post\">
00315         <span class=\"userlist_per_page_header\">" . i18n("Users per page:") . "</span>
00316         <select name=\"userlist_per_page\" class=\"userlist_per_page\" onchange=\"document.userlist_controller.submit();\">
00317         <option value=\"3\"$current_3>3</option>
00318         <option value=\"9\"$current_9>9</option>
00319         <option value=\"27\"$current_27>27</option>
00320         <option value=\"99\"$current_99>99</option>
00321         </select>
00322         <span class=\"userlist_list_style_header\">" . i18n("Listing style") . "</span>
00323         <select name=\"userlist_list_style\" class=\"userlist_list_style\">
00324         <option value=\"threeup\"$current_threeup>" . i18n("Three-up") . "</option>
00325         <option value=\"description\"$current_description>" . i18n("Description") . "</option>
00326         <option value=\"bigtable\"$current_bigtable>" . i18n("Big table") . "</option>
00327         <option value=\"table\"$current_table>" . i18n("Table") . "</option>
00328         <option value=\"heading\"$current_heading>" . i18n("Headings") . "</option>
00329         <option value=\"paragraph\"$current_paragraph>" . i18n("Paragraph") . "</option>
00330         <option value=\"shortparagraph\"$current_shortparagraph>" . i18n("Short paragraph") . "</option>
00331         <option value=\"list\"$current_list>" .i18n("List") . "</option>
00332         <option value=\"shortlist\"$current_shortlist>" . i18n("Short list") . "</option>
00333         </select>
00334         <span class=\"userlist_search_header\">" . i18n("Search user##0##:", array( drawCommand( i18n("?"), i18n("Syntax help for userlist search"), globalIDtoURL("help/userlist/search"), "", "_blank" ) ) ) . "</span>
00335         <input type=\"text\" name=\"userlist_search\" class=\"userlist_search\" value=\"$searchterm\" />
00336         <input type=\"submit\" value=\"" . i18n("Apply") . "\" class=\"userlist_apply\" /></form>";
00337 
00338         return str_replace("\userlist_controller()", $userlist_controller, $page_data);
00339 }
00340 
00341 function parse_userlists($page_data, $is_menu_menu, $userlist = "", $module = "") {
00342         global $setup_folder, $language, $page_id, $userinfo_folder, $viewUser;
00343         
00344         if( $module == "" )
00345                 $module = "view";
00346         
00347         while (true) {
00348                 $begpos = strpos($page_data, "\userlist("); 
00349                 if ($begpos === false) break; 
00350                 $midpos = strpos($page_data, ",", $begpos); 
00351                 $endpos = strpos($page_data, ")", $begpos + 1); 
00352                 
00353                 
00354                 if ($endpos === false) {
00355                         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;
00356                 }
00357 
00358                 if ($midpos && $midpos < $endpos) {
00359                         $listtype = substr($page_data, $begpos + 10, $midpos - ($begpos + 10));
00360                         $listlimit = substr($page_data, $midpos + 1, $endpos - ($midpos + 1));
00361                 } else {
00362                         $listtype  = substr($page_data, $begpos + 10, $endpos - ($begpos + 10));
00363                         $listlimit = 0;
00364                 }
00365                 if (!$is_menu_menu && isAuth()) {
00366                         if (getUserInfo(currentUser(), "userlist_list_style") != i18n("No ##0## information\n", array("userlist_list_style"))) $listtype = getUserInfo(currentUser(), "userlist_list_style");
00367                         if (getUserInfo(currentUser(), "userlist_per_page") != i18n("No ##0## information\n", array("userlist_per_page"))) $listlimit = getUserInfo(currentUser(), "userlist_per_page");
00368                 }
00369                 if ($_REQUEST["userlist_list_style"] != "") $listtype = $_REQUEST["userlist_list_style"];
00370                 if ($_REQUEST["userlist_per_page"] != "") $listlimit = $_REQUEST["userlist_per_page"];
00371                 
00372                 if ($listlimit == "" || $listlimit == -1) $listlimit = 9;
00373                 if ($listtype == "") $listtype = "shortparagraph";
00374                 
00375                 if (!is_array($userlist)) $userlist = allUsersArray();
00376                 
00377                 
00378                 if( array_key_exists( "userlist_search", $_POST ) && $_POST["userlist_search"] != "" )
00379                 {
00380                         $searchterm = stripslashes($_POST["userlist_search"]);
00381                         $foundUsers = array();
00382                         foreach( $userlist as $key => $value )
00383                                 if( strpos( $value, $searchterm ) !== false  || strpos( getUserInfo( $value, "name", " " ), $searchterm ) !== false )
00384                                         $foundUsers[] = $value;
00385                         $userlist = $foundUsers;
00386                 }
00387                 
00388                 if ($viewUser != "") $userid = "&user_id=" . $viewUser;
00389                 if ($listlimit > 0) {
00390                         $usercount = count($userlist);
00391                         $userlist = array_chunk($userlist, $listlimit);
00392                         $userlist_count = count($userlist);
00393                         if ($_REQUEST["userlist_page"] == "") { $userlist_page = 0; } else { $userlist_page = $_REQUEST["userlist_page"]; }
00394                         $listpage = "&userlist_page=$userlist_page";
00395                         $userlist_numberofpages = count($userlist);
00396                         $userlist = $userlist[$userlist_page];
00397                         $navigation = "<form name=\"profilelist_navigation\" action=\"" . thispageurl() . "\" method=\"post\"><p class=\"profilelist_navigation\">";
00398                         
00399                         if ($userlist_page > 0) {
00400                                 $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=\"|<\" /></a><a
00401                                                 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=\"<\" /></a>";
00402                         } else {
00403                                 $navigation .= "<img src=\"" . siteURL(true) . "$setup_folder/images/nav-first.png\" border=\"0\" class=\"profilelist_navigation\" width=\"10\" height=\"10\" alt=\"|<\" /><img src=\"" . siteURL(true) . "$setup_folder/images/nav-prev.png\" border=\"0\" class=\"profilelist_navigation\" width=\"10\" height=\"10\" alt=\"<\" />";
00404                         }               
00405                         
00406                         $currentbegin = ($userlist_page * $listlimit) + 1;
00407                         $currentend = ($userlist_page * $listlimit) +  $listlimit;
00408                         if ($currentend > $usercount) $currentend = $usercount;
00409                         if ($userlist_count > 0) {
00410                                 $navigation .= "<select class=\"userlist_pageselector\" name=\"userlist_page\" onchange=\"document.profilelist_navigation.submit();\">";
00411                                 for ($i = 0; $i < $userlist_count; $i++) {
00412                                         if ($currentbegin == (($i * $listlimit) + 1)) {
00413                                                 $navigation .= "<option value=\"$i\" selected>" . (($i * $listlimit) + 1) . "-" . (($i * $listlimit) + $listlimit) . "</option>";
00414                                         } else {
00415                                                 $navigation .= "<option value=\"$i\">" . (($i * $listlimit) + 1) . "-" . (($i * $listlimit) + $listlimit) . "</option>";
00416                                         }
00417                                 }
00418                                 $navigation .= "</select>/$usercount";
00419                         }
00420                         
00421                         if ($userlist_page < ($userlist_count - 1)) {
00422                                 $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=\">\" /></a><a
00423                                         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=\">|\" /></a>";
00424                         } else {
00425                                 $navigation .= "<img src=\"" . siteURL(true) . "$setup_folder/images/nav-next.png\" border=\"0\" class=\"profilelist_navigation\" width=\"10\" height=\"10\" alt=\">\" /><img src=\"" . siteURL(true) . "$setup_folder/images/nav-last.png\" border=\"0\" class=\"profilelist_navigation\" width=\"10\" height=\"10\" alt=\">|\" />";
00426                         }
00427                         
00428                         $navigation .= "</p ></form>";
00429                         
00430                 } else {
00431                         $navigation = "<p class=\"profilelist_navigation\">" . i18n("Users") . ": " . count($userlist) . "</p>"; 
00432                 }
00433 
00434                 $tempdata = $navigation; 
00435                 if( count( $userlist ) > 0 )
00436                 {
00437                         switch (strtolower($listtype)) {
00438                         case "shortlist":
00439                                 $tempdata .= "
00440                                 <ul class=\"profile_list\">";
00441                                 foreach($userlist as $key => $value) {
00442                                         $tempdata .= "
00443                                         <li><a class=\"profile_list\" href=\"" . globalIDtoURL("user/$value/$module") . "\">$value</a></li>";
00444                                 }
00445                                 $tempdata .= "
00446                                 </ul>";
00447                                 break;
00448                         case "list":
00449                                 $tempdata .= "
00450                                 <ul class=\"profile_list\">";
00451                                 foreach($userlist as $key => $value) {
00452                                         $tempdata .= "
00453                                         <li><a class=\"profile_list\" href=\"" . globalIDtoURL("user/$value/$module") . "\">" . getUserInfo($value, "name") . " ($value)</a></li>";
00454                                 }
00455                                 $tempdata .= "
00456                                 </ul>";
00457                                 break;
00458                         case "shortparagraph":
00459                                 foreach($userlist as $key => $value) {
00460                                         $tempdata .= "
00461                                         <p ><a class=\"profile_list\" href=\"" . globalIDtoURL("user/$value/$module") . "\">$value</a></p >";
00462                                 }
00463                                 break;
00464                         case "paragraph":
00465                                 foreach($userlist as $key => $value) {
00466                                         $tempdata .= "
00467                                         <p ><a class=\"profile_list\" href=\"" . globalIDtoURL("user/$value/$module") . "\">" . getUserInfo($value, "name") . " ($value)</a></p >";
00468                                 }
00469                                 break;
00470                         case "heading":
00471                                 foreach($userlist as $key => $value) {
00472                                         $avatarfile = getAvatar($value);
00473                                         $avatarthumbfile = getAvatarThumbnail($value);
00474                                         list($avatarwidth,$avatarheight) = getAvatarThumbSize($value);
00475                                         $avatarfile = siteURL(true) . $avatarfile;
00476                                         $avatarthumbfile = siteURL(true) . $avatarthumbfile;
00477                                         
00478                                         $profile = getUserInfo($value, "profile");
00479                                         $profile = substr($profile, 0, strposnth($profile, "\n", 3));
00480                                         if ($profile == "")
00481                                                 $profile = getUserInfo($value, "profile");
00482                                         
00483                                         $tempdata .= "
00484                                         <table width=\"100%\"><tr class=\"profile_list\"><td class=\"profile_list\">
00485                                         <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>
00486                                         <a class=\"profile_list\" href=\"" . globalIDtoURL("user/$value/$module") . "\">" . getUserInfo($value, "name") . " ($value)</a></h3>
00487                                         " . parse_page_data($profile) . "
00488                                         </td></tr></table>";
00489                                 }
00490                                 break;
00491                         case "threeup":
00492                                 $tempdata .= "
00493                                 <table class=\"profile_list\" width=\"100%\">";
00494                                 $i = 0;
00495                                 foreach($userlist as $key => $value) {
00496                                         $avatarfile = getAvatar($value);
00497                                         $avatarthumbfile = getAvatarThumbnail($value);
00498                                         list($avatarwidth,$avatarheight) = getAvatarThumbSize($value);
00499                                         $avatarfile = siteURL(true) . $avatarfile;
00500                                         $avatarthumbfile = siteURL(true) . $avatarthumbfile;
00501                                         
00502                                         if ($i == 0) {
00503                                                 $i = 1;
00504                                                 $tempdata .= "
00505                                                 <tr class=\"profile_list\">
00506                                                         <td width=\"33%\" class=\"profile_list\">
00507                                                         <a class=\"profile_list\" href=\"" . globalIDtoURL("user/$value/$module") . "\">
00508                                                                 <div class=\"profile_list\">
00509                                                                         <img border=\"0\" src=\"$avatarthumbfile\" width=\"$avatarwidth\" height=\"$avatarheight\" alt=\"" . i18n("##0##'s avatar", array(getUserInfo($value, "name"))) . "\" />
00510                                                                         <br />" . getUserInfo($value, "name") . " ($value)
00511                                                                 </div>
00512                                                         </a>
00513                                                         </td>";
00514                                         } else if ($i == 1) {
00515                                                 $i = 2;
00516                                                 $tempdata .= "
00517                                                         <td width=\"34%\" class=\"profile_list\">
00518                                                         <a class=\"profile_list\" href=\"" . globalIDtoURL("user/$value/$module") . "\">
00519                                                                 <div class=\"profile_list\">
00520                                                                         <img border=\"0\" src=\"$avatarthumbfile\" width=\"$avatarwidth\" height=\"$avatarheight\" alt=\"" . i18n("##0##'s avatar", array(getUserInfo($value, "name"))) . "\" />
00521                                                                         <br />" . getUserInfo($value, "name") . " ($value)
00522                                                                 </div>
00523                                                         </a>
00524                                                         </td>";
00525                                         } else {
00526                                                 $i = 0;
00527                                                 $tempdata .= "
00528                                                         <td width=\"33%\" class=\"profile_list\">
00529                                                         <a class=\"profile_list\" href=\"" . globalIDtoURL("user/$value/$module") . "\">
00530                                                                 <div class=\"profile_list\">
00531                                                                         <img border=\"0\" src=\"$avatarthumbfile\" width=\"$avatarwidth\" height=\"$avatarheight\" alt=\"" . i18n("##0##'s avatar", array(getUserInfo($value, "name"))) . "\" />
00532                                                                         <br />" . getUserInfo($value, "name") . " ($value)
00533                                                                 </div>
00534                                                         </a>
00535                                                         </td>
00536                                                 </tr>";
00537                                         }
00538                                 }
00539                                 if ($i == 2) $tempdata .= "<td class=\"profile_list\"> </td>";
00540                                 if ($i == 1) $tempdata .= "<td class=\"profile_list\"> </td><td class=\"profile_list\"> </td>";
00541                                 $tempdata .= "
00542                                 </table>";
00543                                 break;
00544                         case "table":
00545                                 $tempdata .= "
00546                                 <table class=\"profile_list\" width=\"100%\">";
00547                                 foreach($userlist as $key => $value) {
00548                                         $avatarfile = getAvatar($value);
00549                                         $avatarthumbfile = getAvatarThumbnail($value);
00550                                         list($avatarwidth,$avatarheight) = getAvatarThumbSize($value);
00551                                         $avatarfile = siteURL(true) . $avatarfile;
00552                                         $avatarthumbfile = siteURL(true) . $avatarthumbfile;
00553                                         
00554                                         $profile = getUserInfo($value, "profile");
00555                                         $profile = substr($profile, 0, strposnth($profile, "\n", 3));
00556                                         if ($profile == "")
00557                                                 $profile = getUserInfo($value, "profile");
00558                                         
00559                                         $tempdata .= "
00560                                         <tr class=\"profile_list\">
00561                                         <th class=\"profile_list\"><a class=\"profile_list\" href=\"" . globalIDtoURL("user/$value/$module") . "\">" . getUserInfo($value, "name") . " ($value)</a></th>
00562                                         <th class=\"profile_list\">" . getUserInfo($value, "email") . "</th>
00563                                         </tr><tr class=\"profile_list\"><td class=\"profile_list\" colspan=\"2\">
00564                                         <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>
00565                                         " . parse_page_data($profile) . "
00566                                         </td>
00567                                         </tr>";
00568                                 }
00569                                 $tempdata .= "
00570                                 </table>";
00571                                 break;
00572                         case "bigtable":
00573                                 $tempdata .= "
00574                                 <table class=\"profile_list\" width=\"100%\">";
00575                                 foreach($userlist as $key => $value) {
00576                                         $avatarfile = getAvatar($value);
00577                                         $avatarthumbfile = getAvatarThumbnail($value);
00578                                         list($avatarwidth,$avatarheight) = getAvatarThumbSize($value);
00579                                         $avatarfile = siteURL(true) . $avatarfile;
00580                                         $avatarthumbfile = siteURL(true) . $avatarthumbfile;
00581                                         
00582                                         $profile = getUserInfo($value, "profile");
00583                                         
00584                                         $tempdata .= "
00585                                         <tr class=\"profile_list\">
00586                                         <th class=\"profile_list\"><a class=\"profile_list\" href=\"" . globalIDtoURL("user/$value/$module") . "\">" . getUserInfo($value, "name") . " ($value)</a></th>
00587                                         <th class=\"profile_list\">" . getUserInfo($value, "email") . "</th>
00588                                         </tr><tr class=\"profile_list\"><td class=\"profile_list\" colspan=\"2\">
00589                                         <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>
00590                                         " . parse_page_data($profile) . "
00591                                         </td>
00592                                         </tr>";
00593                                 }
00594                                 $tempdata .= "
00595                                 </table>";
00596                                 break;
00597                         case "description":
00598                         default:
00599                                 $tempdata .= "
00600                                 <dl class=\"profile_list\">";
00601                                 foreach($userlist as $key => $value) {
00602                                         $profile = getUserInfo($value, "profile");
00603                                         $profile = substr($profile, 0, strposnth($profile, "\n", 3));
00604                                         if ($profile == "")
00605                                                 $profile = getUserInfo($value, "profile");
00606                                         
00607                                         $tempdata .= "
00608                                         <dt class=\"profile_list\"><a class=\"profile_list\" href=\"" . globalIDtoURL("user/$value/$module") . "\">" . getUserInfo($value, "name") . " ($value)</a></dt>
00609                                         <dd class=\"profile_list\">" . parse_page_data($profile) . "</dd>";
00610                                 }
00611                                 $tempdata .= "
00612                                 </dl>";
00613                         }
00614                 }
00615                 else
00616                 {
00617                         $tempdata .= renderInformationBox( i18n("No users"), i18n("There were no users found fitting your request.") );
00618                 }
00619 
00620                 if (substr($page_data, $begpos - 4, 4) == "<p >" && substr($page_data, $endpos + 1, 5) == "</p >") {
00621                         $page_data = substr($page_data, 0, $begpos - 4) . $tempdata . substr($page_data, $endpos + 6);
00622                 } else {
00623                         $page_data = substr($page_data, 0, $begpos) . $tempdata . substr($page_data, $endpos + 1);
00624                 }
00625                 if ($loopcontrol ++ > 1000) die("Loop control spotted an error in the page data!"); 
00626         }
00627         return $page_data;
00628 }
00629 
00630 function parse_preformatted($page_data)
00631 {
00632         if (!strstr($page_data, "<p >:")) return $page_data; 
00633         $lines = explode("\n", $page_data);
00634         $page_data = ""; 
00635         $inPre = false;
00636         foreach($lines as $line)
00637         {
00638                 if( substr( $line, 0, 5 ) == "<p >:" )
00639                 {
00640                         if( !$inPre )
00641                         {
00642                                 $page_data .= "<pre class=\"wikipre\">\n";
00643                                 $inPre = true;
00644                         }
00645                         $page_data .= substr( $line, 5, -5 ) . "\n";
00646                 }
00647                 else if( $inPre && substr( $line, 0, 5 ) != "<p >:" )
00648                 {
00649                         $page_data .= "</pre>\n" . $line . "\n";
00650                         $inPre = false;
00651                 }
00652                 else
00653                         $page_data .= $line . "\n";
00654         }
00655         
00656         
00657         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>";
00658         
00659         return $page_data;
00660 }
00661 
00662 
00663 
00664 
00665 
00666 
00667 global $markup_list_types, $markup_list_subtypes;
00668 $markup_list_types = array("*" => "ul", "+" => "ul", "-" => "ul", "#" => "ol");
00669 $markup_list_subtypes = array("1" => "decimal", "a" => "lower-alpha", "A" => "upper-alpha", "i" => "lower-roman", "I" => "upper-roman", "~" => "none");
00670 define("MARKUP_STATE_LIST",       1);
00671 
00672 function parse_lists($page_data) {
00673     global $markup_list_types;
00674     $str_arr = explode("\n", $page_data);
00675     $line_count = count($str_arr);
00676     $list_level = 0;
00677     $previous_list_stack = array();
00678     for($n = 0; $n<$line_count; $n++){
00679         $line = $str_arr[$n];
00680         $previous_state = $current_state;
00681         $current_state = "";
00682         $prepend = "";
00683         $append = "";
00684         
00685         if(preg_match("/^<p >((?:(?:[*+-]~?|#[1aAiI]?)\s*)+) \s?(.*)$/", $line, $matches)){
00686             $current_state = MARKUP_STATE_LIST;
00687             preg_match_all("/((<p >)*)[*+-]~?|#[1aAiI]?/", $matches[1], $list_begins);
00688         }
00689         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();}
00690     
00691         if($current_state == MARKUP_STATE_LIST){ #lists
00692 #            echo "<br>List begins is: <br>";
00693 #            verbatim($list_begins, true);
00694             $line = list_item($previous_list_stack, $list_begins[0], $matches[2]);
00695         }
00696         $str_arr[$n] = $prepend . $line . $append;
00697     }
00698     $line = "";
00699     #end any remaining states
00700     if(    $current_state == MARKUP_STATE_LIST) {$line .= end_lists(count($list_begins[0]), $list_begins[0]); $previous_list_stack = array();}
00701     return implode("\n", $str_arr);
00702 }
00703 
00704 function print_list_item($depth, $text, $end_list_first = false){
00705     return ($end_list_first ? "</li>\n" : "") . str_repeat("\t", $depth) . "<li>$text";
00706 }
00707 function start_lists(&$previous_list_stack, $new_list_stack){
00708 #function start_lists($current_depth, $list_stack, &$previous_list_stack, $text){
00709     global $markup_list_types, $markup_list_subtypes;
00710     #copy from list stack to previous list stack, starting at current depth
00711     $output = "";
00712     $new_list_level = count($new_list_stack);
00713     $n = count($previous_list_stack);
00714     if($n > 0){$output .= "\n";}
00715     for(;$n < $new_list_level; $n++){
00716         $list_type = $new_list_stack[$n];
00717         $output .= str_repeat("\t", $n) . "<" . $markup_list_types[$list_type{0}] . " " .
00718             ($list_type{1} ? " style=\"list-style-type: {$markup_list_subtypes[$list_type{1}]}\"" : "") .
00719         ">\n";
00720         if($n+1 < $new_list_level){
00721             $output .= str_repeat("\t", $n) . "<li>\n";
00722         }
00723         $previous_list_stack[$n] = $list_type;
00724     }
00725     return $output;
00726 }
00727 function end_lists($how_many, &$previous_list_stack){
00728     global $markup_list_types;
00729     #pop $how_many lists of the previous_list_stack
00730     $output = "</li>\n";
00731     $previous_count = count($previous_list_stack);
00732     $n = 0;
00733     while($n++ < $how_many){
00734         $previous_count--;
00735         $list_type = array_pop($previous_list_stack);
00736         $list_type = $list_type{0};
00737         
00738         $errorlevel=error_reporting();
00739         error_reporting(1);
00740         $output .= str_repeat("\t", $previous_count) . "</$markup_list_types[$list_type]>\n";
00741         error_reporting($errorlevel);
00742         
00743         if($previous_count > 0){
00744             $output .= str_repeat("\t", $previous_count) . "</li>\n";
00745         }
00746     }
00747     if($previous_count == 0){
00748         $output .= "\n";
00749     }
00750     return $output;
00751 }
00752 function list_item(&$previous_list_stack, $new_list_stack, $text){
00753     $previous_depth = count($previous_list_stack);
00754     $new_depth      = count($new_list_stack);
00755     $line = "";
00756 
00757     if($previous_depth > $new_depth){
00758         #we're going down in levels
00759         $line .= end_lists($previous_depth - $new_depth, $previous_list_stack);
00760         $ended_lists = true;
00761     }
00762     #now, new depth will be >= previous depth
00763     if($previous_list_stack == $new_list_stack){
00764         #if the new list spec was a "subset" of the other, then you're good to just print out a list item
00765         $line .= print_list_item($new_depth, $text, ($ended_lists ? false : true));
00766     }else{
00767         #the new list is different than the old list
00768         #start at the beginning of both lists (since they're now the same size)
00769         # and go until you find a difference
00770         $n = 0;
00771         while($n < $previous_depth){
00772             if($previous_list_stack[$n] != $new_list_stack[$n]){
00773                 #you found the start of the differences
00774                 #pop the old list until you're at the current level
00775                 $line .= end_lists($previous_depth - $n, $previous_list_stack);
00776                 #now you can just add on the new list stack stuff
00777                 break;
00778             }else{
00779                 $n++;
00780             }
00781         }
00782         $line .= start_lists($previous_list_stack, $new_list_stack);
00783         $line .= print_list_item($new_depth, $text);
00784     }
00785     return $line;
00786 }
00787 
00788 
00789 ?>