Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
6652 lines (5735 sloc) 301 KB
<?php
/**
* Admin functions.
*
* @since 1.0.0
* @package GeoDirectory
*/
/**
* Updates option value when GeoDirectory get deactivated.
*
* @since 1.0.0
* @package GeoDirectory
*/
function geodir_deactivation() {
// Update installed variable
update_option("geodir_installed", 0);
// Remove rewrite rules and then recreate rewrite rules.
flush_rewrite_rules();
}
if (!function_exists('geodir_admin_styles')) {
/**
* Enqueue Admin Styles.
*
* @since 1.0.0
* @package GeoDirectory
*/
function geodir_admin_styles() {
wp_register_style('geodirectory-admin-css', geodir_plugin_url() . '/geodirectory-assets/css/admin.css', array(), GEODIRECTORY_VERSION);
wp_enqueue_style('geodirectory-admin-css');
wp_register_style('geodirectory-frontend-style', geodir_plugin_url() . '/geodirectory-assets/css/style.css', array(), GEODIRECTORY_VERSION);
wp_enqueue_style('geodirectory-frontend-style');
wp_register_style('geodir-chosen-style', geodir_plugin_url() . '/geodirectory-assets/css/chosen.css', array(), GEODIRECTORY_VERSION);
wp_enqueue_style('geodir-chosen-style');
wp_register_style('geodirectory-jquery-ui-timepicker-css', geodir_plugin_url() . '/geodirectory-assets/css/jquery.ui.timepicker.css', array(), GEODIRECTORY_VERSION);
wp_enqueue_style('geodirectory-jquery-ui-timepicker-css');
wp_register_style('geodirectory-jquery-ui-css', geodir_plugin_url() . '/geodirectory-assets/css/jquery-ui.css', array(), GEODIRECTORY_VERSION);
wp_enqueue_style('geodirectory-jquery-ui-css');
wp_register_style('geodirectory-custom-fields-css', geodir_plugin_url() . '/geodirectory-assets/css/custom_field.css', array(), GEODIRECTORY_VERSION);
wp_enqueue_style('geodirectory-custom-fields-css');
wp_register_style('geodirectory-pluplodar-css', geodir_plugin_url() . '/geodirectory-assets/css/pluploader.css', array(), GEODIRECTORY_VERSION);
wp_enqueue_style('geodirectory-pluplodar-css');
wp_register_style('geodir-rating-style', geodir_plugin_url() . '/geodirectory-assets/css/jRating.jquery.css', array(), GEODIRECTORY_VERSION);
wp_enqueue_style('geodir-rating-style');
wp_register_style('geodir-rtl-style', geodir_plugin_url() . '/geodirectory-assets/css/rtl.css', array(), GEODIRECTORY_VERSION);
wp_enqueue_style('geodir-rtl-style');
}
}
if (!function_exists('geodir_admin_styles_req')) {
/**
* Loads stylesheets from CDN.
*
* @since 1.0.0
* @package GeoDirectory
*/
function geodir_admin_styles_req()
{
// wp_register_script('font-awesome', 'https://use.fontawesome.com/releases/v5.5.0/js/all.js#faload', array('font-awesome-shim'), GEODIRECTORY_VERSION);
// wp_register_script('font-awesome-shim', 'https://use.fontawesome.com/releases/v5.5.0/js/v4-shims.js', array(), GEODIRECTORY_VERSION);
// wp_enqueue_script( 'font-awesome' );
wp_register_script('geodirectory-admin', geodir_plugin_url() . '/geodirectory-assets/js/admin-req.min.js', array('jquery'), GEODIRECTORY_VERSION);
wp_enqueue_script('geodirectory-admin');
}
}
if (!function_exists('geodir_admin_scripts')) {
/**
* Enqueue Admin Scripts.
*
* @since 1.0.0
* @package GeoDirectory
*/
function geodir_admin_scripts()
{
$geodir_map_name = geodir_map_name();
wp_enqueue_script('jquery');
wp_enqueue_script('geodirectory-jquery-ui-timepicker-js', geodir_plugin_url() . '/geodirectory-assets/js/jquery.ui.timepicker.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), '', true);
wp_register_script('chosen', geodir_plugin_url() . '/geodirectory-assets/js/chosen.jquery.js', array('jquery'), GEODIRECTORY_VERSION);
wp_enqueue_script('chosen');
wp_register_script('geodirectory-choose-ajax', geodir_plugin_url() . '/geodirectory-assets/js/ajax-chosen.js', array(), GEODIRECTORY_VERSION);
wp_enqueue_script('geodirectory-choose-ajax');
if (isset($_REQUEST['listing_type'])) {
wp_register_script('geodirectory-custom-fields-script', geodir_plugin_url() . '/geodirectory-assets/js/custom_fields.js', array(), GEODIRECTORY_VERSION);
}
wp_enqueue_script('geodirectory-custom-fields-script');
$plugin_path = geodir_plugin_url() . '/geodirectory-functions/cat-meta-functions';
wp_enqueue_script('tax-meta-clss', $plugin_path . '/js/tax-meta-clss.js', array('jquery'), null, true);
if (in_array($geodir_map_name, array('auto', 'google'))) {
$map_lang = "&language=" . geodir_get_map_default_language();
$map_key = "&key=" . geodir_get_map_api_key();
/** This filter is documented in geodirectory_template_tags.php */
$map_extra = apply_filters('geodir_googlemap_script_extra', '');
wp_enqueue_script('google-maps-api', 'https://maps.google.com/maps/api/js?' . $map_lang . $map_key . $map_extra, '', NULL);
// Overlapping Marker Spiderfier
wp_register_script('geodirectory-g-overlappingmarker-script', geodir_plugin_url() . '/geodirectory-assets/jawj/oms.min.js', array(), GEODIRECTORY_VERSION);
wp_enqueue_script('geodirectory-g-overlappingmarker-script');
}
if ($geodir_map_name == 'osm') {
// Leaflet OpenStreetMap
wp_register_style('geodirectory-leaflet-style', geodir_plugin_url() . '/geodirectory-assets/leaflet/leaflet.css', array(), GEODIRECTORY_VERSION);
wp_enqueue_style('geodirectory-leaflet-style');
wp_register_script('geodirectory-leaflet-script', geodir_plugin_url() . '/geodirectory-assets/leaflet/leaflet.min.js', array(), GEODIRECTORY_VERSION);
wp_enqueue_script('geodirectory-leaflet-script');
wp_register_script('geodirectory-leaflet-geo-script', geodir_plugin_url() . '/geodirectory-assets/leaflet/osm.geocode.min.js', array('geodirectory-leaflet-script'), GEODIRECTORY_VERSION);
wp_enqueue_script('geodirectory-leaflet-geo-script');
// Overlapping Marker Spiderfier Leaflet
wp_register_script('geodirectory-o-overlappingmarker-script', geodir_plugin_url() . '/geodirectory-assets/jawj/oms-leaflet.min.js', array(), GEODIRECTORY_VERSION);
wp_enqueue_script('geodirectory-o-overlappingmarker-script');
}
wp_enqueue_script( 'jquery-ui-autocomplete' );
wp_register_script('geodirectory-goMap-script', geodir_plugin_url() . '/geodirectory-assets/js/goMap.min.js', array(), GEODIRECTORY_VERSION,true);
wp_enqueue_script('geodirectory-goMap-script');
wp_register_script('geodirectory-goMap-script', geodir_plugin_url() . '/geodirectory-assets/js/goMap.js', array(), GEODIRECTORY_VERSION);
wp_enqueue_script('geodirectory-goMap-script');
// font awesome rating script
if (get_option('geodir_reviewrating_enable_font_awesome')) {
wp_register_script('geodir-barrating-js', geodir_plugin_url() . '/geodirectory-assets/js/jquery.barrating.min.js', array(), GEODIRECTORY_VERSION);
wp_enqueue_script('geodir-barrating-js');
} else { // default rating script
wp_register_script('geodir-jRating-js', geodir_plugin_url() . '/geodirectory-assets/js/jRating.jquery.js', array(), GEODIRECTORY_VERSION);
wp_enqueue_script('geodir-jRating-js');
}
wp_register_script('geodir-on-document-load', geodir_plugin_url() . '/geodirectory-assets/js/on_document_load.min.js', array(), GEODIRECTORY_VERSION);
wp_enqueue_script('geodir-on-document-load');
// SCRIPT FOR UPLOAD
wp_enqueue_script('plupload-all');
wp_enqueue_script('jquery-ui-sortable');
wp_register_script('geodirectory-plupload-script', geodir_plugin_url() . '/geodirectory-assets/js/geodirectory-plupload.js', array(), GEODIRECTORY_VERSION);
wp_enqueue_script('geodirectory-plupload-script');
// SCRIPT FOR UPLOAD END
// place js config array for plupload
$plupload_init = array(
'runtimes' => 'html5,silverlight,html4',
'browse_button' => 'plupload-browse-button', // will be adjusted per uploader
'container' => 'plupload-upload-ui', // will be adjusted per uploader
'drop_element' => 'dropbox', // will be adjusted per uploader
'file_data_name' => 'async-upload', // will be adjusted per uploader
'multiple_queues' => true,
'max_file_size' => geodir_max_upload_size(),
'url' => admin_url('admin-ajax.php'),
'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
'filters' => array(array('title' => __('Allowed Files', 'geodirectory'), 'extensions' => '*')),
'multipart' => true,
'urlstream_upload' => true,
'multi_selection' => false, // will be added per uploader
// additional post data to send to our ajax hook
'multipart_params' => array(
'_ajax_nonce' => "", // will be added per uploader
'action' => 'plupload_action', // the ajax action name
'imgid' => 0 // will be added per uploader
)
);
$base_plupload_config = json_encode($plupload_init);
$thumb_img_arr = array();
if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '')
$thumb_img_arr = geodir_get_images($_REQUEST['pid']);
$totImg = '';
$image_limit = '';
if (!empty($thumb_img_arr)) {
$totImg = count($thumb_img_arr);
}
$gd_plupload_init = array('base_plupload_config' => $base_plupload_config,
'totalImg' => $totImg,
'image_limit' => $image_limit,
'upload_img_size' => geodir_max_upload_size());
wp_localize_script('geodirectory-plupload-script', 'gd_plupload', $gd_plupload_init);
$ajax_cons_data = array('url' => __(admin_url('admin-ajax.php')));
wp_localize_script('geodirectory-custom-fields-script', 'geodir_admin_ajax', $ajax_cons_data);
wp_register_script('geodirectory-admin-script', geodir_plugin_url() . '/geodirectory-assets/js/admin.js', array(), GEODIRECTORY_VERSION);
wp_enqueue_script('geodirectory-admin-script');
wp_enqueue_style('farbtastic');
wp_enqueue_script('farbtastic');
$screen = get_current_screen();
if ($screen->base == 'post' && in_array($screen->post_type, geodir_get_posttypes())) {
wp_enqueue_script('geodirectory-listing-validation-script', geodir_plugin_url() . '/geodirectory-assets/js/listing_validation_admin.js');
}
$ajax_cons_data = array('url' => esc_url(__(get_option('siteurl') . '?geodir_ajax=true')));
wp_localize_script('geodirectory-admin-script', 'geodir_ajax', $ajax_cons_data);
}
}
if (!function_exists('geodir_admin_menu')) {
/**
* Admin Menus
*
* Sets up the admin menus in wordpress.
*
* @since 1.0.0
* @package GeoDirectory
* @global array $menu Menu array.
* @global object $geodirectory GeoDirectory plugin object.
*/
function geodir_admin_menu()
{
global $menu, $geodirectory;
if (current_user_can('manage_options')) $menu[] = array('', 'read', 'separator-geodirectory', '', 'wp-menu-separator geodirectory');
add_menu_page(__('Geodirectory', 'geodirectory'), __('Geodirectory', 'geodirectory'), 'manage_options', 'geodirectory', 'geodir_admin_panel', geodir_plugin_url() . '/geodirectory-assets/images/favicon.ico', '55.1984');
}
}
if (!function_exists('geodir_admin_menu_order')) {
/**
* Order admin menus.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $menu_order Menu order array.
* @return array Modified menu order array.
*/
function geodir_admin_menu_order($menu_order)
{
// Initialize our custom order array
$geodir_menu_order = array();
// Get the index of our custom separator
$geodir_separator = array_search('separator-geodirectory', $menu_order);
// Get index of posttype menu
$post_types = geodir_get_posttypes();
// Loop through menu order and do some rearranging
foreach ($menu_order as $index => $item) :
if ((('geodirectory') == $item)) :
$geodir_menu_order[] = 'separator-geodirectory';
if (!empty($post_types)) {
foreach ($post_types as $post_type) {
$geodir_menu_order[] = 'edit.php?post_type=' . $post_type;
}
}
$geodir_menu_order[] = $item;
unset($menu_order[$geodir_separator]);
//unset( $menu_order[$geodir_places] );
elseif (!in_array($item, array('separator-geodirectory'))) :
$geodir_menu_order[] = $item;
endif;
endforeach;
// Return order
return $geodir_menu_order;
}
}
if (!function_exists('geodir_admin_custom_menu_order')) {
/**
* Enables custom menu order.
*
* @since 1.0.0
* @package GeoDirectory
* @return bool
*/
function geodir_admin_custom_menu_order()
{
if (!current_user_can('manage_options')) return false;
return true;
}
}
/**
* Function to show success or error message on admin option form submission.
*
* @since 1.0.0
* @package GeoDirectory
*/
function geodir_before_admin_panel()
{
if (isset($_REQUEST['installed']) && $_REQUEST['installed'] != '') {
echo '<div id="message" class="updated fade">
<p style="float:right;">' . __('Like Geodirectory?', 'geodirectory') . ' <a href="http://wordpress.org/extend/plugins/Geodirectory/" target="_blank">' . __('Support us by leaving a rating!', 'geodirectory') . '</a></p>
<p><strong>' . __('Geodirectory has been installed and setup. Enjoy :)', 'geodirectory') . '</strong></p>
</div>';
}
if (isset($_REQUEST['msg']) && $_REQUEST['msg'] != '') {
switch ($_REQUEST['msg']) {
case 'success':
echo '<div id="message" class="updated fade"><p><strong>' . __('Your settings have been saved.', 'geodirectory') . '</strong></p></div>';
flush_rewrite_rules(false);
break;
case 'fail':
$gderr = isset($_REQUEST['gderr']) ? $_REQUEST['gderr'] : '';
if ($gderr == 21)
echo '<div id="message" class="error fade"><p><strong>' . __('Error: You can not add same permalinks for both Listing and Location, please try again.', 'geodirectory') . '</strong></p></div>';
else
echo '<div id="message" class="error fade"><p><strong>' . __('Error: Your settings have not been saved, please try again.', 'geodirectory') . '</strong></p></div>';
break;
}
}
$geodir_load_map = get_option('geodir_load_map');
$need_map_key = false;
if($geodir_load_map=='' || $geodir_load_map=='google' || $geodir_load_map=='auto' ){
$need_map_key = true;
}
if (!geodir_get_map_api_key() && $need_map_key) {
echo '<div class="error"><p><strong>' . sprintf(__('Google Maps API KEY not set, %sclick here%s to set one OR use Open Street Maps instead.', 'geodirectory'), '<a href=\'' . admin_url('admin.php?page=geodirectory&tab=design_settings&active_tab=geodir_map_settings') . '\'>', '</a>') . '</strong></p></div>';
}
if (!geodir_is_default_location_set()) {
echo '<div class="updated fade"><p><strong>' . sprintf(__('Please %sclick here%s to set a default location, this will make the plugin work properly.', 'geodirectory'), '<a href=\'' . admin_url('admin.php?page=geodirectory&tab=default_location_settings') . '\'>', '</a>') . '</strong></p></div>';
}
if (!function_exists('curl_init')) {
echo '<div class="error"><p><strong>' . __('CURL is not installed on this server, this can cause problems, please ask your server admin to install it.', 'geodirectory') . '</strong></p></div>';
}
}
/**
* Handles data posted from GeoDirectory settings form.
*
* @since 1.0.0
* @package GeoDirectory
* @global array $geodir_settings Geodirectory settings array.
* @param string $current_tab The current settings tab name.
*/
function geodir_handle_option_form_submit($current_tab)
{
global $geodir_settings;
if (file_exists(dirname(__FILE__) . '/option-pages/' . $current_tab . '_array.php')) {
/**
* Contains settings array for current tab.
*
* @since 1.0.0
* @package GeoDirectory
*/
include_once('option-pages/' . $current_tab . '_array.php');
}
if (isset($_POST) && $_POST && isset($_REQUEST['page']) && $_REQUEST['page'] == 'geodirectory') :
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'geodir-settings')) die(__('Action failed. Please refresh the page and retry.', 'geodirectory'));
if (!wp_verify_nonce($_REQUEST['_wpnonce-' . $current_tab], 'geodir-settings-' . $current_tab)) die(__('Action failed. Please refresh the page and retry.', 'geodirectory'));
/**
* Fires before updating geodirectory admin settings.
*
* @since 1.4.2
*
* @param string $current_tab Current tab in geodirectory settings.
* @param array $geodir_settings Array of geodirectory settings.
*/
do_action('geodir_before_update_options', $current_tab, $geodir_settings);
if (!empty($geodir_settings[$current_tab]))
geodir_update_options($geodir_settings[$current_tab]);
/**
* Called after GeoDirectory options settings are updated.
*
* @since 1.0.0
* @param array $geodir_settings The array of GeoDirectory settings.
* @see 'geodir_before_update_options'
*/
do_action('geodir_update_options', $geodir_settings);
/**
* Called after GeoDirectory options settings are updated.
*
* Provides tab specific settings.
*
* @since 1.0.0
* @param string $current_tab The current settings tab name.
* @param array $geodir_settings[$current_tab] The array of settings for the current settings tab.
*/
do_action('geodir_update_options_' . $current_tab, $geodir_settings[$current_tab]);
flush_rewrite_rules(false);
$current_tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : '';
$redirect_url = admin_url('admin.php?page=geodirectory&tab=' . $current_tab . '&active_tab=' . $_REQUEST['active_tab'] . '&msg=success');
wp_redirect($redirect_url);
exit();
endif;
}
/**
* Update options
*
* Updates the options on the geodirectory settings pages. Returns true if saved.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $options The option array.
* @param bool $dummy Is this dummy settings? Default: false.
* @return bool Returns true if saved.
*/
function geodir_update_options($options, $dummy = false) {
if ((!isset($_POST) || !$_POST) && !$dummy) return false;
foreach ($options as $value) {
if ($dummy && isset($value['std']))
$_POST[$value['id']] = $value['std'];
if (isset($value['type']) && $value['type'] == 'checkbox') :
if (isset($value['id']) && isset($_POST[$value['id']])) {
update_option($value['id'], $_POST[$value['id']]);
} else {
update_option($value['id'], 0);
}
elseif (isset($value['type']) && $value['type'] == 'image_width') :
if (isset($value['id']) && isset($_POST[$value['id'] . '_width'])) {
update_option($value['id'] . '_width', $_POST[$value['id'] . '_width']);
update_option($value['id'] . '_height', $_POST[$value['id'] . '_height']);
if (isset($_POST[$value['id'] . '_crop'])) :
update_option($value['id'] . '_crop', 1);
else :
update_option($value['id'] . '_crop', 0);
endif;
} else {
update_option($value['id'] . '_width', $value['std']);
update_option($value['id'] . '_height', $value['std']);
update_option($value['id'] . '_crop', 1);
}
elseif (isset($value['type']) && $value['type'] == 'map') :
$post_types = array();
$categories = array();
if (!empty($_POST['home_map_post_types'])) :
foreach ($_POST['home_map_post_types'] as $post_type) :
$post_types[] = $post_type;
endforeach;
endif;
update_option('geodir_exclude_post_type_on_map', $post_types);
if (!empty($_POST['post_category'])) :
foreach ($_POST['post_category'] as $texonomy => $cat_arr) :
$categories[$texonomy] = array();
foreach ($cat_arr as $category) :
$categories[$texonomy][] = $category;
endforeach;
$categories[$texonomy] = !empty($categories[$texonomy]) ? array_unique($categories[$texonomy]) : array();
endforeach;
endif;
update_option('geodir_exclude_cat_on_map', $categories);
update_option('geodir_exclude_cat_on_map_upgrade', 1);
elseif (isset($value['type']) && $value['type'] == 'map_default_settings') :
if (!empty($_POST['geodir_default_map_language'])):
update_option('geodir_default_map_language', $_POST['geodir_default_map_language']);
endif;
if (!empty($_POST['geodir_default_map_search_pt'])):
update_option('geodir_default_map_search_pt', $_POST['geodir_default_map_search_pt']);
endif;
elseif (isset($value['type']) && $value['type'] == 'file') :
if (isset($_POST[$value['id'] . '_remove']) && $_POST[$value['id'] . '_remove']) {// if remove is set then remove the file
if (get_option($value['id'])) {
$image_name_arr = explode('/', get_option($value['id']));
$noimg_name = end($image_name_arr);
$img_path = $uploads['path'] . '/' . $noimg_name;
if (file_exists($img_path))
unlink($img_path);
}
update_option($value['id'], '');
}
$uploadedfile = isset($_FILES[$value['id']]) ? $_FILES[$value['id']] : '';
$filename = isset($_FILES[$value['id']]['name']) ? $_FILES[$value['id']]['name'] : '';
if (!empty($filename)):
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$uplaods = array();
foreach ($uploadedfile as $key => $uplaod):
if ($key == 'name'):
$uplaods[$key] = $filename;
else :
$uplaods[$key] = $uplaod;
endif;
endforeach;
$uploads = wp_upload_dir();
if (get_option($value['id'])) {
$image_name_arr = explode('/', get_option($value['id']));
$noimg_name = end($image_name_arr);
$img_path = $uploads['path'] . '/' . $noimg_name;
if (file_exists($img_path))
unlink($img_path);
}
$upload_overrides = array('test_form' => false);
$movefile = wp_handle_upload($uplaods, $upload_overrides);
update_option($value['id'], $movefile['url']);
endif;
if (!get_option($value['id']) && isset($value['value'])):
update_option($value['id'], $value['value']);
endif;
else :
// same menu setting per theme.
if (isset($value['id']) && $value['id'] == 'geodir_theme_location_nav' && isset($_POST[$value['id']])) {
$theme = wp_get_theme();
update_option('geodir_theme_location_nav_' . $theme->name, $_POST[$value['id']]);
}
if (isset($value['id']) && isset($_POST[$value['id']])) {
update_option($value['id'], $_POST[$value['id']]);
} else {
delete_option($value['id']);
}
endif;
}
if ($dummy)
$_POST = array();
return true;
}
/**
* create custom fields for place.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $tabs {
* Attributes of the tabs array.
*
* @type array $general_settings {
* Attributes of general settings.
*
* @type string $label Default "General".
*
* }
* @type array $design_settings {
* Attributes of design settings.
*
* @type string $label Default "Design".
*
* }
* @type array $permalink_settings {
* Attributes of permalink settings.
*
* @type string $label Default "Permalinks".
*
* }
* @type array $notifications_settings {
* Attributes of notifications settings.
*
* @type string $label Default "Notifications".
*
* }
* @type array $default_location_settings {
* Attributes of default location settings.
*
* @type string $label Default "Set Default Location".
*
* }
*
* }
* @return array Modified tabs array.
*/
function places_custom_fields_tab($tabs)
{
$geodir_post_types = get_option('geodir_post_types');
if (!empty($geodir_post_types)) {
foreach ($geodir_post_types as $geodir_post_type => $geodir_posttype_info):
$listing_slug = __($geodir_posttype_info['labels']['singular_name'], 'geodirectory');
$tabs[$geodir_post_type . '_fields_settings'] = array(
'label' => wp_sprintf(__('%s Settings', 'geodirectory'), $listing_slug),
'subtabs' => array(
array('subtab' => 'custom_fields',
'label' => __('Custom Fields', 'geodirectory'),
'request' => array('listing_type' => $geodir_post_type)),
array('subtab' => 'sorting_options',
'label' => __('Sorting Options', 'geodirectory'),
'request' => array('listing_type' => $geodir_post_type)),
),
'tab_index' => 9,
'request' => array('listing_type' => $geodir_post_type)
);
endforeach;
}
return $tabs;
}
/**
* Adds GD Tools settings menu to GeoDirectory settings.
*
* Can be found here. WP Admin -> Geodirectory -> GD Tools.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $tabs Tab menu array {@see places_custom_fields_tab()}.
* @return array Modified tab menu array.
*/
function geodir_tools_setting_tab($tabs)
{
wp_enqueue_script( 'jquery-ui-progressbar' );
$tabs['tools_settings'] = array('label' => __('GD Tools', 'geodirectory'));
return $tabs;
}
/**
* Adds Theme Compatibility menu item to GeoDirectory settings page.
*
* Can be found here. WP Admin -> Geodirectory -> Theme Compatibility.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $tabs Tab menu array {@see places_custom_fields_tab()}.
* @return array Modified tab menu array.
*/
function geodir_compatibility_setting_tab($tabs)
{
$tabs['compatibility_settings'] = array('label' => __('Theme Compatibility', 'geodirectory'));
return $tabs;
}
/**
* Adds Extend Geodirectory menu item to GeoDirectory settings page.
*
* Can be found here. WP Admin -> Geodirectory -> Extend Geodirectory.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $tabs Tab menu array {@see places_custom_fields_tab()}.
* @return array Modified tab menu array.
*/
function geodir_extend_geodirectory_setting_tab($tabs)
{
$tabs['extend_geodirectory_settings'] = array('label' => __('Extend Geodirectory', 'geodirectory'). ' <i class="fas fa-plug"></i>', 'url' => 'https://wpgeodirectory.com', 'target' => '_blank');
return $tabs;
}
if (!function_exists('geodir_edit_post_columns')) {
/**
* Modify admin post listing page columns.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $columns The column array.
* @return array Altered column array.
*/
function geodir_edit_post_columns($columns)
{
$new_columns = array('location' => __('Location (ID)', 'geodirectory'),
'categorys' => __('Categories', 'geodirectory'));
if (($offset = array_search('author', array_keys($columns))) === false) // if the key doesn't exist
{
$offset = 0; // should we prepend $array with $data?
$offset = count($columns); // or should we append $array with $data? lets pick this one...
}
$columns = array_merge(array_slice($columns, 0, $offset), $new_columns, array_slice($columns, $offset));
$columns = array_merge($columns, array('expire' => __('Expires', 'geodirectory')));
return $columns;
}
}
if (!function_exists('geodir_manage_post_columns')) {
/**
* Adds content to our custom post listing page columns.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @global object $post WordPress Post object.
* @param string $column The column name.
* @param int $post_id The post ID.
*/
function geodir_manage_post_columns($column, $post_id)
{
global $post, $wpdb;
switch ($column):
/* If displaying the 'city' column. */
case 'location' :
$location_id = geodir_get_post_meta($post->ID, 'post_location_id', true);
$location = geodir_get_location($location_id);
/* If no city is found, output a default message. */
if (empty($location)) {
_e('Unknown', 'geodirectory');
} else {
/* If there is a city id, append 'city name' to the text string. */
$add_location_id = $location_id > 0 ? ' (' . $location_id . ')' : '';
echo(__($location->country, 'geodirectory') . '-' . $location->region . '-' . $location->city . $add_location_id);
}
break;
/* If displaying the 'expire' column. */
case 'expire' :
$expire_date = geodir_get_post_meta($post->ID, 'expire_date', true);
$d1 = $expire_date; // get expire_date
$d2 = date('Y-m-d'); // get current date
$state = __('days left', 'geodirectory');
$date_diff_text = '';
$expire_class = 'expire_left';
if ($expire_date != 'Never') {
if (strtotime($d1) < strtotime($d2)) {
$state = __('days overdue', 'geodirectory');
$expire_class = 'expire_over';
}
$date_diff = round(abs(strtotime($d1) - strtotime($d2)) / 86400); // get the difference in days
$date_diff_text = '<br /><span class="' . $expire_class . '">(' . $date_diff . ' ' . $state . ')</span>';
}
/* If no expire_date is found, output a default message. */
if (empty($expire_date))
echo __('Unknown', 'geodirectory');
/* If there is a expire_date, append 'days left' to the text string. */
else
echo $expire_date . $date_diff_text;
break;
/* If displaying the 'categorys' column. */
case 'categorys' :
/* Get the categorys for the post. */
$terms = wp_get_object_terms($post_id, get_object_taxonomies($post));
/* If terms were found. */
if (!empty($terms)) {
$out = array();
/* Loop through each term, linking to the 'edit posts' page for the specific term. */
foreach ($terms as $term) {
if (!strstr($term->taxonomy, 'tag')) {
$out[] = sprintf('<a href="%s">%s</a>',
esc_url(add_query_arg(array('post_type' => $post->post_type, $term->taxonomy => $term->slug), 'edit.php')),
esc_html(sanitize_term_field('name', $term->name, $term->term_id, $term->taxonomy, 'display'))
);
}
}
/* Join the terms, separating them with a comma. */
echo(join(', ', $out));
} /* If no terms were found, output a default message. */
else {
_e('No Categories', 'geodirectory');
}
break;
endswitch;
}
}
if (!function_exists('geodir_post_sortable_columns')) {
/**
* Makes admin post listing page columns sortable.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $columns The column array.
* @return array Altered column array.
*/
function geodir_post_sortable_columns($columns)
{
$columns['expire'] = 'expire';
return $columns;
}
}
/**
* Saves listing data from request variable to database.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @global object $current_user Current user object.
* @global object $post WordPress Post object.
* @param int $post_id The post ID.
*/
function geodir_post_information_save($post_id, $post) {
global $wpdb, $current_user;
if (isset($post->post_type) && ($post->post_type=='nav_menu_item' || $post->post_type=='page' || $post->post_type=='post')) {
return;
}
$geodir_posttypes = geodir_get_posttypes();
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
if (!wp_is_post_revision($post_id) && isset($post->post_type) && in_array($post->post_type, $geodir_posttypes)) {
if (isset($_REQUEST['_status']))
geodir_change_post_status($post_id, $_REQUEST['_status']);
if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'trash' || $_REQUEST['action'] == 'untrash'))
return;
if (!isset($_POST['geodir_post_info_noncename']) || !wp_verify_nonce($_POST['geodir_post_info_noncename'], plugin_basename(__FILE__)))
return;
if (!isset($_POST['geodir_post_attachments_noncename']) || !wp_verify_nonce($_POST['geodir_post_attachments_noncename'], plugin_basename(__FILE__)))
return;
geodir_save_listing($_REQUEST);
}
}
/**
* Admin fields
*
* Loops though the geodirectory options array and outputs each field.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $geodirectory GeoDirectory plugin object.
* @global object $sitepress Sitepress WPML object.
* @param array $options The options array.
*/
function geodir_admin_fields($options)
{
global $geodirectory;
$first_title = true;
$tab_id = '';
$i = 0;
foreach ($options as $value) :
if (!isset($value['name'])) $value['name'] = '';
if (!isset($value['class'])) $value['class'] = '';
if (!isset($value['css'])) $value['css'] = '';
if (!isset($value['std'])) $value['std'] = '';
$desc = '';
switch ($value['type']) :
case 'dummy_installer':
$post_type = isset($value['post_type']) ? $value['post_type'] : 'gd_place';
geodir_autoinstall_admin_header($post_type);
break;
case 'title':
if ($i == 0) {
echo '<dl id="geodir_oiption_tabs" class="gd-tab-head"></dl>';
echo '<div class="inner_content_tab_main">';
}
$i++;
if (isset($value['id']) && $value['id'])
$tab_id = $value['id'];
if (isset($value['desc']) && $value['desc'])
$desc = '<span style=" text-transform:none;">:- ' . $value['desc'] . '</span>';
if (isset($value['name']) && $value['name']) {
if ($first_title === true) {
$first_title = false;
} else {
echo '</div>';
}
echo '<dd id="' . trim($tab_id) . '" class="geodir_option_tabs" ><a href="javascript:void(0);">' . $value['name'] . '</a></dd>';
echo '<div id="sub_' . trim($tab_id) . '" class="gd-content-heading" style=" margin-bottom:10px;" >';
}
/**
* Called after a GeoDirectory settings title is output in the GD settings page.
*
* The action is called dynamically geodir_settings_$value['id'].
*
* @since 1.0.0
*/
do_action('geodir_settings_' . sanitize_title($value['id']));
break;
case 'no_tabs':
echo '<div class="inner_content_tab_main">';
echo '<div id="sub_' . trim($tab_id) . '" class="gd-content-heading" style=" margin-bottom:10px;" >';
break;
case 'sectionstart':
if (isset($value['desc']) && $value['desc'])
$desc = '<span style=" text-transform:none;"> - ' . $value['desc'] . '</span>';
if (isset($value['name']) && $value['name'])
echo '<h3>' . $value['name'] . $desc . '</h3>';
/**
* Called after a GeoDirectory settings sectionstart is output in the GD settings page.
*
* The action is called dynamically geodir_settings_$value['id']_start.
*
* @since 1.0.0
*/
if (isset($value['id']) && $value['id']) do_action('geodir_settings_' . sanitize_title($value['id']) . '_start');
echo '<table class="form-table">' . "\n\n";
break;
case 'sectionend':
/**
* Called before a GeoDirectory settings sectionend is output in the GD settings page.
*
* The action is called dynamically geodir_settings_$value['id']_end.
*
* @since 1.0.0
*/
if (isset($value['id']) && $value['id']) do_action('geodir_settings_' . sanitize_title($value['id']) . '_end');
echo '</table>';
/**
* Called after a GeoDirectory settings sectionend is output in the GD settings page.
*
* The action is called dynamically geodir_settings_$value['id']_end.
*
* @since 1.0.0
*/
if (isset($value['id']) && $value['id']) do_action('geodir_settings_' . sanitize_title($value['id']) . '_after');
break;
case 'text':
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
<td class="forminp"><input name="<?php echo esc_attr($value['id']); ?>"
id="<?php echo esc_attr($value['id']); ?>"
type="<?php echo esc_attr($value['type']); ?>"
<?php if(isset($value['placeholder'])){?>placeholder="<?php echo esc_attr($value['placeholder']); ?>"<?php }?>
style=" <?php echo esc_attr($value['css']); ?>"
value="<?php if (get_option($value['id']) !== false && get_option($value['id']) !== null) {
echo esc_attr(stripslashes(get_option($value['id'])));
} else {
echo esc_attr($value['std']);
} ?>"/> <span class="description"><?php echo $value['desc']; ?></span></td>
</tr><?php
break;
case 'map-key':
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
<td class="forminp"><input name="<?php echo esc_attr($value['id']); ?>"
id="<?php echo esc_attr($value['id']); ?>"
type="<?php echo esc_attr($value['type']); ?>"
<?php if(isset($value['placeholder'])){?>placeholder="<?php echo esc_attr($value['placeholder']); ?>"<?php }?>
style=" <?php echo esc_attr($value['css']); ?>"
value="<?php if (get_option($value['id']) !== false && get_option($value['id']) !== null) {
echo esc_attr(stripslashes(get_option($value['id'])));
} else {
echo esc_attr($value['std']);
} ?>"/>
<?php $gm_api_url = 'https://console.developers.google.com/henhouse/?pb=["hh-1","maps_backend",null,[],"https://developers.google.com",null,["static_maps_backend","street_view_image_backend","maps_embed_backend","places_backend","geocoding_backend","directions_backend","distance_matrix_backend","geolocation","elevation_backend","timezone_backend","maps_backend"],null]';?>
<a id="gd-api-key" onclick='window.open("<?php echo wp_slash($gm_api_url);?>", "newwindow", "width=600, height=400"); return false;' href='<?php echo $gm_api_url;?>' class="button-primary" name="<?php _e('Generate API Key - ( MUST be logged in to your Google account )','geodirectory');?>" ><?php _e('Generate API Key','geodirectory');?></a>
<span class="description"><?php echo $value['desc']; ?></span></td>
</tr><?php
break;
case 'password':
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
<td class="forminp"><input name="<?php echo esc_attr($value['id']); ?>"
id="<?php echo esc_attr($value['id']); ?>"
type="<?php echo esc_attr($value['type']); ?>"
<?php if(isset($value['placeholder'])){?>placeholder="<?php echo esc_attr($value['placeholder']); ?>"<?php }?>
style="<?php echo esc_attr($value['css']); ?>"
value="<?php if (get_option($value['id']) !== false && get_option($value['id']) !== null) {
echo esc_attr(stripslashes(get_option($value['id'])));
} else {
echo esc_attr($value['std']);
} ?>"/> <span class="description"><?php echo $value['desc']; ?></span></td>
</tr><?php
break;
case 'html_content':
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
<td class="forminp"><span class="description"><?php echo $value['desc']; ?></span></td>
</tr><?php
break;
case 'color' :
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
<td class="forminp"><input name="<?php echo esc_attr($value['id']); ?>"
id="<?php echo esc_attr($value['id']); ?>" type="text"
style="<?php echo esc_attr($value['css']); ?>"
value="<?php if (get_option($value['id']) !== false && get_option($value['id']) !== null) {
echo esc_attr(stripslashes(get_option($value['id'])));
} else {
echo esc_attr($value['std']);
} ?>" class="colorpick"/> <span
class="description"><?php echo $value['desc']; ?></span>
<div id="colorPickerDiv_<?php echo esc_attr($value['id']); ?>" class="colorpickdiv"
style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>
</td>
</tr><?php
break;
case 'image_width' :
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
<td class="forminp">
<?php _e('Width', 'geodirectory'); ?> <input
name="<?php echo esc_attr($value['id']); ?>_width"
id="<?php echo esc_attr($value['id']); ?>_width" type="text" size="3"
value="<?php if ($size = get_option($value['id'] . '_width')) echo stripslashes($size); else echo $value['std']; ?>"/>
<?php _e('Height', 'geodirectory'); ?> <input
name="<?php echo esc_attr($value['id']); ?>_height"
id="<?php echo esc_attr($value['id']); ?>_height" type="text" size="3"
value="<?php if ($size = get_option($value['id'] . '_height')) echo stripslashes($size); else echo $value['std']; ?>"/>
<label><?php _e('Hard Crop', 'geodirectory'); ?> <input
name="<?php echo esc_attr($value['id']); ?>_crop"
id="<?php echo esc_attr($value['id']); ?>_crop"
type="checkbox" <?php if (get_option($value['id'] . '_crop') != '') checked(get_option($value['id'] . '_crop'), 1); else checked(1); ?> /></label>
<span class="description"><?php echo $value['desc'] ?></span></td>
</tr><?php
break;
case 'select':
$option_value = get_option($value['id']);
$option_value = !empty($option_value) ? stripslashes_deep($option_value) : $option_value;
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
<td class="forminp"><select name="<?php echo esc_attr($value['id']); ?>"
id="<?php echo esc_attr($value['id']); ?>"
style="<?php echo esc_attr($value['css']); ?>"
class="<?php if (isset($value['class'])) echo $value['class']; ?>"
option-ajaxchosen="false">
<?php
foreach ($value['options'] as $key => $val) {
$geodir_select_value = '';
if ($option_value != '') {
if ($option_value != '' && $option_value == $key)
$geodir_select_value = ' selected="selected" ';
} else {
if ($value['std'] == $key)
$geodir_select_value = ' selected="selected" ';
}
?>
<option
value="<?php echo esc_attr($key); ?>" <?php echo $geodir_select_value; ?> ><?php echo geodir_utf8_ucfirst($val) ?></option>
<?php
}
?>
</select> <span class="description"><?php echo $value['desc'] ?></span>
</td>
</tr><?php
break;
case 'multiselect':
$option_values = get_option($value['id']);
if ($option_values === '' && !empty($value['std']) && is_array($value['std'])) {
$option_values = $value['std'];
}
$option_values = !empty($option_values) ? stripslashes_deep($option_values) : $option_values;
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
<td class="forminp"><select multiple="multiple" name="<?php echo esc_attr($value['id']); ?>[]"
id="<?php echo esc_attr($value['id']); ?>"
style="<?php echo esc_attr($value['css']); ?>"
class="<?php if (isset($value['class'])) echo $value['class']; ?>"
data-placeholder="<?php if (isset($value['placeholder_text'])) echo $value['placeholder_text'];?>"
option-ajaxchosen="false">
<?php
foreach ($value['options'] as $key => $val) {
if (strpos($key, 'optgroup_start-') === 0) {
?><optgroup label="<?php echo geodir_utf8_ucfirst($val); ?>"><?php
} else if (strpos($key, 'optgroup_end-') === 0) {
?></optgroup><?php
} else {
?>
<option value="<?php echo esc_attr($key); ?>" <?php selected(true, (is_array($option_values) && in_array($key, $option_values)));?>>
<?php echo geodir_utf8_ucfirst($val) ?>
</option>
<?php
}
}
?>
</select> <span class="description"><?php echo $value['desc'] ?></span>
</td>
</tr><?php
break;
case 'file':
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
<td class="forminp">
<input type="file" name="<?php echo esc_attr($value['id']); ?>"
id="<?php echo esc_attr($value['id']); ?>" style="<?php echo esc_attr($value['css']); ?>"
class="<?php if (isset($value['class'])) echo $value['class']; ?>"/>
<?php if (get_option($value['id'])) { ?>
<input type="hidden" name="<?php echo esc_attr($value['id']); ?>_remove"
id="<?php echo esc_attr($value['id']); ?>_remove" value="0">
<span class="description"> <a
href="<?php echo get_option($value['id']); ?>"
target="_blank"><?php echo get_option($value['id']); ?></a> <i
title="<?php _e('remove file (set to empty)', 'geodirectory'); ?>"
onclick="jQuery('#<?php echo esc_attr($value['id']); ?>_remove').val('1'); jQuery( this ).parent().text('<?php _e('save to remove file', 'geodirectory'); ?>');"
class="fas fa-times gd-remove-file"></i></span>
<?php } ?>
</td>
</tr><?php
break;
case 'map_default_settings' :
?>
<tr valign="top">
<th class="titledesc" width="40%"><?php _e('Default map language', 'geodirectory');?></th>
<td width="60%">
<select name="geodir_default_map_language" style="width:60%">
<?php
$arr_map_langages = array(
'ar' => __('ARABIC', 'geodirectory'),
'eu' => __('BASQUE', 'geodirectory'),
'bg' => __('BULGARIAN', 'geodirectory'),
'bn' => __('BENGALI', 'geodirectory'),
'ca' => __('CATALAN', 'geodirectory'),
'cs' => __('CZECH', 'geodirectory'),
'da' => __('DANISH', 'geodirectory'),
'de' => __('GERMAN', 'geodirectory'),
'el' => __('GREEK', 'geodirectory'),
'en' => __('ENGLISH', 'geodirectory'),
'en-AU' => __('ENGLISH (AUSTRALIAN)', 'geodirectory'),
'en-GB' => __('ENGLISH (GREAT BRITAIN)', 'geodirectory'),
'es' => __('SPANISH', 'geodirectory'),
'eu' => __('BASQUE', 'geodirectory'),
'fa' => __('FARSI', 'geodirectory'),
'fi' => __('FINNISH', 'geodirectory'),
'fil' => __('FILIPINO', 'geodirectory'),
'fr' => __('FRENCH', 'geodirectory'),
'gl' => __('GALICIAN', 'geodirectory'),
'gu' => __('GUJARATI', 'geodirectory'),
'hi' => __('HINDI', 'geodirectory'),
'hr' => __('CROATIAN', 'geodirectory'),
'hu' => __('HUNGARIAN', 'geodirectory'),
'id' => __('INDONESIAN', 'geodirectory'),
'it' => __('ITALIAN', 'geodirectory'),
'iw' => __('HEBREW', 'geodirectory'),
'ja' => __('JAPANESE', 'geodirectory'),
'kn' => __('KANNADA', 'geodirectory'),
'ko' => __('KOREAN', 'geodirectory'),
'lt' => __('LITHUANIAN', 'geodirectory'),
'lv' => __('LATVIAN', 'geodirectory'),
'ml' => __('MALAYALAM', 'geodirectory'),
'mr' => __('MARATHI', 'geodirectory'),
'nl' => __('DUTCH', 'geodirectory'),
'no' => __('NORWEGIAN', 'geodirectory'),
'pl' => __('POLISH', 'geodirectory'),
'pt' => __('PORTUGUESE', 'geodirectory'),
'pt-BR' => __('PORTUGUESE (BRAZIL)', 'geodirectory'),
'pt-PT' => __('PORTUGUESE (PORTUGAL)', 'geodirectory'),
'ro' => __('ROMANIAN', 'geodirectory'),
'ru' => __('RUSSIAN', 'geodirectory'),
'ru' => __('RUSSIAN', 'geodirectory'),
'sk' => __('SLOVAK', 'geodirectory'),
'sl' => __('SLOVENIAN', 'geodirectory'),
'sr' => __('SERBIAN', 'geodirectory'),
'sv' => __(' SWEDISH', 'geodirectory'),
'tl' => __('TAGALOG', 'geodirectory'),
'ta' => __('TAMIL', 'geodirectory'),
'te' => __('TELUGU', 'geodirectory'),
'th' => __('THAI', 'geodirectory'),
'tr' => __('TURKISH', 'geodirectory'),
'uk' => __('UKRAINIAN', 'geodirectory'),
'vi' => __('VIETNAMESE', 'geodirectory'),
'zh-CN' => __('CHINESE (SIMPLIFIED)', 'geodirectory'),
'zh-TW' => __('CHINESE (TRADITIONAL)', 'geodirectory'),
);
$geodir_default_map_language = get_option('geodir_default_map_language');
if (empty($geodir_default_map_language))
$geodir_default_map_language = 'en';
foreach ($arr_map_langages as $language_key => $language_txt) {
if (!empty($geodir_default_map_language) && $language_key == $geodir_default_map_language)
$geodir_default_language_selected = "selected='selected'";
else
$geodir_default_language_selected = '';
?>
<option
value="<?php echo $language_key?>" <?php echo $geodir_default_language_selected; ?>><?php echo $language_txt; ?></option>
<?php }
?>
</select>
</td>
</tr>
<tr valign="top">
<th class="titledesc"
width="40%"><?php _e('Default post type search on map', 'geodirectory');?></th>
<td width="60%">
<select name="geodir_default_map_search_pt" style="width:60%">
<?php
$post_types = geodir_get_posttypes('array');
$geodir_default_map_search_pt = get_option('geodir_default_map_search_pt');
if (empty($geodir_default_map_search_pt))
$geodir_default_map_search_pt = 'gd_place';
if (is_array($post_types)) {
foreach ($post_types as $key => $post_types_obj) {
if (!empty($geodir_default_map_search_pt) && $key == $geodir_default_map_search_pt)
$geodir_search_pt_selected = "selected='selected'";
else
$geodir_search_pt_selected = '';
?>
<option
value="<?php echo $key?>" <?php echo $geodir_search_pt_selected; ?>><?php echo __($post_types_obj['labels']['singular_name'], 'geodirectory'); ?></option>
<?php }
}
?>
</select>
</td>
</tr>
<?php
break;
case 'map':
?>
<tr valign="top">
<td class="forminp">
<?php
global $post_cat, $cat_display;
$post_types = geodir_get_posttypes('object');
$cat_display = 'checkbox';
$gd_post_types = get_option('geodir_exclude_post_type_on_map');
$gd_cats = get_option('geodir_exclude_cat_on_map');
$gd_cats_upgrade = (int)get_option('geodir_exclude_cat_on_map_upgrade');
$count = 1;
?>
<table width="70%" class="widefat">
<thead>
<tr>
<th><b><?php echo DESIGN_POST_TYPE_SNO; ?></b></th>
<th><b><?php echo DESIGN_POST_TYPE; ?></b></th>
<th><b><?php echo DESIGN_POST_TYPE_CAT; ?></b></th>
</tr>
<?php
$gd_categs = $gd_cats;
foreach ($post_types as $key => $post_types_obj) :
$checked = is_array($gd_post_types) && in_array($key, $gd_post_types) ? 'checked="checked"' : '';
$gd_taxonomy = geodir_get_taxonomies($key);
if ($gd_cats_upgrade) {
$gd_cat_taxonomy = isset($gd_taxonomy[0]) ? $gd_taxonomy[0] : '';
$gd_cats = isset($gd_categs[$gd_cat_taxonomy]) ? $gd_categs[$gd_cat_taxonomy] : array();
$gd_cats = !empty($gd_cats) && is_array($gd_cats) ? array_unique($gd_cats) : array();
}
$post_cat = implode(',', $gd_cats);
$gd_taxonomy_list = geodir_custom_taxonomy_walker($gd_taxonomy);
?>
<tr>
<td valign="top" width="5%"><?php echo $count; ?></td>
<td valign="top" width="25%" id="td_post_types"><input type="checkbox"
name="home_map_post_types[]"
id="<?php echo esc_attr($value['id']); ?>"
value="<?php echo $key; ?>"
class="map_post_type" <?php echo $checked;?> />
<?php echo __($post_types_obj->labels->singular_name, 'geodirectory'); ?></td>
<td width="40%">
<div class="home_map_category" style="overflow:auto;width:200px;height:100px;"
id="<?php echo $key; ?>"><?php echo $gd_taxonomy_list; ?></div>
</td>
</tr>
<?php $count++; endforeach; ?>
</thead>
</table>
<p><?php _e('Note: Tick respective post type or categories which you want to hide from home page map widget.', 'geodirectory')?></p>
</td>
</tr>
<?php
break;
case 'checkbox' :
if (!isset($value['checkboxgroup']) || (isset($value['checkboxgroup']) && $value['checkboxgroup'] == 'start')) :
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
<td class="forminp">
<?php
endif;
?>
<fieldset>
<legend class="screen-reader-text"><span><?php echo $value['name'] ?></span></legend>
<label for="<?php echo $value['id'] ?>">
<input name="<?php echo esc_attr($value['id']); ?>" id="<?php echo esc_attr($value['id']); ?>"
type="checkbox" value="1" <?php checked(get_option($value['id']), true); ?> />
<?php echo $value['desc'] ?></label><br>
</fieldset>
<?php
if (!isset($value['checkboxgroup']) || (isset($value['checkboxgroup']) && $value['checkboxgroup'] == 'end')) :
?>
</td>
</tr>
<?php
endif;
break;
case 'radio' :
if (!isset($value['radiogroup']) || (isset($value['radiogroup']) && $value['radiogroup'] == 'start')) :
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
<td class="forminp">
<?php
endif;
?>
<fieldset>
<legend class="screen-reader-text"><span><?php echo $value['name'] ?></span></legend>
<label for="<?php echo $value['id'];?>">
<input name="<?php echo esc_attr($value['id']); ?>"
id="<?php echo esc_attr($value['id'] . $value['value']); ?>" type="radio"
value="<?php echo $value['value'] ?>" <?php if (get_option($value['id']) == $value['value']) {
echo 'checked="checked"';
}elseif(get_option($value['id'])=='' && $value['std']==$value['value']){echo 'checked="checked"';} ?> />
<?php echo $value['desc']; ?></label><br>
</fieldset>
<?php
if (!isset($value['radiogroup']) || (isset($value['radiogroup']) && $value['radiogroup'] == 'end')) :
?>
</td>
</tr>
<?php
endif;
break;
case 'textarea':
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
<td class="forminp">
<textarea
<?php if (isset($value['args'])) echo $value['args'] . ' '; ?>name="<?php echo esc_attr($value['id']); ?>"
id="<?php echo esc_attr($value['id']); ?>"
<?php if(isset($value['placeholder'])){?>placeholder="<?php echo esc_attr($value['placeholder']); ?>"<?php }?>
style="<?php echo esc_attr($value['css']); ?>"><?php if (get_option($value['id'])) echo esc_textarea(stripslashes(get_option($value['id']))); else echo esc_textarea($value['std']); ?></textarea><span
class="description"><?php echo $value['desc'] ?></span>
</td>
</tr><?php
break;
case 'editor':
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
<td class="forminp"><?php
if (get_option($value['id']))
$content = stripslashes(get_option($value['id']));
else
$content = $value['std'];
$editor_settings = array('media_buttons' => false, 'textarea_rows' => 10);
wp_editor($content, esc_attr($value['id']), $editor_settings);
?> <span class="description"><?php echo $value['desc'] ?></span>
</td>
</tr><?php
break;
case 'single_select_page' :
// WPML
$switch_lang = false;
$disabled = '';
if (geodir_is_wpml() && isset($_REQUEST['tab']) && $_REQUEST['tab'] == 'permalink_settings') {
global $sitepress;
$default_lang = $sitepress->get_default_language();
$current_lang = $sitepress->get_current_language();
if ($current_lang != 'all' && $current_lang != $default_lang) {
$disabled = "disabled='disabled'";
$switch_lang = $current_lang;
$sitepress->switch_lang('all', true);
}
}
//
$page_setting = (int)get_option($value['id']);
$args = array('name' => $value['id'],
'id' => $value['id'],
'sort_column' => 'menu_order',
'sort_order' => 'ASC',
'show_option_none' => ' ',
'class' => $value['class'],
'echo' => false,
'selected' => $page_setting);
if (isset($value['args'])) $args = wp_parse_args($value['args'], $args);
?>
<tr valign="top" class="single_select_page">
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
<td class="forminp">
<?php echo str_replace(' id=', " data-placeholder='" . __('Select a page...', 'geodirectory') . "' style='" . $value['css'] . "' class='" . $value['class'] . "' " . $disabled . " id=", wp_dropdown_pages($args)); ?>
<span class="description"><?php echo $value['desc'] ?></span>
</td>
</tr><?php
if ($switch_lang) {
$sitepress->switch_lang($switch_lang, true);
}
break;
case 'single_select_country' :
$country_setting = (string)get_option($value['id']);
if (strstr($country_setting, ':')) :
$country = current(explode(':', $country_setting));
$state = end(explode(':', $country_setting));
else :
$country = $country_setting;
$state = '*';
endif;
?>
<tr valign="top">
<th scope="rpw" class="titledesc"><?php echo $value['name'] ?></th>
<td class="forminp"><select name="<?php echo esc_attr($value['id']); ?>"
style="<?php echo esc_attr($value['css']); ?>"
data-placeholder="<?php _e('Choose a country&hellip;', 'geodirectory'); ?>"
title="Country" class="chosen_select">
<?php echo $geodirectory->countries->country_dropdown_options($country, $state); ?>
</select> <span class="description"><?php echo $value['desc'] ?></span>
</td>
</tr><?php
break;
case 'multi_select_countries' :
$countries = $geodirectory->countries->countries;
asort($countries);
$selections = (array)get_option($value['id']);
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
<td class="forminp">
<select multiple="multiple" name="<?php echo esc_attr($value['id']); ?>[]" style="width:450px;"
data-placeholder="<?php _e('Choose countries&hellip;', 'geodirectory'); ?>"
title="Country" class="chosen_select">
<?php
if ($countries) foreach ($countries as $key => $val) :
echo '<option value="' . $key . '" ' . selected(in_array($key, $selections), true, false) . '>' . $val . '</option>';
endforeach;
?>
</select>
</td>
</tr>
<?php
break;
case 'google_analytics' :
$selections = (array)get_option($value['id']);
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
<td class="forminp">
<?php
$oAuthURL = "https://accounts.google.com/o/oauth2/auth?";
$scope = "scope=https://www.googleapis.com/auth/analytics.readonly";
$state = "&state=123";//any string
$redirect_uri = "&redirect_uri=" . admin_url('admin-ajax.php') . "?action=geodir_ga_callback";
$response_type = "&response_type=code";
$client_id = "&client_id=".get_option('geodir_ga_client_id');
$access_type = "&access_type=offline";
$approval_prompt = "&approval_prompt=force";
$auth_url = $oAuthURL . $scope . $state . $redirect_uri . $response_type . $client_id . $access_type . $approval_prompt;
if (get_option('geodir_ga_auth_token')) {
?>
<span class="button-primary"
onclick="gd_GA_Deauthorize('<?php echo wp_create_nonce('gd_ga_deauthorize');?>');"><?php _e('Deauthorize', 'geodirectory'); ?></span>
<span style="color: green; font-weight: bold;"><?php _e('Authorized', 'geodirectory'); ?></span>
<?php
global $gd_ga_errors;
if(!empty($gd_ga_errors)){
print_r($gd_ga_errors);
}
} else {
?>
<span class="button-primary"
onclick="window.open('<?php echo geodir_ga_activation_url();?>', 'activate','width=700, height=600, menubar=0, status=0, location=0, toolbar=0')"><?php _e('Authorize', 'geodirectory');?></span>
<?php
}
?>
</td>
</tr>
<?php
break;
case 'field_seperator' :
?>
<tr valign="top">
<td colspan="2" class="forminp geodir_line_seperator"></td>
</tr>
<?php
break;
endswitch;
endforeach;
if ($first_title === false) {
echo "</div>";
}
?>
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('.geodir_option_tabs').each(function (ele) {
jQuery('#geodir_oiption_tabs').append(jQuery(this));
});
jQuery('.geodir_option_tabs').removeClass('gd-tab-active');
jQuery('.geodir_option_tabs:first').addClass('gd-tab-active');
jQuery('.gd-content-heading').hide();
jQuery('.gd-content-heading:first').show();
jQuery('.geodir_option_tabs').bind('click', function () {
var tab_id = jQuery(this).attr('id');
if (tab_id == 'dummy_data_settings') {
jQuery('p .button-primary').hide();
} else if (tab_id == 'csv_upload_settings') {
jQuery('p .button-primary').hide();
} else {
jQuery('.button-primary').show();
}
if (jQuery('#sub_' + tab_id + ' div').hasClass('geodir_auto_install'))
jQuery('p .button-primary').hide();
jQuery('.geodir_option_tabs').removeClass('gd-tab-active');
jQuery(this).addClass('gd-tab-active');
jQuery('.gd-content-heading').hide();
jQuery('#sub_' + tab_id).show();
jQuery('.active_tab').val(tab_id);
jQuery("select.chosen_select").trigger("chosen:updated"); //refresh chosen
});
<?php if (isset($_REQUEST['active_tab']) && $_REQUEST['active_tab'] != '') { ?>
jQuery('.geodir_option_tabs').removeClass('gd-tab-active');
jQuery('#<?php echo sanitize_text_field($_REQUEST['active_tab']);?>').addClass('gd-tab-active');
jQuery('.gd-content-heading').hide();
jQuery('#sub_<?php echo sanitize_text_field($_REQUEST['active_tab']);?>').show();
<?php } ?>
});
</script>
<?php
}
/**
* Prints post information meta box content.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $post The post object.
* @global int $post_id The post ID.
*/
function geodir_post_info_setting()
{
global $post, $post_id;
$post_type = get_post_type();
$package_info = array();
$package_info = geodir_post_package_info($package_info, $post, $post_type);
wp_nonce_field(plugin_basename(__FILE__), 'geodir_post_info_noncename');
echo '<div id="geodir_wrapper">';
/**
* Called before the GD custom fields are output in the wp-admin area.
*
* @since 1.0.0
* @see 'geodir_after_default_field_in_meta_box'
*/
do_action('geodir_before_default_field_in_meta_box');
//geodir_get_custom_fields_html($package_info->pid,'default',$post_type);
// to display all fields in one information box
geodir_get_custom_fields_html($package_info->pid, 'all', $post_type);
/**
* Called after the GD custom fields are output in the wp-admin area.
*
* @since 1.0.0
* @see 'geodir_before_default_field_in_meta_box'
*/
do_action('geodir_after_default_field_in_meta_box');
echo '</div>';
}
/**
* Prints additional information meta box content.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $post The post object.
* @global int $post_id The post ID.
*/
function geodir_post_addinfo_setting()
{
global $post, $post_id;
$post_type = get_post_type();
$package_info = array();
$package_info = geodir_post_package_info($package_info, $post, $post_type);
wp_nonce_field(plugin_basename(__FILE__), 'geodir_post_addinfo_noncename');
echo '<div id="geodir_wrapper">';
geodir_get_custom_fields_html($package_info->pid, 'custom', $post_type);
echo '</div>';
}
/**
* Prints Attachments meta box content.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $post The post object.
* @global int $post_id The post ID.
*/
function geodir_post_attachments()
{
global $post, $post_id;
wp_nonce_field(plugin_basename(__FILE__), 'geodir_post_attachments_noncename');
if (geodir_get_featured_image($post_id, 'thumbnail')) {
echo '<h4>' . __('Featured Image', 'geodirectory') . '</h4>';
geodir_show_featured_image($post_id, 'thumbnail');
}
$image_limit = 0;
?>
<h5 class="form_title">
<?php if ($image_limit != 0 && $image_limit == 1) {
echo '<br /><small>(' . __('You can upload', 'geodirectory') . ' ' . $image_limit . ' ' . __('image with this package', 'geodirectory') . ')</small>';
} ?>
<?php if ($image_limit != 0 && $image_limit > 1) {
echo '<br /><small>(' . __('You can upload', 'geodirectory') . ' ' . $image_limit . ' ' . __('images with this package', 'geodirectory') . ')</small>';
} ?>
<?php if ($image_limit == 0) {
echo '<br /><small>(' . __('You can upload unlimited images with this package', 'geodirectory') . ')</small>';
} ?>
</h5>
<?php
$curImages = geodir_get_images($post_id);
$place_img_array = array();
if (!empty($curImages)):
foreach ($curImages as $p_img):
$place_img_array[] = $p_img->src;
endforeach;
endif;
if (!empty($place_img_array))
$curImages = implode(',', $place_img_array);
// adjust values here
$id = "post_images"; // this will be the name of form field. Image url(s) will be submitted in $_POST using this key. So if $id == �img1� then $_POST[�img1�] will have all the image urls
$svalue = $curImages; // this will be initial value of the above form field. Image urls.
$multiple = true; // allow multiple files upload
$width = geodir_media_image_large_width(); // If you want to automatically resize all uploaded images then provide width here (in pixels)
$height = geodir_media_image_large_height(); // If you want to automatically resize all uploaded images then provide height here (in pixels)
?>
<div class="gtd-form_row clearfix" id="<?php echo $id; ?>dropbox" style="border:1px solid #999999;padding:5px;text-align:center;">
<input type="hidden" name="<?php echo $id; ?>" id="<?php echo $id; ?>" value="<?php echo $svalue; ?>"/>
<div
class="plupload-upload-uic hide-if-no-js <?php if ($multiple): ?>plupload-upload-uic-multiple<?php endif; ?>"
id="<?php echo $id; ?>plupload-upload-ui">
<h4><?php _e('Drop files to upload', 'geodirectory');?></h4>
<input id="<?php echo $id; ?>plupload-browse-button" type="button"
value="<?php _e('Select Files', 'geodirectory'); ?>" class="button"/>
<span class="ajaxnonceplu" id="ajaxnonceplu<?php echo wp_create_nonce($id . 'pluploadan'); ?>"></span>
<?php if ($width && $height): ?>
<span class="plupload-resize"></span>
<span class="plupload-width" id="plupload-width<?php echo $width; ?>"></span>
<span class="plupload-height" id="plupload-height<?php echo $height; ?>"></span>
<?php endif; ?>
<div class="filelist"></div>
</div>
<div class="plupload-thumbs <?php if ($multiple): ?>plupload-thumbs-multiple<?php endif; ?> clearfix"
id="<?php echo $id; ?>plupload-thumbs" style="border-top:1px solid #ccc; padding-top:10px;">
</div>
<span
id="upload-msg"><?php _e('Please drag &amp; drop the images to rearrange the order', 'geodirectory');?></span>
<span id="<?php echo $id; ?>upload-error" style="display:none"></span>
</div>
<?php
}
/**
* Updates custom table when post get updated.
*
* @since 1.0.0
* @package GeoDirectory
* @param int $post_ID The post ID.
* @param object $post_after Post object after the update.
* @param object $post_before Post object before the update.
*/
function geodir_action_post_updated($post_ID, $post_after, $post_before)
{
$post_type = get_post_type($post_ID);
if (isset($_POST['action']) && $_POST['action'] == 'inline-save') {
if ($post_type != '' && in_array($post_type, geodir_get_posttypes()) && !wp_is_post_revision($post_ID) && !empty($post_after->post_title) && $post_after->post_title != $post_before->post_title) {
geodir_save_post_meta($post_ID, 'post_title', $post_after->post_title);
}
}
}
/**
* Add Listing published bcc option.
*
* WP Admin -> Geodirectory -> Notifications -> Site Bcc Options
*
* @since 1.0.0
* @package GeoDirectory
* @param array $settings The settings array.
* @return array
*/
function geodir_notification_add_bcc_option($settings)
{
if (!empty($settings)) {
$new_settings = array();
foreach ($settings as $setting) {
if (isset($setting['id']) && $setting['id'] == 'site_bcc_options' && isset($setting['type']) && $setting['type'] == 'sectionend') {
$geodir_bcc_listing_published_yes = array(
'name' => __('Listing published', 'geodirectory'),
'desc' => __('Yes', 'geodirectory'),
'id' => 'geodir_bcc_listing_published',
'std' => 'yes',
'type' => 'radio',
'value' => '1',
'radiogroup' => 'start'
);
$geodir_bcc_listing_published_no = array(
'name' => __('Listing published', 'geodirectory'),
'desc' => __('No', 'geodirectory'),
'id' => 'geodir_bcc_listing_published',
'std' => 'yes',
'type' => 'radio',
'value' => '0',
'radiogroup' => 'end'
);
$new_settings[] = $geodir_bcc_listing_published_yes;
$new_settings[] = $geodir_bcc_listing_published_no;
}
$new_settings[] = $setting;
}
$settings = $new_settings;
}
return $settings;
}
add_action('wp_ajax_get_gd_theme_compat_callback', 'get_gd_theme_compat_callback');
/**
* Exports theme compatibility data for given theme.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
*/
function get_gd_theme_compat_callback()
{
global $wpdb;
$themes = get_option('gd_theme_compats');
if (isset($_POST['theme']) && isset($themes[$_POST['theme']]) && !empty($themes[$_POST['theme']])) {
if (isset($_POST['export'])) {
echo json_encode(array($_POST['theme'] => $themes[$_POST['theme']]));
} else {
echo json_encode($themes[$_POST['theme']]);
}
}
die();
}
add_action('wp_ajax_get_gd_theme_compat_import_callback', 'get_gd_theme_compat_import_callback');
/**
* Imports theme compatibility data for given theme.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
*/
function get_gd_theme_compat_import_callback()
{
global $wpdb;
$themes = get_option('gd_theme_compats');
if (isset($_POST['theme']) && !empty($_POST['theme'])) {
$json = json_decode(stripslashes($_POST['theme']), true);
if (!empty($json) && is_array($json)) {
$key = sanitize_text_field(key($json));
$themes[$key] = $json[$key];
update_option('gd_theme_compats', $themes);
echo $key;
die();
}
}
echo '0';
die();
}
/**
* Sets theme compatibility options.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
*/
function gd_set_theme_compat()
{
global $wpdb;
$theme = wp_get_theme();
if ($theme->parent()) {
$theme_name = str_replace(" ", "_", $theme->parent()->get('Name'));
} else {
$theme_name = str_replace(" ", "_", $theme->get('Name'));
}
$theme_compats = get_option('gd_theme_compats');
$current_compat = get_option('gd_theme_compat');
$current_compat = str_replace("_custom", "", $current_compat);
if ($current_compat == $theme_name && strpos(get_option('gd_theme_compat'), "_custom") !== false) {
return;
}// if already running correct compat then bail
if (isset($theme_compats[$theme_name])) {// if there is a compat avail then set it
update_option('gd_theme_compat', $theme_name);
update_option('theme_compatibility_setting', $theme_compats[$theme_name]);
// if there are default options to set then set them
if (isset($theme_compats[$theme_name]['geodir_theme_compat_default_options']) && !empty($theme_compats[$theme_name]['geodir_theme_compat_default_options'])) {
foreach ($theme_compats[$theme_name]['geodir_theme_compat_default_options'] as $key => $val) {
update_option($key, $val);
}
}
} else {
update_option('gd_theme_compat', '');
update_option('theme_compatibility_setting', '');
}
}
add_action('wp_loaded', 'gd_check_avada_compat');
/**
* Function to check if Avada needs header.php replaced
*
* @since 1.0.0
* @package GeoDirectory
*/
function gd_check_avada_compat()
{
if (function_exists('avada_load_textdomain') && !get_option('avada_nag')) {
add_action('admin_notices', 'gd_avada_compat_warning');
}
}
/**
* Displays Avada compatibility warning.
*
* @since 1.0.0
* @package GeoDirectory
*/
function gd_avada_compat_warning()
{
/*
$msg_type = error
$msg_type = updated fade
$msg_type = update-nag
*/
$plugin = 'avada-nag';
$timestamp = 'avada-nag1234';
$message = __('Welcome to GeoDirectory, please have a look <a href="https://docs.wpgeodirectory.com/category/getting-started/" target="_blank">here</a> to get started. :)', 'geodirectory');
echo '<div id="' . $timestamp . '" class="error">';
echo '<span class="gd-remove-noti" onclick="gdRemoveANotification(\'' . $plugin . '\',\'' . $timestamp . '\');" ><i class="fas fa-times"></i></span>';
echo "<img class='gd-icon-noti' src='" . plugin_dir_url('') . "geodirectory/geodirectory-assets/images/favicon.ico' > ";
echo "<p>$message</p>";
echo "</div>";
?>
<script>
function gdRemoveANotification($plugin, $timestamp) {
jQuery('#' + $timestamp).css("background-color", "red");
jQuery('#' + $timestamp).fadeOut("slow");
// This does the ajax request
jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: {
'action': 'geodir_avada_remove_notification',
'plugin': $plugin,
'timestamp': $timestamp
},
success: function (data) {
// This outputs the result of the ajax request
//alert(data);
},
error: function (errorThrown) {
console.log(errorThrown);
}
});
}
</script>
<style>
.gd-icon-noti {
float: left;
margin-top: 10px;
margin-right: 5px;
}
.update-nag .gd-icon-noti {
margin-top: 2px;
}
.gd-remove-noti {
float: right;
margin-top: -20px;
margin-right: -20px;
color: #FF0000;
cursor: pointer;
}
.updated .gd-remove-noti, .error .gd-remove-noti {
float: right;
margin-top: -10px;
margin-right: -17px;
color: #FF0000;
cursor: pointer;
}
</style>
<?php
}
/**
* Removes Avada compatibility warning.
*
* @since 1.0.0
* @package GeoDirectory
*/
function geodir_avada_remove_notification()
{
update_option('avada_nag', TRUE);
// Always die in functions echoing ajax content
die();
}
add_action('wp_ajax_geodir_avada_remove_notification', 'geodir_avada_remove_notification');
/**
* Get the current post type in the WordPress admin
*
* @since 1.4.2
* @package GeoDirectory
*
* @global null|WP_Post $post Post object.
* @global string $typenow Post type.
* @global object|WP_Screen $current_screen Current screen object
*
* @return string Post type ex: gd_place
*/
function geodir_admin_current_post_type() {
global $post, $typenow, $current_screen;
$post_type = NULL;
if (isset($_REQUEST['post_type']))
$post_type = sanitize_key($_REQUEST['post_type']);
elseif (isset($_REQUEST['post']) && get_post_type($_REQUEST['post']))
$post_type = get_post_type($_REQUEST['post']);
elseif ($post && isset($post->post_type))
$post_type = $post->post_type;
elseif ($typenow)
$post_type = $typenow;
elseif ($current_screen && isset($current_screen->post_type))
$post_type = $current_screen->post_type;
return $post_type;
}
/**
* Fires before updating geodirectory admin settings.
*
* @since 1.4.2
* @package GeoDirectory
*
* @global object $sitepress Sitepress WPML object.
*
* @param string $current_tab Current tab in geodirectory settings.
* @param array $geodir_settings Array of geodirectory settings.
*/
function geodir_before_update_options($current_tab, $geodir_settings) {
$active_tab = isset($_REQUEST['active_tab']) ? trim($_REQUEST['active_tab']) : '';
// Permalink settings
if ($current_tab == 'permalink_settings') {
$listing_prefix = isset($_POST['geodir_listing_prefix']) ? trim($_POST['geodir_listing_prefix']) : '';
$location_prefix = isset($_POST['geodir_location_prefix']) ? trim($_POST['geodir_location_prefix']) : '';
// Don't allow same slug url for listing and location
if (geodir_strtolower($listing_prefix) == geodir_strtolower($location_prefix)) {
$redirect_url = admin_url('admin.php?page=geodirectory&tab=' . $current_tab . '&active_tab=' . $active_tab . '&msg=fail&gderr=21');
wp_redirect($redirect_url);
exit;
}
// Don't allow to update page settings on different language.
if (geodir_is_wpml()) {
global $sitepress;
$current_language = $sitepress->get_current_language();
$default_language = $sitepress->get_default_language();
if ($current_language != 'all' && $current_language != $default_language) {
$redirect_url = admin_url('admin.php?page=geodirectory&tab=' . $current_tab . '&active_tab=' . $active_tab);
wp_redirect($redirect_url);
exit;
}
}
}
}
/**
* Removes the preview buttons from the wp-admin area for GD post types.
*
* This was removed as the preview page was causing bugs.
*
* @global string $post_type The current post type.
* @since 1.4.3
* @package GeoDirectory
*/
function geodir_hide_admin_preview_button() {
global $post_type;
$post_types = geodir_get_posttypes();
if(in_array($post_type, $post_types))
echo '<style type="text/css">#post-preview, #view-post-btn{display: none;}</style>';
}
add_action( 'admin_head-post-new.php', 'geodir_hide_admin_preview_button' );
add_action( 'admin_head-post.php', 'geodir_hide_admin_preview_button' );
/**
* Add the tab in left sidebar menu fro import & export page.
*
* @since 1.4.6
* @package GeoDirectory
*
* @return array Array of tab data.
*/
function geodir_import_export_tab( $tabs ) {
$tabs['import_export'] = array( 'label' => __( 'Import & Export', 'geodirectory' ) );
return $tabs;
}
/**
* Display the page to manage import/export categories/listings.
*
* @since 1.4.6
* @since 1.5.6 Option added to export max number listings per csv file.
* @package GeoDirectory
*
* @return string Html content.
*/
function geodir_import_export_page() {
$nonce = wp_create_nonce( 'geodir_import_export_nonce' );
$gd_cats_sample_csv = geodir_plugin_url() . '/geodirectory-assets/gd_sample_categories.csv';
/**
* Filter sample category data csv file url.
*
* @since 1.0.0
* @package GeoDirectory
*
* @param string $gd_cats_sample_csv Sample category data csv file url.
*/
$gd_cats_sample_csv = apply_filters( 'geodir_export_cats_sample_csv', $gd_cats_sample_csv );
$gd_posts_sample_csv = geodir_plugin_url() . '/geodirectory-assets/place_listing.csv';
/**
* Filter sample post data csv file url.
*
* @since 1.0.0
* @package GeoDirectory
*
* @param string $gd_posts_sample_csv Sample post data csv file url.
*/
$gd_posts_sample_csv = apply_filters( 'geodir_export_posts_sample_csv', $gd_posts_sample_csv );
$gd_posttypes = geodir_get_posttypes( 'array' );
$gd_posttypes_option = '';
foreach ( $gd_posttypes as $gd_posttype => $row ) {
$gd_posttypes_option .= '<option value="' . $gd_posttype . '" data-cats="' . (int)geodir_get_terms_count( $gd_posttype ) . '" data-posts="' . (int)geodir_get_posts_count( $gd_posttype ) . '">' . __( $row['labels']['name'], 'geodirectory' ) . '</option>';
}
wp_enqueue_script( 'jquery-ui-progressbar' );
$gd_chunksize_options = array();
$gd_chunksize_options[100] = 100;
$gd_chunksize_options[200] = 200;
$gd_chunksize_options[500] = 500;
$gd_chunksize_options[1000] = 1000;
$gd_chunksize_options[2000] = 2000;
$gd_chunksize_options[5000] = 5000;
$gd_chunksize_options[10000] = 10000;
$gd_chunksize_options[20000] = 20000;
$gd_chunksize_options[50000] = 50000;
$gd_chunksize_options[100000] = 100000;
/**
* Filter max entries per export csv file.
*
* @since 1.5.6
* @package GeoDirectory
*
* @param string $gd_chunksize_options Entries options.
*/
$gd_chunksize_options = apply_filters( 'geodir_export_csv_chunksize_options', $gd_chunksize_options );
$gd_chunksize_option = '';
foreach ($gd_chunksize_options as $value => $title) {
$gd_chunksize_option .= '<option value="' . $value . '" ' . selected($value, 5000, false) . '>' . $title . '</option>';
}
$uploads = wp_upload_dir();
$upload_dir = wp_sprintf( CSV_TRANSFER_IMG_FOLDER, str_replace( ABSPATH, '', $uploads['path'] ) );
?>
</form>
<div class="inner_content_tab_main gd-import-export">
<h3><?php _e( 'GD Import & Export CSV', 'geodirectory' ) ;?></h3>
<span class="description"><?php _e( 'Import & export csv for GD listings & categories.', 'geodirectory' ) ;?></span>
<div class="gd-content-heading">
<?php
@ini_set('max_execution_time', 999999);
$ini_max_execution_time_check = @ini_get( 'max_execution_time' );
@ini_restore('max_execution_time');
if($ini_max_execution_time_check != 999999){ // only show these setting to the user if we can't change the ini setting
?>
<div id="gd_ie_reqs" class="metabox-holder">
<div class="meta-box-sortables ui-sortable">
<div class="postbox">
<h3 class="hndle"><span style='vertical-align:top;'><?php echo __( 'PHP Requirements for GD Import & Export CSV', 'geodirectory' );?></span></h3>
<div class="inside">
<span class="description"><?php echo __( 'Note: In case GD import & export csv not working for larger data then please check and configure following php settings.', 'geodirectory' );?></span>
<table class="form-table">
<thead>
<tr>
<th><?php _e( 'PHP Settings', 'geodirectory' );?></th><th><?php _e( 'Current Value', 'geodirectory' );?></th><th><?php _e( 'Recommended Value', 'geodirectory' );?></th>
</tr>
</thead>
<tbody>
<tr>
<td>max_input_time</td><td><?php echo @ini_get( 'max_input_time' );?></td><td>3000</td>
</tr>
<tr>
<td>max_execution_time</td><td><?php echo @ini_get( 'max_execution_time' );?></td><td>3000</td>
</tr>
<tr>
<td>memory_limit</td><td><?php echo @ini_get( 'memory_limit' );?></td><td>256M</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php }?>
<div id="gd_ie_imposts" class="metabox-holder">
<div class="meta-box-sortables ui-sortable">
<div id="gd_ie_im_posts" class="postbox gd-hndle-pbox">
<button class="handlediv button-link" type="button"><span class="screen-reader-text"><?php _e( 'Toggle panel - GD Listings: Import CSV', 'geodirectory' );?></span><span aria-hidden="true" class="toggle-indicator"></span></button>
<h3 class="hndle gd-hndle-click"><span style='vertical-align:top;'><?php echo __( 'GD Listings: Import CSV', 'geodirectory' );?></span></h3>
<div class="inside">
<table class="form-table">
<tbody>
<tr>
<td class="gd-imex-box">
<div class="gd-im-choices">
<p><input type="radio" value="update" name="gd_im_choicepost" id="gd_im_pchoice_u" /><label for="gd_im_pchoice_u"><?php _e( 'Update listing if post with post_id already exists.', 'geodirectory' );?></label></p>
<p><input type="radio" checked="checked" value="skip" name="gd_im_choicepost" id="gd_im_pchoice_s" /><label for="gd_im_pchoice_s"><?php _e( 'Ignore listing if post with post_id already exists.', 'geodirectory' );?></label></p>
</div>
<div class="plupload-upload-uic hide-if-no-js" id="gd_im_postplupload-upload-ui">
<input type="text" readonly="readonly" name="gd_im_post_file" class="gd-imex-file gd_im_post_file" id="gd_im_post" onclick="jQuery('#gd_im_postplupload-browse-button').trigger('click');" />
<input id="gd_im_postplupload-browse-button" type="button" value="<?php echo SELECT_UPLOAD_CSV; ?>" class="gd-imex-pupload button-primary" /><input type="button" value="<?php echo esc_attr( __( 'Download Sample CSV', 'geodirectory' ) );?>" class="button-secondary" name="gd_ie_imposts_sample" id="gd_ie_imposts_sample">
<input type="hidden" id="gd_ie_imposts_csv" value="<?php echo $gd_posts_sample_csv;?>" />
<input type="hidden" id="gd_im_post_allowed_types" data-exts=".csv" value="csv" />
<?php
/**
* Called just after the sample CSV download link.
*
* @since 1.0.0
*/
do_action('geodir_sample_csv_download_link');
?>
<span class="ajaxnonceplu" id="ajaxnonceplu<?php echo wp_create_nonce( 'gd_im_postpluploadan' ); ?>"></span>
<div class="filelist"></div>
</div>
<span id="gd_im_postupload-error" style="display:none"></span>
<span class="description"></span>
<div id="gd_importer" style="display:none">
<input type="hidden" id="gd_total" value="0"/>
<input type="hidden" id="gd_prepared" value="continue"/>
<input type="hidden" id="gd_processed" value="0"/>
<input type="hidden" id="gd_created" value="0"/>
<input type="hidden" id="gd_updated" value="0"/>
<input type="hidden" id="gd_skipped" value="0"/>
<input type="hidden" id="gd_invalid" value="0"/>
<input type="hidden" id="gd_invalid_addr" value="0"/>
<input type="hidden" id="gd_images" value="0"/>
<input type="hidden" id="gd_terminateaction" value="continue"/>
</div>
<div class="gd-import-progress" id="gd-import-progress" style="display:none">
<div class="gd-import-file"><b><?php _e("Import Data Status :", 'geodirectory');?> </b><font
id="gd-import-done">0</font> / <font id="gd-import-total">0</font>&nbsp;( <font
id="gd-import-perc">0%</font> )
<div class="gd-fileprogress"></div>
</div>
</div>
<div class="gd-import-msg" id="gd-import-msg" style="display:none">
<div id="message" class="message fade"></div>
</div>
<div class="gd-imex-btns" style="display:none;">
<input type="hidden" class="geodir_import_file" name="geodir_import_file" value="save"/>
<input onclick="gd_imex_PrepareImport(this, 'post')" type="button" value="<?php echo CSV_IMPORT_DATA; ?>" id="gd_import_data" class="button-primary" />
<input onclick="gd_imex_ContinueImport(this, 'post')" type="button" value="<?php _e( "Continue Import Data", 'geodirectory' );?>" id="gd_continue_data" class="button-primary" style="display:none"/>
<input type="button" value="<?php _e("Terminate Import Data", 'geodirectory');?>" id="gd_stop_import" class="button-primary" name="gd_stop_import" style="display:none" onclick="gd_imex_TerminateImport(this, 'post')"/>
<div id="gd_process_data" style="display:none">
<span class="spinner is-active" style="display:inline-block;margin:0 5px 0 5px;float:left"></span><?php _e("Wait, processing import data...", 'geodirectory');?>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div id="gd_ie_excategs" class="metabox-holder">
<div class="meta-box-sortables ui-sortable">
<div id="gd_ie_ex_posts" class="postbox gd-hndle-pbox">
<button class="handlediv button-link" type="button"><span class="screen-reader-text"><?php _e( 'Toggle panel - Listings: Export CSV', 'geodirectory' );?></span><span aria-hidden="true" class="toggle-indicator"></span></button>
<h3 class="hndle gd-hndle-click"><span style='vertical-align:top;'><?php echo __( 'GD Listings: Export CSV', 'geodirectory' );?></span></h3>
<div class="inside">
<table class="form-table">
<tbody>
<tr>
<td class="fld"><label for="gd_post_type">
<?php _e( 'Post Type:', 'geodirectory' );?>
</label></td>
<td><select name="gd_post_type" id="gd_post_type" style="min-width:140px">
<?php echo $gd_posttypes_option;?>
</select></td>
</tr>
<tr>
<td class="fld" style="vertical-align:top"><label for="gd_chunk_size"><?php _e( 'Max entries per csv file:', 'geodirectory' );?></label></td>
<td><select name="gd_chunk_size" id="gd_chunk_size" style="min-width:140px"><?php echo $gd_chunksize_option;?></select><span class="description"><?php _e( 'Please select the maximum number of entries per csv file (defaults to 5000, you might want to lower this to prevent memory issues on some installs)', 'geodirectory' );?></span></td>
</tr>
<tr class="gd-imex-dates">
<td class="fld"><label><?php _e( 'Published Date:', 'geodirectory' );?></label></td>
<td><label><span class="label-responsive"><?php _e( 'Start date:', 'geodirectory' );?></span><input type="text" id="gd_imex_start_date" name="gd_imex[start_date]" data-type="date" /></label><label><span class="label-responsive"><?php _e( 'End date:', 'geodirectory' );?></span><input type="text" id="gd_imex_end_date" name="gd_imex[end_date]" data-type="date" /></label></td>
</tr>
<tr>
<td class="fld" style="vertical-align:top"><label>
<?php _e( 'Progress:', 'geodirectory' );?>
</label></td>
<td><div id='gd_progressbar_box'>
<div id="gd_progressbar" class="gd_progressbar">
<div class="gd-progress-label"></div>
</div>
</div>
<p style="display:inline-block">
<?php _e( 'Elapsed Time:', 'geodirectory' );?>
</p>
  
<p id="gd_timer" class="gd_timer">00:00:00</p></td>
</tr>
<tr class="gd-ie-actions">
<td style="vertical-align:top"><input type="submit" value="<?php echo esc_attr( __( 'Export CSV', 'geodirectory' ) );?>" class="button-primary" name="gd_ie_exposts_submit" id="gd_ie_exposts_submit">
</td>
<td id="gd_ie_ex_files" class="gd-ie-files"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div id="gd_ie_imcategs" class="metabox-holder">
<div class="meta-box-sortables ui-sortable">
<div id="gd_ie_imcats" class="postbox gd-hndle-pbox">
<button class="handlediv button-link" type="button"><span class="screen-reader-text"><?php _e( 'Toggle panel - GD Categories: Import CSV', 'geodirectory' );?></span><span aria-hidden="true" class="toggle-indicator"></span></button>
<h3 class="hndle gd-hndle-click"><span style='vertical-align:top;'><?php echo __( 'GD Categories: Import CSV', 'geodirectory' );?></span></h3>
<div class="inside">
<table class="form-table">
<tbody>
<tr>
<td class="gd-imex-box">
<div class="gd-im-choices">
<p><input type="radio" value="update" name="gd_im_choicecat" id="gd_im_cchoice_u" /><label for="gd_im_cchoice_u"><?php _e( 'Update item if item with cat_id/cat_slug already exists.', 'geodirectory' );?></label></p>
<p><input type="radio" checked="checked" value="skip" name="gd_im_choicecat" id="gd_im_cchoice_s" /><label for="gd_im_cchoice_s"><?php _e( 'Ignore item if item with cat_id/cat_slug already exists.', 'geodirectory' );?></label></p>
</div>
<div class="plupload-upload-uic hide-if-no-js" id="gd_im_catplupload-upload-ui">
<input type="text" readonly="readonly" name="gd_im_cat_file" class="gd-imex-file gd_im_cat_file" id="gd_im_cat" onclick="jQuery('#gd_im_catplupload-browse-button').trigger('click');" />
<input id="gd_im_catplupload-browse-button" type="button" value="<?php echo SELECT_UPLOAD_CSV; ?>" class="gd-imex-cupload button-primary" /><input type="button" value="<?php echo esc_attr( __( 'Download Sample CSV', 'geodirectory' ) );?>" class="button-secondary" name="gd_ie_imcats_sample" id="gd_ie_imcats_sample">
<input type="hidden" id="gd_ie_imcats_csv" value="<?php echo $gd_cats_sample_csv;?>" />
<input type="hidden" id="gd_im_cat_allowed_types" data-exts=".csv" value="csv" />
<?php
/**
* Called just after the sample CSV download link.
*
* @since 1.0.0
* @package GeoDirectory
*/
do_action('geodir_sample_cats_csv_download_link');
?>
<span class="ajaxnonceplu" id="ajaxnonceplu<?php echo wp_create_nonce( 'gd_im_catpluploadan' ); ?>"></span>
<div class="filelist"></div>
</div>
<span id="gd_im_catupload-error" style="display:none"></span>
<span class="description"></span>
<div id="gd_importer" style="display:none">
<input type="hidden" id="gd_total" value="0"/>
<input type="hidden" id="gd_prepared" value="continue"/>
<input type="hidden" id="gd_processed" value="0"/>
<input type="hidden" id="gd_created" value="0"/>
<input type="hidden" id="gd_updated" value="0"/>
<input type="hidden" id="gd_skipped" value="0"/>
<input type="hidden" id="gd_invalid" value="0"/>
<input type="hidden" id="gd_images" value="0"/>
<input type="hidden" id="gd_terminateaction" value="continue"/>
</div>
<div class="gd-import-progress" id="gd-import-progress" style="display:none">
<div class="gd-import-file"><b><?php _e("Import Data Status :", 'geodirectory');?> </b><font
id="gd-import-done">0</font> / <font id="gd-import-total">0</font>&nbsp;( <font
id="gd-import-perc">0%</font> )
<div class="gd-fileprogress"></div>
</div>
</div>
<div class="gd-import-msg" id="gd-import-msg" style="display:none">
<div id="message" class="message fade"></div>
</div>
<div class="gd-imex-btns" style="display:none;">
<input type="hidden" class="geodir_import_file" name="geodir_import_file" value="save"/>
<input onclick="gd_imex_PrepareImport(this, 'cat')" type="button" value="<?php echo CSV_IMPORT_DATA; ?>" id="gd_import_data" class="button-primary" />
<input onclick="gd_imex_ContinueImport(this, 'cat')" type="button" value="<?php _e( "Continue Import Data", 'geodirectory' );?>" id="gd_continue_data" class="button-primary" style="display:none"/>
<input type="button" value="<?php _e("Terminate Import Data", 'geodirectory');?>" id="gd_stop_import" class="button-primary" name="gd_stop_import" style="display:none" onclick="gd_imex_TerminateImport(this, 'cat')"/>
<div id="gd_process_data" style="display:none">
<span class="spinner is-active" style="display:inline-block;margin:0 5px 0 5px;float:left"></span><?php _e("Wait, processing import data...", 'geodirectory');?>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div id="gd_ie_excategs" class="metabox-holder">
<div class="meta-box-sortables ui-sortable">
<div id="gd_ie_ex_cats" class="postbox gd-hndle-pbox">
<button class="handlediv button-link" type="button"><span class="screen-reader-text"><?php _e( 'Toggle panel - GD Categories: Export CSV', 'geodirectory' );?></span><span aria-hidden="true" class="toggle-indicator"></span></button>
<h3 class="hndle gd-hndle-click"><span style='vertical-align:top;'><?php echo __( 'GD Categories: Export CSV', 'geodirectory' );?></span></h3>
<div class="inside">
<table class="form-table">
<tbody>
<tr>
<td class="fld"><label for="gd_post_type"><?php _e( 'Post Type:', 'geodirectory' );?></label></td>
<td><select name="gd_post_type" id="gd_post_type" style="min-width:140px"><?php echo $gd_posttypes_option;?></select></td>
</tr>
<tr>
<td class="fld" style="vertical-align:top"><label for="gd_chunk_size"><?php _e( 'Max entries per csv file:', 'geodirectory' );?></label></td>
<td><select name="gd_chunk_size" id="gd_chunk_size" style="min-width:140px"><?php echo $gd_chunksize_option;?></select><span class="description"><?php _e( 'Please select the maximum number of entries per csv file (defaults to 5000, you might want to lower this to prevent memory issues on some installs)', 'geodirectory' );?></span></td>
</tr>
<tr>
<td class="fld" style="vertical-align:top"><label><?php _e( 'Progress:', 'geodirectory' );?></label></td>
<td><div id='gd_progressbar_box'><div id="gd_progressbar" class="gd_progressbar"><div class="gd-progress-label"></div></div></div><p style="display:inline-block"><?php _e( 'Elapsed Time:', 'geodirectory' );?></p>&nbsp;&nbsp;<p id="gd_timer" class="gd_timer">00:00:00</p></td>
</tr>
<tr class="gd-ie-actions">
<td style="vertical-align:top">
<input type="submit" value="<?php echo esc_attr( __( 'Export CSV', 'geodirectory' ) );?>" class="button-primary" name="gd_ie_excats_submit" id="gd_ie_excats_submit">
</td>
<td id="gd_ie_ex_files" class="gd-ie-files"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php
/**
* Allows you to add more setting to the GD > Import & Export page.
*
* Called after the last setting on the GD > Import & Export page.
* @since 1.4.6
* @package GeoDirectory
*
* @param array $gd_posttypes GD post types.
* @param array $gd_chunksize_options File chunk size options.
* @param string $nonce Wordpress security token for GD import & export.
*/
do_action( 'geodir_import_export', $gd_posttypes, $gd_chunksize_options, $nonce );
?>
</div>
</div>
<script type="text/javascript">
var timoutC, timoutP, timoutL, timoutH;
function gd_imex_PrepareImport(el, type) {
var cont = jQuery(el).closest('.gd-imex-box');
var gd_prepared = jQuery('#gd_prepared', cont).val();
var uploadedFile = jQuery('#gd_im_' + type, cont).val();
jQuery('gd-import-msg', cont).hide();
if(gd_prepared == uploadedFile) {
gd_imex_ContinueImport(el, type);
jQuery('#gd_import_data', cont).attr('disabled', 'disabled');
} else {
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: 'action=geodir_import_export&task=prepare_import&_pt=' + type + '&_file=' + uploadedFile + '&_nonce=<?php echo $nonce;?>',
dataType: 'json',
cache: false,
success: function(data) {
if(typeof data == 'object') {
if(data.error) {
jQuery('#gd-import-msg', cont).find('#message').removeClass('updated').addClass('error').html('<p>' + data.error + '</p>');
jQuery('#gd-import-msg', cont).show();
} else if(!data.error && typeof data.rows != 'undefined') {
jQuery('#gd_total', cont).val(data.rows);
jQuery('#gd_prepared', cont).val(uploadedFile);
jQuery('#gd_processed', cont).val('0');
jQuery('#gd_created', cont).val('0');
jQuery('#gd_updated', cont).val('0');
jQuery('#gd_skipped', cont).val('0');
jQuery('#gd_invalid', cont).val('0');
jQuery('#gd_images', cont).val('0');
if(type == 'post') {
jQuery('#gd_invalid_addr', cont).val('0');
}
gd_imex_StartImport(el, type);
}
}
},
error: function(errorThrown) {
console.log(errorThrown);
}
});
}
}
function gd_imex_StartImport(el, type) {
var cont = jQuery(el).closest('.gd-imex-box');
var limit = 1;
var total = parseInt(jQuery('#gd_total', cont).val());
var total_processed = parseInt(jQuery('#gd_processed', cont).val());
var uploadedFile = jQuery('#gd_im_' + type, cont).val();
var choice = jQuery('input[name="gd_im_choice'+ type +'"]:checked', cont).val();
if (!uploadedFile) {
jQuery('#gd_import_data', cont).removeAttr('disabled').show();
jQuery('#gd_stop_import', cont).hide();
jQuery('#gd_process_data', cont).hide();
jQuery('#gd-import-progress', cont).hide();
jQuery('.gd-fileprogress', cont).width(0);
jQuery('#gd-import-done', cont).text('0');
jQuery('#gd-import-total', cont).text('0');
jQuery('#gd-import-perc', cont).text('0%');
jQuery(cont).find('.filelist .file').remove();
jQuery('#gd-import-msg', cont).find('#message').removeClass('updated').addClass('error').html("<p><?php echo esc_attr( PLZ_SELECT_CSV_FILE );?></p>");
jQuery('#gd-import-msg', cont).show();
return false;
}
jQuery('#gd-import-total', cont).text(total);
jQuery('#gd_stop_import', cont).show();
jQuery('#gd_process_data', cont).css({
'display': 'inline-block'
});
jQuery('#gd-import-progress', cont).show();
if ((parseInt(total) / 100) > 0) {
limit = parseInt(parseInt(total) / 100);
}
if (limit == 1) {
if (parseInt(total) > 50) {
limit = 5;
} else if (parseInt(total) > 10 && parseInt(total) < 51) {
limit = 2;
}
}
if (limit > 10) {
limit = 10;
}
if (limit < 1) {
limit = 1;
}
if ( parseInt(limit) > parseInt(total) )
limit = parseInt(total);
if (total_processed >= total) {
jQuery('#gd_import_data', cont).removeAttr('disabled').show();
jQuery('#gd_stop_import', cont).hide();
jQuery('#gd_process_data', cont).hide();
gd_imex_showStatusMsg(el, type);
jQuery('#gd_im_' + type, cont).val('');
jQuery('#gd_prepared', cont).val('');
return false;
}
jQuery('#gd-import-msg', cont).hide();
var gd_processed = parseInt(jQuery('#gd_processed', cont).val());
var gd_created = parseInt(jQuery('#gd_created', cont).val());
var gd_updated = parseInt(jQuery('#gd_updated', cont).val());
var gd_skipped = parseInt(jQuery('#gd_skipped', cont).val());
var gd_invalid = parseInt(jQuery('#gd_invalid', cont).val());
var gd_images = parseInt(jQuery('#gd_images', cont).val());
if (type=='post') {
var gd_invalid_addr = parseInt(jQuery('#gd_invalid_addr', cont).val());
}
var gddata = '&limit=' + limit + '&processed=' + gd_processed;
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: 'action=geodir_import_export&task=import_' + type + '&_pt=' + type + '&_file=' + uploadedFile + gddata + '&_ch=' + choice + '&_nonce=<?php echo $nonce;?>',
dataType : 'json',
cache: false,
success: function (data) {
if (typeof data == 'object') {
if (data.error) {
jQuery('#gd_import_data', cont).removeAttr('disabled').show();
jQuery('#gd_stop_import', cont).hide();
jQuery('#gd_process_data', cont).hide();
jQuery('#gd-import-msg', cont).find('#message').removeClass('updated').addClass('error').html('<p>' + data.error + '</p>');
jQuery('#gd-import-msg', cont).show();
} else {
gd_processed = gd_processed + parseInt(data.processed);
gd_processed = Math.min(gd_processed, total);
gd_created = gd_created + parseInt(data.created);
gd_updated = gd_updated + parseInt(data.updated);
gd_skipped = gd_skipped + parseInt(data.skipped);
gd_invalid = gd_invalid + parseInt(data.invalid);
gd_images = gd_images + parseInt(data.images);
if (type=='post' && typeof data.invalid_addr != 'undefined') {
gd_invalid_addr = gd_invalid_addr + parseInt(data.invalid_addr);
}
jQuery('#gd_processed', cont).val(gd_processed);
jQuery('#gd_created', cont).val(gd_created);
jQuery('#gd_updated', cont).val(gd_updated);
jQuery('#gd_skipped', cont).val(gd_skipped);
jQuery('#gd_invalid', cont).val(gd_invalid);
jQuery('#gd_images', cont).val(gd_images);
if (type=='post') {
jQuery('#gd_invalid_addr', cont).val(gd_invalid_addr);
}
if (parseInt(gd_processed) == parseInt(total)) {
jQuery('#gd-import-done', cont).text(total);
jQuery('#gd-import-perc', cont).text('100%');
jQuery('.gd-fileprogress', cont).css({
'width': '100%'
});
jQuery('#gd_im_' + type, cont).val('');
jQuery('#gd_prepared', cont).val('');
gd_imex_showStatusMsg(el, type);
gd_imex_FinishImport(el, type);
jQuery('#gd_stop_import', cont).hide();
}
if (parseInt(gd_processed) < parseInt(total)) {
var terminate_action = jQuery('#gd_terminateaction', cont).val();
if (terminate_action == 'continue') {
var nTmpCnt = parseInt(total_processed) + parseInt(limit);
nTmpCnt = nTmpCnt > total ? total : nTmpCnt;
jQuery('#gd_processed', cont).val(nTmpCnt);
jQuery('#gd-import-done', cont).text(nTmpCnt);
if (parseInt(total) > 0) {
var percentage = ((parseInt(nTmpCnt) / parseInt(total)) * 100);
percentage = percentage > 100 ? 100 : percentage;
jQuery('#gd-import-perc', cont).text(parseInt(percentage) + '%');
jQuery('.gd-fileprogress', cont).css({
'width': percentage + '%'
});
}
if (type=='cat') {
clearTimeout(timoutC);
timoutC = setTimeout(function () {
gd_imex_StartImport(el, type);
}, 0);
}
if (type=='post') {
clearTimeout(timoutP);
timoutP = setTimeout(function () {
gd_imex_StartImport(el, type);
}, 0);
}
if (type=='loc') {
clearTimeout(timoutL);
timoutL = setTimeout(function () {
gd_imex_StartImport(el, type);
}, 0);
}
if (type=='hood') {
clearTimeout(timoutH);
timoutH = setTimeout(function () {
gd_imex_StartImport(el, type);
}, 0);
}
} else {
jQuery('#gd_import_data', cont).hide();
jQuery('#gd_stop_import', cont).hide();
jQuery('#gd_process_data', cont).hide();
jQuery('#gd_continue_data', cont).show();
return false;
}
} else {
jQuery('#gd_import_data', cont).removeAttr('disabled').show();
jQuery('#gd_stop_import', cont).hide();
jQuery('#gd_process_data', cont).hide();
return false;
}
}
} else {
jQuery('#gd_import_data', cont).removeAttr('disabled').show();
jQuery('#gd_stop_import', cont).hide();
jQuery('#gd_process_data', cont).hide();
}
},
error: function (errorThrown) {
jQuery('#gd_import_data', cont).removeAttr('disabled').show();
jQuery('#gd_stop_import', cont).hide();
jQuery('#gd_process_data', cont).hide();
console.log(errorThrown);
}
});
}
function gd_imex_TerminateImport(el, type) {
var cont = jQuery(el).closest('.gd-imex-box');
jQuery('#gd_terminateaction', cont).val('terminate');
jQuery('#gd_import_data', cont).hide();
jQuery('#gd_stop_import', cont).hide();
jQuery('#gd_process_data', cont).hide();
jQuery('#gd_continue_data', cont).show();
}
function gd_imex_ContinueImport(el, type) {
var cont = jQuery(el).closest('.gd-imex-box');
var processed = jQuery('#gd_processed', cont).val();
var total = jQuery('#gd_total', cont).val();
if (parseInt(processed) > parseInt(total)) {
jQuery('#gd_stop_import', cont).hide();
} else {
jQuery('#gd_stop_import', cont).show();
}
jQuery('#gd_import_data', cont).show();
jQuery('#gd_import_data', cont).attr('disabled', 'disabled');
jQuery('#gd_process_data', cont).css({
'display': 'inline-block'
});
jQuery('#gd_continue_data', cont).hide();
jQuery('#gd_terminateaction', cont).val('continue');
if (type=='cat') {
clearTimeout(timoutC);
timoutC = setTimeout(function () {
gd_imex_StartImport(el, type);
}, 0);
}
if (type=='post') {
clearTimeout(timoutP);
timoutP = setTimeout(function () {
gd_imex_StartImport(el, type);
}, 0);
}
if (type=='loc') {
clearTimeout(timoutL);
timoutL = setTimeout(function () {
gd_imex_StartImport(el, type);
}, 0);
}
if (type=='hood') {
clearTimeout(timoutH);
timoutH = setTimeout(function () {
gd_imex_StartImport(el, type);
}, 0);
}
}
function gd_imex_showStatusMsg(el, type) {
var cont = jQuery(el).closest('.gd-imex-box');
var total = parseInt(jQuery('#gd_total', cont).val());
var processed = parseInt(jQuery('#gd_processed', cont).val());
var created = parseInt(jQuery('#gd_created', cont).val());
var updated = parseInt(jQuery('#gd_updated', cont).val());
var skipped = parseInt(jQuery('#gd_skipped', cont).val());
var invalid = parseInt(jQuery('#gd_invalid', cont).val());
var images =