Blame
Date:
Fri Dec 16 05:00:21 2022 UTC
Message:
Daily backup
001
2021-12-17
jrmu
<?php if (!defined('PmWiki')) exit();
002
2021-12-17
jrmu
/* Copyright 2004-2020 Patrick R. Michaud (pmichaud@pobox.com)
003
2021-12-17
jrmu
This file is part of PmWiki; you can redistribute it and/or modify
004
2021-12-17
jrmu
it under the terms of the GNU General Public License as published
005
2021-12-17
jrmu
by the Free Software Foundation; either version 2 of the License, or
006
2021-12-17
jrmu
(at your option) any later version. See pmwiki.php for full details.
007
2021-12-17
jrmu
008
2021-12-17
jrmu
This file implements the skin selection code for PmWiki. Skin
009
2021-12-17
jrmu
selection is controlled by the $Skin variable, which can also
010
2021-12-17
jrmu
be an array (in which case the first skin found is loaded).
011
2021-12-17
jrmu
012
2021-12-17
jrmu
In addition, $ActionSkin[$action] specifies other skins to be
013
2021-12-17
jrmu
searched based on the current action.
014
2021-12-17
jrmu
015
2021-12-17
jrmu
Script maintained by Petko YOTOV www.pmwiki.org/petko
016
2021-12-17
jrmu
*/
017
2021-12-17
jrmu
018
2021-12-17
jrmu
SDV($Skin, 'pmwiki');
019
2021-12-17
jrmu
SDV($ActionSkin['print'], 'print');
020
2021-12-17
jrmu
SDV($FarmPubDirUrl, $PubDirUrl);
021
2021-12-17
jrmu
SDV($PageLogoUrl, "$FarmPubDirUrl/skins/pmwiki/pmwiki-32.gif");
022
2021-12-17
jrmu
SDVA($TmplDisplay, array('PageEditFmt' => 0));
023
2021-12-17
jrmu
024
2021-12-17
jrmu
## from skinchange.php
025
2021-12-17
jrmu
if (IsEnabled($EnableAutoSkinList, 0) || isset($PageSkinList)) {
026
2021-12-17
jrmu
SDV($SkinCookie, $CookiePrefix.'setskin');
027
2021-12-17
jrmu
SDV($SkinCookieExpires, $Now+60*60*24*365);
028
2021-12-17
jrmu
029
2021-12-17
jrmu
if (isset($_COOKIE[$SkinCookie])) $sk = $_COOKIE[$SkinCookie];
030
2021-12-17
jrmu
if (isset($_GET['setskin'])) {
031
2021-12-17
jrmu
$sk = $_GET['setskin'];
032
2021-12-17
jrmu
pmsetcookie($SkinCookie, $sk, $SkinCookieExpires, '/');
033
2021-12-17
jrmu
if(@$EnableIMSCaching) {
034
2021-12-17
jrmu
SDV($IMSCookie, $CookiePrefix.'imstime');
035
2021-12-17
jrmu
pmsetcookie($IMSCookie, '', $Now -3600, '/');
036
2021-12-17
jrmu
$EnableIMSCaching = 0;
037
2021-12-17
jrmu
}
038
2021-12-17
jrmu
}
039
2021-12-17
jrmu
if (isset($_GET['skin'])) $sk = $_GET['skin'];
040
2021-12-17
jrmu
041
2021-12-17
jrmu
## If $EnableAutoSkinList is set, then we accept any skin that
042
2021-12-17
jrmu
## exists in pub/skins/ or $FarmD/pub/skins/ .
043
2021-12-17
jrmu
if (IsEnabled($EnableAutoSkinList, 0)
044
2021-12-17
jrmu
&& @$sk && preg_match('/^[-\\w]+$/', $sk)
045
2021-12-17
jrmu
&& (is_dir("pub/skins/$sk") || is_dir("$FarmD/pub/skins/$sk")))
046
2021-12-17
jrmu
$Skin = $sk;
047
2021-12-17
jrmu
048
2021-12-17
jrmu
## If there's a specific mapping in $PageSkinList, we use it no
049
2021-12-17
jrmu
## matter what.
050
2021-12-17
jrmu
if (@$PageSkinList[$sk]) $Skin = $PageSkinList[$sk];
051
2021-12-17
jrmu
}
052
2021-12-17
jrmu
053
2021-12-17
jrmu
# $PageTemplateFmt is deprecated
054
2021-12-17
jrmu
if (isset($PageTemplateFmt)) LoadPageTemplate($pagename,$PageTemplateFmt);
055
2021-12-17
jrmu
else {
056
2021-12-17
jrmu
$x = array_merge((array)@$ActionSkin[$action], (array)$Skin);
057
2021-12-17
jrmu
SetSkin($pagename, $x);
058
2021-12-17
jrmu
}
059
2021-12-17
jrmu
060
2021-12-17
jrmu
SDV($PageCSSListFmt,array(
061
2021-12-17
jrmu
'pub/css/local.css' => '$PubDirUrl/css/local.css',
062
2021-12-17
jrmu
'pub/css/{$Group}.css' => '$PubDirUrl/css/{$Group}.css',
063
2021-12-17
jrmu
'pub/css/{$FullName}.css' => '$PubDirUrl/css/{$FullName}.css'));
064
2021-12-17
jrmu
065
2021-12-17
jrmu
foreach((array)$PageCSSListFmt as $k=>$v)
066
2021-12-17
jrmu
if (file_exists(FmtPageName($k,$pagename)))
067
2021-12-17
jrmu
$HTMLHeaderFmt[] = "<link rel='stylesheet' type='text/css' href='$v' />\n";
068
2021-12-17
jrmu
069
2021-12-17
jrmu
if(IsEnabled($WikiPageCSSFmt, false))
070
2021-12-17
jrmu
InsertWikiPageCSS($pagename, $WikiPageCSSFmt);
071
2021-12-17
jrmu
072
2021-12-17
jrmu
# SetSkin changes the current skin to the first available skin from
073
2021-12-17
jrmu
# the $skin array.
074
2021-12-17
jrmu
function SetSkin($pagename, $skin) {
075
2021-12-17
jrmu
global $Skin, $SkinLibDirs, $SkinDir, $SkinDirUrl,
076
2021-12-17
jrmu
$IsTemplateLoaded, $PubDirUrl, $FarmPubDirUrl, $FarmD, $GCount;
077
2021-12-17
jrmu
SDV($SkinLibDirs, array(
078
2021-12-17
jrmu
"./pub/skins/\$Skin" => "$PubDirUrl/skins/\$Skin",
079
2021-12-17
jrmu
"$FarmD/pub/skins/\$Skin" => "$FarmPubDirUrl/skins/\$Skin"));
080
2021-12-17
jrmu
foreach((array)$skin as $sfmt) {
081
2021-12-17
jrmu
$Skin = FmtPageName($sfmt, $pagename); $GCount = 0;
082
2021-12-17
jrmu
foreach($SkinLibDirs as $dirfmt => $urlfmt) {
083
2021-12-17
jrmu
$SkinDir = FmtPageName($dirfmt, $pagename);
084
2021-12-17
jrmu
if (is_dir($SkinDir))
085
2021-12-17
jrmu
{ $SkinDirUrl = FmtPageName($urlfmt, $pagename); break 2; }
086
2021-12-17
jrmu
}
087
2021-12-17
jrmu
}
088
2021-12-17
jrmu
if (!is_dir($SkinDir)) {
089
2021-12-17
jrmu
unset($Skin);
090
2021-12-17
jrmu
Abort("?unable to find skin from list ".implode(' ',(array)$skin));
091
2021-12-17
jrmu
}
092
2021-12-17
jrmu
$IsTemplateLoaded = 0;
093
2021-12-17
jrmu
if (file_exists("$SkinDir/$Skin.php"))
094
2021-12-17
jrmu
include_once("$SkinDir/$Skin.php");
095
2021-12-17
jrmu
else if (file_exists("$SkinDir/skin.php"))
096
2021-12-17
jrmu
include_once("$SkinDir/skin.php");
097
2021-12-17
jrmu
if ($IsTemplateLoaded) return;
098
2021-12-17
jrmu
if (file_exists("$SkinDir/$Skin.tmpl"))
099
2021-12-17
jrmu
LoadPageTemplate($pagename, "$SkinDir/$Skin.tmpl");
100
2021-12-17
jrmu
else if (file_exists("$SkinDir/skin.tmpl"))
101
2021-12-17
jrmu
LoadPageTemplate($pagename, "$SkinDir/skin.tmpl");
102
2021-12-17
jrmu
else if (($dh = opendir($SkinDir))) {
103
2021-12-17
jrmu
while (($fname = readdir($dh)) !== false) {
104
2021-12-17
jrmu
if ($fname[0] == '.') continue;
105
2021-12-17
jrmu
if (substr($fname, -5) != '.tmpl') continue;
106
2021-12-17
jrmu
if ($IsTemplateLoaded)
107
2021-12-17
jrmu
Abort("?unable to find unique template in $SkinDir");
108
2021-12-17
jrmu
LoadPageTemplate($pagename, "$SkinDir/$fname");
109
2021-12-17
jrmu
}
110
2021-12-17
jrmu
closedir($dh);
111
2021-12-17
jrmu
}
112
2021-12-17
jrmu
if (!$IsTemplateLoaded) Abort("Unable to load $Skin template", 'skin');
113
2021-12-17
jrmu
}
114
2021-12-17
jrmu
115
2021-12-17
jrmu
function cb_includeskintemplate($m) {
116
2021-12-17
jrmu
global $SkinDir, $pagename;
117
2021-12-17
jrmu
$x = preg_split('/\\s+/', $m[1], -1, PREG_SPLIT_NO_EMPTY);
118
2021-12-17
jrmu
for ($i=0; $i<count($x); $i++) {
119
2021-12-17
jrmu
$f = FmtPageName("$SkinDir/{$x[$i]}", $pagename);
120
2021-12-17
jrmu
if (strpos($f, '..')!==false || preg_match('/%2e/i', $f)) continue;
121
2021-12-17
jrmu
if (file_exists($f)) return implode('', file($f));
122
2021-12-17
jrmu
}
123
2021-12-17
jrmu
}
124
2021-12-17
jrmu
125
2021-12-17
jrmu
# LoadPageTemplate loads a template into $TmplFmt
126
2021-12-17
jrmu
function LoadPageTemplate($pagename,$tfilefmt) {
127
2021-12-17
jrmu
global $PageStartFmt, $PageEndFmt, $SkinTemplateIncludeLevel,
128
2021-12-17
jrmu
$EnableSkinDiag, $HTMLHeaderFmt, $HTMLFooterFmt,
129
2021-12-17
jrmu
$IsTemplateLoaded, $TmplFmt, $TmplDisplay,
130
2021-12-17
jrmu
$PageTextStartFmt, $PageTextEndFmt, $SkinDirectivesPattern;
131
2021-12-17
jrmu
132
2021-12-17
jrmu
SDV($PageTextStartFmt, "\n<div id='wikitext'>\n");
133
2021-12-17
jrmu
SDV($PageTextEndFmt, "</div>\n");
134
2021-12-17
jrmu
SDV($SkinDirectivesPattern,
135
2021-12-17
jrmu
"[[<]!--((?:wiki|file|function|markup):.*?)--[]>]");
136
2021-12-17
jrmu
137
2021-12-17
jrmu
$sddef = array('PageEditFmt' => 0);
138
2021-12-17
jrmu
$k = implode('', file(FmtPageName($tfilefmt, $pagename)));
139
2021-12-17
jrmu
140
2021-12-17
jrmu
for ($i=0; $i<IsEnabled($SkinTemplateIncludeLevel, 0) && $i<10; $i++) {
141
2021-12-17
jrmu
if (stripos($k, '<!--IncludeTemplate')===false) break;
142
2021-12-17
jrmu
$k = preg_replace_callback('/[<]!--IncludeTemplate: *(\\S.*?) *--[>]/i',
143
2021-12-17
jrmu
'cb_includeskintemplate', $k);
144
2021-12-17
jrmu
}
145
2021-12-17
jrmu
146
2021-12-17
jrmu
if (IsEnabled($EnableSkinDiag, 0)) {
147
2021-12-17
jrmu
if (!preg_match('/<!--((No)?(HT|X)MLHeader|HeaderText)-->/i', $k))
148
2021-12-17
jrmu
Abort("Skin template missing &lt;!--HTMLHeader--&gt;", 'htmlheader');
149
2021-12-17
jrmu
if (!preg_match('/<!--(No)?(HT|X)MLFooter-->/i', $k))
150
2021-12-17
jrmu
Abort("Skin template missing &lt;!--HTMLFooter--&gt;", 'htmlheader');
151
2021-12-17
jrmu
}
152
2021-12-17
jrmu
153
2021-12-17
jrmu
$sect = preg_split(
154
2021-12-17
jrmu
'#[[<]!--(/?(?:Page[A-Za-z]+Fmt|(?:HT|X)ML(?:Head|Foot)er|HeaderText|PageText).*?)--[]>]#',
155
2021-12-17
jrmu
$k, 0, PREG_SPLIT_DELIM_CAPTURE);
156
2021-12-17
jrmu
$TmplFmt['Start'] = array_merge(array('headers:'),
157
2021-12-17
jrmu
preg_split("/$SkinDirectivesPattern/s",
158
2021-12-17
jrmu
array_shift($sect),0,PREG_SPLIT_DELIM_CAPTURE));
159
2021-12-17
jrmu
$TmplFmt['End'] = array($PageTextEndFmt);
160
2021-12-17
jrmu
$ps = 'Start';
161
2021-12-17
jrmu
while (count($sect)>0) {
162
2021-12-17
jrmu
$k = array_shift($sect);
163
2021-12-17
jrmu
$v = preg_split("/$SkinDirectivesPattern/s",
164
2021-12-17
jrmu
array_shift($sect),0,PREG_SPLIT_DELIM_CAPTURE);
165
2021-12-17
jrmu
$TmplFmt[$ps][] = "<!--$k-->";
166
2021-12-17
jrmu
if ($k[0] == '/')
167
2021-12-17
jrmu
{ $TmplFmt[$ps][] = (count($v) > 1) ? $v : $v[0]; continue; }
168
2021-12-17
jrmu
@list($var, $sd) = explode(' ', $k, 2);
169
2021-12-17
jrmu
$GLOBALS[$var] = (count($v) > 1) ? $v : $v[0];
170
2021-12-17
jrmu
if ($sd > '') $sddef[$var] = $sd;
171
2021-12-17
jrmu
if ($var == 'PageText') { $ps = 'End'; }
172
2021-12-17
jrmu
if ($var == 'HTMLHeader' || $var == 'XMLHeader')
173
2021-12-17
jrmu
$TmplFmt[$ps][] = &$HTMLHeaderFmt;
174
2021-12-17
jrmu
if ($var == 'HTMLFooter' || $var == 'XMLFooter')
175
2021-12-17
jrmu
$TmplFmt[$ps][] = &$HTMLFooterFmt;
176
2021-12-17
jrmu
## <!--HeaderText--> deprecated, 2.1.16
177
2021-12-17
jrmu
if ($var == 'HeaderText') { $TmplFmt[$ps][] = &$HTMLHeaderFmt; }
178
2021-12-17
jrmu
$TmplFmt[$ps][$var] =& $GLOBALS[$var];
179
2021-12-17
jrmu
}
180
2021-12-17
jrmu
array_push($TmplFmt['Start'], $PageTextStartFmt);
181
2021-12-17
jrmu
$PageStartFmt = 'function:PrintSkin Start';
182
2021-12-17
jrmu
$PageEndFmt = 'function:PrintSkin End';
183
2021-12-17
jrmu
$IsTemplateLoaded = 1;
184
2021-12-17
jrmu
SDVA($TmplDisplay, $sddef);
185
2021-12-17
jrmu
}
186
2021-12-17
jrmu
187
2021-12-17
jrmu
# This function is called to print a portion of the skin template
188
2021-12-17
jrmu
# according to the settings in $TmplDisplay.
189
2021-12-17
jrmu
function PrintSkin($pagename, $arg) {
190
2021-12-17
jrmu
global $TmplFmt, $TmplDisplay;
191
2021-12-17
jrmu
foreach ($TmplFmt[$arg] as $k => $v)
192
2021-12-17
jrmu
if (!isset($TmplDisplay[$k]) || $TmplDisplay[$k])
193
2021-12-17
jrmu
PrintFmt($pagename, $v);
194
2021-12-17
jrmu
}
195
2021-12-17
jrmu
196
2021-12-17
jrmu
# This function parses a wiki page like Site.LocalCSS
197
2021-12-17
jrmu
# and inserts CSS rules specific to the current page.
198
2021-12-17
jrmu
# Based on Cookbook:LocalCSS by Petko Yotov
199
2021-12-17
jrmu
function InsertWikiPageCSS($pagename, $fmt) {
200
2021-12-17
jrmu
global $HTMLStylesFmt, $EnableSelfWikiPageCSS, $WikiPageCSSVars;
201
2021-12-17
jrmu
SDV($WikiPageCSSVars,array('FarmPubDirUrl','PubDirUrl','Skin','action','SkinDirUrl'));
202
2021-12-17
jrmu
203
2021-12-17
jrmu
$stylepagename = FmtPageName($fmt, $pagename);
204
2021-12-17
jrmu
if ($stylepagename == $pagename &&
205
2021-12-17
jrmu
!IsEnabled($EnableSelfWikiPageCSS, 0)) return;
206
2021-12-17
jrmu
207
2021-12-17
jrmu
if ($stylepagename == $pagename && @$_POST['text'])
208
2021-12-17
jrmu
$text = stripmagic($_POST['text']);
209
2021-12-17
jrmu
else {
210
2021-12-17
jrmu
$p = ReadPage($stylepagename, READPAGE_CURRENT);
211
2021-12-17
jrmu
$text = @$p['text'];
212
2021-12-17
jrmu
}
213
2021-12-17
jrmu
if (!$text) return;
214
2021-12-17
jrmu
215
2021-12-17
jrmu
$text = str_replace(array("\r",'$','<','&#036;='),array('','&#036;','&lt;','$='), $text);
216
2021-12-17
jrmu
$varray = array();
217
2021-12-17
jrmu
218
2021-12-17
jrmu
# global PHP variables as @variables
219
2021-12-17
jrmu
foreach($WikiPageCSSVars as $var) $varray["@$var"] = $GLOBALS[$var];
220
2021-12-17
jrmu
221
2021-12-17
jrmu
# get @variables from page
222
2021-12-17
jrmu
if (preg_match_all("/^\\s*(@\\w+):\\s*(.*?)\\s*$/m", $text, $vars) )
223
2021-12-17
jrmu
foreach($vars[1] as $k=>$varname) $varray[$varname] = trim($vars[2][$k]);
224
2021-12-17
jrmu
225
2021-12-17
jrmu
# expand nested @variables
226
2021-12-17
jrmu
for ($i=0; $i<10; $i++) $text = strtr($text, $varray);
227
2021-12-17
jrmu
228
2021-12-17
jrmu
# process snippets
229
2021-12-17
jrmu
if (preg_match_all("/\\[@\\s*([^\\/!\\s]+)\n(.*?)\\s*@\\]/s", $text, $matches, PREG_SET_ORDER) )
230
2021-12-17
jrmu
foreach($matches as $a)
231
2021-12-17
jrmu
if (count(MatchPageNames($pagename, trim($a[1]))))
232
2021-12-17
jrmu
@$HTMLStylesFmt['WikiPageCSS'] .= trim($a[2]);
233
2021-12-17
jrmu
}
234
2021-12-17
jrmu
IRCNow