* @author Marie Mandrela */ // must be run within Dokuwiki if (!defined('DOKU_INC')) die(); class syntax_plugin_sqljson extends DokuWiki_Syntax_Plugin { public function getType() { return 'substition'; } public function getSort() { return 666; } public function connectTo($mode) { $this->Lexer->addEntryPattern(')', $mode, 'plugin_sqljson'); } public function postConnect() { $this->Lexer->addExitPattern('','plugin_sqljson'); } /** * Handle matches of the sqljson syntax * * @param string $match The match of the syntax * @param int $state The state of the handler * @param int $pos The position in the document * @param Doku_Handler $handler The handler * @return array Data for the renderer */ public function handle($match, $state, $pos, Doku_Handler $handler) { switch ($state) { case DOKU_LEXER_ENTER: $data = array(); return $data; break; case DOKU_LEXER_UNMATCHED: // will include everything from // e.g. ... [name] > [sqljson] list($attr, $content) = preg_split('/>/u',$match,2); return array('sqljson' => $content, 'variable' => trim($attr)); break; case DOKU_LEXER_EXIT: $data = array(); return $data; break; } $data = array(); return $data; } /** * Render xhtml output or metadata * * @param string $mode Renderer mode (supported modes: xhtml) * @param Doku_Renderer $renderer The renderer * @param array $data The data from the handler() function * @return bool If rendering was successful. */ public function render($mode, Doku_Renderer $renderer, $data) { if ( $mode != 'xhtml' ) return false; if ( !empty( $data['sqljson'] ) ) { // get the configuration parameters $host = $this->getConf('Host'); $DB = $this->getConf('DB'); $user = $this->getConf('user'); $password = $this->getConf('password'); // get a query $querystring = $data['sqljson']; // connect to the database $link = mysqli_connect($host, $user, $password, $DB); mysqli_set_charset($link, "utf8"); // connected if ( $link ) { $result = mysqli_query($link, $querystring); if ( $result ) { // get the number of fields in the table $fieldcount = mysqli_num_fields($result); // get the number of rows in the table $rowcount = mysqli_num_rows($result); // open script tag $renderer->doc .= ""; } mysqli_close($link); } } return true; } } // vim:ts=4:sw=4:et: