4 require_once(
"Services/Object/classes/class.ilObject2.php");
5 require_once(
'Modules/File/classes/class.ilFSStorageFile.php');
35 public function __construct($a_id = 0, $a_call_by_reference =
true) {
37 $this->raise_upload_error =
true;
41 parent::__construct($a_id,$a_call_by_reference);
83 $this->file_storage->create();
91 require_once(
"./Services/History/classes/class.ilHistory.php");
96 require_once(
"./Services/News/classes/class.ilNewsItem.php");
98 if ($default_visibility ==
"public")
101 1, 0, $this->
getId());
105 include_once(
"./Services/Utilities/classes/class.ilStr.php");
106 $this->log->debug(
"ilObjFile::createProperties, ID: ".$this->
getId().
115 $q =
"INSERT INTO file_data (file_id,file_name,file_type,file_size,version,f_mode) " 116 .
"VALUES (".$ilDB->quote($this->
getId() ,
'integer').
"," 119 .$ilDB->quote((
int) $this->
getFileSize() ,
'integer').
"," 120 .$ilDB->quote(1 ,
'integer').
",".$ilDB->quote($this->
getMode() ,
'text').
")";
121 $res = $ilDB->manipulate($q);
124 if ($this->
getMode() !=
"filelist")
133 $this->no_meta_data_creation = (bool)$a_status;
138 return !(bool)$this->no_meta_data_creation;
143 return !(bool)$this->no_meta_data_creation;
153 $technical = $md_obj->addTechnical();
156 $format = $technical->addFormat();
159 $technical->update();
166 include_once
'Services/MetaData/classes/class.ilMD.php';
168 if(!is_object($md_gen = $md->getGeneral()))
173 $md_gen->setTitle(
$title);
181 include_once
'Services/MetaData/classes/class.ilMD.php';
189 if(!is_object($md_technical = $md->getTechnical()))
194 foreach($md_technical->getFormatIds() as
$id)
196 $md_format = $md_technical->getFormat(
$id);
210 $version_subdir =
"";
215 $version_subdir = sprintf(
"%03d", $a_version);
219 if(!is_object($this->file_storage))
224 return $this->file_storage->getAbsolutePath().
'/'.$version_subdir;
234 $this->raise_upload_error = $a_raise;
237 function getUploadFile($a_upload_file, $a_filename, $a_prevent_preview =
false, $handle_secure_name =
true)
239 if ($handle_secure_name) {
240 require_once(
'./Services/Utilities/classes/class.ilFileUtils.php');
264 if (!$a_prevent_preview)
277 require_once(
"./Services/History/classes/class.ilHistory.php");
281 $a_filename.
",".$this->getVersion()
283 $this->setFilename($a_filename);
295 require_once(
"./Services/History/classes/class.ilHistory.php");
299 $a_filename.
",".$this->getVersion()
301 $this->setFilename($a_filename);
312 function copy($a_source,$a_destination)
335 require_once(
"./Services/History/classes/class.ilHistory.php");
337 if ($a_hist_entry_ids == null || count($a_hist_entry_ids) < 1)
339 $ilDB->manipulate(
"UPDATE file_data SET version = 1 WHERE file_id = ".$ilDB->quote($this->getId() ,
'integer'));
345 self::handleQuotaUpdate($this);
349 $actualVersionDeleted =
false;
355 foreach ($a_hist_entry_ids as $hist_id)
360 foreach ($versions as $index =>
$version)
362 if (
$version[
"hist_entry_id"] == $hist_id)
373 $actualVersionDeleted =
true;
376 unset($versions[$index]);
383 if ($actualVersionDeleted)
392 self::handleQuotaUpdate($this);
404 $q =
"SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($this->
getId() ,
'integer');
405 $r = $this->
ilias->db->query($q);
421 if ($this->
getMode() !=
"filelist")
438 $q =
"UPDATE file_data SET file_name = ".$ilDB->quote($this->
getFileName() ,
'text').
439 ", file_type = ".$ilDB->quote($this->getFiletype() ,
'text').
" ".
440 ", file_size = ".$ilDB->quote((
int) $this->
getFileSize() ,
'integer').
" ".
441 ", version = ".$ilDB->quote($this->
getVersion() ,
'integer').
" ".
442 ", f_mode = ".$ilDB->quote($this->
getMode() ,
'text').
" ".
443 ", rating = ".$ilDB->quote($this->
hasRating() ,
'integer').
" ".
444 "WHERE file_id = ".$ilDB->quote($this->
getId() ,
'integer');
445 $res = $ilDB->manipulate($q);
447 self::handleQuotaUpdate($this);
459 if(!is_object($technical = $md_obj->getTechnical()))
461 $technical = $md_obj->addTechnical();
466 $format_ids = $technical->getFormatIds();
467 if (count($format_ids) > 0)
469 $format = $technical->getFormat($format_ids[0]);
475 $format = $technical->addFormat();
479 $technical->update();
487 $this->filename = $a_name;
510 $this->filesize = $a_size;
515 return $this->filesize;
525 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
533 if (is_null($a_hist_entry_id))
539 require_once(
"./Services/History/classes/class.ilHistory.php");
542 if ($entry ===
false)
556 $this->version = $a_version;
561 return $this->version ? $this->version : 1;
571 $this->mode = $a_mode;
588 $q =
"UPDATE file_data SET ".
589 " file_type = ".$ilDB->quote($a_format ,
'text').
590 " WHERE file_id = ".$ilDB->quote($a_id ,
'integer');
591 $res = $ilDB->manipulate($q);
599 $q =
"SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,
'integer');
600 $r = $ilDB->query($q);
610 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
619 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
628 if (is_null($a_hist_entry_id))
634 require_once(
"./Services/History/classes/class.ilHistory.php");
637 if ($entry ===
false)
651 function sendFile($a_hist_entry_id = null)
653 if (is_null($a_hist_entry_id))
658 if (@!is_file(
$file))
665 require_once(
"./Services/History/classes/class.ilHistory.php");
668 if ($entry ===
false)
670 echo "3";
return false;
677 if (@!is_file(
$file))
688 global $ilClientIniFile;
692 require_once(
'./Services/FileDelivery/classes/class.ilFileDelivery.php');
697 $ilFileDelivery->setConvertFileNameToAsci(
true);
700 if ($ilClientIniFile->readVariable(
'file_access',
'download_with_uploaded_filename') !=
'1' && is_null($a_hist_entry_id)) {
701 $ilFileDelivery->setDownloadFileName($this->
getTitle());
708 $parts = explode(DIRECTORY_SEPARATOR,
$file);
709 $download_file_name = end($parts);
710 $ilFileDelivery->setDownloadFileName($download_file_name);
712 $ilFileDelivery->deliver();
726 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
735 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
742 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
755 $path = pathinfo($a_file);
756 if (
$path[
"extension"] !=
"")
758 $filename =
$path[
"basename"];
762 $filename =
"dummy.".$this->getFileExtension();
764 include_once(
"./Services/Utilities/classes/class.ilMimeTypeUtil.php");
819 $a_new_obj->createDirectory();
826 $query =
"INSERT INTO file_data (file_id,file_name,file_type,file_size,version,rating,f_mode) VALUES (".
827 $ilDB->quote($a_new_obj->getId() ,
'integer').
",".
828 $ilDB->quote($this->getFileName() ,
'text').
",".
829 $ilDB->quote($this->getFileType() ,
'text').
",".
830 $ilDB->quote((
int) $this->getFileSize() ,
'integer').
", ".
831 $ilDB->quote($this->getVersion() ,
'integer').
", ".
832 $ilDB->quote($this->hasRating() ,
'integer').
", ".
833 $ilDB->quote($this->getMode() ,
'text').
")";
834 $res = $ilDB->manipulate($query);
837 require_once(
"./Services/Preview/classes/class.ilPreview.php");
841 require_once(
"./Services/History/classes/class.ilHistory.php");
845 include_once(
'Services/Tracking/classes/class.ilLPObjSettings.php');
847 $obj_settings->cloneSettings($a_new_obj->getId());
848 unset($obj_settings);
851 $a_new_obj->addNewsNotification(
"file_created");
862 if (count($usages) == 0)
874 $q =
"DELETE FROM file_data WHERE file_id = ".$ilDB->quote($this->
getId() ,
'integer');
875 $this->
ilias->db->query($q);
878 require_once(
"./Services/History/classes/class.ilHistory.php");
888 if ($this->
getMode() !=
"filelist")
893 self::handleQuotaUpdate($this);
908 $subdir =
"il_".IL_INST_ID.
"_file_".$this->
getId();
913 if (@!is_dir($filedir))
928 $and_hist = ($a_usage_hist_nr !==
false)
929 ?
" AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr,
"integer")
933 $set = $ilDB->query(
"SELECT id FROM file_usage".
934 " WHERE usage_type = ".$ilDB->quote(
$a_type,
"text").
935 " AND usage_id= ".$ilDB->quote($a_id,
"integer").
936 " AND usage_lang= ".$ilDB->quote($a_usage_lang,
"text").
938 while(
$row = $ilDB->fetchAssoc($set))
940 $file_ids[] =
$row[
"id"];
943 $ilDB->manipulate(
"DELETE FROM file_usage WHERE usage_type = ".
945 " AND usage_id = ".$ilDB->quote((
int) $a_id,
"integer").
946 " AND usage_lang= ".$ilDB->quote($a_usage_lang,
"text").
947 " AND usage_hist_nr = ".$ilDB->quote((
int) $a_usage_hist_nr,
"integer"));
949 foreach($file_ids as $file_id)
951 self::handleQuotaUpdate(
new self($file_id,
false));
958 static function _saveUsage($a_file_id,
$a_type, $a_id, $a_usage_hist_nr = 0, $a_usage_lang =
"-")
968 $ilDB->replace(
"file_usage",
970 "id" =>
array(
"integer", (
int) $a_file_id),
972 "usage_id" =>
array(
"integer", (
int) $a_id),
973 "usage_hist_nr" =>
array(
"integer", (
int) $a_usage_hist_nr),
974 "usage_lang" =>
array(
"text", $a_usage_lang)
979 self::handleQuotaUpdate(
new self($a_file_id,
false));
990 $q =
"SELECT * FROM file_usage WHERE id = ".$ilDB->quote($this->
getId(),
"integer");
991 $us_set = $ilDB->query($q);
993 while($us_rec = $ilDB->fetchAssoc($us_set))
995 $ret[] =
array(
"type" => $us_rec[
"usage_type"],
996 "id" => $us_rec[
"usage_id"],
997 "lang" => $us_rec[
"usage_lang"],
998 "hist_nr" => $us_rec[
"usage_hist_nr"]);
1017 if ($a_usage_lang !=
"")
1019 $lstr =
"usage_lang = ".$ilDB->quote((
string) $a_usage_lang,
"text").
" AND ";
1023 $q =
"SELECT * FROM file_usage WHERE ".
1024 "usage_id = ".$ilDB->quote((
int) $a_id,
"integer").
" AND ".
1025 "usage_type = ".$ilDB->quote((
string)
$a_type,
"text").
" AND ".
1027 "usage_hist_nr = ".$ilDB->quote((
int) $a_usage_hist_nr,
"integer");
1028 $file_set = $ilDB->query($q);
1030 while($file_rec = $ilDB->fetchAssoc($file_set))
1032 $ret[$file_rec[
"id"]] = $file_rec[
"id"];
1062 include_once(
"./Services/News/classes/class.ilNewsItem.php");
1063 include_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
1065 $news_item->setContext($this->
getId(), $this->
getType());
1067 $news_item->setTitle($a_lang_var);
1068 $news_item->setContentIsLangVar(
true);
1071 $news_item->setContent(
1075 $news_item->setUserId($ilUser->getId());
1077 $news_item->create();
1102 if($this->version) {
1112 require_once(
'./Services/Utilities/classes/class.ilFileUtils.php');
1127 $version_subdir =
"";
1129 if (!is_numeric($a_version))
1133 $version_subdir = DIRECTORY_SEPARATOR.sprintf(
"%03d", $a_version);
1134 return $file_storage->getAbsolutePath().$version_subdir.DIRECTORY_SEPARATOR.$filename;
1143 include_once
'./Modules/File/classes/class.ilObjFileAccess.php';
1146 if ($titleExtension != $fileExtension && strlen($fileExtension) > 0)
1150 $suffix = $pi[
"extension"];
1153 if (substr($new_title,
1154 strlen($new_title) - strlen($suffix) - 1)
1157 $new_title = substr($new_title, 0, strlen($new_title) - strlen($suffix) - 1);
1160 $new_title .=
'.'.$fileExtension;
1173 include_once(
"./Services/History/classes/class.ilHistory.php");
1176 if ($version_ids != null && count($version_ids) > 0)
1178 foreach ($versions as $index =>
$version)
1180 if (!in_array(
$version[
"hist_entry_id"], $version_ids,
true))
1182 unset($versions[$index]);
1188 foreach ($versions as $index =>
$version)
1195 usort($versions,
array($this,
"compareVersions"));
1208 include_once(
"./Services/History/classes/class.ilHistory.php");
1236 if ($source ===
false)
1238 $this->ilErr->raiseError($this->lng->txt(
"obj_not_found"), $this->ilErr->MESSAGE);
1245 $source_path = $this->
getDirectory($source[
"version"]) .
"/" . $source[
"filename"];
1247 if (@!is_dir($dest_dir))
1250 copy($source_path, $dest_dir .
"/" . $source[
"filename"]);
1253 include_once(
"./Services/History/classes/class.ilHistory.php");
1257 $source[
"filename"] .
"," . $new_version_nr .
"|" . $source[
"version"] .
"|" . $ilUser->getId());
1270 return $new_version;
1309 return (
int)$v2[
"version"] - (int)$v1[
"version"];
1320 $data = preg_split(
"/(.*),(.*)/", $entry[
"info_params"], 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
1324 if (empty(
$data[1]))
1327 $result =
array(
"filename" =>
$data[0],
"version" =>
$data[1],
"rollback_version" =>
"",
"rollback_user_id" =>
"");
1330 if ($entry[
"action"] ==
"rollback")
1332 $tokens = explode(
"|",
$result[
"version"]);
1333 if (count($tokens) > 1)
1335 $result[
"version"] = $tokens[0];
1336 $result[
"rollback_version"] = $tokens[1];
1338 if (count($tokens) > 2)
1339 $result[
"rollback_user_id"] = $tokens[2];
1348 include_once
"Services/MediaObjects/classes/class.ilObjMediaObject.php";
1356 $parent_obj_id = $mob->getParentObjectIdForUsage($item);
1357 if($parent_obj_id &&
1358 !in_array($parent_obj_id, $parent_obj_ids))
1360 $parent_obj_ids[]= $parent_obj_id;
1364 include_once
"Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1379 if ($this->
getMode() !=
"object")
1382 require_once(
"./Services/Preview/classes/class.ilPreview.php");
1392 if ($this->
getMode() !=
"object")
1395 require_once(
"./Services/Preview/classes/class.ilPreview.php");
1401 $this->rating = (bool)$a_value;
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static _writeFileType($a_id, $a_format)
createProperties($a_upload=false)
The basic properties of a file object are stored in table object_data.
static _lookupDiskUsage($a_id)
Returns the number of bytes used on the harddisk by the file object with the specified object id...
static _removeEntryByHistoryID($a_hist_entry_id)
Removes a single entry from the history.
static _isFileInline($a_file_name)
Returns true, if the specified file shall be displayed inline in the browser.
parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
setFileName($a_name)
set filename
static _changeUserId($a_hist_entry_id, $new_user_id)
Changes the user id of the specified history entry.
setMode($a_mode)
mode is object or filelist
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
copy($a_source, $a_destination)
copy file
static _isFileHidden($a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user. ...
static _getFileExtension($a_file_name)
Gets the file extension of the specified file name.
clearDataDirectory()
clear data directory
compareVersions($v1, $v2)
Compares two file versions.
getFile($a_hist_entry_id=null)
getMode()
mode is object or filelist
storeUnzipedFile($a_upload_file, $a_filename)
storeUnzipedFile
static _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
static delete all usages of
doCreateMetaData()
create file object meta data
getDirectory($a_version=0)
setNoMetaDataCreation($a_status)
doCreate($a_upload=false)
create object
static _getEntryByHistoryID($a_hist_entry_id)
returns a single history entry
beforeMDUpdateListener($a_element)
checkFileExtension($new_filename, $new_title)
Check if the file extension does still exist after an update of the title.
static _lookupFileSize($a_id)
Quickly looks up the file size from the database and returns the number of bytes. ...
doUpdateMetaData()
update meta data
static rename($a_source, $a_target)
Rename a file.
replaceFile($a_upload_file, $a_filename)
replace file with new file
static getMimeType($a_file='', $a_filename='', $a_mime='')
doRead()
read file properties
static _copyEntriesForObject($a_src_id, $a_dst_id)
copy all history entries for an object
static _lookupFileName($a_id)
static getBytesForString($a_str)
Return string as byte array Note: Use this for debugging purposes only.
addFileVersion($a_upload_file, $a_filename)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static createPreview($a_obj, $a_force=false)
Creates the preview for the object with the specified id.
deletePreview()
Deletes the preview of the file object.
isHidden()
Returns true, if this file should be hidden in the repository view.
redirection script todo: (a better solution should control the processing via a xml file) ...
static _saveUsage($a_file_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
save usage
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
isInline()
Returns true, if this file should be displayed inline in a browser window.
static _createEntry($a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
createPreview($force=false)
Creates a preview for the file object.
getSpecificVersion($version_id)
Gets a specific file version.
static _getFilesOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
get all files of an object
static _getEntriesForObject($a_obj_id, $a_obj_type="")
get all history entries for an object
addNewsNotification($a_lang_var)
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
getUsages()
get all usages of file object
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
doCloneObject($a_new_obj, $a_target_id, $a_copy_id=0)
Clone.
static copyPreviews($a_src_id, $a_dest_id)
Copies the preview images from one preview to a new preview object.
deleteVersions($a_hist_entry_ids=null)
Deletes the specified history entries or all entries if no ids are specified.
static _lookupFileSize($a_id)
Lookups the file size of the file in bytes.
getFileExtension()
Returns the extension of the file name converted to lower-case.
static handleQuotaUpdate(ilObjFile $a_file)
rollback($version_id)
Makes the specified version the current one and returns theSummary of rollbackVersion.
export($a_target_dir)
export files of object to target directory note: target directory must be the export target directory...
static _lookupVersion($a_id)
lookup version
static escapeShellArg($a_arg)
initFileStorage()
init file storage object
static handleUpdatedSourceObject($a_src_obj_type, $a_src_obj_id, $a_src_filesize, $a_owner_obj_ids=null, $a_is_prtf=false)
Find and update/create all related entries for source object.
static deletePreview($a_obj_id)
Deletes the preview for the object with the specified id.
getUploadFile($a_upload_file, $a_filename, $a_prevent_preview=false, $handle_secure_name=true)
static _lookupAbsolutePath($obj_id, $a_version=null)
return absolute path for version
static _getDefaultVisibilityForRefId($a_ref_id)
Get default visibility for reference id.
static _removeEntriesForObject($a_obj_id)
remove all history entries for an object
Class ilObject2 This is an intermediate progress of ilObject class.
static getLogger($a_component_id)
Get component logger.
raiseUploadError($a_raise=true)
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
doMDUpdateListener($a_element)
static _lookupVersion($a_id)
lookup version
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
determineFileSize($a_hist_entry_id=null)
Determine File Size.
__construct($a_id=0, $a_call_by_reference=true)
ilObjFile constructor.
getVersions($version_ids=null)
Gets the file versions for this object.
static getValidFilename($a_filename)
Get valid filename.
guessFileType($a_file="")
Guesses the file type based on the current values returned by getFileType() and getFileExtension().
updateWithVersion($version)
Updates the file object with the specified file version.
cloneMetaData($target_obj)
getDiskUsage()
Gets the disk usage of the object in bytes.