2009-08-27 12:48:09 +00:00
|
|
|
<?php
|
2010-02-10 11:27:44 +00:00
|
|
|
/*
|
|
|
|
|
This file is part of myTinyTodo.
|
|
|
|
|
(C) Copyright 2009-2010 Max Pozdeev <maxpozdeev@gmail.com>
|
|
|
|
|
Licensed under the GNU GPL v3 license. See file COPYRIGHT for details.
|
|
|
|
|
*/
|
2009-08-27 12:48:09 +00:00
|
|
|
|
2010-02-06 17:35:39 +00:00
|
|
|
if(!defined('MTTPATH')) define('MTTPATH', dirname(__FILE__) .'/');
|
|
|
|
|
|
|
|
|
|
require_once(MTTPATH. 'common.php');
|
|
|
|
|
require_once(MTTPATH. 'db/config.php');
|
2009-08-27 12:48:09 +00:00
|
|
|
|
|
|
|
|
ini_set('display_errors', 'On');
|
|
|
|
|
|
2009-11-30 17:59:16 +00:00
|
|
|
if(!isset($config)) global $config;
|
|
|
|
|
Config::loadConfig($config);
|
|
|
|
|
unset($config);
|
|
|
|
|
|
2010-10-25 06:45:04 +00:00
|
|
|
date_default_timezone_set(Config::get('timezone'));
|
|
|
|
|
|
2009-08-27 12:48:09 +00:00
|
|
|
# MySQL Database Connection
|
2009-11-30 17:59:16 +00:00
|
|
|
if(Config::get('db') == 'mysql')
|
2009-08-27 12:48:09 +00:00
|
|
|
{
|
2010-02-06 17:35:39 +00:00
|
|
|
require_once(MTTPATH. 'class.db.mysql.php');
|
2010-10-25 06:45:04 +00:00
|
|
|
$db = DBConnection::init(new Database_Mysql);
|
2009-11-30 17:59:16 +00:00
|
|
|
$db->connect(Config::get('mysql.host'), Config::get('mysql.user'), Config::get('mysql.password'), Config::get('mysql.db'));
|
2009-08-27 12:48:09 +00:00
|
|
|
$db->dq("SET NAMES utf8");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# SQLite3 (pdo_sqlite)
|
2010-04-29 09:38:08 +00:00
|
|
|
elseif(Config::get('db') == 'sqlite')
|
2009-08-27 12:48:09 +00:00
|
|
|
{
|
2010-02-06 17:35:39 +00:00
|
|
|
require_once(MTTPATH. 'class.db.sqlite3.php');
|
2010-10-25 06:45:04 +00:00
|
|
|
$db = DBConnection::init(new Database_Sqlite3);
|
2010-02-06 17:35:39 +00:00
|
|
|
$db->connect(MTTPATH. 'db/todolist.db');
|
2009-08-27 12:48:09 +00:00
|
|
|
}
|
2010-04-29 09:38:08 +00:00
|
|
|
else {
|
|
|
|
|
# It seems not installed
|
|
|
|
|
die("Not installed. Run <a href=setup.php>setup.php</a> first.");
|
|
|
|
|
}
|
2009-12-02 12:37:10 +00:00
|
|
|
$db->prefix = Config::get('prefix');
|
2009-08-27 12:48:09 +00:00
|
|
|
|
2010-02-06 17:35:39 +00:00
|
|
|
require_once(MTTPATH. 'lang/class.default.php');
|
|
|
|
|
require_once(MTTPATH. 'lang/'.Config::get('lang').'.php');
|
2009-08-27 12:48:09 +00:00
|
|
|
|
2010-02-10 11:27:44 +00:00
|
|
|
$_mttinfo = array();
|
|
|
|
|
|
2009-11-30 17:59:16 +00:00
|
|
|
$needAuth = (Config::get('password') != '') ? 1 : 0;
|
2009-11-01 14:42:36 +00:00
|
|
|
if($needAuth && !isset($dontStartSession))
|
2009-08-27 12:48:09 +00:00
|
|
|
{
|
2009-11-30 17:59:16 +00:00
|
|
|
if(Config::get('session') == 'files')
|
2009-08-27 12:48:09 +00:00
|
|
|
{
|
2010-06-08 14:34:58 +00:00
|
|
|
session_save_path(MTTPATH. 'tmp/sessions');
|
2009-08-27 12:48:09 +00:00
|
|
|
ini_set('session.gc_maxlifetime', '1209600'); # 14 days session file minimum lifetime
|
|
|
|
|
ini_set('session.gc_probability', 1);
|
|
|
|
|
ini_set('session.gc_divisor', 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ini_set('session.use_cookies', true);
|
|
|
|
|
ini_set('session.use_only_cookies', true);
|
2010-02-07 13:26:11 +00:00
|
|
|
session_set_cookie_params(1209600, url_dir(Config::get('url')=='' ? $_SERVER['REQUEST_URI'] : Config::get('url'))); # 14 days session cookie lifetime
|
|
|
|
|
session_name('mtt-session');
|
2009-08-27 12:48:09 +00:00
|
|
|
session_start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function is_logged()
|
|
|
|
|
{
|
|
|
|
|
if(!isset($_SESSION['logged']) || !$_SESSION['logged']) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-25 06:45:04 +00:00
|
|
|
function timestampToDatetime($timestamp)
|
2009-11-13 12:38:55 +00:00
|
|
|
{
|
2009-11-30 17:59:16 +00:00
|
|
|
$format = Config::get('dateformat') .' '. (Config::get('clock') == 12 ? 'g:i A' : 'H:i');
|
2010-10-25 06:45:04 +00:00
|
|
|
return formatTime($format, $timestamp);
|
2009-12-15 14:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-25 06:45:04 +00:00
|
|
|
function formatTime($format, $timestamp=0)
|
2009-12-15 14:49:32 +00:00
|
|
|
{
|
2010-02-07 13:26:11 +00:00
|
|
|
$lang = Lang::instance();
|
2009-12-15 14:49:32 +00:00
|
|
|
if($timestamp == 0) $timestamp = time();
|
2009-11-13 12:38:55 +00:00
|
|
|
$newformat = strtr($format, array('F'=>'%1', 'M'=>'%2'));
|
2010-10-25 06:45:04 +00:00
|
|
|
$adate = explode(',', date('n,'.$newformat, $timestamp), 2);
|
2009-11-13 12:38:55 +00:00
|
|
|
$s = $adate[1];
|
|
|
|
|
if($newformat != $format)
|
|
|
|
|
{
|
|
|
|
|
$am = (int)$adate[0];
|
|
|
|
|
$ml = $lang->get('months_long');
|
|
|
|
|
$ms = $lang->get('months_short');
|
|
|
|
|
$F = $ml[$am-1];
|
|
|
|
|
$M = $ms[$am-1];
|
|
|
|
|
$s = strtr($s, array('%1'=>$F, '%2'=>$M));
|
|
|
|
|
}
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-10 11:27:44 +00:00
|
|
|
function _e($s)
|
|
|
|
|
{
|
|
|
|
|
echo Lang::instance()->get($s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function __($s)
|
|
|
|
|
{
|
|
|
|
|
return Lang::instance()->get($s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mttinfo($v)
|
|
|
|
|
{
|
|
|
|
|
global $_mttinfo;
|
|
|
|
|
if(!isset($_mttinfo[$v])) {
|
|
|
|
|
echo get_mttinfo($v);
|
|
|
|
|
} else {
|
|
|
|
|
echo $_mttinfo[$v];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_mttinfo($v)
|
|
|
|
|
{
|
2010-07-18 17:28:21 +00:00
|
|
|
global $_mttinfo;
|
2010-02-10 11:27:44 +00:00
|
|
|
if(isset($_mttinfo[$v])) return $_mttinfo[$v];
|
|
|
|
|
switch($v)
|
|
|
|
|
{
|
|
|
|
|
case 'template_url':
|
|
|
|
|
$_mttinfo['template_url'] = get_mttinfo('mtt_url'). 'themes/'. Config::get('template') . '/';
|
|
|
|
|
return $_mttinfo['template_url'];
|
|
|
|
|
case 'url':
|
|
|
|
|
$_mttinfo['url'] = Config::get('url');
|
|
|
|
|
if($_mttinfo['url'] == '')
|
2010-06-05 17:39:17 +00:00
|
|
|
$_mttinfo['url'] = 'http://'.$_SERVER['HTTP_HOST'] .($_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : '').
|
|
|
|
|
url_dir(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['SCRIPT_NAME']);
|
2010-02-10 11:27:44 +00:00
|
|
|
return $_mttinfo['url'];
|
|
|
|
|
case 'mtt_url':
|
|
|
|
|
$_mttinfo['mtt_url'] = Config::get('mtt_url');
|
2010-06-05 17:39:17 +00:00
|
|
|
if($_mttinfo['mtt_url'] == '') $_mttinfo['mtt_url'] = url_dir(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['SCRIPT_NAME']);
|
2010-02-10 11:27:44 +00:00
|
|
|
return $_mttinfo['mtt_url'];
|
|
|
|
|
case 'title':
|
2010-07-18 17:28:21 +00:00
|
|
|
$_mttinfo['title'] = (Config::get('title') != '') ? htmlarray(Config::get('title')) : __('My Tiny Todolist');
|
2010-02-10 11:27:44 +00:00
|
|
|
return $_mttinfo['title'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-27 12:48:09 +00:00
|
|
|
?>
|