Completed
Branch FET/paypal-add-support-for-INR (235cd4)
by
unknown
55:13 queued 41:19
created
core/libraries/rest_api/CalculatedModelFields.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      */
38 38
     public function mapping($refresh = false)
39 39
     {
40
-        if (! $this->mapping || $refresh) {
40
+        if ( ! $this->mapping || $refresh) {
41 41
             $this->mapping = $this->generateNewMapping();
42 42
         }
43 43
         return $this->mapping;
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
     protected function generateNewMapping()
53 53
     {
54 54
         $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\';
55
-        $event_calculations_class = $rest_api_calculations_namespace . 'Event';
56
-        $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime';
57
-        $registration_class = $rest_api_calculations_namespace . 'Registration';
58
-        $attendee_class = $rest_api_calculations_namespace . 'Attendee';
55
+        $event_calculations_class = $rest_api_calculations_namespace.'Event';
56
+        $datetime_calculations_class = $rest_api_calculations_namespace.'Datetime';
57
+        $registration_class = $rest_api_calculations_namespace.'Registration';
58
+        $attendee_class = $rest_api_calculations_namespace.'Attendee';
59 59
         return apply_filters(
60 60
             'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping',
61 61
             array(
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
     public function retrieveCalculatedFieldsForModel(EEM_Base $model)
101 101
     {
102 102
         $mapping = $this->mapping();
103
-        if (isset($mapping[ $model->get_this_model_name() ])) {
104
-            return array_keys($mapping[ $model->get_this_model_name() ]);
103
+        if (isset($mapping[$model->get_this_model_name()])) {
104
+            return array_keys($mapping[$model->get_this_model_name()]);
105 105
         } else {
106 106
             return array();
107 107
         }
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
         Base $controller
128 128
     ) {
129 129
         $mapping = $this->mapping();
130
-        if (isset($mapping[ $model->get_this_model_name() ])
131
-            && isset($mapping[ $model->get_this_model_name() ][ $field_name ])
130
+        if (isset($mapping[$model->get_this_model_name()])
131
+            && isset($mapping[$model->get_this_model_name()][$field_name])
132 132
         ) {
133
-            $classname = $mapping[ $model->get_this_model_name() ][ $field_name ];
133
+            $classname = $mapping[$model->get_this_model_name()][$field_name];
134 134
             $class_method_name = EEH_Inflector::camelize_all_but_first($field_name);
135 135
             return call_user_func(array($classname, $class_method_name), $wpdb_row, $rest_request, $controller);
136 136
         }
Please login to merge, or discard this patch.
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -19,128 +19,128 @@
 block discarded – undo
19 19
 class CalculatedModelFields
20 20
 {
21 21
 
22
-    /**
23
-     * @var array
24
-     */
25
-    protected $mapping;
22
+	/**
23
+	 * @var array
24
+	 */
25
+	protected $mapping;
26 26
 
27 27
 
28
-    /**
29
-     * @param bool $refresh
30
-     * @return array top-level-keys are model names (eg "Event")
31
-     * next-level are the calculated field names AND method names on classes
32
-     * which perform calculations, values are the fully qualified classnames which do the calculations
33
-     * These callbacks should accept as arguments:
34
-     * the wpdb row results,
35
-     * the WP_Request object,
36
-     * the controller object
37
-     */
38
-    public function mapping($refresh = false)
39
-    {
40
-        if (! $this->mapping || $refresh) {
41
-            $this->mapping = $this->generateNewMapping();
42
-        }
43
-        return $this->mapping;
44
-    }
28
+	/**
29
+	 * @param bool $refresh
30
+	 * @return array top-level-keys are model names (eg "Event")
31
+	 * next-level are the calculated field names AND method names on classes
32
+	 * which perform calculations, values are the fully qualified classnames which do the calculations
33
+	 * These callbacks should accept as arguments:
34
+	 * the wpdb row results,
35
+	 * the WP_Request object,
36
+	 * the controller object
37
+	 */
38
+	public function mapping($refresh = false)
39
+	{
40
+		if (! $this->mapping || $refresh) {
41
+			$this->mapping = $this->generateNewMapping();
42
+		}
43
+		return $this->mapping;
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * Generates  anew mapping between model calculated fields and their callbacks
49
-     *
50
-     * @return array
51
-     */
52
-    protected function generateNewMapping()
53
-    {
54
-        $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\';
55
-        $event_calculations_class = $rest_api_calculations_namespace . 'Event';
56
-        $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime';
57
-        $registration_class = $rest_api_calculations_namespace . 'Registration';
58
-        $attendee_class = $rest_api_calculations_namespace . 'Attendee';
59
-        return apply_filters(
60
-            'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping',
61
-            array(
62
-                'Event'        => array(
63
-                    'optimum_sales_at_start'          => $event_calculations_class,
64
-                    'optimum_sales_now'               => $event_calculations_class,
65
-                    'spots_taken'                     => $event_calculations_class,
66
-                    'spots_taken_pending_payment'     => $event_calculations_class,
67
-                    'spaces_remaining'                => $event_calculations_class,
68
-                    'registrations_checked_in_count'  => $event_calculations_class,
69
-                    'registrations_checked_out_count' => $event_calculations_class,
70
-                    'image_thumbnail'                 => $event_calculations_class,
71
-                    'image_medium'                    => $event_calculations_class,
72
-                    'image_medium_large'              => $event_calculations_class,
73
-                    'image_large'                     => $event_calculations_class,
74
-                    'image_post_thumbnail'            => $event_calculations_class,
75
-                    'image_full'                      => $event_calculations_class,
76
-                ),
77
-                'Datetime'     => array(
78
-                    'spaces_remaining_considering_tickets' => $datetime_calculations_class,
79
-                    'registrations_checked_in_count'       => $datetime_calculations_class,
80
-                    'registrations_checked_out_count'      => $datetime_calculations_class,
81
-                    'spots_taken_pending_payment'          => $datetime_calculations_class,
82
-                ),
83
-                'Registration' => array(
84
-                    'datetime_checkin_stati' => $registration_class,
85
-                ),
86
-                'Attendee' => array(
87
-                    'user_avatar' => $attendee_class,
88
-                ),
89
-            )
90
-        );
91
-    }
47
+	/**
48
+	 * Generates  anew mapping between model calculated fields and their callbacks
49
+	 *
50
+	 * @return array
51
+	 */
52
+	protected function generateNewMapping()
53
+	{
54
+		$rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\';
55
+		$event_calculations_class = $rest_api_calculations_namespace . 'Event';
56
+		$datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime';
57
+		$registration_class = $rest_api_calculations_namespace . 'Registration';
58
+		$attendee_class = $rest_api_calculations_namespace . 'Attendee';
59
+		return apply_filters(
60
+			'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping',
61
+			array(
62
+				'Event'        => array(
63
+					'optimum_sales_at_start'          => $event_calculations_class,
64
+					'optimum_sales_now'               => $event_calculations_class,
65
+					'spots_taken'                     => $event_calculations_class,
66
+					'spots_taken_pending_payment'     => $event_calculations_class,
67
+					'spaces_remaining'                => $event_calculations_class,
68
+					'registrations_checked_in_count'  => $event_calculations_class,
69
+					'registrations_checked_out_count' => $event_calculations_class,
70
+					'image_thumbnail'                 => $event_calculations_class,
71
+					'image_medium'                    => $event_calculations_class,
72
+					'image_medium_large'              => $event_calculations_class,
73
+					'image_large'                     => $event_calculations_class,
74
+					'image_post_thumbnail'            => $event_calculations_class,
75
+					'image_full'                      => $event_calculations_class,
76
+				),
77
+				'Datetime'     => array(
78
+					'spaces_remaining_considering_tickets' => $datetime_calculations_class,
79
+					'registrations_checked_in_count'       => $datetime_calculations_class,
80
+					'registrations_checked_out_count'      => $datetime_calculations_class,
81
+					'spots_taken_pending_payment'          => $datetime_calculations_class,
82
+				),
83
+				'Registration' => array(
84
+					'datetime_checkin_stati' => $registration_class,
85
+				),
86
+				'Attendee' => array(
87
+					'user_avatar' => $attendee_class,
88
+				),
89
+			)
90
+		);
91
+	}
92 92
 
93 93
 
94
-    /**
95
-     * Gets the known calculated fields for model
96
-     *
97
-     * @param EEM_Base $model
98
-     * @return array allowable values for this field
99
-     */
100
-    public function retrieveCalculatedFieldsForModel(EEM_Base $model)
101
-    {
102
-        $mapping = $this->mapping();
103
-        if (isset($mapping[ $model->get_this_model_name() ])) {
104
-            return array_keys($mapping[ $model->get_this_model_name() ]);
105
-        } else {
106
-            return array();
107
-        }
108
-    }
94
+	/**
95
+	 * Gets the known calculated fields for model
96
+	 *
97
+	 * @param EEM_Base $model
98
+	 * @return array allowable values for this field
99
+	 */
100
+	public function retrieveCalculatedFieldsForModel(EEM_Base $model)
101
+	{
102
+		$mapping = $this->mapping();
103
+		if (isset($mapping[ $model->get_this_model_name() ])) {
104
+			return array_keys($mapping[ $model->get_this_model_name() ]);
105
+		} else {
106
+			return array();
107
+		}
108
+	}
109 109
 
110 110
 
111
-    /**
112
-     * Retrieves the value for this calculation
113
-     *
114
-     * @param EEM_Base                                                $model
115
-     * @param string                                                  $field_name
116
-     * @param array                                                   $wpdb_row
117
-     * @param \WP_REST_Request
118
-     * @param \EventEspresso\core\libraries\rest_api\controllers\Base $controller
119
-     * @return mixed|null
120
-     * @throws \EE_Error
121
-     */
122
-    public function retrieveCalculatedFieldValue(
123
-        EEM_Base $model,
124
-        $field_name,
125
-        $wpdb_row,
126
-        $rest_request,
127
-        Base $controller
128
-    ) {
129
-        $mapping = $this->mapping();
130
-        if (isset($mapping[ $model->get_this_model_name() ])
131
-            && isset($mapping[ $model->get_this_model_name() ][ $field_name ])
132
-        ) {
133
-            $classname = $mapping[ $model->get_this_model_name() ][ $field_name ];
134
-            $class_method_name = EEH_Inflector::camelize_all_but_first($field_name);
135
-            return call_user_func(array($classname, $class_method_name), $wpdb_row, $rest_request, $controller);
136
-        }
137
-        throw new RestException(
138
-            'calculated_field_does_not_exist',
139
-            sprintf(
140
-                __('There is no calculated field %1$s on resource %2$s', 'event_espresso'),
141
-                $field_name,
142
-                $model->get_this_model_name()
143
-            )
144
-        );
145
-    }
111
+	/**
112
+	 * Retrieves the value for this calculation
113
+	 *
114
+	 * @param EEM_Base                                                $model
115
+	 * @param string                                                  $field_name
116
+	 * @param array                                                   $wpdb_row
117
+	 * @param \WP_REST_Request
118
+	 * @param \EventEspresso\core\libraries\rest_api\controllers\Base $controller
119
+	 * @return mixed|null
120
+	 * @throws \EE_Error
121
+	 */
122
+	public function retrieveCalculatedFieldValue(
123
+		EEM_Base $model,
124
+		$field_name,
125
+		$wpdb_row,
126
+		$rest_request,
127
+		Base $controller
128
+	) {
129
+		$mapping = $this->mapping();
130
+		if (isset($mapping[ $model->get_this_model_name() ])
131
+			&& isset($mapping[ $model->get_this_model_name() ][ $field_name ])
132
+		) {
133
+			$classname = $mapping[ $model->get_this_model_name() ][ $field_name ];
134
+			$class_method_name = EEH_Inflector::camelize_all_but_first($field_name);
135
+			return call_user_func(array($classname, $class_method_name), $wpdb_row, $rest_request, $controller);
136
+		}
137
+		throw new RestException(
138
+			'calculated_field_does_not_exist',
139
+			sprintf(
140
+				__('There is no calculated field %1$s on resource %2$s', 'event_espresso'),
141
+				$field_name,
142
+				$model->get_this_model_name()
143
+			)
144
+		);
145
+	}
146 146
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Venue_View.helper.php 1 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') . '…');
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/libraries/rest_api/calculations/Attendee.php 2 patches
Unused Use Statements   -6 removed lines patch added patch discarded remove patch
@@ -2,14 +2,8 @@
 block discarded – undo
2 2
 
3 3
 namespace EventEspresso\core\libraries\rest_api\calculations;
4 4
 
5
-use EE_Attendee;
6
-use EE_Error;
7
-use EEM_Attendee;
8
-use EventEspresso\core\exceptions\InvalidDataTypeException;
9
-use EventEspresso\core\exceptions\InvalidInterfaceException;
10 5
 use EventEspresso\core\libraries\rest_api\calculations\Base as Calculations_Base;
11 6
 use EventEspresso\core\libraries\rest_api\controllers\model\Base;
12
-use InvalidArgumentException;
13 7
 use WP_REST_Request;
14 8
 
15 9
 /**
Please login to merge, or discard this patch.
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -23,22 +23,22 @@
 block discarded – undo
23 23
 class Attendee extends Calculations_Base
24 24
 {
25 25
 
26
-    /**
27
-     * @param array           $wpdb_row
28
-     * @param WP_REST_Request $request
29
-     * @param Base            $controller
30
-     * @since $VID:$
31
-     * @return string
32
-     */
33
-    public static function userAvatar(array $wpdb_row, WP_REST_Request $request, Base $controller)
34
-    {
35
-        if (is_array($wpdb_row) && isset($wpdb_row['Attendee_Meta.ATT_email'])) {
36
-            $email_address = $wpdb_row['Attendee_Meta.ATT_email'];
37
-        }
38
-        if (empty($email_address)) {
39
-            return '';
40
-        }
41
-        $avatar = get_avatar_url($email_address);
42
-        return $avatar ? $avatar : '';
43
-    }
26
+	/**
27
+	 * @param array           $wpdb_row
28
+	 * @param WP_REST_Request $request
29
+	 * @param Base            $controller
30
+	 * @since $VID:$
31
+	 * @return string
32
+	 */
33
+	public static function userAvatar(array $wpdb_row, WP_REST_Request $request, Base $controller)
34
+	{
35
+		if (is_array($wpdb_row) && isset($wpdb_row['Attendee_Meta.ATT_email'])) {
36
+			$email_address = $wpdb_row['Attendee_Meta.ATT_email'];
37
+		}
38
+		if (empty($email_address)) {
39
+			return '';
40
+		}
41
+		$avatar = get_avatar_url($email_address);
42
+		return $avatar ? $avatar : '';
43
+	}
44 44
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.66.rc.013');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.66.rc.013');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.