* @package chamilo.metadata */ /** * Chamilo Metadata: XHT test and demo */ require('../../inc/lib/xmd.lib.php'); require('../../inc/lib/xht.lib.php'); // XML DOCUMENT ---------------------------------------------------------------> $testdoc = new xmddoc( << Test for XML HTML Templates This is a [b]test[/b] for &#911; XML with <some> "funny" stuff... a new line and 1 inside tag. kw1 kw2 kw3 IMS Content 1.2.2 en Simple exemplar content package , this description was modified by René EOD ); if ($testdoc->error) die($testdoc->error); // TEMPLATES ------------------------------------------------------------------> $xhtDoc = new xhtdoc( << Expires: Mon, 26 Jul 1997 05:00:00 GMT

testXht

{-X title-}

Hello {-P p1-}! {-X description-}
{-X metadata/lom/general/description/langstring-}

{-D label This is a funny -}{-C LABEL-}

{-R keywords/keyword C KEYWORD-}
There are {-R keywords/keyword P empty-}{-P number-} keywords...



{-R Langnames C LEVEL1-}

{-D author {-V author-}-} {-T author != empty
There is an author
This text is re-calculated when the cache is no longer valid. {-H {-P label-}-} :  {-D label {-L Kw-}-}{-C LABEL-}{-X .-} {-P rdepth-}.{-P key-}: {-R keywords/keyword C LEVEL2-}
{-P rdepth-}.{-P number-} EOD ); if ($xhtDoc->htt_error) die($xhtDoc->htt_error); $xhtDoc->xht_xmldoc = $testdoc; // PREPARE FOR PROCESSING -----------------------------------------------------> function get_lang($word) { if ($word == 'Kw') return 'Keyword'; elseif ($word == 'Am') return '"Automatic"'; elseif ($word == 'Langnames') return array("de"=>"German", "fr"=>"French", "nl"=>"Dutch"); else return 'To be translated'; } $xhtDoc->xht_get_lang = 'get_lang'; $xhtDoc->xht_param['p1'] = 'world'; function md_cache($newtext) // callback from template (for cached HTML) { if ($newtext === FALSE) // this is always the first callback { $cachedHtmlIsValid = FALSE; // in real examples, not always if ($cachedHtmlIsValid) return 'Cached HTML'; else // do some preparations return FALSE; // signals XHT to generate new text from template } else // after template expansion, XHT does a second callback { // store the new text in the cache... // possibly modify the text to be output... return $newtext; // often the output is identical to the new text } } // GENERATE OUTPUT ------------------------------------------------------------> foreach (explode("\n", $xhtDoc->htt_array['HTTP']) as $httpXtra) if ($httpXtra) header($httpXtra); echo "\n", $xhtDoc->xht_fill_template('HEAD'), "\n\n\n\n"; $xhtDoc->xht_dbgn = 0; // for template debug info, set to e.g. 10000 echo $xhtDoc->xht_fill_template('MAIN'), '

Child nodes of "description":'; foreach($testdoc->children[$testdoc->xmd_select_single_element('description')] as $child) echo '
', strlen($child), ': ', htmlspecialchars($child); echo "\n\n\n\n"; if ($xhtDoc->xht_dbgn) echo $xhtDoc->xht_dbgo; // Note: XML document and templates would normally be fetched from (different) // external sources, such as a file or a DB record... ?>