示例#1
0
function VarIndexLoad($pagename) {
  global $VarPagesFmt,$VarIndex,$WikiWordPattern;
  static $loaded;
  $VarIndex = (array)@$VarIndex;
  if ($loaded) return;
  foreach($VarPagesFmt as $vf) {
    $v = FmtPageName($vf, $pagename);
    if (@$loaded[$v]) continue;
    $vlist = array($v);
    $t = ReadTrail($pagename,$v);
    if ($t) 
      for($i=0;$i<count($t);$i++) 
        if (@!$loaded[$t[$i]['pagename']]) $vlist[]=$t[$i]['pagename'];
    foreach($vlist as $vname) {
      $vpage = ReadPage($vname, READPAGE_CURRENT); @$loaded[$vname]++;
      if (!$vpage) continue;
      if (!preg_match_all("/\n:\\$([[:upper:]]\\w+):/",@$vpage['text'],$match))
        continue;
      foreach($match[1] as $n) {
        $VarIndex[$n]['pagename'] = $vname;
        $VarIndex[$n]['url'] = FmtPageName("{\$PageUrl}#$n",$vname);
      }
    }
  }
}
示例#2
0
function VarIndexLoad($pagename)
{
    global $VarPagesFmt, $VarIndex, $WikiWordPattern;
    static $loaded;
    if ($loaded) {
        return;
    }
    foreach ($VarPagesFmt as $vf) {
        $v = FmtPageName($vf, $pagename);
        if (@$loaded[$v]) {
            continue;
        }
        $vlist = array($v);
        $t = ReadTrail($pagename, $v);
        if ($t) {
            for ($i = 0; $i < count($t); $i++) {
                if (@(!$loaded[$t[$i]['pagename']])) {
                    $vlist[] = $t[$i]['pagename'];
                }
            }
        }
        foreach ($vlist as $vname) {
            $vpage = ReadPage($vname);
            @$loaded[$vname]++;
            if (!$vpage) {
                continue;
            }
            if (!preg_match_all("/\n:\\\$([[:upper:]]\\w+):/", @$vpage['text'], $match)) {
                continue;
            }
            foreach ($match[1] as $n) {
                $VarIndex[$n]['pagename'] = $vname;
                $VarIndex[$n]['url'] = FmtPageName("\$PageUrl#{$n}", $vname);
            }
        }
    }
}
示例#3
0
function MakePageList($pagename, $opt)
{
    global $MakePageListOpt, $SearchPatterns, $EnablePageListProtect, $PCache, $FmtV;
    StopWatch('MakePageList begin');
    SDVA($MakePageListOpt, array('list' => 'default'));
    $opt = array_merge((array) $MakePageListOpt, $opt);
    $readf = $opt['readf'];
    # we have to read the page if order= is anything but name
    $order = $opt['order'];
    $readf |= $order && $order != 'name' && $order != '-name';
    $pats = @(array) $SearchPatterns[$opt['list']];
    if (@$opt['group']) {
        array_unshift($pats, "/^({$opt['group']})\\./i");
    }
    # inclp/exclp contain words to be included/excluded.
    $inclp = array();
    $exclp = array();
    foreach ((array) @$opt[''] as $i) {
        $inclp[] = '/' . preg_quote($i, '/') . '/i';
    }
    foreach ((array) @$opt['+'] as $i) {
        $inclp[] = '/' . preg_quote($i, '/') . '/i';
    }
    foreach ((array) @$opt['-'] as $i) {
        $exclp[] = '/' . preg_quote($i, '/') . '/i';
    }
    $searchterms = count($inclp) + count($exclp);
    $readf += $searchterms;
    # forced read if incl/excl
    if (@$opt['trail']) {
        $trail = ReadTrail($pagename, $opt['trail']);
        foreach ($trail as $tstop) {
            $pn = $tstop['pagename'];
            $list[] = $pn;
            $tstop['parentnames'] = array();
            PCache($pn, $tstop);
        }
        foreach ($trail as $tstop) {
            $PCache[$tstop['pagename']]['parentnames'][] = $trail[$tstop['parent']]['pagename'];
        }
    } else {
        $list = ListPages($pats);
    }
    if (IsEnabled($EnablePageListProtect, 0)) {
        $readf = 1000;
    }
    $matches = array();
    $FmtV['$MatchSearched'] = count($list);
    # link= (backlinks)
    if (@$opt['link']) {
        $link = MakePageName($pagename, $opt['link']);
        $linkpat = "/(^|,){$link}(,|\$)/i";
        $readf++;
        $xlist = BacklinksTo($link, false);
        $list = array_diff($list, $xlist);
    }
    $xlist = array();
    StopWatch('MakePageList scan');
    foreach ((array) $list as $pn) {
        if ($readf) {
            $page = $readf >= 1000 ? RetrieveAuthPage($pn, 'read', false, READPAGE_CURRENT) : ReadPage($pn, READPAGE_CURRENT);
            if (!$page) {
                continue;
            }
            if (@$linkpat && !preg_match($linkpat, @$page['targets'])) {
                $PCache[$pn]['targets'] = @$page['targets'];
                $xlist[] = $pn;
                continue;
            }
            if ($searchterms) {
                $text = $pn . "\n" . @$page['targets'] . "\n" . @$page['text'];
                foreach ($inclp as $i) {
                    if (!preg_match($i, $text)) {
                        continue 2;
                    }
                }
                foreach ($exclp as $i) {
                    if (preg_match($i, $text)) {
                        continue 2;
                    }
                }
            }
            $page['size'] = strlen(@$page['text']);
        } else {
            $page = array();
        }
        $page['pagename'] = $page['name'] = $pn;
        PCache($pn, $page);
        $matches[] =& $PCache[$pn];
    }
    StopWatch('MakePageList sort');
    SortPageList($matches, $order);
    StopWatch('MakePageList update');
    if ($xlist) {
        LinkIndexUpdate($xlist);
    }
    StopWatch('MakePageList end');
    return $matches;
}
示例#4
0
文件: rss.php 项目: BogusCurry/pmwiki
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;
}
示例#5
0
function MakeTrailPath($pagename,$trailname) {
  global $TrailPathSep;
  SDV($TrailPathSep,' | ');
  $t = ReadTrail($pagename,$trailname);
  $crumbs = '';
  for($i=0;$i<count($t);$i++) {
    if ($t[$i]['pagename']==$pagename) {
      while (@$t[$i]['depth']>0) {
        $crumbs = $TrailPathSep.$t[$i]['markup'].$crumbs;
        $i = @$t[$i]['parent'];
      }
      return "<span class='wikitrail'>$trailname$crumbs</span>";
    }
  }
  return $trailname;
}
示例#6
0
function PageListSources(&$list, &$opt, $pn, &$page) {
  global $SearchPatterns;

  StopWatch('PageListSources begin');
  ## add the list= option to our list of pagename filter patterns
  $opt['=pnfilter'] = array_merge((array)@$opt['=pnfilter'], 
                                  (array)@$SearchPatterns[$opt['list']]);

  if (@$opt['group']) $opt['=pnfilter'][] = FixGlob($opt['group'], '$1$2.*');
  if (@$opt['name']) $opt['=pnfilter'][] = FixGlob($opt['name'], '$1*.$2');

  if (@$opt['trail']) {
    $trail = ReadTrail($pn, $opt['trail']);
    $tlist = array();
    foreach($trail as $tstop) {
      $n = $tstop['pagename'];
      $tlist[] = $n;
      $tstop['parentnames'] = array();
      PCache($n, $tstop);
    }
    foreach($trail as $tstop) 
      $PCache[$tstop['pagename']]['parentnames'][] = 
        @$trail[$tstop['parent']]['pagename'];
    if (!@$opt['=cached']) $list = MatchPageNames($tlist, $opt['=pnfilter']);
  } else if (!@$opt['=cached']) $list = ListPages($opt['=pnfilter']);

  StopWatch("PageListSources end count=".count($list));
  return 0;
}
示例#7
0
function FmtPageList($fmt, $pagename, $opt)
{
    global $GroupPattern, $SearchPatterns, $FmtV, $FPLFunctions;
    $opt = array_merge(@$_REQUEST, $opt);
    if (!$opt['q']) {
        $opt['q'] = stripmagic(@$_REQUEST['q']);
    }
    if (!$opt['q']) {
        return;
    }
    $terms = preg_split('/((?<!\\S)[-+]?[\'"].*?[\'"](?!\\S)|\\S+)/', $opt['q'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
    if (preg_match("!^({$GroupPattern}(\\|{$GroupPattern})*)?/!i", @$terms[0], $match)) {
        $opt['group'] = @$match[1];
        $terms[0] = str_replace(@$match[1] . '/', '', $terms[0]);
    }
    $excl = array();
    $incl = array();
    foreach ($terms as $t) {
        if (trim($t) == '') {
            continue;
        }
        if (preg_match('/^([^\'":=]*)[:=]([\'"]?)(.*?)\\2$/', $t, $match)) {
            $opt[$match[1]] = $match[3];
            continue;
        }
        preg_match('/^([-+]?)([\'"]?)(.+?)\\2$/', $t, $match);
        if ($match[1] == '-') {
            $excl[] = $match[3];
        } else {
            $incl[] = $match[3];
        }
    }
    $show = isset($opt['list']) ? $opt['list'] : 'default';
    $pats = (array) @$SearchPatterns[$show];
    if (@$opt['group']) {
        array_unshift($pats, "/^({$opt['group']})\\./i");
    }
    if (@$opt['trail']) {
        $t = ReadTrail($pagename, $opt['trail']);
        foreach ($t as $pagefile) {
            $pagelist[] = $pagefile['pagename'];
        }
    } else {
        $pagelist = ListPages($pats);
    }
    $matches = array();
    $searchterms = count($excl) + count($incl);
    foreach ($pagelist as $pagefile) {
        $page = ReadPage($pagefile);
        Lock(0);
        if (!$page) {
            continue;
        }
        if ($searchterms) {
            $text = $pagefile . "\n" . @$page['text'] . "\n" . @$page['targets'];
            foreach ($excl as $t) {
                if (stristr($text, $t)) {
                    continue 2;
                }
            }
            foreach ($incl as $t) {
                if (!stristr($text, $t)) {
                    continue 2;
                }
            }
        }
        $matches[] = array('pagename' => $pagefile, 'size' => strlen(@$page['text']), 'author' => @$page['author'], 'time' => $page['time']);
    }
    sort($matches);
    $FmtV['$MatchCount'] = count($matches);
    $FmtV['$MatchSearched'] = count($pagelist);
    $FmtV['$Needle'] = $opt['q'];
    $fmtfn = @$FPLFunctions[$opt['fmt']];
    if (!function_exists($fmtfn)) {
        $fmtfn = 'FPLByGroup';
    }
    $FmtV['$MatchList'] = $fmtfn($pagename, $matches, $opt);
    return FmtPageName($fmt, $pagename);
}
示例#8
0
function NotifyUpdate($pagename, $dir = '')
{
    global $NotifyList, $NotifyListPageFmt, $NotifyFile, $IsPagePosted, $FmtV, $NotifyTimeFmt, $NotifyItemFmt, $SearchPatterns, $NotifySquelch, $NotifyDelay, $Now, $NotifySubjectFmt, $NotifyBodyFmt, $NotifyHeaders, $NotifyParameters;
    $abort = ignore_user_abort(true);
    if ($dir) {
        flush();
        chdir($dir);
    }
    $GLOBALS['EnableRedirect'] = 0;
    ##   Read in the current notify configuration
    $pn = FmtPageName($NotifyListPageFmt, $pagename);
    $npage = ReadPage($pn, READPAGE_CURRENT);
    preg_match_all('/^[\\s*:#->]*(notify[:=].*)/m', $npage['text'], $nlist);
    $nlist = array_merge((array) @$NotifyList, (array) @$nlist[1]);
    if (!$nlist) {
        return;
    }
    ##   make sure other processes are locked out
    Lock(2);
    ##   let's load the current .notifylist table
    $nfile = FmtPageName($NotifyFile, $pagename);
    $nfp = @fopen($nfile, 'r');
    if ($nfp) {
        ##   get our current squelch and delay timestamps
        clearstatcache();
        $sz = filesize($nfile);
        list($nextevent, $firstpost) = explode(' ', rtrim(fgets($nfp, $sz)));
        ##   restore our notify array
        $notify = unserialize(fgets($nfp, $sz));
        fclose($nfp);
    }
    if (!is_array($notify)) {
        $notify = array();
    }
    ##   if this is for a newly posted page, get its information
    if ($IsPagePosted) {
        $page = ReadPage($pagename, READPAGE_CURRENT);
        $FmtV['$PostTime'] = strftime($NotifyTimeFmt, $Now);
        $item = urlencode(FmtPageName($NotifyItemFmt, $pagename));
        if ($firstpost < 1) {
            $firstpost = $Now;
        }
    }
    foreach ($nlist as $n) {
        $opt = ParseArgs($n);
        $mailto = preg_split('/[\\s,]+/', $opt['notify']);
        if (!$mailto) {
            continue;
        }
        if ($opt['squelch']) {
            foreach ($mailto as $m) {
                $squelch[$m] = $opt['squelch'];
            }
        }
        if (!$IsPagePosted) {
            continue;
        }
        if ($opt['link']) {
            $link = MakePageName($pagename, $opt['link']);
            if (!preg_match("/(^|,){$link}(,|\$)/i", $page['targets'])) {
                continue;
            }
        }
        $pats = @(array) $SearchPatterns[$opt['list']];
        if ($opt['group']) {
            $pats[] = FixGlob($opt['group'], '$1$2.*');
        }
        if ($opt['name']) {
            $pats[] = FixGlob($opt['name'], '$1*.$2');
        }
        if ($pats && !MatchPageNames($pagename, $pats)) {
            continue;
        }
        if ($opt['trail']) {
            $trail = ReadTrail($pagename, $opt['trail']);
            for ($i = 0; $i < count($trail); $i++) {
                if ($trail[$i]['pagename'] == $pagename) {
                    break;
                }
            }
            if ($i >= count($trail)) {
                continue;
            }
        }
        foreach ($mailto as $m) {
            $notify[$m][] = $item;
        }
    }
    $nnow = time();
    if ($nnow < $firstpost + $NotifyDelay) {
        $nextevent = $firstpost + $NotifyDelay;
    } else {
        $firstpost = 0;
        $nextevent = $nnow + 86400;
        $mailto = array_keys($notify);
        $subject = FmtPageName($NotifySubjectFmt, $pagename);
        $body = FmtPageName($NotifyBodyFmt, $pagename);
        foreach ($mailto as $m) {
            $msquelch = @$notify[$m]['lastmail'] + (@$squelch[$m] ? $squelch[$m] : $NotifySquelch);
            if ($nnow < $msquelch) {
                if ($msquelch < $nextevent && count($notify[$m]) > 1) {
                    $nextevent = $msquelch;
                }
                continue;
            }
            unset($notify[$m]['lastmail']);
            if (!$notify[$m]) {
                unset($notify[$m]);
                continue;
            }
            $mbody = str_replace('$NotifyItems', urldecode(implode("\n", $notify[$m])), $body);
            if ($NotifyParameters) {
                mail($m, $subject, $mbody, $NotifyHeaders, $NotifyParameters);
            } else {
                mail($m, $subject, $mbody, $NotifyHeaders);
            }
            $notify[$m] = array('lastmail' => $nnow);
        }
    }
    ##   save the updated notify status
    $nfp = @fopen($nfile, "w");
    if ($nfp) {
        fputs($nfp, "{$nextevent} {$firstpost}\n");
        fputs($nfp, serialize($notify) . "\n");
        fclose($nfp);
    }
    Lock(0);
    return true;
}
示例#9
0
function MakePageList($pagename, $opt, $retpages = 1)
{
    global $MakePageListOpt, $SearchPatterns, $EnablePageListProtect, $PCache, $FmtV;
    StopWatch('MakePageList begin');
    SDVA($MakePageListOpt, array('list' => 'default'));
    $opt = array_merge((array) $MakePageListOpt, $opt);
    $readf = @$opt['readf'];
    # we have to read the page if order= is anything but name
    $order = @$opt['order'];
    $readf |= $order && $order != 'name' && $order != '-name';
    $pats = @(array) $SearchPatterns[$opt['list']];
    if (@$opt['group']) {
        $pats[] = FixGlob($opt['group'], '$1$2.*');
    }
    if (@$opt['name']) {
        $pats[] = FixGlob($opt['name'], '$1*.$2');
    }
    # inclp/exclp contain words to be included/excluded.
    $incl = array();
    $inclp = array();
    $inclx = false;
    $excl = array();
    $exclp = '';
    foreach ((array) @$opt[''] as $i) {
        $incl[] = $i;
    }
    foreach ((array) @$opt['+'] as $i) {
        $incl[] = $i;
    }
    foreach ((array) @$opt['-'] as $i) {
        $excl[] = $i;
    }
    foreach ($incl as $i) {
        $inclp[] = '$' . preg_quote($i) . '$i';
        $inclx |= preg_match('[^\\w\\x80-\\xff]', $i);
    }
    if ($excl) {
        $exclp = '$' . implode('|', array_map('preg_quote', $excl)) . '$i';
    }
    $searchterms = count($incl) + count($excl);
    $readf += $searchterms;
    # forced read if incl/excl
    if (@$opt['trail']) {
        $trail = ReadTrail($pagename, $opt['trail']);
        $list = array();
        foreach ($trail as $tstop) {
            $pn = $tstop['pagename'];
            $list[] = $pn;
            $tstop['parentnames'] = array();
            PCache($pn, $tstop);
        }
        foreach ($trail as $tstop) {
            $PCache[$tstop['pagename']]['parentnames'][] = @$trail[$tstop['parent']]['pagename'];
        }
    } else {
        $list = ListPages($pats);
    }
    if (IsEnabled($EnablePageListProtect, 1)) {
        $readf = 1000;
    }
    $matches = array();
    $FmtV['$MatchSearched'] = count($list);
    $terms = $incl ? PageIndexTerms($incl) : array();
    if (@$opt['link']) {
        $link = MakePageName($pagename, $opt['link']);
        $linkp = "/(^|,){$link}(,|\$)/i";
        $terms[] = " {$link} ";
        $readf++;
    }
    if ($terms) {
        $xlist = PageIndexGrep($terms, true);
        $a = count($list);
        $list = array_diff($list, $xlist);
        $a -= count($list);
        StopWatch("MakePageList: PageIndex filtered {$a} pages");
    }
    $xlist = array();
    StopWatch('MakePageList scanning ' . count($list) . " pages, readf={$readf}");
    foreach ((array) $list as $pn) {
        if ($readf) {
            $page = $readf >= 1000 ? RetrieveAuthPage($pn, 'read', false, READPAGE_CURRENT) : ReadPage($pn, READPAGE_CURRENT);
            if (!$page) {
                continue;
            }
            if (@$linkp && !preg_match($linkp, @$page['targets'])) {
                $xlist[] = $pn;
                continue;
            }
            if ($searchterms) {
                $text = $pn . "\n" . @$page['targets'] . "\n" . @$page['text'];
                if ($exclp && preg_match($exclp, $text)) {
                    continue;
                }
                foreach ($inclp as $i) {
                    if (!preg_match($i, $text)) {
                        if (!$inclx) {
                            $xlist[] = $pn;
                        }
                        continue 2;
                    }
                }
            }
            $page['size'] = strlen(@$page['text']);
        } else {
            $page = array();
        }
        $page['pagename'] = $page['name'] = $pn;
        PCache($pn, $page);
        $matches[] = $pn;
    }
    StopWatch('MakePageList sort');
    if ($order) {
        SortPageList($matches, $order);
    }
    if ($xlist) {
        register_shutdown_function('flush');
        register_shutdown_function('PageIndexUpdate', $xlist, getcwd());
    }
    StopWatch('MakePageList end');
    if ($retpages) {
        for ($i = 0; $i < count($matches); $i++) {
            $matches[$i] =& $PCache[$matches[$i]];
        }
    }
    return $matches;
}
示例#10
0
文件: rss.php 项目: BogusCurry/pmwiki
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;
}
示例#11
0
function FmtPageList($fmt, $pagename, $opt)
{
    global $GroupPattern, $SearchPatterns, $FmtV, $FPLFunctions, $EnablePageListProtect;
    if (isset($_REQUEST['q']) && $_REQUEST['q'] == '') {
        $_REQUEST['q'] = "''";
    }
    $opt = array_merge($opt, @$_REQUEST);
    $rq = htmlspecialchars(stripmagic(@$_REQUEST['q']), ENT_NOQUOTES);
    if (preg_match("!^({$GroupPattern}(\\|{$GroupPattern})*)?/!i", $rq, $match)) {
        $opt['group'] = @$match[1];
        $rq = str_replace(@$match[1] . '/', '', $rq);
    }
    $needle = $opt['o'] . ' ' . $rq;
    $terms = preg_split('/((?<!\\S)[-+]?[\'"].*?[\'"](?!\\S)|\\S+)/', $needle, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
    $excl = array();
    $incl = array();
    foreach ($terms as $t) {
        if (trim($t) == '') {
            continue;
        }
        if (preg_match('/^([^\'":=]*)[:=]([\'"]?)(.*?)\\2$/', $t, $match)) {
            $opt[$match[1]] = $match[3];
            continue;
        }
        preg_match('/^([-+]?)([\'"]?)(.+?)\\2$/', $t, $match);
        if ($match[1] == '-') {
            $excl[] = $match[3];
        } else {
            $incl[] = $match[3];
        }
    }
    if (@$opt['req'] && !$incl && !$excl && !isset($_REQUEST['q'])) {
        return;
    }
    $show = isset($opt['list']) ? $opt['list'] : 'default';
    $pats = (array) @$SearchPatterns[$show];
    if (@$opt['group']) {
        array_unshift($pats, "/^({$opt['group']})\\./i");
    }
    if (@$opt['trail']) {
        $t = ReadTrail($pagename, $opt['trail']);
        foreach ($t as $pagefile) {
            $pagelist[] = $pagefile['pagename'];
        }
    } else {
        $pagelist = ListPages($pats);
    }
    $matches = array();
    $searchterms = count($excl) + count($incl);
    $plprotect = IsEnabled($EnablePageListProtect, 0);
    foreach ($pagelist as $pagefile) {
        if ($plprotect) {
            $page = RetrieveAuthPage($pagefile, 'read', false);
        } else {
            $page = ReadPage($pagefile);
        }
        Lock(0);
        if (!$page) {
            continue;
        }
        if ($searchterms) {
            $text = $pagefile . "\n" . @$page['text'] . "\n" . @$page['targets'];
            foreach ($excl as $t) {
                if (stristr($text, $t)) {
                    continue 2;
                }
            }
            foreach ($incl as $t) {
                if (!stristr($text, $t)) {
                    continue 2;
                }
            }
        }
        $matches[] = array('pagename' => $pagefile, 'size' => strlen(@$page['text']), 'author' => @$page['author'], 'time' => $page['time']);
    }
    sort($matches);
    $FmtV['$MatchCount'] = count($matches);
    $FmtV['$MatchSearched'] = count($pagelist);
    $FmtV['$Needle'] = $needle;
    $GLOBALS['SearchIncl'] = $incl;
    $GLOBALS['SearchExcl'] = $excl;
    $GLOBALS['SearchGroup'] = @$opt['group'];
    $fmtfn = @$FPLFunctions[$opt['fmt']];
    if (!function_exists($fmtfn)) {
        $fmtfn = 'FPLByGroup';
    }
    $FmtV['$MatchList'] = $fmtfn($pagename, $matches, $opt);
    return FmtPageName($fmt, $pagename);
}
示例#12
0
function PageListSources(&$list, &$opt, $pagename, &$page)
{
    global $SearchPatterns;
    StopWatch('PageListSources begin');
    ## add the list= option to our list of pagename filter patterns
    $opt['=pnfilter'] = array_merge(@$opt['=pnfilter'], $SearchPatterns[$opt['list']]);
    if (@$opt['group']) {
        $opt['=pnfilter'][] = FixGlob($opt['group'], '$1$2.*');
    }
    if (@$opt['name']) {
        $opt['=pnfilter'][] = FixGlob($opt['group'], '$1$2.*');
    }
    if (@$opt['trail']) {
        $trail = ReadTrail($pagename, $opt['trail']);
        $list = array();
        foreach ($trail as $tstop) {
            $pn = $tstop['pagename'];
            $list[] = $pn;
            $tstop['parentnames'] = array();
            PCache($pn, $tstop);
        }
        foreach ($trail as $tstop) {
            $PCache[$tstop['pagename']]['parentnames'][] = @$trail[$tstop['parent']]['pagename'];
        }
    } else {
        $list = ListPages($opt['=pnfilter']);
    }
    StopWatch('PageListSources end');
    return 0;
}
示例#13
0
function FmtPageList($fmt, $pagename, $opt)
{
    global $GroupPattern, $SearchPatterns, $FmtV, $FPLFunctions, $EnablePageListProtect;
    if (isset($_REQUEST['q']) && $_REQUEST['q'] == '') {
        $_REQUEST['q'] = "''";
    }
    $opt = array_merge($opt, @$_REQUEST);
    $rq = htmlspecialchars(stripmagic(@$_REQUEST['q']), ENT_NOQUOTES);
    if (preg_match("!^({$GroupPattern}(\\|{$GroupPattern})*)?/!i", $rq, $match)) {
        $opt['group'] = @$match[1];
        $rq = str_replace(@$match[1] . '/', '', $rq);
    }
    $needle = $opt['o'] . ' ' . $rq;
    $opt = array_merge($opt, ParseArgs($needle));
    $excl = (array) @$opt['-'];
    $incl = array_merge((array) @$opt[''], (array) @$opt['+']);
    if (@$opt['req'] && !$incl && !$excl && !isset($_REQUEST['q'])) {
        return;
    }
    $show = isset($opt['list']) ? $opt['list'] : 'default';
    $pats = (array) @$SearchPatterns[$show];
    if (@$opt['group']) {
        array_unshift($pats, "/^({$opt['group']})\\./i");
    }
    if (@$opt['trail']) {
        $t = ReadTrail($pagename, $opt['trail']);
        foreach ($t as $pagefile) {
            $pagelist[] = $pagefile['pagename'];
        }
    } else {
        $pagelist = ListPages($pats);
    }
    $matches = array();
    $searchterms = count($excl) + count($incl);
    $plprotect = IsEnabled($EnablePageListProtect, 0);
    foreach ($pagelist as $pagefile) {
        if ($plprotect) {
            $page = RetrieveAuthPage($pagefile, 'read', false, READPAGE_CURRENT);
        } else {
            $page = ReadPage($pagefile, READPAGE_CURRENT);
        }
        if (!$page) {
            continue;
        }
        if ($searchterms) {
            $text = $pagefile . "\n" . @$page['text'] . "\n" . @$page['targets'];
            foreach ($excl as $t) {
                if (stristr($text, $t)) {
                    continue 2;
                }
            }
            foreach ($incl as $t) {
                if (!stristr($text, $t)) {
                    continue 2;
                }
            }
        }
        $matches[] = array('pagename' => $pagefile, 'size' => strlen(@$page['text']), 'author' => @$page['author'], 'time' => $page['time']);
    }
    sort($matches);
    $FmtV['$MatchCount'] = count($matches);
    $FmtV['$MatchSearched'] = count($pagelist);
    $FmtV['$Needle'] = $needle;
    $GLOBALS['SearchIncl'] = $incl;
    $GLOBALS['SearchExcl'] = $excl;
    $GLOBALS['SearchGroup'] = @$opt['group'];
    $fmtfn = @$FPLFunctions[$opt['fmt']];
    if (!function_exists($fmtfn)) {
        $fmtfn = 'FPLByGroup';
    }
    $FmtV['$MatchList'] = $fmtfn($pagename, $matches, $opt);
    return FmtPageName($fmt, $pagename);
}
function MXRandomPageLink($pagename, $label, $trailname = '', $args)
{
    global $RandomPageNamesUsed;
    $trail = array();
    //if no trailname make trail from all group pages
    if ($trailname == '') {
        if (isset($args['group'])) {
            $group = $args['group'];
        } else {
            $group = PageVar($pagename, '$Group');
        }
        $gplist = ListPages("/^{$group}\\..+/");
        $exclude = array($pagename, $group . '.RecentChanges', $group . '.RecentUploads', $group . '.GroupHeader', $group . '.GroupFooter', $group . '.GroupAttributes');
        if (isset($args['exclude'])) {
            $excl = explode(',', $args['exclude']);
            foreach ($excl as $i => $p) {
                $excl[$i] = MakePageName($group . '.HomePage', $p);
            }
            $exclude = array_merge($exclude, $excl);
        }
        foreach ($gplist as $i => $p) {
            if (in_array($p, $exclude) || in_array($p, (array) $RandomPageNamesUsed)) {
                unset($gplist[$i]);
            }
        }
        sort($gplist);
        foreach ($gplist as $i => $p) {
            $trail[$i]['pagename'] = $p;
        }
    } else {
        $trail = ReadTrail($pagename, $trailname);
    }
    //pick random pagename from trail
    $max = count($trail) - 1;
    $i = rand(0, $max);
    $pn = $trail[$i]['pagename'];
    $RandomPageNamesUsed[] = $pn;
    if ($label == 'title') {
        $label = '+';
    }
    if ($label == '') {
        $label = 'next';
    }
    if ($label == 'name') {
        $label = PageVar($pn, '$Name');
    }
    return "[[{$pn}|{$label}]]";
}