1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22:
23: namespace picon;
24:
25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39:
40: class MarkupParser extends XMLParser
41: {
42: private static $PICON_ELEMENTS = array('picon:child', 'picon:extend', 'picon:panel', 'picon:head', 'picon:border', 'picon:body');
43:
44: protected function onCharacterData($data, XMLTag $element)
45: {
46: $element->addChild(new TextElement($this->html_entities($data)));
47: }
48:
49: protected function newElement($name, $attributes)
50: {
51: if (array_key_exists('picon:id', $attributes))
52: {
53: return new ComponentTag($name, $attributes);
54: }
55: elseif (in_array($name, MarkupParser::$PICON_ELEMENTS) || $name=='head')
56: {
57: $tag = new PiconTag($name, $attributes);
58:
59: if($name=='head')
60: {
61: $tag->put('picon:id', HeaderResolver::HEADER_ID);
62: }
63:
64: return $tag;
65: }
66: else
67: {
68: return new MarkupElement($name, $attributes);
69: }
70: }
71:
72: protected function onXmlError($errorCode, $errorMessage)
73: {
74: throw new \InvalidMarkupException(sprintf("XML error: %s at line %d of file %s", $errorCode, $errorMessage, $this->xmlFile));
75: }
76:
77: protected function prepare($data)
78: {
79: return $this->numeric_entities($data);
80: }
81:
82: private function numeric_entities($string)
83: {
84: $mapping = array();
85: foreach (get_html_translation_table(HTML_ENTITIES, ENT_QUOTES) as $char => $entity)
86: {
87: $mapping[$entity] = '!entity-mark#' . ord($char) . '!entity-mar#';
88: }
89:
90: return str_replace(array_keys($mapping), $mapping, $string);
91: }
92:
93: private function html_entities($string)
94: {
95: $mapping = array();
96: foreach (get_html_translation_table(HTML_ENTITIES, ENT_QUOTES) as $char => $entity)
97: {
98: $mapping['!entity-mark#' . ord($char) . '!entity-mar#'] = $entity;
99: }
100:
101: return str_replace(array_keys($mapping), $mapping, $string);
102: }
103: }
104:
105: ?>
106: