From 3fadd8d5ab3c60a446c936a9717ebffb55092536 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Thu, 22 Jan 2015 06:45:04 +0530 Subject: [PATCH] Adhere to hide_db directive fully Signed-off-by: Madhura Jayaratne --- libraries/navigation/Nodes/Node.class.php | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index a9bb228edd..7400e4d9b4 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -429,6 +429,9 @@ class Node $handle = $GLOBALS['dbi']->tryQuery($query); if ($handle !== false) { while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { + if ($this->_isHideDb($arr[0])) { + continue; + } $prefix = strstr($arr[0], $dbSeparator, true); if ($prefix === false) { $prefix = $arr[0]; @@ -447,6 +450,9 @@ class Node $handle = $GLOBALS['dbi']->tryQuery($query); if ($handle !== false) { while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { + if ($this->_isHideDb($arr[0])) { + continue; + } if (! in_array($arr[0], $retval)) { foreach ($prefixes as $prefix) { $starts_with = strpos( @@ -497,6 +503,9 @@ class Node $handle = $GLOBALS['dbi']->tryQuery($query); if ($handle !== false) { while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { + if ($this->_isHideDb($arr[0])) { + continue; + } if (! in_array($arr[0], $retval)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr[0]; @@ -562,6 +571,9 @@ class Node $handle = $GLOBALS['dbi']->tryQuery($query); if ($handle !== false) { while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { + if ($this->_isHideDb($arr[0])) { + continue; + } $prefix = strstr($arr[0], $dbSeparator, true); if ($prefix === false) { $prefix = $arr[0]; @@ -600,6 +612,22 @@ class Node return $retval; } + /** + * Detemines whether a given database should be hidden according to 'hide_db' + * + * @param string $db database name + * + * @return boolean whether to hide + */ + private function _isHideDb($db) { + if (! empty($GLOBALS['cfg']['Server']['hide_db']) + && preg_match('/' . $GLOBALS['cfg']['Server']['hide_db'] . '/', $db) + ) { + return true; + } + return false; + } + /** * Get the list of databases for 'SHOW DATABASES LIKE' queries. * If a search clause is set it gets the highest priority while only_db gets