PluginProbe
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor / 2.2.4
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor v2.2.4
4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.10.02 3.10.01 3.9.10 3.9.9 3.9.8 3.9.7 3.9.5 3.9.6 3.9.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 All 183 releases
elementskit-lite / helpers / utils.php

utils.php in ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor 2.2.4, at helpers/utils.php

293 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ElementsKit_Lite;
3
4 defined( 'ABSPATH' ) || exit;
5
6 /**
7 * Global helper class.
8 *
9 * @since 1.0.0
10 */
11
12 class Utils {
13
14 /**
15 * Auto generate classname from path.
16 *
17 * @since 1.0.0
18 * @access public
19 */
20 public static function make_classname( $dirname ) {
21 $dirname = pathinfo($dirname, PATHINFO_FILENAME);
22 $class_name = explode( '-', $dirname );
23 $class_name = array_map( 'ucfirst', $class_name );
24 $class_name = implode( '_', $class_name );
25
26 return $class_name;
27 }
28
29 public static function google_fonts($font_families = []) {
30 $fonts_url = '';
31 if ( $font_families ) {
32 $query_args = array(
33 'family' => urlencode( implode( '|', $font_families ) )
34 );
35
36 $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
37 }
38
39 return esc_url_raw( $fonts_url );
40 }
41
42 public static function kses( $raw ) {
43
44 $allowed_tags = array(
45 'a' => array(
46 'class' => array(),
47 'href' => array(),
48 'rel' => array(),
49 'title' => array(),
50 'target' => array(),
51 ),
52 'abbr' => array(
53 'title' => array(),
54 ),
55 'b' => array(),
56 'blockquote' => array(
57 'cite' => array(),
58 ),
59 'cite' => array(
60 'title' => array(),
61 ),
62 'code' => array(),
63 'pre' => array(),
64 'del' => array(
65 'datetime' => array(),
66 'title' => array(),
67 ),
68 'dd' => array(),
69 'div' => array(
70 'class' => array(),
71 'title' => array(),
72 'style' => array(),
73 ),
74 'dl' => array(),
75 'dt' => array(),
76 'em' => array(),
77 'strong' => array(),
78 'h1' => array(
79 'class' => array(),
80 ),
81 'h2' => array(
82 'class' => array(),
83 ),
84 'h3' => array(
85 'class' => array(),
86 ),
87 'h4' => array(
88 'class' => array(),
89 ),
90 'h5' => array(
91 'class' => array(),
92 ),
93 'h6' => array(
94 'class' => array(),
95 ),
96 'i' => array(
97 'class' => array(),
98 ),
99 'img' => array(
100 'alt' => array(),
101 'class' => array(),
102 'height' => array(),
103 'src' => array(),
104 'width' => array(),
105 ),
106 'li' => array(
107 'class' => array(),
108 ),
109 'ol' => array(
110 'class' => array(),
111 ),
112 'p' => array(
113 'class' => array(),
114 ),
115 'q' => array(
116 'cite' => array(),
117 'title' => array(),
118 ),
119 'span' => array(
120 'class' => array(),
121 'title' => array(),
122 'style' => array(),
123 ),
124 'iframe' => array(
125 'width' => array(),
126 'height' => array(),
127 'scrolling' => array(),
128 'frameborder' => array(),
129 'allow' => array(),
130 'src' => array(),
131 ),
132 'strike' => array(),
133 'br' => array(),
134 'strong' => array(),
135 'data-wow-duration' => array(),
136 'data-wow-delay' => array(),
137 'data-wallpaper-options' => array(),
138 'data-stellar-background-ratio' => array(),
139 'ul' => array(
140 'class' => array(),
141 ),
142 );
143
144 if ( function_exists( 'wp_kses' ) ) { // WP is here
145 return wp_kses( $raw, $allowed_tags );
146 } else {
147 return $raw;
148 }
149 }
150
151 public static function kspan($text){
152 return str_replace(['{', '}'], ['<span>', '</span>'], self::kses($text));
153 }
154
155 public static function ekit_get__forms($post_type) {
156 $wpuf_form_list = get_posts(array(
157 'post_type' => $post_type,
158 'showposts' => 999,
159 ));
160
161 $options = array();
162
163 if (!empty($wpuf_form_list) && !is_wp_error($wpuf_form_list)) {
164 $options[0] = esc_html__('Select Form', 'elementskit-lite');
165 foreach ($wpuf_form_list as $post) {
166 $options[$post->ID] = $post->post_title;
167 }
168 } else {
169 $options[0] = esc_html__('Create a form first', 'elementskit-lite');
170 }
171
172 return $options;
173 }
174
175 public static function ekit_get_ninja_form() {
176 $options = array();
177
178 if (class_exists('Ninja_Forms')) {
179 $contact_forms = Ninja_Forms()->form()->get_forms();
180
181 if (!empty($contact_forms) && !is_wp_error($contact_forms)) {
182
183 $options[0] = esc_html__('Select Ninja Form', 'elementskit-lite');
184
185 foreach ($contact_forms as $form) {
186 $options[$form->get_id()] = $form->get_setting('title');
187 }
188 }
189 } else {
190 $options[0] = esc_html__('Create a Form First', 'elementskit-lite');
191 }
192
193 return $options;
194 }
195
196 public static function tablepress_table_list() {
197 $table_options = array();
198
199 if (class_exists('TablePress')) {
200 $table_ids = \TablePress::$model_table->load_all( false );
201 $table_options[0] = esc_html__( 'Select Table', 'elementskit-lite' );
202
203 foreach ( $table_ids as $table_id ) {
204 // Load table, without table data, options, and visibility settings.
205 $table = \TablePress::$model_table->load( $table_id, false, false );
206
207 if ( '' === trim( $table['name'] ) ) {
208 $table['name'] = __( '(no name)', 'elementskit-lite' );
209 }
210
211 $table_options[$table['id']] = $table['name'];
212 }
213 } else {
214 $table_options[0] = esc_html__('Create a Table First', 'elementskit-lite');
215 }
216
217 return $table_options;
218 }
219
220 public static function ekit_do_shortcode( $tag, array $atts = array(), $content = null ) {
221 global $shortcode_tags;
222 if ( ! isset( $shortcode_tags[ $tag ] ) ) {
223 return false;
224 }
225 return call_user_func( $shortcode_tags[ $tag ], $atts, $content, $tag );
226 }
227
228 public static function trim_words($text, $num_words){
229 return wp_trim_words( $text, $num_words, '' );
230 }
231
232 public static function array_push_assoc($array, $key, $value){
233 $array[$key] = $value;
234 return $array;
235 }
236
237 public static function render_elementor_content_css($content_id){
238 if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) {
239 $css_file = new \Elementor\Core\Files\CSS\Post( $content_id );
240 $css_file->enqueue();
241 }
242 }
243
244 public static function render_elementor_content($content_id){
245 $elementor_instance = \Elementor\Plugin::instance();
246 $has_css = false;
247
248 /**
249 * CSS Print Method Internal and Exteral option support for Header and Footer Builder.
250 */
251 if (('internal' === get_option( 'elementor_css_print_method' )) || \Elementor\Plugin::$instance->preview->is_preview_mode()) {
252 $has_css = true;
253 }
254
255 return $elementor_instance->frontend->get_builder_content_for_display( $content_id , $has_css );
256 }
257
258 public static function render($content){
259 if (stripos($content, "elementskit-has-lisence") !== false) {
260 return null;
261 }
262
263 return $content;
264 }
265
266 public static function render_tab_content($content, $id){
267 return str_replace('.elementor-'.$id.' ', '#elementor .elementor-'.$id.' ', $content);
268 }
269
270 public static function img_meta($id){
271 $attachment = get_post($id);
272 if($attachment == null || $attachment->post_type != 'attachment'){
273 return null;
274 }
275 return [
276 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
277 'caption' => $attachment->post_excerpt,
278 'description' => $attachment->post_content,
279 'href' => get_permalink( $attachment->ID ),
280 'src' => $attachment->guid,
281 'title' => $attachment->post_title
282 ];
283 }
284
285 public static function esc_options($str, $options = [], $default = ''){
286 if(!in_array($str, $options)){
287 return $default;
288 }
289
290 return $str;
291 }
292 }
293