From 11d2ad4139a761e9f4dde8e1287cf6db0f1009c8 Mon Sep 17 00:00:00 2001 From: maxpozdeev Date: Mon, 21 Nov 2022 14:55:13 +0300 Subject: [PATCH] * do not use PATH_INFO in http api by default --- src/content/mytinytodo.js | 2 +- src/content/mytinytodo_api.js | 2 +- src/includes/classes.php | 14 ++------------ src/init.php | 2 +- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/content/mytinytodo.js b/src/content/mytinytodo.js index 70a4772..efaca73 100644 --- a/src/content/mytinytodo.js +++ b/src/content/mytinytodo.js @@ -151,7 +151,7 @@ var mytinytodo = window.mytinytodo = _mtt = { delete options.apiUrl; } else { - this.apiUrl = this.mttUrl + 'api.php/'; + this.apiUrl = this.mttUrl + 'api.php?_path=/'; } if (options.hasOwnProperty('db')) { delete options.db; diff --git a/src/content/mytinytodo_api.js b/src/content/mytinytodo_api.js index ccba772..57a5fe5 100644 --- a/src/content/mytinytodo_api.js +++ b/src/content/mytinytodo_api.js @@ -39,7 +39,7 @@ MytinytodoAjaxApi.prototype = if (params.setCompl && params.setCompl != 0) q += '&setCompl=1'; if (params.saveSort && params.saveSort != 0) q += '&saveSort=1'; - $.getJSON(mtt.apiUrl + 'tasks?list='+params.list+'&compl='+params.compl+'&sort='+params.sort+q, callback); + $.getJSON(mtt.apiUrl + 'tasks' + (mtt.apiUrl.indexOf('?') > -1 ? '&' : '?') + 'list='+params.list+'&compl='+params.compl+'&sort='+params.sort+q, callback); }, diff --git a/src/includes/classes.php b/src/includes/classes.php index fc86b9f..be2685a 100644 --- a/src/includes/classes.php +++ b/src/includes/classes.php @@ -14,21 +14,11 @@ class ApiRequest public $jsonBody; function __construct() { - if (isset($_SERVER['PATH_INFO'])) { + if (defined('MTT_API_USE_PATH_INFO') && MTT_API_USE_PATH_INFO) { $this->path = $_SERVER['PATH_INFO']; } else { - $uri = $_SERVER['REQUEST_URI']; - if (false !== $p = strpos($uri, '?')) { - $uri = substr($uri, 0, $p); - } - $script = $_SERVER['SCRIPT_NAME']; - if (0 === $p = strpos($uri, $script)) { - $this->path = substr($uri, strlen($script)); - } - else { - $this->path = ''; - } + $this->path = $_GET['_path'] ?? ''; } $this->method = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET'; $this->contentType = $_SERVER['CONTENT_TYPE'] ?? ''; diff --git a/src/init.php b/src/init.php index 7c92944..372c919 100644 --- a/src/init.php +++ b/src/init.php @@ -349,7 +349,7 @@ function get_unsafe_mttinfo($v) /* 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'] == '') { - $_mttinfo['api_url'] = get_unsafe_mttinfo('mtt_url'). 'api.php/'; + $_mttinfo['api_url'] = get_unsafe_mttinfo('mtt_url'). 'api.php?_path=/'; } return $_mttinfo['api_url']; case 'title':