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 />";
        }
    }
}
Example #2
0
/// Is an Action given ?
if (!$action) {
    error(get_string("noadministrationaction", "wiki"));
}
/// Correct Action ?
if (!in_array($action, array("setpageflags", "removepages", "strippages", "checklinks", "revertpages"))) {
    error("Unknown action '{$action}'", "wiki");
}
/// May the User administrate it ?
if (($wiki_entry = wiki_get_entry($wiki, $course, $userid, $groupid)) === false || wiki_can_edit_entry($wiki_entry, $wiki, $USER, $course) === false) {
    error(get_string("notadministratewiki", "wiki"));
}
$canedit = wiki_can_edit_entry($wiki_entry, $wiki, $USER, $course);
# Check for dangerous events (hacking) !
if (in_array($action, array("removepages", "strippages", "revertpages"))) {
    if (!($wiki->wtype == "student" || ($wiki->wtype == "group" and $canedit) || wiki_is_teacher($wiki))) {
        add_to_log($course->id, "wiki", "hack", "", $wiki->name . ": Tried to trick admin.php with action={$action}.");
        error("Hack attack detected !");
    }
}
# Database and Binary Handler
include_once $CFG->dirroot . "/mod/wiki/ewikimoodlelib.php";
include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php";
/// The wiki_entry->pagename is set to the specified value of the wiki,
/// or the default value in the 'lang' file if the specified value was empty.
define("EWIKI_PAGE_INDEX", $wiki_entry->pagename);
# The mighty Wiki itself
include_once $CFG->dirroot . "/mod/wiki/ewiki/ewiki.php";
$strwikis = get_string("modulenameplural", "wiki");
$strwiki = get_string("modulename", "wiki");
/// Validate Form
Example #3
0
function wiki_print_administration_actions($wiki, $cmid, $userid, $groupid, $page, $noeditor, $course)
{
    /// Displays actions which can be performed on the page
    /// Create the URL
    $ewscript = 'admin.php?id=' . $cmid;
    if (isset($userid) && $userid != 0) {
        $ewscript .= '&amp;userid=' . $userid;
    }
    if (isset($groupid) && $groupid != 0) {
        $ewscript .= '&amp;groupid=' . $groupid;
    }
    if (isset($page)) {
        $ewscript .= '&amp;page=' . $page;
    }
    $ewscript .= "&amp;action=";
    /// Build that action array according to wiki flags.
    $action = array();
    $isteacher = wiki_is_teacher($wiki);
    if ($wiki->setpageflags or $isteacher) {
        $action['setpageflags'] = get_string('setpageflags', 'wiki');
    }
    if ($wiki->removepages or $isteacher) {
        $action['removepages'] = get_string('removepages', 'wiki');
    }
    if ($wiki->strippages or $isteacher) {
        $action['strippages'] = get_string('strippages', 'wiki');
    }
    if ($wiki->revertchanges or $isteacher) {
        $action['revertpages'] = get_string('revertpages', 'wiki');
    }
    if ($noeditor) {
        $action["checklinks"] = get_string("checklinks", "wiki");
    }
    popup_form($ewscript, $action, "wikiadministration", "", get_string("chooseadministration", "wiki"), "", "", false);
}
Example #4
0
/**
 * Displays actions which can be performed on the page
 *
 * @param object $wiki
 * @param int $cmid
 * @param int $userid
 * @param int $groupid
 * @param object $page
 * @param bool $noeditor
 * @param object $course
 */
function wiki_print_administration_actions($wiki, $cmid, $userid, $groupid, $page, $noeditor, $course)
{
    global $OUTPUT;
    /// Create the URL
    $ewscript = 'admin.php?id=' . $cmid;
    if (isset($userid) && $userid != 0) {
        $ewscript .= '&userid=' . $userid;
    }
    if (isset($groupid) && $groupid != 0) {
        $ewscript .= '&groupid=' . $groupid;
    }
    if (isset($page)) {
        $ewscript .= '&page=' . $page;
    }
    /// Build that action array according to wiki flags.
    $action = array();
    $isteacher = wiki_is_teacher($wiki);
    if ($wiki->setpageflags or $isteacher) {
        $action['setpageflags'] = get_string('setpageflags', 'wiki');
    }
    if ($wiki->removepages or $isteacher) {
        $action['removepages'] = get_string('removepages', 'wiki');
    }
    if ($wiki->strippages or $isteacher) {
        $action['strippages'] = get_string('strippages', 'wiki');
    }
    if ($wiki->revertchanges or $isteacher) {
        $action['revertpages'] = get_string('revertpages', 'wiki');
    }
    if ($noeditor) {
        $action["checklinks"] = get_string("checklinks", "wiki");
    }
    $select = html_select::make_popup_form($ewscript, 'action', $action, 'wikiadministration');
    $select->nothinglabel = get_string("chooseadministration", "wiki");
    echo $OUTPUT->select($select);
}