Example #1
0
 /** 
  * return search result ID's
  * @since: 2.0
  */
 public static function output_search_result_ids($search, $grid_id = 0)
 {
     $grid_id = intval($grid_id);
     if ($search == '' || $grid_id === 0) {
         return __('Not found', EG_TEXTDOMAIN);
     }
     $grid = new Essential_Grid();
     if ($grid->init_by_id($grid_id) === false) {
         return __('Not found', EG_TEXTDOMAIN);
     }
     $base = new Essential_Grid_Base();
     $post_category = $grid->get_postparam_by_handle('post_category');
     $post_types = $grid->get_postparam_by_handle('post_types');
     $page_ids = explode(',', $grid->get_postparam_by_handle('selected_pages', '-1'));
     $start_sortby = $grid->get_param_by_handle('sorting-order-by-start', 'none');
     $start_sortby_type = $grid->get_param_by_handle('sorting-order-type', 'ASC');
     $max_entries = $grid->get_maximum_entries($grid);
     $cat_tax = Essential_Grid_Base::getCatAndTaxData($post_category);
     $additional_query = $grid->get_postparam_by_handle('additional-query', '');
     if ($additional_query !== '') {
         $additional_query .= '&s=' . $search;
     } else {
         $additional_query .= 's=' . $search;
     }
     $additional_query = wp_parse_args($additional_query);
     ob_start();
     $posts = Essential_Grid_Base::getPostsByCategory($grid_id, $cat_tax['cats'], $post_types, $cat_tax['tax'], $page_ids, $start_sortby, $start_sortby_type, $max_entries, $additional_query, false);
     ob_clean();
     ob_end_clean();
     if (empty($posts) || count($posts) === 0) {
         return __('Not found', EG_TEXTDOMAIN);
     }
     $ids = array();
     foreach ($posts as $post) {
         $ids[] = $post['ID'];
     }
     return $ids;
 }
Example #2
0
 /**
  * Register Shortcode For Filter
  * @since: 1.5.0
  */
 public static function register_shortcode_filter($args, $mid_content = null)
 {
     extract(shortcode_atts(array('alias' => '', 'id' => ''), $args, 'ess_grid_nav'));
     if ($alias == '') {
         return false;
     }
     //no alias found
     if ($id == '') {
         return false;
     }
     //no alias found
     $base = new Essential_Grid_Base();
     $meta_c = new Essential_Grid_Meta();
     $output_protection = get_option('tp_eg_output_protection', 'none');
     $content = '';
     ob_start();
     $grid = new Essential_Grid();
     $grid_id = self::get_id_by_alias($alias);
     if ($grid_id > 0) {
         $navigation_c = new Essential_Grid_Navigation($grid_id);
         $grid->init_by_id($grid_id);
         $layout = $grid->get_param_by_handle('navigation-layout', array());
         $navig_special_class = $grid->get_param_by_handle('navigation-special-class', array());
         //has all classes in an ordered list
         $navig_special_skin = $grid->get_param_by_handle('navigation-special-skin', array());
         //has all classes in an ordered list
         $special_class = '';
         $special_skin = '';
         if ($id == 'sort') {
             $id = 'sorting';
         }
         //Check if selected element is in external list and also get the key to use it to get class
         if (isset($layout[$id]) && isset($layout[$id]['external'])) {
             $special_class = @$navig_special_class[$layout[$id]['external']];
             $special_skin = @$navig_special_skin[$layout[$id]['external']];
         } else {
             //its not in external set so break since its only allowed to use each element one time
             return false;
         }
         $navigation_c->set_special_class($special_class);
         $navigation_c->set_special_class($special_skin);
         $navigation_c->set_special_class('esg-fgc-' . $grid_id);
         $filter = false;
         switch ($id) {
             case 'sorting':
                 $order_by_start = $grid->get_param_by_handle('sorting-order-by-start', 'none');
                 $sort_by_text = $grid->get_param_by_handle('sort-by-text', __('Sort By ', EG_TEXTDOMAIN));
                 $order_by = explode(',', $grid->get_param_by_handle('sorting-order-by', 'date'));
                 if (!is_array($order_by)) {
                     $order_by = array($order_by);
                 }
                 //set order of filter
                 $navigation_c->set_orders_text($sort_by_text);
                 $navigation_c->set_orders_start($order_by_start);
                 $navigation_c->set_orders($order_by);
                 $navigation_c->output_sorting();
                 break;
             case 'cart':
                 $navigation_c->output_cart();
                 break;
             case 'left':
                 $navigation_c->output_navigation_left();
                 break;
             case 'right':
                 $navigation_c->output_navigation_right();
                 break;
             case 'pagination':
                 $navigation_c->output_pagination();
                 break;
             case 'search-input':
                 $search_text = $grid->get_param_by_handle('search-text', __('Search...', EG_TEXTDOMAIN));
                 $navigation_c->set_search_text($search_text);
                 $navigation_c->output_search_input();
                 break;
             case 'filter':
                 $id = 1;
                 $filter = true;
                 break;
             default:
                 //check for filter
                 if (strpos($id, 'filter-') !== false) {
                     $id = intval(str_replace('filter-', '', $id));
                     $filter = true;
                 } else {
                     return false;
                 }
                 break;
         }
         /*****
          * Complex Filter Part
          *****/
         if ($filter === true) {
             $start_sortby = $grid->get_param_by_handle('sorting-order-by-start', 'none');
             $start_sortby_type = $grid->get_param_by_handle('sorting-order-type', 'ASC');
             $post_category = $grid->get_postparam_by_handle('post_category');
             $post_types = $grid->get_postparam_by_handle('post_types');
             $page_ids = explode(',', $grid->get_postparam_by_handle('selected_pages', '-1'));
             $cat_relation = $grid->get_postparam_by_handle('category-relation', 'OR');
             $max_entries = $grid->get_maximum_entries($grid);
             $additional_query = $grid->get_postparam_by_handle('additional-query', '');
             if ($additional_query !== '') {
                 $additional_query = wp_parse_args($additional_query);
             }
             $cat_tax = Essential_Grid_Base::getCatAndTaxData($post_category);
             $posts = Essential_Grid_Base::getPostsByCategory($grid_id, $cat_tax['cats'], $post_types, $cat_tax['tax'], $page_ids, $start_sortby, $start_sortby_type, $max_entries, $additional_query, true, $cat_relation);
             $nav_filters = array();
             $taxes = array('post_tag');
             if (!empty($cat_tax['tax'])) {
                 $taxes = explode(',', $cat_tax['tax']);
             }
             if (!empty($cat_tax['cats'])) {
                 $cats = explode(',', $cat_tax['cats']);
                 foreach ($cats as $key => $cid) {
                     if (Essential_Grid_Wpml::is_wpml_exists() && isset($sitepress)) {
                         $new_id = icl_object_id($cid, 'category', true, $sitepress->get_default_language());
                         $cat = get_category($new_id);
                     } else {
                         $cat = get_category($cid);
                     }
                     if (is_object($cat)) {
                         $nav_filters[$cid] = array('name' => $cat->cat_name, 'slug' => sanitize_key($cat->slug), 'parent' => $cat->category_parent);
                     }
                     foreach ($taxes as $custom_tax) {
                         $term = get_term_by('id', $cid, $custom_tax);
                         if (is_object($term)) {
                             $nav_filters[$cid] = array('name' => $term->name, 'slug' => sanitize_key($term->slug), 'parent' => $term->parent);
                         }
                     }
                 }
                 if (!empty($filters_meta)) {
                     $nav_filters = $filters_meta + $nav_filters;
                 }
                 asort($nav_filters);
             }
             if ($id == 1) {
                 $all_text = $grid->get_param_by_handle('filter-all-text');
                 $listing_type = $grid->get_param_by_handle('filter-listing', 'list');
                 $listing_text = $grid->get_param_by_handle('filter-dropdown-text');
                 $show_count = $grid->get_param_by_handle('filter-counter', 'off');
                 $selected = $grid->get_param_by_handle('filter-selected', array());
             } else {
                 $all_text = $grid->get_param_by_handle('filter-all-text-' . $id);
                 $listing_type = $grid->get_param_by_handle('filter-listing-' . $id, 'list');
                 $listing_text = $grid->get_param_by_handle('filter-dropdown-text-' . $id);
                 $show_count = $grid->get_param_by_handle('filter-counter-' . $id, 'off');
                 $selected = $grid->get_param_by_handle('filter-selected-' . $id, array());
             }
             $filter_allow = $grid->get_param_by_handle('filter-arrows', 'single');
             $filter_start = $grid->get_param_by_handle('filter-start', '');
             $filter_grouping = $grid->get_param_by_handle('filter-grouping', 'false');
             //check the selected and change metas to correct fields
             $filters_arr['filter-grouping'] = $filter_grouping;
             $filters_arr['filter-listing'] = $listing_type;
             $filters_arr['filter-selected'] = $selected;
             if (!empty($filters_arr['filter-selected'])) {
                 if (!empty($posts) && count($posts) > 0) {
                     foreach ($filters_arr['filter-selected'] as $fk => $filter) {
                         if (strpos($filter, 'meta-') === 0) {
                             unset($filters_arr['filter-selected'][$fk]);
                             //delete entry
                             foreach ($posts as $key => $post) {
                                 $fil = str_replace('meta-', '', $filter);
                                 $post_filter_meta = $meta_c->get_meta_value_by_handle($post['ID'], 'eg-' . $fil);
                                 $arr = json_decode($post_filter_meta, true);
                                 $cur_filter = is_array($arr) ? $arr : array($post_filter_meta);
                                 //$cur_filter = explode(',', $post_filter_meta);
                                 $add_filter = array();
                                 if (!empty($cur_filter)) {
                                     foreach ($cur_filter as $k => $v) {
                                         if (trim($v) !== '') {
                                             $add_filter[sanitize_key($v)] = array('name' => $v, 'slug' => sanitize_key($v), 'parent' => '0');
                                             if (!empty($filters_arr['filter-selected'])) {
                                                 $filter_found = false;
                                                 foreach ($filters_arr['filter-selected'] as $fcheck) {
                                                     if ($fcheck == sanitize_key($v)) {
                                                         $filter_found = true;
                                                         break;
                                                     }
                                                 }
                                                 if (!$filter_found) {
                                                     $filters_arr['filter-selected'][] = sanitize_key($v);
                                                     //add found meta
                                                 }
                                             } else {
                                                 $filters_arr['filter-selected'][] = sanitize_key($v);
                                                 //add found meta
                                             }
                                         }
                                     }
                                     if (!empty($add_filter)) {
                                         $navigation_c->set_filter($add_filter);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($all_text == '' || $listing_type == '' || $listing_text == '' || empty($filters_arr['filter-selected'])) {
                 return false;
             }
             $navigation_c->set_filter_settings('filter', $filters_arr);
             $navigation_c->set_filter_text($all_text);
             $navigation_c->set_dropdown_text($listing_text);
             $navigation_c->set_show_count($show_count);
             $navigation_c->set_filter_type($filter_allow);
             $navigation_c->set_filter_start_select($filter_start);
             $found_filter = array();
             if (!empty($posts) && count($posts) > 0) {
                 foreach ($posts as $key => $post) {
                     //check if post should be visible or if its invisible on current grid settings
                     $is_visible = $grid->check_if_visible($post['ID'], $grid_id);
                     if ($is_visible == false) {
                         continue;
                     }
                     // continue if invisible
                     $filters = array();
                     //$categories = get_the_category($post['ID']);
                     $categories = $base->get_custom_taxonomies_by_post_id($post['ID']);
                     //$tags = wp_get_post_terms($post['ID']);
                     $tags = get_the_tags($post['ID']);
                     if (!empty($categories)) {
                         foreach ($categories as $key => $category) {
                             $filters[$category->term_id] = array('name' => $category->name, 'slug' => sanitize_key($category->slug), 'parent' => $category->parent);
                         }
                     }
                     if (!empty($tags)) {
                         foreach ($tags as $key => $taxonomie) {
                             $filters[$taxonomie->term_id] = array('name' => $taxonomie->name, 'slug' => sanitize_key($taxonomie->slug), 'parent' => '0');
                         }
                     }
                     $filter_meta_selected = $grid->get_param_by_handle('filter-selected', array());
                     if (!empty($filter_meta_selected)) {
                         foreach ($filter_meta_selected as $filter) {
                             if (strpos($filter, 'meta-') === 0) {
                                 $fil = str_replace('meta-', '', $filter);
                                 $post_filter_meta = $meta_c->get_meta_value_by_handle($post['ID'], 'eg-' . $fil);
                                 $arr = json_decode($post_filter_meta, true);
                                 $cur_filter = is_array($arr) ? $arr : array($post_filter_meta);
                                 //$cur_filter = explode(',', $post_filter_meta);
                                 if (!empty($cur_filter)) {
                                     foreach ($cur_filter as $k => $v) {
                                         if (trim($v) !== '') {
                                             $filters[sanitize_key($v)] = array('name' => $v, 'slug' => sanitize_key($v), 'parent' => '0');
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $found_filter = $found_filter + $filters;
                     //these are the found filters, only show filter that the posts have
                 }
             }
             $remove_filter = array_diff_key($nav_filters, $found_filter);
             //check if we have filter that no post has (comes through multilanguage)
             if (!empty($remove_filter)) {
                 foreach ($remove_filter as $key => $rem) {
                     //we have, so remove them from the filter list before setting the filter list
                     unset($found_filter[$key]);
                 }
             }
             $navigation_c->set_filter($found_filter);
             //set filters $nav_filters $found_filter
             $navigation_c->output_filter_unwrapped();
         }
     }
     $content = ob_get_contents();
     ob_clean();
     ob_end_clean();
     //handle output types
     switch ($output_protection) {
         case 'compress':
             $content = str_replace("\n", '', $content);
             $content = str_replace("\r", '', $content);
             return $content;
             break;
         case 'echo':
             echo $content;
             //bypass the filters
             break;
         default:
             //normal output
             return $content;
             break;
     }
 }