PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/src/TTloader.php

https://github.com/oveas/terra-terra
PHP | 678 lines | 354 code | 88 blank | 236 comment | 58 complexity | 366da82480f5b4a189c713e6a9ae4b97 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0
  1. <?php
  2. /**
  3. * \file
  4. * \ingroup TT_LIBRARY
  5. * This file loads the TT environment and initialises some singletons
  6. * \copyright{2007-2014} Oscar van Eijk, Oveas Functionality Provider
  7. * \license
  8. * This file is part of Terra-Terra.
  9. *
  10. * Terra-Terra is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * any later version.
  14. *
  15. * Terra-Terra is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with Terra-Terra. If not, see http://www.gnu.org/licenses/.
  22. */
  23. // Error handling used during development
  24. error_reporting(E_ALL | E_STRICT);
  25. // Doxygen setup
  26. /**
  27. * \defgroup TT_UI_LAYER Presentation Layer modules
  28. * \defgroup TT_BO_LAYER Business Layer modules
  29. * \defgroup TT_SO_LAYER Storage Layer modules
  30. * \defgroup TT_LIBRARY Library (codes, messages files etc.)
  31. * \defgroup TT_CONTRIB Contributed helper functions
  32. * \defgroup TT_UI_PLUGINS Plugins for the presentation modules
  33. * \defgroup TT_DRIVERS Drivers
  34. * \defgroup TT_TTADMIN TT administration site
  35. */
  36. /**
  37. * \defgroup GlobalConstants Global constants
  38. * These constants define all paths for TT
  39. * @{
  40. */
  41. // TT_ROOT must be defined by the application
  42. if (!defined('TT_ROOT')) { trigger_error('TT_ROOT must be defined by the application', E_USER_ERROR); }
  43. //! Application code for Terra-Terra
  44. define ('TT_CODE', 'TT');
  45. //! Toplevel for the TT includes
  46. define ('TT_INCLUDE', TT_ROOT . '/kernel');
  47. //! Storage layer includes
  48. define ('TT_SO_INC', TT_ROOT . '/kernel/so');
  49. //! Business layer includes
  50. define ('TT_BO_INC', TT_ROOT . '/kernel/bo');
  51. //! Presentation layer includes
  52. define ('TT_UI_INC', TT_ROOT . '/kernel/ui');
  53. //! TT library
  54. define ('TT_LIBRARY', TT_ROOT . '/lib');
  55. //! Default log directory
  56. define ('TT_LOG', TT_ROOT . '/log');
  57. //! TT's temp directory. This directory must be writeable by the http user
  58. define ('TT_TEMP', TT_ROOT . '/tmp');
  59. //! TT plugindirectory
  60. define ('TT_PLUGINS', TT_ROOT . '/plugins');
  61. //! TT divers directory
  62. define ('TT_DRIVERS', TT_ROOT . '/drivers');
  63. //! Location for all contributed plugins
  64. define ('TT_CONTRIB', TT_LIBRARY . '/contrib');
  65. //! Toplocation of this server, contains serverwide TT installations
  66. define ('TT_SERVER_TOP', $_SERVER['DOCUMENT_ROOT']);
  67. if (strpos($_SERVER['SCRIPT_FILENAME'], $_SERVER['DOCUMENT_ROOT']) === 0) {
  68. //! Toplocation of this site (directory)
  69. define ('TT_SITE_TOP', $_SERVER['DOCUMENT_ROOT']);
  70. } else {
  71. // Hack to support userdirs
  72. $_pathElements = explode('/', $_SERVER['PHP_SELF']);
  73. array_shift($_pathElements); // Remove leading /
  74. //! Home location when running in an Apache user environment (http://server/~user)
  75. define ('TT_USER_LOCATION', array_shift($_pathElements));
  76. //! Toplocation of this site (directory) in a user specific environment
  77. define ('TT_SITE_TOP', preg_replace('/\/' . implode ('\/', $_pathElements) . '$/', '', $_SERVER['SCRIPT_FILENAME']));
  78. }
  79. //! Toplocation of Terra-Terra (URL)
  80. define ('TT_TT_URL', str_replace(TT_SITE_TOP, '', TT_ROOT));
  81. //! Default URL used for all callbacks (like form actions, AJAX requests etc)
  82. define ('TT_CALLBACK_URL', $_SERVER['PHP_SELF']);
  83. //! Top location (URL) of Terra-Terra/JS
  84. define ('TT_JS_TOP', TT_TT_URL . '/js');
  85. //! Location of the TT-JS library files
  86. define ('TT_JS_LIB', TT_JS_TOP . '/lib');
  87. //! Location of the TT-JS plugins
  88. define ('TT_JS_PLUGINS', TT_JS_TOP . '/plugins');
  89. if (!defined ('TT_TIMERS_ENABLED')) {
  90. //! When true, times are shown at the bottom of the page. Can be set by the application
  91. define ('TT_TIMERS_ENABLED', false);
  92. }
  93. //! Key for the application ID as stored in cache
  94. define ('TT_APPITM_ID', 'id');
  95. //! Key for the application name as stored in cache
  96. define ('TT_APPITM_NAME', 'name');
  97. //! Key for the application's version as stored in cache
  98. define ('TT_APPITM_VERSION', 'version');
  99. //! Key for the application's release date as stored in cache
  100. define ('TT_APPITM_RELEASED', 'released');
  101. //! Key for the application's top-url as stored in cache
  102. define ('TT_APPITM_URL', 'url');
  103. //! Key for the application's site top as stored in cache
  104. define ('TT_APPITM_TOP', 'top');
  105. //! Key for the application's library as stored in cache
  106. define ('TT_APPITM_LIBRARY', 'lib');
  107. //! @}
  108. /**
  109. * \ingroup TT_SO_LAYER
  110. * Abstract class to load other classfiles
  111. * \brief Class loader
  112. * \author Oscar van Eijk, Oveas Functionality Provider
  113. * \version Oct 7, 2010 -- O van Eijk -- Initial version for OWL-PHP
  114. */
  115. abstract class TTloader
  116. {
  117. //! Code of the primary application we're running
  118. private static $primaryApp;
  119. //! Code of the active application instantiated by the dispatcher
  120. private static $currentApp;
  121. //! List of all application ID's that have been loaded
  122. private static $appsLoaded;
  123. //! Boolean set to true when the configuration files have been loaded
  124. private static $configLoaded = false;
  125. //! Array with all available applications that contain hooks for display in the menu
  126. private static $externalAppList = array();
  127. /**
  128. * Load a contentarea. This is done by calling the loadArea() method of the given class.
  129. * \param[in] $_classFile Name of the classfile. This must the full filename without '.php'
  130. * The name must be equal to the name of the class without 'Area in camelcase, so if the name of
  131. * the classfile is 'myspot.php', the classname must be 'MyspotArea' and this argument must
  132. * be 'myspot'
  133. * \param[in] $_classLocation Full path specification (can be as a constant) where the file can
  134. * be found
  135. * \param[in] $_argument An optional argument that will be passed to the loadArea() method. The
  136. * classmethod must accept this argument and must always have a default specified, since nothing
  137. * will be passed if $_argument is null (also not 'null'!)
  138. * \return Reference to the object which is an instantiation of the class, null on erros
  139. * \author Oscar van Eijk, Oveas Functionality Provider
  140. */
  141. public static function getArea ($_classFile, $_classLocation, $_argument = null)
  142. {
  143. if (!self::_tryLoad($_classFile . '.php', $_classLocation)) {
  144. TT::stat(__FILE__, __LINE__, TT_LOADERR, array('Area class', $_classFile, $_classLocation));
  145. return null;
  146. }
  147. $_className = ucfirst($_classFile . 'Area');
  148. if (!class_exists($_className)) {
  149. TT::stat(__FILE__, __LINE__, TT_LOADERR, array($_className));
  150. return null;
  151. }
  152. $_cArea = new $_className();
  153. if ($_argument === null) {
  154. $_loadResult = $_cArea->loadArea();
  155. } else {
  156. $_loadResult = $_cArea->loadArea($_argument);
  157. }
  158. if ($_loadResult === false) {
  159. return null;
  160. } else {
  161. return $_cArea;
  162. }
  163. }
  164. /**
  165. * Load a driverfile
  166. * \param[in] $_driverName Name of the class. Will be converted to lowercase to find the classfile
  167. * \param[in] $_driverType Driver type, must match the directoryname in TT_DRIVERS where the classfile can be found,
  168. * and the filenams for the interface (class.&lt;driverType&gt;driver.php) and abstract default
  169. * class (class.&lt;driverType&gt;defaults.php) if they exist.
  170. * \return True on success
  171. * \author Oscar van Eijk, Oveas Functionality Provider
  172. */
  173. public static function getDriver ($_driverName, $_driverType)
  174. {
  175. // First load the interface and abstract default class, ignoring any errors, since they
  176. // might not exist or have been loaded already.
  177. self::getInterface($_driverType . 'driver', TT_DRIVERS . '/' . $_driverType);
  178. self::getClass($_driverType . 'defaults', TT_DRIVERS . '/' . $_driverType);
  179. return (self::getClass(strtolower($_driverName), TT_DRIVERS . '/' . $_driverType));
  180. }
  181. /**
  182. * Load a PHP interfacefile. The interface must be described in a file called "interface.&lt;interfaceName&gt;.php.
  183. * \param[in] $_interfaceName Name of the interface (not the filename!)
  184. * \param[in] $_interfaceLocation Full path to thelocation of the interface
  185. * \return True on success
  186. * \author Oscar van Eijk, Oveas Functionality Provider
  187. */
  188. public static function getInterface ($_interfaceName, $_interfaceLocation)
  189. {
  190. if (interface_exists($_interfaceName)) {
  191. return true;
  192. }
  193. $_interfaceFile = $_interfaceLocation . '/interface.' . strtolower($_interfaceName) . '.php';
  194. if (!file_exists($_interfaceFile)) {
  195. return false;
  196. }
  197. require ($_interfaceFile);
  198. return true;
  199. }
  200. /**
  201. * Load a PHP classfile
  202. * \param[in] $_className Name of the class; either file full name (&lt;filename.php&gt; or the identifying name ([class.]&lt;name&gt;[.php])
  203. * \param[in] $_classLocation (Array of) location(s) where to look for the class
  204. * \param[in] $_loadMultiple Boolean; by default, the first matching classname will be loaded. Set this to true to load all files with the same name from multiple locations
  205. * \return True on success
  206. * \author Oscar van Eijk, Oveas Functionality Provider
  207. */
  208. public static function getClass ($_className, $_classLocation = array(TT_SO_INC, TT_BO_INC, TT_UI_INC), $_loadMultiple = false)
  209. {
  210. if (!is_array($_classLocation)) {
  211. return self::_tryLoad($_className, $_classLocation);
  212. }
  213. // We got an array; try all locations
  214. $_returnValue = false;
  215. foreach ($_classLocation as $_location) {
  216. if (self::_tryLoad($_className, $_location) === true) { // Found a matching classname
  217. if (!$_loadMultiple) {
  218. return true; // Only 1st matching class will be loaded
  219. }
  220. $_returnValue = true;
  221. }
  222. }
  223. return $_returnValue;
  224. }
  225. /**
  226. * Try loading a class from a specific location
  227. * \private
  228. * \param[in] $_className Name of the classfile
  229. * \param[in] $_classLocation Location where to tru loading it from
  230. * \return True on success
  231. * \author Oscar van Eijk, Oveas Functionality Provider
  232. */
  233. private static function _tryLoad ($_className, $_classLocation)
  234. {
  235. $_origClassName = $_className;
  236. $_classPath = $_classLocation . '/' . $_className;
  237. if (class_exists('TTCache') && ($_loaded = TTCache::get(TTCACHE_CLASSES, $_classPath)) !== null) {
  238. return $_loaded;
  239. }
  240. if (!file_exists($_classLocation . '/' . $_className)) {
  241. // Try the classname with suffix 'php'
  242. $_className = $_className.'.php';
  243. if (!file_exists($_classLocation . '/' . $_className)) {
  244. // Try the classname with prefix 'class'
  245. $_className = 'class.'.$_className;
  246. if (!file_exists($_classLocation . '/' . $_className)) {
  247. // trigger_error('Classfile ' . $_classLocation . '/[class.]' . $_origClassName . '[.php] not found', E_USER_WARNING);
  248. return TTCache::set(TTCACHE_CLASSES, $_classPath, false);
  249. }
  250. }
  251. }
  252. $_classPath = $_classLocation . '/' . $_className;
  253. if (class_exists('TTCache') && ($_loaded = TTCache::get(TTCACHE_CLASSES, $_classPath)) !== null) {
  254. return $_loaded;
  255. }
  256. require ($_classPath);
  257. if (!class_exists('TTCache')) {
  258. trigger_error('TTCache is not loaded first', E_USER_ERROR);
  259. }
  260. return TTCache::set(TTCACHE_CLASSES, $_classPath, true);
  261. }
  262. /**
  263. * Read Terra-Terra's own ID from the database
  264. * \param[in] $app_code Application code, defaults to Terra-Terra's code
  265. * \return Application ID for the requested app
  266. * \author Oscar van Eijk, Oveas Functionality Provider
  267. */
  268. public static function getTTId ($app_code = TT_CODE)
  269. {
  270. // First, try to read ffrom cache
  271. if (($_id = TTCache::getApplic ($app_code, TT_APPITM_ID)) !== null) {
  272. return $_id;
  273. }
  274. // Not yet set; get it from the db
  275. $dataset = new DataHandler();
  276. if (ConfigHandler::get ('database', 'tttables', true)) {
  277. $dataset->setPrefix(ConfigHandler::get ('database', 'ttprefix', 'tt'));
  278. }
  279. $dataset->setTablename('applications');
  280. $dataset->set('code', $app_code);
  281. $dataset->setKey('code');
  282. $dataset->prepare();
  283. $dataset->db($_id, __LINE__, __FILE__);
  284. if (count($_id) == 0) {
  285. if (defined('TT___INSTALLER')) {
  286. // TT being installed
  287. return 0;
  288. } else {
  289. trigger_error('TT application not found in the database - has it been installed?', E_USER_ERROR);
  290. }
  291. }
  292. return ($_id[0]['aid']);
  293. }
  294. /**
  295. * Load the application environment
  296. * \param[in] $applic_code Application code
  297. * \param[in] $primary True (default) for a primary application, false when loaded by the dispatcher (for an external contentarea).
  298. * When called from the entry-point of an application, this must always be true.
  299. * \author Oscar van Eijk, Oveas Functionality Provider
  300. */
  301. public static function loadApplication ($applic_code, $primary = true)
  302. {
  303. if (TTCache::getApplic($applic_code) === null) {
  304. $dataset = new DataHandler();
  305. if (ConfigHandler::get ('database', 'tttables', true)) {
  306. $dataset->setPrefix(ConfigHandler::get ('database', 'ttprefix', 'tt'));
  307. }
  308. $dataset->setTablename('applications');
  309. $dataset->set('code', $applic_code);
  310. $dataset->setKey('code');
  311. $dataset->prepare();
  312. $dataset->db($app_data, __LINE__, __FILE__);
  313. if ($dataset->dbStatus() === DBHANDLE_NODATA) {
  314. TT::stat(__FILE__, __LINE__, TT_APP_NOTFOUND, array($applic_code));
  315. return;
  316. }
  317. TTCache::addApplic(
  318. $applic_code
  319. , array(
  320. TT_APPITM_ID => $app_data[0]['aid']
  321. ,TT_APPITM_NAME => $app_data[0]['name']
  322. ,TT_APPITM_VERSION => $app_data[0]['version']
  323. ,TT_APPITM_RELEASED => $app_data[0]['released']
  324. ,TT_APPITM_URL => '/' . $app_data[0]['url']
  325. ,TT_APPITM_TOP => TT_SITE_TOP . '/' . $app_data[0]['url']
  326. ,TT_APPITM_LIBRARY => TT_SITE_TOP . '/' . $app_data[0]['url'] . '/lib'
  327. )
  328. );
  329. }
  330. if ($primary === true) {
  331. self::$primaryApp = $applic_code;
  332. }
  333. self::$currentApp = $applic_code;
  334. /**
  335. * \todo FIXME This is messy... we need a decent solution here. Should configurations for other applics be loaded as well?
  336. * I suppose so... we might need DBHandler clones...
  337. * */
  338. if (self::$configLoaded === false || $primary === true) {
  339. $_cfgFiles = &TTCache::getRef(TTCACHE_CONFIG, 'files');
  340. // If an APP_CONFIG file has been defined, add it to the config files array
  341. // Values in this config file will overwrite the TT default if the primaty application is loaded
  342. if (file_exists(TT_SITE_TOP . '/' . $app_data[0]['url'] . '/terra-terra.' . strtolower($applic_code) . '.cfg')) {
  343. $_cfgFiles['app'][] = TT_SITE_TOP . '/' . $app_data[0]['url'] . '/terra-terra.' . strtolower($applic_code) . '.cfg';
  344. }
  345. if (count ($_cfgFiles['app']) > 0) {
  346. foreach ($_cfgFiles['app'] as $_cfgfile) {
  347. ConfigHandler::readConfig (array('file' => $_cfgfile), ($applic_code === self::$primaryApp));
  348. }
  349. }
  350. // Get the dynamic configuration from the database for the calling application
  351. ConfigHandler::readConfig (array('aid' => self::getCurrentAppID()), ($applic_code === self::$primaryApp));
  352. self::$configLoaded = true;
  353. }
  354. if ($applic_code === self::$primaryApp) {
  355. // Now make sure the primary DB handle connects with the database as defined in the
  356. // application config.
  357. // FIXME This blocks external contentareas from being loaded!
  358. $_db = TT::factory('dbhandler');
  359. $_db->forceReread();
  360. $_logger = TT::factory('loghandler', 'so');
  361. $_logger->setApplicLogfile();
  362. }
  363. // Load the application and register with the TT framework
  364. if (!file_exists(TT_SITE_TOP . '/' . $app_data[0]['url'] . '/lib/' . strtolower($applic_code) . '.applic.loader.php')) {
  365. trigger_error('The file ' . TT_SITE_TOP . '/' . $app_data[0]['url'] . '/lib/' . strtolower($applic_code) . '.applic.loader.php does not exist', E_USER_ERROR);
  366. } else {
  367. require (TT_SITE_TOP . '/' . $app_data[0]['url'] . '/lib/' . strtolower($applic_code) . '.applic.loader.php');
  368. }
  369. if ($applic_code == TT_CODE) {
  370. // When loading Terra-Terra, also load the layout
  371. //! Terra-Terra Layout location
  372. define ('TT_LAYOUT', TTCache::getApplic ($applic_code, TT_APPITM_TOP) . '/layout/' . ConfigHandler::get('layout', 'layout'));
  373. //! Terra-Terra Stylesheet URL
  374. define ('TT_STYLE_URL', TTCache::getApplic ($applic_code, TT_APPITM_URL) . '/layout/' . ConfigHandler::get('layout', 'layout') . '/style');
  375. if (!TTloader::getClass('layout', TT_LAYOUT)) {
  376. trigger_error('Error loading Layout class from ' . TT_LAYOUT, E_USER_WARNING);
  377. } else {
  378. Layout::createContainers();
  379. }
  380. }
  381. if ($primary === true) {
  382. // Load the list of other available applications
  383. self::loadApps();
  384. }
  385. if (!is_array(self::$appsLoaded)) {
  386. self::$appsLoaded = array();
  387. }
  388. self::$appsLoaded[] = $app_data[0]['aid'];
  389. }
  390. /**
  391. * Return an array with all apps that have been loaded.
  392. * \return Array with all app ID's
  393. */
  394. public static function getLoadedApps()
  395. {
  396. return self::$appsLoaded;
  397. }
  398. /**
  399. * Method the load the application hooks for all available applications
  400. * This method is called after the primary application has been loaded.
  401. */
  402. private static function loadApps ()
  403. {
  404. $dataset = new DataHandler();
  405. if (ConfigHandler::get ('database', 'tttables', true)) {
  406. $dataset->setPrefix(ConfigHandler::get ('database', 'ttprefix', 'tt'));
  407. }
  408. $dataset->setTablename('applications');
  409. $dataset->set('enabled', 1);
  410. $dataset->prepare();
  411. $dataset->db($app_list, __LINE__, __FILE__);
  412. if ($dataset->dbStatus() === DBHANDLE_NODATA) {
  413. return;
  414. }
  415. foreach ($app_list as $app_data) {
  416. if ($app_data['code'] != self::getCurrentAppCode() && file_exists(TT_SITE_TOP . '/' . $app_data['url'] . '/lib/' . strtolower($app_data['code']) . '.applic.hook.php')) {
  417. TTloader::loadApplication($app_data['code'], false);
  418. self::$externalAppList[] = TT_SITE_TOP . '/' . $app_data['url'] . '/lib/' . strtolower($app_data['code']) . '.applic.hook.php';
  419. }
  420. }
  421. }
  422. /**
  423. * Method to display hooks for all applications that have been loaded. Must be called from the primaty application.
  424. */
  425. public static function showApps()
  426. {
  427. foreach (self::$externalAppList as $_hook) {
  428. require ($_hook);
  429. }
  430. }
  431. /**
  432. * Getter for the primary application's code
  433. * \return Application code
  434. */
  435. public static function getPrimaryAppCode()
  436. {
  437. return self::$primaryApp;
  438. }
  439. /**
  440. * Getter for the current application's ID
  441. * \return Application ID
  442. */
  443. public static function getCurrentAppCode()
  444. {
  445. return self::$currentApp;
  446. }
  447. /**
  448. * Getter for the primary application's ID
  449. * \return Application ID
  450. */
  451. public static function getPrimaryAppID()
  452. {
  453. return TTCache::getApplic(self::$primaryApp, TT_APPITM_ID);
  454. }
  455. /**
  456. * Getter for the current application's ID
  457. * \return Application ID
  458. */
  459. public static function getCurrentAppID()
  460. {
  461. return TTCache::getApplic(self::$currentApp, TT_APPITM_ID);
  462. }
  463. /**
  464. * Getter for the primary application's library URL
  465. * \return Application library URL
  466. */
  467. public static function getPrimaryAppLib()
  468. {
  469. return TTCache::getApplic(self::$primaryApp, TT_APPITM_LIBRARY);
  470. }
  471. /**
  472. * Getter for the current application's library URL
  473. * \return Application library URL
  474. */
  475. public static function getCurrentAppLib()
  476. {
  477. return TTCache::getApplic(self::$currentApp, TT_APPITM_LIBRARY);
  478. }
  479. /**
  480. * Getter for the primary application's name
  481. * \return Application name
  482. */
  483. public static function getPrimaryAppName()
  484. {
  485. return TTCache::getApplic(self::$primaryApp, TT_APPITM_NAME);
  486. }
  487. /**
  488. * Getter for the current application's name
  489. * \return Application name
  490. */
  491. public static function getCurrentAppName()
  492. {
  493. return TTCache::getApplic(self::$currentApp, TT_APPITM_NAME);
  494. }
  495. /**
  496. * Getter for the primary application's top URL
  497. * \return Application top URL
  498. */
  499. public static function getPrimaryAppUrl()
  500. {
  501. return TTCache::getApplic(self::$primaryApp, TT_APPITM_TOP);
  502. }
  503. /**
  504. * Getter for the current application's top URL
  505. * \return Application top URL
  506. */
  507. public static function getCurrentAppUrl()
  508. {
  509. return TTCache::getApplic(self::$currentApp, TT_APPITM_TOP);
  510. }
  511. }
  512. // The very first class being loaded must be TTCache; it's used by getClass()
  513. TTloader::getClass('cache', TT_SO_INC);
  514. // Load data from the cache
  515. TTCache::loadCache();
  516. TTloader::getClass('tt.severitycodes.php', TT_LIBRARY);
  517. TTloader::getClass('config.php', TT_ROOT);
  518. TTloader::getClass('timers', TT_SO_INC);
  519. TTTimers::startTimer(TT_MAIN_TIMER);
  520. // Abstract classes
  521. TTloader::getClass('exceptionhandler', TT_SO_INC);
  522. TTloader::getClass('register', TT_SO_INC);
  523. // Base class
  524. TTloader::getClass('_tt', TT_INCLUDE);
  525. // SO Layer
  526. TTloader::getClass('confighandler', TT_SO_INC);
  527. TTloader::getClass('loghandler', TT_SO_INC);
  528. TTloader::getClass('sessionhandler', TT_SO_INC);
  529. TTloader::getClass('outputhandler', TT_SO_INC);
  530. TTloader::getClass('dbhandler', TT_SO_INC);
  531. TTloader::getClass('datahandler', TT_SO_INC);
  532. TTloader::getClass('formhandler', TT_SO_INC);
  533. TTloader::getClass('filehandler', TT_SO_INC);
  534. // BO Layer
  535. TTloader::getClass('tt', TT_BO_INC);
  536. TTloader::getClass('dispatcher', TT_BO_INC);
  537. // Security system
  538. TTloader::getClass('security', TT_BO_INC);
  539. TTloader::getClass('rights', TT_BO_INC);
  540. // User and session
  541. TTloader::getClass('group', TT_BO_INC);
  542. TTloader::getClass('session', TT_BO_INC);
  543. TTloader::getClass('user', TT_BO_INC);
  544. // UI Layer
  545. TTloader::getClass('baseelement', TT_UI_INC);
  546. TTloader::getClass('container', TT_UI_INC);
  547. TTloader::getClass('console', TT_UI_INC);
  548. TTloader::getClass('contentarea', TT_UI_INC);
  549. TTloader::getInterface('ttLayout', TT_UI_INC);
  550. // Setup the cache for labels and messages
  551. TTCache::set(TTCACHE_LOCALE, 'labels', array());
  552. TTCache::set(TTCACHE_LOCALE, 'messages', array());
  553. // General helper functions.
  554. require (TT_LIBRARY . '/tt.helper.functions.php');
  555. // Load the contributed plugins
  556. require (TT_CONTRIB . '/tt.contrib.loader.php');
  557. // Get the static TT configuration from file
  558. $_cfgFile = TTCache::get(TTCACHE_CONFIG, 'files');
  559. ConfigHandler::readConfig (array('file' => $_cfgFile['tt']));
  560. unset ($_cfgFile);
  561. // Now define the TT Application ID; it is required by the next readConfig() call
  562. if (defined('TT___INSTALLER')) {
  563. define('TT_ID', 0); //!< Terra-Terra's own application ID used during the installation process
  564. } else {
  565. define('TT_ID', TTloader::getTTId()); //!< Terra-Terra's own application ID
  566. }
  567. if (!defined('TT___INSTALLER') && TT_ID != 0) {
  568. // Get the dynamic TT configuration from the database, except when installing TT itself
  569. ConfigHandler::readConfig (array());
  570. }
  571. // By now, the timezone should be known. Relevant since PHP v5.1.0
  572. ttTimeZone();
  573. //! Console object
  574. TTCache::set(TTCACHE_OBJECTS, 'Console', TT::factory('Console'));
  575. //! Logger object
  576. TTCache::set(TTCACHE_OBJECTS, 'Logger', TT::factory('LogHandler'));
  577. // Set up the label translations
  578. Register::registerLabels(true);
  579. // Load the Layout file
  580. // Select the (no)debug function libraries.
  581. if (ConfigHandler::get('general', 'debug', 0) > 0) {
  582. require (TT_LIBRARY . '/tt.debug.functions.php');
  583. $_doc = TT::factory('Document', 'ui');
  584. $_doc->loadStyle(TT_STYLE_URL . '/tt_debug.css');
  585. $_confData = TTCache::get(TTCACHE_CONFIG, 'values');
  586. TTdbg_add(TTDEBUG_TT_S01, $_confData, 'Configuration after loadApplication()');
  587. unset ($_confData);
  588. } else {
  589. require (TT_LIBRARY . '/tt.nodebug.functions.php');
  590. }