/** * Hook js script into page headers. * * @author Samuele Tognini <*****@*****.**> */ function _hookjs(&$event, $param) { global $ID; global $INFO; $jsmenu = DOKU_BASE . "lib/plugins/indexmenu/jsmenu/"; if ($INFO['userinfo']['grps']) { $jsmenu .= $this->_notadmin() ? "usrmenu.js" : "admmenu.js"; } else { $jsmenu .= "menu.js"; } $event->data["script"][] = array("type" => "text/javascript", "charset" => "utf-8", "_data" => "", "src" => $jsmenu); $event->data["script"][] = array("type" => "text/javascript", "charset" => "utf-8", "_data" => "", "src" => DOKU_BASE . "lib/plugins/indexmenu/indexmenu.js"); $event->data["script"][] = array("type" => "text/javascript", "charset" => "utf-8", "_data" => "var indexmenu_ID='" . idfilter($ID) . "'"); }
/** * Displays a button (using its own form) * If tooltip exists, the access key tooltip is replaced. * * @author Andreas Gohr <*****@*****.**> */ function html_btn($name, $id, $akey, $params, $method = 'get', $tooltip = '', $label = false) { global $conf; global $lang; if (!$label) { $label = $lang['btn_' . $name]; } $ret = ''; $tip = ''; //filter id (without urlencoding) $id = idfilter($id, false); //make nice URLs even for buttons if ($conf['userewrite'] == 2) { $script = DOKU_BASE . DOKU_SCRIPT . '/' . $id; } elseif ($conf['userewrite']) { $script = DOKU_BASE . $id; } else { $script = DOKU_BASE . DOKU_SCRIPT; $params['id'] = $id; } $ret .= '<form class="button btn_' . $name . '" method="' . $method . '" action="' . $script . '"><div class="no">'; if (is_array($params)) { reset($params); while (list($key, $val) = each($params)) { $ret .= '<input type="hidden" name="' . $key . '" '; $ret .= 'value="' . htmlspecialchars($val) . '" />'; } } if ($tooltip != '') { $tip = htmlspecialchars($tooltip); } else { $tip = htmlspecialchars($label); } $ret .= '<input type="submit" value="' . hsc($label) . '" class="button" '; if ($akey) { $tip .= ' [' . strtoupper($akey) . ']'; $ret .= 'accesskey="' . $akey . '" '; } $ret .= 'title="' . $tip . '" '; $ret .= '/>'; $ret .= '</div></form>'; return $ret; }
/** * Build a link to a media file * * Will return a link to the detail page if $direct is false * * The $more parameter should always be given as array, the function then * will strip default parameters to produce even cleaner URLs * * @param string $id the media file id or URL * @param mixed $more string or array with additional parameters * @param bool $direct link to detail page if false * @param string $sep URL parameter separator * @param bool $abs Create an absolute URL * @return string */ function ml($id = '', $more = '', $direct = true, $sep = '&', $abs = false) { global $conf; if (is_array($more)) { // strip defaults for shorter URLs if (isset($more['cache']) && $more['cache'] == 'cache') { unset($more['cache']); } if (!$more['w']) { unset($more['w']); } if (!$more['h']) { unset($more['h']); } if (isset($more['id']) && $direct) { unset($more['id']); } $more = buildURLparams($more, $sep); } else { $more = str_replace('cache=cache', '', $more); //skip default $more = str_replace(',,', ',', $more); $more = str_replace(',', $sep, $more); } if ($abs) { $xlink = DOKU_URL; } else { $xlink = DOKU_BASE; } // external URLs are always direct without rewriting if (preg_match('#^(https?|ftp)://#i', $id)) { $xlink .= 'lib/exe/fetch.php'; // add hash: $xlink .= '?hash=' . substr(md5(auth_cookiesalt() . $id), 0, 6); if ($more) { $xlink .= $sep . $more; $xlink .= $sep . 'media=' . rawurlencode($id); } else { $xlink .= $sep . 'media=' . rawurlencode($id); } return $xlink; } $id = idfilter($id); // decide on scriptname if ($direct) { if ($conf['userewrite'] == 1) { $script = '_media'; } else { $script = 'lib/exe/fetch.php'; } } else { if ($conf['userewrite'] == 1) { $script = '_detail'; } else { $script = 'lib/exe/detail.php'; } } // build URL based on rewrite mode if ($conf['userewrite']) { $xlink .= $script . '/' . $id; if ($more) { $xlink .= '?' . $more; } } else { if ($more) { $xlink .= $script . '?' . $more; $xlink .= $sep . 'media=' . $id; } else { $xlink .= $script . '?media=' . $id; } } return $xlink; }
/** * Build a link to a media file * * Will return a link to the detail page if $direct is false */ function ml($id = '', $more = '', $direct = true, $sep = '&') { global $conf; if (is_array($more)) { $more = buildURLparams($more, $sep); } else { $more = str_replace(',', $sep, $more); } $xlink = DOKU_BASE; // external URLs are always direct without rewriting if (preg_match('#^(https?|ftp)://#i', $id)) { $xlink .= 'lib/exe/fetch.php'; if ($more) { $xlink .= '?' . $more; $xlink .= $sep . 'media=' . rawurlencode($id); } else { $xlink .= '?media=' . rawurlencode($id); } return $xlink; } $id = idfilter($id); // decide on scriptname if ($direct) { if ($conf['userewrite'] == 1) { $script = '_media'; } else { $script = 'lib/exe/fetch.php'; } } else { if ($conf['userewrite'] == 1) { $script = '_detail'; } else { $script = 'lib/exe/detail.php'; } } // build URL based on rewrite mode if ($conf['userewrite']) { $xlink .= $script . '/' . $id; if ($more) { $xlink .= '?' . $more; } } else { if ($more) { $xlink .= $script . '?' . $more; $xlink .= $sep . 'media=' . $id; } else { $xlink .= $script . '?media=' . $id; } } return $xlink; }
/** * Build a link to a media file * * Will return a link to the detail page if $direct is false * * The $more parameter should always be given as array, the function then * will strip default parameters to produce even cleaner URLs * * @param string $id the media file id or URL * @param mixed $more string or array with additional parameters * @param bool $direct link to detail page if false * @param string $sep URL parameter separator * @param bool $abs Create an absolute URL * @return string */ function ml($id = '', $more = '', $direct = true, $sep = '&', $abs = false) { global $conf; $isexternalimage = media_isexternal($id); if (!$isexternalimage) { $id = cleanID($id); } if (is_array($more)) { // add token for resized images if (!empty($more['w']) || !empty($more['h']) || $isexternalimage) { $more['tok'] = media_get_token($id, $more['w'], $more['h']); } // strip defaults for shorter URLs if (isset($more['cache']) && $more['cache'] == 'cache') { unset($more['cache']); } if (empty($more['w'])) { unset($more['w']); } if (empty($more['h'])) { unset($more['h']); } if (isset($more['id']) && $direct) { unset($more['id']); } if (isset($more['rev']) && !$more['rev']) { unset($more['rev']); } $more = buildURLparams($more, $sep); } else { $matches = array(); if (preg_match_all('/\\b(w|h)=(\\d*)\\b/', $more, $matches, PREG_SET_ORDER) || $isexternalimage) { $resize = array('w' => 0, 'h' => 0); foreach ($matches as $match) { $resize[$match[1]] = $match[2]; } $more .= $more === '' ? '' : $sep; $more .= 'tok=' . media_get_token($id, $resize['w'], $resize['h']); } $more = str_replace('cache=cache', '', $more); //skip default $more = str_replace(',,', ',', $more); $more = str_replace(',', $sep, $more); } if ($abs) { $xlink = DOKU_URL; } else { $xlink = DOKU_BASE; } // external URLs are always direct without rewriting if ($isexternalimage) { $xlink .= 'lib/exe/fetch.php'; $xlink .= '?' . $more; $xlink .= $sep . 'media=' . rawurlencode($id); return $xlink; } $id = idfilter($id); // decide on scriptname if ($direct) { if ($conf['userewrite'] == 1) { $script = '_media'; } else { $script = 'lib/exe/fetch.php'; } } else { if ($conf['userewrite'] == 1) { $script = '_detail'; } else { $script = 'lib/exe/detail.php'; } } // build URL based on rewrite mode if ($conf['userewrite']) { $xlink .= $script . '/' . $id; if ($more) { $xlink .= '?' . $more; } } else { if ($more) { $xlink .= $script . '?' . $more; $xlink .= $sep . 'media=' . $id; } else { $xlink .= $script . '?media=' . $id; } } return $xlink; }
/** * Return array of javascript nodes and nodes to open. * * @author Samuele Tognini <*****@*****.**> */ function _jsnodes($data, $js_name, $noajax = 1) { if (empty($data)) { return false; } //Array of nodes to check $q = array('0'); //Current open node $node = 0; $out = ''; $extra = ''; if ($noajax) { $jscmd = $js_name . ".add"; $com = ";\n"; } else { $jscmd = "new Array "; $com = ","; } foreach ($data as $i => $item) { $i++; //Remove already processed nodes (greater level = lower level) while ($item['level'] <= $data[end($q) - 1]['level']) { array_pop($q); } //till i found its father node if ($item['level'] == 1) { //root node $father = '0'; } else { //Father node $father = end($q); } //add node and its options if ($item['type'] == 'd') { //Search the lowest open node of a tree branch in order to open it. if ($item['open']) { $item['level'] < $data[$node]['level'] ? $node = $i : ($extra .= "{$i} "); } //insert node in last position array_push($q, $i); } $out .= $jscmd . "('" . idfilter($item['id']) . "',{$i}," . $father . ",'" . $item['title'] . "'"; //hns $item['hns'] ? $out .= ",'" . idfilter($item['hns']) . "'" : ($out .= ",0"); $item['type'] == 'd' || $item['type'] == 'l' ? $out .= ",1" : ($out .= ",0"); //MAX option $item['type'] == 'l' ? $out .= ",1" : ($out .= ",0"); $out .= ")" . $com; } $extra = rtrim($extra, ' '); return array($out, $extra); }
/** * Userfunction for html_buildlist * * Prints a media namespace tree item * * @author Andreas Gohr <*****@*****.**> */ function bootstrap_media_nstree_item($item) { global $INPUT; $pos = strrpos($item['id'], ':'); $label = substr($item['id'], $pos > 0 ? $pos + 1 : 0); if (!$item['label']) { $item['label'] = $label; } $class = 'level' . $item['level']; // TODO: only deliver an image if it actually has a subtree... if ($item['open']) { $class .= ' open'; $icon = '<i class="glyphicon glyphicon-minus"></i> '; $alt = '−'; } else { $class .= ' closed'; $icon = '<i class="glyphicon glyphicon-plus"></i> '; $alt = '+'; } $ret = '<li class="' . $class . '">'; if (!($INPUT->str('do') == 'media')) { $ret .= '<a href="' . DOKU_BASE . 'lib/exe/mediamanager.php?ns=' . idfilter($item['id']) . '" class="idx_dir">'; } else { $ret .= '<a href="' . media_managerURL(array('ns' => idfilter($item['id'], false), 'tab_files' => 'files')) . '>'; } $ret .= $icon; $ret .= $item['label']; $ret .= '</a>'; return $ret; }
/** * Userfunction for html_buildlist * * Prints a media namespace tree item * * @author Andreas Gohr <*****@*****.**> */ function media_nstree_item($item) { global $INPUT; $pos = strrpos($item['id'], ':'); $label = substr($item['id'], $pos > 0 ? $pos + 1 : 0); if (empty($item['label'])) { $item['label'] = $label; } $ret = ''; if (!($INPUT->str('do') == 'media')) { $ret .= '<a href="' . DOKU_BASE . 'lib/exe/mediamanager.php?ns=' . idfilter($item['id']) . '" class="idx_dir">'; } else { $ret .= '<a href="' . media_managerURL(array('ns' => idfilter($item['id'], false), 'tab_files' => 'files')) . '" class="idx_dir">'; } $ret .= $item['label']; $ret .= '</a>'; return $ret; }
/** * Userfunction for html_buildlist * * Prints a media namespace tree item * * @author Andreas Gohr <*****@*****.**> */ function media_nstree_item($item) { $pos = strrpos($item['id'], ':'); $label = substr($item['id'], $pos > 0 ? $pos + 1 : 0); if (!$item['label']) { $item['label'] = $label; } $ret = ''; $ret .= '<a href="' . DOKU_BASE . 'lib/exe/mediamanager.php?ns=' . idfilter($item['id']) . '" class="idx_dir">'; $ret .= $item['label']; $ret .= '</a>'; return $ret; }
/** * This builds a link to a wikipage - changed for internal use here * * It handles URL rewriting and adds additional parameter if * given in $more * * @author Andreas Gohr <*****@*****.**> */ function wl($id = '', $more = '', $abs = false, $sep = '&', $IDexists = true, $overrideRewrite = false, $hadBase = false) { global $conf; $this->debug->message("Starting to build WL-URL for '{$id}'", $more, 1); if (is_array($more)) { $intermediateMore = ''; foreach ($more as $key => $value) { if (strlen($intermediateMore) > 0) { $intermediateMore .= $sep; } if (!is_array($value)) { $intermediateMore .= rawurlencode($key) . '='; $intermediateMore .= rawurlencode($value); continue; } foreach ($value as $val) { if (strlen($intermediateMore) > 0) { $intermediateMore .= $sep; } $intermediateMore .= rawurlencode($key) . '[]='; $intermediateMore .= rawurlencode($val); } } $more = $intermediateMore; } else { $more = str_replace(',', $sep, $more); } $id = idfilter($id); if ($abs) { $xlink = DOKU_URL; if (!$IDexists && !$hadBase) { // If the file does not exist, we have to remove the base. This link my be one to an parallel BASE. $xlink = preg_replace('#' . DOKU_BASE . '$#', '', $xlink); } } else { if ($IDexists || $hadBase) { // if the ID does exist, we may add the base. $xlink = DOKU_BASE; } else { $xlink = ""; } } // $this->debug->message("internal WL function Before Replacing: '$xlink'", array(DOKU_REL, DOKU_URL, DOKU_BASE, $xlink), 2); $xlink = preg_replace('#(?<!http:|https:)//+#', '/', ($abs ? '' : '/') . "{$xlink}/"); // ensure slashes at beginning and ending, but strip doubles $this->debug->message("'{$xlink}'", array(DOKU_REL, DOKU_URL, DOKU_BASE, $xlink), 2); if ($overrideRewrite) { $this->debug->message("Override enabled.", null, 1); $id = strtr($id, ':', '/'); $xlink .= $id; if ($more) { $xlink .= '?' . $more; } } else { if ($conf['userewrite'] == 2) { $xlink .= DOKU_SCRIPT . '/' . $id; if ($more) { $xlink .= '?' . $more; } } elseif ($conf['userewrite']) { $xlink .= $id; if ($more) { $xlink .= '?' . $more; } } elseif ($id) { $xlink .= DOKU_SCRIPT . '?id=' . $id; if ($more) { $xlink .= $sep . $more; } } else { $xlink .= DOKU_SCRIPT; if ($more) { $xlink .= '?' . $more; } } } $this->debug->message("internal WL function result: '{$xlink}'", null, 2); return $xlink; }