md_document.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * md_document.php for Dokeos metadata/*.php
  4. * 2005/09/20
  5. * Copyright 2005 rene.haentjens@UGent.be - see metadata/md_funcs.php -->
  6. * @package chamilo.metadata
  7. */
  8. /**
  9. * Chamilo Metadata: class mdobject for Document-type items
  10. * @package chamilo.metadata
  11. */
  12. class mdobject {
  13. var $mdo_course;
  14. var $mdo_type;
  15. var $mdo_id;
  16. var $mdo_eid;
  17. var $mdo_dcmap_e;
  18. var $mdo_dcmap_v;
  19. var $mdo_path;
  20. var $mdo_title;
  21. var $mdo_comment;
  22. var $mdo_filetype;
  23. var $mdo_group;
  24. var $mdo_url;
  25. function mdo_define_htt() { return new xhtdoc(<<<EOD
  26. <!-- {-INDEXABLETEXT-} -->
  27. {-V metadata/lom/general/title/string-} txt-sep
  28. {-R metadata/lom/general/keyword C KWTEXT-} txt-sep
  29. {-V metadata/lom/general/description[1]/string-} txt-end
  30. document-type
  31. {-V metadata/lom/lifeCycle/contribute[1]/entity-}
  32. {-V metadata/lom/lifeCycle/contribute[1]/date/dateTime-}
  33. {-V metadata/lom/technical/format-}
  34. <!-- {-KWTEXT-} -->
  35. {-V string-}-kw
  36. <!-- {--} -->
  37. EOD
  38. );
  39. }
  40. function mdo_generate_default_xml_metadata()
  41. {
  42. global $iso639_2_code, $ieee_xml;
  43. $xhtDoc = new xhtdoc($ieee_xml); $_user = api_get_user_info();
  44. if ($xhtDoc->htt_error)
  45. give_up('IEEE XML (metadata/md_funcs): ' . $xhtDoc->htt_error);
  46. $xhtDoc->xht_get_lang = 'get_lang'; $xhtDoc->xht_xmldoc = new xmddoc('');
  47. if ($xhtDoc->xht_xmldoc->error) give_up($xhtDoc->xht_xmldoc->error);
  48. $xhtDoc->xht_param['siteUri'] = make_uri();
  49. $xhtDoc->xht_param['entry'] = $this->mdo_course['sysCode'] .
  50. '.Document.' . $this->mdo_id; // 2005-05-30: path->sysCode
  51. $xhtDoc->xht_param['location'] = api_get_path(WEB_PATH) .
  52. 'main/metadata/openobject.php?cidReq=' .
  53. urlencode($this->mdo_course['sysCode']) . '&eid=' .
  54. urlencode($this->mdo_eid);
  55. $xhtDoc->xht_param['mdlang'] = strtolower($iso639_2_code);
  56. $xhtDoc->xht_param['lang'] = strtolower($iso639_2_code);
  57. $xhtDoc->xht_param['title'] =
  58. $this->mdo_title ? $this->mdo_title :
  59. ($this->mdo_path ? $this->mdo_path : get_lang('MdTitle', ''));
  60. $xhtDoc->xht_param['description'] =
  61. $this->mdo_comment ? $this->mdo_comment : get_lang('MdDescription', '');
  62. $xhtDoc->xht_param['coverage'] = get_lang('MdCoverage', '');
  63. if (isset($_user))
  64. {
  65. $xhtDoc->xht_param['author'] = "BEGIN:VCARD\\nFN:" .
  66. api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS) .
  67. "\\nEMAIL:".$_user['mail'] . "\\nEND:VCARD\\n";
  68. }
  69. $xhtDoc->xht_param['dateTime'] = date('Y-m-d');
  70. if ($this->mdo_filetype == 'folder') $format = "inode/directory";
  71. else
  72. {
  73. require_once(api_get_path(LIBRARY_PATH) . 'document.lib.php');
  74. $format = DocumentManager::file_get_mime_type($this->mdo_path);
  75. }
  76. $xhtDoc->xht_param['format'] = $format;
  77. $xhtDoc->xht_param['size'] = (($s = filesize(get_course_path() .
  78. $this->mdo_course['path'] . '/document' . $this->mdo_path))) ? $s : '0';
  79. return $xhtDoc->xht_fill_template('XML');
  80. }
  81. function mdo_add_breadcrump_nav()
  82. {
  83. global $interbreadcrumb, $langFormats;
  84. $regs = array(); // for use with ereg()
  85. $docurl = api_get_self(); // should be .../main/xxx/yyy.php
  86. if (ereg('^(.+[^/\.]+)/[^/\.]+/[^/\.]+.[^/\.]+$', $docurl, $regs))
  87. $docurl = $regs[1] . '/document/document.php';
  88. $interbreadcrumb[]= array ('url' => $docurl,
  89. "name"=> get_lang('MdCallingTool'));
  90. if (($docpath = $this->mdo_path))
  91. {
  92. $docpath = substr($docpath, 0, strrpos($docpath, '/'));
  93. if (strlen($docpath) > 1) $interbreadcrumb[]= array ('url' =>
  94. $docurl . '?curdirpath=' . urlencode($docpath) .
  95. ($this->mdo_group ? '&gidReq=' . $this->mdo_group : ''), "name" =>
  96. htmlspecialchars(substr($docpath, strrpos($docpath, '/') + 1)));
  97. }
  98. // Complete assoclist $langFormats from mime types
  99. require_once(api_get_path(LIBRARY_PATH) . 'xht.lib.php');
  100. require_once(api_get_path(LIBRARY_PATH) . 'document.lib.php');
  101. $sep = $langFormats{0} ? $langFormats{0} : ":";
  102. $arrFormats = xht_explode_assoclist($langFormats);
  103. foreach (DocumentManager::file_get_mime_type(TRUE) as $format)
  104. if (!isset($arrFormats[$format]))
  105. $langFormats .= ",, " . $format . $sep . $format;
  106. if (!isset($arrFormats["inode/directory"]))
  107. $langFormats .= ",, inode/directory" . $sep . "inode/directory";
  108. if (substr($langFormats, 0, 3) == ",, ")
  109. $langFormats = $sep . substr($langFormats, 3);
  110. }
  111. function mdobject($_course, $id) {
  112. global $ieee_dcmap_e, $ieee_dcmap_v; // md_funcs
  113. $course_id = api_get_course_int_id();
  114. $this->mdo_course = $_course; $this->mdo_type = 'Document';
  115. $this->mdo_id = $id; $this->mdo_eid = $this->mdo_type . '.' . $id;
  116. $this->mdo_dcmap_e = $ieee_dcmap_e; $this->mdo_dcmap_v = $ieee_dcmap_v;
  117. $document_table = Database::get_course_table(TABLE_DOCUMENT);
  118. $sql = "SELECT path,title,comment,filetype FROM $document_table WHERE c_id = $course_id AND id='" .intval($id) . "'";
  119. if (($docinfo = Database::fetch_array(Database::query($sql)))) {
  120. $this->mdo_path = $docinfo['path'];
  121. $this->mdo_title = $docinfo['title'];
  122. $this->mdo_comment = $docinfo['comment'];
  123. $this->mdo_filetype = $docinfo['filetype'];
  124. $this->mdo_group = ''; // 2005-05-30: find group_id, if any
  125. $group_info = Database::get_course_table(TABLE_GROUP);
  126. $sql = "SELECT id,secret_directory FROM $group_info WHERE c_id = $course_id";
  127. if (($result = Database::query($sql)))
  128. while (($row = Database::fetch_array($result)))
  129. if (($secdir = $row['secret_directory'] . '/') ==
  130. substr($this->mdo_path, 0, strlen($secdir)))
  131. {
  132. $this->mdo_group = $row['id']; break;
  133. }
  134. // 2005-05-30: use direct URL
  135. $this->mdo_url = api_get_path(WEB_COURSE_PATH) . $_course['path'] .
  136. '/document' . str_replace('%2F', '/', urlencode($this->mdo_path)) .
  137. ($this->mdo_group ? '?gidReq=' . $this->mdo_group : '');
  138. }
  139. }
  140. }
  141. ?>