md_link.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php /* <!-- md_link.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 Link-type objects
  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_url;
  21. var $mdo_title;
  22. var $mdo_description;
  23. var $mdo_category;
  24. var $mdo_category_title;
  25. function mdo_define_htt() { return new xhtdoc(<<<EOD
  26. <!-- {-INDEXABLETEXT-} -->
  27. Title: {-V metadata/lom/general/title/string-} txt-sep
  28. Keyword(s): {-R metadata/lom/general/keyword C KWTEXT-} txt-sep
  29. Category: {-V metadata/lom/general/coverage/string-}
  30. {-V metadata/lom/general/description[1]/string-} txt-end
  31. link-type
  32. {-V metadata/lom/lifeCycle/contribute[1]/entity-}
  33. {-V metadata/lom/lifeCycle/contribute[1]/date/dateTime-}
  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. '.Link.' . $this->mdo_id; // 2005-05-30: path->sysCode
  51. $xhtDoc->xht_param['location'] = $this->mdo_url . '';
  52. $xhtDoc->xht_param['mdlang'] = strtolower($iso639_2_code);
  53. $xhtDoc->xht_param['lang'] = strtolower($iso639_2_code);
  54. $xhtDoc->xht_param['title'] =
  55. $this->mdo_title ? $this->mdo_title : get_lang('MdTitle');
  56. if (($d = $this->mdo_description))
  57. {
  58. if ($keywords = $this->_find_keywords($d)) $d = array_pop($keywords);
  59. $xhtDoc->xht_param['description'] = $d;
  60. }
  61. else
  62. $xhtDoc->xht_param['description'] = get_lang('MdDescription');
  63. $xhtDoc->xht_param['coverage'] = $this->mdo_category_title ?
  64. $this->mdo_category_title : get_lang('MdCoverage');
  65. if (isset($_user))
  66. {
  67. $xhtDoc->xht_param['author'] = "BEGIN:VCARD\\nFN:" .
  68. $_user['firstName']." ".$_user['lastName'] .
  69. "\\nEMAIL:".$_user['mail'] . "\\nEND:VCARD\\n";
  70. }
  71. $xhtDoc->xht_param['dateTime'] = date('Y-m-d');
  72. $xhtDoc->xht_param['format'] = ''; $xhtDoc->xht_param['size'] = '0';
  73. if (count($keywords))
  74. {
  75. $xd = new xmddoc(explode("\n",
  76. $mdt = $xhtDoc->xht_fill_template('XML')));
  77. if ($xd->error) return $mdt; // and worry later
  78. $this->_add_keywords($xd, $keywords);
  79. return $xd->xmd_xml();
  80. }
  81. return $xhtDoc->xht_fill_template('XML');
  82. }
  83. function mdo_override(&$xmlDoc) // by ref!
  84. {
  85. if ($this->mdo_url)
  86. {
  87. $xmlDoc->xmd_update('metadata/lom/technical/location', $this->mdo_url);
  88. $ge = $xmlDoc->xmd_select_single_element("metadata/lom/general");
  89. $xmlDoc->xmd_update('title[1]/string', $this->mdo_title, $ge);
  90. $xmlDoc->xmd_update('coverage[1]/string', $this->mdo_category_title, $ge);
  91. if (($d = $this->mdo_description))
  92. if ($keywords = $this->_find_keywords($d)) $d = array_pop($keywords);
  93. $xmlDoc->xmd_update('description[1]/string', $d, $ge);
  94. $xmlDoc->xmd_remove_nodes($xmlDoc->xmd_select_elements('keyword', $ge), $ge);
  95. if (count($keywords)) $this->_add_keywords($xmlDoc, $keywords);
  96. }
  97. return $xmlDoc->xmd_xml();
  98. }
  99. function mdo_storeback(&$xmlDoc) // by ref!
  100. {
  101. if (!$this->mdo_url) return; // no record in link table, most probably
  102. if (!($v = $xmlDoc->xmd_value('metadata/lom/technical/location'))) return;
  103. if ($v != $this->mdo_url)
  104. { $this->mdo_url = $v; $u .= ", url = '" . addslashes($v) . "'"; }
  105. $ge = $xmlDoc->xmd_select_single_element("metadata/lom/general");
  106. $v = $xmlDoc->xmd_value('title[1]/string', $ge);
  107. if ($v != $this->mdo_title)
  108. { $this->mdo_title = $v; $u .= ", title = '" . addslashes($v) . "'"; }
  109. $vd = $xmlDoc->xmd_value('description[1]/string', $ge);
  110. $vk = $xmlDoc->xmd_value('keyword/string', $ge, array('in' => ', '));
  111. $v = $vk ? '<i kw="' . htmlspecialchars($vk) . '">' .
  112. ereg_replace('\[((/?(b|big|i|small|sub|sup|u))|br/)\]', '<\\1>',
  113. htmlspecialchars($vd)) . '</i>' : $vd;
  114. if ($v != $this->mdo_description)
  115. {
  116. $this->mdo_description = $v;
  117. $u .= ", description = '" . addslashes($v) . "'";
  118. }
  119. // do not store back a modified coverage as category...
  120. $link_table = Database::get_course_table(TABLE_LINK);
  121. if ($u) api_sql_query("UPDATE $link_table SET " . substr($u, 2) .
  122. " WHERE id='" . addslashes($this->mdo_id) . "'", __FILE__, __LINE__);
  123. }
  124. function mdo_add_breadcrump_nav()
  125. {
  126. global $interbreadcrumb;
  127. $regs = array(); // for use with ereg()
  128. $docurl = $_SERVER['PHP_SELF']; // should be .../main/xxx/yyy.php
  129. if (ereg('^(.+[^/\.]+)/[^/\.]+/[^/\.]+.[^/\.]+$', $docurl, $regs))
  130. $docurl = $regs[1] . '/link/link.php';
  131. $interbreadcrumb[]= array ('url' => $docurl,
  132. "name"=> get_lang('MdCallingTool'));
  133. }
  134. function mdobject($_course, $id)
  135. {
  136. global $ieee_dcmap_e, $ieee_dcmap_v; // md_funcs
  137. $this->mdo_course = $_course; $this->mdo_type = 'Link';
  138. $this->mdo_id = $id; $this->mdo_eid = $this->mdo_type . '.' . $id;
  139. $this->mdo_dcmap_e = $ieee_dcmap_e; $this->mdo_dcmap_v = $ieee_dcmap_v;
  140. $link_table = Database::get_course_table(TABLE_LINK);
  141. if (($linkinfo = @mysql_fetch_array(api_sql_query(
  142. "SELECT url,title,description,category_id FROM $link_table WHERE id='" .
  143. addslashes($id) . "'", __FILE__, __LINE__))))
  144. {
  145. $this->mdo_url = $linkinfo['url'];
  146. $this->mdo_title = $linkinfo['title'];
  147. $this->mdo_description = $linkinfo['description'];
  148. $this->mdo_category = ($lci = $linkinfo['category_id']);
  149. $linkcat_table = Database::get_course_table(TABLE_LINK_CATEGORY);
  150. if (($catinfo = @mysql_fetch_array(api_sql_query(
  151. "SELECT category_title FROM $linkcat_table WHERE id='" .
  152. addslashes($lci) . "'", __FILE__, __LINE__))))
  153. $this->mdo_category_title = $catinfo['category_title'];
  154. }
  155. }
  156. function _find_keywords($d)
  157. {
  158. $dd = new xmddoc($d); if ($dd->error) return NULL;
  159. $regs = array(); // for use with ereg()
  160. foreach ($dd->attributes[0] as $name => $value)
  161. if ($name == 'kw' && ereg('^<?([^>]+)>?$', $value, $regs))
  162. {
  163. $kwa = array_map('trim', explode(',', $regs[1]));
  164. if (ereg('^<' . ($tag = $dd->name[0]) . '[^>]*>(.*)</'.$tag.'>$',
  165. $d, $regs)) // e.g. <i kw="...">A &amp; <b>B</b>!</i>
  166. {
  167. $htdc = array_flip(get_html_translation_table(HTML_ENTITIES));
  168. $d = strtr(ereg_replace( // first <b> -> [b] etc.
  169. '<((/?(b|big|i|small|sub|sup|u))|br/)>', '[\\1]',
  170. ($regs[1])), $htdc); // then &amp; -> & etc.
  171. $d = strtr(str_replace("\r\n", " ", $d), "\r\n", " ");
  172. }
  173. else $d = $dd->xmd_text();
  174. array_push($kwa, $d); return $kwa;
  175. }
  176. return NULL;
  177. }
  178. function _add_keywords(&$xmlDoc, $keywords) // by ref!
  179. {
  180. $ge = $xmlDoc->xmd_select_single_element("metadata/lom/general");
  181. $dl = array("language" =>
  182. $xmlDoc->xmd_value("description/string/@language", $ge));
  183. foreach ($keywords as $kw)
  184. $xmlDoc->xmd_add_text_element("string", $kw,
  185. $xmlDoc->xmd_add_element("keyword", $ge), $dl);
  186. }
  187. }
  188. ?>