johnburn

Untitled

Apr 11th, 2012
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 29.49 KB | None | 0 0
  1. <?php
  2. interface IApplicationContextAware {
  3.     public abstract function setAppContext();
  4.     $appContext) {
  5.     }
  6.     interface IServiceProvider {
  7.         public abstract function getServiceInstance();
  8.     }
  9.     class System {
  10.         private $appId;
  11.         private static $instance;
  12.         private $_Settings = array();
  13.         private $_Services = array();
  14.         private $knownServiceClassNames = array();
  15.         private $_functionsToExecuteAfterInit = array();
  16.         private $TemplateProcessorPrototype;
  17.         private $TemplateSupplierPrototype;
  18.         public function __construct($appId) {
  19.             self::$instance = $this;
  20.             $this->appId = $appId;
  21.         }
  22.         public function getAppId() {
  23.             return $this->appId;
  24.         }
  25.         private function displayBlockedIpMessage() {
  26.             $message = $this->getSetting("BLOCKED_IP_MESSAGE");
  27.             $message = str_replace("{site_url}", $this->getSetting("SITE_URL"), $message);
  28.             $message = str_replace("{adminNotificationEmail}", $this->getSettingByName("notification_email"), $message);
  29.             header($_SERVER['SERVER_PROTOCOL'] . " 403 Forbidden");
  30.             echo nl2br($message);
  31.         }
  32.         public function addFunctionToExecuteAfterInit($fn, $params = array()) {
  33.             $this->_functionsToExecuteAfterInit[] = array("function" => $fn, "params" => $params);
  34.         }
  35.         public function run() {
  36.             header("Content-type:text/html;charset=utf-8");
  37.             $this->boot();
  38.             $this->init();
  39.             $this->executeAfterInitFunctions();
  40.             $this->startup();
  41.             $this->respond();
  42.         }
  43.         public function loadSettings($filename) {
  44.             $newSettings = include ($filename);
  45.             $this->_Settings = array_merge($this->_Settings, $newSettings);
  46.         }
  47.         public function getSetting($name) {
  48.             if (empty($name)) {
  49.                 return null;
  50.             }
  51.             return null;
  52.         }
  53.         public function registerService($name, $provider) {
  54.             if (strlen($name) < 1) {
  55.                 throw new Exception("Illigal name for service name \"{$name}\" is given");
  56.             }
  57.             $this->_Services[$name] = $provider;
  58.         }
  59.         private function init() {
  60.             $this->createSingletonServiceByClassName("DB");
  61.             $this->createSingletonServiceByClassName("Session");
  62.             $this->createSingletonServiceByClassName("Settings");
  63.             $this->createSingletonServiceByClassName("CustomSettings");
  64.             $this->createSingletonServiceByClassName("Navigator");
  65.             $this->createSingletonServiceByClassName("PageManager");
  66.             $this->createSingletonServiceByClassName("UserSettings");
  67.             $this->createSingletonServiceByClassName("ObjectMother");
  68.             $this->createSingletonServiceByClassName("PathManager");
  69.             $this->createSingletonServiceByClassName("Cache");
  70.             $this->createSingletonServiceByClassName("Cookie");
  71.             $this->createSingletonServiceByClassName("PathProvider");
  72.             $this->ServiceManager = $this->createServiceManager();
  73.             $this->_ModuleManager = $this->createModuleManager();
  74.         }
  75.         private function startup() {
  76.             $this->prepareGlobalArrays();
  77.             $this->setGlobalTemplateVariable("site_url", $this->getSystemSettings("SITE_URL"));
  78.             $this->setGlobalTemplateVariable("radius_search_unit", $this->getSettingByName("radius_search_unit"));
  79.             $this->setGlobalTemplateVariable("google_maps_API_key", $this->getSettingByName("google_maps_API_key"));
  80.             $this->setGlobalTemplateVariable("product_version", $this->getSettingByName("product_version"));
  81.             $this->setGlobalTemplateVariable("notification_email", $this->getSettingByName("notification_email"));
  82.             $this->setGlobalTemplateVariable("enable_wysiwyg_editor", $this->getSettingByName("enable_wysiwyg_editor"));
  83.             $this->setGlobalTemplateVariable("custom_settings", $this->CustomSettings->getSettingsToRegister());
  84.             $this->setGlobalTemplateVariable("mobile_front_end_url", $this->doesAppExist("mobileFrontEnd") ? $this->getApp("mobileFrontEnd")->getSystemSettings("SITE_URL") : null);
  85.             $this->setGlobalTemplateVariable("enable_share_block", $this->getSettingByName("enable_share_block"));
  86.             $this->_ModuleManager->executeModulesStartupFunctions();
  87.         }
  88.         private function executeAfterInitFunctions() {
  89.             foreach($this->_functionsToExecuteAfterInit as $fnDefenition) {
  90.                 call_user_func_array($fnDefenition['function'], array($this, $fnDefenition['params']));
  91.             }
  92.         }
  93.         public function getI18N() {
  94.             if (!isset($this->_Services['I18N'])) {
  95.                 $this->createSingletonServiceByClassName("I18N");
  96.             }
  97.             return $this->I18N;
  98.         }
  99.         public function get($serviceName) {
  100.             if (!isset($this->knownServiceClassNames[$serviceName]) && !isset($this->_Services[$serviceName])) {
  101.                 $this->ServiceManager->tryToFindAndCreateService($serviceName);
  102.             }
  103.             if (isset($this->knownServiceClassNames[$serviceName])) {
  104.                 $this->lazyCreateSingletonServiceByClassName($serviceName);
  105.                 unset($Var_456[$serviceName]);
  106.             }
  107.             if (!isset($this->_Services[$serviceName])) {
  108.                 throw new Exception("Unknown service \"{$serviceName}\" requested");
  109.             }
  110.             return $this->_Services[$serviceName]->getServiceInstance();
  111.         }
  112.         public function __get($serviceName) {
  113.             return $this->get($serviceName);
  114.         }
  115.         public function createSingletonServiceByClassName($className) {
  116.             if (!isset($this->_Services[$className])) {
  117.                 $this->knownServiceClassNames[$className] = true;
  118.             }
  119.         }
  120.         private function lazyCreateSingletonServiceByClassName($className) {
  121.             $service = $this->createContextAwareObjectOfClass($className);
  122.             if (method_exists($service, "init")) {
  123.                 $service->init();
  124.             }
  125.             $this->registerService($className, new SingletonServiceProvider($service));
  126.         }
  127.         public function createContextAwareObjectOfClass($className) {
  128.             $obj = new $className();
  129.             if (!$obj instanceof IApplicationContextAware) {
  130.                 throw new Exception("Non-context aware class \"{$className}\" passed to createContextAwareObjectOfClass");
  131.             }
  132.             $obj->setAppContext($this);
  133.             return $obj;
  134.         }
  135.         private function createModuleManager() {
  136.             require_once ("ModuleManager.php");
  137.             $moduleManager = $this->createContextAwareObjectOfClass("ModuleManager");
  138.             $moduleManager->setPathManager($this->PathManager);
  139.             $moduleManager->init();
  140.             return $moduleManager;
  141.         }
  142.         private function createServiceManager() {
  143.             require_once ("ServiceManager.php");
  144.             $instance = $this->createContextAwareObjectOfClass("ServiceManager");
  145.             $instance->setPathManager($this->PathManager);
  146.             $instance->init();
  147.             return $instance;
  148.         }
  149.         public function getSystemSettings($setting_name) {
  150.             return $this->getSetting($setting_name);
  151.         }
  152.         public function loadSystemSettings($file_name) {
  153.             if (is_readable($file_name)) {
  154.                 if (!isset($GLOBALS['system_settings'])) {
  155.                     $GLOBALS['system_settings'] = array();
  156.                 }
  157.                 $settings = require_once ($file_name);
  158.                 if (gettype($settings) == "array") {
  159.                     $GLOBALS['system_settings'] = array_merge($GLOBALS['system_settings'], $settings);
  160.                 }
  161.             } else {
  162.                 exit("index.php" . " File {$file_name} isn't readable Cannot read config file");
  163.             }
  164.         }
  165.         public function getGlobalTemplateVariables() {
  166.             return $GLOBALS['TEMPLATE_VARIABLES'];
  167.         }
  168.         public function boot() {
  169.             $path_to_system_core = $this->getSetting("CLASSES_DIR");
  170.             set_include_path("." . PATH_SEPARATOR . $this->getSetting("LIBRARY_DIR"));
  171.             set_include_path(get_include_path() . PATH_SEPARATOR . $this->getSetting("EXT_LIBRARY_DIR"));
  172.         }
  173.         public function getGlobalTemplateVariable($variable_name) {
  174.             return isset($GLOBALS['TEMPLATE_VARIABLES'][$variable_name]) ? $GLOBALS['TEMPLATE_VARIABLES'][$variable_name] : null;
  175.         }
  176.         public function setGlobalTemplateVariable($name, $value, $in_global_array = true) {
  177.             if ($in_global_array) {
  178.                 $GLOBALS['TEMPLATE_VARIABLES']['GLOBALS'][$name] = $value;
  179.             } else {
  180.                 $GLOBALS['TEMPLATE_VARIABLES'][$name] = $value;
  181.             }
  182.         }
  183.         public function getModuleManager() {
  184.             return $this->_ModuleManager;
  185.         }
  186.         public function getTemplateProcessor() {
  187.             $module_manager = $this->getModuleManager();
  188.             $module = $module_manager->getCurrentModuleAndFunction() [0];
  189.             if ($module != null) {
  190.                 $template_processor = $this->createTemplateProcessor($module);
  191.                 return $template_processor;
  192.             }
  193.             return null;
  194.         }
  195.         public function createTemplateProcessor($module) {
  196.             if (is_null($this->TemplateProcessorPrototype)) {
  197.                 $fileSystem = new FileSystem();
  198.                 $templateFactory = new TemplateFactory();
  199.                 $templateFactory->setFileSystem($fileSystem);
  200.                 $templatePathManager = new TemplatePathManager($this->getSystemSettings("TEMPLATES_DIR"));
  201.                 $factory = new ThemeFactory();
  202.                 $factory->setSiteUrl($this->getSetting("SITE_URL"));
  203.                 $factory->setTemplatePathManager($templatePathManager);
  204.                 $factory->setFileNotFoundAction($this->getFileNotFoundAction());
  205.                 $factory->setTemplateFactory($templateFactory);
  206.                 $factory->setFileSystem($fileSystem);
  207.                 $themeBuilder = new ThemeBuilder();
  208.                 $themeBuilder->setThemeFactory($factory);
  209.                 $themeManager = $this->createContextAwareObjectOfClass("ThemeManager");
  210.                 $themeManager->setThemeBuilder($themeBuilder);
  211.                 $theme = $themeManager->getCurrentTheme();
  212.                 require_once ($this->getSystemSettings("SMARTY_PATH"));
  213.                 $template_processor = $this->createContextAwareObjectOfClass("TemplateProcessor");
  214.                 $template_processor->init();
  215.                 $template_processor->setHtmlTagConverter($this->ObjectMother->createHTMLTagConverterInArray());
  216.                 $path = new Path();
  217.                 $template_processor->compile_dir = $this->PathProvider->getCacheDir($path->combine($this->getSystemSettings("COMPILED_TEMPLATES_DIR"), $this->getSystemSettings("SYSTEM_ACCESS_TYPE"), $theme->getName()));
  218.                 $i18n = $this->getI18N();
  219.                 $template_processor->registerFilter("pre", array($i18n, "replace_translation_alias"));
  220.                 $template_processor->registerPlugin("block", "tr", array($i18n, "translate"));
  221.                 $template_processor->registerObject("i18n", $i18n);
  222.                 $template_processor->registerPlugin("function", "display_error_messages", array($this->get("Messages"), "fetchErrorMessages"));
  223.                 $template_processor->registerPlugin("function", "display_success_messages", array($this->get("Messages"), "fetchSuccessMessages"));
  224.                 $template_processor->registerPlugin("function", "get_custom_setting", array($this->get("CustomSettings"), "getSettingValueFromTemplate"));
  225.                 $this->getTemplateExternalComponentManager()->register($template_processor);
  226.                 $this->setGlobalTemplateVariable("themeInheritanceBranch", $themeManager->getThemeInheritanceBranch());
  227.                 $this->setGlobalTemplateVariable("current_theme", $theme->getName());
  228.                 $templateSupplier = new TemplateSupplier();
  229.                 $templateSupplier->setTheme($theme);
  230.                 $this->TemplateProcessorPrototype = $template_processor;
  231.                 $this->TemplateSupplierPrototype = $templateSupplier;
  232.             }
  233.             $template_processor = clone $this->TemplateProcessorPrototype;
  234.             $templateSupplier = clone $this->TemplateSupplierPrototype;
  235.             $templateSupplier->setModuleName($module);
  236.             $templateSupplier->registerResources($template_processor);
  237.             $template_processor->assign($this->getGlobalTemplateVariables());
  238.             return $template_processor;
  239.         }
  240.         public function getFileNotFoundAction() {
  241.             switch ($this->getSystemSettings("FILE_NOT_FOUND_ACTION")) {
  242.                 case "ReturnNull":
  243.                     return new ReturnNullAction();
  244.                 case "Return404":
  245.                     return new Return404Action($this->getSystemSettings("SITE_URL") . $this->getSystemSettings("PAGE_404_URI"));
  246.                 case "ThrowException":
  247.                     return new ThrowFileNotFoundExceptionAction();
  248.             }
  249.         }
  250.         private function getTemplateExternalComponentManager() {
  251.             if (!isset($this->_Services['TemplateExternalComponentManager'])) {
  252.                 $templateExternalComponentManager = new TemplateExternalComponentManager();
  253.                 $templateExternalComponentManager->setSiteUrl($this->getSystemSettings("SITE_URL"));
  254.                 $templateExternalComponentManager->setExternalComponentsPath($this->PathManager->getExternalComponentsPath());
  255.                 $templateExternalComponentManager->setFileNotFoundAction($this->getFileNotFoundAction());
  256.                 $this->registerService("TemplateExternalComponentManager", new SingletonServiceProvider($templateExternalComponentManager));
  257.             }
  258.             return $this->TemplateExternalComponentManager;
  259.         }
  260.         public function setCurrentUserInfo($current_user_info) {
  261.             $this->setGlobalTemplateVariable("current_user", $current_user_info);
  262.         }
  263.         public function setPageTitle($page_title) {
  264.             $this->setGlobalTemplateVariable("TITLE", $page_title, false);
  265.         }
  266.         public function getPageTitle() {
  267.             return $this->getGlobalTemplateVariable("TITLE");
  268.         }
  269.         public function setPageKeywords($page_keywords) {
  270.             $this->setGlobalTemplateVariable("KEYWORDS", $page_keywords, false);
  271.         }
  272.         public function getPageKeywords() {
  273.             return $this->getGlobalTemplateVariable("KEYWORDS");
  274.         }
  275.         public function setPageDescription($page_description) {
  276.             $this->setGlobalTemplateVariable("DESCRIPTION", $page_description, false);
  277.         }
  278.         public function getPageDescription() {
  279.             return $this->getGlobalTemplateVariable("DESCRIPTION");
  280.         }
  281.         public function getUserSettings($module_name, $setting_name) {
  282.             return $this->UserSettings->getSetting($module_name, $setting_name);
  283.         }
  284.         public function setUserSettings($module_name, $setting_name, $value) {
  285.             return $this->UserSettings->setSetting($module_name, $setting_name, $value);
  286.         }
  287.         public function executeFunction($module, $setting, $parameters = array(), $inheritRequest = true) {
  288.             $module_manager = $this->getModuleManager();
  289.             return $module_manager->executeFunction($module, $setting, $parameters, $inheritRequest);
  290.         }
  291.         public function getSystemURLByModuleAndFunction($module, $function, $parameters) {
  292.             $parameters_str = "";
  293.             $params = array();
  294.             foreach($parameters as $parameter_name => $parameter_value) {
  295.                 array_push($params, urlencode($parameter_name) . "=" . urlencode($parameter_value));
  296.             }
  297.             $parameters_str = join("&", $params);
  298.             $site_url = $this->getSystemSettings("SITE_URL");
  299.             $system_url_base = $this->getSystemSettings("SYSTEM_URL_BASE");
  300.             $url = $site_url . "/" . $system_url_base . "/" . $module . "/" . $function . "?" . $parameters_str;
  301.             return $url;
  302.         }
  303.         public function getModuleAndFunctionBySystemURL($url) {
  304.             $uri = explode("?", $url) [0];
  305.             $function = explode("/", $uri) [3];
  306.             $module = explode("/", $uri) [2];
  307.             return array("module" => $module, "function" => $function);
  308.         }
  309.         private function testLicense() {
  310.             $licenseFilename = $this->getSystemSettings("LICENSE_FILENAME");
  311.             $license = $this->createContextAwareObjectOfClass("License");
  312.             $license->setFilename($licenseFilename);
  313.             $license->setCode("375963276846296538");
  314.             if (!$license->isValid()) {
  315.                 header($_SERVER['SERVER_PROTOCOL'] . " 403 Forbidden");
  316.                 switch ($license->getError()) {
  317.                     case "FILE_NOT_FOUND":
  318.                         echo "Cannot find the license file. Please make sure that the license file is named \"{$licenseFilename}\" and is located in \"" . realpath(".") . "\"";
  319.                     break;
  320.                     case "INVALID_VERIFICATION_CODE":
  321.                         echo "The license code is invalid. Please make sure that license is issued to the correct URL: \"" . $this->getSystemSettings("SITE_URL") . "\"";
  322.                     break;
  323.                     case "EXPIRED_LICENSE":
  324.                         echo "The license has expired. Please refer to the WorksForWeb Sales Department (sales@worksforweb.com) for updating/extending your license.";
  325.                     break;
  326.                     default:
  327.                         echo "There is an error in your license. However, the cause of has not been identified.";
  328.                     break;
  329.                 }
  330.                 exit();
  331.             }
  332.         }
  333.         public function respond() {
  334.             $this->testLicense();
  335.             if ($this->IpRangeManager->isIpInBlockList(())) {
  336.                 $this->displayBlockedIpMessage();
  337.             } else if ($this->Navigator->isRequestedUnderLegalURI()) {
  338.                 $uri = $this->Navigator->getUri();
  339.                 $page_config = $this->PageManager->getPageConfig($uri);
  340.                 $this->registerService("PageConfig", new SingletonServiceProvider($page_config));
  341.                 if ($page_config->pageExists()) {
  342.                     echo $this->getResponse($page_config);
  343.                 } else {
  344.                     header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently");
  345.                     header("Location: {$_SERVER['REQUEST_URI']}/");
  346.                     echo "The requested resource is located under a different URL: {$_SERVER['REQUEST_URI']}/";
  347.                     return;
  348.                     if ($this->doesParentSitePageExist($uri)) {
  349.                         $parent_uri = $this->getSitePageParentURI($uri);
  350.                         $page_config = $this->PageConfig->getPageConfig($parent_uri);
  351.                         $passed_parameters_via_uri = substr($uri, strlen($parent_uri));
  352.                         $_REQUEST['passed_parameters_via_uri'] = $passed_parameters_via_uri;
  353.                         $page_content = $this->getResponse($page_config);
  354.                         echo $page_content;
  355.                     } else {
  356.                         header($_SERVER['SERVER_PROTOCOL'] . " 404 Not Found");
  357.                         echo "404 Not Found";
  358.                     }
  359.                 }
  360.             } else {
  361.                 header($_SERVER['SERVER_PROTOCOL'] . " 403 Forbidden");
  362.                 echo "The software is not configured to respond to requests to the following URL: <tt>http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}</tt>.\n<br>";
  363.             }
  364.         }
  365.         public function getCurrentPageConfig() {
  366.             return isset($GLOBALS['CURRENT_PAGE_CONFIG']) ? $GLOBALS['CURRENT_PAGE_CONFIG'] : null;
  367.         }
  368.         public function getFunctionInfo($module, $function) {
  369.             $module_manager = $this->getModuleManager();
  370.             $module_info = $module_manager->getModuleInfo($module);
  371.             return array();
  372.         }
  373.         public function getSystemDefaultTemplate() {
  374.             return $this->getSystemSettings("SYSTEM_DEFAULT_TEMPLATE");
  375.         }
  376.         public function isFunctionAccessible($module, $function) {
  377.             $module_manager = $this->getModuleManager();
  378.             return $module_manager->doesFunctionExist($module, $function);
  379.         }
  380.         public function prepareGlobalArrays() {
  381.             if (@ini_get("register_globals")) {
  382.                 $unset = array_keys($_ENV + $_GET + $_POST + $_COOKIE + $_SERVER);
  383.                 foreach($unset as $rg_var) {
  384.                     if (isset($rg_var)) {
  385.                     }
  386.                 }
  387.                 unset($unset);
  388.             }
  389.             if ($_SERVER['REQUEST_METHOD'] == "POST") {
  390.                 $_REQUEST = $_POST;
  391.             } else {
  392.                 $_REQUEST = $_GET;
  393.             }
  394.             if (get_magic_quotes_gpc()) {
  395.                 $this->unquote($_REQUEST);
  396.             }
  397.         }
  398.         private function unquote(&$arr) {
  399.             if (!get_magic_quotes_gpc()) {
  400.             } else {
  401.                 foreach($arr as $index => $value) {
  402.                     if (is_array($arr[$index])) {
  403.                         unquote($arr[$index]);
  404.                     } else {
  405.                         $arr[$index] = stripslashes($arr[$index]);
  406.                     }
  407.                 }
  408.             }
  409.         }
  410.         public function requireAllFilesInDirectory($dir) {
  411.             if (is_dir($dir) && ($dh = opendir($dir))) {
  412.                 while (($file = readdir($dh)) !== false) {
  413.                     if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
  414.                         if ($file != "." && $file != "..") {
  415.                             $this->requireAllFilesInDirectory($dir . DIRECTORY_SEPARATOR . $file);
  416.                         }
  417.                     } else if (!(4 < strlen($file)) || !(strtolower(substr($file, strlen($file) - 4)) == ".php")) {
  418.                         require_once ($dir . DIRECTORY_SEPARATOR . $file);
  419.                     }
  420.                 }
  421.                 closedir($dh);
  422.             }
  423.         }
  424.         public function getResponse($page_config) {
  425.             $this->createSingletonServiceByClassName("PageConstructor");
  426.             return $this->PageConstructor->getResponse($page_config);
  427.         }
  428.         public function doesFunctionHaveRawOutput($module, $function) {
  429.             return $this->getModuleManager()->doesFunctionHaveRawOutput($module, $function);
  430.         }
  431.         public function getPageConfig($uri) {
  432.             return $this->PageManager->getPageConfig($uri);
  433.         }
  434.         public function getSitePages($accessType) {
  435.             return $this->PageManager->get_pages($accessType);
  436.         }
  437.         public function getSitePage($uri, $accessType) {
  438.             return $this->PageManager->get_page($uri, $accessType);
  439.         }
  440.         public function doesSitePageExists($uri, $access_type) {
  441.             return $this->PageManager->doesPageExists($uri, $access_type);
  442.         }
  443.         public function getModulesList() {
  444.             return $this->getModuleManager()->getModulesList();
  445.         }
  446.         public function getFunctionsList($module) {
  447.             return $this->getModuleManager()->getFunctionsList($module, $this->getSystemSettings("SYSTEM_ACCESS_TYPE"));
  448.         }
  449.         public function getParamsList($module, $function) {
  450.             return $this->getModuleManager()->getParamsList($module, $function);
  451.         }
  452.         public function getURI() {
  453.             return $this->Navigator->getURI();
  454.         }
  455.         public function getRegisteredCommands() {
  456.             $module_manager = $this->getModuleManager();
  457.             return $module_manager->getRegisteredCommands();
  458.         }
  459.         public function getCommandScriptAbsolutePath($module, $command) {
  460.             $module_manager = $this->getModuleManager();
  461.             return $module_manager->getCommandScriptAbsolutePath($module, $command);
  462.         }
  463.         public function getModuleOfCommand($command) {
  464.             $module_manager = $this->getModuleManager();
  465.             return $module_manager->getModuleOfCommand($command);
  466.         }
  467.         public function getPackageInfo($package_name) {
  468.             $moduleConfigurator = new ModuleConfigurator();
  469.             return $moduleConfigurator->getPackageInfo($package_name);
  470.         }
  471.         public function getModulesConditionsInfo() {
  472.             $moduleConfigurator = new ModuleConfigurator();
  473.             return $moduleConfigurator->getModulesConditionsInfo();
  474.         }
  475.         public function getSettingsFromFile($file_name, $setting_name) {
  476.             $settings = require ($file_name);
  477.             return isset($settings[$setting_name]) ? $settings[$setting_name] : null;
  478.         }
  479.         public function getSettingByName($setting_name) {
  480.             return $this->Settings->getSettingByName($setting_name);
  481.         }
  482.         public function doesParentSitePageExist($uri) {
  483.             return $this->PageManager->doesParentPageExist($uri, "user");
  484.         }
  485.         public function getSitePageParentURI($uri) {
  486.             return $this->PageManager->getPageParentURI($uri, "user");
  487.         }
  488.         public function redirect($url) {
  489.             if (empty($url)) {
  490.                 $request_uri = $_SERVER['REQUEST_URI'];
  491.                 $query_string = $_SERVER['QUERY_STRING'];
  492.                 $url = str_replace("?" . $query_string, "", $request_uri);
  493.             }
  494.             header("{$_SERVER['SERVER_PROTOCOL']} 303 See Other");
  495.             header("Location: {$url}");
  496.             exit();
  497.         }
  498.         public function getApp($appId) {
  499.             $currentDir = getcwd();
  500.             $currentIncludePath = get_include_path();
  501.             $instance = new System($appId);
  502.             $instance->loadSettings($this->getSystemSettings("APPLICATIONS_DIR") . "{$appId}/config/DefaultSettings.php");
  503.             $instance->loadSettings($this->getSystemSettings("APPLICATIONS_DIR") . "{$appId}/config/LocalSettings.php");
  504.             chdir($this->getSystemSettings("ROOT_DIR") . $instance->getSystemSettings("ENTRY_POINT_RELATIVE_TO_ROOT_DIR"));
  505.             $instance->boot();
  506.             $instance->init();
  507.             chdir($currentDir);
  508.             set_include_path($currentIncludePath);
  509.             return $instance;
  510.         }
  511.         public function doesAppExist($appId) {
  512.             return is_dir($this->getSystemSettings("APPLICATIONS_DIR") . $appId);
  513.         }
  514.     }
  515.     class Cryptographer {
  516.         private $expiration_date;
  517.         private $site_url;
  518.         private $inserted_words;
  519.         private $context;
  520.         public function Cryptographer($expiration_date, $site_url = null) {
  521.             $this->site_url = $site_url;
  522.             $this->expiration_date = $expiration_date;
  523.             $this->inserted_words = array("ASDFG14235", "*&^%\$GKLTYCJQZ)(*", "-=+[]lFCBFgfd@");
  524.         }
  525.         public function getCrypt($base, $context) {
  526.             $this->site_url = empty($site_url) ? $context->getSystemSettings("SITE_URL") : $site_url;
  527.             return $this->_getEncryptedCombination($this->_getCombinedUnEncryptedString($base), 0);
  528.         }
  529.         public function _getCombinedUnEncryptedString($base) {
  530.             $result = join("", $this->inserted_words);
  531.             return $this->site_url . $this->expiration_date;
  532.         }
  533.         public function _getEncryptedCombination($string, $counter) {
  534.             $result = md5($counter) . base64_encode($string) . crc32($string);
  535.             return md5($string);
  536.         }
  537.         public function getCode() {
  538.             return "bFo9N28HOTJUBl8lVQc5KlVaOXNVcVo0bHw9MWxsJi18c1sxfHMmMlNDWwl1Z1MzbwYtMVRyUnNVBj07bgYxc1RZ\r\n\t\tJi1/WSUtbGMlMH9dADN6Q1sJdWMHL393AyxsbDkIVGMtLGxhEzRvYzkuVV8lNGxzPi18cyY2ZlkPLlJyJXdVBzkuVGIlLlJ8\r\n\t\tOTJUWQ84fXchBmJxLRZjBD0WbgQ5CGNdIjJ/d18lf1gld1UHOS5UZ141V3wqK31nKipmZyksbGw5CFRjLSxsYRM0b2M5LlVf\r\n\t\tJTRscz4tfWcAJVVZPXJSbCE3eUNbCXVnUzNXWQRxV3wHc1dOBHR4TghwV3MPd1JjWy19YFI7bGw5c1VZXyVsWS0xVQY+dFVZ\r\n\t\tPXJSbCE3f3w5O1JjPnV9XVMMdVMAKVRnW2lVBzkqVVo5c1VxWjRsfD0xbGwmLX1gGCV6TQQMdVMAKVJzAzJVTVtpVVo9N2cG\r\n\t\tAy5vBhgtf3ciKW9sJjN6B1s0fV0iJX1gGAx1UwA0ek0qM3pDWwlsWj03bwc5MlQGXyVvWSUpV2MxL313OTF6dyopbwZSKWxn\r\n\t\tAAx1WhgMdVMHMmxdKi1sBj1yZWNaKmwGPQ9UBi0pbGwhBlQGOS59czkyVVleKlRjPi1uBVIFZWETBG4FUzJ/d18lf11SFlNs\r\n\t\tJXJsY1s3VXMDNX9dACV/YFslbAY9cmVjWipsBj0PVAYtKWxsIQZUBjkufXcAMn98IS5SfD07VF0qOnlDWwl1ZzkxemBeOGxs\r\n\t\tOQZUBjkufXcDOFJ8ITJUWQgyfXMDLlNzOS5vTQM4UmMhOFJ8Ii1sBj1yZWNaKmwGPQ9UBi0pbGwhBlQGOS59czkyVVleKlRj\r\n\t\tPi1uBVIFZWETBG4FUzJ/d18lf11SFlNsJXJsY1s3VXMDNX9dADF7dxxzfWcAJW5dKSxsbDkrbwY5MlJdDDJ9Zyo3f3MPLlJz\r\n\t\tIShUY1IpfXcAMnlDWwl1bCEuUnw9O1RdKjp5Q1sJUGVWfw==";
  539.         }
  540.     }
  541.     function autoload($className) {
  542.         @include ($className . ".php");
  543.     }
  544.     require_once ("Functions.php");
  545.     spl_autoload_register("autoload");
  546.     class SingletonServiceProvider implements IServiceProvider, IApplicationContextAware {
  547.         private $serviceInstance = null;
  548.         public function __construct($serviceInstance) {
  549.             $this->serviceInstance = $serviceInstance;
  550.         }
  551.         public function getServiceInstance() {
  552.             return $this->serviceInstance;
  553.         }
  554.     }
  555. ?>
Add Comment
Please, Sign In to add comment