/** * main export routine */ public function export() { global $SESSION; // the xml stuff $this->export_header(); $this->setup_links(); $this->notify_progress_callback(10, get_string('exportingviews', 'export')); if ($this->viewexportmode == PluginExport::EXPORT_LIST_OF_COLLECTIONS || $this->viewexportmode == PluginExport::EXPORT_ALL_VIEWS_COLLECTIONS) { $this->export_collections(); } $this->export_views(); $this->notify_progress_callback(50, get_string('exportingartefacts', 'export')); $this->export_artefacts(); $this->notify_progress_callback(80, get_string('exportingartefactplugindata', 'export')); $internal = null; foreach ($this->specialcases as $plugin => $artefacts) { if ($plugin == 'internal') { $internal = $artefacts; continue; // do it last so other plugins can inject persondata } $classname = 'LeapExport' . ucfirst($plugin); $pluginexport = new $classname($this, $artefacts); $this->xml .= $pluginexport->get_export_xml(); } if (!empty($internal)) { $pluginexport = new LeapExportInternal($this, $internal); $this->xml .= $pluginexport->get_export_xml(); } $this->notify_progress_callback(85, get_string('exportingfooter', 'export')); $this->export_footer(); $this->notify_progress_callback(90, get_string('writingfiles', 'export')); // Filter invalid XML characters out of the final product require_once 'file.php'; $this->xml = preg_replace(xml_filter_regex(), '', $this->xml); // write out xml to a file if (!file_put_contents($this->exportdir . $this->leapfile, $this->xml)) { $SESSION->add_error_msg(get_string('couldnotwriteLEAPdata', 'export')); } // copy attachments over foreach ($this->attachments as $id => $fileinfo) { $existingfile = $fileinfo->file; $desiredname = $fileinfo->name; if (!is_file($existingfile) || !copy($existingfile, $this->exportdir . $this->filedir . $id . '-' . $desiredname)) { $SESSION->add_error_msg(get_string('couldnotcopyattachment', 'export', $desiredname)); } } $this->notify_progress_callback(95, get_string('creatingzipfile', 'export')); // zip everything up try { create_zip_archive($this->exportdir, $this->zipfile, array($this->leapfile, $this->filedir)); } catch (SystemException $e) { throw new SystemException('Failed to zip the export file: ' . $e->getMessage()); } $this->notify_progress_callback(100, get_string('Done', 'export')); return $this->zipfile; }
/** * Reads and parses the archive's "leap2a.xml" file * @throws ImportException */ public function read_leap2a_xml_file() { $this->filename = self::find_file($this->get('importertransport')->files_info()); $this->logfile = dirname($this->filename) . '/import.log'; $this->trace('Loading import from ' . $this->filename); $this->snapshot('begin'); $options = LIBXML_COMPACT | LIBXML_NONET; if (function_exists('libxml_disable_entity_loader')) { // The LIBXML_NONET stops proper network based XXE attacks from happening libxml_disable_entity_loader(false); } require_once 'file.php'; if (!($this->xml = simplexml_load_string(preg_replace(xml_filter_regex(), '', file_get_contents($this->filename)), 'SimpleXMLElement', $options))) { // TODO: bail out in a much nicer way... throw new ImportException($this, "FATAL: XML file is not well formed! Please consult Mahara's error log for more information"); } if (function_exists('libxml_disable_entity_loader')) { libxml_disable_entity_loader(true); } $this->namespaces = array_flip($this->xml->getDocNamespaces()); $this->registerXpathNamespaces($this->xml); $this->trace("Document loaded, entries: " . count($this->xml->entry)); $this->snapshot('loaded XML'); $this->detect_leap2a_namespace(); $this->ensure_document_valid(); }