Exemplo n.º 1
0
 function FPLByGroup($pagename, &$matches, $opt)
 {
     global $FPLByGroupStartFmt, $FPLByGroupEndFmt, $FPLByGroupGFmt, $FPLByGroupIFmt, $FPLByGroupOpt;
     SDV($FPLByGroupStartFmt, "<dl class='fplbygroup'>");
     SDV($FPLByGroupEndFmt, '</dl>');
     SDV($FPLByGroupGFmt, "<dt><a href='\$ScriptUrl/\$Group'>\$Group</a> /</dt>\n");
     SDV($FPLByGroupIFmt, "<dd><a href='\$PageUrl'>\$Name</a></dd>\n");
     SDVA($FPLByGroupOpt, array('readf' => 0, 'order' => 'name'));
     $matches = MakePageList($pagename, array_merge((array) $FPLByGroupOpt, $opt), 0);
     if (@$opt['count']) {
         array_splice($matches, $opt['count']);
     }
     if (count($matches) < 1) {
         return '';
     }
     $out = '';
     foreach ($matches as $pn) {
         $pgroup = FmtPageName($FPLByGroupGFmt, $pn);
         if ($pgroup != @$lgroup) {
             $out .= $pgroup;
             $lgroup = $pgroup;
         }
         $out .= FmtPageName($FPLByGroupIFmt, $pn);
     }
     return FmtPageName($FPLByGroupStartFmt, $pagename) . $out . FmtPageName($FPLByGroupEndFmt, $pagename);
 }
function BGetWikiPages($args)
{
    $pages = MakePageList('', $args);
    $grouplist = array();
    foreach ($pages as $page) {
        list($group, $name) = explode('.', $page['name']);
        $grouplist[] = "({$group}.){$name}";
    }
    sort($grouplist);
    return $grouplist;
}
Exemplo n.º 3
0
function FPLGroup($pagename, &$matches, $opt)
{
    global $FPLGroupStartFmt, $FPLGroupIFmt, $FPLGroupEndFmt, $FPLGroupOpt;
    SDV($FPLGroupStartFmt, "<ul class='fplgroup'>");
    SDV($FPLGroupEndFmt, "</ul>");
    SDV($FPLGroupIFmt, "<li><a href='\$ScriptUrl/\$Group'>\$Group</a></li>");
    SDVA($FPLGroupOpt, array('readf' => 0, 'order' => 'name'));
    $matches = MakePageList($pagename, array_merge((array) $FPLGroupOpt, $opt));
    $out = array();
    foreach ($matches as $pc) {
        $group = preg_replace('/\\.[^.]+$/', '', $pc['pagename']);
        if (@(!$seen[$group]++)) {
            $out[] = FmtPageName($FPLGroupIFmt, $pc['pagename']);
            if ($opt['count'] && count($out) >= $opt['count']) {
                break;
            }
        }
    }
    return FmtPageName($FPLGroupStartFmt, $pagename) . implode('', $out) . FmtPageName($FPLGroupEndFmt, $pagename);
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
0
function FPLTemplatePageList($pagename, &$matches, &$opt){
  $matches = array_unique(array_merge((array)$matches, MakePageList($pagename, $opt, 0)));
  ## count matches before any slicing and save value as template var {$$PageListCount}
  $opt['PageListCount'] = count($matches);
}
Exemplo n.º 6
0
function FPLTemplate($pagename, &$matches, $opt)
{
    global $Cursor, $FPLTemplatePageFmt, $RASPageName, $PageListArgPattern;
    SDV($FPLTemplatePageFmt, array('{$FullName}', '{$SiteGroup}.LocalTemplates', '{$SiteGroup}.PageListTemplates'));
    StopWatch("FPLTemplate begin");
    $template = @$opt['template'];
    if (!$template) {
        $template = @$opt['fmt'];
    }
    $ttext = RetrieveAuthSection($pagename, $template, $FPLTemplatePageFmt);
    $ttext = PVSE(Qualify($RASPageName, $ttext));
    ##  save any escapes
    $ttext = MarkupEscape($ttext);
    ##  remove any anchor markups to avoid duplications
    $ttext = preg_replace('/\\[\\[#[A-Za-z][-.:\\w]*\\]\\]/', '', $ttext);
    ##  extract portions of template
    $tparts = preg_split('/\\(:(template)\\s+(\\w+)\\s*(.*?):\\)/i', $ttext, -1, PREG_SPLIT_DELIM_CAPTURE);
    ##  handle (:template defaults:)
    $i = 0;
    while ($i < count($tparts)) {
        if ($tparts[$i] != 'template') {
            $i++;
            continue;
        }
        if ($tparts[$i + 1] != 'defaults' && $tparts[$i + 1] != 'default') {
            $i += 4;
            continue;
        }
        $opt = array_merge(ParseArgs($tparts[$i + 2], $PageListArgPattern), $opt);
        array_splice($tparts, $i, 3);
    }
    SDVA($opt, array('class' => 'fpltemplate', 'wrap' => 'div'));
    ##  get the list of pages
    $matches = array_values(MakePageList($pagename, $opt, 0));
    ##  extract page subset according to 'count=' parameter
    if (@$opt['count']) {
        list($r0, $r1) = CalcRange($opt['count'], count($matches));
        if ($r1 < $r0) {
            $matches = array_reverse(array_slice($matches, $r1 - 1, $r0 - $r1 + 1));
        } else {
            $matches = array_slice($matches, $r0 - 1, $r1 - $r0 + 1);
        }
    }
    $savecursor = $Cursor;
    $pagecount = 0;
    $groupcount = 0;
    $grouppagecount = 0;
    $pseudovars = array('{$$PageCount}' => &$pagecount, '{$$GroupCount}' => &$groupcount, '{$$GroupPageCount}' => &$grouppagecount);
    foreach (preg_grep('/^[\\w$]/', array_keys($opt)) as $k) {
        if (!is_array($opt[$k])) {
            $pseudovars["{\$\${$k}}"] = htmlspecialchars($opt[$k], ENT_NOQUOTES);
        }
    }
    $vk = array_keys($pseudovars);
    $vv = array_values($pseudovars);
    $lgroup = '';
    $out = '';
    foreach ($matches as $i => $pn) {
        $group = PageVar($pn, '$Group');
        if ($group != $lgroup) {
            $groupcount++;
            $grouppagecount = 0;
            $lgroup = $group;
        }
        $grouppagecount++;
        $pagecount++;
        $t = 0;
        while ($t < count($tparts)) {
            if ($tparts[$t] != 'template') {
                $item = $tparts[$t];
                $t++;
            } else {
                list($when, $control, $item) = array_slice($tparts, $t + 1, 3);
                $t += 4;
                if (!$control) {
                    if ($when == 'first' && $i != 0) {
                        continue;
                    }
                    if ($when == 'last' && $i != count($matches) - 1) {
                        continue;
                    }
                } else {
                    if ($when == 'first' || !isset($last[$t])) {
                        $Cursor['<'] = $Cursor['&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']);
    if ($class) {
        $class = " class='{$class}'";
    }
    $wrap = @$opt['wrap'];
    if ($wrap != 'inline') {
        $out = MarkupToHTML($pagename, $out, array('escape' => 0, 'redirect' => 1));
        if ($wrap != 'none') {
            $out = "<div{$class}>{$out}</div>";
        }
    }
    $Cursor = $savecursor;
    StopWatch("FPLTemplate end");
    return $out;
}
Exemplo n.º 7
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>';
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
function FPLTrailTrail($pagename, &$matches, $opt)
{
    if (!@$opt['link']) {
        $opt['link'] = $pagename;
    }
    $matches = MakePageList($pagename, $opt, 0);
    // deal with count
    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);
        }
    }
    if (!@$opt['label']) {
        $opt['label'] = '{$Title}';
    }
    $topt = array();
    $topt['fmt'] = 'fauxtrail';
    $topt['label'] = $opt['label'];
    $out = '';
    $tmatches = array();
    foreach ($matches as $m) {
        $topt['trail'] = $m;
        $topt['trailpage'] = $m;
        $out .= FPLFauxTrail($pagename, $tmatches, $topt);
    }
    return $out;
}
Exemplo n.º 10
0
function FPLTextExtract($pagename, &$matches, $opt)
{
    ##DEBUG	echo "<pre>OPT "; print_r($opt); echo "</pre>";
    global $FmtV, $EnableStopWatch, $KeepToken, $KPV;
    $EnableStopWatch = 1;
    StopWatch('TextExtract pagelist begin');
    $opt['stime'] = strtok(microtime(), ' ') + strtok('');
    $opt['q'] = ltrim($opt['q']);
    foreach ($opt[''] as $k => $v) {
        $opt[''][$k] = htmlspecialchars_decode($v);
    }
    //treat single . search term as request for regex 'all characters'
    if ($opt[''][0] == '.' || $opt['pattern'] == '.') {
        $opt['regex'] = 1;
    }
    //MakePageList() does not evaluate terms as regular expressions, so we save them for later
    if (@$opt['regex'] == 1) {
        $opt['pattern'] = implode(' ', $opt['']);
        unset($opt['']);
    }
    if (@$opt['page']) {
        $opt['name'] .= "," . $opt['page'];
    }
    //allow search of anchor sections
    if ($sa = strpos($opt['name'], '#')) {
        $opt['section'] = strstr($opt['name'], '#');
        $opt['name'] = substr($opt['name'], 0, $sa);
    }
    $list = MakePageList($pagename, $opt, 0);
    //extract page subset according to 'count=' parameter
    if (@$opt['count'] && !$opt['section']) {
        TESliceList($list, $opt);
    }
    return TextExtract($pagename, $list, $opt);
}
function FPLSimpleText($pagename, &$matches, $opt)
{
    $matches = 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);
        }
    }
    $opt['sep'] = @$opt['sep'] ? $opt['sep'] : ",";
    $opt['sep'] = str_replace('\\n', "\n", $opt['sep']);
    if ($opt['sep'] == 'LF') {
        $opt['sep'] = "\n";
    }
    return Keep(implode($opt['sep'], $matches), 'P');
}
Exemplo n.º 12
0
function FPLTemplate($pagename, &$matches, $opt)
{
    global $Cursor, $FPLFormatOpt, $FPLTemplatePageFmt;
    SDV($FPLTemplatePageFmt, '{$SiteGroup}.PageListTemplates');
    $template = @$opt['template'];
    if (!$template) {
        $template = @$opt['fmt'];
    }
    list($tname, $qf) = explode('#', $template, 2);
    if ($tname) {
        $tname = MakePageName($pagename, $tname);
    } else {
        $tname = FmtPageName($FPLTemplatePageFmt, $pagename);
    }
    if ($qf) {
        $tname .= "#{$qf}";
    }
    $ttext = IncludeText($pagename, $tname, true);
    $ttext = preg_replace('/\\[\\[#[A-Za-z][-.:\\w]*\\]\\]/', '', $ttext);
    if (!$opt['order'] && !$opt['trail']) {
        $opt['order'] = 'name';
    }
    $matches = array_values(MakePageList($pagename, $opt, 0));
    if (@$opt['count']) {
        array_splice($matches, $opt['count']);
    }
    $savecursor = $Cursor;
    $pagecount = 0;
    $groupcount = 0;
    $grouppagecount = 0;
    $vk = array('{$PageCount}', '{$GroupCount}', '{$GroupPageCount}');
    $vv = array(&$pagecount, &$groupcount, &$grouppagecount);
    $lgroup = '';
    $out = '';
    foreach ($matches as $i => $pn) {
        $prev = (string) @$matches[$i - 1];
        $next = (string) @$matches[$i + 1];
        $Cursor['<'] = $Cursor['&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;
    }
    return '<div>' . MarkupToHTML($pagename, $out, false) . '</div>';
}
Exemplo n.º 13
0
function HandleFeed($pagename, $auth = 'read') {
  global $FeedFmt, $action, $PCache, $FmtV, $TimeISOZFmt, $RSSTimeFmt,
    $FeedPageListOpt, $FeedCategoryOpt, $FeedTrailOpt,
    $FeedDescPatterns, $CategoryGroup, $EntitiesTable;
  SDV($RSSTimeFmt, 'D, d M Y H:i:s \G\M\T');
  SDV($FeedDescPatterns, 
    array('/<[^>]*$/' => ' ', '/\\w+$/' => '', '/<[^>]+>/' => ''));
  $FeedPageListOpt = (array)@$FeedPageListOpt;
  SDVA($FeedCategoryOpt, array('link' => $pagename));
  SDVA($FeedTrailOpt, array('trail' => $pagename, 'count' => 10));

  $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'] 
        || $_REQUEST['name'])) 
    $opt = $FeedPageListOpt;
  else if (preg_match("/^$CategoryGroup\\./", $pagename)) 
    $opt = $FeedCategoryOpt;
  else if ($action != 'dc') $opt = $FeedTrailOpt;
  else { 
    PCache($pagename, $page); 
    $pagelist = array($pagename); 
  }
  if (!@$pagelist) {
    $opt = array_merge($opt, @$_REQUEST);
    $pagelist = MakePageList($pagename, $opt, 0);
  }

  # process list of pages in feed
  $rdfseq = '';
  $pl = array();
  foreach($pagelist as $pn) {
    if (!PageExists($pn)) continue;
    if (!isset($PCache[$pn]['time'])) 
      { $page = ReadPage($pn, READPAGE_CURRENT); PCache($pn, $page); }
    $pc = & $PCache[$pn];
    $pl[] = $pn;
    $rdfseq .= FmtPageName("<rdf:li resource=\"{\$PageUrl}\" />\n", $pn);
    if ($pc['time'] > $feedtime) $feedtime = $pc['time'];
    if (@$opt['count'] && count($pl) >= $opt['count']) break;
  }
  $pagelist = $pl;

  $FmtV['$FeedRDFSeq'] = $rdfseq;
  $FmtV['$FeedISOTime'] = gmstrftime($TimeISOZFmt, $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'];
    $FmtV['$ItemISOTime'] = gmstrftime($TimeISOZFmt, $page['time']);
    $FmtV['$ItemRSSTime'] = gmdate($RSSTimeFmt, $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);
}