Skip to content

Commit

Permalink
Always using index instead of exploring folders
Browse files Browse the repository at this point in the history
  • Loading branch information
geekitude committed Jun 19, 2016
1 parent fcc0d70 commit 80ff97f
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function register(Doku_Event_Handler $controller) {

function populate_jsinfo(&$event, $params) {
global $JSINFO, $conf, $ID;
global $excluded;

$namespaces = array();
$yah_ns = array(0 => '');
Expand All @@ -49,21 +50,22 @@ function populate_jsinfo(&$event, $params) {
$part = '';
for($i = 0; $i < $count - 1; $i++) {
$part .= $parts[$i].':';
if ($part == $conf['start']) continue; // Skip startpage
if ($part == $conf['start']) continue; // Skip start page
$elements = 0;
// Check corresponding path for subfolders and pages (excluding some pages corresponding to settings)
$path = $conf['savedir']."/pages/".str_replace(":", "/", rtrim($part, ":"));
if (is_dir($path)) {
foreach (new DirectoryIterator($path) as $fileInfo) {
if ($fileInfo->isDot()) continue;
if (($fileInfo->isDir()) or (($fileInfo->isFile()) && ($fileInfo->getExtension() == "txt") && (!in_array($fileInfo->getBasename(".txt"), $excluded)))) {
$elements++;
}
// Get index of current crumb namespace
$idx = cleanID(getNs($part));
$dir = utf8_encodeFN(str_replace(':','/',$idx));
$data = array();
search($data,$conf['datadir'],'search_index',array('ns' => $idx),$dir);
// Count pages that are not in configured exclusions
foreach ($data as $item) {
if (!in_array(noNs($item['id']), $excluded)) {
$elements++;
}
if ($elements > 0) {
$yah_ns[$i+1] = rtrim($part, ":");
}

}
// If there's at least one page that isn't excluded, prepare JSINFO data for that crumb
if ($elements > 0) {
$yah_ns[$i+1] = $idx;
}
}
$JSINFO['plugin_twistienav']['yah_ns'] = $yah_ns;
Expand All @@ -77,21 +79,22 @@ function populate_jsinfo(&$event, $params) {
$i++;
// Don't do anything unless 'startPagesOnly' setting is off or current breadcrumb leads to a namespace start page
if (($this->getConf('startPagesOnly') == 0) or (strpos($crumbId, $conf['start']) !== false)) {
//array_push($namespaces, getNS($crumbId));
$elements = 0;
// Check corresponding path for subfolders and pages (excluding start.txt and topbar.txt pages)
$path = $conf['savedir']."/pages/".str_replace(":", "/", getNS($crumbId));
if (is_dir($path)) {
foreach (new DirectoryIterator($path) as $fileInfo) {
if ($fileInfo->isDot()) continue;
if (($fileInfo->isDir()) or (($fileInfo->isFile()) && ($fileInfo->getExtension() == "txt") && (!in_array($fileInfo->getBasename(".txt"), $excluded)))) {
$elements++;
}
}
if ($elements > 0) {
$bc_ns[$i] = getNS($crumbId);
// Get index of current crumb namespace
$idx = cleanID(getNs($crumbId));
$dir = utf8_encodeFN(str_replace(':','/',$idx));
$data = array();
search($data,$conf['datadir'],'search_index',array('ns' => $idx),$dir);
// Count pages that are not in configured exclusions
foreach ($data as $item) {
if (!in_array(noNs($item['id']), $excluded)) {
$elements++;
}
}
// If there's at least one page that isn't excluded, prepare JSINFO data for that crumb
if ($elements > 0) {
$bc_ns[$i] = $idx;
}
}
}
$JSINFO['plugin_twistienav']['bc_ns'] = $bc_ns;
Expand Down

0 comments on commit 80ff97f

Please sign in to comment.