md_link.php 8.1 KB

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