acp_styles::find_available PHP Method

find_available() protected method

Find styles available for installation
protected find_available ( boolean $all ) : array
$all boolean if true, function will return all installable styles. if false, function will return only styles that can be installed
return array List of styles
    protected function find_available($all)
    {
        // Get list of installed styles
        $installed = $this->get_styles();
        $installed_dirs = array();
        $installed_names = array();
        foreach ($installed as $style) {
            $installed_dirs[] = $style['style_path'];
            $installed_names[$style['style_name']] = array('path' => $style['style_path'], 'id' => $style['style_id'], 'parent' => $style['style_parent_id'], 'tree' => (strlen($style['style_parent_tree']) ? $style['style_parent_tree'] . '/' : '') . $style['style_path']);
        }
        // Get list of directories
        $dirs = $this->find_style_dirs();
        // Find styles that can be installed
        $styles = array();
        foreach ($dirs as $dir) {
            if (in_array($dir, $installed_dirs)) {
                // Style is already installed
                continue;
            }
            $cfg = $this->read_style_cfg($dir);
            if ($cfg === false) {
                // Invalid style.cfg
                continue;
            }
            // Style should be available for installation
            $parent = $cfg['parent'];
            $style = array('style_id' => 0, 'style_name' => $cfg['name'], 'style_copyright' => $cfg['copyright'], 'style_active' => 0, 'style_path' => $dir, 'bbcode_bitfield' => $cfg['template_bitfield'], 'style_parent_id' => 0, 'style_parent_tree' => '', '_inherit_name' => $parent, '_available' => true, '_note' => '');
            // Check style inheritance
            if ($parent != '') {
                if (isset($installed_names[$parent])) {
                    // Parent style is installed
                    $row = $installed_names[$parent];
                    $style['style_parent_id'] = $row['id'];
                    $style['style_parent_tree'] = $row['tree'];
                } else {
                    // Parent style is not installed yet
                    $style['_available'] = false;
                    $style['_note'] = sprintf($this->user->lang['REQUIRES_STYLE'], htmlspecialchars($parent));
                }
            }
            if ($all || $style['_available']) {
                $styles[] = $style;
            }
        }
        return $styles;
    }