Exemplo n.º 1
0
 public function set_sorting_text($san_text)
 {
     if (strpos($san_text, 'eg-') === 0) {
         $meta = new Essential_Grid_Meta();
         $m = $meta->get_all_meta(false);
         if (!empty($m)) {
             foreach ($m as $me) {
                 if ('eg-' . $me['handle'] == $san_text) {
                     return $me['name'];
                 }
             }
         }
     } elseif (strpos($san_text, 'egl-') === 0) {
         $meta = new Essential_Grid_Meta_Linking();
         $m = $meta->get_all_link_meta(false);
         if (!empty($m)) {
             foreach ($m as $me) {
                 if ('egl-' . $me['handle'] == $san_text) {
                     return $me['name'];
                 }
             }
         }
     } else {
         switch ($san_text) {
             case 'date':
                 $san_text = __('Date', EG_TEXTDOMAIN);
                 break;
             case 'title':
                 $san_text = __('Title', EG_TEXTDOMAIN);
                 break;
             case 'excerpt':
                 $san_text = __('Excerpt', EG_TEXTDOMAIN);
                 break;
             case 'id':
                 $san_text = __('ID', EG_TEXTDOMAIN);
                 break;
             case 'slug':
                 $san_text = __('Slug', EG_TEXTDOMAIN);
                 break;
             case 'author':
                 $san_text = __('Author', EG_TEXTDOMAIN);
                 break;
             case 'last-modified':
                 $san_text = __('Last Modified', EG_TEXTDOMAIN);
                 break;
             case 'number-of-comments':
                 $san_text = __('Comments', EG_TEXTDOMAIN);
                 break;
             case 'meta_num_total_sales':
                 $san_text = __('Total Sales', EG_TEXTDOMAIN);
                 break;
             case 'meta_num__regular_price':
                 $san_text = __('Regular Price', EG_TEXTDOMAIN);
                 break;
             case 'meta_num__sale_price':
                 $san_text = __('Sale Price', EG_TEXTDOMAIN);
                 break;
             case 'meta__featured':
                 $san_text = __('Featured', EG_TEXTDOMAIN);
                 break;
             case 'meta__sku':
                 $san_text = __('SKU', EG_TEXTDOMAIN);
                 break;
             case 'meta_num_stock':
                 $san_text = __('In Stock', EG_TEXTDOMAIN);
                 break;
             default:
                 $san_text = ucfirst($san_text);
                 break;
         }
     }
     return $san_text;
 }
Exemplo n.º 2
0
<?php

if (!defined('ABSPATH')) {
    exit;
}
//force the js file to be included
wp_enqueue_script('essential-grid-item-editor-script', plugins_url('../../assets/js/grid-editor.js', __FILE__), array('jquery'), Essential_Grid::VERSION);
$base = new Essential_Grid_Base();
$item_elements = new Essential_Grid_Item_Element();
$meta = new Essential_Grid_Meta();
$meta_link = new Essential_Grid_Meta_Linking();
$fonts = new ThemePunch_Fonts();
//check if id exists and get data from database if so.
$skin = false;
$skin_id = false;
$isCreate = $base->getGetVar('create', 'true');
$title = __('Create New Item Skin', EG_TEXTDOMAIN);
$save = __('Save Item Skin', EG_TEXTDOMAIN);
if (intval($isCreate) > 0) {
    //currently editing
    $skin = Essential_Grid_Item_Skin::get_essential_item_skin_by_id(intval($isCreate));
    if (!empty($skin)) {
        $title = __('Change Item Skin', EG_TEXTDOMAIN);
        $save = __('Change Item Skin', EG_TEXTDOMAIN);
        $skin_id = intval($isCreate);
    }
}
$elements = $item_elements->getElementsForJavascript();
$style_attributes = $item_elements->get_existing_elements(true);
$all_attributes = $item_elements->get_existing_elements();
$element_type = $item_elements->getElementsForDropdown();
Exemplo n.º 3
0
 /**
  * Receive all Posts by given IDs
  */
 public static function get_posts_by_ids($ids, $sort_by = 'none', $sort_order = 'DESC')
 {
     $query = array('post__in' => $ids, 'post_type' => 'any', 'order' => $sort_order, 'numberposts' => count($ids));
     if (strpos($sort_by, 'eg-') === 0) {
         $meta = new Essential_Grid_Meta();
         $m = $meta->get_all_meta(false);
         if (!empty($m)) {
             foreach ($m as $me) {
                 if ('eg-' . $me['handle'] == $sort_by) {
                     $sort_by = isset($me['sort-type']) && $me['sort-type'] == 'numeric' ? 'meta_num_' . $sort_by : 'meta_' . $sort_by;
                     break;
                 }
             }
         }
     } elseif (strpos($sort_by, 'egl-') === 0) {
         //change to meta_num_ or meta_ depending on setting
         $sortfound = false;
         $link_meta = new Essential_Grid_Meta_Linking();
         $m = $link_meta->get_all_link_meta();
         if (!empty($m)) {
             foreach ($m as $me) {
                 if ('egl-' . $me['handle'] == $sort_by) {
                     $sort_by = isset($me['sort-type']) && $me['sort-type'] == 'numeric' ? 'meta_num_' . $me['original'] : 'meta_' . $me['original'];
                     $sortfound = true;
                     break;
                 }
             }
         }
         if (!$sortfound) {
             $sort_by = 'none';
         }
     }
     //add sort by (could be by meta)
     if (strpos($sort_by, "meta_num_") === 0) {
         $metaKey = str_replace("meta_num_", "", $sort_by);
         $query["orderby"] = "meta_value_num";
         $query["meta_key"] = $metaKey;
     } else {
         if (strpos($sort_by, "meta_") === 0) {
             $metaKey = str_replace("meta_", "", $sort_by);
             $query["orderby"] = "meta_value";
             $query["meta_key"] = $metaKey;
         } else {
             $query["orderby"] = $sort_by;
         }
     }
     $objQuery = get_posts($query);
     $arrPosts = $objQuery;
     foreach ($arrPosts as $key => $post) {
         if (method_exists($post, "to_array")) {
             $arrPost = $post->to_array();
         } else {
             $arrPost = (array) $post;
         }
         $arrPosts[$key] = $arrPost;
     }
     return $arrPosts;
 }
 /**
  * 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;
     }
 }
Exemplo n.º 5
0
 /**
  * replace all metas with corresponding text
  */
 public function replace_all_meta_in_text($post_id, $text)
 {
     if (trim($text) === '' || intval($post_id) === 0) {
         return '';
     }
     $base = new Essential_Grid_Base();
     $meta_link = new Essential_Grid_Meta_Linking();
     $cmeta = $this->get_all_meta();
     //process meta tags:
     $arr_matches = array();
     preg_match_all("/%[^%]*%/", $text, $arr_matches);
     if (!empty($arr_matches)) {
         $my_post = get_post($post_id, ARRAY_A);
         foreach ($arr_matches as $matches) {
             if (is_array($matches)) {
                 foreach ($matches as $match) {
                     $meta = trim(str_replace('%', '', $match));
                     $meta_value = get_post_meta($post_id, $meta, true);
                     if (!empty($cmeta)) {
                         foreach ($cmeta as $me) {
                             if ('eg-' . $me['handle'] == $meta) {
                                 if ($me['type'] == 'image') {
                                     if (intval($meta_value) > 0) {
                                         //get URL to Image
                                         $img = wp_get_attachment_image_src($meta_value, 'full');
                                         if ($img !== false) {
                                             $meta_value = $img[0];
                                         } else {
                                             $meta_value = '';
                                         }
                                     } else {
                                         $meta_value = '';
                                     }
                                 }
                                 if ($meta_value == '' && isset($me['default'])) {
                                     $meta_value = $me['default'];
                                 }
                                 break;
                             }
                         }
                     }
                     //check woocommerce
                     if (Essential_Grid_Woocommerce::is_woo_exists()) {
                         $wc_text = Essential_Grid_Woocommerce::get_value_by_meta($post_id, $meta);
                         if ($wc_text !== '') {
                             $meta_value = $wc_text;
                         }
                     }
                     if (empty($meta_value) && !empty($my_post)) {
                         //try to get from post
                         switch ($meta) {
                             //Post elements
                             case 'post_url':
                                 $post_id = $base->getVar($my_post, 'ID', '');
                                 $meta_value = get_permalink($post_id);
                                 break;
                             case 'post_id':
                                 $meta_value = $base->getVar($my_post, 'ID', '');
                                 break;
                             case 'title':
                                 $meta_value = $base->getVar($my_post, 'post_title', '');
                                 break;
                             case 'excerpt':
                                 $meta_value = trim($base->getVar($my_post, 'post_excerpt'));
                                 if (empty($meta_value)) {
                                     $meta_value = trim($base->getVar($my_post, 'post_content'));
                                 }
                                 $meta_value = strip_tags($meta_value);
                                 //,"<b><br><br/><i><strong><small>"
                                 break;
                             case 'meta':
                                 $m = new Essential_Grid_Meta();
                                 $meta_value = $m->get_meta_value_by_handle($my_post['ID'], $meta);
                                 break;
                             case 'alias':
                                 $meta_value = $base->getVar($my_post, 'post_name');
                                 break;
                             case 'content':
                                 $meta_value = $base->getVar($my_post, 'post_content');
                                 break;
                             case 'link':
                                 $meta_value = get_permalink($my_post['ID']);
                                 break;
                             case 'date':
                                 $postDate = $base->getVar($my_post, "post_date_gmt");
                                 $meta_value = $base->convert_post_date($postDate);
                                 break;
                             case 'date_modified':
                                 $dateModified = $base->getVar($my_post, "post_modified");
                                 $meta_value = $base->convert_post_date($dateModified);
                                 break;
                             case 'author_name':
                                 $authorID = $base->getVar($my_post, 'post_author');
                                 $meta_value = get_the_author_meta('display_name', $authorID);
                                 break;
                             case 'num_comments':
                                 $meta_value = $base->getVar($my_post, 'comment_count');
                                 break;
                             case 'cat_list':
                                 $use_taxonomies = false;
                                 $postCatsIDs = $base->getVar($my_post, 'post_category');
                                 if (empty($postCatsIDs) && isset($my_post['post_type'])) {
                                     $postCatsIDs = array();
                                     $obj = get_object_taxonomies($my_post['post_type']);
                                     if (!empty($obj) && is_array($obj)) {
                                         foreach ($obj as $tax) {
                                             $use_taxonomies[] = $tax;
                                             $new_terms = get_the_terms($my_post['ID'], $tax);
                                             if (is_array($new_terms) && !empty($new_terms)) {
                                                 foreach ($new_terms as $term) {
                                                     $postCatsIDs[$term->term_id] = $term->term_id;
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 $meta_value = $base->get_categories_html_list($postCatsIDs, true, ',', $use_taxonomies);
                                 break;
                             case 'tag_list':
                                 $meta_value = $base->get_tags_html_list($my_post['ID']);
                                 break;
                             default:
                                 $meta_value = apply_filters('essgrid_post_meta_content', $meta_value, $meta, $my_post['ID'], $my_post);
                                 break;
                                 break;
                         }
                         if (empty($meta_value)) {
                             //check if its linking
                             $meta_value = $meta_link->get_link_meta_value_by_handle($my_post['ID'], $meta);
                         }
                     }
                     $text = str_replace($match, $meta_value, $text);
                 }
             }
         }
     }
     return $text;
 }
Exemplo n.º 6
0
<?php

/**
 * @package   Essential_Grid
 * @author    ThemePunch <*****@*****.**>
 * @link      http://www.themepunch.com/essential/
 * @copyright 2014 ThemePunch
 */
//force the js file to be included
//wp_enqueue_script('essential-grid-item-editor-script', EG_PLUGIN_URL.'admin/assets/js/grid-editor.js', array('jquery'), Essential_Grid::VERSION );
$metas = new Essential_Grid_Meta();
$meta_links = new Essential_Grid_Meta_Linking();
?>
	<h2 class="topheader"><?php 
echo esc_html(get_admin_page_title());
?>
</h2>
	
	<div id="eg-grid-custom-meta-wrapper">
		<ul class="es-grid-meta-tabs">
			<li><a href="#eg-custom-meta-wrap"><?php 
_e('Custom Meta', EG_TEXTDOMAIN);
?>
</a></li>
			<li><a href="#eg-meta-links-wrap"><?php 
_e('Meta References / Aliases', EG_TEXTDOMAIN);
?>
</a></li>
		</ul>
		<div id="eg-custom-meta-wrap">
			<div class="eg-custom-meta-info-box" style="padding:10px 15px; margin-bottom:15px;background:#3498db; color:#fff;">
Exemplo n.º 7
0
 public function prepare_sorting_array_by_post($post, $order_by)
 {
     $base = new Essential_Grid_Base();
     $link_meta = new Essential_Grid_Meta_Linking();
     $meta = new Essential_Grid_Meta();
     $m = $meta->get_all_meta(false);
     $lm = $link_meta->get_all_link_meta(false);
     $sorts = array();
     foreach ($order_by as $order) {
         switch ($order) {
             case 'date':
                 $sorts['date'] = strtotime($base->getVar($post, 'post_date'));
                 break;
             case 'title':
                 $sorts['title'] = substr($base->getVar($post, 'post_title', ''), 0, 10);
                 break;
             case 'excerpt':
                 $sorts['excerpt'] = substr(strip_tags($base->getVar($post, 'post_excerpt', '')), 0, 10);
                 break;
             case 'id':
                 $sorts['id'] = $base->getVar($post, 'ID');
                 break;
             case 'slug':
                 $sorts['slug'] = $base->getVar($post, 'post_name');
                 break;
             case 'author':
                 $authorID = $base->getVar($post, 'post_author');
                 $sorts['author'] = get_the_author_meta('display_name', $authorID);
                 break;
             case 'last-modified':
                 $sorts['last-modified'] = strtotime($base->getVar($post, 'post_modified'));
                 break;
             case 'number-of-comments':
                 $sorts['number-of-comments'] = $base->getVar($post, 'comment_count');
                 break;
             case 'random':
                 $sorts['random'] = rand(0, 9999);
                 break;
             default:
                 //check if meta. If yes, add meta values
                 if (strpos($order, 'eg-') === 0) {
                     if (!empty($m)) {
                         foreach ($m as $me) {
                             if ('eg-' . $me['handle'] == $order) {
                                 $sorts[$order] = $meta->get_meta_value_by_handle($post['ID'], $order);
                                 break;
                             }
                         }
                     }
                 } elseif (strpos($order, 'egl-') === 0) {
                     if (!empty($lm)) {
                         foreach ($lm as $me) {
                             if ('egl-' . $me['handle'] == $order) {
                                 $sorts[$order] = $link_meta->get_link_meta_value_by_handle($post['ID'], $order);
                                 break;
                             }
                         }
                     }
                 }
                 break;
         }
     }
     //add woocommerce sortings
     if (Essential_Grid_Woocommerce::is_woo_exists()) {
         $product = get_product($post['ID']);
         if (!empty($product)) {
             foreach ($order_by as $order) {
                 switch ($order) {
                     case 'meta_num_total_sales':
                         $sorts['total-sales'] = get_post_meta($post['ID'], $order, true);
                         break;
                     case 'meta_num__regular_price':
                         $sorts['regular-price'] = $product->get_price();
                         break;
                         //case 'meta_num__sale_price':
                         //	$sorts['sale-price'] = $product->get_sale_price();
                         //break;
                     //case 'meta_num__sale_price':
                     //	$sorts['sale-price'] = $product->get_sale_price();
                     //break;
                     case 'meta__featured':
                         $sorts['featured'] = $product->is_featured() ? '1' : '0';
                         break;
                     case 'meta__sku':
                         $sorts['sku'] = $product->get_sku();
                         break;
                     case 'meta_num_stock':
                         $sorts['in-stock'] = $product->get_stock_quantity();
                         break;
                 }
             }
         }
     }
     return $sorts;
 }
Exemplo n.º 8
0
 public function import_custom_meta($import_custom_meta, $import_handles = true, $check_append = true)
 {
     $base = new Essential_Grid_Base();
     $metas = new Essential_Grid_Meta();
     $link_metas = new Essential_Grid_Meta_Linking();
     $custom_metas = $metas->get_all_meta();
     foreach ($import_custom_meta as $i_custom_meta) {
         $type = isset($i_custom_meta['m_type']) && $i_custom_meta['m_type'] == 'link' ? 'link' : 'meta';
         if (!empty($import_handles) && is_array($import_handles)) {
             $found = false;
             foreach ($import_handles as $handle) {
                 if ($i_custom_meta['handle'] == $handle) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 continue;
             }
         } else {
             if ($import_handles !== true) {
                 break;
             }
         }
         $exist = false;
         if (!empty($custom_metas)) {
             foreach ($custom_metas as $meta) {
                 if ($meta['handle'] == $i_custom_meta['handle']) {
                     if ($type == $meta['m_type']) {
                         $exist = true;
                         break;
                     }
                 }
             }
         }
         if ($import_handles == 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 $_POST if append or overwrite
                 $do = $base->getVar($this->overwrite_data, 'custom-meta-overwrite-' . $i_custom_meta['handle'], 'append');
                 $append = $do == 'append' ? true : false;
             }
         }
         if ($import_handles !== true) {
             if ($append) {
                 //append
                 if ($exist) {
                     $orig_handle = $i_custom_meta['handle'];
                     $i_custom_meta['handle'] = $i_custom_meta['handle'] . '-' . date('His');
                     $i_custom_meta['name'] = $i_custom_meta['name'] . '-' . date('His');
                 }
                 if ($type == 'meta') {
                     $metas->add_new_meta($i_custom_meta);
                 } elseif ($type == 'link') {
                     $link_metas->add_new_link_meta($i_custom_meta);
                 }
             } else {
                 //overwrite
                 if ($type == 'meta') {
                     $metas->edit_meta_by_handle($i_custom_meta);
                 } elseif ($type == 'link') {
                     $link_metas->edit_link_meta_by_handle($i_custom_meta);
                 }
             }
         } else {
             //create or overwrite
             if ($exist) {
                 if ($type == 'meta') {
                     $metas->edit_meta_by_handle($i_custom_meta);
                 } elseif ($type == 'link') {
                     $link_metas->edit_link_meta_by_handle($i_custom_meta);
                 }
             } else {
                 if ($type == 'meta') {
                     $metas->add_new_meta($i_custom_meta);
                 } elseif ($type == 'link') {
                     $link_metas->add_new_link_meta($i_custom_meta);
                 }
             }
         }
     }
 }