Completed
Branch EDTR/master (af42c6)
by
unknown
50:36 queued 42:13
created
core/EE_Data_Mapper.core.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -15,98 +15,98 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * instance of the EE_Data_Mapper Object
20
-     *
21
-     * @private _instance
22
-     */
23
-    private static $_instance = null;
24
-
25
-
26
-    public $data = array();
27
-
28
-
29
-    /**
30
-     *private constructor to prevent direct creation
31
-     *
32
-     * @Constructor
33
-     * @access private
34
-     * @return void
35
-     */
36
-    private function __construct()
37
-    {
38
-    }
39
-
40
-
41
-    /**
42
-     *@ singleton method used to instantiate class object
43
-     *@ access public
44
-     *@ return class instance
45
-     */
46
-    public function &instance()
47
-    {
48
-        // check if class object is instantiated
49
-        if (self::$_instance === null
50
-            || ! is_object(self::$_instance)
51
-            || ! self::$_instance instanceof EE_Data_Mapper
52
-        ) {
53
-            self::$_instance = new self();
54
-        }
55
-        return self::$_instance;
56
-    }
57
-
58
-
59
-    /**
60
-     *        @ override magic methods
61
-     *        @ return void
62
-     */
63
-    final public function __destruct()
64
-    {
65
-    }
66
-
67
-    final public function __call($a, $b)
68
-    {
69
-    }
70
-
71
-    public static function __callStatic($a, $b)
72
-    {
73
-    }
74
-
75
-    final public function __get($a)
76
-    {
77
-    }
78
-
79
-    final public function __set($a, $b)
80
-    {
81
-    }
82
-
83
-    final public function __isset($a)
84
-    {
85
-    }
86
-
87
-    final public function __unset($a)
88
-    {
89
-    }
90
-
91
-    final public function __sleep()
92
-    {
93
-        return array();
94
-    }
95
-
96
-    final public function __wakeup()
97
-    {
98
-    }
99
-
100
-    final public function __toString()
101
-    {
102
-        return '';
103
-    }
104
-
105
-    final public function __invoke()
106
-    {
107
-    }
108
-
109
-    final public function __clone()
110
-    {
111
-    }
18
+	/**
19
+	 * instance of the EE_Data_Mapper Object
20
+	 *
21
+	 * @private _instance
22
+	 */
23
+	private static $_instance = null;
24
+
25
+
26
+	public $data = array();
27
+
28
+
29
+	/**
30
+	 *private constructor to prevent direct creation
31
+	 *
32
+	 * @Constructor
33
+	 * @access private
34
+	 * @return void
35
+	 */
36
+	private function __construct()
37
+	{
38
+	}
39
+
40
+
41
+	/**
42
+	 *@ singleton method used to instantiate class object
43
+	 *@ access public
44
+	 *@ return class instance
45
+	 */
46
+	public function &instance()
47
+	{
48
+		// check if class object is instantiated
49
+		if (self::$_instance === null
50
+			|| ! is_object(self::$_instance)
51
+			|| ! self::$_instance instanceof EE_Data_Mapper
52
+		) {
53
+			self::$_instance = new self();
54
+		}
55
+		return self::$_instance;
56
+	}
57
+
58
+
59
+	/**
60
+	 *        @ override magic methods
61
+	 *        @ return void
62
+	 */
63
+	final public function __destruct()
64
+	{
65
+	}
66
+
67
+	final public function __call($a, $b)
68
+	{
69
+	}
70
+
71
+	public static function __callStatic($a, $b)
72
+	{
73
+	}
74
+
75
+	final public function __get($a)
76
+	{
77
+	}
78
+
79
+	final public function __set($a, $b)
80
+	{
81
+	}
82
+
83
+	final public function __isset($a)
84
+	{
85
+	}
86
+
87
+	final public function __unset($a)
88
+	{
89
+	}
90
+
91
+	final public function __sleep()
92
+	{
93
+		return array();
94
+	}
95
+
96
+	final public function __wakeup()
97
+	{
98
+	}
99
+
100
+	final public function __toString()
101
+	{
102
+		return '';
103
+	}
104
+
105
+	final public function __invoke()
106
+	{
107
+	}
108
+
109
+	final public function __clone()
110
+	{
111
+	}
112 112
 }
Please login to merge, or discard this patch.
core/EE_Addon.core.php 2 patches
Indentation   +821 added lines, -821 removed lines patch added patch discarded remove patch
@@ -19,790 +19,790 @@  discard block
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * prefix to be added onto an addon's plugin slug to make a wp option name
24
-     * which will be used to store the plugin's activation history
25
-     */
26
-    const ee_addon_version_history_option_prefix = 'ee_version_history_';
27
-
28
-    /**
29
-     * @var $_version
30
-     * @type string
31
-     */
32
-    protected $_version = '';
33
-
34
-    /**
35
-     * @var $_min_core_version
36
-     * @type string
37
-     */
38
-    protected $_min_core_version = '';
39
-
40
-    /**
41
-     * derived from plugin 'main_file_path using plugin_basename()
42
-     *
43
-     * @type string $_plugin_basename
44
-     */
45
-    protected $_plugin_basename = '';
46
-
47
-    /**
48
-     * A non-internationalized name to identify this addon for use in URLs, etc
49
-     *
50
-     * @type string $_plugin_slug
51
-     */
52
-    protected $_plugin_slug = '';
53
-
54
-    /**
55
-     * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
56
-     *
57
-     * @type string _addon_name
58
-     */
59
-    protected $_addon_name = '';
60
-
61
-    /**
62
-     * one of the EE_System::req_type_* constants
63
-     *
64
-     * @type int $_req_type
65
-     */
66
-    protected $_req_type;
67
-
68
-    /**
69
-     * page slug to be used when generating the "Settings" link on the WP plugin page
70
-     *
71
-     * @type string $_plugin_action_slug
72
-     */
73
-    protected $_plugin_action_slug = '';
74
-
75
-    /**
76
-     * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
77
-     * that can be used for adding upgrading/marketing info
78
-     *
79
-     * @type array $_plugins_page_row
80
-     */
81
-    protected $_plugins_page_row = array();
82
-
83
-
84
-    /**
85
-     *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
86
-     *
87
-     * @type string
88
-     */
89
-    protected $_main_plugin_file;
90
-
91
-
92
-    /**
93
-     * @var EE_Dependency_Map $dependency_map
94
-     */
95
-    private $dependency_map;
96
-
97
-
98
-    /**
99
-     * @var DomainInterface $domain
100
-     */
101
-    private $domain;
102
-
103
-
104
-    /**
105
-     * @param EE_Dependency_Map $dependency_map [optional]
106
-     * @param DomainInterface   $domain         [optional]
107
-     */
108
-    public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null)
109
-    {
110
-        if ($dependency_map instanceof EE_Dependency_Map) {
111
-            $this->setDependencyMap($dependency_map);
112
-        }
113
-        if ($domain instanceof DomainInterface) {
114
-            $this->setDomain($domain);
115
-        }
116
-        add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
117
-    }
118
-
119
-
120
-    /**
121
-     * @param EE_Dependency_Map $dependency_map
122
-     */
123
-    public function setDependencyMap($dependency_map)
124
-    {
125
-        $this->dependency_map = $dependency_map;
126
-    }
127
-
128
-
129
-    /**
130
-     * @return EE_Dependency_Map
131
-     */
132
-    public function dependencyMap()
133
-    {
134
-        return $this->dependency_map;
135
-    }
136
-
137
-
138
-    /**
139
-     * @param DomainInterface $domain
140
-     */
141
-    public function setDomain(DomainInterface $domain)
142
-    {
143
-        $this->domain = $domain;
144
-    }
145
-
146
-    /**
147
-     * @return DomainInterface
148
-     */
149
-    public function domain()
150
-    {
151
-        return $this->domain;
152
-    }
153
-
154
-
155
-    /**
156
-     * @param mixed $version
157
-     */
158
-    public function set_version($version = null)
159
-    {
160
-        $this->_version = $version;
161
-    }
162
-
163
-
164
-    /**
165
-     * get__version
166
-     *
167
-     * @return string
168
-     */
169
-    public function version()
170
-    {
171
-        return $this->_version;
172
-    }
173
-
174
-
175
-    /**
176
-     * @param mixed $min_core_version
177
-     */
178
-    public function set_min_core_version($min_core_version = null)
179
-    {
180
-        $this->_min_core_version = $min_core_version;
181
-    }
182
-
183
-
184
-    /**
185
-     * get__min_core_version
186
-     *
187
-     * @return string
188
-     */
189
-    public function min_core_version()
190
-    {
191
-        return $this->_min_core_version;
192
-    }
193
-
194
-
195
-    /**
196
-     * Sets addon_name
197
-     *
198
-     * @param string $addon_name
199
-     * @return boolean
200
-     */
201
-    public function set_name($addon_name)
202
-    {
203
-        return $this->_addon_name = $addon_name;
204
-    }
205
-
206
-
207
-    /**
208
-     * Gets addon_name
209
-     *
210
-     * @return string
211
-     */
212
-    public function name()
213
-    {
214
-        return $this->_addon_name;
215
-    }
216
-
217
-
218
-    /**
219
-     * @return string
220
-     */
221
-    public function plugin_basename()
222
-    {
223
-
224
-        return $this->_plugin_basename;
225
-    }
226
-
227
-
228
-    /**
229
-     * @param string $plugin_basename
230
-     */
231
-    public function set_plugin_basename($plugin_basename)
232
-    {
233
-
234
-        $this->_plugin_basename = $plugin_basename;
235
-    }
236
-
237
-
238
-    /**
239
-     * @return string
240
-     */
241
-    public function plugin_slug()
242
-    {
243
-
244
-        return $this->_plugin_slug;
245
-    }
246
-
247
-
248
-    /**
249
-     * @param string $plugin_slug
250
-     */
251
-    public function set_plugin_slug($plugin_slug)
252
-    {
253
-
254
-        $this->_plugin_slug = $plugin_slug;
255
-    }
256
-
257
-
258
-    /**
259
-     * @return string
260
-     */
261
-    public function plugin_action_slug()
262
-    {
263
-
264
-        return $this->_plugin_action_slug;
265
-    }
266
-
267
-
268
-    /**
269
-     * @param string $plugin_action_slug
270
-     */
271
-    public function set_plugin_action_slug($plugin_action_slug)
272
-    {
273
-
274
-        $this->_plugin_action_slug = $plugin_action_slug;
275
-    }
276
-
277
-
278
-    /**
279
-     * @return array
280
-     */
281
-    public function get_plugins_page_row()
282
-    {
283
-
284
-        return $this->_plugins_page_row;
285
-    }
286
-
287
-
288
-    /**
289
-     * @param array $plugins_page_row
290
-     */
291
-    public function set_plugins_page_row($plugins_page_row = array())
292
-    {
293
-        // sigh.... check for example content that I stupidly merged to master and remove it if found
294
-        if (! is_array($plugins_page_row)
295
-            && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
296
-        ) {
297
-            $plugins_page_row = array();
298
-        }
299
-        $this->_plugins_page_row = (array) $plugins_page_row;
300
-    }
301
-
302
-
303
-    /**
304
-     * Called when EE core detects this addon has been activated for the first time.
305
-     * If the site isn't in maintenance mode, should setup the addon's database
306
-     *
307
-     * @return void
308
-     */
309
-    public function new_install()
310
-    {
311
-        $classname = get_class($this);
312
-        do_action("AHEE__{$classname}__new_install");
313
-        do_action('AHEE__EE_Addon__new_install', $this);
314
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
315
-        add_action(
316
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
317
-            array($this, 'initialize_db_if_no_migrations_required')
318
-        );
319
-    }
320
-
321
-
322
-    /**
323
-     * Called when EE core detects this addon has been reactivated. When this happens,
324
-     * it's good to just check that your data is still intact
325
-     *
326
-     * @return void
327
-     */
328
-    public function reactivation()
329
-    {
330
-        $classname = get_class($this);
331
-        do_action("AHEE__{$classname}__reactivation");
332
-        do_action('AHEE__EE_Addon__reactivation', $this);
333
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
334
-        add_action(
335
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
336
-            array($this, 'initialize_db_if_no_migrations_required')
337
-        );
338
-    }
339
-
340
-
341
-    /**
342
-     * Called when the registered deactivation hook for this addon fires.
343
-     *
344
-     * @throws EE_Error
345
-     */
346
-    public function deactivation()
347
-    {
348
-        $classname = get_class($this);
349
-        do_action("AHEE__{$classname}__deactivation");
350
-        do_action('AHEE__EE_Addon__deactivation', $this);
351
-        // check if the site no longer needs to be in maintenance mode
352
-        EE_Register_Addon::deregister($this->name());
353
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
354
-    }
355
-
356
-
357
-    /**
358
-     * Takes care of double-checking that we're not in maintenance mode, and then
359
-     * initializing this addon's necessary initial data. This is called by default on new activations
360
-     * and reactivations.
361
-     *
362
-     * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
363
-     *                               This is a resource-intensive job so we prefer to only do it when necessary
364
-     * @return void
365
-     * @throws \EE_Error
366
-     * @throws InvalidInterfaceException
367
-     * @throws InvalidDataTypeException
368
-     * @throws InvalidArgumentException
369
-     */
370
-    public function initialize_db_if_no_migrations_required($verify_schema = true)
371
-    {
372
-        if ($verify_schema === '') {
373
-            // wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
374
-            // (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
375
-            // calls them with an argument of an empty string (ie ""), which evaluates to false
376
-            // so we need to treat the empty string as if nothing had been passed, and should instead use the default
377
-            $verify_schema = true;
378
-        }
379
-        if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
380
-            if ($verify_schema) {
381
-                $this->initialize_db();
382
-            }
383
-            $this->initialize_default_data();
384
-            // @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
385
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to(
386
-                array(
387
-                    'slug'    => $this->name(),
388
-                    'version' => $this->version(),
389
-                )
390
-            );
391
-            /* make sure core's data is a-ok
22
+	/**
23
+	 * prefix to be added onto an addon's plugin slug to make a wp option name
24
+	 * which will be used to store the plugin's activation history
25
+	 */
26
+	const ee_addon_version_history_option_prefix = 'ee_version_history_';
27
+
28
+	/**
29
+	 * @var $_version
30
+	 * @type string
31
+	 */
32
+	protected $_version = '';
33
+
34
+	/**
35
+	 * @var $_min_core_version
36
+	 * @type string
37
+	 */
38
+	protected $_min_core_version = '';
39
+
40
+	/**
41
+	 * derived from plugin 'main_file_path using plugin_basename()
42
+	 *
43
+	 * @type string $_plugin_basename
44
+	 */
45
+	protected $_plugin_basename = '';
46
+
47
+	/**
48
+	 * A non-internationalized name to identify this addon for use in URLs, etc
49
+	 *
50
+	 * @type string $_plugin_slug
51
+	 */
52
+	protected $_plugin_slug = '';
53
+
54
+	/**
55
+	 * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
56
+	 *
57
+	 * @type string _addon_name
58
+	 */
59
+	protected $_addon_name = '';
60
+
61
+	/**
62
+	 * one of the EE_System::req_type_* constants
63
+	 *
64
+	 * @type int $_req_type
65
+	 */
66
+	protected $_req_type;
67
+
68
+	/**
69
+	 * page slug to be used when generating the "Settings" link on the WP plugin page
70
+	 *
71
+	 * @type string $_plugin_action_slug
72
+	 */
73
+	protected $_plugin_action_slug = '';
74
+
75
+	/**
76
+	 * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
77
+	 * that can be used for adding upgrading/marketing info
78
+	 *
79
+	 * @type array $_plugins_page_row
80
+	 */
81
+	protected $_plugins_page_row = array();
82
+
83
+
84
+	/**
85
+	 *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
86
+	 *
87
+	 * @type string
88
+	 */
89
+	protected $_main_plugin_file;
90
+
91
+
92
+	/**
93
+	 * @var EE_Dependency_Map $dependency_map
94
+	 */
95
+	private $dependency_map;
96
+
97
+
98
+	/**
99
+	 * @var DomainInterface $domain
100
+	 */
101
+	private $domain;
102
+
103
+
104
+	/**
105
+	 * @param EE_Dependency_Map $dependency_map [optional]
106
+	 * @param DomainInterface   $domain         [optional]
107
+	 */
108
+	public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null)
109
+	{
110
+		if ($dependency_map instanceof EE_Dependency_Map) {
111
+			$this->setDependencyMap($dependency_map);
112
+		}
113
+		if ($domain instanceof DomainInterface) {
114
+			$this->setDomain($domain);
115
+		}
116
+		add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
117
+	}
118
+
119
+
120
+	/**
121
+	 * @param EE_Dependency_Map $dependency_map
122
+	 */
123
+	public function setDependencyMap($dependency_map)
124
+	{
125
+		$this->dependency_map = $dependency_map;
126
+	}
127
+
128
+
129
+	/**
130
+	 * @return EE_Dependency_Map
131
+	 */
132
+	public function dependencyMap()
133
+	{
134
+		return $this->dependency_map;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @param DomainInterface $domain
140
+	 */
141
+	public function setDomain(DomainInterface $domain)
142
+	{
143
+		$this->domain = $domain;
144
+	}
145
+
146
+	/**
147
+	 * @return DomainInterface
148
+	 */
149
+	public function domain()
150
+	{
151
+		return $this->domain;
152
+	}
153
+
154
+
155
+	/**
156
+	 * @param mixed $version
157
+	 */
158
+	public function set_version($version = null)
159
+	{
160
+		$this->_version = $version;
161
+	}
162
+
163
+
164
+	/**
165
+	 * get__version
166
+	 *
167
+	 * @return string
168
+	 */
169
+	public function version()
170
+	{
171
+		return $this->_version;
172
+	}
173
+
174
+
175
+	/**
176
+	 * @param mixed $min_core_version
177
+	 */
178
+	public function set_min_core_version($min_core_version = null)
179
+	{
180
+		$this->_min_core_version = $min_core_version;
181
+	}
182
+
183
+
184
+	/**
185
+	 * get__min_core_version
186
+	 *
187
+	 * @return string
188
+	 */
189
+	public function min_core_version()
190
+	{
191
+		return $this->_min_core_version;
192
+	}
193
+
194
+
195
+	/**
196
+	 * Sets addon_name
197
+	 *
198
+	 * @param string $addon_name
199
+	 * @return boolean
200
+	 */
201
+	public function set_name($addon_name)
202
+	{
203
+		return $this->_addon_name = $addon_name;
204
+	}
205
+
206
+
207
+	/**
208
+	 * Gets addon_name
209
+	 *
210
+	 * @return string
211
+	 */
212
+	public function name()
213
+	{
214
+		return $this->_addon_name;
215
+	}
216
+
217
+
218
+	/**
219
+	 * @return string
220
+	 */
221
+	public function plugin_basename()
222
+	{
223
+
224
+		return $this->_plugin_basename;
225
+	}
226
+
227
+
228
+	/**
229
+	 * @param string $plugin_basename
230
+	 */
231
+	public function set_plugin_basename($plugin_basename)
232
+	{
233
+
234
+		$this->_plugin_basename = $plugin_basename;
235
+	}
236
+
237
+
238
+	/**
239
+	 * @return string
240
+	 */
241
+	public function plugin_slug()
242
+	{
243
+
244
+		return $this->_plugin_slug;
245
+	}
246
+
247
+
248
+	/**
249
+	 * @param string $plugin_slug
250
+	 */
251
+	public function set_plugin_slug($plugin_slug)
252
+	{
253
+
254
+		$this->_plugin_slug = $plugin_slug;
255
+	}
256
+
257
+
258
+	/**
259
+	 * @return string
260
+	 */
261
+	public function plugin_action_slug()
262
+	{
263
+
264
+		return $this->_plugin_action_slug;
265
+	}
266
+
267
+
268
+	/**
269
+	 * @param string $plugin_action_slug
270
+	 */
271
+	public function set_plugin_action_slug($plugin_action_slug)
272
+	{
273
+
274
+		$this->_plugin_action_slug = $plugin_action_slug;
275
+	}
276
+
277
+
278
+	/**
279
+	 * @return array
280
+	 */
281
+	public function get_plugins_page_row()
282
+	{
283
+
284
+		return $this->_plugins_page_row;
285
+	}
286
+
287
+
288
+	/**
289
+	 * @param array $plugins_page_row
290
+	 */
291
+	public function set_plugins_page_row($plugins_page_row = array())
292
+	{
293
+		// sigh.... check for example content that I stupidly merged to master and remove it if found
294
+		if (! is_array($plugins_page_row)
295
+			&& strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
296
+		) {
297
+			$plugins_page_row = array();
298
+		}
299
+		$this->_plugins_page_row = (array) $plugins_page_row;
300
+	}
301
+
302
+
303
+	/**
304
+	 * Called when EE core detects this addon has been activated for the first time.
305
+	 * If the site isn't in maintenance mode, should setup the addon's database
306
+	 *
307
+	 * @return void
308
+	 */
309
+	public function new_install()
310
+	{
311
+		$classname = get_class($this);
312
+		do_action("AHEE__{$classname}__new_install");
313
+		do_action('AHEE__EE_Addon__new_install', $this);
314
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
315
+		add_action(
316
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
317
+			array($this, 'initialize_db_if_no_migrations_required')
318
+		);
319
+	}
320
+
321
+
322
+	/**
323
+	 * Called when EE core detects this addon has been reactivated. When this happens,
324
+	 * it's good to just check that your data is still intact
325
+	 *
326
+	 * @return void
327
+	 */
328
+	public function reactivation()
329
+	{
330
+		$classname = get_class($this);
331
+		do_action("AHEE__{$classname}__reactivation");
332
+		do_action('AHEE__EE_Addon__reactivation', $this);
333
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
334
+		add_action(
335
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
336
+			array($this, 'initialize_db_if_no_migrations_required')
337
+		);
338
+	}
339
+
340
+
341
+	/**
342
+	 * Called when the registered deactivation hook for this addon fires.
343
+	 *
344
+	 * @throws EE_Error
345
+	 */
346
+	public function deactivation()
347
+	{
348
+		$classname = get_class($this);
349
+		do_action("AHEE__{$classname}__deactivation");
350
+		do_action('AHEE__EE_Addon__deactivation', $this);
351
+		// check if the site no longer needs to be in maintenance mode
352
+		EE_Register_Addon::deregister($this->name());
353
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
354
+	}
355
+
356
+
357
+	/**
358
+	 * Takes care of double-checking that we're not in maintenance mode, and then
359
+	 * initializing this addon's necessary initial data. This is called by default on new activations
360
+	 * and reactivations.
361
+	 *
362
+	 * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
363
+	 *                               This is a resource-intensive job so we prefer to only do it when necessary
364
+	 * @return void
365
+	 * @throws \EE_Error
366
+	 * @throws InvalidInterfaceException
367
+	 * @throws InvalidDataTypeException
368
+	 * @throws InvalidArgumentException
369
+	 */
370
+	public function initialize_db_if_no_migrations_required($verify_schema = true)
371
+	{
372
+		if ($verify_schema === '') {
373
+			// wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
374
+			// (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
375
+			// calls them with an argument of an empty string (ie ""), which evaluates to false
376
+			// so we need to treat the empty string as if nothing had been passed, and should instead use the default
377
+			$verify_schema = true;
378
+		}
379
+		if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
380
+			if ($verify_schema) {
381
+				$this->initialize_db();
382
+			}
383
+			$this->initialize_default_data();
384
+			// @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
385
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to(
386
+				array(
387
+					'slug'    => $this->name(),
388
+					'version' => $this->version(),
389
+				)
390
+			);
391
+			/* make sure core's data is a-ok
392 392
              * (at the time of writing, we especially want to verify all the caps are present
393 393
              * because payment method type capabilities are added dynamically, and it's
394 394
              * possible this addon added a payment method. But it's also possible
395 395
              * other data needs to be verified)
396 396
              */
397
-            EEH_Activation::initialize_db_content();
398
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
399
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
400
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
401
-            );
402
-            $rewrite_rules->flushRewriteRules();
403
-            // in case there are lots of addons being activated at once, let's force garbage collection
404
-            // to help avoid memory limit errors
405
-            // EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
406
-            gc_collect_cycles();
407
-        } else {
408
-            // ask the data migration manager to init this addon's data
409
-            // when migrations are finished because we can't do it now
410
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
411
-        }
412
-    }
413
-
414
-
415
-    /**
416
-     * Used to setup this addon's database tables, but not necessarily any default
417
-     * data in them. The default is to actually use the most up-to-date data migration script
418
-     * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
419
-     * methods to setup the db.
420
-     */
421
-    public function initialize_db()
422
-    {
423
-        // find the migration script that sets the database to be compatible with the code
424
-        $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
425
-        if ($current_dms_name) {
426
-            $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
427
-            $current_data_migration_script->set_migrating(false);
428
-            $current_data_migration_script->schema_changes_before_migration();
429
-            $current_data_migration_script->schema_changes_after_migration();
430
-            if ($current_data_migration_script->get_errors()) {
431
-                foreach ($current_data_migration_script->get_errors() as $error) {
432
-                    EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
433
-                }
434
-            }
435
-        }
436
-        // if not DMS was found that should be ok. This addon just doesn't require any database changes
437
-        EE_Data_Migration_Manager::instance()->update_current_database_state_to(
438
-            array(
439
-                'slug'    => $this->name(),
440
-                'version' => $this->version(),
441
-            )
442
-        );
443
-    }
444
-
445
-
446
-    /**
447
-     * If you want to setup default data for the addon, override this method, and call
448
-     * parent::initialize_default_data() from within it. This is normally called
449
-     * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
450
-     * and should verify default data is present (but this is also called
451
-     * on reactivations and just after migrations, so please verify you actually want
452
-     * to ADD default data, because it may already be present).
453
-     * However, please call this parent (currently it just fires a hook which other
454
-     * addons may be depending on)
455
-     */
456
-    public function initialize_default_data()
457
-    {
458
-        /**
459
-         * Called when an addon is ensuring its default data is set (possibly called
460
-         * on a reactivation, so first check for the absence of other data before setting
461
-         * default data)
462
-         *
463
-         * @param EE_Addon $addon the addon that called this
464
-         */
465
-        do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
466
-        // override to insert default data. It is safe to use the models here
467
-        // because the site should not be in maintenance mode
468
-    }
469
-
470
-
471
-    /**
472
-     * EE Core detected that this addon has been upgraded. We should check if there
473
-     * are any new migration scripts, and if so put the site into maintenance mode until
474
-     * they're ran
475
-     *
476
-     * @return void
477
-     */
478
-    public function upgrade()
479
-    {
480
-        $classname = get_class($this);
481
-        do_action("AHEE__{$classname}__upgrade");
482
-        do_action('AHEE__EE_Addon__upgrade', $this);
483
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
484
-        // also it's possible there is new default data that needs to be added
485
-        add_action(
486
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
487
-            array($this, 'initialize_db_if_no_migrations_required')
488
-        );
489
-    }
490
-
491
-
492
-    /**
493
-     * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
494
-     */
495
-    public function downgrade()
496
-    {
497
-        $classname = get_class($this);
498
-        do_action("AHEE__{$classname}__downgrade");
499
-        do_action('AHEE__EE_Addon__downgrade', $this);
500
-        // it's possible there's old default data that needs to be double-checked
501
-        add_action(
502
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
503
-            array($this, 'initialize_db_if_no_migrations_required')
504
-        );
505
-    }
506
-
507
-
508
-    /**
509
-     * set_db_update_option_name
510
-     * Until we do something better, we'll just check for migration scripts upon
511
-     * plugin activation only. In the future, we'll want to do it on plugin updates too
512
-     *
513
-     * @return bool
514
-     */
515
-    public function set_db_update_option_name()
516
-    {
517
-        EE_Error::doing_it_wrong(
518
-            __FUNCTION__,
519
-            esc_html__(
520
-                'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
521
-                'event_espresso'
522
-            ),
523
-            '4.3.0.alpha.016'
524
-        );
525
-        // let's just handle this on the next request, ok? right now we're just not really ready
526
-        return $this->set_activation_indicator_option();
527
-    }
528
-
529
-
530
-    /**
531
-     * Returns the name of the activation indicator option
532
-     * (an option which is set temporarily to indicate that this addon was just activated)
533
-     *
534
-     * @deprecated since version 4.3.0.alpha.016
535
-     * @return string
536
-     */
537
-    public function get_db_update_option_name()
538
-    {
539
-        EE_Error::doing_it_wrong(
540
-            __FUNCTION__,
541
-            esc_html__(
542
-                'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
543
-                'event_espresso'
544
-            ),
545
-            '4.3.0.alpha.016'
546
-        );
547
-        return $this->get_activation_indicator_option_name();
548
-    }
549
-
550
-
551
-    /**
552
-     * When the addon is activated, this should be called to set a wordpress option that
553
-     * indicates it was activated. This is especially useful for detecting reactivations.
554
-     *
555
-     * @return bool
556
-     */
557
-    public function set_activation_indicator_option()
558
-    {
559
-        // let's just handle this on the next request, ok? right now we're just not really ready
560
-        return update_option($this->get_activation_indicator_option_name(), true);
561
-    }
562
-
563
-
564
-    /**
565
-     * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
566
-     *
567
-     * @return string
568
-     */
569
-    public function get_activation_indicator_option_name()
570
-    {
571
-        return 'ee_activation_' . $this->name();
572
-    }
573
-
574
-
575
-    /**
576
-     * Used by EE_System to set the request type of this addon. Should not be used by addon developers
577
-     *
578
-     * @param int $req_type
579
-     */
580
-    public function set_req_type($req_type)
581
-    {
582
-        $this->_req_type = $req_type;
583
-    }
584
-
585
-
586
-    /**
587
-     * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
588
-     * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
589
-     * EE_System when it is checking for new install or upgrades of addons
590
-     */
591
-    public function detect_req_type()
592
-    {
593
-        if (! $this->_req_type) {
594
-            $this->detect_activation_or_upgrade();
595
-        }
596
-        return $this->_req_type;
597
-    }
598
-
599
-
600
-    /**
601
-     * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
602
-     * Should only be called once per request
603
-     *
604
-     * @return void
605
-     */
606
-    public function detect_activation_or_upgrade()
607
-    {
608
-        $activation_history_for_addon = $this->get_activation_history();
609
-        $request_type = EE_System::detect_req_type_given_activation_history(
610
-            $activation_history_for_addon,
611
-            $this->get_activation_indicator_option_name(),
612
-            $this->version()
613
-        );
614
-        $this->set_req_type($request_type);
615
-        $classname = get_class($this);
616
-        switch ($request_type) {
617
-            case EE_System::req_type_new_activation:
618
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
619
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
620
-                $this->new_install();
621
-                $this->update_list_of_installed_versions($activation_history_for_addon);
622
-                break;
623
-            case EE_System::req_type_reactivation:
624
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
625
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
626
-                $this->reactivation();
627
-                $this->update_list_of_installed_versions($activation_history_for_addon);
628
-                break;
629
-            case EE_System::req_type_upgrade:
630
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
631
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
632
-                $this->upgrade();
633
-                $this->update_list_of_installed_versions($activation_history_for_addon);
634
-                break;
635
-            case EE_System::req_type_downgrade:
636
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
637
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
638
-                $this->downgrade();
639
-                $this->update_list_of_installed_versions($activation_history_for_addon);
640
-                break;
641
-            case EE_System::req_type_normal:
642
-            default:
643
-                break;
644
-        }
645
-
646
-        do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
647
-    }
648
-
649
-    /**
650
-     * Updates the version history for this addon
651
-     *
652
-     * @param array  $version_history
653
-     * @param string $current_version_to_add
654
-     * @return boolean success
655
-     */
656
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
657
-    {
658
-        if (! $version_history) {
659
-            $version_history = $this->get_activation_history();
660
-        }
661
-        if ($current_version_to_add === null) {
662
-            $current_version_to_add = $this->version();
663
-        }
664
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
665
-        // resave
666
-        return update_option($this->get_activation_history_option_name(), $version_history);
667
-    }
668
-
669
-    /**
670
-     * Gets the name of the wp option that stores the activation history
671
-     * of this addon
672
-     *
673
-     * @return string
674
-     */
675
-    public function get_activation_history_option_name()
676
-    {
677
-        return self::ee_addon_version_history_option_prefix . $this->name();
678
-    }
679
-
680
-
681
-    /**
682
-     * Gets the wp option which stores the activation history for this addon
683
-     *
684
-     * @return array
685
-     */
686
-    public function get_activation_history()
687
-    {
688
-        return get_option($this->get_activation_history_option_name(), null);
689
-    }
690
-
691
-
692
-    /**
693
-     * @param string $config_section
694
-     */
695
-    public function set_config_section($config_section = '')
696
-    {
697
-        $this->_config_section = ! empty($config_section) ? $config_section : 'addons';
698
-    }
699
-
700
-    /**
701
-     * Sets the filepath to the main plugin file
702
-     *
703
-     * @param string $filepath
704
-     */
705
-    public function set_main_plugin_file($filepath)
706
-    {
707
-        $this->_main_plugin_file = $filepath;
708
-    }
709
-
710
-    /**
711
-     * gets the filepath to teh main file
712
-     *
713
-     * @return string
714
-     */
715
-    public function get_main_plugin_file()
716
-    {
717
-        return $this->_main_plugin_file;
718
-    }
719
-
720
-    /**
721
-     * Gets the filename (no path) of the main file (the main file loaded
722
-     * by WP)
723
-     *
724
-     * @return string
725
-     */
726
-    public function get_main_plugin_file_basename()
727
-    {
728
-        return plugin_basename($this->get_main_plugin_file());
729
-    }
730
-
731
-    /**
732
-     * Gets the folder name which contains the main plugin file
733
-     *
734
-     * @return string
735
-     */
736
-    public function get_main_plugin_file_dirname()
737
-    {
738
-        return dirname($this->get_main_plugin_file());
739
-    }
740
-
741
-
742
-    /**
743
-     * sets hooks used in the admin
744
-     *
745
-     * @return void
746
-     */
747
-    public function admin_init()
748
-    {
749
-        // is admin and not in M-Mode ?
750
-        if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
751
-            add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
752
-            add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
753
-        }
754
-    }
755
-
756
-
757
-    /**
758
-     * plugin_actions
759
-     * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
760
-     *
761
-     * @param $links
762
-     * @param $file
763
-     * @return array
764
-     */
765
-    public function plugin_action_links($links, $file)
766
-    {
767
-        if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
768
-            // before other links
769
-            array_unshift(
770
-                $links,
771
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
772
-                . esc_html__('Settings', 'event_espresso')
773
-                . '</a>'
774
-            );
775
-        }
776
-        return $links;
777
-    }
778
-
779
-
780
-    /**
781
-     * after_plugin_row
782
-     * Add additional content to the plugins page plugin row
783
-     * Inserts another row
784
-     *
785
-     * @param $plugin_file
786
-     * @param $plugin_data
787
-     * @param $status
788
-     * @return void
789
-     */
790
-    public function after_plugin_row($plugin_file, $plugin_data, $status)
791
-    {
792
-        $after_plugin_row = '';
793
-        $plugins_page_row = $this->get_plugins_page_row();
794
-        if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
795
-            $class = $status ? 'active' : 'inactive';
796
-            $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
797
-            $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
798
-            $description = isset($plugins_page_row['description'])
799
-                ? $plugins_page_row['description']
800
-                : '';
801
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
802
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
803
-                $after_plugin_row .= '<th class="check-column" scope="row"></th>';
804
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
805
-                $after_plugin_row .= '<style>
397
+			EEH_Activation::initialize_db_content();
398
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
399
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
400
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
401
+			);
402
+			$rewrite_rules->flushRewriteRules();
403
+			// in case there are lots of addons being activated at once, let's force garbage collection
404
+			// to help avoid memory limit errors
405
+			// EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
406
+			gc_collect_cycles();
407
+		} else {
408
+			// ask the data migration manager to init this addon's data
409
+			// when migrations are finished because we can't do it now
410
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
411
+		}
412
+	}
413
+
414
+
415
+	/**
416
+	 * Used to setup this addon's database tables, but not necessarily any default
417
+	 * data in them. The default is to actually use the most up-to-date data migration script
418
+	 * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
419
+	 * methods to setup the db.
420
+	 */
421
+	public function initialize_db()
422
+	{
423
+		// find the migration script that sets the database to be compatible with the code
424
+		$current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
425
+		if ($current_dms_name) {
426
+			$current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
427
+			$current_data_migration_script->set_migrating(false);
428
+			$current_data_migration_script->schema_changes_before_migration();
429
+			$current_data_migration_script->schema_changes_after_migration();
430
+			if ($current_data_migration_script->get_errors()) {
431
+				foreach ($current_data_migration_script->get_errors() as $error) {
432
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
433
+				}
434
+			}
435
+		}
436
+		// if not DMS was found that should be ok. This addon just doesn't require any database changes
437
+		EE_Data_Migration_Manager::instance()->update_current_database_state_to(
438
+			array(
439
+				'slug'    => $this->name(),
440
+				'version' => $this->version(),
441
+			)
442
+		);
443
+	}
444
+
445
+
446
+	/**
447
+	 * If you want to setup default data for the addon, override this method, and call
448
+	 * parent::initialize_default_data() from within it. This is normally called
449
+	 * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
450
+	 * and should verify default data is present (but this is also called
451
+	 * on reactivations and just after migrations, so please verify you actually want
452
+	 * to ADD default data, because it may already be present).
453
+	 * However, please call this parent (currently it just fires a hook which other
454
+	 * addons may be depending on)
455
+	 */
456
+	public function initialize_default_data()
457
+	{
458
+		/**
459
+		 * Called when an addon is ensuring its default data is set (possibly called
460
+		 * on a reactivation, so first check for the absence of other data before setting
461
+		 * default data)
462
+		 *
463
+		 * @param EE_Addon $addon the addon that called this
464
+		 */
465
+		do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
466
+		// override to insert default data. It is safe to use the models here
467
+		// because the site should not be in maintenance mode
468
+	}
469
+
470
+
471
+	/**
472
+	 * EE Core detected that this addon has been upgraded. We should check if there
473
+	 * are any new migration scripts, and if so put the site into maintenance mode until
474
+	 * they're ran
475
+	 *
476
+	 * @return void
477
+	 */
478
+	public function upgrade()
479
+	{
480
+		$classname = get_class($this);
481
+		do_action("AHEE__{$classname}__upgrade");
482
+		do_action('AHEE__EE_Addon__upgrade', $this);
483
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
484
+		// also it's possible there is new default data that needs to be added
485
+		add_action(
486
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
487
+			array($this, 'initialize_db_if_no_migrations_required')
488
+		);
489
+	}
490
+
491
+
492
+	/**
493
+	 * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
494
+	 */
495
+	public function downgrade()
496
+	{
497
+		$classname = get_class($this);
498
+		do_action("AHEE__{$classname}__downgrade");
499
+		do_action('AHEE__EE_Addon__downgrade', $this);
500
+		// it's possible there's old default data that needs to be double-checked
501
+		add_action(
502
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
503
+			array($this, 'initialize_db_if_no_migrations_required')
504
+		);
505
+	}
506
+
507
+
508
+	/**
509
+	 * set_db_update_option_name
510
+	 * Until we do something better, we'll just check for migration scripts upon
511
+	 * plugin activation only. In the future, we'll want to do it on plugin updates too
512
+	 *
513
+	 * @return bool
514
+	 */
515
+	public function set_db_update_option_name()
516
+	{
517
+		EE_Error::doing_it_wrong(
518
+			__FUNCTION__,
519
+			esc_html__(
520
+				'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
521
+				'event_espresso'
522
+			),
523
+			'4.3.0.alpha.016'
524
+		);
525
+		// let's just handle this on the next request, ok? right now we're just not really ready
526
+		return $this->set_activation_indicator_option();
527
+	}
528
+
529
+
530
+	/**
531
+	 * Returns the name of the activation indicator option
532
+	 * (an option which is set temporarily to indicate that this addon was just activated)
533
+	 *
534
+	 * @deprecated since version 4.3.0.alpha.016
535
+	 * @return string
536
+	 */
537
+	public function get_db_update_option_name()
538
+	{
539
+		EE_Error::doing_it_wrong(
540
+			__FUNCTION__,
541
+			esc_html__(
542
+				'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
543
+				'event_espresso'
544
+			),
545
+			'4.3.0.alpha.016'
546
+		);
547
+		return $this->get_activation_indicator_option_name();
548
+	}
549
+
550
+
551
+	/**
552
+	 * When the addon is activated, this should be called to set a wordpress option that
553
+	 * indicates it was activated. This is especially useful for detecting reactivations.
554
+	 *
555
+	 * @return bool
556
+	 */
557
+	public function set_activation_indicator_option()
558
+	{
559
+		// let's just handle this on the next request, ok? right now we're just not really ready
560
+		return update_option($this->get_activation_indicator_option_name(), true);
561
+	}
562
+
563
+
564
+	/**
565
+	 * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
566
+	 *
567
+	 * @return string
568
+	 */
569
+	public function get_activation_indicator_option_name()
570
+	{
571
+		return 'ee_activation_' . $this->name();
572
+	}
573
+
574
+
575
+	/**
576
+	 * Used by EE_System to set the request type of this addon. Should not be used by addon developers
577
+	 *
578
+	 * @param int $req_type
579
+	 */
580
+	public function set_req_type($req_type)
581
+	{
582
+		$this->_req_type = $req_type;
583
+	}
584
+
585
+
586
+	/**
587
+	 * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
588
+	 * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
589
+	 * EE_System when it is checking for new install or upgrades of addons
590
+	 */
591
+	public function detect_req_type()
592
+	{
593
+		if (! $this->_req_type) {
594
+			$this->detect_activation_or_upgrade();
595
+		}
596
+		return $this->_req_type;
597
+	}
598
+
599
+
600
+	/**
601
+	 * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
602
+	 * Should only be called once per request
603
+	 *
604
+	 * @return void
605
+	 */
606
+	public function detect_activation_or_upgrade()
607
+	{
608
+		$activation_history_for_addon = $this->get_activation_history();
609
+		$request_type = EE_System::detect_req_type_given_activation_history(
610
+			$activation_history_for_addon,
611
+			$this->get_activation_indicator_option_name(),
612
+			$this->version()
613
+		);
614
+		$this->set_req_type($request_type);
615
+		$classname = get_class($this);
616
+		switch ($request_type) {
617
+			case EE_System::req_type_new_activation:
618
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
619
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
620
+				$this->new_install();
621
+				$this->update_list_of_installed_versions($activation_history_for_addon);
622
+				break;
623
+			case EE_System::req_type_reactivation:
624
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
625
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
626
+				$this->reactivation();
627
+				$this->update_list_of_installed_versions($activation_history_for_addon);
628
+				break;
629
+			case EE_System::req_type_upgrade:
630
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
631
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
632
+				$this->upgrade();
633
+				$this->update_list_of_installed_versions($activation_history_for_addon);
634
+				break;
635
+			case EE_System::req_type_downgrade:
636
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
637
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
638
+				$this->downgrade();
639
+				$this->update_list_of_installed_versions($activation_history_for_addon);
640
+				break;
641
+			case EE_System::req_type_normal:
642
+			default:
643
+				break;
644
+		}
645
+
646
+		do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
647
+	}
648
+
649
+	/**
650
+	 * Updates the version history for this addon
651
+	 *
652
+	 * @param array  $version_history
653
+	 * @param string $current_version_to_add
654
+	 * @return boolean success
655
+	 */
656
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
657
+	{
658
+		if (! $version_history) {
659
+			$version_history = $this->get_activation_history();
660
+		}
661
+		if ($current_version_to_add === null) {
662
+			$current_version_to_add = $this->version();
663
+		}
664
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
665
+		// resave
666
+		return update_option($this->get_activation_history_option_name(), $version_history);
667
+	}
668
+
669
+	/**
670
+	 * Gets the name of the wp option that stores the activation history
671
+	 * of this addon
672
+	 *
673
+	 * @return string
674
+	 */
675
+	public function get_activation_history_option_name()
676
+	{
677
+		return self::ee_addon_version_history_option_prefix . $this->name();
678
+	}
679
+
680
+
681
+	/**
682
+	 * Gets the wp option which stores the activation history for this addon
683
+	 *
684
+	 * @return array
685
+	 */
686
+	public function get_activation_history()
687
+	{
688
+		return get_option($this->get_activation_history_option_name(), null);
689
+	}
690
+
691
+
692
+	/**
693
+	 * @param string $config_section
694
+	 */
695
+	public function set_config_section($config_section = '')
696
+	{
697
+		$this->_config_section = ! empty($config_section) ? $config_section : 'addons';
698
+	}
699
+
700
+	/**
701
+	 * Sets the filepath to the main plugin file
702
+	 *
703
+	 * @param string $filepath
704
+	 */
705
+	public function set_main_plugin_file($filepath)
706
+	{
707
+		$this->_main_plugin_file = $filepath;
708
+	}
709
+
710
+	/**
711
+	 * gets the filepath to teh main file
712
+	 *
713
+	 * @return string
714
+	 */
715
+	public function get_main_plugin_file()
716
+	{
717
+		return $this->_main_plugin_file;
718
+	}
719
+
720
+	/**
721
+	 * Gets the filename (no path) of the main file (the main file loaded
722
+	 * by WP)
723
+	 *
724
+	 * @return string
725
+	 */
726
+	public function get_main_plugin_file_basename()
727
+	{
728
+		return plugin_basename($this->get_main_plugin_file());
729
+	}
730
+
731
+	/**
732
+	 * Gets the folder name which contains the main plugin file
733
+	 *
734
+	 * @return string
735
+	 */
736
+	public function get_main_plugin_file_dirname()
737
+	{
738
+		return dirname($this->get_main_plugin_file());
739
+	}
740
+
741
+
742
+	/**
743
+	 * sets hooks used in the admin
744
+	 *
745
+	 * @return void
746
+	 */
747
+	public function admin_init()
748
+	{
749
+		// is admin and not in M-Mode ?
750
+		if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
751
+			add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
752
+			add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
753
+		}
754
+	}
755
+
756
+
757
+	/**
758
+	 * plugin_actions
759
+	 * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
760
+	 *
761
+	 * @param $links
762
+	 * @param $file
763
+	 * @return array
764
+	 */
765
+	public function plugin_action_links($links, $file)
766
+	{
767
+		if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
768
+			// before other links
769
+			array_unshift(
770
+				$links,
771
+				'<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
772
+				. esc_html__('Settings', 'event_espresso')
773
+				. '</a>'
774
+			);
775
+		}
776
+		return $links;
777
+	}
778
+
779
+
780
+	/**
781
+	 * after_plugin_row
782
+	 * Add additional content to the plugins page plugin row
783
+	 * Inserts another row
784
+	 *
785
+	 * @param $plugin_file
786
+	 * @param $plugin_data
787
+	 * @param $status
788
+	 * @return void
789
+	 */
790
+	public function after_plugin_row($plugin_file, $plugin_data, $status)
791
+	{
792
+		$after_plugin_row = '';
793
+		$plugins_page_row = $this->get_plugins_page_row();
794
+		if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
795
+			$class = $status ? 'active' : 'inactive';
796
+			$link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
797
+			$link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
798
+			$description = isset($plugins_page_row['description'])
799
+				? $plugins_page_row['description']
800
+				: '';
801
+			if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
802
+				$after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
803
+				$after_plugin_row .= '<th class="check-column" scope="row"></th>';
804
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
805
+				$after_plugin_row .= '<style>
806 806
 .ee-button,
807 807
 .ee-button:active,
808 808
 .ee-button:visited {
@@ -839,49 +839,49 @@  discard block
 block discarded – undo
839 839
 }
840 840
 .ee-button:active { top:0; }
841 841
 </style>';
842
-                $after_plugin_row .= '
842
+				$after_plugin_row .= '
843 843
 <p class="ee-addon-upsell-info-dv">
844 844
 	<a class="ee-button" href="' . $link_url . '">'
845
-                                     . $link_text
846
-                                     . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
847
-                                     . '</a>
845
+									 . $link_text
846
+									 . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
847
+									 . '</a>
848 848
 </p>';
849
-                $after_plugin_row .= '</td>';
850
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
851
-                $after_plugin_row .= $description;
852
-                $after_plugin_row .= '</td>';
853
-                $after_plugin_row .= '</tr>';
854
-            } else {
855
-                $after_plugin_row .= $description;
856
-            }
857
-        }
858
-
859
-        echo $after_plugin_row;
860
-    }
861
-
862
-
863
-    /**
864
-     * A safe space for addons to add additional logic like setting hooks that need to be set early in the request.
865
-     * Child classes that have logic like that to run can override this method declaration.  This was not made abstract
866
-     * for back compat reasons.
867
-     *
868
-     * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999.
869
-     *
870
-     * It is recommended, if client code is `de-registering` an add-on, then do it on the
871
-     * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this
872
-     * callback does not get run/set in that request.
873
-     *
874
-     * Also, keep in mind that if a registered add-on happens to be deactivated via
875
-     * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method
876
-     * (including setting hooks etc) will have executed before the plugin was deactivated.  If you use
877
-     * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's
878
-     * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there.  Just remember
879
-     * to call `parent::deactivation`.
880
-     *
881
-     * @since 4.9.26
882
-     */
883
-    public function after_registration()
884
-    {
885
-        // cricket chirp... cricket chirp...
886
-    }
849
+				$after_plugin_row .= '</td>';
850
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
851
+				$after_plugin_row .= $description;
852
+				$after_plugin_row .= '</td>';
853
+				$after_plugin_row .= '</tr>';
854
+			} else {
855
+				$after_plugin_row .= $description;
856
+			}
857
+		}
858
+
859
+		echo $after_plugin_row;
860
+	}
861
+
862
+
863
+	/**
864
+	 * A safe space for addons to add additional logic like setting hooks that need to be set early in the request.
865
+	 * Child classes that have logic like that to run can override this method declaration.  This was not made abstract
866
+	 * for back compat reasons.
867
+	 *
868
+	 * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999.
869
+	 *
870
+	 * It is recommended, if client code is `de-registering` an add-on, then do it on the
871
+	 * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this
872
+	 * callback does not get run/set in that request.
873
+	 *
874
+	 * Also, keep in mind that if a registered add-on happens to be deactivated via
875
+	 * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method
876
+	 * (including setting hooks etc) will have executed before the plugin was deactivated.  If you use
877
+	 * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's
878
+	 * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there.  Just remember
879
+	 * to call `parent::deactivation`.
880
+	 *
881
+	 * @since 4.9.26
882
+	 */
883
+	public function after_registration()
884
+	{
885
+		// cricket chirp... cricket chirp...
886
+	}
887 887
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
     public function set_plugins_page_row($plugins_page_row = array())
292 292
     {
293 293
         // sigh.... check for example content that I stupidly merged to master and remove it if found
294
-        if (! is_array($plugins_page_row)
294
+        if ( ! is_array($plugins_page_row)
295 295
             && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
296 296
         ) {
297 297
             $plugins_page_row = array();
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
      */
569 569
     public function get_activation_indicator_option_name()
570 570
     {
571
-        return 'ee_activation_' . $this->name();
571
+        return 'ee_activation_'.$this->name();
572 572
     }
573 573
 
574 574
 
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
      */
591 591
     public function detect_req_type()
592 592
     {
593
-        if (! $this->_req_type) {
593
+        if ( ! $this->_req_type) {
594 594
             $this->detect_activation_or_upgrade();
595 595
         }
596 596
         return $this->_req_type;
@@ -655,13 +655,13 @@  discard block
 block discarded – undo
655 655
      */
656 656
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
657 657
     {
658
-        if (! $version_history) {
658
+        if ( ! $version_history) {
659 659
             $version_history = $this->get_activation_history();
660 660
         }
661 661
         if ($current_version_to_add === null) {
662 662
             $current_version_to_add = $this->version();
663 663
         }
664
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
664
+        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
665 665
         // resave
666 666
         return update_option($this->get_activation_history_option_name(), $version_history);
667 667
     }
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
      */
675 675
     public function get_activation_history_option_name()
676 676
     {
677
-        return self::ee_addon_version_history_option_prefix . $this->name();
677
+        return self::ee_addon_version_history_option_prefix.$this->name();
678 678
     }
679 679
 
680 680
 
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
         // is admin and not in M-Mode ?
750 750
         if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
751 751
             add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
752
-            add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
752
+            add_filter('after_plugin_row_'.$this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
753 753
         }
754 754
     }
755 755
 
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
             // before other links
769 769
             array_unshift(
770 770
                 $links,
771
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
771
+                '<a href="admin.php?page='.$this->plugin_action_slug().'">'
772 772
                 . esc_html__('Settings', 'event_espresso')
773 773
                 . '</a>'
774 774
             );
@@ -791,15 +791,15 @@  discard block
 block discarded – undo
791 791
     {
792 792
         $after_plugin_row = '';
793 793
         $plugins_page_row = $this->get_plugins_page_row();
794
-        if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
794
+        if ( ! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
795 795
             $class = $status ? 'active' : 'inactive';
796 796
             $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
797 797
             $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
798 798
             $description = isset($plugins_page_row['description'])
799 799
                 ? $plugins_page_row['description']
800 800
                 : '';
801
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
802
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
801
+            if ( ! empty($link_text) && ! empty($link_url) && ! empty($description)) {
802
+                $after_plugin_row .= '<tr id="'.sanitize_title($plugin_file).'-ee-addon" class="'.$class.'">';
803 803
                 $after_plugin_row .= '<th class="check-column" scope="row"></th>';
804 804
                 $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
805 805
                 $after_plugin_row .= '<style>
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
 </style>';
842 842
                 $after_plugin_row .= '
843 843
 <p class="ee-addon-upsell-info-dv">
844
-	<a class="ee-button" href="' . $link_url . '">'
844
+	<a class="ee-button" href="' . $link_url.'">'
845 845
                                      . $link_text
846 846
                                      . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
847 847
                                      . '</a>
Please login to merge, or discard this patch.
core/templates/espresso-ajax-notices.template.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@
 block discarded – undo
1 1
 <div id="espresso-ajax-loading" style="display:none;">
2 2
     <span class="ee-spinner ee-spin"></span><span style="display:none;">
3 3
         <?php _e(
4
-            'loading...',
5
-            'event_espresso'
6
-        ); ?></span>
4
+			'loading...',
5
+			'event_espresso'
6
+		); ?></span>
7 7
 </div>
8 8
 
9 9
 <div id="espresso-ajax-notices">
Please login to merge, or discard this patch.
core/EE_Bootstrap.core.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -14,78 +14,78 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    /**
18
-     * load_espresso_addons
19
-     * runs during the WP 'plugins_loaded' action at priority 1
20
-     * and is the initial loading phase for EE addons
21
-     * no other logic should be performed at this point
22
-     */
23
-    public static function load_espresso_addons()
24
-    {
25
-        do_action('AHEE__EE_Bootstrap__load_espresso_addons');
26
-    }
17
+	/**
18
+	 * load_espresso_addons
19
+	 * runs during the WP 'plugins_loaded' action at priority 1
20
+	 * and is the initial loading phase for EE addons
21
+	 * no other logic should be performed at this point
22
+	 */
23
+	public static function load_espresso_addons()
24
+	{
25
+		do_action('AHEE__EE_Bootstrap__load_espresso_addons');
26
+	}
27 27
 
28 28
 
29
-    /**
30
-     * detect_activations_or_upgrades
31
-     * runs during the WP 'plugins_loaded' action at priority 3
32
-     * Now that all of the addons have been loaded,
33
-     * we can determine if anything needs activating or upgrading
34
-     */
35
-    public static function detect_activations_or_upgrades()
36
-    {
37
-        do_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades');
38
-    }
29
+	/**
30
+	 * detect_activations_or_upgrades
31
+	 * runs during the WP 'plugins_loaded' action at priority 3
32
+	 * Now that all of the addons have been loaded,
33
+	 * we can determine if anything needs activating or upgrading
34
+	 */
35
+	public static function detect_activations_or_upgrades()
36
+	{
37
+		do_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades');
38
+	}
39 39
 
40 40
 
41
-    /**
42
-     * load_core_configuration
43
-     * runs during the WP 'plugins_loaded' action at priority 5
44
-     * Now that the database is assumed to be at the correct version
45
-     * we can load and set all of the system configurations
46
-     */
47
-    public static function load_core_configuration()
48
-    {
49
-        do_action('AHEE__EE_Bootstrap__load_core_configuration');
50
-    }
41
+	/**
42
+	 * load_core_configuration
43
+	 * runs during the WP 'plugins_loaded' action at priority 5
44
+	 * Now that the database is assumed to be at the correct version
45
+	 * we can load and set all of the system configurations
46
+	 */
47
+	public static function load_core_configuration()
48
+	{
49
+		do_action('AHEE__EE_Bootstrap__load_core_configuration');
50
+	}
51 51
 
52 52
 
53
-    /**
54
-     * register_shortcodes_modules_and_widgets
55
-     * runs during the WP 'plugins_loaded' action at priority 7
56
-     * and handles registering all o four shortcodes, modules and widgets
57
-     * so that they are ready to be used throughout the system
58
-     */
59
-    public static function register_shortcodes_modules_and_widgets()
60
-    {
61
-        do_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets');
62
-    }
53
+	/**
54
+	 * register_shortcodes_modules_and_widgets
55
+	 * runs during the WP 'plugins_loaded' action at priority 7
56
+	 * and handles registering all o four shortcodes, modules and widgets
57
+	 * so that they are ready to be used throughout the system
58
+	 */
59
+	public static function register_shortcodes_modules_and_widgets()
60
+	{
61
+		do_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets');
62
+	}
63 63
 
64 64
 
65
-    /**
66
-     * brew_espresso
67
-     * runs during the WP 'plugins_loaded' action at priority 9
68
-     * bootstrapping is considered complete at this point,
69
-     * so let the fun begin...
70
-     */
71
-    public static function brew_espresso()
72
-    {
73
-        do_action('AHEE__EE_Bootstrap__brew_espresso');
74
-    }
65
+	/**
66
+	 * brew_espresso
67
+	 * runs during the WP 'plugins_loaded' action at priority 9
68
+	 * bootstrapping is considered complete at this point,
69
+	 * so let the fun begin...
70
+	 */
71
+	public static function brew_espresso()
72
+	{
73
+		do_action('AHEE__EE_Bootstrap__brew_espresso');
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * @deprecated 4.9.53
79
-     */
80
-    public function run_request_stack()
81
-    {
82
-    }
77
+	/**
78
+	 * @deprecated 4.9.53
79
+	 */
80
+	public function run_request_stack()
81
+	{
82
+	}
83 83
 
84 84
 
85
-    /**
86
-     * @deprecated 4.9.53
87
-     */
88
-    public function build_request_stack()
89
-    {
90
-    }
85
+	/**
86
+	 * @deprecated 4.9.53
87
+	 */
88
+	public function build_request_stack()
89
+	{
90
+	}
91 91
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Parse_Shortcodes.helper.php 2 patches
Indentation   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -13,268 +13,268 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * holds the template
18
-     *
19
-     * @access private
20
-     * @var mixed (string|array)
21
-     */
22
-    private $_template;
23
-
24
-
25
-    /**
26
-     * holds the incoming data object
27
-     *
28
-     * @access private
29
-     * @var object
30
-     */
31
-    private $_data;
32
-
33
-
34
-    /**
35
-     * will hold an array of EE_Shortcodes library objects.
36
-     *
37
-     * @access private
38
-     * @var EE_Shortcodes[]
39
-     */
40
-    private $_shortcode_objs = array();
41
-
42
-
43
-    public function __construct()
44
-    {
45
-    }
46
-
47
-
48
-    /**
49
-     * This kicks off the parsing of shortcodes in message templates
50
-     *
51
-     * @param  string                $template         This is the incoming string to be parsed
52
-     * @param  EE_Messages_Addressee $data             This is the incoming data object
53
-     * @param  array                 $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries
54
-     * @param EE_message_type        $message_type     The message type that called the parser
55
-     * @param EE_messenger           $messenger        The active messenger for this parsing session.
56
-     * @param EE_Message             $message
57
-     * @return string                   The parsed template string
58
-     */
59
-    public function parse_message_template(
60
-        $template,
61
-        EE_Messages_Addressee $data,
62
-        $valid_shortcodes,
63
-        EE_message_type $message_type,
64
-        EE_messenger $messenger,
65
-        EE_Message $message
66
-    ) {
67
-        $extra_data = array(
68
-            'messenger'    => $messenger,
69
-            'message_type' => $message_type,
70
-            'message'      => $message,
71
-        );
72
-        $this->_init_data($template, $data, $valid_shortcodes, $extra_data);
73
-        $this->_template = is_array($template) ? $template['main'] : $template;
74
-        return $this->_parse_message_template();
75
-    }
76
-
77
-
78
-    public function parse_attendee_list_template(
79
-        $template,
80
-        EE_Registration $registration,
81
-        $valid_shortcodes,
82
-        $extra_data = array()
83
-    ) {
84
-        $this->_init_data($template, $registration, $valid_shortcodes, $extra_data);
85
-        $this->_template = is_array($template) ? $template['attendee_list'] : $template;
86
-        return $this->_parse_message_template();
87
-    }
88
-
89
-    public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array())
90
-    {
91
-        $this->_init_data($template, $event, $valid_shortcodes, $extra_data);
92
-        $this->_template = is_array($template) ? $template['event_list'] : $template;
93
-        return $this->_parse_message_template();
94
-    }
95
-
96
-
97
-    public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array())
98
-    {
99
-        $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data);
100
-        $this->_template = is_array($template) ? $template['ticket_list'] : $template;
101
-        return $this->_parse_message_template();
102
-    }
103
-
104
-
105
-    public function parse_line_item_list_template(
106
-        $template,
107
-        EE_Line_Item $line_item,
108
-        $valid_shortcodes,
109
-        $extra_data = array()
110
-    ) {
111
-        $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data);
112
-        $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template;
113
-        return $this->_parse_message_template();
114
-    }
115
-
116
-
117
-    public function parse_payment_list_template(
118
-        $template,
119
-        EE_Payment $payment_item,
120
-        $valid_shortcodes,
121
-        $extra_data = array()
122
-    ) {
123
-        $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data);
124
-        $this->_template = is_array($template) ? $template['payment_list'] : $template;
125
-        return $this->_parse_message_template();
126
-    }
127
-
128
-
129
-    public function parse_datetime_list_template(
130
-        $template,
131
-        EE_Datetime $datetime,
132
-        $valid_shortcodes,
133
-        $extra_data = array()
134
-    ) {
135
-        $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data);
136
-        $this->_template = is_array($template) ? $template['datetime_list'] : $template;
137
-        return $this->_parse_message_template();
138
-    }
139
-
140
-
141
-    public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array())
142
-    {
143
-        $this->_init_data($template, $answer, $valid_shortcodes, $extra_data);
144
-        $this->_template = is_array($template) ? $template['question_list'] : $template;
145
-        return $this->_parse_message_template();
146
-    }
147
-
148
-
149
-    private function _init_data($template, $data, $valid_shortcodes, $extra_data = array())
150
-    {
151
-        $this->_reset_props();
152
-        $this->_data['template']   = $template;
153
-        $this->_data['data']       = $data;
154
-        $this->_data['extra_data'] = $extra_data;
155
-        $this->_set_shortcodes($valid_shortcodes);
156
-    }
157
-
158
-
159
-    private function _reset_props()
160
-    {
161
-        $this->_template       = $this->_data = null;
162
-        $this->_shortcode_objs = array();
163
-    }
164
-
165
-
166
-    /**
167
-     * takes the given template and parses it with the $_shortcodes property
168
-     *
169
-     * @access private
170
-     * @return string
171
-     */
172
-    private function _parse_message_template()
173
-    {
174
-        // now let's get a list of shortcodes that are found in the given template
175
-        preg_match_all('/(\[.+?\])/', $this->_template, $matches);
176
-        $shortcodes = (array) $matches[0]; // this should be an array of shortcodes in the template string.
177
-
178
-        $matched_code = array();
179
-        $sc_values    = array();
180
-
181
-        $list_type_shortcodes = array(
182
-            '[ATTENDEE_LIST]',
183
-            '[EVENT_LIST]',
184
-            '[TICKET_LIST]',
185
-            '[DATETIME_LIST]',
186
-            '[QUESTION_LIST]',
187
-            '[RECIPIENT_QUESTION_LIST]',
188
-            '[PRIMARY_REGISTRANT_QUESTION_LIST]',
189
-            '[RECIPIENT_TICKET_LIST]',
190
-            '[PRIMARY_REGISTRANT_TICKET_LIST]',
191
-            '[RECIPIENT_DATETIME_LIST]',
192
-            '[PRIMARY_REGISTRANT_DATETIME_LIST]',
193
-            '[TICKET_LINE_ITEM_LIST]',
194
-            '[TAX_LINE_ITEM_LIST]',
195
-            '[ADDITIONAL_LINE_ITEM_LIST]',
196
-            '[PRICE_MODIFIER_LINE_ITEM_LIST]',
197
-            '[PAYMENT_LIST_*]',
198
-        );
199
-
200
-        $list_type_shortcodes = apply_filters(
201
-            'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes',
202
-            $list_type_shortcodes
203
-        );
204
-
205
-        // now lets go ahead and loop through our parsers for each shortcode and setup the values
206
-        foreach ($shortcodes as $shortcode) {
207
-            foreach ($this->_shortcode_objs as $sc_obj) {
208
-                if ($sc_obj instanceof EE_Shortcodes) {
209
-                    // we need to setup any dynamic shortcodes so that they work with the array_key_exists
210
-                    preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches);
211
-                    $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode;
212
-
213
-                    if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) {
214
-                        continue; // the given shortcode isn't in this object
215
-                    }
216
-
217
-                    // if this isn't  a "list" type shortcode then we'll send along the data vanilla instead of in an array.
218
-                    if (! in_array($sc_to_verify, $list_type_shortcodes)) {
219
-                        $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data;
220
-                    } else {
221
-                        $data_send = $this->_data;
222
-                    }
223
-
224
-                    // is this a conditional type shortcode?  If it is then we actually parse the template here.
225
-                    if ($this->_is_conditional_shortcode($shortcode)) {
226
-                        // most shortcode parsers are not going to have a match for this shortcode and will return an
227
-                        // empty string so we need to make sure that we're only replacing the template when there is a non empty string.
228
-                        $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']);
229
-                        if ($parsed) {
230
-                            $this->_template = $parsed;
231
-                        }
232
-                    }
233
-
234
-                    $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']);
235
-
236
-                    $matched_code[] = $shortcode;
237
-                    $sc_values[]    = $parsed;
238
-                }
239
-            }
240
-        }
241
-
242
-        // now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out.
243
-        $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template);
244
-        return $parsed;
245
-    }
246
-
247
-
248
-    /**
249
-     * Simply returns whether the given shortcode matches the structure for a conditional shortcode.
250
-     *
251
-     * Does it match this format: `[IF_`
252
-     *
253
-     * @param $shortcode
254
-     */
255
-    protected function _is_conditional_shortcode($shortcode)
256
-    {
257
-        return strpos($shortcode, '[IF_') === 0;
258
-    }
259
-
260
-
261
-    /**
262
-     * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of
263
-     * various EE_Shortcode library objects
264
-     *
265
-     * @access private
266
-     * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects
267
-     * @return void
268
-     */
269
-    private function _set_shortcodes($valid_shortcodes)
270
-    {
271
-        foreach ($valid_shortcodes as $shortcode_ref) {
272
-            $ref       = ucwords(str_replace('_', ' ', $shortcode_ref));
273
-            $ref       = str_replace(' ', '_', $ref);
274
-            $classname = 'EE_' . $ref . '_Shortcodes';
275
-            if (class_exists($classname)) {
276
-                $this->_shortcode_objs[] = new $classname;
277
-            }
278
-        }
279
-    }
16
+	/**
17
+	 * holds the template
18
+	 *
19
+	 * @access private
20
+	 * @var mixed (string|array)
21
+	 */
22
+	private $_template;
23
+
24
+
25
+	/**
26
+	 * holds the incoming data object
27
+	 *
28
+	 * @access private
29
+	 * @var object
30
+	 */
31
+	private $_data;
32
+
33
+
34
+	/**
35
+	 * will hold an array of EE_Shortcodes library objects.
36
+	 *
37
+	 * @access private
38
+	 * @var EE_Shortcodes[]
39
+	 */
40
+	private $_shortcode_objs = array();
41
+
42
+
43
+	public function __construct()
44
+	{
45
+	}
46
+
47
+
48
+	/**
49
+	 * This kicks off the parsing of shortcodes in message templates
50
+	 *
51
+	 * @param  string                $template         This is the incoming string to be parsed
52
+	 * @param  EE_Messages_Addressee $data             This is the incoming data object
53
+	 * @param  array                 $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries
54
+	 * @param EE_message_type        $message_type     The message type that called the parser
55
+	 * @param EE_messenger           $messenger        The active messenger for this parsing session.
56
+	 * @param EE_Message             $message
57
+	 * @return string                   The parsed template string
58
+	 */
59
+	public function parse_message_template(
60
+		$template,
61
+		EE_Messages_Addressee $data,
62
+		$valid_shortcodes,
63
+		EE_message_type $message_type,
64
+		EE_messenger $messenger,
65
+		EE_Message $message
66
+	) {
67
+		$extra_data = array(
68
+			'messenger'    => $messenger,
69
+			'message_type' => $message_type,
70
+			'message'      => $message,
71
+		);
72
+		$this->_init_data($template, $data, $valid_shortcodes, $extra_data);
73
+		$this->_template = is_array($template) ? $template['main'] : $template;
74
+		return $this->_parse_message_template();
75
+	}
76
+
77
+
78
+	public function parse_attendee_list_template(
79
+		$template,
80
+		EE_Registration $registration,
81
+		$valid_shortcodes,
82
+		$extra_data = array()
83
+	) {
84
+		$this->_init_data($template, $registration, $valid_shortcodes, $extra_data);
85
+		$this->_template = is_array($template) ? $template['attendee_list'] : $template;
86
+		return $this->_parse_message_template();
87
+	}
88
+
89
+	public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array())
90
+	{
91
+		$this->_init_data($template, $event, $valid_shortcodes, $extra_data);
92
+		$this->_template = is_array($template) ? $template['event_list'] : $template;
93
+		return $this->_parse_message_template();
94
+	}
95
+
96
+
97
+	public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array())
98
+	{
99
+		$this->_init_data($template, $ticket, $valid_shortcodes, $extra_data);
100
+		$this->_template = is_array($template) ? $template['ticket_list'] : $template;
101
+		return $this->_parse_message_template();
102
+	}
103
+
104
+
105
+	public function parse_line_item_list_template(
106
+		$template,
107
+		EE_Line_Item $line_item,
108
+		$valid_shortcodes,
109
+		$extra_data = array()
110
+	) {
111
+		$this->_init_data($template, $line_item, $valid_shortcodes, $extra_data);
112
+		$this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template;
113
+		return $this->_parse_message_template();
114
+	}
115
+
116
+
117
+	public function parse_payment_list_template(
118
+		$template,
119
+		EE_Payment $payment_item,
120
+		$valid_shortcodes,
121
+		$extra_data = array()
122
+	) {
123
+		$this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data);
124
+		$this->_template = is_array($template) ? $template['payment_list'] : $template;
125
+		return $this->_parse_message_template();
126
+	}
127
+
128
+
129
+	public function parse_datetime_list_template(
130
+		$template,
131
+		EE_Datetime $datetime,
132
+		$valid_shortcodes,
133
+		$extra_data = array()
134
+	) {
135
+		$this->_init_data($template, $datetime, $valid_shortcodes, $extra_data);
136
+		$this->_template = is_array($template) ? $template['datetime_list'] : $template;
137
+		return $this->_parse_message_template();
138
+	}
139
+
140
+
141
+	public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array())
142
+	{
143
+		$this->_init_data($template, $answer, $valid_shortcodes, $extra_data);
144
+		$this->_template = is_array($template) ? $template['question_list'] : $template;
145
+		return $this->_parse_message_template();
146
+	}
147
+
148
+
149
+	private function _init_data($template, $data, $valid_shortcodes, $extra_data = array())
150
+	{
151
+		$this->_reset_props();
152
+		$this->_data['template']   = $template;
153
+		$this->_data['data']       = $data;
154
+		$this->_data['extra_data'] = $extra_data;
155
+		$this->_set_shortcodes($valid_shortcodes);
156
+	}
157
+
158
+
159
+	private function _reset_props()
160
+	{
161
+		$this->_template       = $this->_data = null;
162
+		$this->_shortcode_objs = array();
163
+	}
164
+
165
+
166
+	/**
167
+	 * takes the given template and parses it with the $_shortcodes property
168
+	 *
169
+	 * @access private
170
+	 * @return string
171
+	 */
172
+	private function _parse_message_template()
173
+	{
174
+		// now let's get a list of shortcodes that are found in the given template
175
+		preg_match_all('/(\[.+?\])/', $this->_template, $matches);
176
+		$shortcodes = (array) $matches[0]; // this should be an array of shortcodes in the template string.
177
+
178
+		$matched_code = array();
179
+		$sc_values    = array();
180
+
181
+		$list_type_shortcodes = array(
182
+			'[ATTENDEE_LIST]',
183
+			'[EVENT_LIST]',
184
+			'[TICKET_LIST]',
185
+			'[DATETIME_LIST]',
186
+			'[QUESTION_LIST]',
187
+			'[RECIPIENT_QUESTION_LIST]',
188
+			'[PRIMARY_REGISTRANT_QUESTION_LIST]',
189
+			'[RECIPIENT_TICKET_LIST]',
190
+			'[PRIMARY_REGISTRANT_TICKET_LIST]',
191
+			'[RECIPIENT_DATETIME_LIST]',
192
+			'[PRIMARY_REGISTRANT_DATETIME_LIST]',
193
+			'[TICKET_LINE_ITEM_LIST]',
194
+			'[TAX_LINE_ITEM_LIST]',
195
+			'[ADDITIONAL_LINE_ITEM_LIST]',
196
+			'[PRICE_MODIFIER_LINE_ITEM_LIST]',
197
+			'[PAYMENT_LIST_*]',
198
+		);
199
+
200
+		$list_type_shortcodes = apply_filters(
201
+			'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes',
202
+			$list_type_shortcodes
203
+		);
204
+
205
+		// now lets go ahead and loop through our parsers for each shortcode and setup the values
206
+		foreach ($shortcodes as $shortcode) {
207
+			foreach ($this->_shortcode_objs as $sc_obj) {
208
+				if ($sc_obj instanceof EE_Shortcodes) {
209
+					// we need to setup any dynamic shortcodes so that they work with the array_key_exists
210
+					preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches);
211
+					$sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode;
212
+
213
+					if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) {
214
+						continue; // the given shortcode isn't in this object
215
+					}
216
+
217
+					// if this isn't  a "list" type shortcode then we'll send along the data vanilla instead of in an array.
218
+					if (! in_array($sc_to_verify, $list_type_shortcodes)) {
219
+						$data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data;
220
+					} else {
221
+						$data_send = $this->_data;
222
+					}
223
+
224
+					// is this a conditional type shortcode?  If it is then we actually parse the template here.
225
+					if ($this->_is_conditional_shortcode($shortcode)) {
226
+						// most shortcode parsers are not going to have a match for this shortcode and will return an
227
+						// empty string so we need to make sure that we're only replacing the template when there is a non empty string.
228
+						$parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']);
229
+						if ($parsed) {
230
+							$this->_template = $parsed;
231
+						}
232
+					}
233
+
234
+					$parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']);
235
+
236
+					$matched_code[] = $shortcode;
237
+					$sc_values[]    = $parsed;
238
+				}
239
+			}
240
+		}
241
+
242
+		// now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out.
243
+		$parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template);
244
+		return $parsed;
245
+	}
246
+
247
+
248
+	/**
249
+	 * Simply returns whether the given shortcode matches the structure for a conditional shortcode.
250
+	 *
251
+	 * Does it match this format: `[IF_`
252
+	 *
253
+	 * @param $shortcode
254
+	 */
255
+	protected function _is_conditional_shortcode($shortcode)
256
+	{
257
+		return strpos($shortcode, '[IF_') === 0;
258
+	}
259
+
260
+
261
+	/**
262
+	 * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of
263
+	 * various EE_Shortcode library objects
264
+	 *
265
+	 * @access private
266
+	 * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects
267
+	 * @return void
268
+	 */
269
+	private function _set_shortcodes($valid_shortcodes)
270
+	{
271
+		foreach ($valid_shortcodes as $shortcode_ref) {
272
+			$ref       = ucwords(str_replace('_', ' ', $shortcode_ref));
273
+			$ref       = str_replace(' ', '_', $ref);
274
+			$classname = 'EE_' . $ref . '_Shortcodes';
275
+			if (class_exists($classname)) {
276
+				$this->_shortcode_objs[] = new $classname;
277
+			}
278
+		}
279
+	}
280 280
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
                 if ($sc_obj instanceof EE_Shortcodes) {
209 209
                     // we need to setup any dynamic shortcodes so that they work with the array_key_exists
210 210
                     preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches);
211
-                    $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode;
211
+                    $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode;
212 212
 
213
-                    if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) {
213
+                    if ( ! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) {
214 214
                         continue; // the given shortcode isn't in this object
215 215
                     }
216 216
 
217 217
                     // if this isn't  a "list" type shortcode then we'll send along the data vanilla instead of in an array.
218
-                    if (! in_array($sc_to_verify, $list_type_shortcodes)) {
218
+                    if ( ! in_array($sc_to_verify, $list_type_shortcodes)) {
219 219
                         $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data;
220 220
                     } else {
221 221
                         $data_send = $this->_data;
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
         foreach ($valid_shortcodes as $shortcode_ref) {
272 272
             $ref       = ucwords(str_replace('_', ' ', $shortcode_ref));
273 273
             $ref       = str_replace(' ', '_', $ref);
274
-            $classname = 'EE_' . $ref . '_Shortcodes';
274
+            $classname = 'EE_'.$ref.'_Shortcodes';
275 275
             if (class_exists($classname)) {
276 276
                 $this->_shortcode_objs[] = new $classname;
277 277
             }
Please login to merge, or discard this patch.
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_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.