| 1 |
<?php |
| 2 |
namespace Wdk\DashWidgets\Widgets; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
class WDK_Dashboard_Widget_Map_Listings extends WDK_DashWidgets { |
| 8 |
|
| 9 |
/** |
| 10 |
* The id of this widget. |
| 11 |
*/ |
| 12 |
static $widget_id = 'wdk_dashboard_widget_map_listings'; |
| 13 |
|
| 14 |
/** |
| 15 |
* Hook to wp_dashboard_setup to add the widget. |
| 16 |
*/ |
| 17 |
public static function init() { |
| 18 |
//Register widget settings... |
| 19 |
self::update_dashboard_widget_options( |
| 20 |
self::$widget_id, //The widget id |
| 21 |
array( //Associative array of options & default values |
| 22 |
'example_number' => 42, |
| 23 |
), |
| 24 |
true //Add only (will not update existing options) |
| 25 |
); |
| 26 |
|
| 27 |
//Register the widget... |
| 28 |
wp_add_dashboard_widget( |
| 29 |
self::$widget_id, //A unique slug/ID |
| 30 |
__( 'Wdk Listings map', 'wpdirectorykit' ),//Visible name for the widget |
| 31 |
array('Wdk\DashWidgets\Widgets\WDK_Dashboard_Widget_Map_Listings','widget'), //Callback for the main widget content |
| 32 |
array('Wdk\DashWidgets\Widgets\WDK_Dashboard_Widget_Map_Listings','config') //Optional callback for widget configuration content |
| 33 |
); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Load the widget code |
| 38 |
*/ |
| 39 |
public static function widget() { |
| 40 |
|
| 41 |
$WMVC = &wdk_get_instance(); |
| 42 |
$WMVC->model('listing_m'); |
| 43 |
$WMVC->load_helper('listing'); |
| 44 |
|
| 45 |
$data = array(); |
| 46 |
|
| 47 |
wp_enqueue_style('leaflet'); |
| 48 |
wp_enqueue_style('leaflet-cluster-def'); |
| 49 |
wp_enqueue_style('leaflet-cluster'); |
| 50 |
wp_enqueue_script('leaflet'); |
| 51 |
wp_enqueue_script('leaflet-cluster'); |
| 52 |
wp_enqueue_script('wdk-dash-widgets-map-listings'); |
| 53 |
wp_enqueue_style('wdk-dash-widgets-map-listings'); |
| 54 |
|
| 55 |
wp_enqueue_style('wdk-notify'); |
| 56 |
wp_enqueue_script('wdk-notify'); |
| 57 |
wp_enqueue_style( 'wdk-listings-map' ); |
| 58 |
if(defined('ELEMENTOR_ASSETS_URL')){ |
| 59 |
wp_register_style( |
| 60 |
'elementor-font-awesome', |
| 61 |
ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/font-awesome.min.css', |
| 62 |
[], |
| 63 |
'4.7.0' |
| 64 |
); |
| 65 |
wp_register_style( |
| 66 |
'elementor-font-awesome-solid', |
| 67 |
ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/solid.css' |
| 68 |
); |
| 69 |
wp_register_style( |
| 70 |
'elementor-font-awesome-5', |
| 71 |
ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/fontawesome.css' |
| 72 |
); |
| 73 |
wp_register_style( |
| 74 |
'elementor-font-awesome-brands', |
| 75 |
ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/brands.css' |
| 76 |
); |
| 77 |
wp_register_style( |
| 78 |
'elementor-font-awesome-regular', |
| 79 |
ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/regular.css' |
| 80 |
); |
| 81 |
} |
| 82 |
|
| 83 |
wp_enqueue_style( 'elementor-font-awesome-regular' ); |
| 84 |
wp_enqueue_style( 'elementor-font-awesome-brands' ); |
| 85 |
wp_enqueue_style( 'elementor-font-awesome-solid' ); |
| 86 |
wp_enqueue_style( 'elementor-font-awesome-5' ); |
| 87 |
wp_enqueue_style( 'elementor-font-awesome' ); |
| 88 |
|
| 89 |
/* default from settings */ |
| 90 |
$data['lat'] = wdk_get_option('wdk_default_lat', 51.505); |
| 91 |
$data['lng'] = wdk_get_option('wdk_default_lng', -0.09); |
| 92 |
|
| 93 |
$data['id_element'] = self::$widget_id; |
| 94 |
|
| 95 |
$data['settings'] = array( |
| 96 |
'conf_limit' => 50, |
| 97 |
'conf_custom_map_zoom_index' => 10, |
| 98 |
'conf_custom_dragging' => 'yes', |
| 99 |
'conf_custom_map_style' => '', |
| 100 |
'conf_custom_map_pin_icon' => '', |
| 101 |
'conf_custom_map_pin' => '', |
| 102 |
'conf_custom_map_height' => 450, |
| 103 |
'enable_custom_gps_center' => '', |
| 104 |
|
| 105 |
); |
| 106 |
|
| 107 |
$columns = array('ID', 'location_id', 'category_id', 'post_title', 'post_date', 'search', 'order_by','is_featured', 'address'); |
| 108 |
$controller = 'listing'; |
| 109 |
$custom_parameters = array(); |
| 110 |
|
| 111 |
if(!empty($data['settings']['conf_query'])) { |
| 112 |
$qr_string = trim($data['settings']['conf_query'],'?'); |
| 113 |
$string_par = array(); |
| 114 |
parse_str($qr_string, $string_par); |
| 115 |
$custom_parameters += array_map('trim', $string_par); |
| 116 |
} |
| 117 |
|
| 118 |
$external_columns = array('location_id', 'category_id', 'post_title'); |
| 119 |
wdk_prepare_search_query_GET($columns, $controller.'_m', $external_columns, $custom_parameters); |
| 120 |
$data['results'] = $WMVC->listing_m->get_pagination($data['settings']['conf_limit'], NULL, array('is_activated' => 1,'is_approved'=>1,'('.$WMVC->listing_m->_table_name.'.lat NOT LIKE "0%" and '.$WMVC->listing_m->_table_name.'.lng NOT LIKE "0%")' => NULL), TRUE); |
| 121 |
|
| 122 |
self::view('dash-widgets-map-listings', $data, true); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Load widget config code. |
| 127 |
* |
| 128 |
* This is what will display when an admin clicks |
| 129 |
*/ |
| 130 |
public static function config() { |
| 131 |
wp_redirect(admin_url("admin.php?page=listing_settings")); exit; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
} |