aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/setup/setup.php
blob: 32727e6ab219b13207618e9c7d0a307a0b5db258 (plain)
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?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();
			$ratatoeskr_settings["debugmode"] = False;
		
			$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();
			
			try
			{
				Repository::create("http://r7r-repo-community.kch42.net/");
				Repository::create("http://r7r-repo-official.kch42.net/");
			}
			catch(RepositoryUnreachableOrInvalid $e)
			{
				$ste->vars["notice"] = $translation["could_not_initialize_repos"];
			}
		
			/* 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");

?>