Skip to content

Commit

Permalink
🤖 Rector and PHPCS fixes (#42)
Browse files Browse the repository at this point in the history
Co-authored-by: mprins <mprins@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and mprins authored Nov 8, 2023
1 parent a0827b4 commit fe957bb
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions syntax.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use dokuwiki\Extension\SyntaxPlugin;

/**
* DokuWiki Syntax Plugin Backlinks.
*
Expand All @@ -13,34 +16,37 @@
* @author Michael Klier <chi@chimeric.de>
* @author Mark C. Prins <mprins@users.sf.net>
*/

/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class.
*/
class syntax_plugin_backlinks extends DokuWiki_Syntax_Plugin {
class syntax_plugin_backlinks extends SyntaxPlugin
{
/**
* Syntax Type.
*
* Needs to return one of the mode types defined in $PARSER_MODES in parser.php.
*
* @see DokuWiki_Syntax_Plugin::getType()
*/
public function getType() {
public function getType()
{
return 'substition';
}

/**
* @see DokuWiki_Syntax_Plugin::getPType()
*/
public function getPType() {
public function getPType()
{
return 'block';
}

/**
* @see Doku_Parser_Mode::getSort()
*/
public function getSort() {
public function getSort()
{
return 304;
}

Expand All @@ -49,7 +55,8 @@ public function getSort() {
*
* @see Doku_Parser_Mode::connectTo()
*/
public function connectTo($mode) {
public function connectTo($mode)
{
$this->Lexer->addSpecialPattern('\{\{backlinks>.+?\}\}', $mode, 'plugin_backlinks');
}

Expand All @@ -58,41 +65,43 @@ public function connectTo($mode) {
*
* @see DokuWiki_Syntax_Plugin::handle()
*/
public function handle($match, $state, $pos, Doku_Handler $handler) {
public function handle($match, $state, $pos, Doku_Handler $handler)
{
// strip {{backlinks> from start and }} from end
$match = substr($match, 12, -2);

$includeNS = '';
if(strstr($match, "#")) {
if (strstr($match, "#")) {
$includeNS = substr(strstr($match, "#", false), 1);
$match = strstr($match, "#", true);
}

return (array($match, $includeNS));
return ([$match, $includeNS]);
}

/**
* Handles the actual output creation.
*
* @see DokuWiki_Syntax_Plugin::render()
*/
public function render($format, Doku_Renderer $renderer, $data) {
public function render($format, Doku_Renderer $renderer, $data)
{
global $lang;
global $INFO;
global $ID;

$id = $ID;
// If it's a sidebar, get the original id.
if($INFO != null) {
if ($INFO != null) {
$id = $INFO['id'];
}
$match = $data[0];
$match = ($match == '.') ? $id : $match;
if(strstr($match, ".:")) {
if (strstr($match, ".:")) {
resolve_pageid(getNS($id), $match, $exists);
}

if($format == 'xhtml') {
if ($format == 'xhtml') {
$renderer->info['cache'] = false;

$backlinks = ft_backlinks($match);
Expand All @@ -102,34 +111,31 @@ public function render($format, Doku_Renderer $renderer, $data) {
$renderer->doc .= '<div id="plugin__backlinks">' . "\n";

$filterNS = $data[1];
if(!empty($backlinks) && !empty($filterNS)) {
if(stripos($filterNS, "!", 0) === 0) {
if (!empty($backlinks) && !empty($filterNS)) {
if (stripos($filterNS, "!", 0) === 0) {
$filterNS = substr($filterNS, 1);
dbglog($filterNS, "backlinks: exluding all of namespace: $filterNS");
$backlinks = array_filter(
$backlinks, function ($ns) use ($filterNS) {
return stripos($ns, $filterNS, 0) !== 0;
}
$backlinks,
static fn($ns) => stripos($ns, $filterNS, 0) !== 0
);
} else {
dbglog($filterNS, "backlinks: including namespace: $filterNS only");
$backlinks = array_filter(
$backlinks, function ($ns) use ($filterNS) {
return stripos($ns, $filterNS, 0) === 0;
}
$backlinks,
static fn($ns) => stripos($ns, (string) $filterNS, 0) === 0
);
}
}

dbglog($backlinks, "backlinks: all backlinks to be rendered");

if(!empty($backlinks)) {

if (!empty($backlinks)) {
$renderer->doc .= '<ul class="idx">';

foreach($backlinks as $backlink) {
foreach ($backlinks as $backlink) {
$name = p_get_metadata($backlink, 'title');
if(empty($name)) {
if (empty($name)) {
$name = $backlink;
}
$renderer->doc .= '<li><div class="li">';
Expand Down

0 comments on commit fe957bb

Please sign in to comment.