Skip to content

Commit

Permalink
Merge pull request #1321 from hydephp/fix-rss-feed-generator-not-resp…
Browse files Browse the repository at this point in the history
…ecting-the-no-api-flag

Update FeaturedImage class to only make API calls when not disabled
  • Loading branch information
caendesilva authored Mar 17, 2023
2 parents 481eda1 + 2df51ca commit 6ba776d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This release is the first since the official release of HydePHP 1.0.0. It contai
- Fixed https://github.com/hydephp/develop/issues/1313 in https://github.com/hydephp/develop/commit/134776a1e4af395dab5c15d611fc64c9ebce8596
- Fixed https://github.com/hydephp/develop/issues/1316 in https://github.com/hydephp/develop/pull/1317
- Fixed https://github.com/hydephp/develop/issues/1318 in https://github.com/hydephp/develop/pull/1319
- Fixed https://github.com/hydephp/develop/issues/1320 in https://github.com/hydephp/develop/pull/1321
- Added missing function imports in https://github.com/hydephp/develop/pull/1309

### Security
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Hyde\Framework\Exceptions\FileNotFoundException;
use Hyde\Markdown\Contracts\FrontMatter\SubSchemas\FeaturedImageSchema;

use function in_array;
use function array_key_exists;
use function array_flip;
use function file_exists;
Expand Down Expand Up @@ -224,15 +225,20 @@ protected function getContentLengthForLocalImage(): int

protected function getContentLengthForRemoteImage(): int
{
$headers = Http::withHeaders([
'User-Agent' => Config::getString('hyde.http_user_agent', 'RSS Request Client'),
])->head($this->getSource())->headers();
// TODO: We may want to globalize this check in the config, but for now,
// we just check the server arguments and skip remote requests if
// the --no-api flag is present (in the build command call)
if (! (isset($_SERVER['argv']) && in_array('--no-api', $_SERVER['argv'], true))) {
$headers = Http::withHeaders([
'User-Agent' => Config::getString('hyde.http_user_agent', 'RSS Request Client'),
])->head($this->getSource())->headers();

if (array_key_exists('Content-Length', $headers)) {
return (int) key(array_flip($headers['Content-Length']));
}
if (array_key_exists('Content-Length', $headers)) {
return (int) key(array_flip($headers['Content-Length']));
}

BuildWarnings::report('The image "'.$this->getSource().'" has a content length of zero.');
BuildWarnings::report('The image "'.$this->getSource().'" has a content length of zero.');
}

return 0;
}
Expand Down

0 comments on commit 6ba776d

Please sign in to comment.