/** * Nodesøk */ protected function node_search($cid, $dest, $search) { $search = utf8_decode($search); // hent all informasjon $result = \Kofradia\DB::get()->query("SELECT node_id, node_parent_node_id, node_title, node_type, node_params, node_show_menu, node_expand_menu, node_enabled, node_priority, node_change FROM nodes"); $nodes = array(); while ($row = $result->fetch()) { $row['params'] = new params($row['node_params']); $row['enheter'] = array(); $row['plain'] = ""; $nodes[$row['node_id']] = $row; } if (count($nodes) == 0) { $this->msg($cid, $dest, "Ingen siden eksisterer."); return; } // sett opp søkekriteriene $search_list = search_query($search); $search_list = $search_list[1]; $search_list2 = $search_list; // for delvise treff foreach ($search_list as &$q) { $q = '/(\\P{L}|^)' . preg_replace(array('/([\\/\\\\\\[\\]()$.+?|{}])/', '/\\*\\*+/', '/\\*/'), array('\\\\$1', '*', '\\S*'), $q) . '(\\P{L}|$)/i'; } // sett opp søkeliste hvor vi søker med * på slutten av ordene foreach ($search_list2 as &$q) { $q = '/' . preg_replace(array('/([\\/\\\\\\[\\]()$.+?|{}])/', '/\\*\\*+/', '/\\*/'), array('\\\\$1', '*', '\\S*'), $q) . '/i'; } // hent alle enhetene $result = \Kofradia\DB::get()->query("SELECT ni_id, ni_node_id, ni_type, nir_content, nir_params, nir_time FROM nodes_items LEFT JOIN nodes_items_rev ON nir_id = ni_nir_id WHERE ni_enabled != 0 AND ni_deleted = 0 ORDER BY ni_priority"); while ($row = $result->fetch()) { if (!isset($nodes[$row['ni_node_id']])) { continue; } $data = nodes::content_build($row); $nodes[$row['ni_node_id']]['enheter'][] = $data; // bygg opp plain tekst $plain = preg_replace("/<br[^\\/>]*\\/?>/", "\n", $data); $plain = preg_replace("/(<\\/?(h[1-6]|p)[^>]*>)/", "\n\\1", $plain); $plain = html_entity_decode(strip_tags($plain)); $plain = preg_replace("/(^ +| +\$|\\r)/m", "", $plain); #$plain = preg_replace("/(?<![!,.\\n ])\\n/", " ", $plain); $plain = preg_replace("/\\n/", " ", $plain); $plain = preg_replace("/ +/", " ", $plain); $plain = trim($plain); $nodes[$row['ni_node_id']]['plain'] .= $plain . " "; } // sett opp riktige referanser og lag tree $sub = array(); foreach (nodes::$nodes as $row) { if ($row['node_enabled'] != 0) { $sub[$row['node_parent_node_id']][] = $row['node_id']; } } $tree = new tree($sub); $data = $tree->generate(0, NULL, $nodes); // sett opp paths $paths = array(); $path = array(); $number = 1; foreach ($data as $row) { for (; $row['number'] <= $number; $number--) { // fjern fra path array_pop($path); } if ($row['number'] >= $number) { // legg til i path $path[] = $row['data']['node_title']; } $paths[$row['data']['node_id']] = $path; $number = $row['number']; } // sett opp søkeresultater $result = array(); $points = array(); $points2 = array(); foreach ($data as $row) { if ($row['data']['node_type'] != "container") { continue; } // utfør søk $found = true; $p = 0; $p2 = 0; foreach ($search_list as $key => $regex) { $ok = false; $matches = null; // søk i teksten if (preg_match_all($regex, $row['data']['plain'], $matches)) { $ok = true; $p += count($matches[0]); } if (preg_match_all($search_list2[$key], $row['data']['plain'], $matches)) { $ok = true; $p2 += count($matches[0]); } // søk i tittelen if (preg_match_all($regex, $row['data']['node_title'], $matches)) { $ok = true; $p += count($matches[0]); } if (preg_match_all($search_list2[$key], $row['data']['node_title'], $matches)) { $ok = true; $p2 += count($matches[0]); } if ($ok) { continue; } $found = false; break; } // fant? if ($found) { $result[] = $row; $points[] = $p; $points2[] = $p2; } } // vis søkeresultater if (count($result) == 0) { $this->msg($cid, $dest, "Ingen treff ble funnet."); } // sorter søkeresultatene array_multisort($points, SORT_DESC, SORT_NUMERIC, $points2, SORT_DESC, SORT_NUMERIC, $result); $this->msg($cid, $dest, count($result) . " treff ble funnet - " . ess::$s['path'] . '/node/search?q=' . urlencode($search)); $i = 0; foreach ($result as $key => $row) { if ($i++ == 3) { break; } $partial = $points2[$key] - $points[$key]; if ($row['data']['node_id'] == nodes::$default_node) { $url = ess::$s['path'] . '/node'; } else { $url = ess::$s['path'] . '/node/' . $row['data']['node_id']; } $m = array(); if ($points[$key] > 0) { $m[] = $points[$key] . ' treff'; } if ($partial > 0) { $m[] = fwords("%d delvis treff", "%d delvise treff", $partial); } $this->msg($cid, $dest, implode(", ", $m) . ": " . implode(" -> ", $paths[$row['data']['node_id']]) . " {$url}"); } }
/** * Hent tree for mappene * @return tree */ public static function get_directory_tree() { global $_base; // hent alle mappene $result = \Kofradia\DB::get()->query("SELECT cfd_id, cfd_parent_cfd_id, cfd_title, cfd_description, cfd_time, cfd_up_id, cfd_access_level FROM crewfiles_directories ORDER BY cfd_title"); // les inn mappene $dirs = array(); $dirs_sub = array(); while ($row = $result->fetch()) { $dirs[$row['cfd_id']] = $row; $dirs_sub[$row['cfd_parent_cfd_id']][] = $row['cfd_id']; } // hent tree $root = array(0 => array("number" => 0, "prefix" => "", "prefix_node" => "", "data" => crewfiles_directory::$root)); $tree = new tree($dirs_sub); $tree->generate(0, $root, $dirs); // returner tree return $tree; }
protected static function show_nodes_list() { echo ' <h1>Innhold</h1> <h2>Oversikt over sidene</h2> <p class="h_right"><a href="' . ess::$s['relative_path'] . '/node/a?new_node" class="large_button">Ny side</a></p> <table class="table tablemb" width="100%"> <thead> <tr> <th>Tittel</th> <th>Informasjon</th> <th>Enheter</th> <th>Ny side</th> <th>Vis</th> </tr> </thead> <tbody class="c">'; // hent antall items i hver node $result = \Kofradia\DB::get()->query("SELECT ni_node_id, COUNT(ni_id) count FROM nodes_items WHERE ni_deleted = 0 GROUP BY ni_node_id"); $nodes_items_count = array(); while ($row = $result->fetch()) { $nodes_items_count[$row['ni_node_id']] = $row['count']; } foreach (nodes::$nodes as $key => &$value) { $value['ni_count'] = isset($nodes_items_count[$key]) ? $nodes_items_count[$key] : 0; } // generer data $tree = new tree(nodes::$nodes_sub); $data = $tree->generate(0, NULL, nodes::$nodes); $parent_disabled = 0; $parent_hidden = 0; $i = 0; foreach ($data as $key => $row) { if ($parent_disabled != 0 && $row['number'] <= $parent_disabled) { $parent_disabled = 0; } if ($parent_hidden != 0 && $row['number'] <= $parent_hidden) { $parent_hidden = 0; } // adresse switch ($row['data']['node_type']) { case "url_absolute": $params = new params($row['data']['node_params']); $url = htmlspecialchars($params->get("url")); break; case "url_relative": $params = new params($row['data']['node_params']); $url = ess::$s['relative_path'] . htmlspecialchars($params->get("url")); break; default: if ($key == nodes::$default_node) { $url = ess::$s['relative_path'] . '/'; } else { $url = ess::$s['relative_path'] . '/node/' . $row['data']['node_id']; } } // verktøy $tools = array(); // deaktivert? if ($row['data']['node_enabled'] == 0) { $tools[] = '[<span style="color:#FF0000">deaktivert</span>]'; if ($parent_disabled != 0) { $parent_disabled = $row['number']; } } elseif ($parent_disabled) { $tools[] = '[<span style="color:#FF0000">deaktivert</span> (arvet)]'; } // skjult fra menyen if ($row['data']['node_show_menu'] == 0) { $tools[] = '[<span style="color:#FF0000">skjult fra meny</span> - <a href="' . ess::$s['relative_path'] . '/node/a?node_id=' . $row['data']['node_id'] . '&show_menu">vis</a>]'; if ($parent_hidden != 0) { $parent_hidden = $row['number']; } } elseif ($parent_hidden) { $tools[] = '[<span style="color:#FF0000">skjult fra meny</span> (arvet)]'; } $tools = count($tools) == 0 ? ' ' : '<span style="font-size: 10px">' . implode(" ", $tools) . '</span>'; // farge $i++; $class = nodes::$node_id == $key ? ' class="highlight"' : ($i % 2 == 0 ? ' class="color"' : ''); // informasjon om typen switch ($row['data']['node_type']) { case "url_absolute": $typeinfo = '<span style="font-size: 9px">(absolutt adresse)</span>'; break; case "url_relative": $typeinfo = '<span style="font-size: 9px">(relativ adresse)</span>'; break; default: $typeinfo = ''; } // enheter $units = array(); if ($row['data']['ni_count'] > 0) { $units[] = $row['data']['ni_count']; } if ($typeinfo != "") { $units[] = $typeinfo; } $units = count($units) == 0 ? ' ' : implode(" ", $units); echo ' <tr' . $class . '> <td class="l"><span class="plain">' . $row['prefix'] . $row['prefix_node'] . '</span> <a href="' . ess::$s['relative_path'] . '/node/a?node_id=' . $key . '">' . htmlspecialchars($row['data']['node_title']) . '</a></td> <td>' . $tools . '</td> <td>' . $units . '</td> <td style="font-size: 9px"> <a href="' . ess::$s['relative_path'] . '/node/a?new_node&parent_node=' . $key . '" title="Ny side INNI denne">inni</a> <a href="' . ess::$s['relative_path'] . '/node/a?new_node&parent_node=' . $row['data']['node_parent_node_id'] . '&previous_node=' . $key . '" title="Ny side UNDER denne">under</a> </td> <td><a href="' . $url . '">vis</a></td> </tr>'; } echo ' </tbody> </table>'; }