aboutsummaryrefslogtreecommitdiff
path: root/h-source/Library/BoxParser.php
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2012-05-28 15:31:57 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2012-05-28 15:31:57 +0000
commit129934f892850a90f98f8f5a0e7746cfe57bb958 (patch)
treec03e502f0201d3d8bbd76580670a2ec576f6e2ef /h-source/Library/BoxParser.php
parent054086b33dad4c4f7089cf2ebf0f52eed1d7a023 (diff)
added new EasyGiant library
Diffstat (limited to 'h-source/Library/BoxParser.php')
-rw-r--r--h-source/Library/BoxParser.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/h-source/Library/BoxParser.php b/h-source/Library/BoxParser.php
new file mode 100644
index 0000000..0e7e03f
--- /dev/null
+++ b/h-source/Library/BoxParser.php
@@ -0,0 +1,86 @@
+<?php
+
+// EasyGiant is a PHP framework for creating and managing dynamic content
+//
+// Copyright (C) 2009 - 2011 Antonio Gallo
+// See COPYRIGHT.txt and LICENSE.txt.
+//
+// This file is part of EasyGiant
+//
+// EasyGiant is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// EasyGiant is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with EasyGiant. If not, see <http://www.gnu.org/licenses/>.
+
+if (!defined('EG')) die('Direct access not allowed!');
+
+//class to parse an XML text in order to create the modules corresponding to the elements of the XML text.
+//the <type>module name</type> tag defines the name of the object that has to be instantiate and saved in the
+//$modules property (that is an array referencing different module objects) array(moduleObj1,moduleObj2, ...)
+//if the module class corresponding ot the <type>module name</type> tag does not exists, than no module is created and the next <type>module name</type> is checked
+class BoxParser {
+
+ public $modules = array(); //array referencing different module classes --> array(moduleObj1,moduleObj2, ...) See files inside the Application/Modules folder
+
+ //$simpleXMLText: it has to be an XML text
+ //$type; it can be string or file.
+ public function __construct($simpleXMLText, $type = 'string')
+ {
+ if ($type === 'string')
+ {
+ if (@simplexml_load_string($simpleXMLText))
+ {
+ $simpleXmlObj = simplexml_load_string($simpleXMLText);
+ $this->populate($simpleXmlObj);
+ }
+ }
+ else if ($type === 'file')
+ {
+ if (@simplexml_load_file($simpleXMLText))
+ {
+ $simpleXmlObj = simplexml_load_file($simpleXMLText);
+ $this->populate($simpleXmlObj);
+ }
+ }
+ }
+
+ //inistantiate the module objects and save them in the $this->modules property array
+ private function populate($simpleXmlObj)
+ {
+ foreach ($simpleXmlObj as $mod)
+ {
+ $className = 'Mod'.ucwords((string)$mod->type);
+ if (class_exists($className))
+ {
+ if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Modules' . DS . $className . '.php'))
+ {
+ $newModule = new $className($mod);
+ if ($newModule instanceof ModAbstract)
+ {
+ $this->modules[] = $newModule;
+ }
+ }
+ }
+ }
+ }
+
+ //create the HTML of the modules
+ public function render()
+ {
+ $HTML = null;
+ foreach ($this->modules as $module)
+ {
+ $HTML .= $module->render();
+ }
+ return $HTML;
+ }
+
+} \ No newline at end of file