Exemplo n.º 1
0
function ewiki_mpi_survey($action, &$args, &$iii, &$s)
{
    global $ewiki_id, $ewiki_plugins;
    $o = "";
    #-- load data page
    if (!($df = $args["data"])) {
        return;
    }
    unset($args["data"]);
    unset($args["_"]);
    unset($args[""]);
    $data = ewiki_db::GET($df);
    if (!$data["version"]) {
        $data = ewiki_new_data($df, EWIKI_DB_F_BINARY);
        $data["version"]--;
    }
    if ($data["flags"] != EWIKI_DB_F_BINARY) {
        return;
    }
    $survey = unserialize($data["content"]);
    #-- operation
    $vote = @$_REQUEST[EWIKI_UP_SURVEY];
    if ($vote == "\$") {
        $action = "show";
    }
    if ($action == "html") {
        #-- show entries
        if (!$vote) {
            $o = "\n" . '<form action="' . $_SERVER["REQUEST_URI"] . '" method="POST" enctype="multipart/form-data">' . '<input type="hidden" name="id" value="' . htmlentities($ewiki_id) . '">' . "\n";
            foreach ($args as $name => $text) {
                if (!$name || !$text || $name == "data") {
                    continue;
                }
                $o .= '<input type="radio" name="' . EWIKI_UP_SURVEY . '" value="' . htmlentities($name) . '"> ' . $text . "<br />\n";
            }
            $o .= '<input type="submit" value="vote">';
            $o .= "\n</form>\n<br /><br />\n";
            $o .= '<a href="' . ewiki_script("", $ewiki_id, array(EWIKI_UP_SURVEY => "\$")) . '">show results</a><br />';
        }
        #-- store an entry
        if ($vote) {
            $survey[$vote]++;
            $data["content"] = serialize($survey);
            $data["version"]++;
            $data["lastmodified"] = time();
            $data["author"] = ewiki_author();
            ewiki_db::WRITE($data);
            #-- show it
            $action = "show";
        }
    }
    if ($action == "show") {
        $o .= $ewiki_plugins["view_stat"][0]($survey, $args);
    }
    return $o;
}
Exemplo n.º 2
0
function ewiki_add_thread($id, $data, $action)
{
    global $ewiki_plugins;
    $id = $id . EWIKI_THREAD_SEPARATOR . $_REQUEST['threadname'];
    $save = array("id" => $id, "version" => 1, "flags" => '', "content" => "   ", "author" => ewiki_author(), "lastmodified" => time(), "created" => time(), "meta" => array('isThread' => '1'), "hits" => 0, "refs" => "");
    if (!ewiki_db::WRITE($save)) {
        return ewiki_t("ERRORSAVING");
    }
    return ewiki_add_post($id, array(), 'addpost');
}
Exemplo n.º 3
0
function ewiki_eventually_initialize(&$id, &$data, &$action)
{
    global $USER;
    #-- initialize database only if frontpage missing
    if ($id == EWIKI_PAGE_INDEX && $action == "edit" && empty($data["version"])) {
        ewiki_database("INIT", array());
        #### BEGIN MOODLE CHANGE
        $path = EWIKI_INIT_PAGES;
        if (!empty($path)) {
            if ($dh = @opendir($path = EWIKI_INIT_PAGES)) {
                while (false !== ($filename = readdir($dh))) {
                    #### MOODLE CHANGE TO SOLVE BUG #3830. Original doesn't support dots in names.
                    //Orig->if (preg_match('/^(['.EWIKI_CHARS_U.']+['.EWIKI_CHARS_L.']+\w*)+/', $filename)) {
                    if ($filename == clean_filename($filename) && !is_dir($path . '/' . $filename)) {
                        #### END OF MOODLE CHANGE TO SOLVE BUG #3830. Original doesn't support dots in names.
                        $found = ewiki_database("FIND", array($filename));
                        if (!$found[$filename]) {
                            $content = implode("", file("{$path}/{$filename}"));
                            ewiki_scan_wikiwords($content, $ewiki_links, "_STRIP_EMAIL=1");
                            $refs = "\n\n" . implode("\n", array_keys($ewiki_links)) . "\n\n";
                            $save = array("id" => "{$filename}", "version" => "1", "flags" => "1", "content" => $content, "author" => ewiki_author("ewiki_initialize"), "userid" => $USER->id, "refs" => $refs, "lastmodified" => filemtime("{$path}/{$filename}"), "created" => filectime("{$path}/{$filename}"));
                            ewiki_database("WRITE", $save);
                        }
                    }
                }
                closedir($dh);
            } else {
                echo "<b>ewiki error</b>: could not read from directory " . realpath($path) . "<br />\n";
            }
        }
        #### END MOODLE CHANGE
        #-- try to view/ that newly inserted page
        if ($data = ewiki_database("GET", array("id" => $id))) {
            $action = "view";
        }
    }
}
Exemplo n.º 4
0
function ewiki_initialization_wizard($id, &$data, &$action)
{
    global $ewiki_plugins;
    #-- proceed only if frontpage missing or explicetely requested
    if (strtolower($id) == "wikisetupwizard" || $id == EWIKI_PAGE_INDEX && $action == "edit" && empty($data["version"]) && !$_REQUEST["abort"]) {
        if ($_REQUEST["abort"]) {
        } elseif (empty($_REQUEST["init"])) {
            $o = "<h2>WikiSetupWizard</h2>\n";
            $o .= "You don't have any pages in your Wiki yet, so we should try to read-in the default ones from <tt>init-pages/</tt> now.<br /><br />";
            $o .= '<a href="' . ewiki_script("", $id, array("init" => "now")) . '">[InitializeWikiDatabase]</a>';
            $o .= " &nbsp; ";
            $o .= '<a href="' . ewiki_script("", $id, array("abort" => "this")) . '">[NoThanks]</a>';
            $o .= "<br /><br />";
            #-- analyze and print settings and misconfigurations
            $pf_db = $ewiki_plugins["database"][0];
            $db = substr($pf_db, strrpos($pf_db, "_") + 1);
            $o .= '<table border="0" width="90%" class="diagnosis">';
            $o .= '<tr><td>DatabaseBackend</td><td>';
            $o .= "<b>" . $db . "</b><br />";
            if ($db == "files") {
                $o .= "<small>_DBFILES_DIR='</small><tt>" . EWIKI_DBFILES_DIRECTORY . "'</tt>";
                if (strpos(EWIKI_DBFILES_DIRECTORY, "tmp")) {
                    $o .= "<br /><b>Warning</b>: Storing your pages into a temporary directory is not what you want (there they would get deleted randomly), except for testing purposes of course. See the README.";
                }
            } else {
                $o .= "(looks ok)";
            }
            $o .= "</td></tr>";
            $o .= '<tr><td>WikiSoftware</td><td>ewiki ' . EWIKI_VERSION . "</td></tr>";
            $o .= "</table>";
            #-- more diagnosis
            if (ini_get("magic_quotes")) {
                $o .= "<b>Warning</b>: Your PHP interpreter has enabled the ugly and outdated '<i>magic_quotes</i>'. This will lead to problems, so please ask your provider to correct it; or fix it yourself with .htaccess settings as documented in the README. Otherwise don't forget to include() the <tt>fragments/strip_wonderful_slashes.php</tt> (it's ok to proceed for the moment).<br /><br />";
            }
            if (ini_get("register_globals")) {
                $o .= "<b>Security warning</b>: The horrible '<i>register_globals</i>' setting is enabled. Without always using <tt>fragments/strike_register_globals.php</tt> or letting your provider fix that, you could get into trouble some day.<br /><br />";
            }
            return '<div class="wiki view WikiSetupWizard">' . $o . '</div>';
        } else {
            ewiki_database("INIT", array());
            if ($dh = @opendir($path = EWIKI_INIT_PAGES)) {
                while ($filename = readdir($dh)) {
                    if (preg_match('/^([' . EWIKI_CHARS_U . ']+[' . EWIKI_CHARS_L . ']+\\w*)+/', $filename)) {
                        $found = ewiki_database("FIND", array($filename));
                        if (!$found[$filename]) {
                            $content = implode("", file("{$path}/{$filename}"));
                            ewiki_scan_wikiwords($content, $ewiki_links, "_STRIP_EMAIL=1");
                            $refs = "\n\n" . implode("\n", array_keys($ewiki_links)) . "\n\n";
                            $save = array("id" => "{$filename}", "version" => "1", "flags" => "1", "content" => $content, "author" => ewiki_author("ewiki_initialize"), "refs" => $refs, "lastmodified" => filemtime("{$path}/{$filename}"), "created" => filectime("{$path}/{$filename}"));
                            ewiki_database("WRITE", $save);
                        }
                    }
                }
                closedir($dh);
            } else {
                return "<b>ewiki error</b>: could not read from directory " . realpath($path) . "<br />\n";
            }
            #-- try to view/ that newly inserted page
            if ($data = ewiki_database("GET", array("id" => $id))) {
                $action = "view";
            }
            #-- let ewiki_page() proceed as usual
            return "";
        }
    }
}
Exemplo n.º 5
0
function wiki_admin_checklinks($pagetocheck)
{
    /// Checks http:// Links
    $ret = "";
    if ($pagetocheck) {
        $get = ewiki_database("GET", array("id" => $pagetocheck));
        $content = $get["content"];
        preg_match_all('_(http.?://[^\\s"\'<>#,;]+[^\\s"\'<>#,;.])_', $content, $links);
        $badlinks = array();
        if (!$links[1]) {
            $ret = get_string("nolinksfound", "wiki") . "<br /><br />";
        } else {
            foreach ($links[1] as $href) {
                #print "[ $href ]";
                #$d = @implode("", @file($href));
                $d = "";
                if ($checkfd = @fopen($href, 'r')) {
                    fclose($checkfd);
                    $d = "OK";
                }
                if (empty($d) || !strlen(trim($d)) || stristr("not found", $d) || stristr("error 404", $d)) {
                    $ret .= "[" . get_string("linkdead", "wiki") . "] {$href} <br />\n";
                    $badlinks[] = $href;
                } else {
                    $ret .= "[" . get_string("linkok", "wiki") . "] {$href} <br />\n";
                }
            }
        }
        /// Remove old Notices
        $content = eregi_replace(' µµ__~\\[' . get_string("offline", "wiki") . '\\]__µµ ', '', $content);
        #-- replace dead links
        foreach ($badlinks as $href) {
            $content = preg_replace("ÿ^(.*)({$href})ÿm", '$1 µµ__~[' . get_string("offline", "wiki") . ']__µµ $2', $content);
        }
        #-- compare against db content
        if ($content != $get["content"]) {
            $get["content"] = $content;
            $get["version"]++;
            $get["author"] = ewiki_author("ewiki_checklinks");
            $get["lastmodified"] = time();
            ewiki_database("WRITE", $get);
        }
    }
    return $ret;
}
Exemplo n.º 6
0
function ewiki_action_control_page($id, &$data, $action)
{
    global $ewiki_ring, $ewiki_config, $ewiki_plugins;
    $a_flagnames = array("_TEXT", "_BINARY", "_DISABLED", "_HTML", "_READONLY", "_WRITEABLE", "_APPENDONLY", "_SYSTEM", "_PART", "_MINOR", "_HIDDEN", "_ARCHIVE", "_UU12", "_UU13", "_UU14", "_UU15", "_UU16", "_EXEC", "_UU18", "_UU19");
    $o = ewiki_make_title($id, "control {$id}", 2);
    #-- admin requ. ---------------------------------------------------------
    if (!ewiki_auth($id, $data, $action, $ring = 0, "_FORCE_LOGIN=1") || !isset($ewiki_ring) || $ewiki_ring > 1) {
        if (is_array($data)) {
            $data = "You'll need to be admin. See ewiki_auth() and _PROTECTED_MODE in the README.";
        }
        $o .= $data;
    } elseif (@$_REQUEST["pgc_setflags"]) {
        #-- setted new flags
        $new_f = 0;
        foreach ($_REQUEST["sflag"] as $n => $b) {
            if ($b) {
                $new_f |= 1 << $n;
            }
        }
        #-- administrator may change all flags
        if ($ewiki_ring == 0) {
            $data["flags"] = $new_f;
        } else {
            $data["flags"] = $data["flags"] & ~EWIKI_DB_F_MODERATORFLAGS | $new_f & EWIKI_DB_F_MODERATORFLAGS;
        }
        $data["lastmodified"] = time();
        $data["version"]++;
        if (ewiki_db::WRITE($data)) {
            $o .= "Page flags were updated correctly.";
            ewiki_log("page flags of '{$id}' were set to {$data['flags']}");
        } else {
            $o .= "A database error occoured.";
        }
    } elseif (@$_REQUEST["pgc_rename"] && strlen($new_id = $_REQUEST["mv_to"])) {
        $old_id = $id;
        $report = "";
        $preg_id = "/" . addcslashes($old_id, ".+*?|/\\()\$[]^#") . "/" . ($_REQUEST["mv_cr1"] ? "i" : "");
        #-- check if new name does not already exist in database
        $exists = ewiki_db::GET($new_id);
        if ($exists || !empty($exists)) {
            return $o .= "Cannot overwrite an existing database entry.";
        }
        #-- copy from old name to new name
        $max_ver = $data["version"];
        $data = array();
        for ($v = 1; $v <= $max_ver; $v++) {
            $row = ewiki_db::GET($old_id, $v);
            $row["id"] = $new_id;
            $row["lastmodified"] = time();
            $row["content"] = preg_replace($preg_id, $new_id, $row["content"]);
            ewiki_scan_wikiwords($row["content"], $links, "_STRIP_EMAIL=1");
            $row["refs"] = "\n\n" . implode("\n", array_keys($links)) . "\n\n";
            $row["author"] = ewiki_author("control/");
            if (!ewiki_db::WRITE($row)) {
                $report .= "error while copying version {$v},<br />\n";
            }
        }
        #-- proceed if previous actions error_free
        if (empty($report)) {
            #-- deleting old versions
            for ($v = 1; $v <= $max_ver; $v++) {
                ewiki_db::DELETE($old_id, $v);
            }
            #-- adjust links/references to old page name
            if ($_REQUEST["mv_cr0"]) {
                $result = ewiki_db::SEARCH("refs", $old_id);
                while ($result && ($row = $result->get())) {
                    $row = ewiki_db::GET($row["id"]);
                    if (preg_match($preg_id, $row["content"], $uu)) {
                        $row["content"] = preg_replace($preg_id, $new_id, $row["content"]);
                        $row["lastmodified"] = time();
                        $row["version"]++;
                        ewiki_scan_wikiwords($row["content"], $links, "_STRIP_EMAIL=1");
                        $row["refs"] = "\n\n" . implode("\n", array_keys($links)) . "\n\n";
                        $row["author"] = ewiki_author("control/");
                        if (!ewiki_db::WRITE($row)) {
                            $report .= "could not update references in " . $row['id'] . ",<br />\n";
                        } else {
                            $report .= "updated references in " . $row['id'] . ",<br />\n";
                        }
                    }
                }
            }
            $o .= "This page was correctly renamed from '{$old_id}' to '{$new_id}'.<br /><br />\n{$report}";
            ewiki_log("page renamed from '{$old_id}' to '{$new_id}'", 2);
        } else {
            $o .= "Some problems occoured while processing your request, therefor the old page still exists:<br />\n" . $report;
        }
    } elseif (@$_REQUEST["pgc_setmeta"] && $ewiki_ring == 0 && ($set = explode("\n", $_REQUEST["pgc_meta"]))) {
        $new_meta = array();
        foreach ($set as $line) {
            if (($line = trim($line)) && ($key = trim(strtok($line, ":"))) && ($value = trim(strtok("")))) {
                $new_meta[$key] = $value;
            }
        }
        $data["meta"] = $new_meta;
        $data["lastmodified"] = time();
        $data["version"]++;
        if (ewiki_db::WRITE($data)) {
            $o .= "The {meta} field was updated.";
        } else {
            $o .= "A database error occoured.";
        }
    } elseif (@$_REQUEST["pgc_purge"] && $_REQUEST["pgc_purge1"]) {
        $loop = 3;
        do {
            $verZ = $data["version"];
            while ($verZ > 0) {
                ewiki_db::DELETE($id, $verZ);
                $verZ--;
            }
        } while ($loop-- && ($data = ewiki_db::GET($id)));
        if (empty($data)) {
            $o .= "Page completely removed from database.";
            ewiki_log("page '{$id}' was deleted from db", 2);
        } else {
            $o .= "Page still here.";
        }
    } else {
        $o .= '<form action="' . ewiki_script("{$action}", $id) . '" method="POST" enctype="text/html">' . '<input type="hidden" name="id" value="' . "{$action}/{$id}" . '">';
        #-- flags
        $o .= '<div class="flags">';
        $o .= "<h4>page flags</h4>\n";
        foreach ($a_flagnames as $n => $s) {
            $disabled = $ewiki_ring == 1 && !(1 << $n & EWIKI_DB_F_MODERATORFLAGS) ? ' disabled="disabled"' : "";
            $checked = $data["flags"] & 1 << $n ? ' checked="checked"' : "";
            $a[$n] = '<input type="checkbox" name="sflag[' . $n . ']" value="1"' . $checked . $disabled . '> ' . $s;
        }
        $o .= '<table border="0" class="list">' . "\n";
        for ($n = 0; $n < count($a_flagnames); $n++) {
            $y = $n >> 2;
            $x = $n & 0x3;
            if ($x == 0) {
                $o .= "<tr>";
            }
            $o .= "<td>" . $a[4 * $y + $x] . "</td>";
            if ($x == 3) {
                $o .= "</tr>\n";
            }
        }
        $o .= '</table>';
        $o .= '<input type="submit" name="pgc_setflags" value="chmod">';
        $o .= "\n<br /><br /><hr></div>\n";
        #-- rename
        $o .= '<div class="rename">';
        $o .= "<h4>rename page</h4>\n";
        $o .= 'new page name: <input type="text" size="30" name="mv_to" value="' . htmlentities($id) . '">' . '<br />' . '<input type="checkbox" name="mv_cr0" value="1" checked> also try to change all references from other pages accordingly ' . '(<input type="checkbox" name="mv_cr1" value="1" checked> and act case-insensitive when doing so) ';
        $o .= '<br /><input type="submit" name="pgc_rename" value="mv">';
        $o .= "\n<br /><br /><hr></div>\n";
        #-- meta
        if (isset($ewiki_ring) && $ewiki_ring == 0) {
            $o .= '<div class="meta">';
            $o .= "<h4>meta data</h4>\n";
            $o .= '<textarea cols="40" rows="6" name="pgc_meta">';
            if (($uu = @$data["meta"]) && is_array($uu)) {
                foreach ($uu as $key => $value) {
                    if (is_array($value)) {
                        $value = serialize($array);
                    }
                    $o .= htmlentities($key . ": " . trim($value)) . "\n";
                }
            }
            $o .= "</textarea>\n";
            $o .= '<br /><input type="submit" name="pgc_setmeta" value="set">';
            $o .= "\n<br /><br /><hr></div>\n";
        }
        #-- delete
        $o .= '<div class="delete">';
        $o .= "<h4>delete page</h4>\n";
        $o .= '<input type="checkbox" name="pgc_purge1" value="1"> I\'m sure';
        $o .= '<br /><input type="submit" name="pgc_purge" value="rm">';
        $o .= "\n<br /><br /><hr></div>\n";
        $o .= '</form>';
    }
    return $o;
}
Exemplo n.º 7
0
function ewiki_put_cache($action, $id, &$o)
{
    #-- save into cache dir
    if (defined("EWIKI_CACHE_DIR") && EWIKI_CACHE_DIR) {
        $file = EWIKI_CACHE_DIR . "/" . $action . "," . urlencode($id);
        $f = gzopen($file, "w9");
        if ($f) {
            gzwrite($f, $o);
            fclose($f);
        }
    } elseif (defined("EWIKI_CACHE_DB") && EWIKI_CACHE_DB) {
        $id = EWIKI_CACHE_DB . "{$action}/{$id}";
        $save = array("id" => $id, "version" => 1, "flags" => EWIKI_DB_F_BINARY¦EWIKI_DB_F_TEXT | EWIKI_DB_F_HTML, "created" => $data["lastmodified"], "lastmodified" => time(), "content" => &$o, "meta" => array("class" => "cache"), "author" => ewiki_author("ewiki_cache"));
        ewiki_db::WRITE($save, true);
    }
}
Exemplo n.º 8
0
function ewiki_uservars_pages_store($data = NULL, $username = NULL)
{
    global $ewiki_uservars, $ewiki_errmsg;
    if (!isset($username)) {
        $username = $GLOBALS['ewiki_auth_user'];
    }
    if ($username == $GLOBALS['ewiki_auth_user']) {
        if (!isset($data)) {
            $data = $ewiki_uservars;
        } else {
            $ewiki_uservars = $data;
        }
    }
    //echo("<p>Storing user variables for $username</p>");
    $oldpage = ewiki_db::GET(EWIKI_USERVARS_PAGENAME_PREFIX . $username);
    //if there was already an existing, non-system page, fail out.
    if ($oldpage['version'] > 0 && !($oldpage["flags"] & EWIKI_DB_F_SYSTEM)) {
        $ewiki_errmsg = ewiki_t('ERRORSAVING');
        return 0;
    }
    $save = array("id" => EWIKI_USERVARS_PAGENAME_PREFIX . $username, "version" => @$oldpage["version"] + 1, "flags" => EWIKI_DB_F_SYSTEM, "content" => serialize($data), "author" => ewiki_author(), "lastmodified" => time(), "created" => ($uu = @$oldpage["created"]) ? $uu : time(), "meta" => ($uu = @$oldpage["meta"]) ? $uu : "", "hits" => ($uu = @$oldpage["hits"]) ? $uu : "0");
    return ewiki_db::WRITE($save);
}
Exemplo n.º 9
0
        }
        echo '<TR><TD BGCOLOR="#9090B0">';
        echo '<INPUT NAME="file[' . $fn . ']" TYPE="checkbox" VALUE="1" ' . ($sel ? " CHECKED" : "") . '>';
        echo " " . $fn;
        echo "</TD>\n" . '<TD BGCOLOR="#9090B0">';
        echo $reason . "</TD></TR>\n";
    }
    echo '</TABLE>' . '<INPUT TYPE="submit" NAME="insert" VALUE="&nbsp;  insert files  &nbsp;">' . '</FORM>';
} else {
    $from = $_REQUEST["from"];
    $files = $_REQUEST["file"];
    if (strstr(substr($from, 3), "/")) {
        die("unallowed subdir name");
    }
    $from .= "/";
    foreach ($files as $fn => $uu) {
        if (strstr($fn, "/") || strstr($fn, ".") || !$uu) {
            echo "filename '{$fn}' not allowed (NOTE: no versioned pages!)...<br>\n";
            continue;
        }
        $ctime = filectime($from . $fn);
        $content = implode("", file($from . $fn));
        $prev = ewiki_db::GET($fn);
        $data = array("id" => $fn, "version" => 1 + @$prev["version"], "author" => ewiki_author("ewiki_backdown"), "flags" => EWIKI_DB_F_TEXT | @$prev["flags"], "content" => $content, "created" => $ctime, "lastmodified" => time(), "refs" => "\n", "meta" => "", "hits" => 0 + @$prev["hits"]);
        $r = ewiki_db::WRITE($data) ? "ok" : "error";
        echo "writing '{$fn}'... [{$r}]<br>\n";
    }
}
?>
</body>
</html>
Exemplo n.º 10
0
   -> creates a cache entry for pages with single-word and non-wiki names
*/
#-- cfg (already in the according plugin)
// define("EWIKI_AUTOLINKING_CACHE", "system/tmp/autolinking");
#-- start if plugin loaded / constant defined
if (defined("EWIKI_AUTOLINKING_CACHE")) {
    #-- start list
    $pages = array();
    #-- find AllPages
    $result = ewiki_db::GETALL(array("id", "flags"));
    while ($row = $result->get()) {
        if (EWIKI_DB_F_TEXT != ($row["flags"] & EWIKI_DB_F_TYPE)) {
            continue;
        }
        $id = $row["id"];
        #-- only care about pagenames, which are words but no WikiWords
        if (!strpos($id, " ") && preg_match('/^\\w+$/', $id) && !preg_match('/^([' . EWIKI_CHARS_U . ']+[' . EWIKI_CHARS_L . ']+){2,}[\\w\\d]*$/', $id)) {
            $pages[] = $id;
        }
    }
    #-- save found pages in cache entry
    $DEST = EWIKI_AUTOLINKING_CACHE;
    $save = array("id" => $DEST, "version" => 1, "flags" => EWIKI_DB_F_SYSTEM, "created" => time(), "lastmodified" => time(), "author" => ewiki_author("PrepareAutolinking"), "content" => "", "meta" => "", "refs" => "\n\n" . implode("\n", $pages) . "\n\n");
    $ok = ewiki_db::WRITE($save, true);
    #-- output results
    if ($ok) {
        echo "[{$cron}]: Written informations about " . count($pages) . " pages into the database cache entry '{$DEST}'" . "\n   These pages will then get autolinked by the according plugin.\n";
    } else {
        echo "[{$cron}]: Error writing the database cache entry '{$DEST}'. Autolinking pages won't work now.\n";
    }
}
Exemplo n.º 11
0
function ewiki_page_userregistry($id, &$data, $action)
{
    global $ewiki_plugins, $ewiki_config, $ewiki_auth_user;
    $o = ewiki_make_title($id, $id, 2, $action);
    $url = ewiki_script("", $id);
    #-- auto-login
    if ($ewiki_auth_user && empty($_REQUEST["userreg_name"])) {
        $user = $ewiki_auth_user;
        $uu = ewiki_auth_userdb_userregistry($ewiki_auth_user);
        $pw = $uu[0];
        $_REQUEST["userreg_login"] = 1;
    } else {
        $user = trim($_REQUEST["userreg_name"]);
        $pw = $_REQUEST["userreg_pw"];
    }
    #-- try to get user entry
    $ue = ewiki_auth_userdb_userregistry($user);
    #-- account creation ---------------------------------------------------
    if ($_REQUEST["userreg_register"] && empty($ue)) {
        $o .= ewiki_t(<<<END
<h4>_{New Account}</h4>
<form action="{$url}" method="POST" enctype="multipart/form-data" accept-encoding="ISO-8859-1">
_{user/login name} <input type="text" size="14" name="userreg_name" value="{$user}"> <br />
<input type="hidden" name="userreg_pw" value="">
<br />
_{password} <input type="password" name="new_pw" size="10" maxsize="12" value="{$pw}"> <br />
_{retype} <input type="password" name="new_pw2" size="10" maxsize="12" value=""> <br />
<br />
<input type="submit" name="userreg_store" value="_{create account}">
</form><br /><br />
END
);
        return $o;
        // finished here, prevent fallthrough-display of login-form
    }
    #-- check password
    if ($ue && $user && !ewiki_auth_user($user, $pw)) {
        $o .= $_REQUEST["userreg_register"] ? ewiki_t("USERNAME_ALREADY_USED") : ewiki_t("WRONG_PW") . "\n" . ewiki_t("PLEASE_RETRY");
        return $o;
    }
    #-- set fallback settings for account creation
    if (empty($ue) && $_REQUEST["userreg_store"]) {
        $ue = $_REQUEST["userreg_ue"] = array($pw, EWIKI_REGISTERED_LEVEL, "", "", "");
    }
    #-- check username
    if (preg_match("/[^" . EWIKI_CHARS_U . EWIKI_CHARS_L . "]/", $user . $pw)) {
        $o .= ewiki_t("PW_ONLY_LETTERS") . "\n" . ewiki_t("PLEASE_RETRY");
        return $o;
    } elseif ($name && strlen($user) < 3) {
        return $o . ewiki_t("USERNAME_MIN");
    }
    #-- save changes -------------------------------------------------------
    if ($_REQUEST["userreg_store"] && $user) {
        #-- new user entry
        $new_ue = $_REQUEST["userreg_ue"] or $new_ue = array();
        $new_ue[0] = $pw;
        $new_ue[1] = $ue[1] or $new_ue[1] = EWIKI_REGISTERED_LEVEL;
        if ($new_pw = $_REQUEST["new_pw"]) {
            if ($new_pw == $_REQUEST["new_pw2"]) {
                $new_ue[0] = md5($new_pw);
            } else {
                $o .= ewiki_t("RETYPE_PW") . "\n<br />";
                return $o;
            }
        }
        foreach ($new_ue as $i => $v) {
            $new_ue[$i] = preg_replace("/[^-@._ \\w\\d" . EWIKI_CHARS_L . EWIKI_CHARS_U . "]/", " ", $v);
        }
        #-- get user db page
        $data = ewiki_db::GET(EWIKI_USERDB_USERREGISTRY) or $data = array("id" => EWIKI_USERDB_USERREGISTRY, "version" => 1, flags => 0, "created" => time(), "lastmodified" => time(), "content" => "nobody:*:3::", "meta" => "", "author" => ewiki_author("{$user}@{$id}"));
        $data["flags"] |= EWIKI_DB_F_SYSTEM;
        $list = explode("\n", $data["content"]);
        #-- update entry
        ksort($new_ue);
        $new_ue = $user . ":" . implode(":", $new_ue);
        $found = 0;
        foreach ($list as $i => $line) {
            $line = trim($line);
            if (strtok($line, ":") == $user) {
                $list[$i] = $new_ue;
                $found = 1;
            }
        }
        if (!$found) {
            $list[] = $new_ue;
        }
        #-- save back
        $data["content"] = implode("\n", $list);
        $retry = 3;
        while ($retry--) {
            $data["version"]++;
            if ($ok = ewiki_db::WRITE($data)) {
                break;
            }
        }
        if ($ok) {
            $o .= ewiki_t("Data saved") . "\n<br />";
        } else {
            $o .= ewiki_t("Error saving") . "\n<br />";
            ewiki_log("_userdb_userregistry: failed to update db for user {$user}, retries={$retry}", 2);
        }
        #-- fallthru to view_settings
        $_REQUEST["userreg_login"] = 1;
        $ue = ewiki_auth_userdb_userregistry($user);
    }
    #-- view settings ----------------------------------------------------
    if ($_REQUEST["userreg_login"]) {
        #-- edit <form>
        $o .= ewiki_t(<<<END
<h4>_{Account Settings}</h4>
<form action="{$url}" method="POST" enctype="multipart/form-data" accept-encoding="ISO-8859-1">
<input type="hidden" name="userreg_name" value="{$user}">
<input type="hidden" name="userreg_pw" value="{$pw}">
<b>_{change password}</b><br />
_{new password} <input type="password" size="10" maxsize="12" name="new_pw" value=""> <br />
_{retype} <input type="password" size="10" maxsize="12" name="new_pw2" value=""> <br />
<br />
<b>_{optional infos}</b><br />
_{personal WikiPage} <input type="text" name="userreg_ue[2]" value="{$ue[2]}"><br />
_{email address} <input type="text" name="userreg_ue[3]" value="{$ue[3]}"><br />
<!--
opt string <input type="text" name="userreg_ue[4]" value="{$ue[4]}"><br />
opt string <input type="text" name="userreg_ue[5]" value="{$ue[5]}"><br />
opt string <input type="text" name="userreg_ue[6]" value="{$ue[6]}"><br />
-->
<br />
<input type="submit" name="userreg_store" value="_{save}">
</form><br /><br />
END
);
    } else {
        $url = ewiki_script("", $id);
        $o .= ewiki_t(<<<END
<form action="{$url}" method="POST" enctype="multipart/form-data" accept-encoding="ISO-8859-1">
<div class="userreg-form-settings">
<div class="userreg-form-register">
_{name} <input type="text" size="14" name="userreg_name"> &nbsp;
<input type="submit" name="userreg_register" value="_{create account}"><br />
</div>
<br />
_{password} <input type="password" size="10" maxsize="12" name="userreg_pw"><br />
<br />
<input type="submit" name="userreg_login" value="_{change settings}">
</div>
</form><br /><br />
END
);
    }
    return $o;
}
Exemplo n.º 12
0
    }
    echo '</table><input type="submit" value="&nbsp;    change settings    &nbsp;"></form>';
} else {
    foreach ($_REQUEST["set"] as $page => $fa) {
        $page = rawurldecode($page);
        $flags = 0;
        $fstr = "";
        foreach ($fa as $num => $isset) {
            if ($isset) {
                $flags += $num;
                $fstr .= ($fstr ? "," : "") . $FD[$num];
            }
        }
        echo "· " . htmlentities($page) . " ({$flags}=<small>[{$fstr}]</small>)";
        $data = ewiki_db::GET($page);
        if ($data["flags"] != $flags) {
            $data["flags"] = $flags;
            $data["author"] = "ewiki-tools, " . ewiki_author();
            $data["version"]++;
            ewiki_db::WRITE($data);
            echo " <b>[set]</b>";
        } else {
            echo " [not changed]";
        }
        echo "<br>\n";
    }
}
function strong_htmlentities($str)
{
    return preg_replace('/([^-., \\w\\d])/e', '"&#".ord("\\1").";"', $str);
}
Exemplo n.º 13
0
function ewiki_page_searchandreplace($id, $data, $action)
{
    global $ewiki_ring, $ewiki_plugins;
    $o = ewiki_make_title($id, $id, 2);
    #-- admin requ. ---------------------------------------------------------
    if (!ewiki_auth($id, $data, $action, $ring = 1, "_FORCE_LOGIN=1") || !isset($ewiki_ring) || $ewiki_ring > 1) {
        if (is_array($data)) {
            $data = "You'll need moderator/administrator privileges to use this.";
        }
        return $o .= $data;
    }
    #-- form ----------------------------------------------------------------
    if (empty($_REQUEST["snr_go"]) && empty($_REQUEST["snr_test"])) {
        $url = ewiki_script("", $id);
        $o .= ewiki_t(<<<END
Use this form to replace all occourences of a phrase in all WikiPages.
<br /><br />
<form action="{$url}" method="POST" enctype="multipart/form-data">
search for string<br />
<input type="text" name="snr_search_string" value="" size="30"><br />
<small>this text snippet always matches case-insensitive, used as
<b>first-stage</b> search string; leave it empty to use only the regular
expression matching (slower)</small><br />
look this string up only in <select name="snr_search_string_where"><option selected="selected" value="content">page content / body</option> <option value="id">page name / title</option></select><br />
<br />
<i>and/or</i> with <tt>/Perl/i</tt> regular expression<br />
<input type="text" name="snr_search_regex" value="" size="30"><br />
<small>this is <b>optional</b>, and is anyhow only used as second-stage search
pattern; if used allows to use regex backreferences in the replacement
string field</small><br />
<br />
then replace with string<br />
<input type="text" name="snr_replace" value="" size="30"><br />
<small>can contain backreferences  and \$1 if the regex search field was
used</small><br />
<br />
<input type="submit" name="snr_test" value="dry run / test regex"> &nbsp;
<input type="submit" name="snr_go" value="Replace All">
</form>
<br />
<br />
The regular expression matching is optional, you'll often only need the
simple string search field and another simple string in the replacement
field.
<br />
<br />
Please note, that this form allows to initially search for a simple string,
but you can leave this empty and only use a regex search. And as it is a
two stage searching, both patterns can be completely different.
<br />
<br />
Text replacement always happens in the WikiPages body, even if the simple
search string can be used to search for page names - if you do so, you
certainly need a second regular expression pattern for content replacement.
<br />
END
);
    } else {
        $do = $_REQUEST["snr_go"];
        #-- prepare vars
        $search_where = $_REQUEST["snr_search_string_where"];
        $search_string = $_REQUEST["snr_search_string"];
        $search_regex = $_REQUEST["snr_search_regex"];
        $replacement = $_REQUEST["snr_replace"];
        if ($search_string == "*") {
            $search_string = "";
        }
        $search_string2 = preg_quote($search_string, "/");
        $replacement2 = addcslashes($replacement, "\$");
        #-- security check in search_regex
        if (preg_match('/([\\w\\s]+)$/', $search_regex, $uu) && strstr($uu[0], "e")) {
            ewiki_log("use of regex '{$search_regex}' could be security circumvention attempt", 1);
            return $o . "wrong regex delimiter";
        }
        #-- complain
        if (empty($search_string) && empty($search_regex) || empty($replacement)) {
            return $o . "too few parameters, needs at least one search and a replacement string";
        }
        #-- initial database string search
        if (empty($search_string)) {
            $result = ewiki_db::GETALL(array("id", "version", "flags"));
        } else {
            $result = ewiki_db::SEARCH($search_where, $search_string);
        }
        #-- walk through pages
        while ($row = $result->get()) {
            #-- skip binary entries
            if (EWIKI_DB_F_TEXT != ($row["flags"] & EWIKI_DB_F_TYPE)) {
                continue;
            }
            $id = $row["id"];
            $save = false;
            $row = ewiki_db::GET($id);
            /*
               if (!ewiki_auth($id, $row, "edit", ...
               ...
            */
            if ($search_regex) {
                if (preg_match($search_regex, $row[$search_where], $uu)) {
                    $save = true;
                    $row["content"] = preg_replace($search_regex, $replacement, $row["content"]);
                }
            } elseif ($search_string) {
                if (stristr($row[$search_where], $search_string)) {
                    $save = true;
                    $row["content"] = preg_replace("/{$search_string2}/i", $replacement, $row["content"]);
                }
            }
            if ($save) {
                $o .= "· <a href=\"" . ewiki_script("", $id) . "\">" . htmlentities($id) . "</a> matched given search pattern<br />\n";
                if ($do) {
                    $row["lastmodified"] = time();
                    $row["author"] = ewiki_author("SearchAndReplace");
                    $row["version"]++;
                    if (ewiki_db::WRITE($row)) {
                        $o .= "&nbsp; changed.<br />\n";
                    } else {
                        $o .= "&nbsp; database store error<br />\n";
                        $o .= "&nbsp; " . mysql_error() . "<br />\n";
                    }
                }
            }
        }
        #-- while $result
        if ($do) {
            ewiki_log("SearchAndReplace for '{$search_strinmg}' and '{$search_regex}' to replace with '{$replacement}'");
        }
    }
    return $o;
}