*/
// must be run within Dokuwiki
use dokuwiki\Form\Form;
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_bookcreator_bookmanager extends DokuWiki_Syntax_Plugin {
/** @var helper_plugin_bookcreator */
protected $hlp;
/**
* Constructor
*/
public function __construct() {
$this->hlp = plugin_load('helper', 'bookcreator');
}
/**
* @param string $mode
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern('~~\w*?BOOK.*?~~', $mode, 'plugin_bookcreator_bookmanager');
}
/**
* Syntax Type
*
* @return string
*/
function getType() {
return 'container';
}
/**
* Paragraph Type
*
* @return string
*/
function getPType() {
return 'block';
}
/**
* Where to sort in?
*/
function getSort() {
return 190;
}
/**
* Handler to prepare matched data for the rendering process
*
* @param string $match The text matched by the patterns
* @param int $state The lexer state for the match
* @param int $pos The character position of the matched text
* @param Doku_Handler $handler The Doku_Handler object
* @return 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) {
$match = substr($match, 2, -2); // strip markup
if(substr($match, 0, 7) == 'ARCHIVE') {
$type = 'archive';
} else {
$type = 'bookmanager';
}
$num = 10;
$order = 'date';
if($type == 'archive') {
[/* $junk */, $params] = array_pad(explode(':', $match, 2), 2, '');
[$param1, $param2] = array_pad(explode('&', $params, 2),2, '');
$sortoptions = ['date', 'title'];
if(is_numeric($param1)) {
$num = (int) $param1;
if(in_array($param2, $sortoptions)) {
$order = $param2;
}
} elseif(in_array($param1, $sortoptions)) {
$order = $param1;
if(is_numeric($param2)) {
$num = (int)$param2;
}
} elseif(is_numeric($param2)) {
$num = (int) $param2;
}
}
return array($type, $num, $order);
}
/**
* @param string $format render mode e.g. text, xhtml, meta,...
* @param Doku_Renderer $renderer
* @param array $data return of handle()
* @return bool
*/
function render($format, Doku_Renderer $renderer, $data) {
global $ID;
global $INPUT;
list($type, $num, $order) = $data;
if($type == "bookmanager") {
if($format == 'xhtml') {
/** @var Doku_Renderer_xhtml $renderer */
$renderer->info['cache'] = false;
// verification that if the user can save / delete the selections
$usercansave = (auth_quickaclcheck($this->getConf('save_namespace').':*') >= AUTH_CREATE);
//intervents the normal export_* handling
$do = $INPUT->str('do');
$ignore_onscreen_exports = [
'export_html',
'export_htmlns'
];
if(in_array($do, $ignore_onscreen_exports)) {
//export as xhtml or text, is handled in action component 'export'
return false;
}
//show the bookmanager
$this->showBookManager($renderer, $usercansave);
// Displays the list of saved selections
$this->renderSelectionslist($renderer, true, $ID, $order);
$renderer->doc .= "
";
}
} else {
// type == archive
if($format == 'xhtml') {
/** @var Doku_Renderer_xhtml $renderer */
// generates the list of saved selections
$this->renderSelectionslist($renderer, false, $this->getConf('book_page'), $order, $num);
}
}
return false;
}
/**
* Generates the list of save selections
*
* @param Doku_Renderer_xhtml $renderer
* @param bool $bookmanager whether this list is displayed in the Book Manager
* @param string $bmpage pageid of the page with the Book Manager
* @param string $order sort by 'title' or 'date'
* @param int $num number of listed items, 0=all items
*
* if in the Book Manager, the delete buttons are displayed
* the list with save selections is only displayed once, and the bookmanager with priority
*/
public function renderSelectionslist($renderer, $bookmanager, $bmpage, $order, $num = 0) {
$result = $this->getlist($order, $num);
if(sizeof($result) > 0) {
$form = new Form(['action'=> wl($bmpage)]);
$form->addClass('bookcreator__selections__list');
if($bookmanager) {
$form->addFieldsetOpen($this->getLang('listselections'));
$form->addHTML('