HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/tops.komma.pro/wwwroot/lib/content/content_generator.class.php
<?php
/**
 * generate_content.class.php
 * Created by Komma Mediadesign.
 * Author: mike
 * Date: 12/02/14
 */

require_once DOCUMENT_ROOT . 'lib/content/content_block.class.php';

class Content_Generator
{
    /*
     * Page Name - String
     */
    private $_name;

    /*
     * XML - XML Object
     */
    private $_xml;

    /*
     * File to load - string
     */
    private $_file;

    /*
     * Data to return
     */
    private $_data;

    /*
     * Constructor
     */
    public function __construct($name)
    {
        // Set name
        $this->_name = $name;

        // Set file
        $this->_file = $this->getFile();

        // Get XML file
        $this->load();
    }

    /*
     * Generate content
     * Check what blocks to generate
     */
    public function generate()
    {
        if( $this->_xml != null)
        {
            // Get Main blocks
            $blocks = get_object_vars($this->_xml);

            foreach(array_keys($blocks) as $block)
            {
                // generate method name
                $className = str_replace('_',' ',$block);
                $className = ucwords($className);
                $className = str_replace(' ','_',$className);

                // Check if class exists
                $file = DOCUMENT_ROOT . 'lib/content/' . $block . '.class.php';
                if(is_file($file))
                {
                    require_once $file;

                    $Class = new $className($this->_xml);
                    $this->_data[$block] = $Class->generate();
                }
            }

            return $this->_data;
        }
        return false;
    }

    /*
     * Load file
     * @param string
     * @return boolean
     */
    private function load()
    {
        // Check if file exists
        if(is_file($this->_file))
        {
            ob_start();
            require $this->_file ;
            $string = ob_get_contents();

            ob_end_clean();
            $this->_xml = simplexml_load_string($string);

            return true;
        }
        return false;
    }

    /*
     * Check what file to grab
     */
    private function getFile()
    {
        $file = DOCUMENT_ROOT . 'pages/' . strtolower(URL_LANG) . '/';

        // Check if a folder exists with this name
        if(is_dir($file . $this->_name))
        {
            // Add the folder to the path
            $file .= $this->_name . '/';

            // Check if defined URL_SUB
            if(defined('URL_SUB'))
            {
                // Get Sub
                $Translator = new Translator(URL_LANG);
                $sub = $Translator->getPageKey(URL_SUB);
                $sub = str_replace('-','_',$sub);

                // Check if this is a folder
                if(is_dir($file . $sub))
                {
                    // Check if defined URL_SUB2
                    if(defined('URL_SUB2'))
                    {
                        // Get Sub
                        $sub2 = $Translator->getPageKey(URL_SUB2);
                        $sub2 = str_replace('-','_',$sub2);

                        $file .= $sub . '/' . $sub2 . '.xml.php';
                    }
                    else
                    {
                        $file .= $sub . '/index.xml.php';
                    }
                }
                else
                {
                    $file .= $sub . '.xml.php';
                }
            }
            else
            {
                $file .= 'index.xml.php';
            }
        }
        else
        {
            $file .= $this->_name . '.xml.php';
        }

        return $file;
    }
}