Ejemplo n.º 1
0
function MakeUTF8PageName($basepage, $x)
{
    global $PagePathFmt;
    $PageNameChars = '-\\w\\x80-\\xff';
    if (!preg_match('/(?:([^.\\/]+)[.\\/])?([^.\\/]+)$/', $x, $m)) {
        return '';
    }
    $name = preg_replace("/[^{$PageNameChars}]+/", ' ', $m[2]);
    $name = preg_replace('/(?<=^| )(.)/eu', "mb_strtoupper('\$1','UTF-8')", $name);
    $name = str_replace(' ', '', $name);
    if ($m[1]) {
        $group = preg_replace("/[^{$PageNameChars}]+/", ' ', $m[1]);
        $group = preg_replace('/(?<=^| )(.)/eu', "mb_strtoupper('\$1','UTF-8')", $group);
        $group = str_replace(' ', '', $group);
        return "{$group}.{$name}";
    }
    foreach ((array) $PagePathFmt as $pg) {
        $pn = FmtPageName(str_replace('$1', $name, $pg), $basepage);
        if (PageExists($pn)) {
            return $pn;
        }
    }
    $group = preg_replace('/[\\/.].*$/', '', $basepage);
    return "{$group}.{$name}";
}
Ejemplo n.º 2
0
function MergeSimulEdits($pagename,&$page,&$new) {
  global $Now, $EnablePost, $MessagesFmt, $WorkDir;
  if (@!$_POST['basetime'] || !PageExists($pagename) 
      || $page['time'] >= $Now
      || $_POST['basetime']>=$page['time']
      || $page['text'] == $new['text']) return;
  $EnablePost = 0;
  $old = array();
  RestorePage($pagename,$page,$old,"diff:{$_POST['basetime']}");
  $text = Merge($new['text'],$old['text'],$page['text']);
  if ($text > '') { $new['text'] = $text; $ec = '$[EditConflict]'; }
  else $ec = '$[EditWarning]';
  XLSDV('en', array(
    'EditConflict' => "The page you are
      editing has been modified since you started editing it.
      The modifications have been merged into the text below, 
      you may want to verify the results of the merge before
      pressing save.  Conflicts the system couldn't resolve are
      bracketed by &lt;&lt;&lt;&lt;&lt;&lt;&lt; and
      &gt;&gt;&gt;&gt;&gt;&gt;&gt;.",
    'EditWarning' => "The page you are editing has been modified
      since you started editing it.  If you continue, your
      changes will overwrite any changes that others have made."));
  $MessagesFmt[] = "<p class='editconflict'>$ec
    (<a target='_blank' href='\$PageUrl?action=diff'>$[View changes]</a>)
    </p>\n";
}
Ejemplo n.º 3
0
function EditDraft(&$pagename, &$page, &$new)
{
    global $WikiDir, $DraftSuffix, $DeleteKeyPattern, $EnableDraftAtomicDiff, $DraftRecentChangesFmt, $RecentChangesFmt, $Now;
    SDV($DeleteKeyPattern, "^\\s*delete\\s*\$");
    $basename = preg_replace("/{$DraftSuffix}\$/", '', $pagename);
    $draftname = $basename . $DraftSuffix;
    if ($_POST['postdraft'] || $_POST['postedit']) {
        $pagename = $draftname;
    } else {
        if ($_POST['post'] && !preg_match("/{$DeleteKeyPattern}/", $new['text'])) {
            $pagename = $basename;
            if (IsEnabled($EnableDraftAtomicDiff, 0)) {
                $page = ReadPage($basename);
                foreach ($new as $k => $v) {
                    # delete draft history
                    if (preg_match('/:\\d+(:\\d+:)?$/', $k) && !preg_match("/:{$Now}(:\\d+:)?\$/", $k)) {
                        unset($new[$k]);
                    }
                }
                unset($new['rev']);
                SDVA($new, $page);
            }
            $WikiDir->delete($draftname);
        } else {
            if (PageExists($draftname) && $pagename != $draftname) {
                Redirect($draftname, '$PageUrl?action=edit');
                exit;
            }
        }
    }
    if ($pagename == $draftname && isset($DraftRecentChangesFmt)) {
        $RecentChangesFmt = $DraftRecentChangesFmt;
    }
}
Ejemplo n.º 4
0
function RetrievePageMarkup($pagelist)
{
    foreach ($pagelist as $p) {
        if (PageExists($p)) {
            $page = RetrieveAuthPage($p, 'read', false, READPAGE_CURRENT);
            return array($page['text'], $page['title']);
            break;
        }
    }
    return null;
}
Ejemplo n.º 5
0
function MergeSimulEdits($pagename, &$page, &$new)
{
    global $MessagesFmt, $WorkDir, $SysMergeCmd;
    SDV($SysMergeCmd, "/usr/bin/diff3 -L '' -L '' -L '' -m -E");
    if (@(!$_POST['basetime']) || !PageExists($pagename) || $_POST['basetime'] >= $page['time']) {
        return;
    }
    unset($_POST['post']);
    $MessagesFmt[] = "<p class='editconflict'>The page you are \n    editing has been modified since you started editing it.  \n    The modifications have been merged into the text below,\n    you may want to verify the results of the merge before\n    pressing save.  Conflicts the system couldn't resolve are\n    bracketed by &lt;&lt;&lt;&lt;&lt;&lt;&lt; and \n    &gt;&gt;&gt;&gt;&gt;&gt;&gt;.  (<a target='_blank' \n    href='\$PageUrl?action=diff'>View changes</a>)</p>\n";
    $old = array();
    RestorePage($pagename, $page, $old, "diff:{$_POST['basetime']}");
    $new['text'] = Merge($new['text'], $old['text'], $page['text']);
}
Ejemplo n.º 6
0
function EditDraft(&$pagename, &$page, &$new) {
  global $WikiDir, $DraftSuffix, $DeleteKeyPattern, 
    $DraftRecentChangesFmt, $RecentChangesFmt;
  SDV($DeleteKeyPattern, "^\\s*delete\\s*$");
  $basename = preg_replace("/$DraftSuffix\$/", '', $pagename);
  $draftname = $basename . $DraftSuffix;
  if ($_POST['postdraft'] || $_POST['postedit']) $pagename = $draftname; 
  else if ($_POST['post'] && !preg_match("/$DeleteKeyPattern/", $new['text'])) { 
    $pagename = $basename; 
    # $page = ReadPage($basename); # breaks restores, PITS:01007, Test:DraftRestore
    $WikiDir->delete($draftname);
  }
  else if (PageExists($draftname) && $pagename != $draftname)
    { Redirect($draftname, '$PageUrl?action=edit'); exit(); }
  if ($pagename == $draftname && isset($DraftRecentChangesFmt))
    $RecentChangesFmt = $DraftRecentChangesFmt;
}
Ejemplo n.º 7
0
function EditDraft(&$pagename, &$page, &$new)
{
    global $WikiDir, $DraftSuffix, $DeleteKeyPattern;
    SDV($DeleteKeyPattern, "^\\s*delete\\s*\$");
    $basename = preg_replace("/{$DraftSuffix}\$/", '', $pagename);
    $draftname = $basename . $DraftSuffix;
    if ($_POST['postdraft']) {
        $pagename = $draftname;
        return;
    }
    if ($_POST['post'] && !preg_match("/{$DeleteKeyPattern}/", $new['text'])) {
        $pagename = $basename;
        $page = ReadPage($basename);
        $WikiDir->delete($draftname);
        return;
    }
    if (PageExists($draftname) && $pagename != $draftname) {
        Redirect($draftname, '$PageUrl?action=edit');
        exit;
    }
}
Ejemplo n.º 8
0
function WikiGallerySlideshow($pagename, $auth = 'read')
{
    global $WikiGallery_DefaultSlideshowDelay, $HTMLHeaderFmt, $WikiGallery_Register;
    // get delay from url
    if (isset($_GET["delay"])) {
        $delay = intval($_GET["delay"]);
    } else {
        $delay = $WikiGallery_DefaultSlideshowDelay;
    }
    // find following picture
    $group = PageVar($pagename, '$Group');
    $next = $WikiGallery_Register[$group]->neighbourPicturePage(PageVar($pagename, '$Name'), 1);
    $nextpage = "{$group}.{$next}";
    // exists?
    if ($next && PageExists($nextpage)) {
        // add refresh header
        $url = MakeLink($nextpage, $nextpage, NULL, NULL, "\$LinkUrl");
        array_unshift($HTMLHeaderFmt, "<meta http-equiv=\"refresh\" content=\"{$delay}; URL={$url}?action=slideshow&delay={$delay}\" />");
    }
    return HandleBrowse($pagename, $auth);
}
Ejemplo n.º 9
0
function EditDraft(&$pagename, &$page, &$new)
{
    global $WikiDir, $DraftSuffix, $DeleteKeyPattern, $DraftRecentChangesFmt, $RecentChangesFmt;
    SDV($DeleteKeyPattern, "^\\s*delete\\s*\$");
    $basename = preg_replace("/{$DraftSuffix}\$/", '', $pagename);
    $draftname = $basename . $DraftSuffix;
    if ($_POST['postdraft'] || $_POST['postedit']) {
        $pagename = $draftname;
    } else {
        if ($_POST['post'] && !preg_match("/{$DeleteKeyPattern}/", $new['text'])) {
            $pagename = $basename;
            $page = ReadPage($basename);
            $WikiDir->delete($draftname);
        } else {
            if (PageExists($draftname) && $pagename != $draftname) {
                Redirect($draftname, '$PageUrl?action=edit');
                exit;
            }
        }
    }
    if ($pagename == $draftname && isset($DraftRecentChangesFmt)) {
        $RecentChangesFmt = $DraftRecentChangesFmt;
    }
}
Ejemplo n.º 10
0
function PrintRefCount($pagename)
{
    global $GroupPattern, $NamePattern, $PageRefCountFmt, $RefCountTimeFmt;
    $pagelist = ListPages();
    $grouplist = array();
    foreach ($pagelist as $pname) {
        if (!preg_match("/^({$GroupPattern})[\\/.]({$NamePattern})\$/", $pname, $m)) {
            continue;
        }
        $grouplist[$m[1]] = $m[1];
    }
    asort($grouplist);
    $grouplist = array_merge(array('all' => 'all groups'), $grouplist);
    $wlist = array('all', 'missing', 'existing', 'orphaned');
    $tlist = isset($_REQUEST['tlist']) ? $_REQUEST['tlist'] : array('all');
    $flist = isset($_REQUEST['flist']) ? $_REQUEST['flist'] : array('all');
    $whichrefs = @$_REQUEST['whichrefs'];
    $showrefs = @$_REQUEST['showrefs'];
    $submit = @$_REQUEST['submit'];
    echo FmtPageName($PageRefCountFmt, $pagename);
    echo "<form method='post'><input type='hidden' action='refcount'>\n    <table cellspacing='10'><tr><td valign='top'>Show\n    <br><select name='whichrefs'>";
    foreach ($wlist as $w) {
        echo "<option ", $whichrefs == $w ? 'selected' : '', " value='{$w}'>{$w}\n";
    }
    echo "</select></td><td valign='top'> page names in group<br>\n    <select name='tlist[]' multiple size='4'>";
    foreach ($grouplist as $g => $t) {
        echo "<option ", in_array($g, $tlist) ? 'selected' : '', " value='{$g}'>{$t}\n";
    }
    echo "</select></td><td valign='top'> referenced from pages in<br>\n    <select name='flist[]' multiple size='4'>";
    foreach ($grouplist as $g => $t) {
        echo "<option ", in_array($g, $flist) ? 'selected' : '', " value='{$g}'>{$t}\n";
    }
    echo "</select></td></tr></table>\n    <p><input type='checkbox' name='showrefs' value='checked' {$showrefs}>\n      Display referencing pages\n    <p><input type='submit' name='submit' value='Search'></form><p><hr>";
    if ($submit) {
        foreach ($pagelist as $pname) {
            $ref = array();
            $page = ReadPage($pname, READPAGE_CURRENT);
            if (!$page) {
                continue;
            }
            $tref[$pname]['time'] = $page['time'];
            if (!in_array('all', $flist) && !in_array(FmtPageName('$Group', $pname), $flist)) {
                continue;
            }
            $rc = preg_match('/RecentChanges$/', $pname);
            foreach (explode(',', @$page['targets']) as $r) {
                if ($r == '') {
                    continue;
                }
                if ($rc) {
                    @$tref[$r]['rc']++;
                } else {
                    @$tref[$r]['page']++;
                    @$pref[$r][$pname]++;
                }
            }
        }
        uasort($tref, 'RefCountCmp');
        echo "<table >\n      <tr><th></th><th colspan='2'>Referring pages</th></tr>\n      <tr><th>Name / Time</th><th>All</th><th>R.C.</th></tr>";
        reset($tref);
        foreach ($tref as $p => $c) {
            if (!in_array('all', $tlist) && !in_array(FmtPageName('$Group', $p), $tlist)) {
                continue;
            }
            if ($whichrefs == 'missing' && PageExists($p)) {
                continue;
            } elseif ($whichrefs == 'existing' && !PageExists($p)) {
                continue;
            } elseif ($whichrefs == 'orphaned' && (@$tref[$p]['page'] > 0 || !PageExists($p))) {
                continue;
            }
            echo "<tr><td valign='top'>", LinkPage($pagename, '', $p, '', $p);
            if (@$tref[$p]['time']) {
                echo strftime($RefCountTimeFmt, $tref[$p]['time']);
            }
            if ($showrefs && is_array(@$pref[$p])) {
                foreach ($pref[$p] as $pr => $pc) {
                    echo "<dd>", LinkPage($pagename, '', $pr, '', $pr);
                }
            }
            echo "</td>";
            echo "<td align='center' valign='top'>", @$tref[$p]['page'] + 0, "</td>";
            echo "<td align='center' valign='top'>", @$tref[$p]['rc'] + 0, "</td>";
            echo "</tr>";
        }
        echo "</table>";
    }
}
Ejemplo n.º 11
0
function bi_IsPage($pn)
{
    global $bi_Pagename;
    $mp = MakePageName($bi_Pagename, $pn);
    if (empty($mp)) {
        return true;
    }
    if ($mp == $bi_Pagename) {
        return false;
    }
    return PageExists($mp);
}
Ejemplo n.º 12
0
function FPLTemplate($pagename, &$matches, $opt)
{
    global $Cursor, $FPLFormatOpt, $FPLTemplatePageFmt;
    SDV($FPLTemplatePageFmt, array('{$FullName}', '{$SiteGroup}.LocalTemplates', '{$SiteGroup}.PageListTemplates'));
    $template = @$opt['template'];
    if (!$template) {
        $template = @$opt['fmt'];
    }
    list($tname, $qf) = explode('#', $template, 2);
    if ($tname) {
        $tname = array(MakePageName($pagename, $tname));
    } else {
        $tname = (array) $FPLTemplatePageFmt;
    }
    foreach ($tname as $t) {
        $t = FmtPageName($t, $pagename);
        if (!PageExists($t)) {
            continue;
        }
        if ($qf) {
            $t .= "#{$qf}";
        }
        $ttext = IncludeText($pagename, $t, true);
        if (!$qf || strpos($ttext, "[[#{$qf}]]") !== false) {
            break;
        }
    }
    ##   remove any anchor markups to avoid duplications
    $ttext = preg_replace('/\\[\\[#[A-Za-z][-.:\\w]*\\]\\]/', '', $ttext);
    if (!@$opt['order'] && !@$opt['trail']) {
        $opt['order'] = 'name';
    }
    $matches = array_values(MakePageList($pagename, $opt, 0));
    if (@$opt['count']) {
        array_splice($matches, $opt['count']);
    }
    $savecursor = $Cursor;
    $pagecount = 0;
    $groupcount = 0;
    $grouppagecount = 0;
    $vk = array('{$PageCount}', '{$GroupCount}', '{$GroupPageCount}');
    $vv = array(&$pagecount, &$groupcount, &$grouppagecount);
    $lgroup = '';
    $out = '';
    foreach ($matches as $i => $pn) {
        $prev = (string) @$matches[$i - 1];
        $next = (string) @$matches[$i + 1];
        $Cursor['<'] = $Cursor['&lt;'] = $prev;
        $Cursor['='] = $pn;
        $Cursor['>'] = $Cursor['&gt;'] = $next;
        $group = PageVar($pn, '$Group');
        if ($group != $lgroup) {
            $groupcount++;
            $grouppagecount = 0;
        }
        $grouppagecount++;
        $pagecount++;
        $item = str_replace($vk, $vv, $ttext);
        $item = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PageVar(\$pn, '\$2', '\$1')", $item);
        $out .= $item;
        $lgroup = $group;
    }
    $class = preg_replace('/[^-a-zA-Z0-9\\x80-\\xff]/', ' ', @$opt['class']);
    $div = $class ? "<div class='{$class}'>" : '<div>';
    return $div . MarkupToHTML($pagename, $out, array('escape' => 0)) . '</div>';
}
Ejemplo n.º 13
0
function HandleBrowse($pagename)
{
    # handle display of a page
    global $DefaultPageTextFmt, $FmtV, $HandleBrowseFmt, $PageStartFmt, $PageEndFmt, $PageRedirectFmt;
    Lock(1);
    $page = RetrieveAuthPage($pagename, 'read');
    if (!$page) {
        Abort('?cannot read $pagename');
    }
    PCache($pagename, $page);
    SDV($PageRedirectFmt, "<p><i>(\$[redirected from] \n    <a href='\$PageUrl?action=edit'>\$FullName</a>)</i></p>\$HTMLVSpace\n");
    if (isset($page['text'])) {
        $text = $page['text'];
    } else {
        $text = FmtPageName($DefaultPageTextFmt, $pagename);
    }
    if (@(!$_GET['from'])) {
        $PageRedirectFmt = '';
        if (preg_match('/\\(:redirect\\s+(.+?):\\)/', $text, $match)) {
            $rname = MakePageName($pagename, $match[1]);
            if (PageExists($rname)) {
                Redirect($rname, "\$PageUrl?from={$pagename}");
            }
        }
    } else {
        $PageRedirectFmt = FmtPageName($PageRedirectFmt, $_GET['from']);
    }
    $text = '(:groupheader:)' . @$text . '(:groupfooter:)';
    $FmtV['$PageText'] = MarkupToHTML($pagename, $text);
    SDV($HandleBrowseFmt, array(&$PageStartFmt, &$PageRedirectFmt, '$PageText', &$PageEndFmt));
    PrintFmt($pagename, $HandleBrowseFmt);
}
Ejemplo n.º 14
0
function HandleFeed($pagename, $auth = 'read')
{
    global $FeedFmt, $action, $PCache, $FmtV, $ISOTimeFmt, $RSSTimeFmt, $FeedOpt, $FeedDescPatterns, $CategoryGroup, $EntitiesTable;
    SDV($ISOTimeFmt, '%Y-%m-%dT%H:%M:%SZ');
    SDV($RSSTimeFmt, 'D, d M Y H:i:s \\G\\M\\T');
    SDV($FeedDescPatterns, array('/<[^>]*$/' => ' ', '/\\w+$/' => '', '/<[^>]+>/' => ''));
    SDVA($FeedCategoryOpt, array('link' => $pagename, 'readf' => 1));
    SDVA($FeedTrailOpt, array('trail' => $pagename, 'count' => 10, 'readf' => 1));
    $f = $FeedFmt[$action];
    $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
    if (!$page) {
        Abort("?cannot generate feed");
    }
    $feedtime = $page['time'];
    # determine list of pages to display
    if (@($_REQUEST['trail'] || $_REQUEST['group'] || $_REQUEST['link'])) {
        $opt['readf'] = 1;
    } else {
        if ($action == 'dc') {
            $opt = array();
        } else {
            if (preg_match("/^{$CategoryGroup}\\./", $pagename)) {
                $opt = $FeedCategoryOpt;
            } else {
                $opt = $FeedTrailOpt;
            }
        }
    }
    if (!$opt) {
        PCache($pagename, $page);
        $pagelist = array(&$PCache[$pagename]);
    } else {
        $opt = array_merge($opt, @$_REQUEST);
        $pagelist = MakePageList($pagename, $opt);
    }
    # process list of pages in feed
    $rdfseq = '';
    foreach ($pagelist as $page) {
        $pn = $page['name'];
        if (!PageExists($pn)) {
            continue;
        }
        $pl[] = $pn;
        if (@$opt['count'] && count($pl) >= $opt['count']) {
            break;
        }
        $rdfseq .= FmtPageName("<rdf:li resource=\"\$PageUrl\" />\n", $pn);
        if ($page['time'] > $feedtime) {
            $feedtime = $page['time'];
        }
    }
    $pagelist = $pl;
    $FmtV['$FeedRDFSeq'] = $rdfseq;
    $FmtV['$FeedISOTime'] = gmstrftime($ISOTimeFmt, $feedtime);
    $FmtV['$FeedRSSTime'] = gmdate($RSSTimeFmt, $feedtime);
    # format start of feed
    $out = FmtPageName($f['feed']['_start'], $pagename);
    # format feed elements
    foreach ($f['feed'] as $k => $v) {
        if ($k[0] == '_' || !$v) {
            continue;
        }
        $x = FmtPageName($v, $pagename);
        if (!$x) {
            continue;
        }
        $out .= $v[0] == '<' ? $x : "<{$k}>{$x}</{$k}>\n";
    }
    # format items in feed
    if (@$f['feed']['_items']) {
        $out .= FmtPageName($f['feed']['_items'], $pagename);
    }
    foreach ($pagelist as $pn) {
        $page =& $PCache[$pn];
        $FmtV['$ItemDesc'] = @$page['description'] ? $page['description'] : trim(preg_replace(array_keys($FeedDescPatterns), array_values($FeedDescPatterns), @$page['excerpt']));
        $FmtV['$ItemISOTime'] = gmstrftime($ISOTimeFmt, $page['time']);
        $out .= FmtPageName($f['item']['_start'], $pn);
        foreach ((array) @$f['item'] as $k => $v) {
            if ($k[0] == '_' || !$v) {
                continue;
            }
            if (is_callable($v)) {
                $out .= $v($pn, $page, $k);
                continue;
            }
            if (strpos($v, '$LastModifiedBy') !== false && !@$page['author']) {
                continue;
            }
            if (strpos($v, '$Category') !== false) {
                if (preg_match_all("/(?<=^|,){$CategoryGroup}\\.([^,]+)/", @$page['targets'], $match)) {
                    foreach ($match[1] as $c) {
                        $FmtV['$Category'] = $c;
                        $out .= FmtPageName($v, $pn);
                    }
                }
                continue;
            }
            $x = FmtPageName($v, $pn);
            if (!$x) {
                continue;
            }
            $out .= $v[0] == '<' ? $x : "<{$k}>{$x}</{$k}>\n";
        }
        $out .= FmtPageName($f['item']['_end'], $pn);
    }
    $out .= FmtPageName($f['feed']['_end'], $pagename);
    foreach ((array) @$f['feed']['_header'] as $fmt) {
        header(FmtPageName($fmt, $pagename));
    }
    print str_replace(array_keys($EntitiesTable), array_values($EntitiesTable), $out);
}
Ejemplo n.º 15
0
function AutoCreateTargets($pagename, &$page, &$new) {
  global $IsPagePosted, $AutoCreate, $LinkTargets;
  if (!$IsPagePosted) return;
  foreach((array)@$AutoCreate as $pat => $init) {
    if (is_null($init)) continue;
    foreach(preg_grep($pat, array_keys((array)@$LinkTargets)) as $aname) {
      if (PageExists($aname)) continue;
      $x = RetrieveAuthPage($aname, 'edit', false, READPAGE_CURRENT);
      if (!$x) continue;
      WritePage($aname, $init);
    }
  }
}
Ejemplo n.º 16
0
    by the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.  See pmwiki.php for full details.

    This script handles per-browser preferences.  Preference settings
    are stored in wiki pages as XLPage translations, and a cookie on
    the browser tells PmWiki where to find the browser's preferred
    settings.

    This script looks for a ?setprefs= request parameter (e.g., in
    a url); when it finds one it sets a 'setprefs' cookie on the browser 
    identifying the page to be used to load browser preferences,
    and loads the associated preferences.

    If there is no ?setprefs= request, then the script uses the
    'setprefs' cookie from the browser to load the preference settings.
*/
SDV($PrefsCookie, $CookiePrefix . 'setprefs');
SDV($PrefsCookieExpires, $Now + 60 * 60 * 24 * 365);
$LogoutCookies[] = $PrefsCookie;
$sp = '';
if (@$_COOKIE[$PrefsCookie]) {
    $sp = $_COOKIE[$PrefsCookie];
}
if (isset($_GET['setprefs'])) {
    $sp = $_GET['setprefs'];
    setcookie($PrefsCookie, $sp, $PrefsCookieExpires, '/');
}
if ($sp && PageExists($sp)) {
    XLPage('prefs', $sp);
}
XLSDV('en', array('ak_view' => '', 'ak_edit' => 'e', 'ak_history' => 'h', 'ak_print' => '', 'ak_recentchanges' => 'c', 'ak_save' => 's', 'ak_saveedit' => 'u', 'ak_savedraft' => 'd', 'ak_preview' => 'p', 'ak_em' => '', 'ak_strong' => ''));
Ejemplo n.º 17
0
function HandleRss($pagename)
{
    global $RssMaxItems, $RssSourceSize, $RssDescSize, $RssChannelFmt, $RssChannelDesc, $RssTimeFmt, $RssChannelBuildDate, $RssItemsRDFList, $RssItemsRDFListFmt, $RssItems, $RssItemFmt, $RssItemDesc, $RssItemPubDate, $GCount, $HandleRssFmt;
    $t = ReadTrail($pagename, $pagename);
    $page = RetrieveAuthPage($pagename, false);
    $cbgmt = $page['time'];
    $r = array();
    for ($i = 0; $i < count($t) && count($r) < $RssMaxItems; $i++) {
        if (!PageExists($t[$i]['pagename'])) {
            continue;
        }
        $page = RetrieveAuthPage($t[$i]['pagename'], false);
        $text = MarkupToHTML($t[$i]['pagename'], substr($page['text'], 0, $RssSourceSize));
        $text = rssencode(preg_replace("/<.*?>/s", "", $text));
        preg_match("/^(.{0,{$RssDescSize}}\\s)/s", $text, $match);
        $r[] = array('name' => $t[$i]['pagename'], 'time' => $page['time'], 'desc' => $match[1] . " ...");
        if ($page['time'] > $cbgmt) {
            $cbgmt = $page['time'];
        }
    }
    SDV($RssChannelBuildDate, rssencode(gmstrftime($RssTimeFmt, $cbgmt)));
    SDV($RssChannelDesc, rssencode(FmtPageName('$Group.$Title', $pagename)));
    foreach ($r as $page) {
        $RssItemPubDate = gmstrftime($RssTimeFmt, $page['time']);
        $RssItemDesc = $page['desc'];
        $GCount = 0;
        $RssItemsRDFList[] = rssencode(FmtPageName($RssItemsRDFListFmt, $page['name']));
        $RssItems[] = rssencode(FmtPageName($RssItemFmt, $page['name']));
    }
    header("Content-type: text/xml");
    PrintFmt($pagename, $HandleRssFmt);
    exit;
}
Ejemplo n.º 18
0
    'setprefs' cookie from the browser to load the preference settings.
    
    Script maintained by Petko YOTOV www.pmwiki.org/petko
*/

SDV($PrefsCookie, $CookiePrefix.'setprefs');
SDV($PrefsCookieExpires, $Now + 60 * 60 * 24 * 365);
$LogoutCookies[] = $PrefsCookie;

$sp = '';
if (@$_COOKIE[$PrefsCookie]) $sp = $_COOKIE[$PrefsCookie];
if (isset($_GET['setprefs'])) {
  $sp = MakePageName($pagename, $_GET['setprefs']);
  setcookie($PrefsCookie, $sp, $PrefsCookieExpires, '/');
}
if ($sp && PageExists($sp)) XLPage('prefs', $sp, true);

if(is_array($XL['prefs'])) {
  foreach($XL['prefs'] as $k=>$v) {
    if(! preg_match('/^(e_rows|e_cols|TimeFmt|Locale|Site\\.EditForm)$|^ak_/', $k))
      unset($XL['prefs'][$k]);
  }
}

XLSDV('en', array(
  'ak_view' => '',
  'ak_edit' => 'e',
  'ak_history' => 'h',
  'ak_attach'  => '',
  'ak_backlinks' => '',
  'ak_logout' => '',
Ejemplo n.º 19
0
## $MetaRobots provides the value for the <meta name='robots' ...> tag.
SDV($MetaRobots, $action != 'browse' || !PageExists($pagename) || preg_match('#^PmWiki[./](?!PmWiki$)|^Site[./]#', $pagename) ? 'noindex,nofollow' : 'index,follow');
if ($MetaRobots) {
    $HTMLHeaderFmt['robots'] = "  <meta name='robots' content='\$MetaRobots' />\n";
}
## $RobotPattern is used to identify robots.
SDV($RobotPattern, 'Googlebot|Slurp|msnbot|Teoma|ia_archiver|BecomeBot|HTTrack|MJ12bot|XML Sitemaps');
SDV($IsRobotAgent, $RobotPattern && preg_match("!{$RobotPattern}!", @$_SERVER['HTTP_USER_AGENT']));
if (!$IsRobotAgent) {
    return;
}
## $RobotActions indicates which actions a robot is allowed to perform.
SDVA($RobotActions, array('browse' => 1, 'rss' => 1, 'dc' => 1));
if (!@$RobotActions[$action]) {
    $pagename = ResolvePageName($pagename);
    if (!PageExists($pagename)) {
        header("HTTP/1.1 404 Not Found");
        print "<h1>Not Found</h1>";
        exit;
    }
    header("HTTP/1.1 403 Forbidden");
    print "<h1>Forbidden</h1>";
    exit;
}
## The following removes any ?action= parameters that robots aren't
## allowed to access.
if (IsEnabled($EnableRobotCloakActions, 0)) {
    $p = create_function('$a', 'return (boolean)$a;');
    $p = join('|', array_keys(array_filter($RobotActions, $p)));
    $FmtPV['$PageUrl'] = 'PUE(($EnablePathInfo)
         ? "\\$ScriptUrl/$group/$name"
Ejemplo n.º 20
0
function Redirect($pagename,$urlfmt='$PageUrl') {
  # redirect the browser to $pagename
  global $RedirectDelay;
  clearstatcache();
  if (!PageExists($pagename)) $pagename=$DefaultPage;
  $pageurl = FmtPageName($urlfmt,$pagename);
  #header("Location: $pageurl");
  #header("Content-type: text/html");
  #echo "<html><head>
  #  <meta http-equiv='Refresh' Content='$RedirectDelay; URL=$pageurl' />
  #  <title>Redirect</title></head><body></body></html>";
  echo "<a href='$pageurl'>Redirect to $pageurl</a>";
  exit;
}
Ejemplo n.º 21
0
}
/*  Copyright 2005 Patrick R. Michaud (pmichaud@pobox.com)
    This file is part of PmWiki; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.  See pmwiki.php for full details.

    This script handles per-browser preferences.  Preference settings
    are stored in wiki pages as XLPage translations, and a cookie on
    the browser tells PmWiki where to find the browser's preferred
    settings.

    This script looks for a ?setprefs= request parameter (e.g., in
    a url); when it finds one it sets a 'setprefs' cookie on the browser 
    identifying the page to be used to load browser preferences,
    and loads the associated preferences.

    If there is no ?setprefs= request, then the script uses the
    'setprefs' cookie from the browser to load the preference settings.
*/
SDV($PrefsCookieExpires, $Now + 60 * 60 * 24 * 365);
if (@$_COOKIE['setprefs']) {
    $sp = $_COOKIE['setprefs'];
}
if (isset($_GET['setprefs'])) {
    $sp = $_GET['setprefs'];
    setcookie('setprefs', $sp, $PrefsCookieExpires, '/');
}
if (PageExists($sp)) {
    XLPage('prefs', $sp);
}
Ejemplo n.º 22
0
## mainrc:
##   2.0.beta44 switched Main.AllRecentChanges to be 
##   $SiteGroup.AllRecentChanges.  This setting keeps Main.AllRecentChanges
##   if it exists.
if (@$Transition['mainrc'] && PageExists('Main.AllRecentChanges')) {
  SDV($RecentChangesFmt['Main.AllRecentChanges'],
    '* [[$Group.$Name]]  . . . $CurrentTime $[by] $AuthorLink');
}

## siteapprovedurls:
##   2.0.beta44 switched Main.ApprovedUrls to be $SiteGroup.ApprovedUrls .
##   This setting keeps using Main.ApprovedUrls if it exists.
if (@$Transition['mainapprovedurls'] && PageExists('Main.ApprovedUrls')) {
  $ApprovedUrlPagesFmt = (array)$ApprovedUrlPagesFmt;
  if (PageExists(FmtPageName($ApprovedUrlPagesFmt[0], $pagename))) 
    $ApprovedUrlPagesFmt[] = 'Main.ApprovedUrls';
  else array_unshift($ApprovedUrlPagesFmt, 'Main.ApprovedUrls');
}

## pageeditfmt:
##   2.0.beta44 switched to using wiki markup forms for page editing.
##   However, some sites and skins have customized values of $PageEdit.
##   This setting restores the default values.
if (@$Transition['pageeditfmt']) {
  SDV($PageEditFmt, "<div id='wikiedit'>
    <a id='top' name='top'></a>
    <h1 class='wikiaction'>$[Editing \$FullName]</h1>
    <form method='post' action='\$PageUrl?action=edit'>
    <input type='hidden' name='action' value='edit' />
    <input type='hidden' name='n' value='\$FullName' />
Ejemplo n.º 23
0
function HandleUpgrade($pagename, $auth = 'ALWAYS') {
  global $SiteGroup, $SiteAdminGroup, $StatusPageName, $ScriptUrl,
    $AuthUserPageFmt, $VersionNum, $Version;
  StopWatch('HandleUpgrade: begin');

  $message = '';
  $done = '';
  ##  check for Site.* --> SiteAdmin.*
  foreach(array('AuthUser', 'NotifyList', 'Blocklist', 'ApprovedUrls') as $n) {
    $n0 = "$SiteGroup.$n"; $n1 = "$SiteAdminGroup.$n";
    StopWatch("HandleUpgrade: checking $n0 -> $n1");
    ## checking AuthUser is special, because Site.AuthUser comes with the
    ## distribution.
    if ($n == 'AuthUser') {
      ##  if we already have a user-modified SiteAdmin.AuthUser, we can skip
      SDV($AuthUserPageFmt, '$SiteAdminGroup.AuthUser');
      $n1 = FmtPageName($AuthUserPageFmt, $pagename);
      $page = ReadPage($n1, READPAGE_CURRENT);
      if (@$page['time'] > 1000000000) continue;
      ##  if there's not a user-modified Site.AuthUser, we can skip
      $page = ReadPage($n0, READPAGE_CURRENT);
      if (@$page['time'] == 1000000000) continue;
    } else if (!PageExists($n0) || PageExists($n1)) continue;

    if (@$_REQUEST['migrate'] == 'yes') {
      ##  if the admin wants PmWiki to migrate, do it.
      $page = RetrieveAuthPage($n0, 'admin', true);
      StopWatch("HandleUpgrade: copying $n0 -> $n1");
      if ($page) { 
        WritePage($n1, $page); 
        $done .= "<li>Copied $n0 to $n1</li>";
        continue; 
      }
    }
    $message .= "<li>$n0 -&gt; $n1</li>";
  }

  if ($message) {
    $migrateurl = "$ScriptUrl?action=upgrade&amp;migrate=yes";
    $infourl = 'http://www.pmwiki.org/wiki/PmWiki/UpgradeToSiteAdmin';
    $message = 
      "<h2>Upgrade notice -- SiteAdmin group</h2>
      <p>This version of PmWiki expects several administrative pages 
      from the <em>Site</em> group to be found in a new <em>SiteAdmin</em> group.  
      On this site, the following pages appear to need to be relocated:</p>
      <ul>$message</ul>

      <p>For more information about this change, including the various
      options for proceeding, see</p>
      <blockquote><a target='_blank' href='$infourl'>$infourl</a></blockquote>

      <form action='$ScriptUrl' method='post'>
      <p>If you would like PmWiki to attempt to automatically copy 
      these pages into their new <br /> locations for you, try 
        <input type='hidden' name='action' value='upgrade' />
        <input type='hidden' name='migrate' value='yes' />
        <input type='submit' value='Relocate pages listed above' /> 
        (admin password required) </p>
      </form>

      <p>If you want to configure PmWiki so that it continues to
      look for the above pages in <em>$SiteGroup</em>, add the
      following line near the top of <em>local/config.php</em>:</p>

      <blockquote><pre>\$SiteAdminGroup = \$SiteGroup;</pre></blockquote>

      $Version
      ";
    print $message;
    exit;
  }

  StopWatch("UpgradeCheck: writing $StatusPageName");
  Lock(2);
  SDV($StatusPageName, "$SiteAdminGroup.Status");
  $page = ReadPage($StatusPageName);
  $page['updatedto'] = $VersionNum;
  WritePage($StatusPageName, $page);

  if ($done) {
    $done .= "<li>Updated $StatusPageName</li>";
    echo "<h2>Upgrade to $Version ... ok</h2><ul>$done</ul>";
    $GLOBALS['EnableRedirect'] = 0;
  }
  Redirect($pagename);
}
Ejemplo n.º 24
0
		private function EditPageStep1($MsgDesc = "", $MsgStatus = "", $IsError = false)
		{
			$GLOBALS['Message'] = '';
			if($MsgDesc != "") {
				$GLOBALS['Message'] .= MessageBox($MsgDesc, $MsgStatus);
			}

			$GLOBALS['Message'] .= GetFlashMessageBoxes();

			$pageId = (int)$_REQUEST['pageId'];
			$arrData = array();

			if(PageExists($pageId)) {

				// Was the page submitted with a duplicate page name?
				if($IsError) {
					$this->_GetPageData(0, $arrData);
				}
				else {
					$this->_GetPageData($pageId, $arrData);
				}

				$GLOBALS['CurrentTab'] = '0';
				if(isset($_REQUEST['currentTab'])) {
					$GLOBALS['CurrentTab'] = $_REQUEST['currentTab'];
				}
				// Does this user have permission to edit this product?
				if($GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId() && $arrData['pagevendorid'] != $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId()) {
					FlashMessage(GetLang('Unauthorized'), MSG_ERROR, 'index.php?ToDo=viewPages');
				}

				$GLOBALS['PageId'] = (int) $pageId;
				$GLOBALS['SetupType'] = sprintf("SwitchType(%d);", $arrData['pagetype']);
				$GLOBALS['Title'] = GetLang('EditPage');
				$GLOBALS['FormAction'] = "editPage2";
				$GLOBALS['PageTitle'] = isc_html_escape($arrData['pagetitle']);

				$wysiwygOptions = array(
					'id'		=> 'wysiwyg',
					'value'		=> $arrData['pagecontent']
				);
				$GLOBALS['WYSIWYG'] = GetClass('ISC_ADMIN_EDITOR')->GetWysiwygEditor($wysiwygOptions);

				$GLOBALS['PageLink'] = isc_html_escape($arrData['pagelink']);
				$GLOBALS['PageFeed'] = isc_html_escape($arrData['pagefeed']);
				$GLOBALS['PageEmail'] = isc_html_escape($arrData['pageemail']);
				$GLOBALS['ParentPageOptions'] = $this->GetParentPageOptions($arrData['pageparentid'], $pageId, $arrData['pagevendorid']);
				$GLOBALS['PageKeywords'] = isc_html_escape($arrData['pagekeywords']);
				$GLOBALS['PageMetaTitle'] = isc_html_escape($arrData['pagemetatitle']);
				$GLOBALS['PageDesc'] = isc_html_escape($arrData['pagedesc']);
				$GLOBALS['PageSearchKeywords'] = isc_html_escape($arrData['pagesearchkeywords']);
				$GLOBALS['PageSort'] = (int) $arrData['pagesort'];

				if($arrData['pagestatus'] == 1) {
					$GLOBALS['Visible'] = 'checked="checked"';
				}

				if($arrData['pagecustomersonly'] == 1) {
					$GLOBALS['IsCustomersOnly'] = "checked=\"checked\"";
				}

				if(is_numeric(isc_strpos($arrData['pagecontactfields'], "fullname"))) {
					$GLOBALS['IsContactFullName'] = 'checked="checked"';
				}

				if(is_numeric(isc_strpos($arrData['pagecontactfields'], "companyname"))) {
					$GLOBALS['IsContactCompanyName'] = 'checked="checked"';
				}

				if(is_numeric(isc_strpos($arrData['pagecontactfields'], "phone"))) {
					$GLOBALS['IsContactPhone'] = 'checked="checked"';
				}

				if(is_numeric(isc_strpos($arrData['pagecontactfields'], "orderno"))) {
					$GLOBALS['IsContactOrderNo'] = 'checked="checked"';
				}

				if(is_numeric(isc_strpos($arrData['pagecontactfields'], "rma"))) {
					$GLOBALS['IsContactRMA'] = 'checked="checked"';
				}

				// Is this page the default home page?
				if($arrData['pageishomepage'] == 1) {
					$GLOBALS['IsHomePage'] = 'checked="checked"';
				}

				$GLOBALS['IsVendor'] = 'false';

				if(!gzte11(ISC_HUGEPRINT)) {
					$GLOBALS['HideVendorOption'] = 'display: none';
				}
				else {
					$vendorData = $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendor();
					if(isset($vendorData['vendorid'])) {
						$GLOBALS['HideVendorSelect'] = 'display: none';
						$GLOBALS['IsVendor'] = 'true';
						$GLOBALS['CurrentVendor'] = isc_html_escape($vendorData['vendorname']);
					}
					else {
						$GLOBALS['HideVendorLabel'] = 'display: none';
						$GLOBALS['VendorList'] = $this->BuildVendorSelect($arrData['pagevendorid']);
					}
				}

				// Get a list of all layout files
				$layoutFile = 'page.html';
				if($arrData['pagelayoutfile'] != '') {
					$layoutFile = $arrData['pagelayoutfile'];
				}
				$GLOBALS['LayoutFiles'] = GetCustomLayoutFilesAsOptions("page.html", $layoutFile);



				//Google website optimizer
				$GLOBALS['GoogleWebsiteOptimizerIntro'] = GetLang('PageGoogleWebsiteOptimizerIntro');

				$GLOBALS['HideOptimizerConfigForm'] = 'display:none;';
				$GLOBALS['CheckEnableOptimizer'] = '';
				$GLOBALS['SkipOptimizerConfirmMsg'] = 'true';

				$enabledOptimizers = GetConfig('OptimizerMethods');
				if(!empty($enabledOptimizers)) {
					foreach ($enabledOptimizers as $id => $date) {
						GetModuleById('optimizer', $optimizerModule, $id);
						if ($optimizerModule->_testPage == 'pages' || $optimizerModule->_testPage == 'all') {
							$GLOBALS['SkipOptimizerConfirmMsg'] = 'false';
							break;
						}
					}
				}

				if($arrData['page_enable_optimizer']) {
					$GLOBALS['HideOptimizerConfigForm'] = '';
					$GLOBALS['CheckEnableOptimizer'] = 'Checked';
				}

				$pageUrl = PageLink($pageId, $arrData['pagetitle']);
				$optimizer = getClass('ISC_ADMIN_OPTIMIZER');
				$GLOBALS['OptimizerConfigForm'] = $optimizer->showPerItemConfigForm('page', $pageId, $pageUrl);

				$GLOBALS['SaveAndAddAnother'] = GetLang('SaveAndContinueEditing');

				$this->template->display('page.form.tpl');
			}
			else {
				// The news page doesn't exist
				FlashMessage(GetLang('PageDoesntExist'), MSG_ERROR, 'index.php?ToDo=viewPages');
			}
		}
Ejemplo n.º 25
0
function FPLTemplate($pagename, &$matches, $opt)
{
    global $Cursor, $FPLTemplatePageFmt, $PageListArgPattern;
    SDV($FPLTemplatePageFmt, array('{$FullName}', '{$SiteGroup}.LocalTemplates', '{$SiteGroup}.PageListTemplates'));
    StopWatch("FPLTemplate begin");
    $template = @$opt['template'];
    if (!$template) {
        $template = @$opt['fmt'];
    }
    list($tname, $qf) = explode('#', $template, 2);
    if ($tname) {
        $tname = array(MakePageName($pagename, $tname));
    } else {
        $tname = (array) $FPLTemplatePageFmt;
    }
    foreach ($tname as $t) {
        $t = FmtPageName($t, $pagename);
        if (!PageExists($t)) {
            continue;
        }
        if ($qf) {
            $t .= "#{$qf}";
        }
        $ttext = IncludeText($pagename, $t, true);
        if (!$qf || strpos($ttext, "[[#{$qf}]]") !== false) {
            break;
        }
    }
    ##  save any escapes
    $ttext = MarkupEscape($ttext);
    ##  remove any anchor markups to avoid duplications
    $ttext = preg_replace('/\\[\\[#[A-Za-z][-.:\\w]*\\]\\]/', '', $ttext);
    ##  extract portions of template
    $tparts = preg_split('/\\(:(template)\\s+(\\w+)\\s*(.*?):\\)/i', $ttext, -1, PREG_SPLIT_DELIM_CAPTURE);
    ##  handle (:template defaults:)
    $i = 0;
    while ($i < count($tparts)) {
        if ($tparts[$i] != 'template') {
            $i++;
            continue;
        }
        if ($tparts[$i + 1] != 'defaults') {
            $i += 4;
            continue;
        }
        $opt = array_merge(ParseArgs($tparts[$i + 2], $PageListArgPattern), $opt);
        array_splice($tparts, $i, 3);
    }
    SDV($opt['class'], 'fpltemplate');
    ##  get the list of pages
    $matches = array_values(MakePageList($pagename, $opt, 0));
    ##  extract page subset according to 'count=' parameter
    if (@$opt['count']) {
        list($r0, $r1) = CalcRange($opt['count'], count($matches));
        if ($r1 < $r0) {
            $matches = array_reverse(array_slice($matches, $r1 - 1, $r0 - $r1 + 1));
        } else {
            $matches = array_slice($matches, $r0 - 1, $r1 - $r0 + 1);
        }
    }
    $savecursor = $Cursor;
    $pagecount = 0;
    $groupcount = 0;
    $grouppagecount = 0;
    $pseudovars = array('{$$PageCount}' => &$pagecount, '{$$GroupCount}' => &$groupcount, '{$$GroupPageCount}' => &$grouppagecount);
    foreach (preg_grep('/^[\\w$]/', array_keys($opt)) as $k) {
        if (!is_array($opt[$k])) {
            $pseudovars["{\$\${$k}}"] = htmlspecialchars($opt[$k], ENT_NOQUOTES);
        }
    }
    $vk = array_keys($pseudovars);
    $vv = array_values($pseudovars);
    $lgroup = '';
    $out = '';
    foreach ($matches as $i => $pn) {
        $group = PageVar($pn, '$Group');
        if ($group != $lgroup) {
            $groupcount++;
            $grouppagecount = 0;
            $lgroup = $group;
        }
        $grouppagecount++;
        $pagecount++;
        $t = 0;
        while ($t < count($tparts)) {
            if ($tparts[$t] != 'template') {
                $item = $tparts[$t];
                $t++;
            } else {
                list($when, $control, $item) = array_slice($tparts, $t + 1, 3);
                $t += 4;
                if (!$control) {
                    if ($when == 'first' && $i != 0) {
                        continue;
                    }
                    if ($when == 'last' && $i != count($matches) - 1) {
                        continue;
                    }
                } else {
                    if ($when == 'first' || !isset($last[$t])) {
                        $Cursor['<'] = $Cursor['&lt;'] = (string) @$matches[$i - 1];
                        $Cursor['='] = $pn;
                        $Cursor['>'] = $Cursor['&gt;'] = (string) @$matches[$i + 1];
                        $curr = str_replace($vk, $vv, $control);
                        $curr = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PageVar(\$pn, '\$2', '\$1')", $curr);
                        if ($when == 'first' && $i > 0 && $last[$t] == $curr) {
                            continue;
                        }
                        $last[$t] = $curr;
                    }
                    if ($when == 'last') {
                        $Cursor['<'] = $Cursor['&lt;'] = $pn;
                        $Cursor['='] = (string) @$matches[$i + 1];
                        $Cursor['>'] = $Cursor['&gt;'] = (string) @$matches[$i + 2];
                        $next = str_replace($vk, $vv, $control);
                        $next = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PageVar(\$pn, '\$2', '\$1')", $next);
                        if ($next == $last[$t] && $i != count($matches) - 1) {
                            continue;
                        }
                        $last[$t] = $next;
                    }
                }
            }
            $Cursor['<'] = $Cursor['&lt;'] = (string) @$matches[$i - 1];
            $Cursor['='] = $pn;
            $Cursor['>'] = $Cursor['&gt;'] = (string) @$matches[$i + 1];
            $item = str_replace($vk, $vv, $item);
            $item = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PVSE(PageVar(\$pn, '\$2', '\$1'))", $item);
            $out .= MarkupRestore($item);
        }
    }
    $class = preg_replace('/[^-a-zA-Z0-9\\x80-\\xff]/', ' ', @$opt['class']);
    $div = $class ? "<div class='{$class}'>" : '<div>';
    $out = $div . MarkupToHTML($pagename, $out, array('escape' => 0)) . '</div>';
    $Cursor = $savecursor;
    StopWatch("FPLTemplate end");
    return $out;
}
Ejemplo n.º 26
0
function pmcal($opts)
{
    global $pagename, $MaxIncludes, $HTMLHeaderFmt, $PmCalTextLinkMark, $PmCalIncludeTextLinkMark, $PmCalACALTextLinkMark, $PmCalSubIncludeTextLinkMark, $PmCalSubACALTextLinkMark, $PmCaltyear, $PmCaltmonth, $PmCaltday;
    //Initial PmWiki markup for textlinks
    SDV($PmCalTextLinkMark, '!!');
    SDV($PmCalIncludeTextLinkMark, '!!');
    SDV($PmCalACALTextLinkMark, '!!');
    SDV($PmCalSubIncludeTextLinkMark, $PmCalIncludeTextLinkMark);
    SDV($PmCalSubACALTextLinkMark, $PmCalACALTextLinkMark);
    // Determine this Group
    //
    $group = FmtPageName('$Group', $pagename);
    $name = FmtPageName('$Name', $pagename);
    // What is today?
    //
    // $tmonth = date("m");
    // $tyear = date("Y");
    // $tday = date("d");
    // Process markup arguments first
    //
    $defaults = array('year' => $PmCaltyear, 'month' => $PmCaltmonth, 'day' => $PmCaltday, 'alwaystoday' => 'false', 'acalfmt' => NULL, 'calfmt' => '%s', 'callinks' => 'true', 'caltype' => 'normal', 'cssprefix' => 'pmcal', 'dayofweektitlefmt' => '%a', 'expire' => 'false', 'overrides' => 'true', 'includes' => 'true', 'isodate' => 'false', 'lines' => NULL, 'locale' => NULL, 'monthsahead' => 0, 'monthsback' => 0, 'monthtitlefmt' => '%B %Y', 'navnext' => '&raquo;', 'navprev' => '&laquo;', 'onedate' => 'false', 'paras' => NULL, 'reverse' => 'false', 'stopafter' => 'false', 'textacalfmt' => NULL, 'textcalfmt' => '(%s)', 'textdatefmt' => '%x', 'textlinks' => 'true', 'weekstart' => 0, 'zebra' => 'true', 'acals' => NULL, 'cals' => NULL, 'dayofweektitle' => NULL, 'monthtitle' => NULL, 'styles' => NULL);
    // If name is of the format YYYYMMDD, then we'll
    // override the year, month, day defaults
    //
    // Hack for ACAL isn't perfect here... but ok.
    //
    if (preg_match("/([A0-9][C0-9][A0-9][L0-9])([01][0-9])([0-3][0-9])/", $name, $matches)) {
        $defaults['year'] = $matches[1];
        $defaults['month'] = $matches[2];
        $defaults['day'] = $matches[3];
    }
    $args = array_merge($defaults, ParseArgs($opts));
    $urladd = '';
    // Default to today if nothing supplied on the URL
    // line... ?month=12&day=25&year=2005 would be
    // Christmas 2005
    // URL GET vars override markup arguments
    //
    // With that said, might be useful to have a command line
    // augment the markup arguments in the case of foreign
    // calendar overlays... hmmm...  possible new feature.
    // calsplus=Calendar maybe...
    //
    // Build a url tack on of get vars when get vars are used.
    //
    $year = isset($_GET['year']) ? $_GET['year'] : $args['year'];
    $month = isset($_GET['month']) ? $_GET['month'] : $args['month'];
    $day = isset($_GET['day']) ? $_GET['day'] : $args['day'];
    // Sneaky fix for default monthtitlefmt for ACAL
    if ($year == 'ACAL') {
        $ayear = 'ACAL';
        $args['monthtitlefmt'] = '%B ACAL';
    }
    // Allows overrides=false in the :pmcal: markup to disallow
    // settings on the URL line.
    //
    $overrides = $args['overrides'];
    if ($overrides == 'false') {
        $_GET = NULL;
    }
    $acals = isset($_GET['acals']) ? explode(',', $_GET['acals']) : explode(',', $args['acals']);
    if (isset($_GET['acals'])) {
        $urladd .= "&amp;acals=" . urlencode($_GET['acals']);
    }
    $alwaystoday = isset($_GET['alwaystoday']) ? $_GET['alwaystoday'] : $args['alwaystoday'];
    if (isset($_GET['alwaystoday'])) {
        $urladd .= "&amp;alwaystoday=" . urlencode($_GET['alwaystoday']);
    }
    $acalfmt = isset($_GET['acalfmt']) ? $_GET['acalfmt'] : $args['acalfmt'];
    if (isset($_GET['acalfmt'])) {
        $urladd .= "&amp;acalfmt=" . urlencode($_GET['acalfmt']);
    }
    $calfmt = isset($_GET['calfmt']) ? $_GET['calfmt'] : $args['calfmt'];
    if (isset($_GET['calfmt'])) {
        $urladd .= "&amp;calfmt=" . urlencode($_GET['calfmt']);
    }
    $callinks = isset($_GET['callinks']) ? $_GET['callinks'] : $args['callinks'];
    if (isset($_GET['callinks'])) {
        $urladd .= "&amp;callinks=" . urlencode($_GET['callinks']);
    }
    $cals = isset($_GET['cals']) ? explode(',', $_GET['cals']) : explode(',', $args['cals']);
    if (isset($_GET['cals'])) {
        $urladd .= "&amp;cals=" . urlencode($_GET['cals']);
    }
    $caltype = isset($_GET['caltype']) ? $_GET['caltype'] : $args['caltype'];
    if (isset($_GET['caltype'])) {
        $urladd .= "&amp;caltype=" . urlencode($_GET['caltype']);
    }
    $cssprefix = isset($_GET['cssprefix']) ? $_GET['cssprefix'] : $args['cssprefix'];
    if (isset($_GET['cssprefix'])) {
        $urladd .= "&amp;cssprefix=" . urlencode($_GET['cssprefix']);
    }
    $dayofweektitle = isset($_GET['dayofweektitle']) ? explode(',', $_GET['dayofweektitle']) : explode(',', $args['dayofweektitle']);
    if (isset($_GET['dayofweektitle'])) {
        $urladd .= "&amp;dayofweektitle=" . urlencode($_GET['dayofweektitle']);
    }
    $dayofweektitlefmt = isset($_GET['dayofweektitlefmt']) ? $_GET['dayofweektitlefmt'] : $args['dayofweektitlefmt'];
    if (isset($_GET['dayofweektitlefmt'])) {
        $urladd .= "&amp;dayofweektitlefmt=" . urlencode($_GET['dayofweektitlefmt']);
    }
    $expire = isset($_GET['expire']) ? $_GET['expire'] : $args['expire'];
    if (isset($_GET['expire'])) {
        $urladd .= "&amp;expire=" . urlencode($_GET['expire']);
    }
    $includes = isset($_GET['includes']) ? $_GET['includes'] : $args['includes'];
    if (isset($_GET['includes'])) {
        $urladd .= "&amp;includes=" . urlencode($_GET['includes']);
    }
    $isodate = isset($_GET['isodate']) ? $_GET['isodate'] : $args['isodate'];
    if (isset($_GET['isodate'])) {
        $urladd .= "&amp;isodate=" . urlencode($_GET['isodate']);
    }
    $lines = isset($_GET['lines']) ? $_GET['lines'] : $args['lines'];
    if (isset($_GET['lines'])) {
        $urladd .= "&amp;lines=" . urlencode($_GET['lines']);
    }
    $locale = isset($_GET['locale']) ? $_GET['locale'] : $args['locale'];
    if (isset($_GET['locale'])) {
        $urladd .= "&amp;locale=" . urlencode($_GET['locale']);
    }
    $monthsahead = isset($_GET['monthsahead']) ? $_GET['monthsahead'] : $args['monthsahead'];
    if (isset($_GET['monthsahead'])) {
        $urladd .= "&amp;monthsahead=" . urlencode($_GET['monthsahead']);
    }
    $monthsback = isset($_GET['monthsback']) ? $_GET['monthsback'] : $args['monthsback'];
    if (isset($_GET['monthsback'])) {
        $urladd .= "&amp;monthsback=" . urlencode($_GET['monthsback']);
    }
    $monthtitle = isset($_GET['monthtitle']) ? explode(',', $_GET['monthtitle']) : explode(',', $args['monthtitle']);
    if (isset($_GET['monthtitle'])) {
        $urladd .= "&amp;monthtitle=" . urlencode($_GET['monthtitle']);
    }
    $monthtitlefmt = isset($_GET['monthtitlefmt']) ? $_GET['monthtitlefmt'] : $args['monthtitlefmt'];
    if (isset($_GET['monthtitlefmt'])) {
        $urladd .= "&amp;monthtitlefmt=" . urlencode($_GET['monthtitlefmt']);
    }
    $navnext = isset($_GET['navnext']) ? $_GET['navnext'] : $args['navnext'];
    if (isset($_GET['navnext'])) {
        $urladd .= "&amp;navnext=" . urlencode($_GET['navnext']);
    }
    $navprev = isset($_GET['navprev']) ? $_GET['navprev'] : $args['navprev'];
    if (isset($_GET['navprev'])) {
        $urladd .= "&amp;navprev=" . urlencode($_GET['navprev']);
    }
    $onedate = isset($_GET['onedate']) ? $_GET['onedate'] : $args['onedate'];
    if (isset($_GET['onedate'])) {
        $urladd .= "&amp;paras=" . urlencode($_GET['onedate']);
    }
    $paras = isset($_GET['paras']) ? $_GET['paras'] : $args['paras'];
    if (isset($_GET['paras'])) {
        $urladd .= "&amp;paras=" . urlencode($_GET['paras']);
    }
    $reverse = isset($_GET['reverse']) ? $_GET['reverse'] : $args['reverse'];
    if (isset($_GET['reverse'])) {
        $urladd .= "&amp;reverse=" . urlencode($_GET['reverse']);
    }
    $stopafter = isset($_GET['stopafter']) ? $_GET['stopafter'] : $args['stopafter'];
    if (isset($_GET['stopafter'])) {
        $urladd .= "&amp;stopafter=" . urlencode($_GET['stopafter']);
    }
    $styles = isset($_GET['styles']) ? explode(',', $_GET['styles']) : explode(',', $args['styles']);
    if (isset($_GET['styles'])) {
        $urladd .= "&amp;styles=" . urlencode($_GET['styles']);
    }
    $textacalfmt = isset($_GET['textacalfmt']) ? $_GET['textacalfmt'] : $args['textacalfmt'];
    if (isset($_GET['textacalfmt'])) {
        $urladd .= "&amp;textacalfmt=" . urlencode($_GET['textacalfmt']);
    }
    $textcalfmt = isset($_GET['textcalfmt']) ? $_GET['textcalfmt'] : $args['textcalfmt'];
    if (isset($_GET['textcalfmt'])) {
        $urladd .= "&amp;textcalfmt=" . urlencode($_GET['textcalfmt']);
    }
    $textdatefmt = isset($_GET['textdatefmt']) ? $_GET['textdatefmt'] : $args['textdatefmt'];
    if (isset($_GET['textdatefmt'])) {
        $urladd .= "&amp;textdatefmt=" . urlencode($_GET['textdatefmt']);
    }
    $textlinks = isset($_GET['textlinks']) ? $_GET['textlinks'] : $args['textlinks'];
    if (isset($_GET['textlinks'])) {
        $urladd .= "&amp;textlinks=" . urlencode($_GET['textlinks']);
    }
    $weekstart = isset($_GET['weekstart']) ? $_GET['weekstart'] : $args['weekstart'];
    if (isset($_GET['weekstart'])) {
        $urladd .= "&amp;weekstart=" . urlencode($_GET['weekstart']);
    }
    if (isset($_GET['zebra'])) {
        $urladd .= "&amp;zebra=" . urlencode($_GET['zebra']);
    }
    $zebra = isset($_GET['zebra']) ? $_GET['zebra'] : $args['zebra'];
    // Experimenting with CSS
    // Styles can come out of the upload area for the group!
    //
    $first = 1;
    //Set first style to the preferred.
    if ($styles[0] != NULL) {
        foreach ((array) $styles as $stylename) {
            $filepath = FmtPageName("pub/css/{$stylename}.css", $pagename);
            if ($first) {
                $rel = "rel='stylesheet'";
                $first = 0;
            } else {
                $rel = "rel='alternate stylesheet'";
            }
            if (file_exists($filepath)) {
                $HTMLHeaderFmt[] = "<link {$rel} type='text/css' href='\$PubDirUrl/css/{$stylename}.css' title='{$stylename}'/>\n";
            } else {
                $filepath = FmtPageName("\$UploadFileFmt/{$stylename}.css", "{$pagename}");
                if (file_exists($filepath)) {
                    $HTMLHeaderFmt[] = "<link {$rel} type='text/css' href='\$UploadUrlFmt/{$group}/{$stylename}.css' title='{$stylename}'/>\n";
                }
            }
        }
    }
    // Set the locale
    //
    if ($isodate == 'true') {
        $textdatefmt = '%Y-%m-%d';
    }
    if ($locale != NULL) {
        setlocale(LC_TIME, $locale);
    }
    // Number of paragraphs to include
    $parasorlines = 'paras';
    if ($lines != NULL) {
        $parasorlines = 'lines';
        $normallinesparas = $lines;
        $otherlinesparas = $lines;
    } else {
        if ($paras == NULL) {
            $normallinesparas = '1';
            $otherlinesparas = '-1';
        } else {
            $normallinesparas = $paras;
            $otherlinesparas = $paras;
        }
    }
    // Fallback to today/default information if something doesn't look right.
    //
    if ($month < 1 || $month > 12) {
        $month = $PmCaltmonth;
    }
    if ($year < 1 || $year > 2038) {
        if ($year != 'ACAL') {
            $year = $PmCaltyear;
        }
    }
    if ($alwaystoday == 'true') {
        $year = $PmCaltyear;
        $month = $PmCaltmonth;
        $day = $PmCaltday;
    }
    switch ($caltype) {
        case 'text':
            break;
        case 'normal':
            break;
        default:
            $caltype = 'normal';
    }
    // Set acalfmt to calfmt if not set.
    if ($acalfmt == NULL) {
        $acalfmt = $calfmt;
    }
    // Set textacalfmt to textcalfmt if not set.
    if ($textacalfmt == NULL) {
        $textacalfmt = $textcalfmt;
    }
    // Set PmCalPrefix to cssprefix.
    $PmCalPrefix = $cssprefix;
    // Try to limit look backs and lookaheads (5 years)
    //
    if ($monthsback < 0 || $monthsback > 60) {
        $monthsback = 0;
    }
    if ($monthsahead < 0 || $monthsahead > 60) {
        $monthsahead = 0;
    }
    // Handle expiration.
    //
    $eyear = $PmCaltyear;
    $emonth = $PmCaltmonth;
    $eday = $PmCaltday;
    if ($expire != 'true' && $expire != 'false') {
        // expire could be a day delta off from today
        //
        if ($expire <= 1780 && $expire >= -1780) {
            $expire_time = time() + $expire * 86400;
            $emonth = date("m", $expire_time);
            $eyear = date("Y", $expire_time);
            $eday = date("d", $expire_time);
        }
    }
    // Handle stop after days.
    //
    $syear = 0;
    $smonth = 0;
    $sday = 0;
    if ($stopafter != 'false') {
        // expire could be a day delta off from today
        //
        if ($stopafter <= 1780 && $stopafter >= -1780) {
            $stopafter_time = time() + $stopafter * 86400;
            $smonth = date("m", $stopafter_time);
            $syear = date("Y", $stopafter_time);
            $sday = date("d", $stopafter_time);
        }
    }
    // weekstart should be from 0 to 6.
    // weekstart should be from 0 to 6.
    $weekstart = abs($weekstart) % 7;
    if ($reverse == 'true') {
        $weekstart = (abs($weekstart - 6) + 1) % 7;
    }
    // Begin a new month.
    // If monthsahead is zero, then monthsahead is not used.  Don't go beyond this month.
    // If monthsback is zero, then monthsback is not used, starts with this month (or specified month).
    // If not zero, it is relative to whatever month is set to.
    // We're reindexing to consider months going from 0..11
    // Thus we subtract 1 from month.
    //
    $yearadjust = 0;
    if ($reverse == 'true') {
        $startmonth = $month - 1 + $monthsahead;
        if ($startmonth > 11) {
            $yearadjust = floor($startmonth / 12);
            $year = $year + $yearadjust;
        }
    } else {
        $startmonth = $month - 1 - $monthsback;
        if ($startmonth <= 0) {
            $yearadjust = floor($startmonth / 12);
            $year = $year + $yearadjust;
        }
    }
    $out = "";
    $zebraflag = 0;
    // Adjust month from 0..11 back to 1..12
    //
    $month = (abs($yearadjust * 12) + $startmonth) % 12 + 1;
    // Computer total number of months to display
    //
    $totalmonths = $monthsback + $monthsahead;
    for ($mcount = 0; $mcount <= $totalmonths; $mcount++) {
        // Calculate next month and prev month
        // Used for navigation forward and backward
        //
        if ($month == 12) {
            $nextmonth = 1;
            if ($ayear == "ACAL") {
                $nextyear = "ACAL";
            } else {
                $nextyear = $year + 1;
            }
        } else {
            $nextmonth = $month + 1;
            if ($ayear == "ACAL") {
                $nextyear = "ACAL";
            } else {
                $nextyear = $year;
            }
        }
        if ($month == 1) {
            $prevmonth = 12;
            if ($ayear == "ACAL") {
                $prevyear = "ACAL";
            } else {
                $prevyear = $year - 1;
            }
        } else {
            $prevmonth = $month - 1;
            if ($ayear == "ACAL") {
                $prevyear = "ACAL";
            } else {
                $prevyear = $year;
            }
        }
        // Get number of days in the month, day of week the first day starts on
        // and get month name
        //
        $totaldays = date("t", mktime(0, 0, 0, $month, 1, pmcal_year($year)));
        if ($day > $totaldays) {
            $day = $PmCaltday;
        }
        if ($reverse == 'true') {
            $startdayofweek = date('w', mktime(0, 0, 0, $nextmonth, 1, pmcal_year($nextyear))) - 1;
            if ($startdayofweek < 0) {
                $startdayofweek = 6;
            }
            $startdayofweek = abs($startdayofweek - 6);
        } else {
            $startdayofweek = date('w', mktime(0, 0, 0, $month, 1, pmcal_year($year)));
        }
        // Format monthtitle.
        //
        $m = $month - 1;
        if ($monthtitle[$m] == NULL) {
            // Do not use $day... use 1
            $mt = strftime($monthtitlefmt, mktime(0, 0, 0, $month, 1, pmcal_year($year)));
        } else {
            // This isn't perfect.  Difficulties with apostrophes.
            $mt = strftime(urldecode($monthtitle[$m]), mktime(0, 0, 0, $month, 1, pmcal_year($year)));
        }
        // Fill in array of textual day titles
        // I did this like this so the locale could be changed someday.
        //
        $d = $PmCaltday;
        for ($i = 0; $i < 7; $i++) {
            $titleindex = date("w", mktime(0, 0, 0, $month, $d, pmcal_year($year)));
            if ($dayofweektitle[$titleindex] != NULL) {
                $dayofweektitlefmt = urldecode($dayofweektitle[$titleindex]);
            }
            $title = strftime($dayofweektitlefmt, mktime(0, 0, 0, $month, $d, pmcal_year($year)));
            $dayofweektitle[$titleindex] = $title;
            $d++;
        }
        // It's necessary to force a line break before the (:pmcal:) output.
        //
        if ($callinks != 'false' && $caltype == 'normal') {
            $out .= "\\\\\n";
            // Output Today link
            //
            $cl = "{$PmCalPrefix}todaylink";
            $out .= "%class='{$cl}'%";
            $out .= "[[{$group}?year={$PmCaltyear}&amp;month={$PmCaltmonth}&amp;day={$PmCaltday}{$urladd}|";
            $out .= "Today]]%%\n";
            // Output Extra Included Calendars links
            //
            $cl = sprintf("{$PmCalPrefix}include%slink pmcalincludelink", $cal);
            foreach ($cals as $cal) {
                if ($cal != '') {
                    $out .= "%class='{$cl}'%";
                    $out .= sprintf("[[%s|%s]]\n", $cal, $cal);
                }
            }
        }
        if ($caltype == 'normal') {
            // Note: had to insert some forced returns... still some problems
            // with PmWiki and table begins I guess.
            //
            $out .= "\\\\\n\\\\\n\n";
            // Output monthtitle, the banner with prev and next month links
            //
            $navprevout = strftime($navprev, mktime(0, 0, 0, $prevmonth, $day, pmcal_year($prevyear)));
            $navnextout = strftime($navnext, mktime(0, 0, 0, $nextmonth, $day, pmcal_year($nextyear)));
            $cl = 'pmcal';
            $out .= "(:table ";
            $out .= "class='{$cl}' ";
            $out .= "border=1 cellspacing=0 cellpadding=3 width=100%:)\n";
            $out .= "(:cellnr class='{$PmCalPrefix}monthtitle' colspan=7:)\n";
            // Large one liner broken up into multiple appends
            $out .= "%class='{$PmCalPrefix}navlinks {$PmCalPrefix}navlinksprev'%";
            $out .= "[[{$group}?month={$prevmonth}&amp;day=1&amp;year={$prevyear}{$urladd}|{$navprevout}]] %%";
            $out .= "[[{$group}?month={$month}&amp;day={$day}&amp;year={$year}{$urladd}|{$mt}]]";
            $out .= "%class='{$PmCalPrefix}navlinks {$PmCalPrefix}navlinksnext'%";
            $out .= " [[{$group}?month={$nextmonth}&amp;day=1&amp;year={$nextyear}{$urladd}|{$navnextout}]]%%\n";
            // Output days of week headings
            //
            $ctype = "cellnr";
            for ($i = 0; $i < 7; $i++) {
                $out .= "(:{$ctype} ";
                $out .= "class='{$PmCalPrefix}dayofweektitle' ";
                $out .= "width=10% ";
                $out .= ":)\n";
                $d = ($i + $weekstart) % 7;
                if ($reverse == 'true') {
                    $d = abs($d - 6);
                }
                $out .= "{$dayofweektitle[$d]}\n";
                $ctype = "cell";
            }
            // Output null cells, the empty cells before the first day
            // of the month.
            $ctype = "cellnr";
            for ($i = 0; $i < 7; $i++) {
                $d = ($i + $weekstart) % 7;
                if ($d == $startdayofweek) {
                    break;
                }
                $out .= "(:{$ctype} class='{$PmCalPrefix}null':)\n";
                $ctype = "cell";
            }
        }
        // Output the calendar cells
        // Use a special class for today
        //
        $d = $startdayofweek;
        if ($reverse == 'true') {
            $iday = $totaldays;
        } else {
            $iday = 1;
        }
        // Default flag for monitoring repeated days (included text calendar entries)
        $onedatedone = 0;
        $lyear = 0;
        $lmonth = 0;
        $lday = 0;
        // $i isn't the day now... it's just a counter.
        // $iday is the day now.
        //
        for ($i = 1; $i <= $totaldays; $i++) {
            $dayindex = $d % 7;
            if ($ayear == 'ACAL') {
                $year = 'ACAL';
            } else {
                $year = sprintf("%04d", $year);
            }
            $pmcalpagename = sprintf("%s.%s%02d%02d", $group, $year, $month, $iday);
            // Keep skip here in case we want to use it in caltype=normal??
            //
            $skip = 0;
            if ($expire != 'false') {
                if ($year < $eyear) {
                    $skip = 1;
                } else {
                    if ($year == $eyear && $month < $emonth) {
                        $skip = 1;
                    } else {
                        if ($year == $eyear && $month == $emonth && $iday < $eday) {
                            $skip = 1;
                        }
                    }
                }
            }
            if ($stopafter != 'false') {
                if ($year > $syear) {
                    $skip = 1;
                } else {
                    if ($year == $syear && $month > $smonth) {
                        $skip = 1;
                    } else {
                        if ($year == $syear && $month == $smonth && $iday > $sday) {
                            $skip = 1;
                        }
                    }
                }
            }
            if ($zebra == "resetdaily") {
                $zebraflag = 0;
            }
            $istoday = 0;
            if ($year == $PmCaltyear && $month == $PmCaltmonth && $iday == $PmCaltday) {
                $istoday = 1;
            }
            if ($caltype == 'normal') {
                if ($dayindex == $weekstart) {
                    $ctype = "cellnr";
                } else {
                    $ctype = "cell";
                }
                $cl = "{$PmCalPrefix}day";
                $dn = "{$PmCalPrefix}daynumber";
                if ($istoday) {
                    $cl = "{$PmCalPrefix}today";
                    $dn = "{$dn} {$PmCalPrefix}todaynumber";
                }
                if (!PageExists($pmcalpagename)) {
                    // Bizarre hack added due to PmWiki change.
                    $dn = $dn . " {$PmCalPrefix}createtextlink";
                }
                $out .= sprintf("(:{$ctype} class='%s' height=80px :)\n", $cl);
                $out .= "%class='{$dn}'%";
                $out .= sprintf("[[{$group}.%s%02d%02d?year=%s&amp;month=%s&amp;day=%s%s|%s]]\n", $year, $month, $iday, $year, $month, $iday, $urladd, $iday);
                if ($includes != 'false' && PageExists($pmcalpagename)) {
                    $MaxIncludes++;
                    $out .= sprintf("\\\\\n\n(:include %s %s=%s:)\n", $pmcalpagename, $parasorlines, $normallinesparas);
                }
            } else {
                if ($caltype == "text") {
                    if (!$skip && PageExists($pmcalpagename)) {
                        if ($zebra != 'false' && $zebraflag) {
                            $out .= "(:div id={$PmCalPrefix}zebra:)\n";
                        }
                        if ($textlinks != 'false') {
                            $cl = "{$PmCalPrefix}daytextlink";
                            if ($istoday) {
                                $cl = "{$PmCalPrefix}todaytextlink";
                            }
                            if ($onedate != 'false' && ($lyear != $year || $lmonth != $month || $lday != $iday)) {
                                $onedatedone = 0;
                                $lyear = $year;
                                $lmonth = $month;
                                $lday = $iday;
                            }
                            if (!$onedatedone) {
                                $formatteddate = strftime($textdatefmt, mktime(0, 0, 0, $month, $iday, pmcal_year($year)));
                                if ($textlinks == 'nolinks') {
                                    $out .= sprintf("{$PmCalTextLinkMark}%%class='%s'%%[=%s=]\n", $cl, $formatteddate);
                                } else {
                                    $out .= sprintf("{$PmCalTextLinkMark}%%class='%s'%%[[%s|[=%s=]]]\n", $cl, $pmcalpagename, $formatteddate);
                                }
                                if ($onedate != 'false') {
                                    $onedatedone = 1;
                                }
                            }
                        }
                        if ($includes != 'false') {
                            $MaxIncludes++;
                            $out .= sprintf("(:include %s %s=%s:)\n", $pmcalpagename, $parasorlines, $otherlinesparas);
                        }
                        if ($zebra != 'false' && $zebraflag) {
                            $out .= "(:divend:)\n";
                        }
                        if ($zebraflag) {
                            $zebraflag = 0;
                        } else {
                            $zebraflag = 1;
                        }
                    }
                }
            }
            // Include day pages from other calendars if present.
            // NOTE: The pmcalinclude class will only hold true if no new block construct is begun as a part of
            // the included page.
            //
            foreach ($cals as $cal) {
                if ($cal != '') {
                    $pmcalincpagename = sprintf("%s.%s%02d%02d", $cal, $year, $month, $iday);
                    if (!$skip && PageExists($pmcalincpagename)) {
                        if ($caltype == "text") {
                            if ($zebra != 'false' && $zebraflag) {
                                $out .= "(:div id={$PmCalPrefix}zebra:)\n";
                            }
                            if ($onedate != 'false' && ($lyear != $year || $lmonth != $month || $lday != $iday)) {
                                $onedatedone = 0;
                                $lyear = $year;
                                $lmonth = $month;
                                $lday = $iday;
                            }
                            if (!$onedatedone) {
                                $formatteddate = strftime($textdatefmt, mktime(0, 0, 0, $month, $iday, pmcal_year($year)));
                                $formattedtextcal = sprintf($textcalfmt, $cal);
                                if ($textlinks != 'false') {
                                    $todaycl = "";
                                    if ($istoday) {
                                        $todaycl = sprintf(" {$PmCalPrefix}include%stodaytextlink {$PmCalPrefix}includetodaytextlink", $cal);
                                    }
                                    if ($textlinks == 'nolinks') {
                                        $out .= sprintf("{$PmCalIncludeTextLinkMark}%%class='{$PmCalPrefix}include%stextlink {$PmCalPrefix}includetextlink{$todaycl}'%%[=%s %s=]\n", $cal, $formatteddate, $formattedtextcal);
                                    } else {
                                        $out .= sprintf("{$PmCalIncludeTextLinkMark}%%class='{$PmCalPrefix}include%stextlink {$PmCalPrefix}includetextlink{$todaycl}'%%[[%s|[=%s %s=]]]\n", $cal, $pmcalincpagename, $formatteddate, $formattedtextcal);
                                    }
                                }
                                if ($onedate != 'false') {
                                    $onedatedone = 1;
                                }
                            } elseif ($onedate == "showcals") {
                                $formattedtextcal = sprintf($textcalfmt, $cal);
                                if ($textlinks != 'false') {
                                    $todaycl = "";
                                    if ($istoday) {
                                        $todaycl = sprintf(" {$PmCalPrefix}subinclude%stodaytextlink {$PmCalPrefix}includetodaytextlink", $cal);
                                    }
                                    if ($textlinks == 'nolinks') {
                                        $out .= sprintf("{$PmCalSubIncludeTextLinkMark}%%class='{$PmCalPrefix}subinclude%stextlink {$PmCalPrefix}subincludetextlink{$todaycl}'%%[=%s=]\n", $cal, $formattedtextcal);
                                    } else {
                                        $out .= sprintf("{$PmCalSubIncludeTextLinkMark}%%class='{$PmCalPrefix}subinclude%stextlink {$PmCalPrefix}subincludetextlink{$todaycl}'%%[[%s|[=%s=]]]\n", $cal, $pmcalincpagename, $formattedtextcal);
                                    }
                                }
                            }
                            if ($includes != 'false') {
                                $MaxIncludes++;
                                $out .= sprintf("(:include %s %s=%s:)\n", $pmcalincpagename, $parasorlines, $otherlinesparas);
                            }
                            if ($zebra != 'false' && $zebraflag) {
                                $out .= "(:divend:)\n";
                            }
                            if ($zebraflag) {
                                $zebraflag = 0;
                            } else {
                                $zebraflag = 1;
                            }
                        } else {
                            if ($caltype == "normal") {
                                if ($includes != 'false') {
                                    $formattedcal = sprintf($calfmt, $cal);
                                    $todaycl = "";
                                    if ($istoday) {
                                        $todaycl = sprintf(" {$PmCalPrefix}include%stoday {$PmCalPrefix}includetoday", $cal);
                                    }
                                    $out .= sprintf("%%class='{$PmCalPrefix}include%s {$PmCalPrefix}include{$todaycl}'%%[[%s|%s]]\n", $cal, $pmcalincpagename, $formattedcal);
                                    $MaxIncludes++;
                                    $out .= sprintf("(:include %s %s=%s:)\n", $pmcalincpagename, $parasorlines, $normallinesparas);
                                }
                            }
                        }
                    }
                }
            }
            foreach ($acals as $acal) {
                if ($acal != '') {
                    $pmcalincpagename = sprintf("%s.ACAL%02d%02d", $acal, $month, $iday);
                    if (!$skip && PageExists($pmcalincpagename)) {
                        if ($caltype == "text") {
                            if ($zebra != 'false' && $zebraflag) {
                                $out .= "(:div id={$PmCalPrefix}zebra:)\n";
                            }
                            if ($onedate != 'false' && ($lyear != $year || $lmonth != $month || $lday != $iday)) {
                                $onedatedone = 0;
                                $lyear = $year;
                                $lmonth = $month;
                                $lday = $iday;
                            }
                            if (!$onedatedone) {
                                $formatteddate = strftime($textdatefmt, mktime(0, 0, 0, $month, $iday, pmcal_year($year)));
                                $formattedtextcal = sprintf($textacalfmt, $acal);
                                if ($textlinks != 'false') {
                                    $todaycl = "";
                                    if ($istoday) {
                                        $todaycl = sprintf(" {$PmCalPrefix}include%stodaytextlink {$PmCalPrefix}includetodaytextlink", $cal);
                                    }
                                    if ($textlinks == 'nolinks') {
                                        $out .= sprintf("{$PmCalACALTextLinkMark}%%class='{$PmCalPrefix}include%stextlink {$PmCalPrefix}includetextlink{$todaycl}'%%[=%s %s=]\n", $acal, $formatteddate, $formattedtextcal);
                                    } else {
                                        $out .= sprintf("{$PmCalACALTextLinkMark}%%class='{$PmCalPrefix}include%stextlink {$PmCalPrefix}includetextlink{$todaycl}'%%[[%s|[=%s %s=]]]\n", $acal, $pmcalincpagename, $formatteddate, $formattedtextcal);
                                    }
                                }
                                if ($onedate != 'false') {
                                    $onedatedone = 1;
                                }
                            } elseif ($onedate == "showcals") {
                                $formattedtextcal = sprintf($textacalfmt, $acal);
                                if ($textlinks != 'false') {
                                    $todaycl = "";
                                    if ($istoday) {
                                        $todaycl = sprintf(" {$PmCalPrefix}sbuinclude%stodaytextlink {$PmCalPrefix}subincludetodaytextlink", $cal);
                                    }
                                    if ($textlinks == 'nolinks') {
                                        $out .= sprintf("{$PmCalSubACALTextLinkMark}%%class='{$PmCalPrefix}subinclude%stextlink {$PmCalPrefix}subincludetextlink{$todaycl}'%%[=%s=]\n", $cal, $formattedtextcal);
                                    } else {
                                        $out .= sprintf("{$PmCalSubACALTextLinkMark}%%class='{$PmCalPrefix}subinclude%stextlink {$PmCalPrefix}subincludetextlink{$todaycl}'%%[[%s|[=%s=]]]\n", $cal, $pmcalincpagename, $formattedtextcal);
                                    }
                                }
                            }
                            if ($includes != 'false') {
                                $MaxIncludes++;
                                $out .= sprintf("(:include %s %s=%s:)\n", $pmcalincpagename, $parasorlines, $otherlinesparas);
                            }
                            if ($zebra != 'false' && $zebraflag) {
                                $out .= "(:divend:)\n";
                            }
                            if ($zebraflag) {
                                $zebraflag = 0;
                            } else {
                                $zebraflag = 1;
                            }
                        } else {
                            if ($caltype == "normal") {
                                if ($includes != 'false') {
                                    $formattedcal = sprintf($acalfmt, $acal);
                                    $todaycl = "";
                                    if ($istoday) {
                                        $todaycl = sprintf(" {$PmCalPrefix}include%stoday {$PmCalPrefix}includetoday", $cal);
                                    }
                                    $out .= sprintf("%%class='{$PmCalPrefix}include%s {$PmCalPrefix}include{$todaycl}'%%[[%s|%s]]\n", $acal, $pmcalincpagename, $formattedcal);
                                    $MaxIncludes++;
                                    $out .= sprintf("(:include %s %s=%s:)\n", $pmcalincpagename, $parasorlines, $normallinesparas);
                                }
                            }
                        }
                    }
                }
            }
            if ($reverse == 'true') {
                $iday--;
            } else {
                $iday++;
            }
            $d++;
        }
        // Output null cells, the empty cells after the last day
        // of the month.
        //
        if ($caltype == 'normal') {
            $dayindex = ($d + 7 - $weekstart) % 7;
            if ($dayindex != 0) {
                for ($i = $dayindex; $i < 7; $i++) {
                    $ctype = "cell";
                    $out .= "(:{$ctype} class='{$PmCalPrefix}null':)\n";
                }
            }
            // End the calendar table
            //
            $out .= "(:tableend:)\n";
        }
        if ($reverse == 'true') {
            $year = $prevyear;
            $month = $prevmonth;
        } else {
            $year = $nextyear;
            $month = $nextmonth;
        }
    }
    //end of  month loop
    PRR();
    return $out;
}
Ejemplo n.º 27
0
function HandleRss($pagename)
{
    global $RssMaxItems, $RssSourceSize, $RssDescSize, $RssChannelFmt, $RssChannelDesc, $RssTimeFmt, $RssChannelBuildDate, $RssItemsRDFList, $RssItemsRDFListFmt, $RssItems, $RssItemFmt, $HandleRssFmt, $FmtV;
    $t = ReadTrail($pagename, $pagename);
    $page = RetrieveAuthPage($pagename, 'read', false);
    if (!$page) {
        Abort("?cannot read {$pagename}");
    }
    $cbgmt = $page['time'];
    $r = array();
    for ($i = 0; $i < count($t) && count($r) < $RssMaxItems; $i++) {
        if (!PageExists($t[$i]['pagename'])) {
            continue;
        }
        $page = RetrieveAuthPage($t[$i]['pagename'], 'read', false);
        Lock(0);
        if (!$page) {
            continue;
        }
        $text = MarkupToHTML($t[$i]['pagename'], substr($page['text'], 0, $RssSourceSize));
        $text = entityencode(preg_replace("/<.*?>/s", "", $text));
        preg_match("/^(.{0,{$RssDescSize}}\\s)/s", $text, $match);
        $r[] = array('name' => $t[$i]['pagename'], 'time' => $page['time'], 'desc' => $match[1] . " ...", 'author' => $page['author']);
        if ($page['time'] > $cbgmt) {
            $cbgmt = $page['time'];
        }
    }
    SDV($RssChannelBuildDate, entityencode(gmdate('D, d M Y H:i:s \\G\\M\\T', $cbgmt)));
    SDV($RssChannelDesc, entityencode(FmtPageName('$Group.$Title', $pagename)));
    foreach ($r as $page) {
        $FmtV['$RssItemPubDate'] = gmstrftime($RssTimeFmt, $page['time']);
        $FmtV['$RssItemDesc'] = $page['desc'];
        $FmtV['$RssItemAuthor'] = $page['author'];
        $RssItemsRDFList[] = entityencode(FmtPageName($RssItemsRDFListFmt, $page['name']));
        $RssItems[] = entityencode(FmtPageName($RssItemFmt, $page['name']));
    }
    header("Content-type: text/xml");
    PrintFmt($pagename, $HandleRssFmt);
    exit;
}
Ejemplo n.º 28
0
function FPLTemplate($pagename, &$matches, $opt)
{
    global $Cursor, $FPLFormatOpt, $FPLTemplatePageFmt;
    SDV($FPLTemplatePageFmt, array('{$FullName}', '{$SiteGroup}.LocalTemplates', '{$SiteGroup}.PageListTemplates'));
    StopWatch("FPLTemplate begin");
    $template = @$opt['template'];
    if (!$template) {
        $template = @$opt['fmt'];
    }
    list($tname, $qf) = explode('#', $template, 2);
    if ($tname) {
        $tname = array(MakePageName($pagename, $tname));
    } else {
        $tname = (array) $FPLTemplatePageFmt;
    }
    foreach ($tname as $t) {
        $t = FmtPageName($t, $pagename);
        if (!PageExists($t)) {
            continue;
        }
        if ($qf) {
            $t .= "#{$qf}";
        }
        $ttext = IncludeText($pagename, $t, true);
        if (!$qf || strpos($ttext, "[[#{$qf}]]") !== false) {
            break;
        }
    }
    ##   remove any anchor markups to avoid duplications
    $ttext = preg_replace('/\\[\\[#[A-Za-z][-.:\\w]*\\]\\]/', '', $ttext);
    ##   save any escapes
    $ttext = MarkupEscape($ttext);
    $matches = array_values(MakePageList($pagename, $opt, 0));
    if (@$opt['count']) {
        array_splice($matches, $opt['count']);
    }
    $savecursor = $Cursor;
    $pagecount = 0;
    $groupcount = 0;
    $grouppagecount = 0;
    $pseudovars = array('{$$PageCount}' => &$pagecount, '{$$GroupCount}' => &$groupcount, '{$$GroupPageCount}' => &$grouppagecount);
    foreach (preg_grep('/^[\\w$]/', array_keys($opt)) as $k) {
        if (!is_array($opt[$k])) {
            $pseudovars["{\$\${$k}}"] = htmlspecialchars($opt[$k], ENT_NOQUOTES);
        }
    }
    $vk = array_keys($pseudovars);
    $vv = array_values($pseudovars);
    $lgroup = '';
    $out = '';
    foreach ($matches as $i => $pn) {
        $prev = (string) @$matches[$i - 1];
        $next = (string) @$matches[$i + 1];
        $Cursor['<'] = $Cursor['&lt;'] = $prev;
        $Cursor['='] = $pn;
        $Cursor['>'] = $Cursor['&gt;'] = $next;
        $group = PageVar($pn, '$Group');
        if ($group != $lgroup) {
            $groupcount++;
            $grouppagecount = 0;
        }
        $grouppagecount++;
        $pagecount++;
        $item = str_replace($vk, $vv, $ttext);
        $item = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PVSE(PageVar(\$pn, '\$2', '\$1'))", $item);
        $out .= MarkupRestore($item);
        $lgroup = $group;
    }
    $class = preg_replace('/[^-a-zA-Z0-9\\x80-\\xff]/', ' ', @$opt['class']);
    $div = $class ? "<div class='{$class}'>" : '<div>';
    $out = $div . MarkupToHTML($pagename, $out, array('escape' => 0)) . '</div>';
    StopWatch("FPLTemplate end");
    return $out;
}
Ejemplo n.º 29
0
function EditTemplate($pagename, &$page, &$new) {
  global $EditTemplatesFmt;
  if (@$new['text'] > '') return;
  if (@$_REQUEST['template'] && PageExists($_REQUEST['template'])) {
    $p = RetrieveAuthPage($_REQUEST['template'], 'read', false,
             READPAGE_CURRENT);
    if ($p['text'] > '') $new['text'] = $p['text']; 
    return;
  }
  foreach((array)$EditTemplatesFmt as $t) {
    $p = RetrieveAuthPage(FmtPageName($t,$pagename), 'read', false,
             READPAGE_CURRENT);
    if (@$p['text'] > '') { $new['text'] = $p['text']; return; }
  }
}
Ejemplo n.º 30
0
* Code executed on include
*/
Markup_e('pmgallery', 'inline', "/\\(:pmgallery\\s*(.*?):\\)/s", "Keep(pmGallery(\$m[1]))");
preg_match('!^(.*)(\\.|/)!', $GLOBALS['pagename'], $m);
$pmGroup = $m[1];
// Specifying $pmGallery['virtualgroups'] allows us to prevent "Page not found..." error message showing up
if (!empty($pmGallery['virtualgroups'])) {
    // group names prefixed with '+' will have group-footers auto-created
    $autogroup = in_array('+' . $pmGroup, $pmGallery['virtualgroups']);
    if ($autogroup || in_array($pmGroup, $pmGallery['virtualgroups'])) {
        // prevent "Page not found..." error message showing up in pmGallery groups
        //PageNotFound file doesn't need to exist!
        SDV($GLOBALS['DefaultPageTextFmt'], '(:include {$Group}.pmPageNotFound:)');
        if ($autogroup) {
            $n = $pmGroup . '.GroupFooter';
            if (!PageExists($n) && $n != $GLOBALS['pagename']) {
                ## Add a custom page storage location
                $GLOBALS['PageStorePath'] = dirname(__FILE__) . "/wikilib.d/{\$FullName}";
                $where = count($GLOBALS['WikiLibDirs']);
                if ($where > 1) {
                    $where--;
                }
                array_splice($GLOBALS['WikiLibDirs'], $where, 0, array(new PageStore($GLOBALS['PageStorePath'])));
                // if there is no footer for this group then copy the default over.
                WritePage($n, ReadPage('PmGallery.GroupFooter'));
            }
        }
    }
    $pmGallery['virtualgroups'][0] = trim($pmGallery['virtualgroups'][0], '+');
}
/**