code style changes

This commit is contained in:
Gerrit Uitslag
2024-01-30 23:04:16 +01:00
parent b81aea9a47
commit 89667b1951
7 changed files with 93 additions and 73 deletions

View File

@ -1,8 +1,10 @@
<?php
/**
* Calculate the popularity per plugin/template from the popularity database tables
* Check for version and base discrepancies and update the 'devel:badextensions' page
*/
$TIMEFRAME = 60 * 60 * 24 * 365 * 2; // in seconds
$TIME = time() - $TIMEFRAME;

View File

@ -200,7 +200,11 @@ class helper_plugin_pluginrepo_repository extends Plugin
global $conf;
/** @var PDO $db */
try {
$db = new PDO($this->getConf('db_name'), $this->getConf('db_user'), $this->getConf('db_pass'));
$db = new PDO(
$this->getConf('db_name'),
$this->getConf('db_user'),
$this->getConf('db_pass')
);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
@ -273,7 +277,9 @@ class helper_plugin_pluginrepo_repository extends Plugin
} 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)"
$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;
@ -294,48 +300,48 @@ class helper_plugin_pluginrepo_repository extends Plugin
if ($type < 1 || $type > $alltypes) {
$type = $alltypes; //all types
}
$sql = " SELECT A.*, SUBSTR(A.plugin,10) as simplename
FROM plugins A
WHERE A.type = 32 AND $where_filtered
AND (A.type & :plugin_type)
AND :plugin_tag IN(SELECT tag FROM plugin_tags WHERE plugin_tags.plugin = A.plugin)
UNION
SELECT A.*, A.plugin as simplename
FROM plugins A
WHERE A.type <> 32 AND $where_filtered
AND (A.type & :plugin_type)
AND :plugin_tag IN(SELECT tag FROM plugin_tags WHERE plugin_tags.plugin = A.plugin)
$sortsql";
$sql = "SELECT A.*, SUBSTR(A.plugin,10) as simplename
FROM plugins A
WHERE A.type = 32 AND $where_filtered
AND (A.type & :plugin_type)
AND :plugin_tag IN(SELECT tag FROM plugin_tags WHERE plugin_tags.plugin = A.plugin)
UNION
SELECT A.*, A.plugin as simplename
FROM plugins A
WHERE A.type <> 32 AND $where_filtered
AND (A.type & :plugin_type)
AND :plugin_tag IN(SELECT tag FROM plugin_tags WHERE plugin_tags.plugin = A.plugin)
$sortsql";
$values = array_merge(
[':plugin_tag' => $tag, ':plugin_type' => $type],
$values
);
} elseif ($type > 0 && $type <= $alltypes) {
$sql = " SELECT A.*, SUBSTR(A.plugin,10) as simplename
FROM plugins A
WHERE A.type = 32 AND $where_filtered
AND (A.type & :plugin_type)
UNION
SELECT A.*, A.plugin as simplename
FROM plugins A
WHERE A.type <> 32 AND $where_filtered
AND (A.type & :plugin_type)
$sortsql";
$sql = "SELECT A.*, SUBSTR(A.plugin,10) as simplename
FROM plugins A
WHERE A.type = 32 AND $where_filtered
AND (A.type & :plugin_type)
UNION
SELECT A.*, A.plugin as simplename
FROM plugins A
WHERE A.type <> 32 AND $where_filtered
AND (A.type & :plugin_type)
$sortsql";
$values = array_merge(
[':plugin_type' => $type],
$values
);
} else {
$sql = " SELECT A.*, SUBSTR(A.plugin,10) as simplename
FROM plugins A
WHERE A.type = 32 AND $where_filtered
$where_requested
UNION
SELECT A.*, A.plugin as simplename
FROM plugins A
WHERE A.type <> 32 AND $where_filtered
$where_requested
$sortsql";
$sql = "SELECT A.*, SUBSTR(A.plugin,10) as simplename
FROM plugins A
WHERE A.type = 32 AND $where_filtered
$where_requested
UNION
SELECT A.*, A.plugin as simplename
FROM plugins A
WHERE A.type <> 32 AND $where_filtered
$where_requested
$sortsql";
$values = array_merge(
$requestedINvalues,
@ -563,7 +569,8 @@ class helper_plugin_pluginrepo_repository extends Plugin
$plugins[$i]['thumbnailurl'] = null;
} else {
$plugins[$i]['screenshoturl'] = ml($plugins[$i]['screenshot'], '', true, '&', true);
$plugins[$i]['thumbnailurl'] = ml($plugins[$i]['screenshot'], ['w' => 120, 'h' => 70], true, '&', true);
$size = ['w' => 120, 'h' => 70];
$plugins[$i]['thumbnailurl'] = ml($plugins[$i]['screenshot'], $size, true, '&', true);
}
unset($plugins[$i]['screenshot']);
unset($plugins[$i]['email']); // no spam
@ -728,7 +735,9 @@ class helper_plugin_pluginrepo_repository extends Plugin
if ($filter['showall']) {
$shown = "1";
} else {
$shown = "'" . $this->obsoleteTag . "' NOT IN(SELECT tag FROM plugin_tags WHERE plugin_tags.plugin = B.plugin)
$shown = "'" . $this->obsoleteTag . "' NOT IN(SELECT tag
FROM plugin_tags
WHERE plugin_tags.plugin = B.plugin)
AND B.securityissue = ''";
}
if ($filter['plugintype'] == 32) {
@ -814,19 +823,24 @@ class helper_plugin_pluginrepo_repository extends Plugin
}
/** @var PDOStatement $stmt */
$stmt = $db->prepare('DELETE FROM plugins WHERE plugin = ?');
$stmt = $db->prepare('DELETE FROM plugins
WHERE plugin = ?');
$stmt->execute([$plugin]);
$stmt = $db->prepare('DELETE FROM plugin_tags WHERE plugin = ?');
$stmt = $db->prepare('DELETE FROM plugin_tags
WHERE plugin = ?');
$stmt->execute([$plugin]);
$stmt = $db->prepare('DELETE FROM plugin_similar WHERE plugin = ? OR other = ?');
$stmt = $db->prepare('DELETE FROM plugin_similar
WHERE plugin = ? OR other = ?');
$stmt->execute([$plugin, $plugin]);
$stmt = $db->prepare('DELETE FROM plugin_conflicts WHERE plugin = ? OR other = ?');
$stmt = $db->prepare('DELETE FROM plugin_conflicts
WHERE plugin = ? OR other = ?');
$stmt->execute([$plugin, $plugin]);
$stmt = $db->prepare('DELETE FROM plugin_depends WHERE plugin = ? OR other = ?');
$stmt = $db->prepare('DELETE FROM plugin_depends
WHERE plugin = ? OR other = ?');
$stmt->execute([$plugin, $plugin]);
}
@ -863,7 +877,7 @@ class helper_plugin_pluginrepo_repository extends Plugin
$releases = array_map('trim', $releases);
$releases = array_filter($releases);
foreach ($releases as $release) {
[$date, $name] = array_pad(preg_split('/(\s+"\s*|")/', $release),2, '');
[$date, $name] = array_pad(preg_split('/(\s+"\s*|")/', $release), 2, '');
$name = strtolower($name);
$rel = [
'date' => $date,
@ -1074,7 +1088,8 @@ class helper_plugin_pluginrepo_repository extends Plugin
$db->exec('CREATE TABLE plugin_depends (plugin varchar(50) NOT NULL, other varchar(50) NOT NULL);');
$db->exec('CREATE TABLE plugin_similar (plugin varchar(50) NOT NULL, other varchar(50) NOT NULL);');
$db->exec('CREATE TABLE plugin_tags (plugin varchar(50) NOT NULL, tag varchar(255) NOT NULL);');
$db->exec('CREATE TABLE plugins (plugin varchar(50) PRIMARY KEY NOT NULL, name varchar(255) default NULL,
$db->exec('CREATE TABLE plugins (
plugin varchar(50) PRIMARY KEY NOT NULL, name varchar(255) default NULL,
description varchar(255) default NULL, author varchar(255) default NULL, email varchar(255) default NULL,
compatible varchar(255) default NULL, lastupdate date default NULL, downloadurl varchar(255) default NULL,
bugtracker varchar(255) default NULL, sourcerepo varchar(255) default NULL,
@ -1082,8 +1097,7 @@ class helper_plugin_pluginrepo_repository extends Plugin
screenshot varchar(255) default NULL, tags varchar(255) default NULL,
securitywarning varchar(255) default NULL, securityissue varchar(255) NOT NULL,
bestcompatible varchar(50) default NULL, popularity int default 0,
updatemessage varchar(50) default NULL);'
);
updatemessage varchar(50) default NULL);');
}
/**

View File

@ -11,18 +11,18 @@
* Parameters:
* - output: rss, pie, line, table(default)
* - key: submitted fields by popularity plugin (required)
* e.g. page_size, media_size, webserver, php_version, attic_avg, attic_biggest, attic_count, attic_oldest,
* attic_size, attic_smallest, cache_avg, cache_biggest, cache_count, cache_size, cache_smallest, conf_authtype,
* conf_template, conf_useacl, edits_per_day, index_avg, index_biggest, index_count, index_size, index_smallest,
* language, media_avg, media_biggest, media_count, media_nscount, media_nsnest, media_smallest, meta_avg,
* meta_biggest, meta_count, meta_size, meta_smallest, now, os, page_avg, page_biggest, page_count,
* page_nscount, page_nsnest, page_oldest, page_smallest, pcre_backtrack, pcre_recursion, pcre_version,
* php_exectime, php_extension, php_memory, php_sapi, plugin, popauto, popversion, user_count
* e.g. page_size, media_size, webserver, php_version, attic_avg, attic_biggest, attic_count, attic_oldest,
* attic_size, attic_smallest, cache_avg, cache_biggest, cache_count, cache_size, cache_smallest, conf_authtype,
* conf_template, conf_useacl, edits_per_day, index_avg, index_biggest, index_count, index_size, index_smallest,
* language, media_avg, media_biggest, media_count, media_nscount, media_nsnest, media_smallest, meta_avg,
* meta_biggest, meta_count, meta_size, meta_smallest, now, os, page_avg, page_biggest, page_count,
* page_nscount, page_nsnest, page_oldest, page_smallest, pcre_backtrack, pcre_recursion, pcre_version,
* php_exectime, php_extension, php_memory, php_sapi, plugin, popauto, popversion, user_count
* - limit: number of results shown, when more the rest is summarized as 'other'. -1 shows all results (default 5)
* - w: image width (only charts, default 450px)
* - h: image height (only charts, default 180px)
* - o: ordered by 'cnt' for counts (default) or 'val' for values ('val' is only default for line chart)
* - p: if true use percentages(default), otherwise absolute numbers (absolute numbers is only default for line chart)
* - p: if true use percentages(default), otherwise absolute numbers (absolute is only default for line chart)
* - s: (optional) start date, show only submits after this date
* - e: (optional) end date, when start date set, show only until this date
* - d: (optional) when no start date set, shows the submits of last d days
@ -204,7 +204,7 @@ function buildUnencodedURLparams($params, $sep = '&')
$amp = true;
}
return $url;
};
}
/**
* Format the number, as percentage or number

View File

@ -119,7 +119,8 @@ function getRepository()
} else {
$feed .= '<screenshoturl>' . hsc($plugin['screenshot']) . '</screenshoturl>';
}
$feed .= '<thumbnailurl>' . hsc(ml($plugin['screenshot'], ['cache' => 'cache', 'w' => 120, 'h' => 70], true, '&', true)) . '</thumbnailurl>';
$param = ['cache' => 'cache', 'w' => 120, 'h' => 70];
$feed .= '<thumbnailurl>' . hsc(ml($plugin['screenshot'], $param, true, '&', true)) . '</thumbnailurl>';
}
$feed .= '<downloadurl>' . hsc($plugin['downloadurl']) . '</downloadurl>';

View File

@ -105,7 +105,7 @@ class syntax_plugin_pluginrepo_news extends SyntaxPlugin
* headline: headline of new block
* link: link shown at the bottom of the news block
* linktext: text for the link
* style: 'sameauthor' shows extensions of the same author (only on extension page), otherwise random picked
* style: 'sameauthor' shows extensions of the same author (only on extension page), otherwise random pick
* ..more see functions below
* @return boolean rendered correctly? (however, returned value is not used at the moment)
* @throws Exception

View File

@ -183,7 +183,7 @@ class syntax_plugin_pluginrepo_query extends SyntaxPlugin
if (!$values) {
$values = [''];
}
if($data['headline']) {
if ($data['headline']) {
$headline = $data['headline'];
} else {
$headline = 'Plugins WHERE ' . vsprintf(str_replace('?', '%s', $wheresql), $values);

View File

@ -164,20 +164,23 @@ class syntax_plugin_pluginrepo_table extends SyntaxPlugin
$searchNS = $ID;
}
$R->doc .= '<p>';
$R->doc .= $this->getLang('t_searchintro_' . noNS($ID));
$R->doc .= '</p>';
$R->doc .= '<form action="' . wl() . '" accept-charset="utf-8" class="plugin-search" id="dw__search2" method="get">';
$R->doc .= ' <div class="no">';
$R->doc .= ' <input type="hidden" name="do" value="search" />';
$R->doc .= ' <input type="hidden" id="dw__ns" name="ns" value="' . $searchNS . '" />';
$R->doc .= ' <input type="text" id="qsearch2__in" accesskey="f" name="id" class="edit" />';
$R->doc .= ' <input type="submit" value="' . $this->getLang('t_btn_search') . '" class="button" title="'
. $this->getLang('t_btn_searchtip') . '" />';
$R->doc .= ' <div id="qsearch2__out" class="ajax_qsearch JSpopup"></div>';
$R->doc .= ' </div>';
$R->doc .= '</form>';
$intro = $this->getLang('t_searchintro_' . noNS($ID));
$url = wl();
$R->doc .= <<<HTML
<p>
$intro
</p>
<form action="{$url}" accept-charset="utf-8" class="plugin-search" id="dw__search2" method="get">
<div class="no">
<input type="hidden" name="do" value="search" />
<input type="hidden" id="dw__ns" name="ns" value="$searchNS" />
<input type="text" id="qsearch2__in" accesskey="f" name="id" class="edit" />
<input type="submit" value="{$this->getLang('t_btn_search')}"
class="button" title="{$this->getLang('t_btn_searchtip')}" />
<div id="qsearch2__out" class="ajax_qsearch JSpopup"></div>
</div>
</form>
HTML;
}
/**
@ -262,7 +265,7 @@ class syntax_plugin_pluginrepo_table extends SyntaxPlugin
}
$min = $tag['cnt'];
}
$this->cloud_weight($tags, $min, $max, 5);
$this->cloudWeight($tags, $min, $max, 5);
ksort($tags);
if (count($tags) > 0) {
@ -284,7 +287,7 @@ class syntax_plugin_pluginrepo_table extends SyntaxPlugin
* @param int $max
* @param int $levels
*/
public function cloud_weight(&$tags, $min, $max, $levels)
public function cloudWeight(&$tags, $min, $max, $levels)
{
// calculate tresholds
$tresholds = [];