Skip to content

Commit

Permalink
Merge pull request #14 from lgescobar/feature/include-retweets-and-ov…
Browse files Browse the repository at this point in the history
…erride-flexform-settings

[TASK] #12 Allow to override FlexForm settings & fix include_rts value
  • Loading branch information
lgescobar authored Sep 5, 2018
2 parents cf6a32e + 5247ef9 commit 63be35b
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 3 deletions.
74 changes: 74 additions & 0 deletions Classes/Controller/TweetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
use CW\CwTwitter\Exception\ConfigurationException;
use CW\CwTwitter\Exception\RequestException;
use CW\CwTwitter\Utility\Twitter;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;

Expand All @@ -40,6 +43,19 @@
*/
class TweetController extends ActionController
{
/**
* @var \TYPO3\CMS\Core\TypoScript\TypoScriptService
*/
protected $typoScriptService;

/**
* @param \TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService
*/
public function injectTypoScriptService(TypoScriptService $typoScriptService)
{
$this->typoScriptService = $typoScriptService;
}

/**
* @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view
* @return void
Expand All @@ -49,8 +65,28 @@ protected function initializeView(ViewInterface $view)
$view->assign('contentObjectData', $this->configurationManager->getContentObject()->data);
}

/**
* Override defined settings before calling action methods.
*
* @return void
*/
public function initializeAction()
{
if (!empty($this->settings['overrideFlexformSettings'])) {
$typoScriptSettings = $this->getTypoScriptSettings();
$keysToOverride = GeneralUtility::trimExplode(',', $this->settings['overrideFlexformSettings'], true);

foreach ($keysToOverride as $keyToOverride) {
if (isset($typoScriptSettings[$keyToOverride])) {
$this->settings[$keyToOverride] = $typoScriptSettings[$keyToOverride];
}
}
}
}

/**
* List tweets
*
* @throws \OAuthException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
Expand All @@ -69,4 +105,42 @@ public function listAction()
$this->view->assign('error', $e);
}
}

/**
* Helper method to get the plugin settings not overridden by FlexForm settings.
*
* @see \TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::getPluginConfiguration()
*
* @return array
*/
protected function getTypoScriptSettings()
{
$extensionName = $this->extensionName;
$pluginName = $this->request->getPluginName();
$pluginSettings = [];

$setup = $this->configurationManager->getConfiguration(
ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
);

if (is_array($setup['plugin.']['tx_' . strtolower($extensionName) . '.']['settings.'])) {
$pluginSettings = $this->typoScriptService->convertTypoScriptArrayToPlainArray(
$setup['plugin.']['tx_' . strtolower($extensionName) . '.']['settings.']
);
}

if ($pluginName !== null) {
$pluginSignature = strtolower($extensionName . '_' . $pluginName);
if (is_array($setup['plugin.']['tx_' . $pluginSignature . '.']['settings.'])) {
ArrayUtility::mergeRecursiveWithOverrule(
$pluginSettings,
$this->typoScriptService->convertTypoScriptArrayToPlainArray(
$setup['plugin.']['tx_' . $pluginSignature . '.']['settings.']
)
);
}
}

return $pluginSettings;
}
}
3 changes: 1 addition & 2 deletions Classes/Utility/Twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function getTweetsFromTimeline(
) {
$params = [
'exclude_replies' => $exclude_replies ? 'true' : 'false',
'include_rts' => $include_rts ? 'true' : 'false',
];

if ($extended_tweet_mode) {
Expand All @@ -207,8 +208,6 @@ public function getTweetsFromTimeline(
$params['count'] = $limit;
}

$params['include_rts'] = $include_rts;

$tweets = $this->getData('statuses/user_timeline', $params);
if ($enhanced_privacy) {
$this->saveTweetPicturesLocally($tweets);
Expand Down
11 changes: 11 additions & 0 deletions Configuration/FlexForms/TwitterFeed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@
</config>
</TCEforms>
</settings.exclude_replies>

<settings.include_rts>
<TCEforms>
<label>LLL:EXT:cw_twitter/Resources/Private/Language/locallang.xlf:flexform.settings.include_rts</label>
<displayCond>FIELD:settings.mode:=:timeline</displayCond>
<config>
<type>check</type>
<default>1</default>
</config>
</TCEforms>
</settings.include_rts>
</el>
</ROOT>
</sDEF>
Expand Down
2 changes: 1 addition & 1 deletion Configuration/TypoScript/constants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ plugin.tx_cwtwitter {
enhanced_privacy = 0
# cat=plugin.tx_cwtwitter; type=boolean; label=Enable extended tweet mode (up to 280 chars)
extended_tweet_mode = 1
# cat=plugin.tx_cwtwitter; type=boolean; label=Include retweets
# cat=plugin.tx_cwtwitter; type=boolean; label=Include retweets in timeline
include_rts = 1
}
}
4 changes: 4 additions & 0 deletions Configuration/TypoScript/setup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ plugin.tx_cwtwitter {
enhanced_privacy = {$plugin.tx_cwtwitter.settings.enhanced_privacy}
extended_tweet_mode = {$plugin.tx_cwtwitter.settings.extended_tweet_mode}
include_rts = {$plugin.tx_cwtwitter.settings.include_rts}

# Use it to override FlexForm settings. (Comma-separated list of keys)
# Possible keys are: mode, username, query, limit, exclude_replies and include_rts
overrideFlexformSettings =
}

parsers {
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<trans-unit id="flexform.settings.exclude_replies">
<source>Exclude replies</source>
</trans-unit>
<trans-unit id="flexform.settings.include_rts">
<source>Include retweets</source>
</trans-unit>
<trans-unit id="tweetlist.empty">
<source>No (recent) tweets found</source>
</trans-unit>
Expand Down

0 comments on commit 63be35b

Please sign in to comment.