*/
function handle_parser(Doku_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;
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;
break;
*/
}
break;
case 'section_open':
$level = $ins[$i][1][0];
break;
}
}
}
/**
* Add a hidden input to the form to preserve the redirect_id
*/
function handle_form(Doku_Event &$event, $param) {
if (array_key_exists('redirect_id', $_REQUEST)) {
$event->data->addHidden('redirect_id', cleanID($_REQUEST['redirect_id']));
}
}
/**
* 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);
}
$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) {
global $conf;
/* @var cache_renderer $cache */
$cache =& $event->data;
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')) {
dbglog('---- PLUGIN INCLUDE CACHE DEPENDS START ----');
dbglog($depends);
dbglog('---- PLUGIN INCLUDE CACHE DEPENDS END ----');
}
if (!is_array($depends)) return; // nothing to do for us
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'])) {
$cache->depends['purge'] = true; // included pages changed or old metadata - request purge.
if($conf['allowdebug'] && $this->getConf('debugoutput')) {
dbglog('---- PLUGIN INCLUDE: REQUESTING CACHE PURGE ----');
dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META START ----');
dbglog($depends['pages']);
dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META END ----');
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';
foreach ($depends['pages'] as $page) {
if (!$page['exists']) continue;
$file = wikiFN($page['id']);
if (!in_array($file, $cache->depends['files'])) {
$cache->depends['files'][] = $file;
}
}
}
}
/**
* Handle special section edit buttons for the include plugin to get the current page
* and replace normal section edit buttons when the current page is different from the
* global $ID.
*/
function handle_secedit_button(Doku_Event &$event, $params) {
// stack of included pages in the form ('id' => page, 'rev' => modification time, 'writable' => bool)
static $page_stack = array();
global $ID, $lang;
$data = $event->data;
if ($data['target'] == 'plugin_include_start' || $data['target'] == 'plugin_include_start_noredirect') {
// 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'),
));
} 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']);
if ($page_stack[0]['redirect'])
$params['redirect_id'] = $ID;
$event->result = '' . DOKU_LF .
html_btn('incledit', $page_stack[0]['id'], '',
$params, 'post',
$data['name'],
$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 */
$edittable =& plugin_load('action', 'edittable_editor');
if (is_null($edittable))
$edittable =& plugin_load('action', 'edittable');
$data['name'] = $edittable->getLang('secedit_name');
}
if ($page_stack[0]['writable'] && isset($data['name']) && $data['name'] !== '') {
$name = $data['name'];
unset($data['name']);
$secid = $data['secid'];
unset($data['secid']);
if ($page_stack[0]['redirect'])
$data['redirect_id'] = $ID;
$event->result = "" .
html_btn('secedit', $page_stack[0]['id'], '',
array_merge(array('do' => 'edit',
'rev' => $page_stack[0]['rev'],
'summary' => '['.$name.'] '), $data),
'post', $name) . '
';
} else {
$event->result = '';
}
} else {
return; // return so the event won't be stopped
}
$event->preventDefault();
$event->stopPropagation();
}
public function handle_move_register(Doku_Event $event, $params) {
$event->data['handlers']['include_include'] = array($this, 'rewrite_include');
}
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) = explode('&', $syntax, 2);
// break the pattern up into its parts
list($mode, $page, $sect) = preg_split('/>|#/u', $syntax, 3);
if (method_exists($handler, 'adaptRelativeId')) { // move plugin before version 2015-05-16
$newpage = $handler->adaptRelativeId($page);
} else {
$newpage = $handler->resolveMoves($page, 'page');
$newpage = $handler->relativeLink($page, $newpage, 'page');
}
if ($newpage == $page) {
return $match;
} else {
$result = '{{'.$mode.'>'.$newpage;
if ($sect) $result .= '#'.$sect;
if ($flags) $result .= '&'.$flags;
if ($replacers) $result .= '|'.$replacers;
$result .= '}}';
return $result;
}
}
}
// vim:ts=4:sw=4:et: