Elementor_Enhancer.php
3 years ago
EmbedPress_Core_Installer.php
6 years ago
EmbedPress_Notice.php
4 years ago
EmbedPress_Plugin_Usage_Tracker.php
2 years ago
Extend_CustomPlayer_Controls.php
3 years ago
Extend_Elementor_Controls.php
3 years ago
Feature_Enhancer.php
2 years ago
Helper.php
2 years ago
Helper.php
740 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress\Includes\Classes; |
| 4 | use EmbedPress\Shortcode; |
| 5 | |
| 6 | if ( !defined('ABSPATH') ) { |
| 7 | exit; |
| 8 | } // Exit if accessed directly |
| 9 | |
| 10 | class Helper { |
| 11 | |
| 12 | /** |
| 13 | * Parse a query string into an associative array. |
| 14 | * |
| 15 | * If multiple values are found for the same key, the value of that key |
| 16 | * value pair will become an array. This function does not parse nested |
| 17 | * PHP style arrays into an associative array (e.g., foo[a]=1&foo[b]=2 will |
| 18 | * be parsed into ['foo[a]' => '1', 'foo[b]' => '2']). |
| 19 | * |
| 20 | * @param string $str Query string to parse |
| 21 | * @param int|bool $urlEncoding How the query string is encoded |
| 22 | * |
| 23 | * @return array |
| 24 | */ |
| 25 | |
| 26 | public function __construct () { |
| 27 | add_action('wp_ajax_lock_content_form_handler', [$this, 'lock_content_form_handler']); |
| 28 | add_action('wp_ajax_nopriv_lock_content_form_handler', [$this, 'lock_content_form_handler']); |
| 29 | add_action( 'wp_head', [$this, 'ep_add_meta_tags'] ); |
| 30 | } |
| 31 | |
| 32 | public function ep_add_meta_tags() { |
| 33 | echo 'abstract'; |
| 34 | } |
| 35 | |
| 36 | public static function parse_query($str, $urlEncoding = true) |
| 37 | { |
| 38 | $result = []; |
| 39 | |
| 40 | if ($str === '') { |
| 41 | return $result; |
| 42 | } |
| 43 | |
| 44 | if ($urlEncoding === true) { |
| 45 | $decoder = function ($value) { |
| 46 | return rawurldecode(str_replace('+', ' ', $value)); |
| 47 | }; |
| 48 | } elseif ($urlEncoding === PHP_QUERY_RFC3986) { |
| 49 | $decoder = 'rawurldecode'; |
| 50 | } elseif ($urlEncoding === PHP_QUERY_RFC1738) { |
| 51 | $decoder = 'urldecode'; |
| 52 | } else { |
| 53 | $decoder = function ($str) { return $str; }; |
| 54 | } |
| 55 | |
| 56 | foreach (explode('&', $str) as $kvp) { |
| 57 | $parts = explode('=', $kvp, 2); |
| 58 | $key = $decoder($parts[0]); |
| 59 | $value = isset($parts[1]) ? $decoder($parts[1]) : null; |
| 60 | if (!isset($result[$key])) { |
| 61 | $result[$key] = $value; |
| 62 | } else { |
| 63 | if (!is_array($result[$key])) { |
| 64 | $result[$key] = [$result[$key]]; |
| 65 | } |
| 66 | $result[$key][] = $value; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return $result; |
| 71 | } |
| 72 | public static function get_pdf_renderer() { |
| 73 | // $renderer = EMBEDPRESS_URL_ASSETS . 'pdf/web/viewer.html'; |
| 74 | |
| 75 | $renderer = admin_url('admin-ajax.php?action=get_viewer'); |
| 76 | |
| 77 | // @TODO; apply settings query args here |
| 78 | return $renderer; |
| 79 | } |
| 80 | |
| 81 | public static function get_extension_from_file_url($url) { |
| 82 | $urlSplit = explode(".", $url); |
| 83 | $ext = end($urlSplit); |
| 84 | return $ext; |
| 85 | } |
| 86 | |
| 87 | public static function is_file_url($url) { |
| 88 | $pattern = '/\.([0-9a-z]+)(?=[?#])|(\.)(?:[\w]+)$/i'; |
| 89 | return preg_match($pattern, $url) === 1; |
| 90 | } |
| 91 | |
| 92 | public static function is_opensea($url) { |
| 93 | return strpos($url, "opensea.io") !== false; |
| 94 | } |
| 95 | public static function is_youtube_channel($url) { |
| 96 | return (bool) (preg_match('~(?:https?:\/\/)?(?:www\.)?(?:youtube.com\/)(?:channel\/|c\/|user\/|@)(\w+)~i', (string) $url)); |
| 97 | } |
| 98 | |
| 99 | public static function is_youtube($url) { |
| 100 | return (bool) (preg_match('~(?:https?://)?(?:www\.)?(?:youtube\.com|youtu\.be)/watch\?v=([^&]+)~i', (string) $url)); |
| 101 | } |
| 102 | |
| 103 | // Saved sources data temporary in wp_options table |
| 104 | public static function get_source_data($blockid, $source_url, $source_option_name, $source_temp_option_name) { |
| 105 | |
| 106 | |
| 107 | if(self::is_youtube_channel($source_url)){ |
| 108 | $source_name = 'YoutubeChannel'; |
| 109 | } |
| 110 | else if(self::is_youtube($source_url)){ |
| 111 | $source_name = 'Youtube'; |
| 112 | } |
| 113 | else if (!empty(self::is_file_url($source_url))) { |
| 114 | $source_name = 'document_' . self::get_extension_from_file_url($source_url); |
| 115 | } |
| 116 | else if(self::is_opensea($source_url)){ |
| 117 | $source_name = 'OpenSea'; |
| 118 | } |
| 119 | else{ |
| 120 | Shortcode::get_embera_instance(); |
| 121 | $collectios = Shortcode::get_collection(); |
| 122 | $provider = $collectios->findProviders($source_url); |
| 123 | if(!empty($provider[$source_url])){ |
| 124 | $source_name = $provider[$source_url]->getProviderName(); |
| 125 | } |
| 126 | else{ |
| 127 | $source_name = 'Unknown Source'; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if(!empty($blockid) && $blockid != 'undefined'){ |
| 132 | $sources = json_decode(get_option($source_temp_option_name), true); |
| 133 | |
| 134 | if(!$sources) { |
| 135 | $sources = array(); |
| 136 | } |
| 137 | $exists = false; |
| 138 | |
| 139 | foreach($sources as $i => $source) { |
| 140 | if ($source['id'] === $blockid) { |
| 141 | $sources[$i]['source']['name'] = $source_name; |
| 142 | $sources[$i]['source']['url'] = $source_url; |
| 143 | $exists = true; |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | if(!$exists) { |
| 149 | $sources[] = array('id' => $blockid, 'source' => array('name' => $source_name, 'url' => $source_url, 'count' => 1)); |
| 150 | } |
| 151 | |
| 152 | update_option($source_temp_option_name, json_encode($sources)); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // Saved source data when post updated |
| 157 | public static function get_save_source_data_on_post_update( $source_option_name, $source_temp_option_name ) { |
| 158 | |
| 159 | if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
| 160 | return; |
| 161 | } |
| 162 | $temp_data = json_decode(get_option($source_temp_option_name), true); |
| 163 | $source_data = json_decode(get_option($source_option_name), true); |
| 164 | if(!$temp_data) { |
| 165 | $temp_data = array(); |
| 166 | } |
| 167 | if(!$source_data) { |
| 168 | $source_data = array(); |
| 169 | } |
| 170 | |
| 171 | $sources = array_merge($temp_data, $source_data); |
| 172 | |
| 173 | $unique_sources = array(); |
| 174 | foreach ($sources as $source) { |
| 175 | $unique_sources[$source['id']] = $source; |
| 176 | } |
| 177 | |
| 178 | $unique_sources = array_values($unique_sources); |
| 179 | |
| 180 | delete_option($source_temp_option_name); |
| 181 | |
| 182 | update_option($source_option_name, json_encode($unique_sources)); |
| 183 | } |
| 184 | |
| 185 | //Delete source data from option table when widget is removed |
| 186 | public static function get_delete_source_data($blockid, $source_option_name, $source_temp_option_name) { |
| 187 | if (!empty($blockid) && $blockid != 'undefined') { |
| 188 | $sources = json_decode(get_option($source_option_name), true); |
| 189 | $temp_sources = json_decode(get_option($source_temp_option_name), true); |
| 190 | if ($sources) { |
| 191 | foreach ($sources as $i => $source) { |
| 192 | if ($source['id'] === $blockid) { |
| 193 | unset($sources[$i]); |
| 194 | break; |
| 195 | } |
| 196 | } |
| 197 | update_option($source_option_name, json_encode(array_values($sources))); |
| 198 | } |
| 199 | if ($temp_sources) { |
| 200 | foreach ($temp_sources as $i => $source) { |
| 201 | if ($source['id'] === $blockid) { |
| 202 | unset($temp_sources[$i]); |
| 203 | break; |
| 204 | } |
| 205 | } |
| 206 | update_option($source_temp_option_name, json_encode(array_values($temp_sources))); |
| 207 | } |
| 208 | } |
| 209 | wp_die(); |
| 210 | } |
| 211 | |
| 212 | //Delete source temporary data when reload without update or publish |
| 213 | public static function get_delete_source_temp_data_on_reload($source_temp_option_name) { |
| 214 | $source_temp_data = json_decode(get_option($source_temp_option_name), true); |
| 215 | if ($source_temp_data ) { |
| 216 | delete_option( $source_temp_option_name ); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | public static function get_file_title($url){ |
| 221 | return get_the_title(attachment_url_to_postid( $url )); |
| 222 | } |
| 223 | |
| 224 | public static function get_hash(){ |
| 225 | $hash_key = get_option(EMBEDPRESS_PLG_NAME . '_hash_key'); |
| 226 | if(!$hash_key){ |
| 227 | $hash_key = wp_hash_password(wp_generate_password(30)); |
| 228 | update_option(EMBEDPRESS_PLG_NAME . '_hash_key', $hash_key); |
| 229 | } |
| 230 | return $hash_key; |
| 231 | } |
| 232 | |
| 233 | public function lock_content_form_handler() |
| 234 | { |
| 235 | |
| 236 | $client_id = isset($_POST['client_id']) ? $_POST['client_id'] : ''; |
| 237 | $password = isset($_POST['password']) ? $_POST['password'] : ''; |
| 238 | $post_id = isset($_POST['post_id']) ? $_POST['post_id'] : 'sdfds'; |
| 239 | |
| 240 | // $epbase64 = isset($_POST['epbase']) ? $_POST['epbase'] : ''; |
| 241 | // $hash_key = isset($_POST['hash_key']) ? $_POST['hash_key'] : ''; |
| 242 | |
| 243 | $epbase64 = get_post_meta($post_id, 'ep_base_' .$client_id, false ); |
| 244 | $hash_key = get_post_meta( $post_id, 'hash_key_' .$client_id, false ); |
| 245 | |
| 246 | // Set the decryption key and initialization vector (IV) |
| 247 | $key = self::get_hash(); |
| 248 | |
| 249 | // Decode the base64 encoded cipher |
| 250 | $cipher = base64_decode($epbase64); |
| 251 | // Decrypt the cipher using AES-128-CBC encryption |
| 252 | |
| 253 | $wp_pass_key = hash('sha256', wp_salt(32) . md5($password)); |
| 254 | $iv = substr($wp_pass_key, 0, 16); |
| 255 | if ($wp_pass_key === $hash_key) { |
| 256 | setcookie("password_correct_", $password, time() + 3600); |
| 257 | |
| 258 | $embed = openssl_decrypt($cipher, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv) . '<script> |
| 259 | var now = new Date(); |
| 260 | var time = now.getTime(); |
| 261 | var expireTime = time + 1000 * 60 * 60 * 24 * 30; |
| 262 | now.setTime(expireTime); |
| 263 | document.cookie = "password_correct_' . $client_id . '=' . $hash_key . '; expires=" + now.toUTCString() + "; path=/"; |
| 264 | </script>'; |
| 265 | } else { |
| 266 | $embed = 0; |
| 267 | } |
| 268 | |
| 269 | // Process the form data and return a response |
| 270 | $response = array( |
| 271 | 'success' => true, |
| 272 | 'password' => $password, |
| 273 | 'embedHtml' => $embed, |
| 274 | ); |
| 275 | |
| 276 | echo json_encode($response); |
| 277 | |
| 278 | wp_die(); |
| 279 | } |
| 280 | |
| 281 | public static function display_password_form($client_id='', $embedHtml='', $pass_hash_key='', $attributes = []) |
| 282 | { |
| 283 | $lock_heading = !empty($attributes['lockHeading']) ? $attributes['lockHeading'] : ''; |
| 284 | $lock_subheading = !empty($attributes['lockSubHeading']) ? $attributes['lockSubHeading'] : ''; |
| 285 | $lock_error_message = !empty($attributes['lockErrorMessage']) ? $attributes['lockErrorMessage'] : ''; |
| 286 | $footer_message = !empty($attributes['footerMessage']) ? $attributes['footerMessage'] : ''; |
| 287 | $password_placeholder = !empty($attributes['passwordPlaceholder']) ? $attributes['passwordPlaceholder'] : ''; |
| 288 | $button_text = !empty($attributes['submitButtonText']) ? $attributes['submitButtonText'] : ''; |
| 289 | $unlocking_text = !empty($attributes['submitUnlockingText']) ? $attributes['submitUnlockingText'] : ''; |
| 290 | $enable_footer_message = !empty($attributes['enableFooterMessage']) ? $attributes['enableFooterMessage'] : ''; |
| 291 | |
| 292 | // Set the encryption key and initialization vector (IV) |
| 293 | $key = self::get_hash(); |
| 294 | |
| 295 | $salt = wp_salt(32); |
| 296 | $wp_hash_key = hash('sha256', $salt . $pass_hash_key); |
| 297 | $iv = substr($wp_hash_key, 0, 16); |
| 298 | |
| 299 | |
| 300 | // Encrypt the plaintext using AES-128-CBC encryption |
| 301 | $cipher = openssl_encrypt($embedHtml, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv); |
| 302 | |
| 303 | // Base64 encode the encrypted cipher |
| 304 | $encrypted_data = base64_encode($cipher); |
| 305 | |
| 306 | update_post_meta( get_the_ID( ), 'ep_base_' .$client_id, $encrypted_data ); |
| 307 | update_post_meta( get_the_ID( ), 'hash_key_' .$client_id, $wp_hash_key ); |
| 308 | |
| 309 | $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>'; |
| 310 | |
| 311 | echo ' |
| 312 | <div class="password-form-container"> |
| 313 | <h2>'.esc_html( $lock_heading ).'</h2> |
| 314 | <p>'.esc_html( $lock_subheading ).' </p> |
| 315 | <form class="password-form" method="post" class="password-form" data-unlocking-text="'.esc_attr( $unlocking_text ).'"> |
| 316 | |
| 317 | <div class="password-field"> |
| 318 | <span class="lock-icon">' . $lock_icon . '</span> |
| 319 | <input type="password" name="pass_' . esc_attr($client_id) . '" placeholder="' . esc_attr($password_placeholder) . '" required> |
| 320 | </div> |
| 321 | <input type="hidden" name="ep_client_id" value="' . esc_attr($client_id) . '"> |
| 322 | <input type="hidden" name="post_id" value="' . esc_attr(get_the_ID( ) ) . '"> |
| 323 | |
| 324 | <input type="submit" name="password_submit" value="'.esc_attr( $button_text ).'"> |
| 325 | <div class="error-message hidden">'.esc_html( $lock_error_message ).'</div> |
| 326 | </form> |
| 327 | ' . ( ! empty( $enable_footer_message ) ? '<p class="need-access-message">' . esc_html( $footer_message ) . '</p>' : '' ) . ' |
| 328 | </div> |
| 329 | '; |
| 330 | } |
| 331 | |
| 332 | // Check if the user has already entered the correct password |
| 333 | public static function is_password_correct($client_id) |
| 334 | { |
| 335 | if (isset($_COOKIE['password_correct_' . $client_id])) { |
| 336 | return $_COOKIE['password_correct_' . $client_id]; |
| 337 | } else { |
| 338 | return false; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | public static function customLogo($embedHTML, $atts){ |
| 343 | $x = !empty($atts['logoX']) ? $atts['logoX'] : 0; |
| 344 | $y = !empty($atts['logoY']) ? $atts['logoY'] : 0; |
| 345 | $uniqid = !empty($atts['url'])? '.ose-uid-' . md5($atts['url']): ''; |
| 346 | |
| 347 | $brandUrl = !empty($atts['customlogoUrl']) ? $atts['customlogoUrl'] : ''; |
| 348 | $opacity = !empty($atts['logoOpacity']) ? $atts['logoOpacity'] : ''; |
| 349 | |
| 350 | $cssClass = !empty( $atts['url'] ) ? '.ose-uid-' . md5( $atts['url'] ) : '.ose-youtube'; |
| 351 | |
| 352 | |
| 353 | |
| 354 | ob_start(); ?> |
| 355 | <style type="text/css"> |
| 356 | <?php echo esc_html($cssClass); ?> |
| 357 | { |
| 358 | position: relative; |
| 359 | } |
| 360 | |
| 361 | <?php echo esc_html($cssClass); ?> .watermark { |
| 362 | border: 0; |
| 363 | position: absolute; |
| 364 | bottom: <?php echo esc_html($y); ?>%; |
| 365 | right: <?php echo esc_html($x); ?>%; |
| 366 | max-width: 150px; |
| 367 | max-height: 75px; |
| 368 | opacity: 0.25; |
| 369 | z-index: 5; |
| 370 | -o-transition: opacity 0.5s ease-in-out; |
| 371 | -moz-transition: opacity 0.5s ease-in-out; |
| 372 | -webkit-transition: opacity 0.5s ease-in-out; |
| 373 | transition: opacity 0.5s ease-in-out; |
| 374 | opacity: <?php echo esc_html($opacity); ?>; |
| 375 | } |
| 376 | |
| 377 | <?php echo esc_html($cssClass); ?> |
| 378 | .watermark:hover { |
| 379 | opacity: 1; |
| 380 | } |
| 381 | </style> |
| 382 | <?php |
| 383 | |
| 384 | |
| 385 | $style = ob_get_clean(); |
| 386 | |
| 387 | if ( ! class_exists( '\simple_html_dom' ) ) { |
| 388 | include_once EMBEDPRESS_PATH_CORE . 'simple_html_dom.php'; |
| 389 | } |
| 390 | |
| 391 | $cta = ''; |
| 392 | $img = ''; |
| 393 | |
| 394 | if(!empty($atts['customlogo'])){ |
| 395 | $img = '<img src="'.esc_url($atts['customlogo']).'"/>'; |
| 396 | |
| 397 | $imgDom = str_get_html( $img ); |
| 398 | $imgDom = $imgDom->find( 'img', 0 ); |
| 399 | $imgDom->setAttribute( 'class', 'watermark ep-custom-logo' ); |
| 400 | $imgDom->removeAttribute( 'style' ); |
| 401 | $imgDom->setAttribute( 'width', 'auto' ); |
| 402 | $imgDom->setAttribute( 'height', 'auto' ); |
| 403 | ob_start(); |
| 404 | echo $imgDom; |
| 405 | |
| 406 | $cta .= ob_get_clean(); |
| 407 | |
| 408 | $imgDom->clear(); |
| 409 | unset( $img, $imgDom ); |
| 410 | |
| 411 | if ( !empty($brandUrl) ) { |
| 412 | $cta = '<a href="'.esc_url($brandUrl).'" target="_blank">'.$cta.'</a>'; |
| 413 | } |
| 414 | $dom = str_get_html( $embedHTML ); |
| 415 | |
| 416 | $wrapDiv = $dom->find( $uniqid, 0 ); |
| 417 | |
| 418 | if ( ! empty( $wrapDiv ) && is_object( $wrapDiv ) ) { |
| 419 | $wrapDiv->innertext .= $cta; |
| 420 | } |
| 421 | |
| 422 | ob_start(); |
| 423 | echo $wrapDiv; |
| 424 | |
| 425 | $markup = ob_get_clean(); |
| 426 | |
| 427 | $dom->clear(); |
| 428 | unset( $dom, $wrapDiv ); |
| 429 | |
| 430 | $embedHTML = $style . $markup; |
| 431 | |
| 432 | } |
| 433 | |
| 434 | return $embedHTML; |
| 435 | |
| 436 | } |
| 437 | |
| 438 | |
| 439 | public static function embed_content_share($content_id='', $attributes = []){ |
| 440 | |
| 441 | $share_position = !empty($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right'; |
| 442 | $custom_thumnail = !empty($attributes['customThumbnail']) ? urlencode($attributes['customThumbnail']) : ''; |
| 443 | $custom_title = !empty($attributes['customTitle']) ? urlencode($attributes['customTitle']) : ''; |
| 444 | $custom_description = !empty($attributes['customDescription']) ? urlencode($attributes['customDescription']) : ''; |
| 445 | |
| 446 | $page_url = urlencode(get_permalink().'?hash='.$content_id); |
| 447 | |
| 448 | $social_icons = '<div class="ep-social-share-wraper"><div class="ep-social-share share-position-'.esc_attr( $share_position ).'">'; |
| 449 | $social_icons .= '<a href="https://www.facebook.com/sharer/sharer.php?u=' . $page_url . '" class="ep-social-icon facebook" target="_blank"> |
| 450 | <svg width="64px" height="64px" fill="#000000" viewBox="0 -6 512 512" xmlns="http://www.w3.org/2000/svg"> |
| 451 | <path d="M0 0h512v500H0z" fill="#475a96"/> |
| 452 | <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"/> |
| 453 | </svg> |
| 454 | </a>'; |
| 455 | $social_icons .= '<a href="https://twitter.com/intent/tweet?url=' . $page_url . '&text=' . $custom_title . '" class="ep-social-icon twitter" target="_blank"> |
| 456 | <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="0 0 248 204"> |
| 457 | <path fill="#ffffff" |
| 458 | 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" /> |
| 459 | </svg> |
| 460 | </a>'; |
| 461 | $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"> |
| 462 | |
| 463 | <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> |
| 464 | |
| 465 | </a>'; |
| 466 | |
| 467 | $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"> |
| 468 | |
| 469 | <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" |
| 470 | viewBox="0 0 310 310" xml:space="preserve"> |
| 471 | <g id="XMLID_801_"> |
| 472 | <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 |
| 473 | C77.16,101.969,74.922,99.73,72.16,99.73z"/> |
| 474 | <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 |
| 475 | c22.626,0,41.033-18.41,41.033-41.038C82.1,18.743,63.692,0.341,41.066,0.341z"/> |
| 476 | <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 |
| 477 | 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 |
| 478 | 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 |
| 479 | C310,145.43,300.549,94.761,230.454,94.761z"/> |
| 480 | </g> |
| 481 | </svg> |
| 482 | </a>'; |
| 483 | $social_icons .= '</div></div>'; |
| 484 | |
| 485 | return $social_icons ; |
| 486 | } |
| 487 | |
| 488 | |
| 489 | |
| 490 | public static function ep_get_elementor_widget_settings($page_settings = '', $id = '', $widgetType = ''){ |
| 491 | |
| 492 | $data = json_decode($page_settings, true); |
| 493 | |
| 494 | // Search for the element with the given ID |
| 495 | $element = null; |
| 496 | foreach ($data as $section) { |
| 497 | foreach ($section['elements'] as $column) { |
| 498 | foreach ($column['elements'] as $el) { |
| 499 | if ($el['id'] == $id && $el['elType'] == 'widget' && $el['widgetType'] == $widgetType) { |
| 500 | $element = $el; |
| 501 | break 3; |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | // Output the element code |
| 508 | if ($element) { |
| 509 | return $element;; |
| 510 | } |
| 511 | |
| 512 | } |
| 513 | |
| 514 | public static function ep_get_popup_icon() { |
| 515 | $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>'; |
| 516 | |
| 517 | return $svg; |
| 518 | } |
| 519 | public static function ep_get_download_icon() { |
| 520 | $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>'; |
| 521 | |
| 522 | return $svg; |
| 523 | } |
| 524 | |
| 525 | public static function ep_get_print_icon() { |
| 526 | $svg = '<div class="ep-doc-print-icon" ><svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 24 24"> |
| 527 | <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"/> |
| 528 | </svg></div>'; |
| 529 | |
| 530 | return $svg; |
| 531 | } |
| 532 | |
| 533 | public static function ep_get_fullscreen_icon() { |
| 534 | $svg = '<div class="ep-doc-fullscreen-icon"><svg width="25" height="25" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"> |
| 535 | <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"/> |
| 536 | </svg></div>'; |
| 537 | |
| 538 | return $svg; |
| 539 | } |
| 540 | public static function ep_get_minimize_icon() { |
| 541 | $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>'; |
| 542 | |
| 543 | return $svg; |
| 544 | } |
| 545 | public static function ep_get_draw_icon() { |
| 546 | $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>'; |
| 547 | |
| 548 | return $svg; |
| 549 | } |
| 550 | |
| 551 | public static function get_google_presentation_url($embedded_url){ |
| 552 | $parsed_url = parse_url($embedded_url); |
| 553 | $base_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $parsed_url['path']; |
| 554 | $base_url = strtok($base_url, '?'); |
| 555 | $base_url = rtrim($base_url, '/'); |
| 556 | return $base_url; |
| 557 | |
| 558 | } |
| 559 | |
| 560 | public static function check_media_format($url) { |
| 561 | $pattern1 = '/\.(mp4|mov|avi|wmv|flv|mkv|webm|mpeg|mpg)$/i'; |
| 562 | $pattern2 = '/\.(mp3|wav|ogg|aac)$/i'; |
| 563 | |
| 564 | $isVideo = preg_match($pattern1, $url); |
| 565 | $isAudio = preg_match($pattern2, $url); |
| 566 | |
| 567 | $is_self_hosted = false; |
| 568 | $format = ''; |
| 569 | |
| 570 | if (!empty($isVideo) || !empty($isAudio)) { |
| 571 | $is_self_hosted = true; |
| 572 | if (!empty($isVideo)) { |
| 573 | $format = 'video'; |
| 574 | } else if (!empty($isAudio)) { |
| 575 | $format = 'audio'; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | if (!$is_self_hosted) { |
| 580 | return [ |
| 581 | 'selhosted' => false, |
| 582 | ]; |
| 583 | } |
| 584 | |
| 585 | return [ |
| 586 | 'selhosted' => true, |
| 587 | 'format' => $format, |
| 588 | ]; |
| 589 | } |
| 590 | |
| 591 | public static function getCalendlyUuid($url){ |
| 592 | $pattern = '/\/([0-9a-fA-F-]+)$/'; |
| 593 | if (preg_match($pattern, $url, $matches)) { |
| 594 | $uuid = $matches[1]; |
| 595 | return $uuid; |
| 596 | } |
| 597 | return ''; |
| 598 | } |
| 599 | |
| 600 | public static function getCalendlyUserInfo($access_token) |
| 601 | { |
| 602 | // Attempt to retrieve the data from the transient |
| 603 | $user_info = get_transient('calendly_user_info_' . md5($access_token)); |
| 604 | |
| 605 | if (false === $user_info) { |
| 606 | // If the data is not in the transient, fetch it from the API |
| 607 | $user_endpoint = 'https://api.calendly.com/users/me'; |
| 608 | |
| 609 | $headers = array( |
| 610 | 'Authorization' => "Bearer $access_token", |
| 611 | 'Content-Type' => 'application/json', |
| 612 | ); |
| 613 | |
| 614 | $args = array( |
| 615 | 'headers' => $headers, |
| 616 | ); |
| 617 | |
| 618 | $response = wp_remote_get($user_endpoint, $args); |
| 619 | |
| 620 | if (!is_wp_error($response)) { |
| 621 | $body = wp_remote_retrieve_body($response); |
| 622 | $data = json_decode($body, true); |
| 623 | |
| 624 | // Store the data in a transient for a specified time (e.g., 1 hour) |
| 625 | set_transient('calendly_user_info', $data, HOUR_IN_SECONDS); |
| 626 | |
| 627 | return $data; |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | return $user_info; |
| 632 | } |
| 633 | |
| 634 | public static function getCalaendlyEventTypes($user_uri, $access_token) |
| 635 | { |
| 636 | // Attempt to retrieve the data from the transient |
| 637 | $events_list = get_transient('calendly_events_list_' . md5($access_token)); |
| 638 | |
| 639 | if (false === $events_list) { |
| 640 | // If the data is not in the transient, fetch it from the API |
| 641 | $events_endpoint = "https://api.calendly.com/event_types?user=$user_uri"; |
| 642 | |
| 643 | $headers = array( |
| 644 | 'Authorization' => "Bearer $access_token", |
| 645 | 'Content-Type' => 'application/json', |
| 646 | ); |
| 647 | |
| 648 | $args = array( |
| 649 | 'headers' => $headers, |
| 650 | ); |
| 651 | |
| 652 | $response = wp_remote_get($events_endpoint, $args); |
| 653 | |
| 654 | if (!is_wp_error($response)) { |
| 655 | $body = wp_remote_retrieve_body($response); |
| 656 | $events_list = json_decode($body, true); |
| 657 | |
| 658 | // Store the data in a transient for a specified time (e.g., 1 hour) |
| 659 | set_transient('calendly_events_list', $events_list, HOUR_IN_SECONDS); |
| 660 | |
| 661 | return $events_list; |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | return $events_list; |
| 666 | } |
| 667 | |
| 668 | public static function getListEventInvitee($uuid, $access_token) |
| 669 | { |
| 670 | // Attempt to retrieve the data from the transient |
| 671 | $invitee_list = get_transient('calendly_invitee_list_' . md5($access_token)); |
| 672 | |
| 673 | if (false === $invitee_list) { |
| 674 | // If the data is not in the transient, fetch it from the API |
| 675 | $events_endpoint = "https://api.calendly.com/scheduled_events/$uuid/invitees"; |
| 676 | |
| 677 | $headers = array( |
| 678 | 'Authorization' => "Bearer $access_token", |
| 679 | 'Content-Type' => 'application/json', |
| 680 | ); |
| 681 | |
| 682 | $args = array( |
| 683 | 'headers' => $headers, |
| 684 | ); |
| 685 | |
| 686 | $response = wp_remote_get($events_endpoint, $args); |
| 687 | |
| 688 | if (!is_wp_error($response)) { |
| 689 | $body = wp_remote_retrieve_body($response); |
| 690 | $invitee_list = json_decode($body, true); |
| 691 | |
| 692 | // Store the data in a transient for a specified time (e.g., 1 hour) |
| 693 | set_transient('calendly_invitee_list', $invitee_list, HOUR_IN_SECONDS); |
| 694 | |
| 695 | return $invitee_list; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | return $invitee_list; |
| 700 | } |
| 701 | |
| 702 | public static function getCalaendlyScheduledEvents($user_uri, $access_token) |
| 703 | { |
| 704 | // Attempt to retrieve the data from the transient |
| 705 | $events_list = get_transient('calendly_events_list_' . md5($access_token)); |
| 706 | |
| 707 | if (false === $events_list) { |
| 708 | // If the data is not in the transient, fetch it from the API |
| 709 | $events_endpoint = "https://api.calendly.com/scheduled_events?user=$user_uri"; |
| 710 | |
| 711 | $headers = array( |
| 712 | 'Authorization' => "Bearer $access_token", |
| 713 | 'Content-Type' => 'application/json', |
| 714 | ); |
| 715 | |
| 716 | $args = array( |
| 717 | 'headers' => $headers, |
| 718 | ); |
| 719 | |
| 720 | $response = wp_remote_get($events_endpoint, $args); |
| 721 | |
| 722 | if (!is_wp_error($response)) { |
| 723 | $body = wp_remote_retrieve_body($response); |
| 724 | $events_list = json_decode($body, true); |
| 725 | |
| 726 | // Store the data in a transient for a specified time (e.g., 1 hour) |
| 727 | set_transient('calendly_events_list', $events_list, HOUR_IN_SECONDS); |
| 728 | |
| 729 | return $events_list; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | return $events_list; |
| 734 | } |
| 735 | |
| 736 | |
| 737 | } |
| 738 | |
| 739 | ?> |
| 740 |