* @author Otto Vainio */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'../../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',realpath(dirname(__FILE__).'../').'/'); if(!defined('NL')) define('NL',"\n"); require_once(DOKU_INC.'inc/html.php'); require_once(DOKU_INC.'inc/search.php'); $thislang=array(); setupLocale(); function getPluginName() { $basename = preg_replace( '/^.+[\\\\\\/]/', '', dirname(__FILE__)); return $basename; } function myhtml_index(){ global $NS; global $conf; global $ID; $dir = $conf['datadir']; $ns = cleanID($NS); #fixme use appropriate function if(empty($ns)){ $ns = dirname(str_replace(':','/',$ID)); if($ns == '.') $ns =''; } $dir = utf8_encodeFN(str_replace(':','/',$ns)); print p_locale_xhtml('index'); $data = array(); search($data,$conf['datadir'],'linkpage_search_index',array('ns' => $ns),$dir); print html_buildlist($data,'idx','html_list_index','html_li_index'); } function linkpage_filelist($ns,$auth=null,$jump=''){ global $conf; global $lang; global $thislang; $ns = cleanID($ns); // check auth our self if not given (needed for ajax calls) if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); echo '

:'.hsc($ns).'

'.NL; if($auth < AUTH_READ){ // FIXME: print permission warning here instead? echo '
'.$lang['nothingfound'].'
'.NL; return; } $dir = utf8_encodeFN(str_replace(':','/',$ns)); $data = array(); search($data,$conf['datadir'],'linkpage_search_index',array('ns' => $ns),$dir); if(!count($data)){ echo '
'.$lang['nothingfound'].'
'.NL; return; } linkpage_newpage($ns); echo $thislang['clicktosort'].NL; echo ''; echo ''; echo ''; foreach($data as $item){ linkpage_printfile($item,$auth,$jump); } echo '
'.$thislang['id'].''.$thislang['title'].'
'; } function linkpage_fileContent(){ global $AUTH; global $NS; global $JUMPTO; ptln('
'); linkpage_filelist($NS,$AUTH,$JUMPTO); ptln('
'); } /** * Formats and prints one file in the list */ function linkpage_printfile($item,$auth,$jump){ if ($item['type']=='d') return; global $lang; // Prepare zebra coloring // I always wanted to use this variable name :-D static $twibble = 1; $twibble *= -1; $zebra = ($twibble == -1) ? 'odd' : 'even'; // Automatically jump to recent action if($jump == $item['id']) { $jump = ' id="scroll__here" '; }else{ $jump = ''; } // Prepare fileicons list($ext,$mime) = mimetype($item['file']); $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); $class = 'select linkpagefile mf_'.$class; // Prepare filename $file = utf8_decodeFN($item['id']); $title = $item['title']; $pgsplt=explode(':',$item['id']); $pagename = array_pop($pgsplt); if (!$title) $title=$pagename; // Prepare info $info = ''; // output echo ''; echo '
'.NL; echo ''.$pagename.''; echo '
'.NL; echo ''; echo '
'.NL; echo $title; echo '
'; echo $lang['mediausage'].' [[:'.$item['id'].']]'; echo '
'; echo '
'; echo ''; } function linkpage_mediaTree(){ global $NS; ptln('
'); linkpage_nstree($NS); ptln('
'); } /** * Build a tree outline of available media namespaces * * @author Andreas Gohr * @author Otto Vainio */ function linkpage_nstree($ns){ global $conf; global $lang; // currently selected namespace $ns = cleanID($ns); if(empty($ns)){ $ns = dirname(str_replace(':','/',$ID)); if($ns == '.') $ns =''; } $ns = utf8_encodeFN(str_replace(':','/',$ns)); $data = array(); search($data,$conf['datadir'],'linkpage_search_index',array('ns' => $ns, 'nofiles' => true)); // wrap a list with the root level around the other namespaces $item = array( 'level' => 0, 'id' => '', 'open' =>'true', 'label' => '['.$lang['mediaroot'].']'); echo '
    '; echo linkpage_nstree_li($item); echo linkpage_nstree_item($item); echo html_buildlist($data,'idx','linkpage_nstree_item','linkpage_nstree_li'); echo ''; echo '
'; } /** * Userfunction for html_buildlist * * Prints a linkpage namespace tree item * * @author Andreas Gohr * @author Otto Vainio */ function linkpage_nstree_item($item){ $pos = strrpos($item['id'], ':'); $label = substr($item['id'], $pos > 0 ? $pos + 1 : 0); if(!$item['label']) $item['label'] = $label; $ret = ''; $ret .= ''; $ret .= $item['label']; $ret .= ''; return $ret; } /** * Userfunction for html_buildlist * * Prints a linkpage namespace tree item opener * * @author Andreas Gohr * @author Otto Vainio */ function linkpage_nstree_li($item){ $class='linkpage level'.$item['level']; if($item['open']){ $class .= ' open'; $img = DOKU_BASE.'lib/images/minus.gif'; $alt = '−'; }else{ $class .= ' closed'; $img = DOKU_BASE.'lib/images/plus.gif'; $alt = '+'; } return '
  • '. ''.$alt.''; } /** * Build the browsable index of pages * * $opts['ns'] is the current namespace * * @author Andreas Gohr * @author Otto Vainio */ function linkpage_search_index(&$data,$base,$file,$type,$lvl,$opts){ $return = true; $item = array(); if($type == 'd' && !preg_match('#^'.$file.'(/|$)#','/'.$opts['ns'])){ //add but don't recurse $return = false; }elseif($type == 'f' && ($opts['nofiles'] || !preg_match('#\.txt$#',$file))){ //don't add return false; } $id = pathID($file); $title = p_get_metadata($id, 'title'); //check hidden if(isHiddenPage($id)){ return false; } //check ACL if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){ return false; } $data[]=array( 'id' => $id, 'type' => $type, 'level' => $lvl, 'title' => $title, 'open' => $return ); return $return; } /** * Print the Add new page form * */ function linkpage_newpage($ns){ global $lang; global $thislang; global $conf; $sepa='0'; if ($conf['plugin']['linkmanager']['usetitleseparator']) {$sepa='1';} ?>

    submit

    lang * this function is automatically called by getLang() */ function setupLocale() { if ($localised) return; global $thislang; global $conf; // definitely don't invoke "global $lang" $path = DOKU_PLUGIN.getPluginName().'/lang/'; // echo "polku:$path"; $lang = array(); // don't include once, in case several plugin components require the same language file @include($path.'en/lang.php'); if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php'); $thislang = $lang; $localised = true; } ?>