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; }
function ewiki_page_wiki_mini_tarball_dump($id, $data, $action) { global $ewiki_config, $ewiki_plugins; #-- get all pages / binary files $result = ewiki_db::GETALL(array("id", "version", "flags")); if ($result) { #-- HTTP headers header("Content-Type: application/x-tar"); header("Content-Disposition: attachment; filename=\"InitPages.tar.gz\""); #-- start tar file $tarball = new ewiki_virtual_tarball(); $tarball->open(0); #-- convert all pages while ($row = $result->get(0, 0x1037)) { $id = $row["id"]; $row = ewiki_db::GET($id); $content =& $row["content"]; $fn = $id; if (!$row || !$row["id"] || !$row["content"]) { continue; } #-- for tarball $perms = array("mtime" => $row["lastmodified"], "uname" => "ewiki", "mode" => 0664 | ($row["flags"] & EWIKI_DB_F_WRITEABLE ? 02 : 00)); #-- add file $tarball->add($fn, $content, $perms); } #-- end output $tarball->close(); } #-- fin die; }
function ewiki_anacron_checktime() { global $ewiki_plugins; if ($d = ewiki_db::GET(EWIKI_ANACRON_ID) and $d = unserialize($d["content"]) and $d["last"] >= UNIX_MILLENNIUM and time() >= $d["last"] + EWIKI_ANACRON_INTERLEAVE) { register_shutdown_function("ewiki_anacron_runparts"); } }
function ewiki_load_editable_intermap($uu = 0, $uu = 0, $uu = 0) { global $ewiki_plugins, $ewiki_config; $inter =& $ewiki_config["interwiki"]; #-- fetch from db $id = "EditableInterMap"; if ($data = ewiki_db::GET($id)) { #-- extract entries if (preg_match_all('/^:(\\w+):([^\\s]+)/m', $data["content"], $uu)) { foreach ($uu[1] as $i => $moni) { if (!isset($inter[$moni])) { $inter[$moni] .= $uu[2][$i]; } } } /* WONT_WORK $refs = explode("\n", trim($data["refs"])); for ($n=1; $n<count($refs); $n++) { if (strpos($refs[$n], "://")) { $moni = $refs[$n-1]; if (!isset($inter[$moni])) { $inter[$moni] .= $refs[$n]; } } } */ #-- enable _APPENDONLY part if ($data["flags"] & EWIKI_DB_F_APPENDONLY) { $ewiki_plugins["page"]["EditableInterMap"] = "ewiki_editable_intermap"; } } }
function ewiki_banned_link($href) { global $ewiki_config; #-- buffer list of banned urls if (!isset($ewiki_config["banned"])) { $data = ewiki_db::GET(EWIKI_PAGE_BANNED); $ewiki_config["banned"] = trim(strtolower($data["refs"])); } #-- check for entry if ($b =& $ewiki_config["banned"]) { $href = strtolower(urldecode($href)); if (strpos($b, $href) !== false) { return true; } foreach (explode("\n", $b) as $bad) { if (strpos($href, $bad) !== false) { return true; } } } #-- advanced if ($pf_a = $ewiki_plugins["ban_lookup"]) { foreach ($pf_a as $pf) { if ($pf($href)) { return true; } } } return false; }
function ewiki_announcements($id, $data, $action) { global $ewiki_plugins, $ewiki_config; if (!isset($GLOBALS['ewiki_auth_user'])) { return; } $notifyDates = ewiki_get_uservar("NotifyDates", FALSE); if (!$notifyDates) { $notifyDates = $ewiki_config["DefaultNotify"]; } else { $notifyDates = unserialize($notifyDates); } foreach ($notifyDates as $pageName => $date) { $data = ewiki_db::GET($pageName); if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($pageName, $data, "view")) { continue; } if ($data['lastmodified'] > $date) { $dispDate = $data['lastmodified']; $dispPage = $pageName; break; } } if (!isset($dispPage)) { return; } $notifyDates[$dispPage] = $dispDate; ewiki_set_uservar("NotifyDates", serialize($notifyDates)); $o = ewiki_page('view/' . $dispPage); //page_final plugins have been run, unset them unset($ewiki_plugins["page_final"]); return $o; }
function ewiki_edit_load_template($id, &$data, $action) { if ($id = $_REQUEST["load_template"]) { $d2 = ewiki_db::GET($id); $data["content"] = $d2["content"]; } }
function ewiki_action_rss($id, &$data, $action) { $list = array(); #-- recentchanges as rss if (strtoupper($id) == "RSS") { $res = ewiki_db::GETALL(array("id", "flags", "version", "lastmodified")); $sort = array(); while ($data = $res->get(0, 0x137, EWIKI_DB_F_TEXT)) { $sort[$data["id"]] = $data["lastmodified"]; } arsort($sort); $limit = 100; foreach ($sort as $id => $uu) { $list[] = ewiki_db::GET($id); if ($limit-- < 0) { break; } } } else { $list[] = $data; for ($v = $data["version"] - 1; $v >= 1; $v--) { $d = ewiki_db::GET($id, $v); $list[] = $d; } } ewiki_feed($list); }
function ewiki_blocked_link($href, $LinkPage = EWIKI_PAGE_BLOCKED) { global $ewiki_config, $ewiki_plugins; if (!($href = trim(strtolower(urldecode($href))))) { return; } #-- buffer list of banned urls if (!isset($ewiki_config[$LinkPage])) { $data = ewiki_db::GET($LinkPage); $ewiki_config[$LinkPage] = trim(strtolower($data["refs"])); } #-- check for entry if ($b =& $ewiki_config[$LinkPage]) { if (strpos($b, $href) !== false) { // quick string check return true; } foreach (explode("\n", $b) as $bad) { // use as patterns if (strlen($bad) && strpos($href, $bad) !== false) { return true; } } } #-- advanced if ($pf_a = $ewiki_plugins["ban_lookup"]) { foreach ($pf_a as $pf) { if ($pf($href)) { return true; } } } return false; }
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; }
function ewiki_page_gnu_diff_safemode($id, &$data, $action) { #-- different operation modes of GNU diff: $OPTIONS = " -B -u -U 50 "; # $OPTIONS = " -B "; # $OPTIONS = " -c "; # $OPTIONS = " --side-by-side "; #-- fetch old wiki source if (($old_ver = ($new_ver = $data["version"]) - 1) > 0) { $data0 = ewiki_db::GET($id, $old_ver); } $o = ewiki_make_title($id, "Differences between version {$new_ver} and {$old_ver} of »{$id}«"); #-- create temporary files from wikipages $file0 = tempnam(EWIKI_TMP, "ewiki.diff.gnu."); $f = fopen($file0, "w"); fwrite($f, $data0["content"]); fclose($f); $file1 = tempnam(EWIKI_TMP, "ewiki.diff.gnu."); $f = fopen($file1, "w"); fwrite($f, $data["content"]); fclose($f); #-- parse thru GNU diff util $fn = addslashes($id); $OPTIONS .= " --label='{$fn} (version {$old_ver})' --label='{$fn} (version {$new_ver})' "; //following lines replace the original //$diff = shell_exec("diff $OPTIONS $file0 $file1"); $dfd = popen("diff {$OPTIONS} {$file0} {$file1}", "r"); $diff = ""; while (!feof($dfd)) { $diff .= fread($dfd, 5000); } pclose($dfd); //end of moderation #-- remove temporary files unlink($file0); unlink($file1); #-- encolor diff output foreach (explode("\n", $diff) as $dl) { $str = substr($dl, 1); switch (substr($dl, 0, 1)) { case "<": case "-": $o .= "<b>-</b><font color=\"#990000\"> <tt>{$str}</tt></font><br />\n"; break; case ">": case "+": $o .= "<b>+</b><font color=\"#009900\"> <tt>{$str}</tt></font><br />\n"; break; case "*": case "-": break; default: $o .= "<small><tt>{$dl}</tt></small><br />"; } } return $o; }
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; }
function ewiki_edit_helptext($id, &$data, &$hpost) { global $ewiki_t; if ($help = ewiki_db::GET("EditingHelp")) { $help = ewiki_format($help["content"]); if ($l = strpos($help, "<hr")) { $ewiki_t["en"]["EDIT_FORM_1"] = substr($help, 0, $l); $l = strpos($help, ">", $l); $help = substr($help, $l + 1); } $ewiki_t["en"]["EDIT_FORM_2"] = $help; } }
function ewiki_trigger_spam_watchonly($id, &$data, &$action, $pf_i) { #-- fetch list of tracked pages if ($d = ewiki_db::GET("WatchSpam")) { (array) ($ewiki_config["watchspam"] += explode("\n", trim($d["refs"]))); } #-- disable all bot-blocking plugins? if (!ewiki_in_array($id, $ewiki_config["watchspam"])) { $GLOBALS["ewiki_no_bot"] = 1; } elseif ($action == "edit") { ewiki_log("someone is {$action}ing specifically watched page '{$id}'", 2); } }
function ewiki_pingback_rpc($source_url, $target_url) { global $ewiki_config; #-- does the target URL refer to a known WikiPage ? $id = ewiki_url2id($target_url); if (!$id) { xmlrpc_send_response(xmlrpc_error(0x21, "Could not determine PageName for the given target URL.")); } if (!($data = ewiki_db::GET($id))) { xmlrpc_send_response(xmlrpc_error(0x20, "The given target page does not exist.")); } #-- check if the caller really has a link as he claims ini_set("user_agent", $ewiki_config["ua"]); if (strpos($source_url, "http://") === 0 && ($test = ewiki_http_asis($source_url, 96256))) { $test = strtolower($test); $test_url = strtolower($target_url); if (!strpos($test, $test_url) and !strpos($test, htmlentities($test_url))) { return xmlrpc_error(0x11, "Sorry, but couldn't find a link to '{$target_url}' on your given '{$source_url}' page."); } } else { return xmlrpc_error(0x10, "Your given source URL does not exist, could not be retrieved."); } #-- reject other frivolous links if (preg_match('#^http://[^/]+/?$#', $source_url)) { return xmlrpc_error(0x11, "Rejected '{$source_url}' as frivolous."); } #-- check write permissions if (EWIKI_DB_F_TEXT != $data["flags"] & EWIKI_DB_F_TYPE or $data["flags"] & EWIKI_DB_F_READONLY) { return xmlrpc_error(0x31, "Sorry, but this page is write-protected or not a system page."); } #-- already on page if (strpos($data["content"], $source_url)) { return xmlrpc_error(0x30, "The given link does already exist on this page."); } #-- other go-away cases if (function_exists("ewiki_banned_url") && ewiki_banned_url($source_url) || function_exists("ewiki_blocked_url") && ewiki_blocked_url($source_url)) { return xmlrpc_error(0x100, "Your link is unwanted here (registered on BlockedLinks or BannedLinks)."); } #-- else update page $data["content"] = rtrim($data["content"]) . "\n* {$source_url} (PingBack)\n"; ewiki_db::UPDATE($data); $data["version"]++; $ok = ewiki_db::WRITE($data); #-- fin response if ($ok) { return "Link to '{$source_url}' was added to page '{$id}'."; } else { return xmlrpc_error(0x101, "Seems like a database/writing error occoured."); } }
function ewiki_aview_pagetrail($id, &$data, $action) { if ($m = $data["meta"]["meta"]) { #-- check for parent page $top = $m["top"] or $top = $m["parent"] or $top = $m["group"]; if ($top) { $t = ewiki_db::GET($top); $t = explode("\n", trim($t["refs"])); $n = array_search(ewiki_array($top), strtolower($t)); $prev = $t[$n - 1]; $next = $t[$n + 1]; $o = "<div class=\"page-trail\"><< " . ($prev ? ewiki_link($prev) : "") . " | " . ewiki_link($top) . " | " . ($prev ? ewiki_link($prev) : "") . " >%gt;</div>\n"; return $o; } } }
function ewiki_page_stupid_diff($id, $data, $action) { if ($uu = $GLOBALS["ewiki_diff_versions"]) { list($new_ver, $old_ver) = $uu; $data = ewiki_db::GET($id, $new_ver); } else { $new_ver = $data["version"]; $old_ver = $new_ver - 1; } if ($old_ver > 0) { $data0 = ewiki_db::GET($id, $old_ver); } $o = ewiki_make_title($id, "Differences between version {$new_ver} and {$old_ver} of »{$id}«"); $o .= ewiki_stupid_diff($data["content"], $data0["content"]); return $o; }
function ewiki_mpi_registerspam($action, &$args, &$iii, &$s) { global $ewiki_id; if (!$_POST["regspam"]) { return <<<END <form action="{$_SERVER['REQUEST_URI']}" method="POST" enctype="multipart/form-data"> <textarea name="add_spam" cols="50" rows="3"></textarea><br/> <input type="submit" name="regspam" value="add listed urls" /> </form> END; } else { #-- scan for links $text = $_REQUEST["add_spam"]; ewiki_scan_wikiwords($text, $uu); $ls = array(); foreach ($uu as $href => $uu) { if ($l = strpos($href, "://")) { // filter out redundant pattern parts $href = substr($href, $l + 3); if (strpos($href, "www.") === 0) { $href = substr($href, 4); } $href = trim($href, "/"); $ls[] = strtok($href, " "); } } #-- reduce $ls = array_unique($ls); $data = ewiki_db::GET($ewiki_id); foreach (explode("\n", trim($data["refs"])) as $href) { if (in_array($href, $ls)) { unset($ls[array_search($href, $ls)]); } } #-- add to current page if ($ls) { $inj = "* [" . implode("], [", $ls) . "]\n"; $data["content"] = preg_replace("/(^[-*#])/m", "{$inj}\$1", $data["content"], 1); ewiki_db::UPDATE($data); $data["version"]++; ewiki_db::WRITE($data); return "\n<div class=\"system-message ok\">new links added as patterns here (please go back and reload page to see it)</div>\n"; } else { return "\n<div class=\"system-message failure\">no new links found, please add the patterns by hand then</div>\n"; } } }
function ewiki_sync_local($func, $args = NULL) { switch (strtoupper(trim($func, ":"))) { case "GET": return ewiki_db::GET($args[0], $args[1]); case "WRITE": return ewiki_db::WRITE($args); case "LIST": $all = ewiki_db::GETALL(array("id", "version")); $r = array(); while ($row = $all->get()) { $r[$row["id"]] = $row["version"]; } return $r; default: } }
function ewiki_mpi_removedlinks($action, &$args, &$iii, &$s) { $id = $args["id"] or $id = $args["page"] or $id = $GLOBALS["ewiki_id"]; $data = ewiki_db::GET($id); $ver = $cdata["version"]; $clinks = explode("\n", trim($data["refs"])); $rm = array(); while (--$ver >= 1) { $data = ewiki_db::GET($id, $ver); $refs = explode("\n", trim($data["refs"])); $rm = $rm + array_diff($refs, $clinks, $rm); } if ($rm) { return ewiki_list_pages($rm, 0); } else { return " "; } }
function ewiki_handler_fancy_linkexcerpts($id, &$data, $action) { global $ewiki_fancy_linkexcerpts; if ($action == "view") { $ewiki_fancy_linkexcerpts = array(); foreach (explode("\n", trim($data["refs"])) as $link) { $row = ewiki_db::GET($link); if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) { $text = trim(substr($row["content"], 0, 160)); $text = substr($text, 0, strrpos($text, " ")); $text = strtr($text, "\t\r\n", " "); $text = htmlentities($text); $text = wordwrap($text, 40, " ", 0); $ewiki_fancy_linkexcerpts[strtolower($link)] = $text; } } } }
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; }
function ewiki_get_instanturls() { global $ewiki_config; $ewiki_config["instant"] = array(); $DL = '[:|]([^:|]+)[:|]([^|]+)'; #-- walk through URL definition pages foreach ($ewiki_config["instant_url_pages"] as $id) { #-- fetch content $data = ewiki_db::GET($id); if ($data) { preg_match_all("/^{$DL}/m", $data["content"], $uu); if ($uu) { foreach ($uu[1] as $i => $name) { $ewiki_config["instant"][trim($name)] = strtok(trim($uu[2][$i]), " "); } } } } }
function xpi_init_plugins() { global $ewiki_id, $ewiki_title, $ewiki_action, $ewiki_data, $ewiki_config, $ewiki_t, $ewiki_plugins, $_EWIKI; #-- load xpi registry $conf = ewiki_db::GET(XPI_DB); if ($conf && $conf["flags"] & EWIKI_DB_F_SYSTEM && ($conf = unserialize($conf["content"]))) { #-- collect xpi code, execute it $eval_this = ""; foreach ($conf as $xpi) { if ($xpi["state"] && $xpi["type"] != "page") { $d = ewiki_db::GET($xpi["id"]); if ($d && $d["flags"] & EWIKI_DB_F_EXEC) { $eval_this .= $d["content"]; } } } eval($eval_this); } }
function ewiki_mpi_bugreportstate($action, $args, &$iii, &$s) { global $ewiki_id; #-- possible states $values = array("open", "closed", "done", "frozen", "answered"); foreach ($args as $i => $name) { if (is_int($i)) { if (preg_match("/^\\w+\$/", $name) && !in_array($name, $values)) { $values[] = $name; } } } $rxvals = implode("|", $values); #-- if button pressed if (($new = $_REQUEST["brs_change"]) && in_array($new, $values)) { $pages = ewiki_get_backlinks($ewiki_id); $pages[] = $ewiki_id; #-- change assoc pages foreach ($pages as $id) { $data = ewiki_db::GET($id); if (preg_match("/\n\\|.*stat(e|us).*\\|.*({$rxvals})/", $data["content"]) or preg_match("/\n\\|.*({$rxvals}).*\\|.*{$ewiki_id}/", $data["content"])) { $data["content"] = preg_replace("/(\n\\|.*stat(?:e|us).*\\|.*?)[_*]*(?:{$rxvals})[_*]*/", "\$1{$new}", $data["content"]); $data["content"] = preg_replace("/(\n\\|.*?)[_*]*(?:{$rxvals})[_*]*(.*?\\|.*{$ewiki_id})/", "\$1{$new}\$2", $data["content"]); ewiki_db::UPDATE($data); $data["version"]++; ewiki_db::WRITE($data); } } $o = "<p>(status changed)</p>"; $iii[0][0] = preg_replace("/({$rxvals})/", "{$new}", $iii[0][0]); } else { $url = ewiki_script("", $ewiki_id); $o .= <<<EOT <form action="{$url}#added" method="POST" enctype="multipart/form-data"> <input type="submit" name="brs_change" value="open"> <input type="submit" name="brs_change" value="closed"> <input type="submit" name="brs_change" value="frozen"> </form> EOT; } return $o; }
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; }
function ewiki_action_infoqdiff_plain($id, $data, $prev, $ver) { $CLK = "%c"; #-- get if ($d = ewiki_db::GET($id, $ver - 1)) { $curr = $prev; $prev = $d; $d = NULL; } else { continue; } #-- info header $o .= '<p>'; $o .= 'Version: <b><a href="' . ewiki_script_url("", $id, "version={$ver}") . "\">version {$ver}</a></b> / " . 'Author: <b>' . ewiki_author_html($curr["author"]) . "</b> / " . 'Time: <b>' . strftime($CLK, $curr["lastmodified"]) . "</b>"; $o .= '</p>'; #-- diff part $diff = ewiki_stupid_diff($curr["content"], $prev["content"], $show_unchanged = 0, $magic_notes = 1); $o .= '<p>' . $diff . '</p>'; return $o; }
function ewiki_tour($id, &$data, $action) { $o = "\n"; $page_lists = array(array($id), explode("\n", trim($data["refs"])), ewiki_get_backlinks($id)); foreach ($page_lists as $pages) { foreach ($pages as $page) { $row = ewiki_db::GET($page); if (EWIKI_DB_F_TEXT == $row["flags"] & EWIKI_DB_F_TYPE) { $add = substr($row["content"], 0, 333); $add = substr($add, 0, strrpos($add, " ")); $add = preg_replace("/^[!*#-:;>]+/m", "", $add); $add = strtr($add, "\n\t", " "); $o .= "!!! [tour:{$row[id]}]\n" . "@@tour-page-fragment {$add} ...\n\n"; } } } $o = ewiki_format($o); $o .= ewiki_control_links($id, $data, $action); return $o; }
function mkLiveWebNavBar($navBarPage, $activePage) { #-- fetch from db $data = ewiki_db::GET($navBarPage); #-- Authenticate, return nothing if authentication fails if (!ewiki_auth($navBarPage, $data, EWIKI_NAVBAR_ACTION, $ring = 3, $force = 0)) { return ""; } #-- escape if navBarPage does not exist or was not retrieved. if (empty($data["content"])) { return ""; } //echo(":".$data["content"].":"); $o .= ewiki_navbar_format($data["content"], 1, urlencode($activePage)); //Apply class only if we have a bar at all if ($o) { return " <div class='wikiNavBar' >\n" . $o . "\n</div>\n"; } return ""; }
function ewiki_mpi_addlink($action, $args, &$iii, &$s) { global $ewiki_id, $ewiki_action; $o = ""; #-- add URL if ($_REQUEST["link_save"]) { #-- check parameters $url = trim($_REQUEST["link_url"]); $text = ""; $title = $desc = ""; if (!strpos($url, "example.com") && strlen($url) > 12 && preg_match('#^https?://#', $url)) { $text = implode("", file($url)); if ($text) { preg_match('#<title[^>]*>([^<]+)</title>#ims', $text, $uu) and $title = $uu[1] or preg_match('#//([^/]+)#', $url, $uu) and $title = $uu[1]; preg_match('#<meta[^>]+name=["\']description["\'][^>]+content=["\']([^"\']+)["\']#ims', $text, $uu) and $desc = $uu[1] or preg_match('#<body[^>]+>(.+?)</body#ims', $text, $uu) and $desc = strip_tags($uu[1]); $desc = substr(preg_replace('/\\s+/', " ", $desc), 0, 300); } $add = ":{$title}:\n {$url} %%%\n {$desc}\n"; } #-- store bugreport if ($text) { $data = ewiki_db::GET($ewiki_id); $data["content"] = rtrim($data["content"]) . "\n" . $add; ewiki_data_update($data); $data["version"]++; ewiki_db::WRITE($data); #-- append to page output $iii[] = array($add, 0xffff, "core"); } } else { $url = ewiki_script("", $ewiki_id); $o .= <<<EOT <form style="border:2px #333370 solid; background:#7770B0; padding:5px;"class="BugReport" action="{$url}" method="POST" enctype="multipart/form-data"> <input type="hidden" name="id" value="{$ewiki_action}/{$ewiki_id}"> Link <input type="text" name="link_url" value="http://www.example.com/" size="50"> <input type="submit" name="link_save" value="hinzufügen"> </form> EOT; } return $o; }