X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fpoco.php;h=d8941e51ade5c6de1caa52d71197d6693bc06c8e;hb=38e5733b6ee10f5a6dd7f017b6b6e7acfde80565;hp=3456beb12896a4b2a507f365b28330d66ba76f54;hpb=69a73678ebc18ad27b27f1bf92bc9433b7e7066f;p=friendica.git diff --git a/mod/poco.php b/mod/poco.php index 3456beb128..d8941e51ad 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -6,13 +6,11 @@ use Friendica\App; use Friendica\Content\Text\BBCode; -use Friendica\Core\Cache; -use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Renderer; -use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Protocol\PortableContact; use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; @@ -21,22 +19,22 @@ use Friendica\Util\XML; function poco_init(App $a) { $system_mode = false; - if (intval(Config::get('system', 'block_public')) || (Config::get('system', 'block_local_dir'))) { - System::httpExit(401); + if (intval(DI::config()->get('system', 'block_public')) || (DI::config()->get('system', 'block_local_dir'))) { + throw new \Friendica\Network\HTTPException\ForbiddenException(); } if ($a->argc > 1) { - $user = Strings::escapeTags(trim($a->argv[1])); + $nickname = Strings::escapeTags(trim($a->argv[1])); } - if (empty($user)) { + if (empty($nickname)) { $c = q("SELECT * FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1"); if (!DBA::isResult($c)) { - System::httpExit(401); + throw new \Friendica\Network\HTTPException\ForbiddenException(); } $system_mode = true; } - $format = defaults($_GET, 'format', 'json'); + $format = ($_GET['format'] ?? '') ?: 'json'; $justme = false; $global = false; @@ -46,7 +44,7 @@ function poco_init(App $a) { $ret = PortableContact::serverlist(); header('Content-type: application/json'); echo json_encode($ret); - killme(); + exit(); } if ($a->argc > 1 && $a->argv[1] === '@global') { @@ -69,11 +67,11 @@ function poco_init(App $a) { if (! $system_mode && ! $global) { $users = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid` - where `user`.`nickname` = '%s' and `profile`.`is-default` = 1 limit 1", - DBA::escape($user) + where `user`.`nickname` = '%s' limit 1", + DBA::escape($nickname) ); if (! DBA::isResult($users) || $users[0]['hidewall'] || $users[0]['hide-friends']) { - System::httpExit(404); + throw new \Friendica\Network\HTTPException\NotFoundException(); } $user = $users[0]; @@ -142,7 +140,7 @@ function poco_init(App $a) { `profile`.`postal-code` AS `ppostalcode`, `profile`.`country-name` AS `pcountry`, `user`.`account-type` FROM `contact` INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` - WHERE `self` = 1 AND `profile`.`is-default` + WHERE `self` = 1 AND `contact`.`uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d", intval($startIndex), intval($itemsPerPage) @@ -255,10 +253,10 @@ function poco_init(App $a) { if (isset($contact['account-type'])) { $contact['contact-type'] = $contact['account-type']; } - $about = Cache::get("about:" . $contact['updated'] . ":" . $contact['nurl']); + $about = DI::cache()->get("about:" . $contact['updated'] . ":" . $contact['nurl']); if (is_null($about)) { $about = BBCode::convert($contact['about'], false); - Cache::set("about:" . $contact['updated'] . ":" . $contact['nurl'], $about); + DI::cache()->set("about:" . $contact['updated'] . ":" . $contact['nurl'], $about); } // Non connected persons can only see the keywords of a Diaspora account @@ -371,20 +369,21 @@ function poco_init(App $a) { $ret['entry'][] = []; } } else { - System::httpExit(500); + throw new \Friendica\Network\HTTPException\InternalServerErrorException(); } + Logger::log("End of poco", Logger::DEBUG); if ($format === 'xml') { header('Content-type: text/xml'); echo Renderer::replaceMacros(Renderer::getMarkupTemplate('poco_xml.tpl'), XML::arrayEscape(['$response' => $ret])); - killme(); + exit(); } if ($format === 'json') { header('Content-type: application/json'); echo json_encode($ret); - killme(); + exit(); } else { - System::httpExit(500); + throw new \Friendica\Network\HTTPException\InternalServerErrorException(); } }