} } else { if(!empty($_GET['s'])) { $output = __('Search results for:','avia_framework').' '.esc_attr( get_search_query() ); } else { $output = __('To search the site please enter a valid term','avia_framework'); } } } elseif (is_author()) { $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); $output = __('Author Archive','avia_framework').' '; if(isset($curauth->nickname) && isset($curauth->ID)) { $name = apply_filters('avf_author_nickname', $curauth->nickname, $curauth->ID); $output .= __('for:','avia_framework') .' '. $name; } } elseif (is_tag()) { $output = __('Tag Archive for:','avia_framework').' '.single_tag_title('',false); } elseif(is_tax()) { $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $output = __('Archive for:','avia_framework').' '.$term->name; } else { $output = __('Archives','avia_framework').' '; } if( isset( $_GET['paged'] ) && ! empty( $_GET['paged'] ) ) { // avoid xss vulnerability - e.g. injection of code $output .= is_numeric( $_GET['paged'] ) ? ' (' . __( 'Page', 'avia_framework' ) . ' ' . $_GET['paged'] . ')' : ''; } $output = apply_filters( 'avf_which_archive_output', $output ); return $output; } } if(!function_exists('avia_excerpt')) { /** * Returns a post excerpt. depending on the order parameter the funciton will try to retrieve the excerpt from a different source */ function avia_excerpt($length = 250, $more_text = false, $order = array('more-tag','excerpt')) { $excerpt = ''; if($more_text === false) $more_text = __('Read more', 'avia_framework'); foreach($order as $method) { if(!$excerpt) { switch ($method) { case 'more-tag': global $more; $more = 0; $content = get_the_content($more_text); $pos = strpos($content, 'class="more-link"'); if($pos !== false) { $excerpt = $content; } break; case 'excerpt' : $post = get_post(get_the_ID()); if($post->post_excerpt) { $excerpt = get_the_excerpt(); } else { $excerpt = preg_replace( "!\[.+?\]!", '', get_the_excerpt() ); // $excerpt = preg_replace("!\[.+?\]!", '', $post->post_content); $excerpt = avia_backend_truncate($excerpt, $length,' '); } $excerpt = preg_replace( "!\s\[...\]$!", '...', $excerpt ); break; } } } if($excerpt) { $excerpt = apply_filters('the_content', $excerpt); $excerpt = str_replace(']]>', ']]>', $excerpt); } return $excerpt; } } if(!function_exists('avia_get_browser')) { function avia_get_browser($returnValue = 'class', $lowercase = false) { if(empty($_SERVER['HTTP_USER_AGENT'])) return false; $u_agent = $_SERVER['HTTP_USER_AGENT']; $bname = 'Unknown'; $platform = 'Unknown'; $ub = 'Unknown'; $version= ''; //First get the platform? if (preg_match('!linux!i', $u_agent)) { $platform = 'linux'; } elseif (preg_match('!macintosh|mac os x!i', $u_agent)) { $platform = 'mac'; } elseif (preg_match('!windows|win32!i', $u_agent)) { $platform = 'windows'; } // Next get the name of the useragent yes seperately and for good reason if(preg_match('!MSIE!i',$u_agent) && !preg_match('!Opera!i',$u_agent)) { $bname = 'Internet Explorer'; $ub = 'MSIE'; } elseif(preg_match('!Firefox!i',$u_agent)) { $bname = 'Mozilla Firefox'; $ub = 'Firefox'; } elseif(preg_match('!Chrome!i',$u_agent)) { $bname = 'Google Chrome'; $ub = 'Chrome'; } elseif(preg_match('!Safari!i',$u_agent)) { $bname = 'Apple Safari'; $ub = 'Safari'; } elseif(preg_match('!Opera!i',$u_agent)) { $bname = 'Opera'; $ub = 'Opera'; } elseif(preg_match('!Netscape!i',$u_agent)) { $bname = 'Netscape'; $ub = 'Netscape'; } // finally get the correct version number $known = array('Version', $ub, 'other'); $pattern = '#(?' . join('|', $known) . ')[/ ]+(?[0-9.|a-zA-Z.]*)#'; if (!@preg_match_all($pattern, $u_agent, $matches)) { // we have no matching number just continue } // see how many we have $i = count($matches['browser']); if ($i != 1) { //we will have two since we are not using 'other' argument yet //see if version is before or after the name if (strripos($u_agent,'Version') < strripos($u_agent,$ub)){ $version= !empty($matches['version'][0]) ? $matches['version'][0] : ''; } else { $version= !empty($matches['version'][1]) ? $matches['version'][1] : ''; } } else { $version= !empty($matches['version'][0]) ? $matches['version'][0] : ''; } // check if we have a number if ($version==null || $version=='') {$version='?';} $mainVersion = $version; if (strpos($version, '.') !== false) { $mainVersion = explode('.',$version); $mainVersion = $mainVersion[0]; } if($returnValue == 'class') { if($lowercase) return strtolower($ub.' '.$ub.$mainVersion); return $ub.' '.$ub.$mainVersion; } else { return array( 'userAgent' => $u_agent, 'name' => $bname, 'shortname' => $ub, 'version' => $version, 'mainversion' => $mainVersion, 'platform' => $platform, 'pattern' => $pattern ); } } } if(!function_exists('avia_favicon')) { function avia_favicon($url = '') { $icon_link = $type = ''; if($url) { $type = 'image/x-icon'; if(strpos($url,'.png' )) $type = 'image/png'; if(strpos($url,'.gif' )) $type = 'image/gif'; $icon_link = ''; } $icon_link = apply_filters('avf_favicon_final_output', $icon_link, $url, $type); return $icon_link; } } if(!function_exists('avia_regex')) { /* * regex for url: http://mathiasbynens.be/demo/url-regex */ function avia_regex($string, $pattern = false, $start = '^', $end = '') { if(!$pattern) return false; if($pattern == 'url') { $pattern = "!$start((https?|ftp)://(-\.)?([^\s/?\.#-]+\.?)+(/[^\s]*)?)$end!"; } else if($pattern == 'mail') { $pattern = "!$start\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$end!"; } else if($pattern == 'image') { $pattern = "!$start(https?(?://([^/?#]*))?([^?#]*?\.(?:jpg|gif|png)))$end!"; } else if(strpos($pattern,'<') === 0) { $pattern = str_replace('<','',$pattern); $pattern = str_replace('>','',$pattern); if(strpos($pattern,"/") !== 0) { $close = "\/>"; $pattern = str_replace('/','',$pattern); } $pattern = trim($pattern); if(!isset($close)) $close = "<\/".$pattern.">"; $pattern = "!$start\<$pattern.+?$close!"; } preg_match($pattern, $string, $result); if(empty($result[0])) { return false; } else { return $result; } } } if( ! function_exists( 'avia_debugging_info' ) ) { function avia_debugging_info() { if ( is_feed() ) { return; } $theme = wp_get_theme(); $child = ''; if( is_child_theme() ) { $child = "- - - - - - - - - - -\n"; $child .= 'ChildTheme: ' . $theme->get( 'Name' ) . "\n"; $child .= 'ChildTheme Version: ' . $theme->get( 'Version' ) . "\n"; $child .= 'ChildTheme Installed: ' . $theme->get( 'Template' ) . "\n\n"; $theme = wp_get_theme( $theme->get( 'Template' ) ); } $info = "\n\n'; echo apply_filters( 'avf_debugging_info', $info ); } add_action( 'wp_head', 'avia_debugging_info', 9999999 ); add_action( 'admin_print_scripts', 'avia_debugging_info', 9999999 ); } if(!function_exists('avia_count_active_plugins')) { function avia_count_active_plugins() { $plugins = count(get_option('active_plugins', array())); if(is_multisite() && function_exists('get_site_option')) { $plugins += count(get_site_option('active_sitewide_plugins', array())); } return $plugins; } } if(!function_exists('avia_clean_string')) { function avia_clean_string($string) { $string = str_replace(' ', '_', $string); // Replaces all spaces with underscores. $string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars. return preg_replace('/-+/', '-', strtolower ($string)); // Replaces multiple hyphens with single one. } } if(!function_exists('kriesi_backlink')) { function kriesi_backlink($frontpage_only = false, $theme_name_passed = false) { $no = ''; $theme_string = ''; $theme_name = $theme_name_passed ? $theme_name_passed : THEMENAME; $random_number = get_option(THEMENAMECLEAN.'_fixed_random'); if($random_number % 3 == 0) $theme_string = $theme_name.' Theme by Kriesi'; if($random_number % 3 == 1) $theme_string = $theme_name.' WordPress Theme by Kriesi'; if($random_number % 3 == 2) $theme_string = 'powered by '.$theme_name.' WordPress Theme'; if(!empty($frontpage_only) && !is_front_page()) $no = "rel='nofollow'"; $link = " - {$theme_string}"; $link = apply_filters( 'kriesi_backlink', $link ); return $link; } } if( ! function_exists( 'avia_header_class_filter' ) ) { function avia_header_class_filter( $default = '' ) { $default = apply_filters( 'avia_header_class_filter', $default ); return $default; } } if( ! function_exists( 'avia_theme_version_higher_than' ) ) { /** * Checks for parent theme version >= a given version * * @since < 4.0 * @param string $check_for_version * @return boolean */ function avia_theme_version_higher_than( $check_for_version = '' ) { $theme_version = avia_get_theme_version(); if( version_compare( $theme_version, $check_for_version , '>=' ) ) { return true; } return false; } } if( ! function_exists( 'avia_enqueue_style_conditionally' ) ) { /** * Enque a css file, based on theme options or other conditions that get passed and must be evaluated as true * * 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 * @since 4.3 * @added_by Kriesi * @param boolean $condition * @param string $handle * @param string $src * @param array $deps * @param boolean|string $ver * @param string $media * @param boolean $deregister * @return void */ function avia_enqueue_style_conditionally( $condition = false, $handle = '', $src = '', $deps = array(), $ver = false, $media = 'all', $deregister = true ) { if( $condition == false ) { if( $deregister ) { wp_deregister_style( $handle ); } return; } wp_enqueue_style( $handle, $src, $deps, $ver, $media ); } } if( ! function_exists( 'avia_enqueue_script_conditionally' ) ) { /** * Enque a js file, based on theme options or other conditions that get passed and must be evaluated as true * * 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 * @since 4.3 * @added_by Kriesi * @param boolean $condition * @param string $handle * @param string $src * @param array $deps * @param boolean|string $ver * @param boolean $in_footer * @param boolean $deregister * @return void */ function avia_enqueue_script_conditionally( $condition = false, $handle = '', $src = '', $deps = array(), $ver = false, $in_footer = false, $deregister = true ) { if( $condition == false ) { if( $deregister ) { wp_deregister_script( $handle ); } return; } wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); } } if( ! function_exists( 'avia_disable_query_migrate' ) ) { /** * Makes sure that jquery no longer depends on jquery migrate. * * @since 4.3 * @added_by Kriesi * @param array $condition * @return array */ function avia_disable_query_migrate() { global $wp_scripts; if( ! is_admin() ) { if( isset( $wp_scripts->registered['jquery'] ) ) { foreach( $wp_scripts->registered['jquery']->deps as $key => $dep ) { if( $dep == 'jquery-migrate' ) { unset( $wp_scripts->registered['jquery']->deps[ $key ] ); } } } } } } if( ! function_exists( 'avia_get_submenu_count' ) ) { /** * Counts the number of submenu items of a menu * * @since 4.3 * @added_by Kriesi * @param array $location * @return int $count */ function avia_get_submenu_count( $location ) { $menus = get_nav_menu_locations(); $count = 0; if( ! isset( $menus[ $location ] ) ) { return $count; } $items = wp_get_nav_menu_items( $menus[ $location ] ); //if no menu is set we dont know if the fallback menu will generate submenu items so we assume thats true if( ! $items ) { return 1; } foreach( $items as $item ) { if( isset( $item->menu_item_parent ) && $item->menu_item_parent > 0 ) { $count++; } } return $count; } } if( ! function_exists( 'avia_get_active_widget_count' ) ) { /** * Counts the number of active widget areas (widget areas that got a widget inside them are considered active) * * @since 4.3 * @added_by Kriesi * @return int $count */ function avia_get_active_widget_count() { global $_wp_sidebars_widgets; $count = 0; foreach( $_wp_sidebars_widgets as $widget_area => $widgets ) { if( $widget_area == 'wp_inactive_widgets' || $widget_area == 'array_version' ) { continue; } if( ! empty( $widgets ) ) { $count++; } } return $count; } } if( ! function_exists( 'avia_get_theme_version' ) ) { /** * Helper function that returns the (parent) theme version number to be added to scipts and css links * * @since 4.3.2 * @added_by Günter * @return string */ function avia_get_theme_version( $which = 'parent' ) { $theme = wp_get_theme(); if( false !== $theme->parent() && ( 'parent' == $which ) ) { $theme = $theme->parent(); } $vn = $theme->get( 'Version' ); return $vn; } } if( ! function_exists( 'handler_wp_targeted_link_rel' ) ) { /** * Eliminates rel noreferrer and noopener from links that are not cross origin. * * @since 4.6.3 * @added_by Günter * @param string $rel 'noopener noreferrer' * @param string $link_html space separated string of a attributes * @return string */ function handler_wp_targeted_link_rel( $rel, $link_html ) { $url = get_bloginfo( 'url' ); $url = str_ireplace( array( 'http://', 'https://' ), '', $url ); $href = ''; $found = preg_match( '/href=["\']?([^"\'>]+)["\']?/', $link_html, $href ); if( empty( $found ) ) { return $rel; } $info = explode( '?', $href[1] ); if( false !== stripos( $info[0], $url ) ) { return ''; } return $rel; } add_filter( 'wp_targeted_link_rel', 'handler_wp_targeted_link_rel', 10, 2 ); } if( ! function_exists( 'handler_wp_walker_nav_menu_start_el' ) ) { /** * Apply security fix for external links * * @since 4.6.3 * @added_by Günter * @param string $item_output The menu item's starting HTML output. * @param WP_Post|mixed $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param stdClass $args An object of wp_nav_menu() arguments. * @return type */ function handler_wp_walker_nav_menu_start_el( $item_output, $item, $depth, $args ) { $item_output = avia_targeted_link_rel( $item_output ); return $item_output; } add_filter( 'walker_nav_menu_start_el', 'handler_wp_walker_nav_menu_start_el', 10, 4 ); } if( ! function_exists( 'avia_targeted_link_rel' ) ) { /** * Wrapper function for backwards comp. with older WP vrsions * * @since 4.6.3 * @uses wp_targeted_link_rel @since 5.1.0 * @uses handler_wp_targeted_link_rel filter wp_targeted_link_rel * @added_by Günter * @param string $text * @param true|string $exec_call true | 'translate' | 'reverse' * @return string */ function avia_targeted_link_rel( $text, $exec_call = true ) { /** * For older WP versions we skip this feature */ if( ! function_exists( 'wp_targeted_link_rel' ) ) { return $text; } global $wp_version; /** * WP changed the way it splits the attributes. '_' is not supported as a valid attribute and removes these attributes. * See wp-includes\kses.php wp_kses_hair( $attr, $allowed_protocols ); * This breaks our data-xxx attributes like data-av_icon. * * This might change in a future version of WP. */ if( version_compare( $wp_version, '5.3.1', '<' ) ) { return true === $exec_call ? wp_targeted_link_rel( $text ) : $text; } /** * Do not run (more expensive) regex if no links with targets */ if( stripos( $text, 'target' ) === false || stripos( $text, ']*target\s*=[^>]*)>|i', function ( $matches ) use( $source, $replace ) { $link_html = $matches[1]; // Consider the html escaped if there are no unescaped quotes $is_escaped = ! preg_match( '/(^|[^\\\\])[\'"]/', $link_html ); if ( $is_escaped ) { // Replace only the quotes so that they are parsable by wp_kses_hair, leave the rest as is $link_html = preg_replace( '/\\\\([\'"])/', '$1', $link_html ); } foreach( $source as $key => $value ) { $link_html = preg_replace( '|' . $value . '\s*=|i', $replace[ $key ] . '=', $link_html ); } if ( $is_escaped ) { $link_html = preg_replace( '/[\'"]/', '\\\\$0', $link_html ); } return ""; }, $part ); } unset( $part ); $text = ''; for( $i = 0; $i < count( $html_parts ); $i++ ) { $text .= $html_parts[ $i ]; if( isset( $extra_parts[ $i ] ) ) { $text .= $extra_parts[ $i ]; } } switch( $iteration ) { case 0; if( true === $exec_call ) { $text = wp_targeted_link_rel( $text ); } break; default: break; } if( 'translate' == $test_exec ) { break; } } return $text; } } if( ! function_exists( 'handler_avia_widget_text' ) ) { add_filter( 'widget_text', 'handler_avia_widget_text', 90000, 3 ); /** * Replace attributes with _ that wp_targeted_link_rel() does not remove them * * @since 4.6.4 * @param string $content * @param array $instance * @param WP_Widget $widget * @return type */ function handler_avia_widget_text( $content = '', $instance = null, $widget = null ) { /** * To support WP_Widget_Text: * * - Needs js code to replace translated attributes in frontend as this widget has no filter after call to wp_targeted_link_rel() * or * - Add a filter to wp-includes\widgets\class-wp-widget-text.php after wp_targeted_link_rel() call */ if( ! $widget instanceof WP_Widget_Custom_HTML || ! is_string( $content ) ) { return $content; } return avia_targeted_link_rel( $content, 'translate' ); } } if( ! function_exists( 'handler_avia_widget_custom_html_content' ) ) { add_filter( 'widget_custom_html_content', 'handler_avia_widget_custom_html_content', 90000, 3 ); /** * Revert changes to attributes with _ * * @since 4.6.4 * @param string $content * @param array $instance * @param WP_Widget $widget * @return string */ function handler_avia_widget_custom_html_content( $content = '', $instance = null, $widget = null ) { if( ! is_string( $content ) ) { return $content; } return avia_targeted_link_rel( $content, 'reverse' ); } }