/** * widget output */ public function widget($args, $instance) { $grid_id = $instance["ess_grid"]; $title = @$instance["ess_grid_title"]; if (empty($grid_id)) { return false; } $base = new Essential_Grid_Base(); $grid = new Essential_Grid(); $grids = $grid->get_grids_short_widgets(); if (!isset($grids[$grid_id])) { return false; } $grid_handle = $grids[$grid_id]; //widget output $beforeWidget = $args["before_widget"]; $afterWidget = $args["after_widget"]; $beforeTitle = $args["before_title"]; $afterTitle = $args["after_title"]; echo $beforeWidget; if (!empty($title)) { echo $beforeTitle . $title . $afterTitle; } if ($base->is_shortcode_with_handle_exist($grid_handle)) { $my_grid = $grid->init_by_id($grid_id); if (!$my_grid) { return false; } //be silent $grid->output_grid_sorting(); } echo $afterWidget; }
/** * 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; }
/** * Handle Ajax Requests */ public static function on_front_ajax_action() { $base = new Essential_Grid_Base(); $token = $base->getPostVar("token", false); //verify the token $isVerified = wp_verify_nonce($token, 'Essential_Grid_Front'); $error = false; if ($isVerified) { $data = $base->getPostVar('data', false); //client_action: load_more_items switch ($base->getPostVar('client_action', false)) { case 'load_more_items': $gridid = $base->getPostVar('gridid', 0, 'i'); if (!empty($data) && $gridid > 0) { $grid = new Essential_Grid(); $result = $grid->init_by_id($gridid); if (!$result) { $error = __('Grid not found', EG_TEXTDOMAIN); } else { $grid->set_loading_ids($data); //set to only load choosen items $html = false; //check if we are custom grid if ($grid->is_custom_grid()) { $html = $grid->output_by_specific_ids(); } else { $html = $grid->output_by_specific_posts(); } if ($html !== false) { self::ajaxResponseData($html); } else { $error = __('Items Not Found', EG_TEXTDOMAIN); } } } else { $error = __('No Data Received', EG_TEXTDOMAIN); } break; case 'load_more_content': $postid = $base->getPostVar('postid', 0, 'i'); if ($postid > 0) { $raw_content = get_post_field('post_content', $postid); if (!is_wp_error($raw_content)) { $content = apply_filters('the_content', $raw_content); //filter apply for qTranslate and other self::ajaxResponseData($content); } } $error = __('Post Not Found', EG_TEXTDOMAIN); break; case 'get_search_results': $search_string = $base->getVar($data, 'search', ''); $search_skin = $base->getVar($data, 'skin', 0, 'i'); if ($search_string !== '' && $search_skin > 0) { $search = new Essential_Grid_Search(); $return = $search->output_search_result($search_string, $search_skin); self::ajaxResponseData($return); } $error = __('Not found', EG_TEXTDOMAIN); break; case 'get_grid_search_ids': $search_string = $base->getVar($data, 'search', ''); $grid_id = $base->getVar($data, 'id', 0, 'i'); if ($search_string !== '' && $grid_id > 0) { $return = Essential_Grid_Search::output_search_result_ids($search_string, $grid_id); if (!is_array($return)) { $error = $return; } else { self::ajaxResponseSuccess('', $return); } } $error = __('Not found', EG_TEXTDOMAIN); break; } } else { $error = true; } if ($error !== false) { $showError = __('Loading Error', EG_TEXTDOMAIN); if ($error !== true) { $showError = $error; } self::ajaxResponseError($showError, false); } exit; }