Merge pull request #1 from digitalduke/upload

Uploading local sources to repository. First version.
master 1.0
George Pirogov 7 years ago committed by GitHub
commit 023f5993bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      README
  2. 13
      conf/default.php
  3. 12
      conf/metadata.php
  4. 16
      lang/en/lang.php
  5. 13
      lang/en/settings.php
  6. 16
      lang/ru/lang.php
  7. 17
      lang/ru/settings.php
  8. 7
      plugin.info.txt
  9. 139
      syntax.php

@ -0,0 +1,27 @@
sqlquery Plugin for DokuWiki
Processing query to mysql database and display results as a table.
All documentation for this plugin can be found at
https://www.dokuwiki.org/plugin:sqlquery
If you install this plugin manually, make sure it is installed in
lib/plugins/sqlquery/ - if the folder is called different it
will not work!
Please refer to http://www.dokuwiki.org/plugins for additional info
on how to install plugins in DokuWiki.
----
Copyright (C) George Pirogov <i1557@yandex.ru>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
See the COPYING file in your DokuWiki folder for details

@ -0,0 +1,13 @@
<?php
/**
* Default settings for the sqlquery plugin
*
* @author George Pirogov <i1557@yandex.ru>
*/
//$conf['fixme'] = 'FIXME';
$conf['Host'] = 'localhost';
$conf['DB'] = '';
$conf['user'] = '';
$conf['password'] = '';

@ -0,0 +1,12 @@
<?php
/**
* Options for the sqlquery plugin
*
* @author George Pirogov <i1557@yandex.ru>
*/
$meta['Host'] = array('string');
$meta['DB'] = array('string');
$meta['user'] = array('string');
$meta['password'] = array('string');

@ -0,0 +1,16 @@
<?php
/**
* English language file for sqlquery plugin
*
* @author George Pirogov <i1557@yandex.ru>
*/
// menu entry for admin plugins
// $lang['menu'] = 'Your menu entry';
// custom language strings for the plugin
// $lang['fixme'] = 'FIXME';
//Setup VIM: ex: et ts=4 :

@ -0,0 +1,13 @@
<?php
/**
* english language file for sqlquery plugin
*
* @author George Pirogov <i1557@yandex.ru>
*/
// keys need to match the config setting name
// $lang['fixme'] = 'FIXME';
//Setup VIM: ex: et ts=4 :

@ -0,0 +1,16 @@
<?php
/**
* English language file for sqlquery plugin
*
* @author George Pirogov <i1557@yandex.ru>
*/
// menu entry for admin plugins
// $lang['menu'] = 'Your menu entry';
// custom language strings for the plugin
// $lang['fixme'] = 'FIXME';
//Setup VIM: ex: et ts=4 :

@ -0,0 +1,17 @@
<?php
/**
* english language file for sqlquery plugin
*
* @author George Pirogov <i1557@yandex.ru>
*/
// keys need to match the config setting name
// $lang['fixme'] = 'FIXME';
$lang['Host'] = 'Адрес MySQL сервера (dns или ip)';
$lang['DB'] = 'Имя базы данных MySQL';
$lang['user'] = 'Логин';
$lang['password'] = 'Пароль';
//Setup VIM: ex: et ts=4 :

@ -0,0 +1,7 @@
base sqlquery
author George Pirogov
email i1557@yandex.ru
date 2016-11-25
name SQL query plugin
desc Processing query to mysql database and display results as a table.
url https://www.dokuwiki.org/plugin:sqlquery

@ -0,0 +1,139 @@
<?php
/**
* DokuWiki Plugin sqlquery (Syntax Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author George Pirogov <i1557@yandex.ru>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
class syntax_plugin_sqlquery extends DokuWiki_Syntax_Plugin {
public function getType() {
return 'substition';
}
public function getSort() {
return 666;
}
public function connectTo($mode)
{
$this->Lexer->addEntryPattern('<sql>', $mode, 'plugin_sqlquery');
}
public function postConnect()
{
$this->Lexer->addExitPattern('</sql>','plugin_sqlquery');
}
/**
* Handle matches of the sqlquery 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:
return array('sqlquery' => $match);
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['sqlquery'] ) )
{
// получаем параметры конфигурации
$host = $this->getConf('Host');
$DB = $this->getConf('DB');
$user = $this->getConf('user');
$password = $this->getConf('password');
// получаем запрос
$querystring = $data['sqlquery'];
// подключаемся к базе
$link = mysqli_connect($host, $user, $password, $DB);
mysqli_set_charset($link, "utf8");
// подключились
if ( $link )
{
$result = mysqli_query($link, $querystring);
if ( $result )
{
// получаем кол-во полей в таблице
$fieldcount = mysqli_num_fields($result);
// строим таблицу
$renderer->doc .= "<table id=\"sqlquerytable\" class=\"inline\">";
// строим заголовок
$renderer->doc .= "<thead><tr>";
while ($fieldinfo = mysqli_fetch_field($result))
{
$renderer->doc .= "<th>";
$renderer->doc .= $fieldinfo->name;
$renderer->doc .= "</th>";
}
$renderer->doc .= "</tr></thead>";
// строим содержимое таблицы
$renderer->doc .= "<tbody>";
while ($row = mysqli_fetch_row($result))
{
$renderer->doc .= "<tr>";
// строим строку
for ( $i = 0; $i < $fieldcount; $i++ )
{
$renderer->doc .= "<td>";
$renderer->doc .= $row[$i];
$renderer->doc .= "</td>";
}
$renderer->doc .= "</tr>";
} // of while fetch_row
// закрываем таблицу
$renderer->doc .= "</tbody></table>";
} // of mysqli_query
mysqli_close($link);
} // of mysqli link
} // of sqlquery not empty
return true;
} // of render function
}
// vim:ts=4:sw=4:et: