*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); if(!defined('DOKU_LF')) define('DOKU_LF', "\n"); require_once(DOKU_PLUGIN.'action.php'); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class action_plugin_sidebarng extends DokuWiki_Action_Plugin { // register hook function register(&$controller) { $controller->register_hook('TPL_CONTENT_DISPLAY', 'BEFORE', $this, '_before'); $controller->register_hook('TPL_CONTENT_DISPLAY', 'AFTER', $this, '_after'); } function _before(&$event, $param) { $pos = $this->getConf('pos'); ob_start(); $this->p_sidebar($pos); $this->sidebar = ob_get_contents(); ob_end_clean(); if(empty($this->sidebar) && !$this->getConf('main_always')) { print '
' . DOKU_LF; } else { if($pos == 'left') { print '
' . DOKU_LF; print $this->sidebar; print '
' . DOKU_LF; print '
' . DOKU_LF; } else { print '
' . DOKU_LF; } } } function _after(&$event, $param) { $pos = $this->getConf('pos'); if(empty($this->sidebar) && !$this->getConf('main_always')) { print '
' . DOKU_LF; } else { if($pos == 'left') { print '
' . DOKU_LF; } else { print '
' . DOKU_LF; print '
' . DOKU_LF; print $this->sidebar; print '
'. DOKU_LF; } } } /** * Displays the sidebar * * Michael Klier */ function p_sidebar($pos) { $sb_order = explode(',', $this->getConf('order')); $sb_content = explode(',', $this->getConf('content')); $notoc = (in_array('toc', $sb_content)) ? true : false; // process contents by given order foreach($sb_order as $sb) { if(in_array($sb,$sb_content)) { $key = array_search($sb,$sb_content); unset($sb_content[$key]); $this->_sidebar_dispatch($sb,$pos); } } // check for left content not specified by order if(is_array($sb_content) && !empty($sb_content) > 0) { foreach($sb_content as $sb) { $this->_sidebar_dispatch($sb,$pos); } } } /** * Prints given sidebar box * * @author Michael Klier */ function _sidebar_dispatch($sb, $pos) { global $lang; global $conf; global $ID; global $REV; global $INFO; $svID = $ID; // save current ID $svREV = $REV; // save current REV $pname = $this->getConf('pagename'); switch($sb) { case 'main': $main_sb = $pname; if(@page_exists($main_sb)) { if(auth_quickaclcheck($main_sb) >= AUTH_READ) { $always = $this->getConf('main_always'); if($always or (!$always && !getNS($ID))) { print '' . DOKU_LF; } } } else { $out = $this->locale_xhtml('nosidebar'); $link = '' . $pname . '' . DOKU_LF; print '' . DOKU_LF; } break; case 'namespace': $user_ns = $this->getConf('user_ns'); $group_ns = $this->getConf('group_ns'); if(!preg_match("/^".$user_ns.":.*?$|^".$group_ns.":.*?$/", $svID)) { // skip group/user sidebars and current ID $ns_sb = $this->_getNsSb($svID); if($ns_sb && auth_quickaclcheck($ns_sb) >= AUTH_READ) { print '' . DOKU_LF; } } break; case 'user': $user_ns = $this->getConf('user_ns'); if(isset($INFO['userinfo']['name'])) { $user = $_SERVER['REMOTE_USER']; $user_sb = $user_ns . ':' . $user . ':' . $pname; if(@page_exists($user_sb)) { $subst = array('pattern' => array('/@USER@/'), 'replace' => array($user)); print ''; } // check for namespace sidebars in user namespace too if(preg_match('/'.$user_ns.':'.$user.':.*/', $svID)) { $ns_sb = $this->_getNsSb($svID); if($ns_sb && $ns_sb != $user_sb && auth_quickaclcheck($ns_sb) >= AUTH_READ) { print '' . DOKU_LF; } } } break; case 'group': $group_ns = $this->getConf('group_ns'); if(isset($INFO['userinfo']['grps'])) { foreach($INFO['userinfo']['grps'] as $grp) { $group_sb = $group_ns.':'.$grp.':'.$pname; if(@page_exists($group_sb) && auth_quickaclcheck(cleanID($group_sb)) >= AUTH_READ) { $subst = array('pattern' => array('/@GROUP@/'), 'replace' => array($grp)); print '' . DOKU_LF; } } } else { $group_sb = $group_ns.':all:'.$pname; if(@page_exists($group_sb) && auth_quickaclcheck(cleanID($group_sb)) >= AUTH_READ) { print '' . DOKU_LF; } } break; case 'toolbox': $actions = array('admin', 'edit', 'history', 'recent', 'backlink', 'subscribe', 'subscribens', 'index', 'login', 'profile'); print '' . DOKU_LF; break; case 'trace': print '' . DOKU_LF; break; case 'extra': print '' . DOKU_LF; break; default: // check for user defined sidebars if(@file_exists(DOKU_PLUGIN.'sidebarng/sidebars/'.$sb.'/sidebar.php')) { print '' . DOKU_LF; } break; } // restore ID and REV $ID = $svID; $REV = $svREV; } /** * Removes the TOC of the sidebar pages and * shows a edit button if the user has enough rights * * @author Michael Klier */ function p_sidebar_xhtml($sb,$pos,$subst=array()) { $data = p_wiki_xhtml($sb,'',false); if(!empty($subst)) { $data = preg_replace($subst['pattern'], $subst['replace'], $data); } if(auth_quickaclcheck($sb) >= AUTH_EDIT) { $data .= '
'.html_btn('secedit',$sb,'',array('do'=>'edit','rev'=>'','post')).'
'; } // strip TOC $data = preg_replace('/
.*?(<\/div>\n<\/div>)/s', '', $data); // replace headline ids for XHTML compliance $data = preg_replace('/(.*?<\/a><\/h.*?>)/','\1sb_'.$pos.'_\2\3sb_'.$pos.'_\4\5', $data); return ($data); } /** * Searches for namespace sidebars * * @author Michael Klier */ function _getNsSb($id) { $pname = $this->getConf('pagename'); $ns_sb = ''; $path = explode(':', $id); $found = false; while(count($path) > 0) { $ns_sb = implode(':', $path).':'.$pname; if(@page_exists($ns_sb)) return $ns_sb; array_pop($path); } // nothing found return false; } } // vim:ts=4:sw=4:et:enc=utf-8: