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