PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.6.8
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.6.8
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 3 years ago EmbedPress_Core_Installer.php 6 years ago EmbedPress_Notice.php 4 years ago EmbedPress_Plugin_Usage_Tracker.php 3 years ago Feature_Enhancer.php 3 years ago Helper.php 3 years ago
Helper.php
211 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 public static function parse_query($str, $urlEncoding = true)
26 {
27 $result = [];
28
29 if ($str === '') {
30 return $result;
31 }
32
33 if ($urlEncoding === true) {
34 $decoder = function ($value) {
35 return rawurldecode(str_replace('+', ' ', $value));
36 };
37 } elseif ($urlEncoding === PHP_QUERY_RFC3986) {
38 $decoder = 'rawurldecode';
39 } elseif ($urlEncoding === PHP_QUERY_RFC1738) {
40 $decoder = 'urldecode';
41 } else {
42 $decoder = function ($str) { return $str; };
43 }
44
45 foreach (explode('&', $str) as $kvp) {
46 $parts = explode('=', $kvp, 2);
47 $key = $decoder($parts[0]);
48 $value = isset($parts[1]) ? $decoder($parts[1]) : null;
49 if (!isset($result[$key])) {
50 $result[$key] = $value;
51 } else {
52 if (!is_array($result[$key])) {
53 $result[$key] = [$result[$key]];
54 }
55 $result[$key][] = $value;
56 }
57 }
58
59 return $result;
60 }
61 public static function get_pdf_renderer() {
62 $renderer = EMBEDPRESS_URL_ASSETS . 'pdf/web/viewer.html';
63 // @TODO; apply settings query args here
64 return $renderer;
65 }
66
67 public static function get_extension_from_file_url($url) {
68 $urlSplit = explode(".", $url);
69 $ext = end($urlSplit);
70 return $ext;
71
72 }
73
74 public static function is_file_url($url) {
75 $pattern = '/\.([0-9a-z]+)(?=[?#])|(\.)(?:[\w]+)$/i';
76 return preg_match($pattern, $url) === 1;
77 }
78
79 public static function is_opensea($url) {
80 return strpos($url, "opensea.io") !== false;
81 }
82 public static function is_youtube_channel($url) {
83 return (bool) (preg_match('~(?:https?:\/\/)?(?:www\.)?(?:youtube.com\/)(?:channel\/|c\/|user\/|@)(\w+)~i', (string) $url));
84 }
85
86 public static function is_youtube($url) {
87 return (bool) (preg_match('~(?:https?://)?(?:www\.)?(?:youtube\.com|youtu\.be)/watch\?v=([^&]+)~i', (string) $url));
88 }
89
90 // Saved sources data temporary in wp_options table
91 public static function get_source_data($blockid, $source_url, $source_option_name, $source_temp_option_name) {
92
93
94 if(self::is_youtube_channel($source_url)){
95 $source_name = 'YoutubeChannel';
96 }
97 else if(self::is_youtube($source_url)){
98 $source_name = 'Youtube';
99 }
100 else if (!empty(self::is_file_url($source_url))) {
101 $source_name = 'document_' . self::get_extension_from_file_url($source_url);
102 }
103 else if(self::is_opensea($source_url)){
104 $source_name = 'OpenSea';
105 }
106 else{
107 Shortcode::get_embera_instance();
108 $collectios = Shortcode::get_collection();
109 $provider = $collectios->findProviders($source_url);
110 if(!empty($provider[$source_url])){
111 $source_name = $provider[$source_url]->getProviderName();
112 }
113 else{
114 $source_name = 'Unknown Source';
115 }
116 }
117
118 if(!empty($blockid) && $blockid != 'undefined'){
119 $sources = json_decode(get_option($source_temp_option_name), true);
120
121 if(!$sources) {
122 $sources = array();
123 }
124 $exists = false;
125
126 foreach($sources as $i => $source) {
127 if ($source['id'] === $blockid) {
128 $sources[$i]['source']['name'] = $source_name;
129 $sources[$i]['source']['url'] = $source_url;
130 $exists = true;
131 break;
132 }
133 }
134
135 if(!$exists) {
136 $sources[] = array('id' => $blockid, 'source' => array('name' => $source_name, 'url' => $source_url, 'count' => 1));
137 }
138
139 update_option($source_temp_option_name, json_encode($sources));
140 }
141 }
142
143 // Saved source data when post updated
144 public static function get_save_source_data_on_post_update( $source_option_name, $source_temp_option_name ) {
145
146 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
147 return;
148 }
149 $temp_data = json_decode(get_option($source_temp_option_name), true);
150 $source_data = json_decode(get_option($source_option_name), true);
151 if(!$temp_data) {
152 $temp_data = array();
153 }
154 if(!$source_data) {
155 $source_data = array();
156 }
157
158 $sources = array_merge($temp_data, $source_data);
159
160 $unique_sources = array();
161 foreach ($sources as $source) {
162 $unique_sources[$source['id']] = $source;
163 }
164
165 $unique_sources = array_values($unique_sources);
166
167 delete_option($source_temp_option_name);
168
169 update_option($source_option_name, json_encode($unique_sources));
170 }
171
172 //Delete source data from option table when widget is removed
173 public static function get_delete_source_data($blockid, $source_option_name, $source_temp_option_name) {
174 if (!empty($blockid) && $blockid != 'undefined') {
175 $sources = json_decode(get_option($source_option_name), true);
176 $temp_sources = json_decode(get_option($source_temp_option_name), true);
177 if ($sources) {
178 foreach ($sources as $i => $source) {
179 if ($source['id'] === $blockid) {
180 unset($sources[$i]);
181 break;
182 }
183 }
184 update_option($source_option_name, json_encode(array_values($sources)));
185 }
186 if ($temp_sources) {
187 foreach ($temp_sources as $i => $source) {
188 if ($source['id'] === $blockid) {
189 unset($temp_sources[$i]);
190 break;
191 }
192 }
193 update_option($source_temp_option_name, json_encode(array_values($temp_sources)));
194 }
195 }
196 wp_die();
197 }
198
199 //Delete source temporary data when reload without update or publish
200 public static function get_delete_source_temp_data_on_reload($source_temp_option_name) {
201 $source_temp_data = json_decode(get_option($source_temp_option_name), true);
202 if ($source_temp_data ) {
203 delete_option( $source_temp_option_name );
204 }
205 }
206
207 public static function get_file_title($url){
208 return get_the_title(attachment_url_to_postid( $url ));
209 }
210 }
211