public function __construct() { self::$default_config = array('timezone' => 'Europe/Paris', 'import_tags_from_feeds' => 0, 'template' => DEFAULT_THEME . '/', 'base_url' => rtrim(dirname($_SERVER['SCRIPT_NAME']), '/') . '/', 'synchronization_type' => 'cron', 'anonymous_access' => 0, 'entries_to_keep' => 50, 'display_entries' => 'description', 'version' => self::$versions[count(self::$versions) - 1], 'entries_per_page' => 20, 'use_rewriting' => get_url_rewriting(), 'facebook_share' => 0, 'twitter_share' => 0, 'shaarli_share' => "", 'wallabag_share' => "", 'diaspora_share' => ""); $this->load(); }
/** * Initialize database. */ function install_db() { if (!in_array('pdo_sqlite', get_loaded_extensions())) { $error = array(); $error['type'] = 'error'; $error['title'] = 'Missing dependency'; $error['content'] = 'Module pdo_sqlite not found.'; return $error; } $dbh = new PDO('sqlite:' . DATA_DIR . DB_FILE); $dbh->query('PRAGMA foreign_keys = ON'); $salt = uniqid(mt_rand(), true); $password = sha1($salt . $_POST['password']); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->beginTransaction(); // Create the table to handle users $dbh->query('CREATE TABLE IF NOT EXISTS users( id INTEGER PRIMARY KEY NOT NULL, login TEXT UNIQUE, password TEXT, salt TEXT, remember_token TEXT, is_admin INT DEFAULT 0 )'); $query = $dbh->prepare('INSERT OR IGNORE INTO users(login, password, salt, is_admin) VALUES(:login, :password, :salt, 1)'); $query->execute(array(':login' => $_POST['login'], ':password' => $password, ':salt' => $salt)); // Create the table to store config options $dbh->query('CREATE TABLE IF NOT EXISTS config( option TEXT UNIQUE COLLATE NOCASE, value TEXT )'); // Insert timezone in the config $query = $dbh->prepare('INSERT OR IGNORE INTO config(option, value) VALUES("timezone", :value)'); $query->execute(array(':value' => $_POST['timezone'])); $query = $dbh->prepare('INSERT OR IGNORE INTO config(option, value) VALUES("use_rewriting", :value)'); $query->execute(array(':value' => get_url_rewriting())); // Create the table to store feeds $dbh->query('CREATE TABLE IF NOT EXISTS feeds( id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, title TEXT, has_user_title INTEGER DEFAULT 0, -- To specify wether the user edited the title manually or not url TEXT UNIQUE COLLATE NOCASE, -- Feed URL links TEXT, -- JSON array of links associated with the feed description TEXT, ttl INT DEFAULT 0, -- This is the ttl of the feed, 0 means that it uses the config value has_user_ttl INT DEFAULT 0, -- To specify wether the user edited the TTL manually or not image TEXT, post TEXT, import_tags_from_feed INTEGER DEFAULT 0 -- To specify wether to use tags from feed or not )'); // Create table to store entries $dbh->query('CREATE TABLE IF NOT EXISTS entries( id INTEGER PRIMARY KEY NOT NULL, feed_id INTEGER NOT NULL, authors TEXT, title TEXT, links TEXT, -- JSON array of enclosed links description TEXT, content TEXT, enclosures TEXT, -- JSON array of links to enclosures comments TEXT, -- Link to comments guid TEXT UNIQUE, pubDate INTEGER, lastUpdate INTEGER, FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE )'); // Create table to store tags $dbh->query('CREATE TABLE IF NOT EXISTS tags( id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name TEXT UNIQUE COLLATE NOCASE )'); $dbh->query('INSERT OR IGNORE INTO tags(name) VALUES("_read")'); $dbh->query('INSERT OR IGNORE INTO tags(name) VALUES("_sticky")'); $dbh->query('INSERT OR IGNORE INTO tags(name) VALUES("_private")'); $dbh->query('INSERT OR IGNORE INTO tags(name) VALUES("_no_home")'); $dbh->query('INSERT OR IGNORE INTO tags(name) VALUES("_type_audio")'); $dbh->query('INSERT OR IGNORE INTO tags(name) VALUES("_type_image")'); $dbh->query('INSERT OR IGNORE INTO tags(name) VALUES("_type_text")'); $dbh->query('INSERT OR IGNORE INTO tags(name) VALUES("_type_video")'); // Create table to store association between tags and entries $dbh->query('CREATE TABLE IF NOT EXISTS tags_entries( tag_id INTEGER, entry_id INTEGER, auto_added_tag INTEGER DEFAULT 0, UNIQUE (tag_id, entry_id), FOREIGN KEY(tag_id) REFERENCES tags(id) ON DELETE CASCADE, FOREIGN KEY(entry_id) REFERENCES entries(id) ON DELETE CASCADE )'); $dbh->query('CREATE TABLE IF NOT EXISTS tags_feeds( tag_id INTEGER, feed_id INTEGER, auto_added_tag INTEGER, UNIQUE (tag_id, feed_id), FOREIGN KEY(tag_id) REFERENCES tags(id) ON DELETE CASCADE, FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE )'); // Create the table to store views $dbh->query('CREATE TABLE IF NOT EXISTS views( id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name TEXT UNIQUE, rule TEXT UNIQUE, -- Specifies what to display. See RFF 4 for more info isPublic INT DEFAULT 0 -- Whether the view is publicly available -- theme TEXT, -- displayStyle INT (Title only, Summary, Full text) )'); $dbh->query('INSERT OR IGNORE INTO views(name, rule) VALUES("_home", "+$all -_read -_no_home BY -$pubDate")'); $dbh->query('INSERT OR IGNORE INTO views(name, rule) VALUES("_public", "+$all -_private BY -$pubDate")'); $dbh->commit(); }