Exemplo n.º 1
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;
}
Exemplo n.º 2
0
/**
 * changes user preferences based on form input
 *
 * @param mixed id
 * @param mixed data
 * @return mixed
 */
function ewiki_page_liveuser_chprefs($id, $data)
{
    global $liveuser, $liveuserDB;
    // if form was submitted, write
    if (isset($_REQUEST['submit_prefs'])) {
        return ewiki_t('CHPWFORM');
    }
    ob_start();
    echo ewiki_make_title($id, $id, 2);
    $results = $liveuserDB->getAll('SELECT * FROM ' . LW_PREFIX . '_prefs_fields');
    foreach ($results as $result) {
        if (isset($_REQUEST[$result['field_name']])) {
            liveuser_pref_setPref($liveuser->getHandle(), $result['field_name'], $_REQUEST[$result['field_name']]);
        }
    }
    echo '<form action="" method="post"><table border="1">';
    foreach ($results as $result) {
        echo '<tr><td>';
        echo '<label for="' . $result['field_name'] . '">' . $result['field_name'] . '</label></td><td>';
        echo '<input id="' . $result['field_name'] . '" name="' . $result['field_name'] . '" type="text" ';
        echo ' value=' . liveuser_pref_getPref($liveuser->getHandle(), $result['field_name']) . '></td></tr>';
    }
    echo '<tr><td colspan="2"><input type="reset" text="Reset"><input type="submit"></td></tr></table></form>';
    $o = ob_get_contents();
    ob_end_clean();
    return $o;
}
Exemplo n.º 3
0
function ewiki_view_append_attachments($id, $data, $action)
{
    $o = '<hr /><h4><a href="' . ewiki_script(EWIKI_ACTION_ATTACHMENTS, $id) . '">' . ewiki_t("ATTACHMENTS") . '</a></h4>';
    $scan = 's:7:"section";' . serialize($id);
    $result = ewiki_database("SEARCH", array("meta" => $scan));
    #### BEGIN MOODLE CHANGES - show attachments link only if there are attachments.
    ####                      - don't show the attachments on the content page.
    if (count($result->entries) <= 0) {
        $o = '';
    }
    //   $ord = array();
    //   while ($row = $result->get()) {
    //      $ord[$row["id"]] = $row["created"];
    //   }
    //   arsort($ord);
    //
    //    foreach ($ord as $id => $uu) {
    //        $row = ewiki_database("GET", array("id"=>$id));
    //        if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($row["id"], $row, "view")) {
    //            continue;
    //        }
    //        $o .= ewiki_entry_downloads($row, "*");
    //    }
    #### END MOODLE CHANGES
    return $o;
}
Exemplo n.º 4
0
function ewiki_extract($id, $data, $action)
{
    global $ewiki_links, $ewiki_config, $ewiki_plugins, $ewiki_ring, $ewiki_title;
    $extracttypes = $ewiki_config["extracttypes"][$action];
    $o = ewiki_make_title($id, ewiki_t(strtoupper($action) . "FROM") . $ewiki_title, 2, $action, "", "_MAY_SPLIT=1");
    //ignore any number of list markup tags in front of an @@{todotype},
    //extract only the @@, the types, and their message
    //or
    //extract any header line
    //1 2         3  4-Class                      5     6
    preg_match_all("/^(([-;:#\\* ]*)(@@(" . implode("|", $extracttypes) . ")(.*))|(!+.*))\$/im", $data["content"], $matches);
    for ($index = 0; $index < sizeof($matches[0]); $index++) {
        //a line will be either header or todo, concatenate the two sub expressions
        $extractedContent .= $matches[3][$index] . $matches[6][$index] . "\n\n";
    }
    //Render extracted lines as a wiki page, this code extracted from ewiki_page
    #-- render requested wiki page  <-- goal !!!
    $o .= "<div class='ewiki_page_todolist'>" . $ewiki_plugins["render"][0]($extractedContent . ewiki_t(strtoupper($action) . "POSTSCRIPT"), 1, EWIKI_ALLOW_HTML || @$data["flags"] & EWIKI_DB_F_HTML) . "</div>";
    #-- control line + other per-page info stuff
    if ($pf_a = $ewiki_plugins["view_append"]) {
        ksort($pf_a);
        foreach ($pf_a as $n => $pf) {
            $o .= $pf($id, $data, $action);
        }
    }
    if ($pf_a = $ewiki_plugins["view_final"]) {
        ksort($pf_a);
        foreach ($pf_a as $n => $pf) {
            if (!preg_match('/_title/', $pf)) {
                $pf($o, $id, $data, $action);
            }
        }
    }
    return $o;
}
Exemplo n.º 5
0
function ewiki_addpage($id, &$data, $version)
{
    $o = ewiki_make_title($id, $id, 2);
    #-- output page creation dialog
    if (empty($_REQUEST["new_id"])) {
        $o .= ewiki_t('<form action="' . ewiki_script("", $id) . '" method="POST" enctype="multipart/formdata"> ' . '_{name of the new page} <input type="text" name="new_id" size="26" value="">' . '<br />' . '<input type="submit" value="_{create}">' . '<br /><br />' . '<input type="checkbox" name="add_link_from" value="1" checked="checked">' . ' _{link it from} ' . '<input type="text" name="link_from" size="20" value="_{AddedPages}">' . '</form>');
    } else {
        $new_id = trim($_REQUEST["new_id"]);
        #-- add a link to new page
        if ($_REQUEST["add_link_from"] && ($from = $_REQUEST["link_from"])) {
            $row = ewiki_db::GET($from);
            if ($row && $row["version"]) {
                if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
                    $row["version"]++;
                    $row["content"] .= "\n* [{$new_id}]";
                    ewiki_scan_wikiwords($row["content"], $row["refs"], "_STRIP_EMAIL=1");
                    $row["refs"] = "\n\n" . implode("\n", array_keys($row["refs"])) . "\n\n";
                } else {
                    $row = false;
                }
            } else {
                $row = array("id" => $from, "version" => 1, "flags" => EWIKI_DB_F_TEXT, "created" => time(), "lastmodified" => time(), "hits" => 0, "meta" => "", "content" => "\n* [{$new_id}]", "refs" => "\n\n{$new_id}\n\n");
            }
            if ($row) {
                ewiki_db::WRITE($row);
            }
        }
        #-- call edit <form>
        $o = ewiki_page($new_id);
    }
    return $o;
}
Exemplo n.º 6
0
function ewiki_page_wiki_dump_tarball($id, $data, $action)
{
    #-- return legacy page
    if (empty($_REQUEST["download_tarball"])) {
        $url = ewiki_script("", $id);
        return ewiki_make_title($id, $id, 2) . ewiki_t(<<<END
_{WIKIDUMP}
<br /><br />
<form action="{$url}" method="POST" enctype="multipart/form-data">
<input type="hidden" name="id" value="{$id}">
<input type="submit" name="download_tarball" value="_{download tarball}">
<br /><br />
<input type="checkbox" name="dump_images" value="1"> _{with images}<br />
<input type="checkbox" name="dump_virtual" value="1"> _{include virtual pages}<br />
<input type="checkbox" name="dump_fullhtml" value="1" checked> _{complete .html files}<br />
&nbsp; &nbsp; &nbsp; <input type="checkbox" name="dump_linksto" value="1"> _{with backlink pages}<br />
</form>
END
);
    } else {
        $di = $_REQUEST["dump_images"];
        $fh = $_REQUEST["dump_fullhtml"];
        $bl = $_REQUEST["dump_linksto"];
        $vp = $_REQUEST["dump_virtual"];
        $_REQUEST = $_GET = $_POST = array();
        set_time_limit(180);
        ewiki_page_wiki_dump_send($di, $fh, $vp, $bl);
    }
}
Exemplo n.º 7
0
function ewiki_auth_query_http(&$data, $force_query = 0)
{
    global $ewiki_plugins, $ewiki_errmsg, $ewiki_author, $ewiki_ring;
    #-- fetch user:password
    if ($uu = trim($_SERVER["HTTP_AUTHORIZATION"])) {
        $auth_method = strtolower(strtok($uu, " "));
        if ($auth_method == "basic") {
            $uu = strtok(" ;,");
            $uu = base64_decode($uu);
            list($_a_u, $_a_p) = explode(":", $uu, 2);
        } else {
            #-- invalid response, ignore
        }
    } elseif (strlen($_a_u = trim($_SERVER["PHP_AUTH_USER"]))) {
        $_a_p = trim($_SERVER["PHP_AUTH_PW"]);
    }
    #-- check password
    $_success = ewiki_auth_user($_a_u, $_a_p);
    #-- request HTTP Basic authentication otherwise
    if (!$_success && $force_query || $force_query >= 2) {
        $realm = ewiki_t("RESTRICTED_ACCESS");
        $addmethod = "";
        if ($uu = $ewiki_config["login_notice"]) {
            $realm .= " " . $uu;
        }
        if ($uu = $ewiki_config["http_auth_add"]) {
            $addmethod = ", {$uu} realm=\"{$realm}\"";
        }
        header('HTTP/1.1 401 Authentication Required');
        header('Status: 401 Authentication Required');
        header('WWW-Authenticate: Basic realm="' . $realm . '"' . $addmethod);
    }
    #-- fin
    return $_success;
}
Exemplo n.º 8
0
function ewiki_createpage($id, &$data, $version)
{
    $o = ewiki_make_title($id, $id, 2);
    #-- output page creation dialog
    $o .= ewiki_t('<form action="' . ewiki_script("", "") . '" method="POST" enctype="multipart/formdata"> ' . '_{name of the new page} <input type="text" name="id" size="26" value="">' . '<br />' . '<input type="submit" value="_{create}">' . '</form>');
    return $o;
}
Exemplo n.º 9
0
function ewiki_edit_form_append_updFormat($id, $data, $action)
{
    global $ewiki_ring;
    if (!ewiki_auth_perm_liveuser($id, $data, 'manage', $ewiki_ring, 0)) {
        return '';
    }
    return ' &nbsp; <a href="' . ewiki_script('updformatheader', $id) . '">' . ewiki_t("UPDHEADERFORMAT") . '</a>';
}
Exemplo n.º 10
0
function ewiki_edit_save_antibot_checkbox(&$save, &$data)
{
    global $ewiki_errmsg;
    if (!$_REQUEST["antibot_check"] && !isset($GLOBALS["ewiki_no_bot"])) {
        $save = NULL;
        $ewiki_errmsg = ewiki_t("ANTIBOT_FAILED");
    }
}
Exemplo n.º 11
0
function ewiki_password_status($id, &$data, $action)
{
    global $liveuser;
    $passwd_status = ewiki_get_uservar("passwdstatus", 'expired');
    if ($passwd_status != 'good' && $id != "Logout" && $id != "ChangePassword" && $liveuser->isLoggedIn()) {
        return ewiki_make_title($id, "Change Password:"******"<p>You password has expired</p>" . ewiki_t("CHPW_FORM");
    }
    return 0;
}
Exemplo n.º 12
0
function ewiki_edit_user_flags($id, &$data, $action)
{
    global $ewiki_config;
    $o = "";
    foreach ($ewiki_config as $FLAG => $str) {
        $o .= '<input type="checkbox" name="page_user_flag[' . dechex($FLAG) . ']" value="1"' . ($FLAG != EWIKI_DB_F_MINOR && $data["flags"] & $FLAG ? " checked" : "") . ' id="page_user_flag_' . $FLAG . '"><label for="page_user_flag_' . $FLAG . '"> ' . ewiki_t($str) . '</label><br />' . "\n";
    }
    return $o;
}
Exemplo n.º 13
0
function ewiki_builtin_categories($id, &$data, $action)
{
    global $ewiki_categories;
    $cat = array_merge(array("" => "-"), $ewiki_categories);
    $current = @$data["meta"]["meta"][EWIKI_BULTINCAT_METAID];
    $o = "<br /> \n " . ewiki_t("category") . ": ";
    $o .= ewiki_htm_select(EWIKI_UP_SET_CATEGORY, $cat, $current);
    return $o;
}
Exemplo n.º 14
0
function ewiki_view_append_subpages($id, $data, $action, $title = "SUBPAGES", $class = "subpages")
{
    $pages = ewiki_subpage_list($id);
    if (0 == count($pages)) {
        return "";
    }
    $o = '<div class="' . $class . '"><small>' . ewiki_t($title) . ":</small><br />";
    $o .= ewiki_list_pages($pages) . "</div>\n";
    return $o;
}
Exemplo n.º 15
0
function ewiki_aedit_authorname($id, &$data, $action)
{
    $var = EWIKI_UP_AUTHOR_NAME;
    return ewiki_t(<<<EOT
<br />
 _{set the AuthorName to} <input size="20" name="{$var}" value="{$GLOBALS['ewiki_author']}">
<br />
EOT
);
}
Exemplo n.º 16
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.º 17
0
function ewiki_edit_save_antibot_delay(&$save, &$data)
{
    global $ewiki_errmsg;
    if (!isset($GLOBALS["ewiki_no_bot"])) {
        if (time() < $_REQUEST[EWIKI_UP_SAVE_DELAY] + EWIKI_EDIT_SAVE_DELAY) {
            $save = NULL;
            $ewiki_errmsg = ewiki_t("Too hasty saving rejected. Please go back, wait 3 seconds and hit [save] again.");
        }
    }
}
Exemplo n.º 18
0
function ewiki_aedit_changelog($id, &$data, $action)
{
    $var = EWIKI_UP_CHANGELOG;
    $val = $_REQUEST[EWIKI_UP_CHANGELOG];
    return ewiki_t(<<<EOT
<br />
 _{CHANGELOG}:<br /><input size="50" name="{$var}" value="{$val}">
<br />
EOT
);
}
Exemplo n.º 19
0
function ewiki_page_sitemap($id = 0, $data = 0, $action = 0)
{
    global $ewiki_config;
    //**code hijacked from page_pageindex.php**
    //creates a list of all of the valid wiki pages in the site
    $str_null = NULL;
    $a_validpages = ewiki_valid_pages(0, 1);
    //**end of hijacked code**
    //$time_end=getmicrotime();
    //creates the title bar on top of page
    if ($id == EWIKI_PAGE_SITEMAP) {
        $o = ewiki_make_title($id, ewiki_t($id), 2);
        foreach ($ewiki_config["SiteMap"]["RootList"] as $root) {
            if (isset($a_validpages[$root])) {
                $valid_root = TRUE;
                $str_rootid = $root;
                break;
            }
        }
    } else {
        $o = ewiki_make_title($id, ewiki_t("SMFOR") . " " . $id, 2);
        if (isset($a_validpages[$id])) {
            $valid_root = TRUE;
            $str_rootid = $id;
        }
    }
    $o .= "<p>" . ewiki_t("VIEWSMFOR") . " ";
    foreach ($ewiki_config["SiteMap"]["RootList"] as $root) {
        if (isset($a_validpages[$root])) {
            $o .= '<a href="' . ewiki_script('sitemap/', $root) . '">' . $root . '</a> ';
        }
    }
    $o .= "</p>";
    //checks to see if the user is allowed to view the root page
    if (!isset($a_validpages[$str_rootid])) {
        $o .= ewiki_t("INVALIDROOT");
        return $o;
    }
    //$timesitemap=getmicrotime();
    $a_sitemap = ewiki_sitemap_create($str_rootid, $a_validpages, EWIKI_SITEMAP_DEPTH);
    $timer = array();
    $level = -1;
    $fordump = 0;
    $str_formatted = "<ul>\n<li><a href=\"" . EWIKI_SCRIPT . $str_rootid . "\">" . $str_rootid . "</a></li>";
    $fin_level = format_sitemap($a_sitemap, $str_rootid, $str_formatted, $level, $timer, $fordump);
    $str_formatted .= "</ul>" . str_pad("", $fin_level * 6, "</ul>\n");
    $o .= $str_formatted;
    //$timesitemap_end=getmicrotime();
    //$o.="GetAll: ".($time_end-$time)."\n";
    //$o.="SiteMap: ".($timesitemap_end-$timesitemap)."\n";
    //$o.="Total: ".($timesitemap_end-$time);
    return $o;
}
Exemplo n.º 20
0
function ewiki_handler_jump(&$id, &$data, &$action)
{
    global $ewiki_config;
    static $redirect_count = 5;
    $jump_markup = array("jump", "goto", "redirect", "location");
    #-- we only care about "view" action
    if ($action != "view") {
        return;
    }
    #-- escape from loop
    if (isset($_REQUEST[EWIKI_UP_REDIRECT_COUNT])) {
        $redirect_count = $_REQUEST[EWIKI_UP_REDIRECT_COUNT];
    }
    if ($redirect_count-- <= 0) {
        return ewiki_t("REDIRECTION_LOOP", array("id" => $id));
    }
    #-- search for [jump:...]
    if ($links = explode("\n", trim($data["refs"]))) {
        foreach ($links as $link) {
            if (strlen($link) && strpos($link, ":") && in_array(strtolower(strtok($link, ":")), $jump_markup) && ($dest = trim(strtok("\n")))) {
                #-- URL
                $url = "";
                if (strpos($dest, "://")) {
                    $url = $dest;
                } else {
                    $url = ewiki_interwiki($dest, $uu, $uu2);
                }
                #-- Location:
                if (EWIKI_JUMP_HTTP && EWIKI_HTTP_HEADERS && !headers_sent()) {
                    #-- simple PageLink
                    if (empty($url)) {
                        $url = ewiki_script("", $dest, array(EWIKI_UP_REDIRECT_COUNT => $redirect_count), 0, 0, ewiki_script_url());
                        $url .= defined("SID") ? EWIKI_ADDPARAMDELIM . SID : "";
                    }
                    header("Location: {$url}");
                    die;
                } elseif ($url) {
                    return "";
                    # the rendering kernel will just show up the [jump:]!
                    # (without the jump: of course)
                } else {
                    #-- we'll just restart ewiki
                    $data = array();
                    $id = $dest;
                    return ewiki_page("view/" . $id);
                }
            }
        }
    }
    #-search
}
Exemplo n.º 21
0
function ewiki_edit_save_limit_adding_external_links(&$save, &$old)
{
    global $ewiki_errmsg;
    #-- count
    preg_match_all('°(http://[^\\s*<>"\'\\[\\]\\#]+)°', $old["content"], $old_urls);
    preg_match_all('°(http://[^\\s*<>"\'\\[\\]\\#]+)°', $save["content"], $save_urls);
    $added_urls = array_diff($save_urls[1], $old_urls[1]);
    #-- engage trap
    if (count($added_urls) > EWIKI_LIMIT_LINKS) {
        #-- abort saving with an error message
        $save = array();
        $ewiki_errmsg = ewiki_t("LINK_ADDING_LIMITED");
        return false;
    }
}
Exemplo n.º 22
0
function ewiki_action_calendar_list($id, $data, $action)
{
    $pages = ewiki_subpage_list($id, CALENDAR_NAME_SEP);
    foreach ($pages as $pageId => $uu) {
        if (!ewiki_isCalendarId($pageId)) {
            unset($pages[$pageId]);
        }
    }
    if (0 == count($pages)) {
        return ewiki_t("NOCALENDAR");
    } else {
        //ksort($pages);
        $o = '<div class="calendar_list"><small>' . ewiki_t('CALENDERFOR') . " {$id}:</small><br />";
        $o .= ewiki_list_pages($pages) . "</div>\n";
    }
    return $o;
}
Exemplo n.º 23
0
function ewiki_page_like($id, $data, $action)
{
    preg_match_all("/([" . EWIKI_CHARS_U . "][" . EWIKI_CHARS_L . "]+)/", $id, $words);
    $pages = array();
    foreach ($words[1] as $find) {
        $result = ewiki_db::SEARCH("id", $find);
        while ($row = $result->get()) {
            if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($row["id"], $row, "view")) {
                continue;
            }
            $pages[$row["id"]] = "";
        }
    }
    $o = ewiki_make_title($id, ewiki_t(strtoupper($action) . "_TITLE"), 3);
    $o .= ewiki_list_pages($pages, 0);
    return $o;
}
Exemplo n.º 24
0
function ewiki_view_append_attachments($id, $data, $action)
{
    $o = '<hr><h4><a href="' . ewiki_script(EWIKI_ACTION_ATTACHMENTS, $id) . '">' . ewiki_t("ATTACHMENTS") . '</a></h4>';
    $scan = 's:7:"section";' . serialize($id);
    $result = ewiki_db::SEARCH("meta", $scan);
    $ord = array();
    while ($row = $result->get()) {
        $ord[$row["id"]] = $row["created"];
    }
    arsort($ord);
    foreach ($ord as $id => $uu) {
        $row = ewiki_db::GET($id);
        if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($row["id"], $row, "view")) {
            continue;
        }
        $o .= ewiki_entry_downloads($row, "*");
    }
    return $o;
}
Exemplo n.º 25
0
function ewiki_action_image_append($id, $data, $action)
{
    #-- invalid $id value
    if (empty($data) || !$data["version"] || EWIKI_DB_F_TEXT != ($data["flags"] & EWIKI_DB_F_TYPE)) {
        $o = ewiki_t("CANNOTCHANGEPAGE");
    } elseif ($fa = $_FILES["imagefile"]) {
        #-- guess HTTP meta data
        $meta = array("X-Content-Type" => $fa["type"]);
        if ($s = $fa["name"]) {
            $meta["Content-Location"] = $s;
            $p = 0 or $p = strrpos($s, "/") and $p++ or $p = strrpos($s, '\\') and $p++;
            $meta["Content-Disposition"] = 'inline; filename="' . urlencode(substr($s, $p)) . '"';
        }
        #-- proceed an image (reject binary, resize if too large)
        $result = ewiki_binary_save_image($fa["tmp_name"], "", "RETURN", $meta, 0, 1);
        #-- database rejected file
        if (!$result) {
            $o = ewiki_t("BIN_NOIMG");
        } else {
            $loop = 3;
            while ($loop--) {
                $data = ewiki_db::GET($id);
                $data["version"]++;
                $data["content"] = rtrim($data["content"], "\n") . "\n\n" . "[\"AppendedPicture\"{$result}]\n\n\n";
                $result = ewiki_db::WRITE($data);
                if ($result) {
                    break;
                }
            }
            if ($result) {
                $o = ewiki_page("view/{$id}");
                ewiki_log("image appended to '{$id}'");
            } else {
                $o .= ewiki_t("NO_IMAGEAPPEND");
            }
        }
    } else {
        $o .= ewiki_t("BIN_NOIMG");
        #"You did not select an image, or something went really wrong during tansmission. Plase go back to the previous page.";
    }
    return $o;
}
Exemplo n.º 26
0
function ewiki_edit_save_antispam_urlblock(&$save, &$old_data)
{
    global $ewiki_errmsg, $ewiki_id;
    $BLOCK = EWIKI_PAGE_BLOCKED;
    preg_match_all('°(http://[^\\s*<>"\'\\[\\]\\#]+)°', $save["content"], $save_urls);
    preg_match_all('°(http://[^\\s*<>"\'\\[\\]\\#]+)°', $old_data["content"], $old_urls);
    $added_urls = array_diff($save_urls[1], $old_urls[1]);
    if ($added_urls) {
        foreach ($added_urls as $i => $url) {
            #-- test against BannedLinks, then deface (filter page) URL
            if (ewiki_blocked_link($url, $BLOCK)) {
                $block = true;
                unset($added_urls[$i]);
            }
        }
        $old = $i + 1;
    }
    #-- if matched
    if ($block) {
        #-- add new URLs to our BannedLinks page
        if ($new = count($added_urls)) {
            $content = "";
            foreach ($added_urls as $d) {
                $d = preg_replace('#^.+//(?:www\\.)?#', '', $d);
                $d = preg_replace('#^([^/]+)(/.*)?$*', '$1', $d);
                if ($d) {
                    $content .= "\n* [{$d}] (auto-added by spam attack on [{$ewiki_id}])";
                }
            }
            if ($content) {
                ewiki_db::APPEND($BLOCK, $content);
            }
            $date = strftime("%c", time());
            ewiki_append_to_page("SpamLog", "\n* spam attack on [{$ewiki_id}] from {$_SERVER['REMOTE_ADDRESS']}:{$_SERVER['REMOTE_PORT']} ({$_SERVER['HTTP_USER_AGENT']}) happend at {$date}, around {$new} of the {$old} added URLs were already on BlockedLinks");
        }
        #-- error reporting method for ["edit_save"]
        $save = array();
        $ewiki_errmsg = ewiki_t("BLOCKED_URL");
        return false;
    }
}
Exemplo n.º 27
0
function ewiki_virtual_sisterpages($id, &$data, $action)
{
    global $ewiki_metadb;
    #-- load metadb, inject URLs into $ewiki_links
    if (ewiki_metadb::LOAD()) {
        #-- search for alternatives
        if ($alt = $ewiki_metadb[strtolower($id)]) {
            $virt = "";
            $real = $alt[0];
            foreach ($alt[1] as $iw) {
                if (!strpos($data["content"], "{$iw}:{$real}")) {
                    $virt .= "* {$iw}:{$real}\n";
                }
            }
            if ($virt) {
                $data["content"] .= "\n\n" . ewiki_t("SISTER") . "\n" . $virt . "\n";
            }
        }
        ewiki_metadb::UNLOAD();
    }
}
Exemplo n.º 28
0
function ewiki_page_orphanedpages($id, $data, $action)
{
    global $ewiki_links;
    $o = ewiki_make_title($id, ewiki_t($id), 2);
    $pages = array();
    $refs = array();
    $orphaned = array();
    #-- read database
    $db = ewiki_database("GETALL", array("refs", "flags"));
    $n = 0;
    while ($row = $db->get()) {
        $p = $row["id"];
        #-- remove self-reference
        $row["refs"] = str_replace("\n{$p}\n", "\n", $row["refs"]);
        #-- add to list of referenced pages
        $rf = explode("\n", trim($row["refs"]));
        $refs = array_merge($refs, $rf);
        if ($n++ > 299) {
            $refs = array_unique($refs);
            $n = 0;
        }
        // (clean-up only every 300th loop)
        #-- add page name
        if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
            $pages[] = $row["id"];
        }
    }
    $refs = array_unique($refs);
    #-- check pages to be referenced from somewhere
    foreach ($pages as $p) {
        if (!ewiki_in_array($p, $refs)) {
            if (!EWIKI_PROTECTED_MODE || EWIKI_PROTECTED_MODE_HIDING || ewiki_auth($p, $uu, "view")) {
                $orphaned[] = $p;
            }
        }
    }
    #-- output
    $o .= ewiki_list_pages($orphaned, 0);
    return $o;
}
Exemplo n.º 29
0
function ewiki_page_index($id = 0, $data = 0, $action = 0, $args = array())
{
    global $ewiki_plugins;
    $o = ewiki_make_title($id, ewiki_t($id), 2);
    $sorted = array();
    $sorted = array_merge($sorted, array_keys($ewiki_plugins["page"]));
    $exclude = "\n" . implode("\n", preg_split("/\\s*[,;:\\|]\\s*/", $args["exclude"])) . "\n";
    $result = ewiki_database("GETALL", array("flags"));
    while ($row = $result->get()) {
        if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($row["id"], $uu, "view")) {
            continue;
        }
        if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
            if (!stristr($exclude, "\n" . $row["id"] . "\n")) {
                $sorted[] = $row["id"];
            }
        }
    }
    natcasesort($sorted);
    $o .= ewiki_list_pages($sorted, 0, 0, $ewiki_plugins["list_dict"][0]);
    return $o;
}
Exemplo n.º 30
0
function ewiki_auth_query_form(&$data, $force_query = 0)
{
    global $ewiki_plugins, $ewiki_config, $ewiki_errmsg, $ewiki_id, $ewiki_action, $ewiki_author, $ewiki_ring;
    $o =& $ewiki_errmsg;
    #-- get user/pw from POST or COOKIE
    if ($_POST["login_user"]) {
        $_user = $_REQUEST["login_user"];
        $_pw = $_REQUEST["login_pw"];
    } elseif ($_COOKIE["ewiki_login"]) {
        list($_user, $_pw) = explode(":", base64_decode($_COOKIE["ewiki_login"]));
    }
    #-- check password
    $_success = 0;
    if (strlen($_user) && strlen($_pw)) {
        $_success = ewiki_auth_user($_user, $_pw);
    }
    #-- store login data as Cookie
    if ($_success && $_POST["login_user"]) {
        setcookie("ewiki_login", base64_encode("{$_user}:{$_pw}"), time() + 7 * 24 * 3600);
    }
    #-- login form
    if ($force_query && !$_success || $force_query >= 2) {
        #-- it's safe to call this plugin for interception of running submits
        $_REPOST = "";
        if (defined("EWIKI_AUTH_QUERY_SAFE")) {
            foreach ($_POST as $i => $v) {
                if ($i == "login_name" || $i == "login_pw") {
                    continue;
                }
                $_REPOST .= '<input type="hidden" name="' . $i . '" value="' . preg_replace('/([^\\w\\d\\260-\\377])/e', '"&#".ord("$1").";"', $v) . '">' . "\n";
            }
            $_REPOST = '<!-- $_REPOST -->' . "\n" . $_REPOST . '<!-- $_END -->' . "\n";
        }
        #-- print
        $o = '<div class="login-form auth-login">' . ewiki_make_title($ewiki_id, "Login", $_title_class = 4, $ewiki_action, $_go_action = "info") . ewiki_t("LOGIN_QUERY") . "\n<br /><br />\n" . '<form action="' . $_SERVER["REQUEST_URI"] . '" method="POST">' . "\n" . ewiki_t('_{user} <input type="text" size="14" name="login_user"><br />' . "\n" . '_{password} <input type="password" size="10" maxsize="12" name="login_pw"><br /><br />' . "\n" . '<input type="submit" value="_{login}"><br /><br />' . "\n") . $_REPOST . "</form><br /><br />\n" . ewiki_t("LOGIN_QUERY_2") . '</div>';
    }
    #-- end
    return $_success;
}