@ -0,0 +1,21 @@ | |||
The MIT License (MIT) | |||
Copyright (c) 2014 Maxim Hodyrev | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all | |||
copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
SOFTWARE. |
@ -0,0 +1,63 @@ | |||
Twitter timeline display plugin for [Grav CMS](http://getgrav.org) | |||
------------------------------------------------- | |||
This plugin dislay twitter timeline une a div. | |||
## Working example | |||
This `.md` page source: | |||
``` | |||
--- | |||
title: home | |||
twitty: true | |||
twittyUsername: mytweetername | |||
------------ | |||
## My page | |||
Bla bla bla and below my twitter : | |||
TWITTYTEXT | |||
blablabla | |||
``` | |||
twitty: true => enalbe plugin for this page | |||
twittyUsername: mytweetername => twitterusername | |||
TWITTYTEXT will be replaced by my timeline, simple but working | |||
## Installation | |||
Git clone and put in `/your/site/grav/user/plugins/twitty' folder | |||
## Configuration | |||
All configuration rules located in `twitty.yaml` | |||
You can just disable/enable plugin by changing `enabled` option, example: | |||
enabled: true # enabled: false for disable | |||
## License | |||
The MIT License (MIT) | |||
Copyright (c) 2014 Maxim Hodyrev | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all | |||
copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
SOFTWARE. |
@ -0,0 +1,23 @@ | |||
name: Twitty | |||
version: 1.0 | |||
description: Display twitter timeline in a div | |||
author: | |||
name: tmator | |||
email: tmator@gmail.com | |||
homepage: https://git.tetalab.org:8888/tetalab/twitty | |||
keywords: twitter, embed | |||
bugs: https://git.tetalab.org:8888/tetalab/twitty/issues | |||
license: MIT | |||
form: | |||
fields: | |||
enabled: | |||
type: toggle | |||
label: Plugin status | |||
highlight: 1 | |||
default: 0 | |||
options: | |||
1: Enabled | |||
0: Disabled | |||
validate: | |||
type: bool |
@ -0,0 +1,66 @@ | |||
<?php | |||
namespace Grav\Plugin; | |||
use Grav\Common\Page\Page; | |||
use Grav\Common\Plugin; | |||
class TwittyPlugin extends Plugin | |||
{ | |||
private $code = '<div class="container" align=center><a class="twitter-timeline" href="https://twitter.com/TWITTYNAME" data-widget-id="542690156990697473">Tweets de @TWITTYNAME</a><script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?"http":"https";if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></div>'; | |||
public static function getSubscribedEvents() | |||
{ | |||
return [ | |||
'onPluginsInitialized' => ['onPluginsInitialized', 0] | |||
]; | |||
} | |||
//public function onPluginsInitialized(Event $event) | |||
public function onPluginsInitialized() | |||
{ | |||
$this->enable([ | |||
'onPageInitialized' => ['onPageInitialized', 0] | |||
]); | |||
} | |||
public function onPageInitialized() | |||
{ | |||
$this->mergeConfig($this->grav['page']); | |||
if ( $this->config->get('plugins.twitty.enabled') ) { | |||
$page = $this->grav['page']; | |||
$twig = $this->grav['twig']; | |||
$uri = $this->grav['uri']; | |||
$options = $this->config->get('plugins.twitty'); | |||
$twittyUsername = $this->config->get('plugins.twitty.twittyUsername'); | |||
//Read page and replace | |||
$page->content($this->processHtml($page,$twittyUsername)); | |||
} | |||
} | |||
private function processHtml($page,$twittyUsername) | |||
{ | |||
$content = $page->content(); | |||
$replace = array('TWITTYTEXT'=>$this->code,'TWITTYNAME'=>$twittyUsername); | |||
return str_replace(array_keys($replace),array_values($replace), $content); | |||
} | |||
private function mergeConfig( Page $page ) | |||
{ | |||
$defaults = (array) $this->config->get('plugins.twitty'); | |||
if ( isset($page->header()->twitty) ) { | |||
$this->config->set('plugins.twitty.enabled', true); | |||
} else { | |||
$this->config->set('plugins.twitty.enabled', false); | |||
} | |||
} | |||
} | |||
?> |
@ -0,0 +1 @@ | |||
enabled: true |