Admin.php
3 years ago
Ajax_Handler.php
2 years ago
Controls.php
2 years ago
Core.php
3 years ago
Elements.php
2 years ago
Enqueue.php
3 years ago
Facebook_Feed.php
3 years ago
Helper.php
2 years ago
Library.php
3 years ago
Login_Registration.php
2 years ago
Shared.php
5 years ago
Template_Query.php
4 years ago
Twitter_Feed.php
2 years ago
Woo_Product_Comparable.php
3 years ago
index.php
3 years ago
Library.php
321 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Essential_Addons_Elementor\Traits; |
| 4 | |
| 5 | use Elementor\Plugin; |
| 6 | |
| 7 | if (!defined('ABSPATH')) { |
| 8 | exit; |
| 9 | } // Exit if accessed directly |
| 10 | |
| 11 | trait Library |
| 12 | { |
| 13 | public $a; |
| 14 | /** |
| 15 | * Return array of registered elements. |
| 16 | * |
| 17 | * @todo filter output |
| 18 | */ |
| 19 | |
| 20 | public function get_registered_elements() |
| 21 | { |
| 22 | return array_keys($this->registered_elements); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Return saved settings |
| 27 | * |
| 28 | * @since 3.0.0 |
| 29 | */ |
| 30 | public function get_settings($element = null) |
| 31 | { |
| 32 | $defaults = array_fill_keys(array_keys(array_merge($this->registered_elements, $this->registered_extensions)), true); |
| 33 | $elements = get_option('eael_save_settings', $defaults); |
| 34 | $elements = array_merge($defaults, $elements); |
| 35 | |
| 36 | return (isset($element) ? (isset($elements[$element]) ? $elements[$element] : 0) : array_keys(array_filter($elements))); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @param $page_obj |
| 41 | * @param $key |
| 42 | * @return string |
| 43 | */ |
| 44 | public function get_extension_settings($page_settings = [], $global_settings = [], $extension = '', $key = '') |
| 45 | { |
| 46 | if (isset($page_settings) && $page_settings->get_settings($extension) == 'yes') { |
| 47 | return $page_settings->get_settings($key); |
| 48 | } else if (isset($global_settings[$extension]['enabled'])) { |
| 49 | return isset($global_settings[$extension][$key]) ? $global_settings[$extension][$key] : ''; |
| 50 | } |
| 51 | |
| 52 | return ''; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @param $id |
| 57 | * @param $global_data |
| 58 | * @return string |
| 59 | */ |
| 60 | public function get_typography_data($id, $global_data) |
| 61 | { |
| 62 | $typo_data = ''; |
| 63 | $fields_keys = [ |
| 64 | 'font_family', |
| 65 | 'font_weight', |
| 66 | 'text_transform', |
| 67 | 'font_style', |
| 68 | 'text_decoration', |
| 69 | 'font_size', |
| 70 | 'letter_spacing', |
| 71 | 'line_height', |
| 72 | ]; |
| 73 | |
| 74 | foreach ($fields_keys as $key => $field) { |
| 75 | $typo_attr = $global_data[$id . '_' . $field]; |
| 76 | $attr = str_replace('_', '-', $field); |
| 77 | |
| 78 | if (in_array($field, ['font_size', 'letter_spacing', 'line_height'])) { |
| 79 | if (!empty($typo_attr['size'])) { |
| 80 | $typo_data .= "{$attr}:{$typo_attr['size']}{$typo_attr['unit']} !important;"; |
| 81 | } |
| 82 | } elseif (!empty($typo_attr)) { |
| 83 | $typo_data .= ($attr == 'font-family') ? "{$attr}:{$typo_attr}, sans-serif;" : "{$attr}:{$typo_attr};"; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return $typo_data; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Check if assets files exists |
| 92 | * |
| 93 | * @since 3.0.0 |
| 94 | */ |
| 95 | public function has_assets_files($uid = null, $ext = ['css', 'js']) |
| 96 | { |
| 97 | if (!is_array($ext)) { |
| 98 | $ext = (array) $ext; |
| 99 | } |
| 100 | |
| 101 | foreach ($ext as $e) { |
| 102 | $path = EAEL_ASSET_PATH . DIRECTORY_SEPARATOR . ($uid ? $uid : 'eael') . '.min.' . $e; |
| 103 | |
| 104 | if (!is_readable($this->safe_path($path))) { |
| 105 | return false; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Remove files |
| 114 | * |
| 115 | * @since 3.0.0 |
| 116 | */ |
| 117 | public function remove_files( $post_id = null, $ext = [ 'css', 'js' ] ) { |
| 118 | foreach ( $ext as $e ) { |
| 119 | $path = EAEL_ASSET_PATH . DIRECTORY_SEPARATOR . 'eael' . ( $post_id ? '-' . $post_id : '' ) . '.' . $e; |
| 120 | if ( file_exists( $path ) ) { |
| 121 | unlink( $path ); |
| 122 | } |
| 123 | } |
| 124 | do_action( 'eael_remove_assets', $post_id, $ext ); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Remove files in dir |
| 129 | * |
| 130 | * @since 3.0.0 |
| 131 | */ |
| 132 | public function empty_dir($path) |
| 133 | { |
| 134 | if (!is_dir($path) || !file_exists($path)) { |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | foreach (scandir($path) as $item) { |
| 139 | if ($item == '.' || $item == '..') { |
| 140 | continue; |
| 141 | } |
| 142 | |
| 143 | unlink($this->safe_path($path . DIRECTORY_SEPARATOR . $item)); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Clear cache files |
| 149 | * |
| 150 | * @since 3.0.0 |
| 151 | */ |
| 152 | |
| 153 | |
| 154 | /** |
| 155 | * Check if wp running in background |
| 156 | * |
| 157 | * @since 3.0.0 |
| 158 | */ |
| 159 | public function is_running_background() |
| 160 | { |
| 161 | if (wp_doing_cron()) { |
| 162 | return true; |
| 163 | } |
| 164 | |
| 165 | if (wp_doing_ajax()) { |
| 166 | return true; |
| 167 | } |
| 168 | |
| 169 | if (!empty($_REQUEST['action']) && !$this->check_background_action( sanitize_text_field( $_REQUEST['action'] ) )) { |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Check if elementor edit mode or not |
| 178 | * |
| 179 | * @since 3.0.0 |
| 180 | */ |
| 181 | public function is_edit_mode() |
| 182 | { |
| 183 | if (isset($_REQUEST['elementor-preview'])) { |
| 184 | return true; |
| 185 | } |
| 186 | |
| 187 | return false; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Check if elementor edit mode or not |
| 192 | * |
| 193 | * @since 3.0.0 |
| 194 | */ |
| 195 | public function is_preview_mode() |
| 196 | { |
| 197 | if (isset($_REQUEST['elementor-preview'])) { |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | if (!empty($_REQUEST['action']) && !$this->check_background_action( sanitize_text_field( $_REQUEST['action'] ) )) { |
| 202 | return false; |
| 203 | } |
| 204 | |
| 205 | |
| 206 | return true; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Check if a plugin is installed |
| 211 | * |
| 212 | * @since v3.0.0 |
| 213 | */ |
| 214 | public function is_plugin_installed($basename) |
| 215 | { |
| 216 | if (!function_exists('get_plugins')) { |
| 217 | include_once ABSPATH . '/wp-admin/includes/plugin.php'; |
| 218 | } |
| 219 | |
| 220 | $installed_plugins = get_plugins(); |
| 221 | |
| 222 | return isset($installed_plugins[$basename]); |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Generate safe path |
| 227 | * |
| 228 | * @since v3.0.0 |
| 229 | */ |
| 230 | public function safe_path($path) |
| 231 | { |
| 232 | $path = str_replace(['//', '\\\\'], ['/', '\\'], $path); |
| 233 | |
| 234 | return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Generate safe url |
| 239 | * |
| 240 | * @since v3.0.0 |
| 241 | */ |
| 242 | public function safe_url($url) |
| 243 | { |
| 244 | if (is_ssl()) { |
| 245 | $url = wp_parse_url($url); |
| 246 | |
| 247 | if (!empty($url['host'])) { |
| 248 | $url['scheme'] = 'https'; |
| 249 | } |
| 250 | |
| 251 | return $this->unparse_url($url); |
| 252 | } |
| 253 | |
| 254 | return $url; |
| 255 | } |
| 256 | |
| 257 | public function unparse_url($parsed_url) |
| 258 | { |
| 259 | $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; |
| 260 | $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; |
| 261 | $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; |
| 262 | $user = isset($parsed_url['user']) ? $parsed_url['user'] : ''; |
| 263 | $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : ''; |
| 264 | $pass = ($user || $pass) ? "$pass@" : ''; |
| 265 | $path = isset($parsed_url['path']) ? $parsed_url['path'] : ''; |
| 266 | $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; |
| 267 | $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : ''; |
| 268 | |
| 269 | return "$scheme$user$pass$host$port$path$query$fragment"; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Allow to load asset for some pre defined action query param in elementor preview |
| 274 | * @return bool |
| 275 | */ |
| 276 | public function check_background_action($action_name){ |
| 277 | $allow_action = [ |
| 278 | 'subscriptions', |
| 279 | 'mepr_unauthorized', |
| 280 | 'home', |
| 281 | 'subscriptions', |
| 282 | 'payments', |
| 283 | 'newpassword', |
| 284 | 'manage_sub_accounts', |
| 285 | 'ppw_postpass', |
| 286 | ]; |
| 287 | if (in_array($action_name, $allow_action)){ |
| 288 | return true; |
| 289 | } |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | * Check some other cookie for solve asset loading issue |
| 295 | */ |
| 296 | public function check_third_party_cookie_status($id='') { |
| 297 | global $Password_Protected; |
| 298 | if ( is_object( $Password_Protected ) && method_exists( $Password_Protected, 'cookie_name' ) && isset( $_COOKIE[ $Password_Protected->cookie_name() ] ) ) { |
| 299 | return true; |
| 300 | } |
| 301 | return false; |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * check_protected_content_status |
| 306 | * |
| 307 | * check EaeL Protected content cookie set or not |
| 308 | * |
| 309 | * @return bool |
| 310 | */ |
| 311 | public function check_protected_content_status(){ |
| 312 | if(!empty($_POST['eael_protected_content_id'])){ |
| 313 | if(!empty($_POST['protection_password_'.$_POST['eael_protected_content_id']])){ |
| 314 | return true; |
| 315 | } |
| 316 | } |
| 317 | return false; |
| 318 | } |
| 319 | |
| 320 | } |
| 321 |