Esempio n. 1
0
File: html.php Progetto: hikaram/wee
 public static function get_meta_query_array($page_meta_data_filter)
 {
     if (isset($_GLOBALS['MDF_META_QUERY_ARRAY'])) {
         return $_GLOBALS['MDF_META_QUERY_ARRAY'];
         //query array is cached already
     }
     //+++
     $meta_query_array = array();
     if (!empty($page_meta_data_filter)) {
         //here we get all data about meta keys in constructor!!!
         $filter_post_blocks = array();
         if (isset($page_meta_data_filter['filter_post_blocks'])) {
             $filter_post_blocks = $page_meta_data_filter['filter_post_blocks'];
             unset($page_meta_data_filter['filter_post_blocks']);
             unset($page_meta_data_filter['filter_post_blocks_toggles']);
             unset($page_meta_data_filter['filter_post_blocks_toggles_tax']);
         }
         $filter_post_blocks_data = array();
         if (!empty($filter_post_blocks) and is_array($filter_post_blocks)) {
             foreach ($filter_post_blocks as $p_id) {
                 $html_items = MetaDataFilterPage::get_html_items($p_id);
                 if (is_array($html_items)) {
                     $filter_post_blocks_data = array_merge($filter_post_blocks_data, $html_items);
                 }
             }
         }
         //+++get widget options
         $widget_options = array();
         if (isset($page_meta_data_filter['mdf_widget_options'])) {
             $widget_options = $page_meta_data_filter['mdf_widget_options'];
             unset($page_meta_data_filter['mdf_widget_options']);
         }
         //+++
         if (isset($page_meta_data_filter['taxonomy'])) {
             unset($page_meta_data_filter['taxonomy']);
         }
         $meta_data_filter_bool = isset($_REQUEST['meta_data_filter_bool']) ? $_REQUEST['meta_data_filter_bool'] : 'AND';
         //+++
         if (is_array($page_meta_data_filter)) {
             foreach ($page_meta_data_filter as $key => $value) {
                 if ($value and !empty($value)) {
                     $html_item_data = array();
                     if (isset($filter_post_blocks_data[$key])) {
                         $html_item_data = $filter_post_blocks_data[$key];
                     }
                     //+++
                     $search_key = $key;
                     if (isset($html_item_data['is_reflected']) and $html_item_data['is_reflected'] == 1) {
                         $search_key = $html_item_data['reflected_key'];
                     }
                     if (!empty($html_item_data)) {
                         switch ($html_item_data['type']) {
                             case 'textinput':
                                 if (!empty($value)) {
                                     $textinput_target = isset($html_item_data['textinput_target']) ? $html_item_data['textinput_target'] : 'self';
                                     $textinput_mode = isset($html_item_data['textinput_mode']) ? $html_item_data['textinput_mode'] : 'like';
                                     $compare = 'LIKE';
                                     if ($textinput_mode == 'exact') {
                                         $compare = '=';
                                     }
                                     switch ($textinput_target) {
                                         case 'self':
                                             $meta_query_array[] = array('key' => "{$search_key}", 'value' => "{$value}", 'compare' => $compare);
                                             break;
                                         case 'title':
                                             $_REQUEST['mdf_post_title_request'] = $compare . '^' . $search_key . '^' . $value;
                                             break;
                                         case 'content':
                                             $_REQUEST['mdf_post_content_request'] = $compare . '^' . $search_key . '^' . $value;
                                             break;
                                         case 'title_or_content':
                                             $_REQUEST['mdf_post_title_or_content_request'] = $compare . '^' . $search_key . '^' . $value;
                                             break;
                                         case 'title_and_content':
                                             $_REQUEST['mdf_post_title_and_content_request'] = $compare . '^' . $search_key . '^' . $value;
                                             break;
                                     }
                                 }
                                 break;
                             case 'calendar':
                                 $from = 0;
                                 $to = 0;
                                 if (!empty($value) and is_array($value) and (!empty($value['from']) or !empty($value['to']))) {
                                     $from = intval($value['from']);
                                     $to = intval($value['to']);
                                 }
                                 if ($from > 0 or $to > 0) {
                                     if ($from == 0 and $to > 0) {
                                         $meta_query_array[] = array('key' => $search_key . "_to", 'value' => $to, 'compare' => "<=");
                                     }
                                     //+++
                                     if ($from > 0 and $to == 0) {
                                         $meta_query_array[] = array('key' => $search_key . "_from", 'value' => $from, 'compare' => ">=");
                                     }
                                     //+++
                                     if ($from == $to) {
                                         $meta_query_array[] = array('key' => $search_key . "_from", 'value' => $from, 'compare' => "<=");
                                         $meta_query_array[] = array('key' => $search_key . "_to", 'value' => $to, 'compare' => ">=");
                                     }
                                     //+++
                                     //fixed 08-10-2014
                                     if ($from < $to and $from > 0 and $to > 0) {
                                         /*
                                          $meta_query_array[] = array(
                                          'key' => $search_key . "_from",
                                          'value' => $from,
                                          'compare' => ">="
                                          );
                                         
                                          $meta_query_array[] = array(
                                          'key' => $search_key . "_to",
                                          'value' => $to,
                                          'compare' => "<="
                                          );
                                         */
                                         $meta_query_array[] = array('key' => $search_key . "_from", 'value' => array($from, $to), 'compare' => "BETWEEN");
                                     }
                                 }
                                 break;
                             case 'slider':
                                 //slider
                                 if ($meta_data_filter_bool != 'OR') {
                                     //IMPORTANT! THIS IS FUSE! WITHOUT this: MODE 'OR' BREAK SQL EXEC
                                     if (!isset($html_item_data['slider_range_value'])) {
                                         $html_item_data['slider_range_value'] = 0;
                                     }
                                     if ($html_item_data['slider_range_value'] == 1) {
                                         //double value slider slider
                                         list($single_val, $f) = explode('^', $value);
                                         if ($single_val != 0) {
                                             $meta_query_array[] = array('key' => $search_key, 'value' => $single_val, 'type' => 'DECIMAL', 'compare' => '<=');
                                             $meta_query_array[] = array('key' => $search_key . '_to', 'value' => $single_val, 'type' => 'DECIMAL', 'compare' => '>=');
                                         }
                                         //print_r($meta_query_array);exit;
                                     } else {
                                         //usual 1 value slider
                                         list($s, $f) = explode('^', $value);
                                         //+++
                                         list($min, $max) = explode('^', $html_item_data['slider']);
                                         if (floatval($max) === floatval($s)) {
                                             //to make range +
                                             $f = self::$max_int;
                                         }
                                         if (floatval($f) === floatval($max)) {
                                             $f = self::$max_int;
                                         }
                                         //+++
                                         //http://codex.wordpress.org/Class_Reference/WP_Meta_Query
                                         /*
                                          $meta_query_array[] = array(
                                          'key'=>$search_key,
                                          'value'=>array( (float) $s, (float) $f ),
                                          'type'=>'DECIMAL',
                                          'compare'=>'BETWEEN'
                                          );
                                         */
                                         $meta_query_array[] = self::range_slider_multicontroller($widget_options['slug'], $search_key, (double) $s, (double) $f);
                                     }
                                 }
                                 break;
                             case 'select':
                                 if (!isset($html_item_data['select_range_value'])) {
                                     $html_item_data['select_range_value'] = 0;
                                 }
                                 if ($html_item_data['select_range_value'] == 1) {
                                     //look in range (0-500, 501-1000, 1001-2000 and etc...)
                                     list($from, $to) = explode('-', $value);
                                     $meta_query_array[] = array('key' => $search_key, 'value' => array(floatval($from), floatval($to)), 'compare' => "BETWEEN", 'type' => 'DECIMAL');
                                 } else {
                                     if ($value != '~') {
                                         $meta_query_array[] = array('key' => "{$search_key}", 'value' => "{$value}", 'compare' => '=');
                                     }
                                 }
                                 //~ - mean ANY in select and checkbox
                                 break;
                             default:
                                 //checkbox
                                 if ($value != '~') {
                                     $meta_query_array[] = array('key' => "{$search_key}", 'value' => "{$value}", 'compare' => '=');
                                 }
                                 //~ - mean ANY in select and checkbox
                                 break;
                         }
                     }
                 }
             }
         }
     }
     //lets cache it
     $_GLOBALS['MDF_META_QUERY_ARRAY'] = array($meta_query_array, $filter_post_blocks_data, $widget_options);
     return $_GLOBALS['MDF_META_QUERY_ARRAY'];
 }
Esempio n. 2
0
<?php

if (!defined('ABSPATH')) {
    die('No direct access allowed');
}
?>


<?php 
$res = array();
if (!empty($filter_posts)) {
    if (is_array($filter_posts)) {
        foreach ($filter_posts as $pid) {
            $tmp = MetaDataFilterPage::get_html_items($pid);
            if (!empty($tmp)) {
                if (is_array($tmp)) {
                    foreach ($tmp as $key => $value) {
                        $res[$key] = $value;
                    }
                }
            }
        }
    }
}
?>

<?php 
if (isset($_REQUEST['in_essentil_block'])) {
    ?>

    <?php