md_document.php 6.2 KB

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