📄 moodle_wikidump.php
字号:
#} 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( // single quotes are essential here, // or alternative escape all $ as \$ '$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( // single quotes are essential here, // or alternative escape all $ as \$ '$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 deldir($dir){ $handle = opendir($dir); while (false!==($FolderOrFile = readdir($handle))) { if($FolderOrFile != "." && $FolderOrFile != "..") { if(is_dir("$dir/$FolderOrFile")) { deldir("$dir/$FolderOrFile"); } // recursive else { unlink("$dir/$FolderOrFile"); } } } closedir($handle); if(rmdir($dir)) { $success = true; } return $success; }?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -