Overview

Namespaces

  • None
  • WPGMZA
    • CustomFieldFilterWidget
    • Integration
    • MarkerListing
    • Selector

Classes

  • WPGMapsImportExport
  • WPGMZA\AddMapDialog
  • WPGMZA\AdminMarkerDataTable
  • WPGMZA\AjaxTable
  • WPGMZA\AutoLoader
  • WPGMZA\Categories
  • WPGMZA\Category
  • WPGMZA\CategoryTree
  • WPGMZA\CategoryTreeNode
  • WPGMZA\ContentEditorMapButton
  • WPGMZA\Crud
  • WPGMZA\CustomFieldFilter
  • WPGMZA\CustomFieldFilterController
  • WPGMZA\CustomFieldFilterWidget
  • WPGMZA\CustomFieldFilterWidget\Checkboxes
  • WPGMZA\CustomFieldFilterWidget\Dropdown
  • WPGMZA\CustomFieldFilterWidget\Text
  • WPGMZA\CustomFields
  • WPGMZA\CustomFieldsPage
  • WPGMZA\CustomMapObjectFields
  • WPGMZA\CustomMarkerFields
  • WPGMZA\Database
  • WPGMZA\DataTable
  • WPGMZA\Distance
  • WPGMZA\DOMDocument
  • WPGMZA\DOMElement
  • WPGMZA\Export
  • WPGMZA\Factory
  • WPGMZA\FontAwesomeIconPicker
  • WPGMZA\GDPRCompliance
  • WPGMZA\GlobalSettings
  • WPGMZA\GoogleGeocoder
  • WPGMZA\GoogleMap
  • WPGMZA\GoogleMapsAPILoader
  • WPGMZA\GoogleMapsLoader
  • WPGMZA\GoogleProMapsLoader
  • WPGMZA\Import
  • WPGMZA\ImportCSV
  • WPGMZA\ImportGPX
  • WPGMZA\ImportJSON
  • WPGMZA\ImportKML
  • WPGMZA\Integration\Gutenberg
  • WPGMZA\Integration\ProGutenberg
  • WPGMZA\Integration\WPMigrateDB
  • WPGMZA\LatLng
  • WPGMZA\Map
  • WPGMZA\MapSelect
  • WPGMZA\MapsEngineDialog
  • WPGMZA\Marker
  • WPGMZA\MarkerDataTable
  • WPGMZA\MarkerFilter
  • WPGMZA\MarkerLibraryDialog
  • WPGMZA\MarkerListing
  • WPGMZA\MarkerListing\AdvancedTable
  • WPGMZA\MarkerListing\BasicList
  • WPGMZA\MarkerListing\BasicTable
  • WPGMZA\MarkerListing\Carousel
  • WPGMZA\MarkerListing\Modern
  • WPGMZA\ModalDialog
  • WPGMZA\NominatimGeocodeCache
  • WPGMZA\OLLoader
  • WPGMZA\OLProLoader
  • WPGMZA\Plugin
  • WPGMZA\ProAdminMarkerDataTable
  • WPGMZA\ProMap
  • WPGMZA\ProMarker
  • WPGMZA\ProMarkerFilter
  • WPGMZA\ProPlugin
  • WPGMZA\ProRestAPI
  • WPGMZA\Query
  • WPGMZA\QueryFragment
  • WPGMZA\RestAPI
  • WPGMZA\ScriptLoader
  • WPGMZA\Selector\AttributeSelector
  • WPGMZA\Selector\Parser
  • WPGMZA\Selector\PseudoSelector
  • WPGMZA\Selector\Selector
  • WPGMZA\Selector\Token
  • WPGMZA\Selector\Tokenizer
  • WPGMZA\Selector\TokenStream
  • WPGMZA\Selector\XPathConverter
  • WPGMZA\Strings
  • WPGMZA\Table

Exceptions

  • WPGMZA\Selector\ConvertException
  • WPGMZA\Selector\ParseException

Functions

  • old_wpgmaps_list_categories
  • old_wpgmza_pro_return_category_select_list
  • wpgmaps_admin_add_poly_javascript
  • wpgmaps_admin_add_polyline_javascript
  • wpgmaps_admin_category_scripts
  • wpgmaps_admin_category_styles
  • wpgmaps_admin_edit_poly_javascript
  • wpgmaps_admin_edit_polyline_javascript
  • wpgmaps_admin_wizard_scripts
  • wpgmaps_category_head
  • wpgmaps_list_categories
  • wpgmaps_menu_category_layout
  • wpgmaps_trash_cat
  • wpgmaps_wizard_layout
  • WPGMZA\add_custom_filter_widgets
  • WPGMZA\create_marker_instance_delegate
  • WPGMZA\custom_field_filter_get_filtered_marker_ids
  • WPGMZA\get_custom_field_filter
  • WPGMZA\get_custom_field_filter_controller
  • WPGMZA\get_custom_field_filter_widget
  • WPGMZA\get_marker_custom_fields
  • WPGMZA\import_ajax_delete_schedule
  • WPGMZA\import_ajax_file_options
  • WPGMZA\import_ajax_handle_delete
  • WPGMZA\import_ajax_handle_upload
  • WPGMZA\import_ajax_import
  • WPGMZA\import_ajax_schedule
  • WPGMZA\import_cron_import
  • WPGMZA\import_cron_schedules
  • WPGMZA\import_export_admin_options
  • WPGMZA\import_export_admin_tabs
  • WPGMZA\import_export_download
  • WPGMZA\import_export_get_maps_list
  • WPGMZA\import_get_progress
  • WPGMZA\import_get_schedule
  • WPGMZA\import_mimes
  • WPGMZA\import_wp_check_filetype_and_ext
  • WPGMZA\load_advanced_menu_page_hooks
  • WPGMZA\query_nominatim_cache
  • WPGMZA\Selector\trace
  • WPGMZA\show_custom_fields_page
  • WPGMZA\store_nominatim_cache
  • wpgmza_backwards_compat_get_all_circle_data
  • wpgmza_backwards_compat_get_all_rectangle_data
  • wpgmza_build_tree
  • wpgmza_check_admin_head_backwards_compat_v6
  • wpgmza_check_cat_map
  • wpgmza_check_map_editor_backwards_compat_v6
  • wpgmza_check_pro_compat_required_v6
  • wpgmza_check_user_backwards_compat_v6
  • wpgmza_consume_tree
  • wpgmza_consume_tree_dropdown
  • wpgmza_consume_tree_main_list
  • wpgmza_get_category_localized_data
  • wpgmza_pro_add_poly
  • wpgmza_pro_add_polyline
  • wpgmza_pro_category_edit_layout
  • wpgmza_pro_category_new_layout
  • wpgmza_pro_edit_poly
  • wpgmza_pro_edit_polyline
  • wpgmza_pro_return_category_blocks
  • wpgmza_pro_return_category_checkbox_list
  • wpgmza_pro_return_category_dropdown_list
  • wpgmza_pro_return_category_select_list
  • wpgmza_pro_return_maps_linked_to_cat
  • wpgmza_return_all_categories
  • wpgmza_return_category_data
  • wpgmza_return_marker_count_by_category
  • wpgmza_return_marker_count_category_via_elements
  • wpgmza_return_poly_options
  • wpgmza_return_polygon_array
  • wpgmza_return_polygon_id_array
  • wpgmza_return_polygon_list
  • wpgmza_return_polyline_array
  • wpgmza_return_polyline_id_array
  • wpgmza_return_polyline_list
  • wpgmza_return_polyline_options
  • wpgmza_tree_marker_counter
  • wpgmza_wizard_item_control_c
  • wpgmza_wizard_item_control_gd
  • wpgmza_wizard_item_control_ml
  • wpgmza_wizard_item_control_sl
  • Overview
  • Namespace
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 
<?php

namespace WPGMZA;

class MarkerListing extends AjaxTable
{
    const STYLE_NONE                    = 0;
    const STYLE_BASIC_TABLE             = 1;
    const STYLE_BASIC_LIST              = 4;
    const STYLE_ADVANCED_TABLE          = 2;
    const STYLE_CAROUSEL                = 3;
    const STYLE_MODERN                  = 6;
    
    const ORDER_BY_ID                   = 1;
    const ORDER_BY_TITLE                = 2;
    const ORDER_BY_ADDRESS              = 3;
    const ORDER_BY_DESCRIPTION          = 4;
    const ORDER_BY_CATEGORY             = 5;
    const ORDER_BY_CATEGORY_PRIORITY    = 6;
    const ORDER_BY_DISTANCE             = 7;
    
    const ORDER_ASC                     = 1;
    const ORDER_DESC                    = 2;
    
    private static $_cachedColumnNames;
    protected $map;
    
    // TODO: Pass the map object rather than ID
    public function __construct($map_id)
    {
        global $wpdb;
        global $wpgmza;
        
        AjaxTable::__construct("{$wpdb->prefix}wpgmza", '/marker-listing/');
        
        $this->map = Map::createInstance($map_id);
        
        // HTML attributes
        $this->element->setAttribute('data-wpgmza-marker-listing', null);
        
        // Legacy HTML
        if($wpgmza->settings->useLegacyHTML)
        {
            $this->element->addClass('wpgmza_marker_list_class');
            $this->element->setInlineStyle('width', '100%');
        }
        
        // Pagination
        $proDir = plugin_dir_url(dirname(__DIR__));
        wp_enqueue_style('wpgmza_pagination', $proDir . 'lib/pagination.css');
        wp_enqueue_script('wpgmza_pagination', $proDir . 'lib/pagination.min.js');
    }
    
    public function __get($name)
    {
        global $wpgmza;
        
        switch($name)
        {
            case 'hideIcon':
                return !empty($wpgmza->settings->wpgmza_settings_markerlist_icon);
                break;
            
            case 'hideLink':
                return !empty($wpgmza->settings->wpgmza_settings_markerlist_link);
                break;
            
            case 'hideTitle':
                return !empty($wpgmza->settings->wpgmza_settings_markerlist_title);
                break;
            
            case 'hideAddress':
                return !empty($wpgmza->settings->wpgmza_settings_markerlist_address);
                break;
            
            case 'hideCategories':
                // Only applicable for AdvancedTable
                break;
                
            case 'hideDescription':
                return !empty($wpgmza->settings->wpgmza_settings_markerlist_description);
                break;
        }
        
        return AjaxTable::__get($name);
    }
    
    protected function getItemHTMLPath()
    {
        global $wpgmza;
        
        $path = plugin_dir_path(dirname(__DIR__)) . 'html/marker-listings/';
        
        if($wpgmza->settings->useLegacyHTML)
            $path .= 'legacy/';
        
        return $path;
    }
    
    public function getColumns()
    {
        global $wpdb;
        
        if(empty(MarkerListing::$_cachedColumnNames))
        {
            $cols = $wpdb->get_col("SHOW COLUMNS FROM {$this->table_name}");
            MarkerListing::$_cachedColumnNames = array_combine($cols, $cols);
        }
        
        $result = (array)MarkerListing::$_cachedColumnNames;
        
        return $result;
    }
    
    protected function filterColumns(&$columns, $input_params)
    {
        AjaxTable::filterColumns($columns, $input_params);
        
        foreach($columns as $key => $value)
        {
            $name = $this->getColumnNameByIndex($key);
            
            switch($name)
            {                   
                case 'icon':
                
                    $columns[$key] = \WPGMZA\ProMarker::getIconSQL($this->map->id);
                    
                    break;
            }
        }
        
        if($this->map->order_markers_by == MarkerListing::ORDER_BY_DISTANCE && !empty($input_params['filteringParams']['center']))
        {
            $lat = floatval($input_params['filteringParams']['center']['lat']) / 180 * 3.1415926;
            $lng = floatval($input_params['filteringParams']['center']['lng']) / 180 * 3.1415926;
            
            $columns['distance'] = "
                (
                    6381 *
                
                    2 *
                
                    ATAN2(
                        SQRT(
                            POW( SIN( ( (X(latlng) / 180 * 3.1415926) - $lat ) / 2 ), 2 ) +
                            COS( X(latlng) / 180 * 3.1415926 ) * COS( $lat ) *
                            POW( SIN( ( (Y(latlng) / 180 * 3.1415926) - $lng ) / 2 ), 2 )
                        ),
                        
                        SQRT(1 - 
                            (
                                POW( SIN( ( (X(latlng) / 180 * 3.1415926) - $lat ) / 2 ), 2 ) +
                                COS( X(latlng) / 180 * 3.1415926 ) * COS( $lat ) *
                                POW( SIN( ( (Y(latlng) / 180 * 3.1415926) - $lng ) / 2 ), 2 )
                            )
                        )
                    )
                ) AS distance
            ";
        }
        
        return $columns;
    }
    
    public function filterOrderBy($orderBy, $keys)
    {
        global $WPGMZA_TABLE_NAME_MARKERS;
        global $WPGMZA_TABLE_NAME_MARKERS_HAS_CATEGORIES;
        global $WPGMZA_TABLE_NAME_CATEGORIES;
        
        $column = (empty($this->map->order_markers_by) ? MarkerListing::ORDER_BY_ID : $this->map->order_markers_by);
        
        switch($column)
        {
            case MarkerListing::ORDER_BY_TITLE:
                $orderBy = "title";
                break;
                
            case MarkerListing::ORDER_BY_ADDRESS:
                $orderBy = "address";
                break;
                
            case MarkerListing::ORDER_BY_DESCRIPTION:
                $orderBy = "description";
                break;
                
            case MarkerListing::ORDER_BY_CATEGORY:
                $orderBy = "category";
                break;
                
            case MarkerListing::ORDER_BY_CATEGORY_PRIORITY:
                return "(
                    SELECT MAX(priority) FROM $WPGMZA_TABLE_NAME_CATEGORIES
                    WHERE $WPGMZA_TABLE_NAME_CATEGORIES.id IN (
                        SELECT category_id FROM $WPGMZA_TABLE_NAME_MARKERS_HAS_CATEGORIES
                        WHERE marker_id = $WPGMZA_TABLE_NAME_MARKERS.id
                    )
                )";
                break;
                
            case MarkerListing::ORDER_BY_DISTANCE:
                if(!empty($_REQUEST['filteringParams']['center']))
                {
                    $orderBy = "distance";
                    break;
                }
                
            default:
                $orderBy = "$WPGMZA_TABLE_NAME_MARKERS.id";
                break;
        }
        
        return $orderBy;
    }
    
    public function filterOrderDirection($input_params)
    {
        $dir = (empty($this->map->order_markers_choice) ? MarkerListing::ORDER_DESC : $this->map->order_markers_choice);
        
        return ($dir == MarkerListing::ORDER_DESC ? 'DESC' : 'ASC');
    }
    
    public function setAjaxParameters($params)
    {
        global $wpgmza;
        
        AjaxTable::setAjaxParameters($params);
        
        $obj = (object)$params;
        
        if($wpgmza->settings->useLegacyHTML && property_exists($obj, 'map_id'))
            $this->element->setAttribute('id', 'wpgmza_marker_list_' . $obj->map_id);
    }
    
    public function getImageDimensions()
    {
        global $wpgmza;
        
        $dimensions = (object)array(
            'width'     => 100,
            'height'    => 'auto'
        );
        
        if(!empty($wpgmza->settings->wpgmza_settings_image_width))
            $dimensions->width = $wpgmza->settings->wpgmza_settings_image_width;
        
        if(!empty($wpgmza->settings->wpgmza_settings_image_height))
            $dimensions->height = $wpgmza->settings->wpgmza_settings_image_height;
        
        return $dimensions;
    }
    
    protected function removeHiddenFields($item, $marker)
    {
        global $wpgmza;
        
        // Hide the icon if setting is selected
        if($this->hideIcon && $el = $item->querySelector('.wpgmza_marker_icon'))
            $el->remove();
        
        // Hide the link if selected
        if($link = $item->querySelector('.wpgmza-link, .wpgmza_marker_link'))
        {
            if(empty($marker->link) || $this->hideLink)
                $link->remove();
        }
        
        // Hide title if selected
        if($this->hideTitle && $el = $item->querySelector('.wpgmza_marker_title, .wpgmza_div_title'))
            $el->remove();
        
        // Hide address if selected
        if($this->hideAddress && $el = $item->querySelector('.wpgmza_div_address, .wpgmza-address, .wpgmza_marker_address'))
            $el->remove();
        
        // Hide description if selected
        if($this->hideDescription && $el = $item->querySelector('.wpgmza-desc, .wpgmza_marker_description'))
            $el->remove();
    }
    
    protected function appendListingItem($document, $item, $marker)
    {
        global $wpgmza;
        
        $container = $document->querySelector('body');
        
        if($wpgmza->settings->useLegacyHTML)
        {
            $even = ($container->childNodes->length % 2 == 1);
            $item->addClass(($even ? 'wpgmaps_even' : 'wpgmaps_odd'));
            
            if($customFieldsContainer = $item->querySelector(".wpgmza_custom_fields"))
            {
                $customFields = new CustomMarkerFields($marker->id);
                $customFieldsContainer->import($customFields->html());
            }
        }
        
        $this->removeHiddenFields($item, $marker);
        
        $container->appendChild($item);
    }
    
    public static function createInstanceFromStyle($style, $map_id)
    {
        $class = apply_filters('wpgmza_get_marker_listing_class_from_style', $style);
        
        if(!$class)
            return null;
        
        return $class::createInstance($map_id);
    }
}

// TODO: Don't use a closure, allow this filter to be removed
add_filter('wpgmza_get_marker_listing_class_from_style', function($style) {
    
    switch($style)
    {
        case MarkerListing::STYLE_BASIC_TABLE:
            return '\WPGMZA\MarkerListing\BasicTable';
            break;
            
        case MarkerListing::STYLE_BASIC_LIST:
            return '\WPGMZA\MarkerListing\BasicList';
            break;
            
        case MarkerListing::STYLE_ADVANCED_TABLE:
            return '\WPGMZA\MarkerListing\AdvancedTable';
            break;
            
        case MarkerListing::STYLE_CAROUSEL:
            return '\WPGMZA\MarkerListing\Carousel';
            break;
            
        case MarkerListing::STYLE_MODERN:
            return '\WPGMZA\MarkerListing\Modern';
            break;
    }
    
    return null;
    
}, 1, 1);
API documentation generated by ApiGen