\nRewriteEngine On\nRewriteBase {$index}\nRewriteCond %{REQUEST_FILENAME} !-f\n". "RewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule ^.+$ index.php [L]\n"; $path = preg_quote($index, "/"); $htaccess_has_chyrp = (file_exists(MAIN_DIR."/.htaccess") and preg_match("/\n([\s]*)RewriteEngine On\n([\s]*)RewriteBase {$path}\n". "([\s]*)RewriteCond %\{REQUEST_FILENAME\} !-f\n([\s]*)RewriteCond %\{REQUEST_FILENAME\}". " !-d\n([\s]*)RewriteRule \^\.\+\\$ index\.php \[L\]\n([\s]*)<\/IfModule>/", file_get_contents(MAIN_DIR."/.htaccess"))); $errors = array(); $installed = false; if (file_exists(INCLUDES_DIR."/config.yaml.php") and file_exists(MAIN_DIR."/.htaccess")) { $sql = SQL::current(true); if ($sql->connect(true) and !empty($config->url) and $sql->count("users")) error(__("Already Installed"), __("Chyrp is already correctly installed and configured.")); } if ((!is_writable(MAIN_DIR) and !file_exists(MAIN_DIR."/.htaccess")) or (file_exists(MAIN_DIR."/.htaccess") and !is_writable(MAIN_DIR."/.htaccess") and !$htaccess_has_chyrp)) $errors[] = _f("STOP! Before you go any further, you must create a .htaccess file in Chyrp's install directory and put this in it:\n
%s
", array(fix($htaccess))); if (!is_writable(INCLUDES_DIR)) $errors[] = __("Chyrp's includes directory is not writable by the server. In order for the installer to generate your configuration files, please CHMOD or CHOWN it so that Chyrp can write to it."); if (!empty($_POST)) { if ($_POST['adapter'] == "sqlite" and !@is_writable(dirname($_POST['database']))) $errors[] = __("SQLite database file could not be created. Please make sure your server has write permissions to the location for the database."); else { $sql = SQL::current(array("host" => $_POST['host'], "username" => $_POST['username'], "password" => $_POST['password'], "database" => $_POST['database'], "prefix" => $_POST['prefix'], "adapter" => $_POST['adapter'])); if (!$sql->connect(true)) $errors[] = _f("Could not connect to the specified database:\n
%s
", array($sql->error)); elseif ($_POST['adapter'] == "pgsql") { new Query($sql, "CREATE FUNCTION year(timestamp) RETURNS double precision AS 'select extract(year from $1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT"); new Query($sql, "CREATE FUNCTION month(timestamp) RETURNS double precision AS 'select extract(month from $1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT"); new Query($sql, "CREATE FUNCTION day(timestamp) RETURNS double precision AS 'select extract(day from $1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT"); new Query($sql, "CREATE FUNCTION hour(timestamp) RETURNS double precision AS 'select extract(hour from $1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT"); new Query($sql, "CREATE FUNCTION minute(timestamp) RETURNS double precision AS 'select extract(minute from $1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT"); new Query($sql, "CREATE FUNCTION second(timestamp) RETURNS double precision AS 'select extract(second from $1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT"); } } if (empty($_POST['name'])) $errors[] = __("Please enter a name for your website."); if (!isset($_POST['timezone'])) $errors[] = __("Time zone cannot be blank."); if (empty($_POST['login'])) $errors[] = __("Please enter a username for your account."); if (empty($_POST['password_1'])) $errors[] = __("Password cannot be blank."); if ($_POST['password_1'] != $_POST['password_2']) $errors[] = __("Passwords do not match."); if (empty($_POST['email'])) $errors[] = __("E-Mail address cannot be blank."); if (empty($errors)) { if (!$htaccess_has_chyrp) if (!file_exists(MAIN_DIR."/.htaccess")) { if (!@file_put_contents(MAIN_DIR."/.htaccess", $htaccess)) $errors[] = _f("Could not generate .htaccess file. Clean URLs will not be available unless you create it and put this in it:\n
%s
", array(fix($htaccess))); } elseif (!@file_put_contents(MAIN_DIR."/.htaccess", "\n\n".$htaccess, FILE_APPEND)) { $errors[] = _f("Could not generate .htaccess file. Clean URLs will not be available unless you create it and put this in it:\n
%s
", array(fix($htaccess))); } $config->set("sql", array()); $config->set("name", $_POST['name']); $config->set("description", $_POST['description']); $config->set("url", $url); $config->set("chyrp_url", $url); $config->set("feed_url", ""); $config->set("email", $_POST['email']); $config->set("locale", "en_US"); $config->set("theme", "stardust"); $config->set("posts_per_page", 5); $config->set("feed_items", 20); $config->set("clean_urls", false); $config->set("post_url", "(year)/(month)/(day)/(url)/"); $config->set("timezone", $_POST['timezone']); $config->set("can_register", true); $config->set("default_group", 0); $config->set("guest_group", 0); $config->set("enable_trackbacking", true); $config->set("send_pingbacks", false); $config->set("enable_xmlrpc", true); $config->set("enable_ajax", true); $config->set("uploads_path", "/uploads/"); $config->set("enabled_modules", array()); $config->set("enabled_feathers", array("text")); $config->set("routes", array()); $config->set("secure_hashkey", md5(random(32, true))); foreach (array("host", "username", "password", "database", "prefix", "adapter") as $field) $sql->set($field, $_POST[$field], true); if ($sql->adapter == "mysql" and class_exists("MySQLi")) $sql->method = "mysqli"; elseif ($sql->adapter == "mysql" and function_exists("mysql_connect")) $sql->method = "mysql"; elseif ($sql->adapter == "sqlite" and in_array("sqlite", PDO::getAvailableDrivers())) $sql->method = "pdo"; $sql->connect(); # Posts table $sql->query("CREATE TABLE IF NOT EXISTS __posts ( id INTEGER PRIMARY KEY AUTO_INCREMENT, feather VARCHAR(32) DEFAULT '', clean VARCHAR(128) DEFAULT '', url VARCHAR(128) DEFAULT '', pinned BOOLEAN DEFAULT FALSE, status VARCHAR(32) DEFAULT 'public', user_id INTEGER DEFAULT 0, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL ) DEFAULT CHARSET=utf8"); # Post attributes table. $sql->query("CREATE TABLE IF NOT EXISTS __post_attributes ( post_id INTEGER NOT NULL , name VARCHAR(100) DEFAULT '', value LONGTEXT, PRIMARY KEY (post_id, name) ) DEFAULT CHARSET=utf8"); # Pages table $sql->query("CREATE TABLE IF NOT EXISTS __pages ( id INTEGER PRIMARY KEY AUTO_INCREMENT, title VARCHAR(250) DEFAULT '', body LONGTEXT, show_in_list BOOLEAN DEFAULT '1', list_order INTEGER DEFAULT 0, clean VARCHAR(128) DEFAULT '', url VARCHAR(128) DEFAULT '', user_id INTEGER DEFAULT 0, parent_id INTEGER DEFAULT 0, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL ) DEFAULT CHARSET=utf8"); # Users table $sql->query("CREATE TABLE IF NOT EXISTS __users ( id INTEGER PRIMARY KEY AUTO_INCREMENT, login VARCHAR(64) DEFAULT '', password VARCHAR(60) DEFAULT '', full_name VARCHAR(250) DEFAULT '', email VARCHAR(128) DEFAULT '', website VARCHAR(128) DEFAULT '', group_id INTEGER DEFAULT 0, joined_at DATETIME DEFAULT NULL, UNIQUE (login) ) DEFAULT CHARSET=utf8"); # Groups table $sql->query("CREATE TABLE IF NOT EXISTS __groups ( id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100) DEFAULT '', UNIQUE (name) ) DEFAULT CHARSET=utf8"); # Permissions table $sql->query("CREATE TABLE IF NOT EXISTS __permissions ( id VARCHAR(100) DEFAULT '', name VARCHAR(100) DEFAULT '', group_id INTEGER DEFAULT 0, PRIMARY KEY (id, group_id) ) DEFAULT CHARSET=utf8"); # Sessions table $sql->query("CREATE TABLE IF NOT EXISTS __sessions ( id VARCHAR(40) DEFAULT '', data LONGTEXT, user_id INTEGER DEFAULT 0, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, PRIMARY KEY (id) ) DEFAULT CHARSET=utf8"); # This is to let the gettext scanner add these strings to the .pot file. # They are translated on display via Twig. # We don't want translated strings in the database. /* $translations = array(__("Change Settings"), __("Toggle Extensions"), __("View Site"), __("View Private Posts"), __("View Drafts"), __("View Own Drafts"), __("Add Posts"), __("Add Drafts"), __("Edit Posts"), __("Edit Drafts"), __("Edit Own Posts"), __("Edit Own Drafts"), __("Delete Posts"), __("Delete Drafts"), __("Delete Own Posts"), __("Delete Own Drafts"), __("Add Pages"), __("Edit Pages"), __("Delete Pages"), __("Add Users"), __("Edit Users"), __("Delete Users"), __("Add Groups"), __("Edit Groups"), __("Delete Groups")); */ $names = array("change_settings" => "Change Settings", "toggle_extensions" => "Toggle Extensions", "view_site" => "View Site", "view_private" => "View Private Posts", "view_draft" => "View Drafts", "view_own_draft" => "View Own Drafts", "add_post" => "Add Posts", "add_draft" => "Add Drafts", "edit_post" => "Edit Posts", "edit_draft" => "Edit Drafts", "edit_own_post" => "Edit Own Posts", "edit_own_draft" => "Edit Own Drafts", "delete_post" => "Delete Posts", "delete_draft" => "Delete Drafts", "delete_own_post" => "Delete Own Posts", "delete_own_draft" => "Delete Own Drafts", "add_page" => "Add Pages", "edit_page" => "Edit Pages", "delete_page" => "Delete Pages", "add_user" => "Add Users", "edit_user" => "Edit Users", "delete_user" => "Delete Users", "add_group" => "Add Groups", "edit_group" => "Edit Groups", "delete_group" => "Delete Groups"); foreach ($names as $id => $name) $sql->replace("permissions", array("id", "group_id"), array("id" => $id, "name" => $name, "group_id" => 0)); $groups = array("admin" => array_keys($names), "member" => array("view_site"), "friend" => array("view_site", "view_private"), "banned" => array(), "guest" => array("view_site")); # Insert the default groups (see above) $group_id = array(); foreach($groups as $name => $permissions) { $sql->replace("groups", "name", array("name" => ucfirst($name))); $group_id[$name] = $sql->latest("groups"); foreach ($permissions as $permission) $sql->replace("permissions", array("id", "group_id"), array("id" => $permission, "name" => $names[$permission], "group_id" => $group_id[$name])); } $config->set("default_group", $group_id["member"]); $config->set("guest_group", $group_id["guest"]); if (!$sql->select("users", "id", array("login" => $_POST['login']))->fetchColumn()) $sql->insert("users", array("login" => $_POST['login'], "password" => User::hashPassword($_POST['password_1']), "email" => $_POST['email'], "website" => $config->url, "group_id" => $group_id["admin"], "joined_at" => datetime())); $installed = true; } } function value_fallback($index, $fallback = "") { echo (isset($_POST[$index])) ? $_POST[$index] : $fallback ; } ?> Chyrp Installer
">

>

" id="host" />

>

" id="username" />

>

" id="password" />

" id="database" />

>

" id="prefix" />


" id="name" />


" id="login" />

" id="password_1" />

" id="password_2" />

" id="email" />

  1. Delete install.php, you won't need it anymore."); ?>
  2. /includes/caches to 777."); ?>