Advertisement
Guest User

class.template.php

a guest
Mar 21st, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 56.72 KB | None | 0 0
  1. <?php
  2. /* ************************************************************ *\
  3. |* *    COPYRIGHT (C) 2011 NOBRAIN. ALL RIGHTS RERSERVED.     * *|
  4. |* ************************************************************ *|
  5. |* * This software is licensed under the Common Development   * *|
  6. |* * and Distribution License Version 1 license. This         * *|
  7. |* * software is open source.                                 * *|
  8. |* * http://opensource.org/licenses/CDDL-1.0                  * *|
  9. |* ************************************************************ *|
  10. |* * Project H is an advanced Habbo content management        * *|
  11. |* * system that brings features from the past and present    * *|
  12. |* * into one core system.                                    * *|
  13. |* ************************************************************ *|
  14. |* * @product: Project H                                      * *|
  15. |* * @author: nobrain                                         * *|
  16. \* ************************************************************ */
  17.  
  18. /*
  19.  *
  20.  * Template class.
  21.  *
  22.  * Handles all of the softwares template functionality.
  23.  *
  24.  */
  25. class Template
  26. {
  27.     private $style_id = null;
  28.  
  29.     private $templates = null;
  30.  
  31.     private $parameters = array();
  32.  
  33.     private $header_data = array();
  34.  
  35.     private $output_buffer = null;
  36.  
  37.     private $page_buffer = '';
  38.    
  39.     private $nocachetemplates = array(
  40.     'quickregister',
  41.     'profile',
  42.     'dashboard'
  43.     );
  44.  
  45.     private $nobuildtemplates = array(
  46.     'client'
  47.     );
  48.  
  49.     /*
  50.      *
  51.      * Public Function class constructor.
  52.      *
  53.      * Puts the list of templates to call in the $templates class variable. Initializes the generic environment variables.
  54.      *
  55.      * @param:      $templates      Array of templates to call.
  56.      *
  57.      */
  58.     final public function __construct($templates)
  59.     {
  60.         if ($templates != null)
  61.         {
  62.             $this->templates =& $templates;
  63.         }
  64.         else
  65.         {
  66.             // Error, invalid merged templates.
  67.         }
  68.     }
  69.  
  70.     /*
  71.      *
  72.      * Public Function initialize.
  73.      *
  74.      * Initializes core functions.
  75.      *
  76.      */
  77.     final public function initialize()
  78.     {
  79.         require_once CWD . INCLUDES . LANGUAGES . SITE_LANG . '.php';
  80.        
  81.         $this->setGenericData();
  82.     }
  83.  
  84.     /*
  85.      *
  86.      * Private Function setGenericData.
  87.      *
  88.      * Sets the generic template data.
  89.      *
  90.      */
  91.     final private function setGenericData()
  92.     {
  93.         global $ir, $language;
  94.  
  95.         switch (strtolower(THIS_PAGE))
  96.         {
  97.             case 'frontpage':
  98.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  99.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/landing.js', true);
  100.                 break;
  101.  
  102.             case 'quickregister':
  103.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  104.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  105.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  106.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/quickregister.js', true);
  107.                 break;
  108.  
  109.             case 'me':
  110.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/personal.css', true);
  111.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/minimail.css', true);
  112.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  113.  
  114.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/home.css', true);
  115.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/lightwindow.css', true);
  116.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/group.css', true);
  117.  
  118.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  119.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  120.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  121.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  122.                
  123.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/homeview.js', true);
  124.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/homeauth.js', true);
  125.                 //$this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/homeview.js', true);
  126.                
  127.                 break;
  128.            
  129.             case 'me2':
  130.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/personal.css', true);
  131.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/minimail.css', true);
  132.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  133.  
  134.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  135.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  136.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  137.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  138.                 break;
  139.  
  140.             case 'community':
  141.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  142.                
  143.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  144.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  145.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  146.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  147.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/moredata.js', true);
  148.                 break;
  149.  
  150.             case 'shops':
  151.                 $this->addHeaderData('css', 'http://images.habbo.com/habboweb/' . WEBBUILD . '/web-gallery/static/styles/cbs2credits.css', true);
  152.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  153.                
  154.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  155.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  156.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  157.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  158.                 break;
  159.  
  160.             case 'badgeshop':
  161.                 $this->addHeaderData('css', 'http://images.habbo.com/habboweb/' . WEBBUILD . '/web-gallery/static/styles/cbs2credits.css', true);
  162.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  163.                
  164.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  165.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  166.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  167.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  168.                 break;
  169.  
  170.             case 'profile':
  171.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  172.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/settings.css', true);
  173.  
  174.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  175.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  176.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  177.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  178.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/settings.js', true);
  179.                 break;
  180.  
  181.             case 'dashboard':
  182.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  183.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/settings.css', true);
  184.  
  185.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  186.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  187.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  188.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  189.                 break;
  190.  
  191.             case 'articles':
  192.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  193.                
  194.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  195.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  196.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  197.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  198.                 break;
  199.  
  200.             case 'staff':
  201.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  202.                
  203.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  204.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  205.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  206.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  207.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/moredata.js', true);
  208.                 break;
  209.  
  210.             case 'vip':
  211.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  212.                 //$this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/habboclub.css', true);
  213.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/newcredits.css', true);
  214.  
  215.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  216.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  217.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  218.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  219.                 //$this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/habboclub.js', true);
  220.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/newcredits.js', true);
  221.                 break;
  222.  
  223.             case 'safety':
  224.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  225.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/safety.css', true);
  226.                 //$this->addHeaderData('css', 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/3116/web-gallery/static/styles/embeddedregistration.css', true);
  227.                 //$this->addHeaderData('css', 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/3116/web-gallery/static/styles/identitysettings.css', true);
  228.                 //$this->addHeaderData('css', 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/3116/web-gallery/static/styles/embed.css', true);
  229.  
  230.                 //$this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/embed.js', true);
  231.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  232.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  233.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  234.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  235.                 break;
  236.  
  237.             case 'habbo_way':
  238.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  239.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/safety.css', true);
  240.  
  241.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  242.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  243.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  244.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  245.                 break;
  246.  
  247.             case 'safety_tips':
  248.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  249.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/safety.css', true);
  250.  
  251.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  252.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  253.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  254.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  255.                 break;
  256.  
  257.             case 'home':
  258.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  259.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/home.css', true);
  260.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/lightwindow.css', true);
  261.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/group.css', true);
  262.  
  263.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  264.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  265.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  266.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  267.                
  268.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/homeview.js', true);
  269.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/homeauth.js', true);
  270.                 //$this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/homeview.js', true);
  271.                
  272.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/lightwindow.css', true);
  273.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/group.css', true);
  274.                 break;
  275.             /*
  276.             case 'security':
  277.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  278.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/embeddedregistration.css', true);
  279.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/identitysettings.css', true);
  280.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/embed.css', true);
  281.  
  282.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/embed.js', true);
  283.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
  284.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
  285.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
  286.                 $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
  287.                 break;*/
  288.         }
  289.  
  290.         if (in_array(strtolower(THIS_PAGE), $this->nobuildtemplates) == false)
  291.         {
  292.             // Global CSS.
  293.             if (strtolower(THIS_PAGE) == 'frontpage')
  294.             {
  295.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/frontpage.css', true);
  296.  
  297.                 $this->addHeaderData('css', 'http://habbo.com/styles/local/com.css', true);
  298.             }
  299.             elseif (strtolower(THIS_PAGE) == 'quickregister')
  300.             {
  301.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  302.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/quickregister.css', true);
  303.  
  304.                 $this->addHeaderData('css', 'http://habbo.com/styles/local/com.css', true);
  305.             }
  306.             else
  307.             {
  308.                 $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
  309.  
  310.                 //$this->addHeaderData('css', 'http://habbo.com/styles/local/com.css', true);
  311.             }
  312.  
  313.             // Global JS.
  314.            
  315.  
  316.             $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/common.js', true);
  317.         }
  318.  
  319.         // System.
  320.         $this->addParameter('system_name', SYSTEM_NAME);
  321.         $this->addParameter('system_version', SYSTEM_VERSION);
  322.         $this->addParameter('system_author', SYSTEM_AUTHOR);
  323.         $this->addParameter('system_contributors', SYSTEM_CONTRIBUTORS);
  324.  
  325.         // Header.
  326.         $this->addParameter('meta_http-equiv', 'text/html; charset=utf-8');
  327.  
  328.         $this->addParameter('title', $ir->site_name_long . ' - ' . PAGE_NAME);
  329.  
  330.         $this->addParameter('meta_description', $ir->site_description . ' ' . $ir->getPoweredBy());
  331.         $this->addParameter('meta_keywords', $ir->site_name_long . ', ' . SYSTEM_NAME . ', Habbo, Hotel, Habbo Hotel, retro, avatar, fun, stable, free');
  332.         $this->addParameter('meta_author', SYSTEM_AUTHOR);
  333.         $this->addParameter('meta_generator', SYSTEM_NAME . ' ' . SYSTEM_VERSION);
  334.         $this->addParameter('meta_robots', 'index,follow');
  335.         $this->addParameter('meta_googlebot', 'index,follow');
  336.  
  337.         // All.
  338.         $this->addParameter('top_navigation', $ir->template->buildTopNavigation());
  339.         $this->addParameter('sub_navigation', $ir->template->buildSubNavigation());
  340.  
  341.         $this->addParameter('online_count', $ir->handlers->handleCache('h_oc', $ir->habbo, 'getOnline', null, 60));
  342.  
  343.         // Site.
  344.         $this->addParameter('webbuild', WEBBUILD);
  345.  
  346.         $this->addParameter('site_url', SITE_URL);
  347.  
  348.         $this->addParameter('site_name_long', $ir->site_name_long);
  349.         $this->addParameter('site_name_short', $ir->site_name_short);
  350.        
  351.         // Contact Us Email.
  352.         $this->addParameter('contact_us_email', CU_EMAIL);
  353.  
  354.         // Me.
  355.         $this->addParameter('hot_campaigns', $ir->handlers->handleCache('t_hc', $ir->template, 'buildHotCampaigns', '5', 60));
  356.  
  357.         $this->addParameter('powered_by_long', $ir->getPoweredByLong());
  358.         $this->addParameter('powered_by', $ir->getPoweredBy());
  359.        
  360.         // Client.
  361.         $this->addParameter('external_variables', '');
  362.         $this->addParameter('external_texts', '');
  363.         $this->addParameter('product_data', '');
  364.         $this->addParameter('furniture_data', '');
  365.         $this->addParameter('flash_client', '');
  366.         $this->addParameter('base_url', '');
  367.         $this->addParameter('habbo_swf', '');
  368.  
  369.         // ReCAPTCHA.
  370.         $this->addParameter('public_key', PUB_KEY);
  371.         $this->addParameter('private_key', PRIV_KEY);
  372.        
  373.         $this->addParameter('community', $language['community']);
  374.         $this->addParameter('news', $language['news']);
  375.         $this->addParameter('safety', $language['safety']);
  376.         $this->addParameter('administration', $language['administration']);
  377.        
  378.         $this->addParameter('home', $language['home']);
  379.         $this->addParameter('my_page', $language['my_page']);
  380.         $this->addParameter('account_settings', $language['account_settings']);
  381.         $this->addParameter('hc_vip', $language['hc_vip']);
  382.        
  383.         $this->addParameter('users_online', $language['users_online']);
  384.         $this->addParameter('habbo_staff', $language['habbo_staff']);
  385.         $this->addParameter('safety_tips', $language['safety_tips']);
  386.         $this->addParameter('habbo_way', $language['habbo_way']);
  387.        
  388.         foreach($language as $key => $value)
  389.         {
  390.             $ir->template->addParameter[$key] = $value;
  391.         }
  392.  
  393.         foreach($language as $key => $value)
  394.         {
  395.             $this->addParameter($key, $value);
  396.         }
  397.  
  398.         // Habbo.
  399.         if (IS_LOGGED_IN == true)
  400.         {
  401.             $this->addParameter('to_hotel', (($ir->habbo->getField('online', H_USER) == 1) ? '<a href="' . SITE_URL . 'client" id="enter-hotel-open-medium-link" onclick="return false;">Return to the Hotel</a>' : '<a href="' . SITE_URL . 'client" class="new-button green-button"><b>Enter ' . SITE_NAME_LONG . '</b><i></i></a>'));
  402.         }
  403.         else
  404.         {
  405.             $this->addParameter('to_hotel', '<a href="' . SITE_URL . 'quickregister/start" class="new-button green-button"><b>Register on ' . SITE_NAME_LONG . '</b><i></i></a>');
  406.             //$this->addParameter('', '');
  407.             //$this->addParameter('', '');
  408.         }
  409.  
  410.         $this->addParameter('user', H_USER);
  411.     }
  412.  
  413.     /*
  414.      *
  415.      * Private Function Page.
  416.      *
  417.      * Calls all the template buffering functions to determine the active style and to create the output buffer.
  418.      *
  419.      */
  420.     final private function buildPage()
  421.     {
  422.         global $ir;
  423.  
  424.         if ($ir->cache->existsCache('t_build' . THIS_PAGE) == false)
  425.         {
  426.             $this->style_id = &$this->gatherStyleData();
  427.             $this->output_buffer = &$this->gatherTemplateData();
  428.  
  429.             $buildPage = array(
  430.             'style_id'          =>      $this->style_id,
  431.             'output_buffer'     =>      $this->output_buffer
  432.             );
  433.  
  434.             if (in_array(strtolower(THIS_PAGE), $this->nocachetemplates) == false)
  435.             {
  436.                 $ir->cache->addCache('t_build' . THIS_PAGE, $buildPage, T_BUILD_PAGE_CACHE);
  437.             }
  438.         }
  439.         elseif ($ir->cache->existsCache('t_build' . THIS_PAGE) == true)
  440.         {
  441.             $buildPageCache = $ir->cache->fetchCache('t_build' . THIS_PAGE);
  442.  
  443.             $this->style_id =& $buildPageCache['style_id'];
  444.             $this->output_buffer =& $buildPageCache['output_buffer'];
  445.         }
  446.     }
  447.  
  448.     /*
  449.      *
  450.      * Public Function buildFact.
  451.      *
  452.      * Builds the did you know fact HTML from the database.
  453.      * This has been removed from the website since it's pointless.
  454.      *
  455.      * @return:     $result     string      Fact HTML.
  456.      *
  457.      */
  458.     final public function buildFact()
  459.     {
  460.         global $ir;
  461.  
  462.         $result = null;
  463.  
  464.         $query = $ir->db->executeQuery("SELECT f.fact
  465.                                            FROM " . TABLE_PREFIX . "facts f
  466.                                            ORDER BY RAND() ASC;");
  467.  
  468.         if ($ir->db->numRows($query) > 0)
  469.         {
  470.             $result = $ir->db->fetchObject($query)->fact;
  471.         }
  472.  
  473.         return $result;
  474.     }
  475.  
  476.     /*
  477.      *
  478.      * Public Function buildTopNavigation.
  479.      *
  480.      * Builds the top navigation HTML from the database.
  481.      *
  482.      * @return:     $result     string      Top navigation HTML.
  483.      *
  484.      */
  485.     final public function buildTopNavigation()
  486.     {
  487.         global $ir;
  488.  
  489.         $result = '';
  490.  
  491.         $query = $ir->db->executeQuery("SELECT n.id AS id, n.name AS name, n.url AS url
  492.                                            FROM " . TABLE_PREFIX . "navigation n
  493.                                            WHERE n.type = '1'
  494.                                                AND n.rank <= '{$ir->habbo->getField('rank', H_USER)}'
  495.                                            ORDER BY n.order_number ASC;");
  496.  
  497.         if ($ir->db->numRows($query) > 0)
  498.         {
  499.             while ($row = $ir->db->fetchObject($query))
  500.             {
  501.                 if ($row->id == THIS_PARENT_ID)
  502.                 {
  503.                     $result .= '<li class="metab selected">
  504.                                    <strong>' . $row->name . '</strong>
  505.                                    <span></span>
  506.                                </li>';
  507.                 }
  508.                 elseif ($row->id == 1)
  509.                 {
  510.                     $result .= '<li class="metab">
  511.                                    <a href="' . SITE_URL . $row->url . '">' . $row->name . '</a>
  512.                                    <span></span>
  513.                                </li>';
  514.                 }
  515.                 else
  516.                 {
  517.                     $result .= '<li>
  518.                                    <a href="' . SITE_URL . $row->url . '">' . $row->name . '</a>
  519.                                    <span></span>
  520.                                </li>';
  521.                 }
  522.             }
  523.         }
  524.  
  525.         return $result;
  526.     }
  527.  
  528.     /*
  529.      *
  530.      * Public Function buildSubNavigation.
  531.      *
  532.      * Builds the sub navigation HTML from the database.
  533.      *
  534.      * @return:     $result     string      Sub navigation HTML.
  535.      *
  536.      */
  537.     final public function buildSubNavigation()
  538.     {
  539.         global $ir;
  540.  
  541.         $result = '';
  542.  
  543.         $query = $ir->db->executeQuery("SELECT n.id AS id, n.name AS name, n.url AS url, n.new AS new
  544.                                            FROM " . TABLE_PREFIX . "navigation n
  545.                                            WHERE n.parent_id = '" . THIS_PARENT_ID . "'
  546.                                                AND n.type = '2'
  547.                                                AND n.rank <= '{$ir->habbo->getField('rank', H_USER)}'
  548.                                            ORDER BY n.order_number ASC;");
  549.  
  550.         if (($count = $ir->db->numRows($query)) > 0)
  551.         {
  552.             $loopcount = 1;
  553.  
  554.             while ($row = $ir->db->fetchObject($query))
  555.             {
  556.                 if ($row->id == THIS_SUB_ID)
  557.                 {
  558.                     if ($count == $loopcount)
  559.                     {
  560.                         $result .= '<li class="selected last">
  561.                                        ' . $row->name . '
  562.                                    </li>';
  563.                     }
  564.                     else
  565.                     {
  566.                         $result .= '<li class="selected">
  567.                                        ' . $row->name . '
  568.                                    </li>';
  569.                     }
  570.                 }
  571.                 elseif ($count == $loopcount)
  572.                 {
  573.                     $result .= '<li class="last">
  574.                                    <a href="' . SITE_URL . $row->url . '">' . $row->name . '</a>' . (($row->new == 0) ? '' : ' <span style="float: right; color: red; font-size: 8px;">&nbsp; new</span>') . '
  575.                                </li>';
  576.                 }
  577.                 else
  578.                 {
  579.                     $result .= '<li>
  580.                                    <a href="' . SITE_URL . $row->url . '">' . $row->name . '</a>' . (($row->new == 0) ? '' : ' <span style="float: right; color: red; font-size: 8px;">&nbsp; new</span>') . '
  581.                                </li>';
  582.                 }
  583.  
  584.                 $loopcount++;
  585.             }
  586.         }
  587.  
  588.         return $result;
  589.     }
  590.  
  591.     /*
  592.      *
  593.      * Public Function buildEvents.
  594.      *
  595.      * Builds the events HTML from the database.
  596.      *
  597.      * @return:     $result     string      Events HTML.
  598.      *
  599.      */
  600.     final public function buildEvents()
  601.     {
  602.         global $ir;
  603.  
  604.         $result = '<li class="small" id="feed-hc-reminder">Project H is still in development, some features may not be there or just not working correctly.</li>';
  605.  
  606.         $result = '<li class="small" id="feed-hc-reminder">Project H is still in development, some features may not be there or just not working correctly.</li>';
  607.  
  608.         return $result;
  609.     }
  610.    
  611.     /*
  612.      *
  613.      * Public Function checkFriendRequests.
  614.      *
  615.      * Checks user has friend requests then outputs HTML.
  616.      *
  617.      * @return:     $result     string      Events HTML.
  618.      *
  619.      */
  620.     final public function checkFriendRequests()
  621.     {
  622.         global $ir;
  623.        
  624.         $uid = $ir->habbo->getField('id', H_USER);
  625.  
  626.         $query1 = $ir->db->executeQuery("SELECT id FROM messenger_requests WHERE to_id = {$uid}");
  627.        
  628.         $count = $ir->db->numRows($query1);
  629.         $i = 0;
  630.        
  631.         while($row = mysqli_fetch_row($query1))
  632.         {
  633.             $i++;
  634.            
  635.             if ($count == 0)
  636.             {
  637.                 $result = '';
  638.             }
  639.             elseif ($count == 1)
  640.             {
  641.                 $result = '<li id="feed-notification">You have <a href="client">' . $count . ' friend request.</a></li>';
  642.             }
  643.             else
  644.             {
  645.                 $result = '<li id="feed-notification">You have <a href="client">' . $count . ' friend requests.</a></li>';
  646.             }
  647.     }
  648.         /*
  649.         if ($ir->db->numRows($query1) > 0)
  650.         {
  651.             $result = '<li id="feed-notification">You currently have <b>' . $query1 . '</b> friend requests.';
  652.         }
  653.         else
  654.         {
  655.             $result = '';
  656.         }*/
  657.        
  658.         return $result;
  659.     }
  660.  
  661.  
  662.     /*
  663.      *
  664.      * Public Function checkFriendsOnline.
  665.      *
  666.      * Checks for friends online and output HTML for friends online event.
  667.      *
  668.      * @todo: All friends online.
  669.      *
  670.      * @return:     $result     string      Friends Online HTML.
  671.      *
  672.      */
  673.      final public function checkFriendsOnline()
  674.      {
  675.         global $ir;
  676.        
  677.         $uid = $ir->habbo->getField('id', H_USER);
  678.        
  679.         $query1 = $ir->db->executeQuery("SELECT users.username FROM users INNER JOIN messenger_friendships ON users.id = messenger_friendships.user_one_id WHERE users.online = '1' AND messenger_friendships.user_two_id = {$uid}");
  680.        
  681.         $count = $ir->db->numRows($query1);
  682.         $i = 0;
  683.        
  684.         //return '<li id="feed-friends">You have <b>' . $count . '</b> friends online: ';
  685.            
  686.         while($row = mysqli_fetch_array($query1))
  687.         {
  688.             $i++;
  689.            
  690.             $friend = $row[0];
  691.            
  692.             if($i < $count)
  693.             {
  694.                 $comma = ", ";
  695.             }
  696.                
  697.             $nl = "\n";
  698.            
  699.             $friendsOn .= $friend . $comma . $nl;
  700.     }
  701.        
  702.         if ($count == 0)
  703.         {
  704.             return '<li id="feed-friends">You have <b>' . $count . '</b> friends online.</li>';
  705.         }
  706.         elseif ($count == 1)
  707.         {
  708.             return '<li id="feed-friends">You have <b>' . $count . '</b> friend online: <a href="client">' . $friendsOn . '</a></li>';
  709.            
  710.         }
  711.         else
  712.         {
  713.             return '<li id="feed-friends">You have <b>' . $count . '</b> friends online: <a href="client">' . $friendsOn . '</a></li>';
  714.            
  715.         }
  716.      }
  717.      
  718.     /*
  719.      *
  720.      * Public Function checkTradingLock.
  721.      *
  722.      * Checks if trading is enabled or not and output HTML for trading event.
  723.      *
  724.      * @return:     $result     string      Trading Lock HTML.
  725.      *
  726.      */
  727.      final public function checkTradingLock()
  728.      {
  729.         global $ir, $language;
  730.  
  731.         if ($ir->habbo->getField('trade_lock', H_USER) == 1)
  732.         {
  733.             return '<li class="small" id="feed-trading-disabled">' . $language['trading_eventoff'] . ' <a href="profile?tab=1">' . $language['trading_clickhere_on'] . '</a></li>';
  734.         }
  735.         else
  736.         {
  737.             return '<li class="small" id="feed-trading-enabled">' . $language['trading_eventon'] . ' <a href="profile?tab=1">' . $language['trading_clickhere_off'] . '</a></li>';
  738.         }
  739.      }
  740.      
  741.          /*
  742.      *
  743.      * Public Function checkFriendLock.
  744.      *
  745.      * Checks if trading is enabled or not and output HTML for trading event.
  746.      *
  747.      * @return:     $result     string      Friend Lock HTML.
  748.      *
  749.      */
  750.      final public function checkFriendLock()
  751.      {
  752.         global $ir;
  753.  
  754.         if ($ir->habbo->getField('block_newfriends', H_USER) == 1)
  755.         {
  756.             return '<li id="feed-friends">Friend requests are turned off. <a href="profile?tab=1">Click here to turn it on</a></li>';
  757.         }
  758.         else
  759.         {
  760.             //return '<li id="feed-friends">Friend requests are turned on. <a href="profile?tab=1">Click here to turn it off</a></li>';
  761.         }
  762.      }
  763.  
  764.     /*
  765.      *
  766.      * Public Function checkModerationTickets.
  767.      *
  768.      * Checks if trading is enabled or not and output HTML for trading event.
  769.      *
  770.      * @todo: All moderation ticket warnings.
  771.      *
  772.      * @return:     $result     string      Moderation Tickets HTML.
  773.      *
  774.      */
  775.      final public function checkModerationTickets()
  776.      {
  777.         global $ir;
  778.        
  779.         $query1 = $ir->db->executeQuery("");
  780.        
  781.  
  782.         if ($ir->habbo->getField('trade_lock', H_USER) == 1)
  783.         {
  784.             return '<li class="small" id="feed-trading-disabled">Trading is off. <a href="profile?tab=1">Click here to turn it on</a></li>';
  785.         }
  786.         else
  787.         {
  788.             return '<li class="small" id="feed-trading-enabled">Trading is on. <a href="profile?tab=1">Click here to turn it off</a></li>';
  789.         }
  790.      }
  791.  
  792.     /*
  793.      *
  794.      * Public Function buildImageSelect.
  795.      *
  796.      * Builds the image select HTML from the database.
  797.      *
  798.      * @return:     $result     string      Image Select HTML.
  799.      *
  800.      * @todo: take out the caching and use the handler object.
  801.      *
  802.      */
  803.     final public function buildImageSelect()
  804.     {
  805.         global $ir;
  806.  
  807.         $result = '';
  808.         $spath = CWD . '/images/top_stories/';
  809.         $wpath = SITE_URL . '/images/top_stories/';
  810.  
  811.         $result .= '<select name="n.image_url">';
  812.  
  813.         if ($ir->cache->existsCache('ts_Images') == false)
  814.         {
  815.             $folder = opendir($spath);
  816.  
  817.             $pic_types = array('gif', 'png');
  818.  
  819.             $index = array();
  820.  
  821.             while ($file = readdir($folder))
  822.             {
  823.                 if (in_array(substr(strtolower($file), strrpos($file, '.') + 1), $pic_types) == true)
  824.                 {
  825.                     array_push($index, $file);
  826.                 }
  827.             }
  828.  
  829.             closedir($folder);
  830.  
  831.             $ir->cache->addCache('ts_Images', $index, 0);
  832.         }
  833.         else
  834.         {
  835.             $index = $ir->cache->fetchCache('ts_Images');
  836.         }
  837.  
  838.         foreach ($index AS $value)
  839.         {
  840.             $result .= '<option value="' . ($wpath . $value) . '">' . $value . '</option>';
  841.         }
  842.  
  843.         $result .= '</select>';
  844.  
  845.         return $result;
  846.     }
  847.  
  848.     /*
  849.      *
  850.      * Public Function buildHotCampaigns.
  851.      *
  852.      * Builds the hot campaigns HTML from the database.
  853.      *
  854.      * @param:      $max        int         Maximum number of results to return.
  855.      *
  856.      * @return:     $result     string      Hot campaigns HTML.
  857.      *
  858.      */
  859.     final public function buildHotCampaigns($max)
  860.     {
  861.         global $ir;
  862.  
  863.         $result = '';
  864.  
  865.         $query = $ir->db->executeQuery("SELECT c.title AS title, c.description AS description, c.url AS url, c.image_url AS image_url
  866.                                            FROM " . TABLE_PREFIX . "campaigns c
  867.                                            WHERE c.active = '1'
  868.                                            ORDER BY RAND() ASC
  869.                                            LIMIT 0,{$max};");
  870.  
  871.         if (($count = $ir->db->numRows($query)) > 0)
  872.         {
  873.             $loopcount = 0;
  874.  
  875.             while ($row = $ir->db->fetchObject($query))
  876.             {
  877.                 if ($loopcount == 0)
  878.                 {
  879.                     $result .= '<li class="even">
  880.                                    <div class="hotcampaign-container">
  881.                                        <a href="' . $row->url . '"><img src="' . $row->image_url . '" align="left" alt="" /></a>
  882.                                        <h3>' . $row->title . '</h3>
  883.                                        <p>' . $row->description . '</p>
  884.                                        <!-- <p class="link"><a href="' . $row->url . '">Go there &raquo;</a></p> -->
  885.                                    </div>
  886.                                </li>';
  887.  
  888.                     $loopcount++;
  889.                 }
  890.                 else
  891.                 {
  892.                     $result .= '<li class="odd">
  893.                                    <div class="hotcampaign-container">
  894.                                        <a href="' . $row->url . '"><img src="' . $row->image_url . '" align="left" alt="" /></a>
  895.                                        <h3>' . $row->title . '</h3>
  896.                                        <p>' . $row->description . '</p>
  897.                                        <!-- <p class="link"><a href="' . $row->url . '">Go there &raquo;</a></p> -->
  898.                                    </div>
  899.                                </li>';
  900.  
  901.                     $loopcount--;
  902.                 }
  903.             }
  904.         }
  905.  
  906.         return $result;
  907.     }
  908.  
  909.     /*
  910.      *
  911.      * Public Function buildTopStories.
  912.      *
  913.      * Builds the top stories HTML from the database.
  914.      *
  915.      * @return:     $result     string      Top stories HTML.
  916.      *
  917.      */
  918.     final public function buildTopStories()
  919.     {
  920.         global $ir;
  921.  
  922.         $result = '';
  923.  
  924.         $query = $ir->db->executeQuery("SELECT a.id AS id, a.title AS title, a.summary AS summary, a.image_url AS image_url
  925.                                            FROM " . TABLE_PREFIX . "articles a
  926.                                            ORDER BY a.id DESC
  927.                                            LIMIT 0,5;");
  928.  
  929.         if (($count = $ir->db->numRows($query)) > 0)
  930.         {
  931.             $first = false;
  932.  
  933.             while ($row = $ir->db->fetchObject($query))
  934.             {
  935.                 if ($first == false)
  936.                 {
  937.                     $result .= '<div class="topstory" style="background-image: url(' . $row->image_url . ');">
  938.                                    <h4>Latest news</h4>
  939.                                    <h3><a href="' . SITE_URL . 'articles/' . $row->id . '">' . $row->title . '</a></h3>
  940.                                    <p class="summary">
  941.                                        ' . $row->summary . '
  942.                                    </p>
  943.                                    <p>
  944.                                        <a href="' . SITE_URL . 'articles/' . $row->id . '">Read more &raquo;</a>
  945.                                    </p>
  946.                                </div>';
  947.  
  948.                     $first = true;
  949.                 }
  950.                 else
  951.                 {
  952.                     $result .= '<div class="topstory" style="background-image: url(' . $row->image_url . '); display: none;">
  953.                                    <h4>Latest news</h4>
  954.                                    <h3><a href="' . SITE_URL . 'articles/' . $row->id . '">' . $row->title . '</a></h3>
  955.                                    <p class="summary">
  956.                                        ' . $row->summary . '
  957.                                    </p>
  958.                                    <p>
  959.                                        <a href="' . SITE_URL . 'articles/' . $row->id . '">Read more &raquo;</a>
  960.                                    </p>
  961.                                </div>';
  962.                 }
  963.             }
  964.  
  965.             $result .= '<div id="topstories-nav" style="display: none"><a href="#" class="prev">&laquo; Previous</a><span>1</span> / ' . $count . '<a href="#" class="next">Next &raquo;</a></div>';
  966.         }
  967.  
  968.         return $result;
  969.     }
  970.  
  971.     /*
  972.      *
  973.      * Public Function buildSubStories.
  974.      *
  975.      * Builds the sub stories HTML from the database.
  976.      *
  977.      * @return:     $result     string      Sub stories HTML.
  978.      *
  979.      */
  980.     final public function buildSubStories()
  981.     {
  982.         global $ir;
  983.  
  984.         $result = '';
  985.  
  986.         $query = $ir->db->executeQuery("SELECT a.id AS id, a.title AS title, a.timestamp AS timestamp
  987.                                            FROM " . TABLE_PREFIX . "articles a
  988.                                            ORDER BY a.id DESC
  989.                                            LIMIT 5,2;");
  990.  
  991.         if (($count = $ir->db->numRows($query)) > 0)
  992.         {
  993.             $first = false;
  994.  
  995.             while ($row = $ir->db->fetchObject($query))
  996.             {
  997.                 if ($first == false)
  998.                 {
  999.                     $result .= '<li class="even">
  1000.                                    <a href="' . SITE_URL . 'articles/' . $row->id . '">' . $row->title . ' &raquo;</a><div class="newsitem-date">' . $row->timestamp . '</div>
  1001.                                </li>';
  1002.  
  1003.                     $first = true;
  1004.                 }
  1005.                 else
  1006.                 {
  1007.                     $result .= '<li class="odd">
  1008.                                    <a href="' . SITE_URL . 'articles/' . $row->id . '">' . $row->title . ' &raquo;</a><div class="newsitem-date">' . $row->timestamp . '</div>
  1009.                                </li>';
  1010.                 }
  1011.             }
  1012.         }
  1013.         else
  1014.         {
  1015.             $result .= '<li class="even">
  1016.                            No articles to be displayed.
  1017.                        </li>';
  1018.         }
  1019.  
  1020.         return $result;
  1021.     }
  1022.  
  1023.     /*
  1024.      *
  1025.      * Public Function buildHotRooms.
  1026.      *
  1027.      * Builds the hot rooms HTML from the database.
  1028.      *
  1029.      * @return:     $result     string      Hot rooms HTML.
  1030.      *
  1031.      */
  1032.     final public function buildHotRooms($max)
  1033.     {
  1034.         global $ir;
  1035.  
  1036.         $result = '';
  1037.  
  1038.         $query = $ir->db->executeQuery("SELECT r.id AS id, r.caption AS caption, r.owner AS owner, r.users_now AS users_now, r.users_max AS users_max
  1039.                                            FROM rooms r
  1040.                                            ORDER BY r.users_now DESC
  1041.                                            LIMIT 0,{$max};");
  1042.  
  1043.         if ($ir->db->numRows($query) > 0)
  1044.         {
  1045.             $status = true;
  1046.  
  1047.             while ($row = $ir->db->fetchObject($query))
  1048.             {
  1049.                 if ($status == true)
  1050.                 {
  1051.                     $status = 'even';
  1052.                 }
  1053.                 else
  1054.                 {
  1055.                     $status = 'odd';
  1056.                 }
  1057.  
  1058.                 // Double.
  1059.                 $population = ($row->users_now / $row->users_max);
  1060.  
  1061.                 if ($population >= 1.00)
  1062.                 {
  1063.                     $level = '5';
  1064.                 }
  1065.                 elseif ($population <= 0.99 && $population >= 0.51)
  1066.                 {
  1067.                     $level = '4';
  1068.                 }
  1069.                 elseif ($population <= 0.50 && $population >= 0.26)
  1070.                 {
  1071.                     $level = '3';
  1072.                 }
  1073.                 elseif ($population <= 0.25 && $population >= 0.01)
  1074.                 {
  1075.                     $level = '2';
  1076.                 }
  1077.                 else
  1078.                 {
  1079.                     $level = '1';
  1080.                 }
  1081.  
  1082.                 $result .= '<li class="' . $status . ' room-occupancy-' . $level . '" roomid="' . $row->id . '">
  1083.                                <div>
  1084.                                    <span class="event-name">
  1085.                                        <a href="#">' . $row->caption . '</a>
  1086.                                    </span>
  1087.                                    <span class="event-owner"> by <a href="#">' . $row->owner . '</a></span>
  1088.                                    <p>&nbsp;</p>
  1089.                                </div>
  1090.                            </li>';
  1091.  
  1092.                 if ($status == 'even')
  1093.                 {
  1094.                     $status = false;
  1095.                 }
  1096.                 else
  1097.                 {
  1098.                     $status = true;
  1099.                 }
  1100.             }
  1101.         }
  1102.  
  1103.         return $result;
  1104.     }
  1105.  
  1106.     /*
  1107.      *
  1108.      * Public Function buildComments.
  1109.      *
  1110.      * Fetches all the comment HTML from an article.
  1111.      *
  1112.      * @return:     $result         string         The comments HTML.
  1113.      *
  1114.      */
  1115.     final public function buildComments(&$id)
  1116.     {
  1117.         global $ir;
  1118.  
  1119.         $result = '';
  1120.         $query = $ir->db->executeQuery("SELECT u.username AS username, u.look AS look, c.comment AS comment
  1121.                                            FROM " . TABLE_PREFIX . "comments c
  1122.                                            INNER JOIN users u
  1123.                                            ON u.id = c.user_id
  1124.                                            WHERE c.article_id = '{$id}'
  1125.                                            ORDER BY c.id ASC;");
  1126.  
  1127.         if ($ir->db->numRows($query) > 0)
  1128.         {
  1129.             $count = 1;
  1130.  
  1131.             while ($row = $ir->db->fetchObject($query))
  1132.             {
  1133.                 $result .= '<table style="padding: 5px; width: 100%; background-color: #fff;">
  1134.                                <tbody>
  1135.                                <tr>
  1136.                                    <td valign="middle" width="25">
  1137.                                        <img style="margin-top: -16px; " src="http://www.habbo.fr/habbo-imaging/avatarimage?figure=' . $row->look . '" />
  1138.                                    </td>
  1139.                                    <td valign="top">
  1140.                                        <b style="font-size: 120%;">' . $row->username . '</b><br /><br />
  1141.                                        <p style="background-color: #f2f2f2; padding: 5px; width: 400px;">' . $row->comment . '</p>
  1142.                                    </td>
  1143.                                    <td style="float: right;">
  1144.                                        <span style="color: #747474;">#' . $count++ . '</span>
  1145.                                    </td>
  1146.                                </tr>
  1147.                                </tbody>
  1148.                            </table>';
  1149.             }
  1150.         }
  1151.         else
  1152.         {
  1153.             $result = '<p><i>There are no comments on this article.</i></p>';
  1154.         }
  1155.  
  1156.         return $result;
  1157.     }
  1158.  
  1159.     /*
  1160.      *
  1161.      * Private Function gatherStyleData.
  1162.      *
  1163.      * Determines the active style and fetches its information.
  1164.      *
  1165.      * @return:     $result         int         Active style ID (returned by reference).
  1166.      *
  1167.      */
  1168.     final private function &gatherStyleData()
  1169.     {
  1170.         global $ir;
  1171.  
  1172.         $result = null;
  1173.         $query = $ir->db->executeQuery("SELECT s.id
  1174.                                            FROM " . TABLE_PREFIX . "styles s
  1175.                                            WHERE s.active = '1';");
  1176.  
  1177.         if ($ir->db->numRows($query) == 1)
  1178.         {
  1179.             $result =& $ir->db->fetchObject($query)->id;
  1180.         }
  1181.         else
  1182.         {
  1183.             // Error, there are zero or multiple active styles.
  1184.         }
  1185.  
  1186.         return $result;
  1187.     }
  1188.  
  1189.     /*
  1190.      *
  1191.      * Private Function gatherHeaderData.
  1192.      *
  1193.      * Gathers all of the pre-defined header html (css and javascript).
  1194.      *
  1195.      * @param:      $type           string      Type of header data to fetch from the database.
  1196.      *
  1197.      * @return:     $header_buffer  string      Header data.
  1198.      *
  1199.      */
  1200.     final private function gatherHeaderData($type)
  1201.     {
  1202.         global $ir;
  1203.  
  1204.         $header_buffer = '';
  1205.         $prefix = null;
  1206.         $suffix = null;
  1207.  
  1208.         $query = $ir->db->executeQuery("SELECT h.content AS content
  1209.                                            FROM " . TABLE_PREFIX . "{$type} h
  1210.                                            WHERE h.style_id = '{$this->style_id}'
  1211.                                                AND h.active = '1';");
  1212.  
  1213.         if ($ir->db->numRows($query) > 0)
  1214.         {
  1215.             switch ($type)
  1216.             {
  1217.                 case 'css':
  1218.                     $prefix = '<style type="text/css">';
  1219.                     $suffix = '</style>';
  1220.                     break;
  1221.  
  1222.                 case 'js':
  1223.                     $prefix = '<script type="text/javascript">';
  1224.                     $suffix = '</script>';
  1225.                     break;
  1226.             }
  1227.  
  1228.             while ($row = $ir->db->fetchObject($query))
  1229.             {
  1230.                 $header_buffer .= $prefix . $row->content . $suffix;
  1231.             }
  1232.         }
  1233.  
  1234.         return $header_buffer;
  1235.     }
  1236.  
  1237.     /*
  1238.      *
  1239.      * Private Function gatherExtraHeaderData.
  1240.      *
  1241.      * Gathers all of the extra header html (css and javascript).
  1242.      *
  1243.      * @return:     $header_buffer  string      Header data.
  1244.      *
  1245.      */
  1246.     final private function gatherExtraHeaderData()
  1247.     {
  1248.         $header_buffer = '';
  1249.  
  1250.         foreach ($this->header_data AS $value)
  1251.         {
  1252.             $header_buffer .= $value;
  1253.         }
  1254.  
  1255.         return $header_buffer;
  1256.     }
  1257.  
  1258.     /*
  1259.      *
  1260.      * Private Function gatherTemplateData.
  1261.      *
  1262.      * Gathers all the template html from the database.
  1263.      *
  1264.      * @return:     $template_buffer    string      Template html (returned by reference).
  1265.      *
  1266.      */
  1267.     final private function &gatherTemplateData()
  1268.     {
  1269.         global $ir;
  1270.  
  1271.         $template_buffer = '';
  1272.         $parsedTemplates = '\'' . implode('\', \'', $this->templates) . '\'';
  1273.  
  1274.         $query = $ir->db->executeQuery("SELECT t.name AS name, t.content AS content
  1275.                                            FROM " . TABLE_PREFIX . "templates t
  1276.                                            WHERE t.style_id = '{$this->style_id}'
  1277.                                                AND t.active = '1'
  1278.                                                AND t.name IN ({$parsedTemplates})
  1279.                                            ORDER BY t.order_number ASC;");
  1280.  
  1281.         if ($ir->db->numRows($query) > 0)
  1282.         {
  1283.             while ($row = $ir->db->fetchObject($query))
  1284.             {
  1285.                 //$template_buffer .= '<!-- (s) Template: "' . $row->name . '" -->' . $row->content . '<!-- (e) Template: "' . $row->name . '" -->';
  1286.                 $template_buffer .= $row->content;
  1287.  
  1288.                 // Handles placement of Header Data.
  1289.                 if ($row->name == 'header')
  1290.                 {
  1291.                     $template_buffer .= $this->gatherHeaderData('css');
  1292.                     $template_buffer .= $this->gatherHeaderData('js');
  1293.  
  1294.                     $template_buffer .= $this->gatherExtraHeaderData();
  1295.                 }
  1296.  
  1297.                 if ($row->name == strtolower(THIS_PAGE))
  1298.                 {
  1299.                     $template_buffer .= $this->page_buffer;
  1300.                 }
  1301.             }
  1302.         }
  1303.  
  1304.         return $template_buffer;
  1305.     }
  1306.  
  1307.     /*
  1308.      *
  1309.      * Public Function addToBuffer.
  1310.      *
  1311.      * Adds html to the page buffer.
  1312.      *
  1313.      * @param:      $string       string       HTML content being added to the page_buffer variable.
  1314.      *
  1315.      */
  1316.     final public function addToBuffer($string, $page = false)
  1317.     {
  1318.         global $ir;
  1319.  
  1320.         if ($page == true)
  1321.         {
  1322.             // Change from style_id 1 to proper style_id variable.
  1323.             $query = $ir->db->executeQuery("SELECT t.content AS content
  1324.                                                FROM " . TABLE_PREFIX . "templates t
  1325.                                                WHERE t.name = '{$string}'
  1326.                                                    AND t.active = '0'
  1327.                                                    AND t.style_id = '1'
  1328.                                                LIMIT 0,1;");
  1329.  
  1330.             if ($ir->db->numRows($query) == 1)
  1331.             {
  1332.                 //$this->page_buffer .= $this->parseParameters($ir->db->fetchObject($query)->content, true);
  1333.                 $this->page_buffer .= $ir->db->fetchObject($query)->content;
  1334.             }
  1335.             else
  1336.             {
  1337.                 // Error, page does not exist.
  1338.             }
  1339.         }
  1340.         else
  1341.         {
  1342.             $this->page_buffer .= $this->parseParameters($string, true);
  1343.         }
  1344.     }
  1345.  
  1346.     /*
  1347.      *
  1348.      * Public Function addParameter.
  1349.      *
  1350.      * Adds a parameter (key => value) to the parameters array.
  1351.      *
  1352.      * @param:      $key        string      ID of the parameter.
  1353.      * @param:      $value      string      Value of the parameter.
  1354.      * @param:      $overwrite  bool        Whether to overwrite an existing parameter or not.
  1355.      *
  1356.      */
  1357.     final public function addParameter($key, $value, $overwrite = false)
  1358.     {
  1359.         if ($overwrite == false)
  1360.         {
  1361.             if (array_key_exists($key, $this->parameters) == false)
  1362.             {
  1363.                 $this->parameters[$key] = $value;
  1364.             }
  1365.             else
  1366.             {
  1367.                 // Error, key already exists.
  1368.             }
  1369.         }
  1370.         else
  1371.         {
  1372.             if (array_key_exists($key, $this->parameters) == true)
  1373.             {
  1374.                 unset($this->parameters[$key]);
  1375.             }
  1376.             else
  1377.             {
  1378.                 // Error, key does not exist.
  1379.             }
  1380.  
  1381.             $this->addParameter($key, $value);
  1382.         }
  1383.     }
  1384.  
  1385.     /*
  1386.      *
  1387.      * Public Function addHeaderData.
  1388.      *
  1389.      * Adds header data to the header_data array.
  1390.      *
  1391.      * @param:      $type       string      Type of data being added (css or js).
  1392.      * @param:      $value      string      Value of the data.
  1393.      * @param:      $src        bool        Whether to use the src tag or not.
  1394.      *
  1395.      */
  1396.     final public function addHeaderData($type, $value, $src)
  1397.     {
  1398.         if (in_array($value, $this->header_data) == false)
  1399.         {
  1400.             switch ($type)
  1401.             {
  1402.                 case 'css':
  1403.                     if ($src == true)
  1404.                     {
  1405.                         $this->header_data[] = '<link rel="stylesheet" type="text/css" href="' . $value . '" screen="media" />';
  1406.                     }
  1407.                     else
  1408.                     {
  1409.                         $this->header_data[] = '<style type="text/css">' . $value . '</style>';
  1410.                     }
  1411.                     break;
  1412.  
  1413.                 case 'js':
  1414.                     if ($src == true)
  1415.                     {
  1416.                         $this->header_data[] = '<script type="text/javascript" src="' . $value . '"></script>';
  1417.                     }
  1418.                     else
  1419.                     {
  1420.                         $this->header_data[] = '<script type="text/javascript" async>' . $value . '</script>';
  1421.                     }
  1422.                     break;
  1423.             }
  1424.         }
  1425.     }
  1426.  
  1427.     /*
  1428.      *
  1429.      * Public Function parseOutputBuffer.
  1430.      *
  1431.      * Parses the output buffer by filtering the parameters and stripping HTML.
  1432.      *
  1433.      * @param:      $output_buffer      string      String to be parsed (passed by reference).
  1434.      *
  1435.      */
  1436.     final public function parseOutputBuffer(&$output_buffer)
  1437.     {
  1438.         $this->parseParameters($output_buffer);
  1439.         //$this->parseHTML($output_buffer);
  1440.     }
  1441.  
  1442.     /*
  1443.      *
  1444.      * Private Function parseParameters.
  1445.      *
  1446.      * Parses the parameters in the output buffer.
  1447.      *
  1448.      * @param:      $output_buffer      string      String to be parsed (passed by reference).
  1449.      * @param:      $return             bool        Determines whether the function returns anything or not.
  1450.      *
  1451.      * @return:     $var                mixed       Output buffer parsed.
  1452.      *
  1453.      */
  1454.     final private function parseParameters(&$output_buffer, $return = false)
  1455.     {
  1456.         if (count($this->parameters) > 0)
  1457.         {
  1458.             foreach ($this->parameters AS $key => $value)
  1459.             {
  1460.                 $lkey = strtolower($key);
  1461.  
  1462.                 $output_buffer = str_replace('%' . $lkey . '%', $value, $output_buffer);
  1463.             }
  1464.         }
  1465.  
  1466.         if ($return == true)
  1467.         {
  1468.             return $output_buffer;
  1469.         }
  1470.     }
  1471.    
  1472.     /*
  1473.      *
  1474.      * Private Function parseHTML.
  1475.      *
  1476.      * Strips the HTML in the output buffer.
  1477.      *
  1478.      * @param:      $output_buffer      string      String to be parsed (passed by reference).
  1479.      *
  1480.      */
  1481.     final private function parseHTML(&$output_buffer)
  1482.     {
  1483.         // @source: http://ru.php.net/manual/en/function.ob-start.php#71953
  1484.         $search = array(
  1485.         '/\>[^\S ]+/s',
  1486.         '/[^\S ]+\</s',
  1487.         '/(\s)+/s'
  1488.         );
  1489.  
  1490.         $replace = array(
  1491.         '>',
  1492.         '<',
  1493.         '\\1'
  1494.         );
  1495.  
  1496.         $output_buffer = preg_replace($search, $replace, $output_buffer);
  1497.     }
  1498.  
  1499.     /*
  1500.      *
  1501.      * Public Function getOutputBuffer.
  1502.      *
  1503.      * Builds the page and gets the output buffer.
  1504.      *
  1505.      * @return:     $this->output_buffer        string      Buffered output from the buildPage function.
  1506.      *
  1507.      */
  1508.     final public function &getOutputBuffer()
  1509.     {
  1510.         $this->buildPage();
  1511.  
  1512.         return $this->output_buffer;
  1513.     }
  1514.  
  1515.     final public function __destruct() { }
  1516. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement