/**
  * Create new media object and update page in db and return new media object
  */
 function &_saveTempFileAsMediaObject($name, $tmp_name, $upload = TRUE)
 {
     // create dummy object in db (we need an id)
     $media_object = new ilObjMediaObject();
     $media_object->setTitle($name);
     $media_object->setDescription("");
     $media_object->create();
     // determine and create mob directory, move uploaded file to directory
     $media_object->createDirectory();
     $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
     $media_item =& new ilMediaItem();
     $media_object->addMediaItem($media_item);
     $media_item->setPurpose("Standard");
     $file = $mob_dir . "/" . $name;
     if ($upload) {
         ilUtil::moveUploadedFile($tmp_name, $name, $file);
     } else {
         copy($tmp_name, $file);
     }
     // get mime type
     $format = ilObjMediaObject::getMimeType($file);
     $location = $name;
     // set real meta and object data
     $media_item->setFormat($format);
     $media_item->setLocation($location);
     $media_item->setLocationType("LocalFile");
     $media_object->setTitle($name);
     $media_object->setDescription($format);
     if (ilUtil::deducibleSize($format)) {
         $size = getimagesize($file);
         $media_item->setWidth($size[0]);
         $media_item->setHeight($size[1]);
     }
     $media_item->setHAlign("Left");
     ilUtil::renameExecutables($mob_dir);
     $media_object->update();
     return $media_object;
 }
예제 #2
0
 /**
  * estimate content type for a filename by extension
  * first do it for common static web files from external list
  * if not found peek into file by slow php function mime_content_type()
  * @param $filename required
  * @return string mimetype name e.g. image/jpeg
  */
 public function getMimetype($filename)
 {
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     return ilObjMediaObject::getMimeType($filename);
 }
 /**
  * update media item from form
  *
  * @param IlObjectMediaObject $mob
  * @param IlMediaItem $mediaItem
  * @return string file
  */
 private function updateMediaItem($mob, &$mediaItem)
 {
     $purpose = $mediaItem->getPurpose();
     $url_gui = $this->form_gui->getInput("url_" . $purpose);
     $file_gui = $this->form_gui->getInput("file_" . $purpose);
     if ($url_gui) {
         // http
         $file = $this->form_gui->getInput("url_" . $purpose);
         $title = basename($file);
         $location = $this->form_gui->getInput("url_" . $purpose);
         $locationType = "Reference";
     } elseif ($file_gui["size"] > 0) {
         // lokal
         // determine and create mob directory, move uploaded file to directory
         $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
         if (!is_dir($mob_dir)) {
             $mob->createDirectory();
         }
         $file_name = ilUtil::getASCIIFilename($_FILES['file_' . $purpose]['name']);
         $file_name = str_replace(" ", "_", $file_name);
         $file = $mob_dir . "/" . $file_name;
         $title = $file_name;
         $locationType = "LocalFile";
         $location = $title;
         ilUtil::moveUploadedFile($_FILES['file_' . $purpose]['tmp_name'], $file_name, $file);
         ilUtil::renameExecutables($mob_dir);
     }
     // check if not automatic mimetype detection
     if ($_POST["mimetype_" . $purpose] != "") {
         $mediaItem->setFormat($_POST["mimetype_" . $purpose]);
     } elseif ($mediaItem->getLocation() != "") {
         $format = ilObjMediaObject::getMimeType($mediaItem->getLocation());
         $mediaItem->setFormat($format);
     }
     if (isset($file)) {
         // get mime type, if not already set!
         if (!isset($format)) {
             $format = ilObjMediaObject::getMimeType($file);
         }
         // set real meta and object data
         $mediaItem->setFormat($format);
         $mediaItem->setLocation($location);
         $mediaItem->setLocationType($locationType);
         $mediaItem->setHAlign("Left");
         $mediaItem->setHeight(self::isAudio($format) ? 0 : 180);
     }
     if ($purpose == "Standard") {
         if (isset($title)) {
             $mob->setTitle($title);
         }
         if (isset($format)) {
             $mob->setDescription($format);
         }
     }
     return $file;
 }
 /**
  * Deliver vcard information.
  */
 function deliverVCard()
 {
     // get user object
     if (!ilObject::_exists($this->getUserId())) {
         return "";
     }
     $user = new ilObjUser($this->getUserId());
     require_once "./Services/User/classes/class.ilvCard.php";
     $vcard = new ilvCard();
     // ilsharedresourceGUI: embedded in shared portfolio
     if ($user->getPref("public_profile") != "y" && $user->getPref("public_profile") != "g" && $_GET["baseClass"] != "ilsharedresourceGUI") {
         return;
     }
     $vcard->setName($user->getLastName(), $user->getFirstName(), "", $user->getUTitle());
     $vcard->setNickname($user->getLogin());
     $webspace_dir = ilUtil::getWebspaceDir("output");
     $imagefile = $webspace_dir . "/usr_images/" . $user->getPref("profile_image");
     if ($user->getPref("public_upload") == "y" && @is_file($imagefile)) {
         $fh = fopen($imagefile, "r");
         if ($fh) {
             $image = fread($fh, filesize($imagefile));
             fclose($fh);
             require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
             $mimetype = ilObjMediaObject::getMimeType($imagefile);
             if (preg_match("/^image/", $mimetype)) {
                 $type = $mimetype;
             }
             $vcard->setPhoto($image, $type);
         }
     }
     $val_arr = array("getInstitution" => "institution", "getDepartment" => "department", "getStreet" => "street", "getZipcode" => "zipcode", "getCity" => "city", "getCountry" => "country", "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home", "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email", "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
     $org = array();
     $adr = array();
     foreach ($val_arr as $key => $value) {
         // if value "y" show information
         if ($user->getPref("public_" . $value) == "y") {
             switch ($value) {
                 case "institution":
                     $org[0] = $user->{$key}();
                     break;
                 case "department":
                     $org[1] = $user->{$key}();
                     break;
                 case "street":
                     $adr[2] = $user->{$key}();
                     break;
                 case "zipcode":
                     $adr[5] = $user->{$key}();
                     break;
                 case "city":
                     $adr[3] = $user->{$key}();
                     break;
                 case "country":
                     $adr[6] = $user->{$key}();
                     break;
                 case "phone_office":
                     $vcard->setPhone($user->{$key}(), TEL_TYPE_WORK);
                     break;
                 case "phone_home":
                     $vcard->setPhone($user->{$key}(), TEL_TYPE_HOME);
                     break;
                 case "phone_mobile":
                     $vcard->setPhone($user->{$key}(), TEL_TYPE_CELL);
                     break;
                 case "fax":
                     $vcard->setPhone($user->{$key}(), TEL_TYPE_FAX);
                     break;
                 case "email":
                     $vcard->setEmail($user->{$key}());
                     break;
                 case "hobby":
                     $vcard->setNote($user->{$key}());
                     break;
             }
         }
     }
     if (count($org)) {
         $vcard->setOrganization(join(";", $org));
     }
     if (count($adr)) {
         $vcard->setAddress($adr[0], $adr[1], $adr[2], $adr[3], $adr[4], $adr[5], $adr[6]);
     }
     ilUtil::deliverData(utf8_decode($vcard->buildVCard()), $vcard->getFilename(), $vcard->getMimetype());
 }
 /**
  * store delivered file in filesystem
  * @param array HTTP_POST_FILES
  * @param numeric database id of the user who delivered the file
  * @access	public
  * @return mixed Returns a result array with filename and mime type of the saved file, otherwise false
  */
 function deliverFile($a_http_post_file, $user_id, $is_unziped = false)
 {
     $this->create();
     // TODO:
     // CHECK UPLOAD LIMIT
     //
     $result = false;
     if (isset($a_http_post_file) && $a_http_post_file['size']) {
         $filename = $a_http_post_file['name'];
         // replace whitespaces with underscores
         $filename = preg_replace("/\\s/", "_", $filename);
         // remove all special characters
         $filename = preg_replace("/[^_a-zA-Z0-9\\.]/", "", $filename);
         if (!is_dir($savepath = $this->getAbsoluteSubmissionPath())) {
             ilUtil::makeDir($savepath);
         }
         $savepath .= '/' . $user_id;
         if (!is_dir($savepath)) {
             ilUtil::makeDir($savepath);
         }
         // CHECK IF FILE PATH EXISTS
         if (!is_dir($savepath)) {
             require_once "./Services/Utilities/classes/class.ilUtil.php";
             #ilUtil::makeDirParents($savepath);
             ilUtil::makeDir($savepath);
         }
         $now = getdate();
         $prefix = sprintf("%04d%02d%02d%02d%02d%02d", $now["year"], $now["mon"], $now["mday"], $now["hours"], $now["minutes"], $now["seconds"]);
         if (!$is_unziped) {
             //move_uploaded_file($a_http_post_file["tmp_name"], $savepath . $prefix . "_" . $filename);
             ilUtil::moveUploadedFile($a_http_post_file["tmp_name"], $a_http_post_file["name"], $savepath . "/" . $prefix . "_" . $filename);
         } else {
             rename($a_http_post_file['tmp_name'], $savepath . "/" . $prefix . "_" . $filename);
         }
         require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         if (is_file($savepath . "/" . $prefix . "_" . $filename)) {
             $result = array("filename" => $prefix . "_" . $filename, "fullname" => $savepath . "/" . $prefix . "_" . $filename, "mimetype" => ilObjMediaObject::getMimeType($savepath . "/" . $prefix . "_" . $filename));
         }
     }
     return $result;
 }
 /**
  * Uploads a new rooms agreement by using the ILIAS MediaObject Service.
  * If the old file id is given, the old file will be deleted.
  *
  * @param array  $a_newfile   an array containing the input values of the form
  * @param string $a_oldFileId to delete trash
  *
  * @return string uploaded file id
  */
 public function uploadRoomsAgreement($a_newfile, $a_oldFileId = "0")
 {
     if (!empty($a_oldFileId) && $a_oldFileId != "0") {
         $agreementFile = new ilObjMediaObject($a_oldFileId);
         $agreementFile->delete();
     }
     $mediaObj = new ilObjMediaObject();
     $mediaObj->setTitle("RoomSharingRoomsAgreement");
     $mediaObj->setDescription("RoomSharingRoomsAgreement");
     $mediaObj->create();
     $mob_dir = ilObjMediaObject::_getDirectory($mediaObj->getId());
     if (!is_dir($mob_dir)) {
         $mediaObj->createDirectory();
     }
     $file_name = ilUtil::getASCIIFilename($a_newfile["name"]);
     $file_name_mod = str_replace(" ", "_", $file_name);
     $file = $mob_dir . "/" . $file_name_mod;
     ilUtil::moveUploadedFile($a_newfile["tmp_name"], $file_name_mod, $file);
     ilUtil::renameExecutables($mob_dir);
     $format = ilObjMediaObject::getMimeType($file);
     $media_item = new ilMediaItem();
     $mediaObj->addMediaItem($media_item);
     $media_item->setPurpose("Standard");
     $media_item->setFormat($format);
     $media_item->setLocation($file_name_mod);
     $media_item->setLocationType("LocalFile");
     $mediaObj->update();
     return $mediaObj->getId();
 }
 /**
  * Create media object from upload directory
  */
 function createMediaFromUploadDir()
 {
     $mset = new ilSetting("mobs");
     $upload_dir = trim($mset->get("upload_dir"));
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     if (is_array($_POST["file"]) && ilMainMenuGUI::_checkAdministrationPermission()) {
         foreach ($_POST["file"] as $f) {
             $f = str_replace("..", "", $f);
             $fullpath = $upload_dir . "/" . $f;
             $mob = new ilObjMediaObject();
             $mob->setTitle(basename($fullpath));
             $mob->setDescription("");
             $mob->create();
             // determine and create mob directory, move uploaded file to directory
             //$mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob->getId();
             $mob->createDirectory();
             $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
             $media_item = new ilMediaItem();
             $mob->addMediaItem($media_item);
             $media_item->setPurpose("Standard");
             $file = $mob_dir . "/" . basename($fullpath);
             ilUtil::moveUploadedFile($fullpath, basename($fullpath), $file, false, $_POST["action"]);
             // get mime type
             $format = ilObjMediaObject::getMimeType($file);
             $location = basename($fullpath);
             // set real meta and object data
             $media_item->setFormat($format);
             $media_item->setLocation($location);
             $media_item->setLocationType("LocalFile");
             $mob->setDescription($format);
             // determine width and height of known image types
             $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format, "File", $mob_dir . "/" . $location, $media_item->getLocation(), true, true, "", "");
             $media_item->setWidth($wh["width"]);
             $media_item->setHeight($wh["height"]);
             if ($wh["info"] != "") {
                 //				ilUtil::sendInfo($wh["info"], true);
             }
             $media_item->setHAlign("Left");
             ilUtil::renameExecutables($mob_dir);
             $mob->update();
             // put it into current folder
             $mep_item = new ilMediaPoolItem();
             $mep_item->setTitle($mob->getTitle());
             $mep_item->setType("mob");
             $mep_item->setForeignId($mob->getId());
             $mep_item->create();
             $tree = $this->object->getTree();
             $parent = $_GET["mepitem_id"] == "" ? $tree->getRootId() : $_GET["mepitem_id"];
             $tree->insertNode($mep_item->getId(), $parent);
         }
     }
     ilUtil::redirect("ilias.php?baseClass=ilMediaPoolPresentationGUI&cmd=listMedia&ref_id=" . $_GET["ref_id"] . "&mepitem_id=" . $_GET["mepitem_id"]);
 }
예제 #8
0
 /**
  * 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);
     }
 }
 /**
  * Configures the file for the updateFloorPlanInfosWithFile and addFloorPlan function.
  *
  * @param ilObjMediaObject $a_mediaObj
  * @param array            $a_newfile
  *
  * @return array with format and filename
  */
 private function configureFile($a_mediaObj, $a_newfile = NULL)
 {
     if ($this->mobjMock) {
         return $a_newfile;
     }
     $mob_dir = ilObjMediaObject::_getDirectory($a_mediaObj->getId());
     if (!is_dir($mob_dir)) {
         $a_mediaObj->createDirectory();
     }
     $file_name = ilUtil::getASCIIFilename($a_newfile["name"]);
     $file_name_mod = str_replace(" ", "_", $file_name);
     $file = $mob_dir . "/" . $file_name_mod;
     // construct file path
     ilUtil::moveUploadedFile($a_newfile["tmp_name"], $file_name_mod, $file);
     ilUtil::renameExecutables($mob_dir);
     $format = ilObjMediaObject::getMimeType($file);
     return array("format" => $format, "filename" => $file_name_mod);
 }
 /**
  * Update (base image)
  */
 function update()
 {
     global $ilCtrl, $lng;
     $mob = $this->content_obj->getMediaObject();
     $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
     $std_item = $mob->getMediaItem("Standard");
     $location = $_FILES['image_file']['name'];
     if ($location != "" && is_file($_FILES['image_file']['tmp_name'])) {
         $file = $mob_dir . "/" . $_FILES['image_file']['name'];
         ilUtil::moveUploadedFile($_FILES['image_file']['tmp_name'], $_FILES['image_file']['name'], $file);
         // get mime type
         $format = ilObjMediaObject::getMimeType($file);
         $location = $_FILES['image_file']['name'];
         $std_item->setFormat($format);
         $std_item->setLocation($location);
         $std_item->setLocationType("LocalFile");
         $mob->setDescription($format);
         $mob->update();
     }
     // set caption
     $std_alias_item = new ilMediaAliasItem($this->dom, $this->getHierId(), "Standard", $this->content_obj->getPcId(), "InteractiveImage");
     $std_alias_item->setCaption(ilUtil::stripSlashes($_POST["caption"]));
     $_SESSION["il_pg_error"] = $this->pg_obj->update();
     ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
     $ilCtrl->redirectByClass("ilpcinteractiveimagegui", "editBaseImage");
 }
 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();
     }
 }
예제 #12
0
 /**
  * Get Html for MP3 Player
  */
 function getMp3PlayerHtml($a_preview = false)
 {
     global $tpl, $lng;
     include_once "./Services/YUI/classes/class.ilYuiUtil.php";
     ilYuiUtil::initConnection();
     $tpl->addJavascript("./Services/MediaObjects/js/MediaObjects.js");
     if (!self::$lightbox_initialized && $a_preview) {
         include_once "./Services/UIComponent/Lightbox/classes/class.ilLightboxGUI.php";
         $lb = new ilLightboxGUI("media_lightbox");
         $lb->setWidth("660px");
         $lb->addLightbox();
         self::$lightbox_initialized = true;
     }
     require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
     include_once "./Services/MediaObjects/classes/class.ilExternalMediaAnalyzer.php";
     // youtube
     /*		if (ilExternalMediaAnalyzer::isYouTube($this->getFile()))
     		{
     			$p = ilExternalMediaAnalyzer::extractYouTubeParameters($this->getFile());
     			$html = '<object width="320" height="240">'.
     				'<param name="movie" value="http://www.youtube.com/v/'.$p["v"].'?fs=1">'.
     				'</param><param name="allowFullScreen" value="true"></param>'.
     				'<param name="allowscriptaccess" value="always">'.
     				'</param><embed src="http://www.youtube.com/v/'.$p["v"].'?fs=1" '.
     				'type="application/x-shockwave-flash" allowscriptaccess="always" '.
     				'allowfullscreen="true" width="320" height="240"></embed></object>';
     			return $html;
     		}
     
     		// vimeo
     		if (ilExternalMediaAnalyzer::isVimeo($this->getFile()))
     		{
     			$p = ilExternalMediaAnalyzer::extractVimeoParameters($this->getFile());
     
     			$html = '<iframe src="http://player.vimeo.com/video/'.$p["id"].'" width="320" height="240" '.
     				'frameborder="0"></iframe>';
     
     			return $html;
     		}
     */
     $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
     include_once "./Services/MediaObjects/classes/class.ilPlayerUtil.php";
     // video tag
     if (in_array($mimeType, array("video/mp4", "video/m4v", "video/rtmp", "video/x-flv", "video/webm", "video/youtube", "video/vimeo", "video/ogg"))) {
         ilPlayerUtil::initMediaElementJs();
         if ($mimeType == "video/quicktime") {
             $mimeType = "video/mov";
         }
         $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
         // preview
         if ($a_preview) {
             if ($this->getDownloadLink() != "") {
                 $mp_tpl->setCurrentBlock("download");
                 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
                 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
                 $mp_tpl->parseCurrentBlock();
             }
             $mp_tpl->setCurrentBlock("preview");
             if ($this->getVideoPreviewPic() != "") {
                 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
             } else {
                 $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
             }
             $mp_tpl->setVariable("IMG_ALT", $this->video_preview_pic_alt);
             $mp_tpl->setVariable("PTITLE", $this->getTitle());
             $mp_tpl->parseCurrentBlock();
         }
         // sources
         $mp_tpl->setCurrentBlock("source");
         $mp_tpl->setVariable("FILE", $this->getFile());
         $mp_tpl->setVariable("MIME", $mimeType);
         $mp_tpl->parseCurrentBlock();
         if (in_array($this->getAlternativeVideoMimeType(), array("video/mp4", "video/webm"))) {
             $mp_tpl->setCurrentBlock("source");
             $mp_tpl->setVariable("FILE", $this->getAlternativeVideoFile());
             $mp_tpl->setVariable("MIME", $this->getAlternativeVideoMimeType());
             $mp_tpl->parseCurrentBlock();
         }
         $mp_tpl->setCurrentBlock("mejs_video");
         if ($a_preview) {
             $mp_tpl->setVariable("CLASS", "ilNoDisplay");
         }
         $mp_tpl->setVariable("PLAYER_NR", $this->id . "_" . $this->current_nr);
         $mp_tpl->setVariable("EVENT_URL", $this->event_callback_url);
         $height = $this->getDisplayHeight();
         $width = $this->getDisplayWidth();
         if (is_int(strpos($mimeType, "audio/mpeg"))) {
             $height = "30";
         }
         $mp_tpl->setVariable("DISPLAY_HEIGHT", $height);
         $mp_tpl->setVariable("DISPLAY_WIDTH", $width);
         $mp_tpl->setVariable("PREVIEW_PIC", $this->getVideoPreviewPic());
         $mp_tpl->setVariable("SWF_FILE", ilPlayerUtil::getFlashVideoPlayerFilename(true));
         $mp_tpl->setVariable("FFILE", $this->getFile());
         $mp_tpl->setVariable("TITLE", $this->getTitle());
         $mp_tpl->setVariable("DESCRIPTION", $this->getDescription());
         include_once "./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php";
         if ($a_preview) {
             $mp_tpl->setVariable("CLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
         }
         $mp_tpl->parseCurrentBlock();
         $r = $mp_tpl->get();
         if (!$a_preview) {
             $tpl->addOnLoadCode("new MediaElementPlayer('#player_" . $this->id . "_" . $this->current_nr . "');");
         }
         //echo htmlentities($r);
         return $r;
     }
     // audio/mpeg
     if (is_int(strpos($mimeType, "audio/mpeg")) || in_array($mimeType, array("application/ogg", "audio/ogg"))) {
         ilPlayerUtil::initMediaElementJs();
         $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
         $preview_output = false;
         if ($this->getVideoPreviewPic() != "" || $this->getForceAudioPreview()) {
             if ($this->getDownloadLink() != "") {
                 $mp_tpl->setCurrentBlock("adownload");
                 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
                 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
                 $mp_tpl->parseCurrentBlock();
             }
             $mp_tpl->setCurrentBlock("apreview");
             if ($this->getVideoPreviewPic() != "") {
                 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
             } else {
                 $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
             }
             $mp_tpl->setVariable("PTITLE", $this->getTitle());
             $mp_tpl->parseCurrentBlock();
             $preview_output = true;
         }
         $mp_tpl->setCurrentBlock("audio");
         if ($preview_output) {
             $mp_tpl->setVariable("ASTYLE", "margin-top:-30px");
         }
         $mp_tpl->setVariable("AFILE", $this->getFile());
         $mp_tpl->setVariable("APLAYER_NR", $this->id . "_" . $this->current_nr);
         $mp_tpl->setVariable("AEVENT_URL", $this->event_callback_url);
         $mp_tpl->setVariable("AHEIGHT", "30");
         $mp_tpl->setVariable("AWIDTH", "320");
         $mp_tpl->parseCurrentBlock();
         return $mp_tpl->get();
     }
     // images
     if (is_int(strpos($mimeType, "image/"))) {
         $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
         if ($this->getDownloadLink() != "") {
             $mp_tpl->setCurrentBlock("idownload");
             $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
             $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
             $mp_tpl->parseCurrentBlock();
         }
         $mp_tpl->setCurrentBlock("ipreview");
         if ($this->getVideoPreviewPic() != "") {
             $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
         } else {
             $mp_tpl->setVariable("IMG_SRC", $this->getFile());
         }
         $mp_tpl->setVariable("PTITLE", $this->getTitle());
         $mp_tpl->parseCurrentBlock();
         $mp_tpl->setCurrentBlock("image");
         $mp_tpl->setVariable("IFILE", $this->getFile());
         $mp_tpl->setVariable("IPLAYER_NR", $this->id . "_" . $this->current_nr);
         $mp_tpl->setVariable("ITITLE", $this->getTitle());
         $mp_tpl->setVariable("IDESCRIPTION", $this->getDescription());
         include_once "./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php";
         $mp_tpl->setVariable("ICLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
         $height = $this->getDisplayHeight();
         $width = $this->getDisplayWidth();
         $mp_tpl->setVariable("IHEIGHT", $height);
         $mp_tpl->setVariable("IWIDTH", $width);
         $mp_tpl->parseCurrentBlock();
         return $mp_tpl->get();
     }
     // fallback, no preview mode
     $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
     if (strpos($mimeType, "flv") === false && strpos($mimeType, "audio/mpeg") === false && strpos($mimeType, "image/png") === false && strpos($mimeType, "image/gif") === false) {
         $html = '<embed src="' . $this->getFile() . '" ' . 'type="' . $mimeType . '" ' . 'ShowControls="1" ' . 'autoplay="false" autostart="false" ' . 'width="320" height="240" scale="aspect" ></embed>';
         return $html;
     }
     return;
     $tpl->addJavaScript("./Services/MediaObjects/flash_flv_player/swfobject.js");
     $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
     $mp_tpl->setCurrentBlock("default");
     $mp_tpl->setVariable("FILE", urlencode($this->getFile()));
     $mp_tpl->setVariable("PLAYER_NR", $this->current_nr);
     $mp_tpl->setVariable("DISPLAY_HEIGHT", strpos($mimeType, "audio/mpeg") === false ? "240" : "20");
     $mp_tpl->setVariable("DISPLAY_WIDTH", "320");
     $mp_tpl->parseCurrentBlock();
     return $mp_tpl->get();
 }
예제 #13
0
 /**
  * assign file to fullscreen view
  */
 function assignFullscreenObject()
 {
     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);
     }
     // determine directory
     $cur_subdir = str_replace(".", "", $_GET["cdir"]);
     $mob_dir = ilUtil::getWebspaceDir() . "/mobs/mm_" . $this->object->getId();
     $cur_dir = !empty($cur_subdir) ? $mob_dir . "/" . $cur_subdir : $mob_dir;
     $file = $cur_dir . "/" . $_POST["file"][0];
     $location = !empty($cur_subdir) ? $cur_subdir . "/" . $_POST["file"][0] : $_POST["file"][0];
     if (!is_file($file)) {
         $this->ilias->raiseError($this->lng->txt("cont_select_file"), $this->ilias->error_obj->MESSAGE);
     }
     if (!$this->object->hasFullScreenItem()) {
         // create new fullscreen item
         $std_item =& $this->object->getMediaItem("Standard");
         $mob_dir = ilUtil::getWebspaceDir() . "/mobs/mm_" . $this->object->getId();
         $file = $mob_dir . "/" . $location;
         $full_item =& new ilMediaItem();
         $full_item->setMobId($std_item->getMobId());
         $full_item->setLocation($location);
         $full_item->setLocationType("LocalFile");
         $full_item->setFormat(ilObjMediaObject::getMimeType($file));
         $full_item->setPurpose("Fullscreen");
         $this->object->addMediaItem($full_item);
     } else {
         $full_item =& $this->object->getMediaItem("Fullscreen");
         $full_item->setLocationType("LocalFile");
         $full_item->setLocation($location);
         $format = ilObjMediaObject::getMimeType($file);
         $full_item->setFormat($format);
     }
     $this->object->update();
     //		$this->ctrl->saveParameter($this, "cdir");
     $this->ctrl->redirectByClass("ilfilesystemgui", "listFiles");
 }
 public function checkValidity($value, $record_id = null)
 {
     //Don't check empty values
     if ($value == NULL) {
         return true;
     }
     if (!ilDataCollectionDatatype::checkValidity($this->getDatatypeId(), $value)) {
         throw new ilDataCollectionInputException(ilDataCollectionInputException::TYPE_EXCEPTION);
     }
     $properties = $this->getPropertyvalues();
     $length = ilDataCollectionField::PROPERTYID_LENGTH;
     $regex_id = ilDataCollectionField::PROPERTYID_REGEX;
     $url = ilDataCollectionField::PROPERTYID_URL;
     if ($this->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_TEXT) {
         $regex = $properties[$regex_id];
         if (substr($regex, 0, 1) != "/") {
             $regex = "/" . $regex;
         }
         if (substr($regex, -1) != "/") {
             $regex .= "/";
         }
         if ($properties[$length] < strlen($value) && is_numeric($properties[$length])) {
             throw new ilDataCollectionInputException(ilDataCollectionInputException::LENGTH_EXCEPTION);
         }
         if (!($properties[$regex_id] == NULL || @preg_match($regex, $value))) {
             throw new ilDataCollectionInputException(ilDataCollectionInputException::REGEX_EXCEPTION);
         }
         //email or url
         if ($properties[$url] && !(preg_match('~(^(news|(ht|f)tp(s?)\\://){1}\\S+)~i', $value) || preg_match("/^[a-z0-9!#\$%&'*+=?^_`{|}~-]+(?:\\.[a-z0-9!#\$%&'*+=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\$/i", $value))) {
             throw new ilDataCollectionInputException(ilDataCollectionInputException::NOT_URL);
         }
     }
     if ($this->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB and $value['name']) {
         $arrMimeType = explode('/', ilObjMediaObject::getMimeType($value['name']));
         if ($arrMimeType[0] != "image") {
             throw new ilDataCollectionInputException(ilDataCollectionInputException::NOT_IMAGE);
         }
     }
     if ($this->isUnique() && $record_id === null) {
         $table = ilDataCollectionCache::getTableCache($this->getTableId());
         foreach ($table->getRecords() as $record) {
             if ($record->getRecordFieldValue($this->getId()) == $value && ($record->getId() != $record_id || $record_id == 0)) {
                 throw new ilDataCollectionInputException(ilDataCollectionInputException::UNIQUE_EXCEPTION);
             }
             //for text it has to be case insensitive.
             if ($this->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_TEXT) {
                 if (strtolower($record->getRecordFieldValue($this->getId())) == strtolower($value) && ($record->getId() != $record_id || $record_id == 0)) {
                     throw new ilDataCollectionInputException(ilDataCollectionInputException::UNIQUE_EXCEPTION);
                 }
             }
             if ($this->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) {
                 $datestring = $value["date"] . " " . $value["time"];
                 //["y"]."-".$value["date"]['m']."-".$value["date"]['d']." 00:00:00";
                 if ($record->getRecordFieldValue($this->getId()) == $datestring && ($record->getId() != $record_id || $record_id == 0)) {
                     throw new ilDataCollectionInputException(ilDataCollectionInputException::UNIQUE_EXCEPTION);
                 }
             }
         }
     }
     return true;
 }
 /**
  * Function to parse incoming data from form input value $value. returns the strin/number/etc. to store in the database.
  * @param $value
  * @param ilDataCollectionRecordField $record_field
  * @return int|string
  */
 public function parseValue($value, ilDataCollectionRecordField $record_field)
 {
     $return = false;
     if ($this->id == ilDataCollectionDatatype::INPUTFORMAT_FILE) {
         $file = $value;
         if ($file['tmp_name']) {
             $file_obj = new ilObjFile();
             $file_obj->setType("file");
             $file_obj->setTitle($file["name"]);
             $file_obj->setFileName($file["name"]);
             $file_obj->setFileType(ilMimeTypeUtil::getMimeType("", $file["name"], $file["type"]));
             $file_obj->setFileSize($file["size"]);
             $file_obj->setMode("object");
             $file_obj->create();
             $file_obj->getUploadFile($file["tmp_name"], $file["name"]);
             $file_id = $file_obj->getId();
             $return = $file_id;
         } else {
             $return = $record_field->getValue();
         }
     } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_MOB) {
         if ($value == -1) {
             //marked for deletion.
             return 0;
         }
         $media = $value;
         if ($media['tmp_name']) {
             $mob = new ilObjMediaObject();
             $mob->setTitle($media['name']);
             $mob->create();
             $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
             if (!is_dir($mob_dir)) {
                 $mob->createDirectory();
             }
             $media_item = new ilMediaItem();
             $mob->addMediaItem($media_item);
             $media_item->setPurpose("Standard");
             $file_name = ilUtil::getASCIIFilename($media['name']);
             $file_name = str_replace(" ", "_", $file_name);
             $file = $mob_dir . "/" . $file_name;
             $title = $file_name;
             ilUtil::moveUploadedFile($media['tmp_name'], $file_name, $file);
             ilUtil::renameExecutables($mob_dir);
             list($width, $height, $type, $attr) = getimagesize($file);
             $arr_properties = $record_field->getField()->getProperties();
             $new_width = $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH];
             $new_height = $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT];
             if ($new_width || $new_height) {
                 //only resize if it is bigger, not if it is smaller
                 if ($new_height < $height && $new_width < $width) {
                     //resize proportional
                     if (!$new_height || !$new_width) {
                         $format = ilObjMediaObject::getMimeType($file);
                         $wh = ilObjMediaObject::_determineWidthHeight("", "", $format, "File", $file, "", true, false, $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH], (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT]);
                     } else {
                         $wh['width'] = (int) $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH];
                         $wh['height'] = (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT];
                     }
                 }
                 $location = ilObjMediaObject::_resizeImage($file, $wh['width'], $wh['height'], false);
             } else {
                 $location = $title;
             }
             ilObjMediaObject::_saveUsage($mob->getId(), "dcl:html", $record_field->getRecord()->getTable()->getCollectionObject()->getId());
             $format = ilObjMediaObject::getMimeType($file);
             $media_item->setFormat($format);
             $media_item->setLocation($location);
             $media_item->setLocationType("LocalFile");
             $mob->update();
             $return = $mob->getId();
         } else {
             $return = $record_field->getValue();
         }
     } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) {
         return $value["date"] . " " . $value["time"];
     } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN) {
         $return = $value ? 1 : 0;
     } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_TEXT) {
         $arr_properties = $record_field->getField()->getProperties();
         if ($arr_properties[ilDataCollectionField::PROPERTYID_TEXTAREA]) {
             $return = nl2br($value);
         } else {
             $return = $value;
         }
     } else {
         if ($this->id == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) {
             $return = $value == '' ? null : $value;
             //SW, Ilias Mantis #0011799: Return null otherwise '' is casted to 0 in DB
         } else {
             $return = $value;
         }
     }
     return $return;
 }
예제 #16
0
 /**
  * Sets the image file and uploads the image to the object's image directory.
  *
  * @param string $image_filename Name of the original image file
  * @param string $image_tempfilename Name of the temporary uploaded image file
  * @return integer An errorcode if the image upload fails, 0 otherwise
  * @access public
  */
 function setImageFile($image_filename, $image_tempfilename = "")
 {
     $result = 0;
     if (!empty($image_tempfilename)) {
         $image_filename = str_replace(" ", "_", $image_filename);
         $imagepath = $this->getImagePath();
         if (!file_exists($imagepath)) {
             ilUtil::makeDirParents($imagepath);
         }
         //if (!move_uploaded_file($image_tempfilename, $imagepath . $image_filename))
         if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath . $image_filename)) {
             $result = 2;
         } else {
             include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
             $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
             if (!preg_match("/^image/", $mimetype)) {
                 unlink($imagepath . $image_filename);
                 $result = 1;
             } else {
                 // create thumbnail file
                 if ($this->isSingleline && $this->getThumbSize()) {
                     $this->generateThumbForFile($imagepath, $image_filename);
                 }
             }
         }
     }
     return $result;
 }
 public function checkUploads($foundvalues)
 {
     if (is_array($_FILES) && count($_FILES) && $this->getSingleline()) {
         if (!$this->hideImages) {
             if (is_array($_FILES[$this->getPostVar()]['error']['image'])) {
                 foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error) {
                     // error handling
                     if ($error > 0) {
                         switch ($error) {
                             case UPLOAD_ERR_INI_SIZE:
                                 $this->setAlert($this->lng->txt("form_msg_file_size_exceeds"));
                                 return false;
                                 break;
                             case UPLOAD_ERR_FORM_SIZE:
                                 $this->setAlert($this->lng->txt("form_msg_file_size_exceeds"));
                                 return false;
                                 break;
                             case UPLOAD_ERR_PARTIAL:
                                 $this->setAlert($this->lng->txt("form_msg_file_partially_uploaded"));
                                 return false;
                                 break;
                             case UPLOAD_ERR_NO_FILE:
                                 if ($this->getRequired() && !$this->isIgnoreMissingUploadsEnabled()) {
                                     if (!strlen($foundvalues['imagename'][$index]) && !strlen($foundvalues['answer'][$index])) {
                                         $this->setAlert($this->lng->txt("form_msg_file_no_upload"));
                                         return false;
                                     }
                                 }
                                 break;
                             case UPLOAD_ERR_NO_TMP_DIR:
                                 $this->setAlert($this->lng->txt("form_msg_file_missing_tmp_dir"));
                                 return false;
                                 break;
                             case UPLOAD_ERR_CANT_WRITE:
                                 $this->setAlert($this->lng->txt("form_msg_file_cannot_write_to_disk"));
                                 return false;
                                 break;
                             case UPLOAD_ERR_EXTENSION:
                                 $this->setAlert($this->lng->txt("form_msg_file_upload_stopped_ext"));
                                 return false;
                                 break;
                         }
                     }
                 }
             } else {
                 if ($this->getRequired()) {
                     $this->setAlert($this->lng->txt("form_msg_file_no_upload"));
                     return false;
                 }
             }
             if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
                 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
                     $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
                     $filename_arr = pathinfo($filename);
                     $suffix = $filename_arr["extension"];
                     $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
                     $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
                     // check suffixes
                     if (strlen($tmpname) && is_array($this->getSuffixes())) {
                         if (!in_array(strtolower($suffix), $this->getSuffixes())) {
                             $this->setAlert($this->lng->txt("form_msg_file_wrong_file_type"));
                             return false;
                         }
                     }
                 }
             }
             if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
                 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
                     if ($_FILES[$this->getPostVar()]['error']['image'][$index] > 0) {
                         continue;
                     }
                     $mimetype = ilObjMediaObject::getMimeType($tmpname);
                     if (!preg_match("/^image/", $mimetype)) {
                         $_FILES[$this->getPostVar()]['error']['image'][$index] = self::CUSTOM_UPLOAD_ERR;
                         $this->setAlert($this->lng->txt("form_msg_file_wrong_mime_type"));
                         return false;
                     }
                 }
             }
             if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
                 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
                     $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
                     $filename_arr = pathinfo($filename);
                     $suffix = $filename_arr["extension"];
                     $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
                     $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
                     // virus handling
                     if (strlen($tmpname)) {
                         $vir = ilUtil::virusHandling($tmpname, $filename);
                         if ($vir[0] == false) {
                             $_FILES[$this->getPostVar()]['error']['image'][$index] = self::CUSTOM_UPLOAD_ERR;
                             $this->setAlert($this->lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
                             return false;
                         }
                     }
                 }
             }
         }
     }
     return true;
 }