function check_andor_get($row, $get = '', $check = '', $tobe = '') { global $mdCat, $htmldecode; if (!$check && !$get) return FALSE; $regs = array(); // for use with ereg() if ($get == $mdCat && !$check) // cheat to be quicker if (ereg('<coverage>[^<]*<string language="..">([^<]+)<\/string>', $row['mdxmltext'], $regs)) return strtr($regs[1], $htmldecode); if ($check == $mdCat && !$get) // cheat to be quicker if (ereg('<coverage>[^<]*<string language="..">([^<]+)<\/string>', $row['mdxmltext'], $regs)) return (strtr($regs[1], $htmldecode) == $tobe); $xmlDoc = new xmddoc(explode("\n", $row['mdxmltext'])); if ($xmlDoc->error) return FALSE; if (!$check) return $xmlDoc->xmd_value($get); if ($xmlDoc->xmd_value($check) == $tobe) return $get ? $xmlDoc->xmd_value($get) : TRUE; return FALSE; }
function store_md_and_traverse_subitems($mfdocId, $level, $counter, $contextElem, $treeElem, $parentElem) { global $_user, $xht_doc, $mdStore, $mdObj, $sdisub, $charset; // $contextElem -> @identifier, metadata/lom // $treeElem -> title, items $itemId = $xht_doc->xmd_value(ITEMID, $contextElem); if ($sdisub && $level == 1 && $sdisub != $itemId) { return; } // <item level=... number=... identifier=...>: // <title>...</title> // <parent identifier=... /> <previous ... /> <next ... /> // <child identifier=... /> <child identifier=... /> ... // <resource href=...> // <file href=... /> <file href=... /> ... // </resource> // <metadata>...</metadata> // </item> set_time_limit(30); // again 30 seconds from here on... $mddoc = new xmddoc('<item/>'); // version, name ? $mddoc->xmd_set_attribute(0, 'level', $level, false); $mddoc->xmd_set_attribute(0, 'number', $counter, false); $mddoc->xmd_set_attribute(0, IDENTIF, $itemId, false); if ($level == 0) { $mddoc->xmd_set_attribute(0, 'created', date('Y/m/d H:i:s'), false); $mddoc->xmd_set_attribute(0, 'by', $_user['user_id'], false); } $mddoc->xmd_add_text_element(TITLE, $xht_doc->xmd_value(TITLE, $treeElem)); if ($ppnId = $xht_doc->xmd_value(ITEMID, $parentElem)) { $mddoc->xmd_add_element('parent', 0, array(IDENTIF => $ppnId)); } if ($ppnId = $xht_doc->xmd_value('-' . SUBIT, $treeElem)) { $mddoc->xmd_add_element('previous', 0, array(IDENTIF => $ppnId)); } if ($ppnId = $xht_doc->xmd_value('+' . SUBIT, $treeElem)) { $mddoc->xmd_add_element('next', 0, array(IDENTIF => $ppnId)); } if (($srcElem = resource_for($treeElem)) > 0) { // change stuff below to xmd_copy_foreign_child ? $resElem = $mddoc->xmd_add_element('resource', 0, array(HREF => $xht_doc->xmd_value(WEBF, $srcElem))); foreach ($xht_doc->xmd_select_elements(FILE, $srcElem) as $fileElem) { $mddoc->xmd_add_element(FILE, $resElem, array(HREF => $xht_doc->xmd_value(WEBF, $fileElem))); } } $mddoc->xmd_copy_foreign_child($xht_doc, $xht_doc->xmd_select_single_element('metadata', $contextElem)); foreach ($xht_doc->xmd_select_elements(SUBITEM, $treeElem) as $subElem) { $mddoc->xmd_add_element('child', 0, array(IDENTIF => $xht_doc->xmd_value(ITEMID, $subElem))); } $mdt = $mddoc->xmd_xml(); $xhtDoc = $mdObj->mdo_define_htt(); $xhtDoc->xht_xmldoc = $mddoc; // $xhtDoc->xht_param['xxx'] = 'yyy'; $mdStore->mds_put($eid = EID_TYPE . '.' . $mfdocId . '.' . $itemId, $mdt, 'mdxmltext', '?'); $mdStore->mds_put($eid, $ixt = $xhtDoc->xht_fill_template('INDEXABLETEXT'), 'indexabletext'); if ($level == 0) { $mdStore->mds_put(EID_TYPE . '.' . $mfdocId, $mdt, 'mdxmltext', '?'); $mdStore->mds_put(EID_TYPE . '.' . $mfdocId, $ixt, 'indexabletext'); } echo $level <= 1 ? '<br />' . $level . '/ ' : ' ', htmlspecialchars($itemId, ENT_QUOTES, $charset); flush(); $loopctr = 0; foreach ($xht_doc->xmd_select_elements(SUBITEM, $treeElem) as $subElem) { store_md_and_traverse_subitems($mfdocId, $level + 1, ++$loopctr, $subElem, $subElem, $contextElem); // note: replacing this recursion by queue+loop makes it slower! } }
break; } else { chdir('..'); } } } // XML and DB STUFF -----------------------------------------------------------> $is_allowed_to_edit = isset($_user['user_id']) && $is_courseMember && api_is_allowed_to_edit(); $mdStore = new mdstore($is_allowed_to_edit); if (($mdt_rec = $mdStore->mds_get(EID)) === FALSE) { // no record, default XML $mdt = $mdObj->mdo_generate_default_xml_metadata(); } else { $mdt = $mdt_rec; } $xhtxmldoc = new xmddoc(explode("\n", $mdt)); !$xhtxmldoc->error or give_up($xhtxmldoc->error); if (SID == $id_range_first && ($prv = $xhtxmldoc->xmd_select_single_element('previous')) != -1) { $xhtxmldoc->xmd_remove_element($prv); } if (SID == $id_range_last && ($nxt = $xhtxmldoc->xmd_select_single_element('next')) != -1) { $xhtxmldoc->xmd_remove_element($nxt); } $before_first = $id_range_first ? TRUE : FALSE; $after_last = FALSE; foreach ($xhtxmldoc->xmd_select_elements('child') as $chEl) { $chId = $xhtxmldoc->attributes[$chEl]['identifier']; // no get_att yet... if ($after_last || ($before_first = $before_first && $chId != $id_range_first)) { $xhtxmldoc->xmd_remove_element($chEl); continue;
Display::display_header($nameTools); echo "\n"; // if the language file in use is not 'md_' . EID_TYPE ... $langMdTitle = 'Default Title (if doc not in DB)'; $langMdDescription = 'Default description (if doc has no comment)'; $langMdCoverage = 'bachelor of engineering'; $langMdCopyright = 'Ghent University'; foreach (array(1001, 1002, 1003) as $eid_id) { $mdObj = new mdobject($_course, $eid_id); // see 'md_' . EID_TYPE . '.php' $eid = $mdObj->mdo_eid; $titlePath = $mdObj->mdo_dcmap_v['Title']; // no IEEE dependencies here... if (($mdt_rec = $mdStore->mds_get($eid)) === FALSE) { $mdt = $mdObj->mdo_generate_default_xml_metadata(); $xmlDoc = new xmddoc(explode("\n", $mdt)); if (!$xmlDoc->error) { echo htmlspecialchars($titlePath), ': '; $mdTitle = $xmlDoc->xmd_value($titlePath); if ($mdTitle == $langMdTitle) { $mdTitle = EID_TYPE . ' ' . $eid_id; $xmlDoc->xmd_update($titlePath, $mdTitle); $mdt = $xmlDoc->xmd_xml(); } echo htmlspecialchars($mdTitle), ':'; } $mdStore->mds_put($eid, $mdt, 'mdxmltext', FALSE); echo '<a href="../index.php?eid=', urlencode($eid), '">', htmlspecialchars($eid), '</a><br>'; } } echo '<br>';
function mds_put_dc_elements($mdo, $dcelem) { if (($mdt = $this->mds_get($mdo->mdo_eid)) === FALSE) { $mdt = $mdo->mdo_generate_default_xml_metadata(); $exists = FALSE; } else $exists = TRUE; $xmlDoc = new xmddoc(explode("\n", $mdt)); if ($xmlDoc->error) return FALSE; foreach ($dcelem as $dce => $value) { $xmlDoc->xmd_update($mdo->mdo_dcmap_v[$dce], (string) $value); } $this->mds_put($mdo->mdo_eid, '', 'md5', $exists); return $this->mds_put($mdo->mdo_eid, $xmlDoc->xmd_xml()); }
} showHtml('/*/organizations/organization/item[1]/title'); showHtml('organizations/organization/item/title'); showHtml('organizations/organization/item/title *'); showHtml('Titles: -% organizations/organization/item/titl , %- .'); // if no elements are found, prefix and postfix are not generated showHtml('Titles: -% organizations/organization/item/title , %- .'); showHtml('<ul><li> -% resources/resource/file/../@identifier </li><li> %- </li></ul>'); showHtml('metadata/lom/general/description/langstring'); echo '<h5>The same, but in a HTML construct:</h5>', $testdoc->xmd_html_value('metadata/lom/general/description/langstring'); function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return (double) $usec + (double) $sec; } $xmlFile = 'imsmanifest_reload.xml'; $presXmlFileContents = @file_get_contents_n($xmlFile) or die('XML file ' . htmlspecialchars($xmlFile) . ' is missing...'); $presXmlFileContents = explode("\n", $presXmlFileContents); $seconds = getmicrotime(); $testdoc2 = new xmddoc($presXmlFileContents); $seconds = getmicrotime() - $seconds; showDoc('Time to parse', $seconds); $seconds = getmicrotime(); $testdoc2->xmd_cache(); $seconds = getmicrotime() - $seconds; showDoc('Time to cache', $seconds); $seconds = getmicrotime(); $testdoc = new xmddoc($testdoc2->names, $testdoc2->numbers, $testdoc2->textstring); $seconds = getmicrotime() - $seconds; showDoc('Time to restore from cache', $seconds); showDoc('OK after restore');
$testdoc = new xmddoc(<<<EOD <docroot xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"> <title>Test for XML HTML Templates</title> <description>This is a [b]test[/b] for &#911; XML with <some> "funny" stuff... a new line and <x>1</x> inside tag.</description> <keywords> <keyword>kw1</keyword> <keyword>kw2</keyword> <keyword>kw3</keyword> </keywords> <metadata> <schema>IMS Content</schema> <schemaversion>1.2.2</schemaversion> <imsmd:lom> <imsmd:general> <imsmd:catalogentry> <imsmd:catalog /> <imsmd:entry> <imsmd:langstring xml:lang="en" /> </imsmd:entry> </imsmd:catalogentry> <imsmd:language>en</imsmd:language> <imsmd:description> <imsmd:langstring xml:lang="en">Simple exemplar content package , this description was modified by René </imsmd:langstring> </imsmd:description> </imsmd:general> </imsmd:lom> </metadata> </docroot> EOD );
function _find_keywords($d) { $dd = new xmddoc($d); if ($dd->error) { return NULL; } $regs = array(); // for use with ereg() foreach ($dd->attributes[0] as $name => $value) { if ($name == 'kw' && ereg('^<?([^>]+)>?$', $value, $regs)) { $kwa = array_map('trim', explode(',', $regs[1])); if (ereg('^<' . ($tag = $dd->name[0]) . '[^>]*>(.*)</' . $tag . '>$', $d, $regs)) { $htdc = array_flip(get_html_translation_table(HTML_ENTITIES)); $d = strtr(ereg_replace('<((/?(b|big|i|small|sub|sup|u))|br/)>', '[\\1]', $regs[1]), $htdc); // then & -> & etc. $d = strtr(str_replace("\r\n", " ", $d), "\r\n", " "); } else { $d = $dd->xmd_text(); } array_push($kwa, $d); return $kwa; } } return NULL; }