· 8 years ago · Mar 14, 2018, 02:18 PM
1<!doctype html>
2<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
3<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
4<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
5<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
6<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
7 <head>
8 <meta charset="utf-8">
9 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
10 <title>BigTree 3 to 4 Converter</title>
11 <link rel="stylesheet" href="<?=WWW_ROOT?>admin/css/main.css" type="text/css" media="all" />
12 <script type="text/javascript" src="<?=WWW_ROOT?>admin/js/lib.js"></script>
13 <script type="text/javascript" src="<?=WWW_ROOT?>admin/js/main.js"></script>
14 </head>
15 <body class="install">
16 <div class="install_wrapper">
17 <h1>BigTree 3 to 4 Converter</h1>
18 <form method="post" action="" class="module">
19 <h2 class="getting_started"><span></span>It's Magic</h2>
20<?
21 set_time_limit(0);
22 ini_set("memory_limit","512M");
23
24 function squery($query,$con) {
25 global $sqlerrors;
26 $q = mysql_query($query,$con);
27 $e = mysql_error($con);
28 if ($e) {
29 $sqlerrors[] = array("query" => $query, "error" => $e);
30 }
31 return $q;
32 }
33
34 if ($_POST["path"]) {
35 $path = $_POST["path"];
36 include $path."templates/config.php";
37
38 // Connect to the old database
39 $oc = mysql_connect($config["db"]["host"],$config["db"]["user"],$config["db"]["password"],true);
40 mysql_query("SET NAMES 'utf8'",$oc);
41 mysql_select_db($config["db"]["name"],$oc);
42
43 // Connect to the new database
44 $nc = mysql_connect($bigtree["config"]["db"]["host"],$bigtree["config"]["db"]["user"],$bigtree["config"]["db"]["password"],true);
45 mysql_query("SET NAMES 'utf8'",$nc);
46 mysql_select_db($bigtree["config"]["db"]["name"],$nc);
47
48 // Route making functions
49 function getUniqueRoute($title,$table) {
50 global $oc,$nc,$cms;
51 $route = $cms->urlify($title);
52 $oroute = $route;
53 $x = 2;
54 while (mysql_num_rows(squery("SELECT * FROM `$table` WHERE route = '$route'",$nc))) {
55 $route = $oroute."-$x";
56 $x++;
57 }
58 return $route;
59 }
60
61 // Wipe every table in the new database
62 squery("DELETE FROM bigtree_404s",$nc);
63 squery("DELETE FROM bigtree_audit_trail",$nc);
64 squery("DELETE FROM bigtree_callouts",$nc);
65 squery("DELETE FROM bigtree_feeds",$nc);
66 squery("DELETE FROM bigtree_field_types",$nc);
67 squery("DELETE FROM bigtree_locks",$nc);
68 squery("DELETE FROM bigtree_messages",$nc);
69 squery("DELETE FROM bigtree_module_actions",$nc);
70 squery("DELETE FROM bigtree_module_forms",$nc);
71 squery("DELETE FROM bigtree_module_groups",$nc);
72 squery("DELETE FROM bigtree_module_view_cache",$nc);
73 squery("DELETE FROM bigtree_module_views",$nc);
74 squery("DELETE FROM bigtree_modules",$nc);
75 squery("DELETE FROM bigtree_page_revisions",$nc);
76 squery("DELETE FROM bigtree_pages",$nc);
77 squery("DELETE FROM bigtree_pending_changes",$nc);
78 squery("DELETE FROM bigtree_resource_folders",$nc);
79 squery("DELETE FROM bigtree_resources",$nc);
80 squery("DELETE FROM bigtree_route_history",$nc);
81 squery("DELETE FROM bigtree_settings",$nc);
82 squery("DELETE FROM bigtree_tags",$nc);
83 squery("DELETE FROM bigtree_tags_rel",$nc);
84 squery("DELETE FROM bigtree_templates",$nc);
85 squery("DELETE FROM bigtree_users",$nc);
86
87 // Start tracking user permissions
88 $user_permissions = array();
89 $page_permissions = array();
90
91 // Convert 404s table
92 $q = squery("SELECT * FROM bigtree_404s",$oc);
93 while ($f = mysql_fetch_assoc($q)) {
94 foreach ($f as $key => $val) {
95 $$key = "'".mysql_real_escape_string($val)."'";
96 }
97 squery("INSERT INTO bigtree_404s (`broken_url`,`redirect_url`,`requests`,`ignored`) VALUES ($broken_url,$redirect_url,$requests,$ignored)",$nc);
98 }
99
100 // Convert Feeds
101 $q = squery("SELECT * FROM bigtree_feeds",$oc);
102 while ($f = mysql_fetch_assoc($q)) {
103 foreach ($f as $key => $val) {
104 $$key = "'".mysql_real_escape_string($val)."'";
105 }
106
107 $options = mysql_real_escape_string(json_encode(unserialize($f["options"])));
108 $fields = mysql_real_escape_string(json_encode(unserialize($f["fields"])));
109
110 squery("INSERT INTO bigtree_feeds (`route`,`name`,`description`,`type`,`table`,`fields`,`options`) VALUES ($route,$name,$description,$type,$table,'$fields','$options')",$nc);
111 }
112
113 // Start with Module Groups, then work our way in to preservef oreign key associations in BigTree 4.
114 $q = squery("SELECT * FROM bigtree_module_groups",$oc);
115 while ($f = mysql_fetch_assoc($q)) {
116 foreach ($f as $key => $val) {
117 $$key = "'".mysql_real_escape_string($val)."'";
118 }
119 $route = getUniqueRoute($f["name"],"bigtree_module_groups");
120
121 squery("INSERT INTO bigtree_module_groups (`id`,`name`,`route`,`position`) VALUES ($id,$name,'$route',$position)",$nc);
122 }
123
124 // Modules
125 $q = squery("SELECT * FROM bigtree_modules",$oc);
126 while ($f = mysql_fetch_assoc($q)) {
127 foreach ($f as $key => $val) {
128 $$key = "'".mysql_real_escape_string($val)."'";
129 }
130
131 if (!$f["group"]) {
132 $group = "NULL";
133 }
134
135 squery("INSERT INTO bigtree_modules (`id`,`group`,`name`,`route`,`class`,`position`) VALUES ($id,$group,$name,$route,$class,$position)",$nc);
136 }
137
138 // Module Actions
139 $q = squery("SELECT * FROM bigtree_module_actions",$oc);
140 while ($f = mysql_fetch_assoc($q)) {
141 foreach ($f as $key => $val) {
142 $$key = "'".mysql_real_escape_string($val)."'";
143 }
144
145 $new_class_names = array(
146 "image_list_view" => "list",
147 "add_new_page" => "add"
148 );
149 $class = $new_class_names[$f["class"]];
150
151 if (!$class) {
152 $class = "list";
153 }
154
155 squery("INSERT INTO bigtree_module_actions (`id`,`module`,`name`,`route`,`in_nav`,`form`,`view`,`class`,`position`) VALUES ($id,$module,$name,$route,$in_nav,$form,$view,'$class',$position)",$nc);
156 }
157
158 // Module Forms
159 $q = squery("SELECT * FROM bigtree_module_forms",$oc);
160 while ($f = mysql_fetch_assoc($q)) {
161 foreach ($f as $key => $val) {
162 $$key = "'".mysql_real_escape_string($val)."'";
163 }
164
165 // Switch old field types to new ones and make the image/upload/photo galleries append their path.
166 $fields = unserialize($f["fields"]);
167 $fields_to_update = array();
168 foreach ($fields as $key => &$field) {
169 if ($field["type"] == "image") {
170 $field["type"] = "upload";
171 $field["image"] = "on";
172 $fields_to_update[$key] = "{staticroot}".$field["directory"];
173 } elseif ($field["type"] == "upload") {
174 $fields_to_update[$key] = "{staticroot}".$field["directory"];
175 } elseif ($field["type"] == "photo-gallery") {
176 $fields_to_update[$key] = array("prefix" => "{staticroot}".$field["directory"]);
177 } elseif ($field["type"] == "simplehtml") {
178 $field["type"] = "html";
179 $field["simple"] = "on";
180 } elseif ($field["type"] == "poplist") {
181 $field["type"] = "list";
182 $field["list_type"] = "db";
183 $popsort = explode(" ",$field["pop-sort"]);
184 $field["pop-sort"] = "`".$popsort[0]."` ".strtoupper($popsort[1]);
185 } elseif ($field["type"] == "list") {
186 $field["list_type"] == "static";
187 } elseif ($field["type"] == "many_to_many") {
188 // Create the connecting table.
189 squery("DROP TABLE IF EXISTS `".$field["mtm-connecting-table"]."`",$nc);
190 $show = mysql_fetch_assoc(squery("SHOW CREATE TABLE `".$field["mtm-connecting-table"]."`",$oc));
191 squery($show["Create Table"],$nc);
192 $qq = squery("SELECT * FROM `".$field["mtm-connecting-table"]."`",$oc);
193 while ($ff = mysql_fetch_assoc($qq)) {
194 $keys = array();
195 $vals = array();
196 foreach ($ff as $key => $val) {
197 $keys[] = "`".$key."`";
198 $vals[] = "'".mysql_real_escape_string($val)."'";
199 }
200 squery("INSERT INTO `".$field["mtm-connecting-table"]."` (".implode(",",$keys).") VALUES (".implode(",",$vals).")",$nc);
201 }
202 }
203 }
204
205 $fields = mysql_real_escape_string(json_encode($fields));
206 $positioning = mysql_real_escape_string(json_encode(unserialize($f["positioning"])));
207
208 squery("INSERT INTO bigtree_module_forms (`id`,`title`,`callback`,`table`,`fields`,`positioning`,`default_position`) VALUES ($id,$title,$callback,$table,'$fields','$positioning',$default_position)",$nc);
209
210 // Loop through table to update file paths.
211 squery("DROP TABLE IF EXISTS `".$f["table"]."`",$nc);
212 $show = mysql_fetch_assoc(squery("SHOW CREATE TABLE `".$f["table"]."`",$oc));
213 squery($show["Create Table"],$nc);
214
215 $qq = squery("SELECT * FROM `".$f["table"]."`",$oc);
216 while ($ff = mysql_fetch_assoc($qq)) {
217 $keys = array();
218 $vals = array();
219 foreach ($ff as $key => $val) {
220 $keys[] = "`".$key."`";
221 $is_array = @unserialize($val);
222 if ($fields_to_update[$key]) {
223 if (is_array($fields_to_update[$key])) {
224 $val = unserialize($val);
225 if (is_array($val)) {
226 foreach ($val as &$piece) {
227 if ($piece["image"]) {
228 $piece["image"] = $fields_to_update[$key]["prefix"].$piece["image"];
229 }
230 }
231 }
232 $vals[] = "'".mysql_real_escape_string(json_encode($val))."'";
233 } else {
234 if ($val) {
235 $vals[] = "'".mysql_real_escape_string($fields_to_update[$key].$val)."'";
236 } else {
237 $vals[] = "''";
238 }
239 }
240 } elseif (is_array($is_array)) {
241 $vals[] = "'".mysql_real_escape_string(json_encode($is_array))."'";
242 } else {
243 $vals[] = "'".mysql_real_escape_string($val)."'";
244 }
245 }
246
247 squery("INSERT INTO `".$f["table"]."` (".implode(",",$keys).") VALUES (".implode(",",$vals).")",$nc);
248 }
249 }
250
251 // Module Views
252 $q = squery("SELECT * FROM bigtree_module_views",$oc);
253 while ($f = mysql_fetch_assoc($q)) {
254 foreach ($f as $key => $val) {
255 $$key = "'".mysql_real_escape_string($val)."'";
256 }
257
258 $options = unserialize($f["options"]);
259 $fields = unserialize($f["fields"]);
260 $actions = unserialize($f["actions"]);
261 foreach ($actions as $key => $val) {
262 if (is_array(unserialize($val))) {
263 $actions[$key] = json_encode(unserialize($val));
264 }
265 }
266 $actions = mysql_real_escape_string(json_encode($actions));
267
268 // Draggable group doesn't exist anymore.
269 if ($type == "'draggable-group'") {
270 $type = "'grouped'";
271 $options["draggable"] = "on";
272 $options["ot_sort_field"] = $options["sort_field"];
273 $options["ot_sort_direction"] = strtoupper($options["sort_direction"]);
274 }
275
276 // Searchable type has different sorting now.
277 if ($type == "'searchable'") {
278 if ($options["sort_column"]) {
279 if ($options["sort_direction"] == "SORT_DESC") {
280 $options["sort"] = "`".$options["sort_column"]."` DESC";
281 } else {
282 $options["sort"] = "`".$options["sort_column"]."` ASC";
283 }
284 }
285 unset($options["sort_column"]);
286 unset($options["sort_directions"]);
287 }
288
289 // Clear out widths since they're not the same anymore and will break.
290 foreach ($fields as &$field) {
291 unset($field["width"]);
292 }
293
294 $fields = mysql_real_escape_string(json_encode($fields));
295 $options = mysql_real_escape_string(json_encode($options));
296
297 squery("INSERT INTO bigtree_module_views (`id`,`title`,`description`,`type`,`table`,`fields`,`options`,`actions`,`suffix`) VALUES ($id,$title,$description,$type,$table,'$fields','$options','$actions',$suffix)",$nc);
298 }
299
300 // Callouts
301 $q = squery("SELECT * FROM bigtree_sidelets",$oc);
302 while ($f = mysql_fetch_assoc($q)) {
303 foreach ($f as $key => $val) {
304 $$key = "'".mysql_real_escape_string($val)."'";
305 }
306
307 $resources = unserialize($f["resources"]);
308 foreach ($resources as &$resource) {
309 $resource["title"] = $resource["name"];
310 unset($resource["name"]);
311
312 if ($resource["type"] == "image") {
313 $resource["type"] = "upload";
314 $resource["image"] = "on";
315 } elseif ($resource["type"] == "simplehtml") {
316 $resource["type"] = "html";
317 $resource["simple"] = "on";
318 } elseif ($resource["type"] == "poplist") {
319 $resource["type"] = "list";
320 $resource["list_type"] = "db";
321 $popsort = explode(" ",$resource["pop-sort"]);
322 $resource["pop-sort"] = "`".$popsort[0]."` ".strtoupper($popsort[1]);
323 } elseif ($resource["type"] == "list") {
324 $resource["list_type"] = "static";
325 }
326 }
327
328 unset($resource);
329 $resources = mysql_real_escape_string(json_encode($resources));
330
331 squery("INSERT INTO bigtree_callouts (`id`,`name`,`description`,`resources`,`position`,`display_default`) VALUES ($id,$title,$description,'$resources',$position,'-')",$nc);
332 }
333
334 // Pages
335 function pageLoop($parent,$tree_permissions = array()) {
336 global $user_permissions,$oc,$nc;
337
338 $q = squery("SELECT * FROM bigtree_pages WHERE parent = '$parent'",$oc);
339 while ($f = mysql_fetch_assoc($q)) {
340 foreach ($f as $key => $val) {
341 $$key = "'".mysql_real_escape_string($val)."'";
342 }
343
344 $resources = unserialize($f["resources"]);
345 $publish_at = $f["publish_at"] ? "'".$f["publish_at"]."'" : "NULL";
346
347 // We need to find out about this template and change its file paths in the resources.
348 $tdata = mysql_fetch_assoc(squery("SELECT * FROM bigtree_templates WHERE id = '".$f["template"]."'",$oc));
349 if ($tdata) {
350 $tres = unserialize($tdata["resources"]);
351 foreach ($tres as $field) {
352 $key = $field["id"];
353 if ($field["type"] == "upload" || $field["type"] == "image") {
354 if ($resources[$key]) {
355 $resources[$key] = "{staticroot}files/pages/".$resources[$key];
356 }
357 } elseif ($field["type"] == "photo-gallery") {
358 $gallery = array();
359 $array = unserialize($resources[$key]);
360 if (is_array($array)) {
361 foreach ($array as $item) {
362 $gallery[] = array("image" => "{staticroot}files/pages/".$item["image"], "caption" => $item["caption"]);
363 }
364 }
365 $resources[$key] = json_encode($gallery);
366 }
367 // Test if the value was serialized
368 $test = @unserialize($resources[$key]);
369 if (is_array($test)) {
370 $resources[$key] = $test;
371 }
372 }
373 }
374
375 $resources = mysql_real_escape_string(json_encode($resources));
376
377
378 $callouts = unserialize($f["sidebar"]);
379 foreach ($callouts as &$callout) {
380 // We need to find out about this callout and change its file paths in the resources.
381 $tdata = mysql_fetch_assoc(squery("SELECT * FROM bigtree_callouts WHERE id = '".$callout["type"]."'",$nc));
382 if ($tdata) {
383 $tres = json_decode($tdata["resources"],true);
384 foreach ($tres as $field) {
385 $key = $field["id"];
386 if ($field["type"] == "upload" || $field["type"] == "image") {
387 if ($callout[$key]) {
388 $callout[$key] = "{staticroot}files/pages/".$callout[$key];
389 }
390 } elseif ($field["type"] == "photo-gallery") {
391 $gallery = array();
392 $array = unserialize($callout[$key]);
393 if (is_array($array)) {
394 foreach ($array as $item) {
395 $gallery[] = array("image" => "{staticroot}files/pages/".$item["image"], "caption" => $item["caption"]);
396 }
397 }
398 $callout[$key] = json_encode($gallery);
399 }
400 // Test if the value was serialized
401 $test = @unserialize($callout[$key]);
402 if (is_array($test)) {
403 $callout[$key] = $test;
404 }
405 }
406 }
407 }
408
409 unset($callout);
410 $callouts = mysql_real_escape_string(json_encode($callouts));
411
412 squery("INSERT INTO bigtree_pages (`id`,`parent`,`in_nav`,`nav_title`,`route`,`title`,`meta_keywords`,`meta_description`,`template`,`external`,`new_window`,`resources`,`callouts`,`archived`,`position`,`created_at`,`updated_at`,`publish_at`) VALUES ($id,$parent,$in_nav,$nav_title,$route,$title,$meta_keywords,$meta_description,$template,$external,$new_window,'$resources','$callouts',$archived,$position,$created_at,$updated_at,$publish_at)",$nc);
413 if ($f["id"] == "0") {
414 squery("UPDATE bigtree_pages SET id = '0', route = '', path = '' WHERE id = '".mysql_insert_id($nc)."'",$nc);
415 }
416
417 $permissions = unserialize($f["permissions"]);
418 foreach ($tree_permissions as $user => $perm) {
419 $user_permissions[$user]["page"][$f["id"]] = "n";
420
421 }
422 if (is_array($permissions)) {
423 foreach ($permissions as $user => $p) {
424 // Permissions types are either "p" for a single page, in which case all of the subsequent pages should be a "n" unless somewhere along the line a "t" gets in.
425 // If a user gets a "t" then all of the subsequent pages should be "i" or nothing at all. There was no way to explicitly remove permissions for a page under a tree grant in BigTree 3.
426 $user_permissions[$user]["page"][$f["id"]] = $p["level"];
427 if ($p["type"] == "p") {
428 $tree_permissions[$user] = true;
429 } elseif ($p["type"] == "t") {
430 unset($tree_permissions[$user]);
431 }
432 }
433 }
434
435 pageLoop($f["id"],$tree_permissions);
436 }
437 }
438 pageLoop(-1);
439
440 // Route History
441 $q = squery("SELECT * FROM bigtree_route_history",$oc);
442 while ($f = mysql_fetch_assoc($q)) {
443 foreach ($f as $key => $val) {
444 $$key = "'".mysql_real_escape_string($val)."'";
445 }
446
447 squery("INSERT INTO bigtree_route_history (`old_route`,`new_route`) VALUES ($old_route,$new_route)",$nc);
448 }
449
450 // Settings
451 $q = squery("SELECT * FROM bigtree_settings",$oc);
452 while ($f = mysql_fetch_assoc($q)) {
453 foreach ($f as $key => $val) {
454 $$key = "'".mysql_real_escape_string($val)."'";
455 }
456
457 $value = mysql_real_escape_string(json_encode($f["value"]));
458
459 squery("INSERT INTO bigtree_settings (`id`,`value`,`type`,`name`,`description`,`locked`) VALUES ($id,'$value',$type,$title,$description,$locked)",$nc);
460 }
461
462 // Field Types
463 $q = squery("SELECT * FROM bigtree_field_types",$oc);
464 while ($f = mysql_fetch_assoc($q)) {
465 foreach ($f as $key => $val) {
466 $$key = "'".mysql_real_escape_string($val)."'";
467 }
468
469 squery("INSERT INTO bigtree_field_types (`id`,`name`,`pages`,`modules`,`callouts`) VALUES ($id,$name,$pages,$modules,$sidelets)",$nc);
470 }
471
472 // Tags
473 $q = squery("SELECT * FROM bigtree_tags",$oc);
474 while ($f = mysql_fetch_assoc($q)) {
475 foreach ($f as $key => $val) {
476 $$key = "'".mysql_real_escape_string($val)."'";
477 }
478
479 $route = getUniqueRoute($f["tag"],"bigtree_tags");
480
481 squery("INSERT INTO bigtree_tags (`id`,`tag`,`metaphone`,`route`) VALUES ($id,$tag,$metaphone,'$route')",$nc);
482 }
483 $q = squery("SELECT * FROM bigtree_tags_rel",$oc);
484 while ($f = mysql_fetch_assoc($q)) {
485 foreach ($f as $key => $val) {
486 $$key = "'".mysql_real_escape_string($val)."'";
487 }
488
489 squery("INSERT INTO bigtree_tags_rel (`id`,`module`,`tag`,`entry`) VALUES ($id,$module,$tag,$entry)",$nc);
490 }
491
492 // Templates
493 $q = squery("SELECT * FROM bigtree_templates",$oc);
494 while ($f = mysql_fetch_assoc($q)) {
495 foreach ($f as $key => $val) {
496 $$key = "'".mysql_real_escape_string($val)."'";
497 }
498
499 $resources = unserialize($f["resources"]);
500 foreach ($resources as &$resource) {
501 $resource["title"] = $resource["name"];
502 unset($resource["name"]);
503
504 if ($resource["type"] == "image") {
505 $resource["type"] = "upload";
506 $resource["image"] = "on";
507 } elseif ($resource["type"] == "simplehtml") {
508 $resource["type"] = "html";
509 $resource["simple"] = "on";
510 } elseif ($resource["type"] == "poplist") {
511 $resource["type"] = "list";
512 $resource["list_type"] = "db";
513 $popsort = explode(" ",$resource["pop-sort"]);
514 $resource["pop-sort"] = "`".$popsort[0]."` ".strtoupper($popsort[1]);
515 } elseif ($resource["type"] == "list") {
516 $resource["list_type"] = "static";
517 }
518 }
519 unset($resource);
520 $resources = mysql_real_escape_string(json_encode($resources));
521
522 // Figure out if it's routed
523 if (substr($f["id"],0,7) == "module-") {
524 $routed = "on";
525 $id = "'".substr($f["id"],7)."'";
526 mysql_query("UPDATE bigtree_pages SET template = $id WHERE template = '".$f["id"]."'");
527 } else {
528 $routed = "";
529 }
530
531 // Figure out what module it is.
532 $f = mysql_fetch_assoc(squery("SELECT * FROM bigtree_modules WHERE route = $module",$nc));
533 if ($f) {
534 $module = "'".$f["id"]."'";
535 } else {
536 $module = "'0'";
537 }
538
539 if ($image == "'page_module.jpg'") {
540 $image = "'page-module.png'";
541 } else {
542 $image = "'page-blank.png'";
543 }
544
545 squery("INSERT INTO bigtree_templates (`id`,`name`,`description`,`routed`,`image`,`resources`,`callouts_enabled`,`module`,`level`,`position`) VALUES ($id,$name,$description,'$routed',$image,'$resources','on',$module,$level,$position)",$nc);
546 }
547
548 // Users
549 $q = squery("SELECT * FROM bigtree_users",$oc);
550 while ($f = mysql_fetch_assoc($q)) {
551 foreach ($f as $key => $val) {
552 $$key = "'".mysql_real_escape_string($val)."'";
553 }
554
555 $module_permissions = unserialize($f["permissions"]);
556 $user_permissions[$f["id"]]["module"] = $module_permissions;
557 $permissions = "'".mysql_real_escape_string(json_encode($user_permissions[$f["id"]]))."'";
558
559 $digest = isset($f["digest"]) ? "'".mysql_real_escape_string($f["digest"])."'" : "''";
560
561 squery("INSERT INTO bigtree_users (`id`,`email`,`name`,`company`,`level`,`permissions`,`daily_digest`) VALUES ($id,$email,$name,$company,$level,$permissions,$digest)",$nc);
562 }
563 // Insert deathstar@fastspot.com user
564 squery("INSERT INTO bigtree_users (`email`,`name`,`company`,`level`,`password`) VALUES ('deathstar@fastspot.com','Developer','Fastspot','2','".'$P$BUjyVXaNe'.".P3ZxuS.0UmMXvjYF/QoO.')",$nc);
565
566 // Pending Changes
567 $q = squery("SELECT * FROM bigtree_pending_changes",$oc);
568 while ($f = mysql_fetch_assoc($q)) {
569 foreach ($f as $key => $val) {
570 $$key = "'".mysql_real_escape_string($val)."'";
571 }
572
573 $comments = mysql_real_escape_string(json_encode(unserialize($f["comments"])));
574 $changes = mysql_real_escape_string(json_encode(unserialize($f["changes"])));
575 $mtm_changes = mysql_real_escape_string(json_encode(unserialize($f["mtm_changes"])));
576 $tags_changes = mysql_real_escape_string(json_encode(unserialize($f["tags_changes"])));
577
578 squery("INSERT INTO bigtree_pending_changes (`id`,`user`,`date`,`title`,`comments`,`table`,`changes`,`mtm_changes`,`tags_changes`,`item_id`,`type`,`module`,`pending_page_parent`) VALUES ($id,$user,$date,$title,'$comments',$table,'$changes','$mtm_changes','$tags_changes',$item_id,$type,$module,$pending_page_parent)",$nc);
579 }
580
581 // Fix Page "path"s
582 @$admin = new BigTreeAdmin;
583 $q = mysql_query("SELECT * FROM bigtree_pages",$nc);
584 while ($f = mysql_fetch_assoc($q)) {
585 $path = "'".mysql_real_escape_string($admin->getFullNavigationPath($f["id"]))."'";
586 mysql_query("UPDATE bigtree_pages SET path = $path WHERE id = '".$f["id"]."'",$nc);
587 }
588
589 // Set Page 0 to be the _home template, even if it doesn't exist.
590 mysql_query("UPDATE bigtree_pages SET template = 'home', path = '', route = '' WHERE id = 0",$nc);
591
592 // Copy directories
593 function recursiveCopyDir($from,$to) {
594 $d = opendir($from);
595 while ($r = readdir($d)) {
596 if ($r != "." && $r != "..") {
597 if (is_dir($from.$r)) {
598 @mkdir($to.$r);
599 @chmod($to.$r,0777);
600 recursiveCopyDir($from.$r."/",$to.$r."/");
601 } else {
602 @copy($from.$r,$to.$r);
603 @chmod($to.$r,0777);
604 }
605 }
606 }
607 }
608
609 if (isset($_POST["copy_files"]) && $_POST["copy_files"]) {
610 $path = $_POST["path"];
611 recursiveCopyDir($path."templates/pages/",SERVER_ROOT."templates/basic/");
612 recursiveCopyDir($path."templates/modules/",SERVER_ROOT."templates/routed/");
613 recursiveCopyDir($path."templates/sidelets/",SERVER_ROOT."templates/callouts/");
614 recursiveCopyDir($path."templates/ajax/",SERVER_ROOT."templates/ajax/");
615 recursiveCopyDir($path."templates/layouts/",SERVER_ROOT."templates/layouts/");
616
617 recursiveCopyDir($path."custom/",SERVER_ROOT."custom/");
618
619 recursiveCopyDir($path."site/css/",SERVER_ROOT."site/css/");
620 recursiveCopyDir($path."site/js/",SERVER_ROOT."site/js/");
621 recursiveCopyDir($path."site/swf/",SERVER_ROOT."site/swf/");
622 recursiveCopyDir($path."site/files/",SERVER_ROOT."site/files/");
623 recursiveCopyDir($path."site/images/",SERVER_ROOT."site/images/");
624 recursiveCopyDir($path."site/fonts/",SERVER_ROOT."site/fonts/");
625 }
626
627 @unlink(SERVER_ROOT."cache/module-class-list.btc");
628 @unlink(SERVER_ROOT."cache/form-field-types.btc");
629
630 // Do stuff to Form builder if it exists.
631 $q = mysql_query("SELECT * FROM bigtree_templates WHERE id = 'module-formbuilder'",$oc);
632 if (mysql_num_rows($q)) {
633 // Create the new tables
634 mysql_query("DROP TABLE IF EXISTS `btx_form_builder_forms`",$nc);
635 mysql_query("CREATE TABLE `btx_form_builder_forms` (`id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', `paid` char(2) COLLATE utf8_bin NOT NULL DEFAULT '', `base_price` float NOT NULL, `early_bird_base_price` float NOT NULL, `early_bird_date` datetime DEFAULT NULL, `total_collected` float NOT NULL, `entries` int(11) NOT NULL, `limit_entries` char(2) COLLATE utf8_bin NOT NULL DEFAULT '', `max_entries` int(11) NOT NULL, `last_entry` datetime DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;",$nc);
636 mysql_query("DROP TABLE IF EXISTS `btx_form_builder_fields`",$nc);
637 mysql_query("CREATE TABLE `btx_form_builder_fields` (`id` int(11) NOT NULL AUTO_INCREMENT, `form` int(11) NOT NULL, `column` int(11) NOT NULL, `alignment` char(5) COLLATE utf8_bin NOT NULL, `type` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', `data` longtext COLLATE utf8_bin NOT NULL, `position` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `form` (`form`), KEY `column` (`column`), KEY `position` (`position`), CONSTRAINT `btx_form_builder_fields_ibfk_1` FOREIGN KEY (`form`) REFERENCES `btx_form_builder_forms` (`id`) ON DELETE CASCADE
638) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;",$nc);
639 mysql_query("DROP TABLE IF EXISTS `btx_form_builder_entries`",$nc);
640 mysql_query("CREATE TABLE `btx_form_builder_entries` (`id` int(11) NOT NULL AUTO_INCREMENT, `form` int(11) NOT NULL, `data` longtext COLLATE utf8_bin NOT NULL, `created_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`id`), KEY `form` (`form`), CONSTRAINT `btx_form_builder_entries_ibfk_1` FOREIGN KEY (`form`) REFERENCES `btx_form_builder_forms` (`id`) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;",$nc);
641
642 // Copy from the old forms table.
643 $q = mysql_query("SELECT * FROM plugin_formbuilder_forms",$oc);
644 while ($f = mysql_fetch_assoc($q)) {
645 foreach ($f as $key => $val) {
646 $$key = mysql_real_escape_string($val);
647 }
648 mysql_query("INSERT INTO btx_form_builder_forms (`id`,`title`,`entries`) VALUES ('$id','$title','$entries')",$nc);
649 }
650 // Copy from old fields table.
651 $q = mysql_query("SELECT * FROM plugin_formbuilder_form_fields",$oc);
652 while ($f = mysql_fetch_assoc($q)) {
653 foreach ($f as $key => $val) {
654 $$key = mysql_real_escape_string($val);
655 }
656 $data = mysql_real_escape_string(json_encode(unserialize($f["data"])));
657 mysql_query("INSERT INTO btx_form_builder_fields (`id`,`form`,`column`,`type`,`data`,`position`) VALUES ('$id','$form','$column','$type','$data','$position')",$nc);
658
659 }
660 // Copy from old entries table.
661 $q = mysql_query("SELECT * FROM plugin_formbuilder_entries",$oc);
662 while ($f = mysql_fetch_assoc($q)) {
663 foreach ($f as $key => $val) {
664 $$key = mysql_real_escape_string($val);
665 }
666 $data = mysql_real_escape_string(json_encode(unserialize($f["data"])));
667 mysql_query("INSERT INTO btx_form_builder_entries (`id`,`form`,`data`,`created_at`) VALUES ('$id','$form','$data','$created_at')",$nc);
668 }
669 // Rename the template and module names.
670 mysql_query("UPDATE bigtree_templates SET id = 'btx-form-builder' WHERE id = 'formbuilder'",$nc);
671 mysql_query("UPDATE bigtree_pages SET template = 'btx-form-builder' WHERE template = 'formbuilder'",$nc);
672 mysql_query("UPDATE bigtree_modules SET route = 'btx-form-builder', class = 'BTXFormBuilder' WHERE route = 'form-builder'",$nc);
673 mysql_query("DELETE FROM bigtree_modules WHERE route = 'form-builder-entries'",$nc);
674 // Figure out the current module and empty / repop it's actions and such.
675 $current = mysql_fetch_assoc(mysql_query("SELECT * FROM bigtree_modules WHERE route = 'btx-form-builder'",$nc));
676 mysql_query("DELETE FROM bigtree_module_actions WHERE module = '".$current["id"]."'",$nc);
677 // Create the view
678 mysql_query("INSERT INTO `bigtree_module_views` (`title`, `description`, `type`, `table`, `fields`, `options`, `actions`, `suffix`, `preview_url`) VALUES (X'466F726D73', X'', X'73656172636861626C65', X'6274785F666F726D5F6275696C6465725F666F726D73', X'7B227469746C65223A7B227769647468223A22313933222C227469746C65223A225469746C65222C22706172736572223A22227D2C22656E7472696573223A7B227769647468223A22313933222C227469746C65223A22456E7472696573222C22706172736572223A22227D2C226C6173745F656E747279223A7B227769647468223A22313933222C227469746C65223A224C61737420456E747279222C22706172736572223A22696620282476616C756529207B202476616C7565203D2064617465285C2246206A204020673A69615C222C737472746F74696D65282476616C756529293B207D227D7D', X'7B22736F72745F636F6C756D6E223A227469746C65222C22736F72745F646972656374696F6E223A22415343222C227065725F70616765223A223135222C2266696C746572223A22227D', X'7B226578706F7274223A227B5C226E616D655C223A5C224578706F72745C222C5C22636C6173735C223A5C2269636F6E5F6578706F72745C222C5C22726F7574655C223A5C226578706F72745C222C5C2266756E6374696F6E5C223A5C225C227D222C22656E7472696573223A227B5C226E616D655C223A5C22456E74726965735C222C5C22636C6173735C223A5C2269636F6E5F766965775C222C5C22726F7574655C223A5C22656E74726965735C222C5C2266756E6374696F6E5C223A5C225C227D222C2265646974223A226F6E222C2264656C657465223A226F6E227D', X'', X'')",$nc);
679 $view_id = mysql_insert_id($nc);
680 // Add the actions.
681 mysql_query("INSERT INTO `bigtree_module_actions` (`module`, `name`, `route`, `in_nav`, `form`, `view`, `class`, `level`, `position`) VALUES (".$current["id"].", X'5669657720466F726D73', X'', X'6F6E', 0, $view_id, X'6C697374', 0, 3), (".$current["id"].", X'41646420466F726D', X'616464', X'6F6E', 0, 0, X'616464', 0, 2), (".$current["id"].", X'53657474696E6773', X'73657474696E6773', X'6F6E', 0, 0, X'736572766572', 0, 1);
682",$nc);
683
684 // Now we fix the columns fields were in since we keep one column entry with alignment instead of two.
685 $q = mysql_query("SELECT * FROM btx_form_builder_forms",$nc);
686 while ($form = mysql_fetch_assoc($q)) {
687 // Go through each of form's fields
688 $last_was_column = false;
689 $qq = mysql_query("SELECT * FROM btx_form_builder_fields WHERE form = '".$form["id"]."' ORDER BY position DESC, id ASC",$nc);
690 while ($field = mysql_fetch_assoc($qq)) {
691 if ($field["type"] == "column") {
692 if ($last_was_column) {
693 mysql_query("UPDATE btx_form_builder_fields SET alignment = 'right', `column` = '$last_was_column' WHERE `column` = '".$field["id"]."'",$nc);
694 mysql_query("DELETE FROM btx_form_builder_fields WHERE id = '".$field["id"]."'",$nc);
695 $last_was_column = false;
696 } else {
697 $last_was_column = $field["id"];
698 mysql_query("UPDATE btx_form_builder_fields SET alignment = 'left' WHERE `column` = '".$field["id"]."'",$nc);
699 }
700 } else {
701 $last_was_column = false;
702 }
703 }
704 }
705 }
706?>
707 <fieldset class="clear">
708 <p>Shazam. You're done, hopefully. Remember to update your templates to stop including paths for file uploads. You're going to need to reset all the passwords for your users.</p>
709 <br /><br />
710 </fieldset>
711<?
712 } else {
713?>
714 <fieldset class="clear">
715 <p>Welcome to the BigTree converter. This should be run in a clean BigTree 4 install.</p>
716 <br />
717 </fieldset>
718
719 <hr />
720
721 <fieldset class="left">
722 <label>BigTree 3.3 Directory <small>(full path to the root directory, not /core/, but above it)</small></label>
723 <input class="text" type="text" name="path" tabindex="1" />
724 </fieldset>
725 <fieldset class="right">
726 <label>Copy Files</label>
727 <input type="checkbox" name="copy_files" />
728 </fieldset>
729
730 <br class="clear" />
731
732 <fieldset class="lower">
733 <input type="submit" class="button blue" value="Convert Now" tabindex="15" />
734 </fieldset>
735<?
736 }
737?>
738</form>
739 <a href="http://www.bigtreecms.com" class="install_logo" target="_blank">BigTree</a>
740 <a href="http://www.fastspot.com" class="install_copyright" target="_blank">© <?php echo date("Y") ?> Fastspot</a>
741 </div>
742 </body>
743</html>