* @access public * @modulegroup export_modules * @module export_run_xslt * @package Export */ // +---------------------------------------------------------------------------+ // This file is part of Stud.IP // export_run_xslt.inc.php // Integration of xslt-processor // // Copyright (c) 2002 Arne Schroeder // Suchi & Berg GmbH // +---------------------------------------------------------------------------+ // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or any later version. // +---------------------------------------------------------------------------+ // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // +---------------------------------------------------------------------------+ use Studip\Button, Studip\LinkButton; if (($o_mode != "direct") AND ($o_mode != "passthrough")) $perm->check("tutor"); require_once ('lib/export/export_xslt_vars.inc.php'); // Liste der XSLT-Skripts /** * Checks given parameters * * This function checks the given parameters. If some are missing * it returns false and adds a warning to $export_error. * * @access public * @return boolean */ function CheckParamRUN() { global $ex_type, $o_mode, $xml_file_id, $format, $choose, $xslt_files, $export_error, $export_error_num, $export_o_modes, $export_ex_types; if (($xml_file_id == "") OR ($xslt_files[$choose]["file"] == "") OR (Config::get()->XSLT_ENABLE != true)) { $export_error .= "" . _("Fehlende Parameter!") . "
"; $export_error_num++; return false; } if (!in_array($ex_type, $export_ex_types) OR (!in_array($o_mode, $export_o_modes)) OR (!$xslt_files[$choose][$format])) { $export_error .= "" . _("Unzulässiger Seitenaufruf!") . "
"; $export_error_num++; return false; } return true; } /** * Convert all 2, 3 and 4 byte UTF-8 characters to the RTF unicode sequence \uX * * @param string $utf8_text rft document * @return string converted document */ function encode_utf8_for_rtf($utf8_text) { $utf8_patterns = [ "[\xC0-\xDF][\x80-\xBF]", "[\xE0-\xEF][\x80-\xBF]{2}", "[\xF0-\xF7][\x80-\xBF]{3}", ]; $unicode_text = $utf8_text; foreach($utf8_patterns as $pattern) { $unicode_text = preg_replace_callback("/$pattern/", function($treffer) { return '\u'. hexdec(bin2hex(mb_convert_encoding($treffer[0], 'UCS-4', 'UTF-8'))).'?'; }, $unicode_text); } return $unicode_text; } $export_pagename = _("Download der Ausgabedatei"); $xslt_process = false; $xslt_filename = Request::get('xslt_filename', $xslt_filename_default); if (!CheckParamRUN()) { PageLayout::postError( _('Die Parameter, mit denen diese Seite aufgerufen wurde, sind fehlerhaft.') ); } else { // Process the document $result_file = md5(uniqid(rand())) . "." . $format; $result = "" . $TMP_PATH . "/" . $result_file; $xml_process_file = "" . $TMP_PATH . "/" . $xml_file_id; $xslt_process_file = $GLOBALS['STUDIP_BASE_PATH'] . '/lib/export/' . $xslt_files[$choose]["file"]; $xh = new XSLTProcessor(); $xml_doc = new DOMDocument(); $xml_doc->load($xml_process_file); $xsl_doc = new DOMDocument(); $xsl_doc->load($xslt_process_file); $xh->importStylesheet($xsl_doc); $result_doc = $xh->transformToXML($xml_doc); if ($result_doc) { $processed = true; // if the output format is rtf, convert utf-8 chars to rtf escape sequences if ($format == 'rtf') { $result_doc = encode_utf8_for_rtf($result_doc); } file_put_contents($result, $result_doc); } else { $xh = libxml_get_last_error(); } if ( $processed && ($o_mode != "passthrough")) { $export_msg .= sprintf(_("Die Daten wurden erfolgreich konvertiert. %s Sie können die Ausgabedatei jetzt herunterladen. %s"), "
", "
"); $xslt_info = _("Die Daten sind nun im gewählten Format verfügbar."); $xslt_process = true; $link1 = ""; $link2 = ''; } elseif ($o_mode != "passthrough") { if ($xh) $export_error .= sprintf(_("Bei der Konvertierung ist ein Fehler aufgetreten. %sDer XSLT-Prozessor meldet den Fehler %s %s"), "
", $xh->code, "
"); $xslt_info = _("Bei der Konvertierung ist ein Fehler aufgetreten."); $xslt_process = false; $export_error_num++; } if ($o_mode == "passthrough") { header("Location: " . FileManager::getDownloadURLForTemporaryFile($result_file, $xslt_filename .'.'. $format)); unlink( $TMP_PATH . "/" . $xml_file_id); } else { $export_weiter_button = "
"; $export_weiter_button .= CSRFProtection::tokenTag(); $export_weiter_button .= ""; $export_weiter_button .= ""; $export_weiter_button .= ""; $export_weiter_button .= ""; $export_weiter_button .= ""; $export_pagecontent .= ""; foreach(array_keys($ex_sem_class) as $semclassid){ $export_pagecontent .= ""; } $export_weiter_button .= ""; $export_weiter_button .= ""; $export_weiter_button .= ""; if (Request::option('jump')) $export_weiter_button .= '
' . LinkButton::create('<< ' . _('Zurück'), URLHelper::getURL('seminar_main.php', ['auswahl' => $range_id, 'redirect_to' => $jump])) . "
"; else $export_weiter_button .= "
" . Button::create('<< ' . _('Zurück'), 'back') . "
"; $export_weiter_button .= "
"; if ($xslt_process) { $export_pagecontent .= "
"; $export_pagecontent .= "  " . _("Ausgabe-Datei: ") . ""; $export_pagecontent .= "" . $link2 . htmlReady($xslt_filename) . "." . htmlReady($format) . ""; $export_pagecontent .= "

"; } $xml_printimage = '
'; $xml_printimage.= Icon::create($export_icon['xml'], 'clickable')->asImg(['class' => 'text-top']); $xml_printimage.= ''; $xml_printlink = ' ' . htmlReady($xml_filename) . ''; $xml_printdesc = _("XML-Daten"); $xml_printcontent = _("In dieser Datei sind die Daten als XML-Tags gespeichert. Diese Tags können mit einem XSLT-Script verarbeitet werden.") . '
'; $xslt_printimage = ' '; $xslt_printimage.= Icon::create($export_icon['xslt'], 'clickable')->asImg(['class' => 'text-top']); $xslt_printimage.= ''; $xslt_printlink = ' ' . $xslt_files[$choose]['name'] . '.xsl'; $xslt_printdesc = _("XSLT-Datei"); $xslt_printcontent = _("Dies ist das XSLT-Script zur Konvertierung der Daten. Klicken Sie auf den Dateinamen, um die Datei zu öffnen.") . '
'; if ($xslt_process) { $result_printimage = ''; $result_printimage.= Icon::create($export_icon[$format], 'clickable')->asImg(['class' => 'text-top']); $result_printimage.= ''; $result_printlink = ' ' . htmlReady($xslt_filename) . '.' . htmlReady($format) . ''; $result_printdesc = _("Ausgabe-Datei"); $result_printcontent = _("Dies ist die fertige Ausgabedatei.") . "
"; } include_once ("lib/export/oscar.php"); } }