1: <?php
2: /**
3: * ManiaLib - Lightweight PHP framework for Manialinks
4: *
5: * @see http://code.google.com/p/manialib/
6: * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
7: * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
8: * @version $Revision: 590 $:
9: * @author $Author: maximeraoust $:
10: * @date $Date: 2011-12-27 19:40:38 +0100 (mar., 27 déc. 2011) $:
11: */
12:
13: namespace ManiaLib\Gui\Maniacode;
14:
15: abstract class Maniacode
16: {
17:
18: public static $domDocument;
19: public static $parentNodes;
20:
21: /**
22: * Loads the Maniacode GUI Toolkit. This should be called before doing anything with the toolkit
23: *
24: * @param bool True if you don't want to see a message at the end of the execution of the maniacode
25: * @param bool Wheter you want to create the root "<maniacode>" element in the XML
26: */
27: final public static function load($noconfirmation = false,
28: $createManialinkElement = true)
29: {
30: self::$domDocument = new \DOMDocument('1.0', 'utf8');
31: self::$parentNodes = array();
32:
33: if($createManialinkElement)
34: {
35: $maniacode = self::$domDocument->createElement('maniacode');
36: if($noconfirmation)
37: $maniacode->setAttribute('noconfirmation', $noconfirmation);
38: self::$domDocument->appendChild($maniacode);
39: self::$parentNodes[] = $maniacode;
40: }
41: }
42:
43: /**
44: * Renders the Maniacode if no return the script will be stopped
45: * @param bool Whether you want to return the XML instead of printing it
46: * @return mixed The XML string if param true, in other case it returns void
47: */
48: final public static function render($return = false)
49: {
50: if($return)
51: {
52: return self::$domDocument->saveXML();
53: }
54: else
55: {
56: header('Content-Type: text/xml; charset=utf-8');
57: echo self::$domDocument->saveXML();
58: exit();
59: }
60: }
61:
62: /**
63: * Append some XML code to the document
64: * @param string $XML The given XML
65: */
66: static function appendXML($XML)
67: {
68: $doc = new \DOMDocument('1.0', 'utf8');
69: $doc->loadXML($XML);
70: $node = self::$domDocument->importNode($doc->firstChild, true);
71: end(self::$parentNodes)->appendChild($node);
72: }
73:
74: }
75:
76: ?>