Example #1
0
 /**
  * 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;
 }