2009-08-27 12:48:09 +00:00
|
|
|
<?php
|
2010-02-10 11:27:44 +00:00
|
|
|
/*
|
2022-02-06 20:37:02 +00:00
|
|
|
This file is a part of myTinyTodo.
|
|
|
|
|
(C) Copyright 2009-2011,2019-2022 Max Pozdeev <maxpozdeev@gmail.com>
|
|
|
|
|
Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details.
|
2010-02-10 11:27:44 +00:00
|
|
|
*/
|
2009-08-27 12:48:09 +00:00
|
|
|
|
2022-04-15 18:31:47 +00:00
|
|
|
if (version_compare(PHP_VERSION, '7.2.0') < 0) {
|
|
|
|
|
die("PHP 7.2 or above is required");
|
2020-08-13 18:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-06 17:35:39 +00:00
|
|
|
if(!defined('MTTPATH')) define('MTTPATH', dirname(__FILE__) .'/');
|
2020-09-04 11:26:28 +00:00
|
|
|
if(!defined('MTTINC')) define('MTTINC', MTTPATH. 'includes/');
|
2022-11-14 17:58:34 +00:00
|
|
|
if(!defined('MTT_CONTENT_PATH')) define('MTT_CONTENT_PATH', MTTPATH. 'content/');
|
2010-02-06 17:35:39 +00:00
|
|
|
|
2022-11-20 13:01:35 +00:00
|
|
|
requireConfig();
|
|
|
|
|
|
|
|
|
|
if (!defined('MTT_THEME')) {
|
|
|
|
|
define('MTT_THEME', 'theme');
|
|
|
|
|
}
|
|
|
|
|
define('MTT_THEME_PATH', MTT_CONTENT_PATH. MTT_THEME. '/');
|
|
|
|
|
|
|
|
|
|
|
2021-07-24 15:16:16 +00:00
|
|
|
if (getenv('MTT_ENABLE_DEBUG') == 'YES') {
|
2022-02-06 20:37:02 +00:00
|
|
|
define('MTT_DEBUG', true);
|
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
|
ini_set('display_errors', '1');
|
|
|
|
|
ini_set('log_errors', '1');
|
2021-07-24 15:16:16 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2022-02-06 20:37:02 +00:00
|
|
|
//ini_set('display_errors', '0');
|
|
|
|
|
//ini_set('log_errors', '1');
|
|
|
|
|
define('MTT_DEBUG', false);
|
2021-07-24 15:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-04 11:45:24 +00:00
|
|
|
require_once(MTTINC. 'common.php');
|
2022-09-06 20:28:24 +00:00
|
|
|
require_once(MTTINC. 'classes.php');
|
2022-08-29 20:26:05 +00:00
|
|
|
require_once(MTTINC. 'version.php');
|
2021-07-26 19:04:12 +00:00
|
|
|
require_once(MTTINC. 'class.dbconnection.php');
|
2022-01-14 19:13:04 +00:00
|
|
|
require_once(MTTINC. 'class.dbcore.php');
|
2021-07-25 16:20:24 +00:00
|
|
|
require_once(MTTINC. 'class.config.php');
|
2022-08-29 20:26:05 +00:00
|
|
|
require_once(MTTINC. 'notifications.php');
|
2009-08-27 12:48:09 +00:00
|
|
|
|
2022-07-12 08:26:12 +00:00
|
|
|
configureDbConnection();
|
2009-11-30 17:59:16 +00:00
|
|
|
|
2021-07-28 15:05:14 +00:00
|
|
|
Config::load();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
date_default_timezone_set(Config::get('timezone'));
|
2009-08-27 12:48:09 +00:00
|
|
|
|
2020-09-20 13:46:07 +00:00
|
|
|
//User can override language setting by cookies or query
|
|
|
|
|
$forceLang = '';
|
|
|
|
|
if( isset($_COOKIE['lang']) ) $forceLang = $_COOKIE['lang'];
|
2020-09-24 16:21:13 +00:00
|
|
|
//else if ( isset($_GET['lang']) ) $forceLang = $_GET['lang'];
|
2020-09-20 13:46:07 +00:00
|
|
|
|
2020-09-24 16:21:13 +00:00
|
|
|
if ( $forceLang != '' && preg_match("/^[a-z-]+$/i", $forceLang) ) {
|
2022-02-06 20:37:02 +00:00
|
|
|
Config::set('lang', $forceLang); //TODO: special for demo, do not change config
|
2011-05-30 14:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-04 11:26:28 +00:00
|
|
|
require_once(MTTINC. 'class.lang.php');
|
2020-09-24 16:21:13 +00:00
|
|
|
Lang::loadLang( Config::get('lang') );
|
2009-08-27 12:48:09 +00:00
|
|
|
|
2010-02-10 11:27:44 +00:00
|
|
|
$_mttinfo = array();
|
|
|
|
|
|
2021-09-20 14:34:36 +00:00
|
|
|
if (need_auth() && !isset($dontStartSession)) {
|
2022-02-06 20:37:02 +00:00
|
|
|
setup_and_start_session();
|
2009-08-27 12:48:09 +00:00
|
|
|
}
|
2022-09-15 13:26:22 +00:00
|
|
|
set_nocache_headers();
|
2009-08-27 12:48:09 +00:00
|
|
|
|
2022-09-13 15:21:53 +00:00
|
|
|
if (!defined('MTT_DISABLE_EXT')) {
|
2022-09-06 20:28:24 +00:00
|
|
|
define('MTT_EXT', MTTPATH . 'ext/');
|
|
|
|
|
loadExtensions();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-31 18:49:26 +00:00
|
|
|
|
|
|
|
|
function requireConfig()
|
|
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
$exists = file_exists(MTTPATH. 'config.php');
|
|
|
|
|
$defined = false;
|
|
|
|
|
if ($exists) {
|
|
|
|
|
require_once(MTTPATH. 'config.php');
|
|
|
|
|
$defined = defined('MTT_DB_TYPE');
|
|
|
|
|
}
|
|
|
|
|
# It seems not installed
|
|
|
|
|
if (!$defined) {
|
|
|
|
|
die("Not installed. Run <a href=setup.php>setup.php</a> first.");
|
|
|
|
|
}
|
2022-01-31 18:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-12 08:26:12 +00:00
|
|
|
function configureDbConnection()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
# MySQL Database Connection
|
|
|
|
|
if (MTT_DB_TYPE == 'mysql')
|
|
|
|
|
{
|
|
|
|
|
if (defined('MTT_DB_DRIVER') && MTT_DB_DRIVER == 'mysqli') {
|
|
|
|
|
require_once(MTTINC. 'class.db.mysqli.php');
|
|
|
|
|
$db = new Database_Mysqli();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
require_once(MTTINC. 'class.db.mysql.php');
|
|
|
|
|
$db = new Database_Mysql();
|
|
|
|
|
}
|
|
|
|
|
DBConnection::init($db);
|
|
|
|
|
try {
|
2022-12-07 12:53:47 +00:00
|
|
|
$db->connect([
|
2022-07-12 08:26:12 +00:00
|
|
|
'host' => MTT_DB_HOST,
|
|
|
|
|
'user' => MTT_DB_USER,
|
|
|
|
|
'password' => MTT_DB_PASSWORD,
|
|
|
|
|
'db' => MTT_DB_NAME,
|
2022-12-07 12:53:47 +00:00
|
|
|
]);
|
2022-07-12 08:26:12 +00:00
|
|
|
}
|
|
|
|
|
catch(Exception $e) {
|
|
|
|
|
logAndDie("Failed to connect to mysql database: ". $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
$db->dq("SET NAMES utf8mb4");
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 20:09:32 +00:00
|
|
|
# PostgreSQL Database
|
|
|
|
|
else if (MTT_DB_TYPE == 'postgres')
|
|
|
|
|
{
|
|
|
|
|
require_once(MTTINC. 'class.db.postgres.php');
|
|
|
|
|
$db = DBConnection::init(new Database_Postgres());
|
|
|
|
|
try {
|
|
|
|
|
$db->connect([
|
|
|
|
|
'host' => MTT_DB_HOST,
|
|
|
|
|
'user' => MTT_DB_USER,
|
|
|
|
|
'password' => MTT_DB_PASSWORD,
|
|
|
|
|
'db' => MTT_DB_NAME,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception $e) {
|
|
|
|
|
$errlog = "Failed to connect to PostgreSQL database: ". $e->getMessage();
|
|
|
|
|
if (MTT_DEBUG) {
|
|
|
|
|
logAndDie($errlog);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
logAndDie("Failed to connect to database", $errlog);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$db->dq("SET NAMES 'utf8'");
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-12 08:26:12 +00:00
|
|
|
# SQLite3 Database
|
|
|
|
|
elseif (MTT_DB_TYPE == 'sqlite')
|
|
|
|
|
{
|
2022-12-07 12:53:47 +00:00
|
|
|
require_once(MTTINC. 'vendor/autoload.php');
|
2022-07-12 08:26:12 +00:00
|
|
|
require_once(MTTINC. 'class.db.sqlite3.php');
|
2022-12-07 12:53:47 +00:00
|
|
|
$db = DBConnection::init(new Database_Sqlite3());
|
|
|
|
|
$db->connect([
|
|
|
|
|
'filename' => MTTPATH. 'db/todolist.db'
|
|
|
|
|
]);
|
2022-07-12 08:26:12 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
die("Incorrect database connection config");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DBConnection::setTablePrefix(MTT_DB_PREFIX);
|
|
|
|
|
DBCore::setDefaultInstance(new DBCore($db));
|
|
|
|
|
|
|
|
|
|
# Check tables created
|
|
|
|
|
global $checkDbExists;
|
|
|
|
|
if (!Config::$noDatabase && isset($checkDbExists) && $checkDbExists) {
|
|
|
|
|
$exists = $db->tableExists($db->prefix.'settings');
|
|
|
|
|
if (!$exists) {
|
|
|
|
|
die("Need to create or update the database. Run <a href=setup.php>setup.php</a> first.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-06 11:08:15 +00:00
|
|
|
function need_auth(): bool
|
2020-09-08 11:37:29 +00:00
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
return (Config::get('password') != '') ? true : false;
|
2020-09-08 11:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-06 11:08:15 +00:00
|
|
|
function is_logged(): bool
|
2009-08-27 12:48:09 +00:00
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
if ( !need_auth() ) return true;
|
|
|
|
|
if ( !isset($_SESSION['logged']) || !isset($_SESSION['sign']) ) return false;
|
|
|
|
|
if ( !(int)$_SESSION['logged'] ) return false;
|
2022-02-07 06:57:03 +00:00
|
|
|
return isValidSignature($_SESSION['sign'], session_id(), Config::get('password'), defined('MTT_SALT') ? MTT_SALT : '');
|
2009-08-27 12:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-06 11:08:15 +00:00
|
|
|
function is_readonly(): bool
|
2010-12-15 11:50:04 +00:00
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
if ( !is_logged() ) return true;
|
|
|
|
|
return false;
|
2010-12-15 11:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-09 21:41:28 +00:00
|
|
|
function updateSessionLogged(bool $logged)
|
|
|
|
|
{
|
|
|
|
|
if ($logged) {
|
|
|
|
|
$_SESSION['logged'] = 1;
|
|
|
|
|
$_SESSION['sign'] = idSignature(session_id(), Config::get('password'), defined('MTT_SALT') ? MTT_SALT : '');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
unset($_SESSION['logged']);
|
|
|
|
|
unset($_SESSION['sign']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-06 11:08:15 +00:00
|
|
|
function access_token(): string
|
2021-09-20 09:06:52 +00:00
|
|
|
{
|
2022-10-28 18:29:21 +00:00
|
|
|
if ( need_auth() ) {
|
|
|
|
|
if (!isset($_SESSION)) return '';
|
|
|
|
|
return $_SESSION['token'] ?? '';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (!isset($_COOKIE)) return '';
|
|
|
|
|
return $_COOKIE['mtt-token'] ?? '';
|
|
|
|
|
}
|
2021-09-20 09:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-20 09:30:00 +00:00
|
|
|
function check_token()
|
|
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
$token = access_token();
|
2022-02-09 21:41:28 +00:00
|
|
|
if ($token == '' || !isset($_SERVER['HTTP_MTT_TOKEN']) || $_SERVER['HTTP_MTT_TOKEN'] != $token) {
|
|
|
|
|
http_response_code(403);
|
2022-10-28 18:29:21 +00:00
|
|
|
die("Access denied! No token provided.");
|
2022-02-06 20:37:02 +00:00
|
|
|
}
|
2021-09-20 09:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-09 21:41:28 +00:00
|
|
|
function update_token(): string
|
2022-02-09 19:38:13 +00:00
|
|
|
{
|
2022-10-28 18:29:21 +00:00
|
|
|
$token = generateUUID();
|
|
|
|
|
if ( need_auth() ) {
|
|
|
|
|
$_SESSION['token'] = $token;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-11-02 21:20:32 +00:00
|
|
|
if (PHP_VERSION_ID < 70300) {
|
|
|
|
|
setcookie('mtt-token', $token, 0, url_dir(get_unsafe_mttinfo('mtt_url')). '; samesite=lax', '', false, true );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
setcookie('mtt-token', $token, [
|
|
|
|
|
'path' => url_dir(get_unsafe_mttinfo('mtt_url')),
|
|
|
|
|
'httponly' => true,
|
|
|
|
|
'samesite' => 'lax'
|
|
|
|
|
]);
|
|
|
|
|
}
|
2022-10-28 18:29:21 +00:00
|
|
|
$_COOKIE['mtt-token'] = $token;
|
|
|
|
|
}
|
|
|
|
|
return $token;
|
2022-02-09 19:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-20 14:34:36 +00:00
|
|
|
function setup_and_start_session()
|
|
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
require_once(MTTINC. 'class.sessionhandler.php');
|
|
|
|
|
session_set_save_handler(new MTTSessionHandler());
|
|
|
|
|
|
|
|
|
|
ini_set('session.use_cookies', true);
|
|
|
|
|
ini_set('session.use_only_cookies', true);
|
|
|
|
|
|
2022-09-08 20:16:31 +00:00
|
|
|
/*
|
|
|
|
|
After any request we may have 14 days of inactivity (i.e. not requesting session data),
|
|
|
|
|
then we have to re-login (look at MTTSessionHandler).
|
|
|
|
|
Activity without re-login lasts for max 60 days, the cookie lifetime, then cookie dies
|
|
|
|
|
and we have to re-login having new session id.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-02-06 20:37:02 +00:00
|
|
|
$lifetime = 5184000; # 60 days session cookie lifetime
|
|
|
|
|
$path = url_dir(Config::get('url')=='' ? getRequestUri() : Config::getUrl('url'));
|
|
|
|
|
|
|
|
|
|
if (PHP_VERSION_ID < 70300) {
|
|
|
|
|
# this is a known samesite flag workaround, was fixed in 7.3
|
2022-11-02 21:20:32 +00:00
|
|
|
session_set_cookie_params($lifetime, $path. '; samesite=lax', null, null, true);
|
2022-02-06 20:37:02 +00:00
|
|
|
} else {
|
2022-11-02 21:20:32 +00:00
|
|
|
session_set_cookie_params([
|
2022-02-06 20:37:02 +00:00
|
|
|
'lifetime' => $lifetime,
|
|
|
|
|
'path' => $path,
|
|
|
|
|
'httponly' => true,
|
2022-11-02 21:20:32 +00:00
|
|
|
'samesite' => 'lax'
|
|
|
|
|
]);
|
2022-02-06 20:37:02 +00:00
|
|
|
}
|
|
|
|
|
session_name('mtt-session');
|
|
|
|
|
session_start();
|
2021-09-20 14:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-15 13:03:47 +00:00
|
|
|
function timestampToDatetime($timestamp, $forceTime = false) : string
|
2009-11-13 12:38:55 +00:00
|
|
|
{
|
2022-09-15 13:03:47 +00:00
|
|
|
$format = Config::get('dateformat');
|
|
|
|
|
if ($forceTime || Config::get('showtime')) {
|
|
|
|
|
$format .= ' '. (Config::get('clock') == 12 ? 'g:i A' : 'H:i');
|
|
|
|
|
}
|
2022-02-06 20:37:02 +00:00
|
|
|
return formatTime($format, $timestamp);
|
2009-12-15 14:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
2022-08-01 15:22:30 +00:00
|
|
|
function formatTime($format, $timestamp=0) : string
|
2009-12-15 14:49:32 +00:00
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
$lang = Lang::instance();
|
|
|
|
|
if($timestamp == 0) $timestamp = time();
|
|
|
|
|
$newformat = strtr($format, array('F'=>'%1', 'M'=>'%2'));
|
|
|
|
|
$adate = explode(',', date('n,'.$newformat, $timestamp), 2);
|
|
|
|
|
$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;
|
2009-11-13 12:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-06 18:35:36 +00:00
|
|
|
function _e(string $s)
|
2010-02-10 11:27:44 +00:00
|
|
|
{
|
2022-09-06 18:35:36 +00:00
|
|
|
echo __($s, true);
|
2010-02-10 11:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-06 18:35:36 +00:00
|
|
|
function __(string $s, bool $escape = false)
|
2010-02-10 11:27:44 +00:00
|
|
|
{
|
2022-09-06 18:35:36 +00:00
|
|
|
$v = Lang::instance()->get($s);
|
|
|
|
|
return $escape ? htmlspecialchars($v) : $v;
|
2010-02-10 11:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-06 19:52:08 +00:00
|
|
|
function mttinfo($v)
|
2010-02-10 11:27:44 +00:00
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
echo get_mttinfo($v);
|
2010-02-10 11:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-31 18:49:26 +00:00
|
|
|
function get_mttinfo($v)
|
|
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
return htmlspecialchars( get_unsafe_mttinfo($v) );
|
2022-01-31 18:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-12 14:02:15 +00:00
|
|
|
/*
|
|
|
|
|
* Returned values from get_unsafe_mttinfo() can be unsafe for html.
|
|
|
|
|
* But '\r' and '\n' in URLs taken from config are removed.
|
|
|
|
|
*/
|
|
|
|
|
function get_unsafe_mttinfo($v)
|
2010-02-10 11:27:44 +00:00
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
global $_mttinfo;
|
|
|
|
|
if (isset($_mttinfo[$v])) {
|
|
|
|
|
return $_mttinfo[$v];
|
|
|
|
|
}
|
|
|
|
|
switch($v)
|
|
|
|
|
{
|
2022-07-10 13:08:07 +00:00
|
|
|
case 'theme_url':
|
2022-09-10 22:04:51 +00:00
|
|
|
if (!isset($_mttinfo['theme_url'])) {
|
|
|
|
|
if ( Config::getUrl('url') == '' && Config::getUrl('mtt_url') == ''
|
|
|
|
|
&& (!defined('MTT_USE_HTTPS') || !MTT_USE_HTTPS) ) {
|
2022-11-20 13:01:35 +00:00
|
|
|
$_mttinfo['theme_url'] = url_dir(getRequestUri()). 'content/'. MTT_THEME. '/';
|
2022-09-10 22:04:51 +00:00
|
|
|
} else {
|
2022-11-20 13:01:35 +00:00
|
|
|
$_mttinfo['theme_url'] = get_unsafe_mttinfo('mtt_url'). 'content/'. MTT_THEME. '/';
|
2022-09-10 22:04:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-07-10 13:08:07 +00:00
|
|
|
return $_mttinfo['theme_url'];
|
2022-07-10 15:07:54 +00:00
|
|
|
case 'content_url':
|
2022-09-10 22:04:51 +00:00
|
|
|
if (!isset($_mttinfo['content_url'])) {
|
|
|
|
|
if ( Config::getUrl('url') == '' && Config::getUrl('mtt_url') == ''
|
|
|
|
|
&& (!defined('MTT_USE_HTTPS') || !MTT_USE_HTTPS) ) {
|
|
|
|
|
$_mttinfo['content_url'] = url_dir(getRequestUri()). 'content/';
|
|
|
|
|
} else {
|
|
|
|
|
$_mttinfo['content_url'] = get_unsafe_mttinfo('mtt_url'). 'content/';
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-10 15:07:54 +00:00
|
|
|
return $_mttinfo['content_url'];
|
2022-02-06 20:37:02 +00:00
|
|
|
case 'url':
|
|
|
|
|
/* full url to homepage: directory with root index.php or custom index file in the root. */
|
|
|
|
|
/* ex: http://my.site/mytinytodo/ or https://my.site/mytinytodo/home_for_2nd_theme.php */
|
|
|
|
|
/* Should not contain a query string. Have to be set in config if custom port is used or wrong detection. */
|
|
|
|
|
$_mttinfo['url'] = Config::getUrl('url');
|
|
|
|
|
if ($_mttinfo['url'] == '') {
|
2022-09-10 22:04:51 +00:00
|
|
|
$is_https = is_https();
|
2022-02-06 20:37:02 +00:00
|
|
|
$_mttinfo['url'] = ($is_https ? 'https://' : 'http://'). $_SERVER['HTTP_HOST']. url_dir(getRequestUri());
|
|
|
|
|
}
|
|
|
|
|
return $_mttinfo['url'];
|
|
|
|
|
case 'mtt_url':
|
2022-07-10 12:23:53 +00:00
|
|
|
/* Directory with settings.php. No need to set if you use default directory structure. */
|
2022-02-06 20:37:02 +00:00
|
|
|
$_mttinfo['mtt_url'] = Config::getUrl('mtt_url'); // need to have a trailing slash
|
|
|
|
|
if ($_mttinfo['mtt_url'] == '') {
|
|
|
|
|
$_mttinfo['mtt_url'] = url_dir( get_unsafe_mttinfo('url'), 0 );
|
|
|
|
|
}
|
|
|
|
|
return $_mttinfo['mtt_url'];
|
2022-07-10 12:23:53 +00:00
|
|
|
case 'api_url':
|
|
|
|
|
/* URL for API, like http://localhost/mytinytodo/api/. No need to set by default. */
|
|
|
|
|
$_mttinfo['api_url'] = Config::getUrl('api_url'); // need to have a trailing slash
|
|
|
|
|
if ($_mttinfo['api_url'] == '') {
|
2023-03-24 15:51:46 +00:00
|
|
|
if (defined('MTT_API_USE_PATH_INFO')) {
|
|
|
|
|
$_mttinfo['api_url'] = get_unsafe_mttinfo('mtt_url'). 'api/';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_mttinfo['api_url'] = get_unsafe_mttinfo('mtt_url'). 'api.php?_path=/';
|
|
|
|
|
}
|
2022-07-10 12:23:53 +00:00
|
|
|
}
|
|
|
|
|
return $_mttinfo['api_url'];
|
2022-02-06 20:37:02 +00:00
|
|
|
case 'title':
|
|
|
|
|
$_mttinfo['title'] = (Config::get('title') != '') ? Config::get('title') : __('My Tiny Todolist');
|
|
|
|
|
return $_mttinfo['title'];
|
|
|
|
|
case 'version':
|
2022-02-07 20:41:01 +00:00
|
|
|
if (MTT_DEBUG) {
|
|
|
|
|
$_mttinfo['version'] = mytinytodo\Version::VERSION . '-' . time();
|
|
|
|
|
} else {
|
|
|
|
|
$_mttinfo['version'] = mytinytodo\Version::VERSION;
|
|
|
|
|
}
|
|
|
|
|
return $_mttinfo['version'];
|
2022-02-16 20:04:02 +00:00
|
|
|
case 'appearance':
|
|
|
|
|
$_mttinfo['appearance'] = Config::get('appearance');
|
|
|
|
|
return $_mttinfo['appearance'];
|
2022-02-06 20:37:02 +00:00
|
|
|
}
|
2010-02-10 11:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-05 15:16:20 +00:00
|
|
|
function reset_mttinfo($key)
|
|
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
global $_mttinfo;
|
|
|
|
|
unset( $_mttinfo[$key] );
|
2020-10-05 15:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-10 22:04:51 +00:00
|
|
|
function is_https(): bool
|
|
|
|
|
{
|
|
|
|
|
if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-10-28 18:29:21 +00:00
|
|
|
/*
|
|
|
|
|
TODO: Check for X-Forwarded-Proto==https or X-Forwarded-For==https ?
|
|
|
|
|
*/
|
2022-09-10 22:04:51 +00:00
|
|
|
if (defined('MTT_USE_HTTPS') && MTT_USE_HTTPS) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-15 13:26:22 +00:00
|
|
|
function set_nocache_headers()
|
|
|
|
|
{
|
|
|
|
|
// little more info at https://www.php.net/manual/en/function.session-cache-limiter.php
|
|
|
|
|
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
|
|
|
|
|
header('Expires: Wed, 29 Apr 2009 10:00:00 GMT');
|
|
|
|
|
header('Pragma: no-cache'); // for old HTTP/1.0 intermediate caches
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-02 12:40:29 +00:00
|
|
|
function jsonExit($data)
|
|
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
header('Content-type: application/json; charset=utf-8');
|
2022-02-07 20:41:01 +00:00
|
|
|
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
2022-09-05 19:28:59 +00:00
|
|
|
MTTNotificationCenter::postDidFinishRequestNotification();
|
2022-02-06 20:37:02 +00:00
|
|
|
exit;
|
2011-03-02 12:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-24 15:16:16 +00:00
|
|
|
function logAndDie($userText, $errText = null)
|
2019-06-29 16:05:48 +00:00
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
$errText === null ? error_log($userText) : error_log($errText);
|
|
|
|
|
if (ini_get('display_errors')) {
|
|
|
|
|
echo htmlspecialchars($userText);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "Error! See details in error log.";
|
|
|
|
|
}
|
|
|
|
|
exit(1);
|
2019-06-29 16:05:48 +00:00
|
|
|
}
|
2022-09-06 20:28:24 +00:00
|
|
|
|
|
|
|
|
function loadExtensions()
|
|
|
|
|
{
|
|
|
|
|
$a = Config::get('extensions');
|
|
|
|
|
if (!$a || !is_array($a)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
foreach ($a as $ext) {
|
|
|
|
|
if (is_string($ext)) {
|
|
|
|
|
try {
|
|
|
|
|
MTTExtensionLoader::loadExtension($ext);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $e) {
|
|
|
|
|
error_log($e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|