Example #1
0
function bi_HandleUpgrade($src, $auth = 'admin')
{
    global $_GET, $RecipeInfo, $bi_ConvertRules;
    $first = array_keys($bi_ConvertRules);
    $mode = @$_GET['mode'] ? $_GET['mode'] : 'upgrade';
    $version = @$_GET['version'] ? $_GET['version'] : (array_key_exists($RecipeInfo['BlogIt']['Version'], $bi_ConvertRules) ? $RecipeInfo['BlogIt']['Version'] : $first[0]);
    $pl = ListPages('/^(' . (isset($_GET['pattern']) ? str_replace(',', '|', $_GET['pattern']) : $src) . ')/');
    if ($mode == 'upgrade') {
        bi_Convert($src, $auth, $version, $pl, $mode);
    } elseif ($mode == 'convert' || $mode == 'revert') {
        bi_Convert($src, $auth, $mode, $pl, $mode);
    }
    exit;
    #Prevent original page loading.
}
Example #2
0
function GetWikiPages($pattern, $exclude)
{
    $pagelist = ListPages($pattern);
    $grouplist = array();
    foreach ($pagelist as $page) {
        list($group, $name) = explode('.', $page);
        if (stristr($exclude, $name) === FALSE) {
            $grouplist[] = "({$group}.){$name}";
        }
    }
    sort($grouplist);
    return $grouplist;
}
Example #3
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;
}
Example #4
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);
}
Example #5
0
function TSFmtPageList($pagename, $gallery_group, $opt)
{
    global $SearchPatterns, $FPLFunctions;
    global $ThumbShoeImgExt;
    $imgRx = '(' . implode('|', $ThumbShoeImgExt) . ')';
    $pat = (array) @$SearchPatterns['normal'];
    $pat['galleryGroup'] = "/^{$gallery_group}\\./";
    $pat['notImages'] = "!{$imgRx}\$!";
    $pagelist = ListPages($pat);
    sort($pagelist);
    $matches = array();
    foreach ($pagelist as $pagefile) {
        $matches[] = array('pagename' => $pagefile);
    }
    if (preg_match('/^([^=]*)=(.*?)$/', $opt['o'], $mat)) {
        $f[$mat[1]] = $mat[2];
    }
    $fmtfn = @$FPLFunctions[$f['fmt']];
    if (!function_exists($fmtfn)) {
        $fmtfn = 'TSFPLPickPage';
    }
    return $fmtfn($pagename, $matches, $opt);
}
Example #6
0
function ConvertV1WikiD($path) {
  global $WikiDir;
  Lock(2);
  if (!is_dir($path)) {
    Abort("?$path is not an accessible directory");
    exit();
  }
  $WikiV1Dir = new PageStore1x("$path/\$FullName");
  $oldlist = $WikiV1Dir->ls();
  $newlist = ListPages();
  $bothlist = array_intersect($oldlist,$newlist); sort($bothlist);
  $difflist = array_diff($oldlist,$newlist); sort($difflist);
  $bcount = count($bothlist);
  $dcount = count($difflist); 

  echo "
    <html>
    <head>
    <title>Convert v1 pages to v2</title>
    </head>
    <body>
    <h2>Convert and Copy PmWiki v1.x pages into v2.x</h2>
  ";

  $copy = array();
  if (@$_POST['copydiff']) $copy = $difflist;
  if (@$_POST['copyboth']) $copy = array_merge($copy,$bothlist);
  if (@$_POST['copy']) $copy = array_merge($copy,$_POST['copy']);

  if (@$copy) { 
    echo "<p>Okay, I'm now converting the pages you've requested.
       When this is finished, you can see if anything else needs to
       be converted, otherwise you can get rid of the 
       <tt>include_once('scripts/compat1x.php');</tt> and
       <tt>ConvertV1WikiD()</tt> lines that are in your 
       local/config.php file.</p>";
    $copy = array_unique($copy);
    foreach($copy as $p) { 
      echo "<li>Converting $p</li>\n"; 
      $page = $WikiV1Dir->read($p);
      WritePage($p,$page);
    }
    echo "<p>Converted ", count($copy), " pages.</p>\n";
  } else {
    echo "
      <p>This function will migrate pages from a 1.x wiki.d/ directory ($path)
      into your 2.x wiki.d/ directory, converting markups as it proceeds. 
      Note that the files in your 1.x wiki.d/ directory are not affected
      by this script, so if the conversion doesn't work out for any reason
      you still have your original pages lying around.</p>
    ";
  }

  /* now rebuild the lists */
  $oldlist = $WikiV1Dir->ls();
  $newlist = ListPages();
  $bothlist = array_intersect($oldlist,$newlist); sort($bothlist);
  $difflist = array_diff($oldlist,$newlist); sort($difflist);
  $bcount = count($bothlist);
  $dcount = count($difflist); 

 
  echo " <form method='post'> ";

  echo "<h3>Migrate pages from v1 to v2 (don't overwrite existing 
    v2 pages)</h3>";

  if ($difflist) {
    echo "
      <p>The following $dcount pages exist only in the version 1
      wiki.d/ directory.  </p>
      <dd><input type='submit' name='copydiff' value='Copy and convert all
        pages that do not already exist' /></dd>
      <p>or</p><dd><input type='submit' name='copyindv' value='Copy and convert
        pages checked in the list below' /><p></p></dd>
    ";
    foreach($difflist as $p) 
      echo "<dd><input type='checkbox' name='copy[]' value='$p' /> $p</dd>\n";
  } else {
    echo "<p>There aren't any pages in your version 1 wiki.d/ directory that 
      are not already in your version 2 directory.</p>";
  }
  
  echo "<h3>Migrate pages from v1 to v2 (overwrite existing v2 pages)</h3>
    <p>The following $bcount pages exist in <em>both</em> the version 1 and
    version 2 wiki.d/ directories.  If you use one of the buttons below,
    then your converted version 1 pages will <em>overwrite</em> the existing 
    version 2 pages, and you will lose any edits that you might have made
    in the version 2 installation (it's possible that
    this is what you want).</p>
    <dd><input type='submit' name='copyboth' value='Convert and overwrite
      pages that do already exist' /></dd>
    <p>or</p><dd><input type='submit' name='copyindv' value='Convert and
      overwrite pages checked in the list below' /><p></p></dd>
  ";
  foreach($bothlist as $p) 
    echo "<dd><input type='checkbox' name='copy[]' value='$p' /> $p</dd>\n";

  echo "</form></body></html>\n";
  exit();
}
Example #7
0
if (isset($_GET['delete'])) {
    $page_id = $_GET['delete'];
    DeletePage($page_id);
    return;
}
if (isset($_GET['create'])) {
    $create = $_GET['create'];
    if ($create) {
        NewPage();
        return;
    }
}
?>

  	<table width="100%">
      <tr>
 		<td><?php 
ListPages();
?>
</td>
 		<td class="right">
		 	<?php 
echo LinkInternal('<img src="images/add.gif" />&nbsp;Create a Page', '?load=admin&op=pages&create=true');
?>
	 	</td>

	<tr>
	</table>
	</fieldset>
</div>
Example #8
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;
}
Example #9
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);
}
Example #10
0
function EditPage($page_id)
{
    global $db;
    $page_id = addslashes($page_id);
    // If the user has submitted, then process their request.
    if (isset($_POST['processed'])) {
        //Secure our data to prevent injection attacks.
        $title = addslashes($_POST['title']);
        $text = addslashes($_POST['text']);
        if (empty($title) || empty($text)) {
            echo "You must fill everything out before proceeding.";
            return;
        }
        //Update the database with the new data.
        $db->Query("UPDATE bayonet_pages SET title = '{$title}', text = '{$text}' WHERE page_id = '{$page_id}'");
        echo "Page, '{$title}', has been edited.\n";
        //die, because we have completed what we wanted to do.
        return;
    }
    $aid = $_GET['aid'];
    ?>
  
   <table width="100%">
   		<tr>
   			<td><?php 
    ListPages($page_id);
    ?>
</td>
			<td><?php 
    echo LinkInternal('<img src="images/view.gif" />&nbsp;View this Page', '?load=page&id=' . $page_id);
    ?>
</td>
   			<td class="right"><?php 
    echo LinkInternal('<img src="images/delete.gif" />&nbsp;Delete this Page', '?load=admin&op=pages&delete=' . $page_id);
    ?>
</td>
   		</tr>
   </table>
   <hr />
   <table class="cleartable" width="100%" style="height:95%;" cellspacing="0">
   		<tr>
		   <td style="vertical-align:top;">
   				<?php 
    ListArticles($page_id);
    ?>
			</td>
			<td style="width:589px; vertical-align:top; border-left:1px solid #848484;">
   		<?php 
    //if article is set then EditArticle();
    if ($aid > 0) {
        EditArticle($aid);
    }
    ?>
   			</td>
  		</tr>
  </table>
  <?php 
}
Example #11
0
 */
?>
 
 <div style="text-align:left;"><h2>- Manage Pages</h2></div>
<?php 
if (!defined("ADMIN_FILE")) {
    die("Access denied.");
}
include $basedir . 'pages/functions.php';
?>

   <table class="panel" width="100%" cellspacing="0">
   		<tr style="height:435px;">
	       <td class="panel-none">
	       		<?php 
ListPages(0);
?>
		   </td>
		   <td class="panel-box">
<?php 
if (isset($_GET['edit'])) {
    $page_id = $_GET['edit'];
    EditPage($page_id);
} else {
    if (isset($_GET['delete'])) {
        $page_id = $_GET['delete'];
        DeletePage($page_id);
    } else {
        if (isset($_GET['create'])) {
            $create = $_GET['create'];
            if ($create) {
Example #12
0
function icalexportfct($pagename)
{
    global $ICalCalendarTitle, $ICalCalendarGroup, $ICalTimeZone, $ICalFileName;
    global $UploadDir, $UploadPrefixFmt, $UploadUrlFmt, $GroupPattern, $NamePattern, $FarmD, $IsPagePosted;
    global $ScriptUrl;
    // Script only executes if the wiki page is written
    if (!$IsPagePosted) {
        return;
    }
    // Script only executes if the currently saved page is in the $ICalCalendarGroup
    if (!preg_match("/" . $ICalCalendarGroup . "[\\/.]" . $NamePattern . "/i", $pagename)) {
        return;
    }
    $pagelist = ListPages();
    $attachlist = array();
    $locationi18n = FmtPageName("\$[Location]", $pagename);
    $begini18n = FmtPageName("\$[Begin]", $pagename);
    $endi18n = FmtPageName("\$[End]", $pagename);
    $descriptioni18n = FmtPageName("\$[Description]", $pagename);
    $out[] = "BEGIN:VCALENDAR\r\n";
    $out[] = "VERSION:2.0\r\n";
    $out[] = "X-WR-CALNAME:" . $ICalCalendarTitle . "\r\n";
    foreach ($pagelist as $pagename) {
        // we need only search events on wiki sides belonging to group $ICalCalendarGroup
        if (!preg_match("/" . $ICalCalendarGroup . "." . $NamePattern . "/", $pagename)) {
            continue;
        }
        // we read the page and ...
        $rcpage = ReadPage($pagename);
        // ... split the events apart on horizontal ruler
        $calenderEvents = explode("----", $rcpage['text']);
        $acalYear = date("Y", $rcpage['ctime']);
        foreach ($calenderEvents as $eventNumber => $event) {
            if (preg_match("/^(?:!!)(?!!)\\s?(.*)/m", $event, $eventTitle)) {
                preg_match("/^(?:" . $endi18n . ":)\\s*([0-9]{1,2}:[0-9]{1,2}).*\$/m", $event, $eventEnd);
                preg_match("/^(?:" . $begini18n . ":)\\s*([0-9]{1,2}:[0-9]{1,2}).*\$/m", $event, $eventBegin);
                preg_match("/^(?:" . $locationi18n . ":)\\s*(.*)\$/m", $event, $eventLocation);
                preg_match("/^(?:" . $descriptioni18n . ":)\\s*(.*)\$/ms", $event, $eventDescription);
                $eventTitle = $eventTitle[1];
                $eventBegin = $eventBegin[1];
                $eventEnd = $eventEnd[1];
                // uh, why I did the str_replace here?
                $eventLocation = str_replace("\\", "", $eventLocation[1]);
                $eventDescription = str_replace("\\", "", $eventDescription[1]);
                $temp = explode(".", $pagename);
                $out[] = "BEGIN:VEVENT\r\n";
                if (preg_match("/^ACAL/", $temp[1])) {
                    $temp[1] = str_replace("ACAL", date("Y", $acalYear), $temp[1]);
                    $out[] = "RRULE:FREQ=YEARLY;INTERVAL=1\r\n";
                }
                if ($eventBegin && $eventEnd) {
                    $eventBegin = preg_replace('/^([0-9]:)/', '0$1', $eventBegin);
                    $eventBegin = preg_replace('/:([0-9])$/', ':0$1', $eventBegin);
                    $eventEnd = preg_replace('/^([0-9]:)/', '0$1', $eventEnd);
                    $eventEnd = preg_replace('/:([0-9])$/', ':0$1', $eventEnd);
                    $beginn = str_replace(":", "", $eventBegin);
                    $ende = str_replace(":", "", $eventEnd);
                    $out[] = "DTSTART;TZID=" . $ICalTimeZone . ":" . $temp[1] . "T" . $beginn . "00\r\n";
                    $out[] = "DTEND;TZID=" . $ICalTimeZone . ":" . $temp[1] . "T" . $ende . "00\r\n";
                } else {
                    //we say it is a full day event and set the end to the next day
                    // TODO:1 check if date exists and wrap to next month if not
                    $nextDay = $temp[1] + 1;
                    $out[] = "DTSTART;VALUE=DATE:" . $temp[1] . "\r\n";
                    $out[] = "DTEND;VALUE=DATE:" . $nextDay . "\r\n";
                }
                if ($eventLocation) {
                    $out[] = "LOCATION:" . $eventLocation . "\r\n";
                }
                $title = MarkupToHTML($pagename, $eventTitle);
                $title = chop(preg_replace("/<.*?>/s", "", $title));
                $out[] = "SUMMARY:" . $title . "\r\n";
                //Every event needs a clear ID in the iCal protokoll
                $out[] = "UID:" . $pagename . "-" . $eventNumber . "-@" . $_SERVER['HTTP_HOST'] . "\r\n";
                if ($eventDescription) {
                    $infos = MarkupToHTML($pagename, $eventDescription);
                    $infos = preg_replace("/<.*?>/s", "", $infos);
                    $infos = chop($infos);
                    $infos = preg_replace("/\n/s", "\\r\\n", $infos);
                    //Seperates the following URL by two lines
                    $infos = $infos . "\\r\\n\\r\\n";
                } else {
                    $infos = "";
                }
                $out[] = "DESCRIPTION:" . $infos . $ScriptUrl . "/" . $pagename . "\r\n";
                $out[] = "END:VEVENT\r\n";
            }
        }
    }
    $out[] = "END:VCALENDAR\r\n";
    $pagetext = implode("", $out);
    //debugging help: prints out the written iCal file on the wikipage
    #return implode("<br>", $out);
    // writes out the ics file
    $filename = $UploadDir . "/" . $ICalCalendarGroup . "/" . $ICalFileName . ".ics";
    $handle = fopen($filename, "w");
    fwrite($handle, $pagetext);
    fclose($handle);
    chmod($filename, 0777);
    return;
}
function MakeNewTicket($pagename, $grp)
{
    if (!$grp) {
        $grp = PageVar($pagename, '$Group');
    }
    foreach (ListPages("/^{$grp}.\\d{11}/") as $p) {
        $issue = max(@$issue, substr($p, -11));
    }
    $issueday = substr($issue, 0, 8);
    $today = strftime("%Y%m%d", time());
    if ($issueday == $today) {
        $nextissue = $issue + 1;
        $target = $grp . "." . $nextissue;
    } else {
        $target = $grp . "." . $today . "001";
    }
    return $target;
}
Example #14
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>";
    }
}
Example #15
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;
}
Example #16
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);
}
function bi_CategoryList()
{
    global $CategoryGroup;
    $c = ListPages('/^' . $CategoryGroup . '\\./');
    array_walk($c, create_function('&$v,$k,$l', '$v = substr($v,$l);'), strlen($CategoryGroup) + 1);
    return implode(',', $c);
}
Example #18
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;
}
function FmtGroupList($pagename, $opt)
{
    global $SearchPatterns, $FPLFunctions;
    $pagelist = ListPages((array) @$SearchPatterns['normal']);
    sort($pagelist);
    $matches = array();
    foreach ($pagelist as $pagefile) {
        $matches[] = array('pagename' => $pagefile);
    }
    if (preg_match('/^([^=]*)=(.*?)$/', $opt['o'], $mat)) {
        $f[$mat[1]] = $mat[2];
    }
    $fmtfn = @$FPLFunctions[$f['fmt']];
    if (!function_exists($fmtfn)) {
        $fmtfn = 'FPLPickGroup';
    }
    return $fmtfn($pagename, $matches, $opt);
}