dokeos-metadata
[ class tree: dokeos-metadata ] [ index: dokeos-metadata ] [ all elements ]

Source for file md_link.php

Documentation is available at md_link.php

  1. <?php /*                          <!-- md_link.php for Dokeos metadata/*.php -->
  2.                                                              <!-- 2006/12/15 -->
  3.  
  4. <!-- Copyright (C) 2006 rene.haentjens@UGent.be -  see metadata/md_funcs.php -->
  5.  
  6. */
  7.  
  8. /**
  9. ============================================================================== 
  10. *    Dokeos Metadata: class mdobject for Link-type objects
  11. *
  12. *    @package dokeos.metadata
  13. ============================================================================== 
  14. */
  15.  
  16. class mdobject
  17. {
  18.  
  19. var $mdo_type;
  20. var $mdo_id;
  21. var $mdo_eid;
  22.  
  23. var $mdo_dcmap_e;
  24. var $mdo_dcmap_v;
  25.  
  26. var $mdo_url;
  27. var $mdo_title;
  28. var $mdo_description;
  29. var $mdo_category;
  30. var $mdo_category_title;
  31.  
  32. function mdo_define_htt(return new xhtdoc(<<<EOD
  33.  
  34. <!-- {-INDEXABLETEXT-} -->
  35.  
  36. Title: {-V metadata/lom/general/title/string-} txt-sep
  37. Keyword(s): {-R metadata/lom/general/keyword C KWTEXT-} txt-sep
  38. Category: {-V metadata/lom/general/coverage/string-} txt-sep
  39.  {-V metadata/lom/general/description[1]/string-} txt-end
  40.  link-type
  41.  
  42.  
  43. <!-- {-KWTEXT-} -->
  44.  
  45.  {-V string-}-kw
  46.  
  47.  
  48. <!-- {--} -->
  49. EOD
  50. );
  51. }
  52.  
  53. function mdo_generate_default_xml_metadata()
  54. {
  55.     global $iso639_2_code$ieee_xml;
  56.     
  57.     $xhtDoc new xhtdoc($ieee_xml)$_user api_get_user_info();
  58.     
  59.     if ($xhtDoc->htt_error
  60.         give_up('IEEE XML (metadata/md_funcs): ' $xhtDoc->htt_error);
  61.     
  62.     $xhtDoc->xht_get_lang 'get_lang'$xhtDoc->xht_xmldoc new xmddoc('');
  63.     if ($xhtDoc->xht_xmldoc->errorgive_up($xhtDoc->xht_xmldoc->error);
  64.     
  65.     $xhtDoc->xht_param['siteUri'make_uri();
  66.     
  67.     $xhtDoc->xht_param['entry'$this->mdo_course['sysCode'
  68.         '.Link.' $this->mdo_id;  // 2005-05-30: path->sysCode
  69.     
  70.     $xhtDoc->xht_param['location'$this->mdo_url . '';
  71.     
  72.     $xhtDoc->xht_param['mdlang'strtolower($iso639_2_code);
  73.     $xhtDoc->xht_param['lang'=   strtolower($iso639_2_code);
  74.     
  75.     $xhtDoc->xht_param['title'
  76.         $this->mdo_title $this->mdo_title get_lang('MdTitle');
  77.     
  78.     if (($d $this->mdo_description))
  79.     {
  80.         if ($keywords $this->_find_keywords($d)) $d array_pop($keywords);
  81.         $xhtDoc->xht_param['description'$d;
  82.     }
  83.     else
  84.         $xhtDoc->xht_param['description'get_lang('MdDescription');
  85.     
  86.     $xhtDoc->xht_param['coverage'$this->mdo_category_title 
  87.         $this->mdo_category_title get_lang('MdCoverage');
  88.  
  89.     if (isset($_user))
  90.     {
  91.         $xhtDoc->xht_param['author'"BEGIN:VCARD\\nFN:" 
  92.             $_user['firstName']." ".$_user['lastName'
  93.             "\\nEMAIL:".$_user['mail'"\\nEND:VCARD\\n";
  94.     }
  95.     
  96.     $xhtDoc->xht_param['dateTime'date('Y-m-d');
  97.     
  98.     $xhtDoc->xht_param['format'''$xhtDoc->xht_param['size''0';
  99.     
  100.     if (count($keywords))
  101.     {
  102.         $xd new xmddoc(explode("\n"
  103.             $mdt $xhtDoc->xht_fill_template('XML')));
  104.         if ($xd->errorreturn $mdt;  // and worry later
  105.         
  106.         $this->_add_keywords($xd$keywords);
  107.         
  108.         return $xd->xmd_xml();
  109.     }
  110.     
  111.     return $xhtDoc->xht_fill_template('XML');
  112. }
  113.  
  114.  
  115. function mdo_override(&$xmlDoc)  // by ref!
  116. {
  117.     if ($this->mdo_url)
  118.     {
  119.         $xmlDoc->xmd_update('metadata/lom/technical/location'$this->mdo_url);
  120.         
  121.         $ge $xmlDoc->xmd_select_single_element("metadata/lom/general");
  122.         
  123.         $xmlDoc->xmd_update('title[1]/string'$this->mdo_title$ge);
  124.         $xmlDoc->xmd_update('coverage[1]/string'$this->mdo_category_title$ge);
  125.         
  126.         if (($d $this->mdo_description))
  127.             if ($keywords $this->_find_keywords($d)) $d array_pop($keywords);
  128.         
  129.         $xmlDoc->xmd_update('description[1]/string'$d$ge);
  130.         
  131.         $xmlDoc->xmd_remove_nodes($xmlDoc->xmd_select_elements('keyword'$ge)$ge);
  132.         
  133.         if (count($keywords)) $this->_add_keywords($xmlDoc$keywords);
  134.     }
  135.     
  136.     return $xmlDoc->xmd_xml();
  137. }
  138.  
  139.  
  140. function mdo_storeback(&$xmlDoc)  // by ref!
  141. {
  142.     if (!$this->mdo_urlreturn;  // no record in link table, most probably
  143.     
  144.     if (!($v $xmlDoc->xmd_value('metadata/lom/technical/location'))) return;
  145.     
  146.     if ($v != $this->mdo_url)
  147.     $this->mdo_url = $v;   $u .= ", url = '" addslashes($v"'"}
  148.     
  149.     $ge $xmlDoc->xmd_select_single_element("metadata/lom/general");
  150.     
  151.     $v $xmlDoc->xmd_value('title[1]/string'$ge);
  152.     if ($v != $this->mdo_title)
  153.     $this->mdo_title $v$u .= ", title = '" addslashes($v"'"}
  154.     
  155.     $vd $xmlDoc->xmd_value('description[1]/string'$ge);
  156.     $vk $xmlDoc->xmd_value('keyword/string'$gearray('in' => ', '));
  157.     $v $vk '<i kw="' htmlspecialchars($vk'">' 
  158.         ereg_replace('\[((/?(b|big|i|small|sub|sup|u))|br/)\]''<\\1>'
  159.             htmlspecialchars($vd)) '</i>' $vd;
  160.     
  161.     if ($v != $this->mdo_description)
  162.     {
  163.         $this->mdo_description $v
  164.         $u .= ", description = '" addslashes($v"'";
  165.     }
  166.     
  167.     // do not store back a modified coverage as category...
  168.     
  169.     $link_table Database::get_course_table(TABLE_LINK);
  170.     if ($uapi_sql_query("UPDATE $link_table SET substr($u2
  171.         " WHERE id='" addslashes($this->mdo_id"'"__FILE____LINE__);
  172. }
  173.  
  174.  
  175. function mdo_add_breadcrump_nav()
  176. {
  177.     global $interbreadcrumb;
  178.     
  179.     $regs array()// for use with ereg()
  180.     
  181.     $docurl api_get_self();  // should be .../main/xxx/yyy.php
  182.     if (ereg('^(.+[^/\.]+)/[^/\.]+/[^/\.]+.[^/\.]+$'$docurl$regs))
  183.         $docurl $regs[1'/link/link.php';
  184.     
  185.     $interbreadcrumb[]array ('url' => $docurl
  186.         "name"=> get_lang('MdCallingTool'));
  187. }
  188.  
  189.  
  190. function mdobject($_course$id)
  191. {
  192.     global $ieee_dcmap_e$ieee_dcmap_v;  // md_funcs
  193.     
  194.     $this->mdo_course = $_course$this->mdo_type = 'Link';
  195.     $this->mdo_id = $id$this->mdo_eid = $this->mdo_type . '.' $id;
  196.     
  197.     $this->mdo_dcmap_e $ieee_dcmap_e$this->mdo_dcmap_v $ieee_dcmap_v;
  198.     
  199.     $link_table Database::get_course_table(TABLE_LINK);
  200.     if (($linkinfo @mysql_fetch_array(api_sql_query(
  201.             "SELECT url,title,description,category_id FROM $link_table WHERE id='
  202.             addslashes($id"'"__FILE____LINE__))))
  203.     {
  204.         $this->mdo_url =         $linkinfo['url'];
  205.         $this->mdo_title =       $linkinfo['title'];
  206.         $this->mdo_description $linkinfo['description'];
  207.         $this->mdo_category =    ($lci $linkinfo['category_id']);
  208.         
  209.         $linkcat_table Database::get_course_table(TABLE_LINK_CATEGORY);
  210.         if (($catinfo @mysql_fetch_array(api_sql_query(
  211.                 "SELECT category_title FROM $linkcat_table WHERE id='
  212.                 addslashes($lci"'"__FILE____LINE__))))
  213.             $this->mdo_category_title =    $catinfo['category_title'];
  214.     }
  215. }
  216.  
  217.  
  218. function _find_keywords($d)
  219. {
  220.     $dd new xmddoc($d)if ($dd->errorreturn NULL;
  221.     
  222.     $regs array()// for use with ereg()
  223.     
  224.     foreach ($dd->attributes[0as $name => $value)
  225.         if ($name == 'kw' && ereg('^<?([^>]+)>?$'$value$regs))
  226.         {
  227.             $kwa array_map('trim'explode(','$regs[1]));
  228.             
  229.             if (ereg('^<' ($tag $dd->name[0]'[^>]*>(.*)</'.$tag.'>$'
  230.                     $d$regs))  // e.g. <i kw="...">A &amp; <b>B</b>!</i>
  231.             {
  232.                 $htdc array_flip(get_html_translation_table(HTML_ENTITIES));
  233.                 $d strtr(ereg_replace(  // first  <b>  -> [b] etc.
  234.                     '<((/?(b|big|i|small|sub|sup|u))|br/)>''[\\1]'
  235.                     ($regs[1]))$htdc);  // then  &amp; ->  &  etc.
  236.                 $d strtr(str_replace("\r\n"" "$d)"\r\n""  ");
  237.             }
  238.             else $d $dd->xmd_text();
  239.             
  240.             array_push($kwa$d)return $kwa;
  241.         }
  242.     
  243.     return NULL;
  244. }
  245.  
  246. function _add_keywords(&$xmlDoc$keywords)  // by ref!
  247. {
  248.     $ge $xmlDoc->xmd_select_single_element("metadata/lom/general");
  249.     $dl array("language" => 
  250.         $xmlDoc->xmd_value("description/string/@language"$ge));
  251.     
  252.     foreach ($keywords as $kw)
  253.         $xmlDoc->xmd_add_text_element("string"$kw
  254.             $xmlDoc->xmd_add_element("keyword"$ge)$dl);
  255. }
  256.  
  257. }
  258. ?>

Documentation generated on Thu, 12 Jun 2008 14:05:53 -0500 by phpDocumentor 1.4.1