Blame
Date:
Tue Jun 21 04:00:33 2022 UTC
Message:
Daily backup
0001
2021-12-17
jrmu
<?php
0002
2021-12-17
jrmu
/*
0003
2021-12-17
jrmu
PmWiki
0004
2021-12-17
jrmu
Copyright 2001-2020 Patrick R. Michaud
0005
2021-12-17
jrmu
pmichaud@pobox.com
0006
2021-12-17
jrmu
http://www.pmichaud.com/
0007
2021-12-17
jrmu
0008
2021-12-17
jrmu
This program is free software; you can redistribute it and/or modify
0009
2021-12-17
jrmu
it under the terms of the GNU General Public License as published by
0010
2021-12-17
jrmu
the Free Software Foundation; either version 2 of the License, or
0011
2021-12-17
jrmu
(at your option) any later version.
0012
2021-12-17
jrmu
0013
2021-12-17
jrmu
This program is distributed in the hope that it will be useful,
0014
2021-12-17
jrmu
but WITHOUT ANY WARRANTY; without even the implied warranty of
0015
2021-12-17
jrmu
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0016
2021-12-17
jrmu
GNU General Public License for more details.
0017
2021-12-17
jrmu
0018
2021-12-17
jrmu
You should have received a copy of the GNU General Public License
0019
2021-12-17
jrmu
along with this program; if not, write to the Free Software
0020
2021-12-17
jrmu
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0021
2021-12-17
jrmu
0022
2021-12-17
jrmu
----
0023
2021-12-17
jrmu
Note from Pm: Trying to understand the PmWiki code? Wish it had
0024
2021-12-17
jrmu
more comments? If you want help with any of the code here,
0025
2021-12-17
jrmu
write me at <pmichaud@pobox.com> with your question(s) and I'll
0026
2021-12-17
jrmu
provide explanations (and add comments) that answer them.
0027
2021-12-17
jrmu
0028
2021-12-17
jrmu
Script maintained by Petko YOTOV www.pmwiki.org/petko
0029
2021-12-17
jrmu
$Id: pmwiki.php 3643 2020-05-21 14:25:47Z petko $
0030
2021-12-17
jrmu
*/
0031
2021-12-17
jrmu
error_reporting(E_ALL ^ E_NOTICE);
0032
2021-12-17
jrmu
StopWatch('PmWiki');
0033
2021-12-17
jrmu
@ini_set('magic_quotes_runtime', 0);
0034
2021-12-17
jrmu
@ini_set('magic_quotes_sybase', 0);
0035
2021-12-17
jrmu
if (@ini_get('pcre.backtrack_limit') < 1000000)
0036
2021-12-17
jrmu
@ini_set('pcre.backtrack_limit', 1000000);
0037
2021-12-17
jrmu
if (ini_get('register_globals'))
0038
2021-12-17
jrmu
foreach($_REQUEST as $k=>$v) {
0039
2021-12-17
jrmu
if (preg_match('/^(GLOBALS|_SERVER|_GET|_POST|_COOKIE|_FILES|_ENV|_REQUEST|_SESSION|FarmD|WikiDir)$/i', $k)) exit();
0040
2021-12-17
jrmu
${$k}=''; unset(${$k});
0041
2021-12-17
jrmu
}
0042
2021-12-17
jrmu
$UnsafeGlobals = array_keys($GLOBALS); $GCount=0; $FmtV=array();
0043
2021-12-17
jrmu
SDV($FarmD,dirname(__FILE__));
0044
2021-12-17
jrmu
SDV($WorkDir,'wiki.d');
0045
2021-12-17
jrmu
define('PmWiki',1);
0046
2021-12-17
jrmu
if (preg_match('/\\w\\w:/', $FarmD)) exit();
0047
2021-12-17
jrmu
@include_once("$FarmD/scripts/version.php");
0048
2021-12-17
jrmu
$GroupPattern = '[[:upper:]][\\w]*(?:-\\w+)*';
0049
2021-12-17
jrmu
$NamePattern = '[[:upper:]\\d][\\w]*(?:-\\w+)*';
0050
2021-12-17
jrmu
$BlockPattern = 'form|div|table|t[rdh]|p|[uo]l|d[ltd]|h[1-6r]|pre|blockquote';
0051
2021-12-17
jrmu
$WikiWordPattern = '[[:upper:]][[:alnum:]]*(?:[[:upper:]][[:lower:]0-9]|[[:lower:]0-9][[:upper:]])[[:alnum:]]*';
0052
2021-12-17
jrmu
$WikiDir = new PageStore('wiki.d/{$FullName}');
0053
2021-12-17
jrmu
$WikiLibDirs = array(&$WikiDir,new PageStore('$FarmD/wikilib.d/{$FullName}'));
0054
2021-12-17
jrmu
$PageFileEncodeFunction = 'PUE'; # only used if $WikiDir->encodefilenames is set
0055
2021-12-17
jrmu
$PageFileDecodeFunction = 'urldecode';
0056
2021-12-17
jrmu
$LocalDir = 'local';
0057
2021-12-17
jrmu
$InterMapFiles = array("$FarmD/scripts/intermap.txt",
0058
2021-12-17
jrmu
"$FarmD/local/farmmap.txt", '$SiteGroup.InterMap', 'local/localmap.txt');
0059
2021-12-17
jrmu
$Newline = "\263"; # deprecated, 2.0.0
0060
2021-12-17
jrmu
$KeepToken = "\034\034";
0061
2021-12-17
jrmu
$Now=time();
0062
2021-12-17
jrmu
define('READPAGE_CURRENT', $Now+604800);
0063
2021-12-17
jrmu
$TimeFmt = '%B %d, %Y, at %I:%M %p';
0064
2021-12-17
jrmu
$TimeISOFmt = '%Y-%m-%dT%H:%M:%S';
0065
2021-12-17
jrmu
$TimeISOZFmt = '%Y-%m-%dT%H:%M:%SZ';
0066
2021-12-17
jrmu
$MessagesFmt = array();
0067
2021-12-17
jrmu
$BlockMessageFmt = "<h3 class='wikimessage'>$[This post has been blocked by the administrator]</h3>";
0068
2021-12-17
jrmu
$EditFields = array('text');
0069
2021-12-17
jrmu
$EditFunctions = array('EditTemplate', 'RestorePage', 'ReplaceOnSave',
0070
2021-12-17
jrmu
'SaveAttributes', 'PostPage', 'PostRecentChanges', 'AutoCreateTargets',
0071
2021-12-17
jrmu
'PreviewPage');
0072
2021-12-17
jrmu
$EnablePost = 1;
0073
2021-12-17
jrmu
$ChangeSummary = substr(preg_replace('/[\\x00-\\x1f]|=\\]/', '',
0074
2021-12-17
jrmu
stripmagic(@$_REQUEST['csum'])), 0, 100);
0075
2021-12-17
jrmu
$AsSpacedFunction = 'AsSpaced';
0076
2021-12-17
jrmu
$SpaceWikiWords = 0;
0077
2021-12-17
jrmu
$RCDelimPattern = ' ';
0078
2021-12-17
jrmu
$RecentChangesFmt = array(
0079
2021-12-17
jrmu
'$SiteGroup.AllRecentChanges' =>
0080
2021-12-17
jrmu
'* [[{$Group}.{$Name}]] . . . $CurrentTime $[by] $AuthorLink: [=$ChangeSummary=]',
0081
2021-12-17
jrmu
'$Group.RecentChanges' =>
0082
2021-12-17
jrmu
'* [[{$Group}/{$Name}]] . . . $CurrentTime $[by] $AuthorLink: [=$ChangeSummary=]');
0083
2021-12-17
jrmu
$UrlScheme = (@$_SERVER['HTTPS']=='on' || @$_SERVER['SERVER_PORT']==443)
0084
2021-12-17
jrmu
? 'https' : 'http';
0085
2021-12-17
jrmu
$ScriptUrl = $UrlScheme.'://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
0086
2021-12-17
jrmu
$PubDirUrl = preg_replace('#/[^/]*$#', '/pub', $ScriptUrl, 1);
0087
2021-12-17
jrmu
$HTMLVSpace = "<vspace>";
0088
2021-12-17
jrmu
$HTMLPNewline = '';
0089
2021-12-17
jrmu
$MarkupFrame = array();
0090
2021-12-17
jrmu
$MarkupFrameBase = array('cs' => array(), 'vs' => '', 'ref' => 0,
0091
2021-12-17
jrmu
'closeall' => array(), 'is' => array(),
0092
2021-12-17
jrmu
'escape' => 1);
0093
2021-12-17
jrmu
$WikiWordCountMax = 1000000;
0094
2021-12-17
jrmu
$WikiWordCount['PmWiki'] = 1;
0095
2021-12-17
jrmu
$TableRowIndexMax = 1;
0096
2021-12-17
jrmu
$UrlExcludeChars = '<>"{}|\\\\^`()[\\]\'';
0097
2021-12-17
jrmu
$QueryFragPattern = "[?#][^\\s$UrlExcludeChars]*";
0098
2021-12-17
jrmu
$SuffixPattern = '(?:-?[[:alnum:]]+)*';
0099
2021-12-17
jrmu
$LinkPageSelfFmt = "<a class='selflink' href='\$LinkUrl' title='\$LinkAlt'>\$LinkText</a>";
0100
2021-12-17
jrmu
$LinkPageExistsFmt = "<a class='wikilink' href='\$LinkUrl' title='\$LinkAlt'>\$LinkText</a>";
0101
2021-12-17
jrmu
$LinkPageCreateFmt =
0102
2021-12-17
jrmu
"<a class='createlinktext' rel='nofollow' title='\$LinkAlt'
0103
2021-12-17
jrmu
href='{\$PageUrl}?action=edit'>\$LinkText</a><a rel='nofollow'
0104
2021-12-17
jrmu
class='createlink' href='{\$PageUrl}?action=edit'>?</a>";
0105
2021-12-17
jrmu
$UrlLinkFmt =
0106
2021-12-17
jrmu
"<a class='urllink' href='\$LinkUrl' title='\$LinkAlt' rel='nofollow'>\$LinkText</a>";
0107
2021-12-17
jrmu
umask(002);
0108
2021-12-17
jrmu
$CookiePrefix = '';
0109
2021-12-17
jrmu
$SiteGroup = 'Site';
0110
2021-12-17
jrmu
$SiteAdminGroup = 'SiteAdmin';
0111
2021-12-17
jrmu
$DefaultGroup = 'Main';
0112
2021-12-17
jrmu
$DefaultName = 'HomePage';
0113
2021-12-17
jrmu
$GroupHeaderFmt = '(:include {$Group}.GroupHeader self=0 basepage={*$FullName}:)(:nl:)';
0114
2021-12-17
jrmu
$GroupFooterFmt = '(:nl:)(:include {$Group}.GroupFooter self=0 basepage={*$FullName}:)';
0115
2021-12-17
jrmu
$PagePathFmt = array('{$Group}.$1','$1.$1','$1.{$DefaultName}');
0116
2021-12-17
jrmu
$PageAttributes = array(
0117
2021-12-17
jrmu
'passwdread' => '$[Set new read password:]',
0118
2021-12-17
jrmu
'passwdedit' => '$[Set new edit password:]',
0119
2021-12-17
jrmu
'passwdattr' => '$[Set new attribute password:]');
0120
2021-12-17
jrmu
$XLLangs = array('en');
0121
2021-12-17
jrmu
if (preg_match('/^C$|\.UTF-?8/i',setlocale(LC_ALL,0)))
0122
2021-12-17
jrmu
setlocale(LC_ALL,'en_US');
0123
2021-12-17
jrmu
$FmtP = array();
0124
2021-12-17
jrmu
$FmtPV = array(
0125
2021-12-17
jrmu
# '$ScriptUrl' => 'PUE($ScriptUrl)', ## $ScriptUrl is special
0126
2021-12-17
jrmu
'$PageUrl' =>
0127
2021-12-17
jrmu
'PUE(($EnablePathInfo)
0128
2021-12-17
jrmu
? "$ScriptUrl/$group/$name"
0129
2021-12-17
jrmu
: "$ScriptUrl?n=$group.$name")',
0130
2021-12-17
jrmu
'$FullName' => '"$group.$name"',
0131
2021-12-17
jrmu
'$Groupspaced' => '$AsSpacedFunction($group)',
0132
2021-12-17
jrmu
'$Namespaced' => '$AsSpacedFunction($name)',
0133
2021-12-17
jrmu
'$Group' => '$group',
0134
2021-12-17
jrmu
'$Name' => '$name',
0135
2021-12-17
jrmu
'$Titlespaced' => 'FmtPageTitle(@$page["title"], $name, 1)',
0136
2021-12-17
jrmu
'$Title' => 'FmtPageTitle(@$page["title"], $name, 0)',
0137
2021-12-17
jrmu
'$LastModifiedBy' => '@$page["author"]',
0138
2021-12-17
jrmu
'$LastModifiedHost' => '@$page["host"]',
0139
2021-12-17
jrmu
'$LastModified' => 'strftime($GLOBALS["TimeFmt"], $page["time"])',
0140
2021-12-17
jrmu
'$LastModifiedSummary' => '@$page["csum"]',
0141
2021-12-17
jrmu
'$LastModifiedTime' => '$page["time"]',
0142
2021-12-17
jrmu
'$Description' => '@$page["description"]',
0143
2021-12-17
jrmu
'$SiteGroup' => '$GLOBALS["SiteGroup"]',
0144
2021-12-17
jrmu
'$SiteAdminGroup' => '$GLOBALS["SiteAdminGroup"]',
0145
2021-12-17
jrmu
'$VersionNum' => '$GLOBALS["VersionNum"]',
0146
2021-12-17
jrmu
'$Version' => '$GLOBALS["Version"]',
0147
2021-12-17
jrmu
'$WikiTitle' => '$GLOBALS["WikiTitle"]',
0148
2021-12-17
jrmu
'$Author' => 'NoCache($GLOBALS["Author"])',
0149
2021-12-17
jrmu
'$AuthId' => 'NoCache($GLOBALS["AuthId"])',
0150
2021-12-17
jrmu
'$DefaultGroup' => '$GLOBALS["DefaultGroup"]',
0151
2021-12-17
jrmu
'$DefaultName' => '$GLOBALS["DefaultName"]',
0152
2021-12-17
jrmu
'$BaseName' => 'MakeBaseName($pn)',
0153
2021-12-17
jrmu
'$Action' => '$GLOBALS["action"]',
0154
2021-12-17
jrmu
'$PasswdRead' => 'PasswdVar($pn, "read")',
0155
2021-12-17
jrmu
'$PasswdEdit' => 'PasswdVar($pn, "edit")',
0156
2021-12-17
jrmu
'$PasswdAttr' => 'PasswdVar($pn, "attr")',
0157
2021-12-17
jrmu
);
0158
2021-12-17
jrmu
$SaveProperties = array('title', 'description', 'keywords');
0159
2021-12-17
jrmu
$PageTextVarPatterns = array(
0160
2021-12-17
jrmu
'var:' => '/^(:*[ \\t]*(\\w[-\\w]*)[ \\t]*:[ \\t]?)(.*)($)/m',
0161
2021-12-17
jrmu
'(:var:...:)' => '/(\\(: *(\\w[-\\w]*) *:(?!\\))\\s?)(.*?)(:\\))/s'
0162
2021-12-17
jrmu
);
0163
2021-12-17
jrmu
0164
2021-12-17
jrmu
0165
2021-12-17
jrmu
$WikiTitle = 'PmWiki';
0166
2021-12-17
jrmu
$Charset = 'ISO-8859-1';
0167
2021-12-17
jrmu
$HTTPHeaders = array(
0168
2021-12-17
jrmu
"Expires: Tue, 01 Jan 2002 00:00:00 GMT",
0169
2021-12-17
jrmu
"Cache-Control: no-store, no-cache, must-revalidate",
0170
2021-12-17
jrmu
"Content-type: text/html; charset=ISO-8859-1;");
0171
2021-12-17
jrmu
$CacheActions = array('browse','diff','print');
0172
2021-12-17
jrmu
$EnableHTMLCache = 0;
0173
2021-12-17
jrmu
$NoHTMLCache = 0;
0174
2021-12-17
jrmu
$HTMLTagAttr = '';
0175
2021-12-17
jrmu
$HTMLDoctypeFmt =
0176
2021-12-17
jrmu
"<!DOCTYPE html
0177
2021-12-17
jrmu
PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
0178
2021-12-17
jrmu
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
0179
2021-12-17
jrmu
<html xmlns='http://www.w3.org/1999/xhtml' \$HTMLTagAttr><head>\n";
0180
2021-12-17
jrmu
$HTMLStylesFmt['pmwiki'] = "
0181
2021-12-17
jrmu
ul, ol, pre, dl, p { margin-top:0px; margin-bottom:0px; }
0182
2021-12-17
jrmu
code.escaped { white-space: pre; }
0183
2021-12-17
jrmu
.vspace { margin-top:1.33em; }
0184
2021-12-17
jrmu
.indent { margin-left:40px; }
0185
2021-12-17
jrmu
.outdent { margin-left:40px; text-indent:-40px; }
0186
2021-12-17
jrmu
a.createlinktext { text-decoration:none; border-bottom:1px dotted gray; }
0187
2021-12-17
jrmu
a.createlink { text-decoration:none; position:relative; top:-0.5em;
0188
2021-12-17
jrmu
font-weight:bold; font-size:smaller; border-bottom:none; }
0189
2021-12-17
jrmu
img { border:0px; }
0190
2021-12-17
jrmu
";
0191
2021-12-17
jrmu
$HTMLHeaderFmt['styles'] = array(
0192
2021-12-17
jrmu
"<style type='text/css'><!--",&$HTMLStylesFmt,"\n--></style>");
0193
2021-12-17
jrmu
$HTMLBodyFmt = "</head>\n<body>";
0194
2021-12-17
jrmu
$HTMLStartFmt = array('headers:',&$HTMLDoctypeFmt,&$HTMLHeaderFmt,
0195
2021-12-17
jrmu
&$HTMLBodyFmt);
0196
2021-12-17
jrmu
$HTMLEndFmt = "\n</body>\n</html>";
0197
2021-12-17
jrmu
$PageStartFmt = array(&$HTMLStartFmt,"\n<div id='contents'>\n");
0198
2021-12-17
jrmu
$PageEndFmt = array('</div>',&$HTMLEndFmt);
0199
2021-12-17
jrmu
0200
2021-12-17
jrmu
$HandleActions = array(
0201
2021-12-17
jrmu
'browse' => 'HandleBrowse', 'print' => 'HandleBrowse',
0202
2021-12-17
jrmu
'edit' => 'HandleEdit', 'source' => 'HandleSource',
0203
2021-12-17
jrmu
'attr' => 'HandleAttr', 'postattr' => 'HandlePostAttr',
0204
2021-12-17
jrmu
'logout' => 'HandleLogoutA', 'login' => 'HandleLoginA');
0205
2021-12-17
jrmu
$HandleAuth = array(
0206
2021-12-17
jrmu
'browse' => 'read', 'source' => 'read', 'print' => 'read',
0207
2021-12-17
jrmu
'edit' => 'edit', 'attr' => 'attr', 'postattr' => 'attr',
0208
2021-12-17
jrmu
'logout' => 'read', 'login' => 'login');
0209
2021-12-17
jrmu
$ActionTitleFmt = array(
0210
2021-12-17
jrmu
'edit' => '| $[Edit]',
0211
2021-12-17
jrmu
'attr' => '| $[Attributes]',
0212
2021-12-17
jrmu
'login' => '| $[Login]');
0213
2021-12-17
jrmu
$DefaultPasswords = array('admin'=>'@lock','read'=>'','edit'=>'','attr'=>'');
0214
2021-12-17
jrmu
$AuthCascade = array('edit'=>'read', 'attr'=>'edit');
0215
2021-12-17
jrmu
$AuthList = array('' => 1, 'nopass:' => 1, '@nopass' => 1);
0216
2021-12-17
jrmu
$SessionEncode = 'base64_encode';
0217
2021-12-17
jrmu
$SessionDecode = 'base64_decode';
0218
2021-12-17
jrmu
0219
2021-12-17
jrmu
$CallbackFnTemplates = array(
0220
2021-12-17
jrmu
'default' => '%s',
0221
2021-12-17
jrmu
'return' => 'return %s;',
0222
2021-12-17
jrmu
'markup_e' => 'extract($GLOBALS["MarkupToHTML"]); return %s;',
0223
2021-12-17
jrmu
'qualify' => 'extract($GLOBALS["tmp_qualify"]); return %s;',
0224
2021-12-17
jrmu
);
0225
2021-12-17
jrmu
0226
2021-12-17
jrmu
$Conditions['enabled'] = '(boolean)@$GLOBALS[$condparm]';
0227
2021-12-17
jrmu
$Conditions['false'] = 'false';
0228
2021-12-17
jrmu
$Conditions['true'] = 'true';
0229
2021-12-17
jrmu
$Conditions['group'] =
0230
2021-12-17
jrmu
"(boolean)MatchPageNames(\$pagename, FixGlob(\$condparm, '$1$2.*'))";
0231
2021-12-17
jrmu
$Conditions['name'] =
0232
2021-12-17
jrmu
"(boolean)MatchPageNames(\$pagename, FixGlob(\$condparm, '$1*.$2'))";
0233
2021-12-17
jrmu
$Conditions['match'] = 'preg_match("!$condparm!",$pagename)';
0234
2021-12-17
jrmu
$Conditions['authid'] = 'NoCache(@$GLOBALS["AuthId"] > "")';
0235
2021-12-17
jrmu
$Conditions['exists'] = "(boolean)ListPages(FixGlob(
0236
2021-12-17
jrmu
str_replace(array('[[',']]'), array('', ''), \$condparm) , '$1*.$2'))";
0237
2021-12-17
jrmu
$Conditions['equal'] = 'CompareArgs($condparm) == 0';
0238
2021-12-17
jrmu
function CompareArgs($arg)
0239
2021-12-17
jrmu
{ $arg = ParseArgs($arg); return strcmp(@$arg[''][0], @$arg[''][1]); }
0240
2021-12-17
jrmu
0241
2021-12-17
jrmu
$Conditions['auth'] = 'NoCache(CondAuth($pagename, $condparm))';
0242
2021-12-17
jrmu
function CondAuth($pagename, $condparm) {
0243
2021-12-17
jrmu
global $HandleAuth;
0244
2021-12-17
jrmu
@list($level, $pn) = explode(' ', $condparm, 2);
0245
2021-12-17
jrmu
$pn = ($pn > '') ? MakePageName($pagename, $pn) : $pagename;
0246
2021-12-17
jrmu
if (@$HandleAuth[$level]>'') $level = $HandleAuth[$level];
0247
2021-12-17
jrmu
return (boolean)RetrieveAuthPage($pn, $level, false, READPAGE_CURRENT);
0248
2021-12-17
jrmu
}
0249
2021-12-17
jrmu
0250
2021-12-17
jrmu
## CondExpr handles complex conditions (expressions)
0251
2021-12-17
jrmu
## Portions Copyright 2005 by D. Faure (dfaure@cpan.org)
0252
2021-12-17
jrmu
function CondExpr($pagename, $condname, $condparm) {
0253
2021-12-17
jrmu
global $CondExprOps;
0254
2021-12-17
jrmu
SDV($CondExprOps, 'and|x?or|&&|\\|\\||[!()]');
0255
2021-12-17
jrmu
if ($condname == '(' || $condname == '[')
0256
2021-12-17
jrmu
$condparm = preg_replace('/[\\]\\)]\\s*$/', '', $condparm);
0257
2021-12-17
jrmu
$condparm = str_replace('&amp;&amp;', '&&', $condparm);
0258
2021-12-17
jrmu
$terms = preg_split("/(?<!\\S)($CondExprOps)(?!\\S)/i", $condparm, -1,
0259
2021-12-17
jrmu
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
0260
2021-12-17
jrmu
foreach($terms as $i => $t) {
0261
2021-12-17
jrmu
$t = trim($t);
0262
2021-12-17
jrmu
if (preg_match("/^($CondExprOps)$/i", $t)) continue;
0263
2021-12-17
jrmu
if ($t) $terms[$i] = CondText($pagename, "if $t", 'TRUE') ? '1' : '0';
0264
2021-12-17
jrmu
}
0265
2021-12-17
jrmu
return @eval('return(' . implode(' ', $terms) . ');');
0266
2021-12-17
jrmu
}
0267
2021-12-17
jrmu
$Conditions['expr'] = 'CondExpr($pagename, $condname, $condparm)';
0268
2021-12-17
jrmu
$Conditions['('] = 'CondExpr($pagename, $condname, $condparm)';
0269
2021-12-17
jrmu
$Conditions['['] = 'CondExpr($pagename, $condname, $condparm)';
0270
2021-12-17
jrmu
0271
2021-12-17
jrmu
$MarkupTable['_begin']['seq'] = 'B';
0272
2021-12-17
jrmu
$MarkupTable['_end']['seq'] = 'E';
0273
2021-12-17
jrmu
Markup('fulltext','>_begin');
0274
2021-12-17
jrmu
Markup('split','>fulltext',"\n",
0275
2021-12-17
jrmu
'$RedoMarkupLine=1; return explode("\n",$x);');
0276
2021-12-17
jrmu
Markup('directives','>split');
0277
2021-12-17
jrmu
Markup('inline','>directives');
0278
2021-12-17
jrmu
Markup('links','>inline');
0279
2021-12-17
jrmu
Markup('block','>links');
0280
2021-12-17
jrmu
Markup('style','>block');
0281
2021-12-17
jrmu
Markup('closeall', '_begin',
0282
2021-12-17
jrmu
'/^\\(:closeall:\\)$/', "MarkupMarkupClose");
0283
2021-12-17
jrmu
function MarkupMarkupClose() { return '<:block>' . MarkupClose(); }
0284
2021-12-17
jrmu
0285
2021-12-17
jrmu
$ImgExtPattern="\\.(?:gif|jpg|jpeg|png|svgz?|GIF|JPG|JPEG|PNG|SVGZ?)";
0286
2021-12-17
jrmu
$ImgTagFmt="<img src='\$LinkUrl' alt='\$LinkAlt' title='\$LinkAlt' />";
0287
2021-12-17
jrmu
0288
2021-12-17
jrmu
$BlockMarkups = array(
0289
2021-12-17
jrmu
'block' => array('','','',0),
0290
2021-12-17
jrmu
'ul' => array('<ul><li>','</li><li>','</li></ul>',1),
0291
2021-12-17
jrmu
'dl' => array('<dl>','</dd>','</dd></dl>',1),
0292
2021-12-17
jrmu
'ol' => array('<ol><li>','</li><li>','</li></ol>',1),
0293
2021-12-17
jrmu
'p' => array('<p>','','</p>',0),
0294
2021-12-17
jrmu
'indent' =>
0295
2021-12-17
jrmu
array("<div class='indent'>","</div><div class='indent'>",'</div>',1),
0296
2021-12-17
jrmu
'outdent' =>
0297
2021-12-17
jrmu
array("<div class='outdent'>","</div><div class='outdent'>",'</div>',1),
0298
2021-12-17
jrmu
'pre' => array('<pre>','','</pre>',0),
0299
2021-12-17
jrmu
'table' => array("<table width='100%'>",'','</table>',0));
0300
2021-12-17
jrmu
0301
2021-12-17
jrmu
foreach(array('http:','https:','mailto:','ftp:','news:','gopher:','nap:',
0302
2021-12-17
jrmu
'file:', 'tel:', 'geo:') as $m)
0303
2021-12-17
jrmu
{ $LinkFunctions[$m] = 'LinkIMap'; $IMap[$m]="$m$1"; }
0304
2021-12-17
jrmu
$LinkFunctions['<:page>'] = 'LinkPage';
0305
2021-12-17
jrmu
0306
2021-12-17
jrmu
$q = preg_replace('/(\\?|%3f)([-\\w]+=)/i', '&$2', @$_SERVER['QUERY_STRING']);
0307
2021-12-17
jrmu
if ($q != @$_SERVER['QUERY_STRING']) {
0308
2021-12-17
jrmu
unset($_GET);
0309
2021-12-17
jrmu
parse_str($q, $_GET);
0310
2021-12-17
jrmu
$_REQUEST = array_merge($_REQUEST, $_GET, $_POST);
0311
2021-12-17
jrmu
}
0312
2021-12-17
jrmu
0313
2021-12-17
jrmu
if (isset($_GET['action'])) $action = $_GET['action'];
0314
2021-12-17
jrmu
elseif (isset($_POST['action'])) $action = $_POST['action'];
0315
2021-12-17
jrmu
else $action = 'browse';
0316
2021-12-17
jrmu
0317
2021-12-17
jrmu
$pagename = @$_REQUEST['n'];
0318
2021-12-17
jrmu
if (!$pagename) $pagename = @$_REQUEST['pagename'];
0319
2021-12-17
jrmu
if (!$pagename &&
0320
2021-12-17
jrmu
preg_match('!^'.preg_quote($_SERVER['SCRIPT_NAME'],'!').'/?([^?]*)!',
0321
2021-12-17
jrmu
$_SERVER['REQUEST_URI'],$match))
0322
2021-12-17
jrmu
$pagename = urldecode($match[1]);
0323
2021-12-17
jrmu
if (preg_match('/[\\x80-\\xbf]/',$pagename))
0324
2021-12-17
jrmu
$pagename=utf8_decode($pagename);
0325
2021-12-17
jrmu
$pagename = preg_replace('![^[:alnum:]\\x80-\\xff]+$!','',$pagename);
0326
2021-12-17
jrmu
$pagename_unfiltered = $pagename;
0327
2021-12-17
jrmu
$pagename = preg_replace('![${}\'"\\\\]+!', '', $pagename);
0328
2021-12-17
jrmu
$FmtPV['$RequestedPage'] = 'PHSC($GLOBALS["pagename_unfiltered"], ENT_QUOTES)';
0329
2021-12-17
jrmu
$Cursor['*'] = &$pagename;
0330
2021-12-17
jrmu
if (function_exists("date_default_timezone_get") ) { # fix PHP5.3 warnings
0331
2021-12-17
jrmu
@date_default_timezone_set(@date_default_timezone_get());
0332
2021-12-17
jrmu
}
0333
2021-12-17
jrmu
0334
2021-12-17
jrmu
$DenyHtaccessContent = <<<EOF
0335
2021-12-17
jrmu
<IfModule !mod_authz_host.c>
0336
2021-12-17
jrmu
Order Deny,Allow
0337
2021-12-17
jrmu
Deny from all
0338
2021-12-17
jrmu
</IfModule>
0339
2021-12-17
jrmu
0340
2021-12-17
jrmu
<IfModule mod_authz_host.c>
0341
2021-12-17
jrmu
Require all denied
0342
2021-12-17
jrmu
</IfModule>
0343
2021-12-17
jrmu
0344
2021-12-17
jrmu
EOF;
0345
2021-12-17
jrmu
0346
2021-12-17
jrmu
if (file_exists("$FarmD/local/farmconfig.php"))
0347
2021-12-17
jrmu
include_once("$FarmD/local/farmconfig.php");
0348
2021-12-17
jrmu
if (IsEnabled($EnableLocalConfig,1)) {
0349
2021-12-17
jrmu
if (file_exists("$LocalDir/config.php"))
0350
2021-12-17
jrmu
include_once("$LocalDir/config.php");
0351
2021-12-17
jrmu
elseif (file_exists('config.php'))
0352
2021-12-17
jrmu
include_once('config.php');
0353
2021-12-17
jrmu
}
0354
2021-12-17
jrmu
0355
2021-12-17
jrmu
SDV($CurrentTime, strftime($TimeFmt, $Now));
0356
2021-12-17
jrmu
SDV($CurrentTimeISO, strftime($TimeISOFmt, $Now));
0357
2021-12-17
jrmu
0358
2021-12-17
jrmu
if (IsEnabled($EnableStdConfig,1))
0359
2021-12-17
jrmu
include_once("$FarmD/scripts/stdconfig.php");
0360
2021-12-17
jrmu
0361
2021-12-17
jrmu
if (isset($PostConfig) && is_array($PostConfig)) {
0362
2021-12-17
jrmu
asort($PostConfig, SORT_NUMERIC);
0363
2021-12-17
jrmu
foreach ($PostConfig as $k=>$v) {
0364
2021-12-17
jrmu
if (!$k || !$v || $v<50) continue;
0365
2021-12-17
jrmu
if (function_exists($k)) $k($pagename);
0366
2021-12-17
jrmu
elseif (file_exists($k)) include_once($k);
0367
2021-12-17
jrmu
}
0368
2021-12-17
jrmu
}
0369
2021-12-17
jrmu
0370
2021-12-17
jrmu
function pmsetcookie($name, $val="", $exp=0, $path="", $dom="", $secure=null, $httponly=null) {
0371
2021-12-17
jrmu
global $EnableCookieSecure, $EnableCookieHTTPOnly, $SetCookieFunction;
0372
2021-12-17
jrmu
if(IsEnabled($SetCookieFunction))
0373
2021-12-17
jrmu
return $SetCookieFunction($name, $val, $exp, $path, $dom, $secure, $httponly);
0374
2021-12-17
jrmu
if (is_null($secure)) $secure = IsEnabled($EnableCookieSecure, false);
0375
2021-12-17
jrmu
if (is_null($httponly)) $httponly = IsEnabled($EnableCookieHTTPOnly, false);
0376
2021-12-17
jrmu
setcookie($name, $val, $exp, $path, $dom, $secure, $httponly);
0377
2021-12-17
jrmu
}
0378
2021-12-17
jrmu
if (IsEnabled($EnableCookieSecure, false))
0379
2021-12-17
jrmu
@ini_set('session.cookie_secure', $EnableCookieSecure);
0380
2021-12-17
jrmu
if (IsEnabled($EnableCookieHTTPOnly, false))
0381
2021-12-17
jrmu
@ini_set('session.cookie_httponly', $EnableCookieHTTPOnly);
0382
2021-12-17
jrmu
0383
2021-12-17
jrmu
foreach((array)$InterMapFiles as $f) {
0384
2021-12-17
jrmu
$f = FmtPageName($f, $pagename);
0385
2021-12-17
jrmu
if (($v = @file($f)))
0386
2021-12-17
jrmu
$v = preg_replace('/^\\s*(?>\\w[-\\w]*)(?!:)/m', '$0:', implode('', $v));
0387
2021-12-17
jrmu
else if (@PageExists($f)) {
0388
2021-12-17
jrmu
$p = ReadPage($f, READPAGE_CURRENT);
0389
2021-12-17
jrmu
$v = @$p['text'];
0390
2021-12-17
jrmu
} else continue;
0391
2021-12-17
jrmu
if (!preg_match_all("/^\\s*(\\w[-\\w]*:)[^\\S\n]+(\\S*)/m", $v,
0392
2021-12-17
jrmu
$match, PREG_SET_ORDER)) continue;
0393
2021-12-17
jrmu
foreach($match as $m) {
0394
2021-12-17
jrmu
if (strpos($m[2], '$1') === false) $m[2] .= '$1';
0395
2021-12-17
jrmu
$LinkFunctions[$m[1]] = 'LinkIMap';
0396
2021-12-17
jrmu
$IMap[$m[1]] = FmtPageName($m[2], $pagename);
0397
2021-12-17
jrmu
}
0398
2021-12-17
jrmu
}
0399
2021-12-17
jrmu
0400
2021-12-17
jrmu
$keys = array_keys($AuthCascade);
0401
2021-12-17
jrmu
while ($keys) {
0402
2021-12-17
jrmu
$k = array_shift($keys); $t = $AuthCascade[$k];
0403
2021-12-17
jrmu
if (in_array($t, $keys))
0404
2021-12-17
jrmu
{ unset($AuthCascade[$k]); $AuthCascade[$k] = $t; array_push($keys, $k); }
0405
2021-12-17
jrmu
}
0406
2021-12-17
jrmu
0407
2021-12-17
jrmu
$LinkPattern = implode('|',array_keys($LinkFunctions)); # after InterMaps
0408
2021-12-17
jrmu
SDV($LinkPageCreateSpaceFmt,$LinkPageCreateFmt);
0409
2021-12-17
jrmu
$ActionTitle = FmtPageName(@$ActionTitleFmt[$action], $pagename);
0410
2021-12-17
jrmu
0411
2021-12-17
jrmu
0412
2021-12-17
jrmu
if (!@$HandleActions[$action] || !function_exists($HandleActions[$action]))
0413
2021-12-17
jrmu
$action='browse';
0414
2021-12-17
jrmu
if (IsEnabled($EnableActions, 1)) HandleDispatch($pagename, $action);
0415
2021-12-17
jrmu
Lock(0);
0416
2021-12-17
jrmu
return;
0417
2021-12-17
jrmu
0418
2021-12-17
jrmu
## HandleDispatch() is used to dispatch control to the appropriate
0419
2021-12-17
jrmu
## action handler with the appropriate permissions.
0420
2021-12-17
jrmu
## If a message is supplied, it is added to $MessagesFmt.
0421
2021-12-17
jrmu
function HandleDispatch($pagename, $action, $msg=NULL) {
0422
2021-12-17
jrmu
global $MessagesFmt, $HandleActions, $HandleAuth;
0423
2021-12-17
jrmu
if ($msg) $MessagesFmt[] = "<div class='wikimessage'>$msg</div>";
0424
2021-12-17
jrmu
$fn = $HandleActions[$action];
0425
2021-12-17
jrmu
$auth = @$HandleAuth[$action];
0426
2021-12-17
jrmu
if (!$auth) $auth = 'read';
0427
2021-12-17
jrmu
return $fn($pagename, $auth);
0428
2021-12-17
jrmu
}
0429
2021-12-17
jrmu
0430
2021-12-17
jrmu
## helper functions
0431
2021-12-17
jrmu
function stripmagic($x) {
0432
2021-12-17
jrmu
$fn = 'get_magic_quotes_gpc';
0433
2021-12-17
jrmu
if (!function_exists($fn)) return $x;
0434
2021-12-17
jrmu
if (is_array($x)) {
0435
2021-12-17
jrmu
foreach($x as $k=>$v) $x[$k] = stripmagic($v);
0436
2021-12-17
jrmu
return $x;
0437
2021-12-17
jrmu
}
0438
2021-12-17
jrmu
return @$fn() ? stripslashes($x) : $x;
0439
2021-12-17
jrmu
}
0440
2021-12-17
jrmu
function pre_r(&$x)
0441
2021-12-17
jrmu
{ return '<pre>'.PHSC(print_r($x, true)).'</pre>'; }
0442
2021-12-17
jrmu
function PSS($x)
0443
2021-12-17
jrmu
{ return str_replace('\\"','"',$x); }
0444
2021-12-17
jrmu
function PVS($x)
0445
2021-12-17
jrmu
{ return preg_replace("/\n[^\\S\n]*(?=\n)/", "\n<:vspace>", $x); }
0446
2021-12-17
jrmu
function PVSE($x) { return PVS(PHSC($x, ENT_NOQUOTES)); }
0447
2021-12-17
jrmu
function PZZ($x,$y='') { return ''; }
0448
2021-12-17
jrmu
function PRR($x=NULL)
0449
2021-12-17
jrmu
{ if ($x || is_null($x)) $GLOBALS['RedoMarkupLine']++; return $x; }
0450
2021-12-17
jrmu
function PUE($x)
0451
2021-12-17
jrmu
{ return preg_replace_callback('/[\\x80-\\xff \'"<>]/', "cb_pue", $x); }
0452
2021-12-17
jrmu
function cb_pue($m) { return '%'.dechex(ord($m[0])); }
0453
2021-12-17
jrmu
function PQA($x) {
0454
2021-12-17
jrmu
$out = '';
0455
2021-12-17
jrmu
if (preg_match_all('/([a-zA-Z][-\\w]*)\\s*=\\s*("[^"]*"|\'[^\']*\'|\\S*)/',
0456
2021-12-17
jrmu
$x, $attr, PREG_SET_ORDER)) {
0457
2021-12-17
jrmu
foreach($attr as $a) {
0458
2021-12-17
jrmu
if (preg_match('/^on/i', $a[1])) continue;
0459
2021-12-17
jrmu
$val = preg_replace('/^([\'"]?)(.*)\\1$/', '$2', $a[2]);
0460
2021-12-17
jrmu
$val = str_replace("'", '&#39;', $val);
0461
2021-12-17
jrmu
$out .= "{$a[1]}='$val' ";
0462
2021-12-17
jrmu
}
0463
2021-12-17
jrmu
}
0464
2021-12-17
jrmu
return $out;
0465
2021-12-17
jrmu
}
0466
2021-12-17
jrmu
function SDV(&$v,$x) { if (!isset($v)) $v=$x; }
0467
2021-12-17
jrmu
function SDVA(&$var,$val)
0468
2021-12-17
jrmu
{ foreach($val as $k=>$v) if (!isset($var[$k])) $var[$k]=$v; }
0469
2021-12-17
jrmu
function IsEnabled(&$var,$f=0)
0470
2021-12-17
jrmu
{ return (isset($var)) ? $var : $f; }
0471
2021-12-17
jrmu
function SetTmplDisplay($var, $val)
0472
2021-12-17
jrmu
{ NoCache(); $GLOBALS['TmplDisplay'][$var] = $val; }
0473
2021-12-17
jrmu
function NoCache($x = '') { $GLOBALS['NoHTMLCache'] |= 1; return $x; }
0474
2021-12-17
jrmu
function ParseArgs($x, $optpat = '(?>(\\w+)[:=])') {
0475
2021-12-17
jrmu
$z = array();
0476
2021-12-17
jrmu
preg_match_all("/($optpat|[-+])?(\"[^\"]*\"|'[^']*'|\\S+)/",
0477
2021-12-17
jrmu
$x, $terms, PREG_SET_ORDER);
0478
2021-12-17
jrmu
foreach($terms as $t) {
0479
2021-12-17
jrmu
$v = preg_replace('/^([\'"])?(.*)\\1$/', '$2', $t[3]);
0480
2021-12-17
jrmu
if ($t[2]) { $z['#'][] = $t[2]; $z[$t[2]] = $v; }
0481
2021-12-17
jrmu
else { $z['#'][] = $t[1]; $z[$t[1]][] = $v; }
0482
2021-12-17
jrmu
$z['#'][] = $v;
0483
2021-12-17
jrmu
}
0484
2021-12-17
jrmu
return $z;
0485
2021-12-17
jrmu
}
0486
2021-12-17
jrmu
function PHSC($x, $flags=ENT_COMPAT, $enc=null, $dbl_enc=true) { # for PHP 5.4
0487
2021-12-17
jrmu
if (is_null($enc)) $enc = "ISO-8859-1"; # single-byte charset
0488
2021-12-17
jrmu
if (! is_array($x)) return @htmlspecialchars($x, $flags, $enc, $dbl_enc);
0489
2021-12-17
jrmu
foreach($x as $k=>$v) $x[$k] = PHSC($v, $flags, $enc, $dbl_enc);
0490
2021-12-17
jrmu
return $x;
0491
2021-12-17
jrmu
}
0492
2021-12-17
jrmu
function PCCF($code, $template = 'default', $args = '$m') {
0493
2021-12-17
jrmu
global $CallbackFnTemplates, $CallbackFunctions, $PCCFOverrideFunction;
0494
2021-12-17
jrmu
if ($PCCFOverrideFunction && is_callable($PCCFOverrideFunction))
0495
2021-12-17
jrmu
return $PCCFOverrideFunction($code, $template, $args);
0496
2021-12-17
jrmu
0497
2021-12-17
jrmu
if (!isset($CallbackFnTemplates[$template]))
0498
2021-12-17
jrmu
Abort("No \$CallbackFnTemplates[$template]).");
0499
2021-12-17
jrmu
$code = sprintf($CallbackFnTemplates[$template], $code);
0500
2021-12-17
jrmu
if (!isset($CallbackFunctions[$code])) {
0501
2021-12-17
jrmu
$fn = create_function($args, $code); # called by old addon|skin|recipe needing update, see pmwiki.org/Troubleshooting
0502
2021-12-17
jrmu
if ($fn) $CallbackFunctions[$code] = $fn;
0503
2021-12-17
jrmu
else StopWatch("Failed to create callback function: ".PHSC($code));
0504
2021-12-17
jrmu
}
0505
2021-12-17
jrmu
return $CallbackFunctions[$code];
0506
2021-12-17
jrmu
}
0507
2021-12-17
jrmu
function PPRE($pat, $rep, $x) {
0508
2021-12-17
jrmu
$lambda = PCCF("return $rep;");
0509
2021-12-17
jrmu
return preg_replace_callback($pat, $lambda, $x);
0510
2021-12-17
jrmu
}
0511
2021-12-17
jrmu
function PPRA($array, $x) {
0512
2021-12-17
jrmu
foreach((array)$array as $pat => $rep) {
0513
2021-12-17
jrmu
$fmt = $x; # for $FmtP
0514
2021-12-17
jrmu
if (is_callable($rep) && $rep != '_') $x = preg_replace_callback($pat,$rep,$x);
0515
2021-12-17
jrmu
else $x = preg_replace($pat,$rep,$x);# simple text OR called by old addon|skin|recipe needing update, see pmwiki.org/Troubleshooting
0516
2021-12-17
jrmu
}
0517
2021-12-17
jrmu
return $x;
0518
2021-12-17
jrmu
}
0519
2021-12-17
jrmu
## callback functions
0520
2021-12-17
jrmu
class PPRC { # PmWiki preg replace callbacks + pass local vars
0521
2021-12-17
jrmu
var $vars;
0522
2021-12-17
jrmu
function __construct($vars = false) {
0523
2021-12-17
jrmu
if ($vars && !is_null($vars)) $this->vars = $vars;
0524
2021-12-17
jrmu
}
0525
2021-12-17
jrmu
function pagevar($m) { # called from FmtPageName
0526
2021-12-17
jrmu
$pagename = $this->vars;
0527
2021-12-17
jrmu
return PageVar($pagename, $m[1]);
0528
2021-12-17
jrmu
}
0529
2021-12-17
jrmu
}
0530
2021-12-17
jrmu
0531
2021-12-17
jrmu
# restores kept/protected strings
0532
2021-12-17
jrmu
function cb_expandkpv($m) { return $GLOBALS['KPV'][$m[1]]; }
0533
2021-12-17
jrmu
0534
2021-12-17
jrmu
# make a string upper or lower case in various patterns
0535
2021-12-17
jrmu
function cb_toupper($m) { return strtoupper($m[1]); }
0536
2021-12-17
jrmu
function cb_tolower($m) { return strtolower($m[1]); }
0537
2021-12-17
jrmu
0538
2021-12-17
jrmu
function pmcrypt($str, $salt=null) {
0539
2021-12-17
jrmu
if ($salt && preg_match('/^(-?@|\\*$)/', $salt)) return false;
0540
2021-12-17
jrmu
if (!is_null($salt)) return crypt($str, $salt);
0541
2021-12-17
jrmu
0542
2021-12-17
jrmu
if (function_exists('password_hash'))
0543
2021-12-17
jrmu
return password_hash($str, PASSWORD_DEFAULT);
0544
2021-12-17
jrmu
return crypt($str);
0545
2021-12-17
jrmu
}
0546
2021-12-17
jrmu
0547
2021-12-17
jrmu
function StopWatch($x) {
0548
2021-12-17
jrmu
global $StopWatch, $EnableStopWatch;
0549
2021-12-17
jrmu
if (!$EnableStopWatch) return;
0550
2021-12-17
jrmu
static $wstart = 0, $ustart = 0;
0551
2021-12-17
jrmu
list($usec,$sec) = explode(' ',microtime());
0552
2021-12-17
jrmu
$wtime = ($sec+$usec);
0553
2021-12-17
jrmu
if (!$wstart) $wstart = $wtime;
0554
2021-12-17
jrmu
if ($EnableStopWatch != 2)
0555
2021-12-17
jrmu
{ $StopWatch[] = sprintf("%05.2f %s", $wtime-$wstart, $x); return; }
0556
2021-12-17
jrmu
$dat = getrusage();
0557
2021-12-17
jrmu
$utime = ($dat['ru_utime.tv_sec']+$dat['ru_utime.tv_usec']/1000000);
0558
2021-12-17
jrmu
if (!$ustart) $ustart=$utime;
0559
2021-12-17
jrmu
$StopWatch[] =
0560
2021-12-17
jrmu
sprintf("%05.2f %05.2f %s", $wtime-$wstart, $utime-$ustart, $x);
0561
2021-12-17
jrmu
}
0562
2021-12-17
jrmu
0563
2021-12-17
jrmu
0564
2021-12-17
jrmu
## DRange converts a variety of string formats into date (ranges).
0565
2021-12-17
jrmu
## It returns the start and end timestamps (+1 second) of the specified date.
0566
2021-12-17
jrmu
function DRange($when) {
0567
2021-12-17
jrmu
global $Now;
0568
2021-12-17
jrmu
## unix/posix @timestamp dates
0569
2021-12-17
jrmu
if (preg_match('/^\\s*@(\\d+)\\s*(.*)$/', $when, $m)) {
0570
2021-12-17
jrmu
$t0 = $m[2] ? strtotime($m[2], $m[1]) : $m[1];
0571
2021-12-17
jrmu
return array($t0, $t0+1);
0572
2021-12-17
jrmu
}
0573
2021-12-17
jrmu
## ISO-8601 dates
0574
2021-12-17
jrmu
$dpat = '/
0575
2021-12-17
jrmu
(?<!\\d) # non-digit
0576
2021-12-17
jrmu
(19\\d\\d|20[0-3]\\d) # year ($1)
0577
2021-12-17
jrmu
([-.\\/]?) # date separator ($2)
0578
2021-12-17
jrmu
(0\\d|1[0-2]) # month ($3)
0579
2021-12-17
jrmu
(?: \\2 # repeat date separator
0580
2021-12-17
jrmu
([0-2]\\d|3[0-1]) # day ($4)
0581
2021-12-17
jrmu
(?: T # time marker
0582
2021-12-17
jrmu
([01]\\d|2[0-4]) # hour ($5)
0583
2021-12-17
jrmu
([.:]?) # time separator ($6)
0584
2021-12-17
jrmu
([0-5]\\d) # minute ($7)
0585
2021-12-17
jrmu
(?: \\6 # repeat time separator
0586
2021-12-17
jrmu
([0-5]\\d|60) # seconds ($8)
0587
2021-12-17
jrmu
)? # optional :ss
0588
2021-12-17
jrmu
)? # optional Thh:mm:ss
0589
2021-12-17
jrmu
)? # optional -ddThh:mm:ss
0590
2021-12-17
jrmu
(?!\d) # non-digit
0591
2021-12-17
jrmu
/x';
0592
2021-12-17
jrmu
if (preg_match($dpat, $when, $m) &&
0593
2021-12-17
jrmu
!preg_match('/[+-]\\s*\\d+\\s*(sec(ond)?|min(ute)?|forth?night|day|week(day)?|month|year)s?/i', $when)) {
0594
2021-12-17
jrmu
$n = $m;
0595
2021-12-17
jrmu
## if no time given, assume range of 1 day (except when full month)
0596
2021-12-17
jrmu
if (@$m[4]>'' && @$m[5] == '') { @$n[4]++; }
0597
2021-12-17
jrmu
## if no day given, assume 1st of month and full month range
0598
2021-12-17
jrmu
if (@$m[4] == '') { $m[4] = 1; $n[4] = 1; $n[3]++; }
0599
2021-12-17
jrmu
## if no seconds given, assume range of 1 minute (except when full day)
0600
2021-12-17
jrmu
if (@$m[7]>'' && @$m[8] == '') { @$n[7]++; }
0601
2021-12-17
jrmu
$t0 = @mktime($m[5], $m[7], $m[8], $m[3], $m[4], $m[1]);
0602
2021-12-17
jrmu
$t1 = @mktime($n[5], $n[7], $n[8], $n[3], $n[4], $n[1]);
0603
2021-12-17
jrmu
return array($t0, $t1);
0604
2021-12-17
jrmu
}
0605
2021-12-17
jrmu
## now, today, tomorrow, yesterday
0606
2021-12-17
jrmu
NoCache();
0607
2021-12-17
jrmu
if ($when == 'now') return array($Now, $Now+1);
0608
2021-12-17
jrmu
$m = localtime(time());
0609
2021-12-17
jrmu
if ($when == 'tomorrow') { $m[3]++; $when = 'today'; }
0610
2021-12-17
jrmu
if ($when == 'yesterday') { $m[3]--; $when = 'today'; }
0611
2021-12-17
jrmu
if ($when == 'today')
0612
2021-12-17
jrmu
return array(mktime(0, 0, 0, $m[4]+1, $m[3] , $m[5]+1900),
0613
2021-12-17
jrmu
mktime(0, 0, 0, $m[4]+1, $m[3]+1, $m[5]+1900));
0614
2021-12-17
jrmu
if (preg_match('/^\\s*$/', $when)) return array(-1, -1);
0615
2021-12-17
jrmu
$t0 = strtotime($when);
0616
2021-12-17
jrmu
$t1 = strtotime("+1 day", $t0);
0617
2021-12-17
jrmu
return array($t0, $t1);
0618
2021-12-17
jrmu
}
0619
2021-12-17
jrmu
0620
2021-12-17
jrmu
## DiffTimeCompact subtracts 2 timestamps and outputs a compact
0621
2021-12-17
jrmu
## human-readable delay in hours, days, weeks, months or years
0622
2021-12-17
jrmu
function DiffTimeCompact($time, $time2=null, $precision=1) {
0623
2021-12-17
jrmu
if(is_null($time2)) $time2 = $GLOBALS['Now'];
0624
2021-12-17
jrmu
$suffix = explode(',', XL('h,d,w,m,y'));
0625
2021-12-17
jrmu
$x = $hours = abs($time2 - $time)/3600;
0626
2021-12-17
jrmu
if($x<24) return round($x,$precision).$suffix[0];
0627
2021-12-17
jrmu
$x /= 24; if($x<14) return round($x,$precision).$suffix[1];
0628
2021-12-17
jrmu
$x /= 7; if($x< 9) return round($x,$precision).$suffix[2];
0629
2021-12-17
jrmu
$x = $hours/2/365.2425; if($x<24) return round($x,$precision).$suffix[3];
0630
2021-12-17
jrmu
return round($hours/24/365.2425,$precision).$suffix[4];
0631
2021-12-17
jrmu
}
0632
2021-12-17
jrmu
0633
2021-12-17
jrmu
## FileSizeCompact outputs a human readable file size
0634
2021-12-17
jrmu
## with an appropriate suffix.
0635
2021-12-17
jrmu
## Note: unreliable filemtime()/stat() over 2GB @ 32bit
0636
2021-12-17
jrmu
function FileSizeCompact($n, $precision=1) {
0637
2021-12-17
jrmu
if(!(float)$n) return 0;
0638
2021-12-17
jrmu
$units = 'bkMGTPEZY';
0639
2021-12-17
jrmu
$b = log((float)$n, 1024);
0640
2021-12-17
jrmu
$fb = floor($b);
0641
2021-12-17
jrmu
return round(pow(1024,$b-$fb),$precision).@$units[$fb];
0642
2021-12-17
jrmu
}
0643
2021-12-17
jrmu
0644
2021-12-17
jrmu
## AsSpaced converts a string with WikiWords into a spaced version
0645
2021-12-17
jrmu
## of that string. (It can be overridden via $AsSpacedFunction.)
0646
2021-12-17
jrmu
function AsSpaced($text) {
0647
2021-12-17
jrmu
$text = preg_replace("/([[:lower:]\\d])([[:upper:]])/", '$1 $2', $text);
0648
2021-12-17
jrmu
$text = preg_replace('/([^-\\d])(\\d[-\\d]*( |$))/','$1 $2',$text);
0649
2021-12-17
jrmu
return preg_replace("/([[:upper:]])([[:upper:]][[:lower:]\\d])/",
0650
2021-12-17
jrmu
'$1 $2', $text);
0651
2021-12-17
jrmu
}
0652
2021-12-17
jrmu
0653
2021-12-17
jrmu
## Lock is used to make sure only one instance of PmWiki is running when
0654
2021-12-17
jrmu
## files are being written. It does not "lock pages" for editing.
0655
2021-12-17
jrmu
function Lock($op) {
0656
2021-12-17
jrmu
global $WorkDir, $LockFile, $EnableReadOnly;
0657
2021-12-17
jrmu
if ($op > 0 && IsEnabled($EnableReadOnly, 0))
0658
2021-12-17
jrmu
Abort('Cannot modify site -- $EnableReadOnly is set', 'readonly');
0659
2021-12-17
jrmu
SDV($LockFile, "$WorkDir/.flock");
0660
2021-12-17
jrmu
mkdirp(dirname($LockFile));
0661
2021-12-17
jrmu
static $lockfp,$curop;
0662
2021-12-17
jrmu
if (!$lockfp) $lockfp = @fopen($LockFile, "w");
0663
2021-12-17
jrmu
if (!$lockfp) {
0664
2021-12-17
jrmu
if ($op <= 0) return;
0665
2021-12-17
jrmu
@unlink($LockFile);
0666
2021-12-17
jrmu
$lockfp = fopen($LockFile,"w") or
0667
2021-12-17
jrmu
Abort('Cannot acquire lockfile', 'flock');
0668
2021-12-17
jrmu
fixperms($LockFile);
0669
2021-12-17
jrmu
}
0670
2021-12-17
jrmu
if ($op<0) { flock($lockfp,LOCK_UN); fclose($lockfp); $lockfp=0; $curop=0; }
0671
2021-12-17
jrmu
elseif ($op==0) { flock($lockfp,LOCK_UN); $curop=0; }
0672
2021-12-17
jrmu
elseif ($op==1 && $curop<1)
0673
2021-12-17
jrmu
{ session_write_close(); flock($lockfp,LOCK_SH); $curop=1; }
0674
2021-12-17
jrmu
elseif ($op==2 && $curop<2)
0675
2021-12-17
jrmu
{ session_write_close(); flock($lockfp,LOCK_EX); $curop=2; }
0676
2021-12-17
jrmu
}
0677
2021-12-17
jrmu
0678
2021-12-17
jrmu
## mkdirp creates a directory and its parents as needed, and sets
0679
2021-12-17
jrmu
## permissions accordingly.
0680
2021-12-17
jrmu
function mkdirp($dir) {
0681
2021-12-17
jrmu
global $ScriptUrl;
0682
2021-12-17
jrmu
if (file_exists($dir)) return;
0683
2021-12-17
jrmu
if (!file_exists(dirname($dir))) mkdirp(dirname($dir));
0684
2021-12-17
jrmu
if (mkdir($dir, 0777)) {
0685
2021-12-17
jrmu
fixperms($dir);
0686
2021-12-17
jrmu
if (@touch("$dir/xxx")) { unlink("$dir/xxx"); return; }
0687
2021-12-17
jrmu
rmdir($dir);
0688
2021-12-17
jrmu
}
0689
2021-12-17
jrmu
$parent = realpath(dirname($dir));
0690
2021-12-17
jrmu
$bdir = basename($dir);
0691
2021-12-17
jrmu
$perms = decoct(fileperms($parent) & 03777);
0692
2021-12-17
jrmu
$msg = "PmWiki needs to have a writable <tt>$dir/</tt> directory
0693
2021-12-17
jrmu
before it can continue. You can create the directory manually
0694
2021-12-17
jrmu
by executing the following commands on your server:
0695
2021-12-17
jrmu
<pre> mkdir $parent/$bdir\n chmod 777 $parent/$bdir</pre>
0696
2021-12-17
jrmu
Then, <a href='{$ScriptUrl}'>reload this page</a>.";
0697
2021-12-17
jrmu
$safemode = ini_get('safe_mode');
0698
2021-12-17
jrmu
if (!$safemode) $msg .= "<br /><br />Or, for a slightly more
0699
2021-12-17
jrmu
secure installation, try executing <pre> chmod 2777 $parent</pre>
0700
2021-12-17
jrmu
on your server and following <a target='_blank' href='$ScriptUrl'>
0701
2021-12-17
jrmu
this link</a>. Afterwards you can restore the permissions to
0702
2021-12-17
jrmu
their current setting by executing <pre> chmod $perms $parent</pre>.";
0703
2021-12-17
jrmu
Abort($msg);
0704
2021-12-17
jrmu
}
0705
2021-12-17
jrmu
0706
2021-12-17
jrmu
## fixperms attempts to correct permissions on a file or directory
0707
2021-12-17
jrmu
## so that both PmWiki and the account (current dir) owner can manipulate it
0708
2021-12-17
jrmu
function fixperms($fname, $add = 0, $set = 0) {
0709
2021-12-17
jrmu
clearstatcache();
0710
2021-12-17
jrmu
if (!file_exists($fname)) Abort('?no such file');
0711
2021-12-17
jrmu
if ($set) { # advanced admins, $UploadPermSet
0712
2021-12-17
jrmu
if (fileperms($fname) != $set) @chmod($fname,$set);
0713
2021-12-17
jrmu
}
0714
2021-12-17
jrmu
else {
0715
2021-12-17
jrmu
$bp = 0;
0716
2021-12-17
jrmu
if (fileowner($fname)!=@fileowner('.') && @fileowner('.')!==0)
0717
2021-12-17
jrmu
$bp = (is_dir($fname)) ? 007 : 006;
0718
2021-12-17
jrmu
if (filegroup($fname)==@filegroup('.')) $bp <<= 3;
0719
2021-12-17
jrmu
$bp |= $add;
0720
2021-12-17
jrmu
if ($bp && (fileperms($fname) & $bp) != $bp)
0721
2021-12-17
jrmu
@chmod($fname,fileperms($fname)|$bp);
0722
2021-12-17
jrmu
}
0723
2021-12-17
jrmu
}
0724
2021-12-17
jrmu
0725
2021-12-17
jrmu
## GlobToPCRE converts wildcard patterns into pcre patterns for
0726
2021-12-17
jrmu
## inclusion and exclusion. Wildcards beginning with '-' or '!'
0727
2021-12-17
jrmu
## are treated as things to be excluded.
0728
2021-12-17
jrmu
function GlobToPCRE($pat) {
0729
2021-12-17
jrmu
$pat = preg_quote($pat, '/');
0730
2021-12-17
jrmu
$pat = str_replace(array('\\*', '\\?', '\\[', '\\]', '\\^', '\\-', '\\!'),
0731
2021-12-17
jrmu
array('.*', '.', '[', ']', '^', '-', '!'), $pat);
0732
2021-12-17
jrmu
$excl = array(); $incl = array();
0733
2021-12-17
jrmu
foreach(preg_split('/,+\s?/', $pat, -1, PREG_SPLIT_NO_EMPTY) as $p) {
0734
2021-12-17
jrmu
if ($p[0] == '-' || $p[0] == '!') $excl[] = '^'.substr($p, 1).'$';
0735
2021-12-17
jrmu
else $incl[] = "^$p$";
0736
2021-12-17
jrmu
}
0737
2021-12-17
jrmu
return array(implode('|', $incl), implode('|', $excl));
0738
2021-12-17
jrmu
}
0739
2021-12-17
jrmu
0740
2021-12-17
jrmu
## FixGlob changes wildcard patterns without '.' to things like
0741
2021-12-17
jrmu
## '*.foo' (name matches) or 'foo.*' (group matches).
0742
2021-12-17
jrmu
function FixGlob($x, $rep = '$1*.$2') {
0743
2021-12-17
jrmu
return preg_replace('/([\\s,][-!]?)([^\\/.\\s,]+)(?=[\\s,])/', $rep, ",$x,");
0744
2021-12-17
jrmu
}
0745
2021-12-17
jrmu
0746
2021-12-17
jrmu
## MatchPageNames reduces $pagelist to those pages with names
0747
2021-12-17
jrmu
## matching the pattern(s) in $pat. Patterns can be either
0748
2021-12-17
jrmu
## regexes to include ('/'), regexes to exclude ('!'), or
0749
2021-12-17
jrmu
## wildcard patterns (all others).
0750
2021-12-17
jrmu
function MatchPageNames($pagelist, $pat) {
0751
2021-12-17
jrmu
# Note: MatchNames() is the generic function matching patterns,
0752
2021-12-17
jrmu
# works for attachments and other arrays. We can commit to
0753
2021-12-17
jrmu
# keep it generic, even if we someday change MatchPageNames().
0754
2021-12-17
jrmu
return MatchNames($pagelist, $pat);
0755
2021-12-17
jrmu
}
0756
2021-12-17
jrmu
function MatchNames($list, $pat) {
0757
2021-12-17
jrmu
global $Charset, $EnableRangeMatchUTF8;
0758
2021-12-17
jrmu
# allow range matches in utf8; doesn't work on pmwiki.org and possibly elsewhere
0759
2021-12-17
jrmu
$pcre8 = (IsEnabled($EnableRangeMatchUTF8,0) && $Charset=='UTF-8')? 'u' : '';
0760
2021-12-17
jrmu
$list = (array)$list;
0761
2021-12-17
jrmu
foreach((array)$pat as $p) {
0762
2021-12-17
jrmu
if (count($list) < 1) break;
0763
2021-12-17
jrmu
if (!$p) continue;
0764
2021-12-17
jrmu
switch ($p[0]) {
0765
2021-12-17
jrmu
case '/':
0766
2021-12-17
jrmu
$list = preg_grep($p, $list);
0767
2021-12-17
jrmu
break;
0768
2021-12-17
jrmu
case '!':
0769
2021-12-17
jrmu
$list = array_diff($list, preg_grep($p, $list));
0770
2021-12-17
jrmu
break;
0771
2021-12-17
jrmu
default:
0772
2021-12-17
jrmu
list($inclp, $exclp) = GlobToPCRE(str_replace('/', '.', $p));
0773
2021-12-17
jrmu
if ($exclp)
0774
2021-12-17
jrmu
$list = array_diff($list, preg_grep("/$exclp/i$pcre8", $list));
0775
2021-12-17
jrmu
if ($inclp)
0776
2021-12-17
jrmu
$list = preg_grep("/$inclp/i$pcre8", $list);
0777
2021-12-17
jrmu
}
0778
2021-12-17
jrmu
}
0779
2021-12-17
jrmu
return $list;
0780
2021-12-17
jrmu
}
0781
2021-12-17
jrmu
0782
2021-12-17
jrmu
## ResolvePageName "normalizes" a pagename based on the current
0783
2021-12-17
jrmu
## settings of $DefaultPage and $PagePathFmt. It's normally used
0784
2021-12-17
jrmu
## during initialization to fix up any missing or partial pagenames.
0785
2021-12-17
jrmu
function ResolvePageName($pagename) {
0786
2021-12-17
jrmu
global $DefaultPage, $DefaultGroup, $DefaultName,
0787
2021-12-17
jrmu
$GroupPattern, $NamePattern, $EnableFixedUrlRedirect;
0788
2021-12-17
jrmu
SDV($DefaultPage, "$DefaultGroup.$DefaultName");
0789
2021-12-17
jrmu
$pagename = preg_replace('!([./][^./]+)\\.html?$!', '$1', $pagename);
0790
2021-12-17
jrmu
if ($pagename == '') return $DefaultPage;
0791
2021-12-17
jrmu
$p = MakePageName($DefaultPage, $pagename);
0792
2021-12-17
jrmu
if (!preg_match("/^($GroupPattern)[.\\/]($NamePattern)$/i", $p)) {
0793
2021-12-17
jrmu
header('HTTP/1.1 404 Not Found');
0794
2021-12-17
jrmu
Abort("\$[?invalid page name] \"$p\"");
0795
2021-12-17
jrmu
}
0796
2021-12-17
jrmu
if (preg_match("/^($GroupPattern)[.\\/]($NamePattern)$/i", $pagename))
0797
2021-12-17
jrmu
return $p;
0798
2021-12-17
jrmu
if (IsEnabled($EnableFixedUrlRedirect, 1)
0799
2021-12-17
jrmu
&& $p && (PageExists($p) || preg_match('/[\\/.]/', $pagename)))
0800
2021-12-17
jrmu
{ Redirect($p); exit(); }
0801
2021-12-17
jrmu
return MakePageName($DefaultPage, "$pagename.$pagename");
0802
2021-12-17
jrmu
}
0803
2021-12-17
jrmu
0804
2021-12-17
jrmu
## MakePageName is used to convert a string $str into a fully-qualified
0805
2021-12-17
jrmu
## pagename. If $str doesn't contain a group qualifier, then
0806
2021-12-17
jrmu
## MakePageName uses $basepage and $PagePathFmt to determine the
0807
2021-12-17
jrmu
## group of the returned pagename.
0808
2021-12-17
jrmu
function MakePageName($basepage, $str) {
0809
2021-12-17
jrmu
global $MakePageNameFunction, $PageNameChars, $PagePathFmt,
0810
2021-12-17
jrmu
$MakePageNamePatterns, $MakePageNameSplitPattern;
0811
2021-12-17
jrmu
if (@$MakePageNameFunction) return $MakePageNameFunction($basepage, $str);
0812
2021-12-17
jrmu
SDV($PageNameChars,'-[:alnum:]');
0813
2021-12-17
jrmu
SDV($MakePageNamePatterns, array(
0814
2021-12-17
jrmu
"/'/" => '', # strip single-quotes
0815
2021-12-17
jrmu
"/[^$PageNameChars]+/" => ' ', # convert everything else to space
0816
2021-12-17
jrmu
'/((^|[^-\\w])\\w)/' => 'cb_toupper', # CamelCase
0817
2021-12-17
jrmu
'/ /' => ''));
0818
2021-12-17
jrmu
SDV($MakePageNameSplitPattern, '/[.\\/]/');
0819
2021-12-17
jrmu
$str = preg_replace('/[#?].*$/', '', $str);
0820
2021-12-17
jrmu
$m = preg_split($MakePageNameSplitPattern, $str);
0821
2021-12-17
jrmu
if (count($m)<1 || count($m)>2 || $m[0]=='') return '';
0822
2021-12-17
jrmu
## handle "Group.Name" conversions
0823
2021-12-17
jrmu
if (@$m[1] > '') {
0824
2021-12-17
jrmu
$group = PPRA($MakePageNamePatterns, $m[0]);
0825
2021-12-17
jrmu
$name = PPRA($MakePageNamePatterns, $m[1]);
0826
2021-12-17
jrmu
return "$group.$name";
0827
2021-12-17
jrmu
}
0828
2021-12-17
jrmu
$name = PPRA($MakePageNamePatterns, $m[0]);
0829
2021-12-17
jrmu
$isgrouphome = count($m) > 1;
0830
2021-12-17
jrmu
foreach((array)$PagePathFmt as $pg) {
0831
2021-12-17
jrmu
if ($isgrouphome && strncmp($pg, '$1.', 3) !== 0) continue;
0832
2021-12-17
jrmu
$pn = FmtPageName(str_replace('$1', $name, $pg), $basepage);
0833
2021-12-17
jrmu
if (PageExists($pn)) return $pn;
0834
2021-12-17
jrmu
}
0835
2021-12-17
jrmu
if ($isgrouphome) {
0836
2021-12-17
jrmu
foreach((array)$PagePathFmt as $pg)
0837
2021-12-17
jrmu
if (strncmp($pg, '$1.', 3) == 0)
0838
2021-12-17
jrmu
return FmtPageName(str_replace('$1', $name, $pg), $basepage);
0839
2021-12-17
jrmu
return "$name.$name";
0840
2021-12-17
jrmu
}
0841
2021-12-17
jrmu
return preg_replace('/[^\\/.]+$/', $name, $basepage);
0842
2021-12-17
jrmu
}
0843
2021-12-17
jrmu
0844
2021-12-17
jrmu
0845
2021-12-17
jrmu
## MakeBaseName uses $BaseNamePatterns to return the "base" form
0846
2021-12-17
jrmu
## of a given pagename -- i.e., stripping any recipe-defined
0847
2021-12-17
jrmu
## prefixes or suffixes from the page.
0848
2021-12-17
jrmu
function MakeBaseName($pagename, $patlist = NULL) {
0849
2021-12-17
jrmu
global $BaseNamePatterns;
0850
2021-12-17
jrmu
if (is_null($patlist)) $patlist = (array)@$BaseNamePatterns;
0851
2021-12-17
jrmu
foreach($patlist as $pat => $rep)
0852
2021-12-17
jrmu
$pagename = preg_replace($pat, $rep, $pagename); # TODO
0853
2021-12-17
jrmu
return $pagename;
0854
2021-12-17
jrmu
}
0855
2021-12-17
jrmu
0856
2021-12-17
jrmu
0857
2021-12-17
jrmu
## PCache caches basic information about a page and its attributes--
0858
2021-12-17
jrmu
## usually everything except page text and page history. This makes
0859
2021-12-17
jrmu
## for quicker access to certain values in PageVar below.
0860
2021-12-17
jrmu
function PCache($pagename, $page) {
0861
2021-12-17
jrmu
global $PCache;
0862
2021-12-17
jrmu
foreach($page as $k=>$v)
0863
2021-12-17
jrmu
if ($k!='text' && strpos($k,':')===false) $PCache[$pagename][$k]=$v;
0864
2021-12-17
jrmu
}
0865
2021-12-17
jrmu
0866
2021-12-17
jrmu
## SetProperty saves a page property into $PCache. For convenience
0867
2021-12-17
jrmu
## it returns the $value of the property just set. If $sep is supplied,
0868
2021-12-17
jrmu
## then $value is appended to the current property (with $sep as
0869
2021-12-17
jrmu
## as separator) instead of replacing it. If $keep is suplied and the
0870
2021-12-17
jrmu
## property already exists, then $value will be ignored.
0871
2021-12-17
jrmu
function SetProperty($pagename, $prop, $value, $sep=NULL, $keep=NULL) {
0872
2021-12-17
jrmu
global $PCache, $KeepToken;
0873
2021-12-17
jrmu
NoCache();
0874
2021-12-17
jrmu
$prop = "=p_$prop";
0875
2021-12-17
jrmu
$value = preg_replace_callback("/$KeepToken(\\d.*?)$KeepToken/",
0876
2021-12-17
jrmu
"cb_expandkpv", $value);
0877
2021-12-17
jrmu
if (!is_null($sep) && isset($PCache[$pagename][$prop]))
0878
2021-12-17
jrmu
$value = $PCache[$pagename][$prop] . $sep . $value;
0879
2021-12-17
jrmu
if (is_null($keep) || !isset($PCache[$pagename][$prop]))
0880
2021-12-17
jrmu
$PCache[$pagename][$prop] = $value;
0881
2021-12-17
jrmu
return $PCache[$pagename][$prop];
0882
2021-12-17
jrmu
}
0883
2021-12-17
jrmu
0884
2021-12-17
jrmu
0885
2021-12-17
jrmu
## PageTextVar loads a page's text variables (defined by
0886
2021-12-17
jrmu
## $PageTextVarPatterns) into a page's $PCache entry, and returns
0887
2021-12-17
jrmu
## the property associated with $var.
0888
2021-12-17
jrmu
function PageTextVar($pagename, $var) {
0889
2021-12-17
jrmu
global $PCache, $PageTextVarPatterns, $MaxPageTextVars, $DefaultUnsetPageTextVars, $DefaultEmptyPageTextVars;
0890
2021-12-17
jrmu
SDV($MaxPageTextVars, 500);
0891
2021-12-17
jrmu
static $status;
0892
2021-12-17
jrmu
if (@$status["$pagename:$var"]++ > $MaxPageTextVars) return '';
0893
2021-12-17
jrmu
if (!@$PCache[$pagename]['=pagetextvars']) {
0894
2021-12-17
jrmu
$pc = &$PCache[$pagename];
0895
2021-12-17
jrmu
$pc['=pagetextvars'] = 1;
0896
2021-12-17
jrmu
$page = RetrieveAuthPage($pagename, 'read', false, READPAGE_CURRENT);
0897
2021-12-17
jrmu
if ($page) {
0898
2021-12-17
jrmu
foreach((array)$PageTextVarPatterns as $pat)
0899
2021-12-17
jrmu
if (preg_match_all($pat, IsEnabled($pc['=preview'],@$page['text']),
0900
2021-12-17
jrmu
$match, PREG_SET_ORDER))
0901
2021-12-17
jrmu
foreach($match as $m) {
0902
2021-12-17
jrmu
$t = preg_replace("/\\{\\$:{$m[2]}\\}/", '', $m[3]);
0903
2021-12-17
jrmu
$pc["=p_{$m[2]}"] = Qualify($pagename, $t);
0904
2021-12-17
jrmu
}
0905
2021-12-17
jrmu
}
0906
2021-12-17
jrmu
}
0907
2021-12-17
jrmu
if (! isset($PCache[$pagename]["=p_$var"]) && is_array($DefaultUnsetPageTextVars)) {
0908
2021-12-17
jrmu
foreach($DefaultUnsetPageTextVars as $k=>$v) {
0909
2021-12-17
jrmu
if (count(MatchNames($var, $k))) {
0910
2021-12-17
jrmu
$PCache[$pagename]["=p_$var"] = $v;
0911
2021-12-17
jrmu
break;
0912
2021-12-17
jrmu
}
0913
2021-12-17
jrmu
}
0914
2021-12-17
jrmu
SDV($PCache[$pagename]["=p_$var"], ''); # to avoid re-loop
0915
2021-12-17
jrmu
}
0916
2021-12-17
jrmu
elseif (@$PCache[$pagename]["=p_$var"] == '' && is_array($DefaultEmptyPageTextVars)) {
0917
2021-12-17
jrmu
foreach($DefaultEmptyPageTextVars as $k=>$v) {
0918
2021-12-17
jrmu
if (count(MatchNames($var, $k))) {
0919
2021-12-17
jrmu
$PCache[$pagename]["=p_$var"] = $v;
0920
2021-12-17
jrmu
break;
0921
2021-12-17
jrmu
}
0922
2021-12-17
jrmu
}
0923
2021-12-17
jrmu
SDV($PCache[$pagename]["=p_$var"], ''); # to avoid re-loop
0924
2021-12-17
jrmu
}
0925
2021-12-17
jrmu
return @$PCache[$pagename]["=p_$var"];
0926
2021-12-17
jrmu
}
0927
2021-12-17
jrmu
0928
2021-12-17
jrmu
0929
2021-12-17
jrmu
function PageVar($pagename, $var, $pn = '') {
0930
2021-12-17
jrmu
global $Cursor, $PCache, $FmtPV, $AsSpacedFunction, $ScriptUrl,
0931
2021-12-17
jrmu
$EnablePathInfo;
0932
2021-12-17
jrmu
if ($var == '$ScriptUrl') return PUE($ScriptUrl);
0933
2021-12-17
jrmu
if ($pn) {
0934
2021-12-17
jrmu
$pn = isset($Cursor[$pn]) ? $Cursor[$pn] : MakePageName($pagename, $pn);
0935
2021-12-17
jrmu
} else $pn = $pagename;
0936
2021-12-17
jrmu
if ($pn) {
0937
2021-12-17
jrmu
if (preg_match('/^(.+)[.\\/]([^.\\/]+)$/', $pn, $match)
0938
2021-12-17
jrmu
&& !isset($PCache[$pn]['time'])
0939
2021-12-17
jrmu
&& (!@$FmtPV[$var] || strpos($FmtPV[$var], '$page') !== false)) {
0940
2021-12-17
jrmu
$page = ReadPage($pn, READPAGE_CURRENT);
0941
2021-12-17
jrmu
PCache($pn, $page);
0942
2021-12-17
jrmu
}
0943
2021-12-17
jrmu
@list($d, $group, $name) = $match;
0944
2021-12-17
jrmu
$page = &$PCache[$pn];
0945
2021-12-17
jrmu
if (strpos(@$FmtPV[$var], '$authpage') !== false) {
0946
2021-12-17
jrmu
if (!isset($page['=auth']['read'])) {
0947
2021-12-17
jrmu
$x = RetrieveAuthPage($pn, 'read', false, READPAGE_CURRENT);
0948
2021-12-17
jrmu
if ($x) PCache($pn, $x);
0949
2021-12-17
jrmu
}
0950
2021-12-17
jrmu
if (@$page['=auth']['read']) $authpage = &$page;
0951
2021-12-17
jrmu
}
0952
2021-12-17
jrmu
} else { $group = ''; $name = ''; }
0953
2021-12-17
jrmu
if (@$FmtPV[$var]) return eval("return ({$FmtPV[$var]});");
0954
2021-12-17
jrmu
if (strncmp($var, '$:', 2)==0) return PageTextVar($pn, substr($var, 2));
0955
2021-12-17
jrmu
return '';
0956
2021-12-17
jrmu
}
0957
2021-12-17
jrmu
0958
2021-12-17
jrmu
0959
2021-12-17
jrmu
## FmtPageName handles $[internationalization] and $Variable
0960
2021-12-17
jrmu
## substitutions in strings based on the $pagename argument.
0961
2021-12-17
jrmu
function FmtPageName($fmt, $pagename) {
0962
2021-12-17
jrmu
# Perform $-substitutions on $fmt relative to page given by $pagename
0963
2021-12-17
jrmu
global $GroupPattern, $NamePattern, $EnablePathInfo, $ScriptUrl,
0964
2021-12-17
jrmu
$GCount, $UnsafeGlobals, $FmtV, $FmtP, $FmtPV, $PCache, $AsSpacedFunction;
0965
2021-12-17
jrmu
if (strpos($fmt,'$')===false) return $fmt;
0966
2021-12-17
jrmu
$fmt = preg_replace_callback('/\\$([A-Z]\\w*Fmt)\\b/','cb_expandglobal',$fmt);
0967
2021-12-17
jrmu
$fmt = preg_replace_callback('/\\$\\[(?>([^\\]]+))\\]/',"cb_expandxlang",$fmt);
0968
2021-12-17
jrmu
$fmt = str_replace('{$ScriptUrl}', '$ScriptUrl', $fmt);
0969
2021-12-17
jrmu
$pprc = new PPRC($pagename);
0970
2021-12-17
jrmu
$fmt = preg_replace_callback('/\\{\\*?(\\$[A-Z]\\w+)\\}/',
0971
2021-12-17
jrmu
array($pprc, 'pagevar'), $fmt);
0972
2021-12-17
jrmu
if (strpos($fmt,'$')===false) return $fmt;
0973
2021-12-17
jrmu
if ($FmtP) $fmt = PPRA($FmtP, $fmt); # FIXME
0974
2021-12-17
jrmu
static $pv, $pvpat;
0975
2021-12-17
jrmu
if ($pv != count($FmtPV)) {
0976
2021-12-17
jrmu
$pvpat = str_replace('$', '\\$', implode('|', array_keys($FmtPV)));
0977
2021-12-17
jrmu
$pv = count($FmtPV);
0978
2021-12-17
jrmu
}
0979
2021-12-17
jrmu
$fmt = preg_replace_callback("/($pvpat)\\b/", array($pprc, 'pagevar'), $fmt);
0980
2021-12-17
jrmu
$fmt = preg_replace_callback('!\\$ScriptUrl/([^?#\'"\\s<>]+)!',
0981
2021-12-17
jrmu
'cb_expandscripturl', $fmt);
0982
2021-12-17
jrmu
if (strpos($fmt,'$')===false) return $fmt;
0983
2021-12-17
jrmu
static $g;
0984
2021-12-17
jrmu
if ($GCount != count($GLOBALS)+count($FmtV)) {
0985
2021-12-17
jrmu
$g = array();
0986
2021-12-17
jrmu
foreach($GLOBALS as $n=>$v) {
0987
2021-12-17
jrmu
if (is_array($v) || is_object($v) ||
0988
2021-12-17
jrmu
isset($FmtV["\$$n"]) || in_array($n,$UnsafeGlobals)) continue;
0989
2021-12-17
jrmu
$g["\$$n"] = $v;
0990
2021-12-17
jrmu
}
0991
2021-12-17
jrmu
$GCount = count($GLOBALS)+count($FmtV);
0992
2021-12-17
jrmu
krsort($g); reset($g);
0993
2021-12-17
jrmu
}
0994
2021-12-17
jrmu
$fmt = str_replace(array_keys($g),array_values($g),$fmt);
0995
2021-12-17
jrmu
$fmt = preg_replace_callback('/(?>(\\$[[:alpha:]]\\w+))/',
0996
2021-12-17
jrmu
"cb_expandfmtv", $fmt);
0997
2021-12-17
jrmu
return $fmt;
0998
2021-12-17
jrmu
}
0999
2021-12-17
jrmu
function cb_expandglobal($m){ return @$GLOBALS[$m[1]]; }
1000
2021-12-17
jrmu
function cb_expandxlang ($m){ return NoCache(XL($m[1])); }
1001
2021-12-17
jrmu
function cb_expandfmtv ($m){
1002
2021-12-17
jrmu
return isset($GLOBALS['FmtV'][$m[1]]) ? $GLOBALS['FmtV'][$m[1]] : $m[1];
1003
2021-12-17
jrmu
}
1004
2021-12-17
jrmu
function cb_expandscripturl($m) {
1005
2021-12-17
jrmu
global $EnablePathInfo, $ScriptUrl;
1006
2021-12-17
jrmu
return (@$EnablePathInfo) ? "$ScriptUrl/" . PUE($m[1])
1007
2021-12-17
jrmu
: "$ScriptUrl?n=".str_replace('/','.',PUE($m[1]));
1008
2021-12-17
jrmu
}
1009
2021-12-17
jrmu
1010
2021-12-17
jrmu
1011
2021-12-17
jrmu
## FmtPageTitle returns the page title, or the page name.
1012
2021-12-17
jrmu
## It localizes standard technical pages (RecentChanges...)
1013
2021-12-17
jrmu
function FmtPageTitle($title, $name, $spaced=0) {
1014
2021-12-17
jrmu
if ($title>'') return str_replace("$", "&#036;", $title);
1015
2021-12-17
jrmu
global $SpaceWikiWords, $AsSpacedFunction;
1016
2021-12-17
jrmu
if (preg_match("/^(Site(Admin)?
1017
2021-12-17
jrmu
|(All)?(Site|Group)(Header|Footer|Attributes)
1018
2021-12-17
jrmu
|(Side|Left|Right)Bar
1019
2021-12-17
jrmu
|(Wiki)?Sand[Bb]ox
1020
2021-12-17
jrmu
|(All)?Recent(Changes|Uploads)|(Auth|Edit)Form
1021
2021-12-17
jrmu
|InterMap|PageActions|\\w+QuickReference|\\w+Templates
1022
2021-12-17
jrmu
|NotifyList|AuthUser|ApprovedUrls|(Block|Auth)List
1023
2021-12-17
jrmu
)$/x", $name) && $name != XL($name))
1024
2021-12-17
jrmu
return XL($name);
1025
2021-12-17
jrmu
return ($spaced || $SpaceWikiWords) ? $AsSpacedFunction($name) : $name;
1026
2021-12-17
jrmu
}
1027
2021-12-17
jrmu
1028
2021-12-17
jrmu
## FmtTemplateVars uses $vars to replace all occurrences of
1029
2021-12-17
jrmu
## {$$key} in $text with $vars['key'].
1030
2021-12-17
jrmu
function FmtTemplateVars($text, $vars, $pagename = NULL) {
1031
2021-12-17
jrmu
global $FmtPV, $EnableUndefinedTemplateVars;
1032
2021-12-17
jrmu
if ($pagename) {
1033
2021-12-17
jrmu
$pat = implode('|', array_map('preg_quote', array_keys($FmtPV)));
1034
2021-12-17
jrmu
$pprc = new PPRC($pagename);
1035
2021-12-17
jrmu
$text = preg_replace_callback("/\\{\\$($pat)\\}/",
1036
2021-12-17
jrmu
array($pprc, 'pagevar'), $text);
1037
2021-12-17
jrmu
}
1038
2021-12-17
jrmu
foreach(preg_grep('/^[\\w$]/', array_keys($vars)) as $k)
1039
2021-12-17
jrmu
if (!is_array($vars[$k]))
1040
2021-12-17
jrmu
$text = str_replace("{\$\$$k}", @$vars[$k], $text);
1041
2021-12-17
jrmu
if (! IsEnabled($EnableUndefinedTemplateVars, 0))
1042
2021-12-17
jrmu
$text = preg_replace("/\\{\\$\\$\\w+\\}/", '', $text);
1043
2021-12-17
jrmu
return $text;
1044
2021-12-17
jrmu
}
1045
2021-12-17
jrmu
1046
2021-12-17
jrmu
## The XL functions provide translation tables for $[i18n] strings
1047
2021-12-17
jrmu
## in FmtPageName().
1048
2021-12-17
jrmu
function XL($key) {
1049
2021-12-17
jrmu
global $XL,$XLLangs;
1050
2021-12-17
jrmu
foreach($XLLangs as $l) if (isset($XL[$l][$key])) return $XL[$l][$key];
1051
2021-12-17
jrmu
return $key;
1052
2021-12-17
jrmu
}
1053
2021-12-17
jrmu
function XLSDV($lang,$a) {
1054
2021-12-17
jrmu
global $XL;
1055
2021-12-17
jrmu
foreach($a as $k=>$v) {
1056
2021-12-17
jrmu
if (!isset($XL[$lang][$k])) {
1057
2021-12-17
jrmu
if (preg_match('/^e_(rows|cols)$/', $k)) $v = intval($v);
1058
2021-12-17
jrmu
elseif (preg_match('/^ak_/', $k)) $v = @$v[0];
1059
2021-12-17
jrmu
$XL[$lang][$k]=$v;
1060
2021-12-17
jrmu
}
1061
2021-12-17
jrmu
}
1062
2021-12-17
jrmu
}
1063
2021-12-17
jrmu
function XLPage($lang,$p,$nohtml=false) {
1064
2021-12-17
jrmu
global $TimeFmt,$XLLangs,$FarmD, $EnableXLPageScriptLoad;
1065
2021-12-17
jrmu
$page = ReadPage($p, READPAGE_CURRENT);
1066
2021-12-17
jrmu
if (!$page) return;
1067
2021-12-17
jrmu
$text = preg_replace("/=>\\s*\n/",'=> ',@$page['text']);
1068
2021-12-17
jrmu
foreach(explode("\n",$text) as $l)
1069
2021-12-17
jrmu
if (preg_match('/^\\s*[\'"](.+?)[\'"]\\s*=>\\s*[\'"](.+)[\'"]/',$l,$m))
1070
2021-12-17
jrmu
$xl[stripslashes($m[1])] = stripslashes($nohtml? PHSC($m[2]): $m[2]);
1071
2021-12-17
jrmu
if (isset($xl)) {
1072
2021-12-17
jrmu
if (IsEnabled($EnableXLPageScriptLoad, 0) && @$xl['xlpage-i18n']) {
1073
2021-12-17
jrmu
$i18n = preg_replace('/[^-\\w]/','',$xl['xlpage-i18n']);
1074
2021-12-17
jrmu
include_once("$FarmD/scripts/xlpage-$i18n.php");
1075
2021-12-17
jrmu
}
1076
2021-12-17
jrmu
if (@$xl['Locale']) setlocale(LC_ALL,$xl['Locale']);
1077
2021-12-17
jrmu
if (@$xl['TimeFmt']) $TimeFmt=$xl['TimeFmt'];
1078
2021-12-17
jrmu
if (!in_array($lang, $XLLangs)) array_unshift($XLLangs, $lang);
1079
2021-12-17
jrmu
XLSDV($lang,$xl);
1080
2021-12-17
jrmu
}
1081
2021-12-17
jrmu
}
1082
2021-12-17
jrmu
1083
2021-12-17
jrmu
## CmpPageAttr is used with uksort to order a page's elements with
1084
2021-12-17
jrmu
## the latest items first. This can make some operations more efficient.
1085
2021-12-17
jrmu
function CmpPageAttr($a, $b) {
1086
2021-12-17
jrmu
@list($x, $agmt) = explode(':', $a);
1087
2021-12-17
jrmu
@list($x, $bgmt) = explode(':', $b);
1088
2021-12-17
jrmu
if ($agmt != $bgmt)
1089
2021-12-17
jrmu
return ($agmt==0 || $bgmt==0) ? $agmt - $bgmt : $bgmt - $agmt;
1090
2021-12-17
jrmu
return strcmp($a, $b);
1091
2021-12-17
jrmu
}
1092
2021-12-17
jrmu
1093
2021-12-17
jrmu
## class PageStore holds objects that store pages via the native
1094
2021-12-17
jrmu
## filesystem.
1095
2021-12-17
jrmu
class PageStore {
1096
2021-12-17
jrmu
var $dirfmt;
1097
2021-12-17
jrmu
var $iswrite;
1098
2021-12-17
jrmu
var $encodefilenames;
1099
2021-12-17
jrmu
var $attr;
1100
2021-12-17
jrmu
function __construct($d='$WorkDir/$FullName', $w=0, $a=NULL) {
1101
2021-12-17
jrmu
$this->dirfmt = $d; $this->iswrite = $w; $this->attr = (array)$a;
1102
2021-12-17
jrmu
$GLOBALS['PageExistsCache'] = array();
1103
2021-12-17
jrmu
}
1104
2021-12-17
jrmu
function recodefn($s,$from,$to) {
1105
2021-12-17
jrmu
static $able;
1106
2021-12-17
jrmu
if(is_null($able)) {
1107
2021-12-17
jrmu
# can we rely on iconv() or on mb_convert_encoding() ?
1108
2021-12-17
jrmu
if (function_exists('iconv') && @iconv("UTF-8", "WINDOWS-1252//IGNORE", "te\xd0\xafst")=='test' )
1109
2021-12-17
jrmu
$able = 'iconv';
1110
2021-12-17
jrmu
elseif (function_exists('mb_convert_encoding') && @mb_convert_encoding("te\xd0\xafst", "WINDOWS-1252", "UTF-8")=="te?st")
1111
2021-12-17
jrmu
$able = 'mb';
1112
2021-12-17
jrmu
}
1113
2021-12-17
jrmu
switch ($able) {
1114
2021-12-17
jrmu
case "iconv":
1115
2021-12-17
jrmu
return @iconv($from,"$to//IGNORE",$s);
1116
2021-12-17
jrmu
case "mb":
1117
2021-12-17
jrmu
return @mb_convert_encoding($s,$to,$from);
1118
2021-12-17
jrmu
}
1119
2021-12-17
jrmu
if ($to=='UTF-8' && $from=='WINDOWS-1252') return utf8_decode($s);
1120
2021-12-17
jrmu
if ($from=='UTF-8' && $to=='WINDOWS-1252') return utf8_encode($s);
1121
2021-12-17
jrmu
return $s;
1122
2021-12-17
jrmu
}
1123
2021-12-17
jrmu
function pagefile($pagename) {
1124
2021-12-17
jrmu
global $FarmD;
1125
2021-12-17
jrmu
$dfmt = $this->dirfmt;
1126
2021-12-17
jrmu
if ($pagename > '') {
1127
2021-12-17
jrmu
$pagename = str_replace('/', '.', $pagename);
1128
2021-12-17
jrmu
if ($dfmt == 'wiki.d/{$FullName}') # optimizations for
1129
2021-12-17
jrmu
return $this->PFE("wiki.d/$pagename"); # standard locations
1130
2021-12-17
jrmu
if ($dfmt == '$FarmD/wikilib.d/{$FullName}') #
1131
2021-12-17
jrmu
return $this->PFE("$FarmD/wikilib.d/$pagename");
1132
2021-12-17
jrmu
if ($dfmt == 'wiki.d/{$Group}/{$FullName}')
1133
2021-12-17
jrmu
return $this->PFE(preg_replace('/([^.]+).*/', 'wiki.d/$1/$0', $pagename));
1134
2021-12-17
jrmu
}
1135
2021-12-17
jrmu
return $this->PFE(FmtPageName($dfmt, $pagename));
1136
2021-12-17
jrmu
}
1137
2021-12-17
jrmu
function PFE($f) { # pagefile_encode
1138
2021-12-17
jrmu
if (!$this->encodefilenames) return $f;
1139
2021-12-17
jrmu
global $PageFileEncodeFunction;
1140
2021-12-17
jrmu
return $PageFileEncodeFunction($f);
1141
2021-12-17
jrmu
}
1142
2021-12-17
jrmu
function PFD($f) { # pagefile_decode
1143
2021-12-17
jrmu
if (!$this->encodefilenames) return $f;
1144
2021-12-17
jrmu
global $PageFileDecodeFunction;
1145
2021-12-17
jrmu
return $PageFileDecodeFunction($f);
1146
2021-12-17
jrmu
}
1147
2021-12-17
jrmu
function read($pagename, $since=0) {
1148
2021-12-17
jrmu
$newline = '';
1149
2021-12-17
jrmu
$urlencoded = false;
1150
2021-12-17
jrmu
$pagefile = $this->pagefile($pagename);
1151
2021-12-17
jrmu
if ($pagefile && ($fp=@fopen($pagefile, "r"))) {
1152
2021-12-17
jrmu
$page = $this->attr;
1153
2021-12-17
jrmu
while (!feof($fp)) {
1154
2021-12-17
jrmu
$line = @fgets($fp, 4096);
1155
2021-12-17
jrmu
while (substr($line, -1, 1) != "\n" && !feof($fp))
1156
2021-12-17
jrmu
{ $line .= fgets($fp, 4096); }
1157
2021-12-17
jrmu
$line = rtrim($line);
1158
2021-12-17
jrmu
if ($urlencoded) $line = urldecode(str_replace('+', '%2b', $line));
1159
2021-12-17
jrmu
@list($k,$v) = explode('=', $line, 2);
1160
2021-12-17
jrmu
if (!$k) continue;
1161
2021-12-17
jrmu
if ($k == 'version') {
1162
2021-12-17
jrmu
$ordered = (strpos($v, 'ordered=1') !== false);
1163
2021-12-17
jrmu
$urlencoded = (strpos($v, 'urlencoded=1') !== false);
1164
2021-12-17
jrmu
if (strpos($v, 'pmwiki-0.')!==false) $newline="\262";
1165
2021-12-17
jrmu
}
1166
2021-12-17
jrmu
if ($k == 'newline') { $newline = $v; continue; }
1167
2021-12-17
jrmu
if ($since > 0 && preg_match('/:(\\d+)/', $k, $m) && $m[1] < $since) {
1168
2021-12-17
jrmu
if ($ordered) break;
1169
2021-12-17
jrmu
continue;
1170
2021-12-17
jrmu
}
1171
2021-12-17
jrmu
if ($newline) $v = str_replace($newline, "\n", $v);
1172
2021-12-17
jrmu
$page[$k] = $v;
1173
2021-12-17
jrmu
}
1174
2021-12-17
jrmu
fclose($fp);
1175
2021-12-17
jrmu
}
1176
2021-12-17
jrmu
return $this->recode($pagename, @$page);
1177
2021-12-17
jrmu
}
1178
2021-12-17
jrmu
function write($pagename,$page) {
1179
2021-12-17
jrmu
global $Now, $Version, $Charset, $EnableRevUserAgent, $PageExistsCache, $DenyHtaccessContent;
1180
2021-12-17
jrmu
$page['charset'] = $Charset;
1181
2021-12-17
jrmu
$page['name'] = $pagename;
1182
2021-12-17
jrmu
$page['time'] = $Now;
1183
2021-12-17
jrmu
$page['host'] = $_SERVER['REMOTE_ADDR'];
1184
2021-12-17
jrmu
$page['agent'] = @$_SERVER['HTTP_USER_AGENT'];
1185
2021-12-17
jrmu
if(IsEnabled($EnableRevUserAgent, 0)) $page["agent:$Now"] = $page['agent'];
1186
2021-12-17
jrmu
$page['rev'] = @$page['rev']+1;
1187
2021-12-17
jrmu
unset($page['version']); unset($page['newline']);
1188
2021-12-17
jrmu
uksort($page, 'CmpPageAttr');
1189
2021-12-17
jrmu
$s = false;
1190
2021-12-17
jrmu
$pagefile = $this->pagefile($pagename);
1191
2021-12-17
jrmu
$dir = dirname($pagefile); mkdirp($dir);
1192
2021-12-17
jrmu
if (!file_exists("$dir/.htaccess") && $fp = @fopen("$dir/.htaccess", "w"))
1193
2021-12-17
jrmu
{ fwrite($fp, $DenyHtaccessContent); fclose($fp); }
1194
2021-12-17
jrmu
if ($pagefile && ($fp=fopen("$pagefile,new","w"))) {
1195
2021-12-17
jrmu
$r0 = array('%', "\n", '<');
1196
2021-12-17
jrmu
$r1 = array('%25', '%0a', '%3c');
1197
2021-12-17
jrmu
$x = "version=$Version ordered=1 urlencoded=1\n";
1198
2021-12-17
jrmu
$s = true && fputs($fp, $x); $sz = strlen($x);
1199
2021-12-17
jrmu
foreach($page as $k=>$v)
1200
2021-12-17
jrmu
if ($k > '' && $k[0] != '=') {
1201
2021-12-17
jrmu
$x = str_replace($r0, $r1, "$k=$v") . "\n";
1202
2021-12-17
jrmu
$s = $s && fputs($fp, $x); $sz += strlen($x);
1203
2021-12-17
jrmu
}
1204
2021-12-17
jrmu
$s = fclose($fp) && $s;
1205
2021-12-17
jrmu
$s = $s && (filesize("$pagefile,new") > $sz * 0.95);
1206
2021-12-17
jrmu
if (file_exists($pagefile)) $s = $s && unlink($pagefile);
1207
2021-12-17
jrmu
$s = $s && rename("$pagefile,new", $pagefile);
1208
2021-12-17
jrmu
}
1209
2021-12-17
jrmu
$s && fixperms($pagefile);
1210
2021-12-17
jrmu
if (!$s)
1211
2021-12-17
jrmu
Abort("Cannot write page to $pagename ($pagefile)...changes not saved");
1212
2021-12-17
jrmu
PCache($pagename, $page);
1213
2021-12-17
jrmu
unset($PageExistsCache[$pagename]); # PITS:01401
1214
2021-12-17
jrmu
}
1215
2021-12-17
jrmu
function exists($pagename) {
1216
2021-12-17
jrmu
if (!$pagename) return false;
1217
2021-12-17
jrmu
$pagefile = $this->pagefile($pagename);
1218
2021-12-17
jrmu
return ($pagefile && file_exists($pagefile));
1219
2021-12-17
jrmu
}
1220
2021-12-17
jrmu
function delete($pagename) {
1221
2021-12-17
jrmu
global $Now, $PageExistsCache;
1222
2021-12-17
jrmu
$pagefile = $this->pagefile($pagename);
1223
2021-12-17
jrmu
@rename($pagefile,"$pagefile,del-$Now");
1224
2021-12-17
jrmu
unset($PageExistsCache[$pagename]); # PITS:01401
1225
2021-12-17
jrmu
}
1226
2021-12-17
jrmu
function ls($pats=NULL) {
1227
2021-12-17
jrmu
global $GroupPattern, $NamePattern;
1228
2021-12-17
jrmu
StopWatch("PageStore::ls begin {$this->dirfmt}");
1229
2021-12-17
jrmu
$pats=(array)$pats;
1230
2021-12-17
jrmu
array_push($pats, "/^$GroupPattern\.$NamePattern$/");
1231
2021-12-17
jrmu
$dir = $this->pagefile('$Group.$Name');
1232
2021-12-17
jrmu
$maxslash = substr_count($dir, '/');
1233
2021-12-17
jrmu
$dirlist = array(preg_replace('!/*[^/]*\\$.*$!','',$dir));
1234
2021-12-17
jrmu
$out = array();
1235
2021-12-17
jrmu
while (count($dirlist)>0) {
1236
2021-12-17
jrmu
$dir = array_shift($dirlist);
1237
2021-12-17
jrmu
$dfp = @opendir($dir); if (!$dfp) { continue; }
1238
2021-12-17
jrmu
$dirslash = substr_count($dir, '/') + 1;
1239
2021-12-17
jrmu
$o = array();
1240
2021-12-17
jrmu
while ( ($pagefile = readdir($dfp)) !== false) {
1241
2021-12-17
jrmu
if ($pagefile[0] == '.') continue;
1242
2021-12-17
jrmu
if ($dirslash < $maxslash && is_dir("$dir/$pagefile"))
1243
2021-12-17
jrmu
{ array_push($dirlist,"$dir/$pagefile"); continue; }
1244
2021-12-17
jrmu
if ($dirslash == $maxslash) $o[] = $this->PFD($pagefile);
1245
2021-12-17
jrmu
}
1246
2021-12-17
jrmu
closedir($dfp);
1247
2021-12-17
jrmu
StopWatch("PageStore::ls merge {$this->dirfmt}");
1248
2021-12-17
jrmu
$out = array_merge($out, MatchPageNames($o, $pats));
1249
2021-12-17
jrmu
}
1250
2021-12-17
jrmu
StopWatch("PageStore::ls end {$this->dirfmt}");
1251
2021-12-17
jrmu
return $out;
1252
2021-12-17
jrmu
}
1253
2021-12-17
jrmu
function recode($pagename, $a) {
1254
2021-12-17
jrmu
if (!$a) return false;
1255
2021-12-17
jrmu
global $Charset, $PageRecodeFunction, $DefaultPageCharset, $EnableOldCharset;
1256
2021-12-17
jrmu
if (function_exists($PageRecodeFunction)) return $PageRecodeFunction($a);
1257
2021-12-17
jrmu
if (IsEnabled($EnableOldCharset)) $a['=oldcharset'] = @$a['charset'];
1258
2021-12-17
jrmu
SDVA($DefaultPageCharset, array(''=>@$Charset)); # pre-2.2.31 RecentChanges
1259
2021-12-17
jrmu
if (@$DefaultPageCharset[$a['charset']]>'') # wrong pre-2.2.30 encs. *-2, *-9, *-13
1260
2021-12-17
jrmu
$a['charset'] = $DefaultPageCharset[@$a['charset']];
1261
2021-12-17
jrmu
if (!$a['charset'] || $Charset==$a['charset']) return $a;
1262
2021-12-17
jrmu
$from = ($a['charset']=='ISO-8859-1') ? 'WINDOWS-1252' : $a['charset'];
1263
2021-12-17
jrmu
$to = ($Charset=='ISO-8859-1') ? 'WINDOWS-1252' : $Charset;
1264
2021-12-17
jrmu
if($from != $to) {
1265
2021-12-17
jrmu
foreach($a as $k=>$v) $a[$k] = $this->recodefn($v,$from,$to);
1266
2021-12-17
jrmu
}
1267
2021-12-17
jrmu
$a['charset'] = $Charset;
1268
2021-12-17
jrmu
return $a;
1269
2021-12-17
jrmu
}
1270
2021-12-17
jrmu
}
1271
2021-12-17
jrmu
1272
2021-12-17
jrmu
function ReadPage($pagename, $since=0) {
1273
2021-12-17
jrmu
# read a page from the appropriate directories given by $WikiReadDirsFmt.
1274
2021-12-17
jrmu
global $WikiLibDirs,$Now;
1275
2021-12-17
jrmu
foreach ($WikiLibDirs as $dir) {
1276
2021-12-17
jrmu
$page = $dir->read($pagename, $since);
1277
2021-12-17
jrmu
if ($page) break;
1278
2021-12-17
jrmu
}
1279
2021-12-17
jrmu
if (@!$page) $page['ctime'] = $Now;
1280
2021-12-17
jrmu
if (@!$page['time']) $page['time'] = $Now;
1281
2021-12-17
jrmu
return $page;
1282
2021-12-17
jrmu
}
1283
2021-12-17
jrmu
1284
2021-12-17
jrmu
function WritePage($pagename,$page) {
1285
2021-12-17
jrmu
global $WikiLibDirs,$WikiDir,$LastModFile;
1286
2021-12-17
jrmu
$WikiDir->iswrite = 1;
1287
2021-12-17
jrmu
for($i=0; $i<count($WikiLibDirs); $i++) {
1288
2021-12-17
jrmu
$wd = &$WikiLibDirs[$i];
1289
2021-12-17
jrmu
if ($wd->iswrite && $wd->exists($pagename)) break;
1290
2021-12-17
jrmu
}
1291
2021-12-17
jrmu
if ($i >= count($WikiLibDirs)) $wd = &$WikiDir;
1292
2021-12-17
jrmu
$wd->write($pagename,$page);
1293
2021-12-17
jrmu
if ($LastModFile && !@touch($LastModFile))
1294
2021-12-17
jrmu
{ unlink($LastModFile); touch($LastModFile); fixperms($LastModFile); }
1295
2021-12-17
jrmu
}
1296
2021-12-17
jrmu
1297
2021-12-17
jrmu
function PageExists($pagename) {
1298
2021-12-17
jrmu
## note: $PageExistsCache might change or disappear someday
1299
2021-12-17
jrmu
global $WikiLibDirs, $PageExistsCache;
1300
2021-12-17
jrmu
if (!isset($PageExistsCache[$pagename])) {
1301
2021-12-17
jrmu
foreach((array)$WikiLibDirs as $dir)
1302
2021-12-17
jrmu
if ($PageExistsCache[$pagename] = $dir->exists($pagename)) break;
1303
2021-12-17
jrmu
}
1304
2021-12-17
jrmu
return $PageExistsCache[$pagename];
1305
2021-12-17
jrmu
}
1306
2021-12-17
jrmu
1307
2021-12-17
jrmu
function ListPages($pat=NULL) {
1308
2021-12-17
jrmu
global $WikiLibDirs;
1309
2021-12-17
jrmu
foreach((array)$WikiLibDirs as $dir)
1310
2021-12-17
jrmu
$out = array_unique(array_merge($dir->ls($pat),(array)@$out));
1311
2021-12-17
jrmu
return $out;
1312
2021-12-17
jrmu
}
1313
2021-12-17
jrmu
1314
2021-12-17
jrmu
function RetrieveAuthPage($pagename, $level, $authprompt=true, $since=0) {
1315
2021-12-17
jrmu
global $AuthFunction;
1316
2021-12-17
jrmu
SDV($AuthFunction,'PmWikiAuth');
1317
2021-12-17
jrmu
if (!function_exists($AuthFunction)) return ReadPage($pagename, $since);
1318
2021-12-17
jrmu
return $AuthFunction($pagename, $level, $authprompt, $since);
1319
2021-12-17
jrmu
}
1320
2021-12-17
jrmu
1321
2021-12-17
jrmu
function Abort($msg, $info='') {
1322
2021-12-17
jrmu
# exit pmwiki with an abort message
1323
2021-12-17
jrmu
global $ScriptUrl, $Charset, $AbortFunction;
1324
2021-12-17
jrmu
if (@$AbortFunction) return $AbortFunction($msg, $info);
1325
2021-12-17
jrmu
if ($info)
1326
2021-12-17
jrmu
$info = "<p class='vspace'><a target='_blank' rel='nofollow' href='http://www.pmwiki.org/pmwiki/info/$info'>$[More information]</a></p>";
1327
2021-12-17
jrmu
$msg = "<h3>$[PmWiki can't process your request]</h3>
1328
2021-12-17
jrmu
<p class='vspace'>$msg</p>
1329
2021-12-17
jrmu
<p class='vspace'>$[We are sorry for any inconvenience].</p>
1330
2021-12-17
jrmu
$info
1331
2021-12-17
jrmu
<p class='vspace'><a href='$ScriptUrl'>$[Return to] $ScriptUrl</a></p>";
1332
2021-12-17
jrmu
@header("Content-type: text/html; charset=$Charset");
1333
2021-12-17
jrmu
echo preg_replace_callback('/\\$\\[([^\\]]+)\\]/', "cb_expandxlang", $msg);
1334
2021-12-17
jrmu
exit;
1335
2021-12-17
jrmu
}
1336
2021-12-17
jrmu
1337
2021-12-17
jrmu
function Redirect($pagename, $urlfmt='$PageUrl', $redirecturl=null) {
1338
2021-12-17
jrmu
# redirect the browser to $pagename
1339
2021-12-17
jrmu
global $EnableRedirect, $RedirectDelay, $EnableStopWatch;
1340
2021-12-17
jrmu
SDV($RedirectDelay, 0);
1341
2021-12-17
jrmu
clearstatcache();
1342
2021-12-17
jrmu
if (is_null($redirecturl)) $redirecturl = FmtPageName($urlfmt,$pagename);
1343
2021-12-17
jrmu
if (IsEnabled($EnableRedirect,1) &&
1344
2021-12-17
jrmu
(!isset($_REQUEST['redirect']) || $_REQUEST['redirect'])) {
1345
2021-12-17
jrmu
header("Location: $redirecturl");
1346
2021-12-17
jrmu
header("Content-type: text/html");
1347
2021-12-17
jrmu
echo "<html><head>
1348
2021-12-17
jrmu
<meta http-equiv='Refresh' Content='$RedirectDelay; URL=$redirecturl' />
1349
2021-12-17
jrmu
<title>Redirect</title></head><body></body></html>";
1350
2021-12-17
jrmu
exit;
1351
2021-12-17
jrmu
}
1352
2021-12-17
jrmu
echo "<a href='$redirecturl'>Redirect to $redirecturl</a>";
1353
2021-12-17
jrmu
if (@$EnableStopWatch && function_exists('StopWatchHTML'))
1354
2021-12-17
jrmu
StopWatchHTML($pagename, 1);
1355
2021-12-17
jrmu
exit;
1356
2021-12-17
jrmu
}
1357
2021-12-17
jrmu
1358
2021-12-17
jrmu
function PrintFmt($pagename,$fmt) {
1359
2021-12-17
jrmu
global $HTTPHeaders,$FmtV;
1360
2021-12-17
jrmu
if (is_array($fmt))
1361
2021-12-17
jrmu
{ foreach($fmt as $f) PrintFmt($pagename,$f); return; }
1362
2021-12-17
jrmu
if ($fmt == 'headers:') {
1363
2021-12-17
jrmu
foreach($HTTPHeaders as $h) (@$sent++) ? @header($h) : header($h);
1364
2021-12-17
jrmu
return;
1365
2021-12-17
jrmu
}
1366
2021-12-17
jrmu
$x = FmtPageName($fmt,$pagename);
1367
2021-12-17
jrmu
if (strncmp($fmt, 'function:', 9) == 0 &&
1368
2021-12-17
jrmu
preg_match('/^function:(\S+)\s*(.*)$/s', $x, $match) &&
1369
2021-12-17
jrmu
function_exists($match[1]))
1370
2021-12-17
jrmu
{ $match[1]($pagename,$match[2]); return; }
1371
2021-12-17
jrmu
if (strncmp($fmt, 'file:', 5) == 0 && preg_match("/^file:(.+)/s",$x,$match)) {
1372
2021-12-17
jrmu
$filelist = preg_split('/[\\s]+/',$match[1],-1,PREG_SPLIT_NO_EMPTY);
1373
2021-12-17
jrmu
foreach($filelist as $f) {
1374
2021-12-17
jrmu
if (file_exists($f)) { include($f); return; }
1375
2021-12-17
jrmu
}
1376
2021-12-17
jrmu
return;
1377
2021-12-17
jrmu
}
1378
2021-12-17
jrmu
if (substr($x, 0, 7) == 'markup:')
1379
2021-12-17
jrmu
{ print MarkupToHTML($pagename, substr($x, 7)); return; }
1380
2021-12-17
jrmu
if (substr($x, 0, 5) == 'wiki:')
1381
2021-12-17
jrmu
{ PrintWikiPage($pagename, substr($x, 5), 'read'); return; }
1382
2021-12-17
jrmu
if (substr($x, 0, 5) == 'page:')
1383
2021-12-17
jrmu
{ PrintWikiPage($pagename, substr($x, 5), ''); return; }
1384
2021-12-17
jrmu
echo $x;
1385
2021-12-17
jrmu
}
1386
2021-12-17
jrmu
1387
2021-12-17
jrmu
function PrintWikiPage($pagename, $wikilist=NULL, $auth='read') {
1388
2021-12-17
jrmu
if (is_null($wikilist)) $wikilist=$pagename;
1389
2021-12-17
jrmu
$pagelist = preg_split('/\s+/',$wikilist,-1,PREG_SPLIT_NO_EMPTY);
1390
2021-12-17
jrmu
foreach($pagelist as $p) {
1391
2021-12-17
jrmu
if (PageExists($p)) {
1392
2021-12-17
jrmu
$page = ($auth) ? RetrieveAuthPage($p, $auth, false, READPAGE_CURRENT)
1393
2021-12-17
jrmu
: ReadPage($p, READPAGE_CURRENT);
1394
2021-12-17
jrmu
if ($page['text'])
1395
2021-12-17
jrmu
echo MarkupToHTML($pagename,Qualify($p, $page['text']));
1396
2021-12-17
jrmu
return;
1397
2021-12-17
jrmu
}
1398
2021-12-17
jrmu
}
1399
2021-12-17
jrmu
}
1400
2021-12-17
jrmu
1401
2021-12-17
jrmu
function Keep($x, $pool=NULL) {
1402
2021-12-17
jrmu
if(is_array($x)) $x = $x[0]; # used in many callbacks
1403
2021-12-17
jrmu
# Keep preserves a string from being processed by wiki markups
1404
2021-12-17
jrmu
global $BlockPattern, $KeepToken, $KPV, $KPCount;
1405
2021-12-17
jrmu
$x = preg_replace_callback("/$KeepToken(\\d.*?)$KeepToken/", 'cb_expandkpv', $x);
1406
2021-12-17
jrmu
if (is_null($pool) && preg_match("!</?($BlockPattern)\\b!", $x)) $pool = 'B';
1407
2021-12-17
jrmu
$KPCount++; $KPV[$KPCount.$pool]=$x;
1408
2021-12-17
jrmu
return $KeepToken.$KPCount.$pool.$KeepToken;
1409
2021-12-17
jrmu
}
1410
2021-12-17
jrmu
1411
2021-12-17
jrmu
1412
2021-12-17
jrmu
## MarkupEscape examines markup source and escapes any [@...@]
1413
2021-12-17
jrmu
## and [=...=] sequences using Keep(). MarkupRestore undoes the
1414
2021-12-17
jrmu
## effect of any MarkupEscape().
1415
2021-12-17
jrmu
function MarkupEscape($text) {
1416
2021-12-17
jrmu
global $EscapePattern;
1417
2021-12-17
jrmu
SDV($EscapePattern, '\\[([=@]).*?\\1\\]');
1418
2021-12-17
jrmu
return preg_replace_callback("/$EscapePattern/s", "Keep", $text);
1419
2021-12-17
jrmu
}
1420
2021-12-17
jrmu
function MarkupRestore($text) {
1421
2021-12-17
jrmu
global $KeepToken, $KPV;
1422
2021-12-17
jrmu
return preg_replace_callback("/$KeepToken(\\d.*?)$KeepToken/", 'cb_expandkpv', $text);
1423
2021-12-17
jrmu
}
1424
2021-12-17
jrmu
1425
2021-12-17
jrmu
1426
2021-12-17
jrmu
## Qualify() applies $QualifyPatterns to convert relative links
1427
2021-12-17
jrmu
## and references into absolute equivalents.
1428
2021-12-17
jrmu
function Qualify($pagename, $text) {
1429
2021-12-17
jrmu
global $QualifyPatterns, $KeepToken, $KPV, $tmp_qualify;
1430
2021-12-17
jrmu
if (!@$QualifyPatterns) return $text;
1431
2021-12-17
jrmu
$text = MarkupEscape($text);
1432
2021-12-17
jrmu
$group = $tmp_qualify['group'] = PageVar($pagename, '$Group');
1433
2021-12-17
jrmu
$name = $tmp_qualify['name'] = PageVar($pagename, '$Name');
1434
2021-12-17
jrmu
$tmp_qualify['pagename'] = $pagename;
1435
2021-12-17
jrmu
$text = PPRA((array)$QualifyPatterns, $text);
1436
2021-12-17
jrmu
return MarkupRestore($text);
1437
2021-12-17
jrmu
}
1438
2021-12-17
jrmu
1439
2021-12-17
jrmu
1440
2021-12-17
jrmu
function CondText($pagename,$condspec,$condtext) {
1441
2021-12-17
jrmu
global $Conditions;
1442
2021-12-17
jrmu
if (!preg_match("/^(\\S+)\\s*(!?)\\s*(\\S+)?\\s*(.*?)\\s*$/",
1443
2021-12-17
jrmu
$condspec,$match)) return '';
1444
2021-12-17
jrmu
@list($condstr,$condtype,$not,$condname,$condparm) = $match;
1445
2021-12-17
jrmu
if (isset($Conditions[$condname])) {
1446
2021-12-17
jrmu
$tf = @eval("return (".$Conditions[$condname].");");
1447
2021-12-17
jrmu
if (!$tf xor $not) $condtext='';
1448
2021-12-17
jrmu
}
1449
2021-12-17
jrmu
return $condtext;
1450
2021-12-17
jrmu
}
1451
2021-12-17
jrmu
1452
2021-12-17
jrmu
1453
2021-12-17
jrmu
## TextSection extracts a section of text delimited by page anchors.
1454
2021-12-17
jrmu
## The $sections parameter can have the form
1455
2021-12-17
jrmu
## #abc - [[#abc]] to next anchor
1456
2021-12-17
jrmu
## #abc#def - [[#abc]] up to [[#def]]
1457
2021-12-17
jrmu
## #abc#, #abc.. - [[#abc]] to end of text
1458
2021-12-17
jrmu
## ##abc, #..#abc - beginning of text to [[#abc]]
1459
2021-12-17
jrmu
## Returns the text unchanged if no sections are requested,
1460
2021-12-17
jrmu
## or false if a requested beginning anchor isn't in the text.
1461
2021-12-17
jrmu
function TextSection($text, $sections, $args = NULL) {
1462
2021-12-17
jrmu
$args = (array)$args;
1463
2021-12-17
jrmu
$npat = '[[:alpha:]][-\\w.]*';
1464
2021-12-17
jrmu
if (!preg_match("/#($npat)?(\\.\\.)?(#($npat)?)?/", $sections, $match))
1465
2021-12-17
jrmu
return $text;
1466
2021-12-17
jrmu
@list($x, $aa, $dots, $b, $bb) = $match;
1467
2021-12-17
jrmu
if (!$dots && !$b) $bb = $npat;
1468
2021-12-17
jrmu
if ($aa) {
1469
2021-12-17
jrmu
$aa = preg_replace('/\\.\\.$/', '', $aa);
1470
2021-12-17
jrmu
$pos = strpos($text, "[[#$aa]]"); if ($pos === false) return false;
1471
2021-12-17
jrmu
if (@$args['anchors'])
1472
2021-12-17
jrmu
while ($pos > 0 && $text[$pos-1] != "\n") $pos--;
1473
2021-12-17
jrmu
else $pos += strlen("[[#$aa]]");
1474
2021-12-17
jrmu
$text = substr($text, $pos);
1475
2021-12-17
jrmu
}
1476
2021-12-17
jrmu
if ($bb)
1477
2021-12-17
jrmu
$text = preg_replace("/(\n)[^\n]*\\[\\[#$bb\\]\\].*$/s", '$1', $text, 1);
1478
2021-12-17
jrmu
return $text;
1479
2021-12-17
jrmu
}
1480
2021-12-17
jrmu
1481
2021-12-17
jrmu
1482
2021-12-17
jrmu
## RetrieveAuthSection extracts a section of text from a page.
1483
2021-12-17
jrmu
## If $pagesection starts with anything other than '#', it identifies
1484
2021-12-17
jrmu
## the page to extract text from. Otherwise RetrieveAuthSection looks
1485
2021-12-17
jrmu
## in the pages given by $list, or in $pagename if $list is not specified.
1486
2021-12-17
jrmu
## The selected page is placed in the global $RASPageName variable.
1487
2021-12-17
jrmu
## The caller is responsible for calling Qualify() as needed.
1488
2021-12-17
jrmu
function RetrieveAuthSection($pagename, $pagesection, $list=NULL, $auth='read') {
1489
2021-12-17
jrmu
global $RASPageName, $PCache;
1490
2021-12-17
jrmu
if ($pagesection[0] != '#')
1491
2021-12-17
jrmu
$list = array(MakePageName($pagename, $pagesection));
1492
2021-12-17
jrmu
else if (is_null($list)) $list = array($pagename);
1493
2021-12-17
jrmu
foreach((array)$list as $t) {
1494
2021-12-17
jrmu
$t = FmtPageName($t, $pagename);
1495
2021-12-17
jrmu
if (!PageExists($t)) continue;
1496
2021-12-17
jrmu
$tpage = RetrieveAuthPage($t, $auth, false, READPAGE_CURRENT);
1497
2021-12-17
jrmu
if (!$tpage) continue;
1498
2021-12-17
jrmu
$text = TextSection(IsEnabled($PCache[$t]['=preview'],$tpage['text']),$pagesection);
1499
2021-12-17
jrmu
if ($text !== false) { $RASPageName = $t; return $text; }
1500
2021-12-17
jrmu
}
1501
2021-12-17
jrmu
$RASPageName = '';
1502
2021-12-17
jrmu
return false;
1503
2021-12-17
jrmu
}
1504
2021-12-17
jrmu
1505
2021-12-17
jrmu
function IncludeText($pagename, $inclspec) {
1506
2021-12-17
jrmu
global $MaxIncludes, $IncludeOpt, $InclCount, $PCache;
1507
2021-12-17
jrmu
SDV($MaxIncludes,50);
1508
2021-12-17
jrmu
SDVA($IncludeOpt, array('self'=>1));
1509
2021-12-17
jrmu
if (@$InclCount[$pagename]++>=$MaxIncludes) return Keep($inclspec);
1510
2021-12-17
jrmu
$args = array_merge($IncludeOpt, ParseArgs($inclspec));
1511
2021-12-17
jrmu
while (count($args['#'])>0) {
1512
2021-12-17
jrmu
$k = array_shift($args['#']); $v = array_shift($args['#']);
1513
2021-12-17
jrmu
if ($k=='') {
1514
2021-12-17
jrmu
if ($v[0] != '#') {
1515
2021-12-17
jrmu
if (isset($itext)) continue;
1516
2021-12-17
jrmu
$iname = MakePageName($pagename, $v);
1517
2021-12-17
jrmu
if (!$args['self'] && $iname == $pagename) continue;
1518
2021-12-17
jrmu
$ipage = RetrieveAuthPage($iname, 'read', false, READPAGE_CURRENT);
1519
2021-12-17
jrmu
$itext = IsEnabled($PCache[$iname]['=preview'], @$ipage['text']);
1520
2021-12-17
jrmu
}
1521
2021-12-17
jrmu
$itext = TextSection(@$itext, $v, array('anchors' => 1));
1522
2021-12-17
jrmu
continue;
1523
2021-12-17
jrmu
}
1524
2021-12-17
jrmu
if (preg_match('/^(?:line|para)s?$/', $k)) {
1525
2021-12-17
jrmu
preg_match('/^(\\d*)(\\.\\.(\\d*))?$/', $v, $match);
1526
2021-12-17
jrmu
@list($x, $a, $dots, $b) = $match;
1527
2021-12-17
jrmu
$upat = ($k[0] == 'p') ? ".*?(\n\\s*\n|$)" : "[^\n]*(?:\n|$)";
1528
2021-12-17
jrmu
if (!$dots) { $b=$a; $a=0; }
1529
2021-12-17
jrmu
if ($a>0) $a--;
1530
2021-12-17
jrmu
$itext=preg_replace("/^(($upat){0,$b}).*$/s",'$1',$itext,1);
1531
2021-12-17
jrmu
$itext=preg_replace("/^($upat){0,$a}/s",'',$itext,1);
1532
2021-12-17
jrmu
continue;
1533
2021-12-17
jrmu
}
1534
2021-12-17
jrmu
}
1535
2021-12-17
jrmu
$basepage = isset($args['basepage'])
1536
2021-12-17
jrmu
? MakePageName($pagename, $args['basepage'])
1537
2021-12-17
jrmu
: @$iname;
1538
2021-12-17
jrmu
if ($basepage) $itext = Qualify(@$basepage, @$itext);
1539
2021-12-17
jrmu
return FmtTemplateVars(PVSE(@$itext), $args);
1540
2021-12-17
jrmu
}
1541
2021-12-17
jrmu
1542
2021-12-17
jrmu
1543
2021-12-17
jrmu
function RedirectMarkup($pagename, $opt) {
1544
2021-12-17
jrmu
$k = Keep("(:redirect $opt:)");
1545
2021-12-17
jrmu
global $MarkupFrame, $EnableRedirectQuiet;
1546
2021-12-17
jrmu
if (!@$MarkupFrame[0]['redirect']) return $k;
1547
2021-12-17
jrmu
$opt = ParseArgs($opt);
1548
2021-12-17
jrmu
$to = @$opt['to']; if (!$to) $to = @$opt[''][0];
1549
2021-12-17
jrmu
if (!$to) return $k;
1550
2021-12-17
jrmu
if (preg_match('/^([^#]+)(#[A-Za-z][-\\w]*)$/', $to, $match))
1551
2021-12-17
jrmu
{ $to = $match[1]; $anchor = @$match[2]; }
1552
2021-12-17
jrmu
$to = MakePageName($pagename, $to);
1553
2021-12-17
jrmu
if (!PageExists($to)) return $k;
1554
2021-12-17
jrmu
if ($to == $pagename) return '';
1555
2021-12-17
jrmu
if (@$opt['from']
1556
2021-12-17
jrmu
&& !MatchPageNames($pagename, FixGlob($opt['from'], '$1*.$2')))
1557
2021-12-17
jrmu
return '';
1558
2021-12-17
jrmu
if (preg_match('/^30[1237]$/', @$opt['status']))
1559
2021-12-17
jrmu
header("HTTP/1.1 {$opt['status']}");
1560
2021-12-17
jrmu
Redirect($to, "{\$PageUrl}"
1561
2021-12-17
jrmu
. (IsEnabled($EnableRedirectQuiet, 0) && IsEnabled($opt['quiet'], 0)
1562
2021-12-17
jrmu
? '' : "?from=$pagename")
1563
2021-12-17
jrmu
. $anchor);
1564
2021-12-17
jrmu
exit();
1565
2021-12-17
jrmu
}
1566
2021-12-17
jrmu
1567
2021-12-17
jrmu
1568
2021-12-17
jrmu
function Block($b) {
1569
2021-12-17
jrmu
global $BlockMarkups,$HTMLVSpace,$HTMLPNewline,$MarkupFrame;
1570
2021-12-17
jrmu
$mf = &$MarkupFrame[0]; $cs = &$mf['cs']; $vspaces = &$mf['vs'];
1571
2021-12-17
jrmu
$out = '';
1572
2021-12-17
jrmu
if ($b == 'vspace') {
1573
2021-12-17
jrmu
$vspaces .= "\n";
1574
2021-12-17
jrmu
while (count($cs)>0 && @end($cs)!='pre' && @$BlockMarkups[@end($cs)][3]==0)
1575
2021-12-17
jrmu
{ $c = array_pop($cs); $out .= $BlockMarkups[$c][2]; }
1576
2021-12-17
jrmu
return $out;
1577
2021-12-17
jrmu
}
1578
2021-12-17
jrmu
@list($code, $depth, $icol) = explode(',', $b);
1579
2021-12-17
jrmu
if (!$code) $depth = 1;
1580
2021-12-17
jrmu
if ($depth == 0) $depth = strlen($depth);
1581
2021-12-17
jrmu
if ($icol == 0) $icol = strlen($icol);
1582
2021-12-17
jrmu
if ($depth > 0) $depth += @$mf['idep'];
1583
2021-12-17
jrmu
if ($icol > 0) $mf['is'][$depth] = $icol + @$mf['icol'];
1584
2021-12-17
jrmu
@$mf['idep'] = @$mf['icol'] = 0;
1585
2021-12-17
jrmu
while (count($cs)>$depth)
1586
2021-12-17
jrmu
{ $c = array_pop($cs); $out .= $BlockMarkups[$c][2]; }
1587
2021-12-17
jrmu
if (!$code) {
1588
2021-12-17
jrmu
if (@end($cs) == 'p') { $out .= $HTMLPNewline; $code = 'p'; }
1589
2021-12-17
jrmu
else if ($depth < 2) { $code = 'p'; $mf['is'][$depth] = 0; }
1590
2021-12-17
jrmu
else { $out .= $HTMLPNewline; $code = 'block'; }
1591
2021-12-17
jrmu
}
1592
2021-12-17
jrmu
if ($depth>0 && $depth==count($cs) && $cs[$depth-1]!=$code)
1593
2021-12-17
jrmu
{ $c = array_pop($cs); $out .= $BlockMarkups[$c][2]; }
1594
2021-12-17
jrmu
while (count($cs)>0 && @end($cs)!=$code &&
1595
2021-12-17
jrmu
@$BlockMarkups[@end($cs)][3]==0)
1596
2021-12-17
jrmu
{ $c = array_pop($cs); $out .= $BlockMarkups[$c][2]; }
1597
2021-12-17
jrmu
if ($vspaces) {
1598
2021-12-17
jrmu
$out .= (@end($cs) == 'pre') ? $vspaces : $HTMLVSpace;
1599
2021-12-17
jrmu
$vspaces='';
1600
2021-12-17
jrmu
}
1601
2021-12-17
jrmu
if ($depth==0) { return $out; }
1602
2021-12-17
jrmu
if ($depth==count($cs)) { return $out.$BlockMarkups[$code][1]; }
1603
2021-12-17
jrmu
while (count($cs)<$depth-1) {
1604
2021-12-17
jrmu
array_push($cs, 'dl'); $mf['is'][count($cs)] = 0;
1605
2021-12-17
jrmu
$out .= $BlockMarkups['dl'][0].'<dd>';
1606
2021-12-17
jrmu
}
1607
2021-12-17
jrmu
if (count($cs)<$depth) {
1608
2021-12-17
jrmu
array_push($cs,$code);
1609
2021-12-17
jrmu
$out .= $BlockMarkups[$code][0];
1610
2021-12-17
jrmu
}
1611
2021-12-17
jrmu
return $out;
1612
2021-12-17
jrmu
}
1613
2021-12-17
jrmu
1614
2021-12-17
jrmu
1615
2021-12-17
jrmu
function MarkupClose($key = '') {
1616
2021-12-17
jrmu
global $MarkupFrame;
1617
2021-12-17
jrmu
$cf = & $MarkupFrame[0]['closeall'];
1618
2021-12-17
jrmu
$out = '';
1619
2021-12-17
jrmu
if ($key == '' || isset($cf[$key])) {
1620
2021-12-17
jrmu
$k = array_keys((array)$cf);
1621
2021-12-17
jrmu
while ($k) {
1622
2021-12-17
jrmu
$x = array_pop($k); $out .= $cf[$x]; unset($cf[$x]);
1623
2021-12-17
jrmu
if ($x == $key) break;
1624
2021-12-17
jrmu
}
1625
2021-12-17
jrmu
}
1626
2021-12-17
jrmu
return $out;
1627
2021-12-17
jrmu
}
1628
2021-12-17
jrmu
1629
2021-12-17
jrmu
1630
2021-12-17
jrmu
function FormatTableRow($x, $sep = '\\|\\|') {
1631
2021-12-17
jrmu
global $TableCellAttrFmt, $TableCellAlignFmt, $TableRowAttrFmt,
1632
2021-12-17
jrmu
$TableRowIndexMax, $MarkupFrame, $FmtV, $EnableSimpleTableRowspan;
1633
2021-12-17
jrmu
static $rowcount;
1634
2021-12-17
jrmu
SDV($TableCellAlignFmt, " align='%s'");
1635
2021-12-17
jrmu
1636
2021-12-17
jrmu
if (IsEnabled($EnableSimpleTableRowspan, 0)) {
1637
2021-12-17
jrmu
$x = preg_replace("/\\|\\|__+(?=\\|\\|)/", '||', $x);
1638
2021-12-17
jrmu
$x = preg_replace("/\\|\\|\\^\\^+(?=\\|\\|)/", '', $x);
1639
2021-12-17
jrmu
}
1640
2021-12-17
jrmu
$x = preg_replace("/$sep\\s*$/",'',$x);
1641
2021-12-17
jrmu
$td = preg_split("/$sep/", $x); $y = '';
1642
2021-12-17
jrmu
for($i=0;$i<count($td);$i++) {
1643
2021-12-17
jrmu
if ($td[$i]=='') continue;
1644
2021-12-17
jrmu
$FmtV['$TableCellCount'] = $i;
1645
2021-12-17
jrmu
$attr = FmtPageName(@$TableCellAttrFmt, '');
1646
2021-12-17
jrmu
if (IsEnabled($EnableSimpleTableRowspan, 0)) {
1647
2021-12-17
jrmu
if (preg_match('/(\\+\\++)\\s*$/', $td[$i], $rspn)) {
1648
2021-12-17
jrmu
$td[$i] = preg_replace('/\\+\\++(\\s*)$/', '$1', $td[$i]);
1649
2021-12-17
jrmu
$attr .= " rowspan='".strlen($rspn[1])."'";
1650
2021-12-17
jrmu
}
1651
2021-12-17
jrmu
}
1652
2021-12-17
jrmu
$td[$i] = preg_replace('/^(!?)\\s+$/', '$1&nbsp;', $td[$i]);
1653
2021-12-17
jrmu
if (preg_match('/^!(.*?)!$/',$td[$i],$match))
1654
2021-12-17
jrmu
{ $td[$i]=$match[1]; $t='caption'; $attr=''; }
1655
2021-12-17
jrmu
elseif (preg_match('/^!(.*)$/',$td[$i],$match))
1656
2021-12-17
jrmu
{ $td[$i]=$match[1]; $t='th'; }
1657
2021-12-17
jrmu
else $t='td';
1658
2021-12-17
jrmu
if (preg_match('/^\\s.*\\s$/',$td[$i])) {
1659
2021-12-17
jrmu
if ($t!='caption') $attr .= sprintf($TableCellAlignFmt, 'center');
1660
2021-12-17
jrmu
}
1661
2021-12-17
jrmu
elseif (preg_match('/^\\s/',$td[$i])) { $attr .= sprintf($TableCellAlignFmt, 'right'); }
1662
2021-12-17
jrmu
elseif (preg_match('/\\s$/',$td[$i])) { $attr .= sprintf($TableCellAlignFmt, 'left'); }
1663
2021-12-17
jrmu
for ($colspan=1;$i+$colspan<count($td);$colspan++)
1664
2021-12-17
jrmu
if ($td[$colspan+$i]!='') break;
1665
2021-12-17
jrmu
if ($colspan>1) { $attr .= " colspan='$colspan'"; }
1666
2021-12-17
jrmu
$y .= "<$t $attr>".trim($td[$i])."</$t>";
1667
2021-12-17
jrmu
}
1668
2021-12-17
jrmu
if ($t=='caption') return "<:table,1>$y";
1669
2021-12-17
jrmu
if (@$MarkupFrame[0]['cs'][0] != 'table') $rowcount = 0; else $rowcount++;
1670
2021-12-17
jrmu
$FmtV['$TableRowCount'] = $rowcount + 1;
1671
2021-12-17
jrmu
$FmtV['$TableRowIndex'] = ($rowcount % $TableRowIndexMax) + 1;
1672
2021-12-17
jrmu
$trattr = FmtPageName(@$TableRowAttrFmt, '');
1673
2021-12-17
jrmu
return "<:table,1><tr $trattr>$y</tr>";
1674
2021-12-17
jrmu
}
1675
2021-12-17
jrmu
1676
2021-12-17
jrmu
function LinkIMap($pagename,$imap,$path,$alt,$txt,$fmt=NULL) {
1677
2021-12-17
jrmu
global $FmtV, $IMap, $IMapLinkFmt, $UrlLinkFmt, $IMapLocalPath, $ScriptUrl, $AddLinkCSS;
1678
2021-12-17
jrmu
SDVA($IMapLocalPath, array('Path:'=>1));
1679
2021-12-17
jrmu
if (@$IMapLocalPath[$imap]) {
1680
2021-12-17
jrmu
$path = preg_replace('/^(\\w+):/', "$1%3a", $path); # PITS:01260
1681
2021-12-17
jrmu
}
1682
2021-12-17
jrmu
$FmtV['$LinkUrl'] = PUE(str_replace('$1',$path,$IMap[$imap]));
1683
2021-12-17
jrmu
$FmtV['$LinkText'] = $txt;
1684
2021-12-17
jrmu
$FmtV['$LinkAlt'] = str_replace(array('"',"'"),array('&#34;','&#39;'),$alt);
1685
2021-12-17
jrmu
if (!$fmt)
1686
2021-12-17
jrmu
$fmt = (isset($IMapLinkFmt[$imap])) ? $IMapLinkFmt[$imap] : $UrlLinkFmt;
1687
2021-12-17
jrmu
if(IsEnabled($AddLinkCSS['samedomain'])) {
1688
2021-12-17
jrmu
$parsed_url = parse_url($FmtV['$LinkUrl']);
1689
2021-12-17
jrmu
$parsed_wiki = parse_url($ScriptUrl);
1690
2021-12-17
jrmu
if(! @$parsed_url['host'] || $parsed_url['host'] == $parsed_wiki['host']) {
1691
2021-12-17
jrmu
$fmt = preg_replace('/(<a[^>]*class=["\'])/', "$1{$AddLinkCSS['samedomain']} ", $fmt);
1692
2021-12-17
jrmu
}
1693
2021-12-17
jrmu
}
1694
2021-12-17
jrmu
return str_replace(array_keys($FmtV),array_values($FmtV),$fmt);
1695
2021-12-17
jrmu
}
1696
2021-12-17
jrmu
1697
2021-12-17
jrmu
## These 2 functions hide e-mail addresses from spam bot harvesters
1698
2021-12-17
jrmu
## recover them for most users with a javascript utility,
1699
2021-12-17
jrmu
## while keeping them readable for users with JS disabled.
1700
2021-12-17
jrmu
## Based on Cookbook:DeObMail by Petko Yotov
1701
2021-12-17
jrmu
## To enable, set $LinkFunctions['mailto:'] = 'ObfuscateLinkIMap';
1702
2021-12-17
jrmu
function ObfuscateLinkIMap($pagename,$imap,$path,$title,$txt,$fmt=NULL) {
1703
2021-12-17
jrmu
global $FmtV, $IMap, $IMapLinkFmt;
1704
2021-12-17
jrmu
SDVA($IMapLinkFmt, array('obfuscate-mailto:' =>
1705
2021-12-17
jrmu
"<span class='_pmXmail' title=\"\$LinkAlt\"><span class='_t'>\$LinkText</span><span class='_m'>\$LinkUrl</span></span>"));
1706
2021-12-17
jrmu
$FmtV['$LinkUrl'] = cb_obfuscate_mail(str_replace('$1',$path,$IMap[$imap]));
1707
2021-12-17
jrmu
$FmtV['$LinkText'] = cb_obfuscate_mail(preg_replace('/^mailto:/i', '', $txt));
1708
2021-12-17
jrmu
if($FmtV['$LinkText'] == preg_replace('/^mailto:/i', '', $FmtV['$LinkUrl'])) $FmtV['$LinkUrl'] = '';
1709
2021-12-17
jrmu
else $FmtV['$LinkUrl'] = " -&gt; ".$FmtV['$LinkUrl'];
1710
2021-12-17
jrmu
$FmtV['$LinkAlt'] = str_replace(array('"',"'"),array('&#34;','&#39;'),cb_obfuscate_mail($title, 0));
1711
2021-12-17
jrmu
return str_replace(array_keys($FmtV),array_values($FmtV), $IMapLinkFmt['obfuscate-mailto:']);
1712
2021-12-17
jrmu
}
1713
2021-12-17
jrmu
1714
2021-12-17
jrmu
function cb_obfuscate_mail($x, $wrap=1) {
1715
2021-12-17
jrmu
$classes = array('.' => '_d', '@' => '_a');
1716
2021-12-17
jrmu
$texts = array( '.' => XL(' [period] '), '@' => XL(' [snail] '));
1717
2021-12-17
jrmu
foreach($classes as $k=>$v)
1718
2021-12-17
jrmu
$x = preg_replace("/(\\w)".preg_quote($k)."(\\w)/",
1719
2021-12-17
jrmu
($wrap?
1720
2021-12-17
jrmu
"$1<span class='$v'>{$texts[$k]}</span>$2"
1721
2021-12-17
jrmu
: "$1{$texts[$k]}$2")
1722
2021-12-17
jrmu
, $x);
1723
2021-12-17
jrmu
return $x;
1724
2021-12-17
jrmu
}
1725
2021-12-17
jrmu
1726
2021-12-17
jrmu
function LinkPage($pagename,$imap,$path,$alt,$txt,$fmt=NULL) {
1727
2021-12-17
jrmu
global $QueryFragPattern, $LinkPageExistsFmt, $LinkPageSelfFmt,
1728
2021-12-17
jrmu
$LinkPageCreateSpaceFmt, $LinkPageCreateFmt, $LinkTargets,
1729
2021-12-17
jrmu
$EnableLinkPageRelative, $EnableLinkPlusTitlespaced, $AddLinkCSS;
1730
2021-12-17
jrmu
$alt = str_replace(array('"',"'"),array('&#34;','&#39;'),$alt);
1731
2021-12-17
jrmu
$path = preg_replace('/(#[-.:\\w]*)#.*$/', '$1', $path); # PITS:01388
1732
2021-12-17
jrmu
if (is_array($txt)) { # PITS:01392
1733
2021-12-17
jrmu
$suffix = $txt[1];
1734
2021-12-17
jrmu
$txt = $txt[0];
1735
2021-12-17
jrmu
}
1736
2021-12-17
jrmu
if (!$fmt && @$path[0] == '#') {
1737
2021-12-17
jrmu
$path = preg_replace("/[^-.:\\w]/", '', $path);
1738
2021-12-17
jrmu
if (trim($txt) == '+') $txt = PageVar($pagename, '$Title') . @$suffix;
1739
2021-12-17
jrmu
if ($alt) $alt = " title='$alt'";
1740
2021-12-17
jrmu
return ($path) ? "<a href='#$path'$alt>".str_replace("$", "&#036;", $txt)."</a>" : '';
1741
2021-12-17
jrmu
}
1742
2021-12-17
jrmu
if (!preg_match("/^\\s*([^#?]+)($QueryFragPattern)?$/",$path,$match))
1743
2021-12-17
jrmu
return '';
1744
2021-12-17
jrmu
$tgtname = MakePageName($pagename, $match[1]);
1745
2021-12-17
jrmu
if (!$tgtname) return '';
1746
2021-12-17
jrmu
$qf = @$match[2];
1747
2021-12-17
jrmu
@$LinkTargets[$tgtname]++;
1748
2021-12-17
jrmu
if (!$fmt) {
1749
2021-12-17
jrmu
if (!PageExists($tgtname) && !preg_match('/[&?]action=/', $qf))
1750
2021-12-17
jrmu
$fmt = preg_match('/\\s/', $txt)
1751
2021-12-17
jrmu
? $LinkPageCreateSpaceFmt : $LinkPageCreateFmt;
1752
2021-12-17
jrmu
else
1753
2021-12-17
jrmu
$fmt = ($tgtname == $pagename && $qf == '')
1754
2021-12-17
jrmu
? $LinkPageSelfFmt : $LinkPageExistsFmt;
1755
2021-12-17
jrmu
}
1756
2021-12-17
jrmu
$url = PageVar($tgtname, '$PageUrl');
1757
2021-12-17
jrmu
if (trim($txt) == '+') $txt = PageVar($tgtname,
1758
2021-12-17
jrmu
IsEnabled($EnableLinkPlusTitlespaced, 0) ? '$Titlespaced' : '$Title') . @$suffix;
1759
2021-12-17
jrmu
$txt = str_replace("$", "&#036;", $txt);
1760
2021-12-17
jrmu
if (@$EnableLinkPageRelative)
1761
2021-12-17
jrmu
$url = preg_replace('!^[a-z]+://[^/]*!i', '', $url);
1762
2021-12-17
jrmu
$fmt = str_replace(array('$LinkUrl', '$LinkText', '$LinkAlt'),
1763
2021-12-17
jrmu
array($url.PUE($qf), $txt, $alt), $fmt);
1764
2021-12-17
jrmu
if(IsEnabled($AddLinkCSS['othergroup'])) {
1765
2021-12-17
jrmu
list($cgroup, ) = explode('.', $pagename);
1766
2021-12-17
jrmu
list($tgroup, ) = explode('.', $tgtname);
1767
2021-12-17
jrmu
if($cgroup != $tgroup)
1768
2021-12-17
jrmu
$fmt = preg_replace('/(<a[^>]*class=["\'])/', "$1{$AddLinkCSS['othergroup']} ", $fmt);
1769
2021-12-17
jrmu
}
1770
2021-12-17
jrmu
return FmtPageName($fmt,$tgtname);
1771
2021-12-17
jrmu
}
1772
2021-12-17
jrmu
1773
2021-12-17
jrmu
function MakeLink($pagename,$tgt,$txt=NULL,$suffix=NULL,$fmt=NULL) {
1774
2021-12-17
jrmu
global $LinkPattern,$LinkFunctions,$UrlExcludeChars,$ImgExtPattern,$ImgTagFmt,
1775
2021-12-17
jrmu
$LinkTitleFunction;
1776
2021-12-17
jrmu
if(preg_match("/^(.*)(?:\"(.*)\")\\s*$/",$tgt,$x)) list(,$tgt,$title) = $x;
1777
2021-12-17
jrmu
$t = preg_replace('/[()]/','',trim($tgt));
1778
2021-12-17
jrmu
$t = preg_replace('/<[^>]*>/','',$t);
1779
2021-12-17
jrmu
$t = trim(MarkupRestore($t));
1780
2021-12-17
jrmu
$txtr = trim(MarkupRestore($txt));
1781
2021-12-17
jrmu
1782
2021-12-17
jrmu
preg_match("/^($LinkPattern)?(.+)$/",$t,$m);
1783
2021-12-17
jrmu
if (!@$m[1]) $m[1]='<:page>';
1784
2021-12-17
jrmu
if (preg_match("/(($LinkPattern)([^$UrlExcludeChars]+$ImgExtPattern))(\"(.*)\")?$/",$txtr,$tm))
1785
2021-12-17
jrmu
$txt = $LinkFunctions[$tm[2]]($pagename,$tm[2],$tm[3],@$tm[5],
1786
2021-12-17
jrmu
$tm[1],$ImgTagFmt);
1787
2021-12-17
jrmu
else {
1788
2021-12-17
jrmu
if (is_null($txt)) {
1789
2021-12-17
jrmu
$txt = preg_replace('/\\([^)]*\\)/','',$tgt);
1790
2021-12-17
jrmu
if ($m[1]=='<:page>') {
1791
2021-12-17
jrmu
$txt = preg_replace('!/\\s*$!', '', $txt);
1792
2021-12-17
jrmu
$txt = preg_replace('!^.*[^<]/!', '', $txt);
1793
2021-12-17
jrmu
}
1794
2021-12-17
jrmu
}
1795
2021-12-17
jrmu
if ($m[1]=='<:page>' && trim($txt) == '+' && $suffix>'') { # PITS:01392
1796
2021-12-17
jrmu
$txt = array(trim($txt), $suffix);
1797
2021-12-17
jrmu
}
1798
2021-12-17
jrmu
else $txt .= $suffix;
1799
2021-12-17
jrmu
}
1800
2021-12-17
jrmu
if (@$LinkTitleFunction) $title = $LinkTitleFunction($pagename,$m,$txt);
1801
2021-12-17
jrmu
else $title = PHSC(MarkupRestore(@$title), ENT_QUOTES);
1802
2021-12-17
jrmu
$out = $LinkFunctions[$m[1]]($pagename,$m[1],@$m[2],@$title,$txt,$fmt);
1803
2021-12-17
jrmu
return preg_replace('/(<[^>]+)\\stitle=(""|\'\')/', '$1', $out);
1804
2021-12-17
jrmu
}
1805
2021-12-17
jrmu
1806
2021-12-17
jrmu
function Markup($id, $when, $pat=NULL, $rep=NULL, $tracelev=0) {
1807
2021-12-17
jrmu
global $MarkupTable, $EnableMarkupDiag;
1808
2021-12-17
jrmu
unset($GLOBALS['MarkupRules']);
1809
2021-12-17
jrmu
if (preg_match('/^([<>])?(.+)$/', $when, $m)) {
1810
2021-12-17
jrmu
$MarkupTable[$id]['cmd'] = $when;
1811
2021-12-17
jrmu
$MarkupTable[$m[2]]['dep'][$id] = $m[1];
1812
2021-12-17
jrmu
if (!$m[1]) $m[1] = '=';
1813
2021-12-17
jrmu
if (@$MarkupTable[$m[2]]['seq']) {
1814
2021-12-17
jrmu
$MarkupTable[$id]['seq'] = $MarkupTable[$m[2]]['seq'].$m[1];
1815
2021-12-17
jrmu
foreach((array)@$MarkupTable[$id]['dep'] as $i=>$m)
1816
2021-12-17
jrmu
Markup($i,"$m$id");
1817
2021-12-17
jrmu
unset($GLOBALS['MarkupTable'][$id]['dep']);
1818
2021-12-17
jrmu
}
1819
2021-12-17
jrmu
}
1820
2021-12-17
jrmu
if ($pat && !isset($MarkupTable[$id]['pat'])) {
1821
2021-12-17
jrmu
$MarkupTable[$id]['pat'] = $pat;
1822
2021-12-17
jrmu
$MarkupTable[$id]['rep'] = $rep;
1823
2021-12-17
jrmu
1824
2021-12-17
jrmu
$oldpat = preg_match('!/[^/]*e[^/]*$!', $pat);
1825
2021-12-17
jrmu
if (IsEnabled($EnableMarkupDiag, 0) || $oldpat) {
1826
2021-12-17
jrmu
$exmark = $oldpat ? '!' : ' ';
1827
2021-12-17
jrmu
if (function_exists('debug_backtrace')) {
1828
2021-12-17
jrmu
$dbg = debug_backtrace();
1829
2021-12-17
jrmu
$dbginfo = $dbg[$tracelev];
1830
2021-12-17
jrmu
$MarkupTable[$id]['dbg'] = "$exmark file: {$dbginfo['file']}, "
1831
2021-12-17
jrmu
. "line: {$dbginfo['line']}, pat: {$dbginfo['args'][2]}";
1832
2021-12-17
jrmu
}
1833
2021-12-17
jrmu
else
1834
2021-12-17
jrmu
$MarkupTable[$id]['dbg'] = "$exmark id: '$id', pat: '$pat'";
1835
2021-12-17
jrmu
}
1836
2021-12-17
jrmu
}
1837
2021-12-17
jrmu
}
1838
2021-12-17
jrmu
1839
2021-12-17
jrmu
function Markup_e($id, $when, $pat, $rep, $template = 'markup_e') {
1840
2021-12-17
jrmu
if (!is_callable($rep)) $rep = PCCF($rep, $template);
1841
2021-12-17
jrmu
Markup($id, $when, $pat, $rep, 1);
1842
2021-12-17
jrmu
}
1843
2021-12-17
jrmu
1844
2021-12-17
jrmu
function DisableMarkup() {
1845
2021-12-17
jrmu
global $MarkupTable;
1846
2021-12-17
jrmu
$idlist = func_get_args();
1847
2021-12-17
jrmu
unset($GLOBALS['MarkupRules']);
1848
2021-12-17
jrmu
while (count($idlist)>0) {
1849
2021-12-17
jrmu
$id = array_shift($idlist);
1850
2021-12-17
jrmu
if (is_array($id)) { $idlist = array_merge($idlist, $id); continue; }
1851
2021-12-17
jrmu
$MarkupTable[$id] = array('cmd' => 'none', 'pat'=>'');
1852
2021-12-17
jrmu
}
1853
2021-12-17
jrmu
}
1854
2021-12-17
jrmu
1855
2021-12-17
jrmu
function mpcmp($a,$b) { return @strcmp($a['seq'].'=',$b['seq'].'='); }
1856
2021-12-17
jrmu
function BuildMarkupRules() {
1857
2021-12-17
jrmu
global $MarkupTable,$MarkupRules,$LinkPattern;
1858
2021-12-17
jrmu
if (!$MarkupRules) {
1859
2021-12-17
jrmu
uasort($MarkupTable,'mpcmp');
1860
2021-12-17
jrmu
foreach($MarkupTable as $id=>$m)
1861
2021-12-17
jrmu
if (@$m['pat'] && @$m['seq']) {
1862
2021-12-17
jrmu
$MarkupRules[str_replace('\\L',$LinkPattern,$m['pat'])]
1863
2021-12-17
jrmu
= array($m['rep'], $id);
1864
2021-12-17
jrmu
}
1865
2021-12-17
jrmu
}
1866
2021-12-17
jrmu
return $MarkupRules;
1867
2021-12-17
jrmu
}
1868
2021-12-17
jrmu
1869
2021-12-17
jrmu
1870
2021-12-17
jrmu
function MarkupToHTML($pagename, $text, $opt = NULL) {
1871
2021-12-17
jrmu
# convert wiki markup text to HTML output
1872
2021-12-17
jrmu
global $MarkupRules, $MarkupFrame, $MarkupFrameBase, $WikiWordCount,
1873
2021-12-17
jrmu
$K0, $K1, $RedoMarkupLine, $MarkupToHTML;
1874
2021-12-17
jrmu
$MarkupToHTML['pagename'] = $pagename;
1875
2021-12-17
jrmu
1876
2021-12-17
jrmu
StopWatch('MarkupToHTML begin');
1877
2021-12-17
jrmu
array_unshift($MarkupFrame, array_merge($MarkupFrameBase, (array)$opt));
1878
2021-12-17
jrmu
$MarkupFrame[0]['wwcount'] = $WikiWordCount;
1879
2021-12-17
jrmu
foreach((array)$text as $l)
1880
2021-12-17
jrmu
$lines[] = $MarkupFrame[0]['escape'] ? PVSE($l) : $l;
1881
2021-12-17
jrmu
$lines[] = '(:closeall:)';
1882
2021-12-17
jrmu
$out = '';
1883
2021-12-17
jrmu
while (count($lines)>0) {
1884
2021-12-17
jrmu
$x = array_shift($lines);
1885
2021-12-17
jrmu
$RedoMarkupLine=0;
1886
2021-12-17
jrmu
$markrules = BuildMarkupRules();
1887
2021-12-17
jrmu
foreach($markrules as $p=>$r) {
1888
2021-12-17
jrmu
list($r, $id) = (array)$r;
1889
2021-12-17
jrmu
$MarkupToHTML['markupid'] = $id;
1890
2021-12-17
jrmu
if ($p[0] == '/') {
1891
2021-12-17
jrmu
if (is_callable($r)) $x = preg_replace_callback($p,$r,$x);
1892
2021-12-17
jrmu
else $x=preg_replace($p,$r,$x); # simple text OR called by old addon|skin|recipe needing update, see pmwiki.org/Troubleshooting
1893
2021-12-17
jrmu
}
1894
2021-12-17
jrmu
elseif (strstr($x,$p)!==false) $x=eval($r);
1895
2021-12-17
jrmu
if (isset($php_errormsg))
1896
2021-12-17
jrmu
{ echo "ERROR: pat=$p $php_errormsg"; unset($php_errormsg); }
1897
2021-12-17
jrmu
if ($RedoMarkupLine) { $lines=array_merge((array)$x,$lines); continue 2; }
1898
2021-12-17
jrmu
}
1899
2021-12-17
jrmu
if ($x>'') $out .= "$x\n";
1900
2021-12-17
jrmu
}
1901
2021-12-17
jrmu
foreach((array)(@$MarkupFrame[0]['posteval']) as $v) eval($v);
1902
2021-12-17
jrmu
array_shift($MarkupFrame);
1903
2021-12-17
jrmu
StopWatch('MarkupToHTML end');
1904
2021-12-17
jrmu
return $out;
1905
2021-12-17
jrmu
}
1906
2021-12-17
jrmu
1907
2021-12-17
jrmu
function HandleBrowse($pagename, $auth = 'read') {
1908
2021-12-17
jrmu
# handle display of a page
1909
2021-12-17
jrmu
global $DefaultPageTextFmt, $PageNotFoundHeaderFmt, $HTTPHeaders,
1910
2021-12-17
jrmu
$EnableHTMLCache, $NoHTMLCache, $PageCacheFile, $LastModTime, $IsHTMLCached,
1911
2021-12-17
jrmu
$FmtV, $HandleBrowseFmt, $PageStartFmt, $PageEndFmt, $PageRedirectFmt;
1912
2021-12-17
jrmu
$page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
1913
2021-12-17
jrmu
if (!$page) Abort("?cannot read $pagename");
1914
2021-12-17
jrmu
PCache($pagename,$page);
1915
2021-12-17
jrmu
if (PageExists($pagename)) $text = @$page['text'];
1916
2021-12-17
jrmu
else {
1917
2021-12-17
jrmu
SDV($DefaultPageTextFmt,'(:include $[{$SiteGroup}.PageNotFound]:)');
1918
2021-12-17
jrmu
$text = FmtPageName($DefaultPageTextFmt, $pagename);
1919
2021-12-17
jrmu
SDV($PageNotFoundHeaderFmt, 'HTTP/1.1 404 Not Found');
1920
2021-12-17
jrmu
SDV($HTTPHeaders['status'], $PageNotFoundHeaderFmt);
1921
2021-12-17
jrmu
}
1922
2021-12-17
jrmu
$opt = array();
1923
2021-12-17
jrmu
SDV($PageRedirectFmt,"<p><i>($[redirected from] <a rel='nofollow'
1924
2021-12-17
jrmu
href='{\$PageUrl}?action=edit'>{\$FullName}</a>)</i></p>\n");
1925
2021-12-17
jrmu
if (@!$_GET['from']) { $opt['redirect'] = 1; $PageRedirectFmt = ''; }
1926
2021-12-17
jrmu
else {
1927
2021-12-17
jrmu
$frompage = MakePageName($pagename, $_GET['from']);
1928
2021-12-17
jrmu
$PageRedirectFmt = (!$frompage) ? ''
1929
2021-12-17
jrmu
: FmtPageName($PageRedirectFmt, $frompage);
1930
2021-12-17
jrmu
}
1931
2021-12-17
jrmu
if (@$EnableHTMLCache && !$NoHTMLCache && $PageCacheFile &&
1932
2021-12-17
jrmu
@filemtime($PageCacheFile) > $LastModTime) {
1933
2021-12-17
jrmu
list($ctext) = unserialize(file_get_contents($PageCacheFile));
1934
2021-12-17
jrmu
$FmtV['$PageText'] = "<!--cached-->$ctext";
1935
2021-12-17
jrmu
$IsHTMLCached = 1;
1936
2021-12-17
jrmu
StopWatch("HandleBrowse: using cached copy");
1937
2021-12-17
jrmu
} else {
1938
2021-12-17
jrmu
$IsHTMLCached = 0;
1939
2021-12-17
jrmu
$text = '(:groupheader:)'.@$text.'(:groupfooter:)';
1940
2021-12-17
jrmu
$t1 = time();
1941
2021-12-17
jrmu
$FmtV['$PageText'] = MarkupToHTML($pagename, $text, $opt);
1942
2021-12-17
jrmu
if (@$EnableHTMLCache > 0 && !$NoHTMLCache && $PageCacheFile
1943
2021-12-17
jrmu
&& (time() - $t1 + 1) >= $EnableHTMLCache) {
1944
2021-12-17
jrmu
$fp = @fopen("$PageCacheFile,new", "x");
1945
2021-12-17
jrmu
if ($fp) {
1946
2021-12-17
jrmu
StopWatch("HandleBrowse: caching page");
1947
2021-12-17
jrmu
fwrite($fp, serialize(array($FmtV['$PageText']))); fclose($fp);
1948
2021-12-17
jrmu
rename("$PageCacheFile,new", $PageCacheFile);
1949
2021-12-17
jrmu
}
1950
2021-12-17
jrmu
}
1951
2021-12-17
jrmu
}
1952
2021-12-17
jrmu
SDV($HandleBrowseFmt,array(&$PageStartFmt, &$PageRedirectFmt, '$PageText',
1953
2021-12-17
jrmu
&$PageEndFmt));
1954
2021-12-17
jrmu
PrintFmt($pagename,$HandleBrowseFmt);
1955
2021-12-17
jrmu
}
1956
2021-12-17
jrmu
1957
2021-12-17
jrmu
1958
2021-12-17
jrmu
## UpdatePage goes through all of the steps needed to update a page,
1959
2021-12-17
jrmu
## preserving page history, computing link targets, page titles,
1960
2021-12-17
jrmu
## and other page attributes. It does this by calling each entry
1961
2021-12-17
jrmu
## in $EditFunctions. $pagename is the name of the page to be updated,
1962
2021-12-17
jrmu
## $page is the old version of the page (used for page history),
1963
2021-12-17
jrmu
## $new is the new version of the page to be saved, and $fnlist is
1964
2021-12-17
jrmu
## an optional list of functions to use instead of $EditFunctions.
1965
2021-12-17
jrmu
function UpdatePage(&$pagename, &$page, &$new, $fnlist = NULL) {
1966
2021-12-17
jrmu
global $EditFunctions, $IsPagePosted;
1967
2021-12-17
jrmu
StopWatch("UpdatePage: begin $pagename");
1968
2021-12-17
jrmu
if (is_null($fnlist)) $fnlist = $EditFunctions;
1969
2021-12-17
jrmu
$IsPagePosted = false;
1970
2021-12-17
jrmu
foreach((array)$fnlist as $fn) {
1971
2021-12-17
jrmu
StopWatch("UpdatePage: $fn ($pagename)");
1972
2021-12-17
jrmu
$fn($pagename, $page, $new);
1973
2021-12-17
jrmu
}
1974
2021-12-17
jrmu
StopWatch("UpdatePage: end $pagename");
1975
2021-12-17
jrmu
return $IsPagePosted;
1976
2021-12-17
jrmu
}
1977
2021-12-17
jrmu
1978
2021-12-17
jrmu
1979
2021-12-17
jrmu
# EditTemplate allows a site administrator to pre-populate new pages
1980
2021-12-17
jrmu
# with the contents of another page.
1981
2021-12-17
jrmu
function EditTemplate($pagename, &$page, &$new) {
1982
2021-12-17
jrmu
global $EditTemplatesFmt;
1983
2021-12-17
jrmu
if (@$new['text'] > '') return;
1984
2021-12-17
jrmu
if (@$_REQUEST['template'] && PageExists($_REQUEST['template'])) {
1985
2021-12-17
jrmu
$p = RetrieveAuthPage($_REQUEST['template'], 'read', false,
1986
2021-12-17
jrmu
READPAGE_CURRENT);
1987
2021-12-17
jrmu
if ($p['text'] > '') $new['text'] = $p['text'];
1988
2021-12-17
jrmu
return;
1989
2021-12-17
jrmu
}
1990
2021-12-17
jrmu
foreach((array)$EditTemplatesFmt as $t) {
1991
2021-12-17
jrmu
$p = RetrieveAuthPage(FmtPageName($t,$pagename), 'read', false,
1992
2021-12-17
jrmu
READPAGE_CURRENT);
1993
2021-12-17
jrmu
if (@$p['text'] > '') { $new['text'] = $p['text']; return; }
1994
2021-12-17
jrmu
}
1995
2021-12-17
jrmu
}
1996
2021-12-17
jrmu
1997
2021-12-17
jrmu
# RestorePage handles returning to the version of text as of
1998
2021-12-17
jrmu
# the version given by $restore or $_REQUEST['restore'].
1999
2021-12-17
jrmu
function RestorePage($pagename,&$page,&$new,$restore=NULL) {
2000
2021-12-17
jrmu
if (is_null($restore)) $restore=@$_REQUEST['restore'];
2001
2021-12-17
jrmu
if (!$restore) return;
2002
2021-12-17
jrmu
$t = $page['text'];
2003
2021-12-17
jrmu
$nl = (substr($t,-1)=="\n");
2004
2021-12-17
jrmu
$t = explode("\n",$t);
2005
2021-12-17
jrmu
if ($nl) array_pop($t);
2006
2021-12-17
jrmu
krsort($page); reset($page);
2007
2021-12-17
jrmu
foreach($page as $k=>$v) {
2008
2021-12-17
jrmu
if ($k<$restore) break;
2009
2021-12-17
jrmu
if (strncmp($k, 'diff:', 5) != 0) continue;
2010
2021-12-17
jrmu
foreach(explode("\n",$v) as $x) {
2011
2021-12-17
jrmu
if (preg_match('/^(\\d+)(,(\\d+))?([adc])(\\d+)/',$x,$match)) {
2012
2021-12-17
jrmu
$a1 = $a2 = $match[1];
2013
2021-12-17
jrmu
if ($match[3]) $a2=$match[3];
2014
2021-12-17
jrmu
$b1 = $match[5];
2015
2021-12-17
jrmu
if ($match[4]=='d') array_splice($t,$b1,$a2-$a1+1);
2016
2021-12-17
jrmu
if ($match[4]=='c') array_splice($t,$b1-1,$a2-$a1+1);
2017
2021-12-17
jrmu
continue;
2018
2021-12-17
jrmu
}
2019
2021-12-17
jrmu
if (strncmp($x,'< ',2) == 0) { $nlflag=true; continue; }
2020
2021-12-17
jrmu
if (preg_match('/^> (.*)$/',$x,$match)) {
2021
2021-12-17
jrmu
$nlflag=false;
2022
2021-12-17
jrmu
array_splice($t,$b1-1,0,$match[1]); $b1++;
2023
2021-12-17
jrmu
}
2024
2021-12-17
jrmu
if ($x=='\\ No newline at end of file') $nl=$nlflag;
2025
2021-12-17
jrmu
}
2026
2021-12-17
jrmu
}
2027
2021-12-17
jrmu
if ($nl) $t[]='';
2028
2021-12-17
jrmu
$new['text']=implode("\n",$t);
2029
2021-12-17
jrmu
$new['=preview'] = $new['text'];
2030
2021-12-17
jrmu
PCache($pagename, $new);
2031
2021-12-17
jrmu
return $new['text'];
2032
2021-12-17
jrmu
}
2033
2021-12-17
jrmu
2034
2021-12-17
jrmu
## ReplaceOnSave performs text replacements on the text being posted.
2035
2021-12-17
jrmu
## Patterns held in $ROEPatterns are replaced on every edit request,
2036
2021-12-17
jrmu
## patterns held in $ROSPatterns are replaced only when the page
2037
2021-12-17
jrmu
## is being posted (as signaled by $EnablePost).
2038
2021-12-17
jrmu
function ReplaceOnSave($pagename,&$page,&$new) {
2039
2021-12-17
jrmu
global $EnablePost, $ROSPatterns, $ROEPatterns;
2040
2021-12-17
jrmu
$new['text'] = ProcessROESPatterns(@$new['text'], $ROEPatterns);
2041
2021-12-17
jrmu
if ($EnablePost) {
2042
2021-12-17
jrmu
$new['text'] = ProcessROESPatterns($new['text'], $ROSPatterns);
2043
2021-12-17
jrmu
}
2044
2021-12-17
jrmu
$new['=preview'] = $new['text'];
2045
2021-12-17
jrmu
PCache($pagename, $new);
2046
2021-12-17
jrmu
}
2047
2021-12-17
jrmu
function ProcessROESPatterns($text, $patterns) {
2048
2021-12-17
jrmu
global $EnableROSEscape;
2049
2021-12-17
jrmu
if (IsEnabled($EnableROSEscape, 0)) $text = MarkupEscape($text);
2050
2021-12-17
jrmu
$text = PPRA((array)@$patterns, $text);
2051
2021-12-17
jrmu
if (IsEnabled($EnableROSEscape, 0)) $text = MarkupRestore($text);
2052
2021-12-17
jrmu
return $text;
2053
2021-12-17
jrmu
}
2054
2021-12-17
jrmu
2055
2021-12-17
jrmu
function SaveAttributes($pagename,&$page,&$new) {
2056
2021-12-17
jrmu
global $EnablePost, $LinkTargets, $SaveAttrPatterns, $PCache,
2057
2021-12-17
jrmu
$SaveProperties;
2058
2021-12-17
jrmu
if (!$EnablePost) return;
2059
2021-12-17
jrmu
$text = PPRA($SaveAttrPatterns, $new['text']);
2060
2021-12-17
jrmu
$LinkTargets = array();
2061
2021-12-17
jrmu
$new['=html'] = MarkupToHTML($pagename,$text);
2062
2021-12-17
jrmu
$new['targets'] = implode(',',array_keys((array)$LinkTargets));
2063
2021-12-17
jrmu
$p = & $PCache[$pagename];
2064
2021-12-17
jrmu
foreach((array)$SaveProperties as $k) {
2065
2021-12-17
jrmu
if (@$p["=p_$k"]) $new[$k] = $p["=p_$k"];
2066
2021-12-17
jrmu
else unset($new[$k]);
2067
2021-12-17
jrmu
}
2068
2021-12-17
jrmu
unset($new['excerpt']);
2069
2021-12-17
jrmu
}
2070
2021-12-17
jrmu
2071
2021-12-17
jrmu
function PostPage($pagename, &$page, &$new) {
2072
2021-12-17
jrmu
global $DiffKeepDays, $DiffFunction, $DeleteKeyPattern, $EnablePost,
2073
2021-12-17
jrmu
$Now, $Charset, $Author, $WikiDir, $IsPagePosted, $DiffKeepNum;
2074
2021-12-17
jrmu
SDV($DiffKeepDays,3650);
2075
2021-12-17
jrmu
SDV($DiffKeepNum,20);
2076
2021-12-17
jrmu
SDV($DeleteKeyPattern,"^\\s*delete\\s*$");
2077
2021-12-17
jrmu
$IsPagePosted = false;
2078
2021-12-17
jrmu
if ($EnablePost) {
2079
2021-12-17
jrmu
$new['charset'] = $Charset; # kept for now, may be needed if custom PageStore
2080
2021-12-17
jrmu
$new['author'] = @$Author;
2081
2021-12-17
jrmu
$new["author:$Now"] = @$Author;
2082
2021-12-17
jrmu
$new["host:$Now"] = $_SERVER['REMOTE_ADDR'];
2083
2021-12-17
jrmu
$diffclass = preg_replace('/\\W/','',@$_POST['diffclass']);
2084
2021-12-17
jrmu
if ($page['time']>0 && function_exists(@$DiffFunction))
2085
2021-12-17
jrmu
$new["diff:$Now:{$page['time']}:$diffclass"] =
2086
2021-12-17
jrmu
$DiffFunction($new['text'],@$page['text']);
2087
2021-12-17
jrmu
$keepgmt = $Now-$DiffKeepDays * 86400;
2088
2021-12-17
jrmu
$keepnum = array();
2089
2021-12-17
jrmu
$keys = array_keys($new);
2090
2021-12-17
jrmu
foreach($keys as $k)
2091
2021-12-17
jrmu
if (preg_match("/^\\w+:(\\d+)/",$k,$match)) {
2092
2021-12-17
jrmu
$keepnum[$match[1]] = 1;
2093
2021-12-17
jrmu
if (count($keepnum)>$DiffKeepNum && $match[1]<$keepgmt)
2094
2021-12-17
jrmu
unset($new[$k]);
2095
2021-12-17
jrmu
}
2096
2021-12-17
jrmu
if (preg_match("/$DeleteKeyPattern/",$new['text'])){
2097
2021-12-17
jrmu
if (@$new['passwdattr']>'' && !CondAuth($pagename, 'attr'))
2098
2021-12-17
jrmu
Abort('$[The page has an "attr" attribute and cannot be deleted.]');
2099
2021-12-17
jrmu
else $WikiDir->delete($pagename);
2100
2021-12-17
jrmu
}
2101
2021-12-17
jrmu
else WritePage($pagename,$new);
2102
2021-12-17
jrmu
$IsPagePosted = true;
2103
2021-12-17
jrmu
}
2104
2021-12-17
jrmu
}
2105
2021-12-17
jrmu
2106
2021-12-17
jrmu
function PostRecentChanges($pagename,$page,$new,$Fmt=null) {
2107
2021-12-17
jrmu
global $IsPagePosted, $RecentChangesFmt, $RCDelimPattern, $RCLinesMax,
2108
2021-12-17
jrmu
$EnableRCDiffBytes;
2109
2021-12-17
jrmu
if (!$IsPagePosted && $Fmt==null) return;
2110
2021-12-17
jrmu
if ($Fmt==null) $Fmt = $RecentChangesFmt;
2111
2021-12-17
jrmu
foreach($Fmt as $rcfmt=>$pgfmt) {
2112
2021-12-17
jrmu
$rcname = FmtPageName($rcfmt,$pagename); if (!$rcname) continue;
2113
2021-12-17
jrmu
$pgtext = FmtPageName($pgfmt,$pagename); if (!$pgtext) continue;
2114
2021-12-17
jrmu
if (@$seen[$rcname]++) continue;
2115
2021-12-17
jrmu
2116
2021-12-17
jrmu
if (IsEnabled($EnableRCDiffBytes, 0)) {
2117
2021-12-17
jrmu
$pgtext = PPRA(array(
2118
2021-12-17
jrmu
'/\\(([+-])(\\d+)\\)(\\s*=\\]\\s*)$/'=>'$3%diffmarkup%{$1($1$2)$1}%%',
2119
2021-12-17
jrmu
'/\\(\\+(0\\)\\+\\}%%)$/'=>'(&#177;$1'), $pgtext);
2120
2021-12-17
jrmu
}
2121
2021-12-17
jrmu
$rcpage = ReadPage($rcname);
2122
2021-12-17
jrmu
$rcelim = preg_quote(preg_replace("/$RCDelimPattern.*$/",' ',$pgtext),'/');
2123
2021-12-17
jrmu
$rcpage['text'] = preg_replace("/^.*$rcelim.*\n/m", '', @$rcpage['text']);
2124
2021-12-17
jrmu
if (!preg_match("/$RCDelimPattern/",$rcpage['text']))
2125
2021-12-17
jrmu
$rcpage['text'] .= "$pgtext\n";
2126
2021-12-17
jrmu
else
2127
2021-12-17
jrmu
$rcpage['text'] = preg_replace("/([^\n]*$RCDelimPattern.*\n)/",
2128
2021-12-17
jrmu
str_replace("$", "\\$", $pgtext) . "\n$1", $rcpage['text'], 1);
2129
2021-12-17
jrmu
if (@$RCLinesMax > 0)
2130
2021-12-17
jrmu
$rcpage['text'] = implode("\n", array_slice(
2131
2021-12-17
jrmu
explode("\n", $rcpage['text'], $RCLinesMax + 1), 0, $RCLinesMax));
2132
2021-12-17
jrmu
WritePage($rcname, $rcpage);
2133
2021-12-17
jrmu
}
2134
2021-12-17
jrmu
}
2135
2021-12-17
jrmu
2136
2021-12-17
jrmu
function AutoCreateTargets($pagename, &$page, &$new) {
2137
2021-12-17
jrmu
global $IsPagePosted, $AutoCreate, $LinkTargets;
2138
2021-12-17
jrmu
if (!$IsPagePosted) return;
2139
2021-12-17
jrmu
foreach((array)@$AutoCreate as $pat => $init) {
2140
2021-12-17
jrmu
if (is_null($init)) continue;
2141
2021-12-17
jrmu
foreach(preg_grep($pat, array_keys((array)@$LinkTargets)) as $aname) {
2142
2021-12-17
jrmu
if (PageExists($aname)) continue;
2143
2021-12-17
jrmu
$x = RetrieveAuthPage($aname, 'edit', false, READPAGE_CURRENT);
2144
2021-12-17
jrmu
if (!$x) continue;
2145
2021-12-17
jrmu
WritePage($aname, $init);
2146
2021-12-17
jrmu
}
2147
2021-12-17
jrmu
}
2148
2021-12-17
jrmu
}
2149
2021-12-17
jrmu
2150
2021-12-17
jrmu
function PreviewPage($pagename,&$page,&$new) {
2151
2021-12-17
jrmu
global $IsPageSaved, $FmtV, $ROSPatterns;
2152
2021-12-17
jrmu
if (@$_REQUEST['preview']) {
2153
2021-12-17
jrmu
$text = ProcessROESPatterns($new['text'], $ROSPatterns);
2154
2021-12-17
jrmu
$text = '(:groupheader:)'.$text.'(:groupfooter:)';
2155
2021-12-17
jrmu
$FmtV['$PreviewText'] = MarkupToHTML($pagename,$text);
2156
2021-12-17
jrmu
}
2157
2021-12-17
jrmu
}
2158
2021-12-17
jrmu
2159
2021-12-17
jrmu
function HandleEdit($pagename, $auth = 'edit') {
2160
2021-12-17
jrmu
global $IsPagePosted, $EditFields, $ChangeSummary, $EditFunctions,
2161
2021-12-17
jrmu
$EnablePost, $FmtV, $Now, $EditRedirectFmt, $EnableRCDiffBytes,
2162
2021-12-17
jrmu
$PageEditForm, $HandleEditFmt, $PageStartFmt, $PageEditFmt, $PageEndFmt;
2163
2021-12-17
jrmu
SDV($EditRedirectFmt, '$FullName');
2164
2021-12-17
jrmu
if (@$_POST['cancel'])
2165
2021-12-17
jrmu
{ Redirect(FmtPageName($EditRedirectFmt, $pagename)); return; }
2166
2021-12-17
jrmu
Lock(2);
2167
2021-12-17
jrmu
$page = RetrieveAuthPage($pagename, $auth, true);
2168
2021-12-17
jrmu
if (!$page) Abort("?cannot edit $pagename");
2169
2021-12-17
jrmu
$new = $page;
2170
2021-12-17
jrmu
foreach((array)$EditFields as $k)
2171
2021-12-17
jrmu
if (isset($_POST[$k])) $new[$k]=str_replace("\r",'',stripmagic($_POST[$k]));
2172
2021-12-17
jrmu
2173
2021-12-17
jrmu
if (IsEnabled($EnableRCDiffBytes, 0) && isset($new['text'])) {
2174
2021-12-17
jrmu
$bytes = strlen($new['text']) - strlen(@$page['text']);
2175
2021-12-17
jrmu
if ($bytes>=0) $bytes = "+$bytes";
2176
2021-12-17
jrmu
$ChangeSummary = rtrim($ChangeSummary) . " ($bytes)";
2177
2021-12-17
jrmu
}
2178
2021-12-17
jrmu
$new['csum'] = $ChangeSummary;
2179
2021-12-17
jrmu
if ($ChangeSummary) $new["csum:$Now"] = $ChangeSummary;
2180
2021-12-17
jrmu
$EnablePost &= preg_grep('/^post/', array_keys(@$_POST));
2181
2021-12-17
jrmu
$new['=preview'] = @$new['text'];
2182
2021-12-17
jrmu
PCache($pagename, $new);
2183
2021-12-17
jrmu
UpdatePage($pagename, $page, $new);
2184
2021-12-17
jrmu
Lock(0);
2185
2021-12-17
jrmu
if ($IsPagePosted && !@$_POST['postedit'])
2186
2021-12-17
jrmu
{ Redirect(FmtPageName($EditRedirectFmt, $pagename)); return; }
2187
2021-12-17
jrmu
$FmtV['$DiffClassMinor'] =
2188
2021-12-17
jrmu
(@$_POST['diffclass']=='minor') ? "checked='checked'" : '';
2189
2021-12-17
jrmu
$FmtV['$EditText'] =
2190
2021-12-17
jrmu
str_replace('$','&#036;',PHSC(@$new['text'],ENT_NOQUOTES));
2191
2021-12-17
jrmu
$FmtV['$EditBaseTime'] = $Now;
2192
2021-12-17
jrmu
if (@$PageEditForm) {
2193
2021-12-17
jrmu
$efpage = FmtPageName($PageEditForm, $pagename);
2194
2021-12-17
jrmu
$form = RetrieveAuthPage($efpage, 'read', false, READPAGE_CURRENT);
2195
2021-12-17
jrmu
if (!$form || !@$form['text'])
2196
2021-12-17
jrmu
Abort("?unable to retrieve edit form $efpage", 'editform');
2197
2021-12-17
jrmu
$FmtV['$EditForm'] = MarkupToHTML($pagename, $form['text']);
2198
2021-12-17
jrmu
}
2199
2021-12-17
jrmu
SDV($PageEditFmt, "<div id='wikiedit'>
2200
2021-12-17
jrmu
<h2 class='wikiaction'>$[Editing {\$FullName}]</h2>
2201
2021-12-17
jrmu
<form method='post' rel='nofollow' action='\$PageUrl?action=edit'>
2202
2021-12-17
jrmu
<input type='hidden' name='action' value='edit' />
2203
2021-12-17
jrmu
<input type='hidden' name='n' value='\$FullName' />
2204
2021-12-17
jrmu
<input type='hidden' name='basetime' value='\$EditBaseTime' />
2205
2021-12-17
jrmu
\$EditMessageFmt
2206
2021-12-17
jrmu
<textarea id='text' name='text' rows='25' cols='60'
2207
2021-12-17
jrmu
onkeydown='if (event.keyCode==27) event.returnValue=false;'
2208
2021-12-17
jrmu
>\$EditText</textarea><br />
2209
2021-12-17
jrmu
<input type='submit' name='post' value=' $[Save] ' />");
2210
2021-12-17
jrmu
SDV($HandleEditFmt, array(&$PageStartFmt, &$PageEditFmt, &$PageEndFmt));
2211
2021-12-17
jrmu
PrintFmt($pagename, $HandleEditFmt);
2212
2021-12-17
jrmu
}
2213
2021-12-17
jrmu
2214
2021-12-17
jrmu
function HandleSource($pagename, $auth = 'read') {
2215
2021-12-17
jrmu
global $HTTPHeaders;
2216
2021-12-17
jrmu
$page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
2217
2021-12-17
jrmu
if (!$page) Abort("?cannot source $pagename");
2218
2021-12-17
jrmu
foreach ($HTTPHeaders as $h) {
2219
2021-12-17
jrmu
$h = preg_replace('!^Content-type:\\s+text/html!i',
2220
2021-12-17
jrmu
'Content-type: text/plain', $h);
2221
2021-12-17
jrmu
header($h);
2222
2021-12-17
jrmu
}
2223
2021-12-17
jrmu
echo @$page['text'];
2224
2021-12-17
jrmu
}
2225
2021-12-17
jrmu
2226
2021-12-17
jrmu
## PmWikiAuth provides password-protection of pages using PHP sessions.
2227
2021-12-17
jrmu
## It is normally called from RetrieveAuthPage. Since RetrieveAuthPage
2228
2021-12-17
jrmu
## can be called a lot within a single page execution (i.e., for every
2229
2021-12-17
jrmu
## page accessed), we cache the results of site passwords and
2230
2021-12-17
jrmu
## GroupAttribute pages to be able to speed up subsequent calls.
2231
2021-12-17
jrmu
function PmWikiAuth($pagename, $level, $authprompt=true, $since=0) {
2232
2021-12-17
jrmu
global $DefaultPasswords, $GroupAttributesFmt, $AllowPassword,
2233
2021-12-17
jrmu
$AuthCascade, $FmtV, $AuthPromptFmt, $PageStartFmt, $PageEndFmt,
2234
2021-12-17
jrmu
$AuthId, $AuthList, $NoHTMLCache;
2235
2021-12-17
jrmu
static $acache;
2236
2021-12-17
jrmu
SDV($GroupAttributesFmt,'$Group/GroupAttributes');
2237
2021-12-17
jrmu
SDV($AllowPassword,'nopass');
2238
2021-12-17
jrmu
$page = ReadPage($pagename, $since);
2239
2021-12-17
jrmu
if (!$page) { return false; }
2240
2021-12-17
jrmu
if (!isset($acache))
2241
2021-12-17
jrmu
SessionAuth($pagename, (@$_POST['authpw'])
2242
2021-12-17
jrmu
? array('authpw' => array($_POST['authpw'] => 1))
2243
2021-12-17
jrmu
: '');
2244
2021-12-17
jrmu
if (@$AuthId) {
2245
2021-12-17
jrmu
$AuthList["id:$AuthId"] = 1;
2246
2021-12-17
jrmu
$AuthList["id:-$AuthId"] = -1;
2247
2021-12-17
jrmu
$AuthList["id:*"] = 1;
2248
2021-12-17
jrmu
}
2249
2021-12-17
jrmu
## To allow @_site_edit in GroupAttributes, we cache it first
2250
2021-12-17
jrmu
if (!isset($acache['@site'])) {
2251
2021-12-17
jrmu
foreach($DefaultPasswords as $k => $v) {
2252
2021-12-17
jrmu
$x = array(2, array(), '');
2253
2021-12-17
jrmu
$acache['@site'][$k] = IsAuthorized($v, 'site', $x);
2254
2021-12-17
jrmu
$AuthList["@_site_$k"] = $acache['@site'][$k][0] ? 1 : 0;
2255
2021-12-17
jrmu
}
2256
2021-12-17
jrmu
}
2257
2021-12-17
jrmu
$gn = FmtPageName($GroupAttributesFmt, $pagename);
2258
2021-12-17
jrmu
if (!isset($acache[$gn])) {
2259
2021-12-17
jrmu
$gp = ReadPage($gn, READPAGE_CURRENT);
2260
2021-12-17
jrmu
foreach($DefaultPasswords as $k => $v) {
2261
2021-12-17
jrmu
$acache[$gn][$k] = IsAuthorized(@$gp["passwd$k"], 'group',
2262
2021-12-17
jrmu
$acache['@site'][$k]);
2263
2021-12-17
jrmu
}
2264
2021-12-17
jrmu
}
2265
2021-12-17
jrmu
foreach($DefaultPasswords as $k => $v)
2266
2021-12-17
jrmu
list($page['=auth'][$k], $page['=passwd'][$k], $page['=pwsource'][$k]) =
2267
2021-12-17
jrmu
IsAuthorized(@$page["passwd$k"], 'page', $acache[$gn][$k]);
2268
2021-12-17
jrmu
foreach($AuthCascade as $k => $t) {
2269
2021-12-17
jrmu
if ($page['=auth'][$k]+0 == 2) {
2270
2021-12-17
jrmu
$page['=auth'][$k] = $page['=auth'][$t];
2271
2021-12-17
jrmu
if ($page['=passwd'][$k] = $page['=passwd'][$t]) # assign
2272
2021-12-17
jrmu
$page['=pwsource'][$k] = "cascade:$t";
2273
2021-12-17
jrmu
}
2274
2021-12-17
jrmu
}
2275
2021-12-17
jrmu
if (@$page['=auth']['admin'])
2276
2021-12-17
jrmu
foreach($page['=auth'] as $lv=>$a) @$page['=auth'][$lv] = 3;
2277
2021-12-17
jrmu
if (@$page['=passwd']['read']) $NoHTMLCache |= 2;
2278
2021-12-17
jrmu
if ($level=='ALWAYS' || @$page['=auth'][$level]) return $page;
2279
2021-12-17
jrmu
if (!$authprompt) return false;
2280
2021-12-17
jrmu
$GLOBALS['AuthNeeded'] = (@$_POST['authpw'])
2281
2021-12-17
jrmu
? $page['=pwsource'][$level] . ' ' . $level : '';
2282
2021-12-17
jrmu
PCache($pagename, $page);
2283
2021-12-17
jrmu
$postvars = '';
2284
2021-12-17
jrmu
foreach($_POST as $k=>$v) {
2285
2021-12-17
jrmu
if ($k == 'authpw' || $k == 'authid') continue;
2286
2021-12-17
jrmu
$k = PHSC(stripmagic($k), ENT_QUOTES);
2287
2021-12-17
jrmu
if (is_array($v)) {
2288
2021-12-17
jrmu
foreach($v as $vk=>$vv) {
2289
2021-12-17
jrmu
$vk = PHSC(stripmagic($vk), ENT_QUOTES);
2290
2021-12-17
jrmu
$vv = str_replace('$', '&#036;',
2291
2021-12-17
jrmu
PHSC(stripmagic($vv), ENT_COMPAT));
2292
2021-12-17
jrmu
$postvars .= "<input type='hidden' name='{$k}[{$vk}]' value=\"$vv\" />\n";
2293
2021-12-17
jrmu
}
2294
2021-12-17
jrmu
}
2295
2021-12-17
jrmu
else {
2296
2021-12-17
jrmu
$v = str_replace('$', '&#036;',
2297
2021-12-17
jrmu
PHSC(stripmagic($v), ENT_COMPAT));
2298
2021-12-17
jrmu
$postvars .= "<input type='hidden' name='$k' value=\"$v\" />\n";
2299
2021-12-17
jrmu
}
2300
2021-12-17
jrmu
}
2301
2021-12-17
jrmu
$FmtV['$PostVars'] = $postvars;
2302
2021-12-17
jrmu
$r = str_replace("'", '%37', stripmagic($_SERVER['REQUEST_URI']));
2303
2021-12-17
jrmu
SDV($AuthPromptFmt,array(&$PageStartFmt,
2304
2021-12-17
jrmu
"<p><b>$[Password required]</b></p>
2305
2021-12-17
jrmu
<form name='authform' action='$r' method='post'>
2306
2021-12-17
jrmu
$[Password]: <input tabindex='1' type='password' name='authpw'
2307
2021-12-17
jrmu
value='' />
2308
2021-12-17
jrmu
<input type='submit' value='$[OK]' />\$PostVars</form>
2309
2021-12-17
jrmu
<script language='javascript' type='text/javascript'><!--
2310
2021-12-17
jrmu
document.authform.authpw.focus() //--></script>", &$PageEndFmt));
2311
2021-12-17
jrmu
PrintFmt($pagename,$AuthPromptFmt);
2312
2021-12-17
jrmu
exit;
2313
2021-12-17
jrmu
}
2314
2021-12-17
jrmu
2315
2021-12-17
jrmu
function IsAuthorized($chal, $source, &$from) {
2316
2021-12-17
jrmu
global $AuthList, $AuthPw, $AllowPassword;
2317
2021-12-17
jrmu
if (!$chal) return $from;
2318
2021-12-17
jrmu
$auth = 0;
2319
2021-12-17
jrmu
$passwd = array();
2320
2021-12-17
jrmu
foreach((array)$chal as $c) {
2321
2021-12-17
jrmu
$x = '';
2322
2021-12-17
jrmu
$pwchal = preg_split('/([, ]|\\w+:)/', $c, -1, PREG_SPLIT_DELIM_CAPTURE);
2323
2021-12-17
jrmu
foreach($pwchal as $pw) {
2324
2021-12-17
jrmu
if ($pw == ',' || $pw == '') continue;
2325
2021-12-17
jrmu
else if ($pw == ' ') { $x = ''; continue; }
2326
2021-12-17
jrmu
else if (substr($pw, -1, 1) == ':') { $x = $pw; continue; }
2327
2021-12-17
jrmu
else if ($pw[0] != '@' && $x > '') $pw = $x . $pw;
2328
2021-12-17
jrmu
if (!$pw) continue;
2329
2021-12-17
jrmu
$passwd[] = $pw;
2330
2021-12-17
jrmu
if ($auth < 0) continue;
2331
2021-12-17
jrmu
if ($x || $pw[0] == '@') {
2332
2021-12-17
jrmu
if (@$AuthList[$pw]) $auth = $AuthList[$pw];
2333
2021-12-17
jrmu
continue;
2334
2021-12-17
jrmu
}
2335
2021-12-17
jrmu
if ($AllowPassword && pmcrypt($AllowPassword, $pw) == $pw) # nopass
2336
2021-12-17
jrmu
{ $auth=1; continue; }
2337
2021-12-17
jrmu
foreach((array)$AuthPw as $pwresp) # password
2338
2021-12-17
jrmu
if (pmcrypt($pwresp, $pw) == $pw) { $auth=1; continue; }
2339
2021-12-17
jrmu
}
2340
2021-12-17
jrmu
}
2341
2021-12-17
jrmu
if (!$passwd) return $from;
2342
2021-12-17
jrmu
if ($auth < 0) $auth = 0;
2343
2021-12-17
jrmu
return array($auth, $passwd, $source);
2344
2021-12-17
jrmu
}
2345
2021-12-17
jrmu
2346
2021-12-17
jrmu
2347
2021-12-17
jrmu
## SessionAuth works with PmWikiAuth to manage authorizations
2348
2021-12-17
jrmu
## as stored in sessions. First, it can be used to set session
2349
2021-12-17
jrmu
## variables by calling it with an $auth argument. It then
2350
2021-12-17
jrmu
## uses the authid, authpw, and authlist session variables
2351
2021-12-17
jrmu
## to set the corresponding values of $AuthId, $AuthPw, and $AuthList
2352
2021-12-17
jrmu
## as needed.
2353
2021-12-17
jrmu
function SessionAuth($pagename, $auth = NULL) {
2354
2021-12-17
jrmu
global $AuthId, $AuthList, $AuthPw, $SessionEncode, $SessionDecode,
2355
2021-12-17
jrmu
$EnableSessionPasswords;
2356
2021-12-17
jrmu
static $called;
2357
2021-12-17
jrmu
2358
2021-12-17
jrmu
@$called++;
2359
2021-12-17
jrmu
$sn = session_name(); # in PHP5.3, $_REQUEST doesn't contain $_COOKIE
2360
2021-12-17
jrmu
if (!$auth && ($called > 1 || (!@$_REQUEST[$sn] && !@$_COOKIE[$sn]))) return;
2361
2021-12-17
jrmu
2362
2021-12-17
jrmu
$sid = session_id();
2363
2021-12-17
jrmu
@session_start();
2364
2021-12-17
jrmu
foreach((array)$auth as $k => $v) {
2365
2021-12-17
jrmu
if ($k == 'authpw') {
2366
2021-12-17
jrmu
foreach((array)$v as $pw => $pv) {
2367
2021-12-17
jrmu
if ($SessionEncode) $pw = $SessionEncode($pw);
2368
2021-12-17
jrmu
$_SESSION[$k][$pw] = $pv;
2369
2021-12-17
jrmu
}
2370
2021-12-17
jrmu
}
2371
2021-12-17
jrmu
else if ($k) $_SESSION[$k] = (array)$v + (array)@$_SESSION[$k];
2372
2021-12-17
jrmu
}
2373
2021-12-17
jrmu
2374
2021-12-17
jrmu
if (!isset($AuthId)) $AuthId = @end($_SESSION['authid']);
2375
2021-12-17
jrmu
$AuthPw = array_map($SessionDecode, array_keys((array)@$_SESSION['authpw']));
2376
2021-12-17
jrmu
if (!IsEnabled($EnableSessionPasswords, 1)) $_SESSION['authpw'] = array();
2377
2021-12-17
jrmu
$AuthList = array_merge($AuthList, (array)@$_SESSION['authlist']);
2378
2021-12-17
jrmu
2379
2021-12-17
jrmu
if (!$sid) @session_write_close();
2380
2021-12-17
jrmu
}
2381
2021-12-17
jrmu
2382
2021-12-17
jrmu
2383
2021-12-17
jrmu
function PasswdVar($pagename, $level) {
2384
2021-12-17
jrmu
global $PCache, $PasswdVarAuth, $FmtV;
2385
2021-12-17
jrmu
$page = $PCache[$pagename];
2386
2021-12-17
jrmu
if (!isset($page['=passwd'][$level])) {
2387
2021-12-17
jrmu
$page = RetrieveAuthPage($pagename, 'ALWAYS', false, READPAGE_CURRENT);
2388
2021-12-17
jrmu
if ($page) PCache($pagename, $page);
2389
2021-12-17
jrmu
}
2390
2021-12-17
jrmu
SDV($PasswdVarAuth, 'attr');
2391
2021-12-17
jrmu
if ($PasswdVarAuth && !@$page['=auth'][$PasswdVarAuth]) return XL('(protected)');
2392
2021-12-17
jrmu
$pwsource = $page['=pwsource'][$level];
2393
2021-12-17
jrmu
if (strncmp($pwsource, 'cascade:', 8) == 0) {
2394
2021-12-17
jrmu
$FmtV['$PWCascade'] = substr($pwsource, 8);
2395
2021-12-17
jrmu
return FmtPageName('$[(using $PWCascade password)]', $pagename);
2396
2021-12-17
jrmu
}
2397
2021-12-17
jrmu
$setting = PHSC(implode(' ', preg_replace('/^(?!@|\\w+:).+$/', '****',
2398
2021-12-17
jrmu
(array)$page['=passwd'][$level])));
2399
2021-12-17
jrmu
if ($pwsource == 'group' || $pwsource == 'site') {
2400
2021-12-17
jrmu
$FmtV['$PWSource'] = $pwsource;
2401
2021-12-17
jrmu
$setting = FmtPageName('$[(set by $PWSource)] ', $pagename)
2402
2021-12-17
jrmu
. PHSC($setting);
2403
2021-12-17
jrmu
}
2404
2021-12-17
jrmu
return $setting;
2405
2021-12-17
jrmu
}
2406
2021-12-17
jrmu
2407
2021-12-17
jrmu
2408
2021-12-17
jrmu
function PrintAttrForm($pagename) {
2409
2021-12-17
jrmu
global $PageAttributes, $PCache, $FmtV;
2410
2021-12-17
jrmu
echo FmtPageName("<form action='\$PageUrl' method='post'>
2411
2021-12-17
jrmu
<input type='hidden' name='action' value='postattr' />
2412
2021-12-17
jrmu
<input type='hidden' name='n' value='\$FullName' />
2413
2021-12-17
jrmu
<table>",$pagename);
2414
2021-12-17
jrmu
$page = $PCache[$pagename];
2415
2021-12-17
jrmu
foreach($PageAttributes as $attr=>$p) {
2416
2021-12-17
jrmu
if (!$p) continue;
2417
2021-12-17
jrmu
if (strncmp($attr, 'passwd', 6) == 0) {
2418
2021-12-17
jrmu
$setting = PageVar($pagename, '$Passwd'.ucfirst(substr($attr, 6)));
2419
2021-12-17
jrmu
$value = '';
2420
2021-12-17
jrmu
} else { $setting = $value = PHSC(@$page[$attr]); }
2421
2021-12-17
jrmu
$prompt = FmtPageName($p,$pagename);
2422
2021-12-17
jrmu
echo "<tr><td>$prompt</td>
2423
2021-12-17
jrmu
<td><input type='text' name='$attr' value='$value' /></td>
2424
2021-12-17
jrmu
<td>$setting</td></tr>";
2425
2021-12-17
jrmu
}
2426
2021-12-17
jrmu
echo FmtPageName("</table><input type='submit' value='$[Save]' /></form>",
2427
2021-12-17
jrmu
$pagename);
2428
2021-12-17
jrmu
}
2429
2021-12-17
jrmu
2430
2021-12-17
jrmu
function HandleAttr($pagename, $auth = 'attr') {
2431
2021-12-17
jrmu
global $HandleAttrFmt,$PageAttrFmt,$PageStartFmt,$PageEndFmt;
2432
2021-12-17
jrmu
$page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
2433
2021-12-17
jrmu
if (!$page) { Abort("?unable to read $pagename"); }
2434
2021-12-17
jrmu
PCache($pagename,$page);
2435
2021-12-17
jrmu
XLSDV('en', array('EnterAttributes' =>
2436
2021-12-17
jrmu
"Enter new attributes for this page below. Leaving a field blank
2437
2021-12-17
jrmu
will leave the attribute unchanged. To clear an attribute, enter
2438
2021-12-17
jrmu
'clear'."));
2439
2021-12-17
jrmu
SDV($PageAttrFmt,"<div class='wikiattr'>
2440
2021-12-17
jrmu
<h2 class='wikiaction'>$[{\$FullName} Attributes]</h2>
2441
2021-12-17
jrmu
<p>$[EnterAttributes]</p></div>");
2442
2021-12-17
jrmu
SDV($HandleAttrFmt,array(&$PageStartFmt,&$PageAttrFmt,
2443
2021-12-17
jrmu
'function:PrintAttrForm',&$PageEndFmt));
2444
2021-12-17
jrmu
PrintFmt($pagename,$HandleAttrFmt);
2445
2021-12-17
jrmu
}
2446
2021-12-17
jrmu
2447
2021-12-17
jrmu
function HandlePostAttr($pagename, $auth = 'attr') {
2448
2021-12-17
jrmu
global $PageAttributes, $EnablePostAttrClearSession;
2449
2021-12-17
jrmu
Lock(2);
2450
2021-12-17
jrmu
$page = RetrieveAuthPage($pagename, $auth, true);
2451
2021-12-17
jrmu
if (!$page) { Abort("?unable to read $pagename"); }
2452
2021-12-17
jrmu
foreach($PageAttributes as $attr=>$p) {
2453
2021-12-17
jrmu
$v = stripmagic(@$_POST[$attr]);
2454
2021-12-17
jrmu
if ($v == '') continue;
2455
2021-12-17
jrmu
if ($v=='clear') unset($page[$attr]);
2456
2021-12-17
jrmu
else if (strncmp($attr, 'passwd', 6) != 0) $page[$attr] = $v;
2457
2021-12-17
jrmu
else {
2458
2021-12-17
jrmu
$a = array();
2459
2021-12-17
jrmu
preg_match_all('/"[^"]*"|\'[^\']*\'|\\S+/', $v, $match);
2460
2021-12-17
jrmu
foreach($match[0] as $pw)
2461
2021-12-17
jrmu
$a[] = preg_match('/^(@|\\w+:)/', $pw) ? $pw
2462
2021-12-17
jrmu
: pmcrypt(preg_replace('/^([\'"])(.*)\\1$/', '$2', $pw));
2463
2021-12-17
jrmu
if ($a) $page[$attr] = implode(' ',$a);
2464
2021-12-17
jrmu
}
2465
2021-12-17
jrmu
}
2466
2021-12-17
jrmu
WritePage($pagename,$page);
2467
2021-12-17
jrmu
Lock(0);
2468
2021-12-17
jrmu
if (IsEnabled($EnablePostAttrClearSession, 1)) {
2469
2021-12-17
jrmu
@session_start();
2470
2021-12-17
jrmu
unset($_SESSION['authid']);
2471
2021-12-17
jrmu
unset($_SESSION['authlist']);
2472
2021-12-17
jrmu
$_SESSION['authpw'] = array();
2473
2021-12-17
jrmu
}
2474
2021-12-17
jrmu
Redirect($pagename);
2475
2021-12-17
jrmu
exit;
2476
2021-12-17
jrmu
}
2477
2021-12-17
jrmu
2478
2021-12-17
jrmu
2479
2021-12-17
jrmu
function HandleLogoutA($pagename, $auth = 'read') {
2480
2021-12-17
jrmu
global $LogoutRedirectFmt, $LogoutCookies;
2481
2021-12-17
jrmu
SDV($LogoutRedirectFmt, '$FullName');
2482
2021-12-17
jrmu
SDV($LogoutCookies, array());
2483
2021-12-17
jrmu
@session_start();
2484
2021-12-17
jrmu
$_SESSION = array();
2485
2021-12-17
jrmu
if ( session_id() != '' || isset($_COOKIE[session_name()]) )
2486
2021-12-17
jrmu
pmsetcookie(session_name(), '', time()-43200, '/');
2487
2021-12-17
jrmu
foreach ($LogoutCookies as $c)
2488
2021-12-17
jrmu
if (isset($_COOKIE[$c])) pmsetcookie($c, '', time()-43200, '/');
2489
2021-12-17
jrmu
session_destroy();
2490
2021-12-17
jrmu
Redirect(FmtPageName($LogoutRedirectFmt, $pagename));
2491
2021-12-17
jrmu
}
2492
2021-12-17
jrmu
2493
2021-12-17
jrmu
2494
2021-12-17
jrmu
function HandleLoginA($pagename, $auth = 'login') {
2495
2021-12-17
jrmu
global $AuthId, $DefaultPasswords;
2496
2021-12-17
jrmu
unset($DefaultPasswords['admin']);
2497
2021-12-17
jrmu
$prompt = @(!$_POST['authpw'] || ($AuthId != $_POST['authid']));
2498
2021-12-17
jrmu
$page = RetrieveAuthPage($pagename, $auth, $prompt, READPAGE_CURRENT);
2499
2021-12-17
jrmu
Redirect($pagename);
2500
2021-12-17
jrmu
}
2501
2021-12-17
jrmu
IRCNow