/**
  * Handle Ajax Requests
  */
 public static function on_ajax_action()
 {
     try {
         $token = self::getPostVar('token', false);
         //verify the token
         $isVerified = wp_verify_nonce($token, 'Essential_Grid_actions');
         $error = false;
         if ($isVerified) {
             $data = self::getPostVar("data", false);
             switch (self::getPostVar("client_action", false)) {
                 case 'add_google_fonts':
                     $f = new ThemePunch_Fonts();
                     $result = $f->add_new_font($data);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Font successfully created!", EG_TEXTDOMAIN), array('data' => $result, 'is_redirect' => true, 'redirect_url' => self::getFontsUrl()));
                     } else {
                         Essential_Grid::ajaxResponseError($result, false);
                     }
                     break;
                 case 'remove_google_fonts':
                     if (!isset($data['handle'])) {
                         Essential_Grid::ajaxResponseError(__('Font not found', EG_TEXTDOMAIN), false);
                     }
                     $f = new ThemePunch_Fonts();
                     $result = $f->remove_font_by_handle($data['handle']);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Font successfully removed!", EG_TEXTDOMAIN), array('data' => $result));
                     } else {
                         Essential_Grid::ajaxResponseError($result, false);
                     }
                     break;
                 case 'edit_google_fonts':
                     if (!isset($data['handle'])) {
                         Essential_Grid::ajaxResponseError(__('No handle given', EG_TEXTDOMAIN), false);
                     }
                     if (!isset($data['url'])) {
                         Essential_Grid::ajaxResponseError(__('No parameters given', EG_TEXTDOMAIN), false);
                     }
                     $f = new ThemePunch_Fonts();
                     $result = $f->edit_font_by_handle($data);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Font successfully changed!", EG_TEXTDOMAIN), array('data' => $result));
                     } else {
                         Essential_Grid::ajaxResponseError($result, false);
                     }
                     break;
                 case 'add_custom_meta':
                     $m = new Essential_Grid_Meta();
                     $result = $m->add_new_meta($data);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Meta successfully created!", EG_TEXTDOMAIN), array('data' => $result, 'is_redirect' => true, 'redirect_url' => self::getSubViewUrl(Essential_Grid_Admin::VIEW_SUB_CUSTOM_META_AJAX)));
                     } else {
                         Essential_Grid::ajaxResponseError($result, false);
                     }
                     break;
                 case 'remove_custom_meta':
                     if (!isset($data['handle'])) {
                         Essential_Grid::ajaxResponseError(__('Meta not found', EG_TEXTDOMAIN), false);
                     }
                     $m = new Essential_Grid_Meta();
                     $result = $m->remove_meta_by_handle($data['handle']);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Meta successfully removed!", EG_TEXTDOMAIN), array('data' => $result));
                     } else {
                         Essential_Grid::ajaxResponseError($result, false);
                     }
                     break;
                 case 'edit_custom_meta':
                     if (!isset($data['handle'])) {
                         Essential_Grid::ajaxResponseError(__('No handle given', EG_TEXTDOMAIN), false);
                     }
                     if (!isset($data['name'])) {
                         Essential_Grid::ajaxResponseError(__('No name given', EG_TEXTDOMAIN), false);
                     }
                     $m = new Essential_Grid_Meta();
                     $result = $m->edit_meta_by_handle($data);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Meta successfully changed!", EG_TEXTDOMAIN), array('data' => $result));
                     } else {
                         Essential_Grid::ajaxResponseError($result, false);
                     }
                     break;
                 case 'add_link_meta':
                     $m = new Essential_Grid_Meta_Linking();
                     $result = $m->add_new_link_meta($data);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Meta successfully created!", EG_TEXTDOMAIN), array('data' => $result, 'is_redirect' => true, 'redirect_url' => self::getSubViewUrl(Essential_Grid_Admin::VIEW_SUB_CUSTOM_META_AJAX)));
                     } else {
                         Essential_Grid::ajaxResponseError($result, false);
                     }
                     break;
                 case 'remove_link_meta':
                     if (!isset($data['handle'])) {
                         Essential_Grid::ajaxResponseError(__('Meta not found', EG_TEXTDOMAIN), false);
                     }
                     $m = new Essential_Grid_Meta_Linking();
                     $result = $m->remove_link_meta_by_handle($data['handle']);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Meta successfully removed!", EG_TEXTDOMAIN), array('data' => $result));
                     } else {
                         Essential_Grid::ajaxResponseError($result, false);
                     }
                     break;
                 case 'edit_link_meta':
                     if (!isset($data['handle'])) {
                         Essential_Grid::ajaxResponseError(__('No handle given', EG_TEXTDOMAIN), false);
                     }
                     if (!isset($data['name'])) {
                         Essential_Grid::ajaxResponseError(__('No name given', EG_TEXTDOMAIN), false);
                     }
                     if (!isset($data['original'])) {
                         Essential_Grid::ajaxResponseError(__('No original given', EG_TEXTDOMAIN), false);
                     }
                     $m = new Essential_Grid_Meta_Linking();
                     $result = $m->edit_link_meta_by_handle($data);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Meta successfully changed!", EG_TEXTDOMAIN), array('data' => $result));
                     } else {
                         Essential_Grid::ajaxResponseError($result, false);
                     }
                     break;
                 case 'add_widget_area':
                     $wa = new Essential_Grid_Widget_Areas();
                     $result = $wa->add_new_sidebar($data);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Widget Area successfully created!", EG_TEXTDOMAIN), array('data' => $result, 'is_redirect' => true, 'redirect_url' => self::getSubViewUrl(Essential_Grid_Admin::VIEW_SUB_WIDGET_AREA_AJAX)));
                     } else {
                         Essential_Grid::ajaxResponseError($result, false);
                     }
                     break;
                 case 'edit_widget_area':
                     if (!isset($data['handle'])) {
                         Essential_Grid::ajaxResponseError(__('No handle given', EG_TEXTDOMAIN), false);
                     }
                     if (!isset($data['name'])) {
                         Essential_Grid::ajaxResponseError(__('No name given', EG_TEXTDOMAIN), false);
                     }
                     $wa = new Essential_Grid_Widget_Areas();
                     $result = $wa->edit_widget_area_by_handle($data);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Widget Area successfully changed!", EG_TEXTDOMAIN), array('data' => $result));
                     } else {
                         Essential_Grid::ajaxResponseError($result, false);
                     }
                     break;
                 case 'remove_widget_area':
                     if (!isset($data['handle'])) {
                         Essential_Grid::ajaxResponseError(__('Widget Area not found', EG_TEXTDOMAIN), false);
                     }
                     $wa = new Essential_Grid_Widget_Areas();
                     $result = $wa->remove_widget_area_by_handle($data['handle']);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Widget Area successfully removed!", EG_TEXTDOMAIN), array('data' => $result));
                     } else {
                         Essential_Grid::ajaxResponseError($result, false);
                     }
                     break;
                 case 'get_preview_html_markup':
                     //add wpml transient
                     $lang_code = '';
                     if (Essential_Grid_Wpml::is_wpml_exists()) {
                         $lang_code = Essential_Grid_Wpml::get_current_lang_code();
                     }
                     if (isset($data['id'])) {
                         delete_transient('ess_grid_trans_query_' . $data['id'] . $lang_code);
                         //delete cache
                     }
                     $result = Essential_Grid_Base::output_demo_skin_html($data);
                     if (isset($result['error'])) {
                         Essential_Grid::ajaxResponseData($result);
                     } else {
                         Essential_Grid::ajaxResponseData(array("data" => array('html' => $result['html'], 'preview' => @$result['preview'])));
                     }
                     break;
                     /* //TP: CHUNK
                     			case 'get_preview_html_markup_chunk': //only for custom grid
                     				$grid = new Essential_Grid();
                     				$grid->init_by_data($data);
                     				
                     				$html = '';
                     				
                     				if($grid->is_custom_grid()){
                     					ob_start();
                     					$grid->output_by_custom('custom', true);
                     					$html = ob_get_contents();
                     					ob_clean();
                     					ob_end_clean();
                     				}
                     				$order_id = self::getPostVar("order_id", false);
                     				
                     				Essential_Grid::ajaxResponseData(array("data"=>array('preview' => $html, 'order_id' => $order_id)));
                     				
                     			break; */
                 /* //TP: CHUNK
                 			case 'get_preview_html_markup_chunk': //only for custom grid
                 				$grid = new Essential_Grid();
                 				$grid->init_by_data($data);
                 				
                 				$html = '';
                 				
                 				if($grid->is_custom_grid()){
                 					ob_start();
                 					$grid->output_by_custom('custom', true);
                 					$html = ob_get_contents();
                 					ob_clean();
                 					ob_end_clean();
                 				}
                 				$order_id = self::getPostVar("order_id", false);
                 				
                 				Essential_Grid::ajaxResponseData(array("data"=>array('preview' => $html, 'order_id' => $order_id)));
                 				
                 			break; */
                 case 'save_search_settings':
                     if (!empty($data)) {
                         update_option('esg-search-settings', $data);
                     }
                     Essential_Grid::ajaxResponseSuccess(__("Search Settings succesfully saved!", EG_TEXTDOMAIN));
                     break;
                 case 'update_general_settings':
                     $result = self::savePluginPermission($data['permission']);
                     $cur_query = get_option('tp_eg_query_type', 'wp_query');
                     update_option('tp_eg_output_protection', @$data['protection']);
                     update_option('tp_eg_tooltips', @$data['tooltips']);
                     update_option('tp_eg_wait_for_fonts', @$data['wait_for_fonts']);
                     update_option('tp_eg_js_to_footer', @$data['js_to_footer']);
                     update_option('tp_eg_use_cache', @$data['use_cache']);
                     update_option('tp_eg_query_type', @$data['query_type']);
                     update_option('tp_eg_enable_log', @$data['enable_log']);
                     update_option('tp_eg_use_lightbox', @$data['use_lightbox']);
                     if (@$data['use_lightbox'] === 'jackbox') {
                         Essential_Grid_Jackbox::enable_jackbox();
                     } else {
                         Essential_Grid_Jackbox::disable_jackbox();
                     }
                     if ($cur_query !== $data['query_type']) {
                         //delete cache
                         $lang = array();
                         if (Essential_Grid_Wpml::is_wpml_exists()) {
                             $lang = icl_get_languages();
                         }
                         $grids = Essential_Grid::get_essential_grids();
                         if (!empty($grids)) {
                             foreach ($grids as $grid) {
                                 if (!empty($lang)) {
                                     foreach ($lang as $code => $val) {
                                         delete_transient('ess_grid_trans_query_' . $grid->id . $val['language_code']);
                                         delete_transient('ess_grid_trans_full_grid_' . $grid->id . $val['language_code']);
                                     }
                                 } else {
                                     delete_transient('ess_grid_trans_query_' . $grid->id);
                                     delete_transient('ess_grid_trans_full_grid_' . $grid->id);
                                 }
                             }
                         }
                     }
                     if ($result !== true) {
                         $error = __("Global Settings did not change!", EG_TEXTDOMAIN);
                     } else {
                         Essential_Grid::ajaxResponseSuccess(__("Global Settings succesfully saved!", EG_TEXTDOMAIN), $result);
                     }
                     break;
                 case 'update_create_grid':
                     $result = self::update_create_grid($data);
                     if ($result !== true) {
                         $error = $result;
                     } else {
                         $lang = array();
                         if (Essential_Grid_Wpml::is_wpml_exists()) {
                             $lang = icl_get_languages();
                         }
                         if (isset($data['id']) && intval($data['id']) > 0) {
                             if (!empty($lang)) {
                                 foreach ($lang as $code => $val) {
                                     delete_transient('ess_grid_trans_query_' . $data['id'] . $val['language_code']);
                                     //delete cache
                                     delete_transient('ess_grid_trans_full_grid_' . $data['id'] . $val['language_code']);
                                     //delete cache
                                 }
                             } else {
                                 delete_transient('ess_grid_trans_query_' . $data['id']);
                                 //delete cache
                                 delete_transient('ess_grid_trans_full_grid_' . $data['id']);
                                 //delete cache
                             }
                             Essential_Grid::ajaxResponseSuccess(__("Grid successfully saved/changed!", EG_TEXTDOMAIN), $result);
                         } else {
                             Essential_Grid::ajaxResponseSuccess(__("Grid successfully saved/changed!", EG_TEXTDOMAIN), array('data' => $result, 'is_redirect' => true, 'redirect_url' => self::getViewUrl(Essential_Grid_Admin::VIEW_OVERVIEW)));
                         }
                     }
                     break;
                 case 'delete_grid':
                     $result = self::delete_grid_by_id($data);
                     if ($result !== true) {
                         $error = $result;
                     } else {
                         Essential_Grid::ajaxResponseSuccess(__("Grid deleted", EG_TEXTDOMAIN), array('data' => $result, 'is_redirect' => true, 'redirect_url' => self::getViewUrl(Essential_Grid_Admin::VIEW_OVERVIEW)));
                     }
                     break;
                 case 'duplicate_grid':
                     $result = self::duplicate_grid_by_id($data);
                     if ($result !== true) {
                         $error = $result;
                     } else {
                         Essential_Grid::ajaxResponseSuccess(__("Grid duplicated", EG_TEXTDOMAIN), array('data' => $result, 'is_redirect' => true, 'redirect_url' => self::getViewUrl(Essential_Grid_Admin::VIEW_OVERVIEW)));
                     }
                     break;
                 case 'update_create_item_skin':
                     $result = Essential_Grid_Item_Skin::update_save_item_skin($data);
                     if ($result !== true) {
                         $error = $result;
                     } else {
                         if (isset($data['id']) && intval($data['id']) > 0) {
                             Essential_Grid::ajaxResponseSuccess(__("Item Skin changed", EG_TEXTDOMAIN), array('data' => $result));
                         } else {
                             Essential_Grid::ajaxResponseSuccess(__("Item Skin created/changed", EG_TEXTDOMAIN), array('data' => $result, 'is_redirect' => true, 'redirect_url' => self::getViewUrl("", "", 'essential-' . Essential_Grid_Admin::VIEW_SUB_ITEM_SKIN_OVERVIEW)));
                         }
                     }
                     break;
                 case 'update_custom_css':
                     if (isset($data['global_css'])) {
                         Essential_Grid_Global_Css::set_global_css_styles($data['global_css']);
                         Essential_Grid::ajaxResponseSuccess(__("CSS saved!", EG_TEXTDOMAIN), '');
                     } else {
                         $error = __("No CSS Received", EG_TEXTDOMAIN);
                     }
                     break;
                 case 'delete_item_skin':
                     $result = Essential_Grid_Item_Skin::delete_item_skin_by_id($data);
                     if ($result !== true) {
                         $error = $result;
                     } else {
                         Essential_Grid::ajaxResponseSuccess(__("Item Skin deleted", EG_TEXTDOMAIN), array('data' => $result));
                     }
                     break;
                 case 'duplicate_item_skin':
                     $result = Essential_Grid_Item_Skin::duplicate_item_skin_by_id($data);
                     if ($result !== true) {
                         $error = $result;
                     } else {
                         Essential_Grid::ajaxResponseSuccess(__("Item Skin duplicated", EG_TEXTDOMAIN), array('data' => $result, 'is_redirect' => true, 'redirect_url' => self::getViewUrl("", "", 'essential-' . Essential_Grid_Admin::VIEW_SUB_ITEM_SKIN_OVERVIEW)));
                     }
                     break;
                 case 'star_item_skin':
                     $result = Essential_Grid_Item_Skin::star_item_skin_by_id($data);
                     if ($result !== true) {
                         $error = $result;
                     } else {
                         Essential_Grid::ajaxResponseSuccess(__("Favorite Changed", EG_TEXTDOMAIN), array('data' => $result));
                     }
                     break;
                 case 'update_create_item_element':
                     $result = Essential_Grid_Item_Element::update_create_essential_item_element($data);
                     if ($result !== true) {
                         $error = $result;
                     } else {
                         Essential_Grid::ajaxResponseSuccess(__("Item Element created/changed", EG_TEXTDOMAIN), array('data' => $result));
                     }
                     break;
                 case 'check_item_element_existence':
                     $result = Essential_Grid_Item_Element::check_existence_by_handle(@$data['name']);
                     if ($result === false) {
                         Essential_Grid::ajaxResponseData(array("data" => array('existence' => 'false')));
                     } elseif ($result === true) {
                         Essential_Grid::ajaxResponseData(array("data" => array('existence' => 'true')));
                     } else {
                         Essential_Grid::ajaxResponseData(array("data" => array('existence' => $result)));
                     }
                     break;
                 case 'get_predefined_elements':
                     $elements = Essential_Grid_Item_Element::getElementsForJavascript();
                     $html_elements = Essential_Grid_Item_Element::prepareDefaultElementsForEditor();
                     $html_elements .= Essential_Grid_Item_Element::prepareTextElementsForEditor();
                     Essential_Grid::ajaxResponseData(array("data" => array('elements' => $elements, 'html' => $html_elements)));
                     break;
                 case 'delete_predefined_elements':
                     $result = Essential_Grid_Item_Element::delete_element_by_handle($data);
                     if ($result !== true) {
                         $error = $result;
                     } else {
                         Essential_Grid::ajaxResponseSuccess(__("Item Element successfully deleted", EG_TEXTDOMAIN), array('data' => $result));
                     }
                     break;
                 case 'update_create_navigation_skin_css':
                     $nav = new Essential_Grid_Navigation();
                     $result = $nav->update_create_navigation_skin_css($data);
                     if ($result !== true) {
                         $error = $result;
                     } else {
                         $base = new Essential_Grid_Base();
                         $skin_css = Essential_Grid_Navigation::output_navigation_skins();
                         $skins = Essential_Grid_Navigation::get_essential_navigation_skins();
                         $select = '';
                         foreach ($skins as $skin) {
                             $select .= '<option value="' . $skin['handle'] . '">' . $skin['name'] . '</option>' . "\n";
                         }
                         if (isset($data['sid']) && intval($data['sid']) > 0) {
                             Essential_Grid::ajaxResponseSuccess(__("Navigation Skin successfully changed!", EG_TEXTDOMAIN), array('css' => $skin_css, 'select' => $select, 'default_skins' => $skins));
                         } else {
                             Essential_Grid::ajaxResponseSuccess(__("Navigation Skin successfully created", EG_TEXTDOMAIN), array('css' => $skin_css, 'select' => $select, 'default_skins' => $skins));
                         }
                     }
                     break;
                 case 'delete_navigation_skin_css':
                     $nav = new Essential_Grid_Navigation();
                     $result = $nav->delete_navigation_skin_css($data);
                     if ($result !== true) {
                         $error = $result;
                     } else {
                         $base = new Essential_Grid_Base();
                         $skin_css = Essential_Grid_Navigation::output_navigation_skins();
                         $skins = Essential_Grid_Navigation::get_essential_navigation_skins();
                         $select = '';
                         foreach ($skins as $skin) {
                             $select .= '<option value="' . $skin['handle'] . '">' . $skin['name'] . '</option>' . "\n";
                         }
                         Essential_Grid::ajaxResponseSuccess(__("Navigation Skin successfully deleted!", EG_TEXTDOMAIN), array('css' => $skin_css, 'select' => $select, 'default_skins' => $skins));
                     }
                     break;
                 case 'get_post_meta_html_for_editor':
                     if (!isset($data['post_id']) || intval($data['post_id']) == 0) {
                         Essential_Grid::ajaxResponseError(__('No Post ID/Wrong Post ID!', EG_TEXTDOMAIN), false);
                         exit;
                     }
                     if (!isset($data['grid_id']) || intval($data['grid_id']) == 0) {
                         Essential_Grid::ajaxResponseError(__('Please save the grid first to use this feature!', EG_TEXTDOMAIN), false);
                         exit;
                     }
                     $post = get_post($data['post_id']);
                     $disable_advanced = true;
                     //nessecary, so that only normal things can be changed in preview mode
                     if (!empty($post)) {
                         $grid_id = $data['grid_id'];
                         ob_start();
                         require 'views/elements/grid-meta-box.php';
                         $content = ob_get_contents();
                         ob_clean();
                         ob_end_clean();
                         Essential_Grid::ajaxResponseData(array("data" => array('html' => $content)));
                     } else {
                         Essential_Grid::ajaxResponseError(__('Post not found!', EG_TEXTDOMAIN), false);
                         exit;
                     }
                     break;
                 case 'update_post_meta_through_editor':
                     if (!isset($data['metas']) || !isset($data['metas']['post_id']) || intval($data['metas']['post_id']) == 0) {
                         Essential_Grid::ajaxResponseError(__('No Post ID/Wrong Post ID!', EG_TEXTDOMAIN), false);
                         exit;
                     }
                     if (!isset($data['metas']) || !isset($data['metas']['grid_id']) || intval($data['metas']['grid_id']) == 0) {
                         Essential_Grid::ajaxResponseError(__('Please save the grid first to use this feature!', EG_TEXTDOMAIN), false);
                         exit;
                     }
                     //set the cobbles setting to the post
                     $cobbles = json_decode(get_post_meta($data['metas']['post_id'], 'eg_cobbles', true), true);
                     $cobbles[$data['metas']['grid_id']]['cobbles'] = $data['metas']['eg_cobbles_size'];
                     $cobbles = json_encode($cobbles);
                     update_post_meta($data['metas']['post_id'], 'eg_cobbles', $cobbles);
                     //set the use_skin setting to the post
                     $use_skin = json_decode(get_post_meta($data['metas']['post_id'], 'eg_use_skin', true), true);
                     $use_skin[$data['metas']['grid_id']]['use-skin'] = $data['metas']['eg_use_skin'];
                     $use_skin = json_encode($use_skin);
                     update_post_meta($data['metas']['post_id'], 'eg_use_skin', $use_skin);
                     $result = self::custom_meta_box_save($data['metas']['post_id'], $data['metas'], true);
                     self::check_for_transient_deletion($data['metas']['post_id']);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__("Post Meta saved!", EG_TEXTDOMAIN), array());
                     } else {
                         Essential_Grid::ajaxResponseError(__('Post not found!', EG_TEXTDOMAIN), false);
                         exit;
                     }
                     break;
                 case 'trigger_post_meta_visibility':
                     if (!isset($data['post_id']) || intval($data['post_id']) == 0) {
                         Essential_Grid::ajaxResponseError(__('No Post ID/Wrong Post ID!', EG_TEXTDOMAIN), false);
                         exit;
                     }
                     if (!isset($data['grid_id']) || intval($data['grid_id']) == 0) {
                         Essential_Grid::ajaxResponseError(__('Please save the grid first to use this feature!', EG_TEXTDOMAIN), false);
                         exit;
                     }
                     $visibility = json_decode(get_post_meta($data['post_id'], 'eg_visibility', true), true);
                     $found = false;
                     if (!empty($visibility) && is_array($visibility)) {
                         foreach ($visibility as $grid => $setting) {
                             if ($grid == $data['grid_id']) {
                                 if ($setting == false) {
                                     $visibility[$grid] = true;
                                 } else {
                                     $visibility[$grid] = false;
                                 }
                                 $found = true;
                                 break;
                             }
                         }
                     }
                     if (!$found) {
                         $visibility[$data['grid_id']] = false;
                     }
                     $visibility = json_encode($visibility);
                     update_post_meta($data['post_id'], 'eg_visibility', $visibility);
                     self::check_for_transient_deletion($data['post_id']);
                     Essential_Grid::ajaxResponseSuccess(__("Visibility of Post for this Grid changed!", EG_TEXTDOMAIN), array());
                     break;
                 case 'get_image_by_id':
                     if (!isset($data['img_id']) || intval($data['img_id']) == 0) {
                         $error = __('Wrong Image ID given', EG_TEXTDOMAIN);
                     } else {
                         $img = wp_get_attachment_image_src($data['img_id'], 'full');
                         if ($img !== false) {
                             Essential_Grid::ajaxResponseSuccess('', array('url' => $img[0]));
                         } else {
                             $error = __('Image with given ID does not exist', EG_TEXTDOMAIN);
                         }
                     }
                     break;
                 case 'activate_purchase_code':
                     $result = false;
                     if (!empty($data['username']) && !empty($data['api_key']) && !empty($data['code'])) {
                         $result = Essential_Grid_Admin::check_purchase_verification($data);
                     } else {
                         $error = __('The API key, the Purchase Code and the Username need to be set!', EG_TEXTDOMAIN);
                     }
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__('Purchase Code Successfully Activated', EG_TEXTDOMAIN), array('data' => $result, 'is_redirect' => true, 'redirect_url' => self::getViewUrl("", "", 'essential-' . Essential_Grid_Admin::VIEW_START)));
                     } else {
                         if ($result !== false) {
                             $error = $result;
                         } else {
                             $error = __('Purchase Code is invalid', EG_TEXTDOMAIN);
                         }
                         Essential_Grid::ajaxResponseError($error, false);
                         exit;
                     }
                     break;
                 case 'deactivate_purchase_code':
                     $result = Essential_Grid_Admin::do_purchase_deactivation($data);
                     if ($result === true) {
                         Essential_Grid::ajaxResponseSuccess(__('Successfully removed validation', EG_TEXTDOMAIN), array('data' => $result, 'is_redirect' => true, 'redirect_url' => self::getViewUrl("", "", 'essential-' . Essential_Grid_Admin::VIEW_START)));
                     } else {
                         if ($result !== false) {
                             $error = $result;
                         } else {
                             $error = __('Could not remove Validation!', EG_TEXTDOMAIN);
                         }
                         Essential_Grid::ajaxResponseError($error, false);
                         exit;
                     }
                     break;
                 case 'dismiss_notice':
                     update_option('tp_eg_valid-notice', 'false');
                     Essential_Grid::ajaxResponseSuccess('.');
                     break;
                 case 'import_default_post_data':
                     try {
                         require EG_PLUGIN_PATH . 'includes/assets/default-posts.php';
                         require EG_PLUGIN_PATH . 'includes/assets/default-grids-meta-fonts.php';
                         if (isset($json_tax)) {
                             $import_tax = new PunchPost();
                             $import_tax->import_taxonomies($json_tax);
                         }
                         //insert meta, grids & punchfonts
                         $im = new Essential_Grid_Import();
                         if (isset($tp_grid_meta_fonts)) {
                             $tp_grid_meta_fonts = json_decode($tp_grid_meta_fonts, true);
                             $grids = @$tp_grid_meta_fonts['grids'];
                             if (!empty($grids) && is_array($grids)) {
                                 $grids_imported = $im->import_grids($grids);
                             }
                             $custom_metas = @$tp_grid_meta_fonts['custom-meta'];
                             if (!empty($custom_metas) && is_array($custom_metas)) {
                                 $custom_metas_imported = $im->import_custom_meta($custom_metas);
                             }
                             $custom_fonts = @$tp_grid_meta_fonts['punch-fonts'];
                             if (!empty($custom_fonts) && is_array($custom_fonts)) {
                                 $custom_fonts_imported = $im->import_punch_fonts($custom_fonts);
                             }
                         }
                         if (isset($json_posts)) {
                             $import = new PunchPort();
                             $import->set_tp_import_posts($json_posts);
                             $import->import_custom_posts();
                         }
                         Essential_Grid::ajaxResponseSuccess(__('Demo data successfully imported', EG_TEXTDOMAIN), array());
                     } catch (Exception $d) {
                         $error = __('Something went wrong, please contact the developer', EG_TEXTDOMAIN);
                     }
                     break;
                 case 'export_data':
                     $export_grids = self::getPostVar('export-grids-id', false);
                     $export_skins = self::getPostVar('export-skins-id', false);
                     $export_elements = self::getPostVar('export-elements-id', false);
                     $export_navigation_skins = self::getPostVar('export-navigation-skins-id', false);
                     $export_global_styles = self::getPostVar('export-global-styles', false);
                     $export_custom_meta = self::getPostVar('export-custom-meta-handle', false);
                     $export_punch_fonts = self::getPostVar('export-punch-fonts-handle', false);
                     header('Content-Type: text/json');
                     header('Content-Disposition: attachment;filename=ess_grid.json');
                     ob_start();
                     $export = array();
                     $ex = new Essential_Grid_Export();
                     //export Grids
                     if (!empty($export_grids)) {
                         $export['grids'] = $ex->export_grids($export_grids);
                     }
                     //export Skins
                     if (!empty($export_skins)) {
                         $export['skins'] = $ex->export_skins($export_skins);
                     }
                     //export Elements
                     if (!empty($export_elements)) {
                         $export['elements'] = $ex->export_elements($export_elements);
                     }
                     //export Navigation Skins
                     if (!empty($export_navigation_skins)) {
                         $export['navigation-skins'] = $ex->export_navigation_skins($export_navigation_skins);
                     }
                     //export Custom Meta
                     if (!empty($export_custom_meta)) {
                         $export['custom-meta'] = $ex->export_custom_meta($export_custom_meta);
                     }
                     //export Punch Fonts
                     if (!empty($export_punch_fonts)) {
                         $export['punch-fonts'] = $ex->export_punch_fonts($export_punch_fonts);
                     }
                     //export Global Styles
                     if ($export_global_styles == 'on') {
                         $export['global-css'] = $ex->export_global_styles($export_global_styles);
                     }
                     echo json_encode($export);
                     $content = ob_get_contents();
                     ob_clean();
                     ob_end_clean();
                     echo $content;
                     exit;
                     break;
                 case 'import_data':
                     if (!isset($data['imports']) || empty($data['imports'])) {
                         Essential_Grid::ajaxResponseError(__('No data for import selected', EG_TEXTDOMAIN), false);
                         exit;
                     }
                     try {
                         $im = new Essential_Grid_Import();
                         $temp_d = @$data['imports'];
                         unset($temp_d['data-grids']);
                         unset($temp_d['data-skins']);
                         unset($temp_d['data-elements']);
                         unset($temp_d['data-navigation-skins']);
                         unset($temp_d['data-global-css']);
                         $im->set_overwrite_data($temp_d);
                         //set overwrite data global to class
                         $skins = @$data['imports']['data-skins'];
                         if (!empty($skins) && is_array($skins)) {
                             foreach ($skins as $key => $skin) {
                                 $tskin = json_decode(stripslashes($skin), true);
                                 if (empty($tskin)) {
                                     $tskin = json_decode($skin, true);
                                 }
                                 $skins[$key] = $tskin;
                             }
                             if (!empty($skins)) {
                                 $skins_ids = @$data['imports']['import-skins-id'];
                                 $skins_imported = $im->import_skins($skins, $skins_ids);
                             }
                         }
                         $navigation_skins = @$data['imports']['data-navigation-skins'];
                         if (!empty($navigation_skins) && is_array($navigation_skins)) {
                             foreach ($navigation_skins as $key => $navigation_skin) {
                                 $tnavigation_skin = json_decode(stripslashes($navigation_skin), true);
                                 if (empty($tnavigation_skin)) {
                                     $tnavigation_skin = json_decode($navigation_skin, true);
                                 }
                                 $navigation_skins[$key] = $tnavigation_skin;
                             }
                             if (!empty($navigation_skins)) {
                                 $navigation_skins_ids = @$data['imports']['import-navigation-skins-id'];
                                 $navigation_skins_imported = $im->import_navigation_skins(@$navigation_skins, $navigation_skins_ids);
                             }
                         }
                         $grids = @$data['imports']['data-grids'];
                         if (!empty($grids) && is_array($grids)) {
                             foreach ($grids as $key => $grid) {
                                 $tgrid = json_decode(stripslashes($grid), true);
                                 if (empty($tgrid)) {
                                     $tgrid = json_decode($grid, true);
                                 }
                                 $grids[$key] = $tgrid;
                             }
                             if (!empty($grids)) {
                                 $grids_ids = @$data['imports']['import-grids-id'];
                                 $grids_imported = $im->import_grids($grids, $grids_ids);
                             }
                         }
                         $elements = @$data['imports']['data-elements'];
                         if (!empty($elements) && is_array($elements)) {
                             foreach ($elements as $key => $element) {
                                 $telement = json_decode(stripslashes($element), true);
                                 if (empty($telement)) {
                                     $telement = json_decode($element, true);
                                 }
                                 $elements[$key] = $telement;
                             }
                             if (!empty($elements)) {
                                 $elements_ids = @$data['imports']['import-elements-id'];
                                 $elements_imported = $im->import_elements(@$elements, $elements_ids);
                             }
                         }
                         $custom_metas = @$data['imports']['data-custom-meta'];
                         if (!empty($custom_metas) && is_array($custom_metas)) {
                             foreach ($custom_metas as $key => $custom_meta) {
                                 $tcustom_meta = json_decode(stripslashes($custom_meta), true);
                                 if (empty($tcustom_meta)) {
                                     $tcustom_meta = json_decode($custom_meta, true);
                                 }
                                 $custom_metas[$key] = $tcustom_meta;
                             }
                             if (!empty($custom_metas)) {
                                 $custom_metas_handle = @$data['imports']['import-custom-meta-handle'];
                                 $custom_metas_imported = $im->import_custom_meta($custom_metas, $custom_metas_handle);
                             }
                         }
                         $custom_fonts = @$data['imports']['data-punch-fonts'];
                         if (!empty($custom_fonts) && is_array($custom_fonts)) {
                             foreach ($custom_fonts as $key => $custom_font) {
                                 $tcustom_font = json_decode(stripslashes($custom_font), true);
                                 if (empty($tcustom_font)) {
                                     $tcustom_font = json_decode($custom_font, true);
                                 }
                                 $custom_fonts[$key] = $tcustom_font;
                             }
                             if (!empty($custom_fonts)) {
                                 $custom_fonts_handle = @$data['imports']['import-punch-fonts-handle'];
                                 $custom_fonts_imported = $im->import_punch_fonts($custom_fonts, $custom_fonts_handle);
                             }
                         }
                         if (@$data['imports']['import-global-styles'] == 'on') {
                             $global_css = @$data['imports']['data-global-css'];
                             $tglobal_css = stripslashes($global_css);
                             if (empty($tglobal_css)) {
                                 $tglobal_css = $global_css;
                             }
                             $global_styles_imported = $im->import_global_styles($tglobal_css);
                         }
                         Essential_Grid::ajaxResponseSuccess(__('Successfully imported data', EG_TEXTDOMAIN), array('is_redirect' => true, 'redirect_url' => self::getViewUrl("", "", 'essential-' . Essential_Grid_Admin::VIEW_START)));
                     } catch (Exception $d) {
                         $error = __('Something went wrong, please contact the developer', EG_TEXTDOMAIN);
                     }
                     break;
                 case 'delete_full_cache':
                     $lang = array();
                     if (Essential_Grid_Wpml::is_wpml_exists()) {
                         $lang = icl_get_languages();
                     }
                     $grids = Essential_Grid::get_essential_grids();
                     if (!empty($grids)) {
                         foreach ($grids as $grid) {
                             if (!empty($lang)) {
                                 foreach ($lang as $code => $val) {
                                     delete_transient('ess_grid_trans_query_' . $grid->id . $val['language_code']);
                                     delete_transient('ess_grid_trans_full_grid_' . $grid->id . $val['language_code']);
                                 }
                             } else {
                                 delete_transient('ess_grid_trans_query_' . $grid->id);
                                 delete_transient('ess_grid_trans_full_grid_' . $grid->id);
                             }
                         }
                     }
                     Essential_Grid::ajaxResponseSuccess(__('Successfully deleted all cache', EG_TEXTDOMAIN), array());
                     break;
                 case "get_image_url":
                     if (isset($data['imageid']) && intval($data['imageid']) > 0) {
                         $img_atts = wp_get_attachment_image_src($data['imageid']);
                         if ($img_atts !== false) {
                             $img_src = $img_atts[0];
                             Essential_Grid::ajaxResponseSuccess(__("Image URL found", EG_TEXTDOMAIN), array('url' => $img_src, 'imageid' => $data['imageid']));
                         }
                     }
                     $error = __('No correct image ID given', EG_TEXTDOMAIN);
                     break;
                 case "toggle_grid_favorite":
                     if (isset($data['id']) && intval($data['id']) > 0) {
                         $return = self::toggle_favorite_by_id($data['id']);
                         if ($return === true) {
                             Essential_Grid::ajaxResponseSuccess(__("Favorite Set", EG_TEXTDOMAIN));
                         } else {
                             $error = $return;
                         }
                     } else {
                         $error = __('No ID given', EG_TEXTDOMAIN);
                     }
                     break;
                 case "subscribe_to_newsletter":
                     if (isset($data['email']) && !empty($data['email'])) {
                         $return = ThemePunch_Newsletter::subscribe($data['email']);
                         if ($return !== false) {
                             if (!isset($return['status']) || $return['status'] === 'error') {
                                 $error = isset($return['message']) && !empty($return['message']) ? $return['message'] : __('Invalid Email', EG_TEXTDOMAIN);
                             } else {
                                 Essential_Grid::ajaxResponseSuccess(__("Success! Please check your Emails to finish the subscribtion", EG_TEXTDOMAIN), $return);
                             }
                         } else {
                             $error = __('Invalid Email/Could not connect to the Newsletter server', EG_TEXTDOMAIN);
                         }
                     } else {
                         $error = __('No Email given', EG_TEXTDOMAIN);
                     }
                     break;
                 case "unsubscribe_to_newsletter":
                     if (isset($data['email']) && !empty($data['email'])) {
                         $return = ThemePunch_Newsletter::unsubscribe($data['email']);
                         if ($return !== false) {
                             if (!isset($return['status']) || $return['status'] === 'error') {
                                 $error = isset($return['message']) && !empty($return['message']) ? $return['message'] : __('Invalid Email', EG_TEXTDOMAIN);
                             } else {
                                 Essential_Grid::ajaxResponseSuccess(__("Success! Please check your Emails to finish the process", EG_TEXTDOMAIN), $return);
                             }
                         } else {
                             $error = __('Invalid Email/Could not connect to the Newsletter server', EG_TEXTDOMAIN);
                         }
                     } else {
                         $error = __('No Email given', EG_TEXTDOMAIN);
                     }
                     break;
                 default:
                     $error = true;
                     break;
             }
         } else {
             $error = true;
         }
         if ($error !== false) {
             $showError = __("Wrong Request!", EG_TEXTDOMAIN);
             if ($error !== true) {
                 $showError = __("Ajax Error: ", EG_TEXTDOMAIN) . $error;
             }
             Essential_Grid::ajaxResponseError($showError, false);
         }
         exit;
     } catch (Exception $e) {
         exit;
     }
 }
Пример #2
0
 * @link      http://www.themepunch.com/essential/
 * @copyright 2014 ThemePunch
 * @since 1.0.6
 */
if (!defined('ABSPATH')) {
    exit;
}
?>
	<h2 class="topheader"><?php 
_e('Custom Widgets', EG_TEXTDOMAIN);
?>
</h2>
	
	<div id="eg-grid-widget-areas-wrapper">
		<?php 
$wa = new Essential_Grid_Widget_Areas();
$sidebars = $wa->get_all_sidebars();
if (is_array($sidebars) && !empty($sidebars)) {
    foreach ($sidebars as $handle => $name) {
        ?>
				<div class="postbox eg-postbox" style="width:100%;min-width:500px">
					<h3 class="box-closed"><span style="font-weight:400"><?php 
        _e('Handle:', EG_TEXTDOMAIN);
        ?>
</span><span>eg-<?php 
        echo $handle;
        ?>
 </span><div class="postbox-arrow"></div></h3>
					<div class="inside" style="display:none;padding:0px !important;margin:0px !important;height:100%;position:relative;background:#ebebeb">
						<input type="hidden" name="esg-widget-area-handle[]" value="<?php 
        echo $handle;