str('do') == $value) {
$match += 2;
$match_count++;
}
} else if (strncmp($part, 'do!=', 4) == 0) {
$value = substr($part, 4);
if ($INPUT->str('do') != $value) {
$match += 2;
$match_count++;
}
} else if (strncmp($part, 'ID==', 4) == 0) {
$value = substr($part, 4);
if ($ID == $value) {
$match += 2;
$match_count++;
}
} else if (strncmp($part, 'ID!=', 4) == 0) {
$value = substr($part, 4);
if ($ID != $value) {
$match += 2;
$match_count++;
}
} else if (strncmp($part, 'page==', 6) == 0) {
$value = substr($part, 6);
if ($INPUT->str('page') == $value) {
$match += 2;
$match_count++;
}
} else if (strncmp($part, 'page!=', 6) == 0) {
$value = substr($part, 6);
if ($INPUT->str('page') != $value) {
$match += 2;
$match_count++;
}
} else if (strncmp($part, 'ACT==', 5) == 0) {
$value = substr($part, 5);
if ($ACT == $value) {
$match += 2;
$match_count++;
}
} else if (strncmp($part, 'ACT!=', 5) == 0) {
$value = substr($part, 5);
if ($ACT != $value) {
$match += 2;
$match_count++;
}
}
}
}
if ($match_count == count($parts)) {
// All parts matched
return $match;
}
// No match or only partial match
return 0;
}
/**
* Select the layout to use as specified in the template's configuration.
*
* The function JSON decodes the config parameter 'Layouts', selects
* the best match and returns the array (Layouts[x]).
*
* @return array|NULL
*/
function tpl_get_layout() {
global $default_layout;
global $conf;
$config = tpl_getConf('Layouts', NULL);
if (empty($config)) {
$config = $default_layout;
}
$layouts = json_decode($config, true);
if ($layouts === NULL) {
$layouts = json_decode($default_layout, true);
}
$layouts = $layouts['layouts'];
// Go through all selectors and return the best match
$best = 0;
$best_layout = NULL;
for ($index = 0 ; $index < count($layouts) ; $index++) {
foreach ($layouts[$index]['select'] as $select) {
$match = tpl_selector_matches($select);
if ($match > $best) {
$best = $match;
$best_layout = &$layouts[$index];
}
}
}
if ($best > 0) {
return $best_layout;
}
// Nothing found!
return NULL;
}
/**
* Check if $name refers to a build-in background and return the
* corresponding CSS class name. If $name is unknown, NULL will be returned.
*
* @param string $name Config-name of the background
* @return string|NULL
*/
function tpl_get_background_class($name) {
/* Add backgrounds here.
For the class name '-' will be replaced with '_'! */
$backgrounds = array('weave', 'upholstery', 'bricks', 'diagonal-stripes',
'tablecloth', 'waves', 'lined-paper',
'blueprint-grid', 'cicada-stripes', 'honey-comb',
'cross-dots', 'cross', 'tartan', 'japanese-cube');
if (in_array($name, $backgrounds)) {
return str_replace('-', '_', $name);
}
return NULL;
}
/**
* Print the opening of the
element as specified by @$layout.
*/
function tpl_print_body(array $layout) {
$body_class = tpl_get_background_class($layout['background']);
if (!empty($body_class)) {
print('');
} else {
print('');
}
}
/**
* Print/generate the 'title' section.
*/
function tpl_generate_title() {
global $conf;
// Get logo either out of the template images folder or data/media folder
$logo = tpl_getMediaFile(array(':wiki:logo.png', ':logo.png', 'images/logo.png'), false, $logoSize);
$title = $conf['title'];
//$tagline = ($conf['tagline']) ? ''.$conf['tagline'].'' : '';
// Display logo and wiki title in a link to the home page
$home = wl();
tpl_link($home,
''.$title.'',
'accesskey="h" title="[H]"');
tpl_flush();
}
/**
* Print/generate the 'tagline' section.
*/
function tpl_generate_tagline() {
global $conf;
if ($conf['tagline']) {
print(''.$conf['tagline'].'');
}
tpl_flush();
}
/**
* Print/generate the 'trace' section.
*/
function tpl_generate_trace() {
global $conf;
if ($conf['breadcrumbs']) {
$sep = tpl_getConf('BreadcrumbsSep', NULL);
tpl_breadcrumbs($sep);
}
tpl_flush();
}
/**
* Print/generate the 'youarehere' section.
*/
function tpl_generate_youarehere() {
global $conf;
if ($conf['youarehere']) {
$sep = tpl_getConf('YouAreHereSep', NULL);
tpl_youarehere($sep);
}
tpl_flush();
}
/**
* Print/generate the 'search' section.
*/
function tpl_generate_search() {
tpl_searchform();
tpl_flush();
}
/**
* Print/generate the 'sitetools' section.
*/
function tpl_generate_sitetools() {
print(''.$lang['site_tools'].'
');
// ToDo: for mobile display as drop down
//$mobile = (new \dokuwiki\Menu\MobileMenu())->getDropdown($lang['tools']);
//print(''.$mobile.'
');
$site = (new \dokuwiki\Menu\SiteMenu())->getListItems('action ', false);
print ('');
tpl_flush();
}
/**
* Print/generate the 'usertools' section.
*/
function tpl_generate_usertools() {
global $conf;
if ($conf['useacl']) {
print(''.$lang['user_tools'].'
');
print('');
if (!empty($_SERVER['REMOTE_USER'])) {
print('- ');
/* 'Logged in as ...' */
tpl_userinfo();
print('
');
}
print((new \dokuwiki\Menu\UserMenu())->getListItems('action '));
print('
');
}
tpl_flush();
}
/**
* Print/generate the 'pageid' section.
*
* @param $inside true=render page ID inside of content section,
* false=render page ID in extra div/section,
*/
function tpl_generate_pageid($inside=true) {
global $ID;
if ($inside == true) {
print(''.hsc($ID).'
');
} else {
print(''.hsc($ID).'
');
}
tpl_flush();
}
/**
* Print/generate the 'docinfo' section.
*
* @param boolean $inside true=render doc-info inside of content section,
* false=render doc-info in extra div/section,
*/
function tpl_generate_docinfo($inside=true) {
if ($inside == true) {
print('');
} else {
print('
');
}
tpl_pageinfo();
print('
');
tpl_flush();
}
/**
* Print/generate the 'toc' section.
*
* If this is called then there is an extra div containing the toc.
* Most likely 'tpl_generate_content()' was called with $toc == false.
*/
function tpl_generate_toc() {
tpl_toc();
tpl_flush();
}
/**
* Print/generate the 'content' section.
*
* If this is called then there is an extra div containing the toc.
* Most likely 'tpl_generate_content()' was called with $toc == false.
*
* @param boolean $page_id Render the page ID section
* @param boolean $doc_info Render the doc-info section
* @param boolean $toc Render the toc section
*/
function tpl_generate_content($page_id=true, $doc_info=true, $toc=true) {
// Output any messages created by 'msg(...)' calls
html_msgarea();
if ($page_id == true) {
tpl_generate_pageid();
}
print('
');
tpl_flush();
tpl_includeFile('pageheader.html');
// Render the real content/the wiki page
print('
');
tpl_content($toc);
print('
');
tpl_includeFile('pagefooter.html');
print('
');
if ($doc_info == true) {
tpl_generate_docinfo();
}
tpl_flush();
}
/**
* Print/generate a 'page' section.
*
* A page section includes a specific wiki page or HTML page and could e.g.
* be used to genertae the sidebar.
*
* @param array $layout Layout to be used
* @param string $page Page name
* @param array $params Cell params to apply
*/
function tpl_generate_page(array $layout, $page, $params) {
if (!empty($params['headline-string-name'])) {
print('
'.$lang[$params['headline-string-name']].'
');
}
print ('
');
tpl_flush();
if (strpos($page, '.html') !== false) {
tpl_includeFile($page);
} else {
tpl_include_page($page, true, true);
}
print('
');
tpl_flush();
}
/**
* Print/generate the 'pagetools' section.
*/
function tpl_generate_pagetools() {
print('
'.$lang['page_tools'].'
');
print('
');
tpl_flush();
}
/**
* Print/generate the 'footer' section.
*/
function tpl_generate_footer() {
global $conf;
/* Generate license text */
tpl_license('');
print('
');
tpl_includeFile('footer.html');
}
/**
* Create the grid.
*
* This function validates the 'grid' array contained in @$layout and
* performs adjustment if necessary:
* - guarantee an equal amount of columns in each row
* - rename 'space' to 'empty'
*/
function tpl_create_grid(&$layout) {
// The JSON decoding gives us the grid already as an array.
// We just do some checks and adjust the array if necessary
// Get number of max. columns
$max_columns = 0;
foreach ($layout['grid'] as $row) {
$columns = count($row);
if ($columns > 0) {
if ($columns > $max_columns) {
$max_columns = $columns;
}
}
}
// Rename 'space' to 'empty'
$row = 0;
for ($row = 0 ; $row < count($layout['grid']) ; $row++) {
$columns = count($layout['grid'][$row]);
for ($column = 0 ; $column < $columns ; $column++) {
if ($layout['grid'][$row][$column] == 'space') {
$layout['grid'][$row][$column] = 'empty';
}
}
}
// Validate grid: if there are any rows which do not have a number
// of columns equal to $max_columns then fill the row up with 'empty'
$index = 0;
for ($index = 0 ; $index < count($layout['grid']) ; $index++) {
$columns = count($layout['grid'][$index]);
if ($columns < $max_columns) {
for (;$columns < $max_columns ; $columns++) {
$layout['grid'][$index][] = 'empty';
}
}
}
}
/**
* Returns the CSS params in @params as an CSS formated string.
*
* @return string
*/
function tpl_get_css_props(array $params) {
// Generate CSS props from cell parameters
$css_props = '';
if (is_array($params['css'])) {
foreach ($params['css'] as $key => $value) {
if ($value !== NULL) {
$css_props .= ' '.$key.': '.$value.";\n";
}
}
}
return $css_props;
}
/**
* Print the grid area and CSS params for @$item.
*
* $item can be the name of a well-known build-in section like 'title'
* or 'content'. Or it can be the name of a user-defined container
* which then includes well-known items or pages.
*
* @param array $layout Layout to use
* @param string $item Item type or name to render
*/
function tpl_print_grid_area($layout, $item) {
$params = tpl_get_cell_params($layout, $item);
// Generate CSS props from cell parameters
$css_props = tpl_get_css_props($params);
switch ($item) {
case 'sitetools':
print("#dokuwiki__site div.dokuwiki__sitetools {\n grid-area: sitetools;\n");
break;
case 'usertools':
print("#dokuwiki__site div.dokuwiki__usertools {\n grid-area: usertools;\n");
break;
case 'pagetools':
print("#dokuwiki__site div.dokuwiki__pagetools {\n grid-area: pagetools;\n");
break;
case 'title':
print("#dokuwiki__site div.dokuwiki__title {\n grid-area: title;\n");
break;
case 'tagline':
print("#dokuwiki__site div.dokuwiki__tagline {\n grid-area: tagline;\n");
break;
case 'trace':
print("#dokuwiki__site div.trace { grid-area:\n trace;\n");
break;
case 'youarehere':
print("#dokuwiki__site div.youarehere {\n grid-area: youarehere;\n");
break;
case 'toc':
print("#dokuwiki__site div.dokuwiki__toc {\n grid-area: toc;\n");
break;
case 'content':
print("#dokuwiki__site div.dokuwiki__content {\n grid-area: content;\n");
break;
case 'empty':
print("#dokuwiki__site div.grid-empty {\n grid-area: empty;\n");
break;
case 'search':
print("#dokuwiki__site div.search {\n grid-area: search;\n");
break;
case 'footer':
print("#dokuwiki__site #dokuwiki__footer {\n grid-area: footer;\n");
break;
case 'scroll-up-area':
print("#dokuwiki__site div.scroll_up_area {\n grid-area: scroll-up-area;\n");
break;
case 'scroll-down-area':
print("#dokuwiki__site div.scroll_down_area {\n grid-area: scroll-down-area;\n");
break;
default:
if ($params['id'] != 'default') {
print("#dokuwiki__site div.".$item." {\n grid-area: ".$item.";\n");
} else {
print('');
}
break;
}
if (!empty($css_props)) {
print($css_props);
}
print("}\n");
// Also add css props for included items or pages
$todo = array();
if (is_array($params['items'])) {
$todo = array_merge($todo, $params['items']);
} else if (is_array($params['pages'])) {
$todo = array_merge($todo, $params['pages']);
}
foreach ($todo as $name) {
$params = tpl_get_cell_params($layout, $name);
$css_props = tpl_get_css_props($params);
if (!empty($css_props)) {
print("#dokuwiki__site div.".$name." {\n".$css_props."}\n");
}
}
}
/**
* Print the main grid definition.
*
* @param array $layout Layout to use
*/
function tpl_print_grid(array $layout) {
$max_rows = count($layout['grid']);
$total_vert_space = $layout['grid-vert-space'];
if ($max_rows > 1) {
$vert_space = round($total_vert_space / ($max_rows - 1));
$row_size = round((100 - $total_vert_space) / $max_rows);
} else {
$vert_space = 0;
$row_size = 100;
}
$max_columns = count($layout['grid'][0]);
$total_horiz_space = 10;
if ($max_columns > 1) {
$horiz_space = round($total_horiz_space / ($max_columns - 1));
$column_size = round((100 - $total_horiz_space) / $max_columns);
} else {
$horiz_space = 0;
$column_size = 100;
}
print("\n");
tpl_flush();
}
/**
* Print a div/cell's content of the grid.
*
* This prints the surrounding div and then calls the appropriate
* function to generate the content.
*
* @param array $layout Layout to use
* @param string $type Type or name to render
* @param string $params Cell params to use
* @param $level FIXME: unused for now? Remove it?
*/
function tpl_generate_div(array &$layout, $type, array $params, $level=1) {
$divclass = '';
if ($params['flex']['direction'] == 'column') {
$divclass .= 'flex-column ';
if ($params['flex']['mode'] == 'same-size') {
$divclass .= ' same_height ';
}
} else if ($params['flex']['direction'] == 'row') {
$divclass .= ' flex-row ';
if ($params['flex']['mode'] == 'same-size') {
$divclass .= ' same_width ';
}
}
// Assign class for item
$scroll = '';
$invalid = false;
$item_type = TEMPLATE_KNOWN_TYPE;
switch ($type)
{
case 'title':
$divclass .= 'dokuwiki__title';
break;
case 'tagline':
$divclass .= 'dokuwiki__tagline';
break;
case 'toc':
$divclass .= 'dokuwiki__toc';
break;
case 'content':
$divclass .= 'dokuwiki__content';
break;
case 'space':
$divclass .= 'grid-empty';
break;
case 'trace':
$divclass .= 'trace';
break;
case 'youarehere':
$divclass .= 'youarehere';
break;
case 'sitetools':
$divclass .= 'dokuwiki__sitetools toolslist';
break;
case 'usertools':
$divclass .= 'dokuwiki__usertools toolslist';
break;
case 'pagetools':
$divclass .= 'dokuwiki__pagetools toolslist';
break;
case 'scroll-up-area':
$divclass .= 'scroll_up_area';
$scroll = ' onmouseover="scroll_up();" onmouseout="stop_scroll();"';
break;
case 'scroll-down-area':
$divclass .= 'scroll_down_area';
$scroll = ' onmouseover="scroll_down();" onmouseout="stop_scroll();"';
break;
default:
if ($params['id'] == 'default' && empty($params['items']) &&
empty($params['pages'])) {
/* The type is not known and points to the default cell or
it points do a different cell but it does not define
items or pages to include. */
$item_type = TEMPLATE_INVALID_TYPE;
$divclass .= 'grid-invalid';
} else {
if (!empty($params['items'])) {
$childs = count($params['items']);
$item_type = TEMPLATE_CONTAINER_ITEMS;
$divclass .= 'container_items '.$params['id'];
} else {
$childs = count($params['pages']);
$item_type = TEMPLATE_CONTAINER_PAGES;
$divclass .= 'container_pages '.$params['id'];
}
$divclass .= ' childs'.$childs;
}
break;
}
// Assign class for border
switch ($params['border']) {
case 'user':
$divclass .= ' border_TSS';
break;
case 'semi-transparent';
$divclass .= ' border_semi_transparent';
break;
}
// Assign class for corners
switch ($params['corners']) {
case 'round':
$divclass .= ' corners_round';
break;
}
// Remove text or icons (e.g. for pagetools)
switch ($params['list-type']) {
case 'no-text':
$divclass .= ' no_text';
break;
case 'no-icons':
$divclass .= ' no_icons';
break;
}
// Add known background class if set
if (!empty($params['background'])) {
$background = tpl_get_background_class($params['background']);
$divclass .= ' '.$background;
}
if ($type == 'content') {
print('
'."\n");
} else if ($type == 'footer') {
print('