1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: namespace ManiaLib\Gui;
14:
15: abstract class Manialink
16: {
17:
18: 19: 20:
21: public static $domDocument;
22:
23: 24: 25:
26: public static $parentNodes;
27:
28: 29: 30:
31: public static $parentLayouts;
32:
33: 34: 35:
36: public static $parentFrames;
37: public static $linksEnabled = true;
38: public static $langsURL;
39: public static $imagesURL;
40: public static $mediaURL;
41:
42: 43: 44: 45: 46:
47: final public static function load($root = true, $timeout = 0, $version = 1, $background = 1)
48: {
49: if(class_exists('\ManiaLib\Application\Config'))
50: {
51: $config = \ManiaLib\Application\Config::getInstance();
52: self::$langsURL = $config->getLangsURL();
53: self::$imagesURL = $config->getImagesURL();
54: self::$mediaURL = $config->getMediaURL();
55: }
56:
57:
58: self::$domDocument = new \DOMDocument('1.0', 'utf-8');
59: self::$parentNodes = array();
60: self::$parentLayouts = array();
61: self::$parentFrames = array();
62:
63: if($root)
64: {
65: $nodeManialink = self::$domDocument->createElement('manialink');
66: $nodeManialink->setAttribute('version', $version);
67: if(!$background)
68: {
69: $nodeManialink->setAttribute('background', 0);
70: }
71: self::$domDocument->appendChild($nodeManialink);
72: self::$parentNodes[] = $nodeManialink;
73:
74: $nodeTimeout = self::$domDocument->createElement('timeout');
75: $nodeManialink->appendChild($nodeTimeout);
76: $nodeTimeout->nodeValue = $timeout;
77: }
78: else
79: {
80: $frame = self::$domDocument->createElement('frame');
81: self::$domDocument->appendChild($frame);
82: self::$parentNodes[] = $frame;
83: }
84: }
85:
86: 87: 88: 89:
90: final public static function render($return = false)
91: {
92: if($return)
93: {
94: return self::$domDocument->saveXML();
95: }
96: else
97: {
98: header('Content-Type: text/xml; charset=utf-8');
99: echo self::$domDocument->saveXML();
100: }
101: }
102:
103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113:
114: final public static function beginFrame($x = 0, $y = 0, $z = 0, $scale = null,
115: \ManiaLib\Gui\Layouts\AbstractLayout $layout = null)
116: {
117: $frame = new Elements\Frame();
118: $frame->setPosition($x, $y, $z);
119: $frame->setScale($scale);
120: if($layout instanceof Layouts\AbstractLayout)
121: {
122: $frame->setLayout($layout);
123: }
124: $frame->buildXML();
125:
126: self::$parentFrames[] = $frame;
127: self::$parentNodes[] = $frame->getDOMElement();
128: self::$parentLayouts[] = $frame->getLayout();
129: }
130:
131: 132: 133:
134: final public static function endFrame()
135: {
136: if(!end(self::$parentNodes)->hasChildNodes())
137: {
138: end(self::$parentNodes)->nodeValue = ' ';
139: }
140: array_pop(self::$parentNodes);
141: array_pop(self::$parentLayouts);
142: $frame = array_pop(self::$parentFrames);
143: $frame->save();
144: }
145:
146: final static function setFrameId($id)
147: {
148: end(self::$parentFrames)->setId($id);
149: }
150:
151: final static function setFrameScriptEvents($scriptEvents = 1)
152: {
153: $frame = end(self::$parentNodes);
154: $frame->setAttribute('scriptevents', $scriptEvents);
155: }
156:
157: 158: 159:
160: final public static function redirect($link, $render = true)
161: {
162: self::$domDocument = new \DOMDocument('1.0', 'utf-8');
163: self::$parentNodes = array();
164: self::$parentLayouts = array();
165:
166: $redirect = self::$domDocument->createElement('redirect');
167: $redirect->appendChild(self::$domDocument->createTextNode($link));
168: self::$domDocument->appendChild($redirect);
169: self::$parentNodes[] = $redirect;
170:
171: if($render)
172: {
173: if(ob_get_contents())
174: {
175: ob_clean();
176: }
177: header('Content-Type: text/xml; charset=utf-8');
178: echo self::$domDocument->saveXML();
179: }
180: else
181: {
182: return self::$domDocument->saveXML();
183: }
184: }
185:
186: static function createElement($tagName)
187: {
188: return self::$domDocument->createElement($tagName);
189: }
190:
191: static function ($comment)
192: {
193: end(self::$parentNodes)->appendChild(self::$domDocument->createComment($comment));
194: }
195:
196: 197: 198: 199:
200: static function appendXML($XML)
201: {
202: $doc = new \DOMDocument('1.0', 'utf-8');
203: $doc->loadXML($XML);
204: $node = self::$domDocument->importNode($doc->firstChild, true);
205: end(self::$parentNodes)->appendChild($node);
206: }
207:
208: static function appendScript($maniaScript)
209: {
210: $script = self::$domDocument->createElement('script');
211: $script->appendChild(self::$domDocument->createTextNode($maniaScript));
212: end(self::$parentNodes)->appendChild($script);
213: }
214:
215: 216: 217:
218: static function disableLinks()
219: {
220: self::$linksEnabled = false;
221: }
222:
223: 224: 225:
226: static function enableLinks()
227: {
228: self::$linksEnabled = true;
229: }
230:
231: }
232:
233: ?>