diff --git a/include/class.topic.php b/include/class.topic.php index 2c9fff508a3024bcfad223909309bcbaba2f0045..57230c9be8a3f9ea3f5004269923c1894496ad7e 100644 --- a/include/class.topic.php +++ b/include/class.topic.php @@ -83,7 +83,7 @@ class Topic { } static function getTopicName($id) { - $names = static::getHelpTopics(); + $names = static::getHelpTopics(false, true); return $names[$id]; } @@ -188,43 +188,51 @@ class Topic { return self::save(0, $vars, $errors); } - static function getHelpTopics($publicOnly=false) { + static function getHelpTopics($publicOnly=false, $disabled=false) { global $cfg; - static $names; - - if ($names) return $names; - - $sql = 'SELECT topic_id, topic_pid, ispublic, topic FROM '.TOPIC_TABLE - . ' WHERE isactive=1'; - - $sql .= ' ORDER BY ' - . ($cfg->getTopicSortMode() == 'm' ? '`sort`' : '`topic_id`'); - $res = db_query($sql); + static $topics, $names; + + if (!$names) { + $sql = 'SELECT topic_id, topic_pid, ispublic, isactive, topic FROM '.TOPIC_TABLE + . ' ORDER BY ' + . ($cfg->getTopicSortMode() == 'm' ? '`sort`' : '`topic_id`'); + $res = db_query($sql); + + // Fetch information for all topics, in declared sort order + $topics = array(); + while (list($id, $pid, $pub, $act, $topic) = db_fetch_row($res)) + $topics[$id] = array('pid'=>$pid, 'public'=>$pub, + 'disabled'=>!$act, 'topic'=>$topic); + + // Resolve parent names + foreach ($topics as $id=>$info) { + $name = $info['topic']; + $loop = array($id=>true); + while ($info['pid'] && ($info = $topics[$info['pid']])) { + $name = sprintf('%s / %s', $info['topic'], $name); + if (isset($loop[$info['pid']])) + break; + $loop[$info['pid']] = true; + } + $names[$id] = $name; + } - // Fetch information for all topics, in declared sort order - $topics = array(); - while (list($id, $pid, $pub, $topic) = db_fetch_row($res)) - $topics[$id] = array('pid'=>$pid, 'public'=>$pub, - 'topic'=>$topic); + if ($cfg->getTopicSortMode() == 'a') + uasort($names, function($a, $b) { return strcmp($a, $b); }); + } - // Resolve parent names - foreach ($topics as $id=>$info) { + // Apply requested filters + $requested_names = array(); + foreach ($names as $id=>$n) { + $info = $topics[$id]; if ($publicOnly && !$info['public']) continue; - $name = $info['topic']; - $loop = array($id=>true); - while ($info['pid'] && ($info = $topics[$info['pid']])) { - $name = sprintf('%s / %s', $info['topic'], $name); - if (isset($loop[$info['pid']])) - break; - $loop[$info['pid']] = true; - } - $names[$id] = $name; + if (!$disabled && $info['disabled']) + continue; + $requested_names[$id] = $n; } - if ($cfg->getTopicSortMode() == 'a') - uasort($names, function($a, $b) { return strcmp($a, $b); }); - return $names; + return $requested_names; } function getPublicHelpTopics() {