Last active
November 6, 2017 15:58
-
-
Save sualko/a097036c28ecc0533fa3 to your computer and use it in GitHub Desktop.
Typo3 Neos Plugin to retrieve and display last Facebook post from given fb-pageid.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// YOUR_PACKAGE/Classes/YOUR_NAMESPACE/Controller/FacebookController.php | |
namespace YOUR_NAMESPACE\Controller; | |
use TYPO3\Flow\Annotations as Flow; | |
class FacebookController extends \TYPO3\Flow\Mvc\Controller\ActionController { | |
/** | |
* @Flow\Inject | |
* @var \TYPO3\Flow\Resource\ResourceManager | |
*/ | |
protected $resourceManager; | |
/** | |
* @Flow\InjectConfiguration(path="facebook") | |
* @var array | |
*/ | |
protected $fb = array(); | |
/** | |
* @return void | |
*/ | |
public function indexAction() { | |
$fb = $this->fb; | |
$postsUrl = 'https://graph.facebook.com/'.$fb['pageid'].'/posts?access_token='.$fb['token'].'&limit='.$fb['limit']; | |
//$attachmentsUrl = 'https://graph.facebook.com/v2.1/POST_ID/attachments'; | |
$response = file_get_contents($postsUrl); | |
$json = json_decode($response); | |
if ($json !== null) { | |
$post = $json->data[0]; | |
$this->view->assign('message', $post->message); | |
$this->view->assign('link', $post->link); | |
$this->view->assign('actions', $post->actions); | |
$this->view->assign('created_time', $post->created_time); | |
$this->view->assign('likes_count', count($post->likes->data)); | |
$this->view->assign('likes', $post->likes->data); | |
$newResource = $this->resourceManager->importResource($post->picture); | |
$image = new \TYPO3\Media\Domain\Model\Image($newResource); | |
// Allow image to be persisted even if this is a "safe" HTTP request: | |
$this->persistenceManager->whiteListObject($image); | |
$this->persistenceManager->whiteListObject($image->getResource()); | |
$this->view->assign('image', $image); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prototype(YOUR_PACKAGE:FacebookPost) < prototype(TYPO3.Neos:Plugin) { | |
package = 'YOUR_PACKAGE' | |
controller = 'Facebook' | |
action = 'index' | |
@cache { | |
mode = 'cached' | |
maximumLifetime = '3600' | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{namespace media=TYPO3\Media\ViewHelpers} | |
<!-- YOUR_PACKAGE/Resources/Private/Templates/Facebook/Index.html --> | |
<div class="fb-post"> | |
<div class="fb-body"> | |
<f:if condition="{image}"> | |
<figure> | |
<media:image image="{image}" alt="Facebook Image" /> | |
</figure> | |
</f:if> | |
<p>{message}</p> | |
</div> | |
<div class="fb-meta"> | |
<p>{likes_count} people like that.</p> | |
<p><f:for each="{actions}" as="action" iteration="iterator"> | |
<a class="{action.name}" href="{action.link}" target="_blank">{action.label}</a> | |
</f:for></p> | |
<p><a class="Facebook" href="{link}" target="_blank">Read on Facebook</a></p> | |
<p>{created_time -> f:format.date(format: 'j. M Y, H:i')}</p> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'YOUR_PACKAGE:FacebookPost': | |
superTypes: | |
'TYPO3.Neos:Plugin': TRUE | |
ui: | |
label: 'Facebook Post' | |
group: 'plugins' | |
icon: 'icon-facebook-sign' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YOUR_PACKAGE: | |
facebook: | |
pageid: 'YOUR_PAGEID' | |
toke: 'YOUR_PAGE_TOKEN' | |
limit: '1' |
For reference: https://discuss.neos.io/t/show-last-facebook-post-plugin/472
@dfeyer is there a way to display settings in the nodetype? Maybe as placeholder? This would be great from ux perspective. One more thing I would like to add would be a option to show the second, third, ... last post.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My two cents, maybe the pageid can be configurable in the NodeType for more flexibility. By default, use the setting, or the node property if not empty.