function ultimatum_list_widgets() { global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls; $sort = $wp_registered_widgets; usort( $sort, '_sort_name_callback_ultimatum' ); $done = array(); foreach ( $sort as $widget ) { if ( in_array( $widget['callback'], $done, true ) ) // We already showed this multi-widget continue; $sidebar = is_active_widget( $widget['callback'], $widget['id'], false, false ); $done[] = $widget['callback']; if ( ! isset( $widget['params'][0] ) ) $widget['params'][0] = array(); $args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' ); if ( isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number']) ) { $id_base = $wp_registered_widget_controls[$widget['id']]['id_base']; $args['_temp_id'] = "$id_base-__i__"; $args['_multi_num'] = ult_next_widget_id_number($id_base); $args['_add'] = 'multi'; } else { $args['_add'] = 'single'; if ( $sidebar ) $args['_hide'] = '1'; } $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) ); call_user_func_array( 'wp_widget_control', $args ); } }
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); }