Classes

File phpboost/module/ModuleConfiguration.class.php

File phpboost/module/ModuleConfiguration.class.php

  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 
<?php
/**
 * @package     PHPBoost
 * @subpackage  Module
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Loic ROUCHON <horn@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2018 07 28
 * @since       PHPBoost 3.0 - 2009 12 12
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
 * @contributor Arnaud GENET <elenwii@phpboost.com>
 * @contributor xela <xela@phpboost.com>
 * @contributor Kevin MASSY <reidlos@phpboost.com>
*/

class ModuleConfiguration
{
    private $name;
    private $description;
    private $author;
    private $author_email;
    private $author_website;
    private $version;
    private $date;
    private $compatibility;
    private $php_version;
    private $repository;
    private $admin_main_page;
    private $admin_menu;
    private $home_page;
    private $contribution_interface;
    private $url_rewrite_rules;
    private $documentation;
    private $enabled_features;

    public function __construct($config_ini_file, $desc_ini_file)
    {
        $this->load_configuration($config_ini_file);
        $this->load_description($desc_ini_file);
    }

    public function get_name()
    {
        return $this->name;
    }

    public function get_description()
    {
        return $this->description;
    }

    public function get_author()
    {
        return $this->author;
    }

    public function get_author_email()
    {
        return $this->author_email;
    }

    public function get_author_website()
    {
        return $this->author_website;
    }

    public function get_version()
    {
        return $this->version;
    }

    public function get_date()
    {
        return $this->date;
    }

    public function get_compatibility()
    {
        return $this->compatibility;
    }

    public function get_php_version()
    {
        return $this->php_version;
    }

    public function get_repository()
    {
        return $this->repository;
    }

    public function get_admin_main_page()
    {
        return $this->admin_main_page;
    }

    public function get_admin_menu()
    {
        return $this->admin_menu;
    }

    public function get_home_page()
    {
        return $this->home_page;
    }

    public function get_contribution_interface()
    {
        return $this->contribution_interface;
    }

    public function get_mini_modules()
    {
        return $this->mini_modules;
    }

    public function get_url_rewrite_rules()
    {
        return $this->url_rewrite_rules;
    }

    public function get_documentation()
    {
        return $this->documentation;
    }

    public function get_enabled_features()
    {
        return $this->enabled_features;
    }

    public function feature_is_enabled($feature_id)
    {
        if (in_array($feature_id, array_map('trim', $this->enabled_features), true))
            return true;
        else
            return false;
    }

    private function load_configuration($config_ini_file)
    {
        $config = parse_ini_file($config_ini_file);
        $this->check_parse_ini_file($config, $config_ini_file);

        $this->author = $config['author'];
        $this->author_email = $config['author_mail'];
        $this->author_website = $config['author_website'];
        $this->version = $config['version'];
        $this->date = $config['date'];
        $this->compatibility = $config['compatibility'];
        $this->php_version = !empty($config['php_version']) ? $config['php_version'] : ServerConfiguration::MIN_PHP_VERSION;
        $this->repository = !empty($config['repository']) ? $config['repository'] : Updates::PHPBOOST_OFFICIAL_REPOSITORY;
        $this->admin_main_page = !empty($config['admin_main_page']) ? $config['admin_main_page'] : '';
        $this->admin_menu = !empty($config['admin_menu']) ? $config['admin_menu'] : '';
        $this->home_page = !empty($config['home_page']) ? $config['home_page'] : '';
        $this->contribution_interface = !empty($config['contribution_interface']) ? $config['contribution_interface'] : '';
        $this->url_rewrite_rules = !empty($config['rewrite_rules']) ? $config['rewrite_rules'] : array();
        $this->enabled_features = !empty($config['enabled_features']) ? explode(',', $config['enabled_features']) : array();
    }

    private function load_description($desc_ini_file)
    {
        $desc = @parse_ini_file($desc_ini_file);
        $this->check_parse_ini_file($desc, $desc_ini_file);
        $this->name = $desc['name'];
        $this->description = $desc['desc'];
        $this->documentation = !empty($desc['documentation']) ? $desc['documentation'] : '';
    }

    private function check_parse_ini_file($parse_result, $ini_file)
    {
        if ($parse_result === false)
        {
            throw new IOException('Parse ini file ' . $ini_file . ' failed');
        }
    }
}
?>