/** * Search all Grids and change the term IDs set in the selected terms if needed * @since: 2.1.0 **/ static function split_terms_fix($old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy) { $base = new Essential_Grid_Base(); $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) { $selected = json_decode($grid->postparams, true); $post_category = $base->getVar($selected, 'post_category'); $cat_tax = $base->getCatAndTaxData($post_category); $cats = array(); if (!empty($cat_tax['cats'])) { $cats = explode(',', $cat_tax['cats']); } $taxes = array('post_tag'); if (!empty($cat_tax['tax'])) { $taxes = explode(',', $cat_tax['tax']); } $cont = false; if (!empty($cats)) { foreach ($cats as $cat) { if ($old_term_id == $cat && in_array($taxonomy, $taxes)) { //ID needs to be changed foreach ($taxes as $t) { //replace all occuring old term id with the new term id and then Save the Grid $post_category = str_replace($t . '_' . $old_term_id, $t . '_' . $new_term_id, $post_category); } $selected['post_category'] = $post_category; $grid->postparams = $selected; $grid->params = json_decode($grid->params, true); $grid->layers = json_decode($grid->layers, true); $new_grid = (array) $grid; //cast to array as update_create_grid expects an array Essential_Grid_Admin::update_create_grid($new_grid); //now delete cache of the Grid so that changes take effect immediately 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); } $cont = true; } if ($cont == true) { break; } } } } } }
public function export_grids($export_grids) { $return_grids = array(); if ($export_grids !== false && !empty($export_grids)) { $c_grid = new Essential_Grid(); $base = new Essential_Grid_Base(); $item_skin = new Essential_Grid_Item_Skin(); $grids = $c_grid->get_essential_grids(); if (!empty($grids)) { foreach ($export_grids as $e_grid_id) { foreach ($grids as $grid) { $grid = (array) $grid; if ($e_grid_id == $grid['id']) { //change categories/tags id to slug $check = json_decode($grid['postparams'], true); if (isset($check['post_category']) && !empty($check['post_category'])) { $slug_cats = array(); $the_cats = explode(',', $check['post_category']); foreach ($the_cats as $cat) { $raw = explode('_', $cat); $catSlug = $raw[count($raw) - 1]; unset($raw[count($raw) - 1]); $cat = implode('_', $raw); $category = $base->get_categories_by_ids((array) $catSlug, $cat); foreach ($category as $cat_obj) { $slug_cats[] = $cat . '_' . $cat_obj->slug; } } $check['post_category'] = implode(',', $slug_cats); $grid['postparams'] = json_encode($check); } //change choosen skinid to skinhandle $check = json_decode($grid['params'], true); if (isset($check['entry-skin']) && !empty($check['entry-skin']) && intval($check['entry-skin']) != 0) { $skin = $item_skin->get_handle_by_id($check['entry-skin']); if (!empty($skin)) { $check['entry-skin'] = $skin['handle']; } $grid['params'] = json_encode($check); } $return_grids[] = $grid; break; } } } } } return $return_grids; }
/** * 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; } }
case 'last_modified': $order['last_modified'] = $saved_sorting['order'] == 'asc' ? 'ASC' : 'DESC'; $selected['last_modified'] = $saved_sorting['order'] == 'desc' ? 'asc' : 'desc'; break; case 'favorite': $order['favorite'] = $saved_sorting['order'] == 'asc' ? 'ASC' : 'DESC'; $selected['favorite'] = $saved_sorting['order'] == 'desc' ? 'asc' : 'desc'; break; case 'name': default: $order['name'] = $saved_sorting['order'] == 'asc' ? 'ASC' : 'DESC'; $selected['name'] = $saved_sorting['order'] == 'desc' ? 'asc' : 'desc'; break; } } $grids = Essential_Grid::get_essential_grids($order); $limit = @intval($saved_sorting['limit']) > 0 ? @intval($saved_sorting['limit']) : 10; $otype = 'reg'; $total = 0; $pagenum = isset($saved_sorting['pagenum']) ? absint($saved_sorting['pagenum']) : 1; $offset = ($pagenum - 1) * $limit; $cur_offset = 0; ?> <h2 class="topheader"><?php _e('Overview', EG_TEXTDOMAIN); ?> </h2> <div id="eg-global-settings-wrap"> <a target="_blank" class="button-secondary" href="http://themepunch.com/essential/documentation/"><?php _e('Help', EG_TEXTDOMAIN); ?>
/** * @package Essential_Grid * @author ThemePunch <*****@*****.**> * @link http://www.themepunch.com/essential/ * @copyright 2014 ThemePunch */ if (!defined('ABSPATH')) { exit; } $c_grids = new Essential_Grid(); $item_skin = new Essential_Grid_Item_Skin(); $item_ele = new Essential_Grid_Item_Element(); $nav_skin = new Essential_Grid_Navigation(); $metas = new Essential_Grid_Meta(); $fonts = new ThemePunch_Fonts(); $grids = $c_grids->get_essential_grids(); $skins = $item_skin->get_essential_item_skins(); $elements = $item_ele->get_essential_item_elements(); $navigation_skins = $nav_skin->get_essential_navigation_skins(); $custom_metas = $metas->get_all_meta(); $custom_fonts = $fonts->get_all_fonts(); $token = wp_create_nonce("Essential_Grid_actions"); $import_data = false; if (isset($_FILES['import_file'])) { if ($_FILES['import_file']['error'] > 0) { echo '<div class="error"><p>' . __('Invalid file or file size too big.', EG_TEXTDOMAIN) . '</p></div>'; } else { $file_name = $_FILES['import_file']['name']; $ext = explode(".", $file_name); $file_ext = strtolower(end($ext)); $file_size = $_FILES['import_file']['size'];
public function import_grids($import_grids, $import_ids = true, $check_append = true) { if ($import_grids !== false && !empty($import_grids)) { global $wpdb; $c_grid = new Essential_Grid(); $base = new Essential_Grid_Base(); $table_name = $wpdb->prefix . Essential_Grid::TABLE_GRID; $item_skin = new Essential_Grid_Item_Skin(); $grids = $c_grid->get_essential_grids(); foreach ($import_grids as $i_grid) { if (!empty($import_ids) && is_array($import_ids)) { $found = false; foreach ($import_ids as $id) { if ($i_grid['id'] == $id) { $found = true; break; } } if (!$found) { continue; } } else { if ($import_ids != true) { //only break if we do not want to import all break; } } //create/get category and tags if there are some selected $check = json_decode($i_grid['postparams'], true); if (isset($check['post_category']) && !empty($check['post_category'])) { $slug_cats = array(); $the_cats = explode(',', $check['post_category']); foreach ($the_cats as $cat) { $raw = explode('_', $cat); $catSlug = $raw[count($raw) - 1]; unset($raw[count($raw) - 1]); $cat = implode('_', $raw); $category = $base->get_create_category_by_slug($catSlug, $cat); if ($category !== false) { //only add if we have a ID $slug_cats[] = $cat . '_' . $category; } } $check['post_category'] = implode(',', $slug_cats); $i_grid['postparams'] = json_encode($check); } $check = json_decode($i_grid['params'], true); if (isset($check['entry-skin']) && !empty($check['entry-skin'])) { $skin = $item_skin->get_id_by_handle($check['entry-skin']); if (!empty($skin)) { $check['entry-skin'] = $skin['id']; } $i_grid['params'] = json_encode($check); } $exist = false; if (!empty($grids)) { foreach ($grids as $grid) { if ($grid->handle == $i_grid['handle']) { $i_grid['id'] = $grid->id; //this will force an update $exist = true; break; } } } if ($import_ids === true) { //do not insert if handle exists. This is for the import demo data process if ($exist) { continue; } } $append = true; if ($exist) { //skin exists - append or overwrite if ($check_append) { //check in data if append or overwrite $do = $base->getVar($this->overwrite_data, 'element-overwrite-' . $i_grid['id'], 'append'); $append = $do == 'append' ? true : false; } } if ($import_ids !== true) { if ($append) { //append if ($exist) { $i_grid['handle'] = $i_grid['handle'] . '-' . date('His'); $i_grid['name'] = $i_grid['name'] . '-' . date('His'); } $response = $wpdb->insert($table_name, array('name' => $i_grid['name'], 'handle' => $i_grid['handle'], 'postparams' => $i_grid['postparams'], 'params' => $i_grid['params'], 'layers' => $i_grid['layers'])); } else { //overwrite $response = $wpdb->update($table_name, array('name' => $i_grid['name'], 'handle' => $i_grid['handle'], 'postparams' => $i_grid['postparams'], 'params' => $i_grid['params'], 'layers' => $i_grid['layers']), array('id' => $i_grid['id'])); } } else { //create or overwrite if ($exist) { $response = $wpdb->update($table_name, array('name' => $i_grid['name'], 'handle' => $i_grid['handle'], 'postparams' => $i_grid['postparams'], 'params' => $i_grid['params'], 'layers' => $i_grid['layers']), array('id' => $i_grid['id'])); } else { $response = $wpdb->insert($table_name, array('name' => $i_grid['name'], 'handle' => $i_grid['handle'], 'postparams' => $i_grid['postparams'], 'params' => $i_grid['params'], 'layers' => $i_grid['layers'])); } } } } }
public function export_essential_grid() { require_once ABSPATH . 'wp-content/plugins/essential-grid/essential-grid.php'; $c_grid = new Essential_Grid(); $export_grids = array(); $grids = $c_grid->get_essential_grids(); foreach ($grids as $grid) { $export_grids[] = $grid->id; } $export_skins = array(); $item_skin = new Essential_Grid_Item_Skin(); $skins = $item_skin->get_essential_item_skins('all', false); foreach ($skins as $skin) { $export_grids[] = $skin['id']; } $export_elements = array(); $c_elements = new Essential_Grid_Item_Element(); $elements = $c_elements->get_essential_item_elements(); foreach ($elements as $element) { $export_elements[] = $element['id']; } $export_navigation_skins = array(); $c_nav_skins = new Essential_Grid_Navigation(); $nav_skins = $c_nav_skins->get_essential_navigation_skins(); foreach ($nav_skins as $nav_skin) { $export_navigation_skins[] = $nav_skin['id']; } $export_custom_meta = array(); $metas = new Essential_Grid_Meta(); $custom_metas = $metas->get_all_meta(); foreach ($custom_metas as $custom_meta) { $export_custom_meta[] = $custom_meta['handle']; } $export_punch_fonts = array(); $fonts = new ThemePunch_Fonts(); $custom_fonts = $fonts->get_all_fonts(); foreach ($custom_fonts as $custom_font) { $export_punch_fonts[] = $custom_font['handle']; } $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 $export['global-css'] = $ex->export_global_styles('on'); $this->save_as_txt_file('essential_grid.txt', json_encode($export)); }