Skip to content

Commit

Permalink
Merge pull request #114 from TYPO3incubator/bugfix/file-get-contents-…
Browse files Browse the repository at this point in the history
…htaccess

Bugfix/file get contents htaccess
  • Loading branch information
pixeldesu authored Apr 12, 2024
2 parents 34714e5 + 3308c4e commit 239a75b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .env.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
TYPO3_BE_INSTALLTOOLPASSWORD="$argon2id$v=19$m=65536,t=16,p=1$VktrT0J2cXU3SHNtY0c4SA$36zwyPIHD9iUteTlw04ft6NYYmhVA9FtzkR5py/5B0w" # John3:16
TYPO3_DB_CONNECTIONS_DEFAULT_DBNAME="db"
TYPO3_DB_CONNECTIONS_DEFAULT_HOST="db"
TYPO3_DB_CONNECTIONS_DEFAULT_PASSWORD="db"
TYPO3_DB_CONNECTIONS_DEFAULT_PORT=3306
TYPO3_DB_CONNECTIONS_DEFAULT_USER="db"
TYPO3_MAIL_DEFAULTMAILFROMADDRESS="noreply@localhost"
TYPO3_MAIL_DEFAULTMAILFROMNAME="TYPO3 Surfcamp"
TYPO3_MAIL_TRANSPORT="sendmail"
TYPO3_MAIL_TRANSPORT_SENDMAIL_COMMAND="/usr/local/bin/mailpit sendmail -t --smtp-addr 127.0.0.1:1025"
TYPO3_MAIL_TRANSPORT_SMTP_ENCRYPT=""
TYPO3_MAIL_TRANSPORT_SMTP_PASSWORD=""
TYPO3_MAIL_TRANSPORT_SMTP_SERVER=""
TYPO3_MAIL_TRANSPORT_SMTP_USERNAME=""
TYPO3_MAIL_TRANSPORT_MBOX_FILE=""
TYPO3_SYS_ENCRYPTIONKEY="c26bc4ffae86d01188fe2ff0e9b5061cf81f612d3acdb41a261e035862d0510d4eea24dbce58d7041f7b6aa090346d41"
HTTP_BASIC_AUTH_USER="surfcamp"
HTTP_BASIC_AUTH_PWD="fuerteventura2024"
7 changes: 7 additions & 0 deletions config/system/additional.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
$dotenv->load();
}

if (\TYPO3\CMS\Core\Core\Environment::getContext() == 'Production') {
$dotenv = Dotenv\Dotenv::createMutable(__DIR__ . '/../../', '.env.prod');
$dotenv->load();
}

$GLOBALS['TYPO3_CONF_VARS'] = array_replace_recursive($GLOBALS['TYPO3_CONF_VARS'], [
'BE' => [
'debug' => $_ENV['TYPO3_BE_DEBUG'] ?? 0,
Expand Down Expand Up @@ -43,5 +48,7 @@
'displayErrors' => $_ENV['TYPO3_SYS_DISPLAYERRORS'] ?? 0,
'encryptionKey' => $_ENV['TYPO3_SYS_ENCRYPTIONKEY'],
'exceptionalErrors' => $_ENV['TYPO3_SYS_EXCEPTIONALERRORS'] ?? 4096,
'http_basic_auth_user' => $_ENV['HTTP_BASIC_AUTH_USER'] ?? '',
'http_basic_auth_pwd' => $_ENV['HTTP_BASIC_AUTH_PWD'] ?? '',
],
]);
41 changes: 40 additions & 1 deletion local_packages/football/Classes/DataProcessing/JsonProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace SurfcampTeam4\Football\DataProcessing;

use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
Expand All @@ -17,6 +18,17 @@
*/
class JsonProcessor implements DataProcessorInterface
{
/**
* @var RequestFactory
*/
private RequestFactory $requestFactory;

public function __construct(
RequestFactory $requestFactory,
) {
$this->requestFactory = $requestFactory;
}

/**
* @param ContentObjectRenderer $cObj
* @param array $contentObjectConfiguration
Expand Down Expand Up @@ -53,8 +65,35 @@ public function process(
}

$targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'jsonData');
$content = file_get_contents($jsonFileUrl);
if (
isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['http_basic_auth_user'])
&& $GLOBALS['TYPO3_CONF_VARS']['SYS']['http_basic_auth_pwd']
) {
$credentials = base64_encode(
$GLOBALS['TYPO3_CONF_VARS']['SYS']['http_basic_auth_user']
. ':' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['http_basic_auth_pwd']
);
try {
$response = $this->requestFactory->request(
$jsonFileUrl,
'GET',
[
'headers' => ['Authorization' => 'Basic ' . $credentials]
]
);
$content = $response->getBody()->getContents();
} catch (\Exception $e) {
$content = false;
}
}

if ($content === false) {
return $processedData;
}

// get the jsonData as array and put it in the processedData
$processedData[$targetVariableName] = json_decode(file_get_contents($jsonFileUrl), true);
$processedData[$targetVariableName] = json_decode($content, true);
}

return $processedData;
Expand Down

0 comments on commit 239a75b

Please sign in to comment.