From 6a92bc43cce6fcd1b5b5a46899136f104d27b3af Mon Sep 17 00:00:00 2001 From: Max Pozdeev Date: Thu, 13 Aug 2020 21:41:44 +0300 Subject: [PATCH] - Fix malfunction due to deprecated gpc notice in PHP 7.4 (mtt now requires php 5.4+) --- src/common.php | 24 ++++++++++++++++++------ src/init.php | 9 +++++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/common.php b/src/common.php index e066fee..78b26db 100644 --- a/src/common.php +++ b/src/common.php @@ -2,7 +2,7 @@ /* This file is part of myTinyTodo. - (C) Copyright 2009-2010 Max Pozdeev + (C) Copyright 2009-2010,2020 Max Pozdeev Licensed under the GNU GPL v2 license. See file COPYRIGHT for details. */ @@ -32,14 +32,26 @@ function htmlarray_ref(&$a, $exclude=null) function stop_gpc(&$arr) { - if (!is_array($arr)) return 1; + if (!is_array($arr)) { + return 1; + } + + // Since PHP v5.4.0 magic quotes feature was removed from PHP + // In PHP v7.4 get_magic_quotes_gpc is deprecated + // TODO: do not use get_magic_quotes_gpc() and stop_gpc() + if (!@get_magic_quotes_gpc()) { + return 1; + } - if (!get_magic_quotes_gpc()) return 1; reset($arr); - foreach($arr as $k=>$v) + foreach ($arr as $k=>$v) { - if(is_array($arr[$k])) stop_gpc($arr[$k]); - elseif(is_string($arr[$k])) $arr[$k] = stripslashes($v); + if (is_array($arr[$k])) { + stop_gpc($arr[$k]); + } + elseif (is_string($arr[$k])) { + $arr[$k] = stripslashes($v); + } } return 1; diff --git a/src/init.php b/src/init.php index 550f46a..98ded63 100644 --- a/src/init.php +++ b/src/init.php @@ -1,10 +1,15 @@ + (C) Copyright 2009-2010,2020 Max Pozdeev Licensed under the GNU GPL v2 license. See file COPYRIGHT for details. */ +##### MyTinyTodo requires php 5.4.0 and above! ##### +if (version_compare(PHP_VERSION, '5.4.0') < 0) { + die("PHP 5.4+ is required"); +} + if(!defined('MTTPATH')) define('MTTPATH', dirname(__FILE__) .'/'); require_once(MTTPATH. 'common.php'); @@ -46,7 +51,7 @@ else { $db->prefix = Config::get('prefix'); //User can override language setting by cookies -if(isset($_COOKIE['lang']) && preg_match("/^[a-z-]+$/i", $_COOKIE['lang']) && file_exists('lang/'. $_COOKIE['lang']. '.php')) { +if(isset($_COOKIE['lang']) && preg_match("/^[a-z-]+$/i", $_COOKIE['lang']) && file_exists(MTTPATH. 'lang/'. $_COOKIE['lang']. '.php')) { Config::set('lang', $_COOKIE['lang']); }