'Craig Douglas', 'email' => 'contact22@eldougo.net', 'date' => '2014-09-18', 'name' => 'Tuxquote Plugin', 'desc' => 'Show a random image and quote', 'url' => 'https://github.com/eldougo/dokuwiki_plugin_tuxquote'); } function getType() { return 'substition'; } function getSort() { return 32; } function connectTo($mode) { $this->Lexer->addSpecialPattern('\[TUXQUOTE\]',$mode,'plugin_tuxquote'); } function handle($match, $state, $pos, Doku_Handler $handler) { return array($match, $state, $pos); } function render($mode, Doku_Renderer $renderer, $data) { if($mode == 'xhtml'){ $renderer->doc .= $this->tuxquote_main(); return true; } return false; } /** * Callback used to determine if the passed file is an image. */ function tuxquote_is_image( $file_name ){ return strpos( $file_name, ".jpg" ) || strpos( $file_name, ".png" ) || strpos( $file_name, ".gif" ); } /** * Return a random quote. */ public function tuxquote_choose_quote(){ $quotes = file( DOKU_PLUGIN . $this->getPluginName() . "/quotes.txt" ); return $quotes[ array_rand( $quotes, 1 ) ]; } /** * Chose and format a random image. */ function tuxquote_choose_image() { $image_url = getBaseURL() . "lib/plugins/{$this->getPluginName()}/images/"; $image_dir = DOKU_PLUGIN . $this->getPluginName() . "/images/"; $image_array = array_filter( scandir( $image_dir ), array( $this, 'tuxquote_is_image' ) ); return $image_url . $image_array[ array_rand( $image_array,1 ) ]; } /** * Build and format HTML output. * * @param string $div_width Div width in pixels or percentage [NN%|NNpx]. * @param string $div_align Div float alignment [none|left|right]. * @param string $title Div title, optional. */ function tuxquote_build_format( $div_width, $div_align, $title = '' ) { if ( empty( $div_width ) ) { $div_width = TUXQUOTE_DEFAULT_WIDTH; } if ( is_numeric( $div_width ) ) { $div_width = trim( $div_width ) . "%"; } if ( empty( $div_align ) ) { $div_align = TUXQUOTE_DEFAULT_ALIGN; } if ( ! empty( $title ) ) { $title_line = "

" . $title . "

\n"; } else { $title_line = ''; } return "\n
\n" .$title_line ."
\n" ."

" . $this->tuxquote_choose_quote() . "

\n" ."
\n"; } /** * Return HTML encoded random image and quote. */ function tuxquote_main() { return $this->tuxquote_build_format( $this->getConf( 'tuxquote_width' ), $this->getConf( 'tuxquote_align' ), $this->getConf( 'tuxquote_title' ) ); } } // class syntax_plugin_tuxquote