aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/setup
diff options
context:
space:
mode:
Diffstat (limited to 'ratatoeskr/setup')
-rw-r--r--ratatoeskr/setup/create_tables.php86
-rw-r--r--ratatoeskr/setup/setup.php245
2 files changed, 296 insertions, 35 deletions
diff --git a/ratatoeskr/setup/create_tables.php b/ratatoeskr/setup/create_tables.php
index 0f2f6b5..1c9e67b 100644
--- a/ratatoeskr/setup/create_tables.php
+++ b/ratatoeskr/setup/create_tables.php
@@ -1,10 +1,12 @@
<?php
+if(!defined("SETUP"))
+ die();
-$sql = <<<SQL
-SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
+require_once(dirname(__FILE__) . "/../sys/db.php");
-CREATE TABLE `PREFIX_articles` (
+$sql_tables = <<<SQL
+CREATE TABLE IF NOT EXISTS `PREFIX_articles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`urlname` text COLLATE utf8_unicode_ci NOT NULL,
`title` int(11) NOT NULL,
@@ -20,12 +22,12 @@ CREATE TABLE `PREFIX_articles` (
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_article_tag_relations` (
+CREATE TABLE IF NOT EXISTS `PREFIX_article_tag_relations` (
`tag` int(11) NOT NULL,
`article` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_comments` (
+CREATE TABLE IF NOT EXISTS `PREFIX_comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`article` int(11) NOT NULL,
`language` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
@@ -36,32 +38,32 @@ CREATE TABLE `PREFIX_comments` (
`visible` tinyint(4) NOT NULL,
`read_by_admin` tinyint(4) NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_groups` (
+CREATE TABLE IF NOT EXISTS `PREFIX_groups` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_group_members` (
+CREATE TABLE IF NOT EXISTS `PREFIX_group_members` (
`user` int(11) NOT NULL,
`group` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_images` (
+CREATE TABLE IF NOT EXISTS `PREFIX_images` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_unicode_ci NOT NULL,
`file` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_multilingual` (
+CREATE TABLE IF NOT EXISTS `PREFIX_multilingual` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_plugins` (
+CREATE TABLE IF NOT EXISTS `PREFIX_plugins` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_unicode_ci NOT NULL,
`author` text COLLATE utf8_unicode_ci NOT NULL,
@@ -81,52 +83,63 @@ CREATE TABLE `PREFIX_plugins` (
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_plugin_kvstorage` (
+CREATE TABLE IF NOT EXISTS `PREFIX_plugin_kvstorage` (
`plugin` int(11) NOT NULL,
`key` text COLLATE utf8_unicode_ci NOT NULL,
`value` text COLLATE utf8_unicode_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_sections` (
+CREATE TABLE IF NOT EXISTS `PREFIX_repositories` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `baseurl` text COLLATE utf8_unicode_ci NOT NULL,
+ `name` text COLLATE utf8_unicode_ci NOT NULL,
+ `description` text COLLATE utf8_unicode_ci NOT NULL,
+ `pkgcache` text COLLATE utf8_unicode_ci NOT NULL,
+ `lastrefresh` bigint(20) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+CREATE TABLE IF NOT EXISTS `PREFIX_sections` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_unicode_ci NOT NULL,
`title` int(11) NOT NULL,
`template` text COLLATE utf8_unicode_ci NOT NULL,
+ `styles` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_settings_kvstorage` (
+CREATE TABLE IF NOT EXISTS `PREFIX_section_style_relations` (
+ `section` int(11) NOT NULL,
+ `style` int(11) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+CREATE TABLE IF NOT EXISTS `PREFIX_settings_kvstorage` (
`key` text COLLATE utf8_unicode_ci NOT NULL,
`value` text COLLATE utf8_unicode_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_styles` (
+CREATE TABLE IF NOT EXISTS `PREFIX_styles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_unicode_ci NOT NULL,
`code` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-
-CREATE TABLE `PREFIX_section_style_relations` (
- `section` int(11) NOT NULL,
- `style` int(11) NOT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_tags` (
+CREATE TABLE IF NOT EXISTS `PREFIX_tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_unicode_ci NOT NULL,
`title` int(11) NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_translations` (
+CREATE TABLE IF NOT EXISTS `PREFIX_translations` (
`multilingual` int(11) NOT NULL,
`language` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`text` text COLLATE utf8_unicode_ci NOT NULL,
`texttype` text COLLATE utf8_unicode_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-CREATE TABLE `PREFIX_users` (
+CREATE TABLE IF NOT EXISTS `PREFIX_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` text COLLATE utf8_unicode_ci NOT NULL,
`pwhash` text COLLATE utf8_unicode_ci NOT NULL,
@@ -135,15 +148,18 @@ CREATE TABLE `PREFIX_users` (
`language` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-
-CREATE TABLE `s_db_47`.`PREFIX_repositories` (
-`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
-`baseurl` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
-`name` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
-`description` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
-`pkgcache` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
-`lastrefresh` BIGINT NOT NULL
-) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;
SQL;
+function create_mysql_tables()
+{
+ global $sql_tables;
+
+ $queries = explode(";", $sql_tables);
+ foreach($queries as $q)
+ {
+ if(!empty($q))
+ qdb($q);
+ }
+}
+
?>
diff --git a/ratatoeskr/setup/setup.php b/ratatoeskr/setup/setup.php
new file mode 100644
index 0000000..0eb6d83
--- /dev/null
+++ b/ratatoeskr/setup/setup.php
@@ -0,0 +1,245 @@
+<?php
+
+define("SETUP", True);
+
+require_once(dirname(__FILE__) . "/../sys/init_ste.php");
+require_once(dirname(__FILE__) . "/../sys/translation.php");
+require_once(dirname(__FILE__) . "/../sys/db.php");
+require_once(dirname(__FILE__) . "/../sys/pwhash.php");
+require_once(dirname(__FILE__) . "/../languages.php");
+require_once(dirname(__FILE__) . "/create_tables.php");
+
+$rel_path_to_root = ".";
+$ste->vars["rel_path_to_root"] = $rel_path_to_root;
+
+$ste->vars["translations"] = array();
+foreach($languages as $langcode => $langinfo)
+{
+ if($langinfo["translation_exist"])
+ $ste->vars["translations"][$langcode] = $langinfo["language"];
+}
+
+if(isset($_GET["lang"]) and (@$languages[$_GET["lang"]]["translation_exist"]))
+{
+ load_language($_GET["lang"]);
+ $lang = $_GET["lang"];
+ $ste->vars["lang"] = $_GET["lang"];
+}
+else
+ die($ste->exectemplate("/systemtemplates/setup_select_lang.html"));
+
+if(isset($_POST["apply_setup"]))
+{
+ if(empty($_POST["admin_username"]) or empty($_POST["admin_init_password"]))
+ $ste->vars["error"] = $translation["admin_data_must_be_filled_out"];
+ else
+ {
+ $config["mysql"]["server"] = $_POST["mysql_host"];
+ $config["mysql"]["db"] = $_POST["mysql_database"];
+ $config["mysql"]["user"] = $_POST["mysql_user"];
+ $config["mysql"]["passwd"] = $_POST["mysql_password"];
+ $config["mysql"]["prefix"] = $_POST["table_prefix"];
+
+ try
+ {
+ db_connect();
+ create_mysql_tables();
+
+ /* Writing some demo data to database */
+ require_once(dirname(__FILE__) . "/../sys/models.php");
+
+ $ratatoeskr_settings["default_language"] = $lang;
+ $ratatoeskr_settings["comment_visible_defaut"] = True;
+ $ratatoeskr_settings["allow_comments_default"] = True;
+ $ratatoeskr_settings["comment_textprocessor"] = "Markdown";
+ $ratatoeskr_settings["languages"] = $lang == "en" ? array("en") : array($lang, "en");
+ $ratatoeskr_settings["last_db_cleanup"] = time();
+
+ $style = Style::create("default");
+ $style->code = <<<STYLE
+* {
+ font-family: sans-serif;
+ font-size: 10pt;
+}
+
+html {
+ margin: 0px;
+ padding: 0px;
+}
+
+body {
+ margin: 0px;
+ padding: 0px;
+}
+
+#maincontainer {
+ width: 80%;
+ margin: 0px auto 0px;
+ padding: 0px;
+}
+
+#heading {
+ text-align: center;
+ border-bottom: 1px solid black;
+ margin: 0px auto 0px;
+ padding: 10mm 3mm 5mm
+}
+
+h1 {
+ font-size: 24pt;
+ font-weight: bold;
+ padding: 0px;
+ margin: 0px auto 2mm;
+}
+
+h2 {
+ font-size: 14pt;
+ font-weight: bold;
+}
+
+h3 {
+ font-size: 14pt;
+ font-weight: normal;
+}
+
+h4 {
+ font-size: 12pt;
+ font-weight: bold;
+}
+
+h5 {
+ font-size: 12pt;
+ font-weight: normal
+}
+
+h6 {
+ font-size: 10pt;
+ font-weight: bold;
+ text-decoration: underline;
+}
+
+#mainmenu {
+ border-bottom: 1px solid black;
+ list-style: none;
+ height: 10mm;
+ padding: 0px;
+ margin: 0px 0px 2mm;
+}
+
+#mainmenu li {
+ float: left;
+ margin: 0px 0px 2mm;
+ height: 10mm;
+ overflow: hidden;
+}
+
+#mainmenu li a {
+ color: #444;
+ text-decoration: none;
+ font-size: 12pt;
+ margin: 0px;
+ padding: 2mm 7.5mm 0px;
+ background: white;
+ display: block;
+ height: 10mm;
+}
+
+#mainmenu li.active a {
+ color: black;
+ font-weight: bold;
+}
+
+#mainmenu li a:hover {
+ background: #eee;
+ color: #000;
+}
+
+#metabar {
+ float: right;
+ width: 50mm;
+ margin: 0px;
+ padding: 0px 0px 0px 5mm;
+ border-left: 1px solid black;
+}
+
+div.metabar_module {
+ border-top: 1px solid black;
+ padding: 2mm 0px 0px;
+ margin: 2mm 0px 0px;
+}
+
+div.metabar_module:first-child {
+ border-top: none;
+ margin: 0px;
+ padding: 0px;
+}
+
+div.metabar_module h2 {
+ font-size: 10pt;
+ font-weight: bold;
+ padding: 0px;
+ margin: 0px 0px 2mm;
+}
+
+#content {
+ border-right: 1px solid black;
+ margin: 0px 55mm 0px 0px;
+ padding: 0px 2mm 0px 0px;
+}
+
+#footer {
+ clear: both;
+ margin: 4mm 0mm 4mm;
+ padding: 2mm 0mm 0mm;
+ text-align: center;
+ border-top: 1px solid black;
+}
+
+table.listtab {
+ border-collapse: collapse;
+}
+STYLE;
+ $style->save();
+
+ $section = Section::create("home");
+ $section->title["en"] = new Translation("Home", "");
+ if($lang != "en")
+ $section->title[$lang] = new Translation("Home", "");
+ $section->template = "standard.html";
+ $section->add_style($style);
+ $section->save();
+
+ $ratatoeskr_settings["default_section"] = $section->get_id();
+
+ $ratatoeskr_settings->save();
+
+ $admingrp = Group::create("admins");
+ $admin = user::create($_POST["admin_username"], PasswordHash::create($_POST["admin_init_password"]));
+ $admin->save();
+ $admingrp->include_user($admin);
+
+ $article = Article::create("congratulations");
+ $article->title["en"] = new Translation("Congratulations! You have just installed Ratatöskr!", "");
+ $article->text["en"] = new Translation("Congratulations! You have just installed Ratatöskr!", "Markdown");
+ $article->excerpt["en"] = new Translation("Congratulations! You have just installed Ratatöskr!", "Markdown");
+ $article->status = ARTICLE_STATUS_LIVE;
+ $article->timestamp = time();
+ $article->allow_comments = True;
+ $article->set_section($section);
+ $article->save();
+
+ /* Almost done. Give the user the config file. */
+ $config = "<?php\n\ndefine(\"__DEBUG__\", False);\ndefine(\"CONFIG_FILLED_OUT\", True);\ndefine(\"PLUGINS_ENABLED\", True);\n\n\$config[\"mysql\"][\"server\"] = '" . addcslashes($config["mysql"]["server"], "'") . "';\n\$config[\"mysql\"][\"db\"] = '" . addcslashes($config["mysql"]["db"], "'") . "';\n\$config[\"mysql\"][\"user\"] = '" . addcslashes($config["mysql"]["user"], "'") . "';\n\$config[\"mysql\"][\"passwd\"] = '" . addcslashes($config["mysql"]["passwd"], "'") . "';\n\$config[\"mysql\"][\"prefix\"] = '" . addcslashes($config["mysql"]["prefix"], "'") . "';\n\n?>";
+ $ste->vars["config"] = $config;
+ die($ste->exectemplate("/systemtemplates/setup_done.html"));
+ }
+ catch(MySQLException $e)
+ {
+ $ste->vars["error"] = $e->getMessage();
+ }
+ }
+}
+
+echo $ste->exectemplate("/systemtemplates/setup_dbsetup.html");
+
+?>