From a96d12602b7dfc7e966b0e6136b323b9adc5d4ee Mon Sep 17 00:00:00 2001 From: root Date: Wed, 10 Dec 2014 16:56:30 +0100 Subject: [PATCH] yeah it's working --- LICENSE | 21 ++++++++++++++++ README.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++ blueprints.yaml | 23 +++++++++++++++++ twitty.php | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ twitty.yaml | 1 + 5 files changed, 174 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 blueprints.yaml create mode 100644 twitty.php create mode 100644 twitty.yaml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..06c40b9 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a069182 --- /dev/null +++ b/README.md @@ -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. diff --git a/blueprints.yaml b/blueprints.yaml new file mode 100644 index 0000000..6e6c683 --- /dev/null +++ b/blueprints.yaml @@ -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 diff --git a/twitty.php b/twitty.php new file mode 100644 index 0000000..19f22f9 --- /dev/null +++ b/twitty.php @@ -0,0 +1,66 @@ +Tweets de @TWITTYNAME'; + + 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); + } + } + +} +?> diff --git a/twitty.yaml b/twitty.yaml new file mode 100644 index 0000000..d4ca941 --- /dev/null +++ b/twitty.yaml @@ -0,0 +1 @@ +enabled: true