forked from CosmoCMS/Cosmo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
204 lines (176 loc) · 10.4 KB
/
install.php
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
<?php
/**
* Install Cosmo CMS. Delete this page after installing
*/
// User submitted the form. Proceed with installation
if($_GET)
{
// Catch variables from form
ini_set('display_errors', true);
error_reporting(E_ALL);
// Catch variables from form
$folder = isset($_GET['folder']) ? $_GET['folder'] : '';
$prefix = isset($_GET['prefix']) ? $_GET['prefix'] : '';
$host = isset($_GET['host']) ? $_GET['host'] : '';
$name = isset($_GET['name']) ? $_GET['name'] : '';
$username = isset($_GET['username']) ? $_GET['username'] : '';
$password = isset($_GET['password']) ? $_GET['password'] : '';
$title = isset($_GET['title']) ? $_GET['title'] : '';
$email = isset($_GET['email']) ? $_GET['email'] : '';
$language = isset($_GET['language']) ? $_GET['language'] : '';
$adminUsername = isset($_GET['adminUsername']) ? $_GET['adminUsername'] : '';
$adminPassword = isset($_GET['adminPassword']) ? $_GET['adminPassword'] : '';
// Generate 128 character salt
$salt = "";
for ($i=0; $i<128; $i++)
{
$random_char = chr(round( mt_rand(33, 125)));
if($random_char !== "'")
$salt .= $random_char;
}
// Write settings to config file
$fp = fopen('core/app/autoload.php', 'w');
fwrite($fp, '<?php
$host = \''. $host .'\';
$dbName = \''. $name .'\'; # Database name
$username = \''. $username .'\';
$password = \''. $password .'\';
$prefix = \''. $prefix .'\'; // e.g. cosmo_
define(\'FOLDER\', \''. $folder .'\'); // e.g. subfolder/
$salt = \''. $salt .'\';
$developerMode = false; // Switching this to true prevents minification/combination of JS/CSS files for better error reporting
$pdo = new PDO("mysql:host=$host;dbname=$dbName;charset=utf8", $username, $password);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$username = null;
?>');
fclose($fp);
// Install database
include 'core/app/autoload.php';
include 'core/app/Cosmo.class.php';
$Cosmo = new Cosmo($pdo, $prefix, $salt);
$sqlFile = file_get_contents('install.sql');
$statements = explode(';', $sqlFile);
// Execute MySQL statements, replacing the prefix
foreach ($statements as $statement) {
if(trim($statement) != '') {
$stmt = $pdo->prepare(str_replace('**prefix**', $prefix, $statement));
$stmt->execute();
}
}
// Setup site info
$stmt = $pdo->prepare('INSERT INTO '.$prefix.'settings (site_name, email, theme, language) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE site_name=VALUES(site_name)');
$data = array($title, $email, 'Pendant', $language);
$stmt->execute($data);
// Create home page
$stmt = $pdo->prepare('INSERT INTO '.$prefix.'content (url, type, published) VALUES (?,?,?) ON DUPLICATE KEY UPDATE url=VALUES(url)');
$data = array('/', 'home.html', 'Y');
$stmt->execute($data);
// Create new page
$stmt = $pdo->prepare('INSERT INTO '.$prefix.'content (url, author, published) VALUES (?,?,?) ON DUPLICATE KEY UPDATE url=VALUES(url)');
$data = array('/new', 1, 'Y');
$stmt->execute($data);
// Create error page
$stmt = $pdo->prepare('INSERT INTO '.$prefix.'content (url, type, author, published) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE url=VALUES(url)');
$data = array('/error', 'home.html', 1, 'Y');
$stmt->execute($data);
// Create maintenance page
$stmt = $pdo->prepare('INSERT INTO '.$prefix.'content (url, type, author, published) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE url=VALUES(url)');
$data = array('/maintenance', 'home.html', 1, 'Y');
$stmt->execute($data);
// Insert records
try {
// Create admin username/password
$Cosmo->usersCreate($adminUsername, $email, $adminPassword, 'admin');
// Create first post
$Cosmo->contentCreate('Welcome to Cosmo', 'Welcome to Pendant, a blog theme developed for Cosmo.', 'Welcome to Cosmo', 'Your new website awaits', 'uploads/MIbCzcvxQdahamZSNQ26_12082014-IMG_3526-54571eebdae22.jpg', '<p class="ng-scope">Your site is now running on Cosmo, an open source content management system that\'s designed to help make editing your website quick and easy, it\'s created by James and<a href="http://twitter.com/jordandunn"> Jordan Dunn</a>. If this is your first time using Cosmo we recommend <a href="http://cosmocms.org/cosmo-basics">checking out our how-to\'s</a> for creating pages, editing content, uploading media and more. Once you\'re ready to make your first page, click the umbrella to your left, go to content > new page and you\'ll be on your way.</p><p class="ng-scope"><span class="ng-scope">If you\'re looking to create a new theme for Cosmo you can view all documentation for <a href="http://cosmocms.org/how-to-create-a-theme-for-cosmo">theme creation</a> along with how to use or <a href="http://cosmocms.org/how-to-create-a-module-for-cosmo">create new modules</a> to run within Cosmo.</span></p><p class="ng-scope">If you\'re looking for some free photos to work well with your new site, we recommend checking out <a href="http://deathtothestockphoto.com">Death to Stock Photo</a> or <a href="https://unsplash.com">Unsplash</a>.</p><p class="ng-scope">Once your website is up and running, <a href="http://twitter.com/cosmocms">send us a link</a> so we can check it out and maybe even highlight it on our website or social media.</p>', '/welcome-to-cosmo', 1, 'post.html', 'Y', NULL);
$Cosmo->contentExtrasCreate(4, 'featured', '{"id":"featured","alt":"Welcome","src":"uploads/MIbCzcvxQdahamZSNQ26_12082014-IMG_3526-54571eebdae22.jpg","size":"responsive","responsive":"yes"}');
$Cosmo->contentTagsCreate(4, 'blog');
// Insert first file
$stmt = $pdo->prepare('INSERT INTO '.$prefix.'files (filename, responsive, type, timestamp) VALUES (?,?,?,?)');
$data = array('uploads/MIbCzcvxQdahamZSNQ26_12082014-IMG_3526-54571eebdae22.jpg', 'yes', 'image', time());
$stmt->execute($data);
// Insert first block
$Cosmo->blocksCreate('Home Page');
$Cosmo->blocksUpdate('Home Page', '<div one-post="blog"></div>', 0, 'block1', 1);
$Cosmo->blocksRequirementsCreate(1, 'visible', '/');
// Insert footer block
$Cosmo->blocksCreate('Copyright');
$Cosmo->blocksUpdate('Copyright', '<p>Copyright © {{page.current_year}} | Built with <a href="http://www.cosmocms.org/"><img class="cosmo-logo" alt="Single Page Application CMS" src="core/img/cosmo-logo.svg"></a></p>', 0, 'footer', 2);
// Insert example primary menu
$Cosmo->menusCreate('Primary');
$Cosmo->menusUpdate(1, 'Primary', '[{"id":1,"title":"About","url":"about","items":[]},{"id":100,"title":"Contact","url":"contact","items":[]}]', 'primary');
} catch (Exception $e){
}
}
// User hasn't submitted the form yet
if(!$_GET):
?>
<html ng-app="app">
<head>
<title translate>install_cosmo</title>
<link rel="stylesheet" type="text/css" href="core/css/cosmo-default-style.minify.css">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
<script src="core/js/angular/angular.min.js"></script>
<script src="core/js/3rd-party/angular-translate.min.js"></script>
<!--<script src="core/js/3rd-party/angular-translate-storage-cookie.min.js"></script>-->
<script src="core/js/3rd-party/angular-translate-loader-static-files.min.js"></script>
<script>
angular.module('app', ['pascalprecht.translate'])
.config(function($translateProvider) {
// Load files from the core/languages folder
$translateProvider.useStaticFilesLoader({
prefix: 'core/languages/',
suffix: '.json'
});
})
.controller('installationCtrl', function($scope, $http, $sce, $translate){
$scope.install = {};
$scope.install.dbname = '';
$scope.install.prefix = '';
$scope.install.folder = '';
$scope.install.host = 'localhost';
$scope.install.username = '';
$scope.install.password = '';
$scope.install.title = '';
$scope.install.email = '';
$scope.install.adminUsername = '';
$scope.install.adminPassword = '';
$scope.install.language = 'en';
$translate.use('en');
$scope.uploadsPermissions = '<?php echo fopen('uploads/placeholder.txt', 'w'); ?>';
$scope.autoloadPermissions = '<?php echo fopen('core/app/autoload.php', 'w'); ?>';
$scope.htaccess = '<?php echo file_exists('.htaccess');?>';
$scope.changeLanguage = function(key){
$scope.install.language = key;
$translate.use(key);
};
$scope.submit = function(){
if($scope.install.adminPassword === $scope.install.adminPassword2){
$http.get('install.php?name='+ $scope.install.dbname +
'&host='+ $scope.install.host +
'&username='+ $scope.install.username +
'&password='+ $scope.install.password +
'&prefix='+ $scope.install.prefix +
'&folder='+ $scope.install.folder +
'&title='+ $scope.install.title +
'&language='+ $scope.install.language +
'&adminUsername='+ $scope.install.adminUsername +
'&adminPassword='+ $scope.install.adminPassword +
'&email='+ $scope.install.email)
.success(function(data){
if(data.length===0)
$scope.success = true;
else
$scope.error = $sce.trustAsHtml(data);
});
} else
alert("Passwords don't match");
};
});
</script>
</head>
<body>
<div ng-include="'core/html/install.html'"></div>
</body>
</html><?php endif; ?>