From cb50641bc47dd5ae955467be41f4f8ba3ae7a7ef Mon Sep 17 00:00:00 2001 From: Christian Haschek Date: Sat, 27 Nov 2021 18:09:05 +0100 Subject: [PATCH] more preparations and also small sanity fixes --- web/api.php | 14 +++++++++----- web/inc/core.php | 3 +-- web/rss.php | 8 +++++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/web/api.php b/web/api.php index 0237ed7..c3a2e38 100644 --- a/web/api.php +++ b/web/api.php @@ -7,6 +7,13 @@ ini_set('display_errors', 1); include_once(ROOT.DS.'inc'.DS.'core.php'); +if (PHP_SAPI === 'cli-server') + $_SERVER['SCRIPT_NAME'] = pathinfo(__FILE__, PATHINFO_BASENAME); + +if($_GET['url']) + $url = explode('/',ltrim(parse_url($_GET['url'], PHP_URL_PATH),'/')); +else $url = array_filter(explode('/',ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),'/'))); + $action = strtolower($_REQUEST['a']); $email = strtolower($_REQUEST['email']); if(!empty($email)){ @@ -88,15 +95,13 @@ switch($action) $emails = listEmailAdresses(); $emaillist = array(); - if(count($emails)) + if(count($emails)>0) { foreach($emails as $email) { $emaildata = getEmailsOfEmail($email); foreach($emaildata as $time=>$d) - { $emaillist[$time.'-'.$email]=$d; - } } if(is_array($emaillist)) krsort($emaillist); @@ -126,5 +131,4 @@ switch($action) break; } -echo json_encode($o); -//var_dump($o); +echo json_encode($o); \ No newline at end of file diff --git a/web/inc/core.php b/web/inc/core.php index 2e4ba23..befd8b8 100644 --- a/web/inc/core.php +++ b/web/inc/core.php @@ -33,7 +33,7 @@ function emailIDExists($email,$id) function getEmailsOfEmail($email) { - $o = false; + $o = []; if ($handle = opendir(getDirForEmail($email))) { while (false !== ($entry = readdir($handle))) { if (endsWith($entry,'.json')) { @@ -54,7 +54,6 @@ function getEmailsOfEmail($email) function listEmailAdresses() { $o = array(); - $o = false; if ($handle = opendir(ROOT.DS.'..'.DS.'data'.DS)) { while (false !== ($entry = readdir($handle))) { if(filter_var($entry, FILTER_VALIDATE_EMAIL)) diff --git a/web/rss.php b/web/rss.php index 9acf331..fd0e80f 100644 --- a/web/rss.php +++ b/web/rss.php @@ -10,7 +10,13 @@ include_once(ROOT.DS.'inc'.DS.'core.php'); header("Content-Type: application/rss+xml; charset=UTF8"); -$url = explode('/',ltrim($_GET['url'],'/')); +if (PHP_SAPI === 'cli-server') + $_SERVER['SCRIPT_NAME'] = pathinfo(__FILE__, PATHINFO_BASENAME); + +if($_GET['url']) + $url = explode('/',ltrim(parse_url($_GET['url'], PHP_URL_PATH),'/')); +else $url = array_filter(explode('/',ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),'/'))); + array_shift($url); $email = $url[0];