This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_install.dist
260 lines (237 loc) · 7.84 KB
/
_install.dist
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
257
258
259
260
<html>
<head>
<title>Crayon CMS</title>
</head>
<body>
<pre>
<span style="color:slategray">
____ ____ __ __ ____
/ ___|_ __ __ _ _ _ ___ _ __ / ___| \/ / ___|
| | | '__/ _` | | | |/ _ \| '_ \ | | | |\/| \___ \
| |___| | | (_| | |_| | (_) | | | | | |___| | | |___) |
\____|_| \__,_|\__, |\___/|_| |_| \____|_| |_|____/
|___/
</span>
<span style="color:lightslategray">________________________________________________________</span><br>
<?php
// Create directories
function makeDir($dir_arr){
foreach($dir_arr as $dir=>$mod){
if(!is_dir($dir)){
if(mkdir($dir)){
chmod($dir, ($mod===0)?0755:0777);
echo "<span style='color:green'>Directory <strong>".$dir."</strong> created<br></span>";
} else {
echo "<span style='color:crimson'>Directory <strong>".$dir."</strong> not created<br></span>";
}
}
}
}
// Create json file
function createFile($file,$content){
if(!file_exists($file)){
$fp = fopen($file, 'w');
if(fwrite($fp, $content)){
fclose($fp);
echo "<span style='color:green'>File <strong>".$file."</strong> created</span><br>";
} else {
echo "<span style='color:crimson'>File <strong>".$file."</strong> created</span><br>";
}
} else
echo "<span style='color:slategray'>File <strong>".$file."</strong> exists</span><br>";
}
$directories = array(
// 0 - read only, 1 - writable
'cache'=>1,
'data'=>1,
'data/blog'=>1,
'data/gallery'=>1,
'data/pages'=>1,
'data/tmp'=>1,
'data/tmp/blog'=>1,
'data/tmp/gallery'=>1,
'data/tmp/pages'=>1,
'images'=>0,
'images/pages'=>0,
'views/blog/articles'=>1,
'views/pages'=>1,
'views/tmp'=>1,
'views/tmp/pages'=>1,
'views/tmp/blog'=>1,
'views/tmp/gallery'=>1,
'views/tmp/blog/articles'=>1
);
makeDir($directories);
// Main config
$main_dir = str_replace('/_install.php','',$_SERVER["REQUEST_URI"]);
$config = array(
'site_name'=>'Crayon CMS',
'dev_mode'=>true,
'twig_cache'=>'cache',
'site_color'=>'#ffffff',
'main_dir'=>$main_dir,
'salt'=>uniqid(mt_rand(), true),
'admin_email'=>'admin@admin.com',
'mail_is_smtp'=>true,
'mail_host'=>"",
'mail_smtp_auth'=>false,
'mail_username'=>"admin",
'mail_password'=>"admin",
'mail_smtp_secure'=>"",
'mail_port'=>""
);
createFile('data/config.json', json_encode($config));
// Files manager config
$files_config = array(
'images_sizes'=>array(
'800x600px'=>array(800,600)
)
);
createFile('data/files.config.json', json_encode($files_config));
// Languages config
$languages_config = array(
"en"=>array("English","home")
);
createFile('data/languages.json', json_encode($languages_config));
// Menus config
$menus_config = array(
"main"=>array(
"items"=>array(
"home"=>array(
"order"=>1
)
),
"lang"=>"en"
)
);
createFile('data/menus.json', json_encode($menus_config));
// Routing
$routing_config = array(
"home"=>array(
"type"=>"GET",
"path"=>"/",
"controller"=>"SiteController",
"function"=>"page",
"variables"=>"home",
"name"=>"Home page",
"enabled"=>"true",
"blind"=>"false"
)
);
createFile('data/routing.json', json_encode($routing_config));
// Translations
$translations = array(
"contact"=>array("en"=>"Contact"),
"email"=>array("en"=>"Email"),
"message"=>array("en"=>"Message"),
"error"=>array("en"=>"Error"),
"sending"=>array("en"=>"Sending"),
"read_article"=>array("en"=>"Read article"),
"email_not_blank"=>array("en"=>"Email can't be empty."),
"email_not_valid"=>array("en"=>"Email doesn't look like a valid email."),
"message_not_blank"=>array("en"=>"Message can't be empty."),
"message_too_short"=>array("en"=>"Message is too short"),
"message_sent"=>array("en"=>"Your message has been sent"),
);
createFile('data/translations.json', json_encode($translations));
// Users
$users = array(
"admin"=>array(
"role"=>"admin",
"pwd"=>crypt('admin',$config['salt'])
)
);
createFile('data/users.json', json_encode($users));
// Homepage
$homepage = array(
"title"=>"Homepage",
"description"=>"Homepage",
"menu"=>"main"
);
createFile('data/pages/home.json', json_encode($homepage));
// Homepage content
$content = "{% extends template %}
{% block content %}
<h1>Homepage</h1>
{% endblock %}{# end content #}
{% block scripts %}
{% endblock %}{# end scripts #}";
createFile('views/pages/home.html.twig', $content);
// Blog articles
$articles = array(
"0"=>array(
"id"=>0,
"title"=>"First article",
"slug"=>"first-article",
"title_color"=>"#ffffff",
"category_id"=>"0",
"intro"=>"Intro",
"intro_image"=>"",
"main_image"=>"",
"publication_date"=>date('Y-m-d H:i', time())
)
);
createFile('data/blog/articles.json', json_encode($articles));
// Blog articles content
$content = "{% extends 'blog/article.content.html.twig' %}
{% block content %}Article{% endblock %}{# end content #}
{% block afterContent %}{% endblock %}{# end afterContent #}";
createFile('views/blog/articles/0.html.twig', $content);
// Blog categories
$categories = array(
"0"=>array(
"id"=>0,
"name"=>"First category",
"menu"=>"main",
)
);
createFile('data/blog/categories.json', json_encode($categories));
// Blog config
$blog_config = array(
"articles_per_page"=>5,
"author_name"=>"Author",
"author_desc"=>"",
"author_photo"=>"",
);
createFile('data/blog/config.json', json_encode($blog_config));
// Gallery categories
$gallery_categories = array(
"1"=>array(
"id"=>1,
"name"=>"First category",
"menu"=>"main",
)
);
createFile('data/gallery/categories.json', json_encode($gallery_categories));
// Gallery config
$gallery_config = array(
"items_per_page"=>5
);
createFile('data/gallery/config.json', json_encode($gallery_config));
// Remove _install.php
if(rename('_install.php','_install.dist')):?>
<span style="color:slategray">
┌ <b>SUCCESS!</b> ────────────────────────────────────────────╖
│ <span style='color:yellowgreen'>File <strong>_install.php</strong> renamed</span> ║
╘══════════════════════════════════════════════════════╝</span>
<span style="color:slategray">
┌ <b>IMPORTANT!</b> ──────────────────────────────────────────╖
│ <span style="color:crimson">Change admin password!</span> ║
╘══════════════════════════════════════════════════════╝</span>
<span style="color:slategray">
┌ <b>REMEMBER!</b> ───────────────────────────────────────────╖
│ All data are stored in twig and json files excluded ║
│ from the GIT repository. ║
│ <span style="color:crimson">Make sure you back up your data!</span> ║
╘══════════════════════════════════════════════════════╝</span>
<span style="color:slategray"><a href="<?php echo ($main_dir !== '') ? $main_dir : '/' ?>"><span style="color:dodgerblue">Homepage</span></a></span>
<span style="color:slategray"><a href="<?php echo ($main_dir !== '') ? $main_dir.'/_bo' : '/_bo' ?>"><span style="color:dodgerblue">Back office</span></a> (login: admin, password: admin);</span>
<?php else: ?>
<span style='color:crimson'>File <strong>_install.php</strong> not deleted</span><br>
<span style='color:slategray'>Script does not have proper permissions</span><br>
<span style='color:slategray'>You can try changing settings</span><br>
<span style='color:slategray'>Eg. chown -R www-data:www-data /folder_with_page</span><br>
<?php endif; ?>
</pre>
</body>
</html>