Advertisement
plas71k

@aponte php-crypt file => decoded

Feb 23rd, 2013
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 50.19 KB | None | 0 0
  1. <?php
  2. /*
  3.  * @ Pirate-Sky Crew :: PHP Decoder v2
  4.  * @ Author: pLa$71k
  5.  * @ Web: http://pirate-sky.com
  6.  * @ Pirate-Sky Crew © 2008 - 2013
  7.  */
  8.  
  9. /**
  10.  * =======================================
  11.  * ###################################
  12.  * SWIFT Framework - Cr@cK3D
  13.  * ###################################
  14.  * =======================================
  15.  */
  16.  
  17. /**
  18.  * ###############################################
  19.  * BEGIN LICENSE KEY CHECK
  20.  * ###############################################
  21.  */
  22.  
  23. class SWIFT_License
  24. {
  25.     const LIC_KEY = 'A376545AD82A8B695A60';
  26.    
  27.     static private $_licenseContainer = false;
  28.     static private $_allChecksPass = false;
  29.    
  30.     /**
  31.      * Constructor
  32.      *
  33.      * @return bool "true" on Success, "false" otherwise
  34.      */
  35.     public function __construct()
  36.     {
  37.         parent::__construct();
  38.        
  39.         return true;
  40.     }
  41.    
  42.     /**
  43.      * Destructor
  44.      *
  45.      * @return bool "true" on Success, "false" otherwise
  46.      */
  47.     public function __destruct()
  48.     {
  49.         parent::__destruct();
  50.        
  51.         return true;
  52.     }
  53.    
  54.     /**
  55.      * Attempt to load the license system
  56.      *
  57.      * @return bool "true" on Success, "false" otherwise
  58.      */
  59.     static public function Load()
  60.     {
  61.         // No license checks for setup or console
  62.         if (SWIFT_INTERFACE == 'setup' || SWIFT_INTERFACE == 'console' || SWIFT_INTERFACE == 'winapp' || SWIFT_INTERFACE == 'visitor' || SWIFT_INTERFACE == 'staff' || SWIFT_INTERFACE == 'admin' || SWIFT_INTERFACE == 'client' || SWIFT_INTERFACE == 'chat' || SWIFT_INTERFACE == 'archive' || SWIFT_INTERFACE == 'pda' || SWIFT_INTERFACE == 'rss' || SWIFT_INTERFACE == 'syncworks' || SWIFT_INTERFACE == 'instaalert' || SWIFT_INTERFACE == 'api' || SWIFT_INTERFACE == 'cron' || SWIFT_INTERFACE == 'wallboard' || SWIFT_INTERFACE == 'console' || SWIFT_INTERFACE == 'winapp' || SWIFT_INTERFACE == 'intranet') {
  63.             self::$_allChecksPass = true;
  64.            
  65.             return true;
  66.         }
  67.        
  68.         if (!file_exists('./key.php')) {
  69.             echo 'Unable to locate key.php, please ensure that the key.php is placed in the root directory of the package.';
  70.             exit;
  71.         }
  72.        
  73.         $_keyContents = file_get_contents('./key.php');
  74.         if (!self::DecodeKey($_keyContents)) {
  75.             echo 'Invalid key.php. Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
  76.             exit;
  77.         }
  78.        
  79.        
  80.         return true;
  81.     }
  82.    
  83.     /**
  84.      * The Key Decoder
  85.      *
  86.      * @param string $_keyContents The Key Contents
  87.      * @return bool "true" on Success, "false" otherwise
  88.      */
  89.     static protected function DecodeKey($_keyContents)
  90.     {
  91.         if (trim($_keyContents) == '') {
  92.             echo 'key.php is empty. Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
  93.             exit;
  94.         }
  95.        
  96.         $_finalKeyContents = '';
  97.         $_matches          = array();
  98.         if (!preg_match('@\[([^\[\]]*)\]@', $_keyContents, $_matches)) {
  99.             echo 'Invalid key.php (3). Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
  100.             exit;
  101.         }
  102.        
  103.         $_finalKeyContents = $_matches[1];
  104.        
  105.         // MD5OFBASEDATA;MD5OFDECRYPTEDDATA;EXTENDEDKEY;BASE64DATA
  106.         $_keyChunksContainer = explode(';', $_finalKeyContents);
  107.         if (count($_keyChunksContainer) != 4) {
  108.             echo 'Invalid key.php (2). Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
  109.             exit;
  110.         }
  111.        
  112.         $_md5Base64    = $_keyChunksContainer[0];
  113.         $_md5Decrypted = $_keyChunksContainer[1];
  114.         $_extendedKey  = $_keyChunksContainer[2];
  115.         $_base64Data   = $_keyChunksContainer[3];
  116.        
  117.         if (md5($_base64Data) != $_md5Base64) {
  118.             echo 'Invalid key.php (INVALID BASE64HASH). Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
  119.             exit;
  120.         }
  121.        
  122.         if (empty($_extendedKey)) {
  123.             echo 'Invalid key.php (INVALID EXTENDEDKEY). Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
  124.             exit;
  125.         }
  126.        
  127.         $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
  128.         $iv      = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  129.        
  130.         $_decryptedData    = str_replace("\x0", '', mcrypt_decrypt(MCRYPT_RIJNDAEL_256, self::LIC_KEY . $_extendedKey, base64_decode($_base64Data), MCRYPT_MODE_ECB, $iv));
  131.         $_licenseContainer = mb_unserialize($_decryptedData);
  132.        
  133.         if (empty($_decryptedData) || md5($_decryptedData) != $_md5Decrypted || !_is_array($_licenseContainer)) {
  134.             echo 'Invalid key.php (INVALID DECRYPT). Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
  135.             exit;
  136.         }
  137.        
  138.         self::$_licenseContainer = $_licenseContainer;
  139.        
  140.         SWIFT::Set('licenseexpiry', $_licenseContainer['expiry']);
  141.         SWIFT::Set('licensefullname', $_licenseContainer['fullname']);
  142.         SWIFT::Set('licenseproduct', $_licenseContainer['product']);
  143.         SWIFT::Set('licensestaff', $_licenseContainer['licensedstaff']);
  144.         SWIFT::Set('licensedomains', $_licenseContainer['domains']);
  145.         SWIFT::Set('licensepackage', $_licenseContainer['package']);
  146.         SWIFT::Set('licenseorganization', $_licenseContainer['organization']);
  147.         SWIFT::Set('licenseuniqueid', $_licenseContainer['uniqueid']);
  148.         SWIFT::Set('licenseistrial', $_licenseContainer['istrial']);
  149.        
  150.         if ($_licenseContainer['istrial'] == '1' && (SWIFT_INTERFACE == 'client' || SWIFT_INTERFACE == 'visitor' || SWIFT_INTERFACE == 'admin' || SWIFT_INTERFACE == 'staff')) {
  151.             ob_start();
  152.         }
  153.        
  154.         return true;
  155.     }
  156.    
  157.     /**
  158.      * Check for license expiry
  159.      *
  160.      * @return bool "true" on Success, "false" otherwise
  161.      */
  162.     static public function CheckExpired()
  163.     {
  164.         if (self::$_allChecksPass == true) {
  165.             return true;
  166.         }
  167.        
  168.         if (!isset(self::$_licenseContainer['expiry']) || (self::$_licenseContainer['expiry'] != '0' && self::$_licenseContainer['expiry'] < time())) {
  169.             echo 'License has expired! Expiry: ' . date('d M Y h:i:s A', self::$_licenseContainer['expiry']);
  170.             exit;
  171.         }
  172.        
  173.         return true;
  174.     }
  175.    
  176.     /**
  177.      * Check for valid domain
  178.      *
  179.      * @return bool "true" on Success, "false" otherwise
  180.      * @throws SWIFT_Exception If Invalid Data is Provided
  181.      */
  182.     static public function CheckValidDomain()
  183.     {
  184.         $_SWIFT = SWIFT::GetInstance();
  185.        
  186.         if (self::$_allChecksPass == true) {
  187.             return true;
  188.         }
  189.        
  190.         // ======= START DOMAIN CHECK =======
  191.        
  192.         $_checkHost  = false;
  193.         $_domainData = parse_url($_SWIFT->Settings->Get('general_producturl'));
  194.         if (strtolower(substr($_domainData['host'], 0, 4)) == 'www.') {
  195.             $_checkHost = trim(strtolower(substr($_domainData['host'], 4)));
  196.         } else {
  197.             $_checkHost = trim(strtolower($_domainData['host']));
  198.         }
  199.        
  200.         $_allowedDomains = implode(',', self::$_licenseContainer['domains']);
  201.        
  202.         if (!in_array($_checkHost, self::$_licenseContainer['domains'])) {
  203.             echo '<div style="position: absolute; left: 10px; top: 0; right: 10px; border: 1px SOLID darkred; background: #ffefbb; z-index: 999999999;"><font face="verdana, arial, helvetica, serif" size="3" color="red"><b>ERROR:</b> Domain does not match license key file domain (' . $_checkHost . '), allowed domains: ' . $_allowedDomains . ', please change the product path to match the domain under Admin CP > Settings > General Settings<br>This Product will not work properly unless untill that value is changed.<br /><br />For more information please contact the kayako support at <a href="https://my.kayako.com" target="blank">https://my.kayako.com</a></font></div>';
  204.         }
  205.        
  206.         unset($_checkHost);
  207.         unset($_domainData);
  208.        
  209.         $_httpsExtended = '';
  210.         if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE) {
  211.             $_httpsExtended = 's';
  212.         }
  213.        
  214.         /**
  215.          * ---------------------------------------------
  216.          * EXTENDED DOMAIN CHECK
  217.          * ---------------------------------------------
  218.          */
  219.         $_selfURL    = sprintf('http%s://%s%s', $_httpsExtended, $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']);
  220.         $_checkHost  = false;
  221.         $_domainData = parse_url($_selfURL);
  222.         if (strtolower(substr($_domainData['host'], 0, 4)) == 'www.') {
  223.             $_checkHost = trim(strtolower(substr($_domainData['host'], 4)));
  224.         } else {
  225.             $_checkHost = trim(strtolower($_domainData['host']));
  226.         }
  227.        
  228.         $_allowedDomains = implode(',', self::$_licenseContainer['domains']);
  229.        
  230.         if (!in_array($_checkHost, self::$_licenseContainer['domains'])) {
  231.             echo '<div style="position: absolute; left: 10px; top: 0; right: 10px; border: 1px SOLID darkred; background: #ffefbb; z-index: 999999999;"><font face="verdana, arial, helvetica, serif" size="3" color="red"><b>ERROR:</b> Domain does not match license key file domain (' . $_checkHost . '), allowed domains: ' . $_allowedDomains . ', please change the product path to match the domain under Admin CP > Settings > General Settings<br>This Product will not work properly unless untill that value is changed.<br /><br />For more information please contact the kayako support at <a href="https://my.kayako.com" target="blank">https://my.kayako.com</a></font></div>';
  232.         }
  233.        
  234.         // ======= END DOMAIN CHECK =======
  235.        
  236.         // If its a trial key AND interface is client, display a message
  237.         if (self::$_licenseContainer['istrial'] == '1' && (SWIFT_INTERFACE == 'client' || SWIFT_INTERFACE == 'visitor' || SWIFT_INTERFACE == 'admin' || SWIFT_INTERFACE == 'staff')) {
  238.             $_contents = ob_get_contents();
  239.             ob_end_clean();
  240.            
  241.             // Is it compressor page? dont display any message
  242.             if (isset($_SWIFT->Router) && $_SWIFT->Router instanceof SWIFT_Router && strtolower($_SWIFT->Router->GetAction()) == 'compressor') {
  243.                 echo $_contents;
  244.             } else if (stristr($_contents, '</body>')) {
  245.                 echo str_replace('</body>', '<div style="position: absolute; left: 10px; top: 0; right: 10px; border: 1px SOLID darkred; background: #ffefbb; z-index: 999999999;"><font face="verdana, arial, helvetica, serif" size="3" color="red">This is a trial product!<br /><br />To upgrade or contact kayako sales, please visit <a href="https://my.kayako.com" target="blank">https://my.kayako.com</a></font></div></body>', $_contents);
  246.             } else {
  247.                 echo $_contents;
  248.                 echo '<div style="position: absolute; left: 10px; top: 0; right: 10px; border: 1px SOLID darkred; background: #ffefbb; z-index: 999999999;"><font face="verdana, arial, helvetica, serif" size="3" color="red">This is a trial product!<br /><br />To upgrade or contact kayako sales, please visit <a href="https://my.kayako.com" target="blank">https://my.kayako.com</a></font></div>';
  249.             }
  250.         }
  251.        
  252.         return true;
  253.     }
  254.    
  255.     /**
  256.      * Check for Valid Staff
  257.      *
  258.      * @return bool "true" on Success, "false" otherwise
  259.      * @throws SWIFT_Exception If Invalid Data is Provided
  260.      */
  261.     static public function CheckValidStaff()
  262.     {
  263.         $_SWIFT = SWIFT::GetInstance();
  264.        
  265.         if (self::$_allChecksPass == true) {
  266.             return true;
  267.         }
  268.        
  269.         $_staffCache = $_SWIFT->Cache->Get('staffcache');
  270.        
  271.         if (!isset(self::$_licenseContainer['licensedstaff']) || (self::$_licenseContainer['licensedstaff'] != '0' && count($_staffCache) > self::$_licenseContainer['licensedstaff'])) {
  272.             echo 'Staff count exceeded. (' . count($_staffCache) . ' > ' . self::$_licenseContainer['licensedstaff'] . '). Please contact Kayako Support for further assistance at https://my.kayako.com.';
  273.             exit;
  274.         }
  275.        
  276.         SWIFT::Set('licensedstaff', self::$_licenseContainer['licensedstaff']);
  277.        
  278.         return true;
  279.     }
  280.    
  281.     /**
  282.      * Check for Valid Package
  283.      *
  284.      
  285.      * @return bool "true" on Success, "false" otherwise
  286.      * @throws SWIFT_Exception If Invalid Data is Provided
  287.      */
  288.     static public function CheckPackage()
  289.     {
  290.         $_SWIFT = SWIFT::GetInstance();
  291.        
  292.         if (self::$_allChecksPass == true) {
  293.             return true;
  294.         }
  295.        
  296.         if (strtolower(self::$_licenseContainer['product']) != strtolower(SWIFT_PRODUCT)) {
  297.             echo 'Invalid Product Package (Main). Source: ' . SWIFT_PRODUCT . ', Key: ' . self::$_licenseContainer['product'] . '. Please contact Kayako support for further assistance at https://my.kayako.com.';
  298.             exit;
  299.         }
  300.        
  301.         if (defined('SWIFT_PACKAGE') && isset(self::$_licenseContainer['package']) && !empty(self::$_licenseContainer['package']) && strtolower(constant('SWIFT_PACKAGE')) != strtolower(constant('SWIFT_PRODUCT')) && strtolower(self::$_licenseContainer['package']) != strtolower(constant('SWIFT_PACKAGE'))) {
  302.             echo 'Invalid Product Package. Source: ' . constant('SWIFT_PACKAGE') . ', Key: ' . self::$_licenseContainer['package'] . '. Please contact Kayako support for further assistance at https://my.kayako.com.';
  303.             exit;
  304.         }
  305.        
  306.         // Trial Check. We dont want clients with zendclosed and ioncubeclosed builds where the license key isnt activated for trial.. no free SUS!
  307.         if ((strtolower(SOURCE_TYPE) == 'zendclosed' || strtolower(SOURCE_TYPE) == 'ioncubeclosed') && (!isset(self::$_licenseContainer['istrial']) || self::$_licenseContainer['istrial'] == '0')) {
  308.             echo 'Invalid Product Trial Package. Source: ' . constant('SOURCE_TYPE') . ', Key: ' . self::$_licenseContainer['package'] . '. Please contact Kayako support for further assistance at https://my.kayako.com.';
  309.             exit;
  310.         }
  311.        
  312.         return true;
  313.     }
  314. }
  315.  
  316. SWIFT_License::Load();
  317. /**
  318.  * ###############################################
  319.  * END LICENSE KEY CHECK
  320.  * ###############################################
  321.  */
  322.  
  323. /**
  324.  * The Core SWIFT Class
  325.  *
  326.  * @author Varun Shoor
  327.  */
  328. class SWIFT
  329. {
  330.     static private $_alertContainer = array();
  331.     static private $_infoContainer = array();
  332.     static private $_errorContainer = array();
  333.     static private $_errorFieldContainer = array();
  334.    
  335.     static private $_objectMapContainer = array();
  336.    
  337.     static private $_Instance = false;
  338.     static private $_valueContainer = array();
  339.    
  340.     static private $_objectCache = array();
  341.    
  342.     /**
  343.      * @var SWIFT_FirePHP
  344.      */
  345.     public $FirePHP = false;
  346.    
  347.     /**
  348.      * @var SWIFT_Database
  349.      */
  350.     public $Database = false;
  351.    
  352.     /**
  353.      * @var SWIFT_LanguageEngine
  354.      */
  355.     public $Language = false;
  356.    
  357.     /**
  358.      * @var SWIFT_TemplateEngine
  359.      */
  360.     public $Template = false;
  361.    
  362.     /**
  363.      * @var SWIFT_Registry
  364.      */
  365.     public $Registry = false;
  366.    
  367.     /**
  368.      * @var SWIFT_Interface
  369.      */
  370.     public $Interface = false;
  371.    
  372.     /**
  373.      * @var SWIFT_Module
  374.      */
  375.     public $Module = false;
  376.    
  377.     /**
  378.      * @var SWIFT_Session
  379.      */
  380.     public $Session = false;
  381.    
  382.     /**
  383.      * @var SWIFT_Settings
  384.      */
  385.     public $Settings = false;
  386.    
  387.     /**
  388.      * @var SWIFT_Cache
  389.      */
  390.     public $Cache = false;
  391.    
  392.     /**
  393.      * @var SWIFT_Router
  394.      */
  395.     public $Router = false;
  396.    
  397.     /**
  398.      * @var SWIFT_View
  399.      */
  400.     public $View = false;
  401.    
  402.     /**
  403.      * @var SWIFT_Cookie
  404.      */
  405.     public $Cookie = false;
  406.    
  407.     /**
  408.      * @var SWIFT_Console
  409.      */
  410.     public $Console = false;
  411.    
  412.     /**
  413.      * @var SWIFT_System
  414.      */
  415.     public $System = false;
  416.    
  417.     /**
  418.      * @var SWIFT_Controller
  419.      */
  420.     public $Controller = false;
  421.    
  422.     /**
  423.      * @var SWIFT_UserInterface
  424.      */
  425.     public $UserInterface = false;
  426.    
  427.     /**
  428.      * @var SWIFT_Loader
  429.      */
  430.     public $Load = false;
  431.    
  432.     /**
  433.      * @var SWIFT_Staff
  434.      */
  435.     public $Staff = false;
  436.    
  437.     /**
  438.      * @var SWIFT_User
  439.      */
  440.     public $User = false;
  441.    
  442.     /**
  443.      * @var SWIFT_HTMLPurifier
  444.      */
  445.     public $HTMLPurifier = false;
  446.    
  447.     /**
  448.      * @var SWIFT_TemplateGroup
  449.      */
  450.     public $TemplateGroup = false;
  451.    
  452.     /**
  453.      * Non Core Objects
  454.      */
  455.    
  456.     /**
  457.      * @var SWIFT_Server
  458.      */
  459.     public $Server = false;
  460.    
  461.     /**
  462.      * @var SWIFT_Server
  463.      */
  464.     public $ServerMaster = false;
  465.    
  466.     /**
  467.      * @var SWIFT_JobQueueMessageRemote
  468.      */
  469.     public $JobQueueMessage = false;
  470.    
  471.     /**
  472.      * @var SWIFT_DynectSession
  473.      */
  474.     public $DynectSession = false;
  475.    
  476.     /**
  477.      * Core Constants
  478.      */
  479.     const DEFAULT_ERROR_REPORTING = E_ALL;
  480.    
  481.     /**
  482.      * Constructor
  483.      *
  484.      * @return bool "true" on Success, "false" otherwise
  485.      */
  486.     private function __construct()
  487.     {
  488.         return true;
  489.     }
  490.    
  491.     /**
  492.      * Initialize the Class
  493.      *
  494.      * @return bool "true" on Success, "false" otherwise
  495.      * @throws SWIFT_Exception If the Class is not Loaded
  496.      */
  497.     protected function Initialize()
  498.     {
  499.         global $_shutdownQueue;
  500.        
  501.         $this->SanitizeGlobals();
  502.        
  503.         $_shutdownQueue = array();
  504.        
  505.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_CONFIGDIRECTORY . '/config.php');
  506.        
  507.         // Load FirePHP Connector Class
  508.         $this->FirePHP = new SWIFT_FirePHP();
  509.         self::Set('_startTime', GetMicroTime());
  510.        
  511.         /*
  512.          * ###############################################
  513.          * Error Reporting Functions
  514.          * ###############################################
  515.          */
  516.         error_reporting(self::DEFAULT_ERROR_REPORTING);
  517.         set_error_handler(array(
  518.             'SWIFT_Exception',
  519.             'GlobalErrorHandler'
  520.         ));
  521.         set_exception_handler(array(
  522.             'SWIFT_Exception',
  523.             'GlobalExceptionHandler'
  524.         ));
  525.         @ini_set('session.use_trans_sid', false);
  526.         @ini_set('session.bug_compat_42', true);
  527.        
  528.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Database/class.SWIFT_Database.php');
  529.        
  530.         // Define the DSN
  531.         SWIFT_Database::DefineDSN();
  532.        
  533.         // Libraries
  534.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Interface/class.SWIFT_Interface.php');
  535.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/MVC/class.SWIFT_Model.php');
  536.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/MVC/class.SWIFT_View.php');
  537.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/MVC/class.SWIFT_Controller.php');
  538.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/MVC/class.SWIFT_Library.php');
  539.        
  540.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Module/class.SWIFT_Module.php');
  541.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Registry/class.SWIFT_Registry.php');
  542.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Cache/class.SWIFT_CacheStore.php');
  543.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Settings/class.SWIFT_Settings.php');
  544.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Language/class.SWIFT_LanguagePhraseLinked.php');
  545.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/LanguageEngine/class.SWIFT_LanguageEngine.php');
  546.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/TemplateEngine/class.SWIFT_TemplateEngine.php');
  547.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Date/class.SWIFT_Date.php');
  548.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Session/class.SWIFT_Session.php');
  549.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Loader/class.SWIFT_Loader.php');
  550.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Cookie/class.SWIFT_Cookie.php');
  551.        
  552.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Router/class.SWIFT_Router.php');
  553.        
  554.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Data/class.SWIFT_Data.php');
  555.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Data/class.SWIFT_DataID.php');
  556.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Data/class.SWIFT_DataStore.php');
  557.        
  558.         require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Hook/class.SWIFT_Hook.php');
  559.        
  560.         // Load only if the interface is Console
  561.         if (SWIFT_INTERFACE == 'console') {
  562.             require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Console/class.SWIFT_Console.php');
  563.             require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/System/class.SWIFT_System.php');
  564.            
  565.             $this->Console = new SWIFT_Console();
  566.             $this->System  = new SWIFT_System();
  567.         }
  568.        
  569.         /*
  570.          * ###############################################
  571.          * BEGIN CORE VARIABLES CREATION
  572.          * ###############################################
  573.          */
  574.         if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  575.             self::Set('IP', $_SERVER['HTTP_X_FORWARDED_FOR']);
  576.         } elseif (isset($_SERVER['REMOTE_ADDR'])) {
  577.             self::Set('IP', $_SERVER['REMOTE_ADDR']);
  578.         } else {
  579.             self::Set('IP', '');
  580.         }
  581.        
  582.         self::Set('InstallationHash', '');
  583.         self::Set('ActionHash', BuildHash());
  584.         self::Set('UniqueID', '');
  585.         self::Set('CoreModules', array(
  586.             MODULE_TICKETS,
  587.             MODULE_CORE,
  588.             MODULE_BASE,
  589.             MODULE_LIVECHAT,
  590.             MODULE_KNOWLEDGEBASE,
  591.             MODULE_TROUBLESHOOTER,
  592.             MODULE_NEWS,
  593.             MODULE_DOWNLOADS,
  594.             MODULE_REPORTS,
  595.             MODULE_RINGROUTE,
  596.             MODULE_ISSUES,
  597.             MODULE_MANUALS,
  598.             MODULE_PARSER
  599.         ));
  600.         /*
  601.          * ###############################################
  602.          * BEGIN OBJECT CREATION
  603.          * ###############################################
  604.          */
  605.         try {
  606.             // Create the Cookie Object
  607.             $this->Cookie = new SWIFT_Cookie();
  608.            
  609.             // Connect to the Database
  610.             $this->Database = new SWIFT_Database();
  611.             if (!$this->Database->IsConnected()) {
  612.                 trigger_error('Unable to connect to Database. Please verify the username, password, grant permissions and the database status.', E_USER_ERROR);
  613.                
  614.                 exit;
  615.             }
  616.            
  617.             // Load the Registry
  618.             $this->Registry = new SWIFT_Registry();
  619.            
  620.             // Load the CacheStore
  621.             $this->Cache = new SWIFT_CacheStore();
  622.            
  623.             // Load the Interface
  624.             $this->Interface = SWIFT_Interface::Load();
  625.            
  626.             // Load the main caches
  627.             $this->Cache->LoadQueue();
  628.            
  629.             // Load the Settings
  630.             $this->Settings = new SWIFT_Settings();
  631.            
  632.             // Load the Hook Interface
  633.             $this->Hook = new SWIFT_Hook();
  634.            
  635.             // Load Interface Related Settings
  636.             $this->Interface->LoadSettings();
  637.            
  638.             // Set the Installation Hash
  639.             self::Set('InstallationHash', $this->Settings->GetKey('core', 'installationhash'));
  640.            
  641.             // Set up the timezome and whether or not to use daylight savings
  642.             self::Set('timezone', ($this->Settings->Get('dt_timezonephp')) ? $this->Settings->Get('dt_timezonephp') : 'GMT');
  643.             self::Set('daylightsavings', ($this->Settings->Get('dt_daylightsavings') == 1) ? true : false);
  644.            
  645.             // Configure PHP to use our time zone when dealing with datetime functions
  646.             if (!date_default_timezone_set(SWIFT::Get('timezone'))) {
  647.                 // Fall back to UTC if for some reason PHP doesn't like the one we've chosen.
  648.                 date_default_timezone_set('GMT');
  649.             }
  650.            
  651.             setlocale(LC_ALL, SWIFT_LOCALE);
  652.            
  653.             if (defined('SWIFTLOCALECTYPE')) {
  654.                 setlocale(LC_CTYPE, constant('SWIFTLOCALECTYPE'));
  655.             }
  656.            
  657.             // Load the User Interface Files
  658.             $this->LoadUserInterfaceFiles();
  659.            
  660.             // Parse Template Group from Router
  661.             SWIFT_Router::ParseTemplateGroup();
  662.            
  663.             // Attempt to load the Template Engine
  664.             $this->Template = SWIFT_TemplateEngine::LoadEngine();
  665.            
  666.             // Attempt to load the Language Engine
  667.             $this->Language = SWIFT_LanguageEngine::LoadEngine();
  668.            
  669.             // Load the Template Engine Variables
  670.             $this->Template->LoadVariables();
  671.            
  672.             // Parse the Modules from Settings
  673.             SWIFT_Module::ParseRegisteredModules();
  674.             SWIFT_Module::ParseConfig();
  675.            
  676.             // Load the User Interface Object
  677.             $this->LoadUserInterfaceObject();
  678.            
  679.             // Load the Router
  680.             $this->Router = SWIFT_Router::Load();
  681.            
  682.         }
  683.         catch (Exception $_ExceptionObject) {
  684.             SWIFT_Exception::GlobalExceptionHandler($_ExceptionObject);
  685.             trigger_error($_ExceptionObject->getMessage(), E_USER_ERROR);
  686.            
  687.             exit;
  688.         }
  689.        
  690.         /**
  691.          * ###############################################
  692.          * BEGIN LICENSE KEY CHECK
  693.          * ###############################################
  694.          */
  695.         // Check for Expiry
  696.         SWIFT_License::CheckExpired();
  697.        
  698.         // Check for Staff Licenses
  699.         SWIFT_License::CheckValidStaff();
  700.        
  701.         // Check for Package
  702.         SWIFT_License::CheckPackage();
  703.         /**
  704.          * ###############################################
  705.          * END LICENSE KEY CHECK
  706.          * ###############################################
  707.          */
  708.        
  709.         /*
  710.          * ###############################################
  711.          * BEGIN CORE VARIABLE CREATION (PART 2)
  712.          * ###############################################
  713.          */
  714.        
  715.         $_interfaceType = $this->Interface->GetInterface();
  716.         if ($_interfaceType == SWIFT_Interface::INTERFACE_ADMIN || $_interfaceType == SWIFT_Interface::INTERFACE_STAFF || $_interfaceType == SWIFT_Interface::INTERFACE_WINAPP || $_interfaceType == SWIFT_Interface::INTERFACE_SYNCWORKS || $_interfaceType == SWIFT_Interface::INTERFACE_RSS || $_interfaceType == SWIFT_Interface::INTERFACE_INTRANET || $_interfaceType == SWIFT_Interface::INTERFACE_PDA || $_interfaceType == SWIFT_Interface::INTERFACE_INSTAALERT || $_interfaceType == SWIFT_Interface::INTERFACE_MOBILE || $_interfaceType == SWIFT_Interface::INTERFACE_API) {
  717.             $this->Language->Load('staffactivitylog');
  718.         }
  719.        
  720.         /*
  721.          * ###############################################
  722.          * END CORE VARIABLE CREATION (PART 2)
  723.          * ###############################################
  724.          */
  725.        
  726.         try {
  727.             // Load the Module
  728.             $this->Module = $this->Router->GetModule();
  729.            
  730.             // Execute the relevant controller and load the related objects
  731.             $this->Module->ExecuteController($this->Router);
  732.            
  733.         }
  734.         catch (Exception $_ExceptionObject) {
  735.             trigger_error($_ExceptionObject->GetTraceAsString() . SWIFT_CRLF . $_ExceptionObject->getMessage(), E_USER_ERROR);
  736.            
  737.             exit;
  738.         }
  739.        
  740.         self::RunSystemChecks();
  741.        
  742.         /**
  743.          * ###############################################
  744.          * BEGIN LICENSE KEY CHECK
  745.          * ###############################################
  746.          */
  747.         SWIFT_License::CheckValidDomain();
  748.         /**
  749.          * ###############################################
  750.          * END LICENSE KEY CHECK
  751.          * ###############################################
  752.          */
  753.        
  754.         /*
  755.          * ###############################################
  756.          * PROCESS SHUTDOWN QUEUES
  757.          * ###############################################
  758.          */
  759.         self::ProcessAllShutdownFunctions();
  760.        
  761.         /*
  762.          * ###############################################
  763.          * PROCESS EMAIL QUEUE
  764.          * ###############################################
  765.          */
  766.         $_queueCount = $this->Settings->GetKey('mail', 'queuecount');
  767.         if ($_queueCount) {
  768.             require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Mail/class.SWIFT_MailQueueManager.php');
  769.            
  770.             $_SWIFT_MailQueueManagerObject = new SWIFT_MailQueueManager();
  771.             $_SWIFT_MailQueueManagerObject->ProcessMailQueue();
  772.         }
  773.        
  774.         self::Set('_endTime', GetMicroTime());
  775.         $this->FirePHP->Info('Execution Time: ' . number_format(self::Get('_endTime') - self::Get('_startTime'), 5));
  776.        
  777.         return true;
  778.     }
  779.    
  780.     /**
  781.      * Process All Shutdown Functions
  782.      *
  783.      * @return bool "true" on Success, "false" otherwise
  784.      */
  785.     static public function ProcessAllShutdownFunctions()
  786.     {
  787.         self::ProcessShutdownQueue(-1);
  788.         SWIFT_Model::ProcessShutdownUpdatePool();
  789.         self::ProcessShutdownQueue();
  790.        
  791.         return true;
  792.     }
  793.    
  794.     /**
  795.      * Loads the User Interface Objects
  796.      *
  797.      * @return bool "true" on Success, "false" otherwise
  798.      * @throws SWIFT_Exception If the Class is not Loaded
  799.      */
  800.     protected function LoadUserInterfaceFiles()
  801.     {
  802.         if ($this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_CLIENT || $this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_VISITOR || $this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_RSS) {
  803.             require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/UserInterface/class.SWIFT_UserInterface.php');
  804.             require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/UserInterface/class.SWIFT_UserInterfaceClient.php');
  805.            
  806.         } else {
  807.             require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/UserInterface/class.SWIFT_UserInterface.php');
  808.             require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/UserInterface/class.SWIFT_UserInterfaceControlPanel.php');
  809.            
  810.         }
  811.        
  812.         return true;
  813.     }
  814.    
  815.     /**
  816.      * Loads the User Interface Objects
  817.      *
  818.      * @return bool "true" on Success, "false" otherwise
  819.      * @throws SWIFT_Exception If the Class is not Loaded
  820.      */
  821.     protected function LoadUserInterfaceObject()
  822.     {
  823.         if ($this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_CLIENT || $this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_VISITOR || $this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_RSS) {
  824.             $this->UserInterface = new SWIFT_UserInterfaceClient();
  825.            
  826.         } else if ($this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_STAFF || $this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_INTRANET || $this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_ADMIN) {
  827.             $this->UserInterface = new SWIFT_UserInterfaceControlPanel();
  828.         }
  829.        
  830.         return true;
  831.     }
  832.    
  833.     /**
  834.      * Check the Global Variables and Sanitize them
  835.      *
  836.      * @return bool "true" on Success, "false" otherwise
  837.      * @throws SWIFT_Exception If the Class is not Loaded
  838.      */
  839.     protected function SanitizeGlobals()
  840.     {
  841.         /**
  842.          * Possible globals overwrite attempt, so die
  843.          */
  844.         if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
  845.             throw new SWIFT_Exception('Globals overwrite attempt detected! Terminating.');
  846.            
  847.             exit;
  848.         }
  849.        
  850.         /**
  851.          * Unset all global variables except for the ones defined in _reserved, for servers where register_globals is enabled
  852.          */
  853.         $_reserved = array(
  854.             '_reserved',
  855.             'GLOBALS',
  856.             '_GET',
  857.             '_POST',
  858.             '_COOKIE',
  859.             '_SERVER',
  860.             '_ENV',
  861.             '_REQUEST',
  862.             '_FILES',
  863.             'argv'
  864.         );
  865.        
  866.         if (is_array($GLOBALS)) {
  867.             reset($GLOBALS);
  868.             while (list($_key, $_val) = each($GLOBALS)) {
  869.                 if (!in_array($_key, $_reserved) && ($_key != '_key' && $_key != '_val')) {
  870.                     unset($GLOBALS[$_key]);
  871.                 }
  872.             }
  873.         }
  874.        
  875.         return true;
  876.     }
  877.    
  878.     /**
  879.      * Get the instance of this Class
  880.      *
  881.      * @return SWIFT SWIFT Instance
  882.      */
  883.     static public function GetInstance()
  884.     {
  885.         if (!self::$_Instance) {
  886.             self::$_Instance = new SWIFT();
  887.            
  888.             self::$_Instance->Initialize();
  889.         }
  890.        
  891.         return self::$_Instance;
  892.     }
  893.    
  894.     /**
  895.      * Retrieve the Value from the Value Container
  896.      *
  897.      * @param string $_key The Key
  898.      * @return mixed "_valueContainer[_key]" (MIXED) on Success, "false" otherwise
  899.      */
  900.     static public function Get($_key)
  901.     {
  902.         if (!isset(self::$_valueContainer[$_key])) {
  903.             return false;
  904.         }
  905.        
  906.         return self::$_valueContainer[$_key];
  907.     }
  908.    
  909.     /**
  910.      * Set the Value in the Container
  911.      *
  912.      * @param string $_key The Key
  913.      * @param mixed $_value The Value
  914.      * @return bool "true" on Success, "false" otherwise
  915.      */
  916.     static public function Set($_key, $_value = '')
  917.     {
  918.         self::$_valueContainer[$_key] = $_value;
  919.        
  920.         return true;
  921.     }
  922.    
  923.     /**
  924.      * Set the Value in the Container
  925.      *
  926.      * @param string $_key The Key
  927.      * @param mixed $_value The Value
  928.      * @return bool "true" on Success, "false" otherwise
  929.      */
  930.     static public function SetReference($_key, &$_value)
  931.     {
  932.         if (empty($_key)) {
  933.             return false;
  934.         }
  935.        
  936.         if (empty($_value)) {
  937.             unset(self::$_valueContainer[$_key]);
  938.            
  939.             return true;
  940.         }
  941.        
  942.         self::$_valueContainer[$_key] =& $_value;
  943.        
  944.         return true;
  945.     }
  946.    
  947.     /**
  948.      * Retrieve the Info Container
  949.      *
  950.      * @return array The Info Container
  951.      */
  952.     static public function GetInfoContainer()
  953.     {
  954.         return self::$_infoContainer;
  955.     }
  956.    
  957.     /**
  958.      * Retrieve the Alert Container
  959.      *
  960.      * @return array The Alert Container
  961.      */
  962.     static public function GetAlertContainer()
  963.     {
  964.         return self::$_alertContainer;
  965.     }
  966.    
  967.     /**
  968.      * Retrieve the Error Container
  969.      *
  970.      * @return array The Error Container
  971.      */
  972.     static public function GetErrorContainer()
  973.     {
  974.         return self::$_errorContainer;
  975.     }
  976.    
  977.     /**
  978.      * Retrieve the Error Field Container
  979.      *
  980.      * @return array The Error Field Container
  981.      */
  982.     static public function GetErrorFieldContainer()
  983.     {
  984.         return self::$_errorFieldContainer;
  985.     }
  986.    
  987.     /**
  988.      * Resets all the Containers
  989.      *
  990.      * @return bool "true" on Success, "false" otherwise
  991.      */
  992.     static public function ResetAllContainers()
  993.     {
  994.         self::$_infoContainer  = array();
  995.         self::$_alertContainer = array();
  996.         self::$_errorContainer = array();
  997.        
  998.         return true;
  999.     }
  1000.    
  1001.     /**
  1002.      * Add to Info Container
  1003.      *
  1004.      * @param string $_title The Title
  1005.      * @param string $_message The Message
  1006.      * @return bool "true" on Success, "false" otherwise
  1007.      */
  1008.     static public function Info($_title, $_message)
  1009.     {
  1010.         if (empty($_title) || empty($_message)) {
  1011.             return false;
  1012.         }
  1013.        
  1014.         self::$_infoContainer[] = array(
  1015.             'title' => $_title,
  1016.             'message' => $_message
  1017.         );
  1018.        
  1019.         return true;
  1020.     }
  1021.    
  1022.     /**
  1023.      * Add to Alert Container
  1024.      *
  1025.      * @param string $_title The Title
  1026.      * @param string $_message The Message
  1027.      * @return bool "true" on Success, "false" otherwise
  1028.      */
  1029.     static public function Alert($_title, $_message)
  1030.     {
  1031.         if (empty($_title) || empty($_message)) {
  1032.             return false;
  1033.         }
  1034.        
  1035.         self::$_alertContainer[] = array(
  1036.             'title' => $_title,
  1037.             'message' => $_message
  1038.         );
  1039.        
  1040.         return true;
  1041.     }
  1042.    
  1043.     /**
  1044.      * Add to Error Container
  1045.      *
  1046.      * @param string $_title The Title
  1047.      * @param string $_message The Message
  1048.      * @return bool "true" on Success, "false" otherwise
  1049.      */
  1050.     static public function Error($_title, $_message)
  1051.     {
  1052.         if (empty($_title) || empty($_message)) {
  1053.             return false;
  1054.         }
  1055.        
  1056.         self::$_errorContainer[] = array(
  1057.             'title' => $_title,
  1058.             'message' => $_message
  1059.         );
  1060.        
  1061.         return true;
  1062.     }
  1063.    
  1064.     /**
  1065.      * Add to Error Field Container
  1066.      *
  1067.      * @param string $_fieldName The Field Name
  1068.      * @return bool "true" on Success, "false" otherwise
  1069.      */
  1070.     static public function ErrorField($_fieldName)
  1071.     {
  1072.         if (empty($_fieldName)) {
  1073.             return false;
  1074.         }
  1075.        
  1076.         if (count(func_get_args()) > 1) {
  1077.             foreach (func_get_args() as $_key => $_val) {
  1078.                 if (!in_array($_val, self::$_errorFieldContainer)) {
  1079.                     self::$_errorFieldContainer[] = $_val;
  1080.                 }
  1081.             }
  1082.         } else {
  1083.             self::$_errorFieldContainer[] = $_fieldName;
  1084.         }
  1085.        
  1086.         return true;
  1087.     }
  1088.    
  1089.     /**
  1090.      * Set the relevant class
  1091.      *
  1092.      * @param string $_className The Local Class name
  1093.      * @param object $_SWIFTObject The Object
  1094.      * @return bool "true" on Success, "false" otherwise
  1095.      * @throws SWIFT_Exception If the Class is not Loaded
  1096.      */
  1097.     public function SetClass($_className, SWIFT_Base $_SWIFTObject)
  1098.     {
  1099.         $this->$_className = $_SWIFTObject;
  1100.        
  1101.         self::AddToObjectMap($_SWIFTObject);
  1102.        
  1103.         foreach (self::$_objectMapContainer as $_key => $_SWIFT_BaseObject) {
  1104.             if ($_SWIFT_BaseObject instanceof SWIFT_Base && $_SWIFT_BaseObject->GetIsClassLoaded()) {
  1105.                 //                echo 'SETTING2: ' . $_className . SWIFT_CRLF;
  1106.                
  1107.                 $_SWIFT_BaseObject->UpdateObject($_className, $_SWIFTObject);
  1108.             }
  1109.         }
  1110.        
  1111.         return true;
  1112.     }
  1113.    
  1114.     /**
  1115.      * Add the object to object map
  1116.      *
  1117.      * @param SWIFT_Base $_SWIFT_BaseObject The Base Object
  1118.      * @return bool "true" on Success, "false" otherwise
  1119.      * @throws SWIFT_Exception If Invalid Data is Provided
  1120.      */
  1121.     static public function AddToObjectMap(SWIFT_Base $_SWIFT_BaseObject)
  1122.     {
  1123.         $_SWIFT = SWIFT::GetInstance();
  1124.        
  1125.         if ($_SWIFT_BaseObject instanceof SWIFT_Base && $_SWIFT_BaseObject->GetIsClassLoaded()) {
  1126.             self::$_objectMapContainer[] = $_SWIFT_BaseObject;
  1127.         }
  1128.        
  1129.         return true;
  1130.     }
  1131.    
  1132.     /**
  1133.      * Return the object map
  1134.      *
  1135.      * @return array The object map container
  1136.      * @throws SWIFT_Exception If Invalid Data is Provided
  1137.      */
  1138.     static public function GetObjectMap()
  1139.     {
  1140.         return self::$_objectMapContainer;
  1141.     }
  1142.    
  1143.     /**
  1144.      * Queue a function in object for shutdown execution
  1145.      *
  1146.      * @param mixed $_SWIFT_Object The SWIFT_Base Object Pointer or Name
  1147.      * @param string $_callBackFunction The Callback Function
  1148.      * @param int $_queueBatch The Batch of Execution to put in
  1149.      * @return bool "true" on Success, "false" otherwise
  1150.      * @throws SWIFT_Exception If Invalid Data is Provided
  1151.      */
  1152.     static public function Shutdown($_SWIFT_Object, $_callBackFunction, $_queueBatch = 1, $_replaceIndex = false)
  1153.     {
  1154.         global $_shutdownQueue;
  1155.        
  1156.         $_SWIFT = SWIFT::GetInstance();
  1157.        
  1158.         if ((is_object($_SWIFT_Object) && (!$_SWIFT_Object instanceof SWIFT_Base || !$_SWIFT_Object->GetIsClassLoaded())) || (is_string($_SWIFT_Object) && (empty($_SWIFT_Object) || !class_exists($_SWIFT_Object)))) {
  1159.             throw new SWIFT_Exception(SWIFT_INVALIDDATA);
  1160.         }
  1161.        
  1162.         $_functionArguments      = func_get_args();
  1163.         $_finalFunctionArguments = array();
  1164.         foreach ($_functionArguments as $_key => $_val) {
  1165.             if ($_key > 3) {
  1166.                 $_finalFunctionArguments[] = $_val;
  1167.             }
  1168.         }
  1169.        
  1170.         /*        if (is_string($_SWIFT_Object)) {
  1171.         echo 'S:' . $_SWIFT_Object;
  1172.         } else {
  1173.         echo 'C:' . get_class($_SWIFT_Object) . '(' . $_SWIFT_Object->GetInstanceID() . ')';
  1174.         }
  1175.         echo '::' . $_callBackFunction . '<br />';
  1176.        
  1177.         echo '<br />' . SWIFT_CRLF;*/
  1178.        
  1179.         $_index = 0;
  1180.         if (isset($_shutdownQueue[$_queueBatch])) {
  1181.             $_index = count($_shutdownQueue[$_queueBatch]);
  1182.         } else {
  1183.             $_shutdownQueue[$_queueBatch] = array();
  1184.         }
  1185.        
  1186.         if ($_replaceIndex !== false) {
  1187.             $_index = $_replaceIndex;
  1188.             //            echo 'REPLACING: ' . $_index;
  1189.         }
  1190.        
  1191.         $_shutdownQueue[$_queueBatch][$_index] = array(
  1192.             $_SWIFT_Object,
  1193.             $_callBackFunction,
  1194.             $_finalFunctionArguments
  1195.         );
  1196.        
  1197.         return $_index;
  1198.     }
  1199.    
  1200.     /**
  1201.      * Print the shutdown queue
  1202.      *
  1203.      * @param int $_batchNumber (OPTIONAL) Print the queue for a specific batch number
  1204.      * @return bool "true" on Success, "false" otherwise
  1205.      * @throws SWIFT_Exception If Invalid Data is Provided
  1206.      */
  1207.     static public function PrintShutdownQueue($_batchNumber = false)
  1208.     {
  1209.         global $_shutdownQueue;
  1210.        
  1211.         $_SWIFT = SWIFT::GetInstance();
  1212.        
  1213.         for ($index = -1; $index <= 10; $index++) {
  1214.             $_batchNumber = $index;
  1215.            
  1216.             if (!isset($_shutdownQueue[$_batchNumber]) || !_is_array($_shutdownQueue[$_batchNumber])) {
  1217.                 continue;
  1218.             }
  1219.            
  1220.             $_queueContainerList = $_shutdownQueue[$_batchNumber];
  1221.            
  1222.             foreach ($_queueContainerList as $_queueContainer) {
  1223.                 if (is_string($_queueContainer[0])) {
  1224.                     echo 'S:' . $_queueContainer[0];
  1225.                 } else {
  1226.                     echo 'C:' . get_class($_queueContainer[0]) . '(' . $_queueContainer[0]->GetInstanceID() . ')';
  1227.                 }
  1228.                 echo '::' . $_queueContainer[1] . '<br />';
  1229.                
  1230.                 echo '<br />' . SWIFT_CRLF;
  1231.             }
  1232.         }
  1233.        
  1234.         return true;
  1235.     }
  1236.    
  1237.     /**
  1238.      * Process the shutdown queue
  1239.      *
  1240.      * @param int $_batchNumber (OPTIONAL) Process the queue for a specific batch number
  1241.      * @return bool "true" on Success, "false" otherwise
  1242.      * @throws SWIFT_Exception If Invalid Data is Provided
  1243.      */
  1244.     static public function ProcessShutdownQueue($_batchNumber = false)
  1245.     {
  1246.         global $_shutdownQueue;
  1247.        
  1248.         $_SWIFT = SWIFT::GetInstance();
  1249.        
  1250.         if ($_batchNumber !== false) {
  1251.             if (isset($_shutdownQueue[$_batchNumber]) && _is_array($_shutdownQueue[$_batchNumber])) {
  1252.                 foreach ($_shutdownQueue[$_batchNumber] as $_queueContainer) {
  1253.                     $_result = call_user_func_array(array(
  1254.                         $_queueContainer[0],
  1255.                         $_queueContainer[1]
  1256.                     ), $_queueContainer[2]);
  1257.                 }
  1258.             }
  1259.            
  1260.             $_shutdownQueue[$_batchNumber] = array();
  1261.            
  1262.             return true;
  1263.         }
  1264.        
  1265.         for ($index = -1; $index <= 10; $index++) {
  1266.             $_batchNumber = $index;
  1267.            
  1268.             //            $_SWIFT->FirePHP->Info('Processing Shutdown Queue Batch #' . $_batchNumber);
  1269.            
  1270.             if (!isset($_shutdownQueue[$_batchNumber]) || !_is_array($_shutdownQueue[$_batchNumber])) {
  1271.                 $_shutdownQueue[$_batchNumber] = array();
  1272.                 continue;
  1273.             }
  1274.            
  1275.             $_queueContainerList = $_shutdownQueue[$_batchNumber];
  1276.            
  1277.             foreach ($_queueContainerList as $_queueContainer) {
  1278.                 call_user_func_array(array(
  1279.                     $_queueContainer[0],
  1280.                     $_queueContainer[1]
  1281.                 ), $_queueContainer[2]);
  1282.             }
  1283.         }
  1284.        
  1285.         $_shutdownQueue = array();
  1286.        
  1287.         return true;
  1288.     }
  1289.    
  1290.     /**
  1291.      * Run the System Checks
  1292.      *  
  1293.      * @return bool "true" on Success, "false" otherwise
  1294.      * @throws SWIFT_Exception If Invalid Data is Provided
  1295.      */
  1296.     static public function RunSystemChecks()
  1297.     {
  1298.         $_SWIFT = SWIFT::GetInstance();
  1299.        
  1300.         if ((SWIFT_INTERFACE == 'staff' || SWIFT_INTERFACE == 'admin' || SWIFT_INTERFACE == 'intranet') && file_exists('./setup') && is_dir('./setup') && SWIFT::Get('IP') != '127.0.0.1') {
  1301.             echo '<div style="position: absolute; left: 10px; top: 0; right: 10px; border: 1px SOLID darkred; background: #ffefbb; z-index: 999999999;"><font face="verdana, arial, helvetica, serif" size="3" color="red"><b>ERROR:</b> Setup directory has not been deleted. It is recommended that you immediately delete the setup directory to prevent any damage to your database.<br /><br />For more information please contact the kayako support at <a href="https://my.kayako.com" target="blank">https://my.kayako.com</a></font></div>';
  1302.         } else if ((SWIFT_INTERFACE == 'staff' || SWIFT_INTERFACE == 'admin' || SWIFT_INTERFACE == 'intranet') && $_SWIFT->Settings->GetKey('core', 'version') != SWIFT_VERSION) {
  1303.             echo '<div style="position: absolute; left: 10px; top: 0; right: 10px; border: 1px SOLID darkred; background: #ffefbb; z-index: 999999999;"><font face="verdana, arial, helvetica, serif" size="3" color="red"><b>ERROR:</b> Product file version (' . SWIFT_VERSION . ') does not match with the database version (' . $_SWIFT->Settings->GetKey('core', 'version') . '). Please run the upgrade script to ensure that the product is up to date.<br /><br />For more information please contact the kayako support at <a href="https://my.kayako.com" target="blank">https://my.kayako.com</a></font></div>';
  1304.         }
  1305.        
  1306.         return true;
  1307.     }
  1308.    
  1309.     /**
  1310.      * Cache an Object
  1311.      *
  1312.      * @param SWIFT_Base $_SWIFT_BaseObject
  1313.      * @param int $_objectIdentifier The Unique Object Identifier
  1314.      * @return bool "true" on Success, "false" otherwise
  1315.      * @throws SWIFT_Exception If Invalid Data is Provided
  1316.      */
  1317.     static public function CacheObject(SWIFT_Base $_SWIFT_BaseObject, $_objectIdentifier)
  1318.     {
  1319.         $_SWIFT = SWIFT::GetInstance();
  1320.        
  1321.         $_className = get_class($_SWIFT_BaseObject);
  1322.        
  1323.         if (!isset(self::$_objectCache[$_className])) {
  1324.             self::$_objectCache[$_className] = array();
  1325.         }
  1326.        
  1327.         self::$_objectCache[$_className][$_objectIdentifier] = $_SWIFT_BaseObject;
  1328.        
  1329.         return true;
  1330.     }
  1331.    
  1332.     /**
  1333.      * Check to see if object is cached
  1334.      *
  1335.      * @param SWIFT_Base $_SWIFT_BaseObject
  1336.      * @param int $_objectIdentifier The Unique Object Identifier
  1337.      * @return bool "true" on Success, "false" otherwise
  1338.      * @throws SWIFT_Exception If Invalid Data is Provided
  1339.      */
  1340.     static public function IsObjectCached(SWIFT_Base $_SWIFT_BaseObject, $_objectIdentifier)
  1341.     {
  1342.         $_SWIFT = SWIFT::GetInstance();
  1343.        
  1344.         $_className = get_class($_SWIFT_BaseObject);
  1345.        
  1346.         if (isset(self::$_objectCache[$_className][$_objectIdentifier])) {
  1347.             return true;
  1348.         }
  1349.        
  1350.         return false;
  1351.     }
  1352.    
  1353.     /**
  1354.      * Retrieve the Cached Object
  1355.      *
  1356.      * @param SWIFT_Base $_SWIFT_BaseObject
  1357.      * @param int $_objectIdentifier The Unique Object Identifier
  1358.      * @return bool "true" on Success, "false" otherwise
  1359.      * @throws SWIFT_Exception If Invalid Data is Provided
  1360.      */
  1361.     static public function GetCachedObject(SWIFT_Base $_SWIFT_BaseObject, $_objectIdentifier)
  1362.     {
  1363.         $_SWIFT = SWIFT::GetInstance();
  1364.        
  1365.         $_className = get_class($_SWIFT_BaseObject);
  1366.        
  1367.         if (isset(self::$_objectCache[$_className][$_objectIdentifier])) {
  1368.             return self::$_objectCache[$_className][$_objectIdentifier];
  1369.         }
  1370.        
  1371.         throw new SWIFT_Exception(SWIFT_INVALIDDATA);
  1372.        
  1373.         return false;
  1374.     }
  1375. }
  1376. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement