Simplify the code

Issue #20 resolved
Former user created an issue

Simple code is easier to understand and to maintain.

See this part:

        // get the namespace genealogy of the current id
        $sub_ns = $this->_get_sub_ns($INFO["id"]);

        // build the namespace tree structure
        $ns_acmenu = $this->_get_ns_acmenu($sub_ns);  // namespace in which <acmenu> is

Instead of these 2 functions, one this is enough:

private function _get_sidebar_dir() {
    global $conf, $INFO;
    $base = realpath($conf['datadir']);
    $sidebar = "/" . str_replace(":", "/", $conf['sidebar']) . ".txt";
    $chunks = explode(":", $INFO["id"], -1);
    while ($chunks) {
        $dir = $base . "/" . implode("/", $chunks);
        if (file_exists($dir . $sidebar)) return $dir;
        array_pop($chunks);
    }
    return $base;
}

(Here we can use "/" instead of DIRECTORY_SEPARATOR because we do not compare paths with them. We only perform file functions with them, in which case PHP automatically converts them to proper symbols).

So in function _tree($level) we can just

    $dir = _get_sidebar_dir();

Comments (4)

  1. D. C. Stoyanov repo owner

    Well, actually I've done a different simplification.

    Since in script.js there was the function get_sub_start, which was practically similar to _get_sub_ns defined in syntax.php, I've decided to delete the former and reuse the latter passing it's content to _get_ns_acmenu in syntax.php and to set_cookie in script.js.

  2. Log in to comment