====== dokuwikitweet Plugin ====== ---- plugin ---- description: a plugin to create a mini tweeter page in your wiki author : MARTINEAU Emeric email : bubulemaster@yahoo.fr type : syntax lastupdate : 2010-10-20 compatible : dokuwiki-2009-12-25 depends : conflicts : similar : bliki tags : chat twitter downloadurl: # eg. https://github.com//dokuwiki-plugin-dokuwikitweet/zipball/master bugtracker : # eg. https://github.com//dokuwiki-plugin-dokuwikitweet/issues sourcerepo : # eg. https://github.com//dokuwiki-plugin-dokuwikitweet/ donationurl: ---- ===== Manual installation ===== Refer to [[:Plugins]] on how to install plugins manually. Grap all file below : 'MARTINEAU Emeric', 'email' => '', 'date' => '2010-09-15', 'name' => 'Tweet plugin', 'desc' => 'Space to tweet v1.0', 'url' => 'http://www.dokuwiki.org/plugin:dokuwikitweet' ) ; } // // Type of plugin // function getType() { return 'formatting'; } // // ??? // function getAllowedTypes() { return array() ; //'formatting', 'substition', 'disabled') ; } // // ??? // function getPType() { return 'normal' ; } // // When run it // function getSort() { return 158 ; } // // What tag to connect this plugin // function connectTo($mode) { include(dirname(__FILE__) . '/config.php') ; $this->Lexer->addEntryPattern('<' . $DOKUWIKI_TWEET_CONFIG['tag'] . '?>(?=.*?)', $mode, 'plugin_dokuwikitweet') ; } // // What tag to deconnect this plugin // function postConnect() { include(dirname(__FILE__) . '/config.php') ; $this->Lexer->addExitPattern('', 'plugin_dokuwikitweet') ; } // // Handle the match /// function handle($match, $state, $pos, &$handler) { switch ($state) { case DOKU_LEXER_ENTER : case DOKU_LEXER_UNMATCHED : return array($state, $match) ; case DOKU_LEXER_EXIT : return array($state, '') ; } return array() ; } // // Create output // function render($mode, &$renderer, $data) { global $conf ; global $INFO ; if($mode == 'xhtml') { list($state,$match) = $data ; switch ($state) { case DOKU_LEXER_ENTER : include(dirname(__FILE__) . '/config.php') ; $renderer->doc .= '' . "\n" ; $renderer->doc .= '

' . "\n" ; // Add tweet bar if ($conf['useacl'] && auth_quickAclCheck($pageId) >= AUTH_EDIT) { $renderer->doc .= '
' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . '
' . "\n" . '
Reloading page...
' . "\n" ; } break ; case DOKU_LEXER_UNMATCHED : include(dirname(__FILE__) . '/config.php') ; if (empty($DOKUWIKI_TWEET_CONFIG['date_format'])) { $dateFormat = $conf['dformat'] ; $dateFormat = str_replace('%Y', 'Y', $dateFormat) ; $dateFormat = str_replace('%m', 'm', $dateFormat) ; $dateFormat = str_replace('%d', 'd', $dateFormat) ; $dateFormat = str_replace('%H', 'H', $dateFormat) ; $dateFormat = str_replace('%M', 'i', $dateFormat) ; } else { $dateFormat = $DOKUWIKI_TWEET_CONFIG['date_format'] ; } $oddLine = true ; // Read data $data = explode("\n", $match) ; $count = count($data) ; // if last line empty, delete-it if (($count > 0) && (empty($data[$count -1]))) { unset($data[$count -1]) ; $count-- ; } // Get url $urlPageKey = $DOKUWIKI_TWEET_CONFIG['url_page_key'] ; // Create new url $newUrl = $this->getNewUrlString($urlPageKey) ; // Get max msg $maximumMsg = $DOKUWIKI_TWEET_CONFIG['nb_msg_per_page'] ; // Read current page $currentIndexPage = 0 ; if (isset($_GET[$urlPageKey])) { $selectedPage = $_GET[$urlPageKey] ; } else { $selectedPage = 0 ; } $renderer->doc .= '' . "\n" ; $renderer->doc .= '
 
' . "\n" ; $startMessage = ($selectedPage * $maximumMsg) ; $stopMessage = $startMessage + $maximumMsg ; $renderer->doc .= '
' . "\n" ; self::$urlArray = array() ; for($indexMessage = $startMessage; ($indexMessage < $stopMessage) && ($indexMessage < $count); $indexMessage++) { $line = $data[$indexMessage] ; if (strlen($line) != 0) { $renderer->doc .= ' ' . "\n" ; $oddLine = !$oddLine ; $field = explode($DOKUWIKI_TWEET_CONFIG['separator'], $line) ; $renderer->doc .= ' ' . "\n" ; $renderer->doc .= ' ' . "\n" ; $renderer->doc .= ' ' . "\n" ; } } $renderer->doc .= '
' . "\n" ; $renderer->doc .= ' ' . $field[1] . '
' . '' . date($dateFormat, $field[0]) . '' . "\n" ; $renderer->doc .= '
' . "\n" ; $renderer->doc .= ' ' . $this->decode($field[2], $renderer) . "\n" ; $renderer->doc .= '
' . "\n" ; break ; case DOKU_LEXER_EXIT : $renderer->doc .= "
\n

" ; break ; } return true ; } return false ; } // // Save url // // @param string $url url // // @return string public static function saveUrl($url) { $replace = '$starturl$' . count(self::$urlArray) . '$enurl$' ; self::$urlArray[] = $url[0] ; return $replace ; } // // Restore url // // @param string $ref ref // // @return url public static function restoreUrl($ref) { $url = self::$urlArray[$ref[2]] ; return '' . $url . '' ; } // // Escape url // // @param string $url string // // @return same string but escaped function escapeUrl($url) { $key = preg_quote('!*\'();:@&=+$,/?#[]' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . 'abcdefghijklmnopqrstuvwxyz' . '0123456789-_.~%') ; $in = '`((?:https?|ftp)://[' . $key . ']+/?)`si' ; return preg_replace_callback($in, 'syntax_plugin_dokuwikitweet::saveUrl', $url) ; } // // Escape url // // @param string $url string // // @return same string but escaped function clickableUrl($url) { $key = preg_quote('!*\'();:@&=+$,/?#[]' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . 'abcdefghijklmnopqrstuvwxyz' . '0123456789-_.~%') ; $openTag = preg_quote('$starturl$') ; $closeTag = preg_quote('$enurl$') ; $in = '`(' . $openTag . ')([0-9]+)(' . $closeTag . ')`si' ; return preg_replace_callback($in, 'syntax_plugin_dokuwikitweet::restoreUrl', $url) ; } // // Decode string // // @param string $string string to decode // // @return string function decode($string, $renderer) { $string = urldecode($string) ; $string = $this->escapeUrl($string) ; $string = $renderer->_xmlEntities($string) ; $string = $this->clickableUrl($string) ; return $string ; } // // Create url link // // @param string $without without key // // @return url without function getNewUrlString($without) { $newUrl = '?' ; foreach($_GET as $key => $value) { if ($key != $without) { $newUrl .= urlencode($key) . '=' . urlencode($value) . '&' ; } } return $newUrl ; } } ' ; $tagClose = '' ; // Search tag for($index = 0; $index < $lineCount; $index++) { $pos = strpos($fileContent[$index], $tagOpen) ; if ($pos !== false) { $start = $index ; } } // Found ? if ($start > -1) { $line = time() . $DOKUWIKI_TWEET_CONFIG['separator'] . getUser() . $DOKUWIKI_TWEET_CONFIG['separator'] . getMessage() ; $fileContent[$start] = str_replace($tagOpen, $tagOpen . $line . "\n", $fileContent[$start]) ; $nbMsg = $DOKUWIKI_TWEET_CONFIG['max_msg'] ; // If -1 no delete if ($nbMsg > -1) { // Clear line for($index = $start + 1; $index < $lineCount; ) { $pos = strpos($fileContent[$index], $tagClose) ; if ($pos !== false) { break ; } $nbMsg-- ; if ($nbMsg < 1) { array_splice($fileContent, $index, 1) ; $lineCount-- ; } else { $index++ ; } } } $fileContent = implode('', $fileContent) ; saveWikiText($pageId, $fileContent, "Message added", true) ; unlock($pageId) ; } //} } if (isset($_GET['action'])) { $action = $_GET['action'] ; if ($action == 'save') { saveMessage() ; } } ?> // // Tweet plugin // // @license Public domain // @author MARTINEAU Emeric // var add_tweet = new sack(DOKU_BASE + 'lib/plugins/dokuwikitweet/ajax.php') ; add_tweet.AjaxFailedAlert = '' ; add_tweet.encodeURIString = false ; add_tweet.method = "GET" ; // If not null, a message send var timeOutSend = null ; // Reload time (30s per default) var reloadTime = 30000 ; // If not null, clear if var timeOutReload = null ; // // Get element function getElement(id) { if (document.getElementById) { return document.getElementById(id) ; } else if (document.all) { return window.document.all[id] ; } else if (document.layers) { return window.document.layers[id] ; } return null ; } // // Get value of element of form function getValueElement(id) { var input = getElement(id) ; var value = '' ; if ((input != null) && (input != undefined)) { value = input.value ; } return value ; } // // Send message function sendMessage() { // Clear timeout to reload page clearTimeout(timeOutReload) ; var pageId = encodeURIComponent(getValueElement('tweet_page_id')) ; var user = encodeURIComponent(getValueElement('tweet_user')) ; var message = encodeURIComponent(getValueElement('tweet_msg')) ; if (message.length > 0) { if (add_tweet.setVar) { add_tweet.setVar('action', 'save') ; add_tweet.setVar('pageId', pageId) ; add_tweet.setVar('user', user) ; add_tweet.setVar('msg', message) ; add_tweet.runAJAX() ; } else { add_tweet.runAJAX( 'action=save' + '&pageId=' + pageId+ '&user=' + user+ '&msg=' + message) ; } } timeOutSend = setTimeout('reloadPage()', 2000) ; refreshPage() ; return false ; } // // Hide item function hide(id) { var tweetForm = getElement(id) ; tweetForm.style.display='none' ; tweetForm.style.visibility='hidden' ; } // // Show item function show(id) { var tweetForm = getElement(id) ; tweetForm.style.visibility='visible' ; tweetForm.style.display='block' ; } // // Reload page function reloadPage() { window.location.reload() ; } // // Set element to say page is reloading but don't reloading function refreshPage() { var tweetMsg = getElement('tweet_msg') ; tweetMsg.value = '' ; show('tweet_reloading') ; hide('tweet_form') ; } // Source from // http://www.wikistuce.info/doku.php/javascript/limiter_la_saisie_dans_un_textearea function textLimit(field, maxlen) { if (field.value.length > maxlen) { field.value = field.value.substring(0, maxlen) ; } } // // Auto reload page if message is empty function autoRefreshPage() { // Check if send a message var message = encodeURIComponent(getValueElement('tweet_msg')) ; if ((timeOutSend == null) && (message.length == 0)) { refreshPage() ; reloadPage() ; } else { timeOutReload = setTimeout("autoRefreshPage()", reloadTime) ; } } div.tweet_page { } div.tweet-line-even { background-color: white; } div.tweet-line-odd { background-color: white; } form#tweet_form { } input#tweet_send { } input#tweet_msg { } div.tweet_reloading { visibility : hidden ; display : inline ; } div#tweet_reload { } .tweet_user_and_date { width:auto; background-color:#C1D3D6; white-space:nowrap; vertical-align:top; } span.tweet_show_user { font-weight:bold; } span.tweet_show_date { font-size:80%; } .tweet_show_message { height:40px; background-color:#EEEEEE; width:600px; } ul.tweet_list_page li { display:table; padding: 0px 0px 0px 0px ; margin: 0px 0px 0px 0px; list-style-type: none; float:left; text-align: center; line-height: 2.3em; } li.tweet_list_first_page { display:block; padding:4px; height:2.5em; width:2.5em; } li.tweet_list_one_page { display:block; padding:4px; height:2.5em; width:2.5em; } li.tweet_list_current_page { display:block; padding:4px; height:2.5em; width:2.5em; border:solid #CCCCCC; border-width: 1px 1px 1px 1px; background-color: #3399AA; color:white; } .spacer { clear:left; } a.tweet_url_page { color:#999999 !important; text-decoration:none !important; } a.tweet_url_current_page { color:white !important; text-decoration:none !important; } .tweet_table_msg { border-spacing: 5px; /*border-collapse: collapse; */ } ====== DokuWiki Tweet Plugin ====== Written by MARTINEAU Emeric. Public domain. ===== Installation ===== Just unzip this archive in lib directory or use plugin manager to download it. After, edit config.php file. ===== Use it ===== Create a page and put : ~~NOCACHE~~ ===== History ===== 1.0 - 20/09/2010 - delete CR or LF in text, - use table and not div cause firefox bug, - correct bug to show one page with empty message. - change encoding/decoding string, - better url support. 1.0b1 - 17/09/2010 : - first release. Create a directory ''/lib/plugins/dokuwikitweet'' and put all files in it. ===== Syntax and Usage ===== Create a page and put: ~~NOCACHE~~