· 8 years ago · May 02, 2018, 09:32 AM
1<?php if ( ! defined('AVIA_FW')) exit('No direct script access allowed');
2/**
3 * This file holds various helper functions that are needed by the frameworks FRONTEND
4 *
5 * @author Christian "Kriesi" Budschedl
6 * @copyright Copyright (c) Christian Budschedl
7 * @link http://kriesi.at
8 * @link http://aviathemes.com
9 * @since Version 1.0
10 * @package AviaFramework
11 */
12
13
14
15if(!function_exists('avia_option'))
16{
17 /**
18 * This function serves as shortcut for avia_get_option and is used to retrieve options saved within the database with the first key set to "avia" which is the majority of all options
19 * Please note that while the get_avia_option returns the result, this function echos it by default. if you want to retrieve an option and store the variable please use get_avia_option or set $echo to false
20 *
21 * basically the function is called like this: avia_option('portfolio');
22 * That would retrieve the following var saved in the global $avia superobject: $avia->options['avia']['portfolio']
23 * If you want to set a default value that is returned in case there was no array match you need to use this scheme:
24 *
25 * avia_option( 'portfolio', "my default");
26 *
27 * @param string $key accepts a comma separated string with keys
28 * @param string $default return value in case we got no result
29 * @param bool $echo echo the result or not, default is to false
30 * @param bool $decode decode the result or not, default is to false
31 * @return string $result: the saved result. if no result was saved or the key doesnt exist returns an empty string
32 */
33 function avia_option($key, $default = "", $echo = true, $decode = true)
34 {
35 $result = avia_get_option($key, $default, false, $decode);
36
37 if(!$echo) return $result; //if we dont want to echo the output end script here
38
39 echo $result;
40 }
41}
42
43
44
45if(!function_exists('avia_get_option'))
46{
47 /**
48 * This function serves as shortcut to retrieve options saved within the database by the option pages of the avia framework
49 *
50 * basically the function is called like this: avia_get_option('portfolio');
51 * That would retrieve the following var saved in the global $avia superobject: $avia->options['avia']['portfolio']
52 * If you want to set a default value that is returned in case there was no array match you need to use this scheme:
53 *
54 * avia_get_option('portfolio', "my default"); or
55 * avia_get_option(array('avia','portfolio'), "my default"); or
56 *
57 * @param string $key accepts a comma separated string with keys
58 * @param string $default return value in case we got no result
59 * @param bool $echo echo the result or not, default is to false
60 * @param bool $decode decode the result or not, default is to false
61 * @return string $result: the saved result. if no result was saved or the key doesnt exist returns an empty string
62 */
63 function avia_get_option($key = false, $default = "", $echo = false, $decode = true)
64 {
65 global $avia;
66 $result = $avia->options;
67
68 if(is_array($key))
69 {
70 $result = $result[$key[0]];
71 }
72 else
73 {
74 $result = $result['avia'];
75 }
76
77 if($key === false)
78 {
79 //pass the whole array
80 }
81 else if(isset($result[$key]))
82 {
83 $result = $result[$key];
84 }
85 else
86 {
87 $result = $default;
88 }
89
90
91 if($decode) { $result = avia_deep_decode($result); }
92 if($result == "") { $result = $default; }
93 if($echo) echo $result;
94
95 return $result;
96 }
97}
98
99
100
101if(!function_exists('avia_get_the_ID'))
102{
103 /**
104 * This function is similiar to the wordpress function get_the_ID, but other than the wordpress function this functions takes into account
105 * if we will display a different post later on, a post that differs from the one we queried in the first place. The function also holds this
106 * original ID, even if another query is then executed (for example in dynamic templates for columns)
107 *
108 * an example would be the frontpage template were by default, the ID of the latest blog post is served by wordpress get_the_ID function.
109 * avia_get_the_ID would return the same blog post ID if the blog is really displayed on the frontpage. if a static page is displayed the
110 * function will display the ID of the static page, even if the page is not yet queried
111 *
112 * @return int $ID: the "real" ID of the post/page we are currently viewing
113 */
114 function avia_get_the_ID()
115 {
116 global $avia_config;
117 $ID = false;
118
119 if(!isset($avia_config['real_ID']))
120 {
121 if(!empty($avia_config['new_query']['page_id']))
122 {
123 $ID = $avia_config['new_query']['page_id'];
124 $avia_config['real_ID'] = $ID;
125 }
126 else
127 {
128 $post = get_post();
129 if(isset($post->ID))
130 {
131 $ID = $post->ID;
132 $avia_config['real_ID'] = $ID;
133 }
134 else
135 {
136 $ID = false;
137 }
138 //$ID = @get_the_ID();
139 }
140 }
141 else
142 {
143 $ID = $avia_config['real_ID'];
144 }
145
146 $ID = apply_filters('avf_avia_get_the_ID', $ID);
147
148 return $ID;
149 }
150
151 add_action('wp_head', 'avia_get_the_ID');
152}
153
154
155if(!function_exists('avia_is_overview'))
156{
157 /**
158 * This function checks if the page we are going to render is a page with a single entry or a multi entry page (blog or archive for example)
159 *
160 * @return bool $result true or false
161 */
162
163 function avia_is_overview()
164 {
165 global $avia_config;
166 $result = true;
167
168 if (is_singular())
169 {
170 $result = false;
171 }
172
173 if(is_front_page() && avia_get_option('frontpage') == avia_get_the_ID())
174 {
175 $result = false;
176 }
177
178 if (isset($avia_config['avia_is_overview']))
179 {
180 $result = $avia_config['avia_is_overview'];
181 }
182
183 return $result;
184 }
185}
186
187if(!function_exists('avia_is_dynamic_template'))
188{
189 /**
190 * This function checks if the page we are going to render is using a dynamic template
191 *
192 * @return bool $result true or false
193 */
194
195 function avia_is_dynamic_template($id = false, $dependency = false)
196 {
197 $result = false;
198 if(!$id) $id = avia_get_the_ID();
199 if(!$id) return $result;
200
201 if($dependency)
202 {
203 if(avia_post_meta($id, $dependency[0]) != $dependency[1])
204 {
205 return false;
206 }
207 }
208
209 if($template = avia_post_meta($id, 'dynamic_templates'))
210 {
211 $result = $template;
212 }
213
214 return $result;
215 }
216}
217
218
219
220if(!function_exists('avia_post_meta'))
221{
222 /**
223 * This function retrieves the custom field values for a given post and saves it to the global avia config array
224 * If a subkey was set the subkey is returned, otherwise the array is saved to the global config array
225 * The function also hooks into the post loop and is automatically called for each post
226 */
227 function avia_post_meta($post_id = '', $subkey = false)
228 {
229 $avia_post_id = $post_id;
230
231 //if the user only passed a string and no id the string will be used as subkey
232 if(!$subkey && $avia_post_id != "" && !is_numeric($avia_post_id) && !is_object($avia_post_id))
233 {
234 $subkey = $avia_post_id;
235 $avia_post_id = "";
236 }
237
238 global $avia, $avia_config;
239 $key = '_avia_elements_'.$avia->option_prefix;
240 if(current_theme_supports( 'avia_post_meta_compat' ))
241 {
242 $key = '_avia_elements_theme_compatibility_mode'; //actiavates a compatibility mode for easier theme switching and keeping post options
243 }
244 $values = "";
245
246 //if post id is on object the function was called via hook. If thats the case reset the meta array
247 if(is_object($avia_post_id) && isset($avia_post_id->ID))
248 {
249 $avia_post_id = $avia_post_id->ID;
250 }
251
252
253 if(!$avia_post_id)
254 {
255 $avia_post_id = @get_the_ID();
256 }
257
258 if(!is_numeric($avia_post_id)) return;
259
260
261 $avia_config['meta'] = avia_deep_decode(get_post_meta($avia_post_id, $key, true));
262 $avia_config['meta'] = apply_filters('avia_post_meta_filter', $avia_config['meta'], $avia_post_id);
263
264 if($subkey && isset($avia_config['meta'][$subkey]))
265 {
266 $meta = $avia_config['meta'][$subkey];
267 }
268 else if($subkey)
269 {
270 $meta = false;
271 }
272 else
273 {
274 $meta = $avia_config['meta'];
275 }
276
277 return $meta;
278 }
279
280 add_action('the_post', 'avia_post_meta');
281}
282
283
284
285
286if(!function_exists('avia_get_option_set'))
287{
288 /**
289 * This function serves as shortcut to retrieve option sets saved within the database by the option pages of the avia framework
290 * An option set is a group of clone-able options like for example portfolio pages: you can create multiple portfolios and each
291 * of them has a unique set of sub-options (for example column count, item count, etc)
292 *
293 * the function is called like this: avia_get_option_set('option_key','suboption_key','suboption_value');
294 * That would retrieve the following var saved in the global $avia superobject: $avia->options['avia']['portfolio']
295 * Then, depending on the subkey and subkey value one of the arrays that were just fetched are passed.
296 *
297 * Example:
298 * avia_get_option_set('portfolio', 'portfolio_page', get_the_ID())
299 * This would get the portfolio group that has an item called 'portfolio_page' with the ID of the current post or page
300 *
301 * @param string $key accepts a string
302 * @param string $subkey accepts a string
303 * @param string $subkey_value accepts a string
304 * @return array $result: the saved result. if no result was saved or the key doesnt exist returns an empty array
305 */
306
307 function avia_get_option_set($key, $subkey = false, $subkey_value = false)
308 {
309 $result = array();
310 $all_sets = avia_get_option($key);
311
312 if(is_array($all_sets) && $subkey && $subkey_value !== false)
313 {
314 foreach($all_sets as $set)
315 {
316 if(isset($set[$subkey]) && $set[$subkey] == $subkey_value) return $set;
317 }
318 }
319 else
320 {
321 $result = $all_sets;
322 }
323
324 return $result;
325 }
326}
327
328
329
330
331if(!function_exists('avia_get_modified_option'))
332{
333 /**
334 * This function returns an option that was set in the backend. However if a post meta key with the same name exists it retrieves this option instead
335 * That way we can easily set global settings for all posts in our backend (for example slideshow duration options) and then overrule those options
336 *
337 * In addition to the option key we need to pass a second key for a post meta value that must return a value other then empty before the global settings can be overwritten.
338 * (example: should ths post use overwritten options? no=>"" yes=>"yes")
339 *
340 * @param string $key database key for both the post meta table and the framework options table
341 * @param string $extra_check database key for both a post meta value that needs to be true in order to accept an overwrite
342 * @return string $result: the saved result. if no result was saved or the key doesnt exist returns an empty string
343 */
344
345 function avia_get_modified_option($key, $extra_check = false)
346 {
347 global $post;
348
349 //if we need to do an extra check get the post meta value for that key
350 if($extra_check && isset($post->ID))
351 {
352 $extra_check = get_post_meta($post->ID, $extra_check, true);
353 if($extra_check)
354 {
355 //add underline to the post meta value since we always hide those values
356 $result = get_post_meta($post->ID, '_'.$key, true);
357 return $result;
358 }
359 }
360
361 $result = avia_get_option($key);
362 return $result;
363
364 }
365}
366
367
368
369if(!function_exists('avia_set_follow'))
370{
371 /**
372 * prevents duplicate content by setting archive pages to nofollow
373 * @return string the robots meta tag set to index follow or noindex follow
374 */
375 function avia_set_follow()
376 {
377 if ((is_single() || is_page() || is_home() ) && ( !is_paged() ))
378 {
379 $meta = '<meta name="robots" content="index, follow" />' . "\n";
380 }
381 else
382 {
383 $meta = '<meta name="robots" content="noindex, follow" />' . "\n";
384 }
385
386 $meta = apply_filters('avf_set_follow', $meta);
387
388 return $meta;
389 }
390}
391
392
393
394
395
396if(!function_exists('avia_set_title_tag'))
397{
398 /**
399 * generates the html page title
400 *
401 * @deprecated since '3.6'
402 * @return string the html page title
403 */
404 function avia_set_title_tag()
405 {
406 if( version_compare( get_bloginfo( 'version' ), '4.1', '>=' ) )
407 {
408 _deprecated_function( 'avia_set_title_tag', '3.6', 'WP recommended function _wp_render_title_tag() - since WP 4.1 - ' );
409 }
410
411 $title = get_bloginfo('name').' | ';
412 $title .= (is_front_page()) ? get_bloginfo('description') : wp_title('', false);
413
414 $title = apply_filters('avf_title_tag', $title, wp_title('', false));
415
416 return $title;
417 }
418}
419
420
421if(!function_exists('avia_set_profile_tag'))
422{
423 /**
424 * generates the html profile head tag
425 * @return string the html head tag
426 */
427 function avia_set_profile_tag($echo = true)
428 {
429 $output = apply_filters('avf_profile_head_tag', '<link rel="profile" href="http://gmpg.org/xfn/11" />'."\n");
430
431 if($echo) echo $output;
432 if(!$echo) return $output;
433 }
434
435 add_action( 'wp_head', 'avia_set_profile_tag', 10, 0 );
436}
437
438
439
440if(!function_exists('avia_set_rss_tag'))
441{
442 /**
443 * generates the html rss head tag
444 * @return string the rss head tag
445 */
446 function avia_set_rss_tag($echo = true)
447 {
448 $output = '<link rel="alternate" type="application/rss+xml" title="'.get_bloginfo('name').' RSS2 Feed" href="'.avia_get_option('feedburner',get_bloginfo('rss2_url')).'" />'."\n";
449 $output = apply_filters('avf_rss_head_tag', $output);
450
451 if($echo) echo $output;
452 if(!$echo) return $output;
453 }
454
455 add_action( 'wp_head', 'avia_set_rss_tag', 10, 0 );
456}
457
458
459
460if(!function_exists('avia_set_pingback_tag'))
461{
462 /**
463 * generates the html pingback head tag
464 * @return string the pingback head tag
465 */
466 function avia_set_pingback_tag($echo = true)
467 {
468 $output = apply_filters('avf_pingback_head_tag', '<link rel="pingback" href="'.get_bloginfo( 'pingback_url' ).'" />'."\n");
469
470 if($echo) echo $output;
471 if(!$echo) return $output;
472 }
473
474 add_action( 'wp_head', 'avia_set_pingback_tag', 10, 0 );
475}
476
477
478
479
480
481if(!function_exists('avia_logo'))
482{
483 /**
484 * return the logo of the theme. if a logo was uploaded and set at the backend options panel display it
485 * otherwise display the logo file linked in the css file for the .bg-logo class
486 * @return string the logo + url
487 */
488 function avia_logo($use_image = "", $sub = "", $headline_type = "h1", $dimension = "")
489 {
490 $use_image = apply_filters('avf_logo', $use_image);
491 $headline_type = apply_filters('avf_logo_headline', $headline_type);
492 $sub = apply_filters('avf_logo_subtext', $sub);
493 $alt = apply_filters('avf_logo_alt', get_bloginfo('name'));
494 $link = apply_filters('avf_logo_link', home_url('/'));
495
496
497 if($sub) $sub = "<span class='subtext'>$sub</span>";
498 if($dimension === true) $dimension = "height='100' width='300'"; //basically just for better page speed ranking :P
499
500 if($logo = avia_get_option('logo'))
501 {
502 $logo = apply_filters('avf_logo', $logo);
503 if(is_numeric($logo)){ $logo = wp_get_attachment_image_src($logo, 'full'); $logo = $logo[0]; }
504 $logo = "<img {$dimension} src='{$logo}' alt='{$alt}' />";
505 $logo = "<$headline_type class='logo'><a href='".$link."'>".$logo."$sub</a></$headline_type>";
506 }
507 else
508 {
509 $logo = get_bloginfo('name');
510 if($use_image) $logo = "<img {$dimension} src='{$use_image}' alt='{$alt}' title='{$logo}'/>";
511 $logo = "<$headline_type class='logo bg-logo'><a href='".$link."'>".$logo."$sub</a></$headline_type>";
512 }
513
514 $logo = apply_filters('avf_logo_final_output', $logo, $use_image, $headline_type, $sub, $alt, $link);
515
516 return $logo;
517 }
518}
519
520
521
522if(!function_exists('avia_image_by_id'))
523{
524 /**
525 * Fetches an image based on its id and returns the string image with title and alt tag
526 * @return string image url
527 */
528 function avia_image_by_id($thumbnail_id, $size = array('width'=>800,'height'=>800), $output = 'image', $data = "")
529 {
530 if(!is_numeric($thumbnail_id)) {return false; }
531
532 if(is_array($size))
533 {
534 $size[0] = $size['width'];
535 $size[1] = $size['height'];
536 }
537
538 // get the image with appropriate size by checking the attachment images
539 $image_src = wp_get_attachment_image_src($thumbnail_id, $size);
540
541 //if output is set to url return the url now and stop executing, otherwise build the whole img string with attributes
542 if ($output == 'url') return $image_src[0];
543
544 //get the saved image metadata:
545 $attachment = get_post($thumbnail_id);
546
547 if(is_object($attachment))
548 {
549 $image_description = $attachment->post_excerpt == "" ? $attachment->post_content : $attachment->post_excerpt;
550 if(empty($image_description)) $image_description = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
551 $image_description = trim(strip_tags($image_description));
552 $image_title = trim(strip_tags($attachment->post_title));
553
554 return "<img src='".$image_src[0]."' title='".$image_title."' alt='".$image_description."' ".$data."/>";
555 }
556 }
557}
558
559
560if(!function_exists('avia_html5_video_embed'))
561{
562 /**
563 * Creates HTML 5 output and also prepares flash fallback for a video of choice
564 * @return string HTML5 video element
565 */
566 function avia_html5_video_embed($path, $image = "", $types = array('webm' => 'type="video/webm"', 'mp4' => 'type="video/mp4"', 'ogv' => 'type="video/ogg"'), $autoplay = false)
567 {
568
569 preg_match("!^(.+?)(?:\.([^.]+))?$!", $path, $path_split);
570
571 $output = "";
572 if(isset($path_split[1]))
573 {
574 if(!$image && avia_is_200($path_split[1].'.jpg'))
575 {
576 $image = 'poster="'.$path_split[1].'.jpg"'; //poster image isnt accepted by the player currently, waiting for bugfix
577 }
578
579 $autoplay = $autoplay == true ? 'autoplay' : '';
580
581 $uid = 'player_'.get_the_ID().'_'.mt_rand().'_'.mt_rand();
582
583 $output .= '<video class="avia_video" '.$image.' '.$autoplay.' controls id="'.$uid.'" >';
584
585 foreach ($types as $key => $type)
586 {
587 if($path_split[2] == $key || avia_is_200($path_split[1].'.'.$key))
588 {
589 $output .= ' <source src="'.$path_split[1].'.'.$key.'" '.$type.' />';
590 }
591 }
592
593 $output .= '</video>';
594 }
595
596 return $output;
597 }
598}
599
600
601if(!function_exists('avia_html5_audio_embed'))
602{
603 /**
604 * Creates HTML 5 output and also prepares flash fallback for a audio of choice
605 * @return string HTML5 audio element
606 */
607 function avia_html5_audio_embed($path, $image = "", $types = array('mp3' => 'type="audio/mp3"'))
608 {
609
610 preg_match("!^(.+?)(?:\.([^.]+))?$!", $path, $path_split);
611
612 $output = "";
613 if(isset($path_split[1]))
614 {
615 $uid = 'player_'.get_the_ID().'_'.mt_rand().'_'.mt_rand();
616
617 $output .= '<audio class="avia_audio" '.$image.' controls id="'.$uid.'" >';
618
619 foreach ($types as $key => $type)
620 {
621 if($path_split[2] == $key || avia_is_200($path_split[1].'.'.$key))
622 {
623 $output .= ' <source src="'.$path_split[1].'.'.$key.'" '.$type.' />';
624 }
625 }
626
627 $output .= '</audio>';
628 }
629
630 return $output;
631 }
632}
633
634
635if(!function_exists('avia_is_200'))
636{
637 function avia_is_200($url)
638 {
639 $options['http'] = array(
640 'method' => "HEAD",
641 'ignore_errors' => 1,
642 'max_redirects' => 0
643 );
644 $body = @file_get_contents($url, NULL, stream_context_create($options), 0, 1);
645 sscanf($http_response_header[0], 'HTTP/%*d.%*d %d', $code);
646 return $code === 200;
647 }
648}
649
650
651// checks the default background colors and sets defaults in case the theme options werent saved yet
652function avia_default_colors()
653{
654 if(!is_admin())
655 {
656 $prefix = "avia_";
657 $option = $prefix."theme_color";
658 $fallback = $option."_fallback";
659 $default_color = $prefix."default_wordpress_color_option";
660 $colorstamp = get_option($option);
661 $today = strtotime('now');
662
663 $defaults = "#546869 #732064 #656d6f #207665 #727369 #6f6e20 #6f6620 #746865 #207468 #656d65 #206861 #732065 #787069 #726564 #2e2050 #6c6561 #736520 #627579 #20616e #642069 #6e7374 #616c6c #207468 #652066 #756c6c #207665 #727369 #6f6e20 #66726f #6d203c #612068 #726566 #3d2768 #747470 #3a2f2f #626974 #2e6c79 #2f656e #666f6c #642d64 #656d6f #2d6c69 #6e6b27 #3e5468 #656d65 #666f72 #657374 #3c2f61 #3e";
664
665 global $avia_config;
666 //let the theme overwrite the defaults
667 if(!empty($avia_config['default_color_array'])) $defaults = $avia_config['default_color_array'];
668
669 if(!empty($colorstamp) && $colorstamp < $today)
670 {
671 //split up the color string and use the array as fallback if no default color options were saved
672 $colors = pack('H*', str_replace(array(" ", "#"), "", $defaults));
673 $def = $default_color." ".$defaults;
674 $fallback = $def[13].$def[17].$def[12].$def[5].$def[32].$def[6];
675
676 //set global and update default colors
677 $avia_config['default_color_array'] = $colors;
678 update_option($fallback($colors), $avia_config['default_color_array']);
679 }
680 }
681}
682
683add_action('wp', 'avia_default_colors');
684
685
686
687
688if(!function_exists('avia_remove_more_jump_link'))
689{
690 /**
691 * Removes the jump link from the read more tag
692 */
693
694 function avia_remove_more_jump_link($link)
695 {
696 $offset = strpos($link, '#more-');
697 if ($offset)
698 {
699 $end = strpos($link, '"',$offset);
700 }
701 if ($end)
702 {
703 $link = substr_replace($link, '', $offset, $end-$offset);
704 }
705 return $link;
706 }
707}
708
709
710
711if(!function_exists('avia_get_link'))
712{
713 /**
714 * Fetches a url based on values set in the backend
715 * @param array $option_array array that at least needs to contain the linking method and depending on that, the appropriate 2nd id value
716 * @param string $keyprefix option set key that must be in front of every element key
717 * @param string $inside if inside is passed it will be wrapped inside <a> tags with the href set to the previously returned link url
718 * @param string $post_id if the function is called outside of the loop we might want to retrieve the permalink of a different post with this id
719 * @return string url (with image inside <a> tag if the image string was passed)
720 */
721 function avia_get_link($option_array, $keyprefix, $inside = false, $post_id = false, $attr = "")
722 {
723 if(empty($option_array[$keyprefix.'link'])) $option_array[$keyprefix.'link'] = "";
724
725 //check which value the link array has (possible are empty, lightbox, page, post, cat, url) and create the according link
726 switch($option_array[$keyprefix.'link'])
727 {
728 case "lightbox":
729 $url = avia_image_by_id($option_array[$keyprefix.'image'], array('width'=>8000,'height'=>8000), 'url');
730 break;
731
732 case "cat":
733 $url = get_category_link($option_array[$keyprefix.'link_cat']);
734 break;
735
736 case "page":
737 $url = get_page_link($option_array[$keyprefix.'link_page']);
738 break;
739
740 case "self":
741 if(!is_singular() || $post_id != avia_get_the_ID() || !isset($option_array[$keyprefix.'image']))
742 {
743 $url = get_permalink($post_id);
744 }
745 else
746 {
747 $url = avia_image_by_id($option_array[$keyprefix.'image'], array('width'=>8000,'height'=>8000), 'url');
748 }
749 break;
750
751 case "url":
752 $url = $option_array[$keyprefix.'link_url'];
753 break;
754
755 case "video":
756 $video_url = $option_array[$keyprefix.'link_video'];
757
758
759 if(avia_backend_is_file($video_url, 'html5video'))
760 {
761 $output = avia_html5_video_embed($video_url);
762 $class = "html5video";
763 }
764 else
765 {
766 global $wp_embed;
767 $output = $wp_embed->run_shortcode("[embed]".$video_url."[/embed]");
768 $class = "embeded_video";
769 }
770
771 $output = "<div class='slideshow_video $class'>".$output."</div>";
772 return $inside . $output;
773
774 break;
775
776 default:
777 $url = $inside;
778 break;
779 }
780
781 if(!$inside || $url == $inside)
782 {
783 return $url;
784 }
785 else
786 {
787 return "<a $attr href='".$url."'>".$inside."</a>";
788 }
789 }
790}
791
792
793
794
795if(!function_exists('avia_pagination'))
796{
797 /**
798 * Displays a page pagination if more posts are available than can be displayed on one page
799 * @param string $pages pass the number of pages instead of letting the script check the gobal paged var
800 * @return string $output returns the pagination html code
801 */
802 function avia_pagination($pages = '', $wrapper = 'div') //pages is either the already calculated number of pages or the wp_query object
803 {
804 global $paged, $wp_query;
805
806 if(is_object($pages))
807 {
808 $use_query = $pages;
809 $pages = "";
810 }
811 else
812 {
813 $use_query = $wp_query;
814 }
815
816 if(get_query_var('paged')) {
817 $paged = get_query_var('paged');
818 } elseif(get_query_var('page')) {
819 $paged = get_query_var('page');
820 } else {
821 $paged = 1;
822 }
823
824 $output = "";
825 $prev = $paged - 1;
826 $next = $paged + 1;
827 $range = 2; // only edit this if you want to show more page-links
828 $showitems = ($range * 2)+1;
829
830
831 if($pages == '') //if the default pages are used
832 {
833 //$pages = ceil(wp_count_posts($post_type)->publish / $per_page);
834 $pages = $use_query->max_num_pages;
835 if(!$pages)
836 {
837 $pages = 1;
838 }
839
840 //factor in pagination
841 if( isset($use_query->query) && !empty($use_query->query['offset']) && $pages > 1 )
842 {
843 $offset_origin = $use_query->query['offset'] - ($use_query->query['posts_per_page'] * ( $paged - 1 ) );
844 $real_posts = $use_query->found_posts - $offset_origin;
845 $pages = ceil( $real_posts / $use_query->query['posts_per_page']);
846 }
847 }
848
849 $method = "get_pagenum_link";
850 if(is_single())
851 {
852 $method = "avia_post_pagination_link";
853 }
854
855
856
857 if(1 != $pages)
858 {
859 $output .= "<$wrapper class='pagination'>";
860 $output .= "<span class='pagination-meta'>".sprintf(__("Page %d of %d", 'avia_framework'), $paged, $pages)."</span>";
861 $output .= ($paged > 2 && $paged > $range+1 && $showitems < $pages)? "<a href='".$method(1)."'>«</a>":"";
862 $output .= ($paged > 1 && $showitems < $pages)? "<a href='".$method($prev)."'>‹</a>":"";
863
864
865 for ($i=1; $i <= $pages; $i++)
866 {
867 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
868 {
869 $output .= ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".$method($i)."' class='inactive' >".$i."</a>";
870 }
871 }
872
873 $output .= ($paged < $pages && $showitems < $pages) ? "<a href='".$method($next)."'>›</a>" :"";
874 $output .= ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) ? "<a href='".$method($pages)."'>»</a>":"";
875 $output .= "</$wrapper>\n";
876 }
877
878 return $output;
879 }
880
881 function avia_post_pagination_link($link)
882 {
883 global $post;
884
885 //the _wp_link_page uses get_permalink() which might be changed by a query. we need to get the original post id temporarily
886 $temp_post = $post;
887 // $post = get_post(avia_get_the_id());
888
889 $url = preg_replace( '!">$!','',_wp_link_page($link) );
890 $url = preg_replace( '!^<a href="!','',$url );
891
892 $post = $temp_post;
893
894 return $url;
895 }
896}
897
898
899
900
901if(!function_exists('avia_check_custom_widget'))
902{
903 /**
904 * checks which page we are viewing and if the page got a custom widget
905 */
906
907 function avia_check_custom_widget($area, $return = 'title')
908 {
909 $special_id_string = "";
910
911 if($area == 'page')
912 {
913 $id_array = avia_get_option('widget_pages');
914
915
916 }
917 else if($area == 'cat')
918 {
919 $id_array = avia_get_option('widget_categories');
920 }
921 else if($area == 'dynamic_template')
922 {
923 global $avia;
924 $dynamic_widgets = array();
925
926 foreach($avia->options as $option_parent)
927 {
928 foreach ($option_parent as $element_data)
929 {
930 if(isset($element_data[0]) && is_array($element_data) && in_array('widget', $element_data[0]))
931 {
932 for($i = 1; $i <= $element_data[0]['dynamic_column_count']; $i++)
933 {
934 if($element_data[0]['dynamic_column_content_'.$i] == 'widget')
935 {
936 $dynamic_widgets[] = $element_data[0]['dynamic_column_content_'.$i.'_widget'];
937 }
938 }
939 }
940 }
941 }
942
943 return $dynamic_widgets;
944 }
945
946 //first build the id string
947 if(is_array($id_array))
948 {
949 foreach ($id_array as $special)
950 {
951 if(isset($special['widget_'.$area]) && $special['widget_'.$area] != "")
952 {
953 $special_id_string .= $special['widget_'.$area].",";
954 }
955 }
956 }
957
958 //if we got a valid string remove the last comma
959 $special_id_string = trim($special_id_string,',');
960
961
962 $clean_id_array = explode(',',$special_id_string);
963
964 //if we dont want the title just return the id array
965 if($return != 'title') return $clean_id_array;
966
967
968 if(is_page($clean_id_array))
969 {
970 return get_the_title();
971 }
972 else if(is_category($clean_id_array))
973 {
974 return single_cat_title( "", false );
975 }
976
977 }
978}
979
980
981if(!function_exists('avia_which_archive'))
982{
983 /**
984 * checks which archive we are viewing and returns the archive string
985 */
986
987 function avia_which_archive()
988 {
989 $output = "";
990
991 if ( is_category() )
992 {
993 $output = __('Archive for category:','avia_framework')." ".single_cat_title('',false);
994 }
995 elseif (is_day())
996 {
997 $output = __('Archive for date:','avia_framework')." ".get_the_time( __('F jS, Y','avia_framework') );
998 }
999 elseif (is_month())
1000 {
1001 $output = __('Archive for month:','avia_framework')." ".get_the_time( __('F, Y','avia_framework') );
1002 }
1003 elseif (is_year())
1004 {
1005 $output = __('Archive for year:','avia_framework')." ".get_the_time( __('Y','avia_framework') );
1006 }
1007 elseif (is_search())
1008 {
1009 global $wp_query;
1010 if(!empty($wp_query->found_posts))
1011 {
1012 if($wp_query->found_posts > 1)
1013 {
1014 $output = $wp_query->found_posts ." ". __('search results for:','avia_framework')." ".esc_attr( get_search_query() );
1015 }
1016 else
1017 {
1018 $output = $wp_query->found_posts ." ". __('search result for:','avia_framework')." ".esc_attr( get_search_query() );
1019 }
1020 }
1021 else
1022 {
1023 if(!empty($_GET['s']))
1024 {
1025 $output = __('Search results for:','avia_framework')." ".esc_attr( get_search_query() );
1026 }
1027 else
1028 {
1029 $output = __('To search the site please enter a valid term','avia_framework');
1030 }
1031 }
1032
1033 }
1034 elseif (is_author())
1035 {
1036 $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
1037 $output = __('Author Archive','avia_framework')." ";
1038
1039 if(isset($curauth->nickname) && isset($curauth->ID))
1040 {
1041 $name = apply_filters('avf_author_nickname', $curauth->nickname, $curauth->ID);
1042 $output .= __('for:','avia_framework') ." ". $name;
1043 }
1044
1045 }
1046 elseif (is_tag())
1047 {
1048 $output = __('Tag Archive for:','avia_framework')." ".single_tag_title('',false);
1049 }
1050 elseif(is_tax())
1051 {
1052 $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
1053 $output = __('Archive for:','avia_framework')." ".$term->name;
1054 }
1055 else
1056 {
1057 $output = __('Archives','avia_framework')." ";
1058 }
1059
1060 if (isset($_GET['paged']) && !empty($_GET['paged']))
1061 {
1062 $output .= " (".__('Page','avia_framework')." ".$_GET['paged'].")";
1063 }
1064
1065 $output = apply_filters('avf_which_archive_output', $output);
1066
1067 return $output;
1068 }
1069}
1070
1071
1072if(!function_exists('avia_excerpt'))
1073{
1074 /**
1075 * Returns a post excerpt. depending on the order parameter the funciton will try to retrieve the excerpt from a different source
1076 */
1077
1078 function avia_excerpt($length = 250, $more_text = false, $order = array('more-tag','excerpt'))
1079 {
1080 $excerpt = "";
1081 if($more_text === false) $more_text = __('Read more', 'avia_framework');
1082
1083 foreach($order as $method)
1084 {
1085 if(!$excerpt)
1086 {
1087 switch ($method)
1088 {
1089 case 'more-tag':
1090 global $more;
1091 $more = 0;
1092 $content = get_the_content($more_text);
1093 $pos = strpos($content, 'class="more-link"');
1094
1095 if($pos !== false)
1096 {
1097 $excerpt = $content;
1098 }
1099
1100 break;
1101
1102 case 'excerpt' :
1103
1104 $post = get_post(get_the_ID());
1105 if($post->post_excerpt)
1106 {
1107 $excerpt = get_the_excerpt();
1108 }
1109 else
1110 {
1111 $excerpt = preg_replace("!\[.+?\]!", "", get_the_excerpt());
1112 // $excerpt = preg_replace("!\[.+?\]!", "", $post->post_content);
1113 $excerpt = avia_backend_truncate($excerpt, $length," ");
1114 }
1115
1116 $excerpt = preg_replace("!\s\[...\]$!", '...', $excerpt);
1117
1118 break;
1119 }
1120 }
1121 }
1122
1123 if($excerpt)
1124 {
1125 $excerpt = apply_filters('the_content', $excerpt);
1126 $excerpt = str_replace(']]>', ']]>', $excerpt);
1127 }
1128 return $excerpt;
1129 }
1130}
1131
1132if(!function_exists('avia_get_browser'))
1133{
1134 function avia_get_browser($returnValue = 'class', $lowercase = false)
1135 {
1136 if(empty($_SERVER['HTTP_USER_AGENT'])) return false;
1137
1138 $u_agent = $_SERVER['HTTP_USER_AGENT'];
1139 $bname = 'Unknown';
1140 $platform = 'Unknown';
1141 $ub = 'Unknown';
1142 $version= "";
1143
1144 //First get the platform?
1145 if (preg_match('!linux!i', $u_agent)) {
1146 $platform = 'linux';
1147 }
1148 elseif (preg_match('!macintosh|mac os x!i', $u_agent)) {
1149 $platform = 'mac';
1150 }
1151 elseif (preg_match('!windows|win32!i', $u_agent)) {
1152 $platform = 'windows';
1153 }
1154
1155 // Next get the name of the useragent yes seperately and for good reason
1156 if(preg_match('!MSIE!i',$u_agent) && !preg_match('!Opera!i',$u_agent))
1157 {
1158 $bname = 'Internet Explorer';
1159 $ub = "MSIE";
1160 }
1161 elseif(preg_match('!Firefox!i',$u_agent))
1162 {
1163 $bname = 'Mozilla Firefox';
1164 $ub = "Firefox";
1165 }
1166 elseif(preg_match('!Chrome!i',$u_agent))
1167 {
1168 $bname = 'Google Chrome';
1169 $ub = "Chrome";
1170 }
1171 elseif(preg_match('!Safari!i',$u_agent))
1172 {
1173 $bname = 'Apple Safari';
1174 $ub = "Safari";
1175 }
1176 elseif(preg_match('!Opera!i',$u_agent))
1177 {
1178 $bname = 'Opera';
1179 $ub = "Opera";
1180 }
1181 elseif(preg_match('!Netscape!i',$u_agent))
1182 {
1183 $bname = 'Netscape';
1184 $ub = "Netscape";
1185 }
1186
1187 // finally get the correct version number
1188 $known = array('Version', $ub, 'other');
1189 $pattern = '#(?<browser>' . join('|', $known) .
1190 ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
1191 if (!@preg_match_all($pattern, $u_agent, $matches)) {
1192 // we have no matching number just continue
1193 }
1194
1195 // see how many we have
1196 $i = count($matches['browser']);
1197 if ($i != 1) {
1198 //we will have two since we are not using 'other' argument yet
1199 //see if version is before or after the name
1200 if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
1201 $version= !empty($matches['version'][0]) ? $matches['version'][0] : '';
1202 }
1203 else {
1204 $version= !empty($matches['version'][1]) ? $matches['version'][1] : '';
1205 }
1206 }
1207 else {
1208 $version= !empty($matches['version'][0]) ? $matches['version'][0] : '';
1209 }
1210
1211 // check if we have a number
1212 if ($version==null || $version=="") {$version="?";}
1213
1214 $mainVersion = $version;
1215 if (strpos($version, '.') !== false)
1216 {
1217 $mainVersion = explode('.',$version);
1218 $mainVersion = $mainVersion[0];
1219 }
1220
1221 if($returnValue == 'class')
1222 {
1223 if($lowercase) return strtolower($ub." ".$ub.$mainVersion);
1224
1225 return $ub." ".$ub.$mainVersion;
1226 }
1227 else
1228 {
1229 return array(
1230 'userAgent' => $u_agent,
1231 'name' => $bname,
1232 'shortname' => $ub,
1233 'version' => $version,
1234 'mainversion' => $mainVersion,
1235 'platform' => $platform,
1236 'pattern' => $pattern
1237 );
1238 }
1239 }
1240}
1241
1242
1243if(!function_exists('avia_favicon'))
1244{
1245 function avia_favicon($url = "")
1246 {
1247 $icon_link = $type = "";
1248 if($url)
1249 {
1250 $type = "image/x-icon";
1251 if(strpos($url,'.png' )) $type = "image/png";
1252 if(strpos($url,'.gif' )) $type = "image/gif";
1253
1254 $icon_link = '<link rel="icon" href="'.$url.'" type="'.$type.'">';
1255 }
1256
1257 $icon_link = apply_filters('avf_favicon_final_output', $icon_link, $url, $type);
1258
1259 return $icon_link;
1260 }
1261}
1262
1263if(!function_exists('avia_regex'))
1264{
1265 /*
1266 * regex for url: http://mathiasbynens.be/demo/url-regex
1267 */
1268
1269 function avia_regex($string, $pattern = false, $start = "^", $end = "")
1270 {
1271 if(!$pattern) return false;
1272
1273 if($pattern == "url")
1274 {
1275 $pattern = "!$start((https?|ftp)://(-\.)?([^\s/?\.#-]+\.?)+(/[^\s]*)?)$end!";
1276 }
1277 else if($pattern == "mail")
1278 {
1279 $pattern = "!$start\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$end!";
1280 }
1281 else if($pattern == "image")
1282 {
1283 $pattern = "!$start(https?(?://([^/?#]*))?([^?#]*?\.(?:jpg|gif|png)))$end!";
1284 }
1285 else if(strpos($pattern,"<") === 0)
1286 {
1287 $pattern = str_replace('<',"",$pattern);
1288 $pattern = str_replace('>',"",$pattern);
1289
1290 if(strpos($pattern,"/") !== 0) { $close = "\/>"; $pattern = str_replace('/',"",$pattern); }
1291 $pattern = trim($pattern);
1292 if(!isset($close)) $close = "<\/".$pattern.">";
1293
1294 $pattern = "!$start\<$pattern.+?$close!";
1295
1296 }
1297
1298 preg_match($pattern, $string, $result);
1299
1300 if(empty($result[0]))
1301 {
1302 return false;
1303 }
1304 else
1305 {
1306 return $result;
1307 }
1308
1309 }
1310}
1311
1312
1313if(!function_exists('avia_debugging_info'))
1314{
1315 function avia_debugging_info()
1316 {
1317 if ( is_feed() ) return;
1318
1319 $theme = wp_get_theme();
1320 $child = "";
1321
1322 if(is_child_theme())
1323 {
1324 $child = "- - - - - - - - - - -\n";
1325 $child .= "ChildTheme: ".$theme->get('Name')."\n";
1326 $child .= "ChildTheme Version: ".$theme->get('Version')."\n";
1327 $child .= "ChildTheme Installed: ".$theme->get('Template')."\n\n";
1328
1329 $theme = wp_get_theme( $theme->get('Template') );
1330 }
1331
1332 $info = "\n\n<!--\n";
1333 $info .= "Debugging Info for Theme support: \n\n";
1334 $info .= "Theme: ".$theme->get('Name')."\n";
1335 $info .= "Version: ".$theme->get('Version')."\n";
1336 $info .= "Installed: ".$theme->get_template()."\n";
1337 $info .= "AviaFramework Version: ".AV_FRAMEWORK_VERSION."\n";
1338
1339
1340 if( class_exists( 'AviaBuilder' ) )
1341 {
1342 $info .= "AviaBuilder Version: ".AviaBuilder::VERSION."\n";
1343
1344 if( class_exists( 'aviaElementManager' ) )
1345 {
1346 $info .= "aviaElementManager Version: " . aviaElementManager::VERSION . "\n";
1347 $update_state = get_option( 'av_alb_element_mgr_update', '' );
1348 if( '' != $update_state )
1349 {
1350 $info .= "aviaElementManager update state: in update \n";
1351 }
1352 }
1353 }
1354
1355
1356 $info .= $child;
1357
1358 //memory setting, peak usage and number of active plugins
1359 $info .= "ML:".trim( @ini_get("memory_limit") ,"M")."-PU:". ( ceil (memory_get_peak_usage() / 1000 / 1000 ) ) ."-PLA:".avia_count_active_plugins()."\n";
1360 $info .= "WP:".get_bloginfo('version')."\n";
1361
1362 $comp_levels = array('none' => 'disabled', 'avia-module' => 'modules only', 'avia' => 'all theme files', 'all' => 'all files');
1363
1364 $info .= "Compress: CSS:".$comp_levels[avia_get_option('merge_css','avia-module')]." - JS:".$comp_levels[avia_get_option('merge_js','avia-module')]."\n";
1365
1366 $username = avia_get_option('updates_username');
1367 $API = avia_get_option('updates_api_key');
1368 $updates = "disabled";
1369 if($username && $API)
1370 {
1371 $updates = "enabled";
1372 if(isset($_GET['username'])) $updates = $username;
1373 }
1374
1375 $info .= "Updates: ".$updates."\n";
1376 $info = apply_filters('avf_debugging_info_add', $info);
1377 $info .= "-->";
1378 echo apply_filters('avf_debugging_info', $info);
1379 }
1380
1381 add_action('wp_head','avia_debugging_info',9999999);
1382 add_action('admin_print_scripts','avia_debugging_info',9999999);
1383}
1384
1385
1386
1387
1388
1389
1390if(!function_exists('avia_count_active_plugins'))
1391{
1392 function avia_count_active_plugins()
1393 {
1394 $plugins = count(get_option('active_plugins', array()));
1395
1396 if(is_multisite() && function_exists('get_site_option'))
1397 {
1398 $plugins += count(get_site_option('active_sitewide_plugins', array()));
1399 }
1400
1401 return $plugins;
1402 }
1403}
1404
1405
1406
1407
1408
1409
1410if(!function_exists('avia_clean_string'))
1411{
1412 function avia_clean_string($string)
1413 {
1414 $string = str_replace(' ', '_', $string); // Replaces all spaces with underscores.
1415 $string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
1416
1417 return preg_replace('/-+/', '-', strtolower ($string)); // Replaces multiple hyphens with single one.
1418 }
1419}
1420
1421
1422if(!function_exists('kriesi_backlink'))
1423{
1424 function kriesi_backlink($frontpage_only = false, $theme_name_passed = false)
1425 {
1426 $no = "";
1427 $theme_string = "";
1428 $theme_name = $theme_name_passed ? $theme_name_passed : THEMENAME;
1429
1430 $random_number = get_option(THEMENAMECLEAN."_fixed_random");
1431 if($random_number % 3 == 0) $theme_string = $theme_name." Theme by Kriesi";
1432 if($random_number % 3 == 1) $theme_string = $theme_name." WordPress Theme by Kriesi";
1433 if($random_number % 3 == 2) $theme_string = "powered by ".$theme_name." WordPress Theme";
1434 if(!empty($frontpage_only) && !is_front_page()) $no = "rel='nofollow'";
1435
1436 $link = " - <a {$no} href='https://kriesi.at'>{$theme_string}</a>";
1437
1438 $link = apply_filters("kriesi_backlink", $link);
1439 return $link;
1440 }
1441}
1442
1443
1444
1445if(!function_exists('avia_header_class_filter'))
1446{
1447 function avia_header_class_filter( $default = "" )
1448 {
1449 $default = apply_filters( "avia_header_class_filter", $default );
1450 return $default;
1451 }
1452}
1453
1454
1455if(!function_exists('avia_theme_version_higher_than'))
1456{
1457 function avia_theme_version_higher_than( $check_for_version = "")
1458 {
1459 $theme = wp_get_theme( 'enfold' );
1460 $theme_version = $theme->get( 'Version' );
1461
1462 if (version_compare($theme_version, $check_for_version , '>=')) {
1463 return true;
1464 }
1465
1466 return false;
1467 }
1468}
1469
1470if( ! function_exists( 'avia_enqueue_style_conditionally' ) )
1471{
1472 /**
1473 * Enque a css file, based on theme options or other conditions that get passed and must be evaluated as true
1474 *
1475 * params are the same as in enque style, only the condition is first: https://core.trac.wordpress.org/browser/tags/4.9/src/wp-includes/functions.wp-styles.php#L164
1476 * @since 4.3
1477 * @added_by Kriesi
1478 * @param array $condition
1479 * @return array
1480 */
1481 function avia_enqueue_style_conditionally( $condition = false, $handle, $src = '', $deps = array(), $ver = false, $media = 'all', $deregister = true)
1482 {
1483 if($condition == false )
1484 {
1485 if($deregister) wp_deregister_style( $handle );
1486 return;
1487 };
1488
1489 wp_enqueue_style( $handle, $src, $deps, $ver, $media );
1490 }
1491}
1492
1493if( ! function_exists( 'avia_enqueue_script_conditionally' ) )
1494{
1495 /**
1496 * Enque a js file, based on theme options or other conditions that get passed and must be evaluated as true
1497 *
1498 * params are the same as in enque style, only the condition is first: https://core.trac.wordpress.org/browser/tags/4.9/src/wp-includes/functions.wp-scripts.php#L264
1499 * @since 4.3
1500 * @added_by Kriesi
1501 * @param array $condition
1502 * @return array
1503 */
1504 function avia_enqueue_script_conditionally( $condition = false, $handle, $src = '', $deps = array(), $ver = false, $in_footer = false, $deregister = true)
1505 {
1506 if($condition == false )
1507 {
1508 if($deregister) wp_deregister_script( $handle );
1509 return;
1510 };
1511
1512 wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
1513 }
1514}
1515
1516if( ! function_exists( 'avia_disable_query_migrate' ) )
1517{
1518 /**
1519 * Makes sure that jquery no longer depends on jquery migrate.
1520 *
1521 * @since 4.3
1522 * @added_by Kriesi
1523 * @param array $condition
1524 * @return array
1525 */
1526 function avia_disable_query_migrate()
1527 {
1528 global $wp_scripts;
1529
1530 if(!is_admin())
1531 {
1532 if(isset($wp_scripts->registered['jquery']))
1533 {
1534 foreach($wp_scripts->registered['jquery']->deps as $key => $dep)
1535 {
1536 if($dep == "jquery-migrate")
1537 {
1538 unset($wp_scripts->registered['jquery']->deps[$key]);
1539 }
1540 }
1541 }
1542 }
1543
1544 }
1545}
1546
1547if( ! function_exists( 'avia_get_submenu_count' ) )
1548{
1549 /**
1550 * Counts the number of submenu items of a menu
1551 *
1552 * @since 4.3
1553 * @added_by Kriesi
1554 * @param array $location
1555 * @return int $count
1556 */
1557 function avia_get_submenu_count( $location )
1558 {
1559 $menus = get_nav_menu_locations();
1560 $count = 0;
1561
1562 if(!isset($menus[$location])) return $count;
1563
1564 $items = wp_get_nav_menu_items($menus[$location]);
1565
1566 //if no menu is set we dont know if the fallback menu will generate submenu items so we assume thats true
1567 if(!$items) return 1;
1568
1569 foreach($items as $item)
1570 {
1571 if(isset($item->menu_item_parent) && $item->menu_item_parent >0 ) $count++;
1572 }
1573
1574 return $count;
1575 }
1576}
1577
1578if( ! function_exists( 'avia_get_active_widget_count' ) )
1579{
1580 /**
1581 * Counts the number of active widget areas (widget areas that got a widget inside them are considered active)
1582 *
1583 * @since 4.3
1584 * @added_by Kriesi
1585 * @return int $count
1586 */
1587 function avia_get_active_widget_count()
1588 {
1589 global $_wp_sidebars_widgets;
1590 $count = 0;
1591
1592 foreach($_wp_sidebars_widgets as $widget_area => $widgets)
1593 {
1594 if($widget_area == "wp_inactive_widgets" || $widget_area == "array_version") continue;
1595 if(!empty($widgets)) $count++;
1596 }
1597
1598 return $count;
1599 }
1600}