From 4016a576d55d2e9b4b3acbe515a73b8c025ef215 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 17 May 2022 20:47:23 +0000 Subject: [PATCH 1/5] Log the execution time --- mod/fbrowser.php | 2 ++ mod/photos.php | 2 ++ mod/pubsub.php | 1 + mod/pubsubhubbub.php | 1 + mod/share.php | 3 +++ mod/tagger.php | 2 +- mod/wall_attach.php | 7 ++++++- mod/wall_upload.php | 7 +++++++ src/App.php | 2 ++ src/App/Page.php | 22 ++++++++++++++++++++++ src/Core/System.php | 3 ++- src/Module/Admin/PhpInfo.php | 1 + src/Module/Attach.php | 1 + src/Module/Contact/Hovercard.php | 1 + src/Module/Debug/ItemBody.php | 1 + src/Module/Group.php | 1 + src/Module/HTTPException/PageNotFound.php | 1 + src/Module/Oembed.php | 3 +++ src/Module/PermissionTooltip.php | 2 +- src/Module/Photo.php | 1 + src/Module/Proxy.php | 1 + src/Module/RobotsTxt.php | 1 + src/Module/Settings/UserExport.php | 2 +- src/Module/Theme.php | 2 +- src/Module/ThemeDetails.php | 1 + src/Module/Update/Network.php | 1 + src/Util/JsonLD.php | 1 + 27 files changed, 67 insertions(+), 6 deletions(-) diff --git a/mod/fbrowser.php b/mod/fbrowser.php index 1646b19df..4e887c7eb 100644 --- a/mod/fbrowser.php +++ b/mod/fbrowser.php @@ -39,10 +39,12 @@ use Friendica\Util\Strings; function fbrowser_content(App $a) { if (!local_user()) { + DI::page()->logRuntime(); exit(); } if (DI::args()->getArgc() == 1) { + DI::page()->logRuntime(); exit(); } diff --git a/mod/photos.php b/mod/photos.php index ce6d11340..fa8a434c4 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -158,6 +158,7 @@ function photos_post(App $a) if (!$can_post) { notice(DI::l10n()->t('Permission denied.')); + DI::page()->logRuntime(); exit(); } @@ -166,6 +167,7 @@ function photos_post(App $a) if (!$owner_record) { notice(DI::l10n()->t('Contact information unavailable')); DI::logger()->info('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid); + DI::page()->logRuntime(); exit(); } diff --git a/mod/pubsub.php b/mod/pubsub.php index e07b15583..630b68f50 100644 --- a/mod/pubsub.php +++ b/mod/pubsub.php @@ -38,6 +38,7 @@ function hub_return($valid, $body) } else { throw new \Friendica\Network\HTTPException\NotFoundException(); } + DI::page()->logRuntime(); exit(); } diff --git a/mod/pubsubhubbub.php b/mod/pubsubhubbub.php index 361cb0a59..5300f783d 100644 --- a/mod/pubsubhubbub.php +++ b/mod/pubsubhubbub.php @@ -142,5 +142,6 @@ function pubsubhubbub_init(App $a) { throw new \Friendica\Network\HTTPException\AcceptedException(); } + DI::page()->logRuntime(); exit(); } diff --git a/mod/share.php b/mod/share.php index b18655aef..dde3864bc 100644 --- a/mod/share.php +++ b/mod/share.php @@ -30,6 +30,7 @@ function share_init(App $a) { $post_id = ((DI::args()->getArgc() > 1) ? intval(DI::args()->getArgv()[1]) : 0); if (!$post_id || !local_user()) { + DI::page()->logRuntime(); exit(); } @@ -38,6 +39,7 @@ function share_init(App $a) { $item = Post::selectFirst($fields, ['id' => $post_id]); if (!DBA::isResult($item) || $item['private'] == Item::PRIVATE) { + DI::page()->logRuntime(); exit(); } @@ -56,5 +58,6 @@ function share_init(App $a) { } echo $o; + DI::page()->logRuntime(); exit(); } diff --git a/mod/tagger.php b/mod/tagger.php index 310e3c614..4c0af4a53 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -167,6 +167,6 @@ EOT; $post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]); Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post['uri-id'], $post['uid']); - + DI::page()->logRuntime(); exit(); } diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 607d0fe7a..6dfa40b09 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -67,6 +67,7 @@ function wall_attach_post(App $a) { System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]); } notice(DI::l10n()->t('Permission denied.') . EOL ); + DI::page()->logRuntime(); exit(); } @@ -74,6 +75,7 @@ function wall_attach_post(App $a) { if ($r_json) { System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); } + DI::page()->logRuntime(); exit(); } @@ -97,6 +99,7 @@ function wall_attach_post(App $a) { } else { notice($msg); } + DI::page()->logRuntime(); exit(); } @@ -108,6 +111,7 @@ function wall_attach_post(App $a) { } else { echo $msg . EOL; } + DI::page()->logRuntime(); exit(); } @@ -122,6 +126,7 @@ function wall_attach_post(App $a) { } else { echo $msg . EOL; } + DI::page()->logRuntime(); exit(); } @@ -132,7 +137,7 @@ function wall_attach_post(App $a) { $lf = "\n"; echo $lf . $lf . '[attachment]' . $newid . '[/attachment]' . $lf; - + DI::page()->logRuntime(); exit(); // NOTREACHED } diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 79f1dcc41..8b8b1df9a 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -89,6 +89,7 @@ function wall_upload_post(App $a, $desktopmode = true) System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]); } notice(DI::l10n()->t('Permission denied.')); + DI::page()->logRuntime(); exit(); } @@ -96,6 +97,7 @@ function wall_upload_post(App $a, $desktopmode = true) if ($r_json) { System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); } + DI::page()->logRuntime(); exit(); } @@ -148,6 +150,7 @@ function wall_upload_post(App $a, $desktopmode = true) System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); } notice(DI::l10n()->t('Invalid request.')); + DI::page()->logRuntime(); exit(); } @@ -167,6 +170,7 @@ function wall_upload_post(App $a, $desktopmode = true) } else { echo $msg. EOL; } + DI::page()->logRuntime(); exit(); } @@ -205,6 +209,7 @@ function wall_upload_post(App $a, $desktopmode = true) } else { echo $msg. EOL; } + DI::page()->logRuntime(); exit(); } } @@ -229,6 +234,7 @@ function wall_upload_post(App $a, $desktopmode = true) } else { echo $msg. EOL; } + DI::page()->logRuntime(); exit(); } @@ -281,6 +287,7 @@ function wall_upload_post(App $a, $desktopmode = true) } echo "\n\n" . '[url=' . DI::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $resource_id . '][img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$Image->getExt()."[/img][/url]\n\n"; + DI::page()->logRuntime(); exit(); // NOTREACHED } diff --git a/src/App.php b/src/App.php index f7c929820..bf5c309ed 100644 --- a/src/App.php +++ b/src/App.php @@ -576,6 +576,7 @@ class App $this->profiler->set(microtime(true), 'classinit'); $moduleName = $this->args->getModuleName(); + $page->setLogging($moduleName, $this->args->getMethod()); try { // Missing DB connection: ERROR @@ -712,6 +713,7 @@ class App $this->profiler->set(microtime(true) - $timestamp, 'content'); if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) { $page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig); + $page->logRuntime(); } else { $page->exit($response); } diff --git a/src/App/Page.php b/src/App/Page.php index 14f0101ef..8986d4aa9 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -30,6 +30,7 @@ use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\Hook; use Friendica\Core\L10n; +use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Core\Theme; @@ -78,14 +79,31 @@ class Page implements ArrayAccess */ private $basePath; + private $timestamp = 0; + private $moduleName = ''; + private $method = ''; + /** * @param string $basepath The Page basepath */ public function __construct(string $basepath) { + $this->timestamp = microtime(true); $this->basePath = $basepath; } + public function setLogging(string $moduleName, string $method) + { + $this->moduleName = $moduleName; + $this->method = $method; + } + + public function logRuntime() + { + $runtime = number_format(microtime(true) - $this->timestamp, 3); + Logger::debug('Runtime', ['method' => $this->method, 'module' => $this->moduleName, 'runtime' => $runtime]); + } + /** * Whether a offset exists * @@ -401,6 +419,7 @@ class Page implements ArrayAccess } echo $response->getBody(); + $this->logRuntime(); } /** @@ -421,6 +440,9 @@ class Page implements ArrayAccess { $moduleName = $args->getModuleName(); + $this->moduleName = $moduleName; + $this->method = $args->getMethod(); + /* Create the page content. * Calls all hooks which are including content operations * diff --git a/src/Core/System.php b/src/Core/System.php index 66b6b25a5..7b0a887cd 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -448,7 +448,7 @@ class System case 307: throw new TemporaryRedirectException(); } - + DI::page()->logRuntime(); exit(); } @@ -522,6 +522,7 @@ class System echo str_replace("\t", " ", $o); echo ""; echo "\r\n"; + DI::page()->logRuntime(); exit(); } diff --git a/src/Module/Admin/PhpInfo.php b/src/Module/Admin/PhpInfo.php index 0177424f3..732753b59 100644 --- a/src/Module/Admin/PhpInfo.php +++ b/src/Module/Admin/PhpInfo.php @@ -30,6 +30,7 @@ class PhpInfo extends BaseAdmin self::checkAdminAccess(); phpinfo(); + DI::page()->logRuntime(); exit(); } } diff --git a/src/Module/Attach.php b/src/Module/Attach.php index 60d1015b0..fc7ba74d5 100644 --- a/src/Module/Attach.php +++ b/src/Module/Attach.php @@ -72,6 +72,7 @@ class Attach extends BaseModule } echo $data; + DI::page()->logRuntime(); exit(); // NOTREACHED } diff --git a/src/Module/Contact/Hovercard.php b/src/Module/Contact/Hovercard.php index cd03e2533..2bf6f63ed 100644 --- a/src/Module/Contact/Hovercard.php +++ b/src/Module/Contact/Hovercard.php @@ -107,6 +107,7 @@ class Hovercard extends BaseModule ]); echo $o; + DI::page()->logRuntime(); exit(); } } diff --git a/src/Module/Debug/ItemBody.php b/src/Module/Debug/ItemBody.php index 55abc894e..e066e7656 100644 --- a/src/Module/Debug/ItemBody.php +++ b/src/Module/Debug/ItemBody.php @@ -48,6 +48,7 @@ class ItemBody extends BaseModule if (!empty($item)) { if (DI::mode()->isAjax()) { echo str_replace("\n", '
', $item['body']); + DI::page()->logRuntime(); exit(); } else { return str_replace("\n", '
', $item['body']); diff --git a/src/Module/Group.php b/src/Module/Group.php index 3cd8166f1..4825debd0 100644 --- a/src/Module/Group.php +++ b/src/Module/Group.php @@ -360,6 +360,7 @@ class Group extends BaseModule if ($change) { $tpl = Renderer::getMarkupTemplate('groupeditor.tpl'); echo Renderer::replaceMacros($tpl, $context); + DI::page()->logRuntime(); exit(); } diff --git a/src/Module/HTTPException/PageNotFound.php b/src/Module/HTTPException/PageNotFound.php index a73757d82..ba34df854 100644 --- a/src/Module/HTTPException/PageNotFound.php +++ b/src/Module/HTTPException/PageNotFound.php @@ -47,6 +47,7 @@ class PageNotFound extends BaseModule $queryString = $this->server['QUERY_STRING']; // Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit. if (!empty($queryString) && preg_match('/{[0-9]}/', $queryString) !== 0) { + DI::page()->logRuntime(); exit(); } diff --git a/src/Module/Oembed.php b/src/Module/Oembed.php index 81c858cba..49b479204 100644 --- a/src/Module/Oembed.php +++ b/src/Module/Oembed.php @@ -43,6 +43,7 @@ class Oembed extends BaseModule if (DI::args()->getArgv()[1] == 'b2h') { $url = ["", trim(hex2bin($_REQUEST['url']))]; echo Content\OEmbed::replaceCallback($url); + DI::page()->logRuntime(); exit(); } @@ -50,6 +51,7 @@ class Oembed extends BaseModule if (DI::args()->getArgv()[1] == 'h2b') { $text = trim(hex2bin($_REQUEST['text'])); echo Content\OEmbed::HTML2BBCode($text); + DI::page()->logRuntime(); exit(); } @@ -68,6 +70,7 @@ class Oembed extends BaseModule echo $j->html; echo ''; } + DI::page()->logRuntime(); exit(); } } diff --git a/src/Module/PermissionTooltip.php b/src/Module/PermissionTooltip.php index ff0bae1bc..edc839a38 100644 --- a/src/Module/PermissionTooltip.php +++ b/src/Module/PermissionTooltip.php @@ -164,7 +164,7 @@ class PermissionTooltip extends \Friendica\BaseModule } else { echo $o . $receivers; } - + DI::page()->logRuntime(); exit(); } diff --git a/src/Module/Photo.php b/src/Module/Photo.php index 9e56301b4..d050188aa 100644 --- a/src/Module/Photo.php +++ b/src/Module/Photo.php @@ -224,6 +224,7 @@ class Photo extends BaseModule 'output' => number_format($output, 3), 'rest' => number_format($rest, 3)]); } + DI::page()->logRuntime(); exit(); } diff --git a/src/Module/Proxy.php b/src/Module/Proxy.php index 3ef3117d6..0af49762e 100644 --- a/src/Module/Proxy.php +++ b/src/Module/Proxy.php @@ -202,6 +202,7 @@ class Proxy extends BaseModule header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (31536000)) . ' GMT'); header('Cache-Control: max-age=31536000'); echo $img->asString(); + DI::page()->logRuntime(); exit(); } } diff --git a/src/Module/RobotsTxt.php b/src/Module/RobotsTxt.php index 1fcf1269e..e4b1af7ab 100644 --- a/src/Module/RobotsTxt.php +++ b/src/Module/RobotsTxt.php @@ -44,6 +44,7 @@ class RobotsTxt extends BaseModule foreach ($allDisalloweds as $disallowed) { echo 'Disallow: ' . $disallowed . PHP_EOL; } + DI::page()->logRuntime(); exit(); } } diff --git a/src/Module/Settings/UserExport.php b/src/Module/Settings/UserExport.php index 1d47df4fd..6af321a0b 100644 --- a/src/Module/Settings/UserExport.php +++ b/src/Module/Settings/UserExport.php @@ -112,7 +112,7 @@ class UserExport extends BaseSettings self::exportContactsAsCSV(local_user()); break; } - + DI::page()->logRuntime(); exit(); } } diff --git a/src/Module/Theme.php b/src/Module/Theme.php index 66c9d06f0..8d14d82da 100644 --- a/src/Module/Theme.php +++ b/src/Module/Theme.php @@ -45,7 +45,7 @@ class Theme extends BaseModule if (file_exists("view/theme/$theme/style.php")) { require_once "view/theme/$theme/style.php"; } - + DI::page()->logRuntime(); exit(); } } diff --git a/src/Module/ThemeDetails.php b/src/Module/ThemeDetails.php index 6398a00c9..1bd45913a 100644 --- a/src/Module/ThemeDetails.php +++ b/src/Module/ThemeDetails.php @@ -48,6 +48,7 @@ class ThemeDetails extends BaseModule 'credits' => $credits, ]); } + DI::page()->logRuntime(); exit(); } } diff --git a/src/Module/Update/Network.php b/src/Module/Update/Network.php index 330cba2d3..2b71d23c4 100644 --- a/src/Module/Update/Network.php +++ b/src/Module/Update/Network.php @@ -31,6 +31,7 @@ class Network extends NetworkModule protected function rawContent(array $request = []) { if (!isset($_GET['p']) || !isset($_GET['item'])) { + DI::page()->logRuntime(); exit(); } diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index cf1e058a1..c2271565c 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -69,6 +69,7 @@ class JsonLD if ($recursion > 5) { Logger::error('jsonld bomb detected at: ' . $url); + DI::page()->logRuntime(); exit(); } From aacaa3c2cf7ac4189ae6b41701d66ee3cd7f8535 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 17 May 2022 21:25:01 +0000 Subject: [PATCH 2/5] Log the command, not the module --- src/App.php | 2 +- src/App/Page.php | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/App.php b/src/App.php index bf5c309ed..d85de3670 100644 --- a/src/App.php +++ b/src/App.php @@ -576,7 +576,7 @@ class App $this->profiler->set(microtime(true), 'classinit'); $moduleName = $this->args->getModuleName(); - $page->setLogging($moduleName, $this->args->getMethod()); + $page->setLogging($this->args->getCommand(), $this->args->getMethod()); try { // Missing DB connection: ERROR diff --git a/src/App/Page.php b/src/App/Page.php index 8986d4aa9..16c4934e3 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -79,9 +79,9 @@ class Page implements ArrayAccess */ private $basePath; - private $timestamp = 0; - private $moduleName = ''; - private $method = ''; + private $timestamp = 0; + private $command = ''; + private $method = ''; /** * @param string $basepath The Page basepath @@ -92,16 +92,16 @@ class Page implements ArrayAccess $this->basePath = $basepath; } - public function setLogging(string $moduleName, string $method) + public function setLogging(string $command, string $method) { - $this->moduleName = $moduleName; - $this->method = $method; + $this->command = $command; + $this->method = $method; } public function logRuntime() { $runtime = number_format(microtime(true) - $this->timestamp, 3); - Logger::debug('Runtime', ['method' => $this->method, 'module' => $this->moduleName, 'runtime' => $runtime]); + Logger::debug('Runtime', ['method' => $this->method, 'command' => $this->command, 'runtime' => $runtime]); } /** @@ -440,8 +440,8 @@ class Page implements ArrayAccess { $moduleName = $args->getModuleName(); - $this->moduleName = $moduleName; - $this->method = $args->getMethod(); + $this->command = $moduleName; + $this->method = $args->getMethod(); /* Create the page content. * Calls all hooks which are including content operations From 4e9d7df31adac776af294cd67d28214c43ec2ecf Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 17 May 2022 21:26:35 +0000 Subject: [PATCH 3/5] Add missing DI --- src/Module/Admin/PhpInfo.php | 1 + src/Module/RobotsTxt.php | 1 + src/Module/ThemeDetails.php | 1 + 3 files changed, 3 insertions(+) diff --git a/src/Module/Admin/PhpInfo.php b/src/Module/Admin/PhpInfo.php index 732753b59..feaa9de23 100644 --- a/src/Module/Admin/PhpInfo.php +++ b/src/Module/Admin/PhpInfo.php @@ -21,6 +21,7 @@ namespace Friendica\Module\Admin; +use Friendica\DI; use Friendica\Module\BaseAdmin; class PhpInfo extends BaseAdmin diff --git a/src/Module/RobotsTxt.php b/src/Module/RobotsTxt.php index e4b1af7ab..afc8ebf8f 100644 --- a/src/Module/RobotsTxt.php +++ b/src/Module/RobotsTxt.php @@ -22,6 +22,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\DI; /** * Return the default robots.txt diff --git a/src/Module/ThemeDetails.php b/src/Module/ThemeDetails.php index 1bd45913a..c69c93b03 100644 --- a/src/Module/ThemeDetails.php +++ b/src/Module/ThemeDetails.php @@ -24,6 +24,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\System; use Friendica\Core\Theme; +use Friendica\DI; /** * Prints theme specific details as a JSON string From f6167b4cfd36ca4d7a44d501509627ca8989f6b1 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 18 May 2022 02:13:54 +0000 Subject: [PATCH 4/5] New function to exit the program --- mod/fbrowser.php | 6 ++---- mod/photos.php | 6 ++---- mod/pubsub.php | 4 ++-- mod/pubsubhubbub.php | 4 ++-- mod/share.php | 10 ++++------ mod/tagger.php | 3 +-- mod/wall_attach.php | 18 ++++++------------ mod/wall_upload.php | 21 +++++++-------------- src/App.php | 2 +- src/App/Page.php | 1 - src/Core/System.php | 23 ++++++++++++++++------- src/Module/Admin/PhpInfo.php | 5 ++--- src/Module/Attach.php | 4 ++-- src/Module/Contact/Hovercard.php | 4 ++-- src/Module/Debug/ItemBody.php | 4 ++-- src/Module/Group.php | 3 +-- src/Module/HTTPException/PageNotFound.php | 4 ++-- src/Module/Oembed.php | 10 ++++------ src/Module/PermissionTooltip.php | 4 ++-- src/Module/Photo.php | 4 ++-- src/Module/Proxy.php | 3 +-- src/Module/RobotsTxt.php | 5 ++--- src/Module/Settings/UserExport.php | 4 ++-- src/Module/Theme.php | 5 ++--- src/Module/ThemeDetails.php | 3 +-- src/Module/Update/Network.php | 3 +-- src/Util/JsonLD.php | 4 ++-- 27 files changed, 73 insertions(+), 94 deletions(-) diff --git a/mod/fbrowser.php b/mod/fbrowser.php index 4e887c7eb..81284d6b9 100644 --- a/mod/fbrowser.php +++ b/mod/fbrowser.php @@ -39,13 +39,11 @@ use Friendica\Util\Strings; function fbrowser_content(App $a) { if (!local_user()) { - DI::page()->logRuntime(); - exit(); + System::exit(); } if (DI::args()->getArgc() == 1) { - DI::page()->logRuntime(); - exit(); + System::exit(); } // Needed to match the correct template in a module that uses a different theme than the user/site/default diff --git a/mod/photos.php b/mod/photos.php index fa8a434c4..52d749bb4 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -158,8 +158,7 @@ function photos_post(App $a) if (!$can_post) { notice(DI::l10n()->t('Permission denied.')); - DI::page()->logRuntime(); - exit(); + System::exit(); } $owner_record = User::getOwnerDataById($page_owner_uid); @@ -167,8 +166,7 @@ function photos_post(App $a) if (!$owner_record) { notice(DI::l10n()->t('Contact information unavailable')); DI::logger()->info('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid); - DI::page()->logRuntime(); - exit(); + System::exit(); } $aclFormatter = DI::aclFormatter(); diff --git a/mod/pubsub.php b/mod/pubsub.php index 630b68f50..918c55ee1 100644 --- a/mod/pubsub.php +++ b/mod/pubsub.php @@ -22,6 +22,7 @@ use Friendica\App; use Friendica\Core\Logger; use Friendica\Core\Protocol; +use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -38,8 +39,7 @@ function hub_return($valid, $body) } else { throw new \Friendica\Network\HTTPException\NotFoundException(); } - DI::page()->logRuntime(); - exit(); + System::exit(); } // when receiving an XML feed, always return OK diff --git a/mod/pubsubhubbub.php b/mod/pubsubhubbub.php index 5300f783d..5dda9ee0a 100644 --- a/mod/pubsubhubbub.php +++ b/mod/pubsubhubbub.php @@ -21,6 +21,7 @@ use Friendica\App; use Friendica\Core\Logger; +use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\PushSubscriber; @@ -142,6 +143,5 @@ function pubsubhubbub_init(App $a) { throw new \Friendica\Network\HTTPException\AcceptedException(); } - DI::page()->logRuntime(); - exit(); + System::exit(); } diff --git a/mod/share.php b/mod/share.php index dde3864bc..2f836c5aa 100644 --- a/mod/share.php +++ b/mod/share.php @@ -21,6 +21,7 @@ use Friendica\App; use Friendica\Content\Text\BBCode; +use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Item; @@ -30,8 +31,7 @@ function share_init(App $a) { $post_id = ((DI::args()->getArgc() > 1) ? intval(DI::args()->getArgv()[1]) : 0); if (!$post_id || !local_user()) { - DI::page()->logRuntime(); - exit(); + System::exit(); } $fields = ['private', 'body', 'author-name', 'author-link', 'author-avatar', @@ -39,8 +39,7 @@ function share_init(App $a) { $item = Post::selectFirst($fields, ['id' => $post_id]); if (!DBA::isResult($item) || $item['private'] == Item::PRIVATE) { - DI::page()->logRuntime(); - exit(); + System::exit(); } if (strpos($item['body'], "[/share]") !== false) { @@ -58,6 +57,5 @@ function share_init(App $a) { } echo $o; - DI::page()->logRuntime(); - exit(); + System::exit(); } diff --git a/mod/tagger.php b/mod/tagger.php index 4c0af4a53..1acce4b0b 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -167,6 +167,5 @@ EOT; $post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]); Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post['uri-id'], $post['uid']); - DI::page()->logRuntime(); - exit(); + System::exit(); } diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 6dfa40b09..43f4681df 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -67,16 +67,14 @@ function wall_attach_post(App $a) { System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]); } notice(DI::l10n()->t('Permission denied.') . EOL ); - DI::page()->logRuntime(); - exit(); + System::exit(); } if (empty($_FILES['userfile'])) { if ($r_json) { System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); } - DI::page()->logRuntime(); - exit(); + System::exit(); } $src = $_FILES['userfile']['tmp_name']; @@ -99,8 +97,7 @@ function wall_attach_post(App $a) { } else { notice($msg); } - DI::page()->logRuntime(); - exit(); + System::exit(); } if ($maxfilesize && $filesize > $maxfilesize) { @@ -111,8 +108,7 @@ function wall_attach_post(App $a) { } else { echo $msg . EOL; } - DI::page()->logRuntime(); - exit(); + System::exit(); } $newid = Attach::storeFile($src, $page_owner_uid, $filename, '<' . $page_owner_cid . '>'); @@ -126,8 +122,7 @@ function wall_attach_post(App $a) { } else { echo $msg . EOL; } - DI::page()->logRuntime(); - exit(); + System::exit(); } if ($r_json) { @@ -137,7 +132,6 @@ function wall_attach_post(App $a) { $lf = "\n"; echo $lf . $lf . '[attachment]' . $newid . '[/attachment]' . $lf; - DI::page()->logRuntime(); - exit(); + System::exit(); // NOTREACHED } diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 8b8b1df9a..36e313cec 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -89,16 +89,14 @@ function wall_upload_post(App $a, $desktopmode = true) System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]); } notice(DI::l10n()->t('Permission denied.')); - DI::page()->logRuntime(); - exit(); + System::exit(); } if (empty($_FILES['userfile']) && empty($_FILES['media'])) { if ($r_json) { System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); } - DI::page()->logRuntime(); - exit(); + System::exit(); } $src = ''; @@ -150,8 +148,7 @@ function wall_upload_post(App $a, $desktopmode = true) System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); } notice(DI::l10n()->t('Invalid request.')); - DI::page()->logRuntime(); - exit(); + System::exit(); } $filetype = Images::getMimeTypeBySource($src, $filename, $filetype); @@ -170,8 +167,7 @@ function wall_upload_post(App $a, $desktopmode = true) } else { echo $msg. EOL; } - DI::page()->logRuntime(); - exit(); + System::exit(); } $Image->orient($src); @@ -209,8 +205,7 @@ function wall_upload_post(App $a, $desktopmode = true) } else { echo $msg. EOL; } - DI::page()->logRuntime(); - exit(); + System::exit(); } } @@ -234,8 +229,7 @@ function wall_upload_post(App $a, $desktopmode = true) } else { echo $msg. EOL; } - DI::page()->logRuntime(); - exit(); + System::exit(); } if ($width > 640 || $height > 640) { @@ -287,7 +281,6 @@ function wall_upload_post(App $a, $desktopmode = true) } echo "\n\n" . '[url=' . DI::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $resource_id . '][img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$Image->getExt()."[/img][/url]\n\n"; - DI::page()->logRuntime(); - exit(); + System::exit(); // NOTREACHED } diff --git a/src/App.php b/src/App.php index d85de3670..07296cecf 100644 --- a/src/App.php +++ b/src/App.php @@ -713,13 +713,13 @@ class App $this->profiler->set(microtime(true) - $timestamp, 'content'); if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) { $page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig); - $page->logRuntime(); } else { $page->exit($response); } } catch (HTTPException $e) { (new ModuleHTTPException())->rawContent($e); } + $page->logRuntime(); } /** diff --git a/src/App/Page.php b/src/App/Page.php index 16c4934e3..305b2962b 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -419,7 +419,6 @@ class Page implements ArrayAccess } echo $response->getBody(); - $this->logRuntime(); } /** diff --git a/src/Core/System.php b/src/Core/System.php index 7b0a887cd..10fc5c7d4 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -295,7 +295,7 @@ class System DI::apiResponse()->addContent(XML::fromArray(["result" => $result], $xml)); DI::page()->exit(DI::apiResponse()->generate()); - exit(); + self::exit(); } /** @@ -315,7 +315,7 @@ class System DI::apiResponse()->addContent($content); DI::page()->exit(DI::apiResponse()->generate()); - exit(); + self::exit(); } /** @@ -331,7 +331,8 @@ class System DI::apiResponse()->setType($responce, $content_type); DI::apiResponse()->addContent($content); DI::page()->exit(DI::apiResponse()->generate()); - exit(); + + self::exit(); } public static function jsonError($httpCode, $content, $content_type = 'application/json') @@ -359,6 +360,16 @@ class System DI::apiResponse()->setType(Response::TYPE_JSON, $content_type); DI::apiResponse()->addContent(json_encode($content, $options)); DI::page()->exit(DI::apiResponse()->generate()); + + self::exit(); + } + + /** + * Exit the program execution. + */ + public static function exit() + { + DI::page()->logRuntime(); exit(); } @@ -448,8 +459,7 @@ class System case 307: throw new TemporaryRedirectException(); } - DI::page()->logRuntime(); - exit(); + self::exit(); } /** @@ -522,8 +532,7 @@ class System echo str_replace("\t", " ", $o); echo ""; echo "\r\n"; - DI::page()->logRuntime(); - exit(); + self::exit(); } /** diff --git a/src/Module/Admin/PhpInfo.php b/src/Module/Admin/PhpInfo.php index feaa9de23..c51ed27c0 100644 --- a/src/Module/Admin/PhpInfo.php +++ b/src/Module/Admin/PhpInfo.php @@ -21,7 +21,7 @@ namespace Friendica\Module\Admin; -use Friendica\DI; +use Friendica\Core\System; use Friendica\Module\BaseAdmin; class PhpInfo extends BaseAdmin @@ -31,7 +31,6 @@ class PhpInfo extends BaseAdmin self::checkAdminAccess(); phpinfo(); - DI::page()->logRuntime(); - exit(); + System::exit(); } } diff --git a/src/Module/Attach.php b/src/Module/Attach.php index fc7ba74d5..a73beb2b8 100644 --- a/src/Module/Attach.php +++ b/src/Module/Attach.php @@ -23,6 +23,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\Logger; +use Friendica\Core\System; use Friendica\DI; use Friendica\Model\Attach as MAttach; @@ -72,8 +73,7 @@ class Attach extends BaseModule } echo $data; - DI::page()->logRuntime(); - exit(); + System::exit(); // NOTREACHED } } diff --git a/src/Module/Contact/Hovercard.php b/src/Module/Contact/Hovercard.php index 2bf6f63ed..440c46c50 100644 --- a/src/Module/Contact/Hovercard.php +++ b/src/Module/Contact/Hovercard.php @@ -24,6 +24,7 @@ namespace Friendica\Module\Contact; use Friendica\BaseModule; use Friendica\Core\Renderer; use Friendica\Core\Session; +use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -107,7 +108,6 @@ class Hovercard extends BaseModule ]); echo $o; - DI::page()->logRuntime(); - exit(); + System::exit(); } } diff --git a/src/Module/Debug/ItemBody.php b/src/Module/Debug/ItemBody.php index e066e7656..a9a3c0b50 100644 --- a/src/Module/Debug/ItemBody.php +++ b/src/Module/Debug/ItemBody.php @@ -22,6 +22,7 @@ namespace Friendica\Module\Debug; use Friendica\BaseModule; +use Friendica\Core\System; use Friendica\DI; use Friendica\Model\Post; use Friendica\Network\HTTPException; @@ -48,8 +49,7 @@ class ItemBody extends BaseModule if (!empty($item)) { if (DI::mode()->isAjax()) { echo str_replace("\n", '
', $item['body']); - DI::page()->logRuntime(); - exit(); + System::exit(); } else { return str_replace("\n", '
', $item['body']); } diff --git a/src/Module/Group.php b/src/Module/Group.php index 4825debd0..cd07e9781 100644 --- a/src/Module/Group.php +++ b/src/Module/Group.php @@ -360,8 +360,7 @@ class Group extends BaseModule if ($change) { $tpl = Renderer::getMarkupTemplate('groupeditor.tpl'); echo Renderer::replaceMacros($tpl, $context); - DI::page()->logRuntime(); - exit(); + System::exit(); } return Renderer::replaceMacros($tpl, $context); diff --git a/src/Module/HTTPException/PageNotFound.php b/src/Module/HTTPException/PageNotFound.php index ba34df854..4cfa35276 100644 --- a/src/Module/HTTPException/PageNotFound.php +++ b/src/Module/HTTPException/PageNotFound.php @@ -22,6 +22,7 @@ namespace Friendica\Module\HTTPException; use Friendica\BaseModule; +use Friendica\Core\System; use Friendica\DI; use Friendica\Network\HTTPException; use Psr\Http\Message\ResponseInterface; @@ -47,8 +48,7 @@ class PageNotFound extends BaseModule $queryString = $this->server['QUERY_STRING']; // Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit. if (!empty($queryString) && preg_match('/{[0-9]}/', $queryString) !== 0) { - DI::page()->logRuntime(); - exit(); + System::exit(); } if (!empty($queryString) && ($queryString === 'q=internal_error.html') && isset($dreamhost_error_hack)) { diff --git a/src/Module/Oembed.php b/src/Module/Oembed.php index 49b479204..be8168271 100644 --- a/src/Module/Oembed.php +++ b/src/Module/Oembed.php @@ -23,6 +23,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Content; +use Friendica\Core\System; use Friendica\DI; use Friendica\Util\Strings; @@ -43,16 +44,14 @@ class Oembed extends BaseModule if (DI::args()->getArgv()[1] == 'b2h') { $url = ["", trim(hex2bin($_REQUEST['url']))]; echo Content\OEmbed::replaceCallback($url); - DI::page()->logRuntime(); - exit(); + System::exit(); } // Unused form: /oembed/h2b?text=... if (DI::args()->getArgv()[1] == 'h2b') { $text = trim(hex2bin($_REQUEST['text'])); echo Content\OEmbed::HTML2BBCode($text); - DI::page()->logRuntime(); - exit(); + System::exit(); } // @TODO: Replace with parameter from router @@ -70,7 +69,6 @@ class Oembed extends BaseModule echo $j->html; echo ''; } - DI::page()->logRuntime(); - exit(); + System::exit(); } } diff --git a/src/Module/PermissionTooltip.php b/src/Module/PermissionTooltip.php index edc839a38..07faa72e3 100644 --- a/src/Module/PermissionTooltip.php +++ b/src/Module/PermissionTooltip.php @@ -22,6 +22,7 @@ namespace Friendica\Module; use Friendica\Core\Hook; +use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\APContact; @@ -164,8 +165,7 @@ class PermissionTooltip extends \Friendica\BaseModule } else { echo $o . $receivers; } - DI::page()->logRuntime(); - exit(); + System::exit(); } /** diff --git a/src/Module/Photo.php b/src/Module/Photo.php index d050188aa..134cade65 100644 --- a/src/Module/Photo.php +++ b/src/Module/Photo.php @@ -32,6 +32,7 @@ use Friendica\Model\Post; use Friendica\Model\Profile; use Friendica\Core\Storage\Type\ExternalResource; use Friendica\Core\Storage\Type\SystemResource; +use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Model\User; use Friendica\Network\HTTPClient\Client\HttpClientAccept; @@ -224,8 +225,7 @@ class Photo extends BaseModule 'output' => number_format($output, 3), 'rest' => number_format($rest, 3)]); } - DI::page()->logRuntime(); - exit(); + System::exit(); } private static function getPhotoByid(int $id, $type, $customsize) diff --git a/src/Module/Proxy.php b/src/Module/Proxy.php index 0af49762e..90f118580 100644 --- a/src/Module/Proxy.php +++ b/src/Module/Proxy.php @@ -202,7 +202,6 @@ class Proxy extends BaseModule header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (31536000)) . ' GMT'); header('Cache-Control: max-age=31536000'); echo $img->asString(); - DI::page()->logRuntime(); - exit(); + System::exit(); } } diff --git a/src/Module/RobotsTxt.php b/src/Module/RobotsTxt.php index afc8ebf8f..3651382a0 100644 --- a/src/Module/RobotsTxt.php +++ b/src/Module/RobotsTxt.php @@ -22,7 +22,7 @@ namespace Friendica\Module; use Friendica\BaseModule; -use Friendica\DI; +use Friendica\Core\System; /** * Return the default robots.txt @@ -45,7 +45,6 @@ class RobotsTxt extends BaseModule foreach ($allDisalloweds as $disallowed) { echo 'Disallow: ' . $disallowed . PHP_EOL; } - DI::page()->logRuntime(); - exit(); + System::exit(); } } diff --git a/src/Module/Settings/UserExport.php b/src/Module/Settings/UserExport.php index 6af321a0b..2d29f4d64 100644 --- a/src/Module/Settings/UserExport.php +++ b/src/Module/Settings/UserExport.php @@ -23,6 +23,7 @@ namespace Friendica\Module\Settings; use Friendica\Core\Hook; use Friendica\Core\Renderer; +use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\DI; @@ -112,8 +113,7 @@ class UserExport extends BaseSettings self::exportContactsAsCSV(local_user()); break; } - DI::page()->logRuntime(); - exit(); + System::exit(); } } diff --git a/src/Module/Theme.php b/src/Module/Theme.php index 8d14d82da..50a4f6c55 100644 --- a/src/Module/Theme.php +++ b/src/Module/Theme.php @@ -22,7 +22,7 @@ namespace Friendica\Module; use Friendica\BaseModule; -use Friendica\DI; +use Friendica\Core\System; use Friendica\Util\Strings; /** @@ -45,7 +45,6 @@ class Theme extends BaseModule if (file_exists("view/theme/$theme/style.php")) { require_once "view/theme/$theme/style.php"; } - DI::page()->logRuntime(); - exit(); + System::exit(); } } diff --git a/src/Module/ThemeDetails.php b/src/Module/ThemeDetails.php index c69c93b03..cbb9357c0 100644 --- a/src/Module/ThemeDetails.php +++ b/src/Module/ThemeDetails.php @@ -49,7 +49,6 @@ class ThemeDetails extends BaseModule 'credits' => $credits, ]); } - DI::page()->logRuntime(); - exit(); + System::exit(); } } diff --git a/src/Module/Update/Network.php b/src/Module/Update/Network.php index 2b71d23c4..6282028e6 100644 --- a/src/Module/Update/Network.php +++ b/src/Module/Update/Network.php @@ -31,8 +31,7 @@ class Network extends NetworkModule protected function rawContent(array $request = []) { if (!isset($_GET['p']) || !isset($_GET['item'])) { - DI::page()->logRuntime(); - exit(); + System::exit(); } $this->parseRequest($_GET); diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index c2271565c..732b4b985 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -24,6 +24,7 @@ namespace Friendica\Util; use Friendica\Core\Cache\Enum\Duration; use Friendica\Core\Logger; use Exception; +use Friendica\Core\System; use Friendica\DI; /** @@ -69,8 +70,7 @@ class JsonLD if ($recursion > 5) { Logger::error('jsonld bomb detected at: ' . $url); - DI::page()->logRuntime(); - exit(); + System::exit(); } $result = DI::cache()->get('documentLoader:' . $url); From 2e6e3597e5e9dfe89327d8c0109ad9066f25ae8a Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 18 May 2022 02:19:45 +0000 Subject: [PATCH 5/5] unused DI" removed --- src/Module/ThemeDetails.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Module/ThemeDetails.php b/src/Module/ThemeDetails.php index cbb9357c0..1b12f3e37 100644 --- a/src/Module/ThemeDetails.php +++ b/src/Module/ThemeDetails.php @@ -24,7 +24,6 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\System; use Friendica\Core\Theme; -use Friendica\DI; /** * Prints theme specific details as a JSON string