|
1
|
|
|
<?php |
|
2
|
|
|
namespace EventEspresso\core\libraries\iframe_display; |
|
3
|
|
|
|
|
4
|
|
|
defined( 'ABSPATH' ) || exit; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class IframeEmbedButton |
|
10
|
|
|
* |
|
11
|
|
|
* @package Event Espresso |
|
12
|
|
|
* @author Brent Christensen |
|
13
|
|
|
* @since 4.9 |
|
14
|
|
|
*/ |
|
15
|
|
|
abstract class IframeEmbedButton { |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string $iframe_name |
|
20
|
|
|
*/ |
|
21
|
|
|
private $iframe_name; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string $route_name |
|
25
|
|
|
*/ |
|
26
|
|
|
private $route_name; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string $title |
|
30
|
|
|
*/ |
|
31
|
|
|
private $title; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string $slug |
|
35
|
|
|
*/ |
|
36
|
|
|
private $slug; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var boolean $append_filterable_content |
|
40
|
|
|
*/ |
|
41
|
|
|
private $append_filterable_content; |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* IframeEmbedButton constructor. |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $iframe_name |
|
49
|
|
|
* @param string $route_name |
|
50
|
|
|
* @param string $title |
|
51
|
|
|
* @param string $slug |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct($iframe_name, $route_name, $title, $slug) { |
|
54
|
|
|
$this->iframe_name = $iframe_name; |
|
55
|
|
|
$this->route_name = $route_name; |
|
56
|
|
|
$this->title = $title; |
|
57
|
|
|
$this->slug = $slug; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Adds an iframe embed code button to the Event editor. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function addEventEditorIframeEmbedButtonFilter() |
|
66
|
|
|
{ |
|
67
|
|
|
// add button for iframe code to event editor. |
|
68
|
|
|
add_filter( |
|
69
|
|
|
'get_sample_permalink_html', |
|
70
|
|
|
array($this, 'appendIframeEmbedButtonToSamplePermalinkHtml'), |
|
71
|
|
|
10, |
|
72
|
|
|
2 |
|
73
|
|
|
); |
|
74
|
|
|
add_action( |
|
75
|
|
|
'admin_enqueue_scripts', |
|
76
|
|
|
array($this, 'embedButtonAssets'), |
|
77
|
|
|
10 |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param $permalink_string |
|
85
|
|
|
* @param $id |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
public function appendIframeEmbedButtonToSamplePermalinkHtml( $permalink_string, $id ) { |
|
89
|
|
|
return $this->eventEditorIframeEmbedButton( |
|
90
|
|
|
$permalink_string, |
|
91
|
|
|
$id |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* iframe embed code button to the Event editor. |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $permalink_string |
|
101
|
|
|
* @param int $id |
|
102
|
|
|
* @return string |
|
103
|
|
|
*/ |
|
104
|
|
|
public function eventEditorIframeEmbedButton( |
|
105
|
|
|
$permalink_string, |
|
106
|
|
|
$id |
|
107
|
|
|
) { |
|
108
|
|
|
//make sure this is ONLY when editing and the event id has been set. |
|
109
|
|
|
if ( ! empty($id)) { |
|
110
|
|
|
$post = get_post($id); |
|
111
|
|
|
//if NOT event then let's get out. |
|
112
|
|
|
if ($post->post_type !== 'espresso_events') { |
|
113
|
|
|
return $permalink_string; |
|
114
|
|
|
} |
|
115
|
|
|
$permalink_string .= $this->embedButtonHtml( |
|
116
|
|
|
array($this->slug => $id), |
|
117
|
|
|
'button-small' |
|
118
|
|
|
); |
|
119
|
|
|
} |
|
120
|
|
|
return $permalink_string; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Adds an iframe embed code button via a WP do_action() as determined by the first parameter |
|
126
|
|
|
* |
|
127
|
|
|
* @param string $action name of the WP do_action() to hook into |
|
128
|
|
|
*/ |
|
129
|
|
|
public function addActionIframeEmbedButton($action) { |
|
130
|
|
|
// add button for iframe code to event editor. |
|
131
|
|
|
add_action( |
|
132
|
|
|
$action, |
|
133
|
|
|
array($this, 'addActionIframeEmbedButtonCallback'), |
|
134
|
|
|
10, 2 |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @return void |
|
142
|
|
|
*/ |
|
143
|
|
|
public function addActionIframeEmbedButtonCallback() |
|
144
|
|
|
{ |
|
145
|
|
|
echo $this->embedButtonHtml(); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter |
|
152
|
|
|
* |
|
153
|
|
|
* @param string $filter name of the WP apply_filters() to hook into |
|
154
|
|
|
* @param bool $append if true, will add iframe embed button to end of content, |
|
155
|
|
|
* else if false, will add to the beginning of the content |
|
156
|
|
|
*/ |
|
157
|
|
|
public function addFilterIframeEmbedButton($filter, $append = true) { |
|
158
|
|
|
$this->append_filterable_content = $append; |
|
159
|
|
|
// add button for iframe code to event editor. |
|
160
|
|
|
add_filter( |
|
161
|
|
|
$filter, |
|
162
|
|
|
array($this, 'addFilterIframeEmbedButtonCallback'), |
|
163
|
|
|
10 |
|
164
|
|
|
); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
|
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @param array|string $filterable_content |
|
171
|
|
|
* @return array|string |
|
172
|
|
|
*/ |
|
173
|
|
|
public function addFilterIframeEmbedButtonCallback($filterable_content) |
|
174
|
|
|
{ |
|
175
|
|
|
$embedButtonHtml = $this->embedButtonHtml(); |
|
176
|
|
|
if (is_array($filterable_content)) { |
|
177
|
|
|
$filterable_content = $this->append_filterable_content |
|
178
|
|
|
? $filterable_content + array($this->route_name => $embedButtonHtml) |
|
179
|
|
|
: array($this->route_name => $embedButtonHtml) + $filterable_content; |
|
180
|
|
|
} else { |
|
181
|
|
|
$filterable_content = $this->append_filterable_content |
|
182
|
|
|
? $filterable_content . $embedButtonHtml |
|
183
|
|
|
: $embedButtonHtml . $filterable_content; |
|
184
|
|
|
} |
|
185
|
|
|
return $filterable_content; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* iframe_embed_html |
|
190
|
|
|
* |
|
191
|
|
|
* @param array $query_args |
|
192
|
|
|
* @param string $button_class |
|
193
|
|
|
* @return string |
|
194
|
|
|
*/ |
|
195
|
|
|
public function embedButtonHtml($query_args = array(), $button_class = '' ) { |
|
196
|
|
|
$query_args = array($this->route_name => 'iframe') + $query_args; |
|
197
|
|
|
$query_args = (array) apply_filters( |
|
198
|
|
|
'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args', |
|
199
|
|
|
$query_args |
|
200
|
|
|
); |
|
201
|
|
|
// add this route to our localized vars |
|
202
|
|
|
$iframe_module_routes = isset( \EE_Registry::$i18n_js_strings['iframe_module_routes'] ) |
|
203
|
|
|
? \EE_Registry::$i18n_js_strings['iframe_module_routes'] |
|
204
|
|
|
: array(); |
|
205
|
|
|
$iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
206
|
|
|
\EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes; |
|
207
|
|
|
$iframe_embed_html = \EEH_HTML::link( |
|
208
|
|
|
'#', |
|
209
|
|
|
sprintf( esc_html__( 'Embed %1$s', 'event_espresso' ), $this->iframe_name ), |
|
210
|
|
|
sprintf( |
|
211
|
|
|
esc_html__( |
|
212
|
|
|
'click here to generate code for embedding %1$s iframe into another site.', |
|
213
|
|
|
'event_espresso' |
|
214
|
|
|
), |
|
215
|
|
|
\EEH_Inflector::add_indefinite_article($this->iframe_name) |
|
216
|
|
|
), |
|
217
|
|
|
"{$this->route_name}-iframe-embed-trigger-js", |
|
218
|
|
|
'iframe-embed-trigger-js button ' . $button_class, |
|
219
|
|
|
'', |
|
220
|
|
|
' data-iframe_embed_button="#' . $this->route_name . '-iframe-js" tabindex="-1"' |
|
221
|
|
|
); |
|
222
|
|
|
$iframe_embed_html .= \EEH_HTML::div( '', "{$this->route_name}-iframe-js", 'iframe-embed-wrapper-js', 'display:none;' ); |
|
223
|
|
|
$iframe_embed_html .= esc_html( |
|
224
|
|
|
\EEH_HTML::div( |
|
225
|
|
|
'<iframe src="' . add_query_arg( $query_args, site_url() ) . '" width="100%" height="100%"></iframe>', |
|
226
|
|
|
'', |
|
227
|
|
|
'', |
|
228
|
|
|
'width:100%; height: 500px;' |
|
229
|
|
|
) |
|
230
|
|
|
); |
|
231
|
|
|
$iframe_embed_html .= \EEH_HTML::divx(); |
|
232
|
|
|
return $iframe_embed_html; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
|
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* enqueue iframe button js |
|
239
|
|
|
*/ |
|
240
|
|
|
public function embedButtonAssets() { |
|
241
|
|
|
\EE_Registry::$i18n_js_strings['iframe_embed_title'] = esc_html__( |
|
242
|
|
|
'copy and paste the following into any other site\'s content to display this event:', |
|
243
|
|
|
'event_espresso' |
|
244
|
|
|
); |
|
245
|
|
|
\EE_Registry::$i18n_js_strings['iframe_embed_close_msg'] = esc_html__( |
|
246
|
|
|
'click anywhere outside of this window to close it.', |
|
247
|
|
|
'event_espresso' |
|
248
|
|
|
); |
|
249
|
|
|
wp_register_script( |
|
250
|
|
|
'iframe_embed_button', |
|
251
|
|
|
plugin_dir_url( __FILE__ ) . 'iframe-embed-button.js', |
|
252
|
|
|
array( 'ee-dialog' ), |
|
253
|
|
|
EVENT_ESPRESSO_VERSION, |
|
254
|
|
|
true |
|
255
|
|
|
); |
|
256
|
|
|
wp_enqueue_script( 'iframe_embed_button' ); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
|
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* generates embed button sections for admin pages |
|
263
|
|
|
* |
|
264
|
|
|
* @param array $embed_buttons |
|
265
|
|
|
* @return string |
|
266
|
|
|
*/ |
|
267
|
|
|
public function addIframeEmbedButtonsSection(array $embed_buttons) |
|
268
|
|
|
{ |
|
269
|
|
|
$embed_buttons = (array)apply_filters( |
|
270
|
|
|
'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons', |
|
271
|
|
|
$embed_buttons |
|
272
|
|
|
); |
|
273
|
|
|
// add button for iframe code to event editor. |
|
274
|
|
|
$html = \EEH_HTML::br(2); |
|
275
|
|
|
$html .= \EEH_HTML::h3(esc_html__('iFrame Embed Code', 'event_espresso')); |
|
276
|
|
|
$html .= \EEH_HTML::p( |
|
277
|
|
|
esc_html__( |
|
278
|
|
|
'Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.', |
|
279
|
|
|
'event_espresso' |
|
280
|
|
|
) |
|
281
|
|
|
); |
|
282
|
|
|
$html .= ' ' . implode(' ', $embed_buttons) . ' '; |
|
283
|
|
|
$html .= \EEH_HTML::br(2); |
|
284
|
|
|
return $html; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
|
|
288
|
|
|
} |
|
289
|
|
|
// End of file IframeEmbedButton.php |
|
290
|
|
|
// Location: EventEspresso\core\libraries\iframe_display/IframeEmbedButton.php |