Пример #1
0
function ewiki_powersearch($q, $where = 'content')
{
    $q = ewiki_lowercase(preg_replace('/\\s*[\\000-\\040]+\\s*/', ' ', $q));
    $found = array();
    $scored = array();
    #-- initial scan
    foreach (explode(" ", $q) as $search) {
        if (empty($search)) {
            continue;
        }
        $result = ewiki_db::SEARCH($where, $search);
        while ($row = $result->get()) {
            if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
                $id = $row["id"];
                $content = strtolower($row[$where]);
                unset($row);
                #-- have a closer look
                $len1 = strlen($content) + 1;
                if (!isset($scored[$id])) {
                    $scored[$id] = 1;
                }
                $scored[$id] += 800 * (strlen($search) / $len1);
                $scored[$id] += 65 * (count(explode($search, $content)) - 2);
                $p = -1;
                while (($p = strpos($content, $search, $p + 1)) !== false) {
                    $scored[$id] += 80 * (1 - $p / $len1);
                }
            }
            #if-TXT
        }
    }
    #-- output results
    arsort($scored);
    $o = "<ol>\n";
    $n = 0;
    foreach ($scored as $id => $score) {
        #-- refetch page for top 10 entries (still cached by OS or DB)
        $row = $n < 10 ? ewiki_db::GET($id) : NULL;
        #-- check access rights in protected mode
        if (EWIKI_PROTECTED_MODE && !ewiki_auth($id, $row, "view", $ring = false, $force = 0)) {
            if (EWIKI_PROTECTED_MODE_HIDING) {
                continue;
            } else {
                $row["content"] = ewiki_t("FORBIDDEN");
            }
        }
        $o .= "<li>\n";
        $o .= '<div class="search-result ' . ($oe ^= 1 ? "odd" : "even") . '">' . '<a href="' . ewiki_script("", $id) . '">' . $id . "</a> " . "\n";
        #-- top 10 results are printed more verbosely
        if ($n++ < 10) {
            preg_match_all('/([_-\\w]+)/', $row["content"], $uu);
            $text = htmlentities(substr(implode(" ", $uu[1]), 0, 200));
            $o .= "<br />\n<small>{$text}\n" . "<br />" . strftime(ewiki_t("LASTCHANGED"), $row["lastmodified"]) . "<br /><br /></small>\n";
        }
        $o .= "</div>\n";
        $o .= "</li>\n";
    }
    $o .= "</ol>\n";
    return $o;
}
Пример #2
0
function ewiki_edit_lock($id, &$data, $action)
{
    $keep = 500;
    // in seconds
    $o = "";
    #-- lock dir
    if (!file_exists($dir = EWIKI_TMP . "/edit.d/")) {
        mkdir($dir);
    }
    #-- check file
    $lockfile = $dir . ewiki_lowercase($id) . ".lock";
    $time = 0;
    if (file_exists($lockfile)) {
        $time = filemtime($lockfile);
    }
    #-- force
    if ($_REQUEST["edit_unlock"]) {
        unlink($lockfile);
        $time = -1;
    } elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
        @unlink($lockfile);
    } else {
        if ($time + $keep > time()) {
            $o = ewiki_t("<p class=\"system-message\"><b>_{Warning}</b>:" . " _{This page is currently being edited by someone else}," . " _{and therefore locked currently}." . " " . '<form action="' . $_SERVER[REQUEST_URI] . '" method="POST">' . '<input type="id" name="' . "{$action}/{$id}" . '">' . '<input type="submit" name="edit_unlock" value="_{unlock}">' . '</form>' . "</p>\n");
        } elseif ($time) {
            // unlink($lockfile);
            touch($lockfile);
        } else {
            touch($lockfile);
        }
    }
    return $o;
}
Пример #3
0
function ewiki_edit_warn(&$o, $id, &$data, $action)
{
    $keep = 420;
    // in seconds
    if (!file_exists($dir = EWIKI_TMP . "/edit.d/")) {
        mkdir($dir);
    }
    $lockfile = $dir . ewiki_lowercase($id) . ".lock";
    $time = 0;
    if (file_exists($lockfile)) {
        $time = filemtime($lockfile);
    }
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        @unlink($lockfile);
    } elseif ($time + $keep > time()) {
        $o = ewiki_t("<p class=\"system-message\"><b>_{Warning}</b>:" . " _{This page is currently being edited by someone else}." . " _{If you start editing now, your changes may get lost}." . "</p>\n") . $o;
    } elseif ($time) {
        // unlink($lockfile);
        touch($lockfile);
    } else {
        touch($lockfile);
    }
}
Пример #4
0
 function CACHE_ADD($id, $version)
 {
     $CACHE = $this->dir . "/CACHE";
     if ($version >= 1 && ($f = fopen($CACHE, "ab"))) {
         flock($f, LOCK_EX);
         fwrite($f, ewiki_lowercase($id) . "\n");
         flock($f, LOCK_UN);
         fclose($f);
     }
 }
Пример #5
0
 function FN($id)
 {
     $id = ewiki_lowercase($id);
     return rawurlencode($id);
 }