From 301a75f779ee82d1283e613c94a010d65008e3c9 Mon Sep 17 00:00:00 2001 From: Max Pozdeev Date: Sat, 6 Feb 2010 20:35:39 +0300 Subject: [PATCH] * MTTPATH constant added --- src/ajax.lang.php | 10 +++++----- src/ajax.php | 5 ++--- src/common.php | 2 +- src/feed.php | 5 ++--- src/index.php | 9 +++------ src/init.php | 16 ++++++++++------ src/lang/class.default.php | 12 ++++++++++++ src/settings.php | 6 ++---- 8 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/ajax.lang.php b/src/ajax.lang.php index 9118d3b..c47b5cc 100644 --- a/src/ajax.lang.php +++ b/src/ajax.lang.php @@ -1,12 +1,12 @@ makeJS(); +echo Lang::instance()->makeJS(); ?> \ No newline at end of file diff --git a/src/ajax.php b/src/ajax.php index 22e00c4..b65396b 100644 --- a/src/ajax.php +++ b/src/ajax.php @@ -10,9 +10,8 @@ set_error_handler('myErrorHandler'); set_exception_handler('myExceptionHandler'); require_once('./init.php'); -require_once('./lang/class.default.php'); -require_once('./lang/'.Config::get('lang').'.php'); -$lang = new Lang(); + +$lang = Lang::instance(); if(isset($_GET['loadLists'])) { diff --git a/src/common.php b/src/common.php index c6dc061..9de108a 100644 --- a/src/common.php +++ b/src/common.php @@ -116,7 +116,7 @@ class Config $s .= "\$config['$param'] = '".str_replace(array("\\","'"),array("\\\\","\\'"),$val)."';\n"; } } - $f = fopen('./db/config.php', 'w'); + $f = fopen(MTTPATH. 'db/config.php', 'w'); if($f === false) throw new Exception("Error while saving config file"); fwrite($f, ""); fclose($f); diff --git a/src/feed.php b/src/feed.php index 2033a21..cf63dcf 100644 --- a/src/feed.php +++ b/src/feed.php @@ -8,9 +8,8 @@ $dontStartSession = 1; require_once('./init.php'); -require_once('./lang/class.default.php'); -require_once('./lang/'.Config::get('lang').'.php'); -$lang = new Lang(); + +$lang = Lang::instance(); $listId = (int)_get('list'); diff --git a/src/index.php b/src/index.php index e88c756..85a514c 100644 --- a/src/index.php +++ b/src/index.php @@ -5,12 +5,9 @@ Licensed under the GNU GPL v3 license. See file COPYRIGHT for details. */ +require_once('./init.php'); -require_once('init.php'); -require_once('./lang/class.default.php'); -require_once('./lang/'.Config::get('lang').'.php'); - -$lang = new Lang(); +$lang = Lang::instance(); if($lang->rtl()) Config::set('rtl', 1); @@ -18,7 +15,7 @@ if(!is_int(Config::get('firstdayofweek')) || Config::get('firstdayofweek')<0 || $_mttinfo = array(); -define('TEMPLATEPATH', './themes/'.Config::get('template').'/'); +define('TEMPLATEPATH', MTTPATH. 'themes/'.Config::get('template').'/'); require(TEMPLATEPATH. 'index.php'); diff --git a/src/init.php b/src/init.php index b33e8cc..6bb717e 100644 --- a/src/init.php +++ b/src/init.php @@ -1,7 +1,9 @@ connect(Config::get('mysql.host'), Config::get('mysql.user'), Config::get('mysql.password'), Config::get('mysql.db')); $db->dq("SET NAMES utf8"); @@ -21,19 +23,21 @@ if(Config::get('db') == 'mysql') # SQLite3 (pdo_sqlite) else { - require_once('class.db.sqlite3.php'); + require_once(MTTPATH. 'class.db.sqlite3.php'); $db = new Database_Sqlite3; - $db->connect('./db/todolist.db'); + $db->connect(MTTPATH. 'db/todolist.db'); } $db->prefix = Config::get('prefix'); +require_once(MTTPATH. 'lang/class.default.php'); +require_once(MTTPATH. 'lang/'.Config::get('lang').'.php'); $needAuth = (Config::get('password') != '') ? 1 : 0; if($needAuth && !isset($dontStartSession)) { if(Config::get('session') == 'files') { - session_save_path(realpath('./tmp/sessions/')); + session_save_path(MTTPATH. 'tmp/sessions/'); ini_set('session.gc_maxlifetime', '1209600'); # 14 days session file minimum lifetime ini_set('session.gc_probability', 1); ini_set('session.gc_divisor', 10); diff --git a/src/lang/class.default.php b/src/lang/class.default.php index c06d55b..05ea97f 100644 --- a/src/lang/class.default.php +++ b/src/lang/class.default.php @@ -6,7 +6,9 @@ class DefaultLang { + protected static $instance; protected $rtl = 0; + private $default_js = array ( 'confirmDelete' => "Are you sure you want to delete the task?", @@ -157,6 +159,16 @@ class DefaultLang { return $this->rtl ? 1 : 0; } + + public static function instance() + { + if (!isset(self::$instance)) { + //$c = __CLASS__; + $c = 'Lang'; + self::$instance = new $c; + } + return self::$instance; + } } ?> \ No newline at end of file diff --git a/src/settings.php b/src/settings.php index 1685545..bc0a135 100644 --- a/src/settings.php +++ b/src/settings.php @@ -8,9 +8,7 @@ require_once('./init.php'); -require_once('./lang/class.default.php'); -require_once('./lang/'.Config::get('lang').'.php'); -$lang = new Lang(); +$lang = Lang::instance(); if($needAuth && !is_logged()) { @@ -62,7 +60,7 @@ function __($s) function getLangs() { - if (!$h = opendir('./lang')) return false; + if (!$h = opendir(MTTPATH. 'lang')) return false; $a = array(); while(false !== ($file = readdir($h))) {