forked from boyvanamstel/Wordpress-Project-Creator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.php
156 lines (125 loc) · 4.98 KB
/
setup.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Wordpress Project Creator - Setup</title>
<link rel="stylesheet" href="wpprojectcreator/css/reset.css" type="text/css" />
<link rel="stylesheet" href="wpprojectcreator/css/clearfix.css" type="text/css" />
<link rel="stylesheet" href="wpprojectcreator/css/style.css" type="text/css" />
<link rel="stylesheet" href="wpprojectcreator/css/enhanced.css" type="text/css" />
<script src="wpprojectcreator/js/jquery.js" type="text/javascript"></script>
<script src="wpprojectcreator/js/modernizr.js" type="text/javascript"></script>
<script src="wpprojectcreator/js/config.js" type="text/javascript"></script>
<script src="wpprojectcreator/js/scripts.js" type="text/javascript"></script>
</head>
<body id="index" class="home">
<div id="wrapper">
<?php
/**
* Wordpress config file creator and database importer
*
* @author Boy van Amstel
* @copyright 2010 All rights reserved
*/
require_once('wpprojectcreator/WPProjectCreator.php');
// Check if the base file exists, if not mention it
if(!file_exists('wordpress/wp-config-sample.php')) {
?>
<h1>Error - wp-config-sample.php unavailable</h1>
<p class="error">It seems wp-config-sample.php doesn't exist. Did you run 'wpprojectcreator.py'? <a href="setup.php">retry</a></p>
<?php
} else {
?>
<h1>Wordpress Project Creator - Setup</h1>
<?php
// Set settings
$settings = array();
$settings['wp_url'] = isset($_POST['wp_url']) ? $_POST['wp_url'] : WPProjectCreator::getCurrentPageURL(true).'/wordpress';
$settings['db_name'] = isset($_POST['db_name']) ? $_POST['db_name'] : '';
$settings['db_dump'] = isset($_POST['db_dump']) ? $_POST['db_dump'] : 'wordpress/wp-content/dump.sql';
$settings['db_host'] = isset($_POST['db_host']) ? $_POST['db_host'] : 'localhost';
$settings['db_username'] = isset($_POST['db_username']) ? $_POST['db_username'] : 'root';
$settings['db_password'] = isset($_POST['db_password']) ? $_POST['db_password'] : 'root';
// If not submitting overwrite settings with existing settings
if(!isset($_POST['setup_submit'])) {
$existingSettings = file_exists('wordpress/wp-config.php') ? WPProjectCreator::readWPConfig() : array();
$settings = array_merge($settings, $existingSettings);
}
if(isset($_POST['setup_submit'])) {
// Check if data is set
if(isset($_POST['wp_url']) &&
isset($_POST['db_name']) &&
isset($_POST['db_dump']) &&
isset($_POST['db_host']) &&
isset($_POST['db_username']) &&
isset($_POST['db_password'])) {
// Run setup
$wpProjectCreator = new WPProjectCreator($settings);
?><ul class="log"><?php
?><li>Starting setup..</li><?php
// Connect to database
if($wpProjectCreator->createDBConnection()) {
?><li>Connected to database</li><?php
// Create empty database
if($wpProjectCreator->createEmptyDatabase()) {
?><li>Created new database, or removed old tables</li><?php
// Import .sql file
if($wpProjectCreator->importDatabase()) {
?><li>Database imported</li><?php
// Generate wp-config.php file
if($wpProjectCreator->createWPConfig()) {
?><li>Config file created</li><?php
// Generate .htaccess file
if($wpProjectCreator->createHTAccess()) {
?><li>.htaccess file created, proceed to <a href="<?php echo $settings['wp_url']; ?>">website</a></li><?php
}
}
}
}
}
// Display errors
if(count($wpProjectCreator->getErrors()) > 0) {
foreach($wpProjectCreator->getErrors() as $error) {
printf('<li class="error">%s</li>', $error);
}
}
?></ul><?php
} else {
// Display error
?>
<p class="error">Fill out the entire form.</p>
<?php
}
}
?>
<form action="setup.php" method="POST">
<fieldset>
<legend>Wordpress</legend>
<dl class="clearfix">
<dt><label for="wp_url">URL:</label></dt>
<dd><input type="text" id="wp_url" name="wp_url" value="<?php echo $settings['wp_url']; ?>" /></dd>
</fieldset>
<fieldset>
<legend>Database</legend>
<dl class="clearfix">
<dt><label for="db_name">Name:</label></dt>
<dd><input type="text" id="db_name" name="db_name" value="<?php echo $settings['db_name']; ?>" /></dd>
<dt><label for="db_host">Host:</label></dt>
<dd><input type="text" id="db_host" name="db_host" value="<?php echo $settings['db_host']; ?>" /></dd>
<dt><label for="db_username">Username:</label></dt>
<dd><input type="text" id="db_username" name="db_username" value="<?php echo $settings['db_username']; ?>" /></dd>
<dt><label for="db_password">Password:</label></dt>
<dd><input type="text" id="db_password" value="<?php echo $settings['db_password']; ?>" name="db_password" /></dd>
<dt><label for="db_dump">Dump:</label></dt>
<dd><input type="text" id="db_dump" name="db_dump" value="<?php echo $settings['db_dump']; ?>" /></dd>
</fieldset>
<fieldset class="clearfix">
<input type="submit" name="setup_submit" value="Setup" />
</fieldset>
</form>
<?php
}
?>
</div>
</body>
</html>