1<?php
2/**
3 * DokuWiki Template New Day Functions
4 *
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author  Michael Klier <chi@chimeric.de>
7 */
8
9/**
10 * Renders the topbar
11 *
12 * @author Michael Klier <chi@chimeric.de>
13 * @author Louis Wolf <louiswolf@chirripo.nl>
14 */
15function tpl_topbar() {
16    global $ID;
17
18    $found = false;
19    $tbar  = '';
20    $path  = explode(':', $ID);
21
22    while(!$found && count($path) >= 0) {
23        $tbar = implode(':', $path) . ':' . 'topbar';
24        $found = @file_exists(wikiFN($tbar));
25        array_pop($path);
26        // check if nothing was found
27        if(!$found && $tbar == ':topbar') return;
28    }
29
30    if($found && auth_quickaclcheck($tbar) >= AUTH_READ) {
31        $toolbar = p_wiki_xhtml($tbar,'',false);
32
33	$lines = explode("\n", $toolbar);
34	$nr = count($lines);
35	$open_ul = 0;
36	$primary_ul = 0;
37	$positions = array();
38	for($i=0; $i<$nr; $i++)
39	{
40		if (trim($lines[$i]) == '<ul>')
41		{
42			$open_ul = $open_ul+1;
43			if ($open_ul == 1)
44			{
45				$primary_ul++;
46				$lines[$i] = '<ul class="primary">' . "\n";
47				array_push($positions, $i);
48			}
49		}
50		else if (strpos($lines[$i], '</ul>') !== false)
51		{
52			$open_ul = $open_ul-1;
53		}
54	}
55
56	$first_position = $positions[0];
57	$last_position = $positions[count($positions) - 1];
58 	$lines[$first_position] = '<ul class="primary start">' . "\n";
59	$lines[$last_position] = '<ul class="primary end">' . "\n";
60	$width = $primary_ul * 150;
61
62	print '<div id="tpl_simple_navi" style="width:' . $width . 'px;">';
63	print implode($lines);
64	print '</div>';
65    }
66}
67
68// Verify if the given action is enabled
69function is_action_enabled($type) {
70	$ctype = $type;
71	if($type == 'history') $ctype='revisions';
72	return actionOK($ctype);
73}
74
75// Changes the display style of the given action group, depending on the config file
76function action_group_status($groupname) {
77	if (tpl_getConf('btl_default_' . $groupname . '_actions_status') == "closed") {
78		echo " style='display:none;'" ;
79	}
80}
81
82// Check if a translation is available for the template, otherwise fall back to template setting
83function tpl_translation($conf) {
84	if (file_exists(dirname(__FILE__).'/lang/'.$conf.'/settings.php'))
85	{
86		return $conf;
87	}
88	return tpl_getConf('btl_language');
89
90}
91
92// Parse action URL
93function tpl_action_url($url) {
94	$page_url = urlencode(selfURL());
95	$page_title = urlencode(tpl_pagetitle(null, true));
96
97	$url = str_replace("%PAGEURL%", $page_url, $url);
98	$url = str_replace("%PAGETITLE%", $page_title, $url);
99
100	return $url;
101}
102
103/* Creates the URL of the current page, used for Digg, delicious and google bookmarks */
104function selfURL() {
105	$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
106	$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
107	$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
108	return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
109}
110
111function strleft($s1, $s2) {
112	return substr($s1, 0, strpos($s1, $s2));
113}
114