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_format_nroff(&$source) { global $ewiki_id, $ewiki_config, $mancat; $mancat = "1"; // alternatively use "w" or "wiki" $o = ""; $source = trim($source); if (substr($source, 0, 2) == "#!") { $source = substr($source, strpos($source, "\n") + 1); } #-- wiki2man line by line foreach (explode("\n", $source) as $line) { #-- escaping $line = preg_replace("/^[.]/", "\n .", $line); #-- headlines $line = preg_replace("/^[!]+/", "\n.SH ", $line); #-- definiton lists $line = preg_replace("/^:(.+?):/", "\n.TP 5\n.B \$1\n", $line); #-- indented text $line = preg_replace("/^( [ ]+)/e", '"\\n.TP ".strlen("$1")."\\n"', $line); // $line = ltrim($line, " \t"); #-- ordinary lists $line = preg_replace("/^\\*/", "\n\n*", $line); $line = preg_replace("/^#/", "\n\n#", $line); #-- text style $line = preg_replace("/__(.+?)__/", "\n.B \$1\n", $line); $line = preg_replace("/\\*\\*(.+?)\\*\\*/", "\n.B \$1\n", $line); $line = preg_replace("/'''(.+?)'''/", "\n.B \$1\n", $line); $line = preg_replace("/''(.+?)''/", "\n.I \$1\n", $line); $line = preg_replace("/'''''(.+?)'''''/", "\n.BI \$1\n", $line); #-- rip out some things $line = preg_replace("/@@[^\\s]+/", "", $line); #-- paragraphs if (!strlen($line)) { $o .= "\n\n"; } #-- ok, out $o .= addslashes($line) . " "; } #-- highlight links ewiki_scan_wikiwords($source, $GLOBALS["ewiki_man_links"]); $o = preg_replace_callback($ewiki_config["wiki_link_regex"], "ewiki_format_man_linkrxcb", $o); #-- post fixes $o = preg_replace("/\n\\s*\n+/", "\n\n", $o); $o = preg_replace("/^ ([^\\s])/m", "\$1", $o); #-- prefix output $monthyear = strftime("%B %Y", time()); $name = EWIKI_NAME; $o = ".\\\" this man page was converted by ewiki,\n" . ".\\\" many apologies if it doesn't work\n" . ".\\\"\n" . ".TH \"{$ewiki_id}\" {$mancat} \"{$monthyear}\" \"{$name}\" \"{$name}\"\n" . (!preg_match("/^\\s*\\.SH/", $o) ? "\n.SH {$ewiki_id}\n" : "") . "\n" . $o; 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_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"; } } }
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 .= " "; $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 ""; } } }
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; }
function markup_convert() { global $ewiki_plugins; #-- in-conversion if ($pf_a = $ewiki_plugins["format_source"]) { foreach ($pf_a as $pf) { $pf($data["content"]); } } #-- out-conversion if ($pf_a = $ewiki_plugins["markup_convert"]) { foreach ($pf_a as $pf) { $pf($data["content"]); } } #-- update {refs} (helpful for PmWiki, which does not have an equivalent) ewiki_scan_wikiwords($data["content"], $ewiki_links, "_STRIP_EMAIL=1"); $data["refs"] = "\n\n" . implode("\n", array_keys($ewiki_links)) . "\n\n"; //fin }
function ewiki_navbar_format($wiki_source, $scan_links = 1, $currpage = EWIKI_PAGE_INDEX) { global $ewiki_links, $ewiki_plugins; //echo("navbar function run"); // pre-scan WikiLinks if ($scan_links) { ewiki_scan_wikiwords($wiki_source, $ewiki_links); } // formatted output $o = "\n"; // plugins only format finals are respected $pf_final = @$ewiki_plugins["format_final"]; $table_defaults = 'cellpadding="2" border="1" cellspacing="0"'; $syn_htmlentities = array("&" => "&", ">" => ">", "<" => "<", "%%%" => "<br />"); $wm_list = array("-" => array('ul type="square"', "", "li"), "*" => array('ul type="circle"', "", "li"), "#" => array("ol", "", "li"), ":" => array("dl", "dt", "dd"), ";" => array("dl", "dt", "dd")); // eleminate html foreach ($syn_htmlentities as $find => $replace) { $wiki_source = str_replace($find, $replace, $wiki_source); } array_pop($syn_htmlentities); // strips "&" // add a last empty line to get opened tables/lists closed correctly $wiki_source = trim($wiki_source) . "\n"; #-- finally the link-detection-regex # (impossible to do with the simple string functions) ewiki_render_wiki_links($wiki_source); $NavBar = array(); //return($wiki_source); foreach (explode("\n", $wiki_source) as $line) { $line = rtrim($line); $lineout = ""; #-- wiki list markup if (strlen($line) && isset($wm_list[@$line[0]])) { $n = 0; $li = ""; #-- count depth of list # line has length first character in the line is in wm_list while (strlen($line) && '*' == $line[0]) { $li .= '*'; //add new list delim to list count $n++; //count depth $line = substr($line, 1); //remove first character } $line = ltrim($line); $regex = '#<a href=["\'](.*)' . preg_quote(EWIKI_SCRIPT) . '(.*?)["\'&?^](.*)#i'; preg_match($regex, $line, $matches = array()); $href = $matches[2]; //echo($regex.$line."HREF'".$href."'"); $NavBar[] = array($line, $n, 0, $href); //echo($line.$n.count($NavBar)); } } //$NavBar now contains all elements in the navigation bar. //return(""); $NavBar = $ewiki_plugins['select_navbar_buttons'][0]($NavBar, $currpage); reset($NavBar); $pre = ''; $post = ''; $barText = $ewiki_plugins['render_navbar_section'][0]($pre, $post, $NavBar); $barText = $pre . $barText . $post; //Cut out if we have no navigation bar if (!$barText) { return ""; } #-- close last line $o .= $barText . "\n"; #-- international characters if (EWIKI_HTML_CHARS) { $o = str_replace("&#", "&#", $o); } #-- call post processing plugins if ($pf_final) { foreach ($pf_final as $pf) { $pf($o); } } return $o; }
// {meta} $data["meta"] = recreate_meta($_REQUEST["new"]["meta"]); // {flags} $data["flags"] = 0x0; foreach ($_REQUEST["new_flags"] as $bit => $state) { if ($state) { $data["flags"] += 1 << $bit; } } // {lastmodified} if ($_REQUEST["update"]["lastmodified"]) { $data["lastmodified"] = time(); } // {refs} if ($_REQUEST["update"]["refs"]) { ewiki_scan_wikiwords($data["content"], $links, "_STRIP_EMAIL=1"); $data["refs"] = "\n\n" . implode("\n", array_keys($links)) . "\n\n"; } else { $data["refs"] = "\n\n" . trim(trim($data["refs"], "\n"), "\r") . "\n\n"; } // {content} if ($data["flags"] & EWIKI_DB_F_TEXT) { $data["content"] = preg_replace("/\r*(\n)\r?/", "\$1", $data["content"]); } #-- ok, throw into DB if (ewiki_db::WRITE($data, $overwrite = 1)) { echo "<div class=\"msg\">page written into database</div>\n\n"; } else { echo "<div class=\"msg\">error writing entry to db</div>\n\n"; } }
<?php /* Everybody who leaves a mail address on the "RecentNotify" page, will get a summary of all made edits, once in a week (configured to 8 days per default). */ define("RECENTNOTIFY", "RecentNotify"); // special page name (w/ subscribers) define("RECENTNOTIFY_DAYS", 8); // in days #-- do if (RECENTNOTIFY_DAYS && ($data = ewiki_db::GET(RECENTNOTIFY))) { echo "[{$cron}]: checking for " . RECENTNOTIFY . " subscribers\n"; #-- look up subscribers ewiki_scan_wikiwords($data["content"], $uu, $_strip_email = 0); $subscribers = array(); if ($uu) { foreach ($uu as $str => $x) { if (strpos($str, "@")) { if (strpos($str, "notify:") !== false) { $str = substr($str, strpos($str, ":")); } $subscribers[] = $str; } } } #-- only calc the RC if we have at least one interested if ($subscribers) { echo "[{$cron}]: " . count($subscribers) . " listed (" . implode(", ", $subscribers) . ")\n"; $min_time = time() - RECENTNOTIFY_DAYS * 24 * 3600;
function ewiki_notify_edit_hook($id, $data, &$hidden_postdata) { global $ewiki_t, $ewiki_plugins; $ret_err = 0; if (!isset($_REQUEST["save"])) { return false; } #-- list from current page $mailto = ewiki_notify_links($data["content"], 0); #-- add entries from GlobalNotify page/list if ($add = ewiki_db::GET(EWIKI_NOTIFY_GLOBAL)) { ewiki_scan_wikiwords($add["content"], $uu, $strip_emails = false); foreach ($uu as $add => $stat) { if (strpos($add, "@") && strpos($add, ".")) { $mailto[] = str_replace("notify:", "", $add); } } } if (!count($mailto)) { return false; } #-- generate diff $diff = ""; if (EWIKI_NOTIFY_WITH_DIFF && DIRECTORY_SEPARATOR == "/") { #-- save page versions temporarily as files $fn1 = EWIKI_TMP . "/ewiki.tmp.notify.diff." . md5($data["content"]); $fn2 = EWIKI_TMP . "/ewiki.tmp.notify.diff." . md5($_REQUEST["content"]); $f = fopen($fn1, "w"); fwrite($f, $data["content"]); fclose($f); $f = fopen($fn2, "w"); fwrite($f, $_REQUEST["content"]); fclose($f); #-- set mtime of the old one (GNU diff will report it) touch($fn1, $data["lastmodified"]); #-- get diff output, rm temp files $diff_exe = EWIKI_NOTIFY_DIFF_EXE; $diff_params = EWIKI_NOTIFY_DIFF_PARAMS; if ($f = popen("{$diff_exe} {$diff_params} {$fn1} {$fn2} 2>&1 ", "r")) { $diff .= fread($f, 16 << 10); pclose($f); $diff_failed = !strlen($diff) || strpos($diff, "Files ") === 0; #-- do not [notify:] if changes were minimal if (!$diff_failed && strlen($diff) < EWIKI_NOTIFY_WITH_DIFF) { #echo("WikiNotice: no notify, because too few changes (" .strlen($diff)." byte)\n"); $ret_err = 1; } $diff = "\n\n-----------------------------------------------------------------------------\n\n" . $diff; } else { $diff = ""; #echo("WikiWarning: diff failed in notify module\n"); } unlink($fn1); unlink($fn2); if ($ret_err) { return false; } } #-- separate addresses into (TLD) groups $mailto_lang = array(); foreach ($mailto as $m) { $lang = ""; #-- remove lang selection trailer $m = strtok($m, ","); if ($uu = strtok(",")) { $lang = $uu; } $m = strtok($m, ";"); if ($uu = strtok(";")) { $lang = $uu; } #-- else use TLD as language code if (empty($lang)) { $r = strrpos($m, "."); $lang = substr($m, $r + 1); } $lang = trim($lang); #-- address mangling $m = trim($m); if (substr($m, 0, 4) == "icq:") { $m = substr($m, 4) . "@pager.icq.com"; } $mailto_lang[$lang][] = $m; } #-- go thru email address groups foreach ($mailto_lang as $lang => $a_mailto) { $pref_langs = array("{$lang}", "en") + (array) $ewiki_t["languages"]; $server = $_SERVER["HTTP_HOST"] or $server = $_SERVER["SERVER_NAME"]; $s_4 = "http" . ($_SERVER['HTTPS'] == "on" ? 's' : '') . "://" . $server . $_SERVER["REQUEST_URI"]; $link = str_replace("edit/{$id}", "{$id}", $s_4); $difflink = str_replace("edit/{$id}", "diff/{$id}", $s_4); $m_text = ewiki_t("NOTIFY_BODY", array("id" => $id, "link" => $link, "diff_link" => $difflink, "edit_link" => $s_4, "server_admin" => $_SERVER["SERVER_ADMIN"], "server" => $server, "wiki_title" => EWIKI_PAGE_INDEX), $pref_langs); $m_text .= $diff; $m_from = EWIKI_NOTIFY_SENDER . "@{$server}"; $m_subject = ewiki_t("NOTIFY_SUBJECT", array("id" => $id), $pref_langs); $m_to = implode(", ", $a_mailto); mail($m_to, $m_subject, $m_text, "From: \"{$s_2}\" <{$m_from}>\nX-Mailer: ErfurtWiki/" . EWIKI_VERSION); } }