Skip to content

Commit

Permalink
Fixed debug errors
Browse files Browse the repository at this point in the history
Added new redirect URL to a working redirect script
  • Loading branch information
hschottm committed Jul 27, 2022
1 parent 6211e2c commit c4cdcb3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
26 changes: 20 additions & 6 deletions src/Resources/contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,32 @@ public function __construct()

public function checkConfig()
{
if ((!$GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token']) ||
(!$GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token_secret']) ||
(!$GLOBALS['TL_CONFIG']['twitterreader_credentials_user_id']) ||
(!$GLOBALS['TL_CONFIG']['twitterreader_credentials_screen_name'])
) {
$oauth_token = "";
$oauth_secret = "";
$twitter_user_id = "";
$twitter_screen_name = "";

if (array_key_exists('twitterreader_credentials_oauth_token', $GLOBALS['TL_CONFIG'])) {
$oauth_token = $GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token'];
}
if (array_key_exists('twitterreader_credentials_oauth_token_secret', $GLOBALS['TL_CONFIG'])) {
$oauth_secret = $GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token_secret'];
}
if (array_key_exists('twitterreader_credentials_user_id', $GLOBALS['TL_CONFIG'])) {
$twitter_user_id = $GLOBALS['TL_CONFIG']['twitterreader_credentials_user_id'];
}
if (array_key_exists('twitterreader_credentials_screen_name', $GLOBALS['TL_CONFIG'])) {
$twitter_screen_name = $GLOBALS['TL_CONFIG']['twitterreader_credentials_screen_name'];
}

if (strlen($oauth_token) == 0 || strlen($oauth_secret) == 0 || strlen($twitter_user_id) == 0 || strlen($twitter_screen_name) == 0) {
$_SESSION['TL_ERROR'][] = $GLOBALS['TL_LANG']['tl_module']['twitterreader_auth_missing'];
}
}

public function getTwitterTemplates(DataContainer $dc)
{
return $this->getTemplateGroup('twitterreader_', $dc->activeRecord->pid);
return \Controller::getTemplateGroup('twitterreader_');
}

public function purgeCacheData($field, DataContainer $dc)
Expand Down
14 changes: 12 additions & 2 deletions src/Resources/contao/modules/FrontendTwitterReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function generate()
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = $this->Environment->script.'?do=themes&table=tl_module&act=edit&id='.$this->id;
$objTemplate->href = \Environment::script.'?do=themes&table=tl_module&act=edit&id='.$this->id;

return $objTemplate->parse();
}
Expand All @@ -63,8 +63,18 @@ protected function compile()
// check only, if last check is longer than 1 minute old.
$actualTime = time();

$oauth_token = "";
$oauth_secret = "";

if (array_key_exists('twitterreader_credentials_oauth_token', $GLOBALS['TL_CONFIG'])) {
$oauth_token = $GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token'];
}
if (array_key_exists('twitterreader_credentials_oauth_token_secret', $GLOBALS['TL_CONFIG'])) {
$oauth_secret = $GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token_secret'];
}

if ((($actualTime - $moduleModel->twitterLastUpdate) > $UpdateRange) || (!\is_array($objFeed))) {
$oauth = new TwitterOAuth(TwitterUtil::TwitterReaderConsumerKey(), TwitterUtil::TwitterReaderConsumerSecret(), $GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token'], $GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token_secret']);
$oauth = new TwitterOAuth(TwitterUtil::TwitterReaderConsumerKey(), TwitterUtil::TwitterReaderConsumerSecret(), $oauth_token, $oauth_secret);
$arrFeed = [
'include_entities' => true,
'count' => $this->twittercount,
Expand Down
28 changes: 19 additions & 9 deletions src/Resources/contao/widgets/WidgetTwitterOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,27 @@ public function generate()
} elseif ('TwitterReaderOAuthRevoke' === \Input::get('action')) {
$this->revokeTwitterOAuth();
}
if (\Input::get('oauth_verifyer')) {
if (strlen(\Input::get('oauth_verifier'))) {
$this->verifyTwitterOAuth();
}

if ($GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token']) {
$oauth_token = "";
$oauth_secret = "";

if (array_key_exists('twitterreader_credentials_oauth_token', $GLOBALS['TL_CONFIG'])) {
$oauth_token = $GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token'];
}
if (array_key_exists('twitterreader_credentials_oauth_token_secret', $GLOBALS['TL_CONFIG'])) {
$oauth_secret = $GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token_secret'];
}

$sWizard = '';
if (strlen($oauth_token)) {
$connection = new TwitterOAuth(TwitterUtil::TwitterReaderConsumerKey(), TwitterUtil::TwitterReaderConsumerSecret(),
$GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token'],
$GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token_secret']);
$oauth_token,
$oauth_secret);
$objAuth = $connection->get('account/verify_credentials');

if ($objAuth->error) {
if ($objAuth == null) {
$sWizard .= $objAuth->error.'<br>';
} else {
$sWizard .= '<p>'.$GLOBALS['TL_LANG']['tl_settings']['twitterreader_authenticated_as'].':</p>';
Expand Down Expand Up @@ -173,7 +183,7 @@ protected function requestTwitterOAuth()
$connection = new TwitterOAuth(TwitterUtil::TwitterReaderConsumerKey(), TwitterUtil::TwitterReaderConsumerSecret());
$urlRequest = preg_replace('/&action=TwitterReaderOAuthCheck/i', '', \Environment::get('request'));

$request_token = $connection->oauth('oauth/request_token', ['oauth_callback' => 'https://www.aurealis.de/contao-twitterreader-redirect.php?redirectUrl='.TwitterUtil::base64url_encode(\Environment::get('base').$urlRequest)]);
$request_token = $connection->oauth('oauth/request_token', ['oauth_callback' => 'https://opensource.nasbrill-soft.de/contao-twitterreader-redirect.php?redirectUrl='.TwitterUtil::base64url_encode(\Environment::get('base').$urlRequest)]);

$this->Config->update("\$GLOBALS['TL_CONFIG']['twitterreader_oauth_token']", $request_token['oauth_token']);
$this->Config->update("\$GLOBALS['TL_CONFIG']['twitterreader_oauth_token_secret']", $request_token['oauth_token_secret']);
Expand All @@ -192,14 +202,14 @@ protected function verifyTwitterOAuth()
$GLOBALS['TL_CONFIG']['twitterreader_oauth_token'],
$GLOBALS['TL_CONFIG']['twitterreader_oauth_token_secret']);

$arrAccessToken = $connection->oauth('oauth/access_token', ['oauth_verifier' => \Input::get('oauth_verifyer')]);
$arrAccessToken = $connection->oauth("oauth/access_token", ["oauth_verifier" => \Input::get('oauth_verifier')]);

$this->Config->update("\$GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token']", $arrAccessToken['oauth_token']);
$this->Config->update("\$GLOBALS['TL_CONFIG']['twitterreader_credentials_oauth_token_secret']", $arrAccessToken['oauth_token_secret']);
$this->Config->update("\$GLOBALS['TL_CONFIG']['twitterreader_credentials_user_id']", $arrAccessToken['user_id']);
$this->Config->update("\$GLOBALS['TL_CONFIG']['twitterreader_credentials_screen_name']", $arrAccessToken['screen_name']);

$urlRequest = preg_replace('/(&(amp;)?|\?)oauth_verifyer=[^& ]*/i', '', \Environment::get('request'));
$urlRequest = preg_replace('/(&(amp;)?|\?)oauth_verifier=[^& ]*/i', '', \Environment::get('request'));
$urlRequest = preg_replace('/(&(amp;)?|\?)oauth_token=[^& ]*/i', '', $urlRequest);

$this->redirect($urlRequest);
Expand Down

0 comments on commit c4cdcb3

Please sign in to comment.