function bizz_frame_grid_logic($condition_logic_array = '') { global $bizz_registered_grids, $themeid; $condition_logic = $condition_logic_array; $args = array('post_type' => 'bizz_grid', 'numberposts' => -1, 'orderby' => 'modified', 'order' => 'ASC', 'post_status' => 'publish'); $bizz_old_grids = get_posts($args); foreach ($bizz_old_grids as $grids) { !isset($_condition) ? $_condition = $grids->post_excerpt . ',' : ($_condition .= $grids->post_excerpt . ','); !isset($_item) ? $_item = $grids->post_title . ',' : ($_item .= $grids->post_title . ','); } // print_r($bizz_old_grids); if (!empty($bizz_old_grids)) { // define all saved conditions and items $_condition = substr_replace($_condition, "", -1); // remove last comma $_condition = explode(",", $_condition); $_item = substr_replace($_item, "", -1); // remove last comma $_item = explode(",", $_item); /* Define which templates are active: (array)conditions, (array)items, condition, item */ $level_one = bizz_is_template($_condition, $_item, $condition_logic['bizz_condition'], $condition_logic['bizz_item']); $level_two_one = bizz_is_template($_condition, $_item, $condition_logic['bizz_subtabsub'], $condition_logic['bizz_item']); $level_two_two = bizz_is_template($_condition, $_item, $condition_logic['bizz_subtabsub'], $condition_logic['bizz_subtab']); $level_three = bizz_is_template($_condition, $_item, $condition_logic['bizz_subtab'], $condition_logic['bizz_item']); $level_four = bizz_is_template($_condition, $_item, $condition_logic['bizz_tab'], 'all'); $level_five = in_array('is_index', $_condition) && in_array('all', $_item); // list condition and item for current template if ($level_one) { $this_condition = $condition_logic['bizz_condition']; $this_item = $condition_logic['bizz_item']; // print_r( 'level one<br/>' ); } elseif ($level_two_one) { $this_condition = $condition_logic['bizz_subtabsub']; $this_item = $_item[array_search($condition_logic['bizz_subtab'], $_item)]; // print_r( 'level two<br/>' ); } elseif ($level_two_two) { $this_condition = $condition_logic['bizz_subtabsub']; $this_item = $_item[array_search($condition_logic['bizz_subtab'], $_item)]; // print_r( 'level two<br/>' ); } elseif ($level_three) { $this_condition = $condition_logic['bizz_subtab']; $this_item = $_item[array_search($condition_logic['bizz_subtab'], $_condition)]; // print_r( 'level three<br/>' ); } elseif ($level_four) { $this_condition = $condition_logic['bizz_tab']; $this_item = $_item[array_search($condition_logic['bizz_tab'], $_condition)]; // print_r( 'level four<br/>' ); } elseif ($level_five) { $this_condition = 'is_index'; $this_item = $_item[array_search('is_index', $_condition)]; // print_r( 'level five<br/>' ); } /* echo '<br/>'; print_r($_condition); echo '<br/>'; print_r($_item); echo '--------------------------<br/>'; print_r($this_condition); echo '<br/>'; print_r($this_item); */ if (isset($this_condition)) { foreach ($bizz_old_grids as $grids) { if ($grids->post_excerpt == $this_condition && $grids->post_title == $this_item) { $_layout = bizz_reverse_escape($grids->post_content); $_layout = unserialize($_layout); $_theme = $grids->post_content_filtered; } } } if (isset($_layout)) { $old_containers = $_layout; } else { $old_containers = $bizz_registered_grids; } // print_r($old_containers); // unset customized & unregistered containers / areas $array_keys1 = isset($old_containers) && is_array($old_containers) ? array_keys($old_containers) : ''; $array_keys2 = isset($bizz_registered_grids) && is_array($bizz_registered_grids) ? array_keys($bizz_registered_grids) : ''; $array_keys_match = is_array($array_keys1) && is_array($array_keys2) ? array_diff($array_keys1, $array_keys2) : ''; if (!empty($array_keys_match)) { foreach ((array) $array_keys_match as $value) { unset($old_containers[$value]); } #unset unregistered areas } // check if arrays match (different theme?) $registered_theme = isset($_theme) ? $_theme : ''; $current_theme = $themeid; if ($registered_theme != $current_theme && $registered_theme != '') { $old_containers = $bizz_registered_grids; } } if (empty($old_containers)) { $bizz_registered_grids = $bizz_registered_grids; } else { $array1 = $bizz_registered_grids; $array2 = $old_containers; $array3 = bizz_array_merge_recursive_distinct($array1, $array2); $array4 = array_merge($array2, $array3); $bizz_registered_grids = $array4; // saved grid /* print_r($array1); print_r('<br/>--1--<br/>'); print_r($array2); print_r('<br/>--2--<br/>'); print_r($array3); print_r('<br/>--3--<br/>'); print_r($array4); print_r('<br/>--4--<br/>'); */ } return $bizz_registered_grids; }
/** * MERGE ARRAY WITH UNIQUE VALUES * * extend default PHP4 aray_merge_recursive function * @since 7.0 */ function bizz_array_merge_recursive_distinct($array1, $array2 = null) { $merged = $array1; if (is_array($array2)) { foreach ($array2 as $key => $val) { if (is_array($array2[$key])) { $merged[$key] = is_array($merged[$key]) ? bizz_array_merge_recursive_distinct($merged[$key], $array2[$key]) : $array2[$key]; } else { $merged[$key] = $val; } } } return $merged; }