Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* ************************************************************ *\
- |* * COPYRIGHT (C) 2011 NOBRAIN. ALL RIGHTS RERSERVED. * *|
- |* ************************************************************ *|
- |* * This software is licensed under the Common Development * *|
- |* * and Distribution License Version 1 license. This * *|
- |* * software is open source. * *|
- |* * http://opensource.org/licenses/CDDL-1.0 * *|
- |* ************************************************************ *|
- |* * Project H is an advanced Habbo content management * *|
- |* * system that brings features from the past and present * *|
- |* * into one core system. * *|
- |* ************************************************************ *|
- |* * @product: Project H * *|
- |* * @author: nobrain * *|
- \* ************************************************************ */
- /*
- *
- * Template class.
- *
- * Handles all of the softwares template functionality.
- *
- */
- class Template
- {
- private $style_id = null;
- private $templates = null;
- private $parameters = array();
- private $header_data = array();
- private $output_buffer = null;
- private $page_buffer = '';
- private $nocachetemplates = array(
- 'quickregister',
- 'profile',
- 'dashboard'
- );
- private $nobuildtemplates = array(
- 'client'
- );
- /*
- *
- * Public Function class constructor.
- *
- * Puts the list of templates to call in the $templates class variable. Initializes the generic environment variables.
- *
- * @param: $templates Array of templates to call.
- *
- */
- final public function __construct($templates)
- {
- if ($templates != null)
- {
- $this->templates =& $templates;
- }
- else
- {
- // Error, invalid merged templates.
- }
- }
- /*
- *
- * Public Function initialize.
- *
- * Initializes core functions.
- *
- */
- final public function initialize()
- {
- require_once CWD . INCLUDES . LANGUAGES . SITE_LANG . '.php';
- $this->setGenericData();
- }
- /*
- *
- * Private Function setGenericData.
- *
- * Sets the generic template data.
- *
- */
- final private function setGenericData()
- {
- global $ir, $language;
- switch (strtolower(THIS_PAGE))
- {
- case 'frontpage':
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/landing.js', true);
- break;
- case 'quickregister':
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/quickregister.js', true);
- break;
- case 'me':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/personal.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/minimail.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/home.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/lightwindow.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/group.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/homeview.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/homeauth.js', true);
- //$this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/homeview.js', true);
- break;
- case 'me2':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/personal.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/minimail.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- break;
- case 'community':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/moredata.js', true);
- break;
- case 'shops':
- $this->addHeaderData('css', 'http://images.habbo.com/habboweb/' . WEBBUILD . '/web-gallery/static/styles/cbs2credits.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- break;
- case 'badgeshop':
- $this->addHeaderData('css', 'http://images.habbo.com/habboweb/' . WEBBUILD . '/web-gallery/static/styles/cbs2credits.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- break;
- case 'profile':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/settings.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/settings.js', true);
- break;
- case 'dashboard':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/settings.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- break;
- case 'articles':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- break;
- case 'staff':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/moredata.js', true);
- break;
- case 'vip':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- //$this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/habboclub.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/newcredits.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- //$this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/habboclub.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/newcredits.js', true);
- break;
- case 'safety':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/safety.css', true);
- //$this->addHeaderData('css', 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/3116/web-gallery/static/styles/embeddedregistration.css', true);
- //$this->addHeaderData('css', 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/3116/web-gallery/static/styles/identitysettings.css', true);
- //$this->addHeaderData('css', 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/3116/web-gallery/static/styles/embed.css', true);
- //$this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/embed.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- break;
- case 'habbo_way':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/safety.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- break;
- case 'safety_tips':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/safety.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- break;
- case 'home':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/home.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/lightwindow.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/group.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/homeview.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/homeauth.js', true);
- //$this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/homeview.js', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/lightwindow.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/group.css', true);
- break;
- /*
- case 'security':
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/embeddedregistration.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/identitysettings.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/embed.css', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/embed.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs2.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/visual.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/libs.js', true);
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/fullcontent.js', true);
- break;*/
- }
- if (in_array(strtolower(THIS_PAGE), $this->nobuildtemplates) == false)
- {
- // Global CSS.
- if (strtolower(THIS_PAGE) == 'frontpage')
- {
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/frontpage.css', true);
- $this->addHeaderData('css', 'http://habbo.com/styles/local/com.css', true);
- }
- elseif (strtolower(THIS_PAGE) == 'quickregister')
- {
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/quickregister.css', true);
- $this->addHeaderData('css', 'http://habbo.com/styles/local/com.css', true);
- }
- else
- {
- $this->addHeaderData('css', SITE_URL . 'web-gallery/static/styles/common.css', true);
- //$this->addHeaderData('css', 'http://habbo.com/styles/local/com.css', true);
- }
- // Global JS.
- $this->addHeaderData('js', SITE_URL . 'web-gallery/static/js/common.js', true);
- }
- // System.
- $this->addParameter('system_name', SYSTEM_NAME);
- $this->addParameter('system_version', SYSTEM_VERSION);
- $this->addParameter('system_author', SYSTEM_AUTHOR);
- $this->addParameter('system_contributors', SYSTEM_CONTRIBUTORS);
- // Header.
- $this->addParameter('meta_http-equiv', 'text/html; charset=utf-8');
- $this->addParameter('title', $ir->site_name_long . ' - ' . PAGE_NAME);
- $this->addParameter('meta_description', $ir->site_description . ' ' . $ir->getPoweredBy());
- $this->addParameter('meta_keywords', $ir->site_name_long . ', ' . SYSTEM_NAME . ', Habbo, Hotel, Habbo Hotel, retro, avatar, fun, stable, free');
- $this->addParameter('meta_author', SYSTEM_AUTHOR);
- $this->addParameter('meta_generator', SYSTEM_NAME . ' ' . SYSTEM_VERSION);
- $this->addParameter('meta_robots', 'index,follow');
- $this->addParameter('meta_googlebot', 'index,follow');
- // All.
- $this->addParameter('top_navigation', $ir->template->buildTopNavigation());
- $this->addParameter('sub_navigation', $ir->template->buildSubNavigation());
- $this->addParameter('online_count', $ir->handlers->handleCache('h_oc', $ir->habbo, 'getOnline', null, 60));
- // Site.
- $this->addParameter('webbuild', WEBBUILD);
- $this->addParameter('site_url', SITE_URL);
- $this->addParameter('site_name_long', $ir->site_name_long);
- $this->addParameter('site_name_short', $ir->site_name_short);
- // Contact Us Email.
- $this->addParameter('contact_us_email', CU_EMAIL);
- // Me.
- $this->addParameter('hot_campaigns', $ir->handlers->handleCache('t_hc', $ir->template, 'buildHotCampaigns', '5', 60));
- $this->addParameter('powered_by_long', $ir->getPoweredByLong());
- $this->addParameter('powered_by', $ir->getPoweredBy());
- // Client.
- $this->addParameter('external_variables', '');
- $this->addParameter('external_texts', '');
- $this->addParameter('product_data', '');
- $this->addParameter('furniture_data', '');
- $this->addParameter('flash_client', '');
- $this->addParameter('base_url', '');
- $this->addParameter('habbo_swf', '');
- // ReCAPTCHA.
- $this->addParameter('public_key', PUB_KEY);
- $this->addParameter('private_key', PRIV_KEY);
- $this->addParameter('community', $language['community']);
- $this->addParameter('news', $language['news']);
- $this->addParameter('safety', $language['safety']);
- $this->addParameter('administration', $language['administration']);
- $this->addParameter('home', $language['home']);
- $this->addParameter('my_page', $language['my_page']);
- $this->addParameter('account_settings', $language['account_settings']);
- $this->addParameter('hc_vip', $language['hc_vip']);
- $this->addParameter('users_online', $language['users_online']);
- $this->addParameter('habbo_staff', $language['habbo_staff']);
- $this->addParameter('safety_tips', $language['safety_tips']);
- $this->addParameter('habbo_way', $language['habbo_way']);
- foreach($language as $key => $value)
- {
- $ir->template->addParameter[$key] = $value;
- }
- foreach($language as $key => $value)
- {
- $this->addParameter($key, $value);
- }
- // Habbo.
- if (IS_LOGGED_IN == true)
- {
- $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>'));
- }
- else
- {
- $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>');
- //$this->addParameter('', '');
- //$this->addParameter('', '');
- }
- $this->addParameter('user', H_USER);
- }
- /*
- *
- * Private Function Page.
- *
- * Calls all the template buffering functions to determine the active style and to create the output buffer.
- *
- */
- final private function buildPage()
- {
- global $ir;
- if ($ir->cache->existsCache('t_build' . THIS_PAGE) == false)
- {
- $this->style_id = &$this->gatherStyleData();
- $this->output_buffer = &$this->gatherTemplateData();
- $buildPage = array(
- 'style_id' => $this->style_id,
- 'output_buffer' => $this->output_buffer
- );
- if (in_array(strtolower(THIS_PAGE), $this->nocachetemplates) == false)
- {
- $ir->cache->addCache('t_build' . THIS_PAGE, $buildPage, T_BUILD_PAGE_CACHE);
- }
- }
- elseif ($ir->cache->existsCache('t_build' . THIS_PAGE) == true)
- {
- $buildPageCache = $ir->cache->fetchCache('t_build' . THIS_PAGE);
- $this->style_id =& $buildPageCache['style_id'];
- $this->output_buffer =& $buildPageCache['output_buffer'];
- }
- }
- /*
- *
- * Public Function buildFact.
- *
- * Builds the did you know fact HTML from the database.
- * This has been removed from the website since it's pointless.
- *
- * @return: $result string Fact HTML.
- *
- */
- final public function buildFact()
- {
- global $ir;
- $result = null;
- $query = $ir->db->executeQuery("SELECT f.fact
- FROM " . TABLE_PREFIX . "facts f
- ORDER BY RAND() ASC;");
- if ($ir->db->numRows($query) > 0)
- {
- $result = $ir->db->fetchObject($query)->fact;
- }
- return $result;
- }
- /*
- *
- * Public Function buildTopNavigation.
- *
- * Builds the top navigation HTML from the database.
- *
- * @return: $result string Top navigation HTML.
- *
- */
- final public function buildTopNavigation()
- {
- global $ir;
- $result = '';
- $query = $ir->db->executeQuery("SELECT n.id AS id, n.name AS name, n.url AS url
- FROM " . TABLE_PREFIX . "navigation n
- WHERE n.type = '1'
- AND n.rank <= '{$ir->habbo->getField('rank', H_USER)}'
- ORDER BY n.order_number ASC;");
- if ($ir->db->numRows($query) > 0)
- {
- while ($row = $ir->db->fetchObject($query))
- {
- if ($row->id == THIS_PARENT_ID)
- {
- $result .= '<li class="metab selected">
- <strong>' . $row->name . '</strong>
- <span></span>
- </li>';
- }
- elseif ($row->id == 1)
- {
- $result .= '<li class="metab">
- <a href="' . SITE_URL . $row->url . '">' . $row->name . '</a>
- <span></span>
- </li>';
- }
- else
- {
- $result .= '<li>
- <a href="' . SITE_URL . $row->url . '">' . $row->name . '</a>
- <span></span>
- </li>';
- }
- }
- }
- return $result;
- }
- /*
- *
- * Public Function buildSubNavigation.
- *
- * Builds the sub navigation HTML from the database.
- *
- * @return: $result string Sub navigation HTML.
- *
- */
- final public function buildSubNavigation()
- {
- global $ir;
- $result = '';
- $query = $ir->db->executeQuery("SELECT n.id AS id, n.name AS name, n.url AS url, n.new AS new
- FROM " . TABLE_PREFIX . "navigation n
- WHERE n.parent_id = '" . THIS_PARENT_ID . "'
- AND n.type = '2'
- AND n.rank <= '{$ir->habbo->getField('rank', H_USER)}'
- ORDER BY n.order_number ASC;");
- if (($count = $ir->db->numRows($query)) > 0)
- {
- $loopcount = 1;
- while ($row = $ir->db->fetchObject($query))
- {
- if ($row->id == THIS_SUB_ID)
- {
- if ($count == $loopcount)
- {
- $result .= '<li class="selected last">
- ' . $row->name . '
- </li>';
- }
- else
- {
- $result .= '<li class="selected">
- ' . $row->name . '
- </li>';
- }
- }
- elseif ($count == $loopcount)
- {
- $result .= '<li class="last">
- <a href="' . SITE_URL . $row->url . '">' . $row->name . '</a>' . (($row->new == 0) ? '' : ' <span style="float: right; color: red; font-size: 8px;"> new</span>') . '
- </li>';
- }
- else
- {
- $result .= '<li>
- <a href="' . SITE_URL . $row->url . '">' . $row->name . '</a>' . (($row->new == 0) ? '' : ' <span style="float: right; color: red; font-size: 8px;"> new</span>') . '
- </li>';
- }
- $loopcount++;
- }
- }
- return $result;
- }
- /*
- *
- * Public Function buildEvents.
- *
- * Builds the events HTML from the database.
- *
- * @return: $result string Events HTML.
- *
- */
- final public function buildEvents()
- {
- global $ir;
- $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>';
- $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>';
- return $result;
- }
- /*
- *
- * Public Function checkFriendRequests.
- *
- * Checks user has friend requests then outputs HTML.
- *
- * @return: $result string Events HTML.
- *
- */
- final public function checkFriendRequests()
- {
- global $ir;
- $uid = $ir->habbo->getField('id', H_USER);
- $query1 = $ir->db->executeQuery("SELECT id FROM messenger_requests WHERE to_id = {$uid}");
- $count = $ir->db->numRows($query1);
- $i = 0;
- while($row = mysqli_fetch_row($query1))
- {
- $i++;
- if ($count == 0)
- {
- $result = '';
- }
- elseif ($count == 1)
- {
- $result = '<li id="feed-notification">You have <a href="client">' . $count . ' friend request.</a></li>';
- }
- else
- {
- $result = '<li id="feed-notification">You have <a href="client">' . $count . ' friend requests.</a></li>';
- }
- }
- /*
- if ($ir->db->numRows($query1) > 0)
- {
- $result = '<li id="feed-notification">You currently have <b>' . $query1 . '</b> friend requests.';
- }
- else
- {
- $result = '';
- }*/
- return $result;
- }
- /*
- *
- * Public Function checkFriendsOnline.
- *
- * Checks for friends online and output HTML for friends online event.
- *
- * @todo: All friends online.
- *
- * @return: $result string Friends Online HTML.
- *
- */
- final public function checkFriendsOnline()
- {
- global $ir;
- $uid = $ir->habbo->getField('id', H_USER);
- $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}");
- $count = $ir->db->numRows($query1);
- $i = 0;
- //return '<li id="feed-friends">You have <b>' . $count . '</b> friends online: ';
- while($row = mysqli_fetch_array($query1))
- {
- $i++;
- $friend = $row[0];
- if($i < $count)
- {
- $comma = ", ";
- }
- $nl = "\n";
- $friendsOn .= $friend . $comma . $nl;
- }
- if ($count == 0)
- {
- return '<li id="feed-friends">You have <b>' . $count . '</b> friends online.</li>';
- }
- elseif ($count == 1)
- {
- return '<li id="feed-friends">You have <b>' . $count . '</b> friend online: <a href="client">' . $friendsOn . '</a></li>';
- }
- else
- {
- return '<li id="feed-friends">You have <b>' . $count . '</b> friends online: <a href="client">' . $friendsOn . '</a></li>';
- }
- }
- /*
- *
- * Public Function checkTradingLock.
- *
- * Checks if trading is enabled or not and output HTML for trading event.
- *
- * @return: $result string Trading Lock HTML.
- *
- */
- final public function checkTradingLock()
- {
- global $ir, $language;
- if ($ir->habbo->getField('trade_lock', H_USER) == 1)
- {
- return '<li class="small" id="feed-trading-disabled">' . $language['trading_eventoff'] . ' <a href="profile?tab=1">' . $language['trading_clickhere_on'] . '</a></li>';
- }
- else
- {
- return '<li class="small" id="feed-trading-enabled">' . $language['trading_eventon'] . ' <a href="profile?tab=1">' . $language['trading_clickhere_off'] . '</a></li>';
- }
- }
- /*
- *
- * Public Function checkFriendLock.
- *
- * Checks if trading is enabled or not and output HTML for trading event.
- *
- * @return: $result string Friend Lock HTML.
- *
- */
- final public function checkFriendLock()
- {
- global $ir;
- if ($ir->habbo->getField('block_newfriends', H_USER) == 1)
- {
- return '<li id="feed-friends">Friend requests are turned off. <a href="profile?tab=1">Click here to turn it on</a></li>';
- }
- else
- {
- //return '<li id="feed-friends">Friend requests are turned on. <a href="profile?tab=1">Click here to turn it off</a></li>';
- }
- }
- /*
- *
- * Public Function checkModerationTickets.
- *
- * Checks if trading is enabled or not and output HTML for trading event.
- *
- * @todo: All moderation ticket warnings.
- *
- * @return: $result string Moderation Tickets HTML.
- *
- */
- final public function checkModerationTickets()
- {
- global $ir;
- $query1 = $ir->db->executeQuery("");
- if ($ir->habbo->getField('trade_lock', H_USER) == 1)
- {
- return '<li class="small" id="feed-trading-disabled">Trading is off. <a href="profile?tab=1">Click here to turn it on</a></li>';
- }
- else
- {
- return '<li class="small" id="feed-trading-enabled">Trading is on. <a href="profile?tab=1">Click here to turn it off</a></li>';
- }
- }
- /*
- *
- * Public Function buildImageSelect.
- *
- * Builds the image select HTML from the database.
- *
- * @return: $result string Image Select HTML.
- *
- * @todo: take out the caching and use the handler object.
- *
- */
- final public function buildImageSelect()
- {
- global $ir;
- $result = '';
- $spath = CWD . '/images/top_stories/';
- $wpath = SITE_URL . '/images/top_stories/';
- $result .= '<select name="n.image_url">';
- if ($ir->cache->existsCache('ts_Images') == false)
- {
- $folder = opendir($spath);
- $pic_types = array('gif', 'png');
- $index = array();
- while ($file = readdir($folder))
- {
- if (in_array(substr(strtolower($file), strrpos($file, '.') + 1), $pic_types) == true)
- {
- array_push($index, $file);
- }
- }
- closedir($folder);
- $ir->cache->addCache('ts_Images', $index, 0);
- }
- else
- {
- $index = $ir->cache->fetchCache('ts_Images');
- }
- foreach ($index AS $value)
- {
- $result .= '<option value="' . ($wpath . $value) . '">' . $value . '</option>';
- }
- $result .= '</select>';
- return $result;
- }
- /*
- *
- * Public Function buildHotCampaigns.
- *
- * Builds the hot campaigns HTML from the database.
- *
- * @param: $max int Maximum number of results to return.
- *
- * @return: $result string Hot campaigns HTML.
- *
- */
- final public function buildHotCampaigns($max)
- {
- global $ir;
- $result = '';
- $query = $ir->db->executeQuery("SELECT c.title AS title, c.description AS description, c.url AS url, c.image_url AS image_url
- FROM " . TABLE_PREFIX . "campaigns c
- WHERE c.active = '1'
- ORDER BY RAND() ASC
- LIMIT 0,{$max};");
- if (($count = $ir->db->numRows($query)) > 0)
- {
- $loopcount = 0;
- while ($row = $ir->db->fetchObject($query))
- {
- if ($loopcount == 0)
- {
- $result .= '<li class="even">
- <div class="hotcampaign-container">
- <a href="' . $row->url . '"><img src="' . $row->image_url . '" align="left" alt="" /></a>
- <h3>' . $row->title . '</h3>
- <p>' . $row->description . '</p>
- <!-- <p class="link"><a href="' . $row->url . '">Go there »</a></p> -->
- </div>
- </li>';
- $loopcount++;
- }
- else
- {
- $result .= '<li class="odd">
- <div class="hotcampaign-container">
- <a href="' . $row->url . '"><img src="' . $row->image_url . '" align="left" alt="" /></a>
- <h3>' . $row->title . '</h3>
- <p>' . $row->description . '</p>
- <!-- <p class="link"><a href="' . $row->url . '">Go there »</a></p> -->
- </div>
- </li>';
- $loopcount--;
- }
- }
- }
- return $result;
- }
- /*
- *
- * Public Function buildTopStories.
- *
- * Builds the top stories HTML from the database.
- *
- * @return: $result string Top stories HTML.
- *
- */
- final public function buildTopStories()
- {
- global $ir;
- $result = '';
- $query = $ir->db->executeQuery("SELECT a.id AS id, a.title AS title, a.summary AS summary, a.image_url AS image_url
- FROM " . TABLE_PREFIX . "articles a
- ORDER BY a.id DESC
- LIMIT 0,5;");
- if (($count = $ir->db->numRows($query)) > 0)
- {
- $first = false;
- while ($row = $ir->db->fetchObject($query))
- {
- if ($first == false)
- {
- $result .= '<div class="topstory" style="background-image: url(' . $row->image_url . ');">
- <h4>Latest news</h4>
- <h3><a href="' . SITE_URL . 'articles/' . $row->id . '">' . $row->title . '</a></h3>
- <p class="summary">
- ' . $row->summary . '
- </p>
- <p>
- <a href="' . SITE_URL . 'articles/' . $row->id . '">Read more »</a>
- </p>
- </div>';
- $first = true;
- }
- else
- {
- $result .= '<div class="topstory" style="background-image: url(' . $row->image_url . '); display: none;">
- <h4>Latest news</h4>
- <h3><a href="' . SITE_URL . 'articles/' . $row->id . '">' . $row->title . '</a></h3>
- <p class="summary">
- ' . $row->summary . '
- </p>
- <p>
- <a href="' . SITE_URL . 'articles/' . $row->id . '">Read more »</a>
- </p>
- </div>';
- }
- }
- $result .= '<div id="topstories-nav" style="display: none"><a href="#" class="prev">« Previous</a><span>1</span> / ' . $count . '<a href="#" class="next">Next »</a></div>';
- }
- return $result;
- }
- /*
- *
- * Public Function buildSubStories.
- *
- * Builds the sub stories HTML from the database.
- *
- * @return: $result string Sub stories HTML.
- *
- */
- final public function buildSubStories()
- {
- global $ir;
- $result = '';
- $query = $ir->db->executeQuery("SELECT a.id AS id, a.title AS title, a.timestamp AS timestamp
- FROM " . TABLE_PREFIX . "articles a
- ORDER BY a.id DESC
- LIMIT 5,2;");
- if (($count = $ir->db->numRows($query)) > 0)
- {
- $first = false;
- while ($row = $ir->db->fetchObject($query))
- {
- if ($first == false)
- {
- $result .= '<li class="even">
- <a href="' . SITE_URL . 'articles/' . $row->id . '">' . $row->title . ' »</a><div class="newsitem-date">' . $row->timestamp . '</div>
- </li>';
- $first = true;
- }
- else
- {
- $result .= '<li class="odd">
- <a href="' . SITE_URL . 'articles/' . $row->id . '">' . $row->title . ' »</a><div class="newsitem-date">' . $row->timestamp . '</div>
- </li>';
- }
- }
- }
- else
- {
- $result .= '<li class="even">
- No articles to be displayed.
- </li>';
- }
- return $result;
- }
- /*
- *
- * Public Function buildHotRooms.
- *
- * Builds the hot rooms HTML from the database.
- *
- * @return: $result string Hot rooms HTML.
- *
- */
- final public function buildHotRooms($max)
- {
- global $ir;
- $result = '';
- $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
- FROM rooms r
- ORDER BY r.users_now DESC
- LIMIT 0,{$max};");
- if ($ir->db->numRows($query) > 0)
- {
- $status = true;
- while ($row = $ir->db->fetchObject($query))
- {
- if ($status == true)
- {
- $status = 'even';
- }
- else
- {
- $status = 'odd';
- }
- // Double.
- $population = ($row->users_now / $row->users_max);
- if ($population >= 1.00)
- {
- $level = '5';
- }
- elseif ($population <= 0.99 && $population >= 0.51)
- {
- $level = '4';
- }
- elseif ($population <= 0.50 && $population >= 0.26)
- {
- $level = '3';
- }
- elseif ($population <= 0.25 && $population >= 0.01)
- {
- $level = '2';
- }
- else
- {
- $level = '1';
- }
- $result .= '<li class="' . $status . ' room-occupancy-' . $level . '" roomid="' . $row->id . '">
- <div>
- <span class="event-name">
- <a href="#">' . $row->caption . '</a>
- </span>
- <span class="event-owner"> by <a href="#">' . $row->owner . '</a></span>
- <p> </p>
- </div>
- </li>';
- if ($status == 'even')
- {
- $status = false;
- }
- else
- {
- $status = true;
- }
- }
- }
- return $result;
- }
- /*
- *
- * Public Function buildComments.
- *
- * Fetches all the comment HTML from an article.
- *
- * @return: $result string The comments HTML.
- *
- */
- final public function buildComments(&$id)
- {
- global $ir;
- $result = '';
- $query = $ir->db->executeQuery("SELECT u.username AS username, u.look AS look, c.comment AS comment
- FROM " . TABLE_PREFIX . "comments c
- INNER JOIN users u
- ON u.id = c.user_id
- WHERE c.article_id = '{$id}'
- ORDER BY c.id ASC;");
- if ($ir->db->numRows($query) > 0)
- {
- $count = 1;
- while ($row = $ir->db->fetchObject($query))
- {
- $result .= '<table style="padding: 5px; width: 100%; background-color: #fff;">
- <tbody>
- <tr>
- <td valign="middle" width="25">
- <img style="margin-top: -16px; " src="http://www.habbo.fr/habbo-imaging/avatarimage?figure=' . $row->look . '" />
- </td>
- <td valign="top">
- <b style="font-size: 120%;">' . $row->username . '</b><br /><br />
- <p style="background-color: #f2f2f2; padding: 5px; width: 400px;">' . $row->comment . '</p>
- </td>
- <td style="float: right;">
- <span style="color: #747474;">#' . $count++ . '</span>
- </td>
- </tr>
- </tbody>
- </table>';
- }
- }
- else
- {
- $result = '<p><i>There are no comments on this article.</i></p>';
- }
- return $result;
- }
- /*
- *
- * Private Function gatherStyleData.
- *
- * Determines the active style and fetches its information.
- *
- * @return: $result int Active style ID (returned by reference).
- *
- */
- final private function &gatherStyleData()
- {
- global $ir;
- $result = null;
- $query = $ir->db->executeQuery("SELECT s.id
- FROM " . TABLE_PREFIX . "styles s
- WHERE s.active = '1';");
- if ($ir->db->numRows($query) == 1)
- {
- $result =& $ir->db->fetchObject($query)->id;
- }
- else
- {
- // Error, there are zero or multiple active styles.
- }
- return $result;
- }
- /*
- *
- * Private Function gatherHeaderData.
- *
- * Gathers all of the pre-defined header html (css and javascript).
- *
- * @param: $type string Type of header data to fetch from the database.
- *
- * @return: $header_buffer string Header data.
- *
- */
- final private function gatherHeaderData($type)
- {
- global $ir;
- $header_buffer = '';
- $prefix = null;
- $suffix = null;
- $query = $ir->db->executeQuery("SELECT h.content AS content
- FROM " . TABLE_PREFIX . "{$type} h
- WHERE h.style_id = '{$this->style_id}'
- AND h.active = '1';");
- if ($ir->db->numRows($query) > 0)
- {
- switch ($type)
- {
- case 'css':
- $prefix = '<style type="text/css">';
- $suffix = '</style>';
- break;
- case 'js':
- $prefix = '<script type="text/javascript">';
- $suffix = '</script>';
- break;
- }
- while ($row = $ir->db->fetchObject($query))
- {
- $header_buffer .= $prefix . $row->content . $suffix;
- }
- }
- return $header_buffer;
- }
- /*
- *
- * Private Function gatherExtraHeaderData.
- *
- * Gathers all of the extra header html (css and javascript).
- *
- * @return: $header_buffer string Header data.
- *
- */
- final private function gatherExtraHeaderData()
- {
- $header_buffer = '';
- foreach ($this->header_data AS $value)
- {
- $header_buffer .= $value;
- }
- return $header_buffer;
- }
- /*
- *
- * Private Function gatherTemplateData.
- *
- * Gathers all the template html from the database.
- *
- * @return: $template_buffer string Template html (returned by reference).
- *
- */
- final private function &gatherTemplateData()
- {
- global $ir;
- $template_buffer = '';
- $parsedTemplates = '\'' . implode('\', \'', $this->templates) . '\'';
- $query = $ir->db->executeQuery("SELECT t.name AS name, t.content AS content
- FROM " . TABLE_PREFIX . "templates t
- WHERE t.style_id = '{$this->style_id}'
- AND t.active = '1'
- AND t.name IN ({$parsedTemplates})
- ORDER BY t.order_number ASC;");
- if ($ir->db->numRows($query) > 0)
- {
- while ($row = $ir->db->fetchObject($query))
- {
- //$template_buffer .= '<!-- (s) Template: "' . $row->name . '" -->' . $row->content . '<!-- (e) Template: "' . $row->name . '" -->';
- $template_buffer .= $row->content;
- // Handles placement of Header Data.
- if ($row->name == 'header')
- {
- $template_buffer .= $this->gatherHeaderData('css');
- $template_buffer .= $this->gatherHeaderData('js');
- $template_buffer .= $this->gatherExtraHeaderData();
- }
- if ($row->name == strtolower(THIS_PAGE))
- {
- $template_buffer .= $this->page_buffer;
- }
- }
- }
- return $template_buffer;
- }
- /*
- *
- * Public Function addToBuffer.
- *
- * Adds html to the page buffer.
- *
- * @param: $string string HTML content being added to the page_buffer variable.
- *
- */
- final public function addToBuffer($string, $page = false)
- {
- global $ir;
- if ($page == true)
- {
- // Change from style_id 1 to proper style_id variable.
- $query = $ir->db->executeQuery("SELECT t.content AS content
- FROM " . TABLE_PREFIX . "templates t
- WHERE t.name = '{$string}'
- AND t.active = '0'
- AND t.style_id = '1'
- LIMIT 0,1;");
- if ($ir->db->numRows($query) == 1)
- {
- //$this->page_buffer .= $this->parseParameters($ir->db->fetchObject($query)->content, true);
- $this->page_buffer .= $ir->db->fetchObject($query)->content;
- }
- else
- {
- // Error, page does not exist.
- }
- }
- else
- {
- $this->page_buffer .= $this->parseParameters($string, true);
- }
- }
- /*
- *
- * Public Function addParameter.
- *
- * Adds a parameter (key => value) to the parameters array.
- *
- * @param: $key string ID of the parameter.
- * @param: $value string Value of the parameter.
- * @param: $overwrite bool Whether to overwrite an existing parameter or not.
- *
- */
- final public function addParameter($key, $value, $overwrite = false)
- {
- if ($overwrite == false)
- {
- if (array_key_exists($key, $this->parameters) == false)
- {
- $this->parameters[$key] = $value;
- }
- else
- {
- // Error, key already exists.
- }
- }
- else
- {
- if (array_key_exists($key, $this->parameters) == true)
- {
- unset($this->parameters[$key]);
- }
- else
- {
- // Error, key does not exist.
- }
- $this->addParameter($key, $value);
- }
- }
- /*
- *
- * Public Function addHeaderData.
- *
- * Adds header data to the header_data array.
- *
- * @param: $type string Type of data being added (css or js).
- * @param: $value string Value of the data.
- * @param: $src bool Whether to use the src tag or not.
- *
- */
- final public function addHeaderData($type, $value, $src)
- {
- if (in_array($value, $this->header_data) == false)
- {
- switch ($type)
- {
- case 'css':
- if ($src == true)
- {
- $this->header_data[] = '<link rel="stylesheet" type="text/css" href="' . $value . '" screen="media" />';
- }
- else
- {
- $this->header_data[] = '<style type="text/css">' . $value . '</style>';
- }
- break;
- case 'js':
- if ($src == true)
- {
- $this->header_data[] = '<script type="text/javascript" src="' . $value . '"></script>';
- }
- else
- {
- $this->header_data[] = '<script type="text/javascript" async>' . $value . '</script>';
- }
- break;
- }
- }
- }
- /*
- *
- * Public Function parseOutputBuffer.
- *
- * Parses the output buffer by filtering the parameters and stripping HTML.
- *
- * @param: $output_buffer string String to be parsed (passed by reference).
- *
- */
- final public function parseOutputBuffer(&$output_buffer)
- {
- $this->parseParameters($output_buffer);
- //$this->parseHTML($output_buffer);
- }
- /*
- *
- * Private Function parseParameters.
- *
- * Parses the parameters in the output buffer.
- *
- * @param: $output_buffer string String to be parsed (passed by reference).
- * @param: $return bool Determines whether the function returns anything or not.
- *
- * @return: $var mixed Output buffer parsed.
- *
- */
- final private function parseParameters(&$output_buffer, $return = false)
- {
- if (count($this->parameters) > 0)
- {
- foreach ($this->parameters AS $key => $value)
- {
- $lkey = strtolower($key);
- $output_buffer = str_replace('%' . $lkey . '%', $value, $output_buffer);
- }
- }
- if ($return == true)
- {
- return $output_buffer;
- }
- }
- /*
- *
- * Private Function parseHTML.
- *
- * Strips the HTML in the output buffer.
- *
- * @param: $output_buffer string String to be parsed (passed by reference).
- *
- */
- final private function parseHTML(&$output_buffer)
- {
- // @source: http://ru.php.net/manual/en/function.ob-start.php#71953
- $search = array(
- '/\>[^\S ]+/s',
- '/[^\S ]+\</s',
- '/(\s)+/s'
- );
- $replace = array(
- '>',
- '<',
- '\\1'
- );
- $output_buffer = preg_replace($search, $replace, $output_buffer);
- }
- /*
- *
- * Public Function getOutputBuffer.
- *
- * Builds the page and gets the output buffer.
- *
- * @return: $this->output_buffer string Buffered output from the buildPage function.
- *
- */
- final public function &getOutputBuffer()
- {
- $this->buildPage();
- return $this->output_buffer;
- }
- final public function __destruct() { }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement