4 require_once
"Services/Object/classes/class.ilObject2.php";
5 require_once
"Modules/Bibliographic/classes/class.ilBibliographicEntry.php";
69 if ($existant_bibl_id) {
70 $this->
setId($existant_bibl_id);
84 $ilDB->manipulate(
"INSERT INTO il_bibl_data " .
"(id, filename, is_online) VALUES (" . $ilDB->quote($this->getId(),
"integer") .
"," .
85 $ilDB->quote($this->getFilename(),
"text") .
"," .
86 $ilDB->quote($this->getOnline(),
"integer") .
93 $set = $ilDB->query(
"SELECT * FROM il_bibl_data " .
" WHERE id = " . $ilDB->quote($this->getId(),
"integer"));
94 while ($rec = $ilDB->fetchAssoc($set)) {
108 if (! empty($_FILES[
'bibliographic_file'][
'name'])) {
114 $ilDB->manipulate(
"UPDATE il_bibl_data SET " .
"filename = " . $ilDB->quote($this->getFilename(),
"text") .
", " .
115 "is_online = " . $ilDB->quote($this->getOnline(),
"integer") .
116 " WHERE id = " . $ilDB->quote($this->getId(),
"integer"));
125 protected function doDelete($leave_out_il_bibl_data =
false, $leave_out_delete_file =
false) {
127 if (! $leave_out_delete_file) {
131 $ilDB->manipulate(
"DELETE FROM il_bibl_attribute WHERE il_bibl_attribute.entry_id IN "
132 .
"(SELECT il_bibl_entry.id FROM il_bibl_entry WHERE il_bibl_entry.data_id = " . $ilDB->quote($this->getId(),
"integer") .
");");
134 $ilDB->manipulate(
"DELETE FROM il_bibl_entry WHERE data_id = " . $ilDB->quote($this->getId(),
"integer"));
135 if (! $leave_out_il_bibl_data) {
137 $ilDB->manipulate(
"DELETE FROM il_bibl_data WHERE id = " . $ilDB->quote($this->getId(),
"integer"));
140 require_once(
"./Services/History/classes/class.ilHistory.php");
160 if (! is_dir($target_dir)) {
163 if ($_FILES[
'bibliographic_file'][
'name']) {
164 $filename = $_FILES[
'bibliographic_file'][
'name'];
165 } elseif ($file_to_copy) {
167 $split_path = explode(DIRECTORY_SEPARATOR, $file_to_copy);
168 $filename = $split_path[
sizeof($split_path) - 1];
170 throw new Exception(
"Either a file must be delivered via \$_POST/\$_FILE or the file must be delivered via the method argument file_to_copy");
172 $target_full_filename = $target_dir . DIRECTORY_SEPARATOR .
$filename;
175 if (@! copy($file_to_copy, $target_full_filename)) {
176 if (! empty($_FILES[
'bibliographic_file'][
'tmp_name'])) {
177 ilUtil::moveUploadedFile($_FILES[
'bibliographic_file'][
'tmp_name'], $_FILES[
'bibliographic_file'][
'name'], $target_full_filename);
179 throw new Exception(
"The file delivered via the method argument file_to_copy could not be copied. The file '{$file_to_copy}' does probably not exist.");
200 $set = $ilDB->query(
"SELECT filename FROM il_bibl_data " .
" WHERE id = " . $ilDB->quote($this->getId(),
"integer"));
201 $rec = $ilDB->fetchAssoc($set);
203 if ($without_filename) {
204 return substr($rec[
'filename'], 0, strrpos($rec[
'filename'], DIRECTORY_SEPARATOR));
206 return $rec[
'filename'];
238 if (strtolower(substr($this->
getFilename(), - 6)) ==
"bibtex") {
243 return strtolower(substr($this->
getFilename(), - 3));
253 $set = $ilDB->query(
'SELECT * FROM il_bibl_overview_model');
254 while ($rec = $ilDB->fetchAssoc($set)) {
255 if ($rec[
'literature_type']) {
256 $overviewModels[$rec[
'filetype']][$rec[
'literature_type']] = $rec[
'pattern'];
274 if (! file_exists(
$path)) {
278 return unlink(
$path);
281 $path = rtrim(
$path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
284 foreach ($dir as
$file) {
285 if (! $file->isDot()) {
304 require_once
"./Modules/Bibliographic/lib/LibRIS/src/LibRIS/RISReader.php";
306 $ris_reader->parseFile($full_filename);
308 return $ris_reader->getRecords();
319 require_once
'Modules/Bibliographic/lib/PEAR_BibTex_1.0.0RC5/Structures/BibTex.php';
322 $bibtex_reader->loadFile($full_filename);
325 $bibtex_reader->setOption(
'extractAuthor',
false);
326 $bibtex_reader->parse();
333 foreach ($bibtex_reader->data as $key => $entry) {
334 if (empty($entry[
'cite'])) {
335 unset($bibtex_reader->data[$key][
'cite']);
336 foreach ($entry as $attr_key => $attribute) {
337 if (strpos($attr_key,
'{') !==
false) {
338 unset($bibtex_reader->data[$key][$attr_key]);
339 $attr_key_exploaded = explode(
'{', $attr_key);
340 $bibtex_reader->data[$key][
'entryType'] = trim($attr_key_exploaded[0]);
341 $bibtex_reader->data[$key][trim($attr_key_exploaded[1])] = $attribute;
347 foreach ($entry as $attr_key => $attribute) {
348 if ($attr_key ==
'author' && is_array($attribute)) {
349 $attribute_string = array();
350 foreach ($attribute as $author_key => $author) {
351 $lastname = array( $author[
'von'], $author[
'last'], $author[
'jr'] );
352 $attribute_string[$author_key] = implode(
' ', array_filter($lastname));
353 if (! empty($author[
'first'])) {
354 $attribute_string[$author_key] .=
', ' . $author[
'first'];
357 $bibtex_reader->data[$key][$attr_key] = implode(
' / ', $attribute_string);
362 return $bibtex_reader->data;
371 $filedata = file_get_contents($full_filename);
372 if (strlen($filedata) == strlen(utf8_decode($filedata))) {
374 $filedata = mb_convert_encoding($filedata,
'UTF-8',
'ISO-8859-1');
375 file_put_contents($full_filename, $filedata);
389 $bibtex_special_chars[
'ä'] =
'{\"a}';
390 $bibtex_special_chars[
'ë'] =
'{\"e}';
391 $bibtex_special_chars[
'ï'] =
'{\"i}';
392 $bibtex_special_chars[
'ö'] =
'{\"o}';
393 $bibtex_special_chars[
'ü'] =
'{\"u}';
394 $bibtex_special_chars[
'Ä'] =
'{\"A}';
395 $bibtex_special_chars[
'Ë'] =
'{\"E}';
396 $bibtex_special_chars[
'Ï'] =
'{\"I}';
397 $bibtex_special_chars[
'Ö'] =
'{\"O}';
398 $bibtex_special_chars[
'Ü'] =
'{\"U}';
399 $bibtex_special_chars[
'â'] =
'{\^a}';
400 $bibtex_special_chars[
'ê'] =
'{\^e}';
401 $bibtex_special_chars[
'î'] =
'{\^i}';
402 $bibtex_special_chars[
'ô'] =
'{\^o}';
403 $bibtex_special_chars[
'û'] =
'{\^u}';
404 $bibtex_special_chars[
'Â'] =
'{\^A}';
405 $bibtex_special_chars[
'Ê'] =
'{\^E}';
406 $bibtex_special_chars[
'Î'] =
'{\^I}';
407 $bibtex_special_chars[
'Ô'] =
'{\^O}';
408 $bibtex_special_chars[
'Û'] =
'{\^U}';
409 $bibtex_special_chars[
'à'] =
'{\`a}';
410 $bibtex_special_chars[
'è'] =
'{\`e}';
411 $bibtex_special_chars[
'ì'] =
'{\`i}';
412 $bibtex_special_chars[
'ò'] =
'{\`o}';
413 $bibtex_special_chars[
'ù'] =
'{\`u}';
414 $bibtex_special_chars[
'À'] =
'{\`A}';
415 $bibtex_special_chars[
'È'] =
'{\`E}';
416 $bibtex_special_chars[
'Ì'] =
'{\`I}';
417 $bibtex_special_chars[
'Ò'] =
'{\`O}';
418 $bibtex_special_chars[
'Ù'] =
'{\`U}';
419 $bibtex_special_chars[
'á'] =
'{\\\'a}';
420 $bibtex_special_chars[
'é'] =
'{\\\'e}';
421 $bibtex_special_chars[
'í'] =
'{\\\'i}';
422 $bibtex_special_chars[
'ó'] =
'{\\\'o}';
423 $bibtex_special_chars[
'ú'] =
'{\\\'u}';
424 $bibtex_special_chars[
'Á'] =
'{\\\'A}';
425 $bibtex_special_chars[
'É'] =
'{\\\'E}';
426 $bibtex_special_chars[
'Í'] =
'{\\\'I}';
427 $bibtex_special_chars[
'Ó'] =
'{\\\'O}';
428 $bibtex_special_chars[
'Ú'] =
'{\\\'U}';
429 $bibtex_special_chars[
'à'] =
'{\`a}';
430 $bibtex_special_chars[
'è'] =
'{\`e}';
431 $bibtex_special_chars[
'ì'] =
'{\`i}';
432 $bibtex_special_chars[
'ò'] =
'{\`o}';
433 $bibtex_special_chars[
'ù'] =
'{\`u}';
434 $bibtex_special_chars[
'À'] =
'{\`A}';
435 $bibtex_special_chars[
'È'] =
'{\`E}';
436 $bibtex_special_chars[
'Ì'] =
'{\`I}';
437 $bibtex_special_chars[
'Ò'] =
'{\`O}';
438 $bibtex_special_chars[
'Ù'] =
'{\`U}';
439 $bibtex_special_chars[
'ç'] =
'{\c c}';
440 $bibtex_special_chars[
'ß'] =
'{\ss}';
441 $bibtex_special_chars[
'ñ'] =
'{\~n}';
442 $bibtex_special_chars[
'Ñ'] =
'{\~N}';
444 return str_replace($bibtex_special_chars, array_keys($bibtex_special_chars), $file_content);
463 if(!$cp_options->isRootNode($this->getRefId()))
483 $this->
moveFile($original->getFileAbsolutePath());
485 $this->
setTitle($original->getTitle());
486 $this->
setType($original->getType());
498 for ($i = 0; $i < strlen($input); $i ++) {
499 if ($input[$i] !=
" " && $input[$i] !=
"-") {
500 return substr($input, $i);
513 $entries_from_file = array();
523 foreach ($entries_from_file as $file_entry) {
526 $parsed_entry = array();
527 foreach ($file_entry as $key => $attribute) {
529 if (is_array($attribute)) {
530 $attribute = implode(
", ", $attribute);
534 if (
ilStr::strLen($attribute) > self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH) {
536 $attribute =
ilStr::subStr($attribute, 0, self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH - 3) .
'...';
539 if (strtolower($key) ==
'ty' || strtolower($key) ==
'entrytype') {
545 $parsed_entry[$x][
'name'] = $key;
546 $parsed_entry[$x ++][
'value'] = $attribute;
550 $entry_model->setType(
$type);
551 $entry_model->setAttributes($parsed_entry);
552 $entry_model->setBibliographicObjId($this->
getId());
553 $entry_model->doCreate();
562 $this->is_online = $a_online;