Overview

Namespaces

  • Sleepy
  • Module
    • Authentication
    • CSV
    • DB
    • FormBuilder
    • FSDB
    • IP2Country
    • Mailer
    • MobiDetect
    • Navigation
    • StaticCache
  • PHP

Classes

  • Sleepy\Debug
  • Sleepy\Hook
  • Sleepy\Router
  • Sleepy\SM
  • Sleepy\Template

Exceptions

  • Sleepy\RouteNotFound
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: namespace Sleepy;
  3: 
  4: /**
  5:  * Provides sleepyMUSTACHE core bootstrap functionality
  6:  *
  7:  * ## Usage
  8:  *
  9:  * <code>
 10:  *   \Sleepy\SM::initialize();
 11:  * </code>
 12:  *
 13:  * ## Changelog
 14:  *
 15:  * ### Version 1.1
 16:  * * Updated private previx (_) for consistency
 17:  * * Updated documentation
 18:  * * Added teamsite fixes
 19:  *
 20:  * ### Version 1.0
 21:  * * Initial commit
 22:  *
 23:  * @date July 18, 2016
 24:  * @author Jaime A. Rodriguez <hi.i.am.jaime@gmail.com>
 25:  * @version 1.1
 26:  * @license http://opensource.org/licenses/MIT
 27:  */
 28: class SM {
 29:     private static $_instance;
 30: 
 31:     public static $is_initialized = false;
 32: 
 33:     /**
 34:      * Prevent class from being cloned
 35:      */
 36:     private function __clone() {}
 37: 
 38:     /**
 39:      * The constructor is private to ensure we only have one sleepy_preprocess
 40:      * and sleepy_postprocess hooks.
 41:      */
 42:     private function __construct() {
 43:         require_once('class.debug.php');
 44: 
 45:         // Enable sessions
 46:         session_start();
 47:         
 48:         // Teamsite fixes
 49:         if (@include_once('Webkit/init.php')) {
 50:             define('TEAMSITE', true);
 51:             $_SERVER['DOCUMENT_ROOT'] = $docroot;
 52:         } else {
 53:             $WHG_DB_HOST = "";
 54:             $WHG_DB_USER = "";
 55:             $WHG_DB_PASSWD = "";
 56:             $WHG_DB_REPLDB = "";
 57:         }
 58: 
 59:         // If we are not setup yet, forward the user to the setup page
 60:         if (@!include_once($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'settings.php')) {
 61:             include_once('settings.php');
 62:         }
 63: 
 64:         require_once('class.hooks.php');
 65:         require_once('class.template.php');
 66:         require_once('class.router.php');
 67: 
 68:         ob_start();
 69:         \Sleepy\Hook::addAction('sleepy_preprocess');
 70: 
 71:         // Send the encoding ahead of time to speed up rendering
 72:         header('Content-Type: text/html; charset=utf-8');
 73:     }
 74: 
 75:     public function __destruct() {
 76:         echo \Sleepy\Hook::addFilter('sleepy_render', ob_get_clean());
 77:         \Sleepy\Hook::addAction('sleepy_postprocess');
 78:     }
 79: 
 80:     /**
 81:      * Initialized the SM class
 82:      */
 83:     public static function initialize() {
 84:         if (!self::$is_initialized) {
 85:             self::$is_initialized = true;
 86:             self::$_instance = new SM;
 87:         }
 88:     }
 89: 
 90:     /**
 91:      * Checks if we are in the live environment
 92:      * @return boolean True if we are live
 93:      */
 94:     public static function isLive() {
 95:         return (ENV == 'LIVE');
 96:     }
 97: 
 98:     /**
 99:      * Checks if we are in the staging environment
100:      * @return boolean True if we are in the staging environment
101:      */
102:     public static function isStage() {
103:         return (ENV == 'STAGE');
104:     }
105: 
106:     /**
107:      * Checks if we are in the development environment
108:      * @return boolean True if we are in in the development environment
109:      */
110:     public static function isDev() {
111:         return (ENV != 'LIVE' && ENV != 'STAGE');
112:     }
113: 
114:     /**
115:      * Checks if the current site matches a URL
116:      * @param  string  $str The URL to match with current site
117:      * @return boolean      true if there was a match
118:      */
119:     public static function isENV($str) {
120:         foreach (explode(',' , $str) as $url) {
121:             if (stripos($_SERVER['SERVER_NAME'], trim($url)) !== false)
122:                 return true;
123:         }
124: 
125:         return false;
126:     }
127: }
sleepyMUSTACHE v.0.8 API documentation generated by ApiGen