Exemplo n.º 1
0
function PageIndexUpdate($pagelist = NULL, $dir = '') {
  global $EnableReadOnly, $PageIndexUpdateList, $PageIndexFile, 
    $PageIndexTime, $Now;
  if (IsEnabled($EnableReadOnly, 0)) return;
  $abort = ignore_user_abort(true);
  if ($dir) { flush(); chdir($dir); }
  if (is_null($pagelist)) 
    { $pagelist = (array)$PageIndexUpdateList; $PageIndexUpdateList = array(); }
  if (!$pagelist || !$PageIndexFile) return;
  SDV($PageIndexTime, 10);
  $c = count($pagelist); $updatecount = 0;
  StopWatch("PageIndexUpdate begin ($c pages to update)");
  $pagelist = (array)$pagelist;
  $timeout = time() + $PageIndexTime;
  $cmpfn = create_function('$a,$b', 'return strlen($b)-strlen($a);');
  Lock(2);
  $ofp = fopen("$PageIndexFile,new", 'w');
  foreach($pagelist as $pn) {
    if (@$updated[$pn]) continue;
    @$updated[$pn]++;
    if (time() > $timeout) continue;
    $page = ReadPage($pn, READPAGE_CURRENT);
    if ($page) {
      $targets = str_replace(',', ' ', @$page['targets']);
      $terms = PageIndexTerms(array(@$page['text'], $targets, $pn));
      usort($terms, $cmpfn);
      $x = '';
      foreach($terms as $t) { if (strpos($x, $t) === false) $x .= " $t"; }
      fputs($ofp, "$pn:$Now: $targets :$x\n");
    }
    $updatecount++;
  }
  $ifp = @fopen($PageIndexFile, 'r');
  if ($ifp) {
    while (!feof($ifp)) {
      $line = fgets($ifp, 4096);
      while (substr($line, -1, 1) != "\n" && !feof($ifp)) 
        $line .= fgets($ifp, 4096);
      $i = strpos($line, ':');
      if ($i === false) continue;
      $n = substr($line, 0, $i);
      if (@$updated[$n]) continue;
      fputs($ofp, $line);
    }
    fclose($ifp);
  }
  fclose($ofp);
  if (file_exists($PageIndexFile)) unlink($PageIndexFile); 
  rename("$PageIndexFile,new", $PageIndexFile);
  fixperms($PageIndexFile);
  StopWatch("PageIndexUpdate end ($updatecount updated)");
  ignore_user_abort($abort);
}
Exemplo n.º 2
0
function PageIndexUpdate($pagelist, $dir = '')
{
    global $PageIndexFile, $PageIndexTime, $Now;
    $abort = ignore_user_abort(true);
    if ($dir) {
        chdir($dir);
    }
    SDV($PageIndexTime, 10);
    if (!$pagelist || !$PageIndexFile) {
        return;
    }
    $c = count($pagelist);
    StopWatch("PageIndexUpdate begin ({$c} pages to update)");
    $pagelist = (array) $pagelist;
    $timeout = time() + $PageIndexTime;
    $cmpfn = create_function('$a,$b', 'return strlen($b)-strlen($a);');
    Lock(2);
    $ofp = fopen("{$PageIndexFile},new", 'w');
    foreach ($pagelist as $pn) {
        if (time() > $timeout) {
            break;
        }
        $page = ReadPage($pn, READPAGE_CURRENT);
        if ($page) {
            $targets = str_replace(',', ' ', @$page['targets']);
            $terms = PageIndexTerms(array(@$page['text'], $targets, $pn));
            usort($terms, $cmpfn);
            $x = '';
            foreach ($terms as $t) {
                if (strpos($x, $t) === false) {
                    $x .= " {$t}";
                }
            }
            fputs($ofp, "{$pn}:{$Now}: {$targets} :{$x}\n");
        }
        $updated[$pn]++;
    }
    $ifp = @fopen($PageIndexFile, 'r');
    if ($ifp) {
        while (!feof($ifp)) {
            $line = fgets($ifp, 4096);
            while (substr($line, -1, 1) != "\n" && !feof($ifp)) {
                $line .= fgets($ifp, 4096);
            }
            $i = strpos($line, ':');
            if ($i === false) {
                continue;
            }
            $n = substr($line, 0, $i);
            if (@$updated[$n]) {
                continue;
            }
            fputs($ofp, $line);
        }
        fclose($ifp);
    }
    fclose($ofp);
    if (file_exists($PageIndexFile)) {
        unlink($PageIndexFile);
    }
    rename("{$PageIndexFile},new", $PageIndexFile);
    fixperms($PageIndexFile);
    $c = count($updated);
    StopWatch("PageIndexUpdate end ({$c} updated)");
    ignore_user_abort($abort);
}