Completed
Branch FET-9576-iframes (fd61fb)
by
unknown
1237:34 queued 1222:10
created
core/libraries/iframe_display/Iframe.php 2 patches
Indentation   +476 added lines, -476 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\core\libraries\iframe_display;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -18,508 +18,508 @@  discard block
 block discarded – undo
18 18
 class Iframe
19 19
 {
20 20
 
21
-    /*
21
+	/*
22 22
     * HTML for notices and ajax gif
23 23
     * @var string $title
24 24
     */
25
-    protected $title = '';
25
+	protected $title = '';
26 26
 
27
-    /*
27
+	/*
28 28
     * HTML for the content being displayed
29 29
     * @var string $content
30 30
     */
31
-    protected $content = '';
31
+	protected $content = '';
32 32
 
33
-    /*
33
+	/*
34 34
     * whether or not to call wp_head() and wp_footer()
35 35
     * @var boolean $enqueue_wp_assets
36 36
     */
37
-    protected $enqueue_wp_assets = false;
37
+	protected $enqueue_wp_assets = false;
38 38
 
39
-    /*
39
+	/*
40 40
     * an array of CSS URLs
41 41
     * @var array $css
42 42
     */
43
-    protected $css = array();
43
+	protected $css = array();
44 44
 
45
-    /*
45
+	/*
46 46
     * an array of JS URLs to be set in the HTML header.
47 47
     * @var array $header_js
48 48
     */
49
-    protected $header_js = array();
49
+	protected $header_js = array();
50 50
 
51
-    /*
51
+	/*
52 52
     * an array of JS URLs to be displayed before the HTML </body> tag
53 53
     * @var array $footer_js
54 54
     */
55
-    protected $footer_js = array();
55
+	protected $footer_js = array();
56 56
 
57
-    /*
57
+	/*
58 58
     * an array of JSON vars to be set in the HTML header.
59 59
     * @var array $localized_vars
60 60
     */
61
-    protected $localized_vars = array();
62
-
63
-
64
-
65
-    /**
66
-     * Iframe constructor
67
-     *
68
-     * @param string $title
69
-     * @param string $content
70
-     * @throws \EE_Error
71
-     */
72
-    public function __construct($title, $content)
73
-    {
74
-        global $wp_version;
75
-        if ( ! defined('EE_IFRAME_DIR_URL')) {
76
-            define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__));
77
-        }
78
-        $this->setContent($content);
79
-        $this->setTitle($title);
80
-        $this->addStylesheets(
81
-            apply_filters(
82
-                'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__construct__default_css',
83
-                array(
84
-                    'dashicons'        => includes_url('css/dashicons.min.css?ver=' . $wp_version),
85
-                    'espresso_default' => EE_GLOBAL_ASSETS_URL
86
-                                          . 'css/espresso_default.css?ver='
87
-                                          . EVENT_ESPRESSO_VERSION,
88
-                )
89
-            )
90
-        );
91
-        $this->addScripts(
92
-            apply_filters(
93
-                'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__construct__default_js',
94
-                array(
95
-                    'jquery'        => includes_url('js/jquery/jquery.js?ver=' . $wp_version),
96
-                    'espresso_core' => EE_GLOBAL_ASSETS_URL
97
-                                       . 'scripts/espresso_core.js?ver='
98
-                                       . EVENT_ESPRESSO_VERSION,
99
-                )
100
-            )
101
-        );
102
-    }
103
-
104
-
105
-
106
-    /**
107
-     * @param string $title
108
-     * @throws \EE_Error
109
-     */
110
-    public function setTitle($title)
111
-    {
112
-        if (empty($title)) {
113
-            throw new \EE_Error(
114
-                __('You must provide a page title in order to create an iframe.', 'event_espresso')
115
-            );
116
-        }
117
-        $this->title = $title;
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * @param string $content
124
-     * @throws \EE_Error
125
-     */
126
-    public function setContent($content)
127
-    {
128
-        if (empty($content)) {
129
-            throw new \EE_Error(
130
-                __('You must provide content in order to create an iframe.', 'event_espresso')
131
-            );
132
-        }
133
-        $this->content = $content;
134
-    }
135
-
136
-
137
-
138
-    /**
139
-     * @param boolean $enqueue_wp_assets
140
-     */
141
-    public function setEnqueueWpAssets($enqueue_wp_assets)
142
-    {
143
-        $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN);
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * @param array $stylesheets
150
-     * @throws \EE_Error
151
-     */
152
-    public function addStylesheets(array $stylesheets)
153
-    {
154
-        if (empty($stylesheets)) {
155
-            throw new \EE_Error(
156
-                __('A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', 'event_espresso')
157
-            );
158
-        }
159
-        foreach ($stylesheets as $handle => $stylesheet) {
160
-            $this->css[$handle] = $stylesheet;
161
-        }
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * @param array $scripts
168
-     * @param bool  $add_to_header
169
-     * @throws \EE_Error
170
-     */
171
-    public function addScripts(array $scripts, $add_to_header = false)
172
-    {
173
-        if (empty($scripts)) {
174
-            throw new \EE_Error(
175
-                __('A non-empty array of URLs, is required to add Javascript to an iframe.', 'event_espresso')
176
-            );
177
-        }
178
-        foreach ($scripts as $handle => $script) {
179
-            if ($add_to_header) {
180
-                $this->header_js[$handle] = $script;
181
-            } else {
182
-                $this->footer_js[$handle] = $script;
183
-            }
184
-        }
185
-    }
186
-
187
-
188
-
189
-    /**
190
-     * @param array  $vars
191
-     * @param string $var_name
192
-     * @throws \EE_Error
193
-     */
194
-    public function addLocalizedVars(array $vars, $var_name = 'eei18n')
195
-    {
196
-        if (empty($vars)) {
197
-            throw new \EE_Error(
198
-                __('A non-empty array of vars, is required to add localized Javascript vars to an iframe.',
199
-                    'event_espresso')
200
-            );
201
-        }
202
-        foreach ($vars as $handle => $var) {
203
-            if ($var_name === 'eei18n') {
204
-                \EE_Registry::$i18n_js_strings[$handle] = $var;
205
-            } else {
206
-                if ( ! isset($this->localized_vars[$var_name])) {
207
-                    $this->localized_vars[$var_name] = array();
208
-                }
209
-                $this->localized_vars[$var_name][$handle] = $var;
210
-            }
211
-        }
212
-    }
213
-
214
-
215
-
216
-    /**
217
-     * @return void
218
-     */
219
-    public function display()
220
-    {
221
-        echo $this->getTemplate();
222
-        exit;
223
-    }
224
-
225
-
226
-
227
-    /**
228
-     * @return string
229
-     */
230
-    public function getTemplate()
231
-    {
232
-        return \EEH_Template::display_template(
233
-            __DIR__ . '\iframe_wrapper.template.php',
234
-            array(
235
-                'title'             => apply_filters(
236
-                    'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__title',
237
-                    $this->title
238
-                ),
239
-                'content'           => apply_filters(
240
-                    'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__content',
241
-                    $this->content
242
-                ),
243
-                'enqueue_wp_assets' => apply_filters(
244
-                    'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__enqueue_wp_assets',
245
-                    $this->enqueue_wp_assets
246
-                ),
247
-                'css'               => (array)apply_filters(
248
-                    'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__css_urls',
249
-                    $this->css
250
-                ),
251
-                'header_js'         => (array)apply_filters(
252
-                    'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__header_js_urls',
253
-                    $this->header_js
254
-                ),
255
-                'footer_js'         => (array)apply_filters(
256
-                    'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__footer_js_urls',
257
-                    $this->footer_js
258
-                ),
259
-                'eei18n'            => apply_filters(
260
-                    'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__eei18n_js_strings',
261
-                    \EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars()
262
-                ),
263
-                'notices'           => \EEH_Template::display_template(
264
-                    EE_TEMPLATES . 'espresso-ajax-notices.template.php',
265
-                    array(),
266
-                    true
267
-                ),
268
-            ),
269
-            true
270
-        );
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * localizeJsonVars
277
-     *
278
-     * @return string
279
-     */
280
-    public function localizeJsonVars()
281
-    {
282
-        $JSON = '';
283
-        $localized_vars = (array)$this->localized_vars;
284
-        foreach ($localized_vars as $var_name => $vars) {
285
-            foreach ($vars as $key => $value) {
286
-                if (is_scalar($value)) {
287
-                    $localized_vars[$var_name][$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
288
-                }
289
-            }
290
-            $JSON .= "/* <![CDATA[ */ var $var_name = " . wp_json_encode($localized_vars[$var_name]) . '; /* ]]> */';
291
-        }
292
-        return $JSON;
293
-    }
294
-
295
-
296
-
297
-    /**
298
-     * Adds an iframe embed code button to the Event editor.
299
-     *
300
-     * @param string $route_name the named module route that generates the iframe
301
-     */
302
-    public static function addEventEditorIframeEmbedButton($route_name)
303
-    {
304
-        // add button for iframe code to event editor.
305
-        add_filter(
306
-            'get_sample_permalink_html',
307
-            function ($permalink_string, $id, $new_title = '', $new_slug = '') use ($route_name) {
308
-                return Iframe::eventListIframeEmbedButton($permalink_string, $id, $new_title, $new_slug, $route_name);
309
-            },
310
-            10, 2
311
-        );
312
-        add_action(
313
-            'admin_enqueue_scripts',
314
-            array('\EventEspresso\core\libraries\iframe_display\Iframe', 'EventsAdminEmbedButtonAssets'),
315
-            10
316
-        );
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     * iframe embed code button to the Event editor.
323
-     *
324
-     * @param string $permalink_string
325
-     * @param int    $id
326
-     * @param string $new_title  (unused)
327
-     * @param string $new_slug   (unused)
328
-     * @param string $route_name the named module route that generates the iframe
329
-     * @return string
330
-     */
331
-    public static function eventListIframeEmbedButton(
332
-        $permalink_string,
333
-        $id,
334
-        $new_title = '',
335
-        $new_slug = '',
336
-        $route_name = ''
337
-    ) {
338
-        //make sure this is ONLY when editing and the event id has been set.
339
-        if ( ! empty($id)) {
340
-            $post = get_post($id);
341
-            //if NOT event then let's get out.
342
-            if ($post->post_type !== 'espresso_events') {
343
-                return $permalink_string;
344
-            }
345
-            $permalink_string .= Iframe::embedButtonHtml(
346
-                'Event',
347
-                $route_name,
348
-                array('event' => $id),
349
-                'button-small'
350
-            );
351
-        }
352
-        return $permalink_string;
353
-    }
354
-
355
-
356
-
357
-    /**
358
-     * Adds an iframe embed code button to the Event editor.
359
-     *
360
-     * return string
361
-     */
362
-    public static function addEventListIframeEmbedButton()
363
-    {
364
-        // add button for iframe code to event editor.
365
-        $html = '';
366
-        //make sure this is ONLY when editing and the event id has been set.
367
-        if ($_GET['page'] === 'espresso_events') {
368
-            $html .= \EEH_HTML::h3(__('iFrame Embed Code', 'event_espresso'));
369
-            $html .= \EEH_HTML::p(
370
-                __('Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.',
371
-                'event_espresso')
372
-            );
373
-            $html .= ' &nbsp; ' . Iframe::embedButtonHtml(
374
-                'Events List',
375
-                'event_list'
376
-            ) . ' ';
377
-            add_action(
378
-                'admin_enqueue_scripts',
379
-                array('\EventEspresso\core\libraries\iframe_display\Iframe', 'EventsAdminEmbedButtonAssets'),
380
-                10
381
-            );
382
-        }
383
-        return apply_filters(
384
-            'FHEE__Iframe__addEventListIframeEmbedButton__html',
385
-            $html
386
-        );
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * Adds an iframe embed code button via a WP do_action() as determined by the first parameter
393
-     *
394
-     * @param string $iframe_name
395
-     * @param string $route_name the named module route that generates the iframe
396
-     * @param string $action     name of the WP do_action() to hook into
397
-     */
398
-    public static function addActionIframeEmbedButton($iframe_name, $route_name, $action)
399
-    {
400
-        // add button for iframe code to event editor.
401
-        add_action(
402
-            $action,
403
-            function () use ($iframe_name, $route_name) {
404
-                echo Iframe::embedButtonHtml($iframe_name, $route_name);
405
-            },
406
-            10
407
-        );
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter
414
-     *
415
-     * @param string $iframe_name
416
-     * @param string $route_name the named module route that generates the iframe
417
-     * @param string $filter     name of the WP apply_filters() to hook into
418
-     * @param bool   $append     if true, will add iframe embed button to end of content,
419
-     *                           else if false, will add to the beginning of the content
420
-     */
421
-    public static function addFilterIframeEmbedButton($iframe_name, $route_name, $filter, $append = true)
422
-    {
423
-        // add button for iframe code to event editor.
424
-        add_action(
425
-            $filter,
426
-            function ($filterable_content) use ($iframe_name, $route_name, $append) {
427
-                $embedButtonHtml = Iframe::embedButtonHtml($iframe_name, $route_name);
428
-                if (is_array($filterable_content)) {
429
-                    $filterable_content = $append
430
-                        ? array_push($filterable_content, $embedButtonHtml)
431
-                        : array_unshift($filterable_content, $embedButtonHtml);
432
-                } else {
433
-                    $filterable_content = $append
434
-                        ? $filterable_content . $embedButtonHtml
435
-                        : $embedButtonHtml . $filterable_content;
436
-                }
437
-                return $filterable_content;
438
-            },
439
-            10
440
-        );
441
-    }
442
-
443
-
444
-
445
-    /**
446
-     * iframe_embed_html
447
-     *
448
-     * @param string $iframe_name
449
-     * @param string $route_name the named module route that generates the iframe
450
-     * @param array  $query_args
451
-     * @param string $button_class
452
-     * @return string
453
-     */
454
-    public static function embedButtonHtml($iframe_name, $route_name, $query_args = array(), $button_class = '')
455
-    {
456
-        $query_args = ! empty($query_args) ? $query_args : array($route_name => 'iframe');
457
-        // add this route to our localized vars
458
-        $iframe_module_routes = isset(\EE_Registry::$i18n_js_strings['iframe_module_routes'])
459
-            ? \EE_Registry::$i18n_js_strings['iframe_module_routes']
460
-            : array();
461
-        $iframe_module_routes[$route_name] = $route_name;
462
-        \EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes;
463
-        $iframe_embed_html = \EEH_HTML::link(
464
-            '#',
465
-            sprintf(__('Embed %1$s', 'event_espresso'), $iframe_name),
466
-            sprintf(
467
-                __(
468
-                    'click here to generate code for embedding an %1$s iframe into another site.',
469
-                    'event_espresso'
470
-                ),
471
-                $iframe_name
472
-            ),
473
-            "$route_name-iframe-embed-trigger-js",
474
-            'iframe-embed-trigger-js button ' . $button_class,
475
-            '',
476
-            ' data-iframe_embed_button="#' . $route_name . '-iframe-js" tabindex="-1"'
477
-        );
478
-        $iframe_embed_html .= \EEH_HTML::div('', "$route_name-iframe-js", 'iframe-embed-wrapper-js', 'display:none;');
479
-        $iframe_embed_html .= \EEH_HTML::div(
480
-            '<iframe src="' . add_query_arg($query_args, site_url()) . '" width="100%" height="100%"></iframe>',
481
-            '', '', 'width:100%; height: 500px;'
482
-        );
483
-        $iframe_embed_html .= \EEH_HTML::divx();
484
-        return $iframe_embed_html;
485
-    }
486
-
487
-
488
-
489
-    /**
490
-     * iframe button js on admin events list or event editor page
491
-     */
492
-    public static function EventsAdminEmbedButtonAssets()
493
-    {
494
-        if (\EE_Registry::instance()->REQ->get('page') === 'espresso_events') {
495
-            Iframe::embedButtonAssets();
496
-            \EE_Registry::$i18n_js_strings['iframe_embed_title'] = __(
497
-                'copy and paste the following into any other site\'s content to display this event:',
498
-                'event_espresso'
499
-            );
500
-        }
501
-    }
502
-
503
-
504
-
505
-    /**
506
-     * enqueue iframe button js
507
-     */
508
-    public static function embedButtonAssets()
509
-    {
510
-        \EE_Registry::$i18n_js_strings['iframe_embed_close_msg'] = __(
511
-            'click anywhere outside of this window to close it.',
512
-            'event_espresso'
513
-        );
514
-        wp_register_script(
515
-            'iframe_embed_button',
516
-            plugin_dir_url(__FILE__) . 'iframe-embed-button.js',
517
-            array('ee-dialog'),
518
-            EVENT_ESPRESSO_VERSION,
519
-            true
520
-        );
521
-        wp_enqueue_script('iframe_embed_button');
522
-    }
61
+	protected $localized_vars = array();
62
+
63
+
64
+
65
+	/**
66
+	 * Iframe constructor
67
+	 *
68
+	 * @param string $title
69
+	 * @param string $content
70
+	 * @throws \EE_Error
71
+	 */
72
+	public function __construct($title, $content)
73
+	{
74
+		global $wp_version;
75
+		if ( ! defined('EE_IFRAME_DIR_URL')) {
76
+			define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__));
77
+		}
78
+		$this->setContent($content);
79
+		$this->setTitle($title);
80
+		$this->addStylesheets(
81
+			apply_filters(
82
+				'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__construct__default_css',
83
+				array(
84
+					'dashicons'        => includes_url('css/dashicons.min.css?ver=' . $wp_version),
85
+					'espresso_default' => EE_GLOBAL_ASSETS_URL
86
+										  . 'css/espresso_default.css?ver='
87
+										  . EVENT_ESPRESSO_VERSION,
88
+				)
89
+			)
90
+		);
91
+		$this->addScripts(
92
+			apply_filters(
93
+				'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__construct__default_js',
94
+				array(
95
+					'jquery'        => includes_url('js/jquery/jquery.js?ver=' . $wp_version),
96
+					'espresso_core' => EE_GLOBAL_ASSETS_URL
97
+									   . 'scripts/espresso_core.js?ver='
98
+									   . EVENT_ESPRESSO_VERSION,
99
+				)
100
+			)
101
+		);
102
+	}
103
+
104
+
105
+
106
+	/**
107
+	 * @param string $title
108
+	 * @throws \EE_Error
109
+	 */
110
+	public function setTitle($title)
111
+	{
112
+		if (empty($title)) {
113
+			throw new \EE_Error(
114
+				__('You must provide a page title in order to create an iframe.', 'event_espresso')
115
+			);
116
+		}
117
+		$this->title = $title;
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * @param string $content
124
+	 * @throws \EE_Error
125
+	 */
126
+	public function setContent($content)
127
+	{
128
+		if (empty($content)) {
129
+			throw new \EE_Error(
130
+				__('You must provide content in order to create an iframe.', 'event_espresso')
131
+			);
132
+		}
133
+		$this->content = $content;
134
+	}
135
+
136
+
137
+
138
+	/**
139
+	 * @param boolean $enqueue_wp_assets
140
+	 */
141
+	public function setEnqueueWpAssets($enqueue_wp_assets)
142
+	{
143
+		$this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN);
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * @param array $stylesheets
150
+	 * @throws \EE_Error
151
+	 */
152
+	public function addStylesheets(array $stylesheets)
153
+	{
154
+		if (empty($stylesheets)) {
155
+			throw new \EE_Error(
156
+				__('A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', 'event_espresso')
157
+			);
158
+		}
159
+		foreach ($stylesheets as $handle => $stylesheet) {
160
+			$this->css[$handle] = $stylesheet;
161
+		}
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * @param array $scripts
168
+	 * @param bool  $add_to_header
169
+	 * @throws \EE_Error
170
+	 */
171
+	public function addScripts(array $scripts, $add_to_header = false)
172
+	{
173
+		if (empty($scripts)) {
174
+			throw new \EE_Error(
175
+				__('A non-empty array of URLs, is required to add Javascript to an iframe.', 'event_espresso')
176
+			);
177
+		}
178
+		foreach ($scripts as $handle => $script) {
179
+			if ($add_to_header) {
180
+				$this->header_js[$handle] = $script;
181
+			} else {
182
+				$this->footer_js[$handle] = $script;
183
+			}
184
+		}
185
+	}
186
+
187
+
188
+
189
+	/**
190
+	 * @param array  $vars
191
+	 * @param string $var_name
192
+	 * @throws \EE_Error
193
+	 */
194
+	public function addLocalizedVars(array $vars, $var_name = 'eei18n')
195
+	{
196
+		if (empty($vars)) {
197
+			throw new \EE_Error(
198
+				__('A non-empty array of vars, is required to add localized Javascript vars to an iframe.',
199
+					'event_espresso')
200
+			);
201
+		}
202
+		foreach ($vars as $handle => $var) {
203
+			if ($var_name === 'eei18n') {
204
+				\EE_Registry::$i18n_js_strings[$handle] = $var;
205
+			} else {
206
+				if ( ! isset($this->localized_vars[$var_name])) {
207
+					$this->localized_vars[$var_name] = array();
208
+				}
209
+				$this->localized_vars[$var_name][$handle] = $var;
210
+			}
211
+		}
212
+	}
213
+
214
+
215
+
216
+	/**
217
+	 * @return void
218
+	 */
219
+	public function display()
220
+	{
221
+		echo $this->getTemplate();
222
+		exit;
223
+	}
224
+
225
+
226
+
227
+	/**
228
+	 * @return string
229
+	 */
230
+	public function getTemplate()
231
+	{
232
+		return \EEH_Template::display_template(
233
+			__DIR__ . '\iframe_wrapper.template.php',
234
+			array(
235
+				'title'             => apply_filters(
236
+					'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__title',
237
+					$this->title
238
+				),
239
+				'content'           => apply_filters(
240
+					'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__content',
241
+					$this->content
242
+				),
243
+				'enqueue_wp_assets' => apply_filters(
244
+					'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__enqueue_wp_assets',
245
+					$this->enqueue_wp_assets
246
+				),
247
+				'css'               => (array)apply_filters(
248
+					'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__css_urls',
249
+					$this->css
250
+				),
251
+				'header_js'         => (array)apply_filters(
252
+					'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__header_js_urls',
253
+					$this->header_js
254
+				),
255
+				'footer_js'         => (array)apply_filters(
256
+					'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__footer_js_urls',
257
+					$this->footer_js
258
+				),
259
+				'eei18n'            => apply_filters(
260
+					'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__eei18n_js_strings',
261
+					\EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars()
262
+				),
263
+				'notices'           => \EEH_Template::display_template(
264
+					EE_TEMPLATES . 'espresso-ajax-notices.template.php',
265
+					array(),
266
+					true
267
+				),
268
+			),
269
+			true
270
+		);
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * localizeJsonVars
277
+	 *
278
+	 * @return string
279
+	 */
280
+	public function localizeJsonVars()
281
+	{
282
+		$JSON = '';
283
+		$localized_vars = (array)$this->localized_vars;
284
+		foreach ($localized_vars as $var_name => $vars) {
285
+			foreach ($vars as $key => $value) {
286
+				if (is_scalar($value)) {
287
+					$localized_vars[$var_name][$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
288
+				}
289
+			}
290
+			$JSON .= "/* <![CDATA[ */ var $var_name = " . wp_json_encode($localized_vars[$var_name]) . '; /* ]]> */';
291
+		}
292
+		return $JSON;
293
+	}
294
+
295
+
296
+
297
+	/**
298
+	 * Adds an iframe embed code button to the Event editor.
299
+	 *
300
+	 * @param string $route_name the named module route that generates the iframe
301
+	 */
302
+	public static function addEventEditorIframeEmbedButton($route_name)
303
+	{
304
+		// add button for iframe code to event editor.
305
+		add_filter(
306
+			'get_sample_permalink_html',
307
+			function ($permalink_string, $id, $new_title = '', $new_slug = '') use ($route_name) {
308
+				return Iframe::eventListIframeEmbedButton($permalink_string, $id, $new_title, $new_slug, $route_name);
309
+			},
310
+			10, 2
311
+		);
312
+		add_action(
313
+			'admin_enqueue_scripts',
314
+			array('\EventEspresso\core\libraries\iframe_display\Iframe', 'EventsAdminEmbedButtonAssets'),
315
+			10
316
+		);
317
+	}
318
+
319
+
320
+
321
+	/**
322
+	 * iframe embed code button to the Event editor.
323
+	 *
324
+	 * @param string $permalink_string
325
+	 * @param int    $id
326
+	 * @param string $new_title  (unused)
327
+	 * @param string $new_slug   (unused)
328
+	 * @param string $route_name the named module route that generates the iframe
329
+	 * @return string
330
+	 */
331
+	public static function eventListIframeEmbedButton(
332
+		$permalink_string,
333
+		$id,
334
+		$new_title = '',
335
+		$new_slug = '',
336
+		$route_name = ''
337
+	) {
338
+		//make sure this is ONLY when editing and the event id has been set.
339
+		if ( ! empty($id)) {
340
+			$post = get_post($id);
341
+			//if NOT event then let's get out.
342
+			if ($post->post_type !== 'espresso_events') {
343
+				return $permalink_string;
344
+			}
345
+			$permalink_string .= Iframe::embedButtonHtml(
346
+				'Event',
347
+				$route_name,
348
+				array('event' => $id),
349
+				'button-small'
350
+			);
351
+		}
352
+		return $permalink_string;
353
+	}
354
+
355
+
356
+
357
+	/**
358
+	 * Adds an iframe embed code button to the Event editor.
359
+	 *
360
+	 * return string
361
+	 */
362
+	public static function addEventListIframeEmbedButton()
363
+	{
364
+		// add button for iframe code to event editor.
365
+		$html = '';
366
+		//make sure this is ONLY when editing and the event id has been set.
367
+		if ($_GET['page'] === 'espresso_events') {
368
+			$html .= \EEH_HTML::h3(__('iFrame Embed Code', 'event_espresso'));
369
+			$html .= \EEH_HTML::p(
370
+				__('Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.',
371
+				'event_espresso')
372
+			);
373
+			$html .= ' &nbsp; ' . Iframe::embedButtonHtml(
374
+				'Events List',
375
+				'event_list'
376
+			) . ' ';
377
+			add_action(
378
+				'admin_enqueue_scripts',
379
+				array('\EventEspresso\core\libraries\iframe_display\Iframe', 'EventsAdminEmbedButtonAssets'),
380
+				10
381
+			);
382
+		}
383
+		return apply_filters(
384
+			'FHEE__Iframe__addEventListIframeEmbedButton__html',
385
+			$html
386
+		);
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * Adds an iframe embed code button via a WP do_action() as determined by the first parameter
393
+	 *
394
+	 * @param string $iframe_name
395
+	 * @param string $route_name the named module route that generates the iframe
396
+	 * @param string $action     name of the WP do_action() to hook into
397
+	 */
398
+	public static function addActionIframeEmbedButton($iframe_name, $route_name, $action)
399
+	{
400
+		// add button for iframe code to event editor.
401
+		add_action(
402
+			$action,
403
+			function () use ($iframe_name, $route_name) {
404
+				echo Iframe::embedButtonHtml($iframe_name, $route_name);
405
+			},
406
+			10
407
+		);
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter
414
+	 *
415
+	 * @param string $iframe_name
416
+	 * @param string $route_name the named module route that generates the iframe
417
+	 * @param string $filter     name of the WP apply_filters() to hook into
418
+	 * @param bool   $append     if true, will add iframe embed button to end of content,
419
+	 *                           else if false, will add to the beginning of the content
420
+	 */
421
+	public static function addFilterIframeEmbedButton($iframe_name, $route_name, $filter, $append = true)
422
+	{
423
+		// add button for iframe code to event editor.
424
+		add_action(
425
+			$filter,
426
+			function ($filterable_content) use ($iframe_name, $route_name, $append) {
427
+				$embedButtonHtml = Iframe::embedButtonHtml($iframe_name, $route_name);
428
+				if (is_array($filterable_content)) {
429
+					$filterable_content = $append
430
+						? array_push($filterable_content, $embedButtonHtml)
431
+						: array_unshift($filterable_content, $embedButtonHtml);
432
+				} else {
433
+					$filterable_content = $append
434
+						? $filterable_content . $embedButtonHtml
435
+						: $embedButtonHtml . $filterable_content;
436
+				}
437
+				return $filterable_content;
438
+			},
439
+			10
440
+		);
441
+	}
442
+
443
+
444
+
445
+	/**
446
+	 * iframe_embed_html
447
+	 *
448
+	 * @param string $iframe_name
449
+	 * @param string $route_name the named module route that generates the iframe
450
+	 * @param array  $query_args
451
+	 * @param string $button_class
452
+	 * @return string
453
+	 */
454
+	public static function embedButtonHtml($iframe_name, $route_name, $query_args = array(), $button_class = '')
455
+	{
456
+		$query_args = ! empty($query_args) ? $query_args : array($route_name => 'iframe');
457
+		// add this route to our localized vars
458
+		$iframe_module_routes = isset(\EE_Registry::$i18n_js_strings['iframe_module_routes'])
459
+			? \EE_Registry::$i18n_js_strings['iframe_module_routes']
460
+			: array();
461
+		$iframe_module_routes[$route_name] = $route_name;
462
+		\EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes;
463
+		$iframe_embed_html = \EEH_HTML::link(
464
+			'#',
465
+			sprintf(__('Embed %1$s', 'event_espresso'), $iframe_name),
466
+			sprintf(
467
+				__(
468
+					'click here to generate code for embedding an %1$s iframe into another site.',
469
+					'event_espresso'
470
+				),
471
+				$iframe_name
472
+			),
473
+			"$route_name-iframe-embed-trigger-js",
474
+			'iframe-embed-trigger-js button ' . $button_class,
475
+			'',
476
+			' data-iframe_embed_button="#' . $route_name . '-iframe-js" tabindex="-1"'
477
+		);
478
+		$iframe_embed_html .= \EEH_HTML::div('', "$route_name-iframe-js", 'iframe-embed-wrapper-js', 'display:none;');
479
+		$iframe_embed_html .= \EEH_HTML::div(
480
+			'<iframe src="' . add_query_arg($query_args, site_url()) . '" width="100%" height="100%"></iframe>',
481
+			'', '', 'width:100%; height: 500px;'
482
+		);
483
+		$iframe_embed_html .= \EEH_HTML::divx();
484
+		return $iframe_embed_html;
485
+	}
486
+
487
+
488
+
489
+	/**
490
+	 * iframe button js on admin events list or event editor page
491
+	 */
492
+	public static function EventsAdminEmbedButtonAssets()
493
+	{
494
+		if (\EE_Registry::instance()->REQ->get('page') === 'espresso_events') {
495
+			Iframe::embedButtonAssets();
496
+			\EE_Registry::$i18n_js_strings['iframe_embed_title'] = __(
497
+				'copy and paste the following into any other site\'s content to display this event:',
498
+				'event_espresso'
499
+			);
500
+		}
501
+	}
502
+
503
+
504
+
505
+	/**
506
+	 * enqueue iframe button js
507
+	 */
508
+	public static function embedButtonAssets()
509
+	{
510
+		\EE_Registry::$i18n_js_strings['iframe_embed_close_msg'] = __(
511
+			'click anywhere outside of this window to close it.',
512
+			'event_espresso'
513
+		);
514
+		wp_register_script(
515
+			'iframe_embed_button',
516
+			plugin_dir_url(__FILE__) . 'iframe-embed-button.js',
517
+			array('ee-dialog'),
518
+			EVENT_ESPRESSO_VERSION,
519
+			true
520
+		);
521
+		wp_enqueue_script('iframe_embed_button');
522
+	}
523 523
 
524 524
 
525 525
 
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
             apply_filters(
82 82
                 'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__construct__default_css',
83 83
                 array(
84
-                    'dashicons'        => includes_url('css/dashicons.min.css?ver=' . $wp_version),
84
+                    'dashicons'        => includes_url('css/dashicons.min.css?ver='.$wp_version),
85 85
                     'espresso_default' => EE_GLOBAL_ASSETS_URL
86 86
                                           . 'css/espresso_default.css?ver='
87 87
                                           . EVENT_ESPRESSO_VERSION,
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
             apply_filters(
93 93
                 'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__construct__default_js',
94 94
                 array(
95
-                    'jquery'        => includes_url('js/jquery/jquery.js?ver=' . $wp_version),
95
+                    'jquery'        => includes_url('js/jquery/jquery.js?ver='.$wp_version),
96 96
                     'espresso_core' => EE_GLOBAL_ASSETS_URL
97 97
                                        . 'scripts/espresso_core.js?ver='
98 98
                                        . EVENT_ESPRESSO_VERSION,
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
     public function getTemplate()
231 231
     {
232 232
         return \EEH_Template::display_template(
233
-            __DIR__ . '\iframe_wrapper.template.php',
233
+            __DIR__.'\iframe_wrapper.template.php',
234 234
             array(
235 235
                 'title'             => apply_filters(
236 236
                     'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__title',
@@ -244,24 +244,24 @@  discard block
 block discarded – undo
244 244
                     'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__enqueue_wp_assets',
245 245
                     $this->enqueue_wp_assets
246 246
                 ),
247
-                'css'               => (array)apply_filters(
247
+                'css'               => (array) apply_filters(
248 248
                     'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__css_urls',
249 249
                     $this->css
250 250
                 ),
251
-                'header_js'         => (array)apply_filters(
251
+                'header_js'         => (array) apply_filters(
252 252
                     'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__header_js_urls',
253 253
                     $this->header_js
254 254
                 ),
255
-                'footer_js'         => (array)apply_filters(
255
+                'footer_js'         => (array) apply_filters(
256 256
                     'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__footer_js_urls',
257 257
                     $this->footer_js
258 258
                 ),
259 259
                 'eei18n'            => apply_filters(
260 260
                     'FHEE__\EventEspresso\core\libraries\iframe_display\Iframe__getTemplate__eei18n_js_strings',
261
-                    \EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars()
261
+                    \EE_Registry::localize_i18n_js_strings().$this->localizeJsonVars()
262 262
                 ),
263 263
                 'notices'           => \EEH_Template::display_template(
264
-                    EE_TEMPLATES . 'espresso-ajax-notices.template.php',
264
+                    EE_TEMPLATES.'espresso-ajax-notices.template.php',
265 265
                     array(),
266 266
                     true
267 267
                 ),
@@ -280,14 +280,14 @@  discard block
 block discarded – undo
280 280
     public function localizeJsonVars()
281 281
     {
282 282
         $JSON = '';
283
-        $localized_vars = (array)$this->localized_vars;
283
+        $localized_vars = (array) $this->localized_vars;
284 284
         foreach ($localized_vars as $var_name => $vars) {
285 285
             foreach ($vars as $key => $value) {
286 286
                 if (is_scalar($value)) {
287
-                    $localized_vars[$var_name][$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
287
+                    $localized_vars[$var_name][$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
288 288
                 }
289 289
             }
290
-            $JSON .= "/* <![CDATA[ */ var $var_name = " . wp_json_encode($localized_vars[$var_name]) . '; /* ]]> */';
290
+            $JSON .= "/* <![CDATA[ */ var $var_name = ".wp_json_encode($localized_vars[$var_name]).'; /* ]]> */';
291 291
         }
292 292
         return $JSON;
293 293
     }
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
         // add button for iframe code to event editor.
305 305
         add_filter(
306 306
             'get_sample_permalink_html',
307
-            function ($permalink_string, $id, $new_title = '', $new_slug = '') use ($route_name) {
307
+            function($permalink_string, $id, $new_title = '', $new_slug = '') use ($route_name) {
308 308
                 return Iframe::eventListIframeEmbedButton($permalink_string, $id, $new_title, $new_slug, $route_name);
309 309
             },
310 310
             10, 2
@@ -370,10 +370,10 @@  discard block
 block discarded – undo
370 370
                 __('Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.',
371 371
                 'event_espresso')
372 372
             );
373
-            $html .= ' &nbsp; ' . Iframe::embedButtonHtml(
373
+            $html .= ' &nbsp; '.Iframe::embedButtonHtml(
374 374
                 'Events List',
375 375
                 'event_list'
376
-            ) . ' ';
376
+            ).' ';
377 377
             add_action(
378 378
                 'admin_enqueue_scripts',
379 379
                 array('\EventEspresso\core\libraries\iframe_display\Iframe', 'EventsAdminEmbedButtonAssets'),
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
         // add button for iframe code to event editor.
401 401
         add_action(
402 402
             $action,
403
-            function () use ($iframe_name, $route_name) {
403
+            function() use ($iframe_name, $route_name) {
404 404
                 echo Iframe::embedButtonHtml($iframe_name, $route_name);
405 405
             },
406 406
             10
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
         // add button for iframe code to event editor.
424 424
         add_action(
425 425
             $filter,
426
-            function ($filterable_content) use ($iframe_name, $route_name, $append) {
426
+            function($filterable_content) use ($iframe_name, $route_name, $append) {
427 427
                 $embedButtonHtml = Iframe::embedButtonHtml($iframe_name, $route_name);
428 428
                 if (is_array($filterable_content)) {
429 429
                     $filterable_content = $append
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
                         : array_unshift($filterable_content, $embedButtonHtml);
432 432
                 } else {
433 433
                     $filterable_content = $append
434
-                        ? $filterable_content . $embedButtonHtml
435
-                        : $embedButtonHtml . $filterable_content;
434
+                        ? $filterable_content.$embedButtonHtml
435
+                        : $embedButtonHtml.$filterable_content;
436 436
                 }
437 437
                 return $filterable_content;
438 438
             },
@@ -471,13 +471,13 @@  discard block
 block discarded – undo
471 471
                 $iframe_name
472 472
             ),
473 473
             "$route_name-iframe-embed-trigger-js",
474
-            'iframe-embed-trigger-js button ' . $button_class,
474
+            'iframe-embed-trigger-js button '.$button_class,
475 475
             '',
476
-            ' data-iframe_embed_button="#' . $route_name . '-iframe-js" tabindex="-1"'
476
+            ' data-iframe_embed_button="#'.$route_name.'-iframe-js" tabindex="-1"'
477 477
         );
478 478
         $iframe_embed_html .= \EEH_HTML::div('', "$route_name-iframe-js", 'iframe-embed-wrapper-js', 'display:none;');
479 479
         $iframe_embed_html .= \EEH_HTML::div(
480
-            '<iframe src="' . add_query_arg($query_args, site_url()) . '" width="100%" height="100%"></iframe>',
480
+            '<iframe src="'.add_query_arg($query_args, site_url()).'" width="100%" height="100%"></iframe>',
481 481
             '', '', 'width:100%; height: 500px;'
482 482
         );
483 483
         $iframe_embed_html .= \EEH_HTML::divx();
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
         );
514 514
         wp_register_script(
515 515
             'iframe_embed_button',
516
-            plugin_dir_url(__FILE__) . 'iframe-embed-button.js',
516
+            plugin_dir_url(__FILE__).'iframe-embed-button.js',
517 517
             array('ee-dialog'),
518 518
             EVENT_ESPRESSO_VERSION,
519 519
             true
Please login to merge, or discard this patch.