<?php
if (!defined('entry') || !entry) {
    die('Not a valid page');
}
/* ===========================

  Sorbet CMS - A PHP based tumblelog CMS forked from Gelato CMS

  Sorbet CMS is a free software licensed under the GPL 3.0

  =========================== */
?>
<?php
class configuration
{
    public $urlSorbet;
    public $tablePrefix;
    public $idUser;
    public $postLimit;
    public $title;
    public $description;
    public $lang;
    public $template;
    public $urlFriendly;
    public $richText;
    public $offset_city;
    public $offset_time;
    public $shorten_links;
    public $rssImportFrec;
    public $check_version;
    public $plugins = array();

    public function __construct()
    {
        global $isFeed;
        global $db;

        if ($db->ejecutarConsulta("SELECT * FROM ".Table_prefix."config")) {
            $row=$db->obtenerRegistro();
            $this->tablePrefix = Table_prefix;
            $this->urlSorbet = $row['url_installation'];
            $this->postLimit = $row['posts_limit'];
            $this->title = $row['title'];
            $this->description = $row['description'];
            $this->lang = $row['lang'];
            $this->template = $row['template'];

            initLang($this->lang);

            $this->urlFriendly = $this->get_option("url_friendly");
            $this->richText = $this->get_option("rich_text");
            $this->offsetCity = $this->get_option("offset_city");
            $this->offsetTime = $this->get_option("offset_time");
            $this->allowComments = $this->get_option("allow_comments");
            $this->shorten_links = $this->get_option("shorten_links");
            $this->rssImportFrec = $this->get_option("rss_import_frec");
            $this->check_version = $this->get_option("check_version");
            $this->active_plugins = $this->get_option("active_plugins");

            //TODO: Soporte de los plugins desde BD activar/desactivar
            //FIXME cambiar esto por el soporte por carpetas, mas organizado.
            // asi se pueden estandarizar documentacion y thumbnails,
            /*if ($handle = opendir(Absolute_Path."plugins")) {
                while (false !== ($file = readdir($handle))) {
                    if (substr($file, strlen($file)-4, 4) == ".php") {
                        require_once(Absolute_Path."plugins/{$file}");
                        $this->plugins[] = substr($file, 0, strlen($file)-4);
                    }
                }
                closedir($handle);
            }*/
        } else {
            if ($isFeed) {
                header("HTTP/1.0 503 Service Unavailable");
                header("Retry-After: 60");
                exit();
            } else {
                $message = "
				<h3 class=\"important\">Error establishing a database connection</h3>
				<p>The configuration info is not available.</p>";
                die($message);
            }
        }
    }

    public function get_option($name)
    {
        global $db;
        $sql = "SELECT * FROM ".Table_prefix."options WHERE name='".$name."' LIMIT 1";
        $db->ejecutarConsulta($sql);
        if ($db->contarRegistros()>0) {
            $row=$db->obtenerRegistro();
            return $row['val'];
        } else {
            return "0";
        }
    }
}
?>