PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.9.15
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.9.15
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Includes / Classes / Helper.php
embedpress / EmbedPress / Includes / Classes Last commit date
Elementor_Enhancer.php 2 years ago EmbedPress_Core_Installer.php 6 years ago EmbedPress_Notice.php 2 years ago EmbedPress_Plugin_Usage_Tracker.php 2 years ago Extend_CustomPlayer_Controls.php 3 years ago Extend_Elementor_Controls.php 2 years ago Feature_Enhancer.php 2 years ago Helper.php 2 years ago
Helper.php
981 lines
1 <?php
2
3 namespace EmbedPress\Includes\Classes;
4
5 use EmbedPress\Shortcode;
6
7 if (!defined('ABSPATH')) {
8 exit;
9 } // Exit if accessed directly
10
11 class Helper
12 {
13
14 /**
15 * Parse a query string into an associative array.
16 *
17 * If multiple values are found for the same key, the value of that key
18 * value pair will become an array. This function does not parse nested
19 * PHP style arrays into an associative array (e.g., foo[a]=1&foo[b]=2 will
20 * be parsed into ['foo[a]' => '1', 'foo[b]' => '2']).
21 *
22 * @param string $str Query string to parse
23 * @param int|bool $urlEncoding How the query string is encoded
24 *
25 * @return array
26 */
27
28 public function __construct()
29 {
30 add_action('wp_ajax_lock_content_form_handler', [$this, 'lock_content_form_handler']);
31 add_action('wp_ajax_nopriv_lock_content_form_handler', [$this, 'lock_content_form_handler']);
32 add_action('wp_head', [$this, 'ep_add_meta_tags']);
33 }
34
35 public function ep_add_meta_tags()
36 {
37 echo 'abstract';
38 }
39
40 public static function parse_query($str, $urlEncoding = true)
41 {
42 $result = [];
43
44 if ($str === '') {
45 return $result;
46 }
47
48 if ($urlEncoding === true) {
49 $decoder = function ($value) {
50 return rawurldecode(str_replace('+', ' ', $value));
51 };
52 } elseif ($urlEncoding === PHP_QUERY_RFC3986) {
53 $decoder = 'rawurldecode';
54 } elseif ($urlEncoding === PHP_QUERY_RFC1738) {
55 $decoder = 'urldecode';
56 } else {
57 $decoder = function ($str) {
58 return $str;
59 };
60 }
61
62 foreach (explode('&', $str) as $kvp) {
63 $parts = explode('=', $kvp, 2);
64 $key = $decoder($parts[0]);
65 $value = isset($parts[1]) ? $decoder($parts[1]) : null;
66 if (!isset($result[$key])) {
67 $result[$key] = $value;
68 } else {
69 if (!is_array($result[$key])) {
70 $result[$key] = [$result[$key]];
71 }
72 $result[$key][] = $value;
73 }
74 }
75
76 return $result;
77 }
78 public static function get_pdf_renderer()
79 {
80 // $renderer = EMBEDPRESS_URL_ASSETS . 'pdf/web/viewer.html';
81
82 $renderer = admin_url('admin-ajax.php?action=get_viewer');
83
84 // @TODO; apply settings query args here
85 return $renderer;
86 }
87
88 public static function get_extension_from_file_url($url)
89 {
90 $urlSplit = explode(".", $url);
91 $ext = end($urlSplit);
92 return $ext;
93 }
94
95 public static function is_file_url($url)
96 {
97 $pattern = '/\.([0-9a-z]+)(?=[?#])|(\.)(?:[\w]+)$/i';
98 return preg_match($pattern, $url) === 1;
99 }
100
101 public static function is_opensea($url)
102 {
103 return strpos($url, "opensea.io") !== false;
104 }
105 public static function is_youtube_channel($url)
106 {
107 return (bool) (preg_match('~(?:https?:\/\/)?(?:www\.)?(?:youtube.com\/)(?:channel\/|c\/|user\/|@)(\w+)~i', (string) $url));
108 }
109
110 public static function is_youtube($url)
111 {
112 return (bool) (preg_match('~(?:https?://)?(?:www\.)?(?:youtube\.com|youtu\.be)/watch\?v=([^&]+)~i', (string) $url));
113 }
114
115 // Saved sources data temporary in wp_options table
116 public static function get_source_data($blockid, $source_url, $source_option_name, $source_temp_option_name)
117 {
118
119
120 if (self::is_youtube_channel($source_url)) {
121 $source_name = 'YoutubeChannel';
122 } else if (self::is_youtube($source_url)) {
123 $source_name = 'Youtube';
124 } else if (!empty(self::is_file_url($source_url))) {
125 $source_name = 'document_' . self::get_extension_from_file_url($source_url);
126 } else if (self::is_opensea($source_url)) {
127 $source_name = 'OpenSea';
128 } else {
129 Shortcode::get_embera_instance();
130 $collectios = Shortcode::get_collection();
131 $provider = $collectios->findProviders($source_url);
132 if (!empty($provider[$source_url])) {
133 $source_name = $provider[$source_url]->getProviderName();
134 } else {
135 $source_name = 'Unknown Source';
136 }
137 }
138
139 if (!empty($blockid) && $blockid != 'undefined') {
140 $sources = json_decode(get_option($source_temp_option_name), true);
141
142 if (!$sources) {
143 $sources = array();
144 }
145 $exists = false;
146
147 foreach ($sources as $i => $source) {
148 if ($source['id'] === $blockid) {
149 $sources[$i]['source']['name'] = $source_name;
150 $sources[$i]['source']['url'] = $source_url;
151 $exists = true;
152 break;
153 }
154 }
155
156 if (!$exists) {
157 $sources[] = array('id' => $blockid, 'source' => array('name' => $source_name, 'url' => $source_url, 'count' => 1));
158 }
159
160 update_option($source_temp_option_name, json_encode($sources));
161 }
162 }
163
164 // Saved source data when post updated
165 public static function get_save_source_data_on_post_update($source_option_name, $source_temp_option_name)
166 {
167
168 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
169 return;
170 }
171 $temp_data = json_decode(get_option($source_temp_option_name), true);
172 $source_data = json_decode(get_option($source_option_name), true);
173 if (!$temp_data) {
174 $temp_data = array();
175 }
176 if (!$source_data) {
177 $source_data = array();
178 }
179
180 $sources = array_merge($temp_data, $source_data);
181
182 $unique_sources = array();
183 foreach ($sources as $source) {
184 $unique_sources[$source['id']] = $source;
185 }
186
187 $unique_sources = array_values($unique_sources);
188
189 delete_option($source_temp_option_name);
190
191 update_option($source_option_name, json_encode($unique_sources));
192 }
193
194 //Delete source data from option table when widget is removed
195 public static function get_delete_source_data($blockid, $source_option_name, $source_temp_option_name)
196 {
197 if (!empty($blockid) && $blockid != 'undefined') {
198 $sources = json_decode(get_option($source_option_name), true);
199 $temp_sources = json_decode(get_option($source_temp_option_name), true);
200 if ($sources) {
201 foreach ($sources as $i => $source) {
202 if ($source['id'] === $blockid) {
203 unset($sources[$i]);
204 break;
205 }
206 }
207 update_option($source_option_name, json_encode(array_values($sources)));
208 }
209 if ($temp_sources) {
210 foreach ($temp_sources as $i => $source) {
211 if ($source['id'] === $blockid) {
212 unset($temp_sources[$i]);
213 break;
214 }
215 }
216 update_option($source_temp_option_name, json_encode(array_values($temp_sources)));
217 }
218 }
219 wp_die();
220 }
221
222 //Delete source temporary data when reload without update or publish
223 public static function get_delete_source_temp_data_on_reload($source_temp_option_name)
224 {
225 $source_temp_data = json_decode(get_option($source_temp_option_name), true);
226 if ($source_temp_data) {
227 delete_option($source_temp_option_name);
228 }
229 }
230
231 public static function get_file_title($url)
232 {
233 return get_the_title(attachment_url_to_postid($url));
234 }
235
236 public static function get_hash()
237 {
238 $hash_key = get_option(EMBEDPRESS_PLG_NAME . '_hash_key');
239 if (!$hash_key) {
240 $hash_key = wp_hash_password(wp_generate_password(30));
241 update_option(EMBEDPRESS_PLG_NAME . '_hash_key', $hash_key);
242 }
243 return $hash_key;
244 }
245
246 public function lock_content_form_handler()
247 {
248
249 $client_id = isset($_POST['client_id']) ? sanitize_text_field($_POST['client_id']) : '';
250 $password = isset($_POST['password']) ? sanitize_text_field($_POST['password']) : '';
251 $post_id = isset($_POST['post_id']) ? absint($_POST['post_id']) : 0;
252
253 $epbase64 = get_post_meta($post_id, 'ep_base_' . $client_id, false);
254 $hash_key = get_post_meta($post_id, 'hash_key_' . $client_id, false);
255
256 // Set the decryption key and initialization vector (IV)
257 $key = self::get_hash();
258
259 // Decode the base64 encoded cipher
260 $cipher = base64_decode($epbase64);
261 // Decrypt the cipher using AES-128-CBC encryption
262
263 $wp_pass_key = hash('sha256', wp_salt(32) . md5($password));
264 $iv = substr($wp_pass_key, 0, 16);
265 if ($wp_pass_key === $hash_key) {
266 setcookie("password_correct_", $password, time() + 3600);
267
268 $embed = openssl_decrypt($cipher, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv) . '<script>
269 const now = new Date();
270 const time = now.getTime();
271 const expireTime = time + 1000 * 60 * 60 * 24 * 30;
272 now.setTime(expireTime);
273 document.cookie = "password_correct_' . esc_js($client_id) . '=' . esc_js($hash_key) . '; expires=" + now.toUTCString() + "; path=/";
274 </script>';
275 } else {
276 $embed = 0;
277 }
278
279 // Process the form data and return a response
280 $response = array(
281 'success' => true,
282 'password' => $password,
283 'embedHtml' => $embed,
284 );
285
286 wp_send_json($response);
287 }
288
289 public static function display_password_form($client_id = '', $embedHtml = '', $pass_hash_key = '', $attributes = [])
290 {
291 $lock_heading = !empty($attributes['lockHeading']) ? sanitize_text_field($attributes['lockHeading']) : '';
292 $lock_subheading = !empty($attributes['lockSubHeading']) ? sanitize_text_field($attributes['lockSubHeading']) : '';
293 $lock_error_message = !empty($attributes['lockErrorMessage']) ? sanitize_text_field($attributes['lockErrorMessage']) : '';
294 $footer_message = !empty($attributes['footerMessage']) ? sanitize_text_field($attributes['footerMessage']) : '';
295 $password_placeholder = !empty($attributes['passwordPlaceholder']) ? sanitize_text_field($attributes['passwordPlaceholder']) : '';
296 $button_text = !empty($attributes['submitButtonText']) ? sanitize_text_field($attributes['submitButtonText']) : '';
297 $unlocking_text = !empty($attributes['submitUnlockingText']) ? sanitize_text_field($attributes['submitUnlockingText']) : '';
298 $enable_footer_message = !empty($attributes['enableFooterMessage']) ? sanitize_text_field($attributes['enableFooterMessage']) : '';
299
300
301 // Set the encryption key and initialization vector (IV)
302 $key = self::get_hash();
303
304 $salt = wp_salt(32);
305 $wp_hash_key = hash('sha256', $salt . $pass_hash_key);
306 $iv = substr($wp_hash_key, 0, 16);
307
308
309 // Encrypt the plaintext using AES-128-CBC encryption
310 $cipher = openssl_encrypt($embedHtml, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv);
311
312 // Base64 encode the encrypted cipher
313 $encrypted_data = base64_encode($cipher);
314
315 update_post_meta(get_the_ID(), 'ep_base_' . $client_id, $encrypted_data);
316 update_post_meta(get_the_ID(), 'hash_key_' . $client_id, $wp_hash_key);
317
318 $lock_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><g fill="#6354a5" class="color134563 svgShape"><path d="M46.3 28.7h-3v-6.4C43.3 16.1 38.2 11 32 11c-6.2 0-11.3 5.1-11.3 11.3v6.4h-3v-6.4C17.7 14.4 24.1 8 32 8s14.3 6.4 14.3 14.3v6.4" fill="#6354a5" class="color000000 svgShape"></path><path d="M44.8 55.9H19.2c-2.6 0-4.8-2.2-4.8-4.8V31.9c0-2.6 2.2-4.8 4.8-4.8h25.6c2.6 0 4.8 2.2 4.8 4.8v19.2c0 2.7-2.2 4.8-4.8 4.8zM19.2 30.3c-.9 0-1.6.7-1.6 1.6v19.2c0 .9.7 1.6 1.6 1.6h25.6c.9 0 1.6-.7 1.6-1.6V31.9c0-.9-.7-1.6-1.6-1.6H19.2z" fill="#6354a5" class="color000000 svgShape"></path><path d="M35.2 36.7c0 1.8-1.4 3.2-3.2 3.2s-3.2-1.4-3.2-3.2 1.4-3.2 3.2-3.2 3.2 1.5 3.2 3.2" fill="#6354a5" class="color000000 svgShape"></path><path d="M32.8 36.7h-1.6l-1.6 9.6h4.8l-1.6-9.6" fill="#6354a5" class="color000000 svgShape"></path></g></svg>';
319
320 echo '
321 <div class="password-form-container">
322 <h2>' . esc_html($lock_heading) . '</h2>
323 <p>' . esc_html($lock_subheading) . ' </p>
324 <form class="password-form" method="post" class="password-form" data-unlocking-text="' . esc_attr($unlocking_text) . '">
325
326 <div class="password-field">
327 <span class="lock-icon">' . $lock_icon . '</span>
328 <input type="password" name="pass_' . esc_attr($client_id) . '" placeholder="' . esc_attr($password_placeholder) . '" required>
329 </div>
330 <input type="hidden" name="ep_client_id" value="' . esc_attr($client_id) . '">
331 <input type="hidden" name="post_id" value="' . esc_attr(get_the_ID()) . '">
332
333 <input type="submit" name="password_submit" value="' . esc_attr($button_text) . '">
334 <div class="error-message hidden">' . esc_html($lock_error_message) . '</div>
335 </form>
336 ' . (!empty($enable_footer_message) ? '<p class="need-access-message">' . esc_html($footer_message) . '</p>' : '') . '
337 </div>
338 ';
339 }
340
341 // Check if the user has already entered the correct password
342 public static function is_password_correct($client_id)
343 {
344 if (isset($_COOKIE['password_correct_' . $client_id])) {
345 return $_COOKIE['password_correct_' . $client_id];
346 } else {
347 return false;
348 }
349 }
350
351 public static function customLogo($embedHTML, $atts)
352 {
353 $x = !empty($atts['logoX']) ? $atts['logoX'] : 0;
354 $y = !empty($atts['logoY']) ? $atts['logoY'] : 0;
355 $uniqid = !empty($atts['url']) ? '.ose-uid-' . md5($atts['url']) : '';
356
357 $brandUrl = !empty($atts['customlogoUrl']) ? $atts['customlogoUrl'] : '';
358 $opacity = !empty($atts['logoOpacity']) ? $atts['logoOpacity'] : '';
359
360 $cssClass = !empty($atts['url']) ? '.ose-uid-' . md5($atts['url']) : '.ose-youtube';
361
362
363
364 ob_start(); ?>
365 <style type="text/css">
366 <?php echo esc_html($cssClass); ?> {
367 position: relative;
368 }
369
370 <?php echo esc_html($cssClass); ?>.watermark {
371 border: 0;
372 position: absolute;
373 bottom: <?php echo esc_html($y); ?>%;
374 right: <?php echo esc_html($x); ?>%;
375 max-width: 150px;
376 max-height: 75px;
377 opacity: 0.25;
378 z-index: 5;
379 -o-transition: opacity 0.5s ease-in-out;
380 -moz-transition: opacity 0.5s ease-in-out;
381 -webkit-transition: opacity 0.5s ease-in-out;
382 transition: opacity 0.5s ease-in-out;
383 opacity: <?php echo esc_html($opacity); ?>;
384 }
385
386 <?php echo esc_html($cssClass); ?>.watermark:hover {
387 opacity: 1;
388 }
389 </style>
390 <?php
391
392
393 $style = ob_get_clean();
394
395 if (!class_exists('\simple_html_dom')) {
396 include_once EMBEDPRESS_PATH_CORE . 'simple_html_dom.php';
397 }
398
399 $cta = '';
400 $img = '';
401
402 if (!empty($atts['customlogo'])) {
403 $img = '<img src="' . esc_url($atts['customlogo']) . '"/>';
404
405 $imgDom = str_get_html($img);
406 $imgDom = $imgDom->find('img', 0);
407 $imgDom->setAttribute('class', 'watermark ep-custom-logo');
408 $imgDom->removeAttribute('style');
409 $imgDom->setAttribute('width', 'auto');
410 $imgDom->setAttribute('height', 'auto');
411 ob_start();
412 echo $imgDom;
413
414 $cta .= ob_get_clean();
415
416 $imgDom->clear();
417 unset($img, $imgDom);
418
419 if (!empty($brandUrl)) {
420 $cta = '<a href="' . esc_url($brandUrl) . '" target="_blank">' . $cta . '</a>';
421 }
422 $dom = str_get_html($embedHTML);
423
424 $wrapDiv = $dom->find($uniqid, 0);
425
426 if (!empty($wrapDiv) && is_object($wrapDiv)) {
427 $wrapDiv->innertext .= $cta;
428 }
429
430 ob_start();
431 echo $wrapDiv;
432
433 $markup = ob_get_clean();
434
435 $dom->clear();
436 unset($dom, $wrapDiv);
437
438 $embedHTML = $style . $markup;
439 }
440
441 return $embedHTML;
442 }
443
444
445 public static function embed_content_share($content_id = '', $attributes = [])
446 {
447
448 $share_position = !empty($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
449 $custom_thumnail = !empty($attributes['customThumbnail']) ? urlencode($attributes['customThumbnail']) : '';
450 $custom_title = !empty($attributes['customTitle']) ? urlencode($attributes['customTitle']) : '';
451 $custom_description = !empty($attributes['customDescription']) ? urlencode($attributes['customDescription']) : '';
452
453 $page_url = urlencode(get_permalink() . '?hash=' . $content_id);
454
455 $social_icons = '<div class="ep-social-share-wraper"><div class="ep-social-share share-position-' . esc_attr($share_position) . '">';
456 $social_icons .= '<a href="https://www.facebook.com/sharer/sharer.php?u=' . $page_url . '" class="ep-social-icon facebook" target="_blank">
457 <svg width="64px" height="64px" fill="#000000" viewBox="0 -6 512 512" xmlns="http://www.w3.org/2000/svg">
458 <path d="M0 0h512v500H0z" fill="#475a96"/>
459 <path d="m375.72 112.55h-237.43c-8.137 0-14.73 6.594-14.73 14.73v237.43c0 8.135 6.594 14.73 14.73 14.73h127.83v-103.36h-34.781v-40.28h34.781v-29.705c0-34.473 21.055-53.244 51.807-53.244 14.73 0 27.391 1.097 31.08 1.587v36.026l-21.328 0.01c-16.725 0-19.963 7.947-19.963 19.609v25.717h39.887l-5.193 40.28h-34.693v103.36h68.012c8.135 0 14.73-6.596 14.73-14.73v-237.43c-1e-3 -8.137-6.596-14.73-14.731-14.73z" fill="#fff"/>
460 </svg>
461 </a>';
462 $social_icons .= '<a href="https://twitter.com/intent/tweet?url=' . $page_url . '&text=' . $custom_title . '" class="ep-social-icon twitter" target="_blank">
463 <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="0 0 248 204">
464 <path fill="#ffffff"
465 d="M221.95 51.29c.15 2.17.15 4.34.15 6.53 0 66.73-50.8 143.69-143.69 143.69v-.04c-27.44.04-54.31-7.82-77.41-22.64 3.99.48 8 .72 12.02.73 22.74.02 44.83-7.61 62.72-21.66-21.61-.41-40.56-14.5-47.18-35.07 7.57 1.46 15.37 1.16 22.8-.87-23.56-4.76-40.51-25.46-40.51-49.5v-.64c7.02 3.91 14.88 6.08 22.92 6.32C11.58 63.31 4.74 33.79 18.14 10.71c25.64 31.55 63.47 50.73 104.08 52.76-4.07-17.54 1.49-35.92 14.61-48.25 20.34-19.12 52.33-18.14 71.45 2.19 11.31-2.23 22.15-6.38 32.07-12.26-3.77 11.69-11.66 21.62-22.2 27.93 10.01-1.18 19.79-3.86 29-7.95-6.78 10.16-15.32 19.01-25.2 26.16z" />
466 </svg>
467 </a>';
468 $social_icons .= '<a href="http://pinterest.com/pin/create/button/?url=' . $page_url . '&media=' . $custom_thumnail . '&description=' . $custom_description . '" class="ep-social-icon pinterest" target="_blank">
469
470 <svg xmlns="http://www.w3.org/2000/svg" height="800" width="1200" viewBox="-36.42015 -60.8 315.6413 364.8"><path d="M121.5 0C54.4 0 0 54.4 0 121.5 0 173 32 217 77.2 234.7c-1.1-9.6-2-24.4.4-34.9 2.2-9.5 14.2-60.4 14.2-60.4s-3.6-7.3-3.6-18c0-16.9 9.8-29.5 22-29.5 10.4 0 15.4 7.8 15.4 17.1 0 10.4-6.6 26-10.1 40.5-2.9 12.1 6.1 22 18 22 21.6 0 38.2-22.8 38.2-55.6 0-29.1-20.9-49.4-50.8-49.4-34.6 0-54.9 25.9-54.9 52.7 0 10.4 4 21.6 9 27.7 1 1.2 1.1 2.3.8 3.5-.9 3.8-3 12.1-3.4 13.8-.5 2.2-1.8 2.7-4.1 1.6-15.2-7.1-24.7-29.2-24.7-47.1 0-38.3 27.8-73.5 80.3-73.5 42.1 0 74.9 30 74.9 70.2 0 41.9-26.4 75.6-63 75.6-12.3 0-23.9-6.4-27.8-14 0 0-6.1 23.2-7.6 28.9-2.7 10.6-10.1 23.8-15.1 31.9 11.4 3.5 23.4 5.4 36 5.4 67.1 0 121.5-54.4 121.5-121.5C243 54.4 188.6 0 121.5 0z" fill="#fff"/></svg>
471
472 </a>';
473
474 $social_icons .= '<a href="https://www.linkedin.com/sharing/share-offsite/?url=' . $page_url . '&title=' . $custom_title . '&summary=' . $custom_description . '&source=LinkedIn" class="ep-social-icon linkedin" target="_blank">
475
476 <svg fill="#ffffff" height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
477 viewBox="0 0 310 310" xml:space="preserve">
478 <g id="XMLID_801_">
479 <path id="XMLID_802_" d="M72.16,99.73H9.927c-2.762,0-5,2.239-5,5v199.928c0,2.762,2.238,5,5,5H72.16c2.762,0,5-2.238,5-5V104.73
480 C77.16,101.969,74.922,99.73,72.16,99.73z"/>
481 <path id="XMLID_803_" d="M41.066,0.341C18.422,0.341,0,18.743,0,41.362C0,63.991,18.422,82.4,41.066,82.4
482 c22.626,0,41.033-18.41,41.033-41.038C82.1,18.743,63.692,0.341,41.066,0.341z"/>
483 <path id="XMLID_804_" d="M230.454,94.761c-24.995,0-43.472,10.745-54.679,22.954V104.73c0-2.761-2.238-5-5-5h-59.599
484 c-2.762,0-5,2.239-5,5v199.928c0,2.762,2.238,5,5,5h62.097c2.762,0,5-2.238,5-5v-98.918c0-33.333,9.054-46.319,32.29-46.319
485 c25.306,0,27.317,20.818,27.317,48.034v97.204c0,2.762,2.238,5,5,5H305c2.762,0,5-2.238,5-5V194.995
486 C310,145.43,300.549,94.761,230.454,94.761z"/>
487 </g>
488 </svg>
489 </a>';
490 $social_icons .= '</div></div>';
491
492 return $social_icons;
493 }
494
495 public static function ep_get_elementor_widget_settings($page_settings = '', $id = '', $widgetType = '')
496 {
497
498 $data = json_decode($page_settings, true);
499
500 // Search for the element with the given ID
501 $element = null;
502 foreach ($data as $section) {
503 foreach ($section['elements'] as $column) {
504 foreach ($column['elements'] as $el) {
505 if ($el['id'] == $id && $el['elType'] == 'widget' && $el['widgetType'] == $widgetType) {
506 $element = $el;
507 break 3;
508 }
509 }
510 }
511 }
512
513 // Output the element code
514 if ($element) {
515 return $element;;
516 }
517 }
518
519 public static function ep_get_popup_icon()
520 {
521 $svg = '<div class="ep-doc-popup-icon" ><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" xml:space="preserve"><path fill="#fff" d="M5 3c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2v-6l-2-2v8H5V5h8l-2-2H5zm9 0 2.7 2.7-7.5 7.5 1.7 1.7 7.5-7.5L21 10V3h-7z"/><path style="fill:none" d="M0 0h24v24H0z"/></svg></div>';
522
523 return $svg;
524 }
525 public static function ep_get_download_icon()
526 {
527 $svg = '<div class="ep-doc-download-icon" ><svg width="25" height="25" viewBox="0 0 0.6 0.6" xmlns="http://www.w3.org/2000/svg"><path fill="#fff" fill-rule="evenodd" d="M.525.4A.025.025 0 0 1 .55.422v.053A.075.075 0 0 1 .479.55H.125A.075.075 0 0 1 .05.479V.425A.025.025 0 0 1 .1.422v.053A.025.025 0 0 0 .122.5h.353A.025.025 0 0 0 .5.478V.425A.025.025 0 0 1 .525.4ZM.3.05a.025.025 0 0 1 .025.025v.24L.357.283A.025.025 0 0 1 .39.281l.002.002a.025.025 0 0 1 .002.033L.392.318.317.393.316.394.314.395.311.397.308.398.305.399.301.4H.295L.292.399.289.398.287.397.285.395A.025.025 0 0 1 .283.393L.208.318A.025.025 0 0 1 .241.281l.002.002.032.032v-.24A.025.025 0 0 1 .3.05Z"/></svg></div>';
528
529 return $svg;
530 }
531
532 public static function ep_get_print_icon()
533 {
534 $svg = '<div class="ep-doc-print-icon" ><svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 24 24">
535 <path d="M19 8H5c-1.66 0-3 1.34-3 3v6h4v4h12v-4h4v-6c0-1.66-1.34-3-3-3zm-3 11H8v-5h8v5zm3-7c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1zm-1-9H6v4h12V3z" fill="#fff"/>
536 </svg></div>';
537
538 return $svg;
539 }
540
541 public static function ep_get_fullscreen_icon()
542 {
543 $svg = '<div class="ep-doc-fullscreen-icon"><svg width="25" height="25" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
544 <path d="m3 15 .117.007a1 1 0 0 1 .876.876L4 16v4h4l.117.007a1 1 0 0 1 0 1.986L8 22H3l-.117-.007a1 1 0 0 1-.876-.876L2 21v-5l.007-.117a1 1 0 0 1 .876-.876L3 15Zm18 0a1 1 0 0 1 .993.883L22 16v5a1 1 0 0 1-.883.993L21 22h-5a1 1 0 0 1-.117-1.993L16 20h4v-4a1 1 0 0 1 .883-.993L21 15ZM8 2a1 1 0 0 1 .117 1.993L8 4H4v4a1 1 0 0 1-.883.993L3 9a1 1 0 0 1-.993-.883L2 8V3a1 1 0 0 1 .883-.993L3 2h5Zm13 0 .117.007a1 1 0 0 1 .876.876L22 3v5l-.007.117a1 1 0 0 1-.876.876L21 9l-.117-.007a1 1 0 0 1-.876-.876L20 8V4h-4l-.117-.007a1 1 0 0 1 0-1.986L16 2h5Z" fill="#fff"/>
545 </svg></div>';
546
547 return $svg;
548 }
549 public static function ep_get_minimize_icon()
550 {
551 $svg = '<div class="ep-doc-minimize-icon" style="display:none"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" style="enable-background:new 0 0 385.331 385.331" xml:space="preserve" width="20" height="20"><path fill="#fff" d="M13.751 8.131h5.62c0.355 0 0.619 -0.28 0.619 -0.634 0 -0.355 -0.265 -0.615 -0.619 -0.614h-4.995V1.878c0 -0.355 -0.27 -0.624 -0.624 -0.624s-0.624 0.27 -0.624 0.624v5.62c0 0.002 0.001 0.003 0.001 0.004 0 0.002 -0.001 0.003 -0.001 0.005 0 0.348 0.276 0.625 0.624 0.624zM6.244 1.259c-0.354 0 -0.614 0.265 -0.614 0.619v4.995H0.624c-0.355 0 -0.624 0.27 -0.624 0.624 0 0.355 0.27 0.624 0.624 0.624h5.62c0.002 0 0.003 -0.001 0.004 -0.001 0.002 0 0.003 0.001 0.005 0.001 0.348 0 0.624 -0.276 0.624 -0.624V1.878c0 -0.354 -0.28 -0.619 -0.634 -0.619zm0.005 10.61H0.629c-0.355 0.001 -0.619 0.28 -0.619 0.634 0 0.355 0.265 0.615 0.619 0.614h4.995v5.005c0 0.355 0.27 0.624 0.624 0.624 0.355 0 0.624 -0.27 0.624 -0.624V12.502c0 -0.002 -0.001 -0.003 -0.001 -0.004 0 -0.002 0.001 -0.003 0.001 -0.005 0 -0.348 -0.276 -0.624 -0.624 -0.624zm13.127 0H13.756c-0.002 0 -0.003 0.001 -0.004 0.001 -0.002 0 -0.003 -0.001 -0.005 -0.001 -0.348 0 -0.624 0.276 -0.624 0.624v5.62c0 0.355 0.28 0.619 0.634 0.619 0.354 0.001 0.614 -0.265 0.614 -0.619v-4.995H19.376c0.355 0 0.624 -0.27 0.624 -0.624s-0.27 -0.624 -0.624 -0.625z"/><g/><g/><g/><g/><g/><g/></svg></div>';
552
553 return $svg;
554 }
555 public static function ep_get_draw_icon()
556 {
557 $svg = '<div class="ep-doc-draw-icon"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="m15 7.5 2.5 2.5m-10 10L19.25 8.25c0.69 -0.69 0.69 -1.81 0 -2.5v0c-0.69 -0.69 -1.81 -0.69 -2.5 0L5 17.5V20h2.5Zm0 0h8.379C17.05 20 18 19.05 18 17.879v0c0 -0.563 -0.224 -1.103 -0.621 -1.5L17 16M4.5 5c2 -2 5.5 -1 5.5 1 0 2.5 -6 2.5 -6 5 0 0.876 0.533 1.526 1.226 2" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></div>';
558
559 return $svg;
560 }
561
562 public static function get_google_presentation_url($embedded_url)
563 {
564 $parsed_url = parse_url($embedded_url);
565 $base_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $parsed_url['path'];
566 $base_url = strtok($base_url, '?');
567 $base_url = rtrim($base_url, '/');
568 return $base_url;
569 }
570
571 public static function check_media_format($url)
572 {
573 $pattern1 = '/\.(mp4|mov|avi|wmv|flv|mkv|webm|mpeg|mpg)$/i';
574 $pattern2 = '/\.(mp3|wav|ogg|aac)$/i';
575
576 $isVideo = preg_match($pattern1, $url);
577 $isAudio = preg_match($pattern2, $url);
578
579 $is_self_hosted = false;
580 $format = '';
581
582 if (!empty($isVideo) || !empty($isAudio)) {
583 $is_self_hosted = true;
584 if (!empty($isVideo)) {
585 $format = 'video';
586 } else if (!empty($isAudio)) {
587 $format = 'audio';
588 }
589 }
590
591 if (!$is_self_hosted) {
592 return [
593 'selhosted' => false,
594 ];
595 }
596
597 return [
598 'selhosted' => true,
599 'format' => $format,
600 ];
601 }
602
603 public static function getCalendlyUuid($url)
604 {
605 $pattern = '/\/([0-9a-fA-F-]+)$/';
606 if (preg_match($pattern, $url, $matches)) {
607 $uuid = $matches[1];
608 return $uuid;
609 }
610 return '';
611 }
612
613 public static function getCalendlyUserInfo($access_token) {
614 $transient_name = 'calendly_user_info_' . $access_token;
615 $user_info = get_transient($transient_name);
616 if (false === $user_info) {
617 $user_endpoint = 'https://api.calendly.com/users/me';
618 $headers = array(
619 'Authorization' => "Bearer $access_token",
620 'Content-Type' => 'application/json',
621 );
622 $args = array(
623 'headers' => $headers,
624 );
625 $response = wp_remote_get($user_endpoint, $args);
626 if (!is_wp_error($response) && 200 === wp_remote_retrieve_response_code($response)) {
627 $user_info = wp_remote_retrieve_body($response);
628 set_transient($transient_name, $user_info, 3600);
629 } else {
630 return false;
631 }
632 }
633
634 return $user_info;
635 }
636
637
638
639 public static function getCalaendlyEventTypes($user_uri, $access_token)
640 {
641 // Attempt to retrieve the data from the transient
642 $events_list = get_transient('calendly_events_list_' . md5($access_token));
643
644 if (false === $events_list) {
645 // If the data is not in the transient, fetch it from the API
646 $events_endpoint = "https://api.calendly.com/event_types?user=$user_uri";
647
648 $headers = array(
649 'Authorization' => "Bearer $access_token",
650 'Content-Type' => 'application/json',
651 );
652
653 $args = array(
654 'headers' => $headers,
655 );
656
657 $response = wp_remote_get($events_endpoint, $args);
658
659 if (!is_wp_error($response)) {
660 $body = wp_remote_retrieve_body($response);
661 $events_list = json_decode($body, true);
662
663 // Store the data in a transient for a specified time (e.g., 1 hour)
664 set_transient('calendly_events_list', $events_list, HOUR_IN_SECONDS);
665
666 return $events_list;
667 }
668 }
669
670 return $events_list;
671 }
672
673 public static function getListEventInvitee($uuid, $access_token)
674 {
675 // Attempt to retrieve the data from the transient
676 $invitee_list = get_transient('calendly_invitee_list_' . md5($access_token));
677
678 if (false === $invitee_list) {
679 // If the data is not in the transient, fetch it from the API
680 $events_endpoint = "https://api.calendly.com/scheduled_events/$uuid/invitees";
681
682 $headers = array(
683 'Authorization' => "Bearer $access_token",
684 'Content-Type' => 'application/json',
685 );
686
687 $args = array(
688 'headers' => $headers,
689 );
690
691 $response = wp_remote_get($events_endpoint, $args);
692
693 if (!is_wp_error($response)) {
694 $body = wp_remote_retrieve_body($response);
695 $invitee_list = json_decode($body, true);
696
697 // Store the data in a transient for a specified time (e.g., 1 hour)
698 set_transient('calendly_invitee_list', $invitee_list, HOUR_IN_SECONDS);
699
700 return $invitee_list;
701 }
702 }
703
704 return $invitee_list;
705 }
706
707 public static function getCalaendlyScheduledEvents($user_uri, $access_token)
708 {
709 // Attempt to retrieve the data from the transient
710 $events_list = get_transient('calendly_events_list_' . md5($access_token));
711
712 if (false === $events_list) {
713 // If the data is not in the transient, fetch it from the API
714 $events_endpoint = "https://api.calendly.com/scheduled_events?user=$user_uri";
715
716 $headers = array(
717 'Authorization' => "Bearer $access_token",
718 'Content-Type' => 'application/json',
719 );
720
721 $args = array(
722 'headers' => $headers,
723 );
724
725 $response = wp_remote_get($events_endpoint, $args);
726
727 if (!is_wp_error($response)) {
728 $body = wp_remote_retrieve_body($response);
729 $events_list = json_decode($body, true);
730
731 // Store the data in a transient for a specified time (e.g., 1 hour)
732 set_transient('calendly_events_list', $events_list, HOUR_IN_SECONDS);
733
734 return $events_list;
735 }
736 }
737
738 return $events_list;
739 }
740
741
742 public static function parseDuration($durationString)
743 {
744 list($minutes, $seconds) = explode(':', $durationString);
745 return intval($minutes) * 60 + intval($seconds);
746 }
747
748 public static function generateAdTemplate($client_id, $attributes, $editor = 'elementor')
749 {
750
751 // Example usage
752
753
754 $adSource = isset($attributes['adSource']) ? $attributes['adSource'] : '';
755 $adContent = isset($attributes['adContent']) ? $attributes['adContent'] : '';
756 $unit = isset($attributes['unitoption']) ? $attributes['unitoption'] : 'px';
757
758 if ($editor === 'elementor') {
759 if ($attributes['adSource'] === 'video') {
760 $adFileUrl = isset($attributes['adFileUrl']['url']) ? $attributes['adFileUrl']['url'] : '';
761 } else if ($attributes['adSource'] === 'image') {
762 $adFileUrl = isset($attributes['adFileUrl1']['url']) ? $attributes['adFileUrl1']['url'] : '';
763 } else {
764 $adFileUrl = isset($attributes['adFileUrl2']['url']) ? $attributes['adFileUrl2']['url'] : '';
765 }
766
767 $width = isset($attributes['width']) ? $attributes['width']['size'] : '600';
768 $height = isset($attributes['height']) ? $attributes['height']['size'] : '550';
769 } else {
770 $adFileUrl = isset($attributes['adFileUrl']) ? $attributes['adFileUrl'] : '';
771 $width = isset($attributes['width']) ? $attributes['width'] : '600';
772 $height = isset($attributes['height']) ? $attributes['height'] : '550';
773 }
774 $adStart = isset($attributes['adStart']) ? intval($attributes['adStart']) : 0;
775 $adUrl = isset($attributes['adUrl']) ? $attributes['adUrl'] : '';
776 $adXPosition = isset($attributes['adXPosition']) ? $attributes['adXPosition'] : '';
777 $adYPosition = isset($attributes['adYPosition']) ? $attributes['adYPosition'] : '';
778 $adWidth = isset($attributes['adWidth']) ? $attributes['adWidth'] : '';
779 $adHeight = isset($attributes['adHeight']) ? $attributes['adHeight'] : '';
780 $adSkipButton = isset($attributes['adSkipButton']) ? $attributes['adSkipButton'] : false;
781 $adSkipButtonAfter = isset($attributes['adSkipButtonAfter']) ? intval($attributes['adSkipButtonAfter']) : 5;
782
783 $currentTime = 0;
784 $showSkipButton = false;
785 $videoDuration = 0;
786
787 if ($adContent && isset($adContent['fileLength'])) {
788 $videoDuration = self::parseDuration($adContent['fileLength']);
789 }
790
791 $showSkipButton = true;
792
793 $isYTChannelClass = '';
794 if (!empty($attributes['url']) && self::is_youtube_channel($attributes['url'])) {
795 $isYTChannelClass = ' ep-youtube-channel';
796 }
797
798 ?>
799 <div class="main-ad-template <?php echo esc_attr($adSource);
800 echo esc_attr($isYTChannelClass); ?>" id="<?php echo esc_attr('ad-' . $client_id); ?>" style="display:none">
801 <div class="ep-ad-container">
802 <div class="ep-ad-content" style="position: relative;">
803 <?php if (!empty($adUrl)) : ?> <a target="_blank" href="<?php echo esc_url($adUrl); ?>"> <?php endif; ?>
804 <?php if ($adSource === 'video') : ?>
805 <video class="ep-ad" muted>
806 <source src="<?= esc_url($adFileUrl) ?>">
807 </video>
808
809 <div class="ad-timer">
810 <span class="ad-running-time"></span>
811 <span class="ad-duration">&nbsp;<?php echo esc_html__('• Ad', 'embedpress'); ?></span>
812 </div>
813 <div class="progress-bar-container">
814 <div class="progress-bar"></div>
815 </div>
816
817 <?php else : ?>
818 <img class="ep-ad" src="<?= esc_url($adFileUrl) ?>">
819 <?php endif; ?>
820
821 <?php if (!empty($adUrl)) : ?>
822 </a>
823 <?php endif; ?>
824
825
826 <?php if (!empty($adSkipButton) && !empty($showSkipButton)) : ?>
827 <button title="Skip Ad" class="skip-ad-button" style="display: none;">
828 <?php echo esc_html__('Skip Ad', 'embedpress'); ?>
829 </button>
830 <?php endif; ?>
831
832 </div>
833 </div>
834 </div>
835
836
837 <style>
838 .ad-mask .ose-embedpress-responsive {
839 position: relative;
840 }
841
842 .ad-running {
843 display: inline-block !important;
844 }
845
846 .ad-mask .ep-embed-content-wraper::after {
847 content: '';
848 position: absolute;
849 top: 0;
850 left: 0;
851 right: 0;
852 bottom: 0;
853 }
854
855 .ep-embed-content-wraper {
856 position: relative;
857 }
858
859 .ose-youtube {
860 /* display: none !important; */
861 }
862
863 [data-ad-id="<?php echo esc_attr($client_id) ?>"] .main-ad-template {
864 width: <?php echo esc_attr($width); ?><?php echo esc_attr($unit); ?>;
865 height: <?php echo esc_attr($height); ?>px;
866 max-width: 100%;
867 display: inline-block;
868 }
869
870 [data-ad-id] {
871 position: relative;
872 display: inline-block;
873
874 }
875
876 .ep-percentage-width [data-ad-id] {
877 display: block;
878 }
879
880 .main-ad-template.image.ad-running {
881 position: absolute;
882 z-index: 1;
883 bottom: 75px;
884 left: 50%;
885 height: auto;
886 }
887
888 [data-ad-id="<?php echo esc_attr($client_id) ?>"] .main-ad-template.image.ad-running {
889 width: <?php echo esc_attr($adWidth); ?>px !important;
890 height: <?php echo esc_attr($adHeight); ?>px !important;
891 bottom: <?php echo esc_attr($adYPosition); ?>%;
892 left: <?php echo esc_attr($adXPosition); ?>%;
893 }
894
895 [data-ad-id="<?php echo esc_attr($client_id) ?>"] .main-ad-template .ep-ad-content,
896 [data-ad-id="<?php echo esc_attr($client_id) ?>"] .main-ad-template .ep-ad-container,
897 .main-ad-template div img {
898 height: 100%;
899 object-fit: cover;
900
901 }
902
903
904 .main-ad-template.image.ad-running img {
905 border-radius: 5px;
906 }
907
908 .ep-ad-container {
909 position: relative;
910 }
911
912 .main-ad-template video,
913 .main-ad-template img {
914 width: 100%;
915 height: 100%;
916 background-color: #000;
917 }
918
919 .progress-bar-container {
920 margin-top: -10px;
921 background: #ff000021;
922 }
923
924 .progress-bar {
925 background: #5be82a;
926 height: 5px;
927 margin-top: -4px;
928 max-width: 100%;
929 }
930
931 button.skip-ad-button {
932 position: absolute;
933 bottom: 15px;
934 right: 10px;
935 border: none;
936 background: #d41556b5 !important;
937 color: white !important;
938 z-index: 122222222;
939 font-size: 14px;
940 border-radius: 4px;
941 height: 30px;
942 width: 80px;
943 font-weight: normal;
944 display: flex;
945 align-items: center;
946 justify-content: center;
947 cursor: pointer;
948
949 }
950
951 .ad-timer {
952 position: absolute;
953 background: #d41556b5;
954 font-size: 14px;
955 width: 110px;
956 color: white;
957 bottom: 15px;
958 left: 10px;
959 text-align: center;
960 border-radius: 4px;
961 height: 30px;
962 width: 80px;
963 font-weight: normal;
964 display: flex;
965 align-items: center;
966 justify-content: center;
967
968 }
969
970 [data-ad-id="<?php echo esc_attr($client_id) ?>"] .hidden {
971 display: none !important;
972 }
973 </style>
974
975
976
977 <?php
978 }
979 }
980
981 ?>