function zip_files($files, $dir = '', $zdir = '', $zip) { foreach ($files as $file) { if ($file == '.' || $file == '..' || $file == 'backup') { continue; } if (is_dir($dir . $file)) { $zip->addDir($zdir . $file); zip_files(scandir($dir . $file), $dir . $file . '/', $zdir . $file . '/', $zip); } else { $zip->addFile(file_get_contents($dir . $file), $zdir . $file); } } }
function zip_files($files, $dir = '') { global $zip; foreach ($files as $file) { if ($file == '.' || $file == '..' || $file == 'update.zip' || $file == 'backup') { continue; } if (is_dir(HOME . $dir . $file)) { $zip->addDir($dir . $file); zip_files(scandir(HOME . $dir . $file), $dir . $file . '/'); } else { $zip->addFile(file_get_contents(HOME . '/' . $dir . $file), $dir . $file); } } }
function game_create_zip($srcdir, $courseid, $filename) { global $CFG; $dir = $CFG->dataroot . '/' . $courseid; $filezip = $dir . "/export/{$filename}"; if (file_exists($filezip)) { unlink($filezip); } if (!file_exists($dir)) { mkdir($dir); } if (!file_exists($dir . '/export')) { mkdir($dir . '/export'); } $srcfiles = get_directory_list($srcdir, '', true, true, true); $fullsrcfiles = array(); foreach ($srcfiles as $file) { $fullsrcfiles[] = $srcdir . '/' . $file; } zip_files($fullsrcfiles, $filezip); return file_exists($filezip) ? $filezip : ''; }
mkdir($destpath, $CFG->directorypermissions, true); } foreach ($USER->filelist as $fuuid) { $file = $repo->get_info($fuuid); if (alfresco_get_type($file->uuid) == 'folder') { $dirfiles = $repo->download_dir($destpath, $fuuid); if ($dirfiles !== false) { $filelist[] = $destpath . $file->title; } } else { if ($repo->read_file($fuuid, $destpath . $file->title)) { $filelist[] = $destpath . $file->title; } } } if (!zip_files($filelist, $filepath)) { print_error('zipfileserror'); } $repo->upload_file('', $filepath, $uuid); fulldelete($destpath); fulldelete($filepath); } clearfilelist(); displaydir($uuid, $wdir, $id); } else { html_header($course, $wdir, "form.name"); if (setfilelist($_POST)) { echo "<p align=\"center\">" . get_string("youareabouttocreatezip") . ":</p>"; print_simple_box_start("center"); printfilelist($USER->filelist); print_simple_box_end();
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 />"; } } }
echo "</td></tr></table>\n"; if ($usehtmleditor) { use_html_editor("text"); } } html_footer(); break; case "zip": if (!empty($name) and confirm_sesskey()) { html_header($course, $wdir); $name = clean_filename($name); $files = array(); foreach ($USER->filelist as $file) { $files[] = "{$basedir}/{$file}"; } if (!zip_files($files, "{$basedir}/{$wdir}/{$name}")) { print_error("zipfileserror", "error"); } clearfilelist(); displaydir($wdir); } else { html_header($course, $wdir, "form.name"); if (setfilelist($_POST)) { echo "<p align=\"center\">" . get_string("youareabouttocreatezip") . ":</p>"; print_simple_box_start("center"); printfilelist($USER->filelist); print_simple_box_end(); echo "<br />"; echo "<p align=\"center\">" . get_string("whattocallzip"); echo "<table border=\"0\">\n<tr>\n<td>\n"; echo "<form action=\"coursefiles.php\" method=\"post\" name=\"form\">\n";
} $sourcefiles[] = $exportdir . "imsmanifest.xml"; // create directory for the zip-file: if (!($zipdir = make_upload_directory(export_file_area_name()))) { error(get_string("couldntcreatetempdir", "block_exabis_eportfolio")); exit; } // Delete everything inside remove_dir($zipdir, true); // Put a / on the end if (substr($zipdir, -1) != "/") { $zipdir .= "/"; } $zipname = clean_param($USER->username, PARAM_ALPHANUM) . strftime("_%Y_%m_%d_%H%M") . ".zip"; // zip all the files: zip_files($sourcefiles, $zipdir . $zipname); remove_dir($exportdir); echo '<div class="block_eportfolio_center">'; print_simple_box_start("center", "40%", "#ccffbb"); echo '<input type="submit" name="export" value="' . get_string("download", "block_exabis_eportfolio") . '"'; echo ' onclick="window.open(\'' . $CFG->wwwroot . '/blocks/exabis_eportfolio/portfoliofile.php/' . export_file_area_name() . '/' . $zipname . '\');"/>'; echo '</div>'; print_simple_box_end(); print_footer($course); exit; } echo "<br />"; echo '<div class="block_eportfolio_center">'; $views = get_records('block_exabeporview', 'userid', $USER->id, 'name'); print_simple_box_start("center", "40%", "#ccffbb"); echo '<p>' . get_string("explainexport", "block_exabis_eportfolio") . '</p>';
/** * exports the questions in a question category to the given location * * The parent class method was overridden because the IMS export consists of multiple files * * @param string $filename the directory name which will hold the exported files * @return bool - or errors out */ public function exportprocess() { global $CFG, $OUTPUT, $USER; $courseid = $this->course->id; $path = 'temp/qformat_qti_two/' . $USER->id . '/' . $this->filename; // create a directory for the exports (if not already existing) if (!make_upload_directory($path)) { throw new moodle_exception('cannotcreatepath', 'question', '', $path); } $path = $CFG->dataroot . '/' . $path; // get the questions (from database) in this category $questions = get_questions_category($this->category); // create the imsmanifest file $smarty =& $this->init_smarty(); $this->add_qti_info($questions); // copy files used by the main questions to the export directory $result = $this->handle_questions_media($questions, $path, $courseid); if ($result !== true) { throw new coding_exception(implode("<br />", $result)); } $manifestquestions = $this->objects_to_array($questions); $manifestid = str_replace(array(':', '/'), array('-', '_'), "question_category_{$this->category->id}---{$CFG->wwwroot}"); $smarty->assign('externalfiles', 1); $smarty->assign('manifestidentifier', $manifestid); $smarty->assign('quiztitle', "question_category_{$this->category->id}"); $smarty->assign('quizinfo', "All questions in category {$this->category->id}"); $smarty->assign('questions', $manifestquestions); $smarty->assign('lang', $this->lang); $smarty->error_reporting = 99; $expout = $smarty->fetch('imsmanifest.tpl'); $filepath = $path . '/imsmanifest.xml'; if (empty($expout)) { print_error('emptyxml', 'question'); } if (!($fh = fopen($filepath, "w"))) { print_error('cannotopenforwriting', 'question', '', $filepath); } if (!fwrite($fh, $expout)) { print_error('cannotwriteto', 'question', '', $filepath); } fclose($fh); // iterate through questions foreach ($questions as $question) { // results are first written into string (and then to a file) $expout = $this->writequestion($question, null, true, $path) . "\n"; $expout = $this->presave_process($expout); $filepath = $path . '/' . $this->get_assesment_item_id($question) . ".xml"; if (!($fh = fopen($filepath, "w"))) { print_error('cannotopenforwriting', 'question', '', $filepath); } if (!fwrite($fh, $expout)) { print_error('cannotwriteto', 'question', '', $filepath); } fclose($fh); } // zip files into single export file zip_files(array($path), "{$path}.zip"); // remove the temporary directory remove_dir($path); return true; }
function apply_incremental($courseid, $newfile) { global $CFG; //first need to get the "current" version of the backup. - we'll do this based on the incremental passed. $newfilename = substr($newfile, strrpos($newfile, '/') + 1); $hash = explode('-', $newfilename); $oldbackuppath = $CFG->dataroot . '/incrementals_client/' . $courseid . '/'; if (file_exists($oldbackuppath . $hash[0] . '.zip')) { //now unzip original backup into a temp dir. $tempdir = $CFG->dataroot . '/temp/' . $hash[0] . '-' . uniqid(); //add uniqid to the end as for some stupid reason, when unzip_file unzips over the top of an existing dir - it changes the md5 of the moodle.xml file! if (!check_dir_exists($tempdir, true, true)) { error("failed to create temp dir for original backup"); } if (!unzip_file($oldbackuppath . $hash[0] . '.zip', $tempdir, false)) { error('Couldn\'t unzip old backup'); } //now run diff! $mydiff = new xdelta(); $mydiff->apply_diff($tempdir, $newfile); if (!empty($mydiff->error)) { error("apply diff failed: " . $mydiff->error); } //now zip up the dir again, $listoffiles = get_directory_list($tempdir, '', true, true); $files = array(); foreach ($listoffiles as $file) { $files[] = "{$tempdir}/{$file}"; } if (!zip_files($files, $oldbackuppath . $hash[1])) { error('failed to zip files after diff'); } return $hash[1]; //now return path to new backup. } else { error("Could not find the original backup for this course - you must download a full backup oldpath:" . $oldbackuppath . ' hash:' . $hash[0] . '.zip'); } }
function wiki_export_content(&$WS, $folder = 'exportedfiles') { global $CFG, $contents; $export = optional_param('dfformexport', NULL, PARAM_ALPHA); $exportall = optional_param('dfformexportall', NULL, PARAM_ALPHA); //check if the form was filled in if (isset($export) || isset($exportall)) { //make sure the file doesn't exist $dfformname = optional_param('dfformname', NULL, PARAM_FILE); $currentname = clean_filename($dfformname); $cleandfwiki = clean_filename($WS->dfwiki->name); if (file_exists($CFG->dataroot . "/" . $WS->dfwiki->course . "/" . $folder . "/" . $cleandfwiki . $WS->cm->id . "/" . $currentname)) { $err = $currentname . ' already exists!'; error($err); } else { //export to xml wiki_export_content_XML($WS); $prop = null; $prop->class = 'textcenter'; $info = wiki_size_text(get_string("exportcorrectly", 'wiki'), 2, '', true); wiki_div($info, $prop); //make the zip $files = array(); //copy files inside temp where is the xml check_dir_exists("{$CFG->dataroot}/temp/" . $folder . "/wiki{$WS->cm->id}", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/wiki{$WS->cm->id}", true); $flist = list_directories_and_files("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/wiki{$WS->cm->id}"); if ($flist != null) { foreach ($flist as $fil) { $from_file = "{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/wiki{$WS->cm->id}/{$fil}"; $to_file = "{$CFG->dataroot}/temp/" . $folder . "/wiki{$WS->cm->id}/{$fil}"; copy($from_file, $to_file); } } //continue compressing $filelist = list_directories_and_files("{$CFG->dataroot}/temp/" . $folder . "/wiki{$WS->cm->id}"); foreach ($filelist as $file) { $files[] = "{$CFG->dataroot}/temp/" . $folder . "/wiki{$WS->cm->id}/{$file}"; } check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/" . $folder, true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/" . $folder . "/{$cleandfwiki}{$WS->cm->id}", true); $destination = "{$CFG->dataroot}/{$WS->dfwiki->course}/" . $folder . "/{$cleandfwiki}{$WS->cm->id}/{$currentname}"; $status = zip_files($files, $destination); //delete folder inside temp that we've created $filelist2 = list_directories_and_files("{$CFG->dataroot}/temp/" . $folder . "/wiki{$WS->cm->id}"); foreach ($filelist2 as $file2) { unlink("{$CFG->dataroot}/temp/" . $folder . "/wiki{$WS->cm->id}/{$file2}"); } rmdir("{$CFG->dataroot}/temp/" . $folder . "/wiki{$WS->cm->id}"); $prop = null; $prop->border = '0'; $prop->class = 'boxaligncenter'; $prop->classtd = 'nwikileftnow'; wiki_table_start($prop); $wdir = '/' . $folder . '/' . $cleandfwiki . $WS->cm->id; $fileurl = "{$wdir}/{$currentname}"; $ffurl = "/file.php?file=/{$WS->cm->course}{$fileurl}"; $icon = mimeinfo("icon", $currentname); $prop = null; $prop->src = "{$CFG->pixpath}/f/{$icon}"; $prop->height = '16'; $prop->width = '16'; $prop->alt = 'File'; $im = wiki_img($prop, true); link_to_popup_window($ffurl, "display", $im, 480, 640); echo ' '; link_to_popup_window($ffurl, "display", htmlspecialchars($currentname), 480, 640); $prop = null; $prop->class = 'nwikileftnow'; wiki_change_row($prop); wiki_table_end(); $prop = null; $prop->border = '0'; $prop->class = 'boxaligncenter'; $prop->classtd = 'nwikileftnow'; wiki_table_start($prop); $prop = null; $prop->action = 'index.php?id=' . $WS->dfwiki->course . '&wdir=/"' . $folder; $prop->method = 'post'; $prop->id = 'form'; wiki_form_start($prop); $prop = null; $prop->name = 'dfformviewexported'; $prop->value = get_string('viewexported', 'wiki'); $input = wiki_input_submit($prop, true); wiki_div($input); wiki_form_end(); wiki_change_column(); print_continue("{$CFG->wwwroot}/mod/wiki/view.php?id={$WS->cm->id}"); wiki_table_end(); } } else { //create the form to export //first of all treat the form that we've sended about the pages to export if (!($frm = data_submitted())) { $contents = null; $contentsall = get_records_sql('SELECT DISTINCT pagename,dfwiki FROM ' . $CFG->prefix . 'wiki_pages WHERE dfwiki=' . $WS->dfwiki->id); if ($contentsall != null) { foreach ($contentsall as $call) { $contents[] = $call->pagename; } } $WS->nocontents = null; } else { if (!empty($frm->addall)) { $contents = null; $contentsall = get_records_sql('SELECT DISTINCT pagename,dfwiki FROM ' . $CFG->prefix . 'wiki_pages WHERE dfwiki=' . $WS->dfwiki->id); if ($contentsall != null) { foreach ($contentsall as $call) { $contents[] = $call->pagename; } } $WS->nocontents = null; } else { if (!empty($frm->removeall)) { $WS->nocontents = null; $nocontentsall = get_records_sql('SELECT DISTINCT pagename,dfwiki FROM ' . $CFG->prefix . 'wiki_pages WHERE dfwiki=' . $WS->dfwiki->id); if ($nocontentsall != null) { foreach ($nocontentsall as $nocall) { $WS->nocontents[] = $nocall->pagename; } } $contents = null; } else { $contents = null; $WS->nocontents = null; for ($i = 0; $i < $frm->sizecontents; $i++) { $contents[] = $frm->contents[$i]; } for ($j = 0; $j < $frm->sizenocontents; $j++) { $WS->nocontents[] = $frm->nocontents[$j]; } if (!empty($frm->add) and !empty($frm->addselect)) { foreach ($frm->addselect as $addpage) { $contents[] = $addpage; wiki_remove_nocontents($addpage, $WS); } } else { if (!empty($frm->remove) and !empty($frm->removeselect)) { foreach ($frm->removeselect as $removepage) { $WS->nocontents[] = $removepage; wiki_remove_contents($removepage); } } } } } } $prop = null; $prop->class = 'textcenter'; $info = wiki_size_text(get_string("selectpages", 'wiki'), 2, '', true); wiki_div($info, $prop); include 'pages.html'; wiki_div_end(); $prop = null; $prop->class = 'box generalbox generalboxcontent boxaligncenter textcenter'; wiki_div_start($prop); $prop = null; $prop->action = 'exportxml.php?id=' . $WS->cm->id . '&pageaction=exportxml'; $prop->method = 'post'; $prop->id = 'form'; wiki_form_start($prop); $prop = null; $prop->border = '0'; $prop->class = 'boxaligncenter'; $prop->classtd = 'textcenter'; wiki_table_start($prop); $sizecon = count($WS->nocontents); for ($i = 0; $i < $sizecon; $i++) { $prop = null; $prop->name = 'dfform[' . $WS->nocontents[$i] . ']'; $prop->value = $WS->nocontents[$i]; wiki_input_hidden($prop); } $prop = null; $prop->class = 'textcenter'; $info = wiki_size_text(get_string("otheroptions", 'wiki'), 2, '', true); wiki_div($info, $prop); $cleandfwiki = clean_filename($WS->dfwiki->name); $times = time(); $prop = null; $prop->class = 'nwikileftnow'; wiki_change_row($prop); $prop = null; $prop->name = 'dfforminfo'; $prop->value = '1'; wiki_input_checkbox($prop); print_string('exportinfo', 'wiki'); $prop = null; $prop->class = 'nwikileftnow'; wiki_change_row($prop); $prop = null; $prop->name = 'dfformblocks'; $prop->value = '1'; wiki_input_checkbox($prop); print_string('blocks', 'wiki'); $prop = null; $prop->class = 'nwikicenternow'; wiki_change_row($prop); $info = get_string('saveas', 'wiki'); $prop = null; $prop->name = 'dfformname'; $prop->value = $cleandfwiki . '-' . $times . '.zip'; $info .= wiki_input_text($prop, true); wiki_paragraph($info, ''); $prop = null; $prop->class = 'nwikicenternow'; wiki_change_row($prop); $prop = null; $prop->name = 'dfformexport'; $prop->value = get_string('export', 'wiki'); wiki_input_submit($prop); $prop = null; $prop->name = 'dfformexportall'; $prop->value = get_string('exportall', 'wiki'); wiki_input_submit($prop); $prop = null; $prop->name = 'dfformcancel'; $prop->value = get_string('cancel'); wiki_input_submit($prop); wiki_table_end(); wiki_form_end(); } }
function referentiel_backup_zip($referentiel_referentiel_id, $user_creator, $archive_name) { global $CFG; $status = true; // DEBUG //Base dir where everything happens // Moodle 2 // $basedir = cleardoubleslashes($CFG->dataroot."/temp/archive/".$referentiel_referentiel_id.'/'.$user_creator); // Moodle 22 $path_temp = cleardoubleslashes(get_string('archivetemp', 'referentiel') . '/' . $referentiel_referentiel_id . '/' . $user_creator); // Moodle 2.2 $basedir = make_temp_directory($path_temp); $name = $archive_name; // DEBUG // echo "<br />DEBUG :: lib_archive.php :: 160 :: BASEDIR : '$basedir' NAME : '$name' <br />\n"; //List of files and directories $filelist = referentiel_list_directories_and_files($basedir); // print_object($filelist); // exit; //Convert them to full paths $files = array(); foreach ($filelist as $file) { $files[] = "{$basedir}/{$file}"; } $status = zip_files($files, "{$basedir}/{$name}"); //echo "<br/>Status: ".$status; //Debug return $status; }
public function get_file_content() { global $CFG; require_once $CFG->libdir . '/filelib.php'; do { $dir = 'ods/' . time() . '_' . rand(0, 10000); } while (file_exists($CFG->tempdir . '/' . $dir)); make_temp_directory($dir); make_temp_directory($dir . '/META-INF'); $dir = "{$CFG->tempdir}/{$dir}"; $files = array(); $handle = fopen("{$dir}/mimetype", 'w'); fwrite($handle, $this->get_ods_mimetype()); $files[] = "{$dir}/mimetype"; $handle = fopen("{$dir}/content.xml", 'w'); fwrite($handle, $this->get_ods_content($this->worksheets)); $files[] = "{$dir}/content.xml"; $handle = fopen("{$dir}/meta.xml", 'w'); fwrite($handle, $this->get_ods_meta()); $files[] = "{$dir}/meta.xml"; $handle = fopen("{$dir}/styles.xml", 'w'); fwrite($handle, $this->get_ods_styles()); $files[] = "{$dir}/styles.xml"; $handle = fopen("{$dir}/settings.xml", 'w'); fwrite($handle, $this->get_ods_settings()); $files[] = "{$dir}/settings.xml"; $handle = fopen("{$dir}/META-INF/manifest.xml", 'w'); fwrite($handle, $this->get_ods_manifest()); $files[] = "{$dir}/META-INF"; $filename = "{$dir}/result.ods"; zip_files($files, $filename); $handle = fopen($filename, 'rb'); $contents = fread($handle, filesize($filename)); fclose($handle); remove_dir($dir); // Cleanup the temp directory. return $contents; }
function hiperbook_to_scorm($id) { if (!($cm = get_record('course_modules', 'id', $id))) { error('Course Module ID is incorrect'); } if (!($course = get_record('course', 'id', $cm->course))) { error('Course is misconfigured'); } if (!($book = get_record('hiperbook', 'id', $cm->instance))) { error('Course module is incorrect'); } $bookid = $book->id; set_time_limit(3000); global $CFG, $course; ob_start(); ob_implicit_flush(); echo "<br>Copying files\n"; ob_flush(); // cria a pasta de trabalho temporaria mkdir($CFG->dataroot . '/' . $course->id . '/temp'); mkdir($CFG->dataroot . '/' . $course->id . '/temp/assets'); //copia arquivos do hiperlivro para assets mkdir($CFG->dataroot . '/' . $course->id . '/temp/assets/images'); copy($book->img_hotwords_icon, $CFG->dataroot . '/' . $course->id . '/temp/assets/images/'); copy($book->img_suggestions_icon, $CFG->dataroot . '/' . $course->id . '/temp/assets/images/'); copy('images/next.gif', $CFG->dataroot . '/' . $course->id . '/temp/assets/images/next.gif'); copy('images/back.gif', $CFG->dataroot . '/' . $course->id . '/temp/assets/images/back.gif'); copy('prototype.js', $CFG->dataroot . '/' . $course->id . '/temp/assets/prototype.js'); copy('effects.js', $CFG->dataroot . '/' . $course->id . '/temp/assets/effects.js'); copy('dragdrop.js', $CFG->dataroot . '/' . $course->id . '/temp/assets/dragdrop.js'); copy('popup.js', $CFG->dataroot . '/' . $course->id . '/temp/assets/popup.js'); copy('findAPI.js', $CFG->dataroot . '/' . $course->id . '/temp/assets/findAPI.js'); mkdir($CFG->dataroot . '/' . $course->id . '/temp/scos'); // transforma o hiperbook em um pacote SCORm dentro da estrutura /* /assets : pasta onde sao armazenadas as imgs, swfs e etc /scos : pasta onde sao gravados os capitulos e sub-itens ex /scos/14, /scos/14/dicas / */ //inicia pela geração das paginas html dos capityulos (resources) echo "<br>Processing chapters:<br>"; ob_flush(); hiperbook_parse_chapters($bookid, $cm->id, 'SCORM'); hiperbook_parse_hotwordspage($bookid, $cm->id); hiperbook_parse_suggestionspage($bookid, $cm->id); // converte os navpaths e cria os elementos do modelo de navagação echo "<br>Creating manifest...<br>"; ob_flush(); hiperbook_create_ims_manifest($bookid); //compactando echo "<br>Zipping files..."; ob_flush(); $basedir = $CFG->dataroot . '/' . $course->id . '/temp'; $fullpath = $CFG->dataroot . '/' . $course->id . '/temp'; $directory = opendir($fullpath); // Find all files while (false !== ($file = readdir($directory))) { if ($file == "." || $file == "..") { continue; } $filelist[] = $file; } closedir($directory); if (!($book = get_record('hiperbook', 'id', $bookid))) { return false; } $files = array(); foreach ($filelist as $file) { $files[] = "{$basedir}/{$file}"; } if (!zip_files($files, $CFG->dataroot . '/' . $course->id . "/" . $book->name . "_scorm")) { error(get_string("zipfileserror", "error")); } // remove a pasta temporaria echo "<br>Deleting temporary data..."; hiperbook_recursive_remove_directory($CFG->dataroot . '/' . $course->id . '/temp', $empty = FALSE); echo "<br>Saved in <a href=" . $CFG->wwwroot . "/files/index.php?id=" . $course->id . ".zip>" . $book->name . ".zip</a>"; }
function data_presets_export($course, $cm, $data) { global $CFG; $presetname = clean_filename($data->name) . '-preset-' . gmdate("Ymd_Hi"); $exportsubdir = "{$course->id}/moddata/data/{$data->id}/{$presetname}"; make_upload_directory($exportsubdir); $exportdir = "{$CFG->dataroot}/{$exportsubdir}"; // Assemble "preset.xml": $presetxmldata = "<preset>\n\n"; // Raw settings are not preprocessed during saving of presets $raw_settings = array('intro', 'comments', 'requiredentries', 'requiredentriestoview', 'maxentries', 'rssarticles', 'approval', 'defaultsortdir'); $presetxmldata .= "<settings>\n"; // First, settings that do not require any conversion foreach ($raw_settings as $setting) { $presetxmldata .= "<{$setting}>" . htmlspecialchars($data->{$setting}) . "</{$setting}>\n"; } // Now specific settings if ($data->defaultsort > 0 && ($sortfield = data_get_field_from_id($data->defaultsort, $data))) { $presetxmldata .= '<defaultsort>' . htmlspecialchars($sortfield->field->name) . "</defaultsort>\n"; } else { $presetxmldata .= "<defaultsort>0</defaultsort>\n"; } $presetxmldata .= "</settings>\n\n"; // Now for the fields. Grab all that are non-empty $fields = get_records('data_fields', 'dataid', $data->id); ksort($fields); if (!empty($fields)) { foreach ($fields as $field) { $presetxmldata .= "<field>\n"; foreach ($field as $key => $value) { if ($value != '' && $key != 'id' && $key != 'dataid') { $presetxmldata .= "<{$key}>" . htmlspecialchars($value) . "</{$key}>\n"; } } $presetxmldata .= "</field>\n\n"; } } $presetxmldata .= '</preset>'; // After opening a file in write mode, close it asap $presetxmlfile = fopen($exportdir . '/preset.xml', 'w'); fwrite($presetxmlfile, $presetxmldata); fclose($presetxmlfile); // Now write the template files $singletemplate = fopen($exportdir . '/singletemplate.html', 'w'); fwrite($singletemplate, $data->singletemplate); fclose($singletemplate); $listtemplateheader = fopen($exportdir . '/listtemplateheader.html', 'w'); fwrite($listtemplateheader, $data->listtemplateheader); fclose($listtemplateheader); $listtemplate = fopen($exportdir . '/listtemplate.html', 'w'); fwrite($listtemplate, $data->listtemplate); fclose($listtemplate); $listtemplatefooter = fopen($exportdir . '/listtemplatefooter.html', 'w'); fwrite($listtemplatefooter, $data->listtemplatefooter); fclose($listtemplatefooter); $addtemplate = fopen($exportdir . '/addtemplate.html', 'w'); fwrite($addtemplate, $data->addtemplate); fclose($addtemplate); $rsstemplate = fopen($exportdir . '/rsstemplate.html', 'w'); fwrite($rsstemplate, $data->rsstemplate); fclose($rsstemplate); $rsstitletemplate = fopen($exportdir . '/rsstitletemplate.html', 'w'); fwrite($rsstitletemplate, $data->rsstitletemplate); fclose($rsstitletemplate); $csstemplate = fopen($exportdir . '/csstemplate.css', 'w'); fwrite($csstemplate, $data->csstemplate); fclose($csstemplate); $jstemplate = fopen($exportdir . '/jstemplate.js', 'w'); fwrite($jstemplate, $data->jstemplate); fclose($jstemplate); $asearchtemplate = fopen($exportdir . '/asearchtemplate.html', 'w'); fwrite($asearchtemplate, $data->asearchtemplate); fclose($asearchtemplate); // Check if all files have been generated if (!is_directory_a_preset($exportdir)) { error('Not all files generated!'); // should be migrated to print_error() } $filelist = array('preset.xml', 'singletemplate.html', 'listtemplateheader.html', 'listtemplate.html', 'listtemplatefooter.html', 'addtemplate.html', 'rsstemplate.html', 'rsstitletemplate.html', 'csstemplate.css', 'jstemplate.js', 'asearchtemplate.html'); foreach ($filelist as $key => $file) { $filelist[$key] = $exportdir . '/' . $filelist[$key]; } $exportfile = "{$CFG->dataroot}/{$course->id}/moddata/data/{$data->id}/{$presetname}.zip"; file_exists($exportfile) && unlink($exportfile); $status = zip_files($filelist, $exportfile); // ToDo: status check foreach ($filelist as $file) { unlink($file); } rmdir($exportdir); // Return the full path to the exported preset file: return $exportfile; }
function export() { global $CFG; $dir = opendir($this->path); $exists = false; $file = readdir($dir); do { if ($file == 'pif' . $this->cm->id . '.zip') { $exists = true; } } while ($exists == false && ($file = readdir($dir))); closedir($dir); if ($exists == true) { unlink($this->path . '/' . 'pif' . $this->cm->id . '.zip'); } // create introduction.html, task.html, ... $this->create_webquestscorm('introduction'); $this->create_webquestscorm('task'); $this->create_webquestscorm('process'); $this->create_webquestscorm('evaluation'); $this->create_webquestscorm('conclusion'); $this->create_webquestscorm('credits'); // create pif.zip $pif = new PclZip('pif' . $this->cm->id . '.zip'); $source = $CFG->dirroot . '/mod/webquestscorm/xsd/'; $dir = opendir($source); $route = $this->path . '/pif' . $this->cm->id . '.zip'; while ($fxsd = readdir($dir)) { if ($fxsd != '.' && $fxsd != '..') { if (is_dir($source . $fxsd)) { mkdir($this->path . '/' . $fxsd); $dir2 = opendir($source . $fxsd); while ($fxsd2 = readdir($dir2)) { if ($fxsd2 != '.' && $fxsd2 != '..') { copy($source . $fxsd . '/' . $fxsd2, $this->path . '/' . $fxsd . '/' . $fxsd2); } } } else { copy($source . $fxsd, $this->path . '/' . $fxsd); } } } $dir = opendir($this->path); $i = 0; while ($fxsd = readdir($dir)) { if ($fxsd != '.' && $fxsd != '..') { $files[$i++] = $this->path . '/' . $fxsd; } } closedir($dir); if (!zip_files($files, "{$route}")) { print_error("zipfileserror", "error"); } $dir = opendir($this->path); while ($fxsd = readdir($dir)) { if ($fxsd != '.' && $fxsd != '..') { if (strstr($fxsd, '.xsd') != false || strstr($fxsd, '.dtd') != false) { unlink($this->path . '/' . $fxsd); } else { if (is_dir($this->path . '/' . $fxsd)) { $dir2 = opendir($this->path . '/' . $fxsd); while ($fxsd2 = readdir($dir2)) { if ($fxsd2 != '.' && $fxsd2 != '..') { unlink($this->path . '/' . $fxsd . '/' . $fxsd2); } } closedir($dir2); rmdir($this->path . '/' . $fxsd); } } } } closedir($dir); }
/** * exports the questions in a question category to the given location * * The parent class method was overridden because the IMS export consists of multiple files * * @param string $filename the directory name which will hold the exported files * @return boolean - or errors out */ function exportprocess() { global $CFG; $courseid = $this->course->id; // create a directory for the exports (if not already existing) if (!($export_dir = make_upload_directory($this->question_get_export_dir() . '/' . $this->filename))) { error(get_string('cannotcreatepath', 'quiz', $export_dir)); } $path = $CFG->dataroot . '/' . $this->question_get_export_dir() . '/' . $this->filename; // get the questions (from database) in this category // $questions = get_records("question","category",$this->category->id); $questions = get_questions_category($this->category); notify("Exporting " . count($questions) . " questions."); $count = 0; // create the imsmanifest file $smarty =& $this->init_smarty(); $this->add_qti_info($questions); // copy files used by the main questions to the export directory $result = $this->handle_questions_media($questions, $path, $courseid); if ($result !== true) { notify(implode("<br />", $result)); } $manifestquestions = $this->objects_to_array($questions); $manifestid = str_replace(array(':', '/'), array('-', '_'), "question_category_{$this->category->id}---{$CFG->wwwroot}"); $smarty->assign('externalfiles', 1); $smarty->assign('manifestidentifier', $manifestid); $smarty->assign('quiztitle', "question_category_{$this->category->id}"); $smarty->assign('quizinfo', "All questions in category {$this->category->id}"); $smarty->assign('questions', $manifestquestions); $smarty->assign('lang', $this->lang); $smarty->error_reporting = 99; $expout = $smarty->fetch('imsmanifest.tpl'); $filepath = $path . '/imsmanifest.xml'; if (empty($expout)) { error("Unkown error - empty imsmanifest.xml"); } if (!($fh = fopen($filepath, "w"))) { error("Cannot open for writing: {$filepath}"); } if (!fwrite($fh, $expout)) { error("Cannot write exported questions to {$filepath}"); } fclose($fh); // iterate through questions foreach ($questions as $question) { // results are first written into string (and then to a file) $count++; echo "<hr /><p><b>{$count}</b>. " . stripslashes($question->questiontext) . "</p>"; $expout = $this->writequestion($question, null, true, $path) . "\n"; $expout = $this->presave_process($expout); $filepath = $path . '/' . $this->get_assesment_item_id($question) . ".xml"; if (!($fh = fopen($filepath, "w"))) { error("Cannot open for writing: {$filepath}"); } if (!fwrite($fh, $expout)) { error("Cannot write exported questions to {$filepath}"); } fclose($fh); } // zip files into single export file zip_files(array($path), "{$path}.zip"); // remove the temporary directory remove_dir($path); return true; }
function data_presets_export($course, $cm, $data) { global $CFG; /* Info Collected. Now need to make files in moodledata/temp */ $tempfolder = $CFG->dataroot . '/temp'; $singletemplate = fopen($tempfolder . '/singletemplate.html', 'w'); $listtemplate = fopen($tempfolder . '/listtemplate.html', 'w'); $listtemplateheader = fopen($tempfolder . '/listtemplateheader.html', 'w'); $listtemplatefooter = fopen($tempfolder . '/listtemplatefooter.html', 'w'); $addtemplate = fopen($tempfolder . '/addtemplate.html', 'w'); $rsstemplate = fopen($tempfolder . '/rsstemplate.html', 'w'); $rsstitletemplate = fopen($tempfolder . '/rsstitletemplate.html', 'w'); $csstemplate = fopen($tempfolder . '/csstemplate.css', 'w'); $jstemplate = fopen($tempfolder . '/jstemplate.js', 'w'); fwrite($singletemplate, $data->singletemplate); fwrite($listtemplate, $data->listtemplate); fwrite($listtemplateheader, $data->listtemplateheader); fwrite($listtemplatefooter, $data->listtemplatefooter); fwrite($addtemplate, $data->addtemplate); fwrite($rsstemplate, $data->rsstemplate); fwrite($rsstitletemplate, $data->rsstitletemplate); fwrite($csstemplate, $data->csstemplate); fwrite($jstemplate, $data->jstemplate); fclose($singletemplate); fclose($listtemplate); fclose($listtemplateheader); fclose($listtemplatefooter); fclose($addtemplate); fclose($rsstemplate); fclose($rsstitletemplate); fclose($csstemplate); fclose($jstemplate); /* All the display data is now done. Now assemble preset.xml */ $fields = get_records('data_fields', 'dataid', $data->id); $presetfile = fopen($tempfolder . '/preset.xml', 'w'); $presetxml = "<preset>\n\n"; /* Database settings first. Name not included? */ $settingssaved = array('intro', 'comments', 'requiredentries', 'requiredentriestoview', 'maxentries', 'rssarticles', 'approval', 'scale', 'assessed', 'defaultsort', 'defaultsortdir', 'editany'); $presetxml .= "<settings>\n"; foreach ($settingssaved as $setting) { $presetxml .= "<{$setting}>{$data->{$setting}}</{$setting}>\n"; } $presetxml .= "</settings>\n\n"; /* Now for the fields. Grabs all settings that are non-empty */ if (!empty($fields)) { foreach ($fields as $field) { $presetxml .= "<field>\n"; foreach ($field as $key => $value) { if ($value != '' && $key != 'id' && $key != 'dataid') { $presetxml .= "<{$key}>{$value}</{$key}>\n"; } } $presetxml .= "</field>\n\n"; } } $presetxml .= "</preset>"; fwrite($presetfile, $presetxml); fclose($presetfile); /* Check all is well */ if (!is_directory_a_preset($tempfolder)) { error("Not all files generated!"); } $filelist = array('singletemplate.html', 'listtemplate.html', 'listtemplateheader.html', 'listtemplatefooter.html', 'addtemplate.html', 'rsstemplate.html', 'rsstitletemplate.html', 'csstemplate.css', 'jstemplate.js', 'preset.xml'); foreach ($filelist as $key => $file) { $filelist[$key] = $tempfolder . '/' . $filelist[$key]; } @unlink($tempfolder . '/export.zip'); $status = zip_files($filelist, $tempfolder . '/export.zip'); /* made the zip... now return the filename for storage.*/ return $tempfolder . '/export.zip'; }
function zip_dir($basedir, $destfile) { $paths = ''; $dir = opendir($basedir); while (false !== ($file = readdir($dir))) { if ($file == "." || $file == "..") { continue; } $paths[$file] = $basedir . '/' . $file; } closedir($dir); return zip_files($paths, $destfile); }
/** * Exports this Preset object as a series of files in the Preset's directory. * @return string The path/name of the resulting zip file if successful. */ function export() { global $CFG; $this->directory = $CFG->dataroot . '/temp'; // write all templates, but not the xml yet $template_files = $this->get_template_files(); foreach ($template_files as $var => $file) { $handle = fopen($this->directory . '/' . $file, 'w'); fwrite($handle, $this->{$var}); fclose($handle); } /* All the display data is now done. Now assemble preset.xml */ $fields = get_records('data_fields', 'dataid', $this->data->id); $presetfile = fopen($this->directory . '/preset.xml', 'w'); $presetxml = "<preset>\n\n"; /* Database settings first. Name not included? */ $settingssaved = array('intro', 'comments', 'requiredentries', 'requiredentriestoview', 'maxentries', 'rssarticles', 'approval', 'scale', 'assessed', 'defaultsort', 'defaultsortdir', 'editany'); $presetxml .= "<settings>\n"; foreach ($settingssaved as $setting) { $presetxml .= "<{$setting}>{$this->data->{$setting}}</{$setting}>\n"; } $presetxml .= "</settings>\n\n"; /* Now for the fields. Grabs all settings that are non-empty */ if (!empty($fields)) { foreach ($fields as $field) { $presetxml .= "<field>\n"; foreach ($field as $key => $value) { if ($value != '' && $key != 'id' && $key != 'dataid') { $presetxml .= "<{$key}>{$value}</{$key}>\n"; } } $presetxml .= "</field>\n\n"; } } $presetxml .= "</preset>"; fwrite($presetfile, $presetxml); fclose($presetfile); /* Check all is well */ if (is_array($missing_files = $this->has_all_required_files())) { $missing_files = implode(', ', $missing_files); print_error('filesnotgenerated', 'data', null, $missing_files); } // Remove export.zip @unlink($this->directory . '/export.zip'); $filelist = array(); foreach ($this->required_files as $file) { $filelist[$file] = $this->directory . '/' . $file; } // zip_files is part of moodlelib $status = zip_files($filelist, $this->directory . '/export.zip'); /* made the zip... now return the filename for storage.*/ return $this->directory . '/export.zip'; }
function backup_zip($preferences) { global $CFG; $status = true; //Base dir where everything happens $basedir = cleardoubleslashes($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code); //Backup zip file name $name = $preferences->backup_name; //List of files and directories $filelist = list_directories_and_files($basedir); //Convert them to full paths $files = array(); foreach ($filelist as $file) { $files[] = "{$basedir}/{$file}"; } $status = zip_files($files, "{$basedir}/{$name}"); //echo "<br/>Status: ".$status; //Debug return $status; }
$strbooks = get_string('modulenameplural', 'book'); $strbook = get_string('modulename', 'book'); $strtop = get_string('top', 'book'); add_to_log($course->id, 'book', 'generateimscp', 'generateimscp.php?id=' . $cm->id, $book->id, $cm->id); /// Get all the chapters $chapters = get_records('book_chapters', 'bookid', $book->id, 'pagenum'); /// Generate the manifest and all the contents chapters2imsmanifest($chapters, $book, $cm); /// Now zip everything make_upload_directory('temp'); $zipfile = $CFG->dataroot . "/temp/" . time() . '.zip'; $files = get_directory_list($CFG->dataroot . "/{$cm->course}/moddata/book/{$book->id}", basename($zipfile), false, true, true); foreach ($files as $key => $value) { $files[$key] = $CFG->dataroot . "/{$cm->course}/moddata/book/{$book->id}/" . $value; } zip_files($files, $zipfile); /// Now delete all the temp dirs delete_dir_contents($CFG->dataroot . "/{$cm->course}/moddata/book/{$book->id}"); /// Now serve the file send_temp_file($zipfile, clean_filename($book->name) . '.zip'); /** * This function will create the default imsmanifest plus contents for the book chapters passed as array * Everything will be created under the book moddata file area * */ function chapters2imsmanifest($chapters, $book, $cm) { global $CFG; /// Init imsmanifest and others $imsmanifest = ''; $imsitems = ''; $imsresources = '';
function wiki_export_html(&$WS) { global $CFG; check_dir_exists("{$CFG->dataroot}/temp", true); check_dir_exists("{$CFG->dataroot}/temp/html", true); check_dir_exists("{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}", true); check_dir_exists("{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}/atachments", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}", true); //export contents wiki_export_html_content($WS); //export attached files $flist = list_directories_and_files("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}"); if ($flist != null) { foreach ($flist as $fil) { $from_file = "{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}/{$fil}"; $to_file = "{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}/atachments/{$fil}"; copy($from_file, $to_file); } } //zip file name $times = time(); $name = $WS->dfwiki->name . '-' . $times . '.zip'; $cleanzipname = clean_filename($name); //List of files and directories $filelist = list_directories_and_files("{$CFG->dataroot}/temp/html"); //Convert them to full paths $files = array(); if ($filelist != null) { foreach ($filelist as $file) { $files[] = "{$CFG->dataroot}/temp/html/{$file}"; } } check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/exportedhtml", true); $destination = "{$CFG->dataroot}/{$WS->dfwiki->course}/exportedhtml/{$cleanzipname}"; $status = zip_files($files, $destination); //delete the folder created in temp $filelist2 = list_directories_and_files("{$CFG->dataroot}/temp/html"); if ($filelist2 != null) { $del = delete_dir_contents("{$CFG->dataroot}/temp/html"); } //show it all to be albe to download the file $prop = null; $prop->class = "textcenter"; wiki_div_start($prop); wiki_size_text(get_string("exporthtmlcorrectly", "wiki"), 2); wiki_div_end(); $prop = null; $prop->border = "0"; $prop->class = "boxaligncenter"; $prop->classtd = "nwikileftnow"; wiki_table_start($prop); $wdir = '/exportedhtml'; $fileurl = "{$wdir}/{$cleanzipname}"; $ffurl = "/file.php?file=/{$WS->cm->course}{$fileurl}"; $icon = mimeinfo("icon", $cleanzipname); link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" height=\"16\" width=\"16\" alt=\"File\" />", 480, 640); echo "\n" . ' '; link_to_popup_window($ffurl, "display", htmlspecialchars($cleanzipname), 480, 640); $prop = null; $prop->class = "nwikileftnow"; wiki_change_row($prop); echo ' '; wiki_table_end(); $prop = null; $prop->border = "0"; $prop->class = "boxaligncenter"; $prop->classtd = "nwikileftnow"; wiki_table_start($prop); $prop = null; $prop->id = "form"; $prop->method = "post"; $prop->action = '../xml/index.php?id=' . $WS->dfwiki->course . '&wdir=/exportedhtml'; wiki_form_start($prop); wiki_div_start(); $prop = null; $prop->name = "dfform[viewexported]"; $prop->value = get_string('viewexported', 'wiki'); wiki_input_submit($prop); wiki_div_end(); wiki_form_end(); wiki_change_column(); print_continue("{$CFG->wwwroot}/mod/wiki/view.php?id={$WS->cm->id}"); wiki_table_end(); }
$redirect .= "?zipped=2"; } //pre($redirect); header("Location: " . $redirect); } } else { //pre($signed_folders); $no_signed_folders = true; if (!empty($signed_folders)) { foreach ($signed_folders as $f) { //pre(filetype($f)); if (filetype($f) == "dir") { $raw_data = file_get_contents($f . '/data.txt'); $data = unserialize($raw_data); $no_signed_folders = false; if (zip_files($data)) { echo "Zip file created: <strong>" . $data['tkn'] . "@" . $data['ref'] . ".zip</strong>"; } else { echo "Error creating zip file for REF : <strong>" . $data['ref'] . "</strong>"; } //check if folder zipped or not } //check if is a dir } //loop through all files and folders in dir if ($no_signed_folders) { echo "No folders to zip."; } } // Check if there a signed }
function close() { global $CFG; require_once $CFG->libdir . '/filelib.php'; $dir = 'temp/ods/' . time(); make_upload_directory($dir); make_upload_directory($dir . '/META-INF'); $dir = "{$CFG->dataroot}/{$dir}"; $files = array(); $handle = fopen("{$dir}/mimetype", 'w'); fwrite($handle, get_ods_mimetype()); $files[] = "{$dir}/mimetype"; $handle = fopen("{$dir}/content.xml", 'w'); fwrite($handle, get_ods_content($this->worksheets)); $files[] = "{$dir}/content.xml"; $handle = fopen("{$dir}/meta.xml", 'w'); fwrite($handle, get_ods_meta()); $files[] = "{$dir}/meta.xml"; $handle = fopen("{$dir}/styles.xml", 'w'); fwrite($handle, get_ods_styles()); $files[] = "{$dir}/styles.xml"; $handle = fopen("{$dir}/META-INF/manifest.xml", 'w'); fwrite($handle, get_ods_manifest()); $files[] = "{$dir}/META-INF"; $filename = "{$dir}/result.ods"; zip_files($files, $filename); $handle = fopen($filename, 'rb'); $contents = fread($handle, filesize($filename)); fclose($handle); remove_dir($dir); // cleanup the temp directory send_file($contents, $this->filename, 0, 0, true, true, 'application/vnd.oasis.opendocument.spreadsheet'); }
function task_zip_files($db_id) { $hash_list = Request::getVar('hash_list'); zip_files($hash_list); exit; }