PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/init.php

https://github.com/MrBertie/taskpaperplus
PHP | 167 lines | 71 code | 48 blank | 48 comment | 2 complexity | 9485e60ef94fd7c9dcf7fbf2a32aabd4 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. namespace tpp;
  3. //**************************************
  4. // Fundamental paths and session setup
  5. //**************************************
  6. // globally used app path, for all includes, requires, and file access
  7. $path = realpath(dirname(__FILE__) . '/..');
  8. define('APP_PATH', $path . '/');
  9. define('APP_NAME', basename($path));
  10. // session start up, get a valid session name
  11. $session_name = preg_replace("/[^a-zA-Z0-9]+/", "", APP_NAME);
  12. session_name($session_name);
  13. session_start();
  14. //session_destroy();
  15. //------------------------------
  16. // Error reporting and logging.
  17. //------------------------------
  18. require_once('inc/debugmode.php');
  19. // takes care of autoloading class files
  20. require_once(APP_PATH . 'inc/autoload.php');
  21. //***************************************
  22. // Basic initialisation, config setup
  23. //***************************************
  24. // Load the global app config; including base paths
  25. $config = array();
  26. require_once(APP_PATH . 'conf/config.php');
  27. log&&msg('Initialising basic app data');
  28. //-----------------------------------------------
  29. // Application constants, settings, and language data
  30. //-----------------------------------------------
  31. // default extension for all taskpaper files (txt is probably best)
  32. define('EXT', ".txt");
  33. // default tab/page states (default tab will be the first one available)
  34. define('DEFAULT_ACTION', 'all');
  35. define('DEFAULT_VALUE', null);
  36. /**
  37. * Update types (used in cache.class/taskpaper.class.php)
  38. */
  39. define('UPDATE_NONE', 0);
  40. define('UPDATE_STATE', 1);
  41. define('UPDATE_PARSED', 2);
  42. define('UPDATE_RAWITEM', 3);
  43. define('UPDATE_RAW', 4);
  44. define('UPDATE_FILE', 5);
  45. /**
  46. * Trash and Archive tab/file names
  47. */
  48. define('FILE_TRASH', '__trash__');
  49. define('FILE_ARCHIVE', '__archive__');
  50. define('FILE_TAB_CACHE', '__tabs__');
  51. /**
  52. * Various Http request types used by dispatcher.
  53. */
  54. define('REQ_INVALID', 0); // invalid request
  55. define('REQ_INDEX', 1); // initial index|start page
  56. define('REQ_AJAX', 2); // via JS event call through xhr
  57. /**
  58. * Specific Tab types.
  59. */
  60. define ('TAB_NORMAL', 0);
  61. define ('TAB_TRASH', 1);
  62. define ('TAB_ARCHIVE', 2);
  63. define ('TAB_NEW', 3);
  64. /**
  65. * Enum: Item types within a taskpaper list.
  66. *
  67. * @see Content
  68. */
  69. define('ITEM_NONE', 0);
  70. define('ITEM_PAGE', 1);
  71. define('ITEM_PROJ', 2);
  72. define('ITEM_TASK', 3);
  73. define('ITEM_INFO', 4);
  74. define('ITEM_NOTE', 5); // not used currently
  75. // Regex patterns, terms and symbols used globally in app
  76. require_once(APP_PATH . 'conf/term.php');
  77. // Basic app functions: config() lang(), ini(), + general functions
  78. require_once(APP_PATH . 'inc/common.php');
  79. // Confirm that necessary data folders exist
  80. define('DATA_DIR', getdir_or(ini('taskpaper_folder'), config('data_dir')));
  81. define('DELETED_DIR', getdir_or(config('deleted_dir')));
  82. define('CACHE_DIR', getdir_or(config('cache_dir')));
  83. // Load global language array from existing config file names
  84. $langs = glob('./conf/lang_*');
  85. foreach($langs as $lang) {
  86. $config['lang_list'][] = substr($lang, 12, -4);
  87. }
  88. $cur_lang = \tpp\ini('language');
  89. $lang_path = 'conf/lang_' . $cur_lang . '.php';
  90. $lang_en_path = 'conf/lang_en.php';
  91. // default english lang strings (in case of missing localised items or language)
  92. $lang = array();
  93. require_once(APP_PATH . $lang_en_path);
  94. if (file_exists($lang_path)) {
  95. require_once(APP_PATH . $lang_path);
  96. }
  97. // this ensures that dates will be localised also
  98. // locale names must match PHP standards: see conf/locale_names.txt
  99. $location = setlocale(LC_ALL, $cur_lang);
  100. DEFINE('LOCATION', $location);
  101. // used in TaskItem and Parser
  102. define('MAX_ACTION', count(\tpp\lang('state_order')) - 2);
  103. // set correct locale settings (timezone must be set first)
  104. $timezone = ini('timezone');
  105. // @ to avoid error NOTICE if timezone does not exist
  106. if (@date_default_timezone_set($timezone) === false) {
  107. // this will return a suitable default if user has not set the timezone in his server
  108. $timezone = 'UTC';
  109. date_default_timezone_set($timezone);
  110. }
  111. DEFINE('TIMEZONE', $timezone);
  112. // compile LESS css sheets
  113. require_once(APP_PATH . 'lib/lessc.inc.php');
  114. log&&msg('Compiling the lessCSS files');
  115. try {
  116. \lessc::ccompile('css/style.less', 'css/style.css');
  117. } catch (exception $ex) {
  118. exit('lessc fatal error:<br />'.$ex->getMessage());
  119. }