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; }
function ewiki_edit_patch($id, &$data) { $version = optional_param('version', null); $content = optional_param('content', ''); $r = false; $base = ewiki_database("GET", array("id" => $id, "version" => $version)); if (!$base) { return false; } $fn_base = EWIKI_TMP . "/ewiki.base." . md5($base["content"]); $fn_requ = EWIKI_TMP . "/ewiki..requ." . md5($content); $fn_patch = EWIKI_TMP . "/ewiki.patch." . md5($base["content"]) . "-" . md5($content); $fn_curr = EWIKI_TMP . "/ewiki.curr." . md5($data["content"]); if ($f = fopen($fn_base, "w")) { fwrite($f, $base["content"]); fclose($f); } else { return false; } if ($f = fopen($fn_requ, "w")) { fwrite($f, $content); fclose($f); } else { unlink($fn_base); return false; } if ($f = fopen($fn_curr, "w")) { fwrite($f, $data["content"]); fclose($f); } else { unlink($fn_base); unlink($fn_requ); return false; } exec("diff -c {$fn_base} {$fn_requ} > {$fn_patch}", $output, $retval); if ($retval) { exec("patch {$fn_curr} {$fn_patch}", $output, $retval); if (!$retval) { /// mrc - ?? what is $curr supposed to be ?? $_REQUEST["version"] = $_POST["version"] = $_GET["version"] = $curr["version"]; $_REQUEST["content"] = $_POST["content"] = $_GET["content"] = implode("", file($fn_curr)); $r = true; } } unlink($fn_base); unlink($fn_requ); unlink($fn_patch); unlink($fn_curr); return $r; }
/** * Save selected pageimage value by setting it in the meta field of save data array * passed by reference. * * @param array save associative array of ewiki form data */ function ewiki_edit_save_pageimgcntrl(&$save) { if (isset($_REQUEST['pageimagecntrl'])) { if ($_REQUEST['pageimagecntrl'] == -1) { unset($save['meta']['pageimage']); } else { $imageExist = ewiki_database('FIND', array($_REQUEST['pageimagecntrl'])); //var_dump($imageExist); if ($imageExist[$_REQUEST['pageimagecntrl']]) { $save['meta']['pageimage'] = $_REQUEST['pageimagecntrl']; } } } }
function ewiki_edit_patch($id, &$data) { $r = false; $base = ewiki_database("GET", array("id" => $id, "version" => $_REQUEST["version"])); if (!$base) { return false; } $fn_base = EWIKI_TMP . "/ewiki.base." . md5($base["content"]); $fn_requ = EWIKI_TMP . "/ewiki..requ." . md5($_REQUEST["content"]); $fn_patch = EWIKI_TMP . "/ewiki.patch." . md5($base["content"]) . "-" . md5($_REQUEST["content"]); $fn_curr = EWIKI_TMP . "/ewiki.curr." . md5($data["content"]); if ($f = fopen($fn_base, "w")) { fwrite($f, $base["content"]); fclose($f); } else { return false; } if ($f = fopen($fn_requ, "w")) { fwrite($f, $_REQUEST["content"]); fclose($f); } else { unlink($fn_base); return false; } if ($f = fopen($fn_curr, "w")) { fwrite($f, $data["content"]); fclose($f); } else { unlink($fn_base); unlink($fn_requ); return false; } exec("diff -c {$fn_base} {$fn_requ} > {$fn_patch}", $output, $retval); if ($retval) { exec("patch {$fn_curr} {$fn_patch}", $output, $retval); if (!$retval) { $_REQUEST["version"] = $curr["version"]; $_REQUEST["content"] = implode("", file($fn_curr)); $r = true; } } unlink($fn_base); unlink($fn_requ); unlink($fn_patch); unlink($fn_curr); ewiki_log("patchsaving of {$id}[{$data[version]}] was " . ($r ? "" : "un") . "successful", 2); return $r; }
function ewiki_page_wantedpages($id, $data, $action) { $wanted = array(); #-- collect referenced pages $result = ewiki_database("GETALL", array("refs")); while ($row = $result->get()) { if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($row["id"], $uu, "view")) { continue; } $refs .= $row["refs"]; } #-- build array $refs = array_unique(explode("\n", $refs)); #-- strip existing pages from array $refs = ewiki_database("FIND", $refs); foreach ($refs as $id => $exists) { if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($row["id"], $uu, "view")) { continue; } if (!$exists && !strstr($id, "://") && strlen(trim($id))) { $wanted[] = $id; } } // to prevent empty <ul></ul> getting printed out, we have to interate twice. // once to make sure the <ul></ul> is needed at all. // MDL-7861, <ul></ul> does not validate. $printul = false; foreach ($wanted as $page) { $link = ewiki_link_regex_callback(array($page, $page)); if (strstr($link, "?</a>")) { $printul = true; } } #-- print out if ($printul) { $o .= "<ul>"; foreach ($wanted as $page) { $link = ewiki_link_regex_callback(array($page, $page)); if (strstr($link, "?</a>")) { $o .= "<li>" . $link . "</li>"; } } $o .= "</ul>"; } return $o; }
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; }
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; }
function ewiki_valid_pages($bool_allowimages = 0, $virtual_pages = 0) { //$time=getmicrotime(); global $ewiki_plugins; $result = ewiki_database("GETALL", array("flags", "refs", "meta")); while ($row = $result->get()) { if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($row["id"], $str_null, "view")) { continue; } $isbinary = $row["meta"]["class"] == "image" || $row["meta"]["class"] == "file" ? true : false; if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT || ($bool_allowimages ? $isbinary : 0)) { $temp_refs = explode("\n", $row["refs"]); foreach ($temp_refs as $key => $value) { if (empty($value)) { unset($temp_refs[$key]); } } if ($isbinary) { $a_validpages[$row["id"]] = $temp_array = array("refs" => $temp_refs, "type" => $row["meta"]["class"], "touched" => FALSE); } else { $a_validpages[$row["id"]] = $temp_array = array("refs" => $temp_refs, "type" => "page", "touched" => FALSE); } unset($temp_refs); } } if ($virtual_pages) { #-- include virtual pages to the sitemap. $virtual = array_keys($ewiki_plugins["page"]); foreach ($virtual as $vp) { if (!EWIKI_PROTECTED_MODE || !EWIKI_PROTECTED_MODE_HIDING || ewiki_auth($vp, $str_null, "view")) { $a_validpages[$vp] = array("refs" => array(), "type" => "page", "touched" => FALSE); } } } return $a_validpages; }
function ewiki_page_wiki_dump_send($exportbinaries = 0, $exportformats = 0, $withvirtualpages = 0, $exportdestinations = 0) { global $ewiki_config, $wiki, $ewiki_plugins, $wiki_entry, $course, $CFG, $ewiki_t, $userid, $groupid; $filestozip = array(); #-- disable protected email if (is_array($ewiki_plugins["link_url"])) { foreach ($ewiki_plugins["link_url"] as $key => $linkplugin) { if ($linkplugin == "ewiki_email_protect_link") { unset($ewiki_plugins["link_url"][$key]); } } } /// HTML-Export if ($exportformats == 1) { #-- if exportformats is html $HTML_TEMPLATE = '<html> <head>' . $ewiki_t["c"]["EWIKIDUMPCSS"] . ' <title>$title</title> </head> <body bgcolor="#ffffff";> <div id="PageText"> <h2>$title</h2> $content </div> </body> </html>'; #-- reconfigure ewiki_format() to generate offline pages and files $html_ext = ".html"; $ewiki_config["script"] = "%s{$html_ext}"; $ewiki_config["script_binary"] = "%s"; } // Export Virtual pages special $a_virtual = array_keys($ewiki_plugins["page"]); #-- get all pages / binary files $a_validpages = ewiki_valid_pages(1, $withvirtualpages); $a_pagelist = ewiki_sitemap_create($wiki_entry->pagename, $a_validpages, 100, 1); # Add linked binary files to pagelist foreach ($a_pagelist as $key => $value) { if (is_array($a_validpages[$value]["refs"])) { foreach ($a_validpages[$value]["refs"] as $refs) { if ($a_validpages[$refs]["type"] == "image" || $a_validpages[$refs]["type"] == "file") { $a_pagelist[] = $refs; } } } } # Adjust links to binary files foreach ($a_pagelist as $key => $value) { if ($a_validpages[$value]["type"] == "image") { $a_images[] = urlencode($value); $a_rimages[] = urlencode(preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", $value)); unset($a_validpages[$value]); } if ($a_validpages[$value]["type"] == "file") { $a_images[] = urlencode($value); $a_rimages[] = clean_filename(substr($value, strlen(EWIKI_IDF_INTERNAL))); $a_images[] = $value; $a_rimages[] = clean_filename(substr($value, strlen(EWIKI_IDF_INTERNAL))); unset($a_validpages[$value]); } } # Remove binaries from a_validpages and add to a_pagelist foreach ($a_validpages as $key => $value) { if ($a_validpages[$key]["type"] == "image" || $a_validpages[$key]["type"] == "file") { $a_pagelist[] = $key; unset($a_validpages[$key]); } } #print "<pre>"; print_r($a_validpages); print "</pre>"; #print "<hr /><pre>"; print_r($a_pagelist); print "</pre>"; $a_sitemap = ewiki_sitemap_create($wiki_entry->pagename, $a_validpages, 99, 0); if ($a_pagelist) { #-- create new zip file #if($arctype == "ZIP"){ # $archivename=EWIKI_WIKIDUMP_ARCNAME."$rootid.zip"; # $archive = new ewiki_virtual_zip(); #} elseif ($arctype == "TAR") { # $archivename=EWIKI_WIKIDUMP_ARCNAME."$rootid.tar"; # $archive = new ewiki_virtual_tarball(); #} else { # die(); #} /// Create/Set Directory $wname = clean_filename(strip_tags(format_string($wiki->name, true))); if ($exportdestinations) { if (wiki_is_teacher($wiki)) { $exportdir = $CFG->dataroot . "/" . $course->id . "/" . $exportdestinations; } else { add_to_log($course->id, "wiki", "hack", "", format_string($wiki->name, true) . ": Tried to export a wiki as non-teacher into {$exportdestinations}."); error("You are not a teacher !"); } } else { $exportbasedir = tempnam("/tmp", "WIKIEXPORT"); @unlink($exportbasedir); @mkdir($exportbasedir); /// maybe we need to check the name here...? $exportdir = $exportbasedir . "/" . $wname; @mkdir($exportdir); if (!is_dir($exportdir)) { error("Cannot create temporary directory {$exportdir} !"); } } $a_pagelist = array_unique($a_pagelist); #-- convert all pages foreach ($a_pagelist as $pagename) { if (!in_array($pagename, $a_virtual)) { $id = $pagename; #-- not a virtual page $row = ewiki_database("GET", array("id" => $pagename)); $content = ""; } elseif ($withvirtualpages) { $id = $pagename; #-- is a virtual page $pf = $ewiki_plugins["page"][$id]; $content = $pf($id, $content, "view"); if ($exportformats == 1) { $content = str_replace('$content', $content, str_replace('$title', $id, $HTML_TEMPLATE)); } $fn = urlencode($id); $fn = preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", $fn); $fn = $fn . $html_ext; } else { continue; } if (empty($content)) { switch ($row["flags"] & EWIKI_DB_F_TYPE) { // Text Page case EWIKI_DB_F_TEXT: #print "<pre>"; print_r($row[content]); print "\n-------------</pre>"; if ($exportformats == 1) { /// HTML-Export $content = ewiki_format($row["content"]); } else { $content = $row["content"]; } # Binary files link adjustment when html if ($exportformats == 1) { $content = str_replace($a_images, $a_rimages, $content); } $fn = preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", urlencode($id)); $fn = $fn . $html_ext; if ($exportformats == 1) { /// HTML-Export $content = str_replace('$content', $content, str_replace('$title', $id, $HTML_TEMPLATE)); } break; case EWIKI_DB_F_BINARY: #print "Binary: $row[id]<br />"; if (($row["meta"]["class"] == "image" || $row["meta"]["class"] == "file") && $exportbinaries) { # Copy files to the appropriate directory $fn = moodle_binary_get_path($id, $row["meta"], $course, $wiki, $userid, $groupid); $destfn = clean_filename(substr($id, strlen(EWIKI_IDF_INTERNAL))); $dest = "{$exportdir}/" . $destfn; if (!copy($fn, $dest)) { notify("Cannot copy {$fn} to {$dest}."); } #$fn = urlencode(preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", $id)); #$content = &$row["content"]; $filestozip[] = $exportdir . "/" . $destfn; continue 2; } else { #-- php considers switch statements as loops so continue 2 is needed to #-- hit the end of the for loop continue 2; } break; default: # don't want it continue 2; } } # Do not translate links when wiki already in pure html - mode if ($wiki->htmlmode != 2) { $content = preg_replace_callback('/(<a href=")(.*?)(\\.html">)/', create_function('$matches', 'return($matches[1].preg_replace(EWIKI_DUMP_FILENAME_REGEX,"",$matches[2]).$matches[3]);'), $content); } #-- add file // Let's make sure the file exists and is writable first. if (!($handle = fopen($exportdir . "/" . $fn, 'w'))) { error("Cannot open file ({$exportdir}/{$fn})"); } // Write $content to our opened file. if (fwrite($handle, $content) === FALSE) { error("Cannot write to file ({$exportdir}/{$fn})"); } fclose($handle); $filestozip[] = $exportdir . "/" . $fn; #$archive->add($content, $fn, array( # "mtime" => $row["lastmodified"], # "uname" => "ewiki", # "mode" => 0664 | (($row["flags"]&EWIKI_DB_F_WRITEABLE)?0002:0000), # ), $complevel); } #-- create index page /// HTML-Export if ($exportformats == 1) { $timer = array(); $level = -1; $fordump = 1; $str_formatted = "<ul>\n<li><a href=\"" . $wiki_entry->pagename . $html_ext . "\">" . $wiki_entry->pagename . "</a></li>"; $fin_level = format_sitemap($a_sitemap, $wiki_entry->pagename, $str_formatted, $level, $timer, $fordump); $str_formatted .= "</ul>" . str_pad("", $fin_level * 6, "</ul>\n"); $str_formatted = preg_replace_callback('/(<a href=")(.*?)(\\.html">)/', create_function('$matches', 'return($matches[1].preg_replace(EWIKI_DUMP_FILENAME_REGEX,"",$matches[2]).$matches[3]);'), $str_formatted); $str_formatted = str_replace('$content', $str_formatted, str_replace('$title', get_string("index", "wiki"), $HTML_TEMPLATE)); #-- add file // Let's make sure the file exists and is writable first. $indexname = "index" . $html_ext; if (!($handle = fopen($exportdir . "/" . $indexname, 'w'))) { error("Cannot open file ({$exportdir}/{$indexname})"); } // Write $somecontent to our opened file. if (fwrite($handle, $str_formatted) === FALSE) { error("Cannot write to file ({$exportdir}/{$indexname})"); } fclose($handle); $filestozip[] = $exportdir . "/" . $indexname; #-- add index page # $archive->add($str_formatted, "Index_$rootid".$html_ext, array( # "mtime" => $row["lastmodified"], # "uname" => "ewiki", # "mode" => 0664 | (($row["flags"]&EWIKI_DB_F_WRITEABLE)?0002:0000), # ), $complevel); } if (!$exportdestinations) { $archivename = $wname . ".zip"; zip_files($filestozip, "{$exportbasedir}/{$archivename}"); #-- Headers Header("Content-type: application/zip"); Header("Content-disposition: attachment; filename=\"{$archivename}\""); Header("Cache-control: private"); Header("Original-Filename: {$archivename}"); Header("X-Content-Type: application/zip"); Header("Content-Location: {$archivename}"); if (!@readfile("{$exportbasedir}/{$archivename}")) { error("Cannot read {$exportbasedir}/{$archivename}"); } if (!deldir($exportbasedir)) { error("Cannot delete {$exportbasedir}"); } #exit(); return false; } else { return get_string("exportsuccessful", "wiki") . "<br />"; } } }
function get($all = 0, $flags = 0x0) { $row = array(); $prot_hide = $flags & 0x20 && EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING; do { if (count($this->entries)) { #-- fetch very first entry from $entries list $r = array_shift($this->entries); #-- finish if buffered entry if (is_array($r) && !$all) { $row = $r; } else { if (is_array($r)) { $r = $r["id"]; } $r = ewiki_database("GET", array("id" => $r)); if (!$all) { foreach ($this->keys as $key) { $row[$key] = $r[$key]; } } else { $row = $r; } } unset($r); } else { return NULL; // no more entries } #-- expand {meta} field if (is_array($row) && is_string(@$row["meta"])) { $row["meta"] = unserialize($row["meta"]); } #-- drop unwanted results if ($prot_hide && !ewiki_auth($row["id"], $row, $ewiki_action)) { $row = array(); } } while ($prot_hide && empty($row)); return $row; }
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 wiki_admin_revert($proceed, $authorfieldpattern, $changesfield, $howtooperate, $deleteversions) { $ret = ""; #-- params $m_time = $changesfield * 3600; $depth = $deleteversions - 1; $depth = $depth > 0 ? $depth : 0; #-- walk through $result = ewiki_database("GETALL", array("id", "author", "lastmodified")); while ($row = $result->get()) { $id = $row["id"]; #-- which versions to check $verZ = $row["version"]; if ($howtooperate == "lastonly") { $verA = $verZ; } else { $verA = $verZ - $depth; if ($verA <= 0) { $verA = 1; } } for ($ver = $verA; $ver <= $verZ; $ver++) { #-- load current $ver database entry if ($verA != $verZ) { $row = ewiki_database("GET", array("id" => $id, "version" => $ver)); } #-- match if (stristr($row["author"], $authorfieldpattern) && $row["lastmodified"] + $m_time > time()) { $ret .= "{$id} (" . get_string("versionstodelete", "wiki") . ": "; #-- delete multiple versions if ($howtooperate == "allsince") { while ($ver <= $verZ) { $ret .= " {$ver}"; if ($proceed) { ewiki_database("DELETE", array("id" => $id, "version" => $ver)); } $ver++; } } else { $ret .= " {$ver}"; if ($proceed) { ewiki_database("DELETE", $row); } } $ret .= ")<br />"; break; } } #-- for($ver) } #-- while($row) return $ret; }
function ewiki_page_filedownload($id, $data, $action, $def_sec = "") { global $ewiki_binary_icons, $ewiki_upload_sections; $o = ewiki_make_title($id, $id, 2); #<off># $o .= ewiki_t("DWNL_SEEUPL", '$scr'=>ewiki_script("", "")); #-- params (section, orderby) $orderby = $_REQUEST["orderby"] or $orderby = "created"; if ($def_sec) { $section = $def_sec; } else { $section = $_REQUEST["section"] or $section = ""; if (count($ewiki_upload_sections) > 1) { $oa = array(); $ewiki_upload_sections["*"] = "*"; if (empty($ewiki_plugins["action"][EWIKI_ACTION_ATTACHMENTS])) { $ewiki_upload_sections["**"] = "**"; } foreach ($ewiki_upload_sections as $sec => $title) { $oa[] = '<a href="' . ewiki_script("", $id, array("orderby" => $orderby, "section" => $sec)) . '">' . $title . "</a>"; } $o .= '<div class="mdl-align darker">' . implode(" · ", $oa) . '</div><br />'; } } #-- collect entries $files = array(); $sorted = array(); $result = ewiki_database("GETALL", array("flags", "meta", "created", "hits", "userid")); while ($row = $result->get()) { if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_BINARY) { $m =& $row["meta"]; if (!$section) { $section = "**"; } if ($m["section"] != $section) { if ($section == "**") { } elseif ($section == "*" && !empty($ewiki_upload_sections[$m["section"]])) { } else { continue; } } else { } $files[$row["id"]] = $row; $sorted[$row["id"]] = $row[$orderby]; } } #-- sort arsort($sorted); #-- slice $pnum = $_REQUEST[EWIKI_UP_PAGENUM] or $pnum = 0; if (count($sorted) > EWIKI_LIST_LIMIT) { $o_nl .= '<div class="lighter">>> '; for ($n = 0; $n < (int) (count($sorted) / EWIKI_LIST_LIMIT); $n++) { $o_nl .= '<a href="' . ewiki_script("", $id, array("orderby" => $orderby, "section" => $section, EWIKI_UP_PAGENUM => $n)) . '">[' . $n . "]</a> "; } $o_nl .= '</div><br />'; $o .= $o_nl; } $sorted = array_slice($sorted, $pnum * EWIKI_LIST_LIMIT, EWIKI_LIST_LIMIT); #-- output if (empty($sorted)) { $o .= ewiki_t("DWNL_NOFILES"); } else { foreach ($sorted as $id => $uu) { $row = $files[$id]; $o .= ewiki_entry_downloads($row, $section[0] == "*", true); } } $o .= $o_nl; return $o; }
function ewiki_page_stupid_diff($id, $data, $action) { global $wiki, $moodle_format; if ($uu = $GLOBALS["ewiki_diff_versions"]) { list($new_ver, $old_ver) = $uu; $data = ewiki_database("GET", array("id" => $id, "version" => $new_ver)); } else { $new_ver = $data["version"]; $old_ver = $new_ver - 1; } if ($old_ver > 0) { $data0 = ewiki_database("GET", array("id" => $id, "version" => $old_ver)); } $a->new_ver = $new_ver; $a->old_ver = $old_ver; $a->pagename = $id; $o = ewiki_make_title($id, get_string("differences", "wiki", $a)); # Different handling for html: closes Bug #1530 - Wiki diffs useless when using HTML editor if ($wiki->htmlmode == 2) { /// first do the formatiing to get normal display format without filters $options = new object(); $options->smiley = false; $options->filter = false; $content0 = format_text($data0['content'], $moodle_format, $options); $content = format_text($data['content'], $moodle_format, $options); /// Remove all new line characters. They will be placed at HTML line breaks. $content0 = preg_replace('/\\n|\\r/i', ' ', $content0); $content0 = preg_replace('/(\\S)\\s+(\\S)/', '$1 $2', $content0); // Remove multiple spaces. $content = preg_replace('/\\n|\\r/i', ' ', $content); $content = preg_replace('/(\\S)\\s+(\\S)/', '$1 $2', $content); /// Replace <p> </p> $content0 = preg_replace('#(<p( [^>]*)?>( |\\s+)</p>)|(<p( [^>]*)?></p>)#i', "\n", $content0); $content = preg_replace('#(<p( [^>]*)?>( |\\s+)</p>)|(<p( [^>]*)?></p>)#i', "\n", $content); /// Place new line characters at logical HTML positions. $htmlendings = array('+(<br.*?>)+iU', '+(<p( [^>]*)?>)+iU', '+(</p>)+i', '+(<hr.*?>)+iU', '+(<ol.*?>)+iU', '+(</ol>)+i', '+(<ul.*?>)+iU', '+(</ul>)+i', '+(<li.*?>)+iU', '+(</li>)+i', '+(</tr>)+i', '+(<div.*?>)+iU', '+(</div>)+i'); $htmlrepl = array("\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n"); $content0 = preg_replace($htmlendings, $htmlrepl, $content0); $content = preg_replace($htmlendings, $htmlrepl, $content); } else { $content0 = $data0["content"]; $content = $data["content"]; } $txt0 = preg_split("+\\s*\n+", trim($content0)); $txt2 = preg_split("+\\s*\n+", trim($content)); $diff0 = array_diff($txt0, $txt2); $diff2 = array_diff($txt2, $txt0); foreach ($txt2 as $i => $line) { $i2 = $i; while ($rm = $diff0[$i2++]) { if ($wiki->htmlmode == 2) { if ($rm == '<br />') { //ugly hack to fix line breaks $rm = ''; } $o .= "<b>-</b><font color=\"#990000\">" . format_text($rm, $moodle_format, $options) . "</font><br />\n"; } else { $o .= "<b>-</b><font color=\"#990000\"><tt>" . s($rm) . "</tt></font><br />\n"; } unset($diff0[$i2 - 1]); } if (in_array($line, $diff2)) { if ($wiki->htmlmode == 2) { if ($line == '<br />') { //ugly hack to fix line breaks $line = ''; } $o .= "<b>+</b><font color=\"#009900\">" . format_text($line, $moodle_format, $options) . "</font><br />\n"; } else { $o .= "<b>+</b><font color=\"#009900\"><tt>" . s($line) . "</tt></font><br />\n"; } } else { if ($wiki->htmlmode == 2) { $o .= format_text($line, $moodle_format, $options) . "\n"; } else { $o .= " " . s($line) . "<br />\n"; } } } foreach ($diff0 as $rm) { $o .= "<b>-</b><font color=\"#990000\"> <tt>" . s($rm) . "</tt></font><br />\n"; } return $o; }