diff --git a/GenericResolver.php b/GenericResolver.php
index d02d69c..edbfae3 100644
--- a/GenericResolver.php
+++ b/GenericResolver.php
@@ -1,5 +1,7 @@
helper = plugin_load('helper', 'include');
}
/**
* plugin should use this method to register its handlers with the dokuwiki's event controller
*/
- function register(Doku_Event_Handler $controller) {
+ public function register(EventHandler $controller)
+ {
/* @var Doku_event_handler $controller */
$controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handle_indexer');
$controller->register_hook('INDEXER_VERSION_GET', 'BEFORE', $this, 'handle_indexer_version');
- $controller->register_hook('PARSER_CACHE_USE','BEFORE', $this, '_cache_prepare');
+ $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, '_cache_prepare');
$controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, 'handle_form'); // todo remove
$controller->register_hook('FORM_EDIT_OUTPUT', 'BEFORE', $this, 'handle_form');
$controller->register_hook('HTML_CONFLICTFORM_OUTPUT', 'BEFORE', $this, 'handle_form'); // todo remove
@@ -47,17 +55,19 @@ function register(Doku_Event_Handler $controller) {
* Add a version string to the index so it is rebuilt
* whenever the handler is updated or the safeindex setting is changed
*/
- public function handle_indexer_version($event, $param) {
- $event->data['plugin_include'] = '0.1.safeindex='.$this->getConf('safeindex');
+ public function handle_indexer_version($event, $param)
+ {
+ $event->data['plugin_include'] = '0.1.safeindex=' . $this->getConf('safeindex');
}
/**
* Handles the INDEXER_PAGE_ADD event, prevents indexing of metadata from included pages that aren't public if enabled
*
- * @param Doku_Event $event the event object
+ * @param Event $event the event object
* @param array $params optional parameters (unused)
*/
- public function handle_indexer(Doku_Event $event, $params) {
+ public function handle_indexer(Event $event, $params)
+ {
global $USERINFO;
// check if the feature is enabled at all
@@ -72,7 +82,7 @@ public function handle_indexer(Doku_Event $event, $params) {
// check if the current metadata indicates that non-public pages were included
if ($inclmeta !== null && isset($inclmeta['pages'])) {
foreach ($inclmeta['pages'] as $page) {
- if (auth_aclcheck($page['id'], '', array()) < AUTH_READ) { // is $page public?
+ if (auth_aclcheck($page['id'], '', []) < AUTH_READ) { // is $page public?
$all_public = false;
break;
}
@@ -98,23 +108,23 @@ public function handle_indexer(Doku_Event $event, $params) {
$tag_called = isset($event->data['metadata']['subject']);
// Reset the metadata in the renderer. This removes data from all other event handlers, but we need to be on the safe side here.
- $event->data['metadata'] = array('title' => $meta['title']);
+ $event->data['metadata'] = ['title' => $meta['title']];
// restore the relation references metadata
if (isset($meta['relation']['references'])) {
$event->data['metadata']['relation_references'] = array_keys($meta['relation']['references']);
} else {
- $event->data['metadata']['relation_references'] = array();
+ $event->data['metadata']['relation_references'] = [];
}
// restore the tag metadata if the tag plugin handler has been called before the include plugin handler.
if ($tag_called) {
$tag_helper = $this->loadHelper('tag', false);
if ($tag_helper) {
- if (isset($meta['subject'])) {
+ if (isset($meta['subject'])) {
$event->data['metadata']['subject'] = $tag_helper->_cleanTagList($meta['subject']);
} else {
- $event->data['metadata']['subject'] = array();
+ $event->data['metadata']['subject'] = [];
}
}
}
@@ -128,9 +138,10 @@ public function handle_indexer(Doku_Event $event, $params) {
/**
* Used for debugging purposes only
*/
- function handle_metadata(&$event, $param) {
+ public function handle_metadata(&$event, $param)
+ {
global $conf;
- if($conf['allowdebug'] && $this->getConf('debugoutput')) {
+ if ($conf['allowdebug'] && $this->getConf('debugoutput')) {
dbglog('---- PLUGIN INCLUDE META DATA START ----');
dbglog($event->data);
dbglog('---- PLUGIN INCLUDE META DATA END ----');
@@ -143,31 +154,23 @@ function handle_metadata(&$event, $param) {
* @author Michael Klier
* @author Michael Hamann
*/
- function handle_parser(Doku_Event $event, $param) {
+ public function handle_parser(Event $event, $param)
+ {
global $ID;
$level = 0;
$ins =& $event->data->calls;
$num = count($ins);
- for($i=0; $i<$num; $i++) {
- switch($ins[$i][0]) {
- case 'plugin':
- switch($ins[$i][1][0]) {
- case 'include_include':
- $ins[$i][1][1][4] = $level;
+ for ($i = 0; $i < $num; $i++) {
+ switch ($ins[$i][0]) {
+ case 'plugin':
+ if ($ins[$i][1][0] === 'include_include') {
+ $ins[$i][1][1][4] = $level;
+ }
break;
- /* FIXME: this doesn't work anymore that way with the new structure
- // some plugins already close open sections
- // so we need to make sure we don't close them twice
- case 'box':
- $this->helper->sec_close = false;
+ case 'section_open':
+ $level = $ins[$i][1][0];
break;
- */
- }
- break;
- case 'section_open':
- $level = $ins[$i][1][0];
- break;
}
}
}
@@ -175,11 +178,11 @@ function handle_parser(Doku_Event $event, $param) {
/**
* Add a hidden input to the form to preserve the redirect_id
*/
- function handle_form(Doku_Event $event, $param)
+ public function handle_form(Event $event, $param)
{
if (!array_key_exists('redirect_id', $_REQUEST)) return;
- if(is_a($event->data, \dokuwiki\Form\Form::class)) {
+ if (is_a($event->data, Form::class)) {
$event->data->setHiddenField('redirect_id', cleanID($_REQUEST['redirect_id']));
} else {
// todo remove when old FORM events are no longer supported
@@ -190,35 +193,37 @@ function handle_form(Doku_Event $event, $param)
/**
* Modify the data for the redirect when there is a redirect_id set
*/
- function handle_redirect(Doku_Event &$event, $param) {
- if (array_key_exists('redirect_id', $_REQUEST)) {
- // Render metadata when this is an older DokuWiki version where
- // metadata is not automatically re-rendered as the page has probably
- // been changed but is not directly displayed
- $versionData = getVersionData();
- if ($versionData['date'] < '2010-11-23') {
- p_set_metadata($event->data['id'], array(), true);
+ public function handle_redirect(Event &$event, $param)
+ {
+ if (array_key_exists('redirect_id', $_REQUEST)) {
+ // Render metadata when this is an older DokuWiki version where
+ // metadata is not automatically re-rendered as the page has probably
+ // been changed but is not directly displayed
+ $versionData = getVersionData();
+ if ($versionData['date'] < '2010-11-23') {
+ p_set_metadata($event->data['id'], [], true);
+ }
+ $event->data['id'] = cleanID($_REQUEST['redirect_id']);
+ $event->data['title'] = '';
}
- $event->data['id'] = cleanID($_REQUEST['redirect_id']);
- $event->data['title'] = '';
- }
}
/**
* prepare the cache object for default _useCache action
*/
- function _cache_prepare(Doku_Event &$event, $param) {
+ public function _cache_prepare(Event &$event, $param)
+ {
global $conf;
/* @var cache_renderer $cache */
$cache =& $event->data;
- if(!isset($cache->page)) return;
- if(!isset($cache->mode) || $cache->mode == 'i') return;
+ if (!isset($cache->page)) return;
+ if (!isset($cache->mode) || $cache->mode == 'i') return;
$depends = p_get_metadata($cache->page, 'plugin_include');
- if($conf['allowdebug'] && $this->getConf('debugoutput')) {
+ if ($conf['allowdebug'] && $this->getConf('debugoutput')) {
dbglog('---- PLUGIN INCLUDE CACHE DEPENDS START ----');
dbglog($depends);
dbglog('---- PLUGIN INCLUDE CACHE DEPENDS END ----');
@@ -226,14 +231,15 @@ function _cache_prepare(Doku_Event &$event, $param) {
if (!is_array($depends)) return; // nothing to do for us
- if (!is_array($depends['pages']) ||
+ if (
+ !is_array($depends['pages']) ||
!is_array($depends['instructions']) ||
$depends['pages'] != $this->helper->_get_included_pages_from_meta_instructions($depends['instructions']) ||
// the include_content url parameter may change the behavior for included pages
- $depends['include_content'] != isset($_REQUEST['include_content'])) {
-
+ $depends['include_content'] != isset($_REQUEST['include_content'])
+ ) {
$cache->depends['purge'] = true; // included pages changed or old metadata - request purge.
- if($conf['allowdebug'] && $this->getConf('debugoutput')) {
+ if ($conf['allowdebug'] && $this->getConf('debugoutput')) {
dbglog('---- PLUGIN INCLUDE: REQUESTING CACHE PURGE ----');
dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META START ----');
dbglog($depends['pages']);
@@ -241,11 +247,10 @@ function _cache_prepare(Doku_Event &$event, $param) {
dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META_INSTRUCTIONS START ----');
dbglog($this->helper->_get_included_pages_from_meta_instructions($depends['instructions']));
dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META_INSTRUCTIONS END ----');
-
}
} else {
// add plugin.info.txt to depends for nicer upgrades
- $cache->depends['files'][] = dirname(__FILE__) . '/plugin.info.txt';
+ $cache->depends['files'][] = __DIR__ . '/plugin.info.txt';
foreach ($depends['pages'] as $page) {
if (!$page['exists']) continue;
$file = wikiFN($page['id']);
@@ -261,9 +266,10 @@ function _cache_prepare(Doku_Event &$event, $param) {
* and replace normal section edit buttons when the current page is different from the
* global $ID.
*/
- function handle_secedit_button(Doku_Event &$event, $params) {
+ public function handle_secedit_button(Event &$event, $params)
+ {
// stack of included pages in the form ('id' => page, 'rev' => modification time, 'writable' => bool)
- static $page_stack = array();
+ static $page_stack = [];
global $ID, $lang;
@@ -273,31 +279,29 @@ function handle_secedit_button(Doku_Event &$event, $params) {
// handle the "section edits" added by the include plugin
$fn = wikiFN($data['name']);
$perm = auth_quickaclcheck($data['name']);
- array_unshift($page_stack, array(
- 'id' => $data['name'],
- 'rev' => @filemtime($fn),
- 'writable' => (page_exists($data['name']) ? (is_writable($fn) && $perm >= AUTH_EDIT) : $perm >= AUTH_CREATE),
- 'redirect' => ($data['target'] == 'plugin_include_start'),
- ));
+ array_unshift($page_stack, ['id' => $data['name'], 'rev' => @filemtime($fn), 'writable' => (page_exists($data['name']) ? (is_writable($fn) && $perm >= AUTH_EDIT) : $perm >= AUTH_CREATE), 'redirect' => ($data['target'] == 'plugin_include_start')]);
} elseif ($data['target'] == 'plugin_include_end') {
array_shift($page_stack);
} elseif ($data['target'] == 'plugin_include_editbtn') {
if ($page_stack[0]['writable']) {
- $params = array('do' => 'edit',
- 'id' => $page_stack[0]['id']);
+ $params = ['do' => 'edit', 'id' => $page_stack[0]['id']];
if ($page_stack[0]['redirect']) {
$params['redirect_id'] = $ID;
$params['hid'] = $data['hid'];
}
$event->result = '' . DOKU_LF .
- html_btn('incledit', $page_stack[0]['id'], '',
- $params, 'post',
+ html_btn(
+ 'incledit',
+ $page_stack[0]['id'],
+ '',
+ $params,
+ 'post',
$data['name'],
- $lang['btn_secedit'].' ('.$page_stack[0]['id'].')') .
+ $lang['btn_secedit'] . ' (' . $page_stack[0]['id'] . ')'
+ ) .
'
' . DOKU_LF;
}
} elseif (!empty($page_stack)) {
-
// Special handling for the edittable plugin
if ($data['target'] == 'table' && !plugin_isdisabled('edittable')) {
/* @var action_plugin_edittable_editor $edittable */
@@ -319,11 +323,14 @@ function handle_secedit_button(Doku_Event &$event, $params) {
$event->result = "" .
- html_btn('secedit', $page_stack[0]['id'], '',
- array_merge(array('do' => 'edit',
- 'rev' => $page_stack[0]['rev'],
- 'summary' => '['.$name.'] '), $data),
- 'post', $name) . '
';
+ html_btn(
+ 'secedit',
+ $page_stack[0]['id'],
+ '',
+ array_merge(['do' => 'edit', 'rev' => $page_stack[0]['rev'], 'summary' => '[' . $name . '] '], $data),
+ 'post',
+ $name
+ ) . '';
} else {
$event->result = '';
}
@@ -335,18 +342,20 @@ function handle_secedit_button(Doku_Event &$event, $params) {
$event->stopPropagation();
}
- public function handle_move_register(Doku_Event $event, $params) {
- $event->data['handlers']['include_include'] = array($this, 'rewrite_include');
+ public function handle_move_register(Event $event, $params)
+ {
+ $event->data['handlers']['include_include'] = [$this, 'rewrite_include'];
}
- public function rewrite_include($match, $pos, $state, $plugin, helper_plugin_move_handler $handler) {
+ public function rewrite_include($match, $pos, $state, $plugin, helper_plugin_move_handler $handler)
+ {
$syntax = substr($match, 2, -2); // strip markup
$replacers = explode('|', $syntax);
$syntax = array_shift($replacers);
- list($syntax, $flags) = array_pad(explode('&', $syntax, 2), 2, "");
+ [$syntax, $flags] = array_pad(explode('&', $syntax, 2), 2, "");
// break the pattern up into its parts
- list($mode, $page, $sect) = array_pad(preg_split('/>|#/u', $syntax, 3), 3, "");
+ [$mode, $page, $sect] = array_pad(preg_split('/>|#/u', $syntax, 3), 3, "");
if (method_exists($handler, 'adaptRelativeId')) { // move plugin before version 2015-05-16
$newpage = $handler->adaptRelativeId($page);
@@ -358,10 +367,10 @@ public function rewrite_include($match, $pos, $state, $plugin, helper_plugin_mov
if ($newpage == $page) {
return $match;
} else {
- $result = '{{'.$mode.'>'.$newpage;
- if ($sect) $result .= '#'.$sect;
- if ($flags) $result .= '&'.$flags;
- if ($replacers) $result .= '|'.$replacers;
+ $result = '{{' . $mode . '>' . $newpage;
+ if ($sect) $result .= '#' . $sect;
+ if ($flags) $result .= '&' . $flags;
+ if ($replacers) $result .= '|' . $replacers;
$result .= '}}';
return $result;
}
diff --git a/conf/default.php b/conf/default.php
index c619005..734ed03 100644
--- a/conf/default.php
+++ b/conf/default.php
@@ -1,7 +1,9 @@
*/
+
$meta['noheader'] = array('onoff');
$meta['firstseconly'] = array('onoff');
$meta['showtaglogos'] = array('onoff');
diff --git a/helper.php b/helper.php
index 9dca93b..6582d91 100644
--- a/helper.php
+++ b/helper.php
@@ -1,4 +1,5 @@
@@ -6,24 +7,29 @@
* @author Gina Häußge, Michael Klier
* @author Michael Hamann
*/
+
+use dokuwiki\Extension\Plugin;
use dokuwiki\plugin\include\GenericResolver;
use dokuwiki\File\PageResolver;
/**
* Helper functions for the include plugin and other plugins that want to include pages.
*/
-class helper_plugin_include extends DokuWiki_Plugin { // DokuWiki_Helper_Plugin
+class helper_plugin_include extends Plugin
+{
+ // DokuWiki_Helper_Plugin
- var $defaults = array();
- var $sec_close = true;
+ public $defaults = [];
+ public $sec_close = true;
/** @var helper_plugin_tag $taghelper */
- var $taghelper = null;
- var $includes = array(); // deprecated - compatibility code for the blog plugin
+ public $taghelper;
+ public $includes = []; // deprecated - compatibility code for the blog plugin
/**
* Constructor loads default config settings once
*/
- function __construct() {
+ public function __construct()
+ {
$this->defaults['noheader'] = $this->getConf('noheader');
$this->defaults['firstsec'] = $this->getConf('firstseconly');
$this->defaults['editbtn'] = $this->getConf('showeditbtn');
@@ -53,26 +59,22 @@ function __construct() {
/**
* Available methods for other plugins
*/
- function getMethods() {
- $result = array();
- $result[] = array(
- 'name' => 'get_flags',
- 'desc' => 'overrides standard values for showfooter and firstseconly settings',
- 'params' => array('flags' => 'array'),
- );
- return $result;
+ public function getMethods()
+ {
+ return [['name' => 'get_flags', 'desc' => 'overrides standard values for showfooter and firstseconly settings', 'params' => ['flags' => 'array']]];
}
/**
* Overrides standard values for showfooter and firstseconly settings
*/
- function get_flags($setflags) {
+ public function get_flags($setflags)
+ {
// load defaults
$flags = $this->defaults;
foreach ($setflags as $flag) {
$value = '';
if (strpos($flag, '=') !== false) {
- list($flag, $value) = explode('=', $flag, 2);
+ [$flag, $value] = explode('=', $flag, 2);
}
switch ($flag) {
case 'footer':
@@ -236,7 +238,8 @@ function get_flags($setflags) {
* @author Michael Klier
* @author Michael Hamann
*/
- function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $included_pages = array()) {
+ public function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $included_pages = [])
+ {
$key = ($sect) ? $page . '#' . $sect : $page;
$this->includes[$key] = true; // legacy code for keeping compatibility with other plugins
@@ -251,17 +254,13 @@ function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $
$title = '';
if ($flags['title'])
$title = p_get_first_heading($page);
- if($flags['parlink']) {
- $ins = array(
- array('p_open', array()),
- array('internallink', array(':'.$key, $title)),
- array('p_close', array()),
- );
+ if ($flags['parlink']) {
+ $ins = [['p_open', []], ['internallink', [':' . $key, $title]], ['p_close', []]];
} else {
- $ins = array(array('internallink', array(':'.$key,$title)));
+ $ins = [['internallink', [':' . $key, $title]]];
}
- }else {
- $ins = array();
+ } else {
+ $ins = [];
}
} else {
if (page_exists($page)) {
@@ -271,7 +270,7 @@ function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $
$ins = p_cached_instructions(wikiFN($page), false, $page);
$ID = $backupID;
} else {
- $ins = array();
+ $ins = [];
}
$this->_convert_instructions($ins, $lvl, $page, $sect, $flags, $root_id, $included_pages);
@@ -292,21 +291,22 @@ function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $
*
* @author Michael Klier
*/
- function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $included_pages = array()) {
+ public function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $included_pages = [])
+ {
global $conf;
// filter instructions if needed
- if(!empty($sect)) {
+ if (!empty($sect)) {
$this->_get_section($ins, $sect); // section required
}
- if($flags['firstsec']) {
+ if ($flags['firstsec']) {
$this->_get_firstsec($ins, $page, $flags); // only first section
}
$num = count($ins);
- $conv_idx = array(); // conversion index
+ $conv_idx = []; // conversion index
$lvl_max = false; // max level
$first_header = -1;
$no_header = false;
@@ -315,8 +315,8 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc
$this->adapt_links($ins, $page, $included_pages);
- for($i=0; $i<$num; $i++) {
- switch($ins[$i][0]) {
+ for ($i = 0; $i < $num; $i++) {
+ switch ($ins[$i][0]) {
case 'document_start':
case 'document_end':
case 'section_edit':
@@ -324,27 +324,26 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc
break;
case 'header':
// get section title of first section
- if($sect && !$sect_title) {
+ if ($sect && !$sect_title) {
$sect_title = $ins[$i][1][0];
}
// check if we need to skip the first header
- if((!$no_header) && $flags['noheader']) {
+ if ((!$no_header) && $flags['noheader']) {
$no_header = true;
}
$conv_idx[] = $i;
// get index of first header
- if($first_header == -1) $first_header = $i;
+ if ($first_header == -1) $first_header = $i;
// get max level of this instructions set
- if(!$lvl_max || ($ins[$i][1][1] < $lvl_max)) {
+ if (!$lvl_max || ($ins[$i][1][1] < $lvl_max)) {
$lvl_max = $ins[$i][1][1];
}
break;
case 'section_open':
if ($flags['inline'])
unset($ins[$i]);
- else
- $conv_idx[] = $i;
+ else $conv_idx[] = $i;
break;
case 'section_close':
if ($flags['inline'])
@@ -355,7 +354,7 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc
break;
case 'plugin':
// FIXME skip other plugins?
- switch($ins[$i][1][0]) {
+ switch ($ins[$i][1][0]) {
case 'tag_tag': // skip tags
case 'discussion_comments': // skip comments
case 'linkback': // skip linkbacks
@@ -399,37 +398,37 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc
$footer_lvl = false;
$contains_secedit = false;
$section_close_at = false;
- foreach($conv_idx as $idx) {
- if($ins[$idx][0] == 'header') {
- if ($section_close_at === false && isset($ins[$idx+1]) && $ins[$idx+1][0] == 'section_open') {
+ foreach ($conv_idx as $idx) {
+ if ($ins[$idx][0] == 'header') {
+ if ($section_close_at === false && isset($ins[$idx + 1]) && $ins[$idx + 1][0] == 'section_open') {
// store the index of the first heading that is followed by a new section
// the wrap plugin creates sections without section_open so the section shouldn't be closed before them
$section_close_at = $idx;
}
- if($no_header && !$hdr_deleted) {
- unset ($ins[$idx]);
+ if ($no_header && !$hdr_deleted) {
+ unset($ins[$idx]);
$hdr_deleted = true;
continue;
}
- if($flags['indent']) {
+ if ($flags['indent']) {
$lvl_new = (($ins[$idx][1][1] + $diff) > 5) ? 5 : ($ins[$idx][1][1] + $diff);
$ins[$idx][1][1] = $lvl_new;
}
- if($ins[$idx][1][1] <= $conf['maxseclevel'])
+ if ($ins[$idx][1][1] <= $conf['maxseclevel'])
$contains_secedit = true;
// set permalink
- if($flags['link'] && !$has_permalink && ($idx == $first_header)) {
+ if ($flags['link'] && !$has_permalink && ($idx == $first_header)) {
$this->_permalink($ins[$idx], $page, $sect, $flags);
$has_permalink = true;
}
// set footer level
- if(!$footer_lvl && ($idx == $first_header) && !$no_header) {
- if($flags['indent'] && isset($lvl_new)) {
+ if (!$footer_lvl && ($idx == $first_header) && !$no_header) {
+ if ($flags['indent'] && isset($lvl_new)) {
$footer_lvl = $lvl_new;
} else {
$footer_lvl = $lvl_max;
@@ -437,14 +436,14 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc
}
} else {
// it's a section
- if($flags['indent']) {
+ if ($flags['indent']) {
$lvl_new = (($ins[$idx][1][0] + $diff) > 5) ? 5 : ($ins[$idx][1][0] + $diff);
$ins[$idx][1][0] = $lvl_new;
}
// check if noheader is used and set the footer level to the first section
- if($no_header && !$footer_lvl) {
- if($flags['indent'] && isset($lvl_new)) {
+ if ($no_header && !$footer_lvl) {
+ if ($flags['indent'] && isset($lvl_new)) {
$footer_lvl = $lvl_new;
} else {
$footer_lvl = $lvl_max;
@@ -455,49 +454,49 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc
// close last open section of the included page if there is any
if ($contains_secedit) {
- array_push($ins, array('plugin', array('include_closelastsecedit', array($endpos))));
+ $ins[] = ['plugin', ['include_closelastsecedit', [$endpos]]];
}
- $include_secid = (isset($flags['include_secid']) ? $flags['include_secid'] : NULL);
+ $include_secid = ($flags['include_secid'] ?? null);
// add edit button
- if($flags['editbtn']) {
+ if ($flags['editbtn']) {
$this->_editbtn($ins, $page, $sect, $sect_title, ($flags['redirect'] ? $root_id : false), $include_secid);
}
// add footer
- if($flags['footer']) {
+ if ($flags['footer']) {
$ins[] = $this->_footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id);
}
// wrap content at the beginning of the include that is not in a section in a section
if ($lvl > 0 && $section_close_at !== 0 && $flags['indent'] && !$flags['inline']) {
if ($section_close_at === false) {
- $ins[] = array('section_close', array());
- array_unshift($ins, array('section_open', array($lvl)));
+ $ins[] = ['section_close', []];
+ array_unshift($ins, ['section_open', [$lvl]]);
} else {
$section_close_idx = array_search($section_close_at, array_keys($ins));
if ($section_close_idx > 0) {
$before_ins = array_slice($ins, 0, $section_close_idx);
$after_ins = array_slice($ins, $section_close_idx);
- $ins = array_merge($before_ins, array(array('section_close', array())), $after_ins);
- array_unshift($ins, array('section_open', array($lvl)));
+ $ins = array_merge($before_ins, [['section_close', []]], $after_ins);
+ array_unshift($ins, ['section_open', [$lvl]]);
}
}
}
// add instructions entry wrapper
- array_unshift($ins, array('plugin', array('include_wrap', array('open', $page, $flags['redirect'], $include_secid))));
+ array_unshift($ins, ['plugin', ['include_wrap', ['open', $page, $flags['redirect'], $include_secid]]]);
if (isset($flags['beforeeach']))
- array_unshift($ins, array('entity', array($flags['beforeeach'])));
- array_push($ins, array('plugin', array('include_wrap', array('close'))));
+ array_unshift($ins, ['entity', [$flags['beforeeach']]]);
+ $ins[] = ['plugin', ['include_wrap', ['close']]];
if (isset($flags['aftereach']))
- array_push($ins, array('entity', array($flags['aftereach'])));
+ $ins[] = ['entity', [$flags['aftereach']]];
// close previous section if any and re-open after inclusion
- if($lvl != 0 && $this->sec_close && !$flags['inline']) {
- array_unshift($ins, array('section_close', array()));
- $ins[] = array('section_open', array($lvl));
+ if ($lvl != 0 && $this->sec_close && !$flags['inline']) {
+ array_unshift($ins, ['section_close', []]);
+ $ins[] = ['section_open', [$lvl]];
}
}
@@ -506,11 +505,9 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc
*
* @author Michael Klier
*/
- function _footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id) {
- $footer = array();
- $footer[0] = 'plugin';
- $footer[1] = array('include_footer', array($page, $sect, $sect_title, $flags, $root_id, $footer_lvl));
- return $footer;
+ public function _footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id)
+ {
+ return [0 => 'plugin', 1 => ['include_footer', [$page, $sect, $sect_title, $flags, $root_id, $footer_lvl]]];
}
/**
@@ -518,11 +515,12 @@ function _footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id) {
*
* @author Michael Klier
*/
- function _editbtn(&$ins, $page, $sect, $sect_title, $root_id, $hid = '') {
+ public function _editbtn(&$ins, $page, $sect, $sect_title, $root_id, $hid = '')
+ {
$title = ($sect) ? $sect_title : $page;
- $editbtn = array();
+ $editbtn = [];
$editbtn[0] = 'plugin';
- $editbtn[1] = array('include_editbtn', array($title, $hid));
+ $editbtn[1] = ['include_editbtn', [$title, $hid]];
$ins[] = $editbtn;
}
@@ -531,9 +529,10 @@ function _editbtn(&$ins, $page, $sect, $sect_title, $root_id, $hid = '') {
*
* @author Michael Klier
*/
- function _permalink(&$ins, $page, $sect, $flags) {
+ public function _permalink(&$ins, $page, $sect, $flags)
+ {
$ins[0] = 'plugin';
- $ins[1] = array('include_header', array($ins[1][0], $ins[1][1], $ins[1][2], $page, $sect, $flags));
+ $ins[1] = ['include_header', [$ins[1][0], $ins[1][1], $ins[1][2], $page, $sect, $flags]];
}
/**
@@ -543,19 +542,20 @@ function _permalink(&$ins, $page, $sect, $flags) {
* @param string $page The included page
* @param array $included_pages The array of pages that are included
*/
- private function adapt_links(&$ins, $page, $included_pages = null) {
+ private function adapt_links(&$ins, $page, $included_pages = null)
+ {
$num = count($ins);
- for($i=0; $i<$num; $i++) {
+ for ($i = 0; $i < $num; $i++) {
// adjust links with image titles
if (strpos($ins[$i][0], 'link') !== false && isset($ins[$i][1][1]) && is_array($ins[$i][1][1]) && $ins[$i][1][1]['type'] == 'internalmedia') {
// resolve relative ids, but without cleaning in order to preserve the name
$media_id = (new GenericResolver($page))->resolveId($ins[$i][1][1]['src']);
// make sure that after resolving the link again it will be the same link
- if ($media_id[0] != ':') $media_id = ':'.$media_id;
+ if ($media_id[0] != ':') $media_id = ':' . $media_id;
$ins[$i][1][1]['src'] = $media_id;
}
- switch($ins[$i][0]) {
+ switch ($ins[$i][0]) {
case 'internallink':
case 'internalmedia':
// make sure parameters aren't touched
@@ -569,9 +569,9 @@ private function adapt_links(&$ins, $page, $included_pages = null) {
// resolve the id without cleaning it
$link_id = (new GenericResolver($page))->resolveId($link_id);
// this id is internal (i.e. absolute) now, add ':' to make resolve_id work again
- if ($link_id[0] != ':') $link_id = ':'.$link_id;
+ if ($link_id[0] != ':') $link_id = ':' . $link_id;
// restore parameters
- $ins[$i][1][0] = ($link_params != '') ? $link_id.'?'.$link_params : $link_id;
+ $ins[$i][1][0] = ($link_params != '') ? $link_id . '?' . $link_params : $link_id;
if ($ins[$i][0] == 'internallink' && !empty($included_pages)) {
// change links to included pages into local links
@@ -584,7 +584,7 @@ private function adapt_links(&$ins, $page, $included_pages = null) {
$link_parts = explode('#', $link_id, 2);
$hash = '';
if (count($link_parts) === 2) {
- list($link_id, $hash) = $link_parts;
+ [$link_id, $hash] = $link_parts;
}
if (array_key_exists($link_id, $included_pages)) {
if ($hash) {
@@ -595,7 +595,7 @@ private function adapt_links(&$ins, $page, $included_pages = null) {
// the include section ids are different from normal section ids (so they won't conflict) but this
// also means that the normal locallink function can't be used
$ins[$i][0] = 'plugin';
- $ins[$i][1] = array('include_locallink', array($included_pages[$link_id]['hid'], $ins[$i][1][1], $ins[$i][1][0]));
+ $ins[$i][1] = ['include_locallink', [$included_pages[$link_id]['hid'], $ins[$i][1][1], $ins[$i][1][0]]];
}
}
}
@@ -605,7 +605,7 @@ private function adapt_links(&$ins, $page, $included_pages = null) {
/* Convert local links to internal links if the page hasn't been fully included */
if ($included_pages == null || !array_key_exists($page, $included_pages)) {
$ins[$i][0] = 'internallink';
- $ins[$i][1][0] = ':'.$page.'#'.$ins[$i][1][0];
+ $ins[$i][1][0] = ':' . $page . '#' . $ins[$i][1][0];
}
break;
}
@@ -617,18 +617,18 @@ private function adapt_links(&$ins, $page, $included_pages = null) {
*
* @author Michael Klier
*/
- function _get_section(&$ins, $sect) {
+ public function _get_section(&$ins, $sect)
+ {
$num = count($ins);
$offset = false;
$lvl = false;
$end = false;
$endpos = null; // end position in the input text, needed for section edit buttons
- $check = array(); // used for sectionID() in order to get the same ids as the xhtml renderer
+ $check = []; // used for sectionID() in order to get the same ids as the xhtml renderer
- for($i=0; $i<$num; $i++) {
+ for ($i = 0; $i < $num; $i++) {
if ($ins[$i][0] == 'header') {
-
// found the right header
if (sectionID($ins[$i][1][0], $check) == $sect) {
$offset = $i;
@@ -640,12 +640,12 @@ function _get_section(&$ins, $sect) {
}
}
}
- $offset = $offset ? $offset : 0;
- $end = $end ? $end : ($num - 1);
- if(is_array($ins)) {
+ $offset = $offset ?: 0;
+ $end = $end ?: $num - 1;
+ if (is_array($ins)) {
$ins = array_slice($ins, $offset, $end);
// store the end position in the include_closelastsecedit instruction so it can generate a matching button
- $ins[] = array('plugin', array('include_closelastsecedit', array($endpos)));
+ $ins[] = ['plugin', ['include_closelastsecedit', [$endpos]]];
}
}
@@ -654,12 +654,13 @@ function _get_section(&$ins, $sect) {
*
* @author Michael Klier
*/
- function _get_firstsec(&$ins, $page, $flags) {
+ public function _get_firstsec(&$ins, $page, $flags)
+ {
$num = count($ins);
$first_sect = false;
$endpos = null; // end position in the input text
- for($i=0; $i<$num; $i++) {
- if($ins[$i][0] == 'section_close') {
+ for ($i = 0; $i < $num; $i++) {
+ if ($ins[$i][0] == 'section_close') {
$first_sect = $i;
}
if ($ins[$i][0] == 'header') {
@@ -673,14 +674,14 @@ function _get_firstsec(&$ins, $page, $flags) {
}
// only truncate the content and add the read more link when there is really
// more than that first section
- if(($first_sect) && ($ins[$i][0] == 'section_open')) {
+ if (($first_sect) && ($ins[$i][0] == 'section_open')) {
$ins = array_slice($ins, 0, $first_sect);
if ($flags['readmore']) {
- $ins[] = array('plugin', array('include_readmore', array($page)));
+ $ins[] = ['plugin', ['include_readmore', [$page]]];
}
- $ins[] = array('section_close', array());
+ $ins[] = ['section_close', []];
// store the end position in the include_closelastsecedit instruction so it can generate a matching button
- $ins[] = array('plugin', array('include_closelastsecedit', array($endpos)));
+ $ins[] = ['plugin', ['include_closelastsecedit', [$endpos]]];
return;
}
}
@@ -691,61 +692,62 @@ function _get_firstsec(&$ins, $page, $flags) {
*
* @author Michael Hamann
*/
- function _get_included_pages($mode, $page, $sect, $parent_id, $flags) {
+ public function _get_included_pages($mode, $page, $sect, $parent_id, $flags)
+ {
global $conf;
- $pages = array();
- switch($mode) {
- case 'namespace':
- $page = cleanID($page);
- $ns = utf8_encodeFN(str_replace(':', '/', $page));
- // depth is absolute depth, not relative depth, but 0 has a special meaning.
- $depth = $flags['depth'] ? $flags['depth'] + substr_count($page, ':') + ($page ? 1 : 0) : 0;
- search($pagearrays, $conf['datadir'], 'search_allpages', array('depth' => $depth, 'skipacl' => false), $ns);
- if (is_array($pagearrays)) {
- foreach ($pagearrays as $pagearray) {
- if (!isHiddenPage($pagearray['id'])) // skip hidden pages
+ $pages = [];
+ switch ($mode) {
+ case 'namespace':
+ $page = cleanID($page);
+ $ns = utf8_encodeFN(str_replace(':', '/', $page));
+ // depth is absolute depth, not relative depth, but 0 has a special meaning.
+ $depth = $flags['depth'] ? $flags['depth'] + substr_count($page, ':') + ($page ? 1 : 0) : 0;
+ search($pagearrays, $conf['datadir'], 'search_allpages', ['depth' => $depth, 'skipacl' => false], $ns);
+ if (is_array($pagearrays)) {
+ foreach ($pagearrays as $pagearray) {
+ if (!isHiddenPage($pagearray['id'])) // skip hidden pages
$pages[] = $pagearray['id'];
+ }
}
- }
- break;
- case 'tagtopic':
- if (!$this->taghelper)
+ break;
+ case 'tagtopic':
+ if (!$this->taghelper)
$this->taghelper = plugin_load('helper', 'tag');
- if(!$this->taghelper) {
- msg('You have to install the tag plugin to use this functionality!', -1);
- return array();
- }
- $tag = $page;
- $sect = '';
- $pagearrays = $this->taghelper->getTopic('', null, $tag);
- foreach ($pagearrays as $pagearray) {
- $pages[] = $pagearray['id'];
- }
- break;
- default:
- $page = $this->_apply_macro($page, $parent_id);
- // resolve shortcuts and clean ID
- $page = (new PageResolver($parent_id))->resolveId($page);
- if (auth_quickaclcheck($page) >= AUTH_READ)
+ if (!$this->taghelper) {
+ msg('You have to install the tag plugin to use this functionality!', -1);
+ return [];
+ }
+ $tag = $page;
+ $sect = '';
+ $pagearrays = $this->taghelper->getTopic('', null, $tag);
+ foreach ($pagearrays as $pagearray) {
+ $pages[] = $pagearray['id'];
+ }
+ break;
+ default:
+ $page = $this->_apply_macro($page, $parent_id);
+ // resolve shortcuts and clean ID
+ $page = (new PageResolver($parent_id))->resolveId($page);
+ if (auth_quickaclcheck($page) >= AUTH_READ)
$pages[] = $page;
}
if (isset($flags['exclude']))
$pages = array_filter($pages, function ($page) use ($flags) {
if (@preg_match($flags['exclude'], $page))
- return FALSE;
- return TRUE;
+ return false;
+ return true;
});
if (count($pages) > 1) {
if ($flags['order'] === 'id') {
if ($flags['rsort']) {
- usort($pages, array($this, '_r_strnatcasecmp'));
+ usort($pages, [$this, '_r_strnatcasecmp']);
} else {
natcasesort($pages);
}
} else {
- $ordered_pages = array();
+ $ordered_pages = [];
foreach ($pages as $page) {
$key = '';
switch ($flags['order']) {
@@ -769,11 +771,11 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) {
$key = '';
break;
}
- $key .= '_'.$page;
+ $key .= '_' . $page;
$ordered_pages[$key] = $page;
}
if ($flags['rsort']) {
- uksort($ordered_pages, array($this, '_r_strnatcasecmp'));
+ uksort($ordered_pages, [$this, '_r_strnatcasecmp']);
} else {
uksort($ordered_pages, 'strnatcasecmp');
}
@@ -781,10 +783,10 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) {
}
}
- $result = array();
+ $result = [];
foreach ($pages as $page) {
$exists = page_exists($page);
- $result[] = array('id' => $page, 'exists' => $exists, 'parent_id' => $parent_id);
+ $result[] = ['id' => $page, 'exists' => $exists, 'parent_id' => $parent_id];
}
return $result;
}
@@ -800,7 +802,8 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) {
* 0 if str1 is lesser than
* str2, and 0 if they are equal.
*/
- function _r_strnatcasecmp($a, $b) {
+ public function _r_strnatcasecmp($a, $b)
+ {
return strnatcasecmp($b, $a);
}
@@ -808,8 +811,9 @@ function _r_strnatcasecmp($a, $b) {
* This function generates the list of all included pages from a list of metadata
* instructions.
*/
- function _get_included_pages_from_meta_instructions($instructions) {
- $pages = array();
+ public function _get_included_pages_from_meta_instructions($instructions)
+ {
+ $pages = [];
foreach ($instructions as $instruction) {
$mode = $instruction['mode'];
$page = $instruction['page'];
@@ -825,39 +829,45 @@ function _get_included_pages_from_meta_instructions($instructions) {
* Get wiki language from "HTTP_ACCEPT_LANGUAGE"
* We allow the pattern e.g. "ja,en-US;q=0.7,en;q=0.3"
*/
- function _get_language_of_wiki($id, $parent_id) {
- global $conf;
- $result = $conf['lang'];
- if(strpos($id, '@BROWSER_LANG@') !== false){
- $brlangp = "/([a-zA-Z]{1,8}(-[a-zA-Z]{1,8})*|\*)(;q=(0(.[0-9]{0,3})?|1(.0{0,3})?))?/";
- if(preg_match_all(
- $brlangp, $_SERVER["HTTP_ACCEPT_LANGUAGE"],
- $matches, PREG_SET_ORDER
- )){
- $langs = array();
- foreach($matches as $match){
- $langname = $match[1] == '*' ? $conf['lang'] : $match[1];
- $qvalue = $match[4] == '' ? 1.0 : $match[4];
- $langs[$langname] = $qvalue;
- }
- arsort($langs);
- foreach($langs as $lang => $langq){
- $testpage = $this->_apply_macro(str_replace('@BROWSER_LANG@', $lang, $id), $parent_id);
- $testpage = (new PageResolver($parent_id))->resolveId($testpage);
- if (page_exists($testpage)) {
- $result = $lang;
- break;
- }
- }
- }
- }
- return cleanID($result);
+ public function _get_language_of_wiki($id, $parent_id)
+ {
+ global $conf;
+ $result = $conf['lang'];
+ if (strpos($id, '@BROWSER_LANG@') !== false) {
+ $brlangp = "/([a-zA-Z]{1,8}(-[a-zA-Z]{1,8})*|\\*)(;q=(0(.\\d{0,3})?|1(.0{0,3})?))?/";
+ if (
+ preg_match_all(
+ $brlangp,
+ $_SERVER["HTTP_ACCEPT_LANGUAGE"],
+ $matches,
+ PREG_SET_ORDER
+ )
+ ) {
+ $langs = [];
+ foreach ($matches as $match) {
+ $langname = $match[1] == '*' ? $conf['lang'] : $match[1];
+ $qvalue = $match[4] == '' ? 1.0 : $match[4];
+ $langs[$langname] = $qvalue;
+ }
+ arsort($langs);
+ foreach (array_keys($langs) as $lang) {
+ $testpage = $this->_apply_macro(str_replace('@BROWSER_LANG@', $lang, $id), $parent_id);
+ $testpage = (new PageResolver($parent_id))->resolveId($testpage);
+ if (page_exists($testpage)) {
+ $result = $lang;
+ break;
+ }
+ }
+ }
+ }
+ return cleanID($result);
}
/**
* Makes user or date dependent includes possible
*/
- function _apply_macro($id, $parent_id) {
+ public function _apply_macro($id, $parent_id)
+ {
global $USERINFO;
/* @var Input $INPUT */
global $INPUT;
@@ -865,7 +875,7 @@ function _apply_macro($id, $parent_id) {
// The following is basicaly copied from basicinfo() because
// this function can be called from within pageinfo() in
// p_get_metadata and thus we cannot rely on $INFO being set
- if($INPUT->server->has('REMOTE_USER')) {
+ if ($INPUT->server->has('REMOTE_USER')) {
$user = $INPUT->server->str('REMOTE_USER');
} else {
// no registered user - use IP
@@ -887,54 +897,37 @@ function _apply_macro($id, $parent_id) {
}
$time_stamp = time();
- if(preg_match('/@DATE(\w+)@/',$id,$matches)) {
- switch($matches[1]) {
- case 'PMONTH':
- $time_stamp = strtotime("-1 month");
- break;
- case 'NMONTH':
- $time_stamp = strtotime("+1 month");
- break;
- case 'NWEEK':
- $time_stamp = strtotime("+1 week");
- break;
- case 'PWEEK':
- $time_stamp = strtotime("-1 week");
- break;
- case 'TOMORROW':
- $time_stamp = strtotime("+1 day");
- break;
- case 'YESTERDAY':
- $time_stamp = strtotime("-1 day");
- break;
- case 'NYEAR':
- $time_stamp = strtotime("+1 year");
- break;
- case 'PYEAR':
- $time_stamp = strtotime("-1 year");
- break;
+ if (preg_match('/@DATE(\w+)@/', $id, $matches)) {
+ switch ($matches[1]) {
+ case 'PMONTH':
+ $time_stamp = strtotime("-1 month");
+ break;
+ case 'NMONTH':
+ $time_stamp = strtotime("+1 month");
+ break;
+ case 'NWEEK':
+ $time_stamp = strtotime("+1 week");
+ break;
+ case 'PWEEK':
+ $time_stamp = strtotime("-1 week");
+ break;
+ case 'TOMORROW':
+ $time_stamp = strtotime("+1 day");
+ break;
+ case 'YESTERDAY':
+ $time_stamp = strtotime("-1 day");
+ break;
+ case 'NYEAR':
+ $time_stamp = strtotime("+1 year");
+ break;
+ case 'PYEAR':
+ $time_stamp = strtotime("-1 year");
+ break;
}
- $id = preg_replace('/@DATE(\w+)@/','', $id);
+ $id = preg_replace('/@DATE(\w+)@/', '', $id);
}
- $replace = array(
- '@USER@' => cleanID($user),
- '@NAME@' => cleanID($name),
- '@GROUP@' => cleanID($group),
- '@BROWSER_LANG@' => $this->_get_language_of_wiki($id, $parent_id),
- '@YEAR@' => date('Y',$time_stamp),
- '@MONTH@' => date('m',$time_stamp),
- '@WEEK@' => date('W',$time_stamp),
- '@DAY@' => date('d',$time_stamp),
- '@YEARPMONTH@' => date('Ym',strtotime("-1 month")),
- '@PMONTH@' => date('m',strtotime("-1 month")),
- '@NMONTH@' => date('m',strtotime("+1 month")),
- '@YEARNMONTH@' => date('Ym',strtotime("+1 month")),
- '@YEARPWEEK@' => date('YW',strtotime("-1 week")),
- '@PWEEK@' => date('W',strtotime("-1 week")),
- '@NWEEK@' => date('W',strtotime("+1 week")),
- '@YEARNWEEK@' => date('YW',strtotime("+1 week")),
- );
+ $replace = ['@USER@' => cleanID($user), '@NAME@' => cleanID($name), '@GROUP@' => cleanID($group), '@BROWSER_LANG@' => $this->_get_language_of_wiki($id, $parent_id), '@YEAR@' => date('Y', $time_stamp), '@MONTH@' => date('m', $time_stamp), '@WEEK@' => date('W', $time_stamp), '@DAY@' => date('d', $time_stamp), '@YEARPMONTH@' => date('Ym', strtotime("-1 month")), '@PMONTH@' => date('m', strtotime("-1 month")), '@NMONTH@' => date('m', strtotime("+1 month")), '@YEARNMONTH@' => date('Ym', strtotime("+1 month")), '@YEARPWEEK@' => date('YW', strtotime("-1 week")), '@PWEEK@' => date('W', strtotime("-1 week")), '@NWEEK@' => date('W', strtotime("+1 week")), '@YEARNWEEK@' => date('YW', strtotime("+1 week"))];
return str_replace(array_keys($replace), array_values($replace), $id);
}
}
diff --git a/syntax/closelastsecedit.php b/syntax/closelastsecedit.php
index a5741c8..69055b1 100644
--- a/syntax/closelastsecedit.php
+++ b/syntax/closelastsecedit.php
@@ -1,4 +1,7 @@
*/
-class syntax_plugin_include_closelastsecedit extends DokuWiki_Syntax_Plugin {
-
- function getType() {
+class syntax_plugin_include_closelastsecedit extends SyntaxPlugin
+{
+ public function getType()
+ {
return 'formatting';
}
- function getSort() {
+ public function getSort()
+ {
return 50;
}
- function handle($match, $state, $pos, Doku_Handler $handler) {
+ public function handle($match, $state, $pos, Doku_Handler $handler)
+ {
// this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
}
/**
* Finishes the last open section edit
*/
- function render($mode, Doku_Renderer $renderer, $data) {
+ public function render($mode, Doku_Renderer $renderer, $data)
+ {
if ($mode == 'xhtml') {
/** @var Doku_Renderer_xhtml $renderer */
- list($endpos) = $data;
+ [$endpos] = $data;
$renderer->finishSectionEdit($endpos);
return true;
}
diff --git a/syntax/editbtn.php b/syntax/editbtn.php
index 4d9367f..4b2a226 100644
--- a/syntax/editbtn.php
+++ b/syntax/editbtn.php
@@ -1,4 +1,7 @@
*/
-class syntax_plugin_include_editbtn extends DokuWiki_Syntax_Plugin {
-
- function getType() {
+class syntax_plugin_include_editbtn extends SyntaxPlugin
+{
+ public function getType()
+ {
return 'formatting';
}
-
- function getSort() {
+
+ public function getSort()
+ {
return 50;
}
- function handle($match, $state, $pos, Doku_Handler $handler) {
+ public function handle($match, $state, $pos, Doku_Handler $handler)
+ {
// this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
}
@@ -25,11 +31,12 @@ function handle($match, $state, $pos, Doku_Handler $handler) {
*
* @author Michael Klier
*/
- function render($mode, Doku_Renderer $renderer, $data) {
- list($title, $hid) = $data;
+ public function render($mode, Doku_Renderer $renderer, $data)
+ {
+ [$title, $hid] = $data;
if ($mode == 'xhtml') {
if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions
- $renderer->startSectionEdit(0, array('target' => 'plugin_include_editbtn', 'name' => $title, 'hid' => $hid));
+ $renderer->startSectionEdit(0, ['target' => 'plugin_include_editbtn', 'name' => $title, 'hid' => $hid]);
} else {
$renderer->startSectionEdit(0, 'plugin_include_editbtn', $title);
}
diff --git a/syntax/footer.php b/syntax/footer.php
index 523d005..b9a6440 100644
--- a/syntax/footer.php
+++ b/syntax/footer.php
@@ -1,4 +1,7 @@
*/
-class syntax_plugin_include_footer extends DokuWiki_Syntax_Plugin {
-
- function getType() {
+class syntax_plugin_include_footer extends SyntaxPlugin
+{
+ public function getType()
+ {
return 'formatting';
}
- function getSort() {
+ public function getSort()
+ {
return 300;
}
- function handle($match, $state, $pos, Doku_Handler $handler) {
+ public function handle($match, $state, $pos, Doku_Handler $handler)
+ {
// this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
}
@@ -26,13 +32,14 @@ function handle($match, $state, $pos, Doku_Handler $handler) {
* Code heavily copied from the header renderer from inc/parser/xhtml.php, just
* added an href parameter to the anchor tag linking to the wikilink.
*/
- function render($mode, Doku_Renderer $renderer, $data) {
+ public function render($mode, Doku_Renderer $renderer, $data)
+ {
- list($page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl) = $data;
+ [$page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl] = $data;
if ($mode == 'xhtml') {
$renderer->doc .= $this->html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $renderer);
- return true;
+ return true;
}
return false;
}
@@ -42,14 +49,15 @@ function render($mode, Doku_Renderer $renderer, $data) {
* @param $renderer Doku_Renderer_xhtml The (xhtml) renderer
* @return string The HTML code of the footer
*/
- function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) {
+ public function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer)
+ {
global $conf, $ID;
- if(!$flags['footer']) return '';
+ if (!$flags['footer']) return '';
$meta = p_get_metadata($page);
$exists = page_exists($page);
- $xhtml = array();
+ $xhtml = [];
// permalink
if ($flags['permalink']) {
$class = ($exists ? 'wikilink1' : 'wikilink2');
@@ -57,14 +65,7 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer)
$name = ($sect) ? $sect_title : $page;
$title = ($sect) ? $page . '#' . $sect : $page;
if (!$title) $title = str_replace('_', ' ', noNS($page));
- $link = array(
- 'url' => $url,
- 'title' => $title,
- 'name' => $name,
- 'target' => $conf['target']['wiki'],
- 'class' => $class . ' permalink',
- 'more' => 'rel="bookmark"',
- );
+ $link = ['url' => $url, 'title' => $title, 'name' => $name, 'target' => $conf['target']['wiki'], 'class' => $class . ' permalink', 'more' => 'rel="bookmark"'];
$xhtml[] = $renderer->_formatLink($link);
}
@@ -72,7 +73,7 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer)
if ($flags['date'] && $exists) {
$date = $meta['date']['created'];
if ($date) {
- $xhtml[] = ''
+ $xhtml[] = ''
. dformat($date)
. '';
}
@@ -82,7 +83,7 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer)
if ($flags['mdate'] && $exists) {
$mdate = $meta['date']['modified'];
if ($mdate) {
- $xhtml[] = ''
+ $xhtml[] = ''
. dformat($mdate)
. '';
}
@@ -117,7 +118,7 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer)
// tags - let Tag Plugin do the work for us
if (empty($sect) && $flags['tags'] && (!plugin_isdisabled('tag')) && ($tag = plugin_load('helper', 'tag'))) {
$tags = $tag->td($page);
- if($tags) {
+ if ($tags) {
$xhtml .= '' . DOKU_LF
. DOKU_TAB . $tags . DOKU_LF
. DOKU_TAB . '
' . DOKU_LF;
diff --git a/syntax/header.php b/syntax/header.php
index 3f14dcb..4e773f8 100644
--- a/syntax/header.php
+++ b/syntax/header.php
@@ -1,4 +1,7 @@
*/
-class syntax_plugin_include_header extends DokuWiki_Syntax_Plugin {
-
- function getType() {
+class syntax_plugin_include_header extends SyntaxPlugin
+{
+ public function getType()
+ {
return 'formatting';
}
-
- function getSort() {
+
+ public function getSort()
+ {
return 50;
}
- function handle($match, $state, $pos, Doku_Handler $handler) {
+ public function handle($match, $state, $pos, Doku_Handler $handler)
+ {
// this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
}
/**
* Renders a permalink header.
- *
+ *
* Code heavily copied from the header renderer from inc/parser/xhtml.php, just
* added an href parameter to the anchor tag linking to the wikilink.
*/
- function render($mode, Doku_Renderer $renderer, $data) {
+ public function render($mode, Doku_Renderer $renderer, $data)
+ {
global $conf;
- list($headline, $lvl, $pos, $page, $sect, $flags) = $data;
+ [$headline, $lvl, $pos, $page, $sect, $flags] = $data;
if ($mode == 'xhtml') {
/** @var Doku_Renderer_xhtml $renderer */
$hid = $renderer->_headerToLink($headline, true);
$renderer->toc_additem($hid, $headline, $lvl);
$url = ($sect) ? wl($page) . '#' . $sect : wl($page);
- $renderer->doc .= DOKU_LF.'doc .= DOKU_LF . '_get_firsttag($page);
- if($tag) {
+ if ($tag) {
$classes[] = 'include_firsttag__' . $tag;
}
}
@@ -51,16 +58,16 @@ function render($mode, Doku_Renderer $renderer, $data) {
// wrap so there is no need to close a previous section edit.
if ($lvl <= $conf['maxseclevel']) {
if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions
- $classes[] = $renderer->startSectionEdit($pos, array('target' => 'section', 'name' => $headline, 'hid' => $hid));
+ $classes[] = $renderer->startSectionEdit($pos, ['target' => 'section', 'name' => $headline, 'hid' => $hid]);
} else {
$classes[] = $renderer->startSectionEdit($pos, 'section', $headline);
}
}
if ($classes) {
- $renderer->doc .= ' class="'. implode(' ', $classes) . '"';
+ $renderer->doc .= ' class="' . implode(' ', $classes) . '"';
}
$headline = $renderer->_xmlEntities($headline);
- $renderer->doc .= ' id="'.$hid.'">';
+ $renderer->doc .= ' id="' . $hid . '">';
$renderer->doc .= $headline;
$renderer->doc .= '' . DOKU_LF;
return true;
@@ -75,17 +82,18 @@ function render($mode, Doku_Renderer $renderer, $data) {
*
* @author Michael Klier
*/
- function _get_firsttag($page) {
- if(plugin_isdisabled('tag') || (!plugin_load('helper', 'tag'))) {
+ public function _get_firsttag($page)
+ {
+ if (plugin_isdisabled('tag') || (!plugin_load('helper', 'tag'))) {
return false;
}
$subject = p_get_metadata($page, 'subject');
if (is_array($subject)) {
$tag = $subject[0];
} else {
- list($tag, $rest) = explode(' ', $subject, 2);
+ [$tag, $rest] = explode(' ', $subject, 2);
}
- if($tag) {
+ if ($tag) {
return $tag;
} else {
return false;
diff --git a/syntax/include.php b/syntax/include.php
index 44b803a..a017ab8 100644
--- a/syntax/include.php
+++ b/syntax/include.php
@@ -1,4 +1,7 @@
Lexer->addSpecialPattern("{{page>.+?}}", $mode, 'plugin_include_include');
$this->Lexer->addSpecialPattern("{{section>.+?}}", $mode, 'plugin_include_include');
$this->Lexer->addSpecialPattern("{{namespace>.+?}}", $mode, 'plugin_include_include');
@@ -65,17 +78,18 @@ function connectTo($mode) {
* @param Doku_Handler $handler The hanlder object
* @return array The instructions of the plugin
*/
- function handle($match, $state, $pos, Doku_Handler $handler) {
+ public function handle($match, $state, $pos, Doku_Handler $handler)
+ {
$match = substr($match, 2, -2); // strip markup
- list($match, $flags) = array_pad(explode('&', $match, 2), 2, '');
+ [$match, $flags] = array_pad(explode('&', $match, 2), 2, '');
// break the pattern up into its parts
- list($mode, $page, $sect) = array_pad(preg_split('/>|#/u', $match, 3), 3, null);
+ [$mode, $page, $sect] = array_pad(preg_split('/>|#/u', $match, 3), 3, null);
$check = false;
if (isset($sect)) $sect = sectionID($sect, $check);
- $level = NULL;
- return array($mode, $page, $sect, explode('&', $flags), $level, $pos);
+ $level = null;
+ return [$mode, $page, $sect, explode('&', $flags), $level, $pos];
}
/**
@@ -83,19 +97,20 @@ function handle($match, $state, $pos, Doku_Handler $handler) {
*
* @author Michael Hamann
*/
- function render($format, Doku_Renderer $renderer, $data) {
+ public function render($format, Doku_Renderer $renderer, $data)
+ {
global $ID;
// static stack that records all ancestors of the child pages
- static $page_stack = array();
+ static $page_stack = [];
// when there is no id just assume the global $ID is the current id
if (empty($page_stack)) $page_stack[] = $ID;
- $parent_id = $page_stack[count($page_stack)-1];
+ $parent_id = $page_stack[count($page_stack) - 1];
$root_id = $page_stack[0];
- list($mode, $page, $sect, $flags, $level, $pos) = $data;
+ [$mode, $page, $sect, $flags, $level, $pos] = $data;
if (!$this->helper)
$this->helper = plugin_load('helper', 'include');
@@ -112,14 +127,14 @@ function render($format, Doku_Renderer $renderer, $data) {
unset($renderer->meta['plugin_include']);
}
- $renderer->meta['plugin_include']['instructions'][] = compact('mode', 'page', 'sect', 'parent_id', 'flags');
+ $renderer->meta['plugin_include']['instructions'][] = ['mode' => $mode, 'page' => $page, 'sect' => $sect, 'parent_id' => $parent_id, 'flags' => $flags];
if (!isset($renderer->meta['plugin_include']['pages']))
- $renderer->meta['plugin_include']['pages'] = array(); // add an array for array_merge
+ $renderer->meta['plugin_include']['pages'] = []; // add an array for array_merge
$renderer->meta['plugin_include']['pages'] = array_merge($renderer->meta['plugin_include']['pages'], $pages);
$renderer->meta['plugin_include']['include_content'] = isset($_REQUEST['include_content']);
}
- $secids = array();
+ $secids = [];
if ($format == 'xhtml' || $format == 'odt') {
$secids = p_get_metadata($ID, 'plugin_include secids');
}
@@ -130,14 +145,14 @@ function render($format, Doku_Renderer $renderer, $data) {
$exists = $page['exists'];
if (in_array($id, $page_stack)) continue;
- array_push($page_stack, $id);
+ $page_stack[] = $id;
// add references for backlink
if ($format == 'metadata') {
$renderer->meta['relation']['references'][$id] = $exists;
$renderer->meta['relation']['haspart'][$id] = $exists;
if (!$sect && !$flags['firstsec'] && !$flags['linkonly'] && !isset($renderer->meta['plugin_include']['secids'][$id])) {
- $renderer->meta['plugin_include']['secids'][$id] = array('hid' => 'plugin_include__'.str_replace(':', '__', $id), 'pos' => $pos);
+ $renderer->meta['plugin_include']['secids'][$id] = ['hid' => 'plugin_include__' . str_replace(':', '__', $id), 'pos' => $pos];
}
}
diff --git a/syntax/locallink.php b/syntax/locallink.php
index 2a6a612..539b8cb 100644
--- a/syntax/locallink.php
+++ b/syntax/locallink.php
@@ -1,4 +1,7 @@
*/
-class syntax_plugin_include_locallink extends DokuWiki_Syntax_Plugin {
-
- function getType() {
+class syntax_plugin_include_locallink extends SyntaxPlugin
+{
+ public function getType()
+ {
return 'formatting';
}
- function getSort() {
+ public function getSort()
+ {
return 50;
}
- function handle($match, $state, $pos, Doku_Handler $handler) {
+ public function handle($match, $state, $pos, Doku_Handler $handler)
+ {
// this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
}
@@ -25,16 +31,17 @@ function handle($match, $state, $pos, Doku_Handler $handler) {
*
* @author Michael Hamann
*/
- function render($mode, Doku_Renderer $renderer, $data) {
+ public function render($mode, Doku_Renderer $renderer, $data)
+ {
global $ID;
if ($mode == 'xhtml') {
/** @var Doku_Renderer_xhtml $renderer */
- list($hash, $name, $id) = $data;
+ [$hash, $name, $id] = $data;
// construct title in the same way it would be done for internal links
$default = $renderer->_simpleTitle($id);
$name = $renderer->_getLinkTitle($name, $default, $isImage, $id);
- $title = $ID.' ↵';
- $renderer->doc .= '';
+ $title = $ID . ' ↵';
+ $renderer->doc .= '';
$renderer->doc .= $name;
$renderer->doc .= '';
return true;
diff --git a/syntax/readmore.php b/syntax/readmore.php
index 689e11d..827dd19 100644
--- a/syntax/readmore.php
+++ b/syntax/readmore.php
@@ -1,4 +1,7 @@
*/
-class syntax_plugin_include_readmore extends DokuWiki_Syntax_Plugin {
-
- function getType() {
+class syntax_plugin_include_readmore extends SyntaxPlugin
+{
+ public function getType()
+ {
return 'formatting';
}
- function getSort() {
+ public function getSort()
+ {
return 50;
}
- function handle($match, $state, $pos, Doku_Handler $handler) {
+ public function handle($match, $state, $pos, Doku_Handler $handler)
+ {
// this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
}
- function render($mode, Doku_Renderer $renderer, $data) {
- list($page) = $data;
+ public function render($mode, Doku_Renderer $renderer, $data)
+ {
+ [$page] = $data;
if ($mode == 'xhtml') {
- $renderer->doc .= DOKU_LF.''.DOKU_LF;
+ $renderer->doc .= DOKU_LF . '
' . DOKU_LF;
} else {
$renderer->p_open();
}
@@ -32,7 +39,7 @@ function render($mode, Doku_Renderer $renderer, $data) {
$renderer->internallink($page, $this->getLang('readmore'));
if ($mode == 'xhtml') {
- $renderer->doc .= DOKU_LF.'
'.DOKU_LF;
+ $renderer->doc .= DOKU_LF . '
' . DOKU_LF;
} else {
$renderer->p_close();
}
diff --git a/syntax/sorttag.php b/syntax/sorttag.php
index c7704ba..eea1e0d 100644
--- a/syntax/sorttag.php
+++ b/syntax/sorttag.php
@@ -1,5 +1,7 @@
*
*/
-class syntax_plugin_include_sorttag extends DokuWiki_Syntax_Plugin {
-
+class syntax_plugin_include_sorttag extends SyntaxPlugin
+{
/**
* What kind of syntax are we?
*/
- public function getType(){
+ public function getType()
+ {
return 'substition';
}
@@ -22,36 +25,41 @@ public function getType(){
*
* @return string The paragraph type
*/
- public function getPType() {
+ public function getPType()
+ {
return 'block';
}
/**
* Where to sort in?
*/
- public function getSort(){
+ public function getSort()
+ {
return 139;
}
/**
* Connect pattern to lexer
*/
- public function connectTo($mode) {
- $this->Lexer->addSpecialPattern('{{include_n>.+?}}',$mode,'plugin_include_sorttag');
+ public function connectTo($mode)
+ {
+ $this->Lexer->addSpecialPattern('{{include_n>.+?}}', $mode, 'plugin_include_sorttag');
}
/**
* Handle the match
*/
- public function handle($match, $state, $pos, Doku_Handler $handler){
- $match = substr($match,12,-2);
- return array($match);
+ public function handle($match, $state, $pos, Doku_Handler $handler)
+ {
+ $match = substr($match, 12, -2);
+ return [$match];
}
/**
* Render output
*/
- public function render($mode, Doku_Renderer $renderer, $data) {
+ public function render($mode, Doku_Renderer $renderer, $data)
+ {
if ($mode === 'metadata') {
/** @var Doku_Renderer_metadata $renderer */
$renderer->meta['include_n'] = $data[0];
diff --git a/syntax/wrap.php b/syntax/wrap.php
index 1cb630c..4864e55 100644
--- a/syntax/wrap.php
+++ b/syntax/wrap.php
@@ -1,4 +1,7 @@
*/
-class syntax_plugin_include_wrap extends DokuWiki_Syntax_Plugin {
-
- function getType() {
+class syntax_plugin_include_wrap extends SyntaxPlugin
+{
+ public function getType()
+ {
return 'formatting';
}
- function getSort() {
+ public function getSort()
+ {
return 50;
}
- function handle($match, $state, $pos, Doku_Handler $handler) {
+ public function handle($match, $state, $pos, Doku_Handler $handler)
+ {
// this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
}
@@ -28,41 +34,41 @@ function handle($match, $state, $pos, Doku_Handler $handler) {
* @author Michael Klier
* @author Michael Hamann
*/
- function render($mode, Doku_Renderer $renderer, $data) {
+ public function render($mode, Doku_Renderer $renderer, $data)
+ {
if ($mode == 'xhtml') {
$state = array_shift($data);
- switch($state) {
+ switch ($state) {
case 'open':
- list($page, $redirect, $secid) = $data;
+ [$page, $redirect, $secid] = $data;
if ($redirect) {
if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions
- $renderer->startSectionEdit(0, array('target' => 'plugin_include_start', 'name' => $page, 'hid' => ''));
+ $renderer->startSectionEdit(0, ['target' => 'plugin_include_start', 'name' => $page, 'hid' => '']);
} else {
$renderer->startSectionEdit(0, 'plugin_include_start', $page);
}
+ } elseif (defined('SEC_EDIT_PATTERN')) {
+ // for DokuWiki Greebo and more recent versions
+ $renderer->startSectionEdit(0, ['target' => 'plugin_include_start_noredirect', 'name' => $page, 'hid' => '']);
} else {
- if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions
- $renderer->startSectionEdit(0, array('target' => 'plugin_include_start_noredirect', 'name' => $page, 'hid' => ''));
- } else {
- $renderer->startSectionEdit(0, 'plugin_include_start_noredirect', $page);
- }
+ $renderer->startSectionEdit(0, 'plugin_include_start_noredirect', $page);
}
$renderer->finishSectionEdit();
// Start a new section with type != section so headers in the included page
// won't print section edit buttons of the parent page
if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions
- $renderer->startSectionEdit(0, array('target' => 'plugin_include_end', 'name' => $page, 'hid' => ''));
+ $renderer->startSectionEdit(0, ['target' => 'plugin_include_end', 'name' => $page, 'hid' => '']);
} else {
$renderer->startSectionEdit(0, 'plugin_include_end', $page);
}
- if ($secid === NULL) {
+ if ($secid === null) {
$id = '';
} else {
- $id = ' id="'.$secid.'"';
+ $id = ' id="' . $secid . '"';
}
- $renderer->doc .= '' . DOKU_LF;
- if (is_a($renderer,'renderer_plugin_dw2pdf')) {
- $renderer->doc .= '
';
+ $renderer->doc .= '
' . DOKU_LF;
+ if (is_a($renderer, 'renderer_plugin_dw2pdf')) {
+ $renderer->doc .= '
';
}
break;
case 'close':