diff --git a/.github/workflows/dokuwiki.yml b/.github/workflows/dokuwiki.yml
new file mode 100644
index 0000000..d168d76
--- /dev/null
+++ b/.github/workflows/dokuwiki.yml
@@ -0,0 +1,11 @@
+name: DokuWiki Default Tasks
+on:
+ push:
+ pull_request:
+ schedule:
+ - cron: '16 8 25 * *'
+
+
+jobs:
+ all:
+ uses: dokuwiki/github-action/.github/workflows/all.yml@main
diff --git a/.github/workflows/phpTestLinux.yml b/.github/workflows/phpTestLinux.yml
deleted file mode 100644
index 82b3625..0000000
--- a/.github/workflows/phpTestLinux.yml
+++ /dev/null
@@ -1,52 +0,0 @@
-name: PHP Tests on Linux
-
-on: [push, pull_request]
-
-jobs:
- testLinux:
- name: PHP ${{ matrix.php-versions }} DokuWiki ${{ matrix.dokuwiki-branch }}
- runs-on: ubuntu-latest
- if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
-
- strategy:
- matrix:
- php-versions: ['7.2', '7.3', '7.4', '8.0']
- dokuwiki-branch: [ 'master', 'stable']
- exclude:
- - dokuwiki-branch: 'stable'
- php-versions: '8.0'
- fail-fast: false
-
- steps:
- - name: Checkout
- uses: actions/checkout@v2
-
- - name: Setup PHP
- uses: shivammathur/setup-php@v2
- with:
- php-version: ${{ matrix.php-versions }}
- extensions: mbstring, intl, PDO, pdo_sqlite, bz2
-
- - name: Setup problem matchers
- run: |
- echo ::add-matcher::${{ runner.tool_cache }}/php.json
- echo ::add-matcher::${{ runner.tool_cache }}/phpunit.json
-
- - name: Download DokuWiki Test-setup
- run: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh
-
- - name: Run DokuWiki Test-setup
- env:
- CI_SERVER: 1
- DOKUWIKI: ${{ matrix.dokuwiki-branch }}
- run: sh travis.sh
-
- - name: Setup PHPUnit
- run: |
- php _test/fetchphpunit.php
- cd _test
-
- - name: Run PHPUnit
- run: |
- cd _test
- php phpunit.phar --verbose --stderr --group plugin_data
diff --git a/Form/DropdownElement.php b/Form/DropdownElement.php
index 3006b0e..7ee932e 100644
--- a/Form/DropdownElement.php
+++ b/Form/DropdownElement.php
@@ -2,6 +2,7 @@
namespace dokuwiki\plugin\data\Form;
+use dokuwiki\Form\InputElement;
use dokuwiki\Form\OptGroup;
/**
@@ -14,7 +15,7 @@ class DropdownElement extends \dokuwiki\Form\DropdownElement
protected $values = [];
/** @var \dokuwiki\plugin\data\Form\OptGroup[] */
- protected $optGroups = array();
+ protected $optGroups = [];
/**
@@ -27,7 +28,7 @@ class DropdownElement extends \dokuwiki\Form\DropdownElement
*/
public function __construct($name, $options, $label = '')
{
- \dokuwiki\Form\InputElement::__construct('dropdown', $name, $label);
+ InputElement::__construct('dropdown', $name, $label);
$this->rmattr('type');
$this->optGroups[''] = new \dokuwiki\plugin\data\Form\OptGroup(null, $options);
$this->val('');
@@ -69,7 +70,7 @@ public function val($value = null)
*/
public function attr($name, $value = null)
{
- return \dokuwiki\Form\InputElement::attr($name, $value);
+ return InputElement::attr($name, $value);
}
/**
@@ -143,5 +144,4 @@ function ($html, OptGroup $optGroup) {
return $html;
}
-
}
diff --git a/_test/action_edit_button.test.php b/_test/action_edit_button.test.php
index 1a1dfa0..6d08703 100644
--- a/_test/action_edit_button.test.php
+++ b/_test/action_edit_button.test.php
@@ -16,7 +16,7 @@ function testSetName()
'target' => 'plugin_data'
);
$event = new Doku_Event('', $data);
- $action->_editbutton($event, null);
+ $action->editButton($event, null);
$this->assertTrue(isset($data['name']));
}
@@ -28,7 +28,7 @@ function testWrongTarget()
'target' => 'default target'
);
$event = new Doku_Event('', $data);
- $action->_editbutton($event, null);
+ $action->editButton($event, null);
$this->assertFalse(isset($data['name']));
}
diff --git a/_test/action_handle.test.php b/_test/action_handle.test.php
index 0e78707..b0ab653 100644
--- a/_test/action_handle.test.php
+++ b/_test/action_handle.test.php
@@ -8,7 +8,6 @@
*/
class action_handle_test extends DokuWikiTest
{
-
protected $pluginsEnabled = array('data', 'sqlite');
protected $action;
@@ -30,7 +29,7 @@ public function setUp(): void
$this->action = new action_plugin_data();
$this->helper = plugin_load('helper', 'data');
- $this->db = $this->helper->_getDB();
+ $this->db = $this->helper->getDB();
$this->db->exec(
'INSERT INTO pages ( pid, page, title , class , lastmod) VALUES (?, ?, ?, ?, ?)',
@@ -38,7 +37,7 @@ public function setUp(): void
);
}
- function testHandleStillPresent()
+ public function testHandleStillPresent()
{
$data = array(
@@ -49,13 +48,13 @@ function testHandleStillPresent()
2 => 'test'
);
$event = new Doku_Event('', $data);
- $this->action->_handle($event, null);
+ $this->action->handle($event, null);
$pid = $this->getTestPageId();
$this->assertFalse(!$pid);
}
- function testHandleDelete()
+ public function testHandleDelete()
{
$data = array(
0 => array(
@@ -66,7 +65,7 @@ function testHandleDelete()
);
$event = new Doku_Event('', $data);
- $this->action->_handle($event, null);
+ $this->action->handle($event, null);
$pid = $this->db->queryValue('SELECT pid FROM pages WHERE page = ?', 'test');
$this->assertTrue(!$pid);
diff --git a/_test/helper.test.php b/_test/helper.test.php
index 7eb3621..ea0e85a 100644
--- a/_test/helper.test.php
+++ b/_test/helper.test.php
@@ -31,37 +31,37 @@ function testCleanData()
$helper = new helper_plugin_data();
- $this->assertEquals('', $helper->_cleanData(' ', ''));
- $this->assertEquals('', $helper->_cleanData('', ''));
- $this->assertEquals('', $helper->_cleanData(null, ''));
- $this->assertEquals('', $helper->_cleanData(false, ''));
-
- $this->assertEquals('', $helper->_cleanData('', 'dt'));
- $this->assertEquals('', $helper->_cleanData('this is not a date', 'dt'));
- $this->assertEquals('1234-01-01', $helper->_cleanData('1234-1-1', 'dt'));
- $this->assertEquals('1234-01-01', $helper->_cleanData('1234-01-01', 'dt'));
- $this->assertEquals('%now%', $helper->_cleanData('%now%', 'dt'));
- $this->assertEquals('', $helper->_cleanData('1234-01-011', 'dt'));
-
- $this->assertEquals('http://bla', $helper->_cleanData('bla', 'url'));
- $this->assertEquals('http://bla', $helper->_cleanData('http://bla', 'url'));
- $this->assertEquals('https://bla', $helper->_cleanData('https://bla', 'url'));
- $this->assertEquals('tell://bla', $helper->_cleanData('tell://bla', 'url'));
-
- $this->assertEquals('bla@bla.de', $helper->_cleanData('bla@bla.de', 'mail'));
- $this->assertEquals('bla@bla.de bla', $helper->_cleanData('bla@bla.de bla', 'mail'));
- $this->assertEquals('bla@bla.de bla word', $helper->_cleanData('bla@bla.de bla word', 'mail'));
- $this->assertEquals('bla@bla.de bla bla word', $helper->_cleanData('bla bla@bla.de bla word', 'mail'));
- $this->assertEquals('bla@bla.de bla bla word', $helper->_cleanData(' bla bla@bla.de bla word ', 'mail'));
-
- $this->assertEquals('123', $helper->_cleanData('123', 'page'));
- $this->assertEquals('123_123', $helper->_cleanData('123 123', 'page'));
- $this->assertEquals('123', $helper->_cleanData('123', 'nspage'));
-
- $this->assertEquals('test', $helper->_cleanData('test', ''));
-
- $this->assertEquals('test', $helper->_cleanData('test', array('type' => '')));
- $this->assertEquals('', $helper->_cleanData('test', array('type' => '', 'enum' => 'some other')));
+ $this->assertEquals('', $helper->cleanData(' ', ''));
+ $this->assertEquals('', $helper->cleanData('', ''));
+ $this->assertEquals('', $helper->cleanData(null, ''));
+ $this->assertEquals('', $helper->cleanData(false, ''));
+
+ $this->assertEquals('', $helper->cleanData('', 'dt'));
+ $this->assertEquals('', $helper->cleanData('this is not a date', 'dt'));
+ $this->assertEquals('1234-01-01', $helper->cleanData('1234-1-1', 'dt'));
+ $this->assertEquals('1234-01-01', $helper->cleanData('1234-01-01', 'dt'));
+ $this->assertEquals('%now%', $helper->cleanData('%now%', 'dt'));
+ $this->assertEquals('', $helper->cleanData('1234-01-011', 'dt'));
+
+ $this->assertEquals('http://bla', $helper->cleanData('bla', 'url'));
+ $this->assertEquals('http://bla', $helper->cleanData('http://bla', 'url'));
+ $this->assertEquals('https://bla', $helper->cleanData('https://bla', 'url'));
+ $this->assertEquals('tell://bla', $helper->cleanData('tell://bla', 'url'));
+
+ $this->assertEquals('bla@bla.de', $helper->cleanData('bla@bla.de', 'mail'));
+ $this->assertEquals('bla@bla.de bla', $helper->cleanData('bla@bla.de bla', 'mail'));
+ $this->assertEquals('bla@bla.de bla word', $helper->cleanData('bla@bla.de bla word', 'mail'));
+ $this->assertEquals('bla@bla.de bla bla word', $helper->cleanData('bla bla@bla.de bla word', 'mail'));
+ $this->assertEquals('bla@bla.de bla bla word', $helper->cleanData(' bla bla@bla.de bla word ', 'mail'));
+
+ $this->assertEquals('123', $helper->cleanData('123', 'page'));
+ $this->assertEquals('123_123', $helper->cleanData('123 123', 'page'));
+ $this->assertEquals('123', $helper->cleanData('123', 'nspage'));
+
+ $this->assertEquals('test', $helper->cleanData('test', ''));
+
+ $this->assertEquals('test', $helper->cleanData('test', array('type' => '')));
+ $this->assertEquals('', $helper->cleanData('test', array('type' => '', 'enum' => 'some other')));
}
function testColumn()
@@ -69,29 +69,29 @@ function testColumn()
global $conf;
$helper = new helper_plugin_data();
- $this->assertEquals($this->createColumnEntry('type', false, 'type', 'type', 'type', ''), $helper->_column('type'));
- $this->assertEquals($this->createColumnEntry('types', true, 'type', 'type', 'type', ''), $helper->_column('types'));
- $this->assertEquals($this->createColumnEntry('', false, '', '', '', ''), $helper->_column(''));
- $this->assertEquals($this->createColumnEntry('type_url', false, 'type', 'type', 'type', 'url'), $helper->_column('type_url'));
- $this->assertEquals($this->createColumnEntry('type_urls', true, 'type', 'type', 'type', 'url'), $helper->_column('type_urls'));
+ $this->assertEquals($this->createColumnEntry('type', false, 'type', 'type', 'type', ''), $helper->column('type'));
+ $this->assertEquals($this->createColumnEntry('types', true, 'type', 'type', 'type', ''), $helper->column('types'));
+ $this->assertEquals($this->createColumnEntry('', false, '', '', '', ''), $helper->column(''));
+ $this->assertEquals($this->createColumnEntry('type_url', false, 'type', 'type', 'type', 'url'), $helper->column('type_url'));
+ $this->assertEquals($this->createColumnEntry('type_urls', true, 'type', 'type', 'type', 'url'), $helper->column('type_urls'));
- $this->assertEquals($this->createColumnEntry('type_hidden', false, 'type', 'type', 'type', 'hidden'), $helper->_column('type_hidden'));
- $this->assertEquals($this->createColumnEntry('type_hiddens', true, 'type', 'type', 'type', 'hidden'), $helper->_column('type_hiddens'));
+ $this->assertEquals($this->createColumnEntry('type_hidden', false, 'type', 'type', 'type', 'hidden'), $helper->column('type_hidden'));
+ $this->assertEquals($this->createColumnEntry('type_hiddens', true, 'type', 'type', 'type', 'hidden'), $helper->column('type_hiddens'));
- $this->assertEquals($this->createColumnEntry('%title%', false, '%title%', '%title%', 'Page', 'title'), $helper->_column('%title%'));
- $this->assertEquals($this->createColumnEntry('%pageid%', false, '%pageid%', '%pageid%', 'Title', 'page'), $helper->_column('%pageid%'));
- $this->assertEquals($this->createColumnEntry('%class%', false, '%class%', '%class%', 'Page Class', ''), $helper->_column('%class%'));
- $this->assertEquals($this->createColumnEntry('%lastmod%', false, '%lastmod%', '%lastmod%', 'Last Modified', 'timestamp'), $helper->_column('%lastmod%'));
+ $this->assertEquals($this->createColumnEntry('%title%', false, '%title%', '%title%', 'Page', 'title'), $helper->column('%title%'));
+ $this->assertEquals($this->createColumnEntry('%pageid%', false, '%pageid%', '%pageid%', 'Title', 'page'), $helper->column('%pageid%'));
+ $this->assertEquals($this->createColumnEntry('%class%', false, '%class%', '%class%', 'Page Class', ''), $helper->column('%class%'));
+ $this->assertEquals($this->createColumnEntry('%lastmod%', false, '%lastmod%', '%lastmod%', 'Last Modified', 'timestamp'), $helper->column('%lastmod%'));
- $this->assertEquals($this->createColumnEntry('Type', false, 'type', 'Type', 'Type', ''), $helper->_column('Type'));
+ $this->assertEquals($this->createColumnEntry('Type', false, 'type', 'Type', 'Type', ''), $helper->column('Type'));
// test translated key name
- $this->assertEquals($this->createColumnEntry('trans_urls', true, 'trans', 'trans', 'Translated Title', 'url'), $helper->_column('trans_urls'));
+ $this->assertEquals($this->createColumnEntry('trans_urls', true, 'trans', 'trans', 'Translated Title', 'url'), $helper->column('trans_urls'));
// retry in different language
$conf['lang'] = 'de';
$helper = new helper_plugin_data();
- $this->assertEquals($this->createColumnEntry('trans_urls', true, 'trans', 'trans', 'Übersetzter Titel', 'url'), $helper->_column('trans_urls'));
+ $this->assertEquals($this->createColumnEntry('trans_urls', true, 'trans', 'trans', 'Übersetzter Titel', 'url'), $helper->column('trans_urls'));
}
function testAddPrePostFixes()
@@ -99,16 +99,16 @@ function testAddPrePostFixes()
global $conf;
$helper = new helper_plugin_data();
- $this->assertEquals('value', $helper->_addPrePostFixes('', 'value'));
- $this->assertEquals('prevaluepost', $helper->_addPrePostFixes('', 'value', 'pre', 'post'));
- $this->assertEquals('valuepost', $helper->_addPrePostFixes('', 'value', '', 'post'));
- $this->assertEquals('prevalue', $helper->_addPrePostFixes('', 'value', 'pre'));
- $this->assertEquals('prevaluepost', $helper->_addPrePostFixes(array('prefix' => 'pre', 'postfix' => 'post'), 'value'));
+ $this->assertEquals('value', $helper->addPrePostFixes('', 'value'));
+ $this->assertEquals('prevaluepost', $helper->addPrePostFixes('', 'value', 'pre', 'post'));
+ $this->assertEquals('valuepost', $helper->addPrePostFixes('', 'value', '', 'post'));
+ $this->assertEquals('prevalue', $helper->addPrePostFixes('', 'value', 'pre'));
+ $this->assertEquals('prevaluepost', $helper->addPrePostFixes(array('prefix' => 'pre', 'postfix' => 'post'), 'value'));
$conf['lang'] = 'en';
- $this->assertEquals('envalue', $helper->_addPrePostFixes(array('prefix' => '%lang%'), 'value'));
+ $this->assertEquals('envalue', $helper->addPrePostFixes(array('prefix' => '%lang%'), 'value'));
- $this->assertEquals('value', $helper->_addPrePostFixes(array('prefix' => '%trans%'), 'value'));
+ $this->assertEquals('value', $helper->addPrePostFixes(array('prefix' => '%trans%'), 'value'));
$plugininstalled = in_array('translation', plugin_list('helper', $all = true));
if (!$plugininstalled) $this->markTestSkipped('Pre-condition not satisfied: translation plugin must be installed');
@@ -117,7 +117,7 @@ function testAddPrePostFixes()
global $ID;
$conf['plugin']['translation']['translations'] = 'de';
$ID = 'de:somepage';
- $this->assertEquals('de:value', $helper->_addPrePostFixes(array('prefix' => '%trans%:'), 'value'));
+ $this->assertEquals('de:value', $helper->addPrePostFixes(array('prefix' => '%trans%:'), 'value'));
}
}
@@ -126,11 +126,11 @@ function testResolveData()
{
$helper = new helper_plugin_data();
- $this->assertEquals('tom', $helper->_resolveData('tom', 'name'));
- $this->assertEquals('jerry', $helper->_resolveData('jerry', 'name'));
+ $this->assertEquals('tom', $helper->resolveData('tom', 'name'));
+ $this->assertEquals('jerry', $helper->resolveData('jerry', 'name'));
- $this->assertEquals('wiki:syntax Formatting Syntax', $helper->_resolveData('wiki:syntax', 'name_title'));
- $this->assertEquals('none:existing ', $helper->_resolveData('none:existing', 'name_title'));
+ $this->assertEquals('wiki:syntax Formatting Syntax', $helper->resolveData('wiki:syntax', 'name_title'));
+ $this->assertEquals('none:existing ', $helper->resolveData('none:existing', 'name_title'));
}
function testFormatData()
@@ -143,49 +143,49 @@ function testFormatData()
$renderer = new data_dummy_renderer();
$this->assertEquals('value1, value2, val',
- $helper->_formatData(array('type' => ''), "value1\n value2\n val", $renderer));
+ $helper->formatData(array('type' => ''), "value1\n value2\n val", $renderer));
$this->assertEquals('link: :page ',
- $helper->_formatData(array('type' => 'page'), "page", $renderer));
+ $helper->formatData(array('type' => 'page'), "page", $renderer));
$this->assertEquals('link: :page title',
- $helper->_formatData(array('type' => 'title'), "page|title", $renderer));
+ $helper->formatData(array('type' => 'title'), "page|title", $renderer));
$this->assertEquals('link: page title',
- $helper->_formatData(array('type' => 'pageid'), "page|title", $renderer));
+ $helper->formatData(array('type' => 'pageid'), "page|title", $renderer));
$this->assertEquals('link: :key:page ',
- $helper->_formatData(array('type' => 'nspage', 'key' => 'key'), "page", $renderer));
+ $helper->formatData(array('type' => 'nspage', 'key' => 'key'), "page", $renderer));
$conf['mailguard'] = '';
$this->assertEquals('pa:ge',
- $helper->_formatData(array('type' => 'mail'), "pa:ge", $renderer));
+ $helper->formatData(array('type' => 'mail'), "pa:ge", $renderer));
$this->assertEquals('some user',
- $helper->_formatData(array('type' => 'mail'), "pa:ge some user", $renderer));
+ $helper->formatData(array('type' => 'mail'), "pa:ge some user", $renderer));
$conf['mailguard'] = 'visible';
$this->assertEquals('pa:ge',
- $helper->_formatData(array('type' => 'mail'), "pa:ge", $renderer));
+ $helper->formatData(array('type' => 'mail'), "pa:ge", $renderer));
$this->assertEquals('some user',
- $helper->_formatData(array('type' => 'mail'), "pa:ge some user", $renderer));
+ $helper->formatData(array('type' => 'mail'), "pa:ge some user", $renderer));
$this->assertEquals('url',
- $helper->_formatData(array('type' => 'url'), "url", $renderer));
+ $helper->formatData(array('type' => 'url'), "url", $renderer));
$this->assertEquals('value',
- $helper->_formatData(array('type' => 'tag', 'key' => ''), "value", $renderer));
+ $helper->formatData(array('type' => 'tag', 'key' => ''), "value", $renderer));
$this->assertEquals(strftime('%Y/%m/%d %H:%M', 1234567),
- $helper->_formatData(array('type' => 'timestamp'), "1234567", $renderer));
+ $helper->formatData(array('type' => 'timestamp'), "1234567", $renderer));
$this->assertEquals('bla',
- $helper->_formatData(array('type' => 'wiki'), '|**bla**', $renderer));
+ $helper->formatData(array('type' => 'wiki'), '|**bla**', $renderer));
$this->assertEquals('',
- $helper->_formatData(array('type' => 'img300', 'key' => ''), 'wiki:dokuwiki-128.png', $renderer));
+ $helper->formatData(array('type' => 'img300', 'key' => ''), 'wiki:dokuwiki-128.png', $renderer));
}
function testReplacePlaceholdersInSQL()
@@ -196,20 +196,20 @@ function testReplacePlaceholdersInSQL()
$data = array('sql' => '%user%');
$INPUT->server->set('REMOTE_USER', 'test');
- $helper->_replacePlaceholdersInSQL($data);
+ $helper->replacePlaceholdersInSQL($data);
$this->assertEquals('test', $data['sql']);
$data = array('sql' => '%groups%');
$USERINFO['grps'] = array('test', 'admin');
- $helper->_replacePlaceholdersInSQL($data);
+ $helper->replacePlaceholdersInSQL($data);
$this->assertEquals("test','admin", $data['sql']);
$data = array('sql' => '%now%');
- $helper->_replacePlaceholdersInSQL($data);
+ $helper->replacePlaceholdersInSQL($data);
$this->assertRegExp('/[0-9]{4}-[0-9]{2}-[0-9]{2}/', $data['sql']);
$data = array('sql' => '%lang%');
- $helper->_replacePlaceholdersInSQL($data);
+ $helper->replacePlaceholdersInSQL($data);
$this->assertEquals('en', $data['sql']);
}
@@ -230,7 +230,7 @@ public function testNoSqlPlugin()
plugin_disable('sqlite');
$this->expectException(\Exception::class);
$helper = new helper_plugin_data();
- $helper->_getDB();
+ $helper->getDB();
}
public function testParseFilter()
@@ -238,55 +238,55 @@ public function testParseFilter()
$helper = new helper_plugin_data();
$this->assertEquals($this->createFilterArray('name', "'tom'", '=', 'name_some', 'some')
- , $helper->_parse_filter('name_some = tom'));
+ , $helper->parseFilter('name_some = tom'));
$this->assertEquals($this->createFilterArray('name', "'tom'", '=', 'name', '')
- , $helper->_parse_filter('name = tom'));
+ , $helper->parseFilter('name = tom'));
$this->assertEquals($this->createFilterArray('name', "'tom'", '!=', 'name', '')
- , $helper->_parse_filter('name != tom'));
+ , $helper->parseFilter('name != tom'));
$this->assertEquals($this->createFilterArray('name', "'tom'", '!=', 'name', '')
- , $helper->_parse_filter('name <> tom'));
+ , $helper->parseFilter('name <> tom'));
$this->assertEquals($this->createFilterArray('name', "'tom'", '<', 'name', '')
- , $helper->_parse_filter('name < tom'));
+ , $helper->parseFilter('name < tom'));
$this->assertEquals($this->createFilterArray('name', "'tom'", '>', 'name', '')
- , $helper->_parse_filter('name > tom'));
+ , $helper->parseFilter('name > tom'));
$this->assertEquals($this->createFilterArray('name', "'tom'", '<=', 'name', '')
- , $helper->_parse_filter('name <= tom'));
+ , $helper->parseFilter('name <= tom'));
$this->assertEquals($this->createFilterArray('name', "'tom'", '>=', 'name', '')
- , $helper->_parse_filter('name >= tom'));
+ , $helper->parseFilter('name >= tom'));
$this->assertEquals($this->createFilterArray('name', "'tom'", 'LIKE', 'name', '')
- , $helper->_parse_filter('name ~ tom'));
+ , $helper->parseFilter('name ~ tom'));
$this->assertEquals($this->createFilterArray('name', "'%tom%'", 'LIKE', 'name', '')
- , $helper->_parse_filter('name *~ tom'));
+ , $helper->parseFilter('name *~ tom'));
$this->assertEquals($this->createFilterArray('name', "'tom'", 'NOT LIKE', 'name', '')
- , $helper->_parse_filter('name !~ tom'));
+ , $helper->parseFilter('name !~ tom'));
$this->assertEquals($this->createFilterArray('name', "'%tom'", 'LIKE', 'name', '')
- , $helper->_parse_filter('name ~ *tom'));
+ , $helper->parseFilter('name ~ *tom'));
$this->assertEquals($this->createFilterArray('name', "'tom%'", 'LIKE', 'name', '')
- , $helper->_parse_filter('name ~ tom*'));
+ , $helper->parseFilter('name ~ tom*'));
$this->assertEquals($this->createFilterArray('name', "'%tom%'", 'LIKE', 'name', '')
- , $helper->_parse_filter('name ~ *tom*'));
+ , $helper->parseFilter('name ~ *tom*'));
$this->assertEquals($this->createFilterArray('name', "'tom'", 'IN(', 'name', '')
- , $helper->_parse_filter('name ~~ tom'));
+ , $helper->parseFilter('name ~~ tom'));
$this->assertEquals($this->createFilterArray('name', "'t''om','john*'", 'IN(', 'name', '')
- , $helper->_parse_filter("name ~~ t'om,john*"));
+ , $helper->parseFilter("name ~~ t'om,john*"));
- $this->assertEquals(false, $helper->_parse_filter('name is *tom*'));
- $this->assertEquals(false, $helper->_parse_filter(''));
+ $this->assertEquals(false, $helper->parseFilter('name is *tom*'));
+ $this->assertEquals(false, $helper->parseFilter(''));
}
protected function createFilterArray($key, $value, $compare, $colname, $type)
@@ -304,16 +304,16 @@ public function testGetFilters()
{
$helper = new helper_plugin_data();
- $this->assertEquals(array(), $helper->_get_filters());
+ $this->assertEquals(array(), $helper->getFilters());
$_REQUEST['dataflt'] = 'name = tom';
$this->assertEquals(array($this->createFilterArrayListEntry('name', "'tom'", '=', 'name', '', 'AND')),
- $helper->_get_filters());
+ $helper->getFilters());
$_REQUEST['dataflt'] = array();
$_REQUEST['dataflt'][] = 'name = tom';
$this->assertEquals(array($this->createFilterArrayListEntry('name', "'tom'", '=', 'name', '', 'AND')),
- $helper->_get_filters());
+ $helper->getFilters());
$_REQUEST['dataflt'] = array();
$_REQUEST['dataflt'][] = 'name = tom';
@@ -323,7 +323,7 @@ public function testGetFilters()
$this->createFilterArrayListEntry('name', "'tom'", '=', 'name', '', 'AND'),
$this->createFilterArrayListEntry('unit', "'http://dokuwiki.org'", '=', 'unit_url', 'url', 'AND')
),
- $helper->_get_filters());
+ $helper->getFilters());
}
private function createFilterArrayListEntry($key, $value, $compare, $colname, $type, $logic)
@@ -347,7 +347,7 @@ public function testA2UA()
'table[name]' => 'tom'
);
- $this->assertEquals($result, $helper->_a2ua('table', $array));
+ $this->assertEquals($result, $helper->a2ua('table', $array));
}
public function testMakeTranslationReplacement()
diff --git a/_test/helperAliases.test.php b/_test/helperAliases.test.php
index 1aaa771..63cfbe1 100644
--- a/_test/helperAliases.test.php
+++ b/_test/helperAliases.test.php
@@ -12,7 +12,7 @@ class helper_plugin_data_test_aliases extends DokuWikiTest
public function testAliases()
{
$helper = new helper_plugin_data();
- $db = $helper->_getDB();
+ $db = $helper->getDB();
$this->assertTrue($db !== false);
$db->exec(
'INSERT INTO aliases (name, type, prefix, postfix, enum) VALUES (?,?,?,?,?)',
@@ -26,7 +26,7 @@ public function testAliases()
'postfix' => ']]'
)
);
- $this->assertEquals($expect, $helper->_aliases());
+ $this->assertEquals($expect, $helper->aliases());
}
}
diff --git a/_test/syntax_plugin_data_entry.test.php b/_test/syntax_plugin_data_entry.test.php
index dafbb48..b384925 100644
--- a/_test/syntax_plugin_data_entry.test.php
+++ b/_test/syntax_plugin_data_entry.test.php
@@ -341,7 +341,7 @@ function testShowData()
$result = $plugin->handle($this->exampleEntry, 0, 10, $handler);
- $plugin->_showData($result, $xhtml);
+ $plugin->showData($result, $xhtml);
$doc = (new DOMWrap\Document())->html($xhtml->doc);
$this->assertEquals(1, $doc->find('div.inline.dataplugin_entry.projects')->count());
diff --git a/action.php b/action.php
index 3c4eba0..83544f6 100644
--- a/action.php
+++ b/action.php
@@ -1,26 +1,30 @@
*/
-
/**
* Class action_plugin_data
*/
-class action_plugin_data extends DokuWiki_Action_Plugin
+class action_plugin_data extends ActionPlugin
{
-
/**
* will hold the data helper plugin
* @var helper_plugin_data
*/
- var $dthlp = null;
+ public $dthlp;
/**
* Constructor. Load helper plugin
*/
- function __construct()
+ public function __construct()
{
$this->dthlp = plugin_load('helper', 'data');
}
@@ -28,29 +32,29 @@ function __construct()
/**
* Registers a callback function for a given event
*/
- function register(Doku_Event_Handler $controller)
+ public function register(EventHandler $controller)
{
- $controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, '_handle');
- $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, '_editbutton');
- $controller->register_hook('HTML_EDIT_FORMSELECTION', 'BEFORE', $this, '_editform'); // deprecated
- $controller->register_hook('EDIT_FORM_ADDTEXTAREA', 'BEFORE', $this, '_editform'); // replacement
- $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, '_handle_edit_post');
- $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, '_handle_ajax');
+ $controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'handle');
+ $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, 'editButton');
+ $controller->register_hook('HTML_EDIT_FORMSELECTION', 'BEFORE', $this, 'editForm'); // deprecated
+ $controller->register_hook('EDIT_FORM_ADDTEXTAREA', 'BEFORE', $this, 'editForm'); // replacement
+ $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleEditPost');
+ $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjax');
}
/**
* Handles the page write event and removes the database info
* when the plugin code is no longer in the source
*
- * @param Doku_Event $event
+ * @param Event $event
* @param null $param
*/
- function _handle(Doku_Event $event, $param)
+ public function handle(Event $event, $param)
{
$data = $event->data;
if (strpos($data[0][1], 'dataentry') !== false) return; // plugin seems still to be there
- $sqlite = $this->dthlp->_getDB();
+ $sqlite = $this->dthlp->getDB();
if (!$sqlite) return;
$id = ltrim($data[1] . ':' . $data[2], ':');
@@ -63,10 +67,10 @@ function _handle(Doku_Event $event, $param)
}
/**
- * @param Doku_Event $event
+ * @param Event $event
* @param null $param
*/
- function _editbutton($event, $param)
+ public function editButton($event, $param)
{
if ($event->data['target'] !== 'plugin_data') {
return;
@@ -76,10 +80,10 @@ function _editbutton($event, $param)
}
/**
- * @param Doku_Event $event
+ * @param Event $event
* @param null $param
*/
- function _editform(Doku_Event $event, $param)
+ public function editForm(Event $event, $param)
{
global $TEXT;
if ($event->data['target'] !== 'plugin_data') {
@@ -94,7 +98,7 @@ function _editform(Doku_Event $event, $param)
echo $this->locale_xhtml('edit_intro' . ($this->getConf('edit_content_only') ? '_contentonly' : ''));
- require_once 'renderer_data_edit.php';
+ require_once __DIR__ . '/renderer_data_edit.php';
$Renderer = new Doku_Renderer_plugin_data_edit();
$Renderer->form = $event->data['form'];
@@ -102,28 +106,28 @@ function _editform(Doku_Event $event, $param)
$instructions = p_get_instructions($TEXT);
foreach ($instructions as $instruction) {
// Execute the callback against the Renderer
- call_user_func_array(array($Renderer, $instruction[0]), $instruction[1]);
+ call_user_func_array([$Renderer, $instruction[0]], $instruction[1]);
}
}
/**
- * @param Doku_Event $event
+ * @param Event $event
*/
- function _handle_edit_post(Doku_Event $event)
+ public function handleEditPost(Event $event)
{
if (!isset($_POST['data_edit'])) {
return;
}
global $TEXT;
- require_once 'syntax/entry.php';
+ require_once __DIR__ . '/syntax/entry.php';
$TEXT = syntax_plugin_data_entry::editToWiki($_POST['data_edit']);
}
/**
- * @param Doku_Event $event
+ * @param Event $event
*/
- function _handle_ajax(Doku_Event $event)
+ public function handleAjax(Event $event)
{
if ($event->data !== 'data_page') {
return;
@@ -133,7 +137,7 @@ function _handle_ajax(Doku_Event $event)
$event->preventDefault();
$type = substr($_REQUEST['aliastype'], 10);
- $aliases = $this->dthlp->_aliases();
+ $aliases = $this->dthlp->aliases();
if (!isset($aliases[$type])) {
echo 'Unknown type';
@@ -172,9 +176,9 @@ function _handle_ajax(Doku_Event $event)
}
$regexp .= '$/';
- $result = array();
+ $result = [];
foreach ($pages as $page => $title) {
- $id = array();
+ $id = [];
if (!preg_match($regexp, $page, $id)) {
// Does not satisfy the postfix and prefix criteria
continue;
@@ -182,21 +186,22 @@ function _handle_ajax(Doku_Event $event)
$id = $id[1];
- if ($search !== '' &&
+ if (
+ $search !== '' &&
stripos($id, cleanID($search)) === false &&
- stripos($title, $search) === false) {
+ stripos($title, (string) $search) === false
+ ) {
// Search string is not in id part or title
continue;
}
if ($title === '') {
- $title = utf8_ucwords(str_replace('_', ' ', $id));
+ $title = PhpString::ucwords(str_replace('_', ' ', $id));
}
$result[hsc($id)] = hsc($title);
}
- $json = new JSON();
header('Content-Type: application/json');
- echo $json->encode($result);
+ echo json_encode($result);
}
}
diff --git a/admin/aliases.php b/admin/aliases.php
index e7c4719..65fb13c 100644
--- a/admin/aliases.php
+++ b/admin/aliases.php
@@ -1,4 +1,5 @@
*/
+use dokuwiki\Extension\AdminPlugin;
use dokuwiki\ErrorHandler;
use dokuwiki\Utf8\PhpString;
/**
* Administration form for configuring the type aliases
*/
-class admin_plugin_data_aliases extends DokuWiki_Admin_Plugin
+class admin_plugin_data_aliases extends AdminPlugin
{
-
/**
* will hold the data helper plugin
* @var helper_plugin_data
*/
- protected $dthlp = null;
+ protected $dthlp;
/**
* Constructor. Load helper plugin
@@ -69,7 +70,7 @@ public function handle()
global $INPUT;
if (!$INPUT->has('d') || !checkSecurityToken()) return;
- $sqlite = $this->dthlp->_getDB();
+ $sqlite = $this->dthlp->getDB();
if (!$sqlite) return;
$sqlite->getPdo()->beginTransaction();
@@ -78,7 +79,7 @@ public function handle()
foreach ($INPUT->arr('d') as $row) {
$row = array_map('trim', $row);
- $row['name'] = PHPString::strtolower($row['name']);
+ $row['name'] = PhpString::strtolower($row['name']);
$row['name'] = rtrim($row['name'], 's');
if (!$row['name']) continue;
@@ -102,7 +103,7 @@ public function handle()
*/
public function html()
{
- $sqlite = $this->dthlp->_getDB();
+ $sqlite = $this->dthlp->getDB();
if (!$sqlite) return;
echo $this->locale_xhtml('admin_intro');
@@ -110,7 +111,7 @@ public function html()
$sql = 'SELECT * FROM aliases ORDER BY name';
$rows = $sqlite->queryAll($sql);
- $form = new Doku_Form(array('method' => 'post'));
+ $form = new Doku_Form(['method' => 'post']);
$form->addHidden('page', 'data_aliases');
$form->addElement(
'
' .
@@ -124,7 +125,7 @@ public function html()
);
// add empty row for adding a new entry
- $rows[] = array('name' => '', 'type' => '', 'prefix' => '', 'postfix' => '', 'enum' => '');
+ $rows[] = ['name' => '', 'type' => '', 'prefix' => '', 'postfix' => '', 'enum' => ''];
$cur = 0;
foreach ($rows as $row) {
@@ -137,8 +138,10 @@ public function html()
$form->addElement('');
$form->addElement(form_makeMenuField(
'd[' . $cur . '][type]',
- array('', 'page', 'title', 'mail', 'url', 'dt', 'wiki', 'tag', 'hidden', 'img'),//'nspage' don't support post/prefixes
- $row['type'], ''
+ //'nspage' don't support post/prefixes
+ ['', 'page', 'title', 'mail', 'url', 'dt', 'wiki', 'tag', 'hidden', 'img'],
+ $row['type'],
+ ''
));
$form->addElement(' | ');
@@ -163,5 +166,4 @@ public function html()
$form->addElement(form_makeButton('submit', 'admin', $this->getLang('submit')));
$form->printForm();
}
-
}
diff --git a/admin/clean.php b/admin/clean.php
index 4506ca6..1cb9d24 100644
--- a/admin/clean.php
+++ b/admin/clean.php
@@ -1,22 +1,23 @@
*/
-
/**
* Let admin remove non-existing pages from sqlite db
*/
-class admin_plugin_data_clean extends DokuWiki_Admin_Plugin
+class admin_plugin_data_clean extends AdminPlugin
{
-
/**
* will hold the data helper plugin
* @var helper_plugin_data
*/
- protected $dthlp = null;
+ protected $dthlp;
/**
* Constructor. Load helper plugin
@@ -65,7 +66,7 @@ public function handle()
{
if (!isset($_REQUEST['data_go']) || !checkSecurityToken()) return;
- $sqlite = $this->dthlp->_getDB();
+ $sqlite = $this->dthlp->getDB();
if (!$sqlite) return;
$rows = $sqlite->queryAll('SELECT pid, page FROM pages');
@@ -90,12 +91,11 @@ public function html()
echo $this->locale_xhtml('intro_clean');
- $form = new Doku_Form(array('method' => 'post'));
+ $form = new Doku_Form(['method' => 'post']);
$form->addHidden('page', 'data_clean');
$form->addHidden('data_go', 'go');
$form->addElement(form_makeButton('submit', 'admin', $this->getLang('submit_clean')));
$form->printForm();
}
-
}
diff --git a/bureaucracy_field.php b/bureaucracy_field.php
index 46eb546..b4fc71d 100644
--- a/bureaucracy_field.php
+++ b/bureaucracy_field.php
@@ -1,178 +1,178 @@
init($args);
- $n_args = array();
- $this->args = array();
- foreach ($args as $arg) {
- if ($arg[0] !== '_') {
- $n_args[] = $arg;
- continue;
- }
- $this->args[] = $arg;
+ $this->init($args);
+ $n_args = [];
+ foreach ($args as $arg) {
+ if ($arg[0] !== '_') {
+ $n_args[] = $arg;
+ continue;
}
- $this->standardArgs($n_args);
-
+ $this->args[] = $arg;
}
+ $this->standardArgs($n_args);
+ }
- /**
- * Prepare
- *
- * @param array $args data plugin related field arguments
- */
- private function prepareColumns($args)
- {
- /** @var helper_plugin_data $dthlp */
- $dthlp = plugin_load('helper', 'data');
- if (!$dthlp) msg('Loading the data helper failed. Make sure the data plugin is installed.', -1);
-
- foreach ($args as $arg) {
- $arg = $this->replaceTranslation($arg);
- $datatype = $dthlp->_column($arg);
- if (is_array($datatype['type'])) {
- $datatype['basetype'] = $datatype['type']['type'];
- $datatype['enum'] = $datatype['type']['enum'];
- $datatype['type'] = $datatype['origtype'];
- } else {
- $datatype['basetype'] = $datatype['type'];
- }
- }
- $datatype['title'] = '@@DISPLAY@@';
- if (isset($datatype['enum'])) {
- $values = preg_split('/\s*,\s*/', $datatype['enum']);
- if (!$datatype['multi'] && $this->opt['optional']) array_unshift($values, '');
- $this->opt['args'] = $values;
- $this->additional = ($datatype['multi'] ? array('multiple' => 'multiple') : array());
+ /**
+ * Prepare
+ *
+ * @param array $args data plugin related field arguments
+ */
+ private function prepareColumns($args)
+ {
+ /** @var helper_plugin_data $dthlp */
+ $dthlp = plugin_load('helper', 'data');
+ if (!$dthlp) msg('Loading the data helper failed. Make sure the data plugin is installed.', -1);
+
+ foreach ($args as $arg) {
+ $arg = $this->replaceTranslation($arg);
+ $datatype = $dthlp->column($arg);
+ if (is_array($datatype['type'])) {
+ $datatype['basetype'] = $datatype['type']['type'];
+ $datatype['enum'] = $datatype['type']['enum'];
+ $datatype['type'] = $datatype['origtype'];
} else {
- $classes = 'data_type_' . $datatype['type'] . ($datatype['multi'] ? 's' : '') . ' ' .
- 'data_type_' . $datatype['basetype'] . ($datatype['multi'] ? 's' : '');
- $content = form_makeTextField('@@NAME@@', '@@VALUE@@', '@@DISPLAY@@', '@@ID@@', '@@CLASS@@ ' . $classes);
-
- $this->tpl = $content;
+ $datatype['basetype'] = $datatype['type'];
}
- if (!isset($this->opt['display'])) {
- $this->opt['display'] = $this->opt['label'];
- }
-
}
-
- /**
- * Render the field as XHTML
- *
- * Creates a single line input field or select field
- *
- * @params array $params Additional HTML specific parameters
- * @params Doku_Form $form The target Doku_Form object
- * @params int $formid unique identifier of the form which contains this field
- */
- public function renderfield($params, Doku_Form $form, $formid)
- {
- $this->prepareColumns($this->args);
-
- if (isset($this->tpl)) {
- parent::renderfield($params, $form, $formid);
- } else {
- // Is an enum type, otherwise $this->tpl would be set in __construct
- $this->_handlePreload();
- if (!$form->_infieldset) {
- $form->startFieldset('');
- }
- if ($this->error) {
- $params['class'] = 'bureaucracy_error';
- }
- $params = array_merge($this->opt, $params);
- $params['value'] = preg_split('/\s*,\s*/', $params['value'], -1, PREG_SPLIT_NO_EMPTY);
- if (count($params['value']) === 0) {
- $params['value'] = $params['args'][0];
- }
- if (!isset($this->opt['optional'])) {
- $this->additional['required'] = 'required';
- }
-
- $form->addElement(call_user_func_array('form_makeListboxField',
- $this->_parse_tpl(
- array(
- '@@NAME@@[]',
- $params['args'],
- $params['value'],
- '@@DISPLAY@@',
- '',
- '@@CLASS@@',
- $this->additional
- ),
- $params
- )));
- }
+ $datatype['title'] = '@@DISPLAY@@';
+ if (isset($datatype['enum'])) {
+ $values = preg_split('/\s*,\s*/', $datatype['enum']);
+ if (!$datatype['multi'] && $this->opt['optional']) array_unshift($values, '');
+ $this->opt['args'] = $values;
+ $this->additional = ($datatype['multi'] ? ['multiple' => 'multiple'] : []);
+ } else {
+ $classes = 'data_type_' . $datatype['type'] . ($datatype['multi'] ? 's' : '') . ' ' .
+ 'data_type_' . $datatype['basetype'] . ($datatype['multi'] ? 's' : '');
+ $content = form_makeTextField(
+ '@@NAME@@',
+ '@@VALUE@@',
+ '@@DISPLAY@@',
+ '@@ID@@',
+ '@@CLASS@@ ' . $classes
+ );
+
+ $this->tpl = $content;
+ }
+ if (!isset($this->opt['display'])) {
+ $this->opt['display'] = $this->opt['label'];
}
+ }
- /**
- * Handle a post to the field
- *
- * Accepts and validates a posted value.
- *
- * @param string $value The passed value or array or null if none given
- * @param syntax_plugin_bureaucracy_field[] $fields (reference) form fields (POST handled upto $this field)
- * @param int $index index number of field in form
- * @param int $formid unique identifier of the form which contains this field
- * @return bool Whether the passed value is valid
- */
- public function handle_post($value, &$fields, $index, $formid)
- {
- if (is_array($value)) {
- $value = join(', ', $value);
+ /**
+ * Render the field as XHTML
+ *
+ * Creates a single line input field or select field
+ *
+ * @params array $params Additional HTML specific parameters
+ * @params Doku_Form $form The target Doku_Form object
+ * @params int $formid unique identifier of the form which contains this field
+ */
+ public function renderfield($params, Doku_Form $form, $formid)
+ {
+ $this->prepareColumns($this->args);
+
+ if (isset($this->tpl)) {
+ parent::renderfield($params, $form, $formid);
+ } else {
+ // Is an enum type, otherwise $this->tpl would be set in __construct
+ $this->_handlePreload();
+ if (!$form->_infieldset) {
+ $form->startFieldset('');
+ }
+ if ($this->error) {
+ $params['class'] = 'bureaucracy_error';
+ }
+ $params = array_merge($this->opt, $params);
+ $params['value'] = preg_split('/\s*,\s*/', $params['value'], -1, PREG_SPLIT_NO_EMPTY);
+ if (count($params['value']) === 0) {
+ $params['value'] = $params['args'][0];
+ }
+ if (!isset($this->opt['optional'])) {
+ $this->additional['required'] = 'required';
}
- return parent::handle_post($value, $fields, $index, $formid);
+ $form->addElement(call_user_func_array(
+ 'form_makeListboxField',
+ $this->_parse_tpl(
+ [
+ '@@NAME@@[]',
+ $params['args'],
+ $params['value'],
+ '@@DISPLAY@@',
+ '',
+ '@@CLASS@@',
+ $this->additional
+ ],
+ $params
+ )
+ ));
}
+ }
- /**
- * Replace the translation placeholders
- *
- * @param string $string
- * @return string parsed string
- */
- private function replaceTranslation($string)
- {
- global $ID;
- global $conf;
+ /**
+ * Handle a post to the field
+ *
+ * Accepts and validates a posted value.
+ *
+ * @param string $value The passed value or array or null if none given
+ * @param helper_plugin_bureaucracy_field[] $fields (reference) form fields (POST handled upto $this field)
+ * @param int $index index number of field in form
+ * @param int $formid unique identifier of the form which contains this field
+ * @return bool Whether the passed value is valid
+ */
+ public function handlePost($value, &$fields, $index, $formid)
+ {
+ if (is_array($value)) {
+ $value = implode(', ', $value);
+ }
- $lang = $conf['lang'];
- $trans = '';
+ return parent::handlePost($value, $fields, $index, $formid);
+ }
- /** @var helper_plugin_translation $translationPlugin */
- $translationPlugin = plugin_load('helper', 'translation');
- if ($translationPlugin) {
- $trans = $translationPlugin->getLangPart($ID);
- $lang = $translationPlugin->realLC('');
- }
+ /**
+ * Replace the translation placeholders
+ *
+ * @param string $string
+ * @return string parsed string
+ */
+ private function replaceTranslation($string)
+ {
+ global $ID;
+ global $conf;
- $string = str_replace('@LANG@', $lang, $string);
- return str_replace('@TRANS@', $trans, $string);
+ $lang = $conf['lang'];
+ $trans = '';
+
+ /** @var helper_plugin_translation $translationPlugin */
+ $translationPlugin = plugin_load('helper', 'translation');
+ if ($translationPlugin) {
+ $trans = $translationPlugin->getLangPart($ID);
+ $lang = $translationPlugin->realLC('');
}
+
+ $string = str_replace('@LANG@', $lang, $string);
+ return str_replace('@TRANS@', $trans, $string);
}
}
diff --git a/conf/metadata.php b/conf/metadata.php
index 1e32b78..7aaee1c 100644
--- a/conf/metadata.php
+++ b/conf/metadata.php
@@ -1,6 +1,6 @@
*/
+use dokuwiki\Extension\Plugin;
use dokuwiki\ErrorHandler;
use dokuwiki\plugin\sqlite\SQLiteDB;
use dokuwiki\Utf8\PhpString;
@@ -11,23 +13,22 @@
/**
* This is the base class for all syntax classes, providing some general stuff
*/
-class helper_plugin_data extends DokuWiki_Plugin
+class helper_plugin_data extends Plugin
{
-
/**
* @var SQLiteDB initialized via _getDb()
*/
- protected $db = null;
+ protected $db;
/**
* @var array stores the alias definitions
*/
- protected $aliases = null;
+ protected $aliases;
/**
* @var array stores custom key localizations
*/
- protected $locs = array();
+ protected $locs = [];
/**
* Constructor
@@ -41,13 +42,13 @@ public function __construct()
private function loadLocalizedLabels()
{
- $lang = array();
+ $lang = [];
$path = DOKU_CONF . '/lang/en/data-plugin.php';
if (file_exists($path)) include($path);
$path = DOKU_CONF . '/lang/' . $this->determineLang() . '/data-plugin.php';
if (file_exists($path)) include($path);
foreach ($lang as $key => $val) {
- $lang[PHPString::strtolower($key)] = $val;
+ $lang[PhpString::strtolower($key)] = $val;
}
$this->locs = $lang;
}
@@ -76,7 +77,7 @@ protected function determineLang()
*/
public function ready()
{
- return (bool)$this->_getDB();
+ return (bool)$this->getDB();
}
/**
@@ -84,12 +85,12 @@ public function ready()
*
* @return SQLiteDB|null SQLite class plugin or null if failed
*/
- function _getDB()
+ public function getDB()
{
if ($this->db === null) {
try {
$this->db = new SQLiteDB('data', __DIR__ . '/db/');
- $this->db->getPdo()->sqliteCreateFunction('DATARESOLVE', [$this, '_resolveData'], 2);
+ $this->db->getPdo()->sqliteCreateFunction('DATARESOLVE', [$this, 'resolveData'], 2);
} catch (\Exception $exception) {
if (defined('DOKU_UNITTEST')) throw new \RuntimeException('Could not load SQLite', 0, $exception);
ErrorHandler::logException($exception);
@@ -107,10 +108,10 @@ function _getDB()
* @param string|array $type
* @return string
*/
- function _cleanData($value, $type)
+ public function cleanData($value, $type)
{
$value = trim((string) $value);
- if (!$value and $value !== '0') {
+ if (!$value && $value !== '0') {
return '';
}
if (is_array($type)) {
@@ -166,7 +167,7 @@ function _cleanData($value, $type)
* @param string $post
* @return string
*/
- function _addPrePostFixes($type, $val, $pre = '', $post = '')
+ public function addPrePostFixes($type, $val, $pre = '', $post = '')
{
if (is_array($type)) {
if (isset($type['prefix'])) {
@@ -190,11 +191,11 @@ function _addPrePostFixes($type, $val, $pre = '', $post = '')
* @param string $colname
* @return string
*/
- function _resolveData($value, $colname)
+ public function resolveData($value, $colname)
{
// resolve pre and postfixes
- $column = $this->_column($colname);
- $value = $this->_addPrePostFixes($column['type'], $value);
+ $column = $this->column($colname);
+ $value = $this->addPrePostFixes($column['type'], $value);
// for pages, resolve title
$type = $column['type'];
@@ -204,7 +205,7 @@ function _resolveData($value, $colname)
if ($type == 'title' || ($type == 'page' && useHeading('content'))) {
$id = $value;
if ($type == 'title') {
- list($id,) = explode('|', $value, 2);
+ [$id, ] = explode('|', $value, 2);
}
//DATARESOLVE is only used with the 'LIKE' comparator, so concatenate the different strings is fine.
$value .= ' ' . p_get_first_heading($id);
@@ -228,11 +229,11 @@ public function ensureAbsoluteId($id)
* @param Doku_Renderer_xhtml $R
* @return string
*/
- function _formatData($column, $value, Doku_Renderer_xhtml $R)
+ public function formatData($column, $value, Doku_Renderer_xhtml $R)
{
global $conf;
$vals = explode("\n", $value);
- $outs = array();
+ $outs = [];
//multivalued line from db result for pageid and wiki has only in first value the ID
$storedID = '';
@@ -247,18 +248,18 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R)
}
switch ($type) {
case 'page':
- $val = $this->_addPrePostFixes($column['type'], $val);
+ $val = $this->addPrePostFixes($column['type'], $val);
$val = $this->ensureAbsoluteId($val);
$outs[] = $R->internallink($val, null, null, true);
break;
case 'title':
- list($id, $title) = array_pad(explode('|', $val, 2), 2, null);
- $id = $this->_addPrePostFixes($column['type'], $id);
+ [$id, $title] = array_pad(explode('|', $val, 2), 2, null);
+ $id = $this->addPrePostFixes($column['type'], $id);
$id = $this->ensureAbsoluteId($id);
$outs[] = $R->internallink($id, $title, null, true);
break;
case 'pageid':
- list($id, $title) = array_pad(explode('|', $val, 2), 2, null);
+ [$id, $title] = array_pad(explode('|', $val, 2), 2, null);
//use ID from first value of the multivalued line
if ($title == null) {
@@ -270,7 +271,7 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R)
$storedID = $id;
}
- $id = $this->_addPrePostFixes($column['type'], $id);
+ $id = $this->addPrePostFixes($column['type'], $id);
$outs[] = $R->internallink($id, $title, null, true);
break;
@@ -281,8 +282,8 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R)
$outs[] = $R->internallink($val, null, null, true);
break;
case 'mail':
- list($id, $title) = array_pad(explode(' ', $val, 2), 2, null);
- $id = $this->_addPrePostFixes($column['type'], $id);
+ [$id, $title] = array_pad(explode(' ', $val, 2), 2, null);
+ $id = $this->addPrePostFixes($column['type'], $id);
$id = obfuscate(hsc($id));
if (!$title) {
$title = $id;
@@ -295,7 +296,7 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R)
$outs[] = '' . $title . '';
break;
case 'url':
- $val = $this->_addPrePostFixes($column['type'], $val);
+ $val = $this->addPrePostFixes($column['type'], $val);
$outs[] = $this->external_link($val, false, 'urlextern');
break;
case 'tag':
@@ -303,10 +304,11 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R)
if (!is_array($column['type'])) {
$target = $column['key'] . ':';
} else {
- $target = $this->_addPrePostFixes($column['type'], '');
+ $target = $this->addPrePostFixes($column['type'], '');
}
- $outs[] = 'getTagUrlparam($column, $val))
. '" title="' . sprintf($this->getLang('tagfilter'), hsc($val))
. '" class="wikilink1">' . hsc($val) . '';
break;
@@ -316,7 +318,7 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R)
case 'wiki':
global $ID;
$oldid = $ID;
- list($ID, $data) = explode('|', $val, 2);
+ [$ID, $data] = explode('|', $val, 2);
//use ID from first value of the multivalued line
if ($data == null) {
@@ -325,7 +327,7 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R)
} else {
$storedID = $ID;
}
- $data = $this->_addPrePostFixes($column['type'], $data);
+ $data = $this->addPrePostFixes($column['type'], $data);
// Trim document_{start,end}, p_{open,close} from instructions
$allinstructions = p_get_instructions($data);
@@ -339,7 +341,7 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R)
$ID = $oldid;
break;
default:
- $val = $this->_addPrePostFixes($column['type'], $val);
+ $val = $this->addPrePostFixes($column['type'], $val);
//type '_img' or '_img'
if (substr($type, 0, 3) == 'img') {
$width = (int)substr($type, 3);
@@ -347,7 +349,7 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R)
$width = $this->getConf('image_width');
}
- list($mediaid, $title) = array_pad(explode('|', $val, 2), 2, null);
+ [$mediaid, $title] = array_pad(explode('|', $val, 2), 2, null);
if ($title === null) {
$title = $column['key'] . ': ' . basename(str_replace(':', '/', $mediaid));
} else {
@@ -355,9 +357,27 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R)
}
if (media_isexternal($val)) {
- $html = $R->externalmedia($mediaid, $title, $align = null, $width, $height = null, $cache = null, $linking = 'direct', true);
+ $html = $R->externalmedia(
+ $mediaid,
+ $title,
+ $align = null,
+ $width,
+ $height = null,
+ $cache = null,
+ $linking = 'direct',
+ true
+ );
} else {
- $html = $R->internalmedia($mediaid, $title, $align = null, $width, $height = null, $cache = null, $linking = 'direct', true);
+ $html = $R->internalmedia(
+ $mediaid,
+ $title,
+ $align = null,
+ $width,
+ $height = null,
+ $cache = null,
+ $linking = 'direct',
+ true
+ );
}
if (strpos($html, 'mediafile') === false) {
$html = str_replace('href', 'rel="lightbox" href', $html);
@@ -369,7 +389,7 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R)
}
}
}
- return join(', ', $outs);
+ return implode(', ', $outs);
}
/**
@@ -378,25 +398,25 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R)
* @param string $col column name
* @return array with key, type, ismulti, title, opt
*/
- function _column($col)
+ public function column($col)
{
preg_match('/^([^_]*)(?:_(.*))?((? $col,
'multi' => ($matches[3] === 's'),
- 'key' => PHPString::strtolower($matches[1]),
+ 'key' => PhpString::strtolower($matches[1]),
'origkey' => $matches[1], //similar to key, but stores upper case
'title' => $matches[1],
- 'type' => PHPString::strtolower($matches[2])
- );
+ 'type' => PhpString::strtolower($matches[2]),
+ ];
// fix title for special columns
- static $specials = array(
- '%title%' => array('page', 'title'),
- '%pageid%' => array('title', 'page'),
- '%class%' => array('class'),
- '%lastmod%' => array('lastmod', 'timestamp')
- );
+ static $specials = [
+ '%title%' => ['page', 'title'],
+ '%pageid%' => ['title', 'page'],
+ '%class%' => ['class'],
+ '%lastmod%' => ['lastmod', 'timestamp']
+ ];
if (isset($specials[$column['title']])) {
$s = $specials[$column['title']];
$column['title'] = $this->getLang($s[0]);
@@ -406,7 +426,7 @@ function _column($col)
}
// check if the type is some alias
- $aliases = $this->_aliases();
+ $aliases = $this->aliases();
if (isset($aliases[$column['type']])) {
$column['origtype'] = $column['type'];
$column['type'] = $aliases[$column['type']];
@@ -425,14 +445,14 @@ function _column($col)
*
* @return array
*/
- function _aliases()
+ public function aliases()
{
if (!is_null($this->aliases)) return $this->aliases;
- $sqlite = $this->_getDB();
- if (!$sqlite) return array();
+ $sqlite = $this->getDB();
+ if (!$sqlite) return [];
- $this->aliases = array();
+ $this->aliases = [];
$rows = $sqlite->queryAll("SELECT * FROM aliases");
foreach ($rows as $row) {
$name = $row['name'];
@@ -451,17 +471,14 @@ function _aliases()
* @param $filterline
* @return array|bool - array on success, false on error
*/
- function _parse_filter($filterline)
+ public function parseFilter($filterline)
{
//split filterline on comparator
if (preg_match('/^(.*?)([\*=<>!~]{1,2})(.*)$/', $filterline, $matches)) {
- $column = $this->_column(trim($matches[1]));
+ $column = $this->column(trim($matches[1]));
$com = $matches[2];
- $aliasses = array(
- '<>' => '!=', '=!' => '!=', '~!' => '!~',
- '==' => '=', '~=' => '~', '=~' => '~'
- );
+ $aliasses = ['<>' => '!=', '=!' => '!=', '~!' => '!~', '==' => '=', '~=' => '~', '=~' => '~'];
if (isset($aliasses[$com])) {
$com = $aliasses[$com];
@@ -488,9 +505,9 @@ function _parse_filter($filterline)
}
} else {
// Clean if there are no asterisks I could kill
- $val = $this->_cleanData($val, $column['type']);
+ $val = $this->cleanData($val, $column['type']);
}
- $sqlite = $this->_getDB();
+ $sqlite = $this->getDB();
if (!$sqlite) return false;
if ($com == 'IN(') {
@@ -502,13 +519,13 @@ function _parse_filter($filterline)
$val = $sqlite->getPdo()->quote($val);
}
- return array(
+ return [
'key' => $column['key'],
'value' => $val,
'compare' => $com,
'colname' => $column['colname'],
'type' => $column['type']
- );
+ ];
}
msg('Failed to parse filter "' . hsc($filterline) . '"', -1);
return false;
@@ -519,7 +536,7 @@ function _parse_filter($filterline)
*
* @param $data
*/
- function _replacePlaceholdersInSQL(&$data)
+ public function replacePlaceholdersInSQL(&$data)
{
global $USERINFO;
global $INPUT;
@@ -572,12 +589,12 @@ public function makeTranslationReplacement($data)
*
* @return array
*/
- function _get_filters()
+ public function getFilters()
{
- $filters = array();
+ $filters = [];
if (!isset($_REQUEST['dataflt'])) {
- $flt = array();
+ $flt = [];
} elseif (!is_array($_REQUEST['dataflt'])) {
$flt = (array)$_REQUEST['dataflt'];
} else {
@@ -588,7 +605,7 @@ function _get_filters()
if (!is_numeric($key)) {
$line = $key . $line;
}
- $f = $this->_parse_filter($line);
+ $f = $this->parseFilter($line);
if (is_array($f)) {
$f['logic'] = 'AND';
$filters[] = $f;
@@ -604,9 +621,9 @@ function _get_filters()
* @param string|array $array value or key-value pairs
* @return array
*/
- function _a2ua($name, $array)
+ public function a2ua($name, $array)
{
- $urlarray = array();
+ $urlarray = [];
foreach ((array)$array as $key => $val) {
$urlarray[$name . '[' . $key . ']'] = $val;
}
@@ -619,11 +636,11 @@ function _a2ua($name, $array)
* @param bool $returnURLparams
* @return array with dataflt, datasrt and dataofs parameters
*/
- function _get_current_param($returnURLparams = true)
+ public function getPurrentParam($returnURLparams = true)
{
- $cur_params = array();
+ $cur_params = [];
if (isset($_REQUEST['dataflt'])) {
- $cur_params = $this->_a2ua('dataflt', $_REQUEST['dataflt']);
+ $cur_params = $this->a2ua('dataflt', $_REQUEST['dataflt']);
}
if (isset($_REQUEST['datasrt'])) {
$cur_params['datasrt'] = $_REQUEST['datasrt'];
@@ -634,7 +651,7 @@ function _get_current_param($returnURLparams = true)
//combine key and value
if (!$returnURLparams) {
- $flat_param = array();
+ $flat_param = [];
foreach ($cur_params as $key => $val) {
$flat_param[] = $key . $val;
}
@@ -650,9 +667,9 @@ function _get_current_param($returnURLparams = true)
* @param string $tag
* @return array of url parameters
*/
- function _getTagUrlparam($column, $tag)
+ public function getTagUrlparam($column, $tag)
{
- $param = array();
+ $param = [];
if (isset($_REQUEST['dataflt'])) {
$param = (array)$_REQUEST['dataflt'];
@@ -662,14 +679,14 @@ function _getTagUrlparam($column, $tag)
if (!is_numeric($key)) {
$flt = $key . $flt;
}
- $filter = $this->_parse_filter($flt);
+ $filter = $this->parseFilter($flt);
if ($filter['key'] == $column['key']) {
unset($param[$key]);
}
}
}
$param[] = $column['key'] . "_=$tag";
- $param = $this->_a2ua('dataflt', $param);
+ $param = $this->a2ua('dataflt', $param);
if (isset($_REQUEST['datasrt'])) {
$param['datasrt'] = $_REQUEST['datasrt'];
diff --git a/helper/aliastextbox.php b/helper/aliastextbox.php
index a4a2d33..010e791 100644
--- a/helper/aliastextbox.php
+++ b/helper/aliastextbox.php
@@ -8,7 +8,6 @@
*/
class helper_plugin_data_aliastextbox extends helper_plugin_bureaucracy_field
{
-
private $args;
private $additional;
@@ -24,8 +23,8 @@ class helper_plugin_data_aliastextbox extends helper_plugin_bureaucracy_field
public function initialize($args)
{
$this->init($args);
- $n_args = array();
- $this->args = array();
+ $n_args = [];
+ $this->args = [];
foreach ($args as $arg) {
if ($arg[0] !== '_') {
$n_args[] = $arg;
@@ -34,7 +33,6 @@ public function initialize($args)
$this->args[] = $arg;
}
$this->standardArgs($n_args);
-
}
/**
@@ -50,7 +48,7 @@ private function prepareColumns($args)
foreach ($args as $arg) {
$arg = $this->replaceTranslation($arg);
- $datatype = $dthlp->_column($arg);
+ $datatype = $dthlp->column($arg);
if (is_array($datatype['type'])) {
$datatype['basetype'] = $datatype['type']['type'];
$datatype['enum'] = $datatype['type']['enum'];
@@ -64,7 +62,7 @@ private function prepareColumns($args)
$values = preg_split('/\s*,\s*/', $datatype['enum']);
if (!$datatype['multi'] && $this->opt['optional']) array_unshift($values, '');
$this->opt['args'] = $values;
- $this->additional = ($datatype['multi'] ? array('multiple' => 'multiple') : array());
+ $this->additional = ($datatype['multi'] ? ['multiple' => 'multiple'] : []);
} else {
$classes = 'data_type_' . $datatype['type'] . ($datatype['multi'] ? 's' : '') . ' ' .
'data_type_' . $datatype['basetype'] . ($datatype['multi'] ? 's' : '');
@@ -75,7 +73,6 @@ private function prepareColumns($args)
if (!isset($this->opt['display'])) {
$this->opt['display'] = $this->opt['label'];
}
-
}
/**
@@ -111,9 +108,10 @@ public function renderfield($params, Doku_Form $form, $formid)
$this->additional['required'] = 'required';
}
- $form->addElement(call_user_func_array('form_makeListboxField',
+ $form->addElement(call_user_func_array(
+ 'form_makeListboxField',
$this->_parse_tpl(
- array(
+ [
'@@NAME@@[]',
$params['args'],
$params['value'],
@@ -121,9 +119,10 @@ public function renderfield($params, Doku_Form $form, $formid)
'',
'@@CLASS@@',
$this->additional
- ),
+ ],
$params
- )));
+ )
+ ));
}
}
@@ -138,13 +137,13 @@ public function renderfield($params, Doku_Form $form, $formid)
* @param int $formid unique identifier of the form which contains this field
* @return bool Whether the passed value is valid
*/
- public function handle_post($value, &$fields, $index, $formid)
+ public function handlePost($value, &$fields, $index, $formid)
{
if (is_array($value)) {
- $value = join(', ', $value);
+ $value = implode(', ', $value);
}
- return parent::handle_post($value, $fields, $index, $formid);
+ return parent::handlePost($value, $fields, $index, $formid);
}
/**
@@ -172,4 +171,3 @@ private function replaceTranslation($string)
return str_replace('@TRANS@', $trans, $string);
}
}
-
diff --git a/plugin.info.txt b/plugin.info.txt
index aea4288..761a17c 100644
--- a/plugin.info.txt
+++ b/plugin.info.txt
@@ -5,4 +5,4 @@ date 2023-07-18
name Structured Data Plugin
desc Add and query structured data in your wiki
url https://www.dokuwiki.org/plugin:data
-
+minphp 7.3
diff --git a/renderer_data_edit.php b/renderer_data_edit.php
index b508f12..d77d653 100644
--- a/renderer_data_edit.php
+++ b/renderer_data_edit.php
@@ -1,4 +1,7 @@
Lexer->addSpecialPattern('----+ *datacloud(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+', $mode, 'plugin_data_cloud');
+ $this->Lexer->addSpecialPattern(
+ '----+ *datacloud(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+',
+ $mode,
+ 'plugin_data_cloud'
+ );
}
/**
@@ -68,7 +72,7 @@ public function connectTo($mode)
* @param array &$data instruction by handler
* @return bool|string SQL query or false
*/
- public function _buildSQL(&$data)
+ public function buildSQL(&$data)
{
$ckey = array_keys($data['cols']);
$ckey = $ckey[0];
@@ -76,16 +80,12 @@ public function _buildSQL(&$data)
$from = ' ';
$where = ' ';
$pagesjoin = '';
- $tables = array();
+ $tables = [];
- $sqlite = $this->dthlp->_getDB();
+ $sqlite = $this->dthlp->getDB();
if (!$sqlite) return false;
- $fields = array(
- 'pageid' => 'page',
- 'class' => 'class',
- 'title' => 'title'
- );
+ $fields = ['pageid' => 'page', 'class' => 'class', 'title' => 'title'];
// prepare filters (no request filters - we set them ourselves)
if (is_array($data['filter']) && count($data['filter'])) {
$cnt = 0;
@@ -152,7 +152,7 @@ public function render($format, Doku_Renderer $renderer, $data)
if (!$this->dthlp->ready()) return false;
$renderer->info['cache'] = false;
- $sqlite = $this->dthlp->_getDB();
+ $sqlite = $this->dthlp->getDB();
if (!$sqlite) return false;
$ckey = array_keys($data['cols']);
@@ -162,13 +162,13 @@ public function render($format, Doku_Renderer $renderer, $data)
$data['page'] = $ID;
}
- $this->dthlp->_replacePlaceholdersInSQL($data);
+ $this->dthlp->replacePlaceholdersInSQL($data);
// build cloud data
$rows = $sqlite->queryAll($data['sql']);
$min = 0;
$max = 0;
- $tags = array();
+ $tags = [];
foreach ($rows as $row) {
if (!$max) {
$max = $row['cnt'];
@@ -177,7 +177,7 @@ public function render($format, Doku_Renderer $renderer, $data)
$tags[$row['value']]['cnt'] = $row['cnt'];
$tags[$row['value']]['value'] = $row['value'];
}
- $this->_cloud_weight($tags, $min, $max, 5);
+ $this->cloudWeight($tags, $min, $max, 5);
// output cloud
$renderer->doc .= sprintf($this->before_item, hsc($data['classes']));
@@ -188,7 +188,8 @@ public function render($format, Doku_Renderer $renderer, $data)
}
$renderer->doc .= sprintf($this->before_val, $tag['lvl']);
- $renderer->doc .= 'dthlp->getTagUrlparam($data['cols'][$ckey], $tag['value'])) .
'" title="' . sprintf($this->getLang('tagfilter'), hsc($tag['value'])) .
'" class="wikilink1">' . $tagLabelText . '';
$renderer->doc .= $this->after_val;
@@ -205,14 +206,14 @@ public function render($format, Doku_Renderer $renderer, $data)
* @param $max int The highest count of a single tag
* @param $levels int The number of levels you want. A 5 gives levels 0 to 4.
*/
- protected function _cloud_weight(&$tags, $min, $max, $levels)
+ protected function cloudWeight(&$tags, $min, $max, $levels)
{
$levels--;
// calculate tresholds
- $tresholds = array();
+ $tresholds = [];
for ($i = 0; $i <= $levels; $i++) {
- $tresholds[$i] = pow($max - $min + 1, $i / $levels) + $min - 1;
+ $tresholds[$i] = ($max - $min + 1) ** ($i / $levels) + $min - 1;
}
// assign weights
@@ -229,6 +230,4 @@ protected function _cloud_weight(&$tags, $min, $max, $levels)
// sort
ksort($tags);
}
-
}
-
diff --git a/syntax/entry.php b/syntax/entry.php
index 9d77a7f..d5ea71d 100644
--- a/syntax/entry.php
+++ b/syntax/entry.php
@@ -1,28 +1,32 @@
*/
+use dokuwiki\Extension\SyntaxPlugin;
+use dokuwiki\plugin\data\Form\DropdownElement;
+use dokuwiki\Form\InputElement;
+use dokuwiki\Form\CheckableElement;
use dokuwiki\Form\Element;
use dokuwiki\Utf8\PhpString;
/**
* Class syntax_plugin_data_entry
*/
-class syntax_plugin_data_entry extends DokuWiki_Syntax_Plugin
+class syntax_plugin_data_entry extends SyntaxPlugin
{
-
/**
* @var helper_plugin_data will hold the data helper plugin
*/
- var $dthlp = null;
+ public $dthlp;
/**
* Constructor. Load helper plugin
*/
- function __construct()
+ public function __construct()
{
$this->dthlp = plugin_load('helper', 'data');
if (!$this->dthlp) msg('Loading the data helper failed. Make sure the data plugin is installed.', -1);
@@ -31,7 +35,7 @@ function __construct()
/**
* What kind of syntax are we?
*/
- function getType()
+ public function getType()
{
return 'substition';
}
@@ -39,7 +43,7 @@ function getType()
/**
* What about paragraphs?
*/
- function getPType()
+ public function getPType()
{
return 'block';
}
@@ -47,7 +51,7 @@ function getPType()
/**
* Where to sort in?
*/
- function getSort()
+ public function getSort()
{
return 155;
}
@@ -55,9 +59,13 @@ function getSort()
/**
* Connect pattern to lexer
*/
- function connectTo($mode)
+ public function connectTo($mode)
{
- $this->Lexer->addSpecialPattern('----+ *dataentry(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+', $mode, 'plugin_data_entry');
+ $this->Lexer->addSpecialPattern(
+ '----+ *dataentry(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+',
+ $mode,
+ 'plugin_data_entry'
+ );
}
/**
@@ -69,7 +77,7 @@ function connectTo($mode)
* @param Doku_Handler $handler The Doku_Handler object
* @return bool|array Return an array with all data you want to use in render, false don't add an instruction
*/
- function handle($match, $state, $pos, Doku_Handler $handler)
+ public function handle($match, $state, $pos, Doku_Handler $handler)
{
if (!$this->dthlp->ready()) return null;
@@ -81,8 +89,8 @@ function handle($match, $state, $pos, Doku_Handler $handler)
$class = trim($class, '- ');
// parse info
- $data = array();
- $columns = array();
+ $data = [];
+ $columns = [];
foreach ($lines as $line) {
// ignore comments
preg_match('/^(.*?(?dthlp->_column($line[0]);
+ $column = $this->dthlp->column($line[0]);
if (isset($matches[2])) {
$column['comment'] = $matches[2];
}
@@ -101,25 +109,28 @@ function handle($match, $state, $pos, Doku_Handler $handler)
// init with empty array
// Note that multiple occurrences of the field are
// practically merged
- $data[$column['key']] = array();
+ $data[$column['key']] = [];
}
$vals = explode(',', $line[1]);
foreach ($vals as $val) {
- $val = trim($this->dthlp->_cleanData($val, $column['type']));
+ $val = trim($this->dthlp->cleanData($val, $column['type']));
if ($val == '') continue;
if (!in_array($val, $data[$column['key']])) {
$data[$column['key']][] = $val;
}
}
} else {
- $data[$column['key']] = $this->dthlp->_cleanData($line[1] ?? '', $column['type']);
+ $data[$column['key']] = $this->dthlp->cleanData($line[1] ?? '', $column['type']);
}
$columns[$column['key']] = $column;
}
- return array(
- 'data' => $data, 'cols' => $columns, 'classes' => $class,
- 'pos' => $pos, 'len' => strlen($match)
- ); // not utf8_strlen
+ return [
+ 'data' => $data,
+ 'cols' => $columns,
+ 'classes' => $class,
+ 'pos' => $pos,
+ 'len' => strlen($match) // not utf8_strlen
+ ];
}
/**
@@ -130,7 +141,7 @@ function handle($match, $state, $pos, Doku_Handler $handler)
* @param $data array data created by handler()
* @return boolean rendered correctly?
*/
- function render($format, Doku_Renderer $renderer, $data)
+ public function render($format, Doku_Renderer $renderer, $data)
{
if (is_null($data)) return false;
if (!$this->dthlp->ready()) return false;
@@ -139,18 +150,18 @@ function render($format, Doku_Renderer $renderer, $data)
switch ($format) {
case 'xhtml':
/** @var $renderer Doku_Renderer_xhtml */
- $this->_showData($data, $renderer);
+ $this->showData($data, $renderer);
return true;
case 'metadata':
/** @var $renderer Doku_Renderer_metadata */
- $this->_saveData($data, $ID, $renderer->meta['title'] ?? '');
+ $this->saveData($data, $ID, $renderer->meta['title'] ?? '');
return true;
case 'plugin_data_edit':
/** @var $renderer Doku_Renderer_plugin_data_edit */
if (is_a($renderer->form, 'Doku_Form')) {
- $this->_editDataLegacy($data, $renderer);
+ $this->editDataLegacy($data, $renderer);
} else {
- $this->_editData($data, $renderer);
+ $this->editData($data, $renderer);
}
return true;
default:
@@ -164,7 +175,7 @@ function render($format, Doku_Renderer $renderer, $data)
* @param array $data
* @param Doku_Renderer_xhtml $R
*/
- function _showData($data, $R)
+ public function showData($data, $R)
{
global $ID;
$ret = '';
@@ -173,7 +184,7 @@ function _showData($data, $R)
$data['classes'] .= ' ' . $R->startSectionEdit($data['pos'], $sectionEditData);
$ret .= '';
- $class_names = array();
+ $class_names = [];
foreach ($data['data'] as $key => $val) {
if ($val == '' || is_null($val) || (is_array($val) && count($val) == 0)) continue;
$type = $data['cols'][$key]['type'];
@@ -183,28 +194,26 @@ function _showData($data, $R)
if ($type === 'hidden') continue;
$class_name = hsc(sectionID($key, $class_names));
- $ret .= '- ' . hsc($data['cols'][$key]['title']) . ':
';
+ $ret .= '- ' .
+ hsc($data['cols'][$key]['title']) .
+ ':
';
$ret .= '- ';
if (is_array($val)) {
$cnt = count($val);
for ($i = 0; $i < $cnt; $i++) {
- switch ($type) {
- case 'wiki':
- $val[$i] = $ID . '|' . $val[$i];
- break;
+ if ($type === 'wiki') {
+ $val[$i] = $ID . '|' . $val[$i];
}
- $ret .= $this->dthlp->_formatData($data['cols'][$key], $val[$i], $R);
+ $ret .= $this->dthlp->formatData($data['cols'][$key], $val[$i], $R);
if ($i < $cnt - 1) {
$ret .= ', ';
}
}
} else {
- switch ($type) {
- case 'wiki':
- $val = $ID . '|' . $val;
- break;
+ if ($type === 'wiki') {
+ $val = $ID . '|' . $val;
}
- $ret .= $this->dthlp->_formatData($data['cols'][$key], $val, $R);
+ $ret .= $this->dthlp->formatData($data['cols'][$key], $val, $R);
}
$ret .= '
';
}
@@ -216,9 +225,9 @@ function _showData($data, $R)
/**
* Save date to the database
*/
- function _saveData($data, $id, $title)
+ public function saveData($data, $id, $title)
{
- $sqlite = $this->dthlp->_getDB();
+ $sqlite = $this->dthlp->getDB();
if (!$sqlite) return false;
if (!$title) {
@@ -232,14 +241,19 @@ function _saveData($data, $id, $title)
// store page info
$this->replaceQuery(
"INSERT OR IGNORE INTO pages (page,title,class) VALUES (?,?,?)",
- $id, $title, $class
+ $id,
+ $title,
+ $class
);
// Update title if insert failed (record already saved before)
$revision = filemtime(wikiFN($id));
$this->replaceQuery(
"UPDATE pages SET title = ?, class = ?, lastmod = ? WHERE page = ?",
- $title, $class, $revision, $id
+ $title,
+ $class,
+ $revision,
+ $id
);
// fetch page id
@@ -260,12 +274,16 @@ function _saveData($data, $id, $title)
if (is_array($val)) foreach ($val as $v) {
$this->replaceQuery(
"INSERT INTO DATA (pid, KEY, VALUE) VALUES (?, ?, ?)",
- $pid, $key, $v
+ $pid,
+ $key,
+ $v
);
} else {
$this->replaceQuery(
"INSERT INTO DATA (pid, KEY, VALUE) VALUES (?, ?, ?)",
- $pid, $key, $val
+ $pid,
+ $key,
+ $val
);
}
}
@@ -285,21 +303,21 @@ function _saveData($data, $id, $title)
* @fixme replace this madness
* @return bool|mixed
*/
- function replaceQuery()
+ public function replaceQuery()
{
$args = func_get_args();
$argc = func_num_args();
if ($argc > 1) {
for ($i = 1; $i < $argc; $i++) {
- $data = array();
+ $data = [];
$data['sql'] = $args[$i];
- $this->dthlp->_replacePlaceholdersInSQL($data);
+ $this->dthlp->replacePlaceholdersInSQL($data);
$args[$i] = $data['sql'];
}
}
- $sqlite = $this->dthlp->_getDB();
+ $sqlite = $this->dthlp->getDB();
if (!$sqlite) return false;
return call_user_func_array(array(&$sqlite, 'query'), $args);
@@ -315,7 +333,7 @@ function replaceQuery()
* @param Doku_Renderer_plugin_data_edit $renderer
* @deprecated _editData() is used since Igor
*/
- protected function _editDataLegacy($data, &$renderer)
+ protected function editDataLegacy($data, &$renderer)
{
$renderer->form->startFieldset($this->getLang('dataentry'));
$renderer->form->_content[count($renderer->form->_content) - 1]['class'] = 'plugin__data';
@@ -324,18 +342,25 @@ protected function _editDataLegacy($data, &$renderer)
if ($this->getConf('edit_content_only')) {
$renderer->form->addHidden('data_edit[classes]', $data['classes']);
- $columns = array('title', 'value', 'comment');
+ $columns = ['title', 'value', 'comment'];
$class = 'edit_content_only';
-
} else {
- $renderer->form->addElement(form_makeField('text', 'data_edit[classes]', $data['classes'], $this->getLang('class'), 'data__classes'));
+ $renderer->form->addElement(
+ form_makeField(
+ 'text',
+ 'data_edit[classes]',
+ $data['classes'],
+ $this->getLang('class'),
+ 'data__classes'
+ )
+ );
- $columns = array('title', 'type', 'multi', 'value', 'comment');
+ $columns = ['title', 'type', 'multi', 'value', 'comment'];
$class = 'edit_all_content';
// New line
$data['data'][''] = '';
- $data['cols'][''] = array('type' => '', 'multi' => false);
+ $data['cols'][''] = ['type' => '', 'multi' => false];
}
$renderer->form->addElement("");
@@ -379,50 +404,77 @@ protected function _editDataLegacy($data, &$renderer)
$values,
$data['data'][$key],
$vals['title'],
- '', '',
- ($vals['multi'] ? array('multiple' => 'multiple') : array())
+ '',
+ '',
+ ($vals['multi'] ? ['multiple' => 'multiple'] : [])
);
} else {
$classes = 'data_type_' . $vals['type'] . ($vals['multi'] ? 's' : '') . ' '
. 'data_type_' . $vals['basetype'] . ($vals['multi'] ? 's' : '');
- $attr = array();
+ $attr = [];
if ($vals['basetype'] == 'date' && !$vals['multi']) {
$attr['class'] = 'datepicker';
}
- $content = form_makeField('text', $fieldid . '[value]', $content, $vals['title'], '', $classes, $attr);
-
+ $content = form_makeField(
+ 'text',
+ $fieldid . '[value]',
+ $content,
+ $vals['title'],
+ '',
+ $classes,
+ $attr
+ );
}
- $cells = array(
+ $cells = [
hsc($vals['title']) . ':',
$content,
'' . hsc($vals['comment']) . ''
- );
- foreach (array('multi', 'comment', 'type') as $field) {
+ ];
+ foreach (['multi', 'comment', 'type'] as $field) {
$renderer->form->addHidden($fieldid . "[$field]", $vals[$field]);
}
- $renderer->form->addHidden($fieldid . "[title]", $vals['origkey']); //keep key as key, even if title is translated
+ //keep key as key, even if title is translated
+ $renderer->form->addHidden($fieldid . "[title]", $vals['origkey']);
} else {
- $check_data = $vals['multi'] ? array('checked' => 'checked') : array();
- $cells = array(
- form_makeField('text', $fieldid . '[title]', $vals['origkey'], $this->getLang('title')), // when editable, always use the pure key, not a title
+ $check_data = $vals['multi'] ? ['checked' => 'checked'] : [];
+ $cells = [
+ form_makeField('text', $fieldid . '[title]', $vals['origkey'], $this->getLang('title')),
+ // when editable, always use the pure key, not a title
form_makeMenuField(
$fieldid . '[type]',
array_merge(
- array(
- '', 'page', 'nspage', 'title',
- 'img', 'mail', 'url', 'tag', 'wiki', 'dt', 'hidden'
- ),
- array_keys($this->dthlp->_aliases())
+ ['', 'page', 'nspage', 'title', 'img', 'mail', 'url', 'tag', 'wiki', 'dt', 'hidden'],
+ array_keys($this->dthlp->aliases())
),
$vals['type'],
$this->getLang('type')
),
- form_makeCheckboxField($fieldid . '[multi]', array('1', ''), $this->getLang('multi'), '', '', $check_data),
- form_makeField('text', $fieldid . '[value]', $content, $this->getLang('value')),
- form_makeField('text', $fieldid . '[comment]', $vals['comment'], $this->getLang('comment'), '', 'data_comment', array('readonly' => 1, 'title' => $vals['comment']))
- );
+ form_makeCheckboxField(
+ $fieldid . '[multi]',
+ ['1', ''],
+ $this->getLang('multi'),
+ '',
+ '',
+ $check_data
+ ),
+ form_makeField(
+ 'text',
+ $fieldid . '[value]',
+ $content,
+ $this->getLang('value')
+ ),
+ form_makeField(
+ 'text',
+ $fieldid . '[comment]',
+ $vals['comment'],
+ $this->getLang('comment'),
+ '',
+ 'data_comment',
+ ['readonly' => 1, 'title' => $vals['comment']]
+ ),
+ ];
}
foreach ($cells as $index => $cell) {
@@ -435,7 +487,6 @@ protected function _editDataLegacy($data, &$renderer)
$renderer->form->addElement('
');
$renderer->form->endFieldset();
-
}
/**
@@ -446,27 +497,26 @@ protected function _editDataLegacy($data, &$renderer)
* @param array $data
* @param Doku_Renderer_plugin_data_edit $renderer
*/
- protected function _editData($data, &$renderer)
+ protected function editData($data, &$renderer)
{
$renderer->form->addFieldsetOpen($this->getLang('dataentry'))->attr('class', 'plugin__data');
if ($this->getConf('edit_content_only')) {
$renderer->form->setHiddenField('data_edit[classes]', $data['classes']);
- $columns = array('title', 'value', 'comment');
+ $columns = ['title', 'value', 'comment'];
$class = 'edit_content_only';
-
} else {
$renderer->form->addTextInput('data_edit[classes]', $this->getLang('class'))
->id('data__classes')
->val($data['classes']);
- $columns = array('title', 'type', 'multi', 'value', 'comment');
+ $columns = ['title', 'type', 'multi', 'value', 'comment'];
$class = 'edit_all_content';
// New line
$data['data'][''] = '';
- $data['cols'][''] = array('type' => '', 'multi' => false);
+ $data['cols'][''] = ['type' => '', 'multi' => false];
}
$renderer->form->addHTML("");
@@ -506,71 +556,67 @@ protected function _editData($data, &$renderer)
array_unshift($values, '');
}
- $el = new \dokuwiki\plugin\data\Form\DropdownElement(
+ $el = new DropdownElement(
$fieldid . '[value]',
$values,
$vals['title']
);
$el->useInput(false);
- $el->attrs(($vals['multi'] ? array('multiple' => 'multiple') : array()));
+ $el->attrs(($vals['multi'] ? ['multiple' => 'multiple'] : []));
$el->attr('selected', $data['data'][$key]);
$el->val($data['data'][$key]);
} else {
$classes = 'data_type_' . $vals['type'] . ($vals['multi'] ? 's' : '') . ' '
. 'data_type_' . $vals['basetype'] . ($vals['multi'] ? 's' : '');
- $attr = array();
+ $attr = [];
if ($vals['basetype'] == 'date' && !$vals['multi']) {
$attr['class'] = 'datepicker';
}
- $el = new \dokuwiki\Form\InputElement('text', $fieldid . '[value]', $vals['title']);
+ $el = new InputElement('text', $fieldid . '[value]', $vals['title']);
$el->useInput(false);
$el->val($content);
$el->addClass($classes);
$el->attrs($attr);
-
}
- $cells = array(
- hsc($vals['title']) . ':',
- $el,
+ $cells = [
+ hsc($vals['title']) . ':', $el,
'' . hsc($vals['comment'] ?? '') . ''
- );
- foreach (array('multi', 'comment', 'type') as $field) {
+ ];
+ foreach (['multi', 'comment', 'type'] as $field) {
$renderer->form->setHiddenField($fieldid . "[$field]", $vals[$field] ?? '');
}
- $renderer->form->setHiddenField($fieldid . "[title]", $vals['origkey'] ?? ''); //keep key as key, even if title is translated
+ //keep key as key, even if title is translated
+ $renderer->form->setHiddenField($fieldid . "[title]", $vals['origkey'] ?? '');
} else {
- $check_data = $vals['multi'] ? array('checked' => 'checked') : array();
- $cells = array();
+ $check_data = $vals['multi'] ? ['checked' => 'checked'] : [];
+ $cells = [];
- $el = new \dokuwiki\Form\InputElement('text', $fieldid . '[title]', $this->getLang('title'));
+ $el = new InputElement('text', $fieldid . '[title]', $this->getLang('title'));
$el->val($vals['origkey'] ?? '');
$cells[] = $el;
$el = new \dokuwiki\Form\DropdownElement(
$fieldid . '[type]',
array_merge(
- array(
- '', 'page', 'nspage', 'title',
- 'img', 'mail', 'url', 'tag', 'wiki', 'dt', 'hidden'
- ),
- array_keys($this->dthlp->_aliases())
+ ['', 'page', 'nspage', 'title', 'img', 'mail', 'url', 'tag', 'wiki', 'dt', 'hidden'],
+ array_keys($this->dthlp->aliases())
),
$this->getLang('type')
);
$el->val($vals['type']);
$cells[] = $el;
- $el = new \dokuwiki\Form\CheckableElement('checkbox', $fieldid . '[multi]', $this->getLang('multi'));
+ $el = new CheckableElement('checkbox', $fieldid . '[multi]', $this->getLang('multi'));
$el->attrs($check_data);
$cells[] = $el;
- $el = new \dokuwiki\Form\InputElement('text', $fieldid . '[value]', $this->getLang('value'));
+ $el = new InputElement('text', $fieldid . '[value]', $this->getLang('value'));
$el->val($content);
$cells[] = $el;
- $el = new \dokuwiki\Form\InputElement('text', $fieldid . '[comment]', $this->getLang('comment'));
+ $el = new InputElement('text', $fieldid . '[comment]', $this->getLang('comment'));
$el->addClass('data_comment');
$el->attrs(['readonly' => '1', 'title' => $vals['comment'] ?? '']);
$el->val($vals['comment'] ?? '');
@@ -600,7 +646,7 @@ protected function _editData($data, &$renderer)
* @return mixed
* @todo bad naming
*/
- public static function _normalize($txt)
+ public static function normalize($txt)
{
return str_replace('#', '\#', trim($txt));
}
@@ -613,20 +659,20 @@ public static function _normalize($txt)
*/
public static function editToWiki($data)
{
- $nudata = array();
+ $nudata = [];
$len = 0; // we check the maximum lenght for nice alignment later
foreach ($data['data'] as $field) {
if (is_array($field['value'])) {
- $field['value'] = join(', ', $field['value']);
+ $field['value'] = implode(', ', $field['value']);
}
$field = array_map('trim', $field);
if ($field['title'] === '') continue;
- $name = syntax_plugin_data_entry::_normalize($field['title']);
+ $name = syntax_plugin_data_entry::normalize($field['title']);
if ($field['type'] !== '') {
- $name .= '_' . syntax_plugin_data_entry::_normalize($field['type']);
+ $name .= '_' . syntax_plugin_data_entry::normalize($field['type']);
} elseif (substr($name, -1, 1) === 's') {
$name .= '_'; // when the field name ends in 's' we need to secure it against being assumed as multi
}
@@ -635,13 +681,13 @@ public static function editToWiki($data)
$name .= 's';
}
- $nudata[] = array($name, syntax_plugin_data_entry::_normalize($field['value']), $field['comment']);
- $len = max($len, PHPString::strlen($nudata[count($nudata) - 1][0]));
+ $nudata[] = [$name, syntax_plugin_data_entry::normalize($field['value']), $field['comment']];
+ $len = max($len, PhpString::strlen($nudata[count($nudata) - 1][0]));
}
$ret = '---- dataentry ' . trim($data['classes']) . ' ----' . DOKU_LF;
foreach ($nudata as $field) {
- $ret .= $field[0] . str_repeat(' ', $len + 1 - PHPString::strlen($field[0])) . ': ';
+ $ret .= $field[0] . str_repeat(' ', $len + 1 - PhpString::strlen($field[0])) . ': ';
$ret .= $field[1];
if ($field[2] !== '') {
$ret .= ' # ' . $field[2];
diff --git a/syntax/list.php b/syntax/list.php
index cc472d2..c325931 100644
--- a/syntax/list.php
+++ b/syntax/list.php
@@ -1,4 +1,5 @@
Lexer->addSpecialPattern('----+ *datalist(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+', $mode, 'plugin_data_list');
}
@@ -34,7 +34,7 @@ function connectTo($mode)
*/
protected function beforeVal(&$data, $colno)
{
- if ($data['sepbyheaders'] and $colno === 0) {
+ if ($data['sepbyheaders'] && $colno === 0) {
return $data['headers'][$colno];
} else {
return $this->before_val;
@@ -64,7 +64,7 @@ protected function afterVal(&$data, $colno)
* @param array $data instruction by handler
* @return string html of table header
*/
- function preList($clist, $data)
+ public function preList($clist, $data)
{
return '';
}
@@ -76,7 +76,7 @@ function preList($clist, $data)
* @param array $clist keys of the columns
* @param Doku_Renderer $R
*/
- function nullList($data, $clist, $R)
+ public function nullList($data, $clist, $R)
{
$R->doc .= '';
$R->cdata($this->getLang('none'));
@@ -90,9 +90,8 @@ function nullList($data, $clist, $R)
* @param int $rowcnt number of rows
* @return string html of table footer
*/
- function postList($data, $rowcnt)
+ public function postList($data, $rowcnt)
{
return '
';
}
-
}
diff --git a/syntax/related.php b/syntax/related.php
index ec9c138..ba8f69f 100644
--- a/syntax/related.php
+++ b/syntax/related.php
@@ -1,4 +1,5 @@
Lexer->addSpecialPattern('----+ *datarelated(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+', $mode, 'plugin_data_related');
+ $this->Lexer->addSpecialPattern(
+ '----+ *datarelated(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+',
+ $mode,
+ 'plugin_data_related'
+ );
}
/**
@@ -28,17 +32,17 @@ function connectTo($mode)
* @param array $data data created by handler()
* @return boolean rendered correctly? (however, returned value is not used at the moment)
*/
- function render($format, Doku_Renderer $renderer, $data)
+ public function render($format, Doku_Renderer $renderer, $data)
{
if ($format != 'xhtml') return false;
if (is_null($data)) return false;
if (!$this->dthlp->ready()) return false;
- $sqlite = $this->dthlp->_getDB();
+ $sqlite = $this->dthlp->getDB();
if (!$sqlite) return false;
if (!$data['sql']) return true; // sql build
- $this->dthlp->_replacePlaceholdersInSQL($data);
+ $this->dthlp->replacePlaceholdersInSQL($data);
$rows = $sqlite->queryAll($data['sql']);
if (!$rows) return true; // no rows matched
@@ -62,18 +66,18 @@ function render($format, Doku_Renderer $renderer, $data)
/**
* Builds the SQL query from the given data
*/
- function _buildSQL(&$data, $id = null)
+ public function buildSQL(&$data, $id = null)
{
global $ID;
if (is_null($id)) $id = $ID;
$cnt = 1;
- $tables = array();
- $cond = array();
+ $tables = [];
+ $cond = [];
$from = '';
$where = '';
- $sqlite = $this->dthlp->_getDB();
+ $sqlite = $this->dthlp->getDB();
if (!$sqlite) return false;
// prepare the columns to match against
@@ -86,15 +90,15 @@ function _buildSQL(&$data, $id = null)
AND A.pid = B.pid
AND B.page = ?";
$rows = $sqlite->queryAll($sql, $col, $id);
- if(!$rows) continue; // no values? ignore the column.
+ if (!$rows) continue; // no values? ignore the column.
$values = array_column($rows, 'value');
$found = true;
- $in = join(',', array_map([$sqlite->getPdo(), 'quote'], $values));
+ $in = implode(',', array_map([$sqlite->getPdo(), 'quote'], $values));
$cond[] = " ( T1.key = " . $sqlite->getPdo()->quote($col) .
" AND T1.value IN (" . $in . ") )\n";
}
- $where .= ' AND (' . join(' OR ', $cond) . ') ';
+ $where .= ' AND (' . implode(' OR ', $cond) . ') ';
// any tags to compare?
if (!$found) return false;
@@ -131,9 +135,14 @@ function _buildSQL(&$data, $id = null)
$closecompare = ($filter['compare'] == 'IN(' ? ')' : '');
if ($col == '%pageid%') {
- $where .= " " . $filter['logic'] . " pages.page " . $filter['compare'] . " " . $filter['value'] . $closecompare;
+ $where .= " " . $filter['logic'] . " pages.page "
+ . $filter['compare'] . " "
+ . $filter['value'] . $closecompare;
} elseif ($col == '%title%') {
- $where .= " " . $filter['logic'] . " pages.title " . $filter['compare'] . " " . $filter['value'] . $closecompare;
+ $where .= " "
+ . $filter['logic'] . " pages.title "
+ . $filter['compare'] . " "
+ . $filter['value'] . $closecompare;
} else {
// filter by hidden column?
if (!$tables[$col]) {
diff --git a/syntax/table.php b/syntax/table.php
index fbae805..6046ccc 100644
--- a/syntax/table.php
+++ b/syntax/table.php
@@ -1,29 +1,30 @@
*/
-
/**
* Class syntax_plugin_data_table
*/
-class syntax_plugin_data_table extends DokuWiki_Syntax_Plugin
+class syntax_plugin_data_table extends SyntaxPlugin
{
-
/**
* will hold the data helper plugin
*
* @var $dthlp helper_plugin_data
*/
- var $dthlp = null;
+ public $dthlp;
- var $sums = array();
+ public $sums = [];
/**
* Constructor. Load helper plugin
*/
- function __construct()
+ public function __construct()
{
$this->dthlp = plugin_load('helper', 'data');
}
@@ -31,7 +32,7 @@ function __construct()
/**
* What kind of syntax are we?
*/
- function getType()
+ public function getType()
{
return 'substition';
}
@@ -39,7 +40,7 @@ function getType()
/**
* What about paragraphs?
*/
- function getPType()
+ public function getPType()
{
return 'block';
}
@@ -47,7 +48,7 @@ function getPType()
/**
* Where to sort in?
*/
- function getSort()
+ public function getSort()
{
return 155;
}
@@ -55,9 +56,13 @@ function getSort()
/**
* Connect pattern to lexer
*/
- function connectTo($mode)
+ public function connectTo($mode)
{
- $this->Lexer->addSpecialPattern('----+ *datatable(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+', $mode, 'plugin_data_table');
+ $this->Lexer->addSpecialPattern(
+ '----+ *datatable(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+',
+ $mode,
+ 'plugin_data_table'
+ );
}
/**
@@ -72,7 +77,7 @@ function connectTo($mode)
* @param Doku_Handler $handler The Doku_Handler object
* @return bool|array Return an array with all data you want to use in render, false don't add an instruction
*/
- function handle($match, $state, $pos, Doku_Handler $handler)
+ public function handle($match, $state, $pos, Doku_Handler $handler)
{
if (!$this->dthlp->ready()) return null;
@@ -83,17 +88,17 @@ function handle($match, $state, $pos, Doku_Handler $handler)
$class = preg_replace('/^----+ *data[a-z]+/', '', $class);
$class = trim($class, '- ');
- $data = array(
+ $data = [
'classes' => $class,
'limit' => 0,
'dynfilters' => false,
'summarize' => false,
'rownumbers' => (bool)$this->getConf('rownumbers'),
'sepbyheaders' => false,
- 'headers' => array(),
- 'widths' => array(),
- 'filter' => array()
- );
+ 'headers' => [],
+ 'widths' => [],
+ 'filter' => []
+ ];
// parse info
foreach ($lines as $line) {
@@ -116,7 +121,7 @@ function handle($match, $state, $pos, Doku_Handler $handler)
foreach ($cols as $col) {
$col = trim($col);
if (!$col) continue;
- $column = $this->dthlp->_column($col);
+ $column = $this->dthlp->column($col);
$data['cols'][$column['key']] = $column;
}
break;
@@ -159,26 +164,25 @@ function handle($match, $state, $pos, Doku_Handler $handler)
break;
case 'order':
case 'sort':
- $column = $this->dthlp->_column($line[1]);
+ $column = $this->dthlp->column($line[1]);
$sort = $column['key'];
if (substr($sort, 0, 1) == '^') {
- $data['sort'] = array(substr($sort, 1), 'DESC');
+ $data['sort'] = [substr($sort, 1), 'DESC'];
} else {
- $data['sort'] = array($sort, 'ASC');
+ $data['sort'] = [$sort, 'ASC'];
}
break;
case 'where':
case 'filter':
case 'filterand':
- /** @noinspection PhpMissingBreakStatementInspection */
- case 'and':
+ case 'and': // phpcs:ignore PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
$logic = 'AND';
case 'filteror':
case 'or':
if (!$logic) {
$logic = 'OR';
}
- $flt = $this->dthlp->_parse_filter($line[1]);
+ $flt = $this->dthlp->parseFilter($line[1]);
if (is_array($flt)) {
$flt['logic'] = $logic;
$data['filter'][] = $flt;
@@ -206,7 +210,7 @@ function handle($match, $state, $pos, Doku_Handler $handler)
}
// we need at least one column to display
- if (!is_array($data['cols']) || !count($data['cols'])) {
+ if (!is_array($data['cols']) || $data['cols'] === []) {
msg('data plugin: no columns selected', -1);
return null;
}
@@ -221,10 +225,10 @@ function handle($match, $state, $pos, Doku_Handler $handler)
$data['headers'][] = $columnprops['title'];
}
- $data['sql'] = $this->_buildSQL($data);
+ $data['sql'] = $this->buildSQL($data);
// Save current request params for comparison in updateSQL
- $data['cur_param'] = $this->dthlp->_get_current_param(false);
+ $data['cur_param'] = $this->dthlp->getPurrentParam(false);
return $data;
}
@@ -237,29 +241,27 @@ function handle($match, $state, $pos, Doku_Handler $handler)
* Handles the actual output creation.
*
* @param string $format output format being rendered
- * @param Doku_Renderer $R the current renderer object
+ * @param Doku_Renderer $renderer the current renderer object
* @param array $data data created by handler()
* @return boolean rendered correctly? (however, returned value is not used at the moment)
*/
- function render($format, Doku_Renderer $R, $data)
+ public function render($format, Doku_Renderer $renderer, $data)
{
if ($format != 'xhtml') return false;
- /** @var Doku_Renderer_xhtml $R */
-
if (is_null($data)) return false;
if (!$this->dthlp->ready()) return false;
- $sqlite = $this->dthlp->_getDB();
+ $sqlite = $this->dthlp->getDB();
if (!$sqlite) return false;
- $R->info['cache'] = false;
+ $renderer->info['cache'] = false;
//reset counters
- $this->sums = array();
+ $this->sums = [];
- if ($this->hasRequestFilter() or isset($_REQUEST['dataofs'])) {
+ if ($this->hasRequestFilter() || isset($_REQUEST['dataofs'])) {
$this->updateSQLwithQuery($data); // handles request params
}
- $this->dthlp->_replacePlaceholdersInSQL($data);
+ $this->dthlp->replacePlaceholdersInSQL($data);
// run query
$clist = array_keys($data['cols']);
@@ -267,7 +269,7 @@ function render($format, Doku_Renderer $R, $data)
$cnt = count($rows);
if ($cnt === 0) {
- $this->nullList($data, $clist, $R);
+ $this->nullList($data, $clist, $renderer);
return true;
}
@@ -276,8 +278,8 @@ function render($format, Doku_Renderer $R, $data)
}
//build classnames per column
- $classes = array();
- $class_names_cache = array();
+ $classes = [];
+ $class_names_cache = [];
$offset = 0;
if ($data['rownumbers']) {
$offset = 1; //rownumbers are in first column
@@ -293,27 +295,28 @@ function render($format, Doku_Renderer $R, $data)
}
//start table/list
- $R->doc .= $this->preList($clist, $data);
+ $renderer->doc .= $this->preList($clist, $data);
foreach ($rows as $rownum => $row) {
// build data rows
- $R->doc .= $this->before_item;
+ $renderer->doc .= $this->before_item;
if ($data['rownumbers']) {
- $R->doc .= sprintf($this->before_val, 'class="' . $classes[0] . '"');
- $R->doc .= $rownum + 1;
- $R->doc .= $this->after_val;
+ $renderer->doc .= sprintf($this->before_val, 'class="' . $classes[0] . '"');
+ $renderer->doc .= $rownum + 1;
+ $renderer->doc .= $this->after_val;
}
foreach (array_values($row) as $num => $cval) {
$num_rn = $num + $offset;
- $R->doc .= sprintf($this->beforeVal($data, $num_rn), 'class="' . $classes[$num_rn] . '"');
- $R->doc .= $this->dthlp->_formatData(
+ $renderer->doc .= sprintf($this->beforeVal($data, $num_rn), 'class="' . $classes[$num_rn] . '"');
+ $renderer->doc .= $this->dthlp->formatData(
$data['cols'][$clist[$num]],
- $cval, $R
+ $cval,
+ $renderer
);
- $R->doc .= $this->afterVal($data, $num_rn);
+ $renderer->doc .= $this->afterVal($data, $num_rn);
// clean currency symbols
$nval = str_replace('$€₤', '', $cval);
@@ -328,11 +331,10 @@ function render($format, Doku_Renderer $R, $data)
}
$this->sums[$num] += $nval;
}
-
}
- $R->doc .= $this->after_item;
+ $renderer->doc .= $this->after_item;
}
- $R->doc .= $this->postList($data, $cnt);
+ $renderer->doc .= $this->postList($data, $cnt);
return true;
}
@@ -368,19 +370,19 @@ protected function afterVal(&$data, $colno)
* @param array $data instruction by handler
* @return string html of table header
*/
- function preList($clist, $data)
+ public function preList($clist, $data)
{
global $ID;
global $conf;
// Save current request params to not loose them
- $cur_params = $this->dthlp->_get_current_param();
+ $cur_params = $this->dthlp->getPurrentParam();
//show active filters
$text = '';
if (isset($_REQUEST['dataflt'])) {
- $filters = $this->dthlp->_get_filters();
- $fltrs = array();
+ $filters = $this->dthlp->getFilters();
+ $fltrs = [];
foreach ($filters as $filter) {
if (strpos($filter['compare'], 'LIKE') !== false) {
if (strpos($filter['compare'], 'NOT') !== false) {
@@ -414,7 +416,7 @@ function preList($clist, $data)
$ckey = $clist[$num];
$width = '';
- if (isset($data['widths'][$num]) and $data['widths'][$num] != '-') {
+ if (isset($data['widths'][$num]) && $data['widths'][$num] != '-') {
$width = ' style="width: ' . $data['widths'][$num] . ';"';
}
$text .= '
';
@@ -430,7 +432,7 @@ function preList($clist, $data)
}
// Clickable header for dynamic sorting
- $text .= ' $ckey] + $cur_params) .
'" title="' . $this->getLang('sort') . '">' . hsc($head) . '';
$text .= ' | ';
}
@@ -446,14 +448,14 @@ function preList($clist, $data)
foreach ($data['headers'] as $num => $head) {
$text .= '
';
- $form = new Doku_Form(array('method' => 'GET'));
- $form->_hidden = array();
+ $form = new Doku_Form(['method' => 'GET']);
+ $form->_hidden = [];
if (!$conf['userewrite']) {
$form->addHidden('id', $ID);
}
$key = 'dataflt[' . $data['cols'][$clist[$num]]['colname'] . '*~' . ']';
- $val = isset($cur_params[$key]) ? $cur_params[$key] : '';
+ $val = $cur_params[$key] ?? '';
// Add current request params
foreach ($cur_params as $c_key => $c_val) {
@@ -479,7 +481,7 @@ function preList($clist, $data)
* @param array $clist keys of the columns
* @param Doku_Renderer $R
*/
- function nullList($data, $clist, $R)
+ public function nullList($data, $clist, $R)
{
$R->doc .= $this->preList($clist, $data);
$R->tablerow_open();
@@ -497,7 +499,7 @@ function nullList($data, $clist, $R)
* @param int $rowcnt number of rows
* @return string html of table footer
*/
- function postList($data, $rowcnt)
+ public function postList($data, $rowcnt)
{
global $ID;
$text = '';
@@ -531,7 +533,7 @@ function postList($data, $rowcnt)
}
// keep url params
- $params = $this->dthlp->_a2ua('dataflt', $_REQUEST['dataflt']);
+ $params = $this->dthlp->a2ua('dataflt', $_REQUEST['dataflt']);
if (isset($_REQUEST['datasrt'])) {
$params['datasrt'] = $_REQUEST['datasrt'];
}
@@ -548,7 +550,7 @@ function postList($data, $rowcnt)
$next = $offset + $data['limit'];
// keep url params
- $params = $this->dthlp->_a2ua('dataflt', $_REQUEST['dataflt']);
+ $params = $this->dthlp->a2ua('dataflt', $_REQUEST['dataflt']);
if (isset($_REQUEST['datasrt'])) {
$params['datasrt'] = $_REQUEST['datasrt'];
}
@@ -571,17 +573,17 @@ function postList($data, $rowcnt)
* @param array &$data instruction by handler
* @return bool|string SQL query or false
*/
- function _buildSQL(&$data)
+ public function buildSQL(&$data)
{
$cnt = 0;
- $tables = array();
- $select = array();
+ $tables = [];
+ $select = [];
$from = '';
$from2 = '';
$where2 = '1 = 1';
- $sqlite = $this->dthlp->_getDB();
+ $sqlite = $this->dthlp->getDB();
if (!$sqlite) return false;
// prepare the columns to show
@@ -653,21 +655,24 @@ function _buildSQL(&$data)
// prepare filters
$cnt = 0;
if (is_array($data['filter']) && count($data['filter'])) {
-
foreach ($data['filter'] as $filter) {
$col = $filter['key'];
$closecompare = ($filter['compare'] == 'IN(' ? ')' : '');
if ($col == '%pageid%') {
- $where2 .= " " . $filter['logic'] . " pages.page " . $filter['compare'] . " " . $filter['value'] . $closecompare;
+ $where2 .= " " . $filter['logic'] . " pages.page " .
+ $filter['compare'] . " " . $filter['value'] . $closecompare;
} elseif ($col == '%class%') {
- $where2 .= " " . $filter['logic'] . " pages.class " . $filter['compare'] . " " . $filter['value'] . $closecompare;
+ $where2 .= " " . $filter['logic'] . " pages.class " .
+ $filter['compare'] . " " . $filter['value'] . $closecompare;
} elseif ($col == '%title%') {
- $where2 .= " " . $filter['logic'] . " pages.title " . $filter['compare'] . " " . $filter['value'] . $closecompare;
+ $where2 .= " " . $filter['logic'] . " pages.title " .
+ $filter['compare'] . " " . $filter['value'] . $closecompare;
} elseif ($col == '%lastmod%') {
# parse value to int?
$filter['value'] = (int)strtotime($filter['value']);
- $where2 .= " " . $filter['logic'] . " pages.lastmod " . $filter['compare'] . " " . $filter['value'] . $closecompare;
+ $where2 .= " " . $filter['logic'] . " pages.lastmod " .
+ $filter['compare'] . " " . $filter['value'] . $closecompare;
} else {
// filter by hidden column?
$table = 'T' . (++$cnt);
@@ -676,7 +681,9 @@ function _buildSQL(&$data)
// apply data resolving?
if ($use_dataresolve && $filter['colname'] && (substr($filter['compare'], -4) == 'LIKE')) {
- $where2 .= ' ' . $filter['logic'] . ' DATARESOLVE(' . $table . '.value,' . $sqlite->getPdo()->quote($filter['colname']) . ') ' . $filter['compare'] .
+ $where2 .= ' ' . $filter['logic'] .
+ ' DATARESOLVE(' . $table . '.value,' . $sqlite->getPdo()->quote($filter['colname']) . ') ' .
+ $filter['compare'] .
" " . $filter['value']; //value is already escaped
} else {
$where2 .= ' ' . $filter['logic'] . ' ' . $table . '.value ' . $filter['compare'] .
@@ -687,7 +694,7 @@ function _buildSQL(&$data)
}
// build the query
- $sql = "SELECT " . join(', ', $select) . "
+ $sql = "SELECT " . implode(', ', $select) . "
FROM (
SELECT DISTINCT pages.pid AS pid
FROM pages $from2
@@ -712,22 +719,22 @@ function _buildSQL(&$data)
*
* @param array $data instruction by handler()
*/
- function updateSQLwithQuery(&$data)
+ public function updateSQLwithQuery(&$data)
{
if ($this->hasRequestFilter()) {
if (isset($_REQUEST['datasrt'])) {
if ($_REQUEST['datasrt'][0] == '^') {
- $data['sort'] = array(substr($_REQUEST['datasrt'], 1), 'DESC');
+ $data['sort'] = [substr($_REQUEST['datasrt'], 1), 'DESC'];
} else {
- $data['sort'] = array($_REQUEST['datasrt'], 'ASC');
+ $data['sort'] = [$_REQUEST['datasrt'], 'ASC'];
}
}
// add request filters
- $data['filter'] = array_merge($data['filter'], $this->dthlp->_get_filters());
+ $data['filter'] = array_merge($data['filter'], $this->dthlp->getFilters());
// Rebuild SQL FIXME do this smarter & faster
- $data['sql'] = $this->_buildSQL($data);
+ $data['sql'] = $this->buildSQL($data);
}
if ($data['limit'] && (int)$_REQUEST['dataofs']) {
@@ -740,7 +747,7 @@ function updateSQLwithQuery(&$data)
*
* @return bool
*/
- function hasRequestFilter()
+ public function hasRequestFilter()
{
return isset($_REQUEST['datasrt']) || isset($_REQUEST['dataflt']);
}
@@ -755,7 +762,7 @@ function hasRequestFilter()
*/
protected function parseValues($line)
{
- $values = array();
+ $values = [];
$inQuote = false;
$escapedQuote = false;
$value = '';
@@ -773,17 +780,16 @@ protected function parseValues($line)
$escapedQuote = true;
continue;
}
- array_push($values, $value);
+ $values[] = $value;
$inQuote = false;
$value = '';
continue;
-
} else {
$inQuote = true;
$value = ''; //don't store stuff before the opening quote
continue;
}
- } else if ($line[$i] == ',') {
+ } elseif ($line[$i] == ',') {
if ($inQuote) {
$value .= ',';
continue;
@@ -791,7 +797,7 @@ protected function parseValues($line)
if (strlen($value) < 1) {
continue;
}
- array_push($values, trim($value));
+ $values[] = trim($value);
$value = '';
continue;
}
@@ -800,9 +806,8 @@ protected function parseValues($line)
$value .= $line[$i];
}
if (strlen($value) > 0) {
- array_push($values, trim($value));
+ $values[] = trim($value);
}
return $values;
}
}
-
diff --git a/syntax/taglist.php b/syntax/taglist.php
index abf5238..e3fa379 100644
--- a/syntax/taglist.php
+++ b/syntax/taglist.php
@@ -1,4 +1,5 @@
Lexer->addSpecialPattern('----+ *datataglist(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+', $mode, 'plugin_data_taglist');
+ $this->Lexer->addSpecialPattern(
+ '----+ *datataglist(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+',
+ $mode,
+ 'plugin_data_taglist'
+ );
}
protected $before_item = '';
@@ -34,13 +38,11 @@ function connectTo($mode)
* @param $max int The highest count of a single tag
* @param $levels int The number of levels you want. A 5 gives levels 0 to 4.
*/
- protected function _cloud_weight(&$tags, $min, $max, $levels)
+ protected function cloudWeight(&$tags, $min, $max, $levels)
{
- parent::_cloud_weight($tags, $min, $max, $levels);
+ parent::cloudWeight($tags, $min, $max, $levels);
// sort by values. Key is name of the single tag, value the count
arsort($tags);
}
-
}
-
|