/** * Return the available custom styles * * @return array An array of strings containing the available custom styles * @access public * @see $_customStyle */ public function getCustomStyles() { $css_path = ilUtil::getStyleSheetLocation("filesystem", "ta.css", "Modules/Test"); $css_path = str_replace("ta.css", "customstyles", $css_path) . "/"; $customstyles = array(); if (is_dir($css_path)) { $results = array(); include_once "./Services/Utilities/classes/class.ilFileUtils.php"; ilFileUtils::recursive_dirscan($css_path, $results); if (is_array($results["file"])) { foreach ($results["file"] as $filename) { if (strpos($filename, ".css")) { array_push($customstyles, $filename); } } } } return $customstyles; }
/** * processes errorhandling etc for uploaded archive * @param string $tmpFile path and filename to uploaded file * @param string $storageMethod deliverFile or storeUploadedFile * @param boolean $persistentErrorMessage Defines whether sendInfo will be persistent or not */ function processUploadedFile($fileTmp, $storageMethod, $persistentErrorMessage, $a_ass_id) { global $lng, $ilUser; // Create unzip-directory $newDir = ilUtil::ilTempnam(); ilUtil::makeDir($newDir); include_once "Services/Utilities/classes/class.ilFileUtils.php"; try { $processDone = ilFileUtils::processZipFile($newDir, $fileTmp, false); ilFileUtils::recursive_dirscan($newDir, $filearray); foreach ($filearray["file"] as $key => $filename) { $a_http_post_files["name"] = ilFileUtils::utf8_encode($filename); $a_http_post_files["type"] = "other"; $a_http_post_files["tmp_name"] = $filearray["path"][$key] . "/" . $filename; $a_http_post_files["error"] = 0; $a_http_post_files["size"] = filesize($filearray["path"][$key] . "/" . $filename); if ($storageMethod == "deliverFile") { $this->{$storageMethod}($a_http_post_files, $a_ass_id, $ilUser->id, true); } else { if ($storageMethod == "storeUploadedFile") { $this->file_obj->{$storageMethod}($a_http_post_files, true, true); } } } ilExerciseMembers::_writeReturned($this->getId(), $ilUser->id, 1); ilUtil::sendSuccess($this->lng->txt("file_added"), $persistentErrorMessage); } catch (ilFileUtilsException $e) { ilUtil::sendFailure($e->getMessage(), $persistentErrorMessage); } ilUtil::delDir($newDir); return $processDone; }
function exportPDF($a_inst, $a_target_dir, &$expLog) { global $tpl, $lng, $ilCtrl; $a_xml_writer = new ilXmlWriter(); $a_xml_writer->xmlStartTag("ContentObject", array("Type" => "SCORM2004SCO")); $this->exportPDFPrepareXmlNFiles($a_inst, $a_target_dir, $expLog, $a_xml_writer); $a_xml_writer->xmlEndTag("ContentObject"); include_once 'Services/Transformation/classes/class.ilXML2FO.php'; $xml2FO = new ilXML2FO(); $xml2FO->setXSLTLocation('./Modules/Scorm2004/templates/xsl/contentobject2fo.xsl'); $xml2FO->setXMLString($a_xml_writer->xmlDumpMem()); $xml2FO->setXSLTParams(array('target_dir' => $a_target_dir)); $xml2FO->transform(); $fo_string = $xml2FO->getFOString(); $fo_xml = simplexml_load_string($fo_string); $fo_ext = $fo_xml->xpath("//fo:declarations"); $fo_ext = $fo_ext[0]; $results = array(); include_once "./Services/Utilities/classes/class.ilFileUtils.php"; ilFileUtils::recursive_dirscan($a_target_dir . "/objects", $results); if (is_array($results["file"])) { foreach ($results["file"] as $key => $value) { $e = $fo_ext->addChild("fox:embedded-file", "", "http://xml.apache.org/fop/extensions"); $e->addAttribute("src", $results[path][$key] . $value); $e->addAttribute("name", $value); $e->addAttribute("desc", ""); } } $fo_string = $fo_xml->asXML(); $a_xml_writer->_XmlWriter; return $fo_string; }
/** * save object * @access public */ function afterSave($newObj) { if (!$newObj->getStartFile()) { // try to set start file automatically $files = array(); include_once "Services/Utilities/classes/class.ilFileUtils.php"; ilFileUtils::recursive_dirscan($newObj->getDataDirectory(), $files); if (is_array($files["file"])) { $zip_file = null; if (stristr($newObj->getTitle(), ".zip")) { $zip_file = strtolower($newObj->getTitle()); $suffix = strrpos($zip_file, "."); if ($suffix) { $zip_file = substr($zip_file, 0, $suffix); } } $valid = array("index.htm", "index.html", "start.htm", "start.html"); foreach ($files["file"] as $idx => $file) { $chk_file = null; if (stristr($file, ".htm")) { $chk_file = strtolower($file); $suffix = strrpos($chk_file, "."); if ($suffix) { $chk_file = substr($chk_file, 0, $suffix); } } if (in_array($file, $valid) || $chk_file && $zip_file && $chk_file == $zip_file) { $newObj->setStartFile(str_replace($newObj->getDataDirectory() . "/", "", $files["path"][$idx]) . $file); $newObj->update(); break; } } } } // always send a message ilUtil::sendSuccess($this->lng->txt("object_added"), true); ilUtil::redirect("ilias.php?baseClass=ilHTLMEditorGUI&ref_id=" . $newObj->getRefId()); }
/** * Handles the upload of a single file and adds it to the parent object. * * @param array $file_upload An array containing the file upload parameters. * @return object The response object. */ protected function handleFileUpload($file_upload) { global $ilUser; // file upload params $filename = $file_upload["name"]; $type = $file_upload["type"]; $size = $file_upload["size"]; $temp_name = $file_upload["tmp_name"]; // additional params $title = $file_upload["title"]; $description = $file_upload["description"]; $extract = $file_upload["extract"]; $keep_structure = $file_upload["keep_structure"]; // create answer object $response = new stdClass(); $response->fileName = $filename; $response->fileSize = intval($size); $response->fileType = $type; $response->fileUnzipped = $extract; $response->error = null; // extract archive? if ($extract) { $zip_file = $filename; $adopt_structure = $keep_structure; include_once "Services/Utilities/classes/class.ilFileUtils.php"; // Create unzip-directory $newDir = ilUtil::ilTempnam(); ilUtil::makeDir($newDir); // Check if permission is granted for creation of object, if necessary if ($this->id_type != self::WORKSPACE_NODE_ID) { $type = ilObject::_lookupType((int) $this->parent_id, true); } else { $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false); } $tree = $access_handler = null; switch ($type) { // workspace structure case 'wfld': case 'wsrt': $permission = $this->checkPermissionBool("create", "", "wfld"); $containerType = "WorkspaceFolder"; $tree = $this->tree; $access_handler = $this->getAccessHandler(); break; // use categories as structure // use categories as structure case 'cat': case 'root': $permission = $this->checkPermissionBool("create", "", "cat"); $containerType = "Category"; break; // use folders as structure (in courses) // use folders as structure (in courses) default: $permission = $this->checkPermissionBool("create", "", "fold"); $containerType = "Folder"; break; } try { // processZipFile ( // Dir to unzip, // Path to uploaded file, // should a structure be created (+ permission check)? // ref_id of parent // object that contains files (folder or category) // should sendInfo be persistent?) ilFileUtils::processZipFile($newDir, $temp_name, $adopt_structure && $permission, $this->parent_id, $containerType, $tree, $access_handler); } catch (ilFileUtilsException $e) { $response->error = $e->getMessage(); } catch (Exception $ex) { $response->error = $ex->getMessage(); } ilUtil::delDir($newDir); // #15404 if ($this->id_type != self::WORKSPACE_NODE_ID) { foreach (ilFileUtils::getNewObjects() as $parent_ref_id => $objects) { if ($parent_ref_id != $this->parent_id) { continue; } foreach ($objects as $object) { $this->after_creation_callback_objects[] = $object; } } } } else { if (trim($title) == "") { $title = $filename; } else { // BEGIN WebDAV: Ensure that object title ends with the filename extension $fileExtension = ilObjFileAccess::_getFileExtension($filename); $titleExtension = ilObjFileAccess::_getFileExtension($title); if ($titleExtension != $fileExtension && strlen($fileExtension) > 0) { $title .= '.' . $fileExtension; } // END WebDAV: Ensure that object title ends with the filename extension } // create and insert file in grp_tree include_once "./Modules/File/classes/class.ilObjFile.php"; $fileObj = new ilObjFile(); $fileObj->setTitle($title); $fileObj->setDescription($description); $fileObj->setFileName($filename); include_once "./Services/Utilities/classes/class.ilMimeTypeUtil.php"; $fileObj->setFileType(ilMimeTypeUtil::getMimeType("", $filename, $type)); $fileObj->setFileSize($size); $this->object_id = $fileObj->create(); $this->putObjectInTree($fileObj, $this->parent_id); // see uploadFiles() if (is_array($this->after_creation_callback_objects)) { $this->after_creation_callback_objects[] = $fileObj; } // upload file to filesystem $fileObj->createDirectory(); $fileObj->raiseUploadError(false); $fileObj->getUploadFile($temp_name, $filename); $this->handleAutoRating($fileObj); // BEGIN ChangeEvent: Record write event. require_once './Services/Tracking/classes/class.ilChangeEvent.php'; ilChangeEvent::_recordWriteEvent($fileObj->getId(), $ilUser->getId(), 'create'); // END ChangeEvent: Record write event. } return $response; }
/** * unzip file * * @param string $a_file full path/filename * @param boolean $overwrite pass true to overwrite existing files * @static * */ public static function unzip($a_file, $overwrite = false, $a_flat = false) { if (!is_file($a_file)) { return; } // if flat, move file to temp directory first if ($a_flat) { $tmpdir = ilUtil::ilTempnam(); ilUtil::makeDir($tmpdir); copy($a_file, $tmpdir . DIRECTORY_SEPARATOR . basename($a_file)); $orig_file = $a_file; $a_file = $tmpdir . DIRECTORY_SEPARATOR . basename($a_file); $origpathinfo = pathinfo($orig_file); } $pathinfo = pathinfo($a_file); $dir = $pathinfo["dirname"]; $file = $pathinfo["basename"]; // unzip $cdir = getcwd(); chdir($dir); $unzip = PATH_TO_UNZIP; // the following workaround has been removed due to bug // http://www.ilias.de/mantis/view.php?id=7578 // since the workaround is quite old, it may not be necessary // anymore, alex 9 Oct 2012 /* // workaround for unzip problem (unzip of subdirectories fails, so // we create the subdirectories ourselves first) // get list $unzipcmd = "-Z -1 ".ilUtil::escapeShellArg($file); $arr = ilUtil::execQuoted($unzip, $unzipcmd); $zdirs = array(); foreach($arr as $line) { if(is_int(strpos($line, "/"))) { $zdir = substr($line, 0, strrpos($line, "/")); $nr = substr_count($zdir, "/"); //echo $zdir." ".$nr."<br>"; while ($zdir != "") { $nr = substr_count($zdir, "/"); $zdirs[$zdir] = $nr; // collect directories //echo $dir." ".$nr."<br>"; $zdir = substr($zdir, 0, strrpos($zdir, "/")); } } } asort($zdirs); foreach($zdirs as $zdir => $nr) // create directories { ilUtil::createDirectory($zdir); } */ // real unzip if (!$overwrite) { $unzipcmd = ilUtil::escapeShellArg($file); } else { $unzipcmd = "-o " . ilUtil::escapeShellArg($file); } ilUtil::execQuoted($unzip, $unzipcmd); chdir($cdir); // if flat, get all files and move them to original directory if ($a_flat) { include_once "./Services/Utilities/classes/class.ilFileUtils.php"; $filearray = array(); ilFileUtils::recursive_dirscan($tmpdir, $filearray); if (is_array($filearray["file"])) { foreach ($filearray["file"] as $k => $f) { if (substr($f, 0, 1) != "." && $f != basename($orig_file)) { copy($filearray["path"][$k] . $f, $origpathinfo["dirname"] . DIRECTORY_SEPARATOR . $f); } } } ilUtil::delDir($tmpdir); } }
function exportPDF($a_inst, $a_target_dir, &$expLog) { global $ilBench; $a_xml_writer = new ilXmlWriter(); $a_xml_writer->xmlStartTag("ContentObject", array("Type" => "SCORM2004SCO")); $this->exportXMLMetaData($a_xml_writer); $tree = new ilTree($this->getId()); $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node'); $tree->setTreeTablePK("slm_id"); foreach ($tree->getSubTree($tree->getNodeData($tree->getRootId()), true, 'sco') as $sco) { include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Sco.php"; $sco_folder = $a_target_dir . "/" . $sco['obj_id']; ilUtil::makeDir($sco_folder); $node = new ilSCORM2004Sco($this, $sco['obj_id']); $node->exportPDFPrepareXmlNFiles($a_inst, $a_target_dir, $expLog, $a_xml_writer); } if ($this->getAssignedGlossary() != 0) { ilUtil::makeDir($a_target_dir . "/glossary"); include_once "./Modules/Glossary/classes/class.ilObjGlossary.php"; include_once "./Modules/Glossary/classes/class.ilGlossaryExport.php"; $glos = new ilObjGlossary($this->getAssignedGlossary(), false); $glos_export = new ilGlossaryExport($glos, "xml"); $glos->exportXML($a_xml_writer, $glos_export->getInstId(), $a_target_dir . "/glossary", $expLog); } copy('./templates/default/images/icon_attachment_s.png', $a_target_dir . "/icon_attachment_s.png"); $a_xml_writer->xmlEndTag("ContentObject"); include_once 'Services/Transformation/classes/class.ilXML2FO.php'; $xml2FO = new ilXML2FO(); $xml2FO->setXSLTLocation('./Modules/Scorm2004/templates/xsl/contentobject2fo.xsl'); $xml2FO->setXMLString($a_xml_writer->xmlDumpMem()); $xml2FO->setXSLTParams(array('target_dir' => $a_target_dir)); $xml2FO->transform(); $fo_string = $xml2FO->getFOString(); $fo_xml = simplexml_load_string($fo_string); $fo_ext = $fo_xml->xpath("//fo:declarations"); $fo_ext = $fo_ext[0]; $results = array(); include_once "./Services/Utilities/classes/class.ilFileUtils.php"; ilFileUtils::recursive_dirscan($a_target_dir . "/objects", $results); if (is_array($results["file"])) { foreach ($results["file"] as $key => $value) { $e = $fo_ext->addChild("fox:embedded-file", "", "http://xml.apache.org/fop/extensions"); $e->addAttribute("src", $results[path][$key] . $value); $e->addAttribute("name", $value); $e->addAttribute("desc", ""); } } $fo_string = $fo_xml->asXML(); $a_xml_writer->_XmlWriter; return $fo_string; }
/** * delete object file */ function unzipFile() { global $lng; if (isset($_GET["upfile"])) { $file = basename($_GET["upfile"]); } else { if (!isset($_POST["file"])) { $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE); } if (count($_POST["file"]) > 1) { $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"), $this->ilias->error_obj->MESSAGE); } $file = basename($_POST["file"][0]); } $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"])); $cur_dir = !empty($cur_subdir) ? $this->main_dir . "/" . $cur_subdir : $this->main_dir; $file = $cur_dir . "/" . ilUtil::stripSlashes($file); if (@is_file($file)) { $cur_files = array_keys(ilUtil::getDir($cur_dir)); if ($this->getAllowDirectories()) { ilUtil::unzip($file, true); } else { ilUtil::unzip($file, true, true); } $new_files = array_keys(ilUtil::getDir($cur_dir)); $diff = array_diff($new_files, $cur_files); if (sizeof($diff)) { if ($this->getAllowDirectories()) { include_once "./Services/Utilities/classes/class.ilFileUtils.php"; $new_files = array(); foreach ($diff as $new_item) { if (is_dir($cur_dir . "/" . $new_item)) { ilFileUtils::recursive_dirscan($cur_dir . "/" . $new_item, $new_files); } } if (is_array($new_files["path"])) { foreach ($new_files["path"] as $idx => $path) { $path = substr($path, strlen($this->main_dir) + 1); $diff[] = $path . $new_files["file"][$idx]; } } } $this->setPerformedCommand("unzip_file", array("name" => substr($file, strlen($this->main_dir) + 1), "added" => $diff)); } } ilUtil::renameExecutables($this->main_dir); $this->ctrl->saveParameter($this, "cdir"); ilUtil::sendSuccess($lng->txt("cont_file_unzipped"), true); $this->ctrl->redirect($this, "listFiles"); }
public function dbImportSco($slm, $sco, $asset = false) { $qtis = array(); $d = ilUtil::getDir($this->packageFolder); foreach ($d as $f) { //continue; if ($f[type] == 'file' && substr($f[entry], 0, 4) == 'qti_') { include_once "./Services/QTI/classes/class.ilQTIParser.php"; include_once "./Modules/Test/classes/class.ilObjTest.php"; $qtiParser = new ilQTIParser($this->packageFolder . "/" . $f[entry], IL_MO_VERIFY_QTI, 0, ""); $result = $qtiParser->startParsing(); $founditems =& $qtiParser->getFoundItems(); // die(print_r($founditems)); foreach ($founditems as $qp) { $newObj = new ilObjTest(0, true); // This creates a lot of invalid repository objects for each question // question are not repository objects (see e.g. table object_data), alex 29 Sep 2009 // $newObj->setType ( $qp ['type'] ); // $newObj->setTitle ( $qp ['title'] ); // $newObj->create ( true ); // $newObj->createReference (); // $newObj->putInTree ($_GET ["ref_id"]); // $newObj->setPermissions ( $sco->getId ()); // $newObj->notify ("new", $_GET["ref_id"], $sco->getId (), $_GET["ref_id"], $newObj->getRefId () ); // $newObj->mark_schema->flush (); $qtiParser = new ilQTIParser($this->packageFolder . "/" . $f[entry], IL_MO_PARSE_QTI, 0, ""); $qtiParser->setTestObject($newObj); $result = $qtiParser->startParsing(); // $newObj->saveToDb (); $qtis = array_merge($qtis, $qtiParser->getImportMapping()); } } } //exit; include_once 'Modules/Scorm2004/classes/class.ilSCORM2004Page.php'; $doc = new SimpleXMLElement($this->imsmanifest->saveXml()); $l = $doc->xpath("/ContentObject/MetaData"); if ($l[0]) { include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php'; $mdxml =& new ilMDXMLCopier($l[0]->asXML(), $slm->getId(), $sco->getId(), $sco->getType()); $mdxml->startParsing(); $mdxml->getMDObject()->update(); } $l = $doc->xpath("/ContentObject/PageObject"); foreach ($l as $page_xml) { $tnode = $page_xml->xpath('MetaData/General/Title'); $page = new ilSCORM2004PageNode($slm); $page->setTitle($tnode[0]); $page->setSLMId($slm->getId()); $page->create(true); ilSCORM2004Node::putInTree($page, $sco->getId(), $target); $pmd = $page_xml->xpath("MetaData"); if ($pmd[0]) { include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php'; $mdxml =& new ilMDXMLCopier($pmd[0]->asXML(), $slm->getId(), $page->getId(), $page->getType()); $mdxml->startParsing(); $mdxml->getMDObject()->update(); } $tnode = $page_xml->xpath("//MediaObject/MediaAlias | //InteractiveImage/MediaAlias"); foreach ($tnode as $ttnode) { include_once './Services/MediaObjects/classes/class.ilObjMediaObject.php'; $OriginId = $ttnode[OriginId]; $medianodes = $doc->xpath("//MediaObject[MetaData/General/Identifier/@Entry='" . $OriginId . "']"); $medianode = $medianodes[0]; if ($medianode) { $media_object = new ilObjMediaObject(); $media_object->setTitle($medianode->MetaData->General->Title); $media_object->setDescription($medianode->MetaData->General->Description); $media_object->create(false); $mmd = $medianode->xpath("MetaData"); if ($mmd[0]) { include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php'; $mdxml =& new ilMDXMLCopier($mmd[0]->asXML(), 0, $media_object->getId(), $media_object->getType()); $mdxml->startParsing(); $mdxml->getMDObject()->update(); } // determine and create mob directory, move uploaded file to directory $media_object->createDirectory(); $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId()); foreach ($medianode->MediaItem as $xMediaItem) { $media_item =& new ilMediaItem(); $media_object->addMediaItem($media_item); $media_item->setPurpose($xMediaItem[Purpose]); $media_item->setFormat($xMediaItem->Format); $media_item->setLocation($xMediaItem->Location); $media_item->setLocationType($xMediaItem->Location[Type]); $media_item->setWidth($xMediaItem->Layout[Width]); $media_item->setHeight($xMediaItem->Layout[Height]); $media_item->setHAlign($xMediaItem->Layout[HorizontalAlign]); $media_item->setCaption($xMediaItem->Caption); $media_item->setTextRepresentation($xMediaItem->TextRepresentation); $nr = 0; // add map areas (external links only) foreach ($xMediaItem->MapArea as $n => $v) { if ($v->ExtLink[Href] != "") { include_once "./Services/MediaObjects/classes/class.ilMapArea.php"; $ma = new ilMapArea(); $map_area = new ilMapArea(); $map_area->setShape($v[Shape]); $map_area->setCoords($v[Coords]); $map_area->setLinkType(IL_EXT_LINK); $map_area->setTitle($v->ExtLink); $map_area->setHref($v->ExtLink[Href]); $media_item->addMapArea($map_area); } } if ($media_item->getLocationType() == "LocalFile") { // $tmp_name = $this->packageFolder."/objects/".$OriginId."/".$xMediaItem->Location; // copy($tmp_name, $mob_dir."/".$xMediaItem->Location); } } // copy whole directory ilUtil::rCopy($this->packageFolder . "/objects/" . $OriginId, $mob_dir); // alex: fixed media import: these lines have been // behind the next curly bracket which makes it fail // when no medianode is given. (id=0 -> fatal error) ilUtil::renameExecutables($mob_dir); $media_object->update(true); $ttnode[OriginId] = "il__mob_" . $media_object->getId(); } } include_once "./Modules/File/classes/class.ilObjFile.php"; include_once "./Services/Utilities/classes/class.ilFileUtils.php"; include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $intlinks = $page_xml->xpath("//IntLink"); foreach ($intlinks as $intlink) { if ($intlink[Type] != "File") { continue; } $path = $this->packageFolder . "/objects/" . str_replace('dfile', 'file', $intlink[Target]); if (!is_dir($path)) { continue; } $ffiles = array(); ilFileUtils::recursive_dirscan($path, $ffiles); $filename = $ffiles[file][0]; $fileObj = new ilObjFile(); $fileObj->setType("file"); $fileObj->setTitle(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileObj->setFileName(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); // better use this, mime_content_type is deprecated $fileObj->setFileType(ilObjMediaObject::getMimeType($path . "/" . $filename)); $fileObj->setFileSize(filesize($path . "/" . $filename)); $fileObj->create(); $fileObj->createReference(); //$fileObj->putInTree($_GET["ref_id"]); //$fileObj->setPermissions($slm->getId ()); $fileObj->createDirectory(); $fileObj->storeUnzipedFile($path . "/" . $filename, ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $intlink[Target] = "il__dfile_" . $fileObj->getId(); } $fileitems = $page_xml->xpath("//FileItem/Identifier"); foreach ($fileitems as $fileitem) { $path = $this->packageFolder . "/objects/" . $fileitem[Entry]; if (!is_dir($path)) { continue; } $ffiles = array(); ilFileUtils::recursive_dirscan($path, $ffiles); $filename = $ffiles[file][0]; $fileObj = new ilObjFile(); $fileObj->setType("file"); $fileObj->setTitle(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileObj->setFileName(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); // better use this, mime_content_type is deprecated $fileObj->setFileType(ilObjMediaObject::getMimeType($path . "/" . $filename)); $fileObj->setFileSize(filesize($path . "/" . $filename)); $fileObj->create(); $fileObj->createReference(); //$fileObj->putInTree($_GET["ref_id"]); //$fileObj->setPermissions($slm->getId ()); $fileObj->createDirectory(); $fileObj->storeUnzipedFile($path . "/" . $filename, ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileitem[Entry] = "il__file_" . $fileObj->getId(); } $pagex = new ilSCORM2004Page($page->getId()); $ddoc = new DOMDocument(); $ddoc->async = false; $ddoc->preserveWhiteSpace = false; $ddoc->formatOutput = false; $ddoc->loadXML($page_xml->asXML()); $xpath = new DOMXPath($ddoc); $tnode = $xpath->query('PageContent'); $t = "<PageObject>"; foreach ($tnode as $ttnode) { $t .= $ddoc->saveXML($ttnode); } $t .= "</PageObject>"; foreach ($qtis as $old => $q) { $t = str_replace($old, 'il__qst_' . $q['pool'], $t); } $pagex->setXMLContent($t); $pagex->updateFromXML(); } }
/** * handler for end of element * * @param resource $a_xml_parser xml parser * @param string $a_name element name */ function handlerEndTag($a_xml_parser, $a_name) { $this->cdata = trim($this->cdata); $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->cdata); switch ($a_name) { case 'File': $this->result = true; break; case 'Filename': if (strlen($this->cdata) == 0) { throw new ilFileException("Filename ist missing!"); } $this->file->setFilename($this->cdata); $this->file->setTitle($this->cdata); break; case 'Title': $this->file->setTitle(trim($this->cdata)); break; case 'Description': $this->file->setDescription(trim($this->cdata)); break; case 'Content': $GLOBALS['ilLog']->write($this->mode); $this->isReadingFile = false; $baseDecodedFilename = ilUtil::ilTempnam(); if ($this->mode == ilFileXMLParser::$CONTENT_COPY) { $this->tmpFilename = $this->getImportDirectory() . "/" . $this->cdata; } elseif ($this->mode == ilFileXMLParser::$CONTENT_REST) { include_once './Services/WebServices/Rest/classes/class.ilRestFileStorage.php'; $storage = new ilRestFileStorage(); $this->tmpFilename = $storage->getStoredFilePath($this->cdata); if (!ilFileUtils::fastBase64Decode($this->tmpFilename, $baseDecodedFilename)) { throw new ilFileException("Base64-Decoding failed", ilFileException::$DECOMPRESSION_FAILED); } $this->tmpFilename = $baseDecodedFilename; } else { if (!ilFileUtils::fastBase64Decode($this->tmpFilename, $baseDecodedFilename)) { throw new ilFileException("Base64-Decoding failed", ilFileException::$DECOMPRESSION_FAILED); } if ($this->mode == ilFileXMLParser::$CONTENT_GZ_COMPRESSED) { if (!ilFileUtils::fastGunzip($baseDecodedFilename, $this->tmpFilename)) { throw new ilFileException("Deflating with fastzunzip failed", ilFileException::$DECOMPRESSION_FAILED); } unlink($baseDecodedFilename); } elseif ($this->mode == ilFileXMLParser::$CONTENT_ZLIB_COMPRESSED) { if (!ilFileUtils::fastGunzip($baseDecodedFilename, $this->tmpFilename)) { throw new ilFileException("Deflating with fastDecompress failed", ilFileException::$DECOMPRESSION_FAILED); } unlink($baseDecodedFilename); } else { $this->tmpFilename = $baseDecodedFilename; } } //$this->content = $content; $this->file->setFileSize(filesize($this->tmpFilename)); // strlen($this->content)); // if no file type is given => lookup mime type if (!$this->file->getFileType()) { global $ilLog; #$ilLog->write(__METHOD__.': Trying to detect mime type...'); include_once './Services/Utilities/classes/class.ilFileUtils.php'; $this->file->setFileType(ilFileUtils::_lookupMimeType($this->tmpFilename)); } break; } $this->cdata = ''; return; }
/** * saveUnzip object * * @access public */ function saveUnzip() { $zip_form_gui = $this->initZipUploadForm(); if ($this->checkPermissionBool("create", "", "file")) { if ($zip_form_gui->checkInput()) { $zip_file = $zip_form_gui->getInput("zip_file"); $adopt_structure = $zip_form_gui->getInput("adopt_structure"); include_once "Services/Utilities/classes/class.ilFileUtils.php"; // Create unzip-directory $newDir = ilUtil::ilTempnam(); ilUtil::makeDir($newDir); // Check if permission is granted for creation of object, if necessary if ($this->id_type != self::WORKSPACE_NODE_ID) { $type = ilObject::_lookupType((int) $this->parent_id, true); } else { $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false); } $tree = $access_handler = null; switch ($type) { // workspace structure case 'wfld': case 'wsrt': $permission = $this->checkPermissionBool("create", "", "wfld"); $containerType = "WorkspaceFolder"; $tree = $this->tree; $access_handler = $this->getAccessHandler(); break; // use categories as structure // use categories as structure case 'cat': case 'root': $permission = $this->checkPermissionBool("create", "", "cat"); $containerType = "Category"; break; // use folders as structure (in courses) // use folders as structure (in courses) default: $permission = $this->checkPermissionBool("create", "", "fold"); $containerType = "Folder"; break; } // processZipFile ( // Dir to unzip, // Path to uploaded file, // should a structure be created (+ permission check)? // ref_id of parent // object that contains files (folder or category) // should sendInfo be persistent?) try { $processDone = ilFileUtils::processZipFile($newDir, $zip_file["tmp_name"], $adopt_structure && $permission, $this->parent_id, $containerType, $tree, $access_handler); ilUtil::sendSuccess($this->lng->txt("file_added"), true); } catch (ilFileUtilsException $e) { ilUtil::sendFailure($e->getMessage(), true); } ilUtil::delDir($newDir); $this->ctrl->returnToParent($this); } else { $zip_form_gui->setValuesByPost(); $this->tpl->setContent($zip_form_gui->getHTML()); } } else { $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE); } }
/** * Creates and inserts file object into tree * * @author Jan Hippchen * @version 1.6.9.07 * @param string $filename Name of the object * @param string $path Path to file * @param integer $ref_id ref_id of parent */ function createFile($filename, $path, $ref_id, $tree = null, $access_handler = null) { global $rbacsystem; if (!$access_handler) { $permission = $rbacsystem->checkAccess("create", $ref_id, "file"); } else { $permission = $access_handler->checkAccess("create", "", $ref_id, "file"); } if ($permission) { // create and insert file in grp_tree include_once "./Modules/File/classes/class.ilObjFile.php"; $fileObj = new ilObjFile(); $fileObj->setType($this->type); $fileObj->setTitle(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileObj->setFileName(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); // better use this, mime_content_type is deprecated include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $fileObj->setFileType(ilObjMediaObject::getMimeType($path . "/" . $filename)); $fileObj->setFileSize(filesize($path . "/" . $filename)); $fileObj->create(); // repository if (!$access_handler) { $fileObj->createReference(); $fileObj->putInTree($ref_id); $fileObj->setPermissions($ref_id); self::$new_files[$ref_id][] = $fileObj; } else { $node_id = $tree->insertObject($ref_id, $fileObj->getId()); $access_handler->setPermissions($ref_id, $node_id); } // upload file to filesystem $fileObj->createDirectory(); $fileObj->storeUnzipedFile($path . "/" . $filename, ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); } else { $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE); } }