PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 1.3.14
Shortcodes and extra features for Phlox theme v1.3.14
2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / includes / general-functions.php
auxin-elements / includes Last commit date
classes 8 years ago elements 8 years ago define.php 8 years ago general-functions.php 8 years ago general-hooks.php 8 years ago general-shortcodes.php 8 years ago index.php 8 years ago
general-functions.php
950 lines
1 <?php
2 /**
3 *
4 *
5 * @package Auxin
6 * @license LICENSE.txt
7 * @author
8 * @link http://averta.net/phlox/
9 * @copyright (c) 2010-2017
10 */
11
12 /**
13 * Whether a plugin is active or not
14 *
15 * @param string $plugin_basename plugin directory name and mail file address
16 * @return bool True if plugin is active and FALSE otherwise
17 */
18 if( ! function_exists( 'auxin_is_plugin_active' ) ){
19 function auxin_is_plugin_active( $plugin_basename ){
20 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
21 return is_plugin_active( $plugin_basename );
22 }
23 }
24
25
26 /**
27 * Retrieves the markup for footer logo element
28 *
29 * @param array $args The properties fort this element
30 *
31 * @return string The markup for logo element
32 */
33 function auxin_get_footer_logo_block( $args = array() ){
34
35 $defaults = array(
36 'css_class' => '',
37 'middle' => true
38 );
39
40 $args = wp_parse_args( $args, $defaults );
41
42 ob_start();
43 ?>
44 <div class="aux-logo <?php echo $args['css_class']; ?>">
45 <a class="aux-logo-anchor <?php echo ($args['middle'] ? 'aux-middle' : ''); ?>" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
46 <?php echo _auxin_get_footer_logo_image(); ?>
47 </a>
48 </div><!-- end logo aux-fold -->
49
50 <?php
51 return ob_get_clean();
52 }
53
54
55 /**
56 * Retrieves the footer logo image tag
57 *
58 * @return string The markup for logo image
59 */
60 function _auxin_get_footer_logo_image(){
61
62 return wp_get_attachment_image( auxin_get_option('site_secondary_logo_image'), 'full', false, array(
63 'class' => 'aux-logo-image aux-logo-dark',
64 'itemprop' => 'logo',
65 'alt' => esc_attr( get_bloginfo( 'name', 'display' ) )
66 ) );
67
68 }
69
70 //// is absolute url ///////////////////////////////////////////////////////////////////
71
72 /**
73 * Whether it's absolute url or not
74 *
75 * @param string $url The URL
76 * @return bool TRUE if the URL is absolute
77 */
78
79 if( ! function_exists( "auxin_is_absolute_url" ) ){
80
81 function auxin_is_absolute_url( $url ){
82 return preg_match( "~^(?:f|ht)tps?://~i", $url );
83 }
84
85 }
86
87
88 //// create absolute url if the url is relative ////////////////////////////////////////
89
90 /**
91 * Print absolute URL for media file even if the URL is relative
92 *
93 * @param string $url The link to media file
94 * @return void
95 */
96 function auxin_the_absolute_image_url( $url ){
97 echo auxin_get_the_absolute_image_url( $url );
98 }
99
100 /**
101 * Get absolute URL for media file event if the URL is relative
102 *
103 * @param string $url The link to media file
104 * @return string The absolute URL to media file
105 */
106 if( ! function_exists( 'auxin_get_the_absolute_image_url' ) ){
107
108 function auxin_get_the_absolute_image_url( $url ){
109 if( ! isset( $url ) || empty( $url ) ) return '';
110
111 if( auxin_is_absolute_url( $url ) || auxin_contains_upload_dir( $url ) ) return $url;
112
113 $uploads = wp_get_upload_dir();
114 return trailingslashit( $uploads['baseurl'] ) . $url;
115 }
116
117 }
118
119 //// get all registerd siderbar ids ///////////////////////////////////////////////////
120
121 if( ! function_exists( 'auxin_get_all_sidebar_ids' ) ){
122
123 function auxin_get_all_sidebar_ids(){
124 $sidebars = get_theme_mod( 'auxin_sidebars');
125 $output = array();
126
127 if( isset( $auxin_sidebars ) && ! empty( $auxin_sidebars ) ){
128 foreach( $sidebars as $key => $value ) {
129 $output[] = THEME_ID .'-'. strtolower( str_replace(' ', '-', $value) );
130 }
131 }
132 return $output;
133 }
134
135 }
136
137 //// remove all auto generated p tags from shortcode content //////////////////////////
138
139 if( ! function_exists( "auxin_do_cleanup_shortcode" ) ){
140
141 function auxin_do_cleanup_shortcode( $content ) {
142
143 /* Parse nested shortcodes and add formatting. */
144 $content = trim( wpautop( do_shortcode( $content ) ) );
145
146 /* Remove any instances of '<p>' '</p>'. */
147 $content = auxin_cleanup_content( $content );
148
149 return $content;
150 }
151
152 }
153
154
155 //// remove all p tags from string ////////////////////////////////////////////////////
156
157 if( ! function_exists( 'auxin_cleanup_content' ) ){
158
159 function auxin_cleanup_content( $content ) {
160 /* Remove any instances of '<p>' '</p>'. */
161 return str_replace( array('<p>','</p>'), array('','') , $content );
162 }
163
164 }
165
166 /*-----------------------------------------------------------------------------------*/
167 /* A function that makes excluding featured image, post formats and post ids simpler
168 /*-----------------------------------------------------------------------------------*/
169
170 if( ! function_exists( 'auxin_parse_query_args' ) ){
171
172
173 /**
174 * A function that makes excluding featured image, post formats and post ids simpler
175 *
176 * @param array $args The list of options and query params
177 * @return array The parsed args as array
178 */
179 function auxin_parse_query_args( $args ){
180
181 $defaults = array(
182 'post_type' => 'post',
183 'post_status' => 'publish',
184 'posts_per_page' => -1,
185 'ignore_sticky_posts' => 1,
186
187 'posts__in' => '', // display only these post IDs. array or string comma separated
188 'posts__not_in' => '', // exclude these post IDs from result. array or string comma separated
189
190 'include_posts__in' => '', // include these post IDs in result too. array or string comma separated
191 'exclude_without_media' => 0, // exclude the posts without featured image
192 'exclude_post_formats_in' => '', // exclude the post with these post formats
193 );
194
195 // parse and merge the passed args
196 $parsed_args = wp_parse_args( $args, $defaults );
197
198
199 // Exclude post formats ----------------------------------------------------
200
201 // exclude post formats if specified
202 if( ! empty( $parsed_args['exclude_post_formats_in'] ) ){
203
204 // generate post-format terms (i.e post-format-aside)
205 $post_format_terms = array();
206 foreach ( $parsed_args['exclude_post_formats_in'] as $_post_format ) {
207 $post_format_terms[] = 'post-format-' . $_post_format;
208 }
209
210 // exclude the redundant taxonomies (post-format)
211 $parsed_args['tax_query'] = array(
212 array(
213 'taxonomy' => 'post_format',
214 'field' => 'slug',
215 'terms' => $post_format_terms,
216 'operator' => 'NOT IN'
217 )
218 );
219
220 }
221
222 // Exclude posts without featured image ------------------------------------
223
224 // whether to exclude posts without featured-image or not
225 if( $parsed_args['exclude_without_media'] ){
226 $parsed_args['meta_query'] = array(
227 array(
228 'key' => '_thumbnail_id',
229 'value' => '',
230 'compare' => '!='
231 )
232 );
233 }
234
235
236 // Include, Exclude & Replace Post IDs -------------------------------------
237
238 // get the list of custom post ids to display
239 $only_posts = $parsed_args['posts__in'] ? wp_parse_id_list( $parsed_args['posts__in'] ) : array();
240
241 // get the list of custom post ids to include
242 $include_posts = $parsed_args['include_posts__in'] ? wp_parse_id_list( $parsed_args['include_posts__in'] ) : array();
243
244 // get the list of custom post ids to exclude
245 $exclude_posts = $parsed_args['posts__not_in'] ? wp_parse_id_list( $parsed_args['posts__not_in'] ) : array();
246
247
248 // if both of post__in and post__not_in options are defined, we have to array_diff the arrays,
249 // because we cannot use post__in & post__not_in at the time in WordPress
250
251 if( $only_posts ){
252
253 if( $exclude_posts ){
254 // remove the excluded post ids from post__in list
255 if( $only_posts = array_filter( array_diff( $only_posts, $exclude_posts ) ) ){
256 $parsed_args['post__in'] = $only_posts;
257 }
258 } else {
259 $parsed_args['post__in'] = $only_posts;
260 }
261 $parsed_args['posts__not_in'] = '';
262
263 // if include_posts__in was specified
264 } elseif( $include_posts ){
265
266 $extra_query_args = $parsed_args;
267
268 // query the posts other than the ones we intend to include
269 $include_and_exclude_posts = array_unique( array_filter( array_merge( $include_posts, $exclude_posts ) ) );
270 // remove the excluded post ids from include_posts__in list
271 $the_posts_to_include = array_diff( $include_posts, $exclude_posts );
272
273 $extra_query_args['fields'] = 'ids'; // just get IDs, for better performance
274 $extra_query_args['post__in'] = ''; // forget post__in in this pre query
275 $extra_query_args['post__not_in'] = $include_and_exclude_posts; // dont select our include adn exclude posts in this query, we will prepend them later
276
277 // get the post ids other than our include and exclude list
278 $other_post_ids = get_posts( $extra_query_args );
279
280 // prepend the included post ids
281 $merged_post_ids = array_merge( $the_posts_to_include, $other_post_ids );
282
283 // change the main query base on previous result
284 $parsed_args = array(
285 'post__in' => $merged_post_ids,
286 'orderby' => 'post__in', // query base on the order of defined post ids
287 'posts_per_page' => $parsed_args['posts_per_page'],
288 'ignore_sticky_posts' => 1
289 );
290
291 // if just "post__not_in" option is specified
292 } elseif( $exclude_posts ) {
293 $parsed_args['post__not_in'] = $exclude_posts;
294 }
295
296 // Remove extra query args -------------------------------------------------
297
298 unset( $parsed_args['include_posts__in'] );
299 unset( $parsed_args['exclude_without_media'] );
300 unset( $parsed_args['exclude_post_formats_in'] );
301
302 return $parsed_args;
303 }
304
305 }
306
307
308
309 /*-----------------------------------------------------------------------------------*/
310 /* Extract only raw text - remove all special charecters, html tags, js and css codes
311 /*-----------------------------------------------------------------------------------*/
312
313 function auxin_extract_text( $content = null ) {
314 // decode encoded html tags
315 $content = htmlspecialchars_decode($content);
316 // remove script tag and inline js content
317 $content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content);
318 // remove style tag and inline css content
319 $content = preg_replace('#<style(.*?)>(.*?)</style>#is' , '', $content);
320 // remove iframe content
321 $content = preg_replace('#<if'.'rame(.*?)>(.*?)</iframe>#is', '', $content);
322 // remove extra white spaces
323 $content = preg_replace('/[\s]+/', ' ', $content );
324 // strip html tags and escape special charecters
325 $content = esc_attr(strip_tags($content));
326 // remove double space
327 $content = preg_replace('/\s{3,}/',' ', $content );
328 return $content;
329 }
330
331 /*-----------------------------------------------------------------------------------*/
332 /* Tiles layout patterns
333 /*-----------------------------------------------------------------------------------*/
334
335 /**
336 * Defines the size of post tile based on pattern and given index
337 * @param string $pattern
338 * @param int $index
339 * @return Array classname, image size
340 */
341 function auxin_get_tile_pattern( $pattern = 'default', $index, $column_media_width ) {
342
343 $div_index = $index % 12;
344 $return_value = array();
345
346 switch ( $div_index ) {
347
348 // large squares
349 case 0:
350 case 7:
351 $return_value = array(
352 'classname' => 'aux-tile-2-2 aux-t-tile-4-2 aux-m-tile-4-2',
353 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ),
354 'image_sizes' => array(
355 array( 'min' => '' , 'max' => '992px', 'width' => '100vw' ),
356 array( 'min' => '' , 'max' => '', 'width' => 2 * $column_media_width . 'px' )
357 ),
358 'srcset_sizes' => array(
359 array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ),
360 array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ),
361 array( 'width' => 8 * $column_media_width, 'height' => 8 * $column_media_width )
362 )
363 );
364 break;
365
366 // full width
367 case 5:
368 case 11:
369 $return_value = array(
370 'classname' => 'aux-tile-4-2',
371 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width * 0.5 ),
372 'image_sizes' => array(
373
374 ),
375 'srcset_sizes' => array(
376 array( 'width' => $column_media_width, 'height' => $column_media_width * 0.5),
377 array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width * 0.5),
378 array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width * 0.5 )
379 )
380 );
381 break;
382
383 // small squares
384 default:
385 $return_value = array(
386 'classname' => 'aux-tile-1-1 aux-t-tile-2-2 aux-m-tile-4-2',
387 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ),
388 'image_sizes' => array(
389 array( 'min' => '', 'max' => '767px', 'width' => '100vw' ),
390 array( 'min' => '' , 'max' => '992px', 'width' => '50vw' ),
391 array( 'min' => '' , 'max' => '', 'width' => $column_media_width . 'px' )
392 ),
393 'srcset_sizes' => array(
394 array( 'width' => $column_media_width, 'height' => $column_media_width ),
395 array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ),
396 array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width )
397 )
398 );
399
400 }
401
402 return $return_value;
403 }
404
405
406 /*-----------------------------------------------------------------------------------*/
407 /* Retrieves the provider from an embed code link
408 /*-----------------------------------------------------------------------------------*/
409
410
411 function auxin_extract_embed_provider_name( $src ){
412 require_once( ABSPATH . WPINC . '/class-oembed.php' );
413 $oembed = _wp_oembed_get_object();
414 if( ! $provider = $oembed->get_provider( $src ) ){
415 return '';
416 }
417
418 $provider_info = parse_url( $provider );
419 if( $provider_info['host'] ){
420 $host_parts = explode( '.', $provider_info['host'] );
421 $host_parts_num = count( $host_parts );
422 if( $host_parts_num > 1 ){
423 return $host_parts[ $host_parts_num -2 ];
424 }
425 }
426
427 return '';
428 }
429
430
431
432 //// Store content in file ////////////////////////////////////////////////////////
433
434 /**
435 * Creates and stores content in a file (#admin)
436 *
437 * @param string $content The content for writing in the file
438 * @param string $file_location The address that we plan to create the file in.
439 *
440 * @return boolean Returns true if the file is created and updated successfully, false on failure
441 */
442 function auxin_put_contents( $content, $file_location = '', $chmode = 0644 ){
443
444 if( empty( $file_location ) ){
445 return false;
446 }
447
448 /**
449 * Initialize the WP_Filesystem
450 */
451 global $wp_filesystem;
452 if ( empty( $wp_filesystem ) ) {
453 require_once ( ABSPATH.'/wp-admin/includes/file.php' );
454 WP_Filesystem();
455 }
456
457 // Write the content, if possible
458 if ( wp_mkdir_p( dirname( $file_location ) ) && ! $wp_filesystem->put_contents( $file_location, $content, $chmode ) ) {
459 // If writing the content in the file was not successful
460 return false;
461 } else {
462 return true;
463 }
464
465 }
466
467
468 //// Stores content in custom js file /////////////////////////////////////////////
469
470
471 /**
472 * Stores JavaScript content in custom js file (#admin)
473 *
474 * @return boolean Returns true if the file is created and updated successfully, false on failure
475 */
476 function auxin_save_custom_js(){
477
478 $js_string = get_theme_mod( 'custom_js_string' );
479
480 ob_start();
481 ?>
482 /*
483 ===============================================================
484 #CUSTOM JavaScript
485 - Please do not edit this file. This file is generated from admin area.
486 - Every changes here will be overwritten by theme
487 ===============================================================*/
488 <?php
489
490 $js_string = ob_get_clean() . $js_string;
491
492
493 if ( auxin_put_contents_dir( $js_string, 'custom.js' ) ) {
494 set_theme_mod( 'custom_js_ver', rand(10, 99)/10 ); // disable inline css output
495 set_theme_mod( 'use_inline_custom_js' , false ); // disable inline css output
496
497 return true;
498 } else {
499 // if the directory is not writable, try inline css fallback
500 set_theme_mod( 'use_inline_custom_js' , true ); // save css rules as option to print as inline css
501
502 return false;
503 }
504 }
505
506
507 /**
508 * Removes an specific content from custom js file (#admin)
509 *
510 * @param string $ref_name The reference name for referring a content in $js_array array
511 *
512 * @return boolean Returns true if the content was removed successfully, false on failure
513 */
514 function auxin_remove_custom_js( $ref_name = '' ){
515
516 // retrieve the js array list
517 $js_array = get_theme_mod( 'custom_js_array', array() );
518
519 if( isset( $js_array[ $ref_name ] ) ){
520 unset( $js_array[ $ref_name ] );
521
522 set_theme_mod( 'custom_js_array' , $js_array );
523 // update the file content too
524 auxin_add_custom_js();
525 }
526 }
527
528
529 /**
530 * Retrieves the list of custom scripts generated with themes options
531 *
532 * @param string $exclude_ref_names The reference names that are expected to be excluded from result
533 *
534 * @return boolean The list of custom scripts generated with themes options
535 */
536 function auxin_get_custom_js_array( $exclude_ref_names = array() ){
537 // retrieve the css array list
538 $js_array = get_theme_mod( 'custom_js_array', array() );
539
540 return array_diff_key( $js_array, array_flip( (array) $exclude_ref_names ) );
541 }
542
543
544
545 //// Stores content in custom css file /////////////////////////////////////////////
546
547
548 /**
549 * Stores css content in custom css file (#admin)
550 *
551 * @return boolean Returns true if the file is created and updated successfully, false on failure
552 */
553 function auxin_save_custom_css(){
554
555 $css_string = get_theme_mod( 'custom_css_string' );
556
557 ob_start();
558 ?>
559 /*
560 ===============================================================
561 #CUSTOM CSS
562 - Please do not edit this file. This file is generated from admin area.
563 - Every changes here will be overwritten by theme
564 ===============================================================*/
565 <?php
566
567 $css_string = ob_get_clean() . $css_string;
568
569 if ( auxin_put_contents_dir( $css_string, 'custom.css' ) ) {
570
571 set_theme_mod( 'custom_css_ver', rand(10, 99)/10 );
572 set_theme_mod( 'use_inline_custom_css' , false ); // disable inline css output
573
574 return true;
575 // if the directory is not writable, try inline css fallback
576 } else {
577 set_theme_mod( 'use_inline_custom_css' , true ); // save css rules as option to print as inline css
578 return false;
579 }
580 }
581
582
583 /**
584 * Removes an specific content from custom css file (#admin)
585 *
586 * @param string $ref_name The reference name for referring a content in $css_array array
587 *
588 * @return boolean Returns true if the content was removed successfully, false on failure
589 */
590 function auxin_remove_custom_css( $ref_name = '' ){
591
592 // retrieve the css array list
593 $css_array = get_theme_mod( 'custom_css_array', array() );
594
595 if( isset( $css_array[ $ref_name ] ) ){
596 unset( $css_array[ $ref_name ] );
597
598 set_theme_mod( 'custom_css_array', $css_array );
599 // update the file content too
600 auxin_add_custom_css();
601 }
602 }
603
604
605 /**
606 * Retrieves the list of custom styles generated with themes options
607 *
608 * @param string $exclude_ref_names The reference names that are expected to be excluded from result
609 *
610 * @return boolean The list of custom styles generated with themes options
611 */
612 function auxin_get_custom_css_array( $exclude_ref_names = array() ){
613 // retrieve the css array list
614 $css_array = get_theme_mod( 'custom_css_array', array() );
615
616 return array_diff_key( $css_array, array_flip( (array) $exclude_ref_names ) );
617 }
618
619
620 /**
621 * Retrieves the custom styles generated with themes options
622 *
623 * @param string $exclude_ref_names The css reference names that are expected to be excluded from result
624 *
625 * @return boolean The custom styles generated with themes options
626 */
627 function auxin_get_custom_css_string( $exclude_ref_names = array() ){
628 // retrieve the css array list
629 $css_array = auxin_get_custom_css_array( (array) $exclude_ref_names );
630 $css_string = '';
631
632 $sep_comment = apply_filters( 'auxin_custom_css_sep_comment', "/* %s \n=========================*/\n" );
633
634 // Convert the contents in array to string
635 if( is_array( $css_array ) ){
636 foreach ( $css_array as $node_ref => $node_content ) {
637 if( ! is_numeric( $node_ref) ){
638 $css_string .= sprintf( $sep_comment, str_replace( '_', '-', $node_ref ) );
639 }
640 $css_string .= "$node_content\n";
641 }
642 }
643
644 // Remove <style> if user used them in the style content
645 return str_replace( array( "<style>", "</style>" ), array('', ''), $css_string );
646 }
647
648
649 /**
650 * Extract numbers from string
651 *
652 * @param string $str The string that contains numbers
653 * @param int $default The number which should be returned if no number found in the string
654 * @return int The extracted numbers
655 */
656 function auxin_get_numerics( $str, $default = null ) {
657 if( empty( $str ) ){
658 return is_numeric( $default ) ? $default: '';
659 }
660 preg_match('/\d+/', $str, $matches);
661 return $matches[0];
662 }
663
664 /*-----------------------------------------------------------------------------------*/
665 /* Returns post type menu name
666 /*-----------------------------------------------------------------------------------*/
667
668 if( ! function_exists( 'auxin_get_post_type_name' ) ){
669
670 // returns post type menu name
671 function auxin_get_post_type_name( $post_type = '' ){
672 $post_type = empty( $post_type ) ? get_post_type() : $post_type;
673 $post_type_obj = get_post_type_object( $post_type );
674
675 return apply_filters( 'auxin_get_post_type_name', $post_type_obj->labels->menu_name, $post_type );
676 }
677
678 }
679
680
681 /*-----------------------------------------------------------------------------------*/
682 /* A function to generate header and footer for all widgets
683 /*-----------------------------------------------------------------------------------*/
684
685 function auxin_get_widget_scafold( $atts, $default_atts, $shortcode_content = '' ){
686
687 $result = array(
688 'parsed_atts' => '',
689 'widget_info' => '',
690 'widget_header' => '',
691 'widget_title' => '',
692 'widget_footer' => ''
693 );
694
695 // ----
696 if( ! isset( $default_atts['extra_classes'] ) ){
697 $default_atts['extra_classes'] = '';
698 }
699 if( ! isset( $default_atts['custom_el_id'] ) ){
700 $default_atts['custom_el_id'] = '';
701 }
702 if( ! isset( $default_atts['content'] ) ){
703 $default_atts['content'] = '';
704 }
705
706 // Widget general info
707 $before_widget = $after_widget = '';
708 $before_title = $after_title = '';
709
710 // If widget info is passed, extract them in above variables
711 if( isset( $atts['widget_info'] ) ){
712 $result['widget_info'] = $atts['widget_info'];
713 extract( $atts['widget_info'] );
714 }
715 // CSS class names for section -------------
716
717 // The default CSS classes for widget container
718 // Note that 'widget-container' should be in all element
719 $_css_classes = array( 'widget-container' );
720
721 // Parse shortcode attributes
722 $parsed_atts = shortcode_atts( $default_atts, $atts, __FUNCTION__ );
723
724 if( empty( $parsed_atts['content'] ) ){
725 $parsed_atts['content'] = $shortcode_content;
726 }
727
728 $result['parsed_atts'] = $parsed_atts;
729
730 // make the result params filterable prior to generating markup variables
731 $result = apply_filters( 'auxin_pre_widget_scafold_params', $result, $atts, $default_atts, $shortcode_content );
732
733 // Defining extra class names --------------
734
735 // Add extra class names to class list here - widget-{element_name}
736 $_css_classes[] = $result['parsed_atts']['base_class'];
737
738 // Covering classes in list to class attribute for main section
739 $section_class_attr = auxin_make_html_class_attribute( $_css_classes, $result['parsed_atts']['extra_classes'] );
740
741
742 if( $before_widget ){
743 $result['widget_header'] .= str_replace(
744 array( 'class="', '<div'),
745 array( 'class="'. $result['parsed_atts']['base_class'].' '.$result['parsed_atts']['extra_classes'].' widget-container ', '<section' ),
746 $before_widget
747 );
748 } elseif ( !empty($result['parsed_atts']['custom_el_id']) ){
749 $result['widget_header'] .= sprintf('<section id="%s" %s>', $result['parsed_atts']['custom_el_id'], $section_class_attr );
750 } else {
751 $result['widget_header'] .= sprintf('<section %s>', $section_class_attr );
752 }
753
754 if( ! empty( $result['parsed_atts']['title'] ) ){
755 if( $before_title ){
756 $result['widget_title'] .= $before_title . $result['parsed_atts']['title'] . $after_title;
757 } elseif( ! empty( $result['parsed_atts']['title'] ) ){
758 $result['widget_title'] .= '<h3 class="widget-title">'. $result['parsed_atts']['title'] .'</h3>';
759 }
760 }
761
762 if( $after_widget ){
763 // fix for the difference in end tag in siteorigin page builder
764 $result['widget_footer'] .= str_replace( '</div', '</section', $after_widget );
765 } else {
766 $result['widget_footer'] .= '</section><!-- widget-container -->';
767 }
768
769 return $result;
770 }
771
772
773 /*----------------------------------------------------------------------------*/
774 /* Retrieves remote data
775 /*----------------------------------------------------------------------------*/
776
777 /**
778 * Retrieves a URL using the HTTP POST method
779 *
780 * @return mixed|boolean The body content
781 */
782 function auxin_remote_post( $url, $args ) {
783 $request = wp_remote_post( $url, $args );
784
785 if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) {
786 return $request['body'];
787 }
788 return false;
789 }
790
791 /**
792 * Retrieves a URL using the HTTP GET method
793 *
794 * @return mixed|boolean The body content
795 */
796 function auxin_remote_get( $url, $args ) {
797 $request = wp_remote_get( $url, $args );
798
799 if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) {
800 return $request['body'];
801 }
802 return false;
803 }
804
805 /*----------------------------------------------------------------------------*/
806 /* Removes a class method from a specified filter hook.
807 /*----------------------------------------------------------------------------*/
808
809 if( ! function_exists( 'auxin_remove_filter_from_class' ) ){
810
811 /**
812 * Removes a class method from a specified filter hook.
813 *
814 * @param string $hook_name The filter hook to which the function to be removed is hooked
815 * @param string $class_name The name of class which its method should be removed.
816 * @param string $method_name The name of the method which should be removed.
817 * @param integer $priority Optional. The priority of the function. Default 10.
818 * @return bool Whether the function existed before it was removed.
819 */
820 function auxin_remove_filter_from_class( $hook_name = '', $class_name ='', $method_name = '', $priority = 10 ) {
821 global $wp_filter;
822
823 // Take only filters on right hook name and priority
824 if ( !isset($wp_filter[$hook_name][$priority]) || !is_array($wp_filter[$hook_name][$priority]) )
825 return false;
826
827 // Loop on filters registered
828 foreach( (array) $wp_filter[$hook_name][$priority] as $unique_id => $filter_array ) {
829 // Test if filter is an array ! (always for class/method)
830 if ( isset($filter_array['function']) && is_array($filter_array['function']) ) {
831 // Test if object is a class, class and method is equal to param !
832 if ( is_object($filter_array['function'][0]) && get_class($filter_array['function'][0]) && get_class($filter_array['function'][0]) == $class_name && $filter_array['function'][1] == $method_name ) {
833 unset($wp_filter[$hook_name][$priority][$unique_id]);
834 }
835 }
836
837 }
838
839 return false;
840 }
841
842 }
843
844
845 if( ! function_exists( 'auxin_remove_action_from_class' ) ){
846
847 /**
848 * Removes a class method from a specified filter hook.
849 *
850 * @param string $hook_name The filter hook to which the function to be removed is hooked
851 * @param string $class_name The name of class which its method should be removed.
852 * @param string $method_name The name of the method which should be removed.
853 * @param integer $priority Optional. The priority of the function. Default 10.
854 * @return bool Whether the function existed before it was removed.
855 */
856 function auxin_remove_action_from_class( $hook_name = '', $class_name ='', $method_name = '', $priority = 10 ) {
857 global $wp_action;
858
859 // Take only filters on right hook name and priority
860 if ( !isset($wp_action[$hook_name][$priority]) || !is_array($wp_action[$hook_name][$priority]) )
861 return false;
862
863 // Loop on filters registered
864 foreach( (array) $wp_action[$hook_name][$priority] as $unique_id => $filter_array ) {
865 // Test if filter is an array ! (always for class/method)
866 if ( isset($filter_array['function']) && is_array($filter_array['function']) ) {
867 // Test if object is a class, class and method is equal to param !
868 if ( is_object($filter_array['function'][0]) && get_class($filter_array['function'][0]) && get_class($filter_array['function'][0]) == $class_name && $filter_array['function'][1] == $method_name ) {
869 unset($wp_action[$hook_name][$priority][$unique_id]);
870 }
871 }
872
873 }
874
875 return false;
876 }
877
878 }
879
880
881
882 /*-----------------------------------------------------------------------------------*/
883 /* A function to get the custom style of Google maps
884 /*-----------------------------------------------------------------------------------*/
885
886 if ( ! function_exists( 'auxin_get_gmap_style' ) ) {
887
888 function auxin_get_gmap_style () {
889
890 $styler = '[{"featureType":"landscape.man_made","elementType":"geometry.fill","stylers":[{"color":"#e9e5dc"}]},{"featureType":"landscape.natural","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#b8cb93"}]},{"featureType":"poi","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"poi.business","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"poi.medical","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"poi.park","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"poi.park","elementType":"geometry.fill","stylers":[{"color":"#ccdca1"}]},{"featureType":"poi.sports_complex","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"road","elementType":"geometry.fill","stylers":[{"hue":"#ff0000"},{"saturation":-100},{"lightness":99}]},{"featureType":"road","elementType":"geometry.stroke","stylers":[{"color":"#808080"},{"lightness":54},{"visibility":"off"}]},{"featureType":"road","elementType":"labels.text.fill","stylers":[{"color":"#767676"}]},{"featureType":"road","elementType":"labels.text.stroke","stylers":[{"color":"#ffffff"}]},{"featureType":"water","elementType":"all","stylers":[{"saturation":43},{"lightness":-11},{"color":"#89cada"}]}]';
891
892 return apply_filters( 'auxin_gmap_style', $styler );
893 }
894 }
895
896
897
898
899 /**
900 * Removes all generate images from uploads directory
901 *
902 * @return void
903 */
904 function auxin_remove_all_generate_images( $remove = true ){
905 if( is_multisite() ){
906 return;
907 }
908 $upload_dir = wp_get_upload_dir();
909
910 $all_images = auxin_find_all_files( $upload_dir['basedir'] );
911 $generated_images = array();
912
913 foreach( $all_images as $key => $file ) {
914 if( 1 == preg_match("#-(\d+)x(\d+).(png|jpg|bmp|gif)$#", $file) ) {
915 $generated_images[] = $file;
916 if( $remove ){
917 unlink( $file );
918 }
919 }
920 }
921 echo count( $all_images ) . " / " . count( $generated_images );
922 }
923
924 /**
925 * Find all files within a directory
926 *
927 * @param string $dir The directory which we intend to serach in
928 * @return array List of files
929 */
930 function auxin_find_all_files( $dir, $recursive = true ){
931 $root = scandir( $dir );
932 $result = array();
933
934 foreach( $root as $file ){
935 if( $file === '.' || $file === '..') {
936 continue;
937 }
938 if( is_file( "$dir/$file" ) ){
939 $result[] = "$dir/$file";
940 continue;
941 } elseif( $recursive && is_dir( "$dir/$file" ) ){
942 $sub_dir_files = auxin_find_all_files( "$dir/$file" );
943 $result = array_merge( $result, $sub_dir_files );
944 }
945 }
946 return $result;
947 }
948
949
950