17Syaroslav@ivinco.com<?php
2*130Syaroslav@ivinco.com/*
37Syaroslav@ivinco.com * To change this template, choose Tools | Templates
47Syaroslav@ivinco.com * and open the template in the editor.
57Syaroslav@ivinco.com */
67Syaroslav@ivinco.com
77Syaroslav@ivinco.comfunction formatXml($data)
87Syaroslav@ivinco.com{
97Syaroslav@ivinco.com    $xmlFormat = '
107Syaroslav@ivinco.com<sphinx:document id="{id}">
117Syaroslav@ivinco.com<title><![CDATA[[{title}]]></title>
127Syaroslav@ivinco.com<body><![CDATA[[{body}]]></body>
1380Syaroslav@ivinco.com<namespace><![CDATA[[{namespace}]]></namespace>
1480Syaroslav@ivinco.com<pagename><![CDATA[[{pagename}]]></pagename>
157Syaroslav@ivinco.com<level>{level}</level>
1637Syaroslav@ivinco.com<modified>{modified}</modified>
177Syaroslav@ivinco.com</sphinx:document>
187Syaroslav@ivinco.com
197Syaroslav@ivinco.com';
207Syaroslav@ivinco.com
2180Syaroslav@ivinco.com    return str_replace( array('{id}', '{title}', '{body}', '{namespace}', '{pagename}', '{level}', '{modified}'),
2280Syaroslav@ivinco.com                        array($data['id'], escapeTextValue($data['title_to_index']),
2380Syaroslav@ivinco.com                            escapeTextValue($data['body']),
2480Syaroslav@ivinco.com                            escapeTextValue($data['namespace']),
2580Syaroslav@ivinco.com                            escapeTextValue($data['pagename']),
2612Syaroslav@ivinco.com                             $data['level'], $data['modified']),
277Syaroslav@ivinco.com                $xmlFormat
287Syaroslav@ivinco.com            );
297Syaroslav@ivinco.com}
307Syaroslav@ivinco.com
3137Syaroslav@ivinco.comfunction escapeTextValue($value)
3237Syaroslav@ivinco.com{
3337Syaroslav@ivinco.com    if ("" === $value)
3437Syaroslav@ivinco.com    {
3537Syaroslav@ivinco.com        return "";
3637Syaroslav@ivinco.com    }
3758Syaroslav@ivinco.com    //$value = mb_convert_encoding($value,'UTF-8','ISO-8859-1');
3837Syaroslav@ivinco.com    $value = strip_tags($value);
3937Syaroslav@ivinco.com    $value = stripInvalidXml($value);
4037Syaroslav@ivinco.com    return str_replace("]]>", "]]><![CDATA[]]]]><![CDATA[>]]><![CDATA[", $value);
4137Syaroslav@ivinco.com }
4237Syaroslav@ivinco.com
4337Syaroslav@ivinco.comfunction stripInvalidXml($value)
4437Syaroslav@ivinco.com{
4537Syaroslav@ivinco.com    $ret = "";
4637Syaroslav@ivinco.com    if (empty($value))
4737Syaroslav@ivinco.com    {
4837Syaroslav@ivinco.com      return $ret;
4937Syaroslav@ivinco.com    }
5037Syaroslav@ivinco.com
5137Syaroslav@ivinco.com    $current = null;
5237Syaroslav@ivinco.com    $length = strlen($value);
5337Syaroslav@ivinco.com    for ($i=0; $i < $length; $i++)
5437Syaroslav@ivinco.com    {
5537Syaroslav@ivinco.com      $current = ord($value{$i});
5637Syaroslav@ivinco.com      if (($current == 0x9) ||
5737Syaroslav@ivinco.com          ($current == 0xA) ||
5837Syaroslav@ivinco.com          ($current == 0xD) ||
5937Syaroslav@ivinco.com          (($current >= 0x20) && ($current <= 0xD7FF)) ||
6037Syaroslav@ivinco.com          (($current >= 0xE000) && ($current <= 0xFFFD)) ||
6137Syaroslav@ivinco.com          (($current >= 0x10000) && ($current <= 0x10FFFF)))
6237Syaroslav@ivinco.com      {
6337Syaroslav@ivinco.com        $ret .= chr($current);
6437Syaroslav@ivinco.com      }
6537Syaroslav@ivinco.com      else
6637Syaroslav@ivinco.com      {
6737Syaroslav@ivinco.com        $ret .= " ";
6837Syaroslav@ivinco.com      }
6937Syaroslav@ivinco.com    }
7037Syaroslav@ivinco.com    return $ret;
7137Syaroslav@ivinco.com  }
7237Syaroslav@ivinco.com
737Syaroslav@ivinco.comfunction getDocumentsByHeadings($id, $metadata)
747Syaroslav@ivinco.com{
757Syaroslav@ivinco.com    if (empty($metadata) || empty($metadata['description']['tableofcontents'])) return false;
767Syaroslav@ivinco.com
777Syaroslav@ivinco.com    $sections = array();
7819Syaroslav@ivinco.com    $level = 1;
7919Syaroslav@ivinco.com    $previouse_title = '';
80*130Syaroslav@ivinco.com    $firstSection = true;
817Syaroslav@ivinco.com    foreach($metadata['description']['tableofcontents'] as $row){
82*130Syaroslav@ivinco.com        if ($firstSection){
83*130Syaroslav@ivinco.com            $zerocontent  = getZeroSectionContent($id, $row['title']);
84*130Syaroslav@ivinco.com            if ($zerocontent){
85*130Syaroslav@ivinco.com                $sections[$id] = array(
86*130Syaroslav@ivinco.com                    'section' => $zerocontent,
87*130Syaroslav@ivinco.com                    'level' => 0,
88*130Syaroslav@ivinco.com                    'title' => $id,
89*130Syaroslav@ivinco.com                    'title_to_index' => $id
90*130Syaroslav@ivinco.com                );
91*130Syaroslav@ivinco.com            }
92*130Syaroslav@ivinco.com            $firstSection = false;
93*130Syaroslav@ivinco.com        }
947Syaroslav@ivinco.com        $sections[$row['hid']] = array(
95*130Syaroslav@ivinco.com                                    'section' => getSectionByTitleLevel($id, $row['title'], false),
9619Syaroslav@ivinco.com                                    'level' => $row['level'],
9719Syaroslav@ivinco.com                                    'title' => $row['title']
987Syaroslav@ivinco.com                                    );
9956Syaroslav@ivinco.com        if ($row['level'] > $level && !empty($previouse_title)){
10019Syaroslav@ivinco.com            $sections[$row['hid']]['title_text'] = $previouse_title . " &raquo; ".$row['title'];
10119Syaroslav@ivinco.com        } else {
10219Syaroslav@ivinco.com            $sections[$row['hid']]['title_text'] = $row['title'];
10319Syaroslav@ivinco.com            $previouse_title = $row['title'];
10419Syaroslav@ivinco.com        }
10556Syaroslav@ivinco.com        $sections[$row['hid']]['title_to_index'] = $row['title'];
1067Syaroslav@ivinco.com    }
1077Syaroslav@ivinco.com    return $sections;
1087Syaroslav@ivinco.com}
1097Syaroslav@ivinco.com
110*130Syaroslav@ivinco.comfunction getZeroSectionContent($id, $header)
111*130Syaroslav@ivinco.com{
112*130Syaroslav@ivinco.com    $headerReg = preg_quote($header, '/');
113*130Syaroslav@ivinco.com    $regex = "(={1,6})\s*({$headerReg})\s*(={1,6})";
114*130Syaroslav@ivinco.com    $doc = io_readFile(wikiFN($id));
115*130Syaroslav@ivinco.com    $matches = array();
116*130Syaroslav@ivinco.com    if (!preg_match("/$regex/i",$doc,$matches)) {
117*130Syaroslav@ivinco.com        return false;
118*130Syaroslav@ivinco.com    }
119*130Syaroslav@ivinco.com    if (empty($matches[1])){
120*130Syaroslav@ivinco.com        return false;
121*130Syaroslav@ivinco.com    }
122*130Syaroslav@ivinco.com    $end = strpos($doc, $matches[1]);
123*130Syaroslav@ivinco.com    if (!$end){
124*130Syaroslav@ivinco.com        return false;
125*130Syaroslav@ivinco.com    }
126*130Syaroslav@ivinco.com    $zerocontent = substr($doc, 0, $end);
127*130Syaroslav@ivinco.com    return $zerocontent;
128*130Syaroslav@ivinco.com}
129*130Syaroslav@ivinco.com
13021Syaroslav@ivinco.comfunction getSectionByTitleLevel($id, $header, $extended=false)
13120Syaroslav@ivinco.com{
13220Syaroslav@ivinco.com    $headerReg = preg_quote($header, '/');
13320Syaroslav@ivinco.com    $doc = io_readFile(wikiFN($id));
134*130Syaroslav@ivinco.com    $regex = "(={1,6})\s*({$headerReg})\s*(={1,6})";
13520Syaroslav@ivinco.com    $section = '';
13620Syaroslav@ivinco.com    if (preg_match("/$regex/i",$doc,$matches)) {
13720Syaroslav@ivinco.com        $startHeader = $matches[0];
13820Syaroslav@ivinco.com        $startHeaderPos = strpos($doc, $startHeader) + strlen($startHeader);
13920Syaroslav@ivinco.com        $endDoc = substr($doc, $startHeaderPos);
14020Syaroslav@ivinco.com
14196Syaroslav@ivinco.com        $regex = '(={4,6})(.*?)(={4,6})';
14220Syaroslav@ivinco.com        if (preg_match("/$regex/i",$endDoc,$matches)) {
14320Syaroslav@ivinco.com            $endHeader = $matches[0];
14420Syaroslav@ivinco.com            $endHeaderPos = strpos($doc, $endHeader);
14520Syaroslav@ivinco.com        } else {
14620Syaroslav@ivinco.com            $endHeaderPos = 0;
14720Syaroslav@ivinco.com        }
14820Syaroslav@ivinco.com        if ($endHeaderPos){
14920Syaroslav@ivinco.com            $section = substr($doc, $startHeaderPos, $endHeaderPos - $startHeaderPos);
15020Syaroslav@ivinco.com        } else {
15120Syaroslav@ivinco.com            $section = substr($doc, $startHeaderPos);
152*130Syaroslav@ivinco.com        }
15320Syaroslav@ivinco.com    }
15420Syaroslav@ivinco.com    $section = trim($section);
15521Syaroslav@ivinco.com    //trying to get next section content if body for first section is empty
15621Syaroslav@ivinco.com    //working only for extended mode
15721Syaroslav@ivinco.com    if ($extended && empty($section)){
15820Syaroslav@ivinco.com        $startHeaderPos = $endHeaderPos + strlen($endHeader);
15920Syaroslav@ivinco.com        $endDoc = substr($endDoc, $startHeaderPos);
16096Syaroslav@ivinco.com        $regex = '(={4,6})(.*?)(={4,6})';
16120Syaroslav@ivinco.com        if (preg_match("/$regex/i",$endDoc,$matches)) {
16220Syaroslav@ivinco.com            $endHeader = $matches[0];
16320Syaroslav@ivinco.com            $endHeaderPos = strpos($doc, $endHeader);
16420Syaroslav@ivinco.com        } else {
16520Syaroslav@ivinco.com            $endHeaderPos = 0;
16620Syaroslav@ivinco.com        }
16720Syaroslav@ivinco.com        if ($endHeaderPos){
16820Syaroslav@ivinco.com            $section = substr($doc, $startHeaderPos, $endHeaderPos - $startHeaderPos);
16920Syaroslav@ivinco.com        } else {
17020Syaroslav@ivinco.com            $section = substr($doc, $startHeaderPos);
17120Syaroslav@ivinco.com        }
17220Syaroslav@ivinco.com    }
17321Syaroslav@ivinco.com    $section = trim($section);
17420Syaroslav@ivinco.com    return $section;
17520Syaroslav@ivinco.com}
17620Syaroslav@ivinco.com
1777Syaroslav@ivinco.comfunction getSection($id, $header)
1787Syaroslav@ivinco.com{
17917Syaroslav@ivinco.com    static $cacheInstructions = null;
18017Syaroslav@ivinco.com    static $cacheDoc = null;
18117Syaroslav@ivinco.com
18218Syaroslav@ivinco.com    if (empty($cacheDoc[$id])){
18317Syaroslav@ivinco.com        // Create the parser
18417Syaroslav@ivinco.com        $Parser = & new Doku_Parser();
1857Syaroslav@ivinco.com
18617Syaroslav@ivinco.com        // Add the Handler
18717Syaroslav@ivinco.com        $Parser->Handler = & new Doku_Handler();
18817Syaroslav@ivinco.com
18917Syaroslav@ivinco.com        // Load the header mode to find headers
19017Syaroslav@ivinco.com        $Parser->addMode('header',new Doku_Parser_Mode_Header());
19118Syaroslav@ivinco.com        $Parser->addMode('listblock',new Doku_Parser_Mode_ListBlock());
19217Syaroslav@ivinco.com
19317Syaroslav@ivinco.com        // Loads the raw wiki document
19417Syaroslav@ivinco.com        $doc = io_readFile(wikiFN($id));
1957Syaroslav@ivinco.com
19617Syaroslav@ivinco.com        // Get a list of instructions
19717Syaroslav@ivinco.com        $instructions = $Parser->parse($doc);
19817Syaroslav@ivinco.com
19917Syaroslav@ivinco.com        unset($Parser->Handler);
20017Syaroslav@ivinco.com        unset($Parser);
20117Syaroslav@ivinco.com
20217Syaroslav@ivinco.com        //free old cache
20318Syaroslav@ivinco.com        $cacheInstructions = null;
20418Syaroslav@ivinco.com        $cacheDoc = null;
2057Syaroslav@ivinco.com
20617Syaroslav@ivinco.com        //initialize new cache
20718Syaroslav@ivinco.com        $cacheInstructions[$id] = $instructions;
20818Syaroslav@ivinco.com        $cacheDoc[$id] = $doc;
20917Syaroslav@ivinco.com    } else {
21017Syaroslav@ivinco.com        $instructions = $cacheInstructions[$id];
21117Syaroslav@ivinco.com        $doc = $cacheDoc[$id];
212*130Syaroslav@ivinco.com    }
2137Syaroslav@ivinco.com
214*130Syaroslav@ivinco.com
2157Syaroslav@ivinco.com
2167Syaroslav@ivinco.com    // Use this to watch when we're inside the section we want
2177Syaroslav@ivinco.com    $inSection = FALSE;
2187Syaroslav@ivinco.com    $startPos = 0;
2197Syaroslav@ivinco.com    $endPos = 0;
2207Syaroslav@ivinco.com
2217Syaroslav@ivinco.com    // Loop through the instructions
2227Syaroslav@ivinco.com    foreach ( $instructions as $instruction ) {
2237Syaroslav@ivinco.com
2247Syaroslav@ivinco.com        if ( !$inSection ) {
2257Syaroslav@ivinco.com
2267Syaroslav@ivinco.com            // Look for the header for the "Lists" heading
2277Syaroslav@ivinco.com            if ( $instruction[0] == 'header' &&
2287Syaroslav@ivinco.com                    trim($instruction[1][0]) == $header ) {
2297Syaroslav@ivinco.com
2307Syaroslav@ivinco.com                $startPos = $instruction[2];
2317Syaroslav@ivinco.com                $inSection = TRUE;
2327Syaroslav@ivinco.com            }
2337Syaroslav@ivinco.com        } else {
2347Syaroslav@ivinco.com
2357Syaroslav@ivinco.com            // Look for the end of the section
2367Syaroslav@ivinco.com            if ( $instruction[0] == 'section_close' ) {
2377Syaroslav@ivinco.com                $endPos = $instruction[2];
2387Syaroslav@ivinco.com                break;
2397Syaroslav@ivinco.com            }
2407Syaroslav@ivinco.com        }
2417Syaroslav@ivinco.com    }
2427Syaroslav@ivinco.com
2437Syaroslav@ivinco.com    // Normalize and pad the document in the same way the parse does
2447Syaroslav@ivinco.com    // so that byte indexes with match
2457Syaroslav@ivinco.com    $doc = "\n".str_replace("\r\n","\n",$doc)."\n";
2467Syaroslav@ivinco.com    $section = substr($doc, $startPos, ($endPos-$startPos));
2477Syaroslav@ivinco.com
2487Syaroslav@ivinco.com    return $section;
2497Syaroslav@ivinco.com}
2507Syaroslav@ivinco.com
2517Syaroslav@ivinco.comfunction getCategories($id)
2527Syaroslav@ivinco.com{
2537Syaroslav@ivinco.com    if (empty($id)) return '';
2547Syaroslav@ivinco.com
2557Syaroslav@ivinco.com    if (false === strpos($id, ":")){
25680Syaroslav@ivinco.com        return '';
2577Syaroslav@ivinco.com    }
2587Syaroslav@ivinco.com
2597Syaroslav@ivinco.com    $ns = explode(":", $id);
26080Syaroslav@ivinco.com    $nsCount = count($ns) - 1;
2617Syaroslav@ivinco.com
2627Syaroslav@ivinco.com    $result = '';
2637Syaroslav@ivinco.com    do{
2647Syaroslav@ivinco.com        for($i = 0; $i < $nsCount; $i++){
2657Syaroslav@ivinco.com            $name = $ns[$i];
2667Syaroslav@ivinco.com            $result .= $name;
2677Syaroslav@ivinco.com            if ($i < $nsCount - 1){
2687Syaroslav@ivinco.com                 $result .= ':';
2697Syaroslav@ivinco.com            }
2707Syaroslav@ivinco.com        }
2717Syaroslav@ivinco.com        $result .= ' ';
2727Syaroslav@ivinco.com    }while($nsCount--);
2737Syaroslav@ivinco.com    return $result;
2747Syaroslav@ivinco.com}
2757Syaroslav@ivinco.com
27680Syaroslav@ivinco.comfunction getPagename($id)
27780Syaroslav@ivinco.com{
27880Syaroslav@ivinco.com    if (empty($id)) return '';
27980Syaroslav@ivinco.com
28080Syaroslav@ivinco.com    if (false === strpos($id, ":")){
28180Syaroslav@ivinco.com        return $id;
28280Syaroslav@ivinco.com    }
28380Syaroslav@ivinco.com
28480Syaroslav@ivinco.com    $ns = explode(":", $id);
28580Syaroslav@ivinco.com    return $ns[count($ns) - 1];
28680Syaroslav@ivinco.com}
28780Syaroslav@ivinco.com
28880Syaroslav@ivinco.com
2897Syaroslav@ivinco.com
2907Syaroslav@ivinco.com /**
2917Syaroslav@ivinco.com  * Method return all wiki page names
2927Syaroslav@ivinco.com  * @global array $conf
2937Syaroslav@ivinco.com  * @return array
2947Syaroslav@ivinco.com  */
2957Syaroslav@ivinco.com function getPagesList()
2967Syaroslav@ivinco.com {
2977Syaroslav@ivinco.com    global $conf;
2987Syaroslav@ivinco.com
2997Syaroslav@ivinco.com    $data = array();
3007Syaroslav@ivinco.com    sort($data);
301104Syaroslav@ivinco.com    search($data,$conf['datadir'],'search_allpages',array('skipacl'=>1),'');
3027Syaroslav@ivinco.com
3037Syaroslav@ivinco.com    return $data;
3048Syaroslav@ivinco.com}
3058Syaroslav@ivinco.com
30615Syaroslav@ivinco.comfunction getNsLinks($id, $keywords, $search)
3078Syaroslav@ivinco.com{
3088Syaroslav@ivinco.com    global $conf;
3098Syaroslav@ivinco.com    $parts = explode(':', $id);
3108Syaroslav@ivinco.com    $count = count($parts);
311*130Syaroslav@ivinco.com
3128Syaroslav@ivinco.com    // print intermediate namespace links
3138Syaroslav@ivinco.com    $part = '';
31410Syaroslav@ivinco.com    $data = array();
31510Syaroslav@ivinco.com    $titles = array();
3168Syaroslav@ivinco.com    for($i=0; $i<$count; $i++){
3178Syaroslav@ivinco.com        $part .= $parts[$i].':';
3188Syaroslav@ivinco.com        $page = $part;
3198Syaroslav@ivinco.com        resolve_pageid('',$page,$exists);
32015Syaroslav@ivinco.com
32115Syaroslav@ivinco.com        if (preg_match("#:start$#", $page) && !preg_match("#:start:$#", $part)) {
32213Syaroslav@ivinco.com            $page = substr($page, 0, strpos($page, ":start"));
323*130Syaroslav@ivinco.com        };
3248Syaroslav@ivinco.com
3258Syaroslav@ivinco.com        // output
3268Syaroslav@ivinco.com        if ($exists){
32715Syaroslav@ivinco.com            $titles[wl($page)] = $parts[$i];
3288Syaroslav@ivinco.com        } else {
32918Syaroslav@ivinco.com            $titles[wl($page)] = $parts[$i];
33015Syaroslav@ivinco.com        }
33182Syaroslav@ivinco.com        $data[] = array('link' => "?do=search&id={$keywords}".urlencode(" @ns $page"));
3328Syaroslav@ivinco.com    }
33315Syaroslav@ivinco.com    $titleExcerpt = $search->getExcerpt($titles, $search->starQuery($keywords));
33410Syaroslav@ivinco.com    $i = 0;
33510Syaroslav@ivinco.com    foreach ($data as $key => $notused){
33610Syaroslav@ivinco.com        $data[$key]['title'] = $titleExcerpt[$i++];
33710Syaroslav@ivinco.com    }
33810Syaroslav@ivinco.com    return $data;
33939Syaroslav@ivinco.com}
34039Syaroslav@ivinco.com
34139Syaroslav@ivinco.comfunction printNamespaces($query)
34239Syaroslav@ivinco.com{
34339Syaroslav@ivinco.com  $data = array();
34461Syaroslav@ivinco.com  $query = str_replace(" ", "_", $query);
34569Syaroslav@ivinco.com  $data = ft_pageLookup($query, false);
34639Syaroslav@ivinco.com
34753Syaroslav@ivinco.com  if(!count($data)) return false;
34839Syaroslav@ivinco.com
34953Syaroslav@ivinco.com  print '<h3>Matching pagenames</h3>';
35039Syaroslav@ivinco.com  print '<ul>';
35148Syaroslav@ivinco.com  $counter = 0;
35239Syaroslav@ivinco.com  foreach($data as $id){
35339Syaroslav@ivinco.com    print '<li>';
35439Syaroslav@ivinco.com    $ns = getNS($id);
35539Syaroslav@ivinco.com    if($ns){
35639Syaroslav@ivinco.com      $name = shorten(noNS($id), ' ('.$ns.')',30);
35739Syaroslav@ivinco.com    }else{
35839Syaroslav@ivinco.com      $name = $id;
35939Syaroslav@ivinco.com    }
36061Syaroslav@ivinco.com    $href = wl($id);
36161Syaroslav@ivinco.com
36250Syaroslav@ivinco.com    tpl_link($href,$id, "class='wikilink1'");
36339Syaroslav@ivinco.com    print '</li>';
36448Syaroslav@ivinco.com    if(++$counter == 20){
36548Syaroslav@ivinco.com        break;
36648Syaroslav@ivinco.com    }
36739Syaroslav@ivinco.com  }
36839Syaroslav@ivinco.com  print '</ul>';
36968Syaroslav@ivinco.com}
37068Syaroslav@ivinco.com
37169Syaroslav@ivinco.comfunction printNamespacesNew($pageNames)
37268Syaroslav@ivinco.com{
37369Syaroslav@ivinco.com    if(empty($pageNames)) return false;
37468Syaroslav@ivinco.com
37570Syaroslav@ivinco.com    $limit = 10;
37668Syaroslav@ivinco.com    print '<h3>Matching pagenames</h3>';
37768Syaroslav@ivinco.com    print '<ul>';
37870Syaroslav@ivinco.com    $counter = 0;
37977Syaroslav@ivinco.com    foreach($pageNames as $id => $header){
38076Syaroslav@ivinco.com        $ns = getNS($id);
38176Syaroslav@ivinco.com        if($ns){
38276Syaroslav@ivinco.com          $name = shorten(noNS($id), ' ('.$ns.')',30);
38376Syaroslav@ivinco.com        }else{
38476Syaroslav@ivinco.com          $name = $id;
38576Syaroslav@ivinco.com        }
38668Syaroslav@ivinco.com        print '<li>';
38781Syaroslav@ivinco.com        /*if (!empty($header)){
38877Syaroslav@ivinco.com            print '<a href="'.wl($id).'#'.$header.'" '. "class='wikilink1'>".$id."</a>".'#'.$header;
38977Syaroslav@ivinco.com        } else {
39077Syaroslav@ivinco.com            print '<a href="'.wl($id).'" '. "class='wikilink1'>".$id."</a>";
39181Syaroslav@ivinco.com        }*/
39281Syaroslav@ivinco.com        print '<a href="'.wl($id).'" '. "class='wikilink1'>".$id."</a>";
39368Syaroslav@ivinco.com        print '</li>';
39470Syaroslav@ivinco.com        if (++$counter == $limit){
39570Syaroslav@ivinco.com            break;
39670Syaroslav@ivinco.com        }
39768Syaroslav@ivinco.com    }
39868Syaroslav@ivinco.com    print '</ul>';
39994Syaroslav@ivinco.com}
40094Syaroslav@ivinco.com
40194Syaroslav@ivinco.comif(!function_exists('shorten')){
40294Syaroslav@ivinco.com    /**
40394Syaroslav@ivinco.com     * Shorten a given string by removing data from the middle
40494Syaroslav@ivinco.com     *
40594Syaroslav@ivinco.com     * You can give the string in two parts, teh first part $keep
40694Syaroslav@ivinco.com     * will never be shortened. The second part $short will be cut
40794Syaroslav@ivinco.com     * in the middle to shorten but only if at least $min chars are
40894Syaroslav@ivinco.com     * left to display it. Otherwise it will be left off.
40994Syaroslav@ivinco.com     *
41094Syaroslav@ivinco.com     * @param string $keep   the part to keep
41194Syaroslav@ivinco.com     * @param string $short  the part to shorten
41294Syaroslav@ivinco.com     * @param int    $max    maximum chars you want for the whole string
41394Syaroslav@ivinco.com     * @param int    $min    minimum number of chars to have left for middle shortening
41494Syaroslav@ivinco.com     * @param string $char   the shortening character to use
41594Syaroslav@ivinco.com     */
41694Syaroslav@ivinco.com    function shorten($keep,$short,$max,$min=9,$char='⌇'){
41794Syaroslav@ivinco.com        $max = $max - utf8_strlen($keep);
41894Syaroslav@ivinco.com       if($max < $min) return $keep;
41994Syaroslav@ivinco.com        $len = utf8_strlen($short);
42094Syaroslav@ivinco.com        if($len <= $max) return $keep.$short;
42194Syaroslav@ivinco.com        $half = floor($max/2);
42294Syaroslav@ivinco.com        return $keep.utf8_substr($short,0,$half-1).$char.utf8_substr($short,$len-$half);
42394Syaroslav@ivinco.com    }
42494Syaroslav@ivinco.com}
425