Пример #1
0
 /**
  * @author Inez Korczynski <*****@*****.**>
  */
 private function parseSidebarMenu($lines)
 {
     wfProfileIn(__METHOD__);
     $nodes = array();
     $nodes[] = array();
     $lastDepth = 0;
     $i = 0;
     if (is_array($lines)) {
         foreach ($lines as $line) {
             if (strlen($line) == 0) {
                 # ignore empty lines
                 continue;
             }
             $node = MonacoSidebar::parseItem($line);
             $node['depth'] = strrpos($line, '*') + 1;
             if ($node['depth'] == $lastDepth) {
                 $node['parentIndex'] = $nodes[$i]['parentIndex'];
             } else {
                 if ($node['depth'] == $lastDepth + 1) {
                     $node['parentIndex'] = $i;
                 } else {
                     for ($x = $i; $x >= 0; $x--) {
                         if ($x == 0) {
                             $node['parentIndex'] = 0;
                             break;
                         }
                         if ($nodes[$x]['depth'] == $node['depth'] - 1) {
                             $node['parentIndex'] = $x;
                             break;
                         }
                     }
                 }
             }
             if (substr($node['org'], 0, 1) == '#') {
                 $this->addExtraItemsToSidebarMenu($node, $nodes);
             }
             $nodes[$i + 1] = $node;
             $nodes[$node['parentIndex']]['children'][] = $i + 1;
             $lastDepth = $node['depth'];
             $i++;
         }
     }
     wfProfileOut(__METHOD__);
     return $nodes;
 }