function ReadTrail($pagename, $trailname) { global $RASPageName, $SuffixPattern, $GroupPattern, $WikiWordPattern, $LinkWikiWords; if (preg_match('/^\\[\\[(.+?)(->|\\|)(.+?)\\]\\]$/', $trailname, $m)) $trailname = ($m[2] == '|') ? $m[1] : $m[3]; $trailtext = RetrieveAuthSection($pagename, $trailname); $trailname = $RASPageName; $t = array(); $n = 0; foreach(explode("\n", htmlspecialchars(@$trailtext, ENT_NOQUOTES)) as $x) { $x = preg_replace("/\\[\\[([^\\]]*)->([^\\]]*)\\]\\]/",'[[$2|$1]]',$x); if (!preg_match("/^([#*:]+) \\s* (\\[\\[([^:#!|][^|:]*?)(\\|.*?)?\\]\\]($SuffixPattern) | (($GroupPattern([\\/.]))?$WikiWordPattern)) (.*)/x",$x,$match)) continue; if (@$match[6]) { if (!$LinkWikiWords) continue; $tgt = MakePageName($trailname, $match[6]); } else $tgt = MakePageName($trailname, preg_replace('/[#?].+/', '', $match[3])); $t[$n]['depth'] = $depth = strlen($match[1]); $t[$n]['pagename'] = $tgt; $t[$n]['markup'] = $match[2]; $t[$n]['detail'] = $match[9]; for($i=$depth;$i<10;$i++) $d[$i]=$n; if ($depth>1) $t[$n]['parent']=@$d[$depth-1]; $n++; } return $t; }
function ReadTrail($pagename, $trailname) { global $SuffixPattern, $GroupPattern, $WikiWordPattern; $trailname = MakePageName($pagename, $trailname); $trailpage = ReadPage($trailname); if (!$trailpage) { return false; } $t = array(); $n = 0; foreach (explode("\n", @$trailpage['text']) as $x) { $x = preg_replace("/^([#*]+)\\s*(({$GroupPattern}([\\.]))?{$WikiWordPattern})/", '$1 [[$2]]', $x); $x = preg_replace("/\\[\\[([^\\]]*)->([^\\]]*)\\]\\]/", '[[$2|$1]]', $x); if (!preg_match("/^([#*]+)\\s*(\\[\\[([^|]*?)(\\|.*?)?\\]\\]({$SuffixPattern}))(.*)\$/", $x, $match)) { continue; } $tgt = MakePageName($trailname, $match[3]); $t[$n]['depth'] = $depth = strlen($match[1]); $t[$n]['pagename'] = $tgt; $t[$n]['markup'] = $match[2]; for ($i = $depth; $i < 10; $i++) { $d[$i] = $n; } if ($depth > 1) { $t[$n]['parent'] = @$d[$depth - 1]; } $n++; } return $t; }
function HandleNew($pagename) { $name = @$_REQUEST['name']; if (!$name) { Redirect($pagename); } $base = MakePageName($pagename, $_REQUEST['base']); $newpage = MakePageName($base, $name); $urlfmt = '$PageUrl?action=edit'; if (@$_REQUEST['template']) { $urlfmt .= '&template=' . MakePageName($base, $_REQUEST['template']); } Redirect($newpage, $urlfmt); }
function FmtUploadList2($pagename, $args) { global $UploadDir, $UploadPrefixFmt, $UploadUrlFmt, $EnableUploadOverwrite, $FileListTimeFmt, $EnableDirectDownload, $HTMLStylesFmt, $FarmPubDirUrl; $HTMLStylesFmt['filelist'] = "\r\n table.filelist { padding:0; margin:0; border-spacing:0; }\r\n table.filelist td { padding:3px 0 0 0; margin:0; }\r\n .filelist a { text-decoration:underline; }\r\n .dotted { background:url({$FarmPubDirUrl}/images/dot3.png) repeat-x bottom; }\r\n .nodots { background:#feffff; }\r\n "; $opt = ParseArgs($args); if (@$opt[''][0]) { $pagename = MakePageName($pagename, $opt[''][0]); } if (@$opt['re']) { $matchre = '/^(' . $opt['re'] . ')$/i'; } if (@$opt['ext']) { $matchext = '/\\.(' . implode('|', preg_split('/\\W+/', $opt['ext'], -1, PREG_SPLIT_NO_EMPTY)) . ')$/i'; } $uploaddir = FmtPageName("{$UploadDir}{$UploadPrefixFmt}", $pagename); $uploadurl = FmtPageName(IsEnabled($EnableDirectDownload, 1) ? "{$UploadUrlFmt}{$UploadPrefixFmt}/" : "\$PageUrl?action=download&upname=", $pagename); $dirp = @opendir($uploaddir); if (!$dirp) { return ''; } $filelist = array(); while (($file = readdir($dirp)) !== false) { if ($file[0] == '.') { continue; } if (@$matchext && !preg_match(@$matchext, $file)) { continue; } if (@$matchre && !preg_match(@$matchre, $file)) { continue; } $filelist[$file] = $file; } closedir($dirp); $out = array(); #asort($filelist); $overwrite = ''; foreach ($filelist as $file => $x) { $name = PUE("{$uploadurl}{$file}"); $stat = stat("{$uploaddir}/{$file}"); if ($EnableUploadOverwrite) { $overwrite = FmtPageName("<a class='createlink'\r\n href='\$PageUrl?action=upload&upname={$file}'> Δ</a>", $pagename); } $out[] = "<tr><td class='dotted'> <a href='{$name}'>{$file}</a>{$overwrite} </td>" . "<td class='dotted' align=right><span class='nodots'>" . number_format($stat['size'] / 1024) . "Kb</span></td>" . "<td> " . strftime($FileListTimeFmt, $stat['mtime']) . "</td>" . "<tr>"; } return implode("\n", $out); }
function ThumbShoeKeywords($pagename, $label = 'LinkedName') { global $ThumbShoeKeywordsGroup; $inval = PageTextVar($pagename, 'Keywords'); $out = ''; // don't process if there are already links there if (strpos($inval, '[[') !== false) { $out = $inval; } else { $array_sep = ''; if (strpos($inval, ';') !== false) { $array_sep = ';'; } $oo = array(); if ($label == 'Name') { $pn = str_replace($array_sep, ' ', $inval); $cpage = MakePageName($pagename, "{$ThumbShoeKeywordsGroup}.{$pn}"); $out = PageVar($cpage, '$Name'); } else { $parts = $array_sep ? explode($array_sep, $inval) : array($inval); foreach ($parts as $part) { $part = trim($part); if ($part) { $cpage = MakePageName($pagename, "{$ThumbShoeKeywordsGroup}.{$part}"); if ($label == 'LinkedTitle') { $oo[] = "[[{$cpage}|+]]"; } else { $oo[] = "[[{$cpage}|{$part}]]"; } } } } if ($array_sep == ',' or $array_sep == ';') { $out .= implode("{$array_sep} ", $oo); } else { if ($array_sep == '/' or $array_sep == ' ') { $out .= implode($array_sep, $oo); } else { $out .= implode(" {$array_sep} ", $oo); } } } rtrim($out); return $out; }
function FPLFauxTrail($pagename, &$matches, $opt) { $matches = MakePageList($pagename, $opt, 0); // make the matches array into a number-indexed array $matches = array_values($matches); // check for a minimum count if (@$opt['min']) { if (count($matches) < $opt['min']) { return ''; } } $trailpage = '{$Group}'; if (@$opt['trailpage']) { $trailpage = $opt['trailpage']; } $label = '{$Title}'; if (@$opt['label']) { $label = $opt['label']; } $index_itemfmt = "<a href='{\$PageUrl}'>{$label}</a>"; $tp_val = FmtPageName($trailpage, $pagename); $tp_page = MakePageName($pagename, $tp_val); $itemfmt = "<a href='{\$PageUrl}'>{\$Title}</a>"; $prev_link = ''; $next_link = ''; $out = ''; for ($i = 0; $i < count($matches); $i++) { if ($matches[$i] == $pagename) { if ($i > 0) { $prev_page = $matches[$i - 1]; $prev_link = FmtPageName($itemfmt, $prev_page); } $trailindex = FmtPageName($index_itemfmt, $tp_page); if ($i + 1 < count($matches)) { $next_page = $matches[$i + 1]; $next_link = FmtPageName($itemfmt, $next_page); } $out = "<p><< {$prev_link} | {$trailindex} | {$next_link} >></p>"; break; } } return $out; }
function ReadTrail($pagename, $trailname) { global $SuffixPattern, $GroupPattern, $WikiWordPattern, $LinkWikiWords; if (preg_match('/^\\[\\[(.+?)(->|\\|)(.+?)\\]\\]$/', $trailname, $m)) { $trailname = $m[2] == '|' ? $m[1] : $m[3]; } $trailname = MakePageName($pagename, $trailname); $trailpage = ReadPage($trailname, READPAGE_CURRENT); if (!$trailpage) { return false; } $t = array(); $n = 0; foreach (explode("\n", @$trailpage['text']) as $x) { $x = preg_replace("/\\[\\[([^\\]]*)->([^\\]]*)\\]\\]/", '[[$2|$1]]', $x); if (!preg_match("/^([#*:]+) \\s* \n (\\[\\[([^:#!|][^|:]*?)(\\|.*?)?\\]\\]({$SuffixPattern})\n | (({$GroupPattern}([\\/.]))?{$WikiWordPattern})) (.*)/x", $x, $match)) { continue; } if (@$match[6]) { if (!$LinkWikiWords) { continue; } $tgt = MakePageName($trailname, $match[6]); } else { $tgt = MakePageName($trailname, preg_replace('/[#?].+/', '', $match[3])); } $t[$n]['depth'] = $depth = strlen($match[1]); $t[$n]['pagename'] = $tgt; $t[$n]['markup'] = $match[2]; $t[$n]['detail'] = $match[9]; for ($i = $depth; $i < 10; $i++) { $d[$i] = $n; } if ($depth > 1) { $t[$n]['parent'] = @$d[$depth - 1]; } $n++; } return $t; }
function ReadTrail($pagename, $trailname) { global $RASPageName, $SuffixPattern, $GroupPattern, $WikiWordPattern, $LinkWikiWords; if (preg_match('/^\\[\\[(.+?)(->|\\|)(.+?)\\]\\]$/', $trailname, $m)) { $trailname = $m[2] == '|' ? $m[1] : $m[3]; } $trailtext = RetrieveAuthSection($pagename, $trailname); $trailname = $RASPageName; $trailtext = Qualify($trailname, $trailtext); $t = array(); $n = 0; foreach (explode("\n", PHSC(@$trailtext, ENT_NOQUOTES)) as $x) { $x = preg_replace("/\\[\\[([^\\]]*)->([^\\]]*)\\]\\]/", '[[$2|$1]]', $x); if (!preg_match("/^([#*:]+) \\s* \n (\\[\\[([^:#!|][^|:]*?)(?:\".*?\")?(\\|.*?)?\\]\\]({$SuffixPattern})\n | (({$GroupPattern}([\\/.]))?{$WikiWordPattern})) (.*)/x", $x, $match)) { continue; } if (@$match[6]) { if (!$LinkWikiWords) { continue; } $tgt = MakePageName($trailname, $match[6]); } else { $tgt = MakePageName($trailname, $match[3]); } $t[$n]['depth'] = $depth = strlen($match[1]); $t[$n]['pagename'] = $tgt; $t[$n]['markup'] = $match[2]; $t[$n]['detail'] = $match[9]; for ($i = $depth; $i < 10; $i++) { $d[$i] = $n; } if ($depth > 1) { $t[$n]['parent'] = @$d[$depth - 1]; } $n++; } return $t; }
function MakePageList($pagename, $opt) { global $MakePageListOpt, $SearchPatterns, $EnablePageListProtect, $PCache, $FmtV; StopWatch('MakePageList begin'); SDVA($MakePageListOpt, array('list' => 'default')); $opt = array_merge((array) $MakePageListOpt, $opt); $readf = $opt['readf']; # we have to read the page if order= is anything but name $order = $opt['order']; $readf |= $order && $order != 'name' && $order != '-name'; $pats = @(array) $SearchPatterns[$opt['list']]; if (@$opt['group']) { array_unshift($pats, "/^({$opt['group']})\\./i"); } # inclp/exclp contain words to be included/excluded. $inclp = array(); $exclp = array(); foreach ((array) @$opt[''] as $i) { $inclp[] = '/' . preg_quote($i, '/') . '/i'; } foreach ((array) @$opt['+'] as $i) { $inclp[] = '/' . preg_quote($i, '/') . '/i'; } foreach ((array) @$opt['-'] as $i) { $exclp[] = '/' . preg_quote($i, '/') . '/i'; } $searchterms = count($inclp) + count($exclp); $readf += $searchterms; # forced read if incl/excl if (@$opt['trail']) { $trail = ReadTrail($pagename, $opt['trail']); foreach ($trail as $tstop) { $pn = $tstop['pagename']; $list[] = $pn; $tstop['parentnames'] = array(); PCache($pn, $tstop); } foreach ($trail as $tstop) { $PCache[$tstop['pagename']]['parentnames'][] = $trail[$tstop['parent']]['pagename']; } } else { $list = ListPages($pats); } if (IsEnabled($EnablePageListProtect, 0)) { $readf = 1000; } $matches = array(); $FmtV['$MatchSearched'] = count($list); # link= (backlinks) if (@$opt['link']) { $link = MakePageName($pagename, $opt['link']); $linkpat = "/(^|,){$link}(,|\$)/i"; $readf++; $xlist = BacklinksTo($link, false); $list = array_diff($list, $xlist); } $xlist = array(); StopWatch('MakePageList scan'); foreach ((array) $list as $pn) { if ($readf) { $page = $readf >= 1000 ? RetrieveAuthPage($pn, 'read', false, READPAGE_CURRENT) : ReadPage($pn, READPAGE_CURRENT); if (!$page) { continue; } if (@$linkpat && !preg_match($linkpat, @$page['targets'])) { $PCache[$pn]['targets'] = @$page['targets']; $xlist[] = $pn; continue; } if ($searchterms) { $text = $pn . "\n" . @$page['targets'] . "\n" . @$page['text']; foreach ($inclp as $i) { if (!preg_match($i, $text)) { continue 2; } } foreach ($exclp as $i) { if (preg_match($i, $text)) { continue 2; } } } $page['size'] = strlen(@$page['text']); } else { $page = array(); } $page['pagename'] = $page['name'] = $pn; PCache($pn, $page); $matches[] =& $PCache[$pn]; } StopWatch('MakePageList sort'); SortPageList($matches, $order); StopWatch('MakePageList update'); if ($xlist) { LinkIndexUpdate($xlist); } StopWatch('MakePageList end'); return $matches; }
SDV($AuthorCookieExpires, $Now + 60 * 60 * 24 * 30); SDV($AuthorCookieDir, '/'); SDV($AuthorGroup, 'Profiles'); SDV($AuthorRequiredFmt, "<h3 class='wikimessage'>\$[An author name is required.]</h3>"); Markup('[[~', '<[[', '/\\[\\[~(.*?)\\]\\]/', "[[{$AuthorGroup}/\$1]]"); if (!isset($Author)) { if (isset($_POST['author'])) { $Author = htmlspecialchars(stripmagic($_POST['author']), ENT_QUOTES); setcookie('author', $Author, $AuthorCookieExpires, $AuthorCookieDir); } else { $Author = htmlspecialchars(stripmagic(@$_COOKIE['author']), ENT_QUOTES); } $Author = preg_replace('/(^[^[:alpha:]]+)|[^-\\w ]/', '', $Author); } if (!isset($AuthorPage)) { $AuthorPage = FmtPageName('$AuthorGroup/$Name', MakePageName($pagename, $Author)); } SDV($AuthorLink, $Author ? "[[~{$Author}]]" : '?'); if (IsEnabled($EnableAuthorSignature, 1)) { $ROSPatterns['/~~~~/'] = '[[~$Author]] $CurrentTime'; $ROSPatterns['/~~~/'] = '[[~$Author]]'; Markup('~~~~', '<links', '/~~~~/', "[[~{$Author}]] {$CurrentTime}"); Markup('~~~', '>~~~~', '/~~~/', "[[~{$Author}]]"); } if (IsEnabled($EnablePostAuthorRequired, 0)) { array_unshift($EditFunctions, 'RequireAuthor'); } ## RequireAuthor forces an author to enter a name before posting. function RequireAuthor($pagename, &$page, &$new) { global $Author, $MessagesFmt, $AuthorRequiredFmt;
function HandleBrowse($pagename, $auth = 'read') { # handle display of a page global $DefaultPageTextFmt, $PageNotFoundHeaderFmt, $HTTPHeaders, $EnableHTMLCache, $NoHTMLCache, $PageCacheFile, $LastModTime, $IsHTMLCached, $FmtV, $HandleBrowseFmt, $PageStartFmt, $PageEndFmt, $PageRedirectFmt; $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT); if (!$page) Abort("?cannot read $pagename"); PCache($pagename,$page); if (PageExists($pagename)) $text = @$page['text']; else { 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' href='{\$PageUrl}?action=edit'>{\$FullName}</a>)</i></p>\n"); if (@!$_GET['from']) { $opt['redirect'] = 1; $PageRedirectFmt = ''; } else { $frompage = MakePageName($pagename, $_GET['from']); $PageRedirectFmt = (!$frompage) ? '' : FmtPageName($PageRedirectFmt, $frompage); } if (@$EnableHTMLCache && !$NoHTMLCache && $PageCacheFile && @filemtime($PageCacheFile) > $LastModTime) { list($ctext) = unserialize(file_get_contents($PageCacheFile)); $FmtV['$PageText'] = "<!--cached-->$ctext"; $IsHTMLCached = 1; StopWatch("HandleBrowse: using cached copy"); } 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("HandleBrowse: caching page"); fwrite($fp, serialize(array($FmtV['$PageText']))); fclose($fp); rename("$PageCacheFile,new", $PageCacheFile); } } } SDV($HandleBrowseFmt,array(&$PageStartFmt, &$PageRedirectFmt, '$PageText', &$PageEndFmt)); PrintFmt($pagename,$HandleBrowseFmt); }
and loads the associated preferences. If there is no ?setprefs= request, then the script uses the 'setprefs' cookie from the browser to load the preference settings. Script maintained by Petko YOTOV www.pmwiki.org/petko */ SDV($PrefsCookie, $CookiePrefix.'setprefs'); SDV($PrefsCookieExpires, $Now + 60 * 60 * 24 * 365); $LogoutCookies[] = $PrefsCookie; $sp = ''; if (@$_COOKIE[$PrefsCookie]) $sp = $_COOKIE[$PrefsCookie]; if (isset($_GET['setprefs'])) { $sp = MakePageName($pagename, $_GET['setprefs']); setcookie($PrefsCookie, $sp, $PrefsCookieExpires, '/'); } if ($sp && PageExists($sp)) XLPage('prefs', $sp, true); if(is_array($XL['prefs'])) { foreach($XL['prefs'] as $k=>$v) { if(! preg_match('/^(e_rows|e_cols|TimeFmt|Locale|Site\\.EditForm)$|^ak_/', $k)) unset($XL['prefs'][$k]); } } XLSDV('en', array( 'ak_view' => '', 'ak_edit' => 'e', 'ak_history' => 'h',
function AttachExist($pagename, $condparm='*') { global $UploadFileFmt; @list($fpat, $pn) = explode(' ', $condparm, 2); $pn = ($pn > '') ? MakePageName($pagename, $pn) : $pagename; $uploaddir = FmtPageName($UploadFileFmt, $pn); $flist = array(); $dirp = @opendir($uploaddir); if ($dirp) { while (($file = readdir($dirp)) !== false) if ($file{0} != '.') $flist[] = $file; closedir($dirp); $flist = MatchNames($flist, $fpat); } return count($flist); }
Markup('[[~','<links','/\\[\\[~(.*?)\\]\\]/',"[[$AuthorGroup/$1]]"); $LogoutCookies[] = $AuthorCookie; if (!isset($Author)) { if (isset($_POST['author'])) { $x = stripmagic($_POST['author']); setcookie($AuthorCookie, $x, $AuthorCookieExpires, $AuthorCookieDir); } elseif (@$_COOKIE[$AuthorCookie]) { $x = stripmagic(@$_COOKIE[$AuthorCookie]); } else $x = @$AuthId; $Author = PHSC(preg_replace("/[^$AuthorNameChars]/", '', $x), ENT_COMPAT); } if (!isset($AuthorPage)) $AuthorPage = FmtPageName('$AuthorGroup/$Name', MakePageName("$AuthorGroup.$AuthorGroup", $Author)); SDV($AuthorLink,($Author) ? "[[~$Author]]" : '?'); if (IsEnabled($EnableAuthorSignature,1)) { SDVA($ROSPatterns, array( '/(?<!~)~~~~(?!~)/' => "[[~$Author]] $CurrentTime", '/(?<!~)~~~(?!~)/' => "[[~$Author]]", )); Markup('~~~~','<[[~','/(?<!~)~~~~(?!~)/',"[[~$Author]] $CurrentTime"); Markup('~~~','>~~~~','/(?<!~)~~~(?!~)/',"[[~$Author]]"); } if (IsEnabled($EnablePostAuthorRequired,0)) array_unshift($EditFunctions,'RequireAuthor'); ## RequireAuthor forces an author to enter a name before posting. function RequireAuthor($pagename, &$page, &$new) {
function InputDefault($pagename, $type, $args) { global $InputValues, $PageTextVarPatterns, $PCache; $args = ParseArgs($args); $args[''] = (array) @$args['']; $name = isset($args['name']) ? $args['name'] : array_shift($args['']); $name = preg_replace('/^\\$:/', 'ptv_', $name); $value = isset($args['value']) ? $args['value'] : array_shift($args['']); if (!isset($InputValues[$name])) { $InputValues[$name] = $value; } if (@$args['request']) { $req = array_merge($_GET, $_POST); foreach ($req as $k => $v) { if (!isset($InputValues[$k])) { $InputValues[$k] = PHSC(stripmagic($v), ENT_NOQUOTES); } } } $source = @$args['source']; if ($source) { $source = MakePageName($pagename, $source); $page = RetrieveAuthPage($source, 'read', false, READPAGE_CURRENT); if ($page) { foreach ((array) $PageTextVarPatterns as $pat) { if (preg_match_all($pat, IsEnabled($PCache[$source]['=preview'], $page['text']), $match, PREG_SET_ORDER)) { foreach ($match as $m) { # if (!isset($InputValues['ptv_'.$m[2]])) PITS:01337 $InputValues['ptv_' . $m[2]] = PHSC(Qualify($source, $m[3]), ENT_NOQUOTES); } } } } } return ''; }
function QualifiedLink($grp, $ref) { return $grp . '1' == FmtPageName('$Group', MakePageName($grp . '1.' . $grp, $ref)) ? "{$grp}/{$ref}" : $ref; }
function NotifyUpdate($pagename, $dir = '') { global $NotifyList, $NotifyListPageFmt, $NotifyFile, $IsPagePosted, $FmtV, $NotifyTimeFmt, $NotifyItemFmt, $SearchPatterns, $NotifySquelch, $NotifyDelay, $Now, $NotifySubjectFmt, $NotifyBodyFmt, $NotifyHeaders, $NotifyParameters; $abort = ignore_user_abort(true); if ($dir) { flush(); chdir($dir); } $GLOBALS['EnableRedirect'] = 0; ## Read in the current notify configuration $pn = FmtPageName($NotifyListPageFmt, $pagename); $npage = ReadPage($pn, READPAGE_CURRENT); preg_match_all('/^[\\s*:#->]*(notify[:=].*)/m', $npage['text'], $nlist); $nlist = array_merge((array) @$NotifyList, (array) @$nlist[1]); if (!$nlist) { return; } ## make sure other processes are locked out Lock(2); ## let's load the current .notifylist table $nfile = FmtPageName($NotifyFile, $pagename); $nfp = @fopen($nfile, 'r'); if ($nfp) { ## get our current squelch and delay timestamps clearstatcache(); $sz = filesize($nfile); list($nextevent, $firstpost) = explode(' ', rtrim(fgets($nfp, $sz))); ## restore our notify array $notify = unserialize(fgets($nfp, $sz)); fclose($nfp); } if (!is_array($notify)) { $notify = array(); } ## if this is for a newly posted page, get its information if ($IsPagePosted) { $page = ReadPage($pagename, READPAGE_CURRENT); $FmtV['$PostTime'] = strftime($NotifyTimeFmt, $Now); $item = urlencode(FmtPageName($NotifyItemFmt, $pagename)); if ($firstpost < 1) { $firstpost = $Now; } } foreach ($nlist as $n) { $opt = ParseArgs($n); $mailto = preg_split('/[\\s,]+/', $opt['notify']); if (!$mailto) { continue; } if ($opt['squelch']) { foreach ($mailto as $m) { $squelch[$m] = $opt['squelch']; } } if (!$IsPagePosted) { continue; } if ($opt['link']) { $link = MakePageName($pagename, $opt['link']); if (!preg_match("/(^|,){$link}(,|\$)/i", $page['targets'])) { continue; } } $pats = @(array) $SearchPatterns[$opt['list']]; if ($opt['group']) { $pats[] = FixGlob($opt['group'], '$1$2.*'); } if ($opt['name']) { $pats[] = FixGlob($opt['name'], '$1*.$2'); } if ($pats && !MatchPageNames($pagename, $pats)) { continue; } if ($opt['trail']) { $trail = ReadTrail($pagename, $opt['trail']); for ($i = 0; $i < count($trail); $i++) { if ($trail[$i]['pagename'] == $pagename) { break; } } if ($i >= count($trail)) { continue; } } foreach ($mailto as $m) { $notify[$m][] = $item; } } $nnow = time(); if ($nnow < $firstpost + $NotifyDelay) { $nextevent = $firstpost + $NotifyDelay; } else { $firstpost = 0; $nextevent = $nnow + 86400; $mailto = array_keys($notify); $subject = FmtPageName($NotifySubjectFmt, $pagename); $body = FmtPageName($NotifyBodyFmt, $pagename); foreach ($mailto as $m) { $msquelch = @$notify[$m]['lastmail'] + (@$squelch[$m] ? $squelch[$m] : $NotifySquelch); if ($nnow < $msquelch) { if ($msquelch < $nextevent && count($notify[$m]) > 1) { $nextevent = $msquelch; } continue; } unset($notify[$m]['lastmail']); if (!$notify[$m]) { unset($notify[$m]); continue; } $mbody = str_replace('$NotifyItems', urldecode(implode("\n", $notify[$m])), $body); if ($NotifyParameters) { mail($m, $subject, $mbody, $NotifyHeaders, $NotifyParameters); } else { mail($m, $subject, $mbody, $NotifyHeaders); } $notify[$m] = array('lastmail' => $nnow); } } ## save the updated notify status $nfp = @fopen($nfile, "w"); if ($nfp) { fputs($nfp, "{$nextevent} {$firstpost}\n"); fputs($nfp, serialize($notify) . "\n"); fclose($nfp); } Lock(0); return true; }
SDV($AuthorCookieExpires, $Now + 60 * 60 * 24 * 30); SDV($AuthorCookieDir, '/'); SDV($AuthorGroup, 'Profiles'); SDV($AuthorRequiredFmt, "<h3 class='wikimessage'>\$[An author name is required.]</h3>"); Markup('[[~', '<[[', '/\\[\\[~(.*?)\\]\\]/', "[[{$AuthorGroup}/\$1]]"); "[[{$AuthorGroup}/\$1]]"; if (!isset($Author)) { if (isset($_POST['author'])) { $Author = htmlspecialchars(stripmagic($_POST['author']), ENT_QUOTES); setcookie('author', $Author, $AuthorCookieExpires, $AuthorCookieDir); } else { $Author = htmlspecialchars(stripmagic(@$_COOKIE['author']), ENT_QUOTES); } $Author = preg_replace('/(^[^[:alpha:]]+)|[^\\w- ]/', '', $Author); } $k = MakePageName($pagename, $Author); SDV($AuthorPage, "{$AuthorGroup}/{$k}"); SDV($AuthorLink, "[[~{$Author}]]"); if (IsEnabled($EnableAuthorSignature, 1)) { $ROSPatterns['/~~~~/'] = '[[~$Author]] $CurrentTime'; $ROSPatterns['/~~~/'] = '[[~$Author]]'; } if (IsEnabled($EnableAuthorRequired, 0)) { array_unshift($EditFunctions, 'RequireAuthor'); } ## RequireAuthor forces an author to enter a name before posting. function RequireAuthor($pagename, &$page, &$new) { global $Author, $EditMessageFmt, $AuthorRequiredFmt; if (!$Author) { $EditMessageFmt .= $AuthorRequiredFmt;
function FmtUploadList($pagename, $args) { global $UploadDir, $UploadPrefixFmt, $UploadUrlFmt, $EnableUploadOverwrite, $TimeFmt, $EnableDirectDownload; $opt = ParseArgs($args); if (@$opt[''][0]) { $pagename = MakePageName($pagename, $opt[''][0]); } if (@$opt['ext']) { $matchext = '/\\.(' . implode('|', preg_split('/\\W+/', $opt['ext'], -1, PREG_SPLIT_NO_EMPTY)) . ')$/i'; } $uploaddir = FmtPageName("{$UploadDir}{$UploadPrefixFmt}", $pagename); $uploadurl = FmtPageName(IsEnabled($EnableDirectDownload, 1) ? "{$UploadUrlFmt}{$UploadPrefixFmt}/" : "\$PageUrl?action=download&upname=", $pagename); $dirp = @opendir($uploaddir); if (!$dirp) { return ''; } $filelist = array(); while (($file = readdir($dirp)) !== false) { if ($file[0] == '.') { continue; } if (@$matchext && !preg_match(@$matchext, $file)) { continue; } $filelist[$file] = $file; } closedir($dirp); $out = array(); asort($filelist); $overwrite = ''; foreach ($filelist as $file => $x) { $name = PUE("{$uploadurl}{$file}"); $stat = stat("{$uploaddir}/{$file}"); if ($EnableUploadOverwrite) { $overwrite = FmtPageName("<a class='createlink'\n href='\$PageUrl?action=upload&upname={$file}'> Δ</a>", $pagename); } $out[] = "<li> <a href='{$name}'>{$file}</a>{$overwrite} ... " . number_format($stat['size']) . " bytes ... " . strftime($TimeFmt, $stat['mtime']) . "</li>"; } return implode("\n", $out); }
function FPLTemplate($pagename, &$matches, $opt) { global $Cursor, $FPLTemplatePageFmt, $PageListArgPattern; 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; } } ## 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') { $i += 4; continue; } $opt = array_merge(ParseArgs($tparts[$i + 2], $PageListArgPattern), $opt); array_splice($tparts, $i, 3); } SDV($opt['class'], 'fpltemplate'); ## 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']); $div = $class ? "<div class='{$class}'>" : '<div>'; $out = $div . MarkupToHTML($pagename, $out, array('escape' => 0)) . '</div>'; $Cursor = $savecursor; StopWatch("FPLTemplate end"); return $out; }
function PageListTermsTargets(&$list, &$opt, $pn, &$page) { global $FmtV; static $reindex = array(); $fold = $GLOBALS['StrFoldFunction']; switch ($opt['=phase']) { case PAGELIST_PRE: $FmtV['$MatchSearched'] = count($list); $incl = array(); $excl = array(); foreach((array)@$opt[''] as $i) { $incl[] = $fold($i); } foreach((array)@$opt['+'] as $i) { $incl[] = $fold($i); } foreach((array)@$opt['-'] as $i) { $excl[] = $fold($i); } $indexterms = PageIndexTerms($incl); foreach($incl as $i) { $delim = (!preg_match('/[^\\w\\x80-\\xff]/', $i)) ? '$' : '/'; $opt['=inclp'][] = $delim . preg_quote($i,$delim) . $delim . 'i'; } if ($excl) $opt['=exclp'][] = '$'.implode('|', array_map('preg_quote',$excl)).'$i'; if (@$opt['link']) { $link = MakePageName($pn, $opt['link']); $opt['=linkp'] = "/(^|,)$link(,|$)/i"; $indexterms[] = " $link "; } if (@$opt['=cached']) return 0; if ($indexterms) { StopWatch("PageListTermsTargets begin count=".count($list)); $xlist = PageIndexGrep($indexterms, true); $list = array_diff($list, $xlist); StopWatch("PageListTermsTargets end count=".count($list)); } if (@$opt['=inclp'] || @$opt['=exclp'] || @$opt['=linkp']) return PAGELIST_ITEM|PAGELIST_POST; return 0; case PAGELIST_ITEM: if (!$page) { $page = ReadPage($pn, READPAGE_CURRENT); $opt['=readc']++; } if (!$page) return 0; if (@$opt['=linkp'] && !preg_match($opt['=linkp'], @$page['targets'])) { $reindex[] = $pn; return 0; } if (@$opt['=inclp'] || @$opt['=exclp']) { $text = $fold($pn."\n".@$page['targets']."\n".@$page['text']); foreach((array)@$opt['=exclp'] as $i) if (preg_match($i, $text)) return 0; foreach((array)@$opt['=inclp'] as $i) if (!preg_match($i, $text)) { if ($i{0} == '$') $reindex[] = $pn; return 0; } } return 1; case PAGELIST_POST: if ($reindex) PageIndexQueueUpdate($reindex); $reindex = array(); return 0; } }
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 readIncludedText ($basepage, $includepage) { $page = ReadPage(MakePageName(trim($basepage), trim($includepage))); return $page['text']; }
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 HandleBrowse($pagename) { # handle display of a page global $DefaultPageTextFmt, $FmtV, $HandleBrowseFmt, $PageStartFmt, $PageEndFmt, $PageRedirectFmt; Lock(1); $page = RetrieveAuthPage($pagename, 'read'); if (!$page) { Abort('?cannot read $pagename'); } PCache($pagename, $page); SDV($PageRedirectFmt, "<p><i>(\$[redirected from] \n <a href='\$PageUrl?action=edit'>\$FullName</a>)</i></p>\$HTMLVSpace\n"); if (isset($page['text'])) { $text = $page['text']; } else { $text = FmtPageName($DefaultPageTextFmt, $pagename); } if (@(!$_GET['from'])) { $PageRedirectFmt = ''; if (preg_match('/\\(:redirect\\s+(.+?):\\)/', $text, $match)) { $rname = MakePageName($pagename, $match[1]); if (PageExists($rname)) { Redirect($rname, "\$PageUrl?from={$pagename}"); } } } else { $PageRedirectFmt = FmtPageName($PageRedirectFmt, $_GET['from']); } $text = '(:groupheader:)' . @$text . '(:groupfooter:)'; $FmtV['$PageText'] = MarkupToHTML($pagename, $text); SDV($HandleBrowseFmt, array(&$PageStartFmt, &$PageRedirectFmt, '$PageText', &$PageEndFmt)); PrintFmt($pagename, $HandleBrowseFmt); }
function LinkPage($pagename, $imap, $path, $title, $txt, $fmt = NULL) { global $QueryFragPattern, $LinkPageExistsFmt, $LinkPageSelfFmt, $LinkPageCreateSpaceFmt, $LinkPageCreateFmt, $LinkTargets, $EnableLinkPageRelative; if (!$fmt && $path[0] == '#') { $path = preg_replace("/[^-.:\\w]/", '', $path); return $path ? "<a href='#{$path}'>{$txt}</a>" : ''; } if (!preg_match("/^\\s*([^#?]+)({$QueryFragPattern})?\$/", $path, $match)) { return ''; } $tgtname = MakePageName($pagename, $match[1]); if (!$tgtname) { return ''; } $qf = @$match[2]; @$LinkTargets[$tgtname]++; if (!$fmt) { if (!PageExists($tgtname) && !preg_match('/[&?]action=/', $qf)) { $fmt = preg_match('/\\s/', $txt) ? $LinkPageCreateSpaceFmt : $LinkPageCreateFmt; } else { $fmt = $tgtname == $pagename && $qf == '' ? $LinkPageSelfFmt : $LinkPageExistsFmt; } } $url = PageVar($tgtname, '$PageUrl'); if (@$EnableLinkPageRelative) { $url = preg_replace('!^[a-z]+://[^/]*!i', '', $url); } $fmt = str_replace(array('$LinkUrl', '$LinkText'), array($url . PUE($qf), $txt), $fmt); return FmtPageName($fmt, $tgtname); }
function LinkPage($pagename,$imap,$path,$title,$txt,$fmt=NULL) { global $QueryFragPattern,$LinkPageExistsFmt,$LinkPageSelfFmt, $LinkPageCreateSpaceFmt,$LinkPageCreateFmt,$FmtV,$LinkTargets; if (!$fmt && $path{0} == '#') { $path = preg_replace("/[^-.:\\w]/", '', $path); return ($path) ? "<a href='#$path'>$txt</a>" : ''; } if (!preg_match("/^\\s*([^#?]+)($QueryFragPattern)?$/",$path,$match)) return ''; $tgtname = MakePageName($pagename, $match[1]); if (!$tgtname) return ''; $qf = @$match[2]; @$LinkTargets[$tgtname]++; if (!$fmt) { if (!PageExists($tgtname) && !preg_match('/[&?]action=/', $qf)) $fmt = preg_match('/\\s/', $txt) ? $LinkPageCreateSpaceFmt : $LinkPageCreateFmt; else $fmt = ($tgtname == $pagename && $qf == '') ? $LinkPageSelfFmt : $LinkPageExistsFmt; } $fmt = str_replace(array('$LinkUrl', '$LinkText'), array(PageVar($tgtname, '$PageUrl').PUE($qf), $txt), $fmt); return FmtPageName($fmt,$tgtname); }
function HandleBrowse($pagename, $auth = 'read') { # handle display of a page global $DefaultPageTextFmt, $PageNotFoundHeaderFmt, $HTTPHeaders, $FmtV, $HandleBrowseFmt, $PageStartFmt, $PageEndFmt, $PageRedirectFmt; $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT); if (!$page) { Abort('?cannot read $pagename'); } PCache($pagename, $page); if (PageExists($pagename)) { $text = @$page['text']; } else { SDV($DefaultPageTextFmt, '(:include $[{$SiteGroup}.PageNotFound]:)'); $text = FmtPageName($DefaultPageTextFmt, $pagename); SDV($PageNotFoundHeaderFmt, 'HTTP/1.1 404 Not Found'); SDV($HTTPHeaders['status'], $PageNotFoundHeaderFmt); } SDV($PageRedirectFmt, "<p><i>(\$[redirected from] \n <a rel='nofollow' href='{\$PageUrl}?action=edit'>{\$FullName}</a>)</i></p>\$HTMLVSpace\n"); if (@(!$_GET['from'])) { $PageRedirectFmt = ''; if (preg_match('/\\(:redirect\\s+(.+?):\\)/', $text, $match)) { $rname = MakePageName($pagename, $match[1]); if (PageExists($rname)) { Redirect($rname, "\$PageUrl?from={$pagename}"); } } } else { $PageRedirectFmt = FmtPageName($PageRedirectFmt, $_GET['from']); } $text = '(:groupheader:)' . @$text . '(:groupfooter:)'; $FmtV['$PageText'] = MarkupToHTML($pagename, $text); SDV($HandleBrowseFmt, array(&$PageStartFmt, &$PageRedirectFmt, '$PageText', &$PageEndFmt)); PrintFmt($pagename, $HandleBrowseFmt); }
function FmtUploadList($pagename, $args) { global $UploadDir, $UploadPrefixFmt, $UploadUrlFmt, $EnableUploadOverwrite, $TimeFmt, $EnableDirectDownload; $opt = ParseArgs($args); if (@$opt[''][0]) $pagename = MakePageName($pagename, $opt[''][0]); if (@$opt['ext']) $matchext = '/\\.(' . implode('|', preg_split('/\\W+/', $opt['ext'], -1, PREG_SPLIT_NO_EMPTY)) . ')$/i'; $uploaddir = FmtPageName("$UploadDir$UploadPrefixFmt", $pagename); $uploadurl = FmtPageName(IsEnabled($EnableDirectDownload, 1) ? "$UploadUrlFmt$UploadPrefixFmt/" : "\$PageUrl?action=download&upname=", $pagename); $dirp = @opendir($uploaddir); if (!$dirp) return ''; $filelist = array(); while (($file=readdir($dirp)) !== false) { if ($file{0} == '.') continue; if (@$matchext && !preg_match(@$matchext, $file)) continue; $filelist[$file] = $file; } closedir($dirp); $out = array(); natcasesort($filelist); $overwrite = ''; foreach($filelist as $file=>$x) { $name = PUE("$uploadurl$file"); $stat = stat("$uploaddir/$file"); if ($EnableUploadOverwrite) $overwrite = FmtPageName("<a rel='nofollow' class='createlink' href='\$PageUrl?action=upload&upname=$file'> Δ</a>", $pagename); $out[] = "<li> <a href='$name'>$file</a>$overwrite ... ". number_format($stat['size']) . " bytes ... " . strftime($TimeFmt, $stat['mtime']) . "</li>"; } return implode("\n",$out); }
function InputDefault($pagename, $type, $args) { global $InputValues, $PageTextVarPatterns; $args = ParseArgs($args); $args[''] = (array)@$args['']; $name = (isset($args['name'])) ? $args['name'] : array_shift($args['']); $name = str_replace('/^\\$:/', 'ptv_', $name); $value = (isset($args['value'])) ? $args['value'] : array_shift($args['']); if (!isset($InputValues[$name])) $InputValues[$name] = $value; if (@$args['request']) { $req = array_merge($_GET, $_POST); foreach($req as $k => $v) if (!isset($InputValues[$k])) $InputValues[$k] = htmlspecialchars(stripmagic($v), ENT_NOQUOTES); } $source = @$args['source']; if ($source) { $source = MakePageName($pagename, $source); $page = RetrieveAuthPage($source, 'read', false, READPAGE_CURRENT); if ($page) { foreach((array)$PageTextVarPatterns as $pat) if (preg_match_all($pat, $page['text'], $match, PREG_SET_ORDER)) foreach($match as $m) if (!isset($InputValues['ptv_'.$m[1]])) $InputValues['ptv_'.$m[2]] = htmlspecialchars(Qualify($source, $m[3]), ENT_NOQUOTES); } } return ''; }