Ejemplo n.º 1
0
 function ls($pats=NULL) {
   global $GroupPattern, $NamePattern;
   StopWatch("PageStore::ls begin {$this->dir}");
   $pats=(array)$pats; 
   array_push($pats, "/^$GroupPattern\.$NamePattern$/");
   $dir = $this->pagefile('$Group.$Name');
   $dirlist = array(preg_replace('!/*[^/]*\\$.*$!','',$dir));
   $out = array();
   while (count($dirlist)>0) {
     $dir = array_shift($dirlist);
     $dfp = @opendir($dir); if (!$dfp) { continue; }
     $o = array();
     while ( ($pagefile = readdir($dfp)) !== false) {
       if ($pagefile{0} == '.') continue;
       if (is_dir("$dir/$pagefile"))
         { array_push($dirlist,"$dir/$pagefile"); continue; }
       $o[] = $pagefile;
     }
     closedir($dfp);
     StopWatch("PageStore::ls merge {$this->dir}");
     $out = array_merge($out, MatchPageNames($o, $pats));
   }
   StopWatch("PageStore::ls end {$this->dir}");
   return $out;
 }
Ejemplo n.º 2
0
 function ls($pats = NULL)
 {
     global $GroupPattern, $NamePattern;
     StopWatch("PageStore::ls begin {$this->dirfmt}");
     $pats = (array) $pats;
     array_push($pats, "/^{$GroupPattern}\\.{$NamePattern}\$/");
     $dir = $this->pagefile('$Group.$Name');
     $maxslash = substr_count($dir, '/');
     $dirlist = array(preg_replace('!/*[^/]*\\$.*$!', '', $dir));
     $out = array();
     while (count($dirlist) > 0) {
         $dir = array_shift($dirlist);
         $dfp = @opendir($dir);
         if (!$dfp) {
             continue;
         }
         $dirslash = substr_count($dir, '/') + 1;
         $o = array();
         while (($pagefile = readdir($dfp)) !== false) {
             if ($pagefile[0] == '.') {
                 continue;
             }
             if ($dirslash < $maxslash && is_dir("{$dir}/{$pagefile}")) {
                 array_push($dirlist, "{$dir}/{$pagefile}");
                 continue;
             }
             if ($dirslash == $maxslash) {
                 $o[] = $pagefile;
             }
         }
         closedir($dfp);
         StopWatch("PageStore::ls merge {$this->dirfmt}");
         $out = array_merge($out, MatchPageNames($o, $pats));
     }
     StopWatch("PageStore::ls end {$this->dirfmt}");
     return $out;
 }
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
 function ls($pats = NULL)
 {
     global $GroupPattern, $NamePattern;
     $pats = (array) $pats;
     array_push($pats, "/^{$GroupPattern}\\.{$NamePattern}\$/");
     $dir = $this->pagefile('$Group.$Name');
     $dirlist = array(preg_replace('!/*[^/]*\\$.*$!', '', $dir));
     $out = array();
     while (count($dirlist) > 0) {
         $dir = array_shift($dirlist);
         $dfp = opendir($dir);
         if (!$dfp) {
             continue;
         }
         $o = array();
         while (($pagefile = readdir($dfp)) !== false) {
             if ($pagefile[0] == '.') {
                 continue;
             }
             if (is_dir("{$dir}/{$pagefile}")) {
                 array_push($dirlist, "{$dir}/{$pagefile}");
                 continue;
             }
             if (@$seen[$pagefile]++) {
                 continue;
             }
             $o[] = $pagefile;
         }
         closedir($dfp);
         $out = array_merge($out, MatchPageNames($o, $pats));
     }
     return $out;
 }
Ejemplo n.º 6
0
 function ls($pats = NULL)
 {
     global $UploadDir, $UploadPrefixFmt;
     global $GroupPattern, $NamePattern;
     global $ThumbShoeThumbPrefix, $ThumbShoePageSep;
     StopWatch("ThumbShoePageStore::ls begin {$this->galleryGroup}");
     $pats = (array) $pats;
     $topdir = PageVar($this->galleryGroup . '.' . $this->galleryGroup, '$TSAttachTopDir');
     StopWatch("ThumbShoePageStore::ls topdir={$topdir}");
     $out = array();
     $o = array();
     $dfp = @opendir($topdir);
     if ($dfp) {
         while (($file = readdir($dfp)) !== false) {
             if ($file[0] == '.') {
                 continue;
             }
             if (is_dir("{$topdir}/{$file}")) {
                 $sub_dfp = @opendir("{$topdir}/{$file}");
                 while (($subfile = readdir($sub_dfp)) !== false) {
                     if ($subfile[0] == '.') {
                         continue;
                     }
                     if (is_dir("{$topdir}/{$file}/{$subfile}")) {
                         continue;
                     }
                     if (!preg_match("/{$this->ImgRx}\$/", $subfile)) {
                         continue;
                     }
                     if (preg_match("/^{$ThumbShoeThumbPrefix}/", $subfile)) {
                         continue;
                     }
                     $pn = str_replace('.', '_', $subfile);
                     $pn = "{$file}{$ThumbShoePageSep}" . $pn;
                     $pn = MakePageName($this->galleryGroup . '.' . $this->galleryGroup, $pn);
                     $o[] = $pn;
                     StopWatch("ThumbShoePageStore::ls pn={$pn}");
                 }
                 closedir($sub_dfp);
             } else {
                 if (!preg_match("/{$this->ImgRx}\$/", $file)) {
                     continue;
                 }
                 if (preg_match("/^{$ThumbShoeThumbPrefix}/", $file)) {
                     continue;
                 }
                 $pn = str_replace('.', '_', $file);
                 $pn = MakePageName($this->galleryGroup . '.' . $this->galleryGroup, $pn);
                 $o[] = $pn;
                 StopWatch("ThumbShoePageStore::ls pn={$pn}");
             }
         }
         closedir($dfp);
     }
     StopWatch("ThumbShoePageStore::ls merge {$this->galleryGroup}");
     $out = array_merge($out, MatchPageNames($o, $pats));
     StopWatch("ThumbShoePageStore::ls end {$this->galleryGroup}");
     return $out;
 }
Ejemplo n.º 7
0
function bi_Convert($src, $auth = 'admin', $dataset, $pagelist, $mode)
{
    global $bi_ConvertRules, $bi_TagSeparator, $_GET, $SearchPatterns;
    $datarules = $bi_ConvertRules[$dataset];
    $pagelist = MatchPageNames($pagelist, $SearchPatterns['default']);
    foreach ($pagelist as $i => $pn) {
        list($group, $name) = explode('.', $pn);
        #$name used to derive title.
        $pagetext = '';
        $org = RetrieveAuthPage($pn, $auth, 0, READPAGE_CURRENT);
        echo "<b>{$pn}</b><br/>";
        if (!$org) {
            echo 'No admin privs on page.<br/>';
            continue;
        }
        $entryType = PageTextVar($pn, 'entrytype');
        if ($mode == 'convert' && empty($entryType) || $mode == 'upgrade' && $entryType == 'blog') {
            #populate $new_field_val array for each $new_field_name based on $new_field_rules
            foreach ($datarules['new'] as $new_field_name => $new_field_rules) {
                $new_field_val[$new_field_name] = '';
                #is the new field based on an old_field or was the field defined in the prior version, with the same name?
                if (isset($datarules['old'][$new_field_name])) {
                    $new_field_val[$new_field_name] = PageTextVar($pn, $new_field_name);
                    # Get basic separated list with no formatting
                    if ($datarules['old'][$old_field]['format']) {
                        $new_field_val[$new_field_name] = implode($bi_TagSeparator, preg_match_all('/' . $datarules['old'][$old_field]['format'] . '/', $new_field_val[$new_field_name], $m) ? $m[1] : array());
                    }
                }
                # Set default value if none calculated so far
                if (empty($new_field_val[$new_field_name]) && isset($datarules['new'][$new_field_name]['default'])) {
                    $new_field_val[$new_field_name] = eval('return (' . $datarules['new'][$new_field_name]['default'] . ');');
                }
                # Format the field
                if (isset($datarules['new'][$new_field_name]['format'])) {
                    $new_field_val[$new_field_name] = str_replace('$1', $new_field_val[$new_field_name], $datarules['new'][$new_field_name]['format']);
                } else {
                    $new_field_val[$new_field_name] = '(:' . $new_field_name . ':' . $new_field_val[$new_field_name] . ':)';
                }
                $pagetext .= $new_field_val[$new_field_name] . "\n";
            }
        } elseif ($mode == 'revert' && $entryType == 'blog') {
            $pagetext = PageTextVar($pn, 'entrybody') . "\n\n" . PageTextVar($pn, 'pmmarkup');
        } else {
            echo 'Nothing to ' . $mode . '<br/>';
        }
        if ($_GET['writetofile'] == 'true') {
            if (!empty($pagetext)) {
                $new = $org;
                $new['csum'] = $new['csum:' . $GLOBALS['Now']] = $GLOBALS['ChangeSummary'] = 'BlogIt Format: ' . $mode;
                $new['diffclass'] = 'minor';
                $new['text'] = $pagetext;
                PostPage($pn, $org, $new);
                #Don't need UpdatePage, as we don't require edit functions to run
                echo 'BlogIt page attributes written.<br/>';
            } else {
                echo 'Nothing to write.<br/>';
            }
        }
        echo str_replace("\n", '<br/>', $pagetext . '<br/>');
    }
}
Ejemplo n.º 8
0
 function ls($pats = NULL)
 {
     global $GroupPattern, $NamePattern;
     $pats = (array) $pats;
     array_push($pats, "/^{$GroupPattern}\\.{$NamePattern}\$/");
     $out = array();
     // only one directory, no subdirs
     $dir = $this->dirfmt;
     $dfp = @opendir($dir);
     if (!$dfp) {
         continue;
     }
     $o = array();
     while (($pagefile = readdir($dfp)) !== false) {
         if ($pagefile[0] == '.') {
             continue;
         }
         if (is_dir("{$dir}/{$pagefile}")) {
             continue;
         } else {
             $o[] = $this->cddbGroup . '.' . $this->filepage($pagefile);
         }
     }
     closedir($dfp);
     $out = array_merge($out, MatchPageNames($o, $pats));
     return $out;
 }