function ult_legacy_importer($theme){ global $wpdb; // Create the Theme $table = $wpdb->prefix.ULTIMATUM_PREFIX.'_templates'; $ltable = $wpdb->prefix.ULTIMATUM_PREFIX.'_layout'; $atable = $wpdb->prefix.ULTIMATUM_PREFIX.'_layout_assign'; $rtable = $wpdb->prefix.ULTIMATUM_PREFIX.'_rows'; $ctable = $wpdb->prefix.ULTIMATUM_PREFIX.'_css'; $classtable = $wpdb->prefix.ULTIMATUM_PREFIX.'_classes'; $themesql = "INSERT INTO $table (`name`, `width`,`margin`,`mwidth`,`mmargin`,`swidth`,`smargin`,`type`,`theme`,gridwork,swatch) VALUES ('$theme[name]','$theme[width]','$theme[margin]','1200','20','747','10','$theme[type]','".THEME_SLUG."','ultimatum','default')"; $wpdb->query($themesql); $themeid = $wpdb->insert_id; foreach($theme['layouts'] as $layout){ if($layout['type']=='part'){ $layoutsql = "INSERT INTO $ltable (`title`,`type`,`theme`,`default`) VALUES ('$layout[name]','$layout[type]','$themeid','$layout[default]')"; $wpdb->query($layoutsql); $layoutid = $wpdb->insert_id; $old_lay_id=$layout['oldid']; $partconv[$old_lay_id]='layout-'.$layoutid; } else { if($layout["default"]==1){ //set this as theme css ;) $themeoptionname = THEME_SLUG.'_template_'.$themeid.'_css'; update_option($themeoptionname,$layout['css']); // Create Custom CSS file if(strlen($layout['custom_css'])>0){ update_option(THEME_SLUG.'_custom_template_css_'.$themeid,$layout['custom_css']); } } $new_parts_before=array(); $lbefore=''; if($layout['before']){ $old_parts_before=explode(',',$layout['before']); foreach($old_parts_before as $p_b){ $new_parts_before[]=$partconv[$p_b]; } $lbefore = implode(',', $new_parts_before); } $new_parts_after=array(); $lafter=''; if($layout['after']){ $old_parts_after=explode(',',$layout['after']); foreach($old_parts_after as $p_b){ $new_parts_after[]=$partconv[$p_b]; } $lafter = implode(',', $new_parts_after); } $layoutsql = "INSERT INTO $ltable (`title`,`type`,`theme`,`default`,`before`,`after`) VALUES ('$layout[name]','$layout[type]','$themeid','$layout[default]','$lbefore','$lafter')"; $wpdb->query($layoutsql); $layoutid = $wpdb->insert_id; if($_POST['assigners']=='assign'){ if(count($layout['assigned'])!=0){ foreach ($layout['assigned'] as $assignemnt){ $query = "REPLACE INTO $atable VALUES ('".THEME_SLUG."','$assignemnt','$layoutid')"; $wpdb->query($query); } } } } // Insert Layout CSS in WP Options and Generate file if($layout['type']=='full'){ $optionname = THEME_SLUG.'_'.$layoutid.'_css'; update_option($optionname,$layout['css']); // Create Custom CSS file if(strlen($layout['custom_css'])>0){ update_option(THEME_SLUG.'_custom_css_'.$layoutid,$layout['custom_css']); } } // Do the ROWS $rows = $layout['rows']; foreach ($rows as $row){ // Insert the row and get id $rowsql = "INSERT INTO $rtable (`layout_id`, `type_id`) VALUES ('$layoutid','$row[type]')"; $wpdb->query($rowsql); $rowid = $wpdb->insert_id; $layoutrows[]='row-'.$rowid; // Insert row wrapper CSS $wrapper = 'wrapper-'.$rowid; foreach($row['wrapper'] as $element=>$property){ if($element!='custom_classes'){ $properties = serialize($property); $wrappersql = "INSERT INTO $ctable VALUES ('','$wrapper','$layoutid','$element','$properties')"; $wpdb->query($wrappersql); } else { $properties = unserialize($property); if(count($properties)!=0): $classql = "REPLACE INTO $classtable (`container`,`user_class`,`hidephone`,`hidetablet`,`hidedesktop`,`layout_id`) VALUES ('$wrapper','".$properties["user_class"]."','".$properties["hidephone"]."','".$properties["hidetablet"]."','".$properties["hidedesktop"]."','$layoutid')"; $wpdb->query($classql); endif; } } // Insert row container CSS $container = 'container-'.$rowid; foreach($row['container'] as $element=>$property){ if($element!='custom_classes'){ $properties = serialize($property); $containersql = "INSERT INTO $ctable VALUES ('','$container','$layoutid','$element','$properties')"; $wpdb->query($containersql); } else { $properties = unserialize($property); if(count($properties)!=0): $classql = "REPLACE INTO $classtable (`container`,`user_class`,`hidephone`,`hidetablet`,`hidedesktop`,`layout_id`) VALUES ('$container','".$properties["user_class"]."','".$properties["hidephone"]."','".$properties["hidetablet"]."','".$properties["hidedesktop"]."','$layoutid')"; $wpdb->query($classql); endif; } } // Insert row Column CSS foreach ($row['col'] as $colid=>$colcss){ $column = 'col-'.$rowid.'-'.$colid; foreach ($colcss as $element=>$property){ if($element!='custom_classes'){ $properties = serialize($property); $colsql = "INSERT INTO $ctable VALUES ('','$column','$layoutid','$element','$properties')"; $wpdb->query($colsql); } else { $properties = unserialize($property); if(is_array($properties)): $classql = "REPLACE INTO $classtable (`container`,`user_class`,`hidephone`,`hidetablet`,`hidedesktop`,`layout_id`) VALUES ('$column','".$properties["user_class"]."','".$properties["hidephone"]."','".$properties["hidetablet"]."','".$properties["hidedesktop"]."','$layoutid')"; $wpdb->query($classql); endif; } } } //Import the widgets if(is_array($row['widgets'])){ foreach($row["widgets"] as $sidebar=>$widgets){ foreach($widgets as $widget) { $option = $widget['widget_name']; $id_base = $widget['id_base']; // Better widget ID control $nextidfromWP = ult_next_widget_id_number($widget['id_base']); $nextid = ult_messed_widget_id($option, $nextidfromWP); $warray = get_option($option); unset($widget['widget_name']); unset($widget['id_base']); $warray[$nextid] = $widget; update_option($option, $warray); $ultimatum_sidebars_widgets = get_option('ultimatum_sidebars_widgets'); $ultimatum_sidebars_widgets['sidebar-' . $rowid . '-' . $sidebar][] = $id_base . '-' . $nextid; update_option('ultimatum_sidebars_widgets', $ultimatum_sidebars_widgets); unset($warray); } } } // Widget import Done :) } $rowss = implode(',', $layoutrows); unset($layoutrows); $layoutupdatesql = "UPDATE $ltable SET `rows`='$rowss' WHERE `id`='$layoutid'"; $wpdb->query($layoutupdatesql); }// layouts foreach finish return $themeid; }
function ultimatum_clone_layout_part($data,$part,$source,$target){ global $wpdb; global $wp_registered_widgets, $wp_registered_widget_controls; $ultimatum_sidebars_widgets = get_option('ultimatum_sidebars_widgets'); $rows = explode(',',$data); foreach ($rows as $row){ $rowinfo = explode('-',$row); if($rowinfo[0]!='row'){ $newrows[] = $row; } else { $rowid = $rowinfo[1]; $query = "SELECT * FROM `".ULTIMATUM_TABLE_ROWS."` WHERE id=$rowid"; $sourcerow = $wpdb->get_row($query,ARRAY_A); $rtype = $sourcerow["type_id"]; $insertrow = "INSERT INTO `".ULTIMATUM_TABLE_ROWS."` (`layout_id`,`type_id`) VALUES ('$target','$rtype')"; $insertrow = $wpdb->query($insertrow); $newrowid = $wpdb->insert_id; $newrows[]='row-'.$newrowid; // DO CSS // 1- Wrapper $oldw= 'wrapper-'.$rowid; $qw = "SELECT * FROM `".ULTIMATUM_TABLE_CSS."` WHERE `container`='$oldw' AND `layout_id`='$source'"; $qwc = "SELECT * FROM `".ULTIMATUM_TABLE_CLASSES."` WHERE `container`='$oldw' AND `layout_id`='$source'"; $qwf = $wpdb->get_row($qw,ARRAY_A); $qwcf = $wpdb->get_row($qwc,ARRAY_A); if($qwf){ $neww = 'wrapper-'.$newrowid; $newwi = "INSERT INTO `".ULTIMATUM_TABLE_CSS."` (`container`,`layout_id`,`element`,`properties`) VALUES ('$neww','$target','$qwf[element]','$qwf[properties]')"; $newwi = $wpdb->query($newwi); } if($qwcf){ $neww = 'wrapper-'.$newrowid; $newwi = "INSERT INTO `".ULTIMATUM_TABLE_CLASSES."` (`container`,`layout_id`,`user_class`,`hidephone`,`hidetablet`,`hidedesktop`) VALUES ('$neww','$target','$qwcf[user_class]','$qwcf[hidephone]','$qwcf[hidetablet]','$qwcf[hidedesktop]')"; $newwi = $wpdb->query($newwi); } // 2- Container $oldw= 'container-'.$rowid; $qw = "SELECT * FROM `".ULTIMATUM_TABLE_CSS."` WHERE `container`='$oldw' AND `layout_id`='$source'"; $qwc = "SELECT * FROM `".ULTIMATUM_TABLE_CLASSES."` WHERE `container`='$oldw' AND `layout_id`='$source'"; $qwf = $wpdb->get_row($qw,ARRAY_A); $qwcf = $wpdb->get_row($qwc,ARRAY_A); if($qwf){ $neww = 'container-'.$newrowid; $newwi = "INSERT INTO `".ULTIMATUM_TABLE_CSS."` (`container`,`layout_id`,`element`,`properties`) VALUES ('$neww','$target','$qwf[element]','$qwf[properties]')"; $newwi = $wpdb->query($newwi); } if($qwcf){ $neww = 'container-'.$newrowid; $newwi = "INSERT INTO `".ULTIMATUM_TABLE_CLASSES."` (`container`,`layout_id`,`user_class`,`hidephone`,`hidetablet`,`hidedesktop`) VALUES ('$neww','$target','$qwcf[user_class]','$qwcf[hidephone]','$qwcf[hidetablet]','$qwcf[hidedesktop]')"; $newwi = $wpdb->query($newwi); } // 3- Columns global $wp_registered_widgets; for($j=1;$j<=6;$j++){ $oldw= 'col-'.$rowid.'-'.$j; $olds= 'sidebar-'.$rowid.'-'.$j; $neww = 'col-'.$newrowid.'-'.$j; $newsb = 'sidebar-'.$newrowid.'-'.$j; // 4- Widgets !!! ultimatum_next_widget_id_number if(count($ultimatum_sidebars_widgets["$olds"])>=1){ foreach ($ultimatum_sidebars_widgets["$olds"] as $id){ if(isset($wp_registered_widgets["$id"])){ $fwidget = $wp_registered_widgets["$id"]; $id_base = $wp_registered_widget_controls[$fwidget['id']]['id_base']; $currentwid = str_replace($id_base.'-', '', $fwidget["id"]); $callback = $wp_registered_widgets["$id"]['callback'][0]; $option= $callback->option_name; $warray = get_option($option); // Better widget ID control $nextidfromWP = ult_next_widget_id_number($id_base); $nextid = ult_messed_widget_id($option,$nextidfromWP); $warray["$nextid"] = $warray["$currentwid"]; update_option($option, $warray); $ultimatum_sidebars_widgets[$newsb][]=$id_base.'-'.$nextid; update_option('ultimatum_sidebars_widgets',$ultimatum_sidebars_widgets); unset($warray); } } } $qw = "SELECT * FROM `".ULTIMATUM_TABLE_CSS."` WHERE `container`='$oldw' AND `layout_id`='$source'"; $qwc = "SELECT * FROM `".ULTIMATUM_TABLE_CLASSES."` WHERE `container`='$oldw' AND `layout_id`='$source'"; $qwf = $wpdb->get_row($qw,ARRAY_A); $qwcf = $wpdb->get_row($qwc,ARRAY_A); if($qwf){ $newwi = "INSERT INTO `".ULTIMATUM_TABLE_CSS."` (`container`,`layout_id`,`element`,`properties`) VALUES ('$neww','$target','$qwf[element]','$qwf[properties]')"; $newwi = $wpdb->query($newwi); } if($qwcf){ $newwi = "INSERT INTO `".ULTIMATUM_TABLE_CLASSES."` (`container`,`layout_id`,`user_class`,`hidephone`,`hidetablet`,`hidedesktop`) VALUES ('$neww','$target','$qwcf[user_class]','$qwcf[hidephone]','$qwcf[hidetablet]','$qwcf[hidedesktop]')"; $newwi = $wpdb->query($newwi); } } } } // Insert rows $newrow = implode(',',$newrows); $update = "UPDATE `".ULTIMATUM_TABLE_LAYOUT."` SET `".$part."`='$newrow' WHERE id='$target'"; $wpdb->query($update); }