Skip to content

Commit

Permalink
Merge pull request #153 from Klap-in/devel
Browse files Browse the repository at this point in the history
refactor and fixes
  • Loading branch information
splitbrain authored Feb 10, 2024
2 parents 3ac1238 + bf906a0 commit 4638988
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 69 deletions.
74 changes: 47 additions & 27 deletions helper/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class helper_plugin_pluginrepo_repository extends Plugin
{
public array $dokuReleases = []; // array of DokuWiki releases (name & date)
private array $dokuReleases = []; // array of DokuWiki releases (name & date)

public array $types = [
1 => 'Syntax',
Expand Down Expand Up @@ -108,17 +108,19 @@ public function parseData($match, $data)
public function convertToType($key, $value)
{
$hasYesValue = ['showall', 'includetemplates', 'showcompatible', 'showscreenshot'];
$hasNoValue = ['random'];
$hasNoValue = ['random', 'onlyrecent'];
$isInteger = ['entries', 'plugintype', 'cloudmin'];
if (in_array($key, $hasYesValue)) {
$value = $value == 'yes';
$value = strtolower($value) == 'yes';
}
if (in_array($key, $hasNoValue)) {
$value = $value == 'no';
$value = strtolower($value) != 'no';
}
if (in_array($key, $isInteger)) {
if (is_numeric($value)) {
$value = (int) $value;
} else {
$value = 0;
}
}

Expand Down Expand Up @@ -237,12 +239,13 @@ public function getPluginsDB()
*
* @param array $filter with entries used
* <ul>
* <li>'plugins' (array) returns only data of named plugins</li>
* <li>'plugins' (array|string) returns only data of named plugins</li>
* <li>'plugintype' (integer) filter by type, binary-code decimal so you can combine types</li>
* <li>'plugintag' (string) filter by one tag</li>
* <li>'pluginsort' (string) sort by some specific columns (also shortcuts available)</li>
* <li>'showall' (bool) default/unset is false and obsolete plugins and security issues are not returned</li>
* <li>'includetemplates' (bool) default/unset is false and template data will not be returned</li>
* <li>'onlyrecent' (bool) include only extensions which are marked compatible with last 2 releases</li>
* </ul>
* @return array data per plugin
*/
Expand Down Expand Up @@ -277,12 +280,29 @@ public function getPlugins($filter = null)
} else {
[$bundledINsql, $bundledINvalues] = $this->prepareINstmt('bundled', $this->bundled);

$where_filtered = "'" . $this->obsoleteTag . "' NOT IN(SELECT tag
FROM plugin_tags
WHERE plugin_tags.plugin = A.plugin)"
. " AND A.securityissue = ''"
. " AND (A.downloadurl <> '' OR A.plugin " . $bundledINsql . ")";
$where_filtered = "'$this->obsoleteTag' NOT IN(SELECT tag
FROM plugin_tags
WHERE plugin_tags.plugin = A.plugin)
AND A.securityissue = ''
AND (A.downloadurl <> '' OR A.plugin $bundledINsql)";
$values = $bundledINvalues;

if ($filter['onlyrecent']) {
$rows = 0;
$recentDates = [];
foreach ($this->getDokuReleases() as $release) {
if (++$rows > 2) {
break;
}
$recentDates[] = $release['date'];
}
[$compatibilityINsql, $compatibilityINvalues] = $this->prepareINstmt('bestcompat', $recentDates);
$where_filtered .= " AND A.bestcompatible $compatibilityINsql";
$values = array_merge(
$compatibilityINvalues,
$values
);
}
}
if (!$filter['includetemplates']) {
$where_filtered .= " AND A.type <> 32"; // templates are only type=32, has no other type.
Expand All @@ -292,15 +312,15 @@ public function getPlugins($filter = null)
$sortsql = $this->getPluginsSortSql($sort);

$alltypes = 0;
foreach (array_keys($this->types) as $t) {
$alltypes += $t;
foreach (array_keys($this->types) as $number) {
$alltypes += $number;
}

if ($tag) {
if ($type < 1 || $type > $alltypes) {
$type = $alltypes; //all types
}
$sql = "SELECT A.*, SUBSTR(A.plugin,10) as simplename
$sql = " SELECT A.*, SUBSTR(A.plugin,10) as simplename
FROM plugins A
WHERE A.type = 32 AND $where_filtered
AND (A.type & :plugin_type)
Expand All @@ -317,7 +337,7 @@ public function getPlugins($filter = null)
$values
);
} elseif ($type > 0 && $type <= $alltypes) {
$sql = "SELECT A.*, SUBSTR(A.plugin,10) as simplename
$sql = " SELECT A.*, SUBSTR(A.plugin,10) as simplename
FROM plugins A
WHERE A.type = 32 AND $where_filtered
AND (A.type & :plugin_type)
Expand Down Expand Up @@ -427,8 +447,8 @@ public function getFilteredPlugins(

// default to all extensions
if ($type == 0) {
foreach (array_keys($this->types) as $t) {
$type += $t;
foreach (array_keys($this->types) as $number) {
$type += $number;
}
}

Expand Down Expand Up @@ -1025,11 +1045,11 @@ public function parsetags($string)
public function listtype($type, $target, $sep = ', ')
{
$types = [];
foreach ($this->types as $k => $v) {
if ($type & $k) {
$url = wl($target, ['plugintype' => $k]) . '#extension__table';
$types[] = '<a href="' . $url . '" class="wikilink1" title="List all ' . $v . ' plugins">'
. $v
foreach ($this->types as $number => $label) {
if ($type & $number) {
$url = wl($target, ['plugintype' => $number]) . '#extension__table';
$types[] = '<a href="' . $url . '" class="wikilink1" title="List all ' . $label . ' plugins">'
. $label
. '</a>';
}
}
Expand All @@ -1046,9 +1066,9 @@ public function listtype($type, $target, $sep = ', ')
public function listtypes($type)
{
$types = [];
foreach ($this->types as $k => $v) {
if ($type & $k) {
$types[] = $v;
foreach ($this->types as $number => $label) {
if ($type & $number) {
$types[] = $label;
}
}
sort($types);
Expand All @@ -1064,9 +1084,9 @@ public function listtypes($type)
public function parsetype($types)
{
$type = 0;
foreach ($this->types as $k => $v) {
if (preg_match('#' . preg_quote($v) . '#i', $types)) {
$type += $k;
foreach ($this->types as $number => $label) {
if (preg_match('#' . preg_quote($label) . '#i', $types)) {
$type += $number;
}
}
if ($type === 0 && $types === '') {
Expand Down
6 changes: 3 additions & 3 deletions plugin.info.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
base pluginrepo
author Andreas Gohr/Håkan Sandell
email sandell.hakan@gmail.com
date 2024-01-30
date 2024-02-09
name Repository plugin
desc Helps organizing the plugin repository
url http://www.dokuwiki.org/plugin:pluginrepo
desc Helps organizing the plugin and template repository
url https://www.dokuwiki.org/plugin:repository
minphp 7.4
6 changes: 3 additions & 3 deletions repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ function getRepository()
$feed .= '<type>';
if ($plugin['type']) {
$types = [];
foreach ($hlp->types as $k => $v) {
if ($plugin['type'] & $k) {
$types[] = $v;
foreach ($hlp->types as $number => $label) {
if ($plugin['type'] & $number) {
$types[] = $label;
}
}
sort($types);
Expand Down
48 changes: 34 additions & 14 deletions syntax/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler)
'pluginsort' => '',
'showall' => false,
'includetemplates' => false,
'onlyrecent' => true
];
return $this->hlp->parseData($match, $initialData);
}
Expand Down Expand Up @@ -142,7 +143,9 @@ public function render($format, Doku_Renderer $renderer, $data)
*
* @param Doku_Renderer_xhtml $R
* @param array $data used entries:
* entries: number of plugins/templates displayed, otherwise 10
* <ul>
* <li>entries: number of plugins/templates displayed, otherwise 10</li>
* </ul>
*/
public function showSameAuthor($R, $data)
{
Expand All @@ -155,16 +158,16 @@ public function showSameAuthor($R, $data)
}

$rel = $this->hlp->getPluginRelations($id);
if (count($rel) == 0) {
if (count($rel['sameauthor']) == 0) {
$R->doc .= '<p class="nothing">Can\'t find any other plugins or templates</p>';
return;
}

$limit = $data['entries'] > 0 ? $data['entries'] : 10;
$itr = 0;
$i = 0;
$R->doc .= '<ul>';
while ($itr < count($rel['sameauthor']) && $itr < $limit) {
$R->doc .= '<li>' . $this->hlp->pluginlink($R, $rel['sameauthor'][$itr++]) . '</li>';
while ($i < count($rel['sameauthor']) && $i < $limit) {
$R->doc .= '<li>' . $this->hlp->pluginlink($R, $rel['sameauthor'][$i++]) . '</li>';
}
$R->doc .= '</ul>';
}
Expand All @@ -174,22 +177,38 @@ public function showSameAuthor($R, $data)
*
* @param Doku_Renderer_xhtml $R
* @param array $data used entries:
* entries: number of plugins/templates displayed, otherwise 1
* random: if 'no' the plugin/template is not selected randomly
* screenshot: if 'yes' a screenshot is shown
* and used by the filtering:
*
* <ul>
* <li>entries: number of plugins/templates displayed, otherwise 1</li>
* <li>random: if 'no' the plugin/template is not selected randomly</li>
* <li>screenshot: if 'yes' a screenshot is shown</li>
* <li>via getPlugins():
* <ul>
* <li>'plugins' array or str, if used plugintype and plugintag are skipped</li>
* <li>'plugintype' int,</li>
* <li>'plugintag' str</li>
* <li>'pluginsort' str shortcuts assumed</li>
* <li>'showall' bool</li>
* <li>'includetemplates' bool</li>
* <li>'onlyrecent' bool</li>
* </ul>
* </li>
* </ul>
* @throws Exception
* @see helper_plugin_pluginrepo_repository::getPlugins()
*/
public function showDefault($R, $data)
{
$limit = $data['entries'] > 0 ? $data['entries'] : 1;
$plugins = $this->hlp->getPlugins($data);

$limit = $data['entries'] > 0 ? $data['entries'] : 1;
$limit = min($limit, count($plugins));

if ($data['random']) {
$start = random_int(0, count($plugins) - 1 - $limit);
$start = random_int(0, count($plugins) - $limit);
} else {
$start = 0;
}

for ($i = 0; $i < $limit; $i++) {
$row = $plugins[$start + $i];
$linkText = ucfirst(noNS($row['plugin'])) . ($row['type'] == 32 ? ' template' : ' plugin');
Expand All @@ -198,8 +217,9 @@ public function showDefault($R, $data)

$url = $row['screenshot'];
if ($url && $data['showscreenshot']) {
$R->doc .= '<a href="' . ml($url) . '" class="media screenshot" rel="lightbox">';
$R->doc .= '<img src="' . ml($url, "w=200") . '" alt="" width="200" /></a>';
$R->doc .= '<a href="' . ml($url) . '" class="media screenshot" rel="lightbox">'
. '<img src="' . ml($url, "w=200") . '" alt="" width="200" />'
. '</a>';
}

$R->doc .= '<p class="author">Author: ';
Expand Down
8 changes: 4 additions & 4 deletions syntax/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function render($format, Doku_Renderer $renderer, $data)
foreach ($this->allowedfields as $field) {
$error = str_replace($field, '', $error);
}
$error = preg_replace('/(LIKE|AND|OR|NOT|IS|NULL|[<>=?()])/i', '', $error);
$error = preg_replace('/(LIKE|AND|OR|NOT|IS|NULL|[<>=?()&])/i', '', $error);
if (trim($error)) {
$renderer->doc .= '<div class="error repoquery">'
. '<strong>Repoquery error - Unsupported chars in WHERE clause:</strong> ' . hsc($error)
Expand Down Expand Up @@ -250,9 +250,9 @@ public function render($format, Doku_Renderer $renderer, $data)
$renderer->doc .= '<td>';

if ($field == 'type') {
foreach ($this->hlp->types as $k => $v) {
if ($row['type'] & $k) {
$renderer->doc .= $v . ' ';
foreach ($this->hlp->types as $number => $label) {
if ($row['type'] & $number) {
$renderer->doc .= $label . ' ';
}
}
} elseif ($field == 'plugin') {
Expand Down
Loading

0 comments on commit 4638988

Please sign in to comment.