Completed
Branch sideload-all-language-files (829736)
by
unknown
08:41
created
core/helpers/EEH_Address.helper.php 2 patches
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -13,124 +13,124 @@
 block discarded – undo
13 13
 
14 14
 
15 15
 
16
-    /**
17
-     *    format - output formatted EE object address information
18
-     *
19
-     * @access public
20
-     * @param         object      EEI_Address $obj_with_address
21
-     * @param string  $type       how the address is formatted. for example: 'multiline' or 'inline'
22
-     * @param boolean $use_schema whether to apply schema.org formatting to the address
23
-     * @param bool    $add_wrapper
24
-     * @return string
25
-     */
26
-    public static function format(
27
-        $obj_with_address = null,
28
-        $type = 'multiline',
29
-        $use_schema = true,
30
-        $add_wrapper = true
31
-    ) {
32
-        // check that incoming object implements the EEI_Address interface
33
-        if (! $obj_with_address instanceof EEI_Address) {
34
-            $msg = __('The address could not be formatted.', 'event_espresso');
35
-            $dev_msg = __(
36
-                'The Address Formatter requires passed objects to implement the EEI_Address interface.',
37
-                'event_espresso'
38
-            );
39
-            EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
40
-            return null;
41
-        }
42
-        // obtain an address formatter
43
-        $formatter = EEH_Address::_get_formatter($type);
44
-        // apply schema.org formatting ?
45
-        $use_schema = ! is_admin() ? $use_schema : false;
46
-        $formatted_address = $use_schema
47
-            ? EEH_Address::_schema_formatting($formatter, $obj_with_address)
48
-            : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper);
49
-        $formatted_address = $add_wrapper && ! $use_schema
50
-            ? '<div class="espresso-address-dv">' . $formatted_address . '</div>'
51
-            : $formatted_address;
52
-        // return the formatted address
53
-        return $formatted_address;
54
-    }
16
+	/**
17
+	 *    format - output formatted EE object address information
18
+	 *
19
+	 * @access public
20
+	 * @param         object      EEI_Address $obj_with_address
21
+	 * @param string  $type       how the address is formatted. for example: 'multiline' or 'inline'
22
+	 * @param boolean $use_schema whether to apply schema.org formatting to the address
23
+	 * @param bool    $add_wrapper
24
+	 * @return string
25
+	 */
26
+	public static function format(
27
+		$obj_with_address = null,
28
+		$type = 'multiline',
29
+		$use_schema = true,
30
+		$add_wrapper = true
31
+	) {
32
+		// check that incoming object implements the EEI_Address interface
33
+		if (! $obj_with_address instanceof EEI_Address) {
34
+			$msg = __('The address could not be formatted.', 'event_espresso');
35
+			$dev_msg = __(
36
+				'The Address Formatter requires passed objects to implement the EEI_Address interface.',
37
+				'event_espresso'
38
+			);
39
+			EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
40
+			return null;
41
+		}
42
+		// obtain an address formatter
43
+		$formatter = EEH_Address::_get_formatter($type);
44
+		// apply schema.org formatting ?
45
+		$use_schema = ! is_admin() ? $use_schema : false;
46
+		$formatted_address = $use_schema
47
+			? EEH_Address::_schema_formatting($formatter, $obj_with_address)
48
+			: EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper);
49
+		$formatted_address = $add_wrapper && ! $use_schema
50
+			? '<div class="espresso-address-dv">' . $formatted_address . '</div>'
51
+			: $formatted_address;
52
+		// return the formatted address
53
+		return $formatted_address;
54
+	}
55 55
 
56 56
 
57 57
 
58
-    /**
59
-     *    _get_formatter - obtain the requester formatter class
60
-     *
61
-     * @access private
62
-     * @param string $type how the address is formatted. for example: 'multiline' or 'inline'
63
-     * @return EEI_Address_Formatter
64
-     */
65
-    private static function _get_formatter($type)
66
-    {
67
-        switch ($type) {
68
-            case 'multiline':
69
-                return new EventEspresso\core\services\address\formatters\MultiLineAddressFormatter();
70
-            case 'inline':
71
-                return new EventEspresso\core\services\address\formatters\InlineAddressFormatter();
72
-            default:
73
-                return new EventEspresso\core\services\address\formatters\NullAddressFormatter();
74
-        }
75
-    }
58
+	/**
59
+	 *    _get_formatter - obtain the requester formatter class
60
+	 *
61
+	 * @access private
62
+	 * @param string $type how the address is formatted. for example: 'multiline' or 'inline'
63
+	 * @return EEI_Address_Formatter
64
+	 */
65
+	private static function _get_formatter($type)
66
+	{
67
+		switch ($type) {
68
+			case 'multiline':
69
+				return new EventEspresso\core\services\address\formatters\MultiLineAddressFormatter();
70
+			case 'inline':
71
+				return new EventEspresso\core\services\address\formatters\InlineAddressFormatter();
72
+			default:
73
+				return new EventEspresso\core\services\address\formatters\NullAddressFormatter();
74
+		}
75
+	}
76 76
 
77 77
 
78 78
 
79
-    /**
80
-     *    _regular_formatting
81
-     *    adds formatting to an address
82
-     *
83
-     * @access private
84
-     * @param      object EEI_Address_Formatter $formatter
85
-     * @param      object EEI_Address $obj_with_address
86
-     * @param bool $add_wrapper
87
-     * @return string
88
-     */
89
-    private static function _regular_formatting(
90
-        EEI_Address_Formatter $formatter,
91
-        EEI_Address $obj_with_address,
92
-        $add_wrapper = true
93
-    ) {
94
-        $formatted_address = $add_wrapper ? '<div>' : '';
95
-        $formatted_address .= $formatter->format(
96
-            $obj_with_address->address(),
97
-            $obj_with_address->address2(),
98
-            $obj_with_address->city(),
99
-            $obj_with_address->state_name(),
100
-            $obj_with_address->zip(),
101
-            $obj_with_address->country_name(),
102
-            $obj_with_address->country_ID()
103
-        );
104
-        $formatted_address .= $add_wrapper ? '</div>' : '';
105
-        // return the formatted address
106
-        return $formatted_address;
107
-    }
79
+	/**
80
+	 *    _regular_formatting
81
+	 *    adds formatting to an address
82
+	 *
83
+	 * @access private
84
+	 * @param      object EEI_Address_Formatter $formatter
85
+	 * @param      object EEI_Address $obj_with_address
86
+	 * @param bool $add_wrapper
87
+	 * @return string
88
+	 */
89
+	private static function _regular_formatting(
90
+		EEI_Address_Formatter $formatter,
91
+		EEI_Address $obj_with_address,
92
+		$add_wrapper = true
93
+	) {
94
+		$formatted_address = $add_wrapper ? '<div>' : '';
95
+		$formatted_address .= $formatter->format(
96
+			$obj_with_address->address(),
97
+			$obj_with_address->address2(),
98
+			$obj_with_address->city(),
99
+			$obj_with_address->state_name(),
100
+			$obj_with_address->zip(),
101
+			$obj_with_address->country_name(),
102
+			$obj_with_address->country_ID()
103
+		);
104
+		$formatted_address .= $add_wrapper ? '</div>' : '';
105
+		// return the formatted address
106
+		return $formatted_address;
107
+	}
108 108
 
109 109
 
110 110
 
111
-    /**
112
-     *    _schema_formatting
113
-     *    adds schema.org formatting to an address
114
-     *
115
-     * @access private
116
-     * @param object EEI_Address_Formatter $formatter
117
-     * @param object EEI_Address $obj_with_address
118
-     * @return string
119
-     */
120
-    private static function _schema_formatting(EEI_Address_Formatter $formatter, EEI_Address $obj_with_address)
121
-    {
122
-        $formatted_address = '<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">';
123
-        $formatted_address .= $formatter->format(
124
-            EEH_Schema::streetAddress($obj_with_address),
125
-            EEH_Schema::postOfficeBoxNumber($obj_with_address),
126
-            EEH_Schema::addressLocality($obj_with_address),
127
-            EEH_Schema::addressRegion($obj_with_address),
128
-            EEH_Schema::postalCode($obj_with_address),
129
-            EEH_Schema::addressCountry($obj_with_address),
130
-            $obj_with_address->country_ID()
131
-        );
132
-        $formatted_address .= '</div>';
133
-        // return the formatted address
134
-        return $formatted_address;
135
-    }
111
+	/**
112
+	 *    _schema_formatting
113
+	 *    adds schema.org formatting to an address
114
+	 *
115
+	 * @access private
116
+	 * @param object EEI_Address_Formatter $formatter
117
+	 * @param object EEI_Address $obj_with_address
118
+	 * @return string
119
+	 */
120
+	private static function _schema_formatting(EEI_Address_Formatter $formatter, EEI_Address $obj_with_address)
121
+	{
122
+		$formatted_address = '<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">';
123
+		$formatted_address .= $formatter->format(
124
+			EEH_Schema::streetAddress($obj_with_address),
125
+			EEH_Schema::postOfficeBoxNumber($obj_with_address),
126
+			EEH_Schema::addressLocality($obj_with_address),
127
+			EEH_Schema::addressRegion($obj_with_address),
128
+			EEH_Schema::postalCode($obj_with_address),
129
+			EEH_Schema::addressCountry($obj_with_address),
130
+			$obj_with_address->country_ID()
131
+		);
132
+		$formatted_address .= '</div>';
133
+		// return the formatted address
134
+		return $formatted_address;
135
+	}
136 136
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,13 +30,13 @@  discard block
 block discarded – undo
30 30
         $add_wrapper = true
31 31
     ) {
32 32
         // check that incoming object implements the EEI_Address interface
33
-        if (! $obj_with_address instanceof EEI_Address) {
33
+        if ( ! $obj_with_address instanceof EEI_Address) {
34 34
             $msg = __('The address could not be formatted.', 'event_espresso');
35 35
             $dev_msg = __(
36 36
                 'The Address Formatter requires passed objects to implement the EEI_Address interface.',
37 37
                 'event_espresso'
38 38
             );
39
-            EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
39
+            EE_Error::add_error($msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
40 40
             return null;
41 41
         }
42 42
         // obtain an address formatter
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
             ? EEH_Address::_schema_formatting($formatter, $obj_with_address)
48 48
             : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper);
49 49
         $formatted_address = $add_wrapper && ! $use_schema
50
-            ? '<div class="espresso-address-dv">' . $formatted_address . '</div>'
50
+            ? '<div class="espresso-address-dv">'.$formatted_address.'</div>'
51 51
             : $formatted_address;
52 52
         // return the formatted address
53 53
         return $formatted_address;
Please login to merge, or discard this patch.
core/helpers/EEH_Maps.helper.php 2 patches
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -12,173 +12,173 @@
 block discarded – undo
12 12
 class EEH_Maps
13 13
 {
14 14
 
15
-    // array of map settings
16
-    public static $gmap_vars = array();
17
-
18
-
19
-    /**
20
-     * google_map - creates a Google Map Link
21
-     *
22
-     * @param  array $ee_gmaps_opts array of attributes required for the map link generation
23
-     * @return string (link to map!)
24
-     */
25
-    public static function google_map($ee_gmaps_opts)
26
-    {
27
-
28
-        $ee_map_width        = ! empty($ee_gmaps_opts['ee_map_width']) ? $ee_gmaps_opts['ee_map_width'] : '300';
29
-        $ee_map_height       = ! empty($ee_gmaps_opts['ee_map_height']) ? $ee_gmaps_opts['ee_map_height'] : '185';
30
-        $ee_map_zoom         = ! empty($ee_gmaps_opts['ee_map_zoom']) ? $ee_gmaps_opts['ee_map_zoom'] : '12';
31
-        $ee_map_nav_display  = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false';
32
-        $ee_map_nav_size     = ! empty($ee_gmaps_opts['ee_map_nav_size'])
33
-            ? $ee_gmaps_opts['ee_map_nav_size']
34
-            : 'default';
35
-        $ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control'])
36
-            ? $ee_gmaps_opts['ee_map_type_control']
37
-            : 'default';
38
-        $static_url          = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false;
39
-
40
-        if (! empty($ee_gmaps_opts['ee_map_align'])) {
41
-            switch ($ee_gmaps_opts['ee_map_align']) {
42
-                case "left":
43
-                    $map_align = 'ee-gmap-align-left left';
44
-                    break;
45
-                case "right":
46
-                    $map_align = 'ee-gmap-align-right right';
47
-                    break;
48
-                case "center":
49
-                    $map_align = 'ee-gmap-align-center center';
50
-                    break;
51
-                case "none":
52
-                default:
53
-                    $map_align = 'ee-gmap-align-none';
54
-            }
55
-        } else {
56
-            $map_align = 'ee-gmap-align-none';
57
-        }
58
-
59
-
60
-        // Determine whether user has set a hardoded url to use and
61
-        // if so display a Google static iframe map else run V3 api
62
-        if ($static_url) {
63
-            $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">';
64
-            $html .= '<iframe src="' . $static_url . '&output=embed"'
65
-                . ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"'
66
-                . ' frameborder="0" scrolling="no">';
67
-            $html .= '</iframe>';
68
-            $html .= '<a href="' . $static_url . '">View Large map</a>';
69
-            $html .= '</div>';
70
-            return $html;
71
-        } else {
72
-            EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = array(
73
-                'map_ID'              => $ee_gmaps_opts['map_ID'],
74
-                'ee_map_zoom'         => $ee_map_zoom,
75
-                'ee_map_nav_display'  => $ee_map_nav_display,
76
-                'ee_map_nav_size'     => $ee_map_nav_size,
77
-                'ee_map_type_control' => $ee_map_type_control,
78
-                'location'            => $ee_gmaps_opts['location'],
79
-            );
80
-
81
-            $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;';
82
-            $html = '<div class="ee-gmap-wrapper ' . $map_align . '">'
83
-                    . '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"'
84
-                    . ' style="' . $style . '"></div>'
85
-                    . '</div>';
86
-
87
-            wp_enqueue_script('gmap_api');
88
-            wp_enqueue_script('ee_gmap');
89
-            add_action('wp_footer', array('EEH_Maps', 'footer_enqueue_script'));
90
-
91
-            return $html;
92
-        } // end auto map or static url map check
93
-    }
94
-
95
-
96
-    /**
97
-     * enqueue_script
98
-     *
99
-     * @return void
100
-     */
101
-    public static function footer_enqueue_script()
102
-    {
103
-        wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars);
104
-    }
105
-
106
-
107
-    /**
108
-     * registers scripts for maps
109
-     */
110
-    public static function espresso_google_map_js()
111
-    {
112
-        $api_url = sprintf(
113
-            "https://maps.googleapis.com/maps/api/js?key=%s",
114
-            apply_filters(
115
-                'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
116
-                EE_Registry::instance()->CFG->map_settings->google_map_api_key
117
-            )
118
-        );
119
-        wp_register_script('gmap_api', $api_url, array('jquery'), null, true);
120
-        wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true);
121
-    }
122
-
123
-    /**
124
-     * creates a Google Map Link
125
-     *
126
-     * @param  array $atts array of attributes required for the map link generation
127
-     * @return string (link to map!)
128
-     */
129
-    public static function google_map_link($atts)
130
-    {
131
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
132
-        extract($atts);
133
-        /** @var string $address */
134
-        /** @var string $city */
135
-        /** @var string $state */
136
-        /** @var string $zip */
137
-        /** @var string $country */
138
-        $address         = "{$address}";
139
-        $city            = "{$city}";
140
-        $state           = "{$state}";
141
-        $zip             = "{$zip}";
142
-        $country         = "{$country}";
143
-        $text            = isset($text) ? "{$text}" : "";
144
-        $type            = isset($type) ? "{$type}" : "";
145
-        $map_w           = isset($map_w) ? "{$map_w}" : 400;
146
-        $map_h           = isset($map_h) ? "{$map_h}" : 400;
147
-        $id              = isset($id) ? $id : 'not_set';
148
-        $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view';
149
-
150
-        $address_string = ($address != '' ? $address : '')
151
-                          . ($city != '' ? ',' . $city : '')
152
-                          . ($state != '' ? ',' . $state : '')
153
-                          . ($zip != '' ? ',' . $zip : '')
154
-                          . ($country != '' ? ',' . $country : '');
155
-
156
-        $google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string));
157
-
158
-        switch ($type) {
159
-            case 'text':
160
-            default:
161
-                $text = $text == '' ? __('Map and Directions', 'event_espresso') : $text;
162
-                break;
163
-
164
-            case 'url_only':
165
-            case 'url':
166
-                $text = $google_map;
167
-                break;
168
-
169
-            case 'map':
170
-                $scheme = is_ssl() ? 'https://' : 'http://';
171
-
172
-                $api_key = apply_filters(
173
-                    'FHEE__EEH_Maps__espresso_google_maps_link__api_key',
174
-                    EE_Registry::instance()->CFG->map_settings->google_map_api_key
175
-                );
176
-
177
-                return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&amp;zoom=14&amp;size=' . $map_w . 'x' . $map_h . '&amp;markers=color:green|label:|' . urlencode($address_string) . '&amp;sensor=false&amp;key=' . $api_key) . '" /></a>';
178
-        }
179
-
180
-        return $type === 'url_only'
181
-            ? $text
182
-            : '<a href="' . $google_map . '" target="_blank">' . $text . '</a>';
183
-    }
15
+	// array of map settings
16
+	public static $gmap_vars = array();
17
+
18
+
19
+	/**
20
+	 * google_map - creates a Google Map Link
21
+	 *
22
+	 * @param  array $ee_gmaps_opts array of attributes required for the map link generation
23
+	 * @return string (link to map!)
24
+	 */
25
+	public static function google_map($ee_gmaps_opts)
26
+	{
27
+
28
+		$ee_map_width        = ! empty($ee_gmaps_opts['ee_map_width']) ? $ee_gmaps_opts['ee_map_width'] : '300';
29
+		$ee_map_height       = ! empty($ee_gmaps_opts['ee_map_height']) ? $ee_gmaps_opts['ee_map_height'] : '185';
30
+		$ee_map_zoom         = ! empty($ee_gmaps_opts['ee_map_zoom']) ? $ee_gmaps_opts['ee_map_zoom'] : '12';
31
+		$ee_map_nav_display  = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false';
32
+		$ee_map_nav_size     = ! empty($ee_gmaps_opts['ee_map_nav_size'])
33
+			? $ee_gmaps_opts['ee_map_nav_size']
34
+			: 'default';
35
+		$ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control'])
36
+			? $ee_gmaps_opts['ee_map_type_control']
37
+			: 'default';
38
+		$static_url          = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false;
39
+
40
+		if (! empty($ee_gmaps_opts['ee_map_align'])) {
41
+			switch ($ee_gmaps_opts['ee_map_align']) {
42
+				case "left":
43
+					$map_align = 'ee-gmap-align-left left';
44
+					break;
45
+				case "right":
46
+					$map_align = 'ee-gmap-align-right right';
47
+					break;
48
+				case "center":
49
+					$map_align = 'ee-gmap-align-center center';
50
+					break;
51
+				case "none":
52
+				default:
53
+					$map_align = 'ee-gmap-align-none';
54
+			}
55
+		} else {
56
+			$map_align = 'ee-gmap-align-none';
57
+		}
58
+
59
+
60
+		// Determine whether user has set a hardoded url to use and
61
+		// if so display a Google static iframe map else run V3 api
62
+		if ($static_url) {
63
+			$html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">';
64
+			$html .= '<iframe src="' . $static_url . '&output=embed"'
65
+				. ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"'
66
+				. ' frameborder="0" scrolling="no">';
67
+			$html .= '</iframe>';
68
+			$html .= '<a href="' . $static_url . '">View Large map</a>';
69
+			$html .= '</div>';
70
+			return $html;
71
+		} else {
72
+			EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = array(
73
+				'map_ID'              => $ee_gmaps_opts['map_ID'],
74
+				'ee_map_zoom'         => $ee_map_zoom,
75
+				'ee_map_nav_display'  => $ee_map_nav_display,
76
+				'ee_map_nav_size'     => $ee_map_nav_size,
77
+				'ee_map_type_control' => $ee_map_type_control,
78
+				'location'            => $ee_gmaps_opts['location'],
79
+			);
80
+
81
+			$style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;';
82
+			$html = '<div class="ee-gmap-wrapper ' . $map_align . '">'
83
+					. '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"'
84
+					. ' style="' . $style . '"></div>'
85
+					. '</div>';
86
+
87
+			wp_enqueue_script('gmap_api');
88
+			wp_enqueue_script('ee_gmap');
89
+			add_action('wp_footer', array('EEH_Maps', 'footer_enqueue_script'));
90
+
91
+			return $html;
92
+		} // end auto map or static url map check
93
+	}
94
+
95
+
96
+	/**
97
+	 * enqueue_script
98
+	 *
99
+	 * @return void
100
+	 */
101
+	public static function footer_enqueue_script()
102
+	{
103
+		wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars);
104
+	}
105
+
106
+
107
+	/**
108
+	 * registers scripts for maps
109
+	 */
110
+	public static function espresso_google_map_js()
111
+	{
112
+		$api_url = sprintf(
113
+			"https://maps.googleapis.com/maps/api/js?key=%s",
114
+			apply_filters(
115
+				'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
116
+				EE_Registry::instance()->CFG->map_settings->google_map_api_key
117
+			)
118
+		);
119
+		wp_register_script('gmap_api', $api_url, array('jquery'), null, true);
120
+		wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true);
121
+	}
122
+
123
+	/**
124
+	 * creates a Google Map Link
125
+	 *
126
+	 * @param  array $atts array of attributes required for the map link generation
127
+	 * @return string (link to map!)
128
+	 */
129
+	public static function google_map_link($atts)
130
+	{
131
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
132
+		extract($atts);
133
+		/** @var string $address */
134
+		/** @var string $city */
135
+		/** @var string $state */
136
+		/** @var string $zip */
137
+		/** @var string $country */
138
+		$address         = "{$address}";
139
+		$city            = "{$city}";
140
+		$state           = "{$state}";
141
+		$zip             = "{$zip}";
142
+		$country         = "{$country}";
143
+		$text            = isset($text) ? "{$text}" : "";
144
+		$type            = isset($type) ? "{$type}" : "";
145
+		$map_w           = isset($map_w) ? "{$map_w}" : 400;
146
+		$map_h           = isset($map_h) ? "{$map_h}" : 400;
147
+		$id              = isset($id) ? $id : 'not_set';
148
+		$map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view';
149
+
150
+		$address_string = ($address != '' ? $address : '')
151
+						  . ($city != '' ? ',' . $city : '')
152
+						  . ($state != '' ? ',' . $state : '')
153
+						  . ($zip != '' ? ',' . $zip : '')
154
+						  . ($country != '' ? ',' . $country : '');
155
+
156
+		$google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string));
157
+
158
+		switch ($type) {
159
+			case 'text':
160
+			default:
161
+				$text = $text == '' ? __('Map and Directions', 'event_espresso') : $text;
162
+				break;
163
+
164
+			case 'url_only':
165
+			case 'url':
166
+				$text = $google_map;
167
+				break;
168
+
169
+			case 'map':
170
+				$scheme = is_ssl() ? 'https://' : 'http://';
171
+
172
+				$api_key = apply_filters(
173
+					'FHEE__EEH_Maps__espresso_google_maps_link__api_key',
174
+					EE_Registry::instance()->CFG->map_settings->google_map_api_key
175
+				);
176
+
177
+				return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&amp;zoom=14&amp;size=' . $map_w . 'x' . $map_h . '&amp;markers=color:green|label:|' . urlencode($address_string) . '&amp;sensor=false&amp;key=' . $api_key) . '" /></a>';
178
+		}
179
+
180
+		return $type === 'url_only'
181
+			? $text
182
+			: '<a href="' . $google_map . '" target="_blank">' . $text . '</a>';
183
+	}
184 184
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
             : 'default';
38 38
         $static_url          = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false;
39 39
 
40
-        if (! empty($ee_gmaps_opts['ee_map_align'])) {
40
+        if ( ! empty($ee_gmaps_opts['ee_map_align'])) {
41 41
             switch ($ee_gmaps_opts['ee_map_align']) {
42 42
                 case "left":
43 43
                     $map_align = 'ee-gmap-align-left left';
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
         // Determine whether user has set a hardoded url to use and
61 61
         // if so display a Google static iframe map else run V3 api
62 62
         if ($static_url) {
63
-            $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">';
64
-            $html .= '<iframe src="' . $static_url . '&output=embed"'
65
-                . ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"'
63
+            $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper '.$map_align.'">';
64
+            $html .= '<iframe src="'.$static_url.'&output=embed"'
65
+                . ' style="width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;"'
66 66
                 . ' frameborder="0" scrolling="no">';
67 67
             $html .= '</iframe>';
68
-            $html .= '<a href="' . $static_url . '">View Large map</a>';
68
+            $html .= '<a href="'.$static_url.'">View Large map</a>';
69 69
             $html .= '</div>';
70 70
             return $html;
71 71
         } else {
72
-            EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = array(
72
+            EEH_Maps::$gmap_vars[$ee_gmaps_opts['map_ID']] = array(
73 73
                 'map_ID'              => $ee_gmaps_opts['map_ID'],
74 74
                 'ee_map_zoom'         => $ee_map_zoom,
75 75
                 'ee_map_nav_display'  => $ee_map_nav_display,
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
                 'location'            => $ee_gmaps_opts['location'],
79 79
             );
80 80
 
81
-            $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;';
82
-            $html = '<div class="ee-gmap-wrapper ' . $map_align . '">'
83
-                    . '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"'
84
-                    . ' style="' . $style . '"></div>'
81
+            $style = 'width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;';
82
+            $html = '<div class="ee-gmap-wrapper '.$map_align.'">'
83
+                    . '<div class="ee-gmap" id="map_canvas_'.$ee_gmaps_opts['map_ID'].'"'
84
+                    . ' style="'.$style.'"></div>'
85 85
                     . '</div>';
86 86
 
87 87
             wp_enqueue_script('gmap_api');
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
             )
118 118
         );
119 119
         wp_register_script('gmap_api', $api_url, array('jquery'), null, true);
120
-        wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true);
120
+        wp_register_script('ee_gmap', plugin_dir_url(__FILE__).'assets/ee_gmap.js', array('gmap_api'), '1.0', true);
121 121
     }
122 122
 
123 123
     /**
@@ -148,12 +148,12 @@  discard block
 block discarded – undo
148 148
         $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view';
149 149
 
150 150
         $address_string = ($address != '' ? $address : '')
151
-                          . ($city != '' ? ',' . $city : '')
152
-                          . ($state != '' ? ',' . $state : '')
153
-                          . ($zip != '' ? ',' . $zip : '')
154
-                          . ($country != '' ? ',' . $country : '');
151
+                          . ($city != '' ? ','.$city : '')
152
+                          . ($state != '' ? ','.$state : '')
153
+                          . ($zip != '' ? ','.$zip : '')
154
+                          . ($country != '' ? ','.$country : '');
155 155
 
156
-        $google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string));
156
+        $google_map = htmlentities2('http://maps.google.com/maps?q='.urlencode($address_string));
157 157
 
158 158
         switch ($type) {
159 159
             case 'text':
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
                     EE_Registry::instance()->CFG->map_settings->google_map_api_key
175 175
                 );
176 176
 
177
-                return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&amp;zoom=14&amp;size=' . $map_w . 'x' . $map_h . '&amp;markers=color:green|label:|' . urlencode($address_string) . '&amp;sensor=false&amp;key=' . $api_key) . '" /></a>';
177
+                return '<a class="a_map_image_link" href="'.$google_map.'" target="_blank">'.'<img class="map_image_link" id="venue_map_'.$id.'" '.$map_image_class.' src="'.htmlentities2($scheme.'maps.googleapis.com/maps/api/staticmap?center='.urlencode($address_string).'&amp;zoom=14&amp;size='.$map_w.'x'.$map_h.'&amp;markers=color:green|label:|'.urlencode($address_string).'&amp;sensor=false&amp;key='.$api_key).'" /></a>';
178 178
         }
179 179
 
180 180
         return $type === 'url_only'
181 181
             ? $text
182
-            : '<a href="' . $google_map . '" target="_blank">' . $text . '</a>';
182
+            : '<a href="'.$google_map.'" target="_blank">'.$text.'</a>';
183 183
     }
184 184
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Venue_View.helper.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
                     // the post already contains the related EE_Venue object AND one of the following is TRUE:
59 59
                     // the requested Venue ID matches the post ID OR...
60 60
                     // there was no specific Venue ID requested
61
-                    if (isset($post->EE_Venue) && ( $VNU_ID == $post->ID || ! $VNU_ID )) {
61
+                    if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) {
62 62
                         // use existing related EE_Venue object
63
-                        EEH_Venue_View::$_venue =  $post->EE_Venue;
63
+                        EEH_Venue_View::$_venue = $post->EE_Venue;
64 64
                     } elseif ($VNU_ID) {
65 65
                         // there WAS a specific Venue ID requested, but it's NOT the current post object
66 66
                         EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
             }
100 100
         }
101 101
         // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID...
102
-        if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
102
+        if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
103 103
             // sigh... pull it from the db
104 104
             EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
105 105
         }
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
     public static function is_venue_private($VNU_ID = false)
172 172
     {
173 173
         $venue = EEH_Venue_View::get_venue($VNU_ID, true, true);
174
-        if (! $venue instanceof EE_Venue) {
174
+        if ( ! $venue instanceof EE_Venue) {
175 175
             return null;
176 176
         }
177 177
 
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
         $venue = EEH_Venue_View::get_venue($VNU_ID);
251 251
         if ($venue instanceof EE_Venue) {
252 252
             $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description();
253
-            $venue_link = ' ' . EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso') . '&hellip;');
254
-            return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : '';
253
+            $venue_link = ' '.EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso').'&hellip;');
254
+            return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '').$venue_link : '';
255 255
         }
256 256
         return '';
257 257
     }
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
                 // loop thru terms and create links
277 277
                 foreach ($venue_categories as $term) {
278 278
                     $url = get_term_link($term, 'espresso_venue_categories');
279
-                    if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) {
280
-                        $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> ';
279
+                    if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) {
280
+                        $category_links[] = '<a href="'.esc_url($url).'" rel="tag">'.$term->name.'</a> ';
281 281
                     }
282 282
                 }
283 283
             }
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
             $venue_name = apply_filters(
342 342
                 'FHEE__EEH_Venue__venue_name__append_private_venue_name',
343 343
                 EEH_Venue_View::is_venue_private()
344
-                    ? EEH_Venue_View::$_venue->name() . "&nbsp;" . __('(Private)', 'event_espresso')
344
+                    ? EEH_Venue_View::$_venue->name()."&nbsp;".__('(Private)', 'event_espresso')
345 345
                     : EEH_Venue_View::$_venue->name(),
346 346
                 EEH_Venue_View::$_venue
347 347
             );
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
             if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) {
451 451
                 $details_page = is_single();
452 452
                 $options = array();
453
-                $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/;
453
+                $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID.'-'.$venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/;
454 454
 
455 455
                 $options['location'] = EEH_Address::format($venue, 'inline', false, false);
456 456
 
@@ -468,15 +468,15 @@  discard block
 block discarded – undo
468 468
                 ;
469 469
 
470 470
                 $options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size;
471
-                $options['ee_map_nav_size'] =  isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size'])? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size'];
471
+                $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) ? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size'];
472 472
 
473 473
                 $options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type;
474
-                $options['ee_map_type_control'] =  isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control'])? $gmap['ee_map_type_control'] : $options['ee_map_type_control'];
474
+                $options['ee_map_type_control'] = isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) ? $gmap['ee_map_type_control'] : $options['ee_map_type_control'];
475 475
 
476 476
                 $options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align;
477
-                $options['ee_map_align'] =  isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align'])? $gmap['ee_map_align'] : $options['ee_map_align'];
477
+                $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) ? $gmap['ee_map_align'] : $options['ee_map_align'];
478 478
 
479
-                $options['ee_static_url'] =  isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link();
479
+                $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link();
480 480
 
481 481
                 return EEH_Maps::google_map($options);
482 482
             }
@@ -535,13 +535,13 @@  discard block
 block discarded – undo
535 535
                 // generate nonce
536 536
                 $nonce = wp_create_nonce('edit_nonce');
537 537
                 // generate url to venue editor for this venue
538
-                $url = add_query_arg(array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url('admin.php'));
538
+                $url = add_query_arg(array('page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce), admin_url('admin.php'));
539 539
                 // get edit CPT text
540 540
                 $post_type_obj = get_post_type_object('espresso_venues');
541 541
                 // build final link html
542
-                $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr($post_type_obj->labels->edit_item) . '">' . $link . '</a>';
542
+                $link = '<a class="post-edit-link" href="'.$url.'" title="'.esc_attr($post_type_obj->labels->edit_item).'">'.$link.'</a>';
543 543
                 // put it all together
544
-                return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after;
544
+                return $before.apply_filters('edit_post_link', $link, $venue->ID()).$after;
545 545
             }
546 546
         }
547 547
         return '';
Please login to merge, or discard this patch.
Indentation   +534 added lines, -535 removed lines patch added patch discarded remove patch
@@ -11,539 +11,538 @@
 block discarded – undo
11 11
 class EEH_Venue_View extends EEH_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @access    private
16
-     * @var EE_Venue
17
-     */
18
-    private static $_venue = null;
19
-
20
-
21
-
22
-    /**
23
-     *    get_venue
24
-     *    attempts to retrieve an EE_Venue object any way it can
25
-     *
26
-     * @access    public
27
-     * @param int  $VNU_ID
28
-     * @param bool $look_in_event
29
-     * @param bool $privacy_check   Defaults to true.
30
-     *                              When false, means even if the venue is private we return it regardless of access.
31
-     * @param bool $password_check
32
-     * @return \EE_Venue|null
33
-     */
34
-    public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true)
35
-    {
36
-        $VNU_ID = absint($VNU_ID);
37
-        // do we already have the Venue you are looking for?
38
-        if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
39
-            // If the Venue ID matches $VNU_ID, return the venue.
40
-            if (EEH_Venue_View::$_venue->ID() === $VNU_ID) {
41
-                return EEH_Venue_View::_get_venue($privacy_check);
42
-            }
43
-            // If the Venue ID does not match, try pulling a venue using $VNU_ID.
44
-            $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
45
-            if ($venue instanceof EE_Venue) {
46
-                EEH_Venue_View::$_venue = $venue;
47
-                return EEH_Venue_View::_get_venue($privacy_check);
48
-            }
49
-        }
50
-        // international newspaper?
51
-        global $post;
52
-        if ($post instanceof WP_Post) {
53
-            switch ($post->post_type) {
54
-                // if this is being called from an EE_Venue post,
55
-                // and the EE_Venue post corresponds to the EE_Venue that is being asked for,
56
-                // then we can try to just grab the attached EE_Venue object
57
-                case 'espresso_venues':
58
-                    // the post already contains the related EE_Venue object AND one of the following is TRUE:
59
-                    // the requested Venue ID matches the post ID OR...
60
-                    // there was no specific Venue ID requested
61
-                    if (isset($post->EE_Venue) && ( $VNU_ID == $post->ID || ! $VNU_ID )) {
62
-                        // use existing related EE_Venue object
63
-                        EEH_Venue_View::$_venue =  $post->EE_Venue;
64
-                    } elseif ($VNU_ID) {
65
-                        // there WAS a specific Venue ID requested, but it's NOT the current post object
66
-                        EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
67
-                    } else {
68
-                        // no specific Venue ID requested, so use post ID to generate EE_Venue object
69
-                        EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID);
70
-                    }
71
-                    break;
72
-
73
-                case 'espresso_events':
74
-                    if ($look_in_event) {
75
-                        // grab the events related venues
76
-                        $venues = EEH_Venue_View::get_event_venues();
77
-                        // make sure the result is an array
78
-                        $venues = is_array($venues) ? $venues : array();
79
-                        // do we have an ID for a specific venue?
80
-                        if ($VNU_ID) {
81
-                            // loop thru the related venues
82
-                            foreach ($venues as $venue) {
83
-                                if ($venue instanceof EE_Venue) {
84
-                                    // until we find the venue we're looking for
85
-                                    if ($venue->ID() == $VNU_ID) {
86
-                                        EEH_Venue_View::$_venue = $venue;
87
-                                        break;
88
-                                    }
89
-                                }
90
-                            }
91
-                        // no venue ID ?
92
-                        // then the global post is an events post and this function was called with no argument
93
-                        } else {
94
-                            // just grab the first related event venue
95
-                            EEH_Venue_View::$_venue = reset($venues);
96
-                        }
97
-                    }
98
-                    break;
99
-            }
100
-        }
101
-        // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID...
102
-        if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
103
-            // sigh... pull it from the db
104
-            EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
105
-        }
106
-        return EEH_Venue_View::_get_venue($privacy_check, $password_check);
107
-    }
108
-
109
-
110
-
111
-    /**
112
-     * return a single venue
113
-     *
114
-     * @param bool $privacy_check   Defaults to true.
115
-     *                              When false, means even if the venue is private we return it regardless of access.
116
-     * @param bool $password_check
117
-     * @return  EE_Venue
118
-     */
119
-    protected static function _get_venue($privacy_check = true, $password_check = true)
120
-    {
121
-        // check for private venues.
122
-        if (EEH_Venue_View::$_venue instanceof EE_Venue
123
-            && EEH_Venue_View::$_venue->status() == 'private'
124
-            && $privacy_check
125
-            && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')
126
-        ) {
127
-            return null;
128
-        }
129
-        // check for password protected venues
130
-        if (EEH_Venue_View::$_venue instanceof EE_Venue
131
-            && $password_check
132
-            && post_password_required(EEH_Venue_View::$_venue->ID())
133
-        ) {
134
-            return null;
135
-        }
136
-        return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null;
137
-    }
138
-
139
-
140
-
141
-    /**
142
-     *  get_event_venues
143
-     *
144
-     *  @access     public
145
-     *  @return     EE_Venue[]
146
-     */
147
-    public static function get_event_venues()
148
-    {
149
-        global $post;
150
-        if ($post->post_type == 'espresso_events') {
151
-            if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) {
152
-                return $post->EE_Event->venues();
153
-            }
154
-        }
155
-        return array();
156
-    }
157
-
158
-
159
-
160
-
161
-    /**
162
-     * Simply checks whether a venue for the given ID (or the internally derived venue is private).
163
-     *
164
-     * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but is not
165
-     *    private.  So it is important to do explicit boolean checks when using this conditional.
166
-     *
167
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
168
-     *
169
-     * @return bool|null
170
-     */
171
-    public static function is_venue_private($VNU_ID = false)
172
-    {
173
-        $venue = EEH_Venue_View::get_venue($VNU_ID, true, true);
174
-        if (! $venue instanceof EE_Venue) {
175
-            return null;
176
-        }
177
-
178
-        return $venue->status() == 'private' ? true : false;
179
-    }
180
-
181
-
182
-
183
-
184
-    /**
185
-     * returns true or false if a venue is password protected or not
186
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
187
-     * @return bool
188
-     */
189
-    public static function is_venue_password_protected($VNU_ID = false)
190
-    {
191
-        $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
192
-        if ($venue instanceof EE_Venue
193
-            && post_password_required($venue->ID())
194
-        ) {
195
-            return true;
196
-        }
197
-        return false;
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * If a venue is password protected, this will return the password form for gaining access
204
-     * returns an empty string otherwise
205
-
206
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
207
-     *
208
-     * @return string
209
-     */
210
-    public static function password_protected_venue_form($VNU_ID = false)
211
-    {
212
-        $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
213
-        if ($venue instanceof EE_Venue
214
-            && post_password_required($venue->ID())
215
-        ) {
216
-            return get_the_password_form($venue->ID());
217
-        }
218
-        return '';
219
-    }
220
-
221
-
222
-
223
-    /**
224
-     *    venue_description
225
-     *
226
-     * @access    public
227
-     * @param int $VNU_ID
228
-     * @return string
229
-     */
230
-    public static function venue_description($VNU_ID = 0)
231
-    {
232
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
233
-        if ($venue instanceof EE_Venue) {
234
-            return $venue->get_pretty('VNU_desc');
235
-        }
236
-        return '';
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     *    venue_excerpt
243
-     *
244
-     * @access    public
245
-     * @param int $VNU_ID
246
-     * @return string
247
-     */
248
-    public static function venue_excerpt($VNU_ID = 0)
249
-    {
250
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
251
-        if ($venue instanceof EE_Venue) {
252
-            $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description();
253
-            $venue_link = ' ' . EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso') . '&hellip;');
254
-            return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : '';
255
-        }
256
-        return '';
257
-    }
258
-
259
-
260
-
261
-    /**
262
-     *    venue_categories
263
-     *
264
-     * @access    public
265
-     * @param int $VNU_ID
266
-     * @param bool $hide_uncategorized
267
-     * @return string
268
-     */
269
-    public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true)
270
-    {
271
-        $category_links = array();
272
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
273
-        if ($venue instanceof EE_Venue) {
274
-            // get category terms
275
-            if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) {
276
-                // loop thru terms and create links
277
-                foreach ($venue_categories as $term) {
278
-                    $url = get_term_link($term, 'espresso_venue_categories');
279
-                    if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) {
280
-                        $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> ';
281
-                    }
282
-                }
283
-            }
284
-        }
285
-        return implode(', ', $category_links);
286
-    }
287
-
288
-
289
-
290
-    /**
291
-     *    venue_address
292
-     *
293
-     * @access    public
294
-     * @param string $type
295
-     * @param int $VNU_ID
296
-     * @param bool $use_schema
297
-     * @param bool $add_wrapper
298
-     * @return string
299
-     */
300
-    public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true)
301
-    {
302
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
303
-        if ($venue instanceof EE_Venue) {
304
-            return EEH_Address::format($venue, $type, $use_schema, $add_wrapper);
305
-        }
306
-        return '';
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     *    venue_has_address
313
-     *
314
-     * @access    public
315
-     * @param int $VNU_ID
316
-     * @return bool|string
317
-     */
318
-    public static function venue_has_address($VNU_ID = 0)
319
-    {
320
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
321
-        if ($venue instanceof EE_Venue) {
322
-            return EEH_Address::format($venue, 'inline', false, false);
323
-        }
324
-        return false;
325
-    }
326
-
327
-
328
-
329
-    /**
330
-     *    venue_name
331
-     *
332
-     * @access    public
333
-     * @param    string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to the Venue's details page or website
334
-     * @param int $VNU_ID
335
-     * @return string
336
-     */
337
-    public static function venue_name($link_to = 'details', $VNU_ID = 0)
338
-    {
339
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
340
-        if ($venue instanceof EE_Venue) {
341
-            $venue_name = apply_filters(
342
-                'FHEE__EEH_Venue__venue_name__append_private_venue_name',
343
-                EEH_Venue_View::is_venue_private()
344
-                    ? EEH_Venue_View::$_venue->name() . "&nbsp;" . __('(Private)', 'event_espresso')
345
-                    : EEH_Venue_View::$_venue->name(),
346
-                EEH_Venue_View::$_venue
347
-            );
348
-            $venue_name = EEH_Schema::name($venue_name);
349
-
350
-            // if venue is trashed then ignore the "link to" setting because the venue is trashed.
351
-            if ($venue->get('status') == 'trash') {
352
-                $link_to = '';
353
-            }
354
-            switch ($link_to) {
355
-                case 'details':
356
-                    return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name);
357
-                break;
358
-
359
-                case 'website':
360
-                    return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name);
361
-                break;
362
-
363
-                default:
364
-                    return $venue_name;
365
-            }
366
-        }
367
-        return '';
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     *    venue_details_link
374
-     *
375
-     * @access    public
376
-     * @param int $VNU_ID
377
-     * @param    string $text
378
-     * @return string
379
-     */
380
-    public static function venue_details_link($VNU_ID = 0, $text = '')
381
-    {
382
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
383
-        if ($venue instanceof EE_Venue) {
384
-            return EEH_Schema::url(get_permalink($venue->ID()), $text);
385
-        }
386
-        return '';
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     *    venue_website_link
393
-     *
394
-     * @access    public
395
-     * @param int $VNU_ID
396
-     * @param    string $text
397
-     * @return string
398
-     */
399
-    public static function venue_website_link($VNU_ID = 0, $text = '')
400
-    {
401
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
402
-        if ($venue instanceof EE_Venue) {
403
-            $url = $venue->venue_url();
404
-            $text = ! empty($text) ? $text : $url;
405
-            return ! empty($url) ? EEH_Schema::url($url, $text) : '';
406
-        }
407
-        return '';
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     *    venue_phone
414
-     *
415
-     * @access    public
416
-     * @param int $VNU_ID
417
-     * @return string
418
-     */
419
-    public static function venue_phone($VNU_ID = 0)
420
-    {
421
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
422
-        if ($venue instanceof EE_Venue) {
423
-            return EEH_Schema::telephone($venue->phone());
424
-        }
425
-        return '';
426
-    }
427
-
428
-
429
-
430
-    /**
431
-     *    venue_gmap
432
-     *
433
-     * @access    public
434
-     * @param int $VNU_ID
435
-     * @param bool|string $map_ID a unique identifier for this map
436
-     * @param    array $gmap map options
437
-     * @return string
438
-     */
439
-    public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = array())
440
-    {
441
-
442
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
443
-        if ($venue instanceof EE_Venue) {
444
-            // check for global espresso_events post and use it's ID if no map_ID is set
445
-            global $post;
446
-            $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID;
447
-            // grab map settings
448
-            $map_cfg = EE_Registry::instance()->CFG->map_settings;
449
-            // are maps enabled ?
450
-            if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) {
451
-                $details_page = is_single();
452
-                $options = array();
453
-                $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/;
454
-
455
-                $options['location'] = EEH_Address::format($venue, 'inline', false, false);
456
-
457
-                $options['ee_map_width'] = $details_page ? $map_cfg->event_details_map_width : $map_cfg->event_list_map_width;
458
-                $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) ? $gmap['ee_map_width'] : $options['ee_map_width'];
459
-
460
-                $options['ee_map_height'] = $details_page ? $map_cfg->event_details_map_height : $map_cfg->event_list_map_height;
461
-                $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) ? $gmap['ee_map_height'] : $options['ee_map_height'];
462
-
463
-                $options['ee_map_zoom'] = $details_page ? $map_cfg->event_details_map_zoom : $map_cfg->event_list_map_zoom;
464
-                $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom'];
465
-
466
-                $options['ee_map_nav_display'] = $details_page ? $map_cfg->event_details_display_nav : $map_cfg->event_list_display_nav;
467
-                $options['ee_map_nav_display'] = isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) ? 'true' : $options['ee_map_nav_display'];
468
-                ;
469
-
470
-                $options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size;
471
-                $options['ee_map_nav_size'] =  isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size'])? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size'];
472
-
473
-                $options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type;
474
-                $options['ee_map_type_control'] =  isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control'])? $gmap['ee_map_type_control'] : $options['ee_map_type_control'];
475
-
476
-                $options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align;
477
-                $options['ee_map_align'] =  isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align'])? $gmap['ee_map_align'] : $options['ee_map_align'];
478
-
479
-                $options['ee_static_url'] =  isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link();
480
-
481
-                return EEH_Maps::google_map($options);
482
-            }
483
-        }
484
-
485
-        return '';
486
-    }
487
-
488
-    /**
489
-     * Gets the HTML to display a static map of the venue
490
-     * @param EE_Venue $venue
491
-     * @param array $atts like EEH_Maps::google_map_link
492
-     * @return string
493
-     */
494
-    public static function espresso_google_static_map(EE_Venue $venue, $atts = array())
495
-    {
496
-        $state = $venue->state_obj();
497
-        $country = $venue->country_obj();
498
-        $atts = shortcode_atts(
499
-            array(
500
-                    'id' => $venue->ID(),
501
-                    'address' => $venue->get('VNU_address'),
502
-                    'city' => $venue->get('VNU_city'),
503
-                    'state' => $state instanceof EE_State ? $state->name() : '',
504
-                    'zip' => $venue->get('VNU_zip'),
505
-                    'country' => $country instanceof EE_Country ? $country->name() : '',
506
-                    'type' => 'map',
507
-                    'map_w' => 200,
508
-                    'map_h' => 200
509
-                    ),
510
-            $atts
511
-        );
512
-        return EEH_Maps::google_map_link($atts);
513
-    }
514
-
515
-
516
-
517
-    /**
518
-     *    edit_venue_link
519
-     *
520
-     * @access    public
521
-     * @param int $VNU_ID
522
-     * @param string $link
523
-     * @param string $before
524
-     * @param string $after
525
-     * @return string
526
-     */
527
-    public static function edit_venue_link($VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>')
528
-    {
529
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
530
-        if ($venue instanceof EE_Venue) {
531
-            // can the user edit this post ?
532
-            if (current_user_can('edit_post', $venue->ID())) {
533
-                // set link text
534
-                $link = ! empty($link) ? $link : __('edit this venue', 'event_espresso');
535
-                // generate nonce
536
-                $nonce = wp_create_nonce('edit_nonce');
537
-                // generate url to venue editor for this venue
538
-                $url = add_query_arg(array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url('admin.php'));
539
-                // get edit CPT text
540
-                $post_type_obj = get_post_type_object('espresso_venues');
541
-                // build final link html
542
-                $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr($post_type_obj->labels->edit_item) . '">' . $link . '</a>';
543
-                // put it all together
544
-                return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after;
545
-            }
546
-        }
547
-        return '';
548
-    }
14
+	/**
15
+	 * @access    private
16
+	 * @var EE_Venue
17
+	 */
18
+	private static $_venue = null;
19
+
20
+
21
+
22
+	/**
23
+	 *    get_venue
24
+	 *    attempts to retrieve an EE_Venue object any way it can
25
+	 *
26
+	 * @access    public
27
+	 * @param int  $VNU_ID
28
+	 * @param bool $look_in_event
29
+	 * @param bool $privacy_check   Defaults to true.
30
+	 *                              When false, means even if the venue is private we return it regardless of access.
31
+	 * @param bool $password_check
32
+	 * @return \EE_Venue|null
33
+	 */
34
+	public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true)
35
+	{
36
+		$VNU_ID = absint($VNU_ID);
37
+		// do we already have the Venue you are looking for?
38
+		if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
39
+			// If the Venue ID matches $VNU_ID, return the venue.
40
+			if (EEH_Venue_View::$_venue->ID() === $VNU_ID) {
41
+				return EEH_Venue_View::_get_venue($privacy_check);
42
+			}
43
+			// If the Venue ID does not match, try pulling a venue using $VNU_ID.
44
+			$venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
45
+			if ($venue instanceof EE_Venue) {
46
+				EEH_Venue_View::$_venue = $venue;
47
+				return EEH_Venue_View::_get_venue($privacy_check);
48
+			}
49
+		}
50
+		// international newspaper?
51
+		global $post;
52
+		if ($post instanceof WP_Post) {
53
+			switch ($post->post_type) {
54
+				// if this is being called from an EE_Venue post,
55
+				// and the EE_Venue post corresponds to the EE_Venue that is being asked for,
56
+				// then we can try to just grab the attached EE_Venue object
57
+				case 'espresso_venues':
58
+					// the post already contains the related EE_Venue object AND one of the following is TRUE:
59
+					// the requested Venue ID matches the post ID OR...
60
+					// there was no specific Venue ID requested
61
+					if (isset($post->EE_Venue) && ( $VNU_ID == $post->ID || ! $VNU_ID )) {
62
+						// use existing related EE_Venue object
63
+						EEH_Venue_View::$_venue =  $post->EE_Venue;
64
+					} elseif ($VNU_ID) {
65
+						// there WAS a specific Venue ID requested, but it's NOT the current post object
66
+						EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
67
+					} else {
68
+						// no specific Venue ID requested, so use post ID to generate EE_Venue object
69
+						EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID);
70
+					}
71
+					break;
72
+
73
+				case 'espresso_events':
74
+					if ($look_in_event) {
75
+						// grab the events related venues
76
+						$venues = EEH_Venue_View::get_event_venues();
77
+						// make sure the result is an array
78
+						$venues = is_array($venues) ? $venues : array();
79
+						// do we have an ID for a specific venue?
80
+						if ($VNU_ID) {
81
+							// loop thru the related venues
82
+							foreach ($venues as $venue) {
83
+								if ($venue instanceof EE_Venue) {
84
+									// until we find the venue we're looking for
85
+									if ($venue->ID() == $VNU_ID) {
86
+										EEH_Venue_View::$_venue = $venue;
87
+										break;
88
+									}
89
+								}
90
+							}
91
+						// no venue ID ?
92
+						// then the global post is an events post and this function was called with no argument
93
+						} else {
94
+							// just grab the first related event venue
95
+							EEH_Venue_View::$_venue = reset($venues);
96
+						}
97
+					}
98
+					break;
99
+			}
100
+		}
101
+		// now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID...
102
+		if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
103
+			// sigh... pull it from the db
104
+			EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
105
+		}
106
+		return EEH_Venue_View::_get_venue($privacy_check, $password_check);
107
+	}
108
+
109
+
110
+
111
+	/**
112
+	 * return a single venue
113
+	 *
114
+	 * @param bool $privacy_check   Defaults to true.
115
+	 *                              When false, means even if the venue is private we return it regardless of access.
116
+	 * @param bool $password_check
117
+	 * @return  EE_Venue
118
+	 */
119
+	protected static function _get_venue($privacy_check = true, $password_check = true)
120
+	{
121
+		// check for private venues.
122
+		if (EEH_Venue_View::$_venue instanceof EE_Venue
123
+			&& EEH_Venue_View::$_venue->status() == 'private'
124
+			&& $privacy_check
125
+			&& ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')
126
+		) {
127
+			return null;
128
+		}
129
+		// check for password protected venues
130
+		if (EEH_Venue_View::$_venue instanceof EE_Venue
131
+			&& $password_check
132
+			&& post_password_required(EEH_Venue_View::$_venue->ID())
133
+		) {
134
+			return null;
135
+		}
136
+		return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null;
137
+	}
138
+
139
+
140
+
141
+	/**
142
+	 *  get_event_venues
143
+	 *
144
+	 *  @access     public
145
+	 *  @return     EE_Venue[]
146
+	 */
147
+	public static function get_event_venues()
148
+	{
149
+		global $post;
150
+		if ($post->post_type == 'espresso_events') {
151
+			if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) {
152
+				return $post->EE_Event->venues();
153
+			}
154
+		}
155
+		return array();
156
+	}
157
+
158
+
159
+
160
+
161
+	/**
162
+	 * Simply checks whether a venue for the given ID (or the internally derived venue is private).
163
+	 *
164
+	 * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but is not
165
+	 *    private.  So it is important to do explicit boolean checks when using this conditional.
166
+	 *
167
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
168
+	 *
169
+	 * @return bool|null
170
+	 */
171
+	public static function is_venue_private($VNU_ID = false)
172
+	{
173
+		$venue = EEH_Venue_View::get_venue($VNU_ID, true, true);
174
+		if (! $venue instanceof EE_Venue) {
175
+			return null;
176
+		}
177
+
178
+		return $venue->status() == 'private' ? true : false;
179
+	}
180
+
181
+
182
+
183
+
184
+	/**
185
+	 * returns true or false if a venue is password protected or not
186
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
187
+	 * @return bool
188
+	 */
189
+	public static function is_venue_password_protected($VNU_ID = false)
190
+	{
191
+		$venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
192
+		if ($venue instanceof EE_Venue
193
+			&& post_password_required($venue->ID())
194
+		) {
195
+			return true;
196
+		}
197
+		return false;
198
+	}
199
+
200
+
201
+
202
+	/**
203
+	 * If a venue is password protected, this will return the password form for gaining access
204
+	 * returns an empty string otherwise
205
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
206
+	 *
207
+	 * @return string
208
+	 */
209
+	public static function password_protected_venue_form($VNU_ID = false)
210
+	{
211
+		$venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
212
+		if ($venue instanceof EE_Venue
213
+			&& post_password_required($venue->ID())
214
+		) {
215
+			return get_the_password_form($venue->ID());
216
+		}
217
+		return '';
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 *    venue_description
224
+	 *
225
+	 * @access    public
226
+	 * @param int $VNU_ID
227
+	 * @return string
228
+	 */
229
+	public static function venue_description($VNU_ID = 0)
230
+	{
231
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
232
+		if ($venue instanceof EE_Venue) {
233
+			return $venue->get_pretty('VNU_desc');
234
+		}
235
+		return '';
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 *    venue_excerpt
242
+	 *
243
+	 * @access    public
244
+	 * @param int $VNU_ID
245
+	 * @return string
246
+	 */
247
+	public static function venue_excerpt($VNU_ID = 0)
248
+	{
249
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
250
+		if ($venue instanceof EE_Venue) {
251
+			$excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description();
252
+			$venue_link = ' ' . EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso') . '&hellip;');
253
+			return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : '';
254
+		}
255
+		return '';
256
+	}
257
+
258
+
259
+
260
+	/**
261
+	 *    venue_categories
262
+	 *
263
+	 * @access    public
264
+	 * @param int $VNU_ID
265
+	 * @param bool $hide_uncategorized
266
+	 * @return string
267
+	 */
268
+	public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true)
269
+	{
270
+		$category_links = array();
271
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
272
+		if ($venue instanceof EE_Venue) {
273
+			// get category terms
274
+			if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) {
275
+				// loop thru terms and create links
276
+				foreach ($venue_categories as $term) {
277
+					$url = get_term_link($term, 'espresso_venue_categories');
278
+					if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) {
279
+						$category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> ';
280
+					}
281
+				}
282
+			}
283
+		}
284
+		return implode(', ', $category_links);
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 *    venue_address
291
+	 *
292
+	 * @access    public
293
+	 * @param string $type
294
+	 * @param int $VNU_ID
295
+	 * @param bool $use_schema
296
+	 * @param bool $add_wrapper
297
+	 * @return string
298
+	 */
299
+	public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true)
300
+	{
301
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
302
+		if ($venue instanceof EE_Venue) {
303
+			return EEH_Address::format($venue, $type, $use_schema, $add_wrapper);
304
+		}
305
+		return '';
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 *    venue_has_address
312
+	 *
313
+	 * @access    public
314
+	 * @param int $VNU_ID
315
+	 * @return bool|string
316
+	 */
317
+	public static function venue_has_address($VNU_ID = 0)
318
+	{
319
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
320
+		if ($venue instanceof EE_Venue) {
321
+			return EEH_Address::format($venue, 'inline', false, false);
322
+		}
323
+		return false;
324
+	}
325
+
326
+
327
+
328
+	/**
329
+	 *    venue_name
330
+	 *
331
+	 * @access    public
332
+	 * @param    string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to the Venue's details page or website
333
+	 * @param int $VNU_ID
334
+	 * @return string
335
+	 */
336
+	public static function venue_name($link_to = 'details', $VNU_ID = 0)
337
+	{
338
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
339
+		if ($venue instanceof EE_Venue) {
340
+			$venue_name = apply_filters(
341
+				'FHEE__EEH_Venue__venue_name__append_private_venue_name',
342
+				EEH_Venue_View::is_venue_private()
343
+					? EEH_Venue_View::$_venue->name() . "&nbsp;" . __('(Private)', 'event_espresso')
344
+					: EEH_Venue_View::$_venue->name(),
345
+				EEH_Venue_View::$_venue
346
+			);
347
+			$venue_name = EEH_Schema::name($venue_name);
348
+
349
+			// if venue is trashed then ignore the "link to" setting because the venue is trashed.
350
+			if ($venue->get('status') == 'trash') {
351
+				$link_to = '';
352
+			}
353
+			switch ($link_to) {
354
+				case 'details':
355
+					return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name);
356
+				break;
357
+
358
+				case 'website':
359
+					return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name);
360
+				break;
361
+
362
+				default:
363
+					return $venue_name;
364
+			}
365
+		}
366
+		return '';
367
+	}
368
+
369
+
370
+
371
+	/**
372
+	 *    venue_details_link
373
+	 *
374
+	 * @access    public
375
+	 * @param int $VNU_ID
376
+	 * @param    string $text
377
+	 * @return string
378
+	 */
379
+	public static function venue_details_link($VNU_ID = 0, $text = '')
380
+	{
381
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
382
+		if ($venue instanceof EE_Venue) {
383
+			return EEH_Schema::url(get_permalink($venue->ID()), $text);
384
+		}
385
+		return '';
386
+	}
387
+
388
+
389
+
390
+	/**
391
+	 *    venue_website_link
392
+	 *
393
+	 * @access    public
394
+	 * @param int $VNU_ID
395
+	 * @param    string $text
396
+	 * @return string
397
+	 */
398
+	public static function venue_website_link($VNU_ID = 0, $text = '')
399
+	{
400
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
401
+		if ($venue instanceof EE_Venue) {
402
+			$url = $venue->venue_url();
403
+			$text = ! empty($text) ? $text : $url;
404
+			return ! empty($url) ? EEH_Schema::url($url, $text) : '';
405
+		}
406
+		return '';
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 *    venue_phone
413
+	 *
414
+	 * @access    public
415
+	 * @param int $VNU_ID
416
+	 * @return string
417
+	 */
418
+	public static function venue_phone($VNU_ID = 0)
419
+	{
420
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
421
+		if ($venue instanceof EE_Venue) {
422
+			return EEH_Schema::telephone($venue->phone());
423
+		}
424
+		return '';
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 *    venue_gmap
431
+	 *
432
+	 * @access    public
433
+	 * @param int $VNU_ID
434
+	 * @param bool|string $map_ID a unique identifier for this map
435
+	 * @param    array $gmap map options
436
+	 * @return string
437
+	 */
438
+	public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = array())
439
+	{
440
+
441
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
442
+		if ($venue instanceof EE_Venue) {
443
+			// check for global espresso_events post and use it's ID if no map_ID is set
444
+			global $post;
445
+			$map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID;
446
+			// grab map settings
447
+			$map_cfg = EE_Registry::instance()->CFG->map_settings;
448
+			// are maps enabled ?
449
+			if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) {
450
+				$details_page = is_single();
451
+				$options = array();
452
+				$options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/;
453
+
454
+				$options['location'] = EEH_Address::format($venue, 'inline', false, false);
455
+
456
+				$options['ee_map_width'] = $details_page ? $map_cfg->event_details_map_width : $map_cfg->event_list_map_width;
457
+				$options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) ? $gmap['ee_map_width'] : $options['ee_map_width'];
458
+
459
+				$options['ee_map_height'] = $details_page ? $map_cfg->event_details_map_height : $map_cfg->event_list_map_height;
460
+				$options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) ? $gmap['ee_map_height'] : $options['ee_map_height'];
461
+
462
+				$options['ee_map_zoom'] = $details_page ? $map_cfg->event_details_map_zoom : $map_cfg->event_list_map_zoom;
463
+				$options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom'];
464
+
465
+				$options['ee_map_nav_display'] = $details_page ? $map_cfg->event_details_display_nav : $map_cfg->event_list_display_nav;
466
+				$options['ee_map_nav_display'] = isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) ? 'true' : $options['ee_map_nav_display'];
467
+				;
468
+
469
+				$options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size;
470
+				$options['ee_map_nav_size'] =  isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size'])? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size'];
471
+
472
+				$options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type;
473
+				$options['ee_map_type_control'] =  isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control'])? $gmap['ee_map_type_control'] : $options['ee_map_type_control'];
474
+
475
+				$options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align;
476
+				$options['ee_map_align'] =  isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align'])? $gmap['ee_map_align'] : $options['ee_map_align'];
477
+
478
+				$options['ee_static_url'] =  isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link();
479
+
480
+				return EEH_Maps::google_map($options);
481
+			}
482
+		}
483
+
484
+		return '';
485
+	}
486
+
487
+	/**
488
+	 * Gets the HTML to display a static map of the venue
489
+	 * @param EE_Venue $venue
490
+	 * @param array $atts like EEH_Maps::google_map_link
491
+	 * @return string
492
+	 */
493
+	public static function espresso_google_static_map(EE_Venue $venue, $atts = array())
494
+	{
495
+		$state = $venue->state_obj();
496
+		$country = $venue->country_obj();
497
+		$atts = shortcode_atts(
498
+			array(
499
+					'id' => $venue->ID(),
500
+					'address' => $venue->get('VNU_address'),
501
+					'city' => $venue->get('VNU_city'),
502
+					'state' => $state instanceof EE_State ? $state->name() : '',
503
+					'zip' => $venue->get('VNU_zip'),
504
+					'country' => $country instanceof EE_Country ? $country->name() : '',
505
+					'type' => 'map',
506
+					'map_w' => 200,
507
+					'map_h' => 200
508
+					),
509
+			$atts
510
+		);
511
+		return EEH_Maps::google_map_link($atts);
512
+	}
513
+
514
+
515
+
516
+	/**
517
+	 *    edit_venue_link
518
+	 *
519
+	 * @access    public
520
+	 * @param int $VNU_ID
521
+	 * @param string $link
522
+	 * @param string $before
523
+	 * @param string $after
524
+	 * @return string
525
+	 */
526
+	public static function edit_venue_link($VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>')
527
+	{
528
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
529
+		if ($venue instanceof EE_Venue) {
530
+			// can the user edit this post ?
531
+			if (current_user_can('edit_post', $venue->ID())) {
532
+				// set link text
533
+				$link = ! empty($link) ? $link : __('edit this venue', 'event_espresso');
534
+				// generate nonce
535
+				$nonce = wp_create_nonce('edit_nonce');
536
+				// generate url to venue editor for this venue
537
+				$url = add_query_arg(array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url('admin.php'));
538
+				// get edit CPT text
539
+				$post_type_obj = get_post_type_object('espresso_venues');
540
+				// build final link html
541
+				$link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr($post_type_obj->labels->edit_item) . '">' . $link . '</a>';
542
+				// put it all together
543
+				return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after;
544
+			}
545
+		}
546
+		return '';
547
+	}
549 548
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Base.helper.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -11,42 +11,42 @@
 block discarded – undo
11 11
 class EEH_Base
12 12
 {
13 13
 
14
-    /**
15
-     *  @var    array   $uri_segment_array  URL segments
16
-     *  @access     private
17
-     */
14
+	/**
15
+	 *  @var    array   $uri_segment_array  URL segments
16
+	 *  @access     private
17
+	 */
18 18
 //  final private function __construct() {}
19 19
 
20
-    /**
21
-     *      @ override magic methods
22
-     *      @ return void
23
-     */
24
-    public function __set($a, $b)
25
-    {
26
-        return false;
27
-    }
28
-    public function __get($a)
29
-    {
30
-        return false;
31
-    }
32
-    public function __isset($a)
33
-    {
34
-        return false;
35
-    }
36
-    public function __unset($a)
37
-    {
38
-        return false;
39
-    }
40
-    public function __clone()
41
-    {
42
-        return false;
43
-    }
44
-    public function __wakeup()
45
-    {
46
-        return false;
47
-    }
48
-    public function __destruct()
49
-    {
50
-        return false;
51
-    }
20
+	/**
21
+	 *      @ override magic methods
22
+	 *      @ return void
23
+	 */
24
+	public function __set($a, $b)
25
+	{
26
+		return false;
27
+	}
28
+	public function __get($a)
29
+	{
30
+		return false;
31
+	}
32
+	public function __isset($a)
33
+	{
34
+		return false;
35
+	}
36
+	public function __unset($a)
37
+	{
38
+		return false;
39
+	}
40
+	public function __clone()
41
+	{
42
+		return false;
43
+	}
44
+	public function __wakeup()
45
+	{
46
+		return false;
47
+	}
48
+	public function __destruct()
49
+	{
50
+		return false;
51
+	}
52 52
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Array.helper.php 2 patches
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -13,203 +13,203 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays
18
-     * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects
19
-     *
20
-     * @uses array_udiff core php function for setting up our own array comparison
21
-     * @uses self::_compare_objects as the custom method for array_udiff
22
-     * @param  array $array1 an array of objects
23
-     * @param  array $array2 an array of objects
24
-     * @return array         an array of objects found in array 1 that aren't found in array 2.
25
-     */
26
-    public static function object_array_diff($array1, $array2)
27
-    {
28
-        return array_udiff($array1, $array2, array('self', '_compare_objects'));
29
-    }
30
-
31
-    /**
32
-     * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed
33
-     *
34
-     * @param array $array
35
-     * @return boolean
36
-     */
37
-    public static function is_associative_array(array $array)
38
-    {
39
-        return array_keys($array) !== range(0, count($array) - 1);
40
-    }
41
-
42
-    /**
43
-     * Gets an item from the array and leave the array intact. Use in place of end()
44
-     * when you don't want to change the array
45
-     *
46
-     * @param array $arr
47
-     * @return mixed what ever is in the array
48
-     */
49
-    public static function get_one_item_from_array($arr)
50
-    {
51
-        $item = end($arr);
52
-        reset($arr);
53
-        return $item;
54
-    }
55
-
56
-    /**
57
-     * Detects if this is a multi-dimensional array (meaning that the top-level
58
-     * values are themselves array. Eg array(array(...),...)
59
-     *
60
-     * @param mixed $arr
61
-     * @return boolean
62
-     */
63
-    public static function is_multi_dimensional_array($arr)
64
-    {
65
-        if (is_array($arr)) {
66
-            $first_item = reset($arr);
67
-            if (is_array($first_item)) {
68
-                return true;// yep, there's at least 2 levels to this array
69
-            } else {
70
-                return false;// nope, only 1 level
71
-            }
72
-        } else {
73
-            return false;// its not an array at all!
74
-        }
75
-    }
76
-
77
-    /**
78
-     * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default
79
-     *
80
-     * @param array $arr
81
-     * @param mixed $index
82
-     * @param mixed $default
83
-     * @return mixed
84
-     */
85
-    public static function is_set($arr, $index, $default)
86
-    {
87
-        return isset($arr[ $index ]) ? $arr[ $index ] : $default;
88
-    }
89
-
90
-    /**
91
-     * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118
92
-     *
93
-     * @param mixed $value usually a string, but could be an array or object
94
-     * @return mixed the UN-serialized data
95
-     */
96
-    public static function maybe_unserialize($value)
97
-    {
98
-        $data = maybe_unserialize($value);
99
-        // it's possible that this still has serialized data if its the session.  WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesnt' unserialize this automatically.
100
-        $token = 'C';
101
-        $data = is_string($data) ? trim($data) : $data;
102
-        if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) {
103
-            return unserialize($data);
104
-        } else {
105
-            return $data;
106
-        }
107
-    }
108
-
109
-
110
-    /**
111
-     * insert_into_array
112
-     *
113
-     * @param array        $target_array the array to insert new data into
114
-     * @param array        $array_to_insert the new data to be inserted
115
-     * @param int | string $offset a known key within $target_array where new data will be inserted
116
-     * @param bool         $add_before whether to add new data before or after the offset key
117
-     * @param bool         $preserve_keys whether or not to reset numerically indexed arrays
118
-     * @return array
119
-     */
120
-    public static function insert_into_array(
121
-        $target_array = array(),
122
-        $array_to_insert = array(),
123
-        $offset = null,
124
-        $add_before = true,
125
-        $preserve_keys = true
126
-    ) {
127
-        // ensure incoming arrays are actually arrays
128
-        $target_array = (array) $target_array;
129
-        $array_to_insert = (array) $array_to_insert;
130
-        // if no offset key was supplied
131
-        if (empty($offset)) {
132
-            // use start or end of $target_array based on whether we are adding before or not
133
-            $offset = $add_before ? 0 : count($target_array);
134
-        }
135
-        // if offset key is a string, then find the corresponding numeric location for that element
136
-        $offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array));
137
-        // add one to the offset if adding after
138
-        $offset = $add_before ? $offset : $offset + 1;
139
-        // but ensure offset does not exceed the length of the array
140
-        $offset = $offset > count($target_array) ? count($target_array) : $offset;
141
-        // reindex array ???
142
-        if ($preserve_keys) {
143
-            // take a slice of the target array from the beginning till the offset,
144
-            // then add the new data
145
-            // then add another slice that starts at the offset and goes till the end
146
-            return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice(
147
-                $target_array,
148
-                $offset,
149
-                null,
150
-                true
151
-            );
152
-        } else {
153
-            // since we don't want to preserve keys, we can use array_splice
154
-            array_splice($target_array, $offset, 0, $array_to_insert);
155
-            return $target_array;
156
-        }
157
-    }
158
-
159
-
160
-    /**
161
-     * array_merge() is slow and should never be used while looping over data
162
-     * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster
163
-     * so really this acts more like array_replace( $array1, $array2 )
164
-     * or a union with the arrays flipped ( $array2 + $array1 )
165
-     * this saves a few lines of code and improves readability
166
-     *
167
-     * @param array $array1
168
-     * @param array $array2
169
-     * @return array
170
-     */
171
-    public static function merge_arrays_and_overwrite_keys(array $array1, array $array2)
172
-    {
173
-        foreach ($array2 as $key => $value) {
174
-            $array1[ $key ] = $value;
175
-        }
176
-        return $array1;
177
-    }
178
-
179
-
180
-    /**
181
-     * given a flat array like $array = array('A', 'B', 'C')
182
-     * will convert into a multidimensional array like $array[A][B][C]
183
-     * if $final_value is provided and is anything other than null,
184
-     * then that will be set as the value for the innermost array key
185
-     * like so: $array[A][B][C] = $final_value
186
-     *
187
-     * @param array $flat_array
188
-     * @param mixed $final_value
189
-     * @return array
190
-     */
191
-    public static function convert_array_values_to_keys(array $flat_array, $final_value = null)
192
-    {
193
-        $multidimensional = array();
194
-        $reference = &$multidimensional;
195
-        foreach ($flat_array as $key) {
196
-            $reference[ $key ] = array();
197
-            $reference = &$reference[ $key ];
198
-        }
199
-        if ($final_value !== null) {
200
-            $reference = $final_value;
201
-        }
202
-        return $multidimensional;
203
-    }
204
-
205
-
206
-    /**
207
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
208
-     * @param array $array
209
-     * @return bool
210
-     */
211
-    public static function is_array_numerically_and_sequentially_indexed(array $array)
212
-    {
213
-        return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
214
-    }
16
+	/**
17
+	 * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays
18
+	 * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects
19
+	 *
20
+	 * @uses array_udiff core php function for setting up our own array comparison
21
+	 * @uses self::_compare_objects as the custom method for array_udiff
22
+	 * @param  array $array1 an array of objects
23
+	 * @param  array $array2 an array of objects
24
+	 * @return array         an array of objects found in array 1 that aren't found in array 2.
25
+	 */
26
+	public static function object_array_diff($array1, $array2)
27
+	{
28
+		return array_udiff($array1, $array2, array('self', '_compare_objects'));
29
+	}
30
+
31
+	/**
32
+	 * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed
33
+	 *
34
+	 * @param array $array
35
+	 * @return boolean
36
+	 */
37
+	public static function is_associative_array(array $array)
38
+	{
39
+		return array_keys($array) !== range(0, count($array) - 1);
40
+	}
41
+
42
+	/**
43
+	 * Gets an item from the array and leave the array intact. Use in place of end()
44
+	 * when you don't want to change the array
45
+	 *
46
+	 * @param array $arr
47
+	 * @return mixed what ever is in the array
48
+	 */
49
+	public static function get_one_item_from_array($arr)
50
+	{
51
+		$item = end($arr);
52
+		reset($arr);
53
+		return $item;
54
+	}
55
+
56
+	/**
57
+	 * Detects if this is a multi-dimensional array (meaning that the top-level
58
+	 * values are themselves array. Eg array(array(...),...)
59
+	 *
60
+	 * @param mixed $arr
61
+	 * @return boolean
62
+	 */
63
+	public static function is_multi_dimensional_array($arr)
64
+	{
65
+		if (is_array($arr)) {
66
+			$first_item = reset($arr);
67
+			if (is_array($first_item)) {
68
+				return true;// yep, there's at least 2 levels to this array
69
+			} else {
70
+				return false;// nope, only 1 level
71
+			}
72
+		} else {
73
+			return false;// its not an array at all!
74
+		}
75
+	}
76
+
77
+	/**
78
+	 * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default
79
+	 *
80
+	 * @param array $arr
81
+	 * @param mixed $index
82
+	 * @param mixed $default
83
+	 * @return mixed
84
+	 */
85
+	public static function is_set($arr, $index, $default)
86
+	{
87
+		return isset($arr[ $index ]) ? $arr[ $index ] : $default;
88
+	}
89
+
90
+	/**
91
+	 * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118
92
+	 *
93
+	 * @param mixed $value usually a string, but could be an array or object
94
+	 * @return mixed the UN-serialized data
95
+	 */
96
+	public static function maybe_unserialize($value)
97
+	{
98
+		$data = maybe_unserialize($value);
99
+		// it's possible that this still has serialized data if its the session.  WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesnt' unserialize this automatically.
100
+		$token = 'C';
101
+		$data = is_string($data) ? trim($data) : $data;
102
+		if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) {
103
+			return unserialize($data);
104
+		} else {
105
+			return $data;
106
+		}
107
+	}
108
+
109
+
110
+	/**
111
+	 * insert_into_array
112
+	 *
113
+	 * @param array        $target_array the array to insert new data into
114
+	 * @param array        $array_to_insert the new data to be inserted
115
+	 * @param int | string $offset a known key within $target_array where new data will be inserted
116
+	 * @param bool         $add_before whether to add new data before or after the offset key
117
+	 * @param bool         $preserve_keys whether or not to reset numerically indexed arrays
118
+	 * @return array
119
+	 */
120
+	public static function insert_into_array(
121
+		$target_array = array(),
122
+		$array_to_insert = array(),
123
+		$offset = null,
124
+		$add_before = true,
125
+		$preserve_keys = true
126
+	) {
127
+		// ensure incoming arrays are actually arrays
128
+		$target_array = (array) $target_array;
129
+		$array_to_insert = (array) $array_to_insert;
130
+		// if no offset key was supplied
131
+		if (empty($offset)) {
132
+			// use start or end of $target_array based on whether we are adding before or not
133
+			$offset = $add_before ? 0 : count($target_array);
134
+		}
135
+		// if offset key is a string, then find the corresponding numeric location for that element
136
+		$offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array));
137
+		// add one to the offset if adding after
138
+		$offset = $add_before ? $offset : $offset + 1;
139
+		// but ensure offset does not exceed the length of the array
140
+		$offset = $offset > count($target_array) ? count($target_array) : $offset;
141
+		// reindex array ???
142
+		if ($preserve_keys) {
143
+			// take a slice of the target array from the beginning till the offset,
144
+			// then add the new data
145
+			// then add another slice that starts at the offset and goes till the end
146
+			return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice(
147
+				$target_array,
148
+				$offset,
149
+				null,
150
+				true
151
+			);
152
+		} else {
153
+			// since we don't want to preserve keys, we can use array_splice
154
+			array_splice($target_array, $offset, 0, $array_to_insert);
155
+			return $target_array;
156
+		}
157
+	}
158
+
159
+
160
+	/**
161
+	 * array_merge() is slow and should never be used while looping over data
162
+	 * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster
163
+	 * so really this acts more like array_replace( $array1, $array2 )
164
+	 * or a union with the arrays flipped ( $array2 + $array1 )
165
+	 * this saves a few lines of code and improves readability
166
+	 *
167
+	 * @param array $array1
168
+	 * @param array $array2
169
+	 * @return array
170
+	 */
171
+	public static function merge_arrays_and_overwrite_keys(array $array1, array $array2)
172
+	{
173
+		foreach ($array2 as $key => $value) {
174
+			$array1[ $key ] = $value;
175
+		}
176
+		return $array1;
177
+	}
178
+
179
+
180
+	/**
181
+	 * given a flat array like $array = array('A', 'B', 'C')
182
+	 * will convert into a multidimensional array like $array[A][B][C]
183
+	 * if $final_value is provided and is anything other than null,
184
+	 * then that will be set as the value for the innermost array key
185
+	 * like so: $array[A][B][C] = $final_value
186
+	 *
187
+	 * @param array $flat_array
188
+	 * @param mixed $final_value
189
+	 * @return array
190
+	 */
191
+	public static function convert_array_values_to_keys(array $flat_array, $final_value = null)
192
+	{
193
+		$multidimensional = array();
194
+		$reference = &$multidimensional;
195
+		foreach ($flat_array as $key) {
196
+			$reference[ $key ] = array();
197
+			$reference = &$reference[ $key ];
198
+		}
199
+		if ($final_value !== null) {
200
+			$reference = $final_value;
201
+		}
202
+		return $multidimensional;
203
+	}
204
+
205
+
206
+	/**
207
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
208
+	 * @param array $array
209
+	 * @return bool
210
+	 */
211
+	public static function is_array_numerically_and_sequentially_indexed(array $array)
212
+	{
213
+		return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
214
+	}
215 215
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
         if (is_array($arr)) {
66 66
             $first_item = reset($arr);
67 67
             if (is_array($first_item)) {
68
-                return true;// yep, there's at least 2 levels to this array
68
+                return true; // yep, there's at least 2 levels to this array
69 69
             } else {
70
-                return false;// nope, only 1 level
70
+                return false; // nope, only 1 level
71 71
             }
72 72
         } else {
73
-            return false;// its not an array at all!
73
+            return false; // its not an array at all!
74 74
         }
75 75
     }
76 76
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public static function is_set($arr, $index, $default)
86 86
     {
87
-        return isset($arr[ $index ]) ? $arr[ $index ] : $default;
87
+        return isset($arr[$index]) ? $arr[$index] : $default;
88 88
     }
89 89
 
90 90
     /**
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
     public static function merge_arrays_and_overwrite_keys(array $array1, array $array2)
172 172
     {
173 173
         foreach ($array2 as $key => $value) {
174
-            $array1[ $key ] = $value;
174
+            $array1[$key] = $value;
175 175
         }
176 176
         return $array1;
177 177
     }
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
         $multidimensional = array();
194 194
         $reference = &$multidimensional;
195 195
         foreach ($flat_array as $key) {
196
-            $reference[ $key ] = array();
197
-            $reference = &$reference[ $key ];
196
+            $reference[$key] = array();
197
+            $reference = &$reference[$key];
198 198
         }
199 199
         if ($final_value !== null) {
200 200
             $reference = $final_value;
Please login to merge, or discard this patch.
core/helpers/EEH_Event_Query.helper.php 2 patches
Indentation   +669 added lines, -669 removed lines patch added patch discarded remove patch
@@ -15,673 +15,673 @@
 block discarded – undo
15 15
 class EEH_Event_Query
16 16
 {
17 17
 
18
-    /**
19
-     * Start Date
20
-     *
21
-     * @var $_event_query_month
22
-     */
23
-    protected static $_event_query_month;
24
-
25
-    /**
26
-     * Category
27
-     *
28
-     * @var $_event_query_category
29
-     */
30
-    protected static $_event_query_category;
31
-
32
-    /**
33
-     * whether to display expired events in the event list
34
-     *
35
-     * @var bool $_show_expired
36
-     */
37
-    protected static $_event_query_show_expired = false;
38
-
39
-    /**
40
-     * list of params for controlling how the query results are ordered
41
-     *
42
-     * @var array $_event_query_orderby
43
-     */
44
-    protected static $_event_query_orderby = array();
45
-
46
-    /**
47
-     * direction list is sorted
48
-     *
49
-     * @var string $_event_query_sort
50
-     */
51
-    protected static $_event_query_sort;
52
-
53
-    /**
54
-     * list of params used to build the query's various clauses
55
-     *
56
-     * @var $_query_params
57
-     */
58
-    protected static $_query_params = array();
59
-
60
-
61
-
62
-    /**
63
-     * @return void
64
-     */
65
-    public static function add_query_filters()
66
-    {
67
-        // add query filters
68
-        add_action('pre_get_posts', array('EEH_Event_Query', 'filter_query_parts'), 10, 1);
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * @param WP_Query $WP_Query
75
-     * @return bool
76
-     */
77
-    public static function apply_query_filters(WP_Query $WP_Query)
78
-    {
79
-        return (
80
-                   isset($WP_Query->query['post_type'])
81
-                   && $WP_Query->query['post_type'] === 'espresso_events'
82
-               )
83
-               || apply_filters('FHEE__EEH_Event_Query__apply_query_filters', false);
84
-    }
85
-
86
-
87
-    /**
88
-     * @param WP_Query $WP_Query
89
-     */
90
-    public static function filter_query_parts(WP_Query $WP_Query)
91
-    {
92
-        // ONLY add our filters if this isn't the main wp_query,
93
-        // because if this is the main wp_query we already have
94
-        // our cpt strategies take care of adding things in.
95
-        if ($WP_Query instanceof WP_Query && ! $WP_Query->is_main_query()) {
96
-            // build event list query
97
-            add_filter('posts_fields', array('EEH_Event_Query', 'posts_fields'), 10, 2);
98
-            add_filter('posts_join', array('EEH_Event_Query', 'posts_join'), 10, 2);
99
-            add_filter('posts_where', array('EEH_Event_Query', 'posts_where'), 10, 2);
100
-            add_filter('posts_orderby', array('EEH_Event_Query', 'posts_orderby'), 10, 2);
101
-            add_filter('posts_clauses_request', array('EEH_Event_Query', 'posts_clauses'), 10, 2);
102
-        }
103
-    }
104
-
105
-
106
-
107
-    /**
108
-     * @param string $month
109
-     * @param string $category
110
-     * @param bool   $show_expired
111
-     * @param string $orderby
112
-     * @param string $sort
113
-     * @throws InvalidArgumentException
114
-     * @throws InvalidDataTypeException
115
-     * @throws InvalidInterfaceException
116
-     */
117
-    public static function set_query_params(
118
-        $month = '',
119
-        $category = '',
120
-        $show_expired = false,
121
-        $orderby = 'start_date',
122
-        $sort = 'ASC'
123
-    ) {
124
-        self::$_query_params                        = array();
125
-        EEH_Event_Query::$_event_query_month        = EEH_Event_Query::_display_month($month);
126
-        EEH_Event_Query::$_event_query_category     = EEH_Event_Query::_event_category_slug($category);
127
-        EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired($show_expired);
128
-        EEH_Event_Query::$_event_query_orderby      = EEH_Event_Query::_orderby($orderby);
129
-        EEH_Event_Query::$_event_query_sort         = EEH_Event_Query::_sort($sort);
130
-    }
131
-
132
-
133
-
134
-    /**
135
-     * what month should the event list display events for?
136
-     *
137
-     * @param string $month
138
-     * @return string
139
-     * @throws InvalidArgumentException
140
-     * @throws InvalidDataTypeException
141
-     * @throws InvalidInterfaceException
142
-     */
143
-    private static function _display_month($month = '')
144
-    {
145
-        return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month));
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     * @param string $category
152
-     * @return string
153
-     * @throws InvalidArgumentException
154
-     * @throws InvalidDataTypeException
155
-     * @throws InvalidInterfaceException
156
-     */
157
-    private static function _event_category_slug($category = '')
158
-    {
159
-        return sanitize_title_with_dashes(EE_Registry::instance()->REQ->get('event_query_category', $category));
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * @param bool $show_expired
166
-     * @return bool
167
-     * @throws InvalidArgumentException
168
-     * @throws InvalidDataTypeException
169
-     * @throws InvalidInterfaceException
170
-     */
171
-    private static function _show_expired($show_expired = false)
172
-    {
173
-        // override default expired option if set via filter
174
-        return filter_var(
175
-            EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired),
176
-            FILTER_VALIDATE_BOOLEAN
177
-        );
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * @param    string $orderby
184
-     * @return array
185
-     * @throws InvalidArgumentException
186
-     * @throws InvalidDataTypeException
187
-     * @throws InvalidInterfaceException
188
-     */
189
-    private static function _orderby($orderby = 'start_date')
190
-    {
191
-        $event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby);
192
-        $event_query_orderby = is_array($event_query_orderby)
193
-            ? $event_query_orderby
194
-            : explode(',', $event_query_orderby);
195
-        $event_query_orderby = array_map('trim', $event_query_orderby);
196
-        $event_query_orderby = array_map('sanitize_text_field', $event_query_orderby);
197
-        return $event_query_orderby;
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * @param string $sort
204
-     * @return string
205
-     * @throws InvalidArgumentException
206
-     * @throws InvalidDataTypeException
207
-     * @throws InvalidInterfaceException
208
-     */
209
-    private static function _sort($sort = 'ASC')
210
-    {
211
-        $sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort);
212
-        return in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true)
213
-            ? strtoupper($sort)
214
-            : 'ASC';
215
-    }
216
-
217
-
218
-
219
-    /**
220
-     * Filters the clauses for the WP_Query object
221
-     *
222
-     * @param array    $clauses array of clauses
223
-     * @param WP_Query $wp_query
224
-     * @return array   array of clauses
225
-     */
226
-    public static function posts_clauses($clauses, WP_Query $wp_query)
227
-    {
228
-        if (EEH_Event_Query::apply_query_filters($wp_query)) {
229
-            global $wpdb;
230
-            $clauses['groupby'] = $wpdb->posts . '.ID ';
231
-        }
232
-        return $clauses;
233
-    }
234
-
235
-
236
-
237
-    /**
238
-     * @param string   $SQL
239
-     * @param WP_Query $wp_query
240
-     * @return string
241
-     * @throws EE_Error
242
-     * @throws InvalidArgumentException
243
-     * @throws InvalidDataTypeException
244
-     * @throws InvalidInterfaceException
245
-     */
246
-    public static function posts_fields($SQL, WP_Query $wp_query)
247
-    {
248
-        if (EEH_Event_Query::apply_query_filters($wp_query)) {
249
-            // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
250
-            $SQL .= EEH_Event_Query::posts_fields_sql_for_orderby(EEH_Event_Query::$_event_query_orderby);
251
-        }
252
-        return $SQL;
253
-    }
254
-
255
-
256
-
257
-    /**
258
-     * @param array $orderby_params
259
-     * @return string
260
-     * @throws EE_Error
261
-     * @throws InvalidArgumentException
262
-     * @throws InvalidDataTypeException
263
-     * @throws InvalidInterfaceException
264
-     */
265
-    public static function posts_fields_sql_for_orderby(array $orderby_params = array())
266
-    {
267
-        $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
268
-        foreach ($orderby_params as $orderby) {
269
-            switch ($orderby) {
270
-                case 'ticket_start':
271
-                    $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date';
272
-                    break;
273
-                case 'ticket_end':
274
-                    $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date';
275
-                    break;
276
-                case 'venue_title':
277
-                    $SQL .= ', Venue.post_title AS venue_title';
278
-                    break;
279
-                case 'city':
280
-                    $SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city';
281
-                    break;
282
-                case 'state':
283
-                    $SQL .= ', ' . EEM_State::instance()->table() . '.STA_name';
284
-                    break;
285
-            }
286
-        }
287
-        return $SQL;
288
-    }
289
-
290
-
291
-
292
-    /**
293
-     * @param string   $SQL
294
-     * @param WP_Query $wp_query
295
-     * @return string
296
-     * @throws EE_Error
297
-     * @throws InvalidArgumentException
298
-     * @throws InvalidDataTypeException
299
-     * @throws InvalidInterfaceException
300
-     */
301
-    public static function posts_join($SQL = '', WP_Query $wp_query)
302
-    {
303
-        if (EEH_Event_Query::apply_query_filters($wp_query)) {
304
-            // Category
305
-            $SQL = EEH_Event_Query::posts_join_sql_for_show_expired($SQL, EEH_Event_Query::$_event_query_show_expired);
306
-            $SQL = EEH_Event_Query::posts_join_sql_for_terms($SQL, EEH_Event_Query::$_event_query_category);
307
-            $SQL = EEH_Event_Query::posts_join_for_orderby($SQL, EEH_Event_Query::$_event_query_orderby);
308
-        }
309
-        return $SQL;
310
-    }
311
-
312
-
313
-
314
-    /**
315
-     * @param string  $SQL
316
-     * @param boolean $show_expired if TRUE, then displayed past events
317
-     * @return string
318
-     * @throws EE_Error
319
-     * @throws InvalidArgumentException
320
-     * @throws InvalidDataTypeException
321
-     * @throws InvalidInterfaceException
322
-     */
323
-    public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = false)
324
-    {
325
-        if (! $show_expired) {
326
-            $join = EEM_Event::instance()->table() . '.ID = ';
327
-            $join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
328
-            // don't add if this is already in the SQL
329
-            if (strpos($SQL, $join) === false) {
330
-                $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) ';
331
-            }
332
-        }
333
-        return $SQL;
334
-    }
335
-
336
-
337
-
338
-    /**
339
-     * @param string $SQL
340
-     * @param string $join_terms    pass TRUE or term string, doesn't really matter since this value doesn't really get
341
-     *                              used for anything yet
342
-     * @return string
343
-     */
344
-    public static function posts_join_sql_for_terms($SQL = '', $join_terms = '')
345
-    {
346
-        if (! empty($join_terms)) {
347
-            global $wpdb;
348
-            $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
349
-            $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
350
-            $SQL .= " LEFT JOIN $wpdb->terms ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) ";
351
-        }
352
-        return $SQL;
353
-    }
354
-
355
-
356
-
357
-    /**
358
-     * usage:  $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params );
359
-     *
360
-     * @param    string $SQL
361
-     * @param    array  $orderby_params
362
-     * @return string
363
-     * @throws EE_Error
364
-     * @throws InvalidArgumentException
365
-     * @throws InvalidDataTypeException
366
-     * @throws InvalidInterfaceException
367
-     */
368
-    public static function posts_join_for_orderby($SQL = '', array $orderby_params = array())
369
-    {
370
-        foreach ($orderby_params as $orderby) {
371
-            switch ($orderby) {
372
-                case 'ticket_start':
373
-                case 'ticket_end':
374
-                    $SQL .= EEH_Event_Query::_posts_join_for_datetime(
375
-                        $SQL,
376
-                        EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name()
377
-                    );
378
-                    $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table();
379
-                    $SQL .= ' ON (';
380
-                    $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
381
-                    $SQL .= ' = ';
382
-                    $SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
383
-                    $SQL .= ' )';
384
-                    break;
385
-                case 'venue_title':
386
-                case 'city':
387
-                    $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL);
388
-                    break;
389
-                case 'state':
390
-                    $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL);
391
-                    $SQL .= EEH_Event_Query::_posts_join_for_venue_state($SQL);
392
-                    break;
393
-                case 'start_date':
394
-                default:
395
-                    $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table() . '.ID');
396
-                    break;
397
-            }
398
-        }
399
-        return $SQL;
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     * @param string $SQL
406
-     * @param string $join
407
-     * @return string
408
-     * @throws EE_Error
409
-     * @throws InvalidArgumentException
410
-     * @throws InvalidDataTypeException
411
-     * @throws InvalidInterfaceException
412
-     */
413
-    protected static function _posts_join_for_datetime($SQL = '', $join = '')
414
-    {
415
-        if (! empty($join)) {
416
-            $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
417
-            if (strpos($SQL, $join) === false) {
418
-                return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )';
419
-            }
420
-        }
421
-        return '';
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * @param string $SQL
428
-     * @return string
429
-     * @throws EE_Error
430
-     * @throws InvalidArgumentException
431
-     * @throws InvalidDataTypeException
432
-     * @throws InvalidInterfaceException
433
-     */
434
-    protected static function _posts_join_for_event_venue($SQL = '')
435
-    {
436
-        // Event Venue table name
437
-        $event_venue_table = EEM_Event_Venue::instance()->table();
438
-        // generate conditions for:  Event <=> Event Venue  JOIN clause
439
-        $event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = ';
440
-        $event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name();
441
-        // don't add joins if they have already been added
442
-        if (strpos($SQL, $event_to_event_venue_join) === false) {
443
-            // Venue table name
444
-            $venue_table = EEM_Venue::instance()->table();
445
-            // Venue table pk
446
-            $venue_table_pk = EEM_Venue::instance()->primary_key_name();
447
-            // Venue Meta table name
448
-            $venue_meta_table = EEM_Venue::instance()->second_table();
449
-            // generate JOIN clause for: Event <=> Event Venue
450
-            $venue_SQL = " LEFT JOIN $event_venue_table ON ( $event_to_event_venue_join )";
451
-            // generate JOIN clause for: Event Venue <=> Venue
452
-            $venue_SQL .= " LEFT JOIN $venue_table as Venue ON ( $event_venue_table.$venue_table_pk = Venue.ID )";
453
-            // generate JOIN clause for: Venue <=> Venue Meta
454
-            $venue_SQL .= " LEFT JOIN $venue_meta_table ON ( Venue.ID = $venue_meta_table.$venue_table_pk )";
455
-            unset($event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table);
456
-            return $venue_SQL;
457
-        }
458
-        unset($event_venue_table, $event_to_event_venue_join);
459
-        return '';
460
-    }
461
-
462
-
463
-
464
-    /**
465
-     * @param string $SQL
466
-     * @return string
467
-     * @throws EE_Error
468
-     * @throws InvalidArgumentException
469
-     * @throws InvalidDataTypeException
470
-     * @throws InvalidInterfaceException
471
-     */
472
-    protected static function _posts_join_for_venue_state($SQL = '')
473
-    {
474
-        // Venue Meta table name
475
-        $venue_meta_table = EEM_Venue::instance()->second_table();
476
-        // State table name
477
-        $state_table = EEM_State::instance()->table();
478
-        // State table pk
479
-        $state_table_pk = EEM_State::instance()->primary_key_name();
480
-        // verify vars
481
-        if ($venue_meta_table && $state_table && $state_table_pk) {
482
-            // like: wp_esp_venue_meta.STA_ID = wp_esp_state.STA_ID
483
-            $join = "$venue_meta_table.$state_table_pk = $state_table.$state_table_pk";
484
-            // don't add join if it has already been added
485
-            if (strpos($SQL, $join) === false) {
486
-                unset($state_table_pk, $venue_meta_table, $venue_table_pk);
487
-                return " LEFT JOIN $state_table ON ( $join )";
488
-            }
489
-        }
490
-        unset($join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk);
491
-        return '';
492
-    }
493
-
494
-
495
-
496
-    /**
497
-     * @param string   $SQL
498
-     * @param WP_Query $wp_query
499
-     * @return string
500
-     * @throws EE_Error
501
-     * @throws InvalidArgumentException
502
-     * @throws InvalidDataTypeException
503
-     * @throws InvalidInterfaceException
504
-     */
505
-    public static function posts_where($SQL = '', WP_Query $wp_query)
506
-    {
507
-        if (EEH_Event_Query::apply_query_filters($wp_query)) {
508
-            // Show Expired ?
509
-            $SQL .= EEH_Event_Query::posts_where_sql_for_show_expired(EEH_Event_Query::$_event_query_show_expired);
510
-            // Category
511
-            $SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug(EEH_Event_Query::$_event_query_category);
512
-            // Start Date
513
-            $SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month(EEH_Event_Query::$_event_query_month);
514
-        }
515
-        return $SQL;
516
-    }
517
-
518
-
519
-
520
-    /**
521
-     * @param    boolean $show_expired if TRUE, then displayed past events
522
-     * @return string
523
-     * @throws EE_Error
524
-     * @throws InvalidArgumentException
525
-     * @throws InvalidDataTypeException
526
-     * @throws InvalidInterfaceException
527
-     */
528
-    public static function posts_where_sql_for_show_expired($show_expired = false)
529
-    {
530
-        return ! $show_expired
531
-            ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time('mysql', true) . '\' '
532
-            : '';
533
-    }
534
-
535
-
536
-
537
-    /**
538
-     * @param boolean $event_category_slug
539
-     * @return string
540
-     */
541
-    public static function posts_where_sql_for_event_category_slug($event_category_slug = null)
542
-    {
543
-        global $wpdb;
544
-        return ! empty($event_category_slug)
545
-            ? $wpdb->prepare(" AND {$wpdb->terms}.slug = %s ", $event_category_slug)
546
-            : '';
547
-    }
548
-
549
-
550
-
551
-    /**
552
-     * @param boolean $month
553
-     * @return string
554
-     * @throws EE_Error
555
-     * @throws InvalidArgumentException
556
-     * @throws InvalidDataTypeException
557
-     * @throws InvalidInterfaceException
558
-     */
559
-    public static function posts_where_sql_for_event_list_month($month = null)
560
-    {
561
-        $SQL = '';
562
-        if (! empty($month)) {
563
-            $datetime_table = EEM_Datetime::instance()->table();
564
-            // event start date is LESS than the end of the month ( so nothing that doesn't start until next month )
565
-            $SQL = " AND {$datetime_table}.DTT_EVT_start <= '";
566
-            $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'";
567
-            // event end date is GREATER than the start of the month ( so nothing that ended before this month )
568
-            $SQL .= " AND {$datetime_table}.DTT_EVT_end >= '";
569
-            $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' ";
570
-        }
571
-        return $SQL;
572
-    }
573
-
574
-
575
-
576
-    /**
577
-     * @param string $SQL
578
-     * @param WP_Query $wp_query
579
-     * @return string
580
-     * @throws EE_Error
581
-     * @throws InvalidArgumentException
582
-     * @throws InvalidDataTypeException
583
-     * @throws InvalidInterfaceException
584
-     */
585
-    public static function posts_orderby($SQL = '', WP_Query $wp_query)
586
-    {
587
-        if (EEH_Event_Query::apply_query_filters($wp_query)) {
588
-            $SQL = EEH_Event_Query::posts_orderby_sql(
589
-                EEH_Event_Query::$_event_query_orderby,
590
-                EEH_Event_Query::$_event_query_sort
591
-            );
592
-        }
593
-        return $SQL;
594
-    }
595
-
596
-
597
-
598
-    /**
599
-     *    posts_orderby_sql
600
-     *    possible parameters:
601
-     *    ID
602
-     *    start_date
603
-     *    end_date
604
-     *    event_name
605
-     *    category_slug
606
-     *    ticket_start
607
-     *    ticket_end
608
-     *    venue_title
609
-     *    city
610
-     *    state
611
-     *    **IMPORTANT**
612
-     *    make sure to also send the $orderby_params array to the posts_join_for_orderby() method
613
-     *    or else some of the table references below will result in MySQL errors
614
-     *
615
-     * @param array  $orderby_params
616
-     * @param string $sort
617
-     * @return string
618
-     * @throws EE_Error
619
-     * @throws InvalidArgumentException
620
-     * @throws InvalidDataTypeException
621
-     * @throws InvalidInterfaceException
622
-     */
623
-    public static function posts_orderby_sql(array $orderby_params = array(), $sort = 'ASC')
624
-    {
625
-        global $wpdb;
626
-        $SQL     = '';
627
-        $counter = 0;
628
-        $sort    = in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true)
629
-            ? strtoupper($sort)
630
-            : 'ASC';
631
-        // make sure 'orderby' is set in query params
632
-        if (! isset(self::$_query_params['orderby'])) {
633
-            self::$_query_params['orderby'] = array();
634
-        }
635
-        // loop thru $orderby_params (type cast as array)
636
-        foreach ($orderby_params as $orderby) {
637
-            // check if we have already added this param
638
-            if (isset(self::$_query_params['orderby'][ $orderby ])) {
639
-                // if so then remove from the $orderby_params so that the count() method below is accurate
640
-                unset($orderby_params[ $orderby ]);
641
-                // then bump ahead to the next param
642
-                continue;
643
-            }
644
-            // this will ad a comma depending on whether this is the first or last param
645
-            $glue = $counter === 0 || $counter === count($orderby_params) ? ' ' : ', ';
646
-            // ok what's we dealing with?
647
-            switch ($orderby) {
648
-                case 'id':
649
-                case 'ID':
650
-                    $SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
651
-                    break;
652
-                case 'end_date':
653
-                    $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
654
-                    break;
655
-                case 'event_name':
656
-                    $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
657
-                    break;
658
-                case 'category_slug':
659
-                    $SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
660
-                    break;
661
-                case 'ticket_start':
662
-                    $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
663
-                    break;
664
-                case 'ticket_end':
665
-                    $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
666
-                    break;
667
-                case 'venue_title':
668
-                    $SQL .= $glue . 'venue_title ' . $sort;
669
-                    break;
670
-                case 'city':
671
-                    $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
672
-                    break;
673
-                case 'state':
674
-                    $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
675
-                    break;
676
-                case 'start_date':
677
-                default:
678
-                    $SQL .= $glue . ' event_start_date ' . $sort;
679
-                    break;
680
-            }
681
-            // add to array of orderby params that have been added
682
-            self::$_query_params['orderby'][ $orderby ] = true;
683
-            $counter++;
684
-        }
685
-        return $SQL;
686
-    }
18
+	/**
19
+	 * Start Date
20
+	 *
21
+	 * @var $_event_query_month
22
+	 */
23
+	protected static $_event_query_month;
24
+
25
+	/**
26
+	 * Category
27
+	 *
28
+	 * @var $_event_query_category
29
+	 */
30
+	protected static $_event_query_category;
31
+
32
+	/**
33
+	 * whether to display expired events in the event list
34
+	 *
35
+	 * @var bool $_show_expired
36
+	 */
37
+	protected static $_event_query_show_expired = false;
38
+
39
+	/**
40
+	 * list of params for controlling how the query results are ordered
41
+	 *
42
+	 * @var array $_event_query_orderby
43
+	 */
44
+	protected static $_event_query_orderby = array();
45
+
46
+	/**
47
+	 * direction list is sorted
48
+	 *
49
+	 * @var string $_event_query_sort
50
+	 */
51
+	protected static $_event_query_sort;
52
+
53
+	/**
54
+	 * list of params used to build the query's various clauses
55
+	 *
56
+	 * @var $_query_params
57
+	 */
58
+	protected static $_query_params = array();
59
+
60
+
61
+
62
+	/**
63
+	 * @return void
64
+	 */
65
+	public static function add_query_filters()
66
+	{
67
+		// add query filters
68
+		add_action('pre_get_posts', array('EEH_Event_Query', 'filter_query_parts'), 10, 1);
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * @param WP_Query $WP_Query
75
+	 * @return bool
76
+	 */
77
+	public static function apply_query_filters(WP_Query $WP_Query)
78
+	{
79
+		return (
80
+				   isset($WP_Query->query['post_type'])
81
+				   && $WP_Query->query['post_type'] === 'espresso_events'
82
+			   )
83
+			   || apply_filters('FHEE__EEH_Event_Query__apply_query_filters', false);
84
+	}
85
+
86
+
87
+	/**
88
+	 * @param WP_Query $WP_Query
89
+	 */
90
+	public static function filter_query_parts(WP_Query $WP_Query)
91
+	{
92
+		// ONLY add our filters if this isn't the main wp_query,
93
+		// because if this is the main wp_query we already have
94
+		// our cpt strategies take care of adding things in.
95
+		if ($WP_Query instanceof WP_Query && ! $WP_Query->is_main_query()) {
96
+			// build event list query
97
+			add_filter('posts_fields', array('EEH_Event_Query', 'posts_fields'), 10, 2);
98
+			add_filter('posts_join', array('EEH_Event_Query', 'posts_join'), 10, 2);
99
+			add_filter('posts_where', array('EEH_Event_Query', 'posts_where'), 10, 2);
100
+			add_filter('posts_orderby', array('EEH_Event_Query', 'posts_orderby'), 10, 2);
101
+			add_filter('posts_clauses_request', array('EEH_Event_Query', 'posts_clauses'), 10, 2);
102
+		}
103
+	}
104
+
105
+
106
+
107
+	/**
108
+	 * @param string $month
109
+	 * @param string $category
110
+	 * @param bool   $show_expired
111
+	 * @param string $orderby
112
+	 * @param string $sort
113
+	 * @throws InvalidArgumentException
114
+	 * @throws InvalidDataTypeException
115
+	 * @throws InvalidInterfaceException
116
+	 */
117
+	public static function set_query_params(
118
+		$month = '',
119
+		$category = '',
120
+		$show_expired = false,
121
+		$orderby = 'start_date',
122
+		$sort = 'ASC'
123
+	) {
124
+		self::$_query_params                        = array();
125
+		EEH_Event_Query::$_event_query_month        = EEH_Event_Query::_display_month($month);
126
+		EEH_Event_Query::$_event_query_category     = EEH_Event_Query::_event_category_slug($category);
127
+		EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired($show_expired);
128
+		EEH_Event_Query::$_event_query_orderby      = EEH_Event_Query::_orderby($orderby);
129
+		EEH_Event_Query::$_event_query_sort         = EEH_Event_Query::_sort($sort);
130
+	}
131
+
132
+
133
+
134
+	/**
135
+	 * what month should the event list display events for?
136
+	 *
137
+	 * @param string $month
138
+	 * @return string
139
+	 * @throws InvalidArgumentException
140
+	 * @throws InvalidDataTypeException
141
+	 * @throws InvalidInterfaceException
142
+	 */
143
+	private static function _display_month($month = '')
144
+	{
145
+		return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month));
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 * @param string $category
152
+	 * @return string
153
+	 * @throws InvalidArgumentException
154
+	 * @throws InvalidDataTypeException
155
+	 * @throws InvalidInterfaceException
156
+	 */
157
+	private static function _event_category_slug($category = '')
158
+	{
159
+		return sanitize_title_with_dashes(EE_Registry::instance()->REQ->get('event_query_category', $category));
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * @param bool $show_expired
166
+	 * @return bool
167
+	 * @throws InvalidArgumentException
168
+	 * @throws InvalidDataTypeException
169
+	 * @throws InvalidInterfaceException
170
+	 */
171
+	private static function _show_expired($show_expired = false)
172
+	{
173
+		// override default expired option if set via filter
174
+		return filter_var(
175
+			EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired),
176
+			FILTER_VALIDATE_BOOLEAN
177
+		);
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * @param    string $orderby
184
+	 * @return array
185
+	 * @throws InvalidArgumentException
186
+	 * @throws InvalidDataTypeException
187
+	 * @throws InvalidInterfaceException
188
+	 */
189
+	private static function _orderby($orderby = 'start_date')
190
+	{
191
+		$event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby);
192
+		$event_query_orderby = is_array($event_query_orderby)
193
+			? $event_query_orderby
194
+			: explode(',', $event_query_orderby);
195
+		$event_query_orderby = array_map('trim', $event_query_orderby);
196
+		$event_query_orderby = array_map('sanitize_text_field', $event_query_orderby);
197
+		return $event_query_orderby;
198
+	}
199
+
200
+
201
+
202
+	/**
203
+	 * @param string $sort
204
+	 * @return string
205
+	 * @throws InvalidArgumentException
206
+	 * @throws InvalidDataTypeException
207
+	 * @throws InvalidInterfaceException
208
+	 */
209
+	private static function _sort($sort = 'ASC')
210
+	{
211
+		$sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort);
212
+		return in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true)
213
+			? strtoupper($sort)
214
+			: 'ASC';
215
+	}
216
+
217
+
218
+
219
+	/**
220
+	 * Filters the clauses for the WP_Query object
221
+	 *
222
+	 * @param array    $clauses array of clauses
223
+	 * @param WP_Query $wp_query
224
+	 * @return array   array of clauses
225
+	 */
226
+	public static function posts_clauses($clauses, WP_Query $wp_query)
227
+	{
228
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
229
+			global $wpdb;
230
+			$clauses['groupby'] = $wpdb->posts . '.ID ';
231
+		}
232
+		return $clauses;
233
+	}
234
+
235
+
236
+
237
+	/**
238
+	 * @param string   $SQL
239
+	 * @param WP_Query $wp_query
240
+	 * @return string
241
+	 * @throws EE_Error
242
+	 * @throws InvalidArgumentException
243
+	 * @throws InvalidDataTypeException
244
+	 * @throws InvalidInterfaceException
245
+	 */
246
+	public static function posts_fields($SQL, WP_Query $wp_query)
247
+	{
248
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
249
+			// adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
250
+			$SQL .= EEH_Event_Query::posts_fields_sql_for_orderby(EEH_Event_Query::$_event_query_orderby);
251
+		}
252
+		return $SQL;
253
+	}
254
+
255
+
256
+
257
+	/**
258
+	 * @param array $orderby_params
259
+	 * @return string
260
+	 * @throws EE_Error
261
+	 * @throws InvalidArgumentException
262
+	 * @throws InvalidDataTypeException
263
+	 * @throws InvalidInterfaceException
264
+	 */
265
+	public static function posts_fields_sql_for_orderby(array $orderby_params = array())
266
+	{
267
+		$SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
268
+		foreach ($orderby_params as $orderby) {
269
+			switch ($orderby) {
270
+				case 'ticket_start':
271
+					$SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date';
272
+					break;
273
+				case 'ticket_end':
274
+					$SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date';
275
+					break;
276
+				case 'venue_title':
277
+					$SQL .= ', Venue.post_title AS venue_title';
278
+					break;
279
+				case 'city':
280
+					$SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city';
281
+					break;
282
+				case 'state':
283
+					$SQL .= ', ' . EEM_State::instance()->table() . '.STA_name';
284
+					break;
285
+			}
286
+		}
287
+		return $SQL;
288
+	}
289
+
290
+
291
+
292
+	/**
293
+	 * @param string   $SQL
294
+	 * @param WP_Query $wp_query
295
+	 * @return string
296
+	 * @throws EE_Error
297
+	 * @throws InvalidArgumentException
298
+	 * @throws InvalidDataTypeException
299
+	 * @throws InvalidInterfaceException
300
+	 */
301
+	public static function posts_join($SQL = '', WP_Query $wp_query)
302
+	{
303
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
304
+			// Category
305
+			$SQL = EEH_Event_Query::posts_join_sql_for_show_expired($SQL, EEH_Event_Query::$_event_query_show_expired);
306
+			$SQL = EEH_Event_Query::posts_join_sql_for_terms($SQL, EEH_Event_Query::$_event_query_category);
307
+			$SQL = EEH_Event_Query::posts_join_for_orderby($SQL, EEH_Event_Query::$_event_query_orderby);
308
+		}
309
+		return $SQL;
310
+	}
311
+
312
+
313
+
314
+	/**
315
+	 * @param string  $SQL
316
+	 * @param boolean $show_expired if TRUE, then displayed past events
317
+	 * @return string
318
+	 * @throws EE_Error
319
+	 * @throws InvalidArgumentException
320
+	 * @throws InvalidDataTypeException
321
+	 * @throws InvalidInterfaceException
322
+	 */
323
+	public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = false)
324
+	{
325
+		if (! $show_expired) {
326
+			$join = EEM_Event::instance()->table() . '.ID = ';
327
+			$join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
328
+			// don't add if this is already in the SQL
329
+			if (strpos($SQL, $join) === false) {
330
+				$SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) ';
331
+			}
332
+		}
333
+		return $SQL;
334
+	}
335
+
336
+
337
+
338
+	/**
339
+	 * @param string $SQL
340
+	 * @param string $join_terms    pass TRUE or term string, doesn't really matter since this value doesn't really get
341
+	 *                              used for anything yet
342
+	 * @return string
343
+	 */
344
+	public static function posts_join_sql_for_terms($SQL = '', $join_terms = '')
345
+	{
346
+		if (! empty($join_terms)) {
347
+			global $wpdb;
348
+			$SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
349
+			$SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
350
+			$SQL .= " LEFT JOIN $wpdb->terms ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) ";
351
+		}
352
+		return $SQL;
353
+	}
354
+
355
+
356
+
357
+	/**
358
+	 * usage:  $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params );
359
+	 *
360
+	 * @param    string $SQL
361
+	 * @param    array  $orderby_params
362
+	 * @return string
363
+	 * @throws EE_Error
364
+	 * @throws InvalidArgumentException
365
+	 * @throws InvalidDataTypeException
366
+	 * @throws InvalidInterfaceException
367
+	 */
368
+	public static function posts_join_for_orderby($SQL = '', array $orderby_params = array())
369
+	{
370
+		foreach ($orderby_params as $orderby) {
371
+			switch ($orderby) {
372
+				case 'ticket_start':
373
+				case 'ticket_end':
374
+					$SQL .= EEH_Event_Query::_posts_join_for_datetime(
375
+						$SQL,
376
+						EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name()
377
+					);
378
+					$SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table();
379
+					$SQL .= ' ON (';
380
+					$SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
381
+					$SQL .= ' = ';
382
+					$SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
383
+					$SQL .= ' )';
384
+					break;
385
+				case 'venue_title':
386
+				case 'city':
387
+					$SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL);
388
+					break;
389
+				case 'state':
390
+					$SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL);
391
+					$SQL .= EEH_Event_Query::_posts_join_for_venue_state($SQL);
392
+					break;
393
+				case 'start_date':
394
+				default:
395
+					$SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table() . '.ID');
396
+					break;
397
+			}
398
+		}
399
+		return $SQL;
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 * @param string $SQL
406
+	 * @param string $join
407
+	 * @return string
408
+	 * @throws EE_Error
409
+	 * @throws InvalidArgumentException
410
+	 * @throws InvalidDataTypeException
411
+	 * @throws InvalidInterfaceException
412
+	 */
413
+	protected static function _posts_join_for_datetime($SQL = '', $join = '')
414
+	{
415
+		if (! empty($join)) {
416
+			$join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
417
+			if (strpos($SQL, $join) === false) {
418
+				return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )';
419
+			}
420
+		}
421
+		return '';
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * @param string $SQL
428
+	 * @return string
429
+	 * @throws EE_Error
430
+	 * @throws InvalidArgumentException
431
+	 * @throws InvalidDataTypeException
432
+	 * @throws InvalidInterfaceException
433
+	 */
434
+	protected static function _posts_join_for_event_venue($SQL = '')
435
+	{
436
+		// Event Venue table name
437
+		$event_venue_table = EEM_Event_Venue::instance()->table();
438
+		// generate conditions for:  Event <=> Event Venue  JOIN clause
439
+		$event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = ';
440
+		$event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name();
441
+		// don't add joins if they have already been added
442
+		if (strpos($SQL, $event_to_event_venue_join) === false) {
443
+			// Venue table name
444
+			$venue_table = EEM_Venue::instance()->table();
445
+			// Venue table pk
446
+			$venue_table_pk = EEM_Venue::instance()->primary_key_name();
447
+			// Venue Meta table name
448
+			$venue_meta_table = EEM_Venue::instance()->second_table();
449
+			// generate JOIN clause for: Event <=> Event Venue
450
+			$venue_SQL = " LEFT JOIN $event_venue_table ON ( $event_to_event_venue_join )";
451
+			// generate JOIN clause for: Event Venue <=> Venue
452
+			$venue_SQL .= " LEFT JOIN $venue_table as Venue ON ( $event_venue_table.$venue_table_pk = Venue.ID )";
453
+			// generate JOIN clause for: Venue <=> Venue Meta
454
+			$venue_SQL .= " LEFT JOIN $venue_meta_table ON ( Venue.ID = $venue_meta_table.$venue_table_pk )";
455
+			unset($event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table);
456
+			return $venue_SQL;
457
+		}
458
+		unset($event_venue_table, $event_to_event_venue_join);
459
+		return '';
460
+	}
461
+
462
+
463
+
464
+	/**
465
+	 * @param string $SQL
466
+	 * @return string
467
+	 * @throws EE_Error
468
+	 * @throws InvalidArgumentException
469
+	 * @throws InvalidDataTypeException
470
+	 * @throws InvalidInterfaceException
471
+	 */
472
+	protected static function _posts_join_for_venue_state($SQL = '')
473
+	{
474
+		// Venue Meta table name
475
+		$venue_meta_table = EEM_Venue::instance()->second_table();
476
+		// State table name
477
+		$state_table = EEM_State::instance()->table();
478
+		// State table pk
479
+		$state_table_pk = EEM_State::instance()->primary_key_name();
480
+		// verify vars
481
+		if ($venue_meta_table && $state_table && $state_table_pk) {
482
+			// like: wp_esp_venue_meta.STA_ID = wp_esp_state.STA_ID
483
+			$join = "$venue_meta_table.$state_table_pk = $state_table.$state_table_pk";
484
+			// don't add join if it has already been added
485
+			if (strpos($SQL, $join) === false) {
486
+				unset($state_table_pk, $venue_meta_table, $venue_table_pk);
487
+				return " LEFT JOIN $state_table ON ( $join )";
488
+			}
489
+		}
490
+		unset($join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk);
491
+		return '';
492
+	}
493
+
494
+
495
+
496
+	/**
497
+	 * @param string   $SQL
498
+	 * @param WP_Query $wp_query
499
+	 * @return string
500
+	 * @throws EE_Error
501
+	 * @throws InvalidArgumentException
502
+	 * @throws InvalidDataTypeException
503
+	 * @throws InvalidInterfaceException
504
+	 */
505
+	public static function posts_where($SQL = '', WP_Query $wp_query)
506
+	{
507
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
508
+			// Show Expired ?
509
+			$SQL .= EEH_Event_Query::posts_where_sql_for_show_expired(EEH_Event_Query::$_event_query_show_expired);
510
+			// Category
511
+			$SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug(EEH_Event_Query::$_event_query_category);
512
+			// Start Date
513
+			$SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month(EEH_Event_Query::$_event_query_month);
514
+		}
515
+		return $SQL;
516
+	}
517
+
518
+
519
+
520
+	/**
521
+	 * @param    boolean $show_expired if TRUE, then displayed past events
522
+	 * @return string
523
+	 * @throws EE_Error
524
+	 * @throws InvalidArgumentException
525
+	 * @throws InvalidDataTypeException
526
+	 * @throws InvalidInterfaceException
527
+	 */
528
+	public static function posts_where_sql_for_show_expired($show_expired = false)
529
+	{
530
+		return ! $show_expired
531
+			? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time('mysql', true) . '\' '
532
+			: '';
533
+	}
534
+
535
+
536
+
537
+	/**
538
+	 * @param boolean $event_category_slug
539
+	 * @return string
540
+	 */
541
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = null)
542
+	{
543
+		global $wpdb;
544
+		return ! empty($event_category_slug)
545
+			? $wpdb->prepare(" AND {$wpdb->terms}.slug = %s ", $event_category_slug)
546
+			: '';
547
+	}
548
+
549
+
550
+
551
+	/**
552
+	 * @param boolean $month
553
+	 * @return string
554
+	 * @throws EE_Error
555
+	 * @throws InvalidArgumentException
556
+	 * @throws InvalidDataTypeException
557
+	 * @throws InvalidInterfaceException
558
+	 */
559
+	public static function posts_where_sql_for_event_list_month($month = null)
560
+	{
561
+		$SQL = '';
562
+		if (! empty($month)) {
563
+			$datetime_table = EEM_Datetime::instance()->table();
564
+			// event start date is LESS than the end of the month ( so nothing that doesn't start until next month )
565
+			$SQL = " AND {$datetime_table}.DTT_EVT_start <= '";
566
+			$SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'";
567
+			// event end date is GREATER than the start of the month ( so nothing that ended before this month )
568
+			$SQL .= " AND {$datetime_table}.DTT_EVT_end >= '";
569
+			$SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' ";
570
+		}
571
+		return $SQL;
572
+	}
573
+
574
+
575
+
576
+	/**
577
+	 * @param string $SQL
578
+	 * @param WP_Query $wp_query
579
+	 * @return string
580
+	 * @throws EE_Error
581
+	 * @throws InvalidArgumentException
582
+	 * @throws InvalidDataTypeException
583
+	 * @throws InvalidInterfaceException
584
+	 */
585
+	public static function posts_orderby($SQL = '', WP_Query $wp_query)
586
+	{
587
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
588
+			$SQL = EEH_Event_Query::posts_orderby_sql(
589
+				EEH_Event_Query::$_event_query_orderby,
590
+				EEH_Event_Query::$_event_query_sort
591
+			);
592
+		}
593
+		return $SQL;
594
+	}
595
+
596
+
597
+
598
+	/**
599
+	 *    posts_orderby_sql
600
+	 *    possible parameters:
601
+	 *    ID
602
+	 *    start_date
603
+	 *    end_date
604
+	 *    event_name
605
+	 *    category_slug
606
+	 *    ticket_start
607
+	 *    ticket_end
608
+	 *    venue_title
609
+	 *    city
610
+	 *    state
611
+	 *    **IMPORTANT**
612
+	 *    make sure to also send the $orderby_params array to the posts_join_for_orderby() method
613
+	 *    or else some of the table references below will result in MySQL errors
614
+	 *
615
+	 * @param array  $orderby_params
616
+	 * @param string $sort
617
+	 * @return string
618
+	 * @throws EE_Error
619
+	 * @throws InvalidArgumentException
620
+	 * @throws InvalidDataTypeException
621
+	 * @throws InvalidInterfaceException
622
+	 */
623
+	public static function posts_orderby_sql(array $orderby_params = array(), $sort = 'ASC')
624
+	{
625
+		global $wpdb;
626
+		$SQL     = '';
627
+		$counter = 0;
628
+		$sort    = in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true)
629
+			? strtoupper($sort)
630
+			: 'ASC';
631
+		// make sure 'orderby' is set in query params
632
+		if (! isset(self::$_query_params['orderby'])) {
633
+			self::$_query_params['orderby'] = array();
634
+		}
635
+		// loop thru $orderby_params (type cast as array)
636
+		foreach ($orderby_params as $orderby) {
637
+			// check if we have already added this param
638
+			if (isset(self::$_query_params['orderby'][ $orderby ])) {
639
+				// if so then remove from the $orderby_params so that the count() method below is accurate
640
+				unset($orderby_params[ $orderby ]);
641
+				// then bump ahead to the next param
642
+				continue;
643
+			}
644
+			// this will ad a comma depending on whether this is the first or last param
645
+			$glue = $counter === 0 || $counter === count($orderby_params) ? ' ' : ', ';
646
+			// ok what's we dealing with?
647
+			switch ($orderby) {
648
+				case 'id':
649
+				case 'ID':
650
+					$SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
651
+					break;
652
+				case 'end_date':
653
+					$SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
654
+					break;
655
+				case 'event_name':
656
+					$SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
657
+					break;
658
+				case 'category_slug':
659
+					$SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
660
+					break;
661
+				case 'ticket_start':
662
+					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
663
+					break;
664
+				case 'ticket_end':
665
+					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
666
+					break;
667
+				case 'venue_title':
668
+					$SQL .= $glue . 'venue_title ' . $sort;
669
+					break;
670
+				case 'city':
671
+					$SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
672
+					break;
673
+				case 'state':
674
+					$SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
675
+					break;
676
+				case 'start_date':
677
+				default:
678
+					$SQL .= $glue . ' event_start_date ' . $sort;
679
+					break;
680
+			}
681
+			// add to array of orderby params that have been added
682
+			self::$_query_params['orderby'][ $orderby ] = true;
683
+			$counter++;
684
+		}
685
+		return $SQL;
686
+	}
687 687
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
     {
228 228
         if (EEH_Event_Query::apply_query_filters($wp_query)) {
229 229
             global $wpdb;
230
-            $clauses['groupby'] = $wpdb->posts . '.ID ';
230
+            $clauses['groupby'] = $wpdb->posts.'.ID ';
231 231
         }
232 232
         return $clauses;
233 233
     }
@@ -264,23 +264,23 @@  discard block
 block discarded – undo
264 264
      */
265 265
     public static function posts_fields_sql_for_orderby(array $orderby_params = array())
266 266
     {
267
-        $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
267
+        $SQL = ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date ';
268 268
         foreach ($orderby_params as $orderby) {
269 269
             switch ($orderby) {
270 270
                 case 'ticket_start':
271
-                    $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date';
271
+                    $SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_start_date';
272 272
                     break;
273 273
                 case 'ticket_end':
274
-                    $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date';
274
+                    $SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_end_date';
275 275
                     break;
276 276
                 case 'venue_title':
277 277
                     $SQL .= ', Venue.post_title AS venue_title';
278 278
                     break;
279 279
                 case 'city':
280
-                    $SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city';
280
+                    $SQL .= ', '.EEM_Venue::instance()->second_table().'.VNU_city';
281 281
                     break;
282 282
                 case 'state':
283
-                    $SQL .= ', ' . EEM_State::instance()->table() . '.STA_name';
283
+                    $SQL .= ', '.EEM_State::instance()->table().'.STA_name';
284 284
                     break;
285 285
             }
286 286
         }
@@ -322,12 +322,12 @@  discard block
 block discarded – undo
322 322
      */
323 323
     public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = false)
324 324
     {
325
-        if (! $show_expired) {
326
-            $join = EEM_Event::instance()->table() . '.ID = ';
327
-            $join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
325
+        if ( ! $show_expired) {
326
+            $join = EEM_Event::instance()->table().'.ID = ';
327
+            $join .= EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name();
328 328
             // don't add if this is already in the SQL
329 329
             if (strpos($SQL, $join) === false) {
330
-                $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) ';
330
+                $SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' ) ';
331 331
             }
332 332
         }
333 333
         return $SQL;
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
      */
344 344
     public static function posts_join_sql_for_terms($SQL = '', $join_terms = '')
345 345
     {
346
-        if (! empty($join_terms)) {
346
+        if ( ! empty($join_terms)) {
347 347
             global $wpdb;
348 348
             $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
349 349
             $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
@@ -373,13 +373,13 @@  discard block
 block discarded – undo
373 373
                 case 'ticket_end':
374 374
                     $SQL .= EEH_Event_Query::_posts_join_for_datetime(
375 375
                         $SQL,
376
-                        EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name()
376
+                        EEM_Datetime_Ticket::instance()->table().'.'.EEM_Datetime::instance()->primary_key_name()
377 377
                     );
378
-                    $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table();
378
+                    $SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table();
379 379
                     $SQL .= ' ON (';
380
-                    $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
380
+                    $SQL .= EEM_Datetime_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name();
381 381
                     $SQL .= ' = ';
382
-                    $SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
382
+                    $SQL .= EEM_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name();
383 383
                     $SQL .= ' )';
384 384
                     break;
385 385
                 case 'venue_title':
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
                     break;
393 393
                 case 'start_date':
394 394
                 default:
395
-                    $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table() . '.ID');
395
+                    $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table().'.ID');
396 396
                     break;
397 397
             }
398 398
         }
@@ -412,10 +412,10 @@  discard block
 block discarded – undo
412 412
      */
413 413
     protected static function _posts_join_for_datetime($SQL = '', $join = '')
414 414
     {
415
-        if (! empty($join)) {
416
-            $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
415
+        if ( ! empty($join)) {
416
+            $join .= ' = '.EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name();
417 417
             if (strpos($SQL, $join) === false) {
418
-                return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )';
418
+                return ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' )';
419 419
             }
420 420
         }
421 421
         return '';
@@ -436,8 +436,8 @@  discard block
 block discarded – undo
436 436
         // Event Venue table name
437 437
         $event_venue_table = EEM_Event_Venue::instance()->table();
438 438
         // generate conditions for:  Event <=> Event Venue  JOIN clause
439
-        $event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = ';
440
-        $event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name();
439
+        $event_to_event_venue_join = EEM_Event::instance()->table().'.ID = ';
440
+        $event_to_event_venue_join .= $event_venue_table.'.'.EEM_Event::instance()->primary_key_name();
441 441
         // don't add joins if they have already been added
442 442
         if (strpos($SQL, $event_to_event_venue_join) === false) {
443 443
             // Venue table name
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
     public static function posts_where_sql_for_show_expired($show_expired = false)
529 529
     {
530 530
         return ! $show_expired
531
-            ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time('mysql', true) . '\' '
531
+            ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > \''.current_time('mysql', true).'\' '
532 532
             : '';
533 533
     }
534 534
 
@@ -559,14 +559,14 @@  discard block
 block discarded – undo
559 559
     public static function posts_where_sql_for_event_list_month($month = null)
560 560
     {
561 561
         $SQL = '';
562
-        if (! empty($month)) {
562
+        if ( ! empty($month)) {
563 563
             $datetime_table = EEM_Datetime::instance()->table();
564 564
             // event start date is LESS than the end of the month ( so nothing that doesn't start until next month )
565 565
             $SQL = " AND {$datetime_table}.DTT_EVT_start <= '";
566
-            $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'";
566
+            $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month))."'";
567 567
             // event end date is GREATER than the start of the month ( so nothing that ended before this month )
568 568
             $SQL .= " AND {$datetime_table}.DTT_EVT_end >= '";
569
-            $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' ";
569
+            $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month))."' ";
570 570
         }
571 571
         return $SQL;
572 572
     }
@@ -629,15 +629,15 @@  discard block
 block discarded – undo
629 629
             ? strtoupper($sort)
630 630
             : 'ASC';
631 631
         // make sure 'orderby' is set in query params
632
-        if (! isset(self::$_query_params['orderby'])) {
632
+        if ( ! isset(self::$_query_params['orderby'])) {
633 633
             self::$_query_params['orderby'] = array();
634 634
         }
635 635
         // loop thru $orderby_params (type cast as array)
636 636
         foreach ($orderby_params as $orderby) {
637 637
             // check if we have already added this param
638
-            if (isset(self::$_query_params['orderby'][ $orderby ])) {
638
+            if (isset(self::$_query_params['orderby'][$orderby])) {
639 639
                 // if so then remove from the $orderby_params so that the count() method below is accurate
640
-                unset($orderby_params[ $orderby ]);
640
+                unset($orderby_params[$orderby]);
641 641
                 // then bump ahead to the next param
642 642
                 continue;
643 643
             }
@@ -647,39 +647,39 @@  discard block
 block discarded – undo
647 647
             switch ($orderby) {
648 648
                 case 'id':
649 649
                 case 'ID':
650
-                    $SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
650
+                    $SQL .= $glue.$wpdb->posts.'.ID '.$sort;
651 651
                     break;
652 652
                 case 'end_date':
653
-                    $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
653
+                    $SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort;
654 654
                     break;
655 655
                 case 'event_name':
656
-                    $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
656
+                    $SQL .= $glue.$wpdb->posts.'.post_title '.$sort;
657 657
                     break;
658 658
                 case 'category_slug':
659
-                    $SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
659
+                    $SQL .= $glue.$wpdb->terms.'.slug '.$sort;
660 660
                     break;
661 661
                 case 'ticket_start':
662
-                    $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
662
+                    $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort;
663 663
                     break;
664 664
                 case 'ticket_end':
665
-                    $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
665
+                    $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort;
666 666
                     break;
667 667
                 case 'venue_title':
668
-                    $SQL .= $glue . 'venue_title ' . $sort;
668
+                    $SQL .= $glue.'venue_title '.$sort;
669 669
                     break;
670 670
                 case 'city':
671
-                    $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
671
+                    $SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort;
672 672
                     break;
673 673
                 case 'state':
674
-                    $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
674
+                    $SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort;
675 675
                     break;
676 676
                 case 'start_date':
677 677
                 default:
678
-                    $SQL .= $glue . ' event_start_date ' . $sort;
678
+                    $SQL .= $glue.' event_start_date '.$sort;
679 679
                     break;
680 680
             }
681 681
             // add to array of orderby params that have been added
682
-            self::$_query_params['orderby'][ $orderby ] = true;
682
+            self::$_query_params['orderby'][$orderby] = true;
683 683
             $counter++;
684 684
         }
685 685
         return $SQL;
Please login to merge, or discard this patch.
core/helpers/EEH_Autoloader.helper.php 2 patches
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -15,286 +15,286 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     *    instance of the EE_System object
20
-     *
21
-     * @var    $_instance
22
-     * @access    private
23
-     */
24
-    private static $_instance = null;
25
-
26
-    /**
27
-    *   $_autoloaders
28
-    *   @var array $_autoloaders
29
-    *   @access     private
30
-    */
31
-    private static $_autoloaders;
32
-
33
-    /**
34
-     * set to "paths" to display autoloader class => path mappings
35
-     * set to "times" to display autoloader loading times
36
-     * set to "all" to display both
37
-     *
38
-     * @var string $debug
39
-     * @access    private
40
-     */
41
-    public static $debug = false;
42
-
43
-
44
-
45
-    /**
46
-     *    class constructor
47
-     *
48
-     * @access    private
49
-     * @return \EEH_Autoloader
50
-     */
51
-    private function __construct()
52
-    {
53
-        if (self::$_autoloaders === null) {
54
-            self::$_autoloaders = array();
55
-            $this->_register_custom_autoloaders();
56
-            spl_autoload_register(array( $this, 'espresso_autoloader' ));
57
-        }
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * @access public
64
-     * @return EEH_Autoloader
65
-     */
66
-    public static function instance()
67
-    {
68
-        // check if class object is instantiated
69
-        if (! self::$_instance instanceof EEH_Autoloader) {
70
-            self::$_instance = new self();
71
-        }
72
-        return self::$_instance;
73
-    }
74
-
75
-
76
-
77
-    /**
78
-     *    espresso_autoloader
79
-     *
80
-     * @access    public
81
-     * @param   $class_name
82
-     * @internal  param $className
83
-     * @internal  param string $class_name - simple class name ie: session
84
-     * @return  void
85
-     */
86
-    public static function espresso_autoloader($class_name)
87
-    {
88
-        if (isset(self::$_autoloaders[ $class_name ])) {
89
-            require_once(self::$_autoloaders[ $class_name ]);
90
-        }
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     *    register_autoloader
97
-     *
98
-     * @access    public
99
-     * @param array | string $class_paths - array of key => value pairings between class names and paths
100
-     * @param bool           $read_check  true if we need to check whether the file is readable or not.
101
-     * @param bool           $debug **deprecated**
102
-     * @throws \EE_Error
103
-     */
104
-    public static function register_autoloader($class_paths, $read_check = true, $debug = false)
105
-    {
106
-        $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
107
-        foreach ($class_paths as $class => $path) {
108
-            // don't give up! you gotta...
109
-            // get some class
110
-            if (empty($class)) {
111
-                throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path));
112
-            }
113
-            // one day you will find the path young grasshopper
114
-            if (empty($path)) {
115
-                throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class));
116
-            }
117
-            // is file readable ?
118
-            if ($read_check && ! is_readable($path)) {
119
-                throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
120
-            }
121
-            if (! isset(self::$_autoloaders[ $class ])) {
122
-                self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), DS, $path);
123
-                if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
124
-                    EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
125
-                }
126
-            }
127
-        }
128
-    }
129
-
130
-
131
-
132
-
133
-    /**
134
-     *  get_autoloaders
135
-     *
136
-     *  @access public
137
-     *  @return array
138
-     */
139
-    public static function get_autoloaders()
140
-    {
141
-        return self::$_autoloaders;
142
-    }
143
-
144
-
145
-
146
-
147
-    /**
148
-     *  register core, model and class 'autoloaders'
149
-     *
150
-     *  @access private
151
-     *  @return void
152
-     */
153
-    private function _register_custom_autoloaders()
154
-    {
155
-        EEH_Autoloader::$debug = '';
156
-        \EEH_Autoloader::register_helpers_autoloaders();
157
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
158
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
159
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
160
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
161
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
162
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
163
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
164
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
165
-            EEH_Debug_Tools::instance()->show_times();
166
-        }
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     *    register core, model and class 'autoloaders'
173
-     *
174
-     * @access public
175
-     */
176
-    public static function register_helpers_autoloaders()
177
-    {
178
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
179
-    }
180
-
181
-
182
-
183
-
184
-    /**
185
-     *  register core, model and class 'autoloaders'
186
-     *
187
-     *  @access public
188
-     *  @return void
189
-     */
190
-    public static function register_form_sections_autoloaders()
191
-    {
192
-        // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
193
-    }
194
-
195
-
196
-
197
-
198
-    /**
199
-     *  register core, model and class 'autoloaders'
200
-     *
201
-     *  @access public
202
-     *  @return void
203
-     */
204
-    public static function register_line_item_display_autoloaders()
205
-    {
206
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
207
-    }
208
-
209
-
210
-
211
-
212
-    /**
213
-     *  register core, model and class 'autoloaders'
214
-     *
215
-     *  @access public
216
-     *  @return void
217
-     */
218
-    public static function register_line_item_filter_autoloaders()
219
-    {
220
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
221
-    }
222
-
223
-
224
-
225
-
226
-    /**
227
-     *  register template part 'autoloaders'
228
-     *
229
-     *  @access public
230
-     *  @return void
231
-     */
232
-    public static function register_template_part_autoloaders()
233
-    {
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * Assumes all the files in this folder have the normal naming scheme (namely that their classname
241
-     * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
242
-     * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly.
243
-     * Yes this has to scan the directory for files, but it only does it once -- not on EACH
244
-     * time the autoloader is used
245
-     *
246
-     * @param string $folder name, with or without trailing /, doesn't matter
247
-     * @param bool   $recursive
248
-     * @param bool   $debug  **deprecated**
249
-     * @throws \EE_Error
250
-     */
251
-    public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false)
252
-    {
253
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
254
-            EEH_Debug_Tools::instance()->start_timer(basename($folder));
255
-        }
256
-        // make sure last char is a /
257
-        $folder .= $folder[ strlen($folder)-1 ] !== DS ? DS : '';
258
-        $class_to_filepath_map = array();
259
-        $exclude = array( 'index' );
260
-        // get all the files in that folder that end in php
261
-        $filepaths = glob($folder.'*');
262
-
263
-        if (empty($filepaths)) {
264
-            return;
265
-        }
266
-
267
-        foreach ($filepaths as $filepath) {
268
-            if (substr($filepath, -4, 4) === '.php') {
269
-                $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
270
-                if (! in_array($class_name, $exclude)) {
271
-                    $class_to_filepath_map [ $class_name ] = $filepath;
272
-                }
273
-            } elseif ($recursive) {
274
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
275
-            }
276
-        }
277
-        // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
278
-        self::register_autoloader($class_to_filepath_map, false, $debug);
279
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
280
-            EEH_Debug_Tools::instance()->stop_timer(basename($folder));
281
-        }
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * add_alias
288
-     * register additional autoloader based on variation of the classname for an existing autoloader
289
-     *
290
-     * @access    public
291
-     * @param string $class_name - simple class name ie: EE_Session
292
-     * @param string $alias - variation on class name ie: EE_session, session, etc
293
-     */
294
-    public static function add_alias($class_name, $alias)
295
-    {
296
-        if (isset(self::$_autoloaders[ $class_name ])) {
297
-            self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
298
-        }
299
-    }
18
+	/**
19
+	 *    instance of the EE_System object
20
+	 *
21
+	 * @var    $_instance
22
+	 * @access    private
23
+	 */
24
+	private static $_instance = null;
25
+
26
+	/**
27
+	 *   $_autoloaders
28
+	 *   @var array $_autoloaders
29
+	 *   @access     private
30
+	 */
31
+	private static $_autoloaders;
32
+
33
+	/**
34
+	 * set to "paths" to display autoloader class => path mappings
35
+	 * set to "times" to display autoloader loading times
36
+	 * set to "all" to display both
37
+	 *
38
+	 * @var string $debug
39
+	 * @access    private
40
+	 */
41
+	public static $debug = false;
42
+
43
+
44
+
45
+	/**
46
+	 *    class constructor
47
+	 *
48
+	 * @access    private
49
+	 * @return \EEH_Autoloader
50
+	 */
51
+	private function __construct()
52
+	{
53
+		if (self::$_autoloaders === null) {
54
+			self::$_autoloaders = array();
55
+			$this->_register_custom_autoloaders();
56
+			spl_autoload_register(array( $this, 'espresso_autoloader' ));
57
+		}
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * @access public
64
+	 * @return EEH_Autoloader
65
+	 */
66
+	public static function instance()
67
+	{
68
+		// check if class object is instantiated
69
+		if (! self::$_instance instanceof EEH_Autoloader) {
70
+			self::$_instance = new self();
71
+		}
72
+		return self::$_instance;
73
+	}
74
+
75
+
76
+
77
+	/**
78
+	 *    espresso_autoloader
79
+	 *
80
+	 * @access    public
81
+	 * @param   $class_name
82
+	 * @internal  param $className
83
+	 * @internal  param string $class_name - simple class name ie: session
84
+	 * @return  void
85
+	 */
86
+	public static function espresso_autoloader($class_name)
87
+	{
88
+		if (isset(self::$_autoloaders[ $class_name ])) {
89
+			require_once(self::$_autoloaders[ $class_name ]);
90
+		}
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 *    register_autoloader
97
+	 *
98
+	 * @access    public
99
+	 * @param array | string $class_paths - array of key => value pairings between class names and paths
100
+	 * @param bool           $read_check  true if we need to check whether the file is readable or not.
101
+	 * @param bool           $debug **deprecated**
102
+	 * @throws \EE_Error
103
+	 */
104
+	public static function register_autoloader($class_paths, $read_check = true, $debug = false)
105
+	{
106
+		$class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
107
+		foreach ($class_paths as $class => $path) {
108
+			// don't give up! you gotta...
109
+			// get some class
110
+			if (empty($class)) {
111
+				throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path));
112
+			}
113
+			// one day you will find the path young grasshopper
114
+			if (empty($path)) {
115
+				throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class));
116
+			}
117
+			// is file readable ?
118
+			if ($read_check && ! is_readable($path)) {
119
+				throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
120
+			}
121
+			if (! isset(self::$_autoloaders[ $class ])) {
122
+				self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), DS, $path);
123
+				if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
124
+					EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
125
+				}
126
+			}
127
+		}
128
+	}
129
+
130
+
131
+
132
+
133
+	/**
134
+	 *  get_autoloaders
135
+	 *
136
+	 *  @access public
137
+	 *  @return array
138
+	 */
139
+	public static function get_autoloaders()
140
+	{
141
+		return self::$_autoloaders;
142
+	}
143
+
144
+
145
+
146
+
147
+	/**
148
+	 *  register core, model and class 'autoloaders'
149
+	 *
150
+	 *  @access private
151
+	 *  @return void
152
+	 */
153
+	private function _register_custom_autoloaders()
154
+	{
155
+		EEH_Autoloader::$debug = '';
156
+		\EEH_Autoloader::register_helpers_autoloaders();
157
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
158
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
159
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
160
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
161
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
162
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
163
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
164
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
165
+			EEH_Debug_Tools::instance()->show_times();
166
+		}
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 *    register core, model and class 'autoloaders'
173
+	 *
174
+	 * @access public
175
+	 */
176
+	public static function register_helpers_autoloaders()
177
+	{
178
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
179
+	}
180
+
181
+
182
+
183
+
184
+	/**
185
+	 *  register core, model and class 'autoloaders'
186
+	 *
187
+	 *  @access public
188
+	 *  @return void
189
+	 */
190
+	public static function register_form_sections_autoloaders()
191
+	{
192
+		// EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
193
+	}
194
+
195
+
196
+
197
+
198
+	/**
199
+	 *  register core, model and class 'autoloaders'
200
+	 *
201
+	 *  @access public
202
+	 *  @return void
203
+	 */
204
+	public static function register_line_item_display_autoloaders()
205
+	{
206
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
207
+	}
208
+
209
+
210
+
211
+
212
+	/**
213
+	 *  register core, model and class 'autoloaders'
214
+	 *
215
+	 *  @access public
216
+	 *  @return void
217
+	 */
218
+	public static function register_line_item_filter_autoloaders()
219
+	{
220
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
221
+	}
222
+
223
+
224
+
225
+
226
+	/**
227
+	 *  register template part 'autoloaders'
228
+	 *
229
+	 *  @access public
230
+	 *  @return void
231
+	 */
232
+	public static function register_template_part_autoloaders()
233
+	{
234
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * Assumes all the files in this folder have the normal naming scheme (namely that their classname
241
+	 * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
242
+	 * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly.
243
+	 * Yes this has to scan the directory for files, but it only does it once -- not on EACH
244
+	 * time the autoloader is used
245
+	 *
246
+	 * @param string $folder name, with or without trailing /, doesn't matter
247
+	 * @param bool   $recursive
248
+	 * @param bool   $debug  **deprecated**
249
+	 * @throws \EE_Error
250
+	 */
251
+	public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false)
252
+	{
253
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
254
+			EEH_Debug_Tools::instance()->start_timer(basename($folder));
255
+		}
256
+		// make sure last char is a /
257
+		$folder .= $folder[ strlen($folder)-1 ] !== DS ? DS : '';
258
+		$class_to_filepath_map = array();
259
+		$exclude = array( 'index' );
260
+		// get all the files in that folder that end in php
261
+		$filepaths = glob($folder.'*');
262
+
263
+		if (empty($filepaths)) {
264
+			return;
265
+		}
266
+
267
+		foreach ($filepaths as $filepath) {
268
+			if (substr($filepath, -4, 4) === '.php') {
269
+				$class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
270
+				if (! in_array($class_name, $exclude)) {
271
+					$class_to_filepath_map [ $class_name ] = $filepath;
272
+				}
273
+			} elseif ($recursive) {
274
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
275
+			}
276
+		}
277
+		// we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
278
+		self::register_autoloader($class_to_filepath_map, false, $debug);
279
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
280
+			EEH_Debug_Tools::instance()->stop_timer(basename($folder));
281
+		}
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * add_alias
288
+	 * register additional autoloader based on variation of the classname for an existing autoloader
289
+	 *
290
+	 * @access    public
291
+	 * @param string $class_name - simple class name ie: EE_Session
292
+	 * @param string $alias - variation on class name ie: EE_session, session, etc
293
+	 */
294
+	public static function add_alias($class_name, $alias)
295
+	{
296
+		if (isset(self::$_autoloaders[ $class_name ])) {
297
+			self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
298
+		}
299
+	}
300 300
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         if (self::$_autoloaders === null) {
54 54
             self::$_autoloaders = array();
55 55
             $this->_register_custom_autoloaders();
56
-            spl_autoload_register(array( $this, 'espresso_autoloader' ));
56
+            spl_autoload_register(array($this, 'espresso_autoloader'));
57 57
         }
58 58
     }
59 59
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     public static function instance()
67 67
     {
68 68
         // check if class object is instantiated
69
-        if (! self::$_instance instanceof EEH_Autoloader) {
69
+        if ( ! self::$_instance instanceof EEH_Autoloader) {
70 70
             self::$_instance = new self();
71 71
         }
72 72
         return self::$_instance;
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
      */
86 86
     public static function espresso_autoloader($class_name)
87 87
     {
88
-        if (isset(self::$_autoloaders[ $class_name ])) {
89
-            require_once(self::$_autoloaders[ $class_name ]);
88
+        if (isset(self::$_autoloaders[$class_name])) {
89
+            require_once(self::$_autoloaders[$class_name]);
90 90
         }
91 91
     }
92 92
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public static function register_autoloader($class_paths, $read_check = true, $debug = false)
105 105
     {
106
-        $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
106
+        $class_paths = is_array($class_paths) ? $class_paths : array($class_paths);
107 107
         foreach ($class_paths as $class => $path) {
108 108
             // don't give up! you gotta...
109 109
             // get some class
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
             if ($read_check && ! is_readable($path)) {
119 119
                 throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
120 120
             }
121
-            if (! isset(self::$_autoloaders[ $class ])) {
122
-                self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), DS, $path);
123
-                if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
124
-                    EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
121
+            if ( ! isset(self::$_autoloaders[$class])) {
122
+                self::$_autoloaders[$class] = str_replace(array('/', '\\'), DS, $path);
123
+                if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) {
124
+                    EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__);
125 125
                 }
126 126
             }
127 127
         }
@@ -154,13 +154,13 @@  discard block
 block discarded – undo
154 154
     {
155 155
         EEH_Autoloader::$debug = '';
156 156
         \EEH_Autoloader::register_helpers_autoloaders();
157
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
157
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces');
158 158
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
159 159
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
160 160
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
161 161
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
162 162
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
163
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
163
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages');
164 164
         if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
165 165
             EEH_Debug_Tools::instance()->show_times();
166 166
         }
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      */
204 204
     public static function register_line_item_display_autoloaders()
205 205
     {
206
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
206
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true);
207 207
     }
208 208
 
209 209
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
      */
218 218
     public static function register_line_item_filter_autoloaders()
219 219
     {
220
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
220
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true);
221 221
     }
222 222
 
223 223
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      */
232 232
     public static function register_template_part_autoloaders()
233 233
     {
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
234
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true);
235 235
     }
236 236
 
237 237
 
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
             EEH_Debug_Tools::instance()->start_timer(basename($folder));
255 255
         }
256 256
         // make sure last char is a /
257
-        $folder .= $folder[ strlen($folder)-1 ] !== DS ? DS : '';
257
+        $folder .= $folder[strlen($folder) - 1] !== DS ? DS : '';
258 258
         $class_to_filepath_map = array();
259
-        $exclude = array( 'index' );
259
+        $exclude = array('index');
260 260
         // get all the files in that folder that end in php
261 261
         $filepaths = glob($folder.'*');
262 262
 
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
         foreach ($filepaths as $filepath) {
268 268
             if (substr($filepath, -4, 4) === '.php') {
269 269
                 $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
270
-                if (! in_array($class_name, $exclude)) {
271
-                    $class_to_filepath_map [ $class_name ] = $filepath;
270
+                if ( ! in_array($class_name, $exclude)) {
271
+                    $class_to_filepath_map [$class_name] = $filepath;
272 272
                 }
273 273
             } elseif ($recursive) {
274 274
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
@@ -293,8 +293,8 @@  discard block
 block discarded – undo
293 293
      */
294 294
     public static function add_alias($class_name, $alias)
295 295
     {
296
-        if (isset(self::$_autoloaders[ $class_name ])) {
297
-            self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
296
+        if (isset(self::$_autoloaders[$class_name])) {
297
+            self::$_autoloaders[$alias] = self::$_autoloaders[$class_name];
298 298
         }
299 299
     }
300 300
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Class_Tools.helper.php 2 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -11,131 +11,131 @@
 block discarded – undo
11 11
 class EEH_Class_Tools
12 12
 {
13 13
 
14
-    public static $i = 0;
15
-    public static $file_line = null;
14
+	public static $i = 0;
15
+	public static $file_line = null;
16 16
 
17
-    /**
18
-     *  get_called_class - for PHP versions < 5.3
19
-     *
20
-     *  @access     public
21
-     *  @author origins:  http://stackoverflow.com/a/1542045
22
-     *  return string
23
-     */
24
-    public static function get_called_class()
25
-    {
26
-        $backtrace = debug_backtrace();
27
-        if (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['class']) && ! isset($backtrace[2]['file'])) {
28
-            return $backtrace[2]['class'];
29
-        } elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) {
30
-            return $backtrace[3]['class'];
31
-        } elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) {
32
-            if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) {
33
-                self::$i++;
34
-            } else {
35
-                self::$i = 0;
36
-                self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line'];
37
-            }
38
-            // was  class method called via call_user_func ?
39
-            if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) {
40
-                if (isset($backtrace[2]['args'][0]) && isset($backtrace[2]['args'][0][0])) {
41
-                    $called_class = $backtrace[2]['args'][0][0];
42
-                    // is it an EE function ?
43
-                    if (strpos($called_class, 'EE') === 0) {
44
-                        $prefix_chars = strpos($called_class, '_') + 1;
45
-                        $prefix = substr($called_class, 0, $prefix_chars);
46
-                        $classname = substr($called_class, $prefix_chars, strlen($called_class));
47
-                        $classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname))));
48
-                        return $classname;
49
-                    }
50
-                }
51
-            } else {
52
-                $lines = file($backtrace[2]['file']);
53
-                preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line']-1 ], $matches);
54
-                if (isset($matches[1]) && isset($matches[1][ self::$i ])) {
55
-                    return $matches[1][ self::$i ];
56
-                }
57
-            }
58
-        }
59
-        return false;
60
-    }
17
+	/**
18
+	 *  get_called_class - for PHP versions < 5.3
19
+	 *
20
+	 *  @access     public
21
+	 *  @author origins:  http://stackoverflow.com/a/1542045
22
+	 *  return string
23
+	 */
24
+	public static function get_called_class()
25
+	{
26
+		$backtrace = debug_backtrace();
27
+		if (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['class']) && ! isset($backtrace[2]['file'])) {
28
+			return $backtrace[2]['class'];
29
+		} elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) {
30
+			return $backtrace[3]['class'];
31
+		} elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) {
32
+			if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) {
33
+				self::$i++;
34
+			} else {
35
+				self::$i = 0;
36
+				self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line'];
37
+			}
38
+			// was  class method called via call_user_func ?
39
+			if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) {
40
+				if (isset($backtrace[2]['args'][0]) && isset($backtrace[2]['args'][0][0])) {
41
+					$called_class = $backtrace[2]['args'][0][0];
42
+					// is it an EE function ?
43
+					if (strpos($called_class, 'EE') === 0) {
44
+						$prefix_chars = strpos($called_class, '_') + 1;
45
+						$prefix = substr($called_class, 0, $prefix_chars);
46
+						$classname = substr($called_class, $prefix_chars, strlen($called_class));
47
+						$classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname))));
48
+						return $classname;
49
+					}
50
+				}
51
+			} else {
52
+				$lines = file($backtrace[2]['file']);
53
+				preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line']-1 ], $matches);
54
+				if (isset($matches[1]) && isset($matches[1][ self::$i ])) {
55
+					return $matches[1][ self::$i ];
56
+				}
57
+			}
58
+		}
59
+		return false;
60
+	}
61 61
 
62 62
 
63 63
 
64 64
 
65
-    /**
66
-     *  get_class_names_for_all_callbacks_on_hook
67
-     * returns an array of names for all classes that have methods registered as callbacks for the given action or filter hook
68
-     *  @access     public
69
-     *  @param  string  $hook
70
-     *  @return     array
71
-     */
72
-    public static function get_class_names_for_all_callbacks_on_hook($hook = null)
73
-    {
74
-        global $wp_filter;
75
-        $class_names = array();
76
-        // are any callbacks registered for this hook ?
77
-        if (isset($wp_filter[ $hook ])) {
78
-            // loop thru all of the callbacks attached to the deprecated hookpoint
79
-            foreach ($wp_filter[ $hook ] as $priority) {
80
-                foreach ($priority as $callback) {
81
-                    // is the callback a non-static class method ?
82
-                    if (isset($callback['function']) && is_array($callback['function'])) {
83
-                        if (isset($callback['function'][0]) && is_object($callback['function'][0])) {
84
-                            $class_names[] = get_class($callback['function'][0]);
85
-                        }
86
-                    // test for static method
87
-                    } elseif (strpos($callback['function'], '::') !== false) {
88
-                        $class = explode('::', $callback['function']);
89
-                        $class_names[] = $class[0];
90
-                    } else {
91
-                        // just a function
92
-                    }
93
-                }
94
-            }
95
-        }
96
-        return $class_names;
97
-    }
65
+	/**
66
+	 *  get_class_names_for_all_callbacks_on_hook
67
+	 * returns an array of names for all classes that have methods registered as callbacks for the given action or filter hook
68
+	 *  @access     public
69
+	 *  @param  string  $hook
70
+	 *  @return     array
71
+	 */
72
+	public static function get_class_names_for_all_callbacks_on_hook($hook = null)
73
+	{
74
+		global $wp_filter;
75
+		$class_names = array();
76
+		// are any callbacks registered for this hook ?
77
+		if (isset($wp_filter[ $hook ])) {
78
+			// loop thru all of the callbacks attached to the deprecated hookpoint
79
+			foreach ($wp_filter[ $hook ] as $priority) {
80
+				foreach ($priority as $callback) {
81
+					// is the callback a non-static class method ?
82
+					if (isset($callback['function']) && is_array($callback['function'])) {
83
+						if (isset($callback['function'][0]) && is_object($callback['function'][0])) {
84
+							$class_names[] = get_class($callback['function'][0]);
85
+						}
86
+					// test for static method
87
+					} elseif (strpos($callback['function'], '::') !== false) {
88
+						$class = explode('::', $callback['function']);
89
+						$class_names[] = $class[0];
90
+					} else {
91
+						// just a function
92
+					}
93
+				}
94
+			}
95
+		}
96
+		return $class_names;
97
+	}
98 98
 
99 99
 
100 100
 
101 101
 
102
-    /**
103
-     *  property_exists() with fallback for PHP versions < 5.3
104
-     *  @access     public
105
-     *  @param      mixed object | string   $class
106
-     *  @param      string  $property
107
-     *  @return         boolean
108
-     */
109
-    public static function has_property($class = null, $property = null)
110
-    {
111
-        // if $class or $property don't exist, then get out, cuz that would be like... fatal dude
112
-        if (empty($class) || empty($property)) {
113
-            return false;
114
-        }
115
-        // if your hosting company doesn't cut the mustard
116
-        if (version_compare(PHP_VERSION, '5.3.0') < 0) {
117
-            // just in case $class is an actual instantiated object
118
-            if (is_object($class)) {
119
-                return isset($class->{$property}) ? true : false;
120
-            } else {
121
-                // use reflection for < PHP 5.3 to get details using just the class name
122
-                $reflector = new ReflectionClass($class);
123
-                return $reflector->hasProperty($property);
124
-            }
125
-        } else {
126
-            // or try regular property exists method which works as expected in PHP 5.3+
127
-            return property_exists($class, $property);
128
-        }
129
-    }
102
+	/**
103
+	 *  property_exists() with fallback for PHP versions < 5.3
104
+	 *  @access     public
105
+	 *  @param      mixed object | string   $class
106
+	 *  @param      string  $property
107
+	 *  @return         boolean
108
+	 */
109
+	public static function has_property($class = null, $property = null)
110
+	{
111
+		// if $class or $property don't exist, then get out, cuz that would be like... fatal dude
112
+		if (empty($class) || empty($property)) {
113
+			return false;
114
+		}
115
+		// if your hosting company doesn't cut the mustard
116
+		if (version_compare(PHP_VERSION, '5.3.0') < 0) {
117
+			// just in case $class is an actual instantiated object
118
+			if (is_object($class)) {
119
+				return isset($class->{$property}) ? true : false;
120
+			} else {
121
+				// use reflection for < PHP 5.3 to get details using just the class name
122
+				$reflector = new ReflectionClass($class);
123
+				return $reflector->hasProperty($property);
124
+			}
125
+		} else {
126
+			// or try regular property exists method which works as expected in PHP 5.3+
127
+			return property_exists($class, $property);
128
+		}
129
+	}
130 130
 }
131 131
 
132 132
 // if PHP version < 5.3
133 133
 if (! function_exists('get_called_class')) {
134
-    /**
135
-     * @return string
136
-     */
137
-    function get_called_class()
138
-    {
139
-        return EEH_Class_Tools::get_called_class();
140
-    }
134
+	/**
135
+	 * @return string
136
+	 */
137
+	function get_called_class()
138
+	{
139
+		return EEH_Class_Tools::get_called_class();
140
+	}
141 141
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
         } elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) {
30 30
             return $backtrace[3]['class'];
31 31
         } elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) {
32
-            if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) {
32
+            if (self::$file_line == $backtrace[2]['file'].$backtrace[2]['line']) {
33 33
                 self::$i++;
34 34
             } else {
35 35
                 self::$i = 0;
36
-                self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line'];
36
+                self::$file_line = $backtrace[2]['file'].$backtrace[2]['line'];
37 37
             }
38 38
             // was  class method called via call_user_func ?
39 39
             if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) {
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
                         $prefix_chars = strpos($called_class, '_') + 1;
45 45
                         $prefix = substr($called_class, 0, $prefix_chars);
46 46
                         $classname = substr($called_class, $prefix_chars, strlen($called_class));
47
-                        $classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname))));
47
+                        $classname = $prefix.str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname))));
48 48
                         return $classname;
49 49
                     }
50 50
                 }
51 51
             } else {
52 52
                 $lines = file($backtrace[2]['file']);
53
-                preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line']-1 ], $matches);
54
-                if (isset($matches[1]) && isset($matches[1][ self::$i ])) {
55
-                    return $matches[1][ self::$i ];
53
+                preg_match_all('/([a-zA-Z0-9\_]+)::'.$backtrace[2]['function'].'/', $lines[$backtrace[2]['line'] - 1], $matches);
54
+                if (isset($matches[1]) && isset($matches[1][self::$i])) {
55
+                    return $matches[1][self::$i];
56 56
                 }
57 57
             }
58 58
         }
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
         global $wp_filter;
75 75
         $class_names = array();
76 76
         // are any callbacks registered for this hook ?
77
-        if (isset($wp_filter[ $hook ])) {
77
+        if (isset($wp_filter[$hook])) {
78 78
             // loop thru all of the callbacks attached to the deprecated hookpoint
79
-            foreach ($wp_filter[ $hook ] as $priority) {
79
+            foreach ($wp_filter[$hook] as $priority) {
80 80
                 foreach ($priority as $callback) {
81 81
                     // is the callback a non-static class method ?
82 82
                     if (isset($callback['function']) && is_array($callback['function'])) {
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 }
131 131
 
132 132
 // if PHP version < 5.3
133
-if (! function_exists('get_called_class')) {
133
+if ( ! function_exists('get_called_class')) {
134 134
     /**
135 135
      * @return string
136 136
      */
Please login to merge, or discard this patch.
core/helpers/EEH_Tabbed_Content.helper.php 2 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -21,202 +21,202 @@
 block discarded – undo
21 21
 
22 22
 
23 23
 
24
-    /**
25
-     * assembles and returns the html structure for tabs
26
-     *
27
-     * @static
28
-     * @param  array $tabs_contents an array of the content for each tab [required]
29
-     * @param  array $tabs_names    an unassociative array of names for each tab [optional] - if this isn't included then we use the indexes for $tabs_content as the tab names)
30
-     * @param bool   $small_tabs
31
-     * @param bool   $tabs_content
32
-     * @return string the assembled html string containing the tabbed content for display.
33
-     * @throws \EE_Error
34
-     */
35
-    public static function display($tabs_contents, $tabs_names = array(), $small_tabs = true, $tabs_content = true)
36
-    {
37
-
38
-        // first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston
39
-        if (!empty($tabs_names) && ( count((array) $tabs_names) != count((array) $tabs_content) )) {
40
-            throw new EE_Error(__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso'));
41
-        }
42
-
43
-        // make sure we've got incoming data setup properly
44
-        $tabs = !empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents);
45
-        $tabs_content = !empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents;
46
-
47
-        $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n";
48
-        $all_tabs_content = '';
49
-
50
-        $index = 0;
51
-        foreach ($tabs as $tab) {
52
-            $active = $index === 0 ? true : false;
53
-            $all_tabs .= self::tab($tab, $active);
54
-            $all_tabs_content .= self::tab_content($tab, $tabs_content[ $tab ], $active);
55
-            $index++;
56
-        }
57
-        /*
24
+	/**
25
+	 * assembles and returns the html structure for tabs
26
+	 *
27
+	 * @static
28
+	 * @param  array $tabs_contents an array of the content for each tab [required]
29
+	 * @param  array $tabs_names    an unassociative array of names for each tab [optional] - if this isn't included then we use the indexes for $tabs_content as the tab names)
30
+	 * @param bool   $small_tabs
31
+	 * @param bool   $tabs_content
32
+	 * @return string the assembled html string containing the tabbed content for display.
33
+	 * @throws \EE_Error
34
+	 */
35
+	public static function display($tabs_contents, $tabs_names = array(), $small_tabs = true, $tabs_content = true)
36
+	{
37
+
38
+		// first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston
39
+		if (!empty($tabs_names) && ( count((array) $tabs_names) != count((array) $tabs_content) )) {
40
+			throw new EE_Error(__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso'));
41
+		}
42
+
43
+		// make sure we've got incoming data setup properly
44
+		$tabs = !empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents);
45
+		$tabs_content = !empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents;
46
+
47
+		$all_tabs = '<h2 class="nav-tab-wrapper">' . "\n";
48
+		$all_tabs_content = '';
49
+
50
+		$index = 0;
51
+		foreach ($tabs as $tab) {
52
+			$active = $index === 0 ? true : false;
53
+			$all_tabs .= self::tab($tab, $active);
54
+			$all_tabs_content .= self::tab_content($tab, $tabs_content[ $tab ], $active);
55
+			$index++;
56
+		}
57
+		/*
58 58
         sample content for testing
59 59
 
60 60
         $all_tabs .= '<a class="nav-tab" rel="ee-tab-anothertab" href="#anothertab">Another Tab</a>';
61 61
         $all_tabs_content .= '<div class="nav-tab-content hidden" id="ee-tab-anothertab">This is just some sample content to show another tab<div style="clear:both"></div></div>';
62 62
         //end sample content /**/
63 63
 
64
-        $all_tabs .= '</h2>';
65
-
66
-        $tab_container_class = $small_tabs ? 'ee-nav-tabs ee-nav-tabs-small' : 'ee-nav-tabs';
67
-
68
-        return '<div class="'. $tab_container_class . '">' . "\n\t" . $all_tabs . $all_tabs_content . "\n" . '</div>';
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * display_admin_nav_tabs
75
-     * this returns the properly formatted tab html for EE_Admin_Pages.
76
-     * We are expecting an array of tabs in the following format
77
-     * array(
78
-     *    'nav_tab_name' => array(
79
-     *        'url' => 'url for tab',
80
-     *        'link_text' => 'tab text',
81
-     *        'css_class' => 'tab class' //including the nav-tab-active class if its active
82
-     *    )
83
-     * )
84
-     *
85
-     * @access public
86
-     * @static
87
-     * @param array $nav_tabs tab array for nav tabs
88
-     * @return string
89
-     * @throws \EE_Error
90
-     */
91
-    public static function display_admin_nav_tabs($nav_tabs = array())
92
-    {
93
-        if (empty($nav_tabs)) {
94
-            throw new EE_Error(__('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso'));
95
-        }
96
-
97
-        $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n";
98
-        foreach ($nav_tabs as $slug => $tab) {
99
-            $all_tabs .= self::tab($slug, false, $tab['link_text'], $tab['url'], $tab['css_class']);
100
-        }
101
-        $all_tabs .= '</h2>';
102
-        return $all_tabs;
103
-    }
104
-
105
-    /**
106
-     * this simply returns a single tab given a tab name & content
107
-     * @param  string $name    name of tab
108
-     * @param bool $active true=tab active, false=tab not active
109
-     * @param bool|string $nice_name if string given then this value will be used for the tab link text.
110
-     * @param bool|string $url If url given then tabs will be generated linking to the url.
111
-     * @param bool|string $css If string given then the generated tab will include that as the class.
112
-     * @return string          html for tab
113
-     */
114
-    private static function tab($name, $active = false, $nice_name = false, $url = false, $css = false)
115
-    {
116
-        $name = str_replace(' ', '-', $name);
117
-        $class = $active ? 'nav-tab nav-tab-active' : 'nav-tab';
118
-        $class = $css ? $class . ' ' . $css : $class;
119
-        $nice_name = $nice_name ? $nice_name : ucwords(preg_replace('/(-|_)/', ' ', $name));
120
-        $url = $url ? $url : '#' . $name;
121
-        $tab = '<a class="' . $class . '" rel="ee-tab-' . $name . '" href="' . $url . '">' . $nice_name . '</a>' . "\n\t";
122
-        return $tab;
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * this just returns the properly formatted tab content for our tab box.
129
-     *
130
-     * @param  string $name        name of tab (used for selector)
131
-     * @param  string $tab_content content of tab
132
-     * @param  bool   $active
133
-     * @return string html for content area
134
-     */
135
-    private static function tab_content($name, $tab_content, $active = false)
136
-    {
137
-        $class = $active ? 'nav-tab-content' : 'nav-tab-content hidden';
138
-        $name = str_replace(' ', '-', $name);
139
-        $content = "\t" . '<div class="'. $class . '" id="ee-tab-' . $name . '">' . "\n";
140
-        $content .= "\t" . $tab_content . "\n";
141
-        $content .= '<div style="clear:both"></div></div>';
142
-        return $content;
143
-    }
144
-
145
-
146
-
147
-    /** HORIZONTAL TEXT LINKS **/
148
-
149
-    /**
150
-     * This will take in an array of link items and spit out a formatted list of links that can be used to navigate to items.
151
-     * There is a corresponding js file that can be loaded to dynamically display containers with the same id as the href -ref.
152
-     *
153
-     * @param  array $item_array      formatted array of items.  Format:
154
-     * array(
155
-     *      'label' => __('localized label displayed'),
156
-     *      'class' => 'class_for_item',
157
-     *      'href' => '#some_item_id', //url/bookmark for item.  If you include a bookmark the js will used this to show the container div.
158
-     *      'title' => __('localized text for the title attribute of the link'),
159
-     *      'slug' => 'slug_used_for_reference'
160
-     * )
161
-     * @param  string $container_class class used for main container
162
-     * @param  string $sep              you can add in what is used as a separator between each link (or leave blank for none)
163
-     * @param string $default           You can include a string for the item that will receive the "item_display" class for the js.
164
-     * @return string                  a html snippet of of all the formatted link elements.
165
-     */
166
-    public static function tab_text_links($item_array, $container_class = '', $sep = '|', $default = '')
167
-    {
168
-        $item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class);
169
-        if (!is_array($item_array) || empty($item_array)) {
170
-            return false; // get out we don't have even the basic thing we need!
171
-        }
172
-
173
-
174
-        $defaults = array(
175
-            'label' => __('Item', 'event_espresso'),
176
-            'class' => '',
177
-            'href' => '',
178
-            'title' => esc_attr__('Link for Item', 'event_espresso'),
179
-            'slug' => 'item_slug'
180
-        );
181
-        $container_class = !empty($container_class) ? 'ee-text-links ' . $container_class : 'ee-text-links';
182
-        $list = '<ul class="' . $container_class . '">';
183
-
184
-        $ci = 1;
185
-        foreach ($item_array as $item) {
186
-            $item = wp_parse_args($item, $defaults);
187
-            $item['class'] = !empty($default) && $default == $item['slug'] ? 'item_display ' . $item['class'] : $item['class'];
188
-            $list .= self::_text_link_item($item);
189
-            if (!empty($sep) && $ci != count($item_array)) {
190
-                $list .= self::_text_link_item($sep);
191
-            }
192
-            $ci++;
193
-        }
194
-
195
-        $list .= '</ul>';
196
-        return $list;
197
-    }
198
-
199
-
200
-
201
-    private static function _text_link_item($item)
202
-    {
203
-        // if this isn't an array then we're doing a separator
204
-        if (!is_array($item)) {
205
-            $label = $item;
206
-            $class = 'ee-text-link-sep';
207
-            $href = '';
208
-            $title = '';
209
-        } else {
210
-            extract($item);
211
-        }
212
-
213
-        $class = $class != 'ee-text-link-sep'  ? 'class="ee-text-link-li ' . $class . '"' : 'class="ee-text-link-sep"';
214
-
215
-        $content = '<li ' . $class . '>';
216
-        $content .= !empty($href) ? '<a class="ee-text-link" href="#' . $href . '" title="' . $title . '">' : '';
217
-        $content .= $label;
218
-        $content .= !empty($href) ? '</a>' : '';
219
-        $content .= '</li>';
220
-        return $content;
221
-    }
64
+		$all_tabs .= '</h2>';
65
+
66
+		$tab_container_class = $small_tabs ? 'ee-nav-tabs ee-nav-tabs-small' : 'ee-nav-tabs';
67
+
68
+		return '<div class="'. $tab_container_class . '">' . "\n\t" . $all_tabs . $all_tabs_content . "\n" . '</div>';
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * display_admin_nav_tabs
75
+	 * this returns the properly formatted tab html for EE_Admin_Pages.
76
+	 * We are expecting an array of tabs in the following format
77
+	 * array(
78
+	 *    'nav_tab_name' => array(
79
+	 *        'url' => 'url for tab',
80
+	 *        'link_text' => 'tab text',
81
+	 *        'css_class' => 'tab class' //including the nav-tab-active class if its active
82
+	 *    )
83
+	 * )
84
+	 *
85
+	 * @access public
86
+	 * @static
87
+	 * @param array $nav_tabs tab array for nav tabs
88
+	 * @return string
89
+	 * @throws \EE_Error
90
+	 */
91
+	public static function display_admin_nav_tabs($nav_tabs = array())
92
+	{
93
+		if (empty($nav_tabs)) {
94
+			throw new EE_Error(__('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso'));
95
+		}
96
+
97
+		$all_tabs = '<h2 class="nav-tab-wrapper">' . "\n";
98
+		foreach ($nav_tabs as $slug => $tab) {
99
+			$all_tabs .= self::tab($slug, false, $tab['link_text'], $tab['url'], $tab['css_class']);
100
+		}
101
+		$all_tabs .= '</h2>';
102
+		return $all_tabs;
103
+	}
104
+
105
+	/**
106
+	 * this simply returns a single tab given a tab name & content
107
+	 * @param  string $name    name of tab
108
+	 * @param bool $active true=tab active, false=tab not active
109
+	 * @param bool|string $nice_name if string given then this value will be used for the tab link text.
110
+	 * @param bool|string $url If url given then tabs will be generated linking to the url.
111
+	 * @param bool|string $css If string given then the generated tab will include that as the class.
112
+	 * @return string          html for tab
113
+	 */
114
+	private static function tab($name, $active = false, $nice_name = false, $url = false, $css = false)
115
+	{
116
+		$name = str_replace(' ', '-', $name);
117
+		$class = $active ? 'nav-tab nav-tab-active' : 'nav-tab';
118
+		$class = $css ? $class . ' ' . $css : $class;
119
+		$nice_name = $nice_name ? $nice_name : ucwords(preg_replace('/(-|_)/', ' ', $name));
120
+		$url = $url ? $url : '#' . $name;
121
+		$tab = '<a class="' . $class . '" rel="ee-tab-' . $name . '" href="' . $url . '">' . $nice_name . '</a>' . "\n\t";
122
+		return $tab;
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * this just returns the properly formatted tab content for our tab box.
129
+	 *
130
+	 * @param  string $name        name of tab (used for selector)
131
+	 * @param  string $tab_content content of tab
132
+	 * @param  bool   $active
133
+	 * @return string html for content area
134
+	 */
135
+	private static function tab_content($name, $tab_content, $active = false)
136
+	{
137
+		$class = $active ? 'nav-tab-content' : 'nav-tab-content hidden';
138
+		$name = str_replace(' ', '-', $name);
139
+		$content = "\t" . '<div class="'. $class . '" id="ee-tab-' . $name . '">' . "\n";
140
+		$content .= "\t" . $tab_content . "\n";
141
+		$content .= '<div style="clear:both"></div></div>';
142
+		return $content;
143
+	}
144
+
145
+
146
+
147
+	/** HORIZONTAL TEXT LINKS **/
148
+
149
+	/**
150
+	 * This will take in an array of link items and spit out a formatted list of links that can be used to navigate to items.
151
+	 * There is a corresponding js file that can be loaded to dynamically display containers with the same id as the href -ref.
152
+	 *
153
+	 * @param  array $item_array      formatted array of items.  Format:
154
+	 * array(
155
+	 *      'label' => __('localized label displayed'),
156
+	 *      'class' => 'class_for_item',
157
+	 *      'href' => '#some_item_id', //url/bookmark for item.  If you include a bookmark the js will used this to show the container div.
158
+	 *      'title' => __('localized text for the title attribute of the link'),
159
+	 *      'slug' => 'slug_used_for_reference'
160
+	 * )
161
+	 * @param  string $container_class class used for main container
162
+	 * @param  string $sep              you can add in what is used as a separator between each link (or leave blank for none)
163
+	 * @param string $default           You can include a string for the item that will receive the "item_display" class for the js.
164
+	 * @return string                  a html snippet of of all the formatted link elements.
165
+	 */
166
+	public static function tab_text_links($item_array, $container_class = '', $sep = '|', $default = '')
167
+	{
168
+		$item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class);
169
+		if (!is_array($item_array) || empty($item_array)) {
170
+			return false; // get out we don't have even the basic thing we need!
171
+		}
172
+
173
+
174
+		$defaults = array(
175
+			'label' => __('Item', 'event_espresso'),
176
+			'class' => '',
177
+			'href' => '',
178
+			'title' => esc_attr__('Link for Item', 'event_espresso'),
179
+			'slug' => 'item_slug'
180
+		);
181
+		$container_class = !empty($container_class) ? 'ee-text-links ' . $container_class : 'ee-text-links';
182
+		$list = '<ul class="' . $container_class . '">';
183
+
184
+		$ci = 1;
185
+		foreach ($item_array as $item) {
186
+			$item = wp_parse_args($item, $defaults);
187
+			$item['class'] = !empty($default) && $default == $item['slug'] ? 'item_display ' . $item['class'] : $item['class'];
188
+			$list .= self::_text_link_item($item);
189
+			if (!empty($sep) && $ci != count($item_array)) {
190
+				$list .= self::_text_link_item($sep);
191
+			}
192
+			$ci++;
193
+		}
194
+
195
+		$list .= '</ul>';
196
+		return $list;
197
+	}
198
+
199
+
200
+
201
+	private static function _text_link_item($item)
202
+	{
203
+		// if this isn't an array then we're doing a separator
204
+		if (!is_array($item)) {
205
+			$label = $item;
206
+			$class = 'ee-text-link-sep';
207
+			$href = '';
208
+			$title = '';
209
+		} else {
210
+			extract($item);
211
+		}
212
+
213
+		$class = $class != 'ee-text-link-sep'  ? 'class="ee-text-link-li ' . $class . '"' : 'class="ee-text-link-sep"';
214
+
215
+		$content = '<li ' . $class . '>';
216
+		$content .= !empty($href) ? '<a class="ee-text-link" href="#' . $href . '" title="' . $title . '">' : '';
217
+		$content .= $label;
218
+		$content .= !empty($href) ? '</a>' : '';
219
+		$content .= '</li>';
220
+		return $content;
221
+	}
222 222
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -36,22 +36,22 @@  discard block
 block discarded – undo
36 36
     {
37 37
 
38 38
         // first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston
39
-        if (!empty($tabs_names) && ( count((array) $tabs_names) != count((array) $tabs_content) )) {
39
+        if ( ! empty($tabs_names) && (count((array) $tabs_names) != count((array) $tabs_content))) {
40 40
             throw new EE_Error(__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso'));
41 41
         }
42 42
 
43 43
         // make sure we've got incoming data setup properly
44
-        $tabs = !empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents);
45
-        $tabs_content = !empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents;
44
+        $tabs = ! empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents);
45
+        $tabs_content = ! empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents;
46 46
 
47
-        $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n";
47
+        $all_tabs = '<h2 class="nav-tab-wrapper">'."\n";
48 48
         $all_tabs_content = '';
49 49
 
50 50
         $index = 0;
51 51
         foreach ($tabs as $tab) {
52 52
             $active = $index === 0 ? true : false;
53 53
             $all_tabs .= self::tab($tab, $active);
54
-            $all_tabs_content .= self::tab_content($tab, $tabs_content[ $tab ], $active);
54
+            $all_tabs_content .= self::tab_content($tab, $tabs_content[$tab], $active);
55 55
             $index++;
56 56
         }
57 57
         /*
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 
66 66
         $tab_container_class = $small_tabs ? 'ee-nav-tabs ee-nav-tabs-small' : 'ee-nav-tabs';
67 67
 
68
-        return '<div class="'. $tab_container_class . '">' . "\n\t" . $all_tabs . $all_tabs_content . "\n" . '</div>';
68
+        return '<div class="'.$tab_container_class.'">'."\n\t".$all_tabs.$all_tabs_content."\n".'</div>';
69 69
     }
70 70
 
71 71
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
             throw new EE_Error(__('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso'));
95 95
         }
96 96
 
97
-        $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n";
97
+        $all_tabs = '<h2 class="nav-tab-wrapper">'."\n";
98 98
         foreach ($nav_tabs as $slug => $tab) {
99 99
             $all_tabs .= self::tab($slug, false, $tab['link_text'], $tab['url'], $tab['css_class']);
100 100
         }
@@ -115,10 +115,10 @@  discard block
 block discarded – undo
115 115
     {
116 116
         $name = str_replace(' ', '-', $name);
117 117
         $class = $active ? 'nav-tab nav-tab-active' : 'nav-tab';
118
-        $class = $css ? $class . ' ' . $css : $class;
118
+        $class = $css ? $class.' '.$css : $class;
119 119
         $nice_name = $nice_name ? $nice_name : ucwords(preg_replace('/(-|_)/', ' ', $name));
120
-        $url = $url ? $url : '#' . $name;
121
-        $tab = '<a class="' . $class . '" rel="ee-tab-' . $name . '" href="' . $url . '">' . $nice_name . '</a>' . "\n\t";
120
+        $url = $url ? $url : '#'.$name;
121
+        $tab = '<a class="'.$class.'" rel="ee-tab-'.$name.'" href="'.$url.'">'.$nice_name.'</a>'."\n\t";
122 122
         return $tab;
123 123
     }
124 124
 
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
     {
137 137
         $class = $active ? 'nav-tab-content' : 'nav-tab-content hidden';
138 138
         $name = str_replace(' ', '-', $name);
139
-        $content = "\t" . '<div class="'. $class . '" id="ee-tab-' . $name . '">' . "\n";
140
-        $content .= "\t" . $tab_content . "\n";
139
+        $content = "\t".'<div class="'.$class.'" id="ee-tab-'.$name.'">'."\n";
140
+        $content .= "\t".$tab_content."\n";
141 141
         $content .= '<div style="clear:both"></div></div>';
142 142
         return $content;
143 143
     }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
     public static function tab_text_links($item_array, $container_class = '', $sep = '|', $default = '')
167 167
     {
168 168
         $item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class);
169
-        if (!is_array($item_array) || empty($item_array)) {
169
+        if ( ! is_array($item_array) || empty($item_array)) {
170 170
             return false; // get out we don't have even the basic thing we need!
171 171
         }
172 172
 
@@ -178,15 +178,15 @@  discard block
 block discarded – undo
178 178
             'title' => esc_attr__('Link for Item', 'event_espresso'),
179 179
             'slug' => 'item_slug'
180 180
         );
181
-        $container_class = !empty($container_class) ? 'ee-text-links ' . $container_class : 'ee-text-links';
182
-        $list = '<ul class="' . $container_class . '">';
181
+        $container_class = ! empty($container_class) ? 'ee-text-links '.$container_class : 'ee-text-links';
182
+        $list = '<ul class="'.$container_class.'">';
183 183
 
184 184
         $ci = 1;
185 185
         foreach ($item_array as $item) {
186 186
             $item = wp_parse_args($item, $defaults);
187
-            $item['class'] = !empty($default) && $default == $item['slug'] ? 'item_display ' . $item['class'] : $item['class'];
187
+            $item['class'] = ! empty($default) && $default == $item['slug'] ? 'item_display '.$item['class'] : $item['class'];
188 188
             $list .= self::_text_link_item($item);
189
-            if (!empty($sep) && $ci != count($item_array)) {
189
+            if ( ! empty($sep) && $ci != count($item_array)) {
190 190
                 $list .= self::_text_link_item($sep);
191 191
             }
192 192
             $ci++;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     private static function _text_link_item($item)
202 202
     {
203 203
         // if this isn't an array then we're doing a separator
204
-        if (!is_array($item)) {
204
+        if ( ! is_array($item)) {
205 205
             $label = $item;
206 206
             $class = 'ee-text-link-sep';
207 207
             $href = '';
@@ -210,12 +210,12 @@  discard block
 block discarded – undo
210 210
             extract($item);
211 211
         }
212 212
 
213
-        $class = $class != 'ee-text-link-sep'  ? 'class="ee-text-link-li ' . $class . '"' : 'class="ee-text-link-sep"';
213
+        $class = $class != 'ee-text-link-sep' ? 'class="ee-text-link-li '.$class.'"' : 'class="ee-text-link-sep"';
214 214
 
215
-        $content = '<li ' . $class . '>';
216
-        $content .= !empty($href) ? '<a class="ee-text-link" href="#' . $href . '" title="' . $title . '">' : '';
215
+        $content = '<li '.$class.'>';
216
+        $content .= ! empty($href) ? '<a class="ee-text-link" href="#'.$href.'" title="'.$title.'">' : '';
217 217
         $content .= $label;
218
-        $content .= !empty($href) ? '</a>' : '';
218
+        $content .= ! empty($href) ? '</a>' : '';
219 219
         $content .= '</li>';
220 220
         return $content;
221 221
     }
Please login to merge, or discard this patch.