plugin:twitter
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:twitter [2013-11-02 02:24] – Klap-in | plugin:twitter [2023-02-17 15:30] (current) – [Twitter Plugin] mprins | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
---- plugin ---- | ---- plugin ---- | ||
- | description: | + | description: |
author | author | ||
- | email : mprins@users.sf.net | + | email : REMOVE.mprins@users.sf.net |
type : syntax | type : syntax | ||
- | lastupdate : 2013-08-23 | + | lastupdate : 2020-11-22 |
- | compatible : Angua, "Adora Belle" Weatherwax | + | compatible : Angua, "Adora Belle" Weatherwax |
depends | depends | ||
conflicts | conflicts | ||
similar | similar | ||
- | tags : embed, listing, users, search, social, twitter | + | tags : embed, listing, users, search, social, twitter, !up_for_adoption, |
+ | screenshot_img: | ||
- | downloadurl: | + | downloadurl: |
+ | bugtracker | ||
sourcerepo : https:// | sourcerepo : https:// | ||
- | bugtracker | + | donationurl: https:// |
---- | ---- | ||
+ | |||
+ | ====== Discontinued ====== | ||
+ | :!: Since I stopped using this plugin some years back this plugin is up for adoption. Ping me if you're interested in maintaining so I can transfer ownership. | ||
===== Description ===== | ===== Description ===== | ||
Line 23: | Line 28: | ||
===== Installation ===== | ===== Installation ===== | ||
- | + | Search and install | |
- | :!: As of 2013-03-08 this requires OAuth credentials | + | |
- | + | ||
- | Install | + | |
After installation you need to [[https:// | After installation you need to [[https:// | ||
Line 32: | Line 34: | ||
===== Purpose ===== | ===== Purpose ===== | ||
- | IF you want to show some tweets from twitter on a DokuWiki page, use this Plugin. The syntax is easy: | + | If you want to show some tweets from twitter on a DokuWiki page, use this Plugin. The syntax is easy: |
< | < | ||
[TWITTER: | [TWITTER: | ||
Line 42: | Line 44: | ||
* **COUNT**: The number of tweets to show, when in user mode. | * **COUNT**: The number of tweets to show, when in user mode. | ||
- | And here comes some valid examples: | + | And here are some valid examples: |
< | < | ||
Line 55: | Line 57: | ||
</ | </ | ||
- | ===== Information===== | ||
- | I created that plugin in around 30 minutes, so it's only a first demo and I personally don't like the look. | ||
- | But at least it's working. I will do some improvements, | ||
- | ===== Installation ===== | ||
- | Save the following code into default.php and copy it into folder: / | ||
- | |||
- | <code php default.php> | ||
- | <?php | ||
- | /** | ||
- | * Options for the Twitter plugin | ||
- | */ | ||
- | $conf[' | ||
- | |||
- | </ | ||
- | |||
- | Save the following code into the following file names given below and copy it into folder: **/ | ||
- | |||
- | <code php action.php> | ||
- | <?php | ||
- | /** | ||
- | * Twitter Plugin | ||
- | * | ||
- | * Action plugin component, for cache validity determination; | ||
- | * | ||
- | * @license | ||
- | * @author | ||
- | */ | ||
- | if(!defined(' | ||
- | |||
- | if(!defined(' | ||
- | require_once(DOKU_PLUGIN.' | ||
- | |||
- | /** | ||
- | * All DokuWiki plugins to extend the parser/ | ||
- | * need to inherit from this class | ||
- | */ | ||
- | class action_plugin_twitter extends DokuWiki_Action_Plugin { | ||
- | |||
- | /** | ||
- | * return some info | ||
- | */ | ||
- | function getInfo(){ | ||
- | return array( | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ); | ||
- | } | ||
- | |||
- | /** | ||
- | * plugin should use this method to register its handlers with the dokuwiki' | ||
- | */ | ||
- | function register(Doku_Event_Handler $controller) { | ||
- | $controller-> | ||
- | } | ||
- | |||
- | /** | ||
- | * prepare the cache object for default _useCache action | ||
- | */ | ||
- | function _cache_prepare(& | ||
- | $cache =& $event-> | ||
- | |||
- | // we're only interested in wiki pages and supported render modes | ||
- | if (!isset($cache-> | ||
- | if (!isset($cache-> | ||
- | |||
- | $max_age = $this-> | ||
- | |||
- | if (is_null($max_age)) return; | ||
- | |||
- | if ($max_age <= 0) { | ||
- | // expire the cache | ||
- | //no cache for twitter! | ||
- | $event-> | ||
- | $event-> | ||
- | $event-> | ||
- | return; | ||
- | } | ||
- | |||
- | $cache-> | ||
- | |||
- | } | ||
- | |||
- | /** | ||
- | * determine the max allowable age of the cache | ||
- | * | ||
- | * @param | ||
- | * | ||
- | * @return | ||
- | | ||
- | */ | ||
- | function _cache_maxage($id) { | ||
- | |||
- | $hasPart = p_get_metadata($id, | ||
- | |||
- | if (empty($hasPart) || !is_array($hasPart)) return null; | ||
- | |||
- | $age = 0; | ||
- | foreach ($hasPart as $file => $data) { | ||
- | if ($file == " | ||
- | { | ||
- | //this is us, outdate the cache if older than the configured seconds | ||
- | return $this-> | ||
- | } | ||
- | } | ||
- | |||
- | return $age ? time()-$age : null; | ||
- | } | ||
- | |||
- | } | ||
- | </ | ||
- | |||
- | |||
- | |||
- | <code php syntax.php> | ||
- | <?php | ||
- | /** | ||
- | * Twitter Plugin | ||
- | * | ||
- | * @license | ||
- | * @author | ||
- | */ | ||
- | |||
- | // based on http:// | ||
- | |||
- | // must be run within DokuWiki | ||
- | if (!defined(' | ||
- | |||
- | if (!defined(' | ||
- | require_once(DOKU_PLUGIN . ' | ||
- | |||
- | /** | ||
- | * All DokuWiki plugins to extend the parser/ | ||
- | * need to inherit from this class | ||
- | */ | ||
- | class syntax_plugin_twitter extends DokuWiki_Syntax_Plugin { | ||
- | function getInfo() { | ||
- | return array( | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ); | ||
- | } | ||
- | |||
- | private function replace($data) { | ||
- | |||
- | |||
- | $sResponse = "< | ||
- | $data = $data[0]; | ||
- | |||
- | if(!isset($data)){ | ||
- | return $sResponse."< | ||
- | } | ||
- | $sResponse .= '< | ||
- | |||
- | |||
- | foreach($data as $entry){ | ||
- | |||
- | $text=$entry-> | ||
- | $image=$entry-> | ||
- | $time=$entry-> | ||
- | $time = strtotime($time); | ||
- | //$time = date(" | ||
- | $time = $this-> | ||
- | $from=$entry-> | ||
- | $name = ""; | ||
- | if(!empty($entry-> | ||
- | $name = " (" | ||
- | |||
- | if(empty($from)) | ||
- | $from=$entry-> | ||
- | |||
- | if(isset($entry-> | ||
- | { | ||
- | $image=$entry-> | ||
- | } | ||
- | |||
- | // get links | ||
- | $search = array( | ||
- | ' | ||
- | ' | ||
- | ); | ||
- | $replace = array( | ||
- | '<a href=" | ||
- | '<a href=" | ||
- | ); | ||
- | $text = preg_replace($search, | ||
- | |||
- | // get hashtags | ||
- | if (preg_match_all('/# | ||
- | { | ||
- | for($i=0; | ||
- | | ||
- | } | ||
- | |||
- | // get twitterer | ||
- | if (preg_match_all('/ | ||
- | { | ||
- | for($i=0; | ||
- | | ||
- | $text = str_replace($strTwitterer, | ||
- | } | ||
- | } | ||
- | |||
- | $sResponse .= '< | ||
- | } | ||
- | $sResponse .= "</ | ||
- | |||
- | |||
- | return $sResponse; | ||
- | } | ||
- | /* Works out the time since the entry post, takes a an argument in unix time (seconds) | ||
- | */ | ||
- | public function Timesince($original) { | ||
- | // array of time period chunks | ||
- | $chunks = array( | ||
- | array(60 * 60 * 24 * 365 , ' | ||
- | array(60 * 60 * 24 * 30 , ' | ||
- | array(60 * 60 * 24 * 7, ' | ||
- | array(60 * 60 * 24 , ' | ||
- | array(60 * 60 , ' | ||
- | array(60 , ' | ||
- | array(1 , ' | ||
- | ); | ||
- | | ||
- | $today = time(); /* Current unix time */ | ||
- | $since = $today - $original; | ||
- | | ||
- | // $j saves performing the count function each time around the loop | ||
- | for ($i = 0, $j = count($chunks); | ||
- | | ||
- | $seconds = $chunks[$i][0]; | ||
- | $name = $chunks[$i][1]; | ||
- | | ||
- | // finding the biggest chunk (if the chunk fits, break) | ||
- | if (($count = floor($since / $seconds)) != 0) { | ||
- | break; | ||
- | } | ||
- | } | ||
- | | ||
- | $print = ($count == 1) ? '1 ' | ||
- | | ||
- | if ($i + 1 < $j) { | ||
- | // now getting the second item | ||
- | $seconds2 = $chunks[$i + 1][0]; | ||
- | $name2 = $chunks[$i + 1][1]; | ||
- | | ||
- | // add second item if its greater than 0 | ||
- | if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) { | ||
- | $print .= ($count2 == 1) ? ', 1 ' | ||
- | } | ||
- | } | ||
- | return $print; | ||
- | } | ||
- | |||
- | |||
- | function connectTo($mode) { | ||
- | $this-> | ||
- | $this-> | ||
- | |||
- | $this-> | ||
- | $this-> | ||
- | |||
- | } | ||
- | |||
- | function getType() { return ' | ||
- | |||
- | function getSort() { return 314; } | ||
- | |||
- | function handle($match, | ||
- | |||
- | $match = str_replace(array(">"," | ||
- | |||
- | $match = substr($match, | ||
- | $data = explode(":", | ||
- | |||
- | $number =""; | ||
- | |||
- | | ||
- | if(strtoupper($data[1]) == " | ||
- | |||
- | @$json = file_get_contents(" | ||
- | }else{ | ||
- | |||
- | if(isset($data[3])) | ||
- | $number = "? | ||
- | |||
- | @$json = file_get_contents(" | ||
- | |||
- | } | ||
- | |||
- | $decode = json_decode ( $json ); | ||
- | |||
- | if(isset($decode-> | ||
- | { | ||
- | return array($decode-> | ||
- | } | ||
- | |||
- | return array($decode," | ||
- | } | ||
- | |||
- | function render($mode, | ||
- | |||
- | if ($mode == ' | ||
- | // prevent caching to ensure content is always fresh | ||
- | $renderer-> | ||
- | |||
- | $renderer-> | ||
- | return true; | ||
- | } elseif ($mode == ' | ||
- | // for metadata renderer | ||
- | $renderer-> | ||
- | return true; | ||
- | } | ||
- | |||
- | return false; | ||
- | } | ||
- | }</ | ||
- | ===== Discussion ===== | ||
- | **I would like to send dokuwiki changes (the changelog) to twitter automatically. | ||
- | // | ||
- | > That is not possible with this plugin. You would need another plugin to do automatic tweeting of the changelog. The plugin needs to be a action plugin and not a syntax plugin. Currently i'm not havin any plans to realize that, althought it would be really easy because Twitter has a really good API. // | ||
- | >>// | ||
- | |||
- | **Can you (or anybody!) please write a plugin to send dokuwiki updates to twitter? | ||
- | // | ||
- | |||
- | > I wouldn' | ||
- | |||
- | >> [[plugin: | ||
- | |||
- | |||
- | Nice plugin! But is it possible to make the syntax more *DokuWiki-like*? | ||
- | // | ||
- | |||
- | >Ok, just updated the code. Now you can also use: | ||
- | < | ||
- | //Timeline of user | ||
- | {{twitter> | ||
- | //Search for Keyword ' | ||
- | {{twitter> | ||
- | </ | ||
- | |||
- | Hope that helps. | ||
- | |||
- | ---- | ||
- | |||
- | I build some regex into the Plugin to make links, twitterer and hashtags clickable. | ||
- | // | ||
- | |||
- | > Thank you, seems to work very fine! | ||
- | // | ||
- | |||
- | |||
- | Updated the code a little bit, mainly the time of the tweet is now displayed Twitter-like, | ||
- | Also there was a problem with the regex (only first hastag was clickable). Now all hastags are clickable. | ||
- | // | ||
- | |||
- | >Getting a " | ||
- | |||
- | >> " | ||
- | >> | ||
- | |||
- | >>> | ||
- | |||
- | >> In you PHP.ini the option allow_url_fopen is Off. You have to turn it On, so that the Plugin can fetch the data from Twitter. | ||
- | >> If Option is Off [[phpfn> | ||
- | |||
- | >>> | ||
- | >>> | ||
- | >>> | ||
- | >>> | ||
- | >>> | ||
- | |||
- | I updated the mod, now you can use allow_url_fopen with ON or OFF (I need for local Installation ON and for the Server OFF) | ||
- | --- // | ||
- | |||
- | <code php> | ||
- | private function file_get_contents($url) { | ||
- | /** | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | * thx to Christoph Lang and http:// | ||
- | **/ | ||
- | | ||
- | // handle error if fopen is Off | ||
- | if (is_bool($json) && $json == false) | ||
- | { | ||
- | $curl = @curl_init($url); | ||
- | @curl_setopt($curl, | ||
- | @curl_setopt($curl, | ||
- | @$json = curl_exec($curl); | ||
- | curl_close($curl); | ||
- | } | ||
- | | ||
- | } | ||
- | </ | ||
- | |||
- | Fantastic plugin, thanks - is there a way to do negative keywords on the search? (UPDATE 7/22 - WORKED! | ||
- | > Just updated the plugin. Now you can combine searchwords, | ||
- | < | ||
- | //Search for PHP but NOT Zend | ||
- | {{twitter> | ||
- | //Search for PHP AND Zend | ||
- | {{twitter> | ||
- | </ | ||
- | In theory other search parameters from the Twitter-Api should also work, but I didn't test it. | ||
- | |||
- | This requires PHP 5.2 or later, or alternatively you'll have to add a json_decode function, e.g. from http:// | ||
- | |||
- | >>> | ||
- | >>> | ||
- | >> It seems your server is returning the wrong time to the plugin. 01.01.1970 is the start of the UNIX time, and that is what your server is returning (40years and 1 month ago). | ||
- | >> Maybe you have to set the correct time on your server first. --- C.Lang | ||
- | >No, the server' | ||
- | >> | ||
- | >> | ||
- | >>You can also contact me via Email, my mail address is on top of the page (I'm German, too). | ||
- | |||
- | > Updated the plugin with cache " | ||
- | // | ||
- | |||
- | --- [[e-team@bluemel.eu|Andreas]] --- | ||
- | Just receiving the message: | ||
- | Timeline from experimenteandi | ||
- | Twitter is down.... | ||
- | |||
- | What's wrong ? | ||
- | |||
- | > This was already discussed a few lines above. Check your PHP Inifile for allow_url_fopen. // | ||
- | |||
- | >> | ||
- | >>I used the new link to the Twitter API and get the plugin to work\\ | ||
- | >> | ||
- | < | ||
- | @$json = $this-> | ||
- | </ | ||
- | >>in | ||
- | < | ||
- | @$json = $this-> | ||
- | </ | ||
- | >>"& | ||
- | >> | ||
- | >>// |
plugin/twitter.1383355457.txt.gz · Last modified: 2013-11-02 02:24 by Klap-in