'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 ; } }