7 */ |
7 */ |
8 function duplicator_create_dbscript($destination) { |
8 function duplicator_create_dbscript($destination) { |
9 try { |
9 try { |
10 |
10 |
11 global $wpdb; |
11 global $wpdb; |
12 $dbiconv = ($GLOBALS['duplicator_opts']['dbiconv'] == "0" && function_exists("iconv")) ? false : true; |
12 //$dbiconv = ($GLOBALS['duplicator_opts']['dbiconv'] == "0" && function_exists("iconv")) ? false : true; |
|
13 |
13 $handle = fopen($destination,'w+'); |
14 $handle = fopen($destination,'w+'); |
14 $tables = $wpdb->get_col('SHOW TABLES'); |
15 $tables = $wpdb->get_col('SHOW TABLES'); |
15 |
16 |
16 duplicator_log("log:fun__create_dbscript=>started"); |
17 duplicator_log("log:fun__create_dbscript=>started"); |
17 if ($dbiconv) { |
18 //if ($dbiconv) { |
18 duplicator_log("log:fun__create_dbscript=>dbiconv enabled"); |
19 //duplicator_log("log:fun__create_dbscript=>dbiconv enabled"); |
19 } |
20 //} |
20 |
21 |
21 foreach ($tables as $table) { |
22 foreach ($tables as $table) { |
22 |
23 |
23 //Generate Drop Statement |
24 //Generate Drop Statement |
24 //$sql_del = ($GLOBALS['duplicator_opts']['dbadd_drop']) ? "DROP TABLE IF EXISTS {$table};\n\n" : ""; |
25 //$sql_del = ($GLOBALS['duplicator_opts']['dbadd_drop']) ? "DROP TABLE IF EXISTS {$table};\n\n" : ""; |
107 duplicator_log("log:fun__create_dbscript=>runtime error: " . $e); |
108 duplicator_log("log:fun__create_dbscript=>runtime error: " . $e); |
108 } |
109 } |
109 } |
110 } |
110 |
111 |
111 /** |
112 /** |
|
113 * DUPLICATOR_BUILD_INSTALLERFILE |
|
114 * Builds the Installer file from the contents of the files/installer directory |
|
115 */ |
|
116 function duplicator_build_installerFile() { |
|
117 |
|
118 duplicator_log("log:fun__build_installerFile=>start"); |
|
119 |
|
120 $template_path = duplicator_safe_path(DUPLICATOR_PLUGIN_PATH . 'files/installer.template.php'); |
|
121 $main_path = duplicator_safe_path(DUPLICATOR_PLUGIN_PATH . 'files/installer/main.installer.php'); |
|
122 @chmod($template_path, 0777); |
|
123 @chmod($main_path, 0777); |
|
124 |
|
125 $main_data = file_get_contents("{$main_path}"); |
|
126 $template_result = file_put_contents($template_path, $main_data); |
|
127 if ($main_data === false || $template_result == false) { |
|
128 duplicator_log("log:fun__build_installerFile=>install generation failed to copy {$main_path}"); |
|
129 } |
|
130 |
|
131 $embeded_files = array ( |
|
132 "inc.utils.php" => "@@INC.UTILS.PHP@@", |
|
133 "ajax.step1.php" => "@@AJAX.STEP1.PHP@@", |
|
134 "ajax.step2.php" => "@@AJAX.STEP2.PHP@@", |
|
135 "inc.style.css" => "@@INC.STYLE.CSS@@", |
|
136 "inc.scripts.js" => "@@INC.SCRIPTS.JS@@", |
|
137 "view.step1.php" => "@@VIEW.STEP1.PHP@@", |
|
138 "view.step2.php" => "@@VIEW.STEP2.PHP@@", |
|
139 "view.step3.php" => "@@VIEW.STEP3.PHP@@"); |
|
140 |
|
141 foreach ($embeded_files as $name=>$token) { |
|
142 $file_path = DUPLICATOR_PLUGIN_PATH . "files/installer/${name}"; |
|
143 @chmod($file_path, 0777); |
|
144 |
|
145 $search_data = @file_get_contents($template_path); |
|
146 $insert_data = @file_get_contents($file_path); |
|
147 file_put_contents($template_path, str_replace("${token}", "{$insert_data}", $search_data)); |
|
148 if ($search_data === false || $insert_data == false) { |
|
149 duplicator_log("log:fun__build_installerFile=>install generation failed at {$token}"); |
|
150 } |
|
151 @chmod($file_path, 0644); |
|
152 } |
|
153 |
|
154 @chmod($template_path, 0644); |
|
155 @chmod($main_path, 0644); |
|
156 |
|
157 duplicator_log("log:fun__build_installerFile=>end"); |
|
158 } |
|
159 |
|
160 |
|
161 /** |
112 * DUPLICATOR_CREATE_INSTALLERFILE |
162 * DUPLICATOR_CREATE_INSTALLERFILE |
113 * Prep the Installer file for use. use %string% token for replacing |
163 * Prep the Installer file for use. use %string% token for replacing |
114 * @param string $uniquename The unique name this installer file will be associated with |
164 * @param string $uniquename The unique name this installer file will be associated with |
115 */ |
165 */ |
116 function duplicator_create_installerFile($uniquename) { |
166 function duplicator_create_installerFile($uniquename) { |
124 |
174 |
125 $err_msg = "\n!!!WARNING!!! unable to read/write installer\nSee file:{$installerCore} \nPlease check permission and owner on file and parent folder."; |
175 $err_msg = "\n!!!WARNING!!! unable to read/write installer\nSee file:{$installerCore} \nPlease check permission and owner on file and parent folder."; |
126 |
176 |
127 get_option('duplicator_options') == "" ? "" : $duplicator_opts = unserialize(get_option('duplicator_options')); |
177 get_option('duplicator_options') == "" ? "" : $duplicator_opts = unserialize(get_option('duplicator_options')); |
128 $replace_items = Array( |
178 $replace_items = Array( |
129 "fwrite_current_url" => get_option('siteurl'), |
179 "fwrite_url_old" => get_option('siteurl'), |
130 "fwrite_package_name" => "{$uniquename}_package.zip", |
180 "fwrite_package_name" => "{$uniquename}_package.zip", |
131 "fwrite_secure_name" => "{$uniquename}", |
181 "fwrite_secure_name" => "{$uniquename}", |
132 "fwrite_nurl" => $duplicator_opts['nurl'], |
182 "fwrite_url_new" => $duplicator_opts['url_new'], |
133 "fwrite_dbhost" => $duplicator_opts['dbhost'], |
183 "fwrite_dbhost" => $duplicator_opts['dbhost'], |
134 "fwrite_dbname" => $duplicator_opts['dbname'], |
184 "fwrite_dbname" => $duplicator_opts['dbname'], |
135 "fwrite_dbuser" => $duplicator_opts['dbuser'], |
185 "fwrite_dbuser" => $duplicator_opts['dbuser'], |
136 "fwrite_wp_tableprefix" => $wpdb->prefix, |
186 "fwrite_wp_tableprefix" => $wpdb->prefix, |
137 "fwrite_site_title" => get_option('blogname'), |
187 "fwrite_blogname" => get_option('blogname'), |
|
188 "fwrite_wproot" => DUPLICATOR_WPROOTPATH, |
138 "fwrite_rescue_flag" => ""); |
189 "fwrite_rescue_flag" => ""); |
139 |
190 |
140 if( file_exists($template) && is_readable($template)) { |
191 if( file_exists($template) && is_readable($template)) { |
141 |
192 |
142 $install_str = duplicator_parse_template($template, $replace_items); |
193 $install_str = duplicator_parse_template($template, $replace_items); |
340 * DUPLICATOR_FCGI_FLUSH |
391 * DUPLICATOR_FCGI_FLUSH |
341 * PHP_SAPI for fcgi requires a data flush of at least 256 |
392 * PHP_SAPI for fcgi requires a data flush of at least 256 |
342 * bytes every 40 seconds or else it forces a script hault |
393 * bytes every 40 seconds or else it forces a script hault |
343 */ |
394 */ |
344 function duplicator_fcgi_flush() { |
395 function duplicator_fcgi_flush() { |
345 echo(str_repeat(' ',256)); |
396 echo(str_repeat(' ',264)); |
346 @flush(); |
397 @flush(); |
347 } |
398 } |
348 |
399 |
349 /** |
400 /** |
350 * DUPLICATOR_SNAPSHOT_URLPATH |
401 * DUPLICATOR_SNAPSHOT_URLPATH |