Skip to content

Commit

Permalink
shortening lines, little reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Klap-in committed Oct 27, 2023
1 parent ec0643c commit 4d75850
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 117 deletions.
6 changes: 4 additions & 2 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public function _cleanOldEntry(Event $event)
global $ID;

$data = $event->data;
$haspluginentry = preg_match('/----+ *plugin *-+/', $data[0][1]); // addSpecialPattern: ----+ *plugin *-+\n.*?\n----+
$hastemplateentry = preg_match('/----+ *template *-+/', $data[0][1]); // addSpecialPattern: ----+ *template *-+\n.*?\n----+
// addSpecialPattern: ----+ *plugin *-+\n.*?\n----+
$haspluginentry = preg_match('/----+ *plugin *-+/', $data[0][1]);
// addSpecialPattern: ----+ *template *-+\n.*?\n----+
$hastemplateentry = preg_match('/----+ *template *-+/', $data[0][1]);
if ($haspluginentry || $hastemplateentry) {
return; // plugin seems still to be there
}
Expand Down
22 changes: 11 additions & 11 deletions helper/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,24 +762,24 @@ public function cleanCompat($compatible, $onlyCompatibleReleases = true)
{
if (!$this->dokuReleases) {
$this->dokuReleases = [];
$releases = explode(',', $this->getConf('releases'));
$releases = array_map('trim', $releases);
$releases = array_filter($releases);
$releases = explode(',', $this->getConf('releases'));
$releases = array_map('trim', $releases);
$releases = array_filter($releases);
foreach ($releases as $release) {
[$date, $name] = preg_split('/(\s+"\s*|")/', $release);
$name = strtolower($name);
$rel = ['date' => $date, 'name' => $name];
$rel['label'] = ($name ? '"' . ucwords($name) . '"' : '');
$name = strtolower($name);
$rel = ['date' => $date, 'name' => $name];
$rel['label'] = ($name ? '"' . ucwords($name) . '"' : '');
$this->dokuReleases[$date] = $rel;
}
}
preg_match_all('/(!?\d\d\d\d-\d\d-\d\d\+?|!?[a-z A-Z]{4,}\+?)/', $compatible, $matches);
$matches[0] = array_map('strtolower', $matches[0]);
$matches[0] = array_map('trim', $matches[0]);
$retval = [];
$matches[0] = array_map('strtolower', $matches[0]);
$matches[0] = array_map('trim', $matches[0]);
$retval = [];
$implicitCompatible = false;
$nextImplicitCompatible = false;
$dokuReleases = $this->dokuReleases;
$dokuReleases = $this->dokuReleases;
ksort($dokuReleases);
foreach ($dokuReleases as $release) {
$isCompatible = true;
Expand All @@ -793,7 +793,7 @@ public function cleanCompat($compatible, $onlyCompatibleReleases = true)
}
if ($nextImplicitCompatible || !$isCompatible || in_array($release['date'], $matches[0]) || in_array($release['name'], $matches[0]) || $implicitCompatible) {
if (!$onlyCompatibleReleases || $isCompatible) {
$retval[$release['date']]['label'] = $release['label'];
$retval[$release['date']]['label'] = $release['label'];
$retval[$release['date']]['implicit'] = $implicitCompatible;
$retval[$release['date']]['isCompatible'] = $isCompatible;
}
Expand Down
21 changes: 11 additions & 10 deletions popularity.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
define('DOKU_INC', __DIR__ . '/../../../');
}
require_once(DOKU_INC . 'inc/init.php');

require_once(DOKU_PLUGIN . 'pluginrepo/helper/repository.php');

//close session
Expand Down Expand Up @@ -274,22 +273,24 @@ function xml_rss($counts, $usepercentage, $limit)
$other = 0;

header('Content-Type: text/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="utf-8"?>' . NL;
echo '<rss version="0.91">' . NL;
echo '<channel>' . NL;
echo '<?xml version="1.0" encoding="utf-8"?>';
echo '<rss version="0.91">';
echo '<channel>';
foreach ($counts as $count) {
if ($limit > 0 && ++$cnt > $limit) {
$other += $count['cnt'];
} else {
echo ' <item>' . NL;
echo ' <title>' . formatNumber($count['cnt'], $usepercentage) . ' ' . htmlspecialchars($count['val']) . '</title>' . NL;
echo ' </item>' . NL;
echo '<item>';
echo ' <title>';
echo formatNumber($count['cnt'], $usepercentage) . ' ' . htmlspecialchars($count['val']);
echo ' </title>';
echo '</item>';
}
}
if ($other > 0) {
echo ' <item>' . NL;
echo ' <title>' . formatNumber($other, $usepercentage) . ' other</title>' . NL;
echo ' </item>' . NL;
echo '<item>';
echo ' <title>' . formatNumber($other, $usepercentage) . ' other</title>';
echo '</item>';
}
echo '</channel>';
echo '</rss>';
Expand Down
114 changes: 60 additions & 54 deletions syntax/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ public function render($format, Doku_Renderer $renderer, $data)
switch ($format) {
case 'xhtml':
/** @var Doku_Renderer_xhtml $renderer */
$this->_showData($data, $id, $renderer);
$this->showData($data, $id, $renderer);
return true;
case 'metadata':
/** @var Doku_Renderer_metadata $renderer */
// only save if in first level namespace to ignore translated namespaces, and only plugins or templates
if (substr_count($ID, ':') == 1 && (curNS($ID) == 'plugin' || curNS($ID) == 'template')) {
$this->_saveData($data, $id, $renderer->meta['title']);
$this->saveData($data, $id, $renderer->meta['title']);
}
return true;
default:
Expand All @@ -128,7 +128,7 @@ public function render($format, Doku_Renderer $renderer, $data)
* @param string $id plugin/template id
* @param Doku_Renderer_xhtml $R
*/
protected function _showData($data, $id, $R)
protected function showData($data, $id, $R)
{
$rel = $this->hlp->getPluginRelations($id);
$type = $this->hlp->parsetype($data['type']);
Expand All @@ -149,23 +149,26 @@ protected function _showData($data, $id, $R)
$R->doc .= "<div class=\"pluginrepo_entry$obsClass\">";

$R->doc .= '<div class="usageInfo">';
$uptodate = $this->_showCompatibility($R, $data);
$this->_showActionLinks($R, $data);
$uptodate = $this->showCompatibility($R, $data);
$this->showActionLinks($R, $data);
$R->doc .= '</div>';

$this->_showMainInfo($R, $data, $extensionType);
$this->_showMetaInfo($R, $data, $type, $rel);
$this->showMainInfo($R, $data, $extensionType);
$this->showMetaInfo($R, $data, $type, $rel);

$isOld = ($age >= 2) && !$uptodate && !$isBundled;

if ($rel['similar'] || $data['tags'] || $data['securitywarning'] || $data['securityissue'] || $hasUnderscoreIssue || $isOld || $isObsoleted) {
if (
$rel['similar'] || $data['tags'] || $data['securitywarning'] || $data['securityissue']
|| $hasUnderscoreIssue || $isOld || $isObsoleted
) {
$R->doc .= '<div class="moreInfo">';
$this->_showWarnings($R, $data, $hasUnderscoreIssue, $isOld, $isObsoleted, $isBundled);
$this->_showTaxonomy($R, $data, $rel);
$this->showWarnings($R, $data, $hasUnderscoreIssue, $isOld, $isObsoleted, $isBundled);
$this->showTaxonomy($R, $data, $rel);
$R->doc .= '</div>';
}

$this->_showAuthorInfo($R, $data, $rel);
$this->showAuthorInfo($R, $data, $rel);

$R->doc .= '</div>'; // pluginrepo_entry
}
Expand All @@ -175,7 +178,7 @@ protected function _showData($data, $id, $R)
* @param array $data instructions from handle()
* @param string $extensionType
*/
protected function _showMainInfo($R, $data, $extensionType)
protected function showMainInfo($R, $data, $extensionType)
{
global $ID;

Expand All @@ -188,7 +191,8 @@ protected function _showMainInfo($R, $data, $extensionType)
// icon and description
$extensionIcon = '<a class="media" href="' . wl($extensionType . 's') . '">' .
'<img alt="' . $extensionType . '" class="medialeft" src="' .
DOKU_BASE . 'lib/plugins/pluginrepo/images/dwplugin.png" width="60" height="60" /></a> ';
DOKU_BASE . 'lib/plugins/pluginrepo/images/dwplugin.png" width="60" height="60" />'
. '</a> ';
$R->doc .= '<p class="description">' . $extensionIcon . hsc($data['description']) . '</p>';

// screenshot
Expand All @@ -208,7 +212,7 @@ protected function _showMainInfo($R, $data, $extensionType)
* @param int $type
* @param array $rel relations with other extensions
*/
protected function _showMetaInfo($R, $data, $type, $rel)
protected function showMetaInfo($R, $data, $type, $rel)
{
global $ID;
$target = getNS($ID);
Expand All @@ -233,7 +237,9 @@ protected function _showMetaInfo($R, $data, $type, $rel)
// repository
if ($data['sourcerepo']) {
$R->doc .= '<dt>' . $this->getLang('sourcerepo') . '</dt>';
$R->doc .= '<dd><a class="urlextern" href="' . hsc($data['sourcerepo']) . '">' . $this->getLang('source') . '</a></dd>';
$R->doc .= '<dd>'
. '<a class="urlextern" href="' . hsc($data['sourcerepo']) . '">' . $this->getLang('source') . '</a>'
. '</dd>';
}

// conflicts
Expand All @@ -259,7 +265,7 @@ protected function _showMetaInfo($R, $data, $type, $rel)
* @param array $data instructions from handle()
* @return bool
*/
protected function _showCompatibility($R, $data)
protected function showCompatibility($R, $data)
{
$R->doc .= '<div class="compatibility">';
$R->doc .= '<p class="label">' . $this->hlp->renderCompatibilityHelp() . '</p>';
Expand Down Expand Up @@ -321,7 +327,7 @@ protected function _showCompatibility($R, $data)
* @param Doku_Renderer_xhtml $R
* @param array $data instructions from handle()
*/
protected function _showActionLinks($R, $data)
protected function showActionLinks($R, $data)
{
if ($data['downloadurl'] || $data['bugtracker'] || $data['donationurl']) {
$R->doc .= '<ul class="actions">';
Expand Down Expand Up @@ -349,7 +355,7 @@ protected function _showActionLinks($R, $data)
* @param bool $isObsoleted
* @param bool $isBundled
*/
protected function _showWarnings($R, $data, $hasUnderscoreIssue, $isOld, $isObsoleted, $isBundled)
protected function showWarnings($R, $data, $hasUnderscoreIssue, $isOld, $isObsoleted, $isBundled)
{
global $ID;

Expand Down Expand Up @@ -410,7 +416,7 @@ protected function _showWarnings($R, $data, $hasUnderscoreIssue, $isOld, $isObso
* @param array $data instructions from handle()
* @param array $rel
*/
protected function _showTaxonomy($R, $data, $rel)
protected function showTaxonomy($R, $data, $rel)
{
global $ID;
$target = getNS($ID);
Expand Down Expand Up @@ -443,7 +449,7 @@ protected function _showTaxonomy($R, $data, $rel)
* @param array $data instructions from handle()
* @param array $rel
*/
protected function _showAuthorInfo($R, $data, $rel)
protected function showAuthorInfo($R, $data, $rel)
{
$R->doc .= '<div class="authorInfo">';

Expand Down Expand Up @@ -481,7 +487,7 @@ protected function _showAuthorInfo($R, $data, $rel)
* @param string $id plugin/template id
* @param string $name page title
*/
protected function _saveData($data, $id, $name)
protected function saveData($data, $id, $name)
{
$db = $this->hlp->_getPluginsDB();
if (!$db) {
Expand Down Expand Up @@ -538,40 +544,40 @@ protected function _saveData($data, $id, $name)
$duplicate = '';
}

$stmt = $db->prepare($insert . ' INTO plugins
(plugin, name, description,
author, email,
compatible, bestcompatible, lastupdate, securityissue, securitywarning,
downloadurl, bugtracker, sourcerepo, donationurl,
screenshot, tags, type)
VALUES
(:plugin, :name, :description,
:author, LOWER(:email),
:compatible, :bestcompatible, :lastupdate, :securityissue, :securitywarning,
:downloadurl, :bugtracker, :sourcerepo, :donationurl,
:screenshot, :tags, :type)
' . $duplicate);
$stmt->execute(
[
':plugin' => $id,
':name' => $name,
':description' => $data['description'],
':author' => $data['author'],
':email' => $data['email'],
':compatible' => $data['compatible'],
':bestcompatible' => $compatible,
':lastupdate' => $data['lastupdate'],
':securityissue' => $data['securityissue'],
':securitywarning' => $data['securitywarning'],
':downloadurl' => $data['downloadurl'],
':bugtracker' => $data['bugtracker'],
':sourcerepo' => $data['sourcerepo'],
':donationurl' => $data['donationurl'],
':screenshot' => $data['screenshot_img'],
':tags' => $data['tags'],
':type' => $type
]
$stmt = $db->prepare(
$insert . ' INTO plugins
(plugin, name, description,
author, email,
compatible, bestcompatible, lastupdate, securityissue, securitywarning,
downloadurl, bugtracker, sourcerepo, donationurl,
screenshot, tags, type)
VALUES
(:plugin, :name, :description,
:author, LOWER(:email),
:compatible, :bestcompatible, :lastupdate, :securityissue, :securitywarning,
:downloadurl, :bugtracker, :sourcerepo, :donationurl,
:screenshot, :tags, :type)
' . $duplicate
);
$stmt->execute([
':plugin' => $id,
':name' => $name,
':description' => $data['description'],
':author' => $data['author'],
':email' => $data['email'],
':compatible' => $data['compatible'],
':bestcompatible' => $compatible,
':lastupdate' => $data['lastupdate'],
':securityissue' => $data['securityissue'],
':securitywarning' => $data['securitywarning'],
':downloadurl' => $data['downloadurl'],
':bugtracker' => $data['bugtracker'],
':sourcerepo' => $data['sourcerepo'],
':donationurl' => $data['donationurl'],
':screenshot' => $data['screenshot_img'],
':tags' => $data['tags'],
':type' => $type
]);

if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
$insert = 'INSERT IGNORE';
Expand Down
7 changes: 4 additions & 3 deletions syntax/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public function handle($match, $state, $pos, Doku_Handler $handler)
* @param Doku_Renderer $renderer the current renderer object
* @param array $data data created by handler() used entries:
* headline: headline of new block
* link: link shown at the bottom of the news 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 picked
* ..more see functions below
* @return boolean rendered correctly? (however, returned value is not used at the moment)
* @return boolean rendered correctly? (however, returned value is not used at the moment)
*/
public function render($format, Doku_Renderer $renderer, $data)
{
Expand Down Expand Up @@ -162,6 +162,7 @@ public function showSameAuthor($R, $data)
* screenshot: if 'yes' a screenshot is shown
* and used by the filtering:
*
* @throws Exception
*/
public function showDefault($R, $data)
{
Expand Down
10 changes: 7 additions & 3 deletions syntax/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public function render($format, Doku_Renderer $R, $data)
$counter = count($fields);
for ($fieldItr = 0; $fieldItr < $counter; $fieldItr++) {
if (!in_array($fields[$fieldItr], $this->allowedfields)) {
$R->doc .= '<div class="error repoquery"><strong>Repoquery error - Unknown field:</strong> ' . hsc($fields[$fieldItr]) . '</div>';
$R->doc .= '<div class="error repoquery">'
. '<strong>Repoquery error - Unknown field:</strong> ' . hsc($fields[$fieldItr])
. '</div>';
return true;
}
}
Expand All @@ -130,7 +132,9 @@ public function render($format, Doku_Renderer $R, $data)
}
$error = preg_replace('/(LIKE|AND|OR|NOT|IS|NULL|[<>=\?\(\)])/i', '', $error);
if (trim($error)) {
$R->doc .= '<div class="error repoquery"><strong>Repoquery error - Unsupported chars in WHERE clause:</strong> ' . hsc($error) . '</div>';
$R->doc .= '<div class="error repoquery">'
. '<strong>Repoquery error - Unsupported chars in WHERE clause:</strong> ' . hsc($error)
. '</div>';
return true;
}
$wheresql = $data['where'];
Expand All @@ -141,7 +145,7 @@ public function render($format, Doku_Renderer $R, $data)
ORDER BY $ordersql");

// prepare VALUES input and execute query
$values = preg_split("/,/", $data['values']);
$values = explode(",", $data['values']);
$values = array_map('trim', $values);
$values = array_filter($values);
if (!$values && array_key_exists('values', $data)) {
Expand Down
Loading

0 comments on commit 4d75850

Please sign in to comment.