function HandleRecipeCheck($pagename, $auth = 'admin') { global $RecipeListUrl, $Version, $RecipeInfo, $RecipeCheckFmt, $PageStartFmt, $PageEndFmt; $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT); if (!$page) { Abort('?admin access required'); } $cvinfo = GetRecipeList($RecipeListUrl); if (!$cvinfo) { $msg = "Unable to retrieve cookbook data from {$RecipeListUrl}\n"; $allow_url_fopen = ini_get('allow_url_fopen'); if (!$allow_url_fopen) { $msg .= "\n <br /><br />It appears that your PHP environment isn't allowing\n the recipelist to be downloaded from pmwiki.org \n (allow_url_fopen = {$allow_url_fopen})."; } Abort($msg); } $rinfo['PmWiki:Upgrades'] = $Version; ScanRecipeInfo('cookbook', $cvinfo); foreach ((array) $RecipeInfo as $r => $v) { if (!@$v['Version']) { continue; } $r = preg_replace('/^(?!PmWiki:)(Cookbook[.:])?/', 'Cookbook:', $r); $rinfo[$r] = $v['Version']; } $markup = "!!Recipe status for {\$PageUrl}\n" . RecipeTable($rinfo, $cvinfo); $html = MarkupToHTML($pagename, $markup); SDV($RecipeCheckFmt, array(&$PageStartFmt, $html, &$PageEndFmt)); PrintFmt($pagename, $RecipeCheckFmt); }
function MarkupMarkup($pagename, $text, $opt = '') { $MarkupMarkupOpt = array('class' => 'vert'); $opt = array_merge($MarkupMarkupOpt, ParseArgs($opt)); $html = MarkupToHTML($pagename, $text, array('escape' => 0)); if (@$opt['caption']) $caption = str_replace("'", ''', "<caption>{$opt['caption']}</caption>"); $class = preg_replace('/[^-\\s\\w]+/', ' ', @$opt['class']); $sep = (strpos($class, 'horiz') !== false) ? '' : '</tr><tr>'; $pretext = str_replace(" ", " ", nl2br($text)); return Keep(@"<table class='markup $class' align='center'>$caption <tr><td class='markup1' valign='top'><code>$pretext</code></td>$sep<td class='markup2' valign='top'>$html</td></tr></table>"); }
function HandleEdit($pagename, $auth = 'edit') { global $IsPagePosted, $EditFields, $ChangeSummary, $EditFunctions, $EnablePost, $FmtV, $Now, $EditRedirectFmt, $PageEditForm, $HandleEditFmt, $PageStartFmt, $PageEditFmt, $PageEndFmt; SDV($EditRedirectFmt, '$FullName'); if (@$_POST['cancel']) { Redirect(FmtPageName($EditRedirectFmt, $pagename)); return; } Lock(2); $IsPagePosted = false; $page = RetrieveAuthPage($pagename, $auth, true); if (!$page) Abort("?cannot edit $pagename"); PCache($pagename,$page); $new = $page; foreach((array)$EditFields as $k) if (isset($_POST[$k])) $new[$k]=str_replace("\r",'',stripmagic($_POST[$k])); $new['csum'] = $ChangeSummary; if ($ChangeSummary) $new["csum:$Now"] = $ChangeSummary; $EnablePost &= preg_grep('/^post/', array_keys(@$_POST)); foreach((array)$EditFunctions as $fn) $fn($pagename,$page,$new); Lock(0); if ($IsPagePosted && !@$_POST['postedit']) { Redirect(FmtPageName($EditRedirectFmt, $pagename)); return; } $FmtV['$DiffClassMinor'] = (@$_POST['diffclass']=='minor') ? "checked='checked'" : ''; $FmtV['$EditText'] = str_replace('$','$',htmlspecialchars(@$new['text'],ENT_NOQUOTES)); $FmtV['$EditBaseTime'] = $Now; if (@$PageEditForm) { $form = ReadPage(FmtPageName($PageEditForm, $pagename), READPAGE_CURRENT); $FmtV['$EditForm'] = MarkupToHTML($pagename, $form['text']); } SDV($PageEditFmt, "<div id='wikiedit'> <h2 class='wikiaction'>$[Editing {\$FullName}]</h2> <form method='post' rel='nofollow' action='\$PageUrl?action=edit'> <input type='hidden' name='action' value='edit' /> <input type='hidden' name='n' value='\$FullName' /> <input type='hidden' name='basetime' value='\$EditBaseTime' /> \$EditMessageFmt <textarea id='text' name='text' rows='25' cols='60' onkeydown='if (event.keyCode==27) event.returnValue=false;' >\$EditText</textarea><br /> <input type='submit' name='post' value=' $[Save] ' />"); SDV($HandleEditFmt, array(&$PageStartFmt, &$PageEditFmt, &$PageEndFmt)); PrintFmt($pagename, $HandleEditFmt); }
function HandleRss($pagename) { global $RssMaxItems, $RssSourceSize, $RssDescSize, $RssChannelFmt, $RssChannelDesc, $RssTimeFmt, $RssChannelBuildDate, $RssItemsRDFList, $RssItemsRDFListFmt, $RssItems, $RssItemFmt, $HandleRssFmt, $FmtV; $t = ReadTrail($pagename, $pagename); $page = RetrieveAuthPage($pagename, 'read', false); if (!$page) { Abort("?cannot read {$pagename}"); } $cbgmt = $page['time']; $r = array(); for ($i = 0; $i < count($t) && count($r) < $RssMaxItems; $i++) { if (!PageExists($t[$i]['pagename'])) { continue; } $page = RetrieveAuthPage($t[$i]['pagename'], 'read', false); Lock(0); if (!$page) { continue; } $text = MarkupToHTML($t[$i]['pagename'], substr($page['text'], 0, $RssSourceSize)); $text = entityencode(preg_replace("/<.*?>/s", "", $text)); preg_match("/^(.{0,{$RssDescSize}}\\s)/s", $text, $match); $r[] = array('name' => $t[$i]['pagename'], 'time' => $page['time'], 'desc' => $match[1] . " ...", 'author' => $page['author']); if ($page['time'] > $cbgmt) { $cbgmt = $page['time']; } } SDV($RssChannelBuildDate, entityencode(gmdate('D, d M Y H:i:s \\G\\M\\T', $cbgmt))); SDV($RssChannelDesc, entityencode(FmtPageName('$Group.$Title', $pagename))); foreach ($r as $page) { $FmtV['$RssItemPubDate'] = gmstrftime($RssTimeFmt, $page['time']); $FmtV['$RssItemDesc'] = $page['desc']; $FmtV['$RssItemAuthor'] = $page['author']; $RssItemsRDFList[] = entityencode(FmtPageName($RssItemsRDFListFmt, $page['name'])); $RssItems[] = entityencode(FmtPageName($RssItemFmt, $page['name'])); } header("Content-type: text/xml"); PrintFmt($pagename, $HandleRssFmt); exit; }
function PrintDiff($pagename) { global $DiffShow, $DiffStartFmt, $TimeFmt, $DiffDelFmt, $DiffAddFmt, $DiffEndDelAddFmt, $DiffEndFmt, $DiffRestoreFmt, $FmtV, $LinkFunctions; $page = ReadPage($pagename); if (!$page) { return; } krsort($page); reset($page); $lf = $LinkFunctions; $LinkFunctions['http:'] = 'LinkSuppress'; $LinkFunctions['https:'] = 'LinkSuppress'; foreach ($page as $k => $v) { if (!preg_match("/^diff:(\\d+):(\\d+):?([^:]*)/", $k, $match)) { continue; } $diffclass = $match[3]; if ($diffclass == 'minor' && $DiffShow['minor'] != 'y') { continue; } $diffgmt = $match[1]; $FmtV['$DiffTime'] = strftime($TimeFmt, $diffgmt); $diffauthor = @$page["author:{$diffgmt}"]; if (!$diffauthor) { @($diffauthor = $page["host:{$diffgmt}"]); } if (!$diffauthor) { $diffauthor = "unknown"; } $FmtV['$DiffChangeSum'] = htmlspecialchars(@$page["csum:{$diffgmt}"]); $FmtV['$DiffHost'] = @$page["host:{$diffgmt}"]; $FmtV['$DiffAuthor'] = $diffauthor; $FmtV['$DiffId'] = $k; echo FmtPageName($DiffStartFmt, $pagename); $difflines = explode("\n", $v . "\n"); $in = array(); $out = array(); $dtype = ''; foreach ($difflines as $d) { if ($d > '') { if ($d[0] == '-' || $d[0] == '\\') { continue; } if ($d[0] == '<') { $out[] = substr($d, 2); continue; } if ($d[0] == '>') { $in[] = substr($d, 2); continue; } } if (preg_match("/^(\\d+)(,(\\d+))?([adc])(\\d+)(,(\\d+))?/", $dtype, $match)) { if (@$match[7] > '') { $lines = 'lines'; $count = $match[1] . '-' . ($match[1] + $match[7] - $match[5]); } elseif ($match[3] > '') { $lines = 'lines'; $count = $match[1] . '-' . $match[3]; } else { $lines = 'line'; $count = $match[1]; } if ($match[4] == 'a' || $match[4] == 'c') { $txt = str_replace('line', $lines, $DiffDelFmt[$match[4]]); $FmtV['$DiffLines'] = $count; echo FmtPageName($txt, $pagename); if ($DiffShow['source'] == 'y') { echo "<div class='diffmarkup'>", str_replace("\n", "<br />", htmlspecialchars(join("\n", $in))), "</div>"; } else { echo MarkupToHTML($pagename, preg_replace('/\\(:(.*?):\\)/', '[@$1@]', join("\n", $in))); } } if ($match[4] == 'd' || $match[4] == 'c') { $txt = str_replace('line', $lines, $DiffAddFmt[$match[4]]); $FmtV['$DiffLines'] = $count; echo FmtPageName($txt, $pagename); if ($DiffShow['source'] == 'y') { echo "<div class='diffmarkup'>", str_replace("\n", "<br />", htmlspecialchars(join("\n", $out))), "</div>"; } else { echo MarkupToHTML($pagename, preg_replace('/(\\(:.*?:\\))/', '[@$1@]', join("\n", $out))); } } echo FmtPageName($DiffEndDelAddFmt, $pagename); } $in = array(); $out = array(); $dtype = $d; } echo FmtPageName($DiffEndFmt, $pagename); echo FmtPageName($DiffRestoreFmt, $pagename); } $LinkFunctions = $lf; }
function MarkupMarkup($pagename, $text, $opt = '') { $MarkupMarkupOpt = array('class' => 'vert'); $opt = array_merge($MarkupMarkupOpt, ParseArgs($opt)); $html = MarkupToHTML($pagename, $text, array('escape' => 0)); if (@$opt['caption']) { $caption = str_replace("'", ''', "<caption>{$opt['caption']}</caption>"); } $class = preg_replace('/[^-\\s\\w]+/', ' ', @$opt['class']); if (strpos($class, 'horiz') !== false) { $sep = ''; $pretext = wordwrap($text, 40); } else { $sep = '</tr><tr>'; $pretext = wordwrap($text, 75); } return Keep("<table class='markup {$class}' align='center'>{$caption}\n <tr><td class='markup1' valign='top'><pre>{$pretext}</pre></td>{$sep}<td \n class='markup2' valign='top'>{$html}</td></tr></table>"); }
function FPLTemplate($pagename, &$matches, $opt) { global $Cursor, $FPLTemplatePageFmt, $RASPageName, $PageListArgPattern; SDV($FPLTemplatePageFmt, array('{$FullName}', '{$SiteGroup}.LocalTemplates', '{$SiteGroup}.PageListTemplates')); StopWatch("FPLTemplate begin"); $template = @$opt['template']; if (!$template) { $template = @$opt['fmt']; } $ttext = RetrieveAuthSection($pagename, $template, $FPLTemplatePageFmt); $ttext = PVSE(Qualify($RASPageName, $ttext)); ## save any escapes $ttext = MarkupEscape($ttext); ## remove any anchor markups to avoid duplications $ttext = preg_replace('/\\[\\[#[A-Za-z][-.:\\w]*\\]\\]/', '', $ttext); ## extract portions of template $tparts = preg_split('/\\(:(template)\\s+(\\w+)\\s*(.*?):\\)/i', $ttext, -1, PREG_SPLIT_DELIM_CAPTURE); ## handle (:template defaults:) $i = 0; while ($i < count($tparts)) { if ($tparts[$i] != 'template') { $i++; continue; } if ($tparts[$i + 1] != 'defaults' && $tparts[$i + 1] != 'default') { $i += 4; continue; } $opt = array_merge(ParseArgs($tparts[$i + 2], $PageListArgPattern), $opt); array_splice($tparts, $i, 3); } SDVA($opt, array('class' => 'fpltemplate', 'wrap' => 'div')); ## get the list of pages $matches = array_values(MakePageList($pagename, $opt, 0)); ## extract page subset according to 'count=' parameter if (@$opt['count']) { list($r0, $r1) = CalcRange($opt['count'], count($matches)); if ($r1 < $r0) { $matches = array_reverse(array_slice($matches, $r1 - 1, $r0 - $r1 + 1)); } else { $matches = array_slice($matches, $r0 - 1, $r1 - $r0 + 1); } } $savecursor = $Cursor; $pagecount = 0; $groupcount = 0; $grouppagecount = 0; $pseudovars = array('{$$PageCount}' => &$pagecount, '{$$GroupCount}' => &$groupcount, '{$$GroupPageCount}' => &$grouppagecount); foreach (preg_grep('/^[\\w$]/', array_keys($opt)) as $k) { if (!is_array($opt[$k])) { $pseudovars["{\$\${$k}}"] = htmlspecialchars($opt[$k], ENT_NOQUOTES); } } $vk = array_keys($pseudovars); $vv = array_values($pseudovars); $lgroup = ''; $out = ''; foreach ($matches as $i => $pn) { $group = PageVar($pn, '$Group'); if ($group != $lgroup) { $groupcount++; $grouppagecount = 0; $lgroup = $group; } $grouppagecount++; $pagecount++; $t = 0; while ($t < count($tparts)) { if ($tparts[$t] != 'template') { $item = $tparts[$t]; $t++; } else { list($when, $control, $item) = array_slice($tparts, $t + 1, 3); $t += 4; if (!$control) { if ($when == 'first' && $i != 0) { continue; } if ($when == 'last' && $i != count($matches) - 1) { continue; } } else { if ($when == 'first' || !isset($last[$t])) { $Cursor['<'] = $Cursor['<'] = (string) @$matches[$i - 1]; $Cursor['='] = $pn; $Cursor['>'] = $Cursor['>'] = (string) @$matches[$i + 1]; $curr = str_replace($vk, $vv, $control); $curr = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PageVar(\$pn, '\$2', '\$1')", $curr); if ($when == 'first' && $i > 0 && $last[$t] == $curr) { continue; } $last[$t] = $curr; } if ($when == 'last') { $Cursor['<'] = $Cursor['<'] = $pn; $Cursor['='] = (string) @$matches[$i + 1]; $Cursor['>'] = $Cursor['>'] = (string) @$matches[$i + 2]; $next = str_replace($vk, $vv, $control); $next = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PageVar(\$pn, '\$2', '\$1')", $next); if ($next == $last[$t] && $i != count($matches) - 1) { continue; } $last[$t] = $next; } } } $Cursor['<'] = $Cursor['<'] = (string) @$matches[$i - 1]; $Cursor['='] = $pn; $Cursor['>'] = $Cursor['>'] = (string) @$matches[$i + 1]; $item = str_replace($vk, $vv, $item); $item = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PVSE(PageVar(\$pn, '\$2', '\$1'))", $item); $out .= MarkupRestore($item); } } $class = preg_replace('/[^-a-zA-Z0-9\\x80-\\xff]/', ' ', @$opt['class']); if ($class) { $class = " class='{$class}'"; } $wrap = @$opt['wrap']; if ($wrap != 'inline') { $out = MarkupToHTML($pagename, $out, array('escape' => 0, 'redirect' => 1)); if ($wrap != 'none') { $out = "<div{$class}>{$out}</div>"; } } $Cursor = $savecursor; StopWatch("FPLTemplate end"); return $out; }
function FPLTemplate($pagename, &$matches, $opt) { global $Cursor, $FPLFormatOpt, $FPLTemplatePageFmt; SDV($FPLTemplatePageFmt, array('{$FullName}', '{$SiteGroup}.LocalTemplates', '{$SiteGroup}.PageListTemplates')); $template = @$opt['template']; if (!$template) { $template = @$opt['fmt']; } list($tname, $qf) = explode('#', $template, 2); if ($tname) { $tname = array(MakePageName($pagename, $tname)); } else { $tname = (array) $FPLTemplatePageFmt; } foreach ($tname as $t) { $t = FmtPageName($t, $pagename); if (!PageExists($t)) { continue; } if ($qf) { $t .= "#{$qf}"; } $ttext = IncludeText($pagename, $t, true); if (!$qf || strpos($ttext, "[[#{$qf}]]") !== false) { break; } } ## remove any anchor markups to avoid duplications $ttext = preg_replace('/\\[\\[#[A-Za-z][-.:\\w]*\\]\\]/', '', $ttext); if (!@$opt['order'] && !@$opt['trail']) { $opt['order'] = 'name'; } $matches = array_values(MakePageList($pagename, $opt, 0)); if (@$opt['count']) { array_splice($matches, $opt['count']); } $savecursor = $Cursor; $pagecount = 0; $groupcount = 0; $grouppagecount = 0; $vk = array('{$PageCount}', '{$GroupCount}', '{$GroupPageCount}'); $vv = array(&$pagecount, &$groupcount, &$grouppagecount); $lgroup = ''; $out = ''; foreach ($matches as $i => $pn) { $prev = (string) @$matches[$i - 1]; $next = (string) @$matches[$i + 1]; $Cursor['<'] = $Cursor['<'] = $prev; $Cursor['='] = $pn; $Cursor['>'] = $Cursor['>'] = $next; $group = PageVar($pn, '$Group'); if ($group != $lgroup) { $groupcount++; $grouppagecount = 0; } $grouppagecount++; $pagecount++; $item = str_replace($vk, $vv, $ttext); $item = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PageVar(\$pn, '\$2', '\$1')", $item); $out .= $item; $lgroup = $group; } $class = preg_replace('/[^-a-zA-Z0-9\\x80-\\xff]/', ' ', @$opt['class']); $div = $class ? "<div class='{$class}'>" : '<div>'; return $div . MarkupToHTML($pagename, $out, array('escape' => 0)) . '</div>'; }
function icalexportfct($pagename) { global $ICalCalendarTitle, $ICalCalendarGroup, $ICalTimeZone, $ICalFileName; global $UploadDir, $UploadPrefixFmt, $UploadUrlFmt, $GroupPattern, $NamePattern, $FarmD, $IsPagePosted; global $ScriptUrl; // Script only executes if the wiki page is written if (!$IsPagePosted) { return; } // Script only executes if the currently saved page is in the $ICalCalendarGroup if (!preg_match("/" . $ICalCalendarGroup . "[\\/.]" . $NamePattern . "/i", $pagename)) { return; } $pagelist = ListPages(); $attachlist = array(); $locationi18n = FmtPageName("\$[Location]", $pagename); $begini18n = FmtPageName("\$[Begin]", $pagename); $endi18n = FmtPageName("\$[End]", $pagename); $descriptioni18n = FmtPageName("\$[Description]", $pagename); $out[] = "BEGIN:VCALENDAR\r\n"; $out[] = "VERSION:2.0\r\n"; $out[] = "X-WR-CALNAME:" . $ICalCalendarTitle . "\r\n"; foreach ($pagelist as $pagename) { // we need only search events on wiki sides belonging to group $ICalCalendarGroup if (!preg_match("/" . $ICalCalendarGroup . "." . $NamePattern . "/", $pagename)) { continue; } // we read the page and ... $rcpage = ReadPage($pagename); // ... split the events apart on horizontal ruler $calenderEvents = explode("----", $rcpage['text']); $acalYear = date("Y", $rcpage['ctime']); foreach ($calenderEvents as $eventNumber => $event) { if (preg_match("/^(?:!!)(?!!)\\s?(.*)/m", $event, $eventTitle)) { preg_match("/^(?:" . $endi18n . ":)\\s*([0-9]{1,2}:[0-9]{1,2}).*\$/m", $event, $eventEnd); preg_match("/^(?:" . $begini18n . ":)\\s*([0-9]{1,2}:[0-9]{1,2}).*\$/m", $event, $eventBegin); preg_match("/^(?:" . $locationi18n . ":)\\s*(.*)\$/m", $event, $eventLocation); preg_match("/^(?:" . $descriptioni18n . ":)\\s*(.*)\$/ms", $event, $eventDescription); $eventTitle = $eventTitle[1]; $eventBegin = $eventBegin[1]; $eventEnd = $eventEnd[1]; // uh, why I did the str_replace here? $eventLocation = str_replace("\\", "", $eventLocation[1]); $eventDescription = str_replace("\\", "", $eventDescription[1]); $temp = explode(".", $pagename); $out[] = "BEGIN:VEVENT\r\n"; if (preg_match("/^ACAL/", $temp[1])) { $temp[1] = str_replace("ACAL", date("Y", $acalYear), $temp[1]); $out[] = "RRULE:FREQ=YEARLY;INTERVAL=1\r\n"; } if ($eventBegin && $eventEnd) { $eventBegin = preg_replace('/^([0-9]:)/', '0$1', $eventBegin); $eventBegin = preg_replace('/:([0-9])$/', ':0$1', $eventBegin); $eventEnd = preg_replace('/^([0-9]:)/', '0$1', $eventEnd); $eventEnd = preg_replace('/:([0-9])$/', ':0$1', $eventEnd); $beginn = str_replace(":", "", $eventBegin); $ende = str_replace(":", "", $eventEnd); $out[] = "DTSTART;TZID=" . $ICalTimeZone . ":" . $temp[1] . "T" . $beginn . "00\r\n"; $out[] = "DTEND;TZID=" . $ICalTimeZone . ":" . $temp[1] . "T" . $ende . "00\r\n"; } else { //we say it is a full day event and set the end to the next day // TODO:1 check if date exists and wrap to next month if not $nextDay = $temp[1] + 1; $out[] = "DTSTART;VALUE=DATE:" . $temp[1] . "\r\n"; $out[] = "DTEND;VALUE=DATE:" . $nextDay . "\r\n"; } if ($eventLocation) { $out[] = "LOCATION:" . $eventLocation . "\r\n"; } $title = MarkupToHTML($pagename, $eventTitle); $title = chop(preg_replace("/<.*?>/s", "", $title)); $out[] = "SUMMARY:" . $title . "\r\n"; //Every event needs a clear ID in the iCal protokoll $out[] = "UID:" . $pagename . "-" . $eventNumber . "-@" . $_SERVER['HTTP_HOST'] . "\r\n"; if ($eventDescription) { $infos = MarkupToHTML($pagename, $eventDescription); $infos = preg_replace("/<.*?>/s", "", $infos); $infos = chop($infos); $infos = preg_replace("/\n/s", "\\r\\n", $infos); //Seperates the following URL by two lines $infos = $infos . "\\r\\n\\r\\n"; } else { $infos = ""; } $out[] = "DESCRIPTION:" . $infos . $ScriptUrl . "/" . $pagename . "\r\n"; $out[] = "END:VEVENT\r\n"; } } } $out[] = "END:VCALENDAR\r\n"; $pagetext = implode("", $out); //debugging help: prints out the written iCal file on the wikipage #return implode("<br>", $out); // writes out the ics file $filename = $UploadDir . "/" . $ICalCalendarGroup . "/" . $ICalFileName . ".ics"; $handle = fopen($filename, "w"); fwrite($handle, $pagetext); fclose($handle); chmod($filename, 0777); return; }
function HandleFastCacheBrowse($pagename, $auth = 'read') { # handle display of a page global $DefaultPageTextFmt, $PageNotFoundHeaderFmt, $HTTPHeaders, $EnableHTMLCache, $NoHTMLCache, $PageCacheFile, $LastModTime, $IsHTMLCached, $FmtV, $HandleBrowseFmt, $PageStartFmt, $PageEndFmt, $PageRedirectFmt; ## begin added global $FastCachePage, $FastCacheDir, $FastCacheValid, $FastCacheSuffix; if (!$FastCacheValid || !$FastCacheDir) { HandleBrowse($pagename, $auth); return; } SDV($FastCacheSuffix, '.html'); $fcfile = "{$FastCacheDir}/{$pagename}{$FastCacheSuffix}"; if (@filemtime($fcfile) > $LastModTime) { if ($FastCachePage = file_get_contents($fcfile)) { StopWatch("HandleFastCacheBrowse: using FastCached copy of {$pagename}"); echo $FastCachePage; } else { $FastCacheValid = FALSE; StopWatch("HandleFastCacheBrowse: read error on {$fcfile}"); HandleBrowse($pagename, $auth); } return; } ## end added $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT); if (!$page) { Abort("?cannot read {$pagename}"); } PCache($pagename, $page); if (PageExists($pagename)) { $text = @$page['text']; } else { $FastCacheValid = FALSE; ## added SDV($DefaultPageTextFmt, '(:include $[{$SiteGroup}.PageNotFound]:)'); $text = FmtPageName($DefaultPageTextFmt, $pagename); SDV($PageNotFoundHeaderFmt, 'HTTP/1.1 404 Not Found'); SDV($HTTPHeaders['status'], $PageNotFoundHeaderFmt); } $opt = array(); SDV($PageRedirectFmt, "<p><i>(\$[redirected from] <a rel='nofollow'\n href='{\$PageUrl}?action=edit'>{\$FullName}</a>)</i></p>\$HTMLVSpace\n"); if (@(!$_GET['from'])) { $opt['redirect'] = 1; $PageRedirectFmt = ''; } else { $PageRedirectFmt = FmtPageName($PageRedirectFmt, $_GET['from']); } if (@$EnableHTMLCache && !$NoHTMLCache && $PageCacheFile && @filemtime($PageCacheFile) > $LastModTime) { list($ctext) = unserialize(file_get_contents($PageCacheFile)); $FmtV['$PageText'] = "<!--cached-->{$ctext}"; $IsHTMLCached = 1; StopWatch("HandleFastCacheBrowse: using HTMLCached copy"); ## modified } else { $IsHTMLCached = 0; $text = '(:groupheader:)' . @$text . '(:groupfooter:)'; $t1 = time(); $FmtV['$PageText'] = MarkupToHTML($pagename, $text, $opt); if (@$EnableHTMLCache > 0 && !$NoHTMLCache && $PageCacheFile && time() - $t1 + 1 >= $EnableHTMLCache) { $fp = @fopen("{$PageCacheFile},new", "x"); if ($fp) { StopWatch("HandleFastCacheBrowse: HTMLCaching page"); ## modified fwrite($fp, serialize(array($FmtV['$PageText']))); fclose($fp); rename("{$PageCacheFile},new", $PageCacheFile); } } } SDV($HandleBrowseFmt, array(&$PageStartFmt, &$PageRedirectFmt, '$PageText', &$PageEndFmt)); ## begin modified if ($FastCacheValid) { ob_start(); PrintFmt($pagename, $HandleBrowseFmt); $FastCachePage = ob_get_contents(); ob_end_flush(); mkdirp(dirname($fcfile)); if ($FastCacheValid && ($fc = fopen("{$fcfile},new", 'x'))) { StopWatch("HandleFastCacheBrowse: FastCaching {$pagename}"); fwrite($fc, $FastCachePage); fclose($fc); rename("{$fcfile},new", $fcfile); } else { StopWatch("HandleFastCacheBrowse: error writing cache to {$fcfile},new"); } } else { PrintFmt($pagename, $HandleBrowseFmt); } ## end modified }
function convertPagesToXML ($pageinfo) { $xml = "<!-- Frontmatter -->\n"; if ($pageinfo['preface'] != '') { // extract title and author information message("processing trail page ".$this->pagename, 'start'); while (preg_match('/(\(:(\w+)(\s+.+?)?:\).*?\(:end\2:\)\s*)/s', $pageinfo['preface'], $m)) { $xml .= preg_replace('#^\s*<p>(.*)</p>\s*$#s', '$1', MarkupToHTML($this->pagename, trim($m[1]))); $pageinfo['preface'] = str_replace($m[1], '', $pageinfo['preface']); } while (preg_match('/(\(:\w+(\s+.+?)?:\))\s*/s', $pageinfo['preface'], $m)) { $xml .= preg_replace('#^\s*<p>(.*)</p>\s*$#s', '$1', MarkupToHTML($this->pagename, trim($m[1]))); $pageinfo['preface'] = str_replace($m[1], '', $pageinfo['preface']); } message('', 'end'); } unset($pageinfo['preface']); foreach ($pageinfo as $pi) { global $WikiDir; $pagefile = $WikiDir->pagefile($pi['pagename']); $cachefile = $this->outputDir($pi['pagename'])."/cache.xml"; $msg = "processing page ".htmlentities($pi['pagename']); if (0) { // @@ message("$msg from cache", 'start'); $localxml = file_get_contents($cachefile); } else { global $ProcessedPages; $empty = file_exists($pagefile) ? '' : ' (page empty)'; message($msg.$empty, 'start'); $ProcessedPages[] = $pi['pagename']; list($group) = explode('.', $pi['pagename']); $page = ReadPage($pi['pagename']); $text = trim($page['text']); $text = preg_replace('/^!+.*?\\n/', '', $text); // remove title header from wiki page $text = html_entity_decode($text); $title = $pi['title'] ? $pi['title'] : $pi['pagename']; $sectcmd = "(:section level=$pi[depth] title=\"$pi[title]\" label=".Keep($pi[pagename]).":)"; $text = "{$sectcmd}\n$text"; // ...then add a title with name of wiki page $text = str_replace(chr(128), '¤', $text); // das "Windows" ¤-Zeichen liegt auf 128... $localxml = MarkupToHTML($pi['pagename'], $text); // generate XML of current wiki page if (file_exists($pagefile)) { // does wikipage exist? recursive_mkdir(dirname($cachefile)); $f = fopen($cachefile, 'w'); fputs($f, $localxml); fclose($f); } } $xml .= $localxml; message('', 'end'); } // close all open section elements $xml .= flush_section(0); $xml = "<article page-width='210mm' page-height='297mm' margin='2cm'>$xml</article>"; return $xml; }
function FPLTemplate($pagename, &$matches, $opt) { global $Cursor, $FPLFormatOpt, $FPLTemplatePageFmt; SDV($FPLTemplatePageFmt, '{$SiteGroup}.PageListTemplates'); $template = @$opt['template']; if (!$template) { $template = @$opt['fmt']; } list($tname, $qf) = explode('#', $template, 2); if ($tname) { $tname = MakePageName($pagename, $tname); } else { $tname = FmtPageName($FPLTemplatePageFmt, $pagename); } if ($qf) { $tname .= "#{$qf}"; } $ttext = IncludeText($pagename, $tname, true); $ttext = preg_replace('/\\[\\[#[A-Za-z][-.:\\w]*\\]\\]/', '', $ttext); if (!$opt['order'] && !$opt['trail']) { $opt['order'] = 'name'; } $matches = array_values(MakePageList($pagename, $opt, 0)); if (@$opt['count']) { array_splice($matches, $opt['count']); } $savecursor = $Cursor; $pagecount = 0; $groupcount = 0; $grouppagecount = 0; $vk = array('{$PageCount}', '{$GroupCount}', '{$GroupPageCount}'); $vv = array(&$pagecount, &$groupcount, &$grouppagecount); $lgroup = ''; $out = ''; foreach ($matches as $i => $pn) { $prev = (string) @$matches[$i - 1]; $next = (string) @$matches[$i + 1]; $Cursor['<'] = $Cursor['<'] = $prev; $Cursor['='] = $pn; $Cursor['>'] = $Cursor['>'] = $next; $group = PageVar($pn, '$Group'); if ($group != $lgroup) { $groupcount++; $grouppagecount = 0; } $grouppagecount++; $pagecount++; $item = str_replace($vk, $vv, $ttext); $item = preg_replace('/\\{(=|&[lg]t;)(\\$\\w+)\\}/e', "PageVar(\$pn, '\$2', '\$1')", $item); $out .= $item; $lgroup = $group; } return '<div>' . MarkupToHTML($pagename, $out, false) . '</div>'; }
function HandlePDF($pagename) { global $WikiTitle; // modify WikiTitle $WikiTitle = str_replace(' ', '_', $WikiTitle); $WikiTitle = html_entity_decode($WikiTitle); // read wiki page ! //$page = ReadPage($pagename); $page = RetrieveAuthPage($pagename, 'read', true, READPAGE_CURRENT); //$date['modif'] = filemtime($_SERVER['DOCUMENT_ROOT'].'/wiki.d/'.$pagename); // define variable $xyz['author'] = 'by ' . $page['author']; // pdf author $xyz['name']['page'] = str_replace('.', '_', $pagename); // page name $xyz['name']['pdf'] = $WikiTitle . '_' . $xyz['name']['page'] . '.pdf'; // pdf name $xyz['text'] = mv_breakpage($page['text']); // to transform breakpage markup $xyz['title'] = $WikiTitle . ' : page ' . $xyz['name']['page']; // pdf title $xyz['path'] = $_SERVER["DOCUMENT_ROOT"]; // return root path of your site web $xyz['url'] = 'http://' . HOST . URI; // pdf URL // transform text to html ! $html = change_code(MarkupToHTML($pagename, $xyz['text'])); /*** for test ! *** echo $xyz['text']; echo "\n HTML : ".$html; /** */ //out pass memory server ini_set('memory_limit', '24M'); ini_set('max_execution_time', 0); // declare a new object pdf $pdf = new HTML2FPDF(); // Disactive elements HTML ... cause bad support ! $pdf->DisableTags('<span>'); $pdf->DisableTags('<dl>'); $pdf->DisableTags('<dt>'); $pdf->DisableTags('<dd>'); // generals informations $pdf->SetCompression(1); $pdf->SetAuthor($xyz['author']); $pdf->SetTitle($xyz['title']); // method implemented by me to return in footer pdf generated. $pdf->PutHREF($xyz['url']); // method implemented by html2pdf author ! $pdf->setBasePath($xyz['path']); // to implement path of your site ; need it for include correctly the image on pdf ! $pdf->UseCSS(false); // to recognize CSS ... run correctly ? $pdf->UsePRE(false); // to recognize element PRE in your code HTML ... but, really bad support ! // build the page PDF $pdf->AddPage(); $pdf->WriteHTML($html); $pdf->Output($xyz['name']['pdf'], I); /**/ // retabli valeur serveur ini_set('memory_limit', MEM); ini_set('max_execution_time', MAX_TIME); }
function RenderSidePart($pagename, $params) { $pagelist = preg_split('/\\s+/', $params, -1, PREG_SPLIT_NO_EMPTY); $class_title = array_shift($pagelist); $class = array_shift($pagelist); $id = array_shift($pagelist); list($text, $title) = RetrievePageMarkup($pagelist); if (!isset($text)) { return; } $orig_page_title = PageVar($pagename, '$Title'); print "<div class='{$class_title}'>{$title}</div><div class='{$class}' id='{$id}'>"; print MarkupToHTML($pagename, $text); print "</div><!-- id='{$id}' -->"; PCache($pagename, array('title' => SetProperty($pagename, 'title', $orig_page_title))); }
function HandleRss($pagename) { global $RssMaxItems, $RssSourceSize, $RssDescSize, $RssChannelFmt, $RssChannelDesc, $RssTimeFmt, $RssChannelBuildDate, $RssItemsRDFList, $RssItemsRDFListFmt, $RssItems, $RssItemFmt, $RssItemDesc, $RssItemPubDate, $GCount, $HandleRssFmt; $t = ReadTrail($pagename, $pagename); $page = RetrieveAuthPage($pagename, false); $cbgmt = $page['time']; $r = array(); for ($i = 0; $i < count($t) && count($r) < $RssMaxItems; $i++) { if (!PageExists($t[$i]['pagename'])) { continue; } $page = RetrieveAuthPage($t[$i]['pagename'], false); $text = MarkupToHTML($t[$i]['pagename'], substr($page['text'], 0, $RssSourceSize)); $text = rssencode(preg_replace("/<.*?>/s", "", $text)); preg_match("/^(.{0,{$RssDescSize}}\\s)/s", $text, $match); $r[] = array('name' => $t[$i]['pagename'], 'time' => $page['time'], 'desc' => $match[1] . " ..."); if ($page['time'] > $cbgmt) { $cbgmt = $page['time']; } } SDV($RssChannelBuildDate, rssencode(gmstrftime($RssTimeFmt, $cbgmt))); SDV($RssChannelDesc, rssencode(FmtPageName('$Group.$Title', $pagename))); foreach ($r as $page) { $RssItemPubDate = gmstrftime($RssTimeFmt, $page['time']); $RssItemDesc = $page['desc']; $GCount = 0; $RssItemsRDFList[] = rssencode(FmtPageName($RssItemsRDFListFmt, $page['name'])); $RssItems[] = rssencode(FmtPageName($RssItemFmt, $page['name'])); } header("Content-type: text/xml"); PrintFmt($pagename, $HandleRssFmt); exit; }
function TextExtract($pagename, $list, $opt = NULL) { global $TextExtractOpt, $TEModeDefaults, $TextExtract, $TextExtractExclude, $FmtV, $HTMLStylesFmt, $KeepToken, $KPV, $PageListArgPattern; ##DEBUG echo "<pre>LIST "; print_r($list); echo "</pre>"; foreach ($opt as $k => $v) { if (is_array($v)) { foreach ($v as $kk => $vv) { $opt[$k][$kk] = stripmagic($vv); } } else { $opt[$k] = stripmagic($v); } } //internal arg array $par = array(); //start time StopWatch('TextExtract start'); if ($opt['stime']) { $par['stime'] = $opt['stime']; } else { $par['stime'] = strtok(microtime(), ' ') + strtok(''); } //set default options foreach ($TEModeDefaults as $mode => $ar) { foreach ($ar as $k => $val) { if ($opt['markup'] == $mode && !$opt[$k]) { $opt[$k] = $val; } } } $opt = array_merge($TextExtractOpt, $opt); ##DEBUG echo "<pre>OPT "; print_r($opt); echo "</pre>"; //input parameter check if (!in_array($opt['unit'], array('line', 'para', 'page')) or !in_array($opt['markup'], array('code', 'cut', 'source', 'text', 'on'))) { return "%red%\$[Error: check input parameters!]"; } foreach ((array) @$opt['+'] as $i) { $opt[''][] = $i; } if (!isset($opt['']) && !isset($opt['pattern'])) { return '%red%$[Error: search term missing!]'; } //term is regular expression if ($opt['regex'] == 1) { $pat = $par['pattern'] = $opt[''][0] = $opt['pattern']; //exclude various input patterns SDVA($TextExtractExclude, array("*", "?", "+", "(", ")", "[", "]", "^", "\$", "|", "??", "\\")); foreach ($TextExtractExclude as $v) { if ($pat == $v) { return '%red%$[Error: disallowed character input!]'; } } } else { $terms = implode(" + ", $opt['']); if ($opt['-']) { $terms .= " -" . implode(" -", $opt['-']); } $par['pattern'] = $terms; $pregchars = array('.', '?', '!', '*', '|', '$', '(', ')', '[', ']', '{', '}'); foreach ($pregchars as $v) { $opt[''] = str_replace($v, '\\' . $v, $opt['']); $opt['-'] = str_replace($v, '\\' . $v, $opt['-']); } if ($opt['word'] == 1) { foreach ($opt[''] as $i => $pt) { $opt[''][$i] = '\\b' . $pt . '\\b'; } } $pat = implode("|", $opt['']); } $par['pat'] = $pat; ##DEBUG echo $pat; //always wrap lines when displaying preformatted 'source' code if ($opt['markup'] == 'source') { $opt['linewrap'] = 1; } // wrap lines of preformatted text and code //IE may not work with word-wrap, therefore special IE rule if ($opt['linewrap'] == 1) { # whitespace wrap (perhaps copy styles to css stylesheet) $HTMLStylesFmt['prewrap'] = "\r\n code, div.te-results pre, div.te-results code, code.escaped, pre.escaped { \r\n\t white-space: pre-wrap; /* CSS-3 */\r\n\t white-space: -moz-pre-wrap; /* Mozilla, since 1999 */\r\n\t white-space: -pre-wrap; /* Opera 4-6 */\r\n\t white-space: -o-pre-wrap; /* Opera 7 */\r\n\t word-wrap: break-word; /* Internet Explorer 5.5+ */\r\n\t _white-space: pre; \r\n\t }\r\n\t * html pre.escaped, * html code.escaped { white-space: normal; }\r\n\t "; } //setting keep values here, and keeptokens directly in TEHighLight() //instead of calling Keep again and again switch ($opt['highlight']) { case 'none': $KPV['01¶'] = $KPV['02¶'] = ""; break; case 'bold': $KPV['01¶'] = "<strong>"; $KPV['02¶'] = "</strong>"; break; case '1': default: $KPV['01¶'] = "<span class='te-hilight'>"; $KPV['02¶'] = "</span>"; $HTMLStylesFmt['te-hilight'] = " .te-hilight { background-color: {$opt['highlight']}; } "; } $par['hitoklen'] = 6 + 4 * strlen($KeepToken); // token length * 2 $KPV['03¶'] = "<br />"; $par['br-tag'] = $KeepToken . "03¶" . $KeepToken; $KPV['04¶'] = "<div class='spacer'><!-- spacer --></div>"; $par['vspace'] = $KeepToken . "04¶" . $KeepToken; //header, footer, pagelink prefix styles if ($opt['header'] == 'full') { $opt['footer'] = 1; } if ($opt['phead']) { SDV($HTMLStylesFmt['teprefix'], " .te-pageheader { margin:.8em 0 .5em 0; padding:.2em .2em 0 .2em;} \r\n\t .te-pageheader { border-top:1px solid #ccc; border-bottom:1px solid #ccc; background:#f7f7f7;}\r\n\t\t"); } if ($opt['header']) { SDV($HTMLStylesFmt['teheader'], " .te-header {margin-top:0.5em; padding:0.3em; border-top:1px solid #ccc; border-bottom:1px solid #ccc; background:#f7f7f7;}\r\n\t\t"); } if ($opt['footer']) { SDV($HTMLStylesFmt['tefooter'], " .te-footer {margin-top:0.5em; padding:0.3em; border-top:1px solid #ccc; border-bottom:1px solid #ccc; background:#f7f7f7;}\r\n\t\t"); } //number color defaults foreach (array('line', 'match', 'page') as $c) { if ($opt[$c . 'num'] == 1) { $opt[$c . 'num'] = $opt[$c . 'num-color']; } if ($opt[$c . 'num']) { $HTMLStylesFmt[$c . 'num'] = " .{$c}num { color: {$opt[$c . 'num']} ;} "; } } SDV($HTMLStylesFmt['telinktext'], " .te-linktext {color: {$opt['linktext']} } "); //case insensitive search $qi = $par['qi'] = @$opt['case'] == 1 ? '' : 'i'; $par['listcnt'] = $FmtV['$MatchSearched'] ? $FmtV['$MatchSearched'] : count($list); //inits $par['sorcnt'] = $par['matchnum'] = $par['matchcnt'] = $par['rowcnt'] = 0; $par['title'] = $opt['title']; //process each source page in turn $new = array(); $j = 0; foreach ($list as $i => $pn) { $par['source'] = $pn; $par['pname'] = substr(strstr($pn, '.'), 1); $par['pmatchnum'] = 0; $par['prevpmnum'] = 0; //get rows from source page $rows = TETextRows($pagename, $pn, $opt, $par); if (!$rows) { continue; } $j++; $list[$j] = $pn; //processing lines (rows) foreach ($rows as $k => $row) { $par['linenum'] = $k + 1; //skip pages which don't match if ($opt['unit'] == 'page') { if (!preg_match("({$pat})" . $qi, $row)) { continue; } } //preserve empty rows for 'all including' pattern if ($opt['unit'] == 'line' && $row == "" && $pat == ".") { $new[$j]['rows'][] = $row; continue; } //skip rows which don't match if ($opt['unit'] == 'line' || $opt['unit'] == 'para') { if (!preg_match("({$pat})" . $qi, $row)) { continue; } } //use row 'as is' if markup=on or whole page, no futher row processing if ($opt['markup'] == 'on' && ($pat == "." || $opt['unit'] == 'page' || $opt['unit'] == 'para')) { $new[$j]['phead'] = TEPageHeader($pagename, $pn, $opt, $par); $new[$j]['rows'][] = $row; $par['rowcnt']++; continue; //start with next source row } //change some markup into code or 'defuse', so it will not get rendered, or cut it $row = TEMarkupCleaner($row, $opt, $par); //exclude lines containing matches with cut pattern if ($opt['cut'] != '') { if (preg_match("({$opt['cut']})" . $qi, $row)) { continue; } } //count matches in row $par['rowmatchcnt'] = preg_match_all("({$pat})" . $qi, $row, $mr); //check if textrow needs processing if ($opt['snip'] != '') { $row = preg_replace("({$opt['snip']})", '', $row); } $row = ltrim($row); //empty row if ($row == '') { continue; } //highlight matches if ($opt['highlight'] && $pat != '.') { $row = TEHighlight($opt, $par, $row); } //numbering $par['pagenum'] = $par['pagecnt'] + 1; $par['rowcnt']++; $new[$j]['rowcnt']++; $new[$j]['pmatchcnt'] += $par['rowmatchcnt']; $par['prevmnum'] = $par['matchnum']; $par['matchcnt'] = $par['matchnum'] += $par['rowmatchcnt']; $par['prevpmnum'] = $par['pmatchnum']; $par['pmatchnum'] += $par['rowmatchcnt']; $rownum = $opt['linenum'] || $opt['matchnum'] || $opt['pagenum'] ? TERowNumbers($opt, $par) : ''; //add new result row $new[$j]['rows'][] = $rownum . $row; //add vertical spacing to para if ($opt['unit'] == 'para' && $opt['markup'] != 'source') { $new[$j]['rows'][] = "\n¶¶"; } } //end of page rows processing if (count($new[$j]['rows']) > 0) { //add pagelink (prefix) row if ($opt['phead']) { $new[$j]['phead'] = TEPageHeader($pagename, $pn, $opt, $par); } $par['sorcnt']++; if ($opt['pfoot']) { $new[$j]['pfoot'] = TEPageFooter($pagename, $pn, $opt, $par); } $new[$j]['name'] = $pn; } } //end of source pages processing //slice list if we got #section if (@$opt['section'] && @$opt['count']) { TESliceList($new, $opt); } $par['pagecnt'] = count($new); //sort list by results per page, subsort by name if ($opt['order'] == 'results') { TESort($new); } ## DEBUG echo "<pre>NEW "; print_r($new); echo "</pre>"; //output text from array of rows, adding page prefix header (and footer) $out = ''; foreach ($new as $i => $ar) { //markup pageheader if ($opt['phead']) { $out .= MarkupToHTML($pagename, $new[$i]['phead']); } //markup rows $rnew = implode("\n", $new[$i]['rows']); $rnew = TEVSpace($rnew, $par, $opt); global $LinkFunctions; if ($opt['textlinks'] == 1) { $lf = $LinkFunctions; foreach ($LinkFunctions as $k => $v) { $LinkFunctions[$k] = 'TELinkText'; } } $out .= $opt['markup'] == 'source' ? "<code class='escaped'>" . $rnew . "</code>" : MarkupToHTML($pagename, $rnew); if ($opt['textlinks'] == 1) { $LinkFunctions = $lf; } //markup pagefooter if ($opt['pfoot']) { $out .= MarkupToHTML($pagename, $new[$i]['pfoot']); } } //stop timer TEStopwatch($par); //make header and footer $header = TEHeader($opt, $par); $header = MarkupToHTML($pagename, $header); $footer = TEFooter($opt, $par); $footer = MarkupToHTML($pagename, $footer); $out = $header . $out . $footer; StopWatch('TextExtract end'); return Keep($out); }
function FPLTemplate($pagename, &$matches, $opt) { global $Cursor, $FPLFormatOpt, $FPLTemplatePageFmt; SDV($FPLTemplatePageFmt, array('{$FullName}', '{$SiteGroup}.LocalTemplates', '{$SiteGroup}.PageListTemplates')); StopWatch("FPLTemplate begin"); $template = @$opt['template']; if (!$template) { $template = @$opt['fmt']; } list($tname, $qf) = explode('#', $template, 2); if ($tname) { $tname = array(MakePageName($pagename, $tname)); } else { $tname = (array) $FPLTemplatePageFmt; } foreach ($tname as $t) { $t = FmtPageName($t, $pagename); if (!PageExists($t)) { continue; } if ($qf) { $t .= "#{$qf}"; } $ttext = IncludeText($pagename, $t, true); if (!$qf || strpos($ttext, "[[#{$qf}]]") !== false) { break; } } ## remove any anchor markups to avoid duplications $ttext = preg_replace('/\\[\\[#[A-Za-z][-.:\\w]*\\]\\]/', '', $ttext); ## save any escapes $ttext = MarkupEscape($ttext); $matches = array_values(MakePageList($pagename, $opt, 0)); if (@$opt['count']) { array_splice($matches, $opt['count']); } $savecursor = $Cursor; $pagecount = 0; $groupcount = 0; $grouppagecount = 0; $pseudovars = array('{$$PageCount}' => &$pagecount, '{$$GroupCount}' => &$groupcount, '{$$GroupPageCount}' => &$grouppagecount); foreach (preg_grep('/^[\\w$]/', array_keys($opt)) as $k) { if (!is_array($opt[$k])) { $pseudovars["{\$\${$k}}"] = htmlspecialchars($opt[$k], ENT_NOQUOTES); } } $vk = array_keys($pseudovars); $vv = array_values($pseudovars); $lgroup = ''; $out = ''; foreach ($matches as $i => $pn) { $prev = (string) @$matches[$i - 1]; $next = (string) @$matches[$i + 1]; $Cursor['<'] = $Cursor['<'] = $prev; $Cursor['='] = $pn; $Cursor['>'] = $Cursor['>'] = $next; $group = PageVar($pn, '$Group'); if ($group != $lgroup) { $groupcount++; $grouppagecount = 0; } $grouppagecount++; $pagecount++; $item = str_replace($vk, $vv, $ttext); $item = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PVSE(PageVar(\$pn, '\$2', '\$1'))", $item); $out .= MarkupRestore($item); $lgroup = $group; } $class = preg_replace('/[^-a-zA-Z0-9\\x80-\\xff]/', ' ', @$opt['class']); $div = $class ? "<div class='{$class}'>" : '<div>'; $out = $div . MarkupToHTML($pagename, $out, array('escape' => 0)) . '</div>'; StopWatch("FPLTemplate end"); return $out; }
function insertFootnotes ($pagename) { global $FOOTNOTES; if (!is_array($FOOTNOTES)) // no footnotes => no output return ''; $fnotes = $FOOTNOTES; $FOOTNOTES = false; // avoid infinite recursion $ret = "<hr>"; // align='left'>"; foreach ($fnotes as $num=>$fntext) { $num++; $fntext = MarkupToHTML($pagename, $fntext); // apply formattings to footnote text $fntext = preg_replace('#^<p>(.*?)</p>$#s', '\1', $fntext); // remove outer paragraph $ret .= "<p><a name='fn$num'><sup>$num</sup></a> $fntext</p>\n"; } return $ret; }
function MarkupMarkup($pagename, $text, $opt = '') { global $MarkupWordwrapFunction; SDV($MarkupWordwrapFunction, 'wordwrap'); $MarkupMarkupOpt = array('class' => 'vert'); $opt = array_merge($MarkupMarkupOpt, ParseArgs($opt)); $html = MarkupToHTML($pagename, $text, array('escape' => 0)); if (@$opt['caption']) $caption = str_replace("'", ''', "<caption>{$opt['caption']}</caption>"); $class = preg_replace('/[^-\\s\\w]+/', ' ', @$opt['class']); if (strpos($class, 'horiz') !== false) { $sep = ''; $pretext = $MarkupWordwrapFunction($text, 40); } else { $sep = '</tr><tr>'; $pretext = $MarkupWordwrapFunction($text, 75); } return Keep(@"<table class='markup $class' align='center'>$caption <tr><td class='markup1' valign='top'><pre>$pretext</pre></td>$sep<td class='markup2' valign='top'>$html</td></tr></table>"); }
function bi_FeedText($pagename, &$page, $tag) { return '<' . $tag . '><![CDATA[' . MarkupToHTML($pagename, '{' . $pagename . '$:entrybody}') . ']]></' . $tag . '>'; }
function DiffHTML($pagename, $diff) { if (@$_REQUEST['nodiff']>'') return ''; global $FmtV, $DiffShow, $DiffAddFmt, $DiffDelFmt, $DiffEndDelAddFmt, $DiffRenderSourceFunction; SDV($DiffRenderSourceFunction, 'DiffRenderSource'); $difflines = explode("\n",$diff."\n"); $in=array(); $out=array(); $dtype=''; $html = ''; foreach($difflines as $d) { if ($d>'') { if ($d[0]=='-' || $d[0]=='\\') continue; if ($d[0]=='<') { $out[]=substr($d,2); continue; } if ($d[0]=='>') { $in[]=substr($d,2); continue; } } if (preg_match("/^(\\d+)(,(\\d+))?([adc])(\\d+)(,(\\d+))?/", $dtype,$match)) { if (@$match[7]>'') { $lines='lines'; $count=$match[1].'-'.($match[1]+$match[7]-$match[5]); } elseif ($match[3]>'') { $lines='lines'; $count=$match[1].'-'.$match[3]; } else { $lines='line'; $count=$match[1]; } if ($match[4]=='a' || $match[4]=='c') { $txt = str_replace('line',$lines,$DiffDelFmt[$match[4]]); $FmtV['$DiffLines'] = $count; $html .= FmtPageName($txt,$pagename); if ($DiffShow['source']=='y') $html .= "<div class='diffmarkup'>" .$DiffRenderSourceFunction($in, $out, 0) ."</div>"; else $html .= MarkupToHTML($pagename, preg_replace('/\\(:.*?:\\)/e',"Keep(htmlspecialchars(PSS('$0')))", join("\n",$in))); } if ($match[4]=='d' || $match[4]=='c') { $txt = str_replace('line',$lines,$DiffAddFmt[$match[4]]); $FmtV['$DiffLines'] = $count; $html .= FmtPageName($txt,$pagename); if ($DiffShow['source']=='y') $html .= "<div class='diffmarkup'>" .$DiffRenderSourceFunction($in, $out, 1) ."</div>"; else $html .= MarkupToHTML($pagename, preg_replace('/\\(:.*?:\\)/e',"Keep(htmlspecialchars(PSS('$0')))",join("\n",$out))); } $html .= FmtPageName($DiffEndDelAddFmt,$pagename); } $in=array(); $out=array(); $dtype=$d; } return $html; }
<?php $mdp = opendir("$testdir/markup"); $tests=0; $passes=0; TestNote(basename(__FILE__),0); while (($mfile=readdir($mdp))!==false) { if (substr($mfile,0,1)=='.') continue; $markup = implode('',file("$testdir/markup/$mfile")); preg_match_all("/=test\\s+(\\S+)\\s+\\[=\n(.*?)\n=\\]\\s*=result\\s+\\[=\n(.*?)=\\]/s",$markup,$match); for($i=0;$i<count($match[1]);$i++) { $out = MarkupToHTML("Test.Markup",$match[2][$i]); $p = ($out==$match[3][$i]); $passes += $p; $tests++; TestNote("$mfile/{$match[1][$i]}: ".(($p) ? 'Pass' : 'Fail')); if (!$p) { TestNote("<pre>out:\n".htmlspecialchars($out)."\nkey:\n". htmlspecialchars($match[3][$i]),2); } } } closedir($mdp); TestResult(__FILE__,$passes,$tests); 0;
function HandleSearchA($pagename, $level = 'read') { global $PageSearchForm, $FmtV, $HandleSearchFmt, $PageStartFmt, $PageEndFmt; SDV($HandleSearchFmt,array(&$PageStartFmt, '$PageText', &$PageEndFmt)); SDV($PageSearchForm, '$[{$SiteGroup}/Search]'); $form = RetrieveAuthPage($pagename, $level, true, READPAGE_CURRENT); if (!$form) Abort("?unable to read $pagename"); PCache($pagename, $form); $text = preg_replace('/\\[([=@])(.*?)\\1\\]/s', ' ', @$form['text']); if (!preg_match('/\\(:searchresults(\\s.*?)?:\\)/', $text)) foreach((array)$PageSearchForm as $formfmt) { $form = ReadPage(FmtPageName($formfmt, $pagename), READPAGE_CURRENT); if ($form['text']) break; } $text = @$form['text']; if (!$text) $text = '(:searchresults:)'; $FmtV['$PageText'] = MarkupToHTML($pagename,$text); PrintFmt($pagename, $HandleSearchFmt); }
function HandleEdit($pagename) { global $IsPagePosted, $EditFields, $ChangeSummary, $EditFunctions, $FmtV, $Now, $PageEditForm, $HandleEditFmt, $PageStartFmt, $PageEditFmt, $PageEndFmt; if ($_POST['cancel']) { Redirect($pagename); return; } Lock(2); $IsPagePosted = false; $page = RetrieveAuthPage($pagename, 'edit'); if (!$page) { Abort("?cannot edit {$pagename}"); } PCache($pagename, $page); $new = $page; foreach ((array) $EditFields as $k) { if (isset($_POST[$k])) { $new[$k] = str_replace("\r", '', stripmagic($_POST[$k])); } } if ($ChangeSummary) { $new["csum:{$Now}"] = $ChangeSummary; } if (@$_POST['postedit']) { $_POST['post'] = 1; } foreach ((array) $EditFunctions as $fn) { $fn($pagename, $page, $new); } Lock(0); if ($IsPagePosted && !@$_POST['postedit']) { Redirect($pagename); return; } $FmtV['$DiffClassMinor'] = @$_POST['diffclass'] == 'minor' ? "checked='checked'" : ''; $FmtV['$EditText'] = str_replace('$', '$', htmlspecialchars(@$new['text'], ENT_NOQUOTES)); $FmtV['$EditBaseTime'] = $Now; if (@$PageEditForm) { $form = ReadPage(FmtPageName($PageEditForm, $pagename), READPAGE_CURRENT); $FmtV['$EditForm'] = MarkupToHTML($pagename, $form['text']); } SDV($PageEditFmt, "<div id='wikiedit'>\n <h1 class='wikiaction'>\$[Editing {\$FullName}]</h1>\n <form method='post' action='\$PageUrl?action=edit'>\n <input type='hidden' name='action' value='edit' />\n <input type='hidden' name='n' value='\$FullName' />\n <input type='hidden' name='basetime' value='\$EditBaseTime' />\n \$EditMessageFmt\n <textarea id='text' name='text' rows='25' cols='60'\n onkeydown='if (event.keyCode==27) event.returnValue=false;'\n >\$EditText</textarea><br />\n <input type='submit' name='post' value=' \$[Save] ' />"); SDV($HandleEditFmt, array(&$PageStartFmt, &$PageEditFmt, &$PageEndFmt)); PrintFmt($pagename, $HandleEditFmt); }
function evaluateTrail () { $trailpage = ReadPage($this->pagename); if ($trailpage) { global $M2MDir, $MarkupTable, $SuffixPattern; $html = MarkupToHTML($this->pagename, $trailpage['text']); } }
function HandleBrowse($pagename) { # handle display of a page $page = ReadPage($pagename); if (!$page) Abort('Invalid page name'); $PageText = MarkupToHTML($pagename,$page['text']); print $PageText; }
function PreviewPage($pagename, &$page, &$new) { global $IsPageSaved, $FmtV, $PagePreviewFmt; if (!$IsPageSaved && @$_REQUEST['preview']) { $text = '(:groupheader:)' . $new['text'] . '(:groupfooter:)'; $FmtV['$PreviewText'] = MarkupToHTML($pagename, $text); } else { $PagePreviewFmt = ''; } }
function MarkupMarkup($pagename, $text) { $html = MarkupToHTML($pagename, $text, false); return Keep("<table class='markup' align='center'><tr><td class='markup1'><pre>" . wordwrap($text, 70) . "</pre></td></tr><tr><td class='markup2'>\n {$html}</td></tr></table>"); }
function HandleSearchA($pagename, $level = 'read') { global $PageSearchForm, $FmtV, $HandleSearchFmt, $PageStartFmt, $PageEndFmt; SDV($HandleSearchFmt, array(&$PageStartFmt, '$PageText', &$PageEndFmt)); SDV($PageSearchForm, '$[$SiteGroup/Search]'); PCache($pagename, RetrieveAuthPage($pagename, 'read')); $form = ReadPage(FmtPageName($PageSearchForm, $pagename), READPAGE_CURRENT); $text = @$form['text']; if (!$text) { $text = '(:searchresults:)'; } $FmtV['$PageText'] = MarkupToHTML($pagename, $text); PrintFmt($pagename, $HandleSearchFmt); }
function FmtLinksList($pagename, $opt) { global $FPLFunctions, $FPLSimpleIFmt, $FPLSimpleSFmt, $PublishSearchChecked; global $PDFCheckboxFmt, $PDFTypesetFmt, $PDFOptionsFmt, $HTMLVSpace; global $FPLByGroupStartFmt, $FPLByGroupEndFmt, $FPLByGroupIFmt, $FPLByGroupCFmt, $FPLByGroupSFmt; $FPLSimpleIFmt = "<li><a href='\$PageUrl'>\$Title</a></li>\n"; $FPLSimpleSFmt = "<li><b class='selflink'>\$Title</b></li>\n"; $FPLByGroupSFmt = "<dd><b class='selflink'>\$Title</b></dd>\n"; if ($opt['action'] == 'publish') { $checked = $PublishSearchChecked ? "checked='checked'" : ''; $FPLByGroupStartFmt = "<form class='publish' action='\$ScriptUrl' method='get'>\n <input type='hidden' name='n' value='\$FullName' />\n <dl class='fplbygroup'>"; $FPLByGroupEndFmt = "</dl>{$HTMLVSpace}\n <input type='hidden' name='action' value='publish' />\n <input type='hidden' name='ptype' value='search' />\n <input type='hidden' name='page' value='\$Group/\$Name' />\n <input type='hidden' name='include' value='include' />"; $FPLByGroupEndFmt .= "{$PDFCheckboxFmt}{$PDFTypesetFmt}{$PDFOptionsFmt}</form>"; $FPLByGroupIFmt = "<dd><input type='checkbox' name='pagearray[]' value='\$Group/\$Name' {$checked}/>\n <a href='\$PageUrl'>\$Title</a></dd>\n"; /* $FPLByGroupCFmt = "<dd><input type='checkbox' name='pagearray[]' value='\$Group/\$Name' $checked/> <a class='createlinktext' href='\$PageUrl?action=edit'>\$Title</a><a class='createlink' href='\$PageUrl?action=edit'>?</a></dd>\n"; */ } else { SDV($FPLByGroupStartFmt, "<dl class='fplbygroup'>"); SDV($FPLByGroupEndFmt, '</dl>'); SDV($FPLByGroupGFmt, "<dt><a href='\$ScriptUrl/\$Group'>\$Group</a></dt>\n"); SDV($FPLByGroupIFmt, "<dd><a href='\$PageUrl'>\$Title</a></dd>\n"); SDV($FPLByGroupCFmt, "<dd><a class='createlinktext' href='\$PageUrl?action=edit'>\$Title</a><a \n class='createlink' href='\$PageUrl?action=edit'>?</a></dd>\n"); SDV($FPLByGroupSFmt, "<dd><b class='selflink'>\$Title</b></dd>\n"); } $pagelist = ListPageLinks($pagename, $opt['list']); sort($pagelist); $matches = array(); foreach ($pagelist as $pagefile) { if ($pagefile != @$lpage) { $matches[] = array('pagename' => $pagefile); $lpage = $pagefile; } } if (count($matches) == 0) { return MarkupToHTML($pagename, "->''\$[No links found].''"); } if (preg_match('/^([^=]*)=(.*?)$/', $opt['o'], $mat)) { $f[$mat[1]] = $mat[2]; } $fmtfn = @$FPLFunctions[$f['fmt']]; if (!function_exists($fmtfn)) { $fmtfn = 'FPLPageLinks'; } return $fmtfn($pagename, $matches, $opt); }