當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PageIndexTerms函數代碼示例

本文整理匯總了PHP中PageIndexTerms函數的典型用法代碼示例。如果您正苦於以下問題:PHP PageIndexTerms函數的具體用法?PHP PageIndexTerms怎麽用?PHP PageIndexTerms使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了PageIndexTerms函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: PageIndexUpdate

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);
}
開發者ID:BogusCurry,項目名稱:pmwiki,代碼行數:53,代碼來源:pagelist.php

示例2: PageIndexUpdate

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);
}
開發者ID:BogusCurry,項目名稱:pmwiki,代碼行數:66,代碼來源:pagelist.php


注:本文中的PageIndexTerms函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。