Skip to content

Commit

Permalink
automatic code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed Dec 19, 2024
1 parent 3113520 commit 9730265
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion conf/default.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Default settings for the dbquery plugin
*
Expand All @@ -9,4 +10,3 @@
$conf['dsn'] = '';
$conf['user'] = '';
$conf['pass'] = '';

3 changes: 1 addition & 2 deletions conf/metadata.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Options for the dbquery plugin
*
Expand All @@ -9,5 +10,3 @@
$meta['dsn'] = [];
$meta['user'] = ['string'];
$meta['pass'] = ['password'];


9 changes: 6 additions & 3 deletions helper.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

use dokuwiki\Extension\Plugin;

/**
* DokuWiki Plugin dbquery (Helper Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <dokuwiki@cosmocode.de>
*/
class helper_plugin_dbquery extends dokuwiki\Extension\Plugin
class helper_plugin_dbquery extends Plugin
{
/** @var PDO[] do not access directly, use getPDO instead */
protected $pdo = [];
Expand Down Expand Up @@ -76,6 +78,7 @@ public function executeQuery($query, $dsnalias = null)
$params = $this->gatherVariables();
$sth = $this->prepareStatement($pdo, $query, $params);
$sth->execute();

$data = $sth->fetchAll(PDO::FETCH_ASSOC);
$sth->closeCursor();

Expand All @@ -101,13 +104,13 @@ public function prepareStatement(\PDO $pdo, $sql, $parameters)
$groupids[] = ":$id";
}
unset($parameters[':groups']);
$sql = str_replace(':groups', join(',', $groupids), $sql);
$sql = str_replace(':groups', implode(',', $groupids), $sql);

$sth = $pdo->prepare($sql);
foreach ($parameters as $key => $val) {
if (is_array($val)) continue;
if (is_object($val)) continue;
if (strpos($sql, $key) === false) continue; // skip if parameter is missing
if (!str_contains($sql, $key)) continue; // skip if parameter is missing

if (is_int($val)) {
$sth->bindValue($key, $val, PDO::PARAM_INT);
Expand Down
2 changes: 0 additions & 2 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/
class renderer_plugin_dbquery extends \Doku_Renderer
{

protected $codeBlocks = [];
protected $lastHeader = '';

Expand Down Expand Up @@ -53,5 +52,4 @@ public function document_end()
'macros' => $this->info['dbquery'],
]);
}

}
7 changes: 4 additions & 3 deletions syntax/macro.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

use dokuwiki\Extension\SyntaxPlugin;

/**
* DokuWiki Plugin dbquery (Syntax Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <dokuwiki@cosmocode.de>
*/
class syntax_plugin_dbquery_macro extends \dokuwiki\Extension\SyntaxPlugin
class syntax_plugin_dbquery_macro extends SyntaxPlugin
{
/** @inheritDoc */
public function getType()
Expand Down Expand Up @@ -45,10 +47,9 @@ public function render($mode, Doku_Renderer $renderer, $data)
[$name, $value] = sexplode('=', $data[0], 2);
$name = trim($name);
$value = trim($value);
if(!$value) $value = true;
if (!$value) $value = true;

$renderer->info['dbquery'][$name] = $value;
return true;
}
}

19 changes: 9 additions & 10 deletions syntax/query.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

use dokuwiki\Extension\SyntaxPlugin;

/**
* DokuWiki Plugin dbquery (Syntax Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <dokuwiki@cosmocode.de>
*/
class syntax_plugin_dbquery_query extends DokuWiki_Syntax_Plugin
class syntax_plugin_dbquery_query extends SyntaxPlugin
{
/** @inheritDoc */
public function getType()
Expand Down Expand Up @@ -57,12 +59,10 @@ public function render($mode, Doku_Renderer $renderer, $data)

if (count($result) === 1 && isset($result[0]['status']) && isset($qdata['codeblocks'][$result[0]['status']])) {
$this->renderStatus($result, $qdata['codeblocks'][$result[0]['status']], $renderer);
} elseif ($qdata['macros']['transpose']) {
$this->renderTransposedResultTable($result, $renderer);
} else {
if ($qdata['macros']['transpose']) {
$this->renderTransposedResultTable($result, $renderer);
} else {
$this->renderResultTable($result, $renderer);
}
$this->renderResultTable($result, $renderer);
}

return true;
Expand All @@ -77,7 +77,7 @@ public function render($mode, Doku_Renderer $renderer, $data)
*/
public function renderStatus($result, $html, Doku_Renderer $R)
{
$value = isset($result[0]['result']) ? $result[0]['result'] : '';
$value = $result[0]['result'] ?? '';
$html = str_replace(':result', hsc($value), $html);
$R->doc .= $html;
}
Expand Down Expand Up @@ -172,7 +172,7 @@ protected function cellFormat($content, Doku_Renderer $R)
if (preg_match('/^\[\[(https?:\/\/[^|\]]+)(|.*?)?]]$/', $content, $m)) {
$url = $m[1];
$title = $m[2] ?? '';
$title = trim($title,'|');
$title = trim($title, '|');
$R->externallink($url, $title);
return;
}
Expand All @@ -181,12 +181,11 @@ protected function cellFormat($content, Doku_Renderer $R)
if (preg_match('/^\[\[([^|\]]+)(|.*?)?]]$/', $content, $m)) {
$page = cleanID($m[1]);
$title = $m[2] ?? '';
$title = trim($title,'|');
$title = trim($title, '|');
$R->internallink($page, $title);
return;
}

$R->cdata($content);
}
}

0 comments on commit 9730265

Please sign in to comment.