Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 74.78 KB | None | 0 0
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly
  3.  
  4. /*
  5. * The function within this file are theme specific:
  6. * they are used only by this theme and not by the Avia Framework in general
  7. */
  8.  
  9.  
  10. /* wrap embeds into a proportion containing div */
  11. if(!function_exists('avia_preload_screen'))
  12. {
  13. function avia_preload_screen()
  14. {
  15. $class = avia_get_option('preloader_transitions') != "disabled" ? 'av-transition-enabled' : "";
  16. $label = __('Loading','avia_framework');
  17. $logo = avia_get_option('preloader_logo');
  18. if( is_numeric( $logo ) )
  19. {
  20. $logo = wp_get_attachment_image_src( $logo, 'full' );
  21. $logo = is_array( $logo ) ? $logo[0] : '';
  22. }
  23.  
  24. if( $logo )
  25. {
  26. $class .= " av-transition-with-logo";
  27. $logo = "<img class='av-preloading-logo' src='{$logo}' alt='{$label}' title='{$label}' />";
  28. }
  29.  
  30. $output = "";
  31. $output .= "<div class='av-siteloader-wrap {$class}'>";
  32. $output .= "<div class='av-siteloader-inner'>";
  33. $output .= "<div class='av-siteloader-cell'>";
  34. $output .= $logo;
  35. $output .= "<div class='av-siteloader'><div class='av-siteloader-extra'></div>";
  36. $output .= "</div>";
  37. $output .= "</div>";
  38. $output .= "</div>";
  39. $output .= "</div>";
  40.  
  41. return $output;
  42. }
  43. }
  44.  
  45.  
  46.  
  47. /* filter menu item urls */
  48. if(!function_exists('avia_menu_item_filter'))
  49. {
  50. add_filter( 'avf_menu_items', 'avia_menu_item_filter', 10 );
  51.  
  52. function avia_menu_item_filter ( $item )
  53. {
  54.  
  55. if(isset( $item->url ) && strpos($item->url, '#DOMAIN') === 0)
  56. {
  57. $item->url = str_replace("#DOMAIN", get_site_url(), $item->url);
  58. }
  59.  
  60. return $item;
  61. }
  62. }
  63.  
  64.  
  65.  
  66. /* filter menu item urls */
  67. if(!function_exists('avia_maps_key_for_plugins'))
  68. {
  69. add_filter( 'script_loader_src', 'avia_maps_key_for_plugins', 10, 2 );
  70.  
  71. function avia_maps_key_for_plugins ( $url, $handle )
  72. {
  73. $key = get_option( 'gmap_api' );
  74.  
  75. if ( ! $key ) { return $url; }
  76.  
  77. if ( strpos( $url, "maps.google.com/maps/api/js" ) !== false || strpos( $url, "maps.googleapis.com/maps/api/js" ) !== false )
  78. {
  79. // if no key, we can generate a new link with our key
  80. if ( strpos( $url, "key=" ) === false )
  81. {
  82. $url = av_google_maps::api_url( $key );
  83. }
  84. }
  85.  
  86. return $url;
  87. }
  88. }
  89.  
  90.  
  91.  
  92. /* wrap embeds into a proportion containing div */
  93. if(!function_exists('avia_iframe_proportion_wrap'))
  94. {
  95. add_filter( 'embed_oembed_html', 'avia_iframe_proportion_wrap', 10, 4 );
  96.  
  97. function avia_iframe_proportion_wrap ( $html, $url, $attr, $post_ID )
  98. {
  99. if(strpos($html, '<iframe') !== false)
  100. {
  101. $html = "<div class='avia-iframe-wrap'>{$html}</div>";
  102. }
  103. return $html;
  104. }
  105. }
  106.  
  107.  
  108.  
  109. /* AJAX SEARCH */
  110. if( ! function_exists( 'avia_append_search_nav' ) )
  111. {
  112. //first append search item to main menu
  113. add_filter( 'wp_nav_menu_items', 'avia_append_search_nav', 9997, 2 );
  114. add_filter( 'avf_fallback_menu_items', 'avia_append_search_nav', 9997, 2 );
  115.  
  116. /**
  117. *
  118. *
  119. * @param string $items
  120. * @param array $args
  121. * @return string
  122. */
  123. function avia_append_search_nav ( $items, $args )
  124. {
  125. if( avia_get_option( 'header_searchicon', 'header_searchicon' ) != "header_searchicon" )
  126. {
  127. return $items;
  128. }
  129.  
  130. if( avia_get_option( 'header_position', 'header_top' ) != "header_top" )
  131. {
  132. return $items;
  133. }
  134.  
  135. if( ( is_object( $args ) && $args->theme_location == 'avia') || ( is_string( $args ) && $args = 'fallback_menu' ) )
  136. {
  137.  
  138. ob_start();
  139. get_search_form();
  140. $form = ob_get_clean();
  141.  
  142. $form = str_replace( '<form ', '<form role="search" ', $form );
  143. $form = htmlspecialchars( $form );
  144.  
  145. /**
  146. * Avoid duplicate indexing or empty search page
  147. *
  148. * @since 4.5.3
  149. * @param string $items
  150. * @param array $args
  151. * @return string
  152. */
  153. $nofollow = apply_filters( 'avf_nav_search_icon_nofollow', 'rel="nofollow"', $items, $args );
  154.  
  155. $aria_label = __( 'Search', 'avia_framework' );
  156. $aria_label = apply_filters( 'avf_nav_search_aria_label', $aria_label, $items, $args );
  157.  
  158. $items .= '<li id="menu-item-search" class="noMobile menu-item menu-item-search-dropdown menu-item-avia-special">';
  159. $items .= '<a aria-label="' . $aria_label . '" href="?s=" '. $nofollow . ' data-avia-search-tooltip="' . $form . '" ' . av_icon_string( 'search', false ) . '>';
  160. $items .= '<span class="avia_hidden_link_text">' . __( 'Search', 'avia_framework' ) . '</span>';
  161. $items .= '</a>';
  162. $items .= '</li>';
  163. }
  164.  
  165. return $items;
  166. }
  167. }
  168.  
  169. /* Prepare a possible fix for menu plugins, that remove theme location from menu array to exchange the menus */
  170. if( ! function_exists( 'avia_save_menu_location' ) )
  171. {
  172. add_filter( 'wp_nav_menu_args', 'avia_save_menu_location', 1, 1 );
  173.  
  174. function avia_save_menu_location( $args )
  175. {
  176. global $avia_config;
  177.  
  178. $avia_config['current_menu_location_output'] = isset( $args['theme_location'] ) ? $args['theme_location'] : '';
  179.  
  180. return $args;
  181. }
  182. }
  183.  
  184.  
  185. /* Append the burger menu */
  186. if(!function_exists('avia_append_burger_menu'))
  187. {
  188. //first append search item to main menu
  189. add_filter( 'wp_nav_menu_items', 'avia_append_burger_menu', 9998, 2 );
  190. add_filter( 'avf_fallback_menu_items', 'avia_append_burger_menu', 9998, 2 );
  191.  
  192. function avia_append_burger_menu ( $items , $args )
  193. {
  194. global $avia_config;
  195.  
  196. $location = ( is_object( $args ) && isset( $args->theme_location ) ) ? $args->theme_location : '';
  197. $original_location = isset( $avia_config['current_menu_location_output'] ) ? $avia_config['current_menu_location_output'] : '';
  198.  
  199. /**
  200. * Allow compatibility with plugins that change menu or third party plugins to manpulate the location
  201. *
  202. * @used_by Enfold config-menu-exchange\config.php 10
  203. * @since 4.1.3
  204. */
  205. $location = apply_filters( 'avf_append_burger_menu_location', $location, $original_location, $items , $args );
  206.  
  207. if( ( is_object( $args ) && ( $location == 'avia' ) ) || ( is_string( $args ) && ( $args == "fallback_menu" ) ) )
  208. {
  209. $class = avia_get_option('burger_size');
  210.  
  211. $items .= '<li class="av-burger-menu-main menu-item-avia-special '.$class.'">
  212. <a href="#">
  213. <span class="av-hamburger av-hamburger--spin av-js-hamburger">
  214. <span class="av-hamburger-box">
  215. <span class="av-hamburger-inner"></span>
  216. <strong>'.__('Menu','avia_framework').'</strong>
  217. </span>
  218. </span>
  219. </a>
  220. </li>';
  221. }
  222. return $items;
  223. }
  224. }
  225.  
  226. if(!function_exists('avia_is_burger_menu'))
  227. {
  228. function avia_is_burger_menu ()
  229. {
  230. $burger_menu = false;
  231.  
  232. if(avia_get_option('menu_display') !== "burger_menu") return $burger_menu;
  233. if(avia_get_option('header_position') !== "header_top") return $burger_menu;
  234.  
  235. //if(avia_get_option('header_position') !== "header_top") return $burger_menu;
  236. //if(strpos(avia_get_option('header_layout'), 'main_nav_header') === false) return $burger_menu;
  237.  
  238. return true;
  239. }
  240. }
  241.  
  242.  
  243.  
  244.  
  245.  
  246. if(!function_exists('avia_ajax_search'))
  247. {
  248. //now hook into wordpress ajax function to catch any ajax requests
  249. add_action( 'wp_ajax_avia_ajax_search', 'avia_ajax_search' );
  250. add_action( 'wp_ajax_nopriv_avia_ajax_search', 'avia_ajax_search' );
  251.  
  252. function avia_ajax_search()
  253. {
  254. global $avia_config;
  255.  
  256. unset($_REQUEST['action']);
  257. if(empty($_REQUEST['s'])) $_REQUEST['s'] = array_shift(array_values($_REQUEST));
  258. if(empty($_REQUEST['s'])) die();
  259.  
  260. $defaults = array('numberposts' => 5, 'post_type' => 'any', 'post_status' => 'publish', 'post_password' => '', 'suppress_filters' => false, 'results_hide_fields' => '');
  261.  
  262. $_REQUEST['s'] = apply_filters( 'get_search_query', $_REQUEST['s']);
  263.  
  264. $search_parameters = array_merge($defaults, $_REQUEST);
  265.  
  266. if ( $search_parameters['results_hide_fields'] !== '' ) {
  267. $search_parameters['results_hide_fields'] = explode(',', $_REQUEST['results_hide_fields']);
  268. }
  269. else {
  270. $search_parameters['results_hide_fields'] = array();
  271. }
  272.  
  273. $search_query = apply_filters('avf_ajax_search_query', http_build_query($search_parameters));
  274. $query_function = apply_filters('avf_ajax_search_function', 'get_posts', $search_query, $search_parameters, $defaults);
  275. $posts = (($query_function == 'get_posts') || !function_exists($query_function)) ? get_posts($search_query) : $query_function($search_query, $search_parameters, $defaults);
  276.  
  277. $search_messages = array(
  278. 'no_criteria_matched' => __("Sorry, no posts matched your criteria", 'avia_framework'),
  279. 'another_search_term' => __("Please try another search term", 'avia_framework'),
  280. 'time_format' => get_option('date_format'),
  281. 'all_results_query' => http_build_query($_REQUEST),
  282. 'all_results_link' => home_url('?' . http_build_query($_REQUEST)),
  283. 'view_all_results' => __('View all results','avia_framework')
  284. );
  285.  
  286. $search_messages = apply_filters('avf_ajax_search_messages', $search_messages, $search_query);
  287.  
  288. if(empty($posts))
  289. {
  290. $output = "<span class='av_ajax_search_entry ajax_not_found'>";
  291. $output .= "<span class='av_ajax_search_image ".av_icon_string('info')."'>";
  292. $output .= "</span>";
  293. $output .= "<span class='av_ajax_search_content'>";
  294. $output .= " <span class='av_ajax_search_title'>";
  295. $output .= $search_messages['no_criteria_matched'];
  296. $output .= " </span>";
  297. $output .= " <span class='ajax_search_excerpt'>";
  298. $output .= $search_messages['another_search_term'];
  299. $output .= " </span>";
  300. $output .= "</span>";
  301. $output .= "</span>";
  302. echo $output;
  303. die();
  304. }
  305.  
  306. //if we got posts resort them by post type
  307. $output = "";
  308. $sorted = array();
  309. $post_type_obj = array();
  310. foreach($posts as $post)
  311. {
  312. $sorted[$post->post_type][] = $post;
  313. if(empty($post_type_obj[$post->post_type]))
  314. {
  315. $post_type_obj[$post->post_type] = get_post_type_object($post->post_type);
  316. }
  317. }
  318.  
  319.  
  320.  
  321. //now we got everything we need to preapre the output
  322. foreach($sorted as $key => $post_type)
  323. {
  324.  
  325. // check if post titles are in the hidden fields list
  326. if ( ! in_array('post_titles', $search_parameters['results_hide_fields'] ) )
  327. {
  328. if(isset($post_type_obj[$key]->labels->name))
  329. {
  330. $label = apply_filters('avf_ajax_search_label_names', $post_type_obj[$key]->labels->name);
  331. $output .= "<h4>".$label."</h4>";
  332. }
  333. else
  334. {
  335. $output .= "<hr />";
  336. }
  337. }
  338.  
  339.  
  340. foreach($post_type as $post) {
  341.  
  342.  
  343. $image = "";
  344. $extra_class = "";
  345.  
  346. // check if image is in the hidden fields list
  347. if (!in_array('image', $search_parameters['results_hide_fields']))
  348. {
  349. $image = get_the_post_thumbnail($post->ID, 'thumbnail');
  350. $extra_class = $image ? "with_image" : "";
  351. $post_type = $image ? "" : ( get_post_format($post->ID) != "" ? get_post_format($post->ID) : "standard" );
  352. $iconfont = $image ? "" : av_icon_string($post_type);
  353.  
  354. }
  355.  
  356. $excerpt = "";
  357.  
  358. // check if post meta fields are in the hidden fields list
  359. if ( ! in_array('meta', $search_parameters['results_hide_fields'] ) )
  360. {
  361. if(!empty($post->post_excerpt))
  362. {
  363. $excerpt = apply_filters( 'avf_ajax_search_excerpt', avia_backend_truncate($post->post_excerpt,70," ","...", true, '', true) );
  364. }
  365. else
  366. {
  367. $excerpt = apply_filters( 'avf_ajax_search_no_excerpt', get_the_time( $search_messages['time_format'], $post->ID ), $post );
  368. }
  369. }
  370.  
  371.  
  372. $link = apply_filters('av_custom_url', get_permalink($post->ID), $post);
  373.  
  374. $output .= "<a class ='av_ajax_search_entry {$extra_class}' href='".$link."'>";
  375.  
  376. if ($image !== "" || $iconfont) {
  377. $output .= "<span class='av_ajax_search_image' {$iconfont}>";
  378. $output .= $image;
  379. $output .= "</span>";
  380. }
  381. $output .= "<span class='av_ajax_search_content'>";
  382. $output .= " <span class='av_ajax_search_title'>";
  383. $output .= get_the_title($post->ID);
  384. $output .= " </span>";
  385. if ($excerpt !== '') {
  386. $output .= " <span class='ajax_search_excerpt'>";
  387. $output .= $excerpt;
  388. $output .= " </span>";
  389. }
  390. $output .= "</span>";
  391. $output .= "</a>";
  392. }
  393. }
  394.  
  395. $output .= "<a class='av_ajax_search_entry av_ajax_search_entry_view_all' href='".$search_messages['all_results_link']."'>".$search_messages['view_all_results']."</a>";
  396.  
  397. echo $output;
  398. die();
  399. }
  400. }
  401.  
  402.  
  403. if(!function_exists('avia_social_widget_icon'))
  404. {
  405. /*modify twitter social count widget and add social icons as iconfont*/
  406. add_filter('avf_social_widget', 'avia_social_widget_icon',2,2);
  407.  
  408. function avia_social_widget_icon($content, $icon)
  409. {
  410. global $avia_config;
  411.  
  412. $content = "<span class='social_widget_icon' ".av_icon_string($icon)."></span>".$content;
  413. return $content;
  414. }
  415. }
  416.  
  417.  
  418.  
  419.  
  420.  
  421. //call functions for the theme
  422. add_filter('the_content_more_link', 'avia_remove_more_jump_link');
  423. add_post_type_support('page', 'excerpt');
  424.  
  425.  
  426.  
  427.  
  428. //allow additional file type uploads
  429. if(!function_exists('avia_upload_mimes'))
  430. {
  431. add_filter('upload_mimes','avia_upload_mimes');
  432. function avia_upload_mimes($mimes){ return array_merge($mimes, array ('mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm', 'txt' => 'text/plain')); }
  433. }
  434.  
  435.  
  436.  
  437.  
  438. //change default thumbnail size and fullwidth size on theme activation
  439. if(!function_exists('avia_set_thumb_size'))
  440. {
  441. add_action('avia_backend_theme_activation', 'avia_set_thumb_size');
  442. function avia_set_thumb_size()
  443. {
  444. update_option( 'thumbnail_size_h', 80 ); update_option( 'thumbnail_size_w', 80 );
  445. update_option( 'large_size_w', 1030 ); update_option( 'large_size_h', 1030 );
  446. }
  447. }
  448.  
  449.  
  450.  
  451.  
  452. //add support for post thumbnails
  453. add_theme_support( 'post-thumbnails' );
  454.  
  455.  
  456.  
  457.  
  458. //advanced title + breadcrumb function
  459. if(!function_exists('avia_title'))
  460. {
  461. function avia_title($args = false, $id = false)
  462. {
  463. global $avia_config;
  464.  
  465. if(!$id) $id = avia_get_the_id();
  466.  
  467. $header_settings = avia_header_setting();
  468. if($header_settings['header_title_bar'] == 'hidden_title_bar') return "";
  469.  
  470. $defaults = array(
  471.  
  472. 'title' => get_the_title($id),
  473. 'subtitle' => "", //avia_post_meta($id, 'subtitle'),
  474. 'link' => get_permalink($id),
  475. 'html' => "<div class='{class} title_container'><div class='container'>{heading_html}{additions}</div></div>",
  476. 'heading_html' => "<{heading} class='main-title entry-title {heading_class}'>{title}</{heading}>",
  477. 'class' => 'stretch_full container_wrap alternate_color '.avia_is_dark_bg('alternate_color', true),
  478. 'breadcrumb' => true,
  479. 'additions' => "",
  480. 'heading' => 'h1', //headings are set based on this article: http://yoast.com/blog-headings-structure/
  481. 'heading_class' => ''
  482. );
  483.  
  484. if ( is_tax() || is_category() || is_tag() )
  485. {
  486. global $wp_query;
  487.  
  488. $term = $wp_query->get_queried_object();
  489. $defaults['link'] = get_term_link( $term );
  490. }
  491. else if(is_archive())
  492. {
  493. $defaults['link'] = "";
  494. }
  495.  
  496.  
  497. // Parse incomming $args into an array and merge it with $defaults
  498. $args = wp_parse_args( $args, $defaults );
  499.  
  500. /**
  501. * @used_by config-woocommerce\config.php avia_title_args_woopage() 10
  502. * @since < 4.0
  503. * @return array
  504. */
  505. $args = apply_filters( 'avf_title_args', $args, $id );
  506.  
  507. //disable breadcrumb if requested
  508. if($header_settings['header_title_bar'] == 'title_bar') $args['breadcrumb'] = false;
  509.  
  510. //disable title if requested
  511. if($header_settings['header_title_bar'] == 'breadcrumbs_only') $args['title'] = '';
  512.  
  513.  
  514. // OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
  515. extract( $args, EXTR_SKIP );
  516.  
  517. if(empty($title)) $class .= " empty_title ";
  518. $markup = avia_markup_helper(array('context' => 'avia_title','echo'=>false));
  519. if(!empty($link) && !empty($title)) $title = "<a href='".$link."' rel='bookmark' title='".__('Permanent Link:','avia_framework')." ".esc_attr( $title )."' $markup>".$title."</a>";
  520. if(!empty($subtitle)) $additions .= "<div class='title_meta meta-color'>".wpautop($subtitle)."</div>";
  521. if($breadcrumb) $additions .= avia_breadcrumbs(array('separator' => '/', 'richsnippet' => true));
  522.  
  523.  
  524. if(!$title) $heading_html = "";
  525. $html = str_replace('{heading_html}', $heading_html, $html);
  526.  
  527.  
  528. $html = str_replace( '{class}', $class, $html );
  529. $html = str_replace( '{title}', $title, $html );
  530. $html = str_replace( '{additions}', $additions, $html );
  531. $html = str_replace( '{heading}', $heading, $html );
  532. $html = str_replace( '{heading_class}', $heading_class, $html );
  533.  
  534. if(!empty($avia_config['slide_output']) && !avia_is_dynamic_template($id) && !avia_is_overview())
  535. {
  536. $avia_config['small_title'] = $title;
  537. }
  538. else
  539. {
  540. return $html;
  541. }
  542. }
  543. }
  544.  
  545.  
  546.  
  547.  
  548.  
  549. if( ! function_exists( 'avia_post_nav' ) )
  550. {
  551. /**
  552. * Add navigation link elements for single post pages
  553. *
  554. * @since < 4.0
  555. * @param boolean $same_category
  556. * @param string $taxonomy
  557. * @return string
  558. */
  559. function avia_post_nav( $same_category = false, $taxonomy = 'category' )
  560. {
  561. global $post, $wp_version;
  562.  
  563. /**
  564. * Create a settings array to allow filtering and change behaviour
  565. */
  566. $settings = array();
  567.  
  568. $settings['disable_post_nav_option'] = avia_get_option('disable_post_nav');
  569. $settings['skip_output'] = ! is_singular() || 'disable_post_nav' == $settings['disable_post_nav_option'];
  570. $settings['loop_post_nav'] = 'loop_post_nav' == $settings['disable_post_nav_option'];
  571.  
  572. $settings['same_category'] = $same_category;
  573. $settings['excluded_terms'] = '';
  574. $settings['wpversion'] = $wp_version;
  575. $settings['type'] = get_post_type();
  576. $settings['taxonomy'] = ( $settings['type'] == 'portfolio' ) ? 'portfolio_entries' : $taxonomy;
  577.  
  578. /**
  579. * Don't display if a fullscreen slider is available since they overlap
  580. */
  581. $settings['is_fullwidth'] = false;
  582. if( ( class_exists( 'avia_sc_layerslider' ) && ! empty( avia_sc_layerslider::$slide_count ) ) ||
  583. ( class_exists( 'avia_sc_slider_full' ) && ! empty( avia_sc_slider_full::$slide_count ) ) )
  584. {
  585. $settings['is_fullwidth'] = true;
  586. }
  587.  
  588. $settings['is_hierarchical'] = is_post_type_hierarchical( $settings['type'] );
  589.  
  590. /**
  591. * Check if we need to skip output
  592. */
  593. if( ! $settings['skip_output'] )
  594. {
  595. $settings['skip_output'] = $settings['is_hierarchical'] || $settings['is_fullwidth'];
  596. }
  597.  
  598. /**
  599. * Backwards compatibility - next 2 lines will be removed in a future version
  600. */
  601. $settings = apply_filters_deprecated( 'avia_post_nav_settings', array( $settings ), '4.5.6', 'avf_post_nav_settings', __( 'Return values handling has changed', 'avia_framework' ) );
  602. $settings['skip_output'] = $settings['skip_output'] || ! empty( $settings['is_hierarchical'] ) || ! empty( $settings['is_fullwidth'] );
  603.  
  604.  
  605. /**
  606. * $settings['skip_output'] = true if you want to skip output
  607. * $settings['same_category'] = true|false
  608. * $settings['excluded_terms'] = array|comma speerated string of id's
  609. *
  610. * @used_by config-bbpress\config.php avia_bbpress_avf_post_nav_settings 10
  611. * @since 4.5.6
  612. * @return array
  613. */
  614. $settings = apply_filters( 'avf_post_nav_settings', $settings );
  615.  
  616. if( true === $settings['skip_output'] )
  617. {
  618. return '';
  619. }
  620.  
  621. if(version_compare( $settings['wpversion'], '3.8', '>=' ) )
  622. {
  623. $entries['prev'] = get_previous_post( $settings['same_category'], $settings['excluded_terms'], $settings['taxonomy'] );
  624. $entries['next'] = get_next_post( $settings['same_category'], $settings['excluded_terms'], $settings['taxonomy'] );
  625. }
  626. else
  627. {
  628. $entries['prev'] = get_previous_post( $settings['same_category'] );
  629. $entries['next'] = get_next_post( $settings['same_category'] );
  630. }
  631.  
  632. $queried_entries = $entries;
  633. if( true === $settings['loop_post_nav'] && ( ! $entries['prev'] instanceof WP_Post || ! $entries['next'] instanceof WP_Post ) )
  634. {
  635. $order = ! $entries['prev'] instanceof WP_Post ? 'DESC' : 'ASC';
  636. $args = array(
  637. 'post_type' => $settings['type'],
  638. 'post_status' => 'publish',
  639. 'posts_per_page' => 1,
  640. 'orderby' => array( 'post_date' => $order, 'ID' => $order )
  641. );
  642.  
  643.  
  644. $tax_query = array();
  645.  
  646. if( $settings['same_category'] )
  647. {
  648. $ids_in = array();
  649. $terms = get_the_terms( $post, $settings['taxonomy'] );
  650. if( is_array( $terms ) && ! empty( $terms ) )
  651. {
  652. foreach( $terms as $term )
  653. {
  654. $ids_in[] = $term->term_id;
  655. }
  656. }
  657.  
  658. if( ! empty( $ids_in ) )
  659. {
  660. $tax_query[] = array(
  661. 'taxonomy' => $settings['taxonomy'],
  662. 'field' => 'term_id',
  663. 'terms' => $ids_in,
  664. 'operator' => 'IN',
  665. );
  666. }
  667. }
  668.  
  669. if( ! empty( $settings['excluded_terms'] ) )
  670. {
  671. $ids_not_in = array();
  672. if( is_array( $settings['excluded_terms'] ) )
  673. {
  674. $ids_not_in = $settings['excluded_terms'];
  675. }
  676. else
  677. {
  678. $ids_not_in = explode( ',', $settings['excluded_terms'] );
  679. }
  680.  
  681. if( ! empty( $ids_not_in ) )
  682. {
  683. $tax_query[] = array(
  684. 'taxonomy' => $settings['taxonomy'],
  685. 'field' => 'term_id',
  686. 'terms' => $ids_not_in,
  687. 'operator' => 'NOT IN',
  688. );
  689. }
  690. }
  691.  
  692. if( count( $tax_query ) > 1 )
  693. {
  694. $tax_query['relation'] = 'AND';
  695. }
  696.  
  697. if( count( $tax_query ) >= 1 )
  698. {
  699. $args['tax_query'] = $tax_query;
  700. }
  701.  
  702. /**
  703. * Allows e.g. to change sort order of posts (see WP filter "get_{$adjacent}_post_sort") in get_adjacent_post()
  704. *
  705. * @since 4.5.6.2
  706. * @param array $args
  707. * @param array $settings
  708. * @return array
  709. */
  710. $args = apply_filters( 'avf_post_nav_loop_args', $args, $settings );
  711.  
  712. $looped = new WP_Query( $args );
  713. if( $looped->post_count >= 1 )
  714. {
  715. if( ! $entries['prev'] instanceof WP_Post )
  716. {
  717. $entries['prev'] = $looped->posts[0];
  718. }
  719. else
  720. {
  721. $entries['next'] = $looped->posts[0];
  722. }
  723. }
  724. }
  725.  
  726. /**
  727. * Backwards comp. only, will be removed in future
  728. * @since < 4.0
  729. * @added 4.5.6
  730. */
  731. $entries = apply_filters_deprecated( 'avia_post_nav_entries', array( $entries, $settings, $queried_entries ), '4.5.6', 'avf_post_nav_entries', __( 'Filter name has changed', 'avia_framework' ) );
  732.  
  733. /**
  734. * @used_by config-events-calendar\config.php avia_events_custom_post_nav() 10
  735. *
  736. * @since 4.5.6
  737. * @return array
  738. */
  739. $entries = apply_filters( 'avf_post_nav_entries', $entries, $settings, $queried_entries );
  740.  
  741.  
  742. $output = '';
  743.  
  744. foreach( $entries as $key => $entry )
  745. {
  746. if( empty( $entry ) )
  747. {
  748. continue;
  749. }
  750.  
  751. $the_title = isset($entry->av_custom_title) ? $entry->av_custom_title : avia_backend_truncate(get_the_title( $entry->ID), 75, ' ' );
  752. $link = isset($entry->av_custom_link) ? $entry->av_custom_link : get_permalink( $entry->ID );
  753. $image = isset($entry->av_custom_image) ? $entry->av_custom_image : get_the_post_thumbnail( $entry->ID, 'thumbnail' );
  754.  
  755. $tc1 = $tc2 = '';
  756. $class = $image ? 'with-image' : 'without-image';
  757.  
  758. $output .= "<a class='avia-post-nav avia-post-{$key} {$class}' href='{$link}' >";
  759. $output .= " <span class='label iconfont' " . av_icon_string( $key ) . "></span>";
  760. $output .= " <span class='entry-info-wrap'>";
  761. $output .= " <span class='entry-info'>";
  762.  
  763. $tc1 = " <span class='entry-title'>{$the_title}</span>";
  764. if( $image )
  765. {
  766. $tc2 = " <span class='entry-image'>{$image}</span>";
  767. }
  768.  
  769. $output .= $key == 'prev' ? $tc1 . $tc2 : $tc2 . $tc1;
  770.  
  771. $output .= " </span>";
  772. $output .= " </span>";
  773. $output .= "</a>";
  774. }
  775.  
  776. return $output;
  777. }
  778. }
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785. //wrap ampersands into special calss to apply special styling
  786.  
  787. if(!function_exists('avia_ampersand'))
  788. {
  789. add_filter('avia_ampersand','avia_ampersand');
  790.  
  791. function avia_ampersand($content)
  792. {
  793. //ampersands
  794. $content = str_replace(" &amp; "," <span class='special_amp'>&amp;</span> ",$content);
  795. $content = str_replace(" &#038; "," <span class='special_amp'>&amp;</span> ",$content);
  796.  
  797.  
  798. // quotes
  799. $content = str_replace("“","<span class='special_amp'>“</span>",$content); // left double quotation mark “
  800. $content = str_replace("”","<span class='special_amp'>”</span>",$content); // right double quotation mark ”
  801. $content = str_replace("„","<span class='special_amp'>„</span>",$content); // double low-9 quotation mark „
  802.  
  803.  
  804. $content = str_replace("&#8220;","<span class='special_amp'>&#8220;</span>",$content); // left double quotation mark “
  805. $content = str_replace("&#8221;","<span class='special_amp'>&#8221;</span>",$content); // right double quotation mark ”
  806. $content = str_replace("&#8222;","<span class='special_amp'>&#8222;</span>",$content); // double low-9 quotation mark „
  807.  
  808. return $content;
  809. }
  810. }
  811.  
  812.  
  813.  
  814.  
  815.  
  816. // checks if a background color of a specific region is dark or light and returns a class name
  817. if(!function_exists('avia_is_dark_bg'))
  818. {
  819. function avia_is_dark_bg($region, $return_only = false)
  820. {
  821. global $avia_config;
  822.  
  823. $return = "";
  824. $color = $avia_config['backend_colors']['color_set'][$region]['bg'];
  825.  
  826. $is_dark = avia_backend_calc_preceived_brightness($color, 70);
  827.  
  828. $return = $is_dark ? "dark_bg_color" : "light_bg_color";
  829. if($return_only)
  830. {
  831. return $return;
  832. }
  833. else
  834. {
  835. echo $return;
  836. }
  837. }
  838. }
  839.  
  840.  
  841.  
  842.  
  843. //set post excerpt to be visible on theme acivation in user backend
  844. if(!function_exists('avia_show_menu_description'))
  845. {
  846.  
  847. //add_action('avia_backend_theme_activation', 'avia_show_menu_description');
  848. function avia_show_menu_description()
  849. {
  850. global $current_user;
  851. get_currentuserinfo();
  852. $old_meta_data = $meta_data = get_user_meta($current_user->ID, 'metaboxhidden_page', true);
  853.  
  854. if(is_array($meta_data) && isset($meta_data[0]))
  855. {
  856. $key = array_search('postexcerpt', $meta_data);
  857.  
  858. if($key !== false)
  859. {
  860. unset($meta_data[$key]);
  861. update_user_meta( $current_user->ID, 'metaboxhidden_page', $meta_data, $old_meta_data );
  862. }
  863. }
  864. else
  865. {
  866. update_user_meta( $current_user->ID, 'metaboxhidden_page', array('postcustom', 'commentstatusdiv', 'commentsdiv', 'slugdiv', 'authordiv', 'revisionsdiv') );
  867. }
  868. }
  869. }
  870.  
  871.  
  872.  
  873.  
  874. /*
  875. * make google analytics code work, even if the user only enters the UA id. if the new async tracking code is entered add it to the header, else to the footer
  876. */
  877.  
  878. if( ! function_exists( 'avia_get_tracking_code' ) )
  879. {
  880. add_action( 'init', 'avia_get_tracking_code' );
  881.  
  882. function avia_get_tracking_code()
  883. {
  884. global $avia_config;
  885.  
  886. $avia_config['analytics_code'] = '';
  887.  
  888. $analytics = avia_get_option( 'analytics', '' );
  889. $avia_config['analytics_code'] = trim( $analytics );
  890.  
  891. if( empty( $avia_config['analytics_code'] ) )
  892. {
  893. return;
  894. }
  895.  
  896. if( strpos( $avia_config['analytics_code'], 'UA-' ) === 0 ) // if we only get passed the UA-id create the script for the user (universal tracking code)
  897. {
  898. $avia_config['analytics_code'] = "
  899. <!-- Global site tag (gtag.js) - Google Analytics -->
  900. <script id='google_analytics_script' class='google_analytics_scripts' async src='https://www.googletagmanager.com/gtag/js?id=" . $avia_config['analytics_code'] . "'></script>
  901. <script class='google_analytics_scripts' type='text/javascript'>
  902. window.dataLayer = window.dataLayer || [];
  903. function gtag(){dataLayer.push(arguments);}
  904. gtag('js', new Date());
  905. gtag('config', '" . $avia_config['analytics_code'] . "', { 'anonymize_ip': true });
  906. </script>
  907. ";
  908. }
  909.  
  910. add_action( 'wp_footer', 'avia_print_tracking_code', 10000 );
  911. }
  912.  
  913. function avia_print_tracking_code()
  914. {
  915. global $avia_config;
  916.  
  917. if( ! empty( $avia_config['analytics_code'] ) )
  918. {
  919. //extract UA ID from code
  920. $UAID = false;
  921. $extra_code = '';
  922. $match = array();
  923. preg_match( "!UA-[0-9]+-[0-9]+!", $avia_config['analytics_code'], $match );
  924.  
  925. if( ! empty( $match ) && isset( $match[0] ) )
  926. {
  927. $UAID = $match[0];
  928. }
  929.  
  930. $code = json_encode( $avia_config['analytics_code'] );
  931.  
  932. //if we got a valid uaid, add the js cookie check
  933. if( $UAID )
  934. {
  935. $extra_code = "
  936. <script type='text/javascript'>
  937.  
  938. (function($) {
  939.  
  940. /* check if google analytics tracking is disabled by user setting via cookie - or user must opt in. */
  941.  
  942. var analytics_code = {$code}.replace(/\\\"/g, '\"' );
  943. var html = document.getElementsByTagName('html')[0];
  944.  
  945. $('html').on( 'avia-cookie-settings-changed', function(e)
  946. {
  947. var cookie_check = html.className.indexOf('av-cookies-needs-opt-in') >= 0 || html.className.indexOf('av-cookies-can-opt-out') >= 0;
  948. var allow_continue = true;
  949. var silent_accept_cookie = html.className.indexOf('av-cookies-user-silent-accept') >= 0;
  950. var script_loaded = $( 'script.google_analytics_scripts' );
  951.  
  952. if( cookie_check && ! silent_accept_cookie )
  953. {
  954. if( ! document.cookie.match(/aviaCookieConsent/) || html.className.indexOf('av-cookies-session-refused') >= 0 )
  955. {
  956. allow_continue = false;
  957. }
  958. else
  959. {
  960. if( ! document.cookie.match(/aviaPrivacyRefuseCookiesHideBar/) )
  961. {
  962. allow_continue = false;
  963. }
  964. else if( ! document.cookie.match(/aviaPrivacyEssentialCookiesEnabled/) )
  965. {
  966. allow_continue = false;
  967. }
  968. else if( document.cookie.match(/aviaPrivacyGoogleTrackingDisabled/) )
  969. {
  970. allow_continue = false;
  971. }
  972. }
  973. }
  974.  
  975. if( ! allow_continue )
  976. {
  977. // window['ga-disable-{$UAID}'] = true;
  978. if( script_loaded.length > 0 )
  979. {
  980. script_loaded.remove();
  981. }
  982. }
  983. else
  984. {
  985. if( script_loaded.length == 0 )
  986. {
  987. $('head').append( analytics_code );
  988. }
  989. }
  990. });
  991.  
  992. $('html').trigger( 'avia-cookie-settings-changed' );
  993.  
  994. })( jQuery );
  995.  
  996. </script>";
  997. }
  998.  
  999. // echo $extra_code . $avia_config['analytics_code'];
  1000.  
  1001. echo $extra_code;
  1002. }
  1003. }
  1004. }
  1005.  
  1006.  
  1007. /*
  1008. function that checks which header style we are using. In general the whole site has the same header active, based on the option in theme options->header
  1009. however, for the theme demo we need to showcase all headers, thats why we can simply add a custom field key to overwrite the default heading
  1010. */
  1011.  
  1012. if(!function_exists('avia_header_setting'))
  1013. {
  1014. function avia_header_setting($single_val = false)
  1015. {
  1016. global $avia_config;
  1017. if(isset($avia_config['header_settings']) && $single_val && isset($avia_config['header_settings'][$single_val])) return $avia_config['header_settings'][$single_val];
  1018. if(isset($avia_config['header_settings']) && !$single_val) return $avia_config['header_settings']; //return cached header setting if available
  1019.  
  1020. $defaults = array( 'header_position' => 'header_top',
  1021. 'header_layout' => 'logo_left menu_right',
  1022. 'header_size' => 'slim',
  1023. 'header_custom_size' => '',
  1024. 'header_sticky' => 'header_sticky',
  1025. 'header_shrinking' =>'header_shrinking',
  1026. 'header_title_bar' => '',
  1027. 'header_social' => '',
  1028. 'header_unstick_top' => '',
  1029. 'header_secondary_menu' => '',
  1030. 'header_stretch' => '',
  1031. 'header_custom_size' => '',
  1032. 'header_phone_active' => '',
  1033. 'header_replacement_logo' => '',
  1034. 'header_replacement_logo_title' => '',
  1035. 'header_replacement_logo_alt' => '',
  1036. 'header_replacement_menu' => '',
  1037. 'submenu_visibility' => '',
  1038. 'overlay_style' => 'av-overlay-side',
  1039. 'header_searchicon' => true,
  1040. 'header_mobile_activation' => 'mobile_menu_phone',
  1041. 'phone' =>'',
  1042. 'sidebarmenu_sticky' => 'conditional_sticky',
  1043. 'layout_align_content' => 'content_align_center',
  1044. 'sidebarmenu_widgets' => '',
  1045. 'sidebarmenu_social' => 'disabled',
  1046. 'header_menu_border' => '',
  1047. 'header_style' => '',
  1048. 'blog_global_style' => '',
  1049. 'menu_display' => '',
  1050. 'alternate_menu' => '',
  1051. 'submenu_clone' => 'av-submenu-noclone',
  1052. );
  1053.  
  1054. $settings = avia_get_option();
  1055.  
  1056. //overwrite with custom fields if they are set
  1057. $post_id = avia_get_the_id();
  1058. if($post_id && is_singular())
  1059. {
  1060. $custom_fields = get_post_custom($post_id);
  1061.  
  1062. foreach( $defaults as $key => $default )
  1063. {
  1064. if(!empty($custom_fields[$key]) && !empty($custom_fields[$key][0]) )
  1065. {
  1066. $settings[$key] = $custom_fields[$key][0];
  1067. }
  1068. }
  1069.  
  1070. //check if header transparency is set to true
  1071. $transparency = post_password_required() ? false : get_post_meta($post_id, 'header_transparency', true);
  1072. }
  1073.  
  1074. $header = shortcode_atts($defaults, $settings);
  1075. $header['header_scroll_offset'] = avia_get_header_scroll_offset($header);
  1076.  
  1077. //if sidebar main menu is active set the header accordingly and return the sidebar header
  1078. if($header['header_position'] != "header_top") return avia_header_setting_sidebar($header, $single_val);
  1079. //------------------------------------------------------------------------------------------------------
  1080. //------------------------------------------------------------------------------------------------------
  1081.  
  1082.  
  1083. //if header main menu is above the logo set a var to indicate that and disable transparency and shrinking
  1084. if( strpos( $header['header_layout'] , 'top_nav_header' ) !== false )
  1085. {
  1086. $header['header_menu_above'] = true;
  1087. $header['header_shrinking'] = 'disabled';
  1088. $transparency = false;
  1089. }
  1090.  
  1091. //set header transparency
  1092. $header['header_transparency'] = "";
  1093. if(!empty($transparency)) $header['header_transparency'] = 'header_transparency';
  1094. if(!empty($transparency) && strpos($transparency, 'glass')) $header['header_transparency'] .= ' header_glassy';
  1095. if(!empty($transparency) && strpos($transparency, 'with_border')) $header['header_transparency'] .= ' header_with_border';
  1096. if(!empty($transparency) && strpos($transparency, 'hidden')) $header['disabled'] = true;
  1097. if(!empty($transparency) && strpos($transparency, 'scrolldown'))
  1098. {
  1099. $header['header_transparency'] .= ' header_scrolldown';
  1100. $header['header_sticky'] = 'header_sticky';
  1101. }
  1102.  
  1103.  
  1104. //deactivate title bar if header is transparent
  1105. if(!empty($transparency)) $header['header_title_bar'] = 'hidden_title_bar';
  1106.  
  1107. //sticky and shrinking are tied together
  1108. if($header['header_sticky'] == 'disabled') { $header['header_shrinking'] = 'disabled'; $header['header_scroll_offset'] = 0; }
  1109.  
  1110. //if the custom height is less than 70 shrinking doesnt really work
  1111. if($header['header_size'] == 'custom' && (int) $header['header_custom_size'] < 65) $header['header_shrinking'] = 'disabled';
  1112.  
  1113. //deactivate icon menu if we dont have the correct header
  1114. if(strpos(avia_get_option('header_layout'), 'main_nav_header') === false) $header['menu_display'] = "";
  1115.  
  1116. if($header['menu_display'] == 'burger_menu') { $header['header_menu_border'] = "";}
  1117.  
  1118. if(avia_is_burger_menu())
  1119. {
  1120. $header['header_mobile_activation'] = "mobile_menu_tablet";
  1121. }
  1122.  
  1123. //create a header class so we can style properly
  1124. $header_class_var = array( 'header_position',
  1125. 'header_layout',
  1126. 'header_size',
  1127. 'header_sticky',
  1128. 'header_shrinking',
  1129. 'header_stretch',
  1130. 'header_mobile_activation',
  1131. 'header_transparency',
  1132. 'header_searchicon',
  1133. 'header_unstick_top',
  1134. 'header_menu_border',
  1135. 'header_style'
  1136. );
  1137.  
  1138. $header['header_class'] = "";
  1139.  
  1140. foreach($header_class_var as $class_name)
  1141. {
  1142. if(!empty($header[$class_name]))
  1143. {
  1144. if($header[$class_name] == "disabled") $header[$class_name] = $class_name."_disabled";
  1145. $header['header_class'] .= " av_".str_replace(' ',' av_',$header[$class_name]);
  1146. }
  1147. }
  1148.  
  1149. //set manual flag if we should display the top bar
  1150. $header['header_topbar'] = false;
  1151. if(strpos($header['header_social'], 'extra_header_active') !== false || strpos($header['header_secondary_menu'], 'extra_header_active') !== false || !empty($header['header_phone_active'])){ $header['header_topbar'] = 'header_topbar_active'; }
  1152.  
  1153. //set manual flag if the menu is at the bottom
  1154. $header['bottom_menu'] = false;
  1155. if(strpos($header['header_layout'],'bottom_nav_header') !== false)
  1156. {
  1157. $header['bottom_menu'] = 'header_bottom_menu_active';
  1158. }
  1159. else
  1160. {
  1161. $header['header_class'] .= " av_bottom_nav_disabled ";
  1162. }
  1163.  
  1164.  
  1165.  
  1166. //header class that tells us to use the alternate logo
  1167. if(!empty($header['header_replacement_logo']))
  1168. {
  1169. $header['header_class'] .= " av_alternate_logo_active";
  1170. $header_replacement_logo_id = avia_get_attachment_id( $header['header_replacement_logo'] );
  1171. $header_replacement_logo_src = wp_get_attachment_image_src( $header_replacement_logo_id, 'full' );
  1172. if( is_array( $header_replacement_logo_src ) )
  1173. {
  1174. $header['header_replacement_logo'] = $header_replacement_logo_src[0];
  1175.  
  1176. /**
  1177. * We added title and alt attribute - this allows to ignore it
  1178. *
  1179. * @since 4.5.7.2
  1180. * @param boolean
  1181. * @param int
  1182. * @rturn boolean
  1183. */
  1184. if( false === apply_filters( 'avf_hide_transparency_logo_meta', false, $header_replacement_logo_id ) )
  1185. {
  1186. $header['header_replacement_logo_title'] = get_the_title( $header_replacement_logo_id );
  1187. $header['header_replacement_logo_alt'] = get_post_meta( $header_replacement_logo_id, '_wp_attachment_image_alt', true );
  1188. }
  1189. }
  1190. }
  1191.  
  1192. //header class that tells us to use the alternate logo
  1193. if(empty($header['header_menu_border']))
  1194. {
  1195. $header['header_class'] .= " av_header_border_disabled";
  1196. }
  1197.  
  1198. /**
  1199. * Modify the header settings
  1200. *
  1201. * @param array $header
  1202. * @param string $context
  1203. * @return array
  1204. */
  1205. $header = apply_filters('avf_header_setting_filter', $header, 'setting_header' );
  1206.  
  1207. //make settings available globaly
  1208. $avia_config['header_settings'] = $header;
  1209.  
  1210. if(!empty($single_val) && isset($header[$single_val])) return $header[$single_val];
  1211.  
  1212. return $header;
  1213. }
  1214. }
  1215.  
  1216. if ( ! function_exists( 'avia_get_attachment_id' ) ) {
  1217. /**
  1218. * Get the Attachment ID for a given image URL.
  1219. *
  1220. * @link http://wordpress.stackexchange.com/a/7094
  1221. *
  1222. * @param string $url
  1223. *
  1224. * @return boolean|integer
  1225. */
  1226. function avia_get_attachment_id( $url ) {
  1227.  
  1228. $dir = wp_upload_dir();
  1229.  
  1230. // baseurl never has a trailing slash
  1231. if ( false === strpos( $url, $dir['baseurl'] . '/' ) ) {
  1232. // URL points to a place outside of upload directory
  1233. return false;
  1234. }
  1235.  
  1236. $file = basename( $url );
  1237. $query = array(
  1238. 'post_type' => 'attachment',
  1239. 'fields' => 'ids',
  1240. 'meta_query' => array(
  1241. array(
  1242. 'key' => '_wp_attached_file',
  1243. 'value' => $file,
  1244. 'compare' => 'LIKE',
  1245. ),
  1246. )
  1247. );
  1248.  
  1249. // query attachments
  1250. $ids = get_posts( $query );
  1251.  
  1252. if ( ! empty( $ids ) ) {
  1253.  
  1254. foreach ( $ids as $id ) {
  1255.  
  1256. // first entry of returned array is the URL
  1257. $img_src = wp_get_attachment_image_src( $id, 'full' );
  1258. $img_url = array_shift( $img_src );
  1259. if ( $url === $img_url )
  1260. return $id;
  1261. }
  1262. }
  1263.  
  1264. $query['meta_query'][0]['key'] = '_wp_attachment_metadata';
  1265.  
  1266. // query attachments again
  1267. $ids = get_posts( $query );
  1268.  
  1269. if ( empty( $ids) )
  1270. return false;
  1271.  
  1272. foreach ( $ids as $id ) {
  1273.  
  1274. $meta = wp_get_attachment_metadata( $id );
  1275.  
  1276. foreach ( $meta['sizes'] as $size => $values ) {
  1277.  
  1278. if ( $values['file'] === $file && $url === array_shift( wp_get_attachment_image_src( $id, $size ) ) )
  1279. return $id;
  1280. }
  1281. }
  1282.  
  1283. return false;
  1284. }
  1285. }
  1286.  
  1287. if(!function_exists('avia_header_setting_sidebar'))
  1288. {
  1289. function avia_header_setting_sidebar( $header, $single_val = false )
  1290. {
  1291. $overwrite = array(
  1292. 'header_layout' => 'logo_left menu_right',
  1293. 'header_size' => 'slim',
  1294. 'header_custom_size' => '',
  1295. 'header_sticky' => 'disabled',
  1296. 'header_shrinking' => 'disabled',
  1297. 'header_title_bar' => 'hidden_title_bar',
  1298. 'header_social' => '',
  1299. 'header_secondary_menu' => '',
  1300. 'header_stretch' => '',
  1301. 'header_custom_size' => '',
  1302. 'header_phone_active' => 'disabled',
  1303. 'header_replacement_logo' => '',
  1304. 'header_replacement_logo_title' => '',
  1305. 'header_replacement_logo_alt' => '',
  1306. 'header_replacement_menu' => '',
  1307. 'header_mobile_activation' => 'mobile_menu_phone',
  1308. 'phone' =>'',
  1309. 'header_menu_border' => '',
  1310. 'header_topbar' => false,
  1311. 'bottom_menu' => false,
  1312. 'header_style' => '',
  1313. 'menu_display' => '',
  1314. 'submenu_clone' => 'av-submenu-noclone',
  1315. );
  1316.  
  1317. $header = array_merge( $header, $overwrite );
  1318.  
  1319. // Reset to actual user setting - otherwise burger menu will result in wrong behaviour
  1320. $settings = avia_get_option();
  1321. $header['submenu_clone'] = isset( $settings['submenu_clone'] ) && in_array( $settings['submenu_clone'], array( 'av-submenu-clone', 'av-submenu-noclone' ) ) ? $settings['submenu_clone'] : 'av-submenu-noclone';
  1322.  
  1323. if( strpos($header['header_position'] , 'left') === false ) $header['sidebarmenu_sticky'] = "never_sticky";
  1324.  
  1325. $header['header_class'] = " av_".str_replace(' ',' av_',$header['header_position']." ".$header['sidebarmenu_sticky']);
  1326.  
  1327. /**
  1328. * Modify the header settings
  1329. *
  1330. * @param array $header
  1331. * @param string $context
  1332. * @return array
  1333. */
  1334. $header = apply_filters('avf_header_setting_filter', $header, 'setting_sidebar' );
  1335.  
  1336. //make settings available globaly
  1337. $avia_config['header_settings'] = $header;
  1338.  
  1339. if(!empty($single_val) && isset($header[$single_val])) return $header[$single_val];
  1340.  
  1341. return $header;
  1342. }
  1343. }
  1344.  
  1345.  
  1346. if(!function_exists('avia_get_header_scroll_offset'))
  1347. {
  1348. function avia_get_header_scroll_offset($header = array())
  1349. {
  1350. //#main data attribute used to calculate scroll offset
  1351. $modifier = 0;
  1352.  
  1353. if(empty($header))
  1354. {
  1355. $header['header_position'] = avia_get_option('header_position','header_top');
  1356. $header['header_size'] = avia_get_option('header_size');
  1357. $header['header_custom_size'] = avia_get_option('header_custom_size');
  1358. $header['header_style'] = avia_get_option('header_style');
  1359. }
  1360.  
  1361. if("minimal_header" == $header['header_style']) $modifier = 2;
  1362.  
  1363. switch($header['header_size'])
  1364. {
  1365. case 'large': $header['header_scroll_offset'] = 116; break;
  1366. case 'custom': $header['header_scroll_offset'] = $header['header_custom_size'] - $modifier; break;
  1367. default : $header['header_scroll_offset'] = 88; break;
  1368. }
  1369.  
  1370. if($header['header_position'] != 'header_top') $header['header_scroll_offset'] = 0;
  1371.  
  1372. return $header['header_scroll_offset'];
  1373. }
  1374. }
  1375.  
  1376. if(!function_exists('avia_header_class_string'))
  1377. {
  1378. function avia_header_class_string($necessary = array() , $prefix = "html_"){
  1379.  
  1380. if(empty($necessary)) $necessary = array( 'header_position',
  1381. 'header_layout',
  1382. 'header_size',
  1383. 'header_sticky',
  1384. 'header_shrinking',
  1385. 'header_topbar',
  1386. 'header_transparency',
  1387. 'header_mobile_activation',
  1388. 'header_searchicon',
  1389. 'layout_align_content',
  1390. 'header_unstick_top',
  1391. 'header_stretch',
  1392. 'header_style',
  1393. 'blog_global_style',
  1394. 'menu_display',
  1395. 'submenu_visibility',
  1396. 'overlay_style',
  1397. 'alternate_menu',
  1398. 'submenu_clone',
  1399.  
  1400. );
  1401.  
  1402. $settings = avia_header_setting();
  1403. $class = array();
  1404. $post_id = function_exists('avia_get_the_id') ? avia_get_the_id() : get_the_ID();
  1405.  
  1406. foreach($necessary as $class_name)
  1407. {
  1408. if(!empty($settings[$class_name]))
  1409. {
  1410. $result = array_filter(explode(' ', $settings[$class_name]));
  1411. $class = array_merge($class, $result);
  1412. }
  1413. }
  1414.  
  1415. if($post_id) $class[] = "entry_id_".$post_id;
  1416. if(is_admin_bar_showing()) $class[] = "av_admin_bar_active";
  1417.  
  1418.  
  1419.  
  1420. $class = apply_filters('avf_header_classes', $class, $necessary, $prefix);
  1421.  
  1422. if(!empty($class))
  1423. {
  1424. $class = array_unique($class);
  1425. $class = " ".$prefix.implode(" ".$prefix, $class);
  1426. }
  1427.  
  1428.  
  1429. return $class;
  1430. }
  1431. }
  1432.  
  1433.  
  1434.  
  1435. if(!function_exists('avia_blog_class_string'))
  1436. {
  1437. function avia_blog_class_string($necessary = array() , $prefix = "av-"){
  1438.  
  1439. if(empty($necessary)) $necessary = array( 'blog-meta-author',
  1440. 'blog-meta-comments',
  1441. 'blog-meta-category',
  1442. 'blog-meta-date',
  1443. 'blog-meta-html-info',
  1444. 'blog-meta-tag',
  1445. );
  1446. $class = array();
  1447. $settings = avia_get_option();
  1448.  
  1449. foreach($necessary as $class_name)
  1450. {
  1451. if(isset($settings[$class_name]) && $settings[$class_name] == "disabled") $class[] = $class_name."-disabled";
  1452. }
  1453.  
  1454. if(empty($class)) $class = "";
  1455. if(!empty($class))
  1456. {
  1457. $class = array_unique($class);
  1458. if(!empty($class[0]))
  1459. {
  1460. $class = " ".$prefix.implode(" ".$prefix, $class);
  1461. }
  1462. else
  1463. {
  1464. $class = "";
  1465. }
  1466. }
  1467.  
  1468.  
  1469. return $class;
  1470. }
  1471. }
  1472.  
  1473.  
  1474.  
  1475. if(!function_exists('avia_header_html_custom_height'))
  1476. {
  1477. function avia_header_html_custom_height()
  1478. {
  1479. $settings = avia_header_setting();
  1480.  
  1481. if($settings['header_size'] == "custom")
  1482. {
  1483. $modifier = 0;
  1484. $size = $settings['header_custom_size'];
  1485. $bottom_bar = $settings['bottom_menu'] == true ? 52 : 0;
  1486. $top_bar = $settings['header_topbar'] == true ? 30 : 0;
  1487.  
  1488. if(!empty($settings['header_style']) && "minimal_header" == $settings['header_style'] ){ $modifier = 2;}
  1489.  
  1490.  
  1491. $html = "";
  1492. $html .= "\n<style type='text/css' media='screen'>\n";
  1493. $html .= " #top #header_main > .container, #top #header_main > .container .main_menu .av-main-nav > li > a,";
  1494. $html .= " #top #header_main #menu-item-shop .cart_dropdown_link{ height:{$size}px; line-height: {$size}px; }\n";
  1495. $html .= " .html_top_nav_header .av-logo-container{ height:{$size}px; }\n";
  1496. $html .= " .html_header_top.html_header_sticky #top #wrap_all #main{ padding-top:".((int)$size + $bottom_bar + $top_bar - $modifier)."px; } \n";
  1497. $html .= "</style>\n";
  1498.  
  1499. echo $html;
  1500. }
  1501.  
  1502. }
  1503.  
  1504. add_action('wp_head', 'avia_header_html_custom_height');
  1505.  
  1506. }
  1507.  
  1508.  
  1509. /*
  1510. * Display sidebar widgets in the main navigation area when it is set as sidebar instead of top
  1511. */
  1512. if(!function_exists('avia_sidebar_menu_additions'))
  1513. {
  1514. function avia_sidebar_menu_additions()
  1515. {
  1516. $settings = avia_header_setting();
  1517. $output = "";
  1518.  
  1519. if($settings['header_position'] != "header_top")
  1520. {
  1521. /*add social icons*/
  1522. if($settings['sidebarmenu_social'] != "disabled")
  1523. {
  1524. $social_args = array('outside'=>'ul', 'inside'=>'li', 'append' => '');
  1525. $social = avia_social_media_icons($social_args, false);
  1526. if($social) $output .= "<div class='av-sidebar-social-container'>".$social."</div>";
  1527. }
  1528.  
  1529.  
  1530. /*add widgets*/
  1531. if(!empty( $settings['sidebarmenu_widgets']))
  1532. {
  1533. if('av-auto-widget-logic' == $settings['sidebarmenu_widgets'])
  1534. {
  1535.  
  1536. }
  1537. else if( is_dynamic_sidebar( $settings['sidebarmenu_widgets'] ) )
  1538. {
  1539. ob_start();
  1540. dynamic_sidebar( $settings['sidebarmenu_widgets'] );
  1541. $output .= ob_get_clean();
  1542. $output = "<aside class='avia-custom-sidebar-widget-area sidebar sidebar_right'>".$output."</aside>";
  1543. }
  1544. }
  1545. }
  1546.  
  1547. echo $output;
  1548.  
  1549. }
  1550.  
  1551. add_action('ava_after_main_menu', 'avia_sidebar_menu_additions');
  1552.  
  1553. }
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559. /*
  1560. * Display a subnavigation for pages that is automatically generated, so the users doesnt need to work with widgets
  1561. */
  1562. if(!function_exists('avia_sidebar_menu'))
  1563. {
  1564. function avia_sidebar_menu($echo = true)
  1565. {
  1566. $sidebar_menu = "";
  1567.  
  1568. $subNav = avia_get_option('page_nesting_nav');
  1569.  
  1570.  
  1571. $the_id = @get_the_ID();
  1572. $args = array();
  1573. global $post;
  1574.  
  1575. if($subNav && $subNav != 'disabled' && !empty($the_id) && is_page())
  1576. {
  1577. $subNav = false;
  1578. $parent = $post->ID;
  1579. $sidebar_menu = "";
  1580.  
  1581. if (!empty($post->post_parent))
  1582. {
  1583. if(isset($post->ancestors)) $ancestors = $post->ancestors;
  1584. if(!isset($ancestors)) $ancestors = get_post_ancestors($post->ID);
  1585. $root = count($ancestors)-1;
  1586. $parent = $ancestors[$root];
  1587. }
  1588.  
  1589. $args = array('title_li'=>'', 'child_of'=>$parent, 'echo'=>0, 'sort_column'=>'menu_order, post_title');
  1590.  
  1591. //enables user to change query args
  1592. $args = apply_filters('avia_sidebar_menu_args', $args, $post);
  1593.  
  1594. //hide or show child pages in menu - if the class is set to 'widget_nav_hide_child' the child pages will be hidden
  1595. $display_child_pages = apply_filters('avia_sidebar_menu_display_child', 'widget_nav_hide_child', $args, $post);
  1596.  
  1597. $children = wp_list_pages($args);
  1598.  
  1599. if ($children)
  1600. {
  1601. $default_sidebar = false;
  1602. $sidebar_menu .= "<nav class='widget widget_nav_menu $display_child_pages'><ul class='nested_nav'>";
  1603. $sidebar_menu .= $children;
  1604. $sidebar_menu .= "</ul></nav>";
  1605. }
  1606. }
  1607.  
  1608. $sidebar_menu = apply_filters('avf_sidebar_menu_filter', $sidebar_menu, $args, $post);
  1609.  
  1610. if($echo == true) { echo $sidebar_menu; } else { return $sidebar_menu; }
  1611. }
  1612. }
  1613.  
  1614.  
  1615.  
  1616. /*
  1617. show tag archive page for post type - without this code you'll get 404 errors: http://wordpress.org/support/topic/custom-post-type-tagscategories-archive-page
  1618. */
  1619. if(!function_exists('avia_fix_tag_archive_page'))
  1620. {
  1621. function avia_fix_tag_archive_page($query)
  1622. {
  1623. $post_types = get_post_types();
  1624.  
  1625. if ( is_category() || is_tag())
  1626. {
  1627. if(!is_admin() && $query->is_main_query() )
  1628. {
  1629. $post_type = get_query_var(get_post_type());
  1630.  
  1631. if ($post_type) {
  1632. $post_type = $post_type;
  1633. } else {
  1634. $post_type = $post_types;
  1635. }
  1636. $query->set('post_type', $post_type);
  1637. }
  1638. }
  1639.  
  1640.  
  1641. return $query;
  1642. }
  1643. add_filter('pre_get_posts', 'avia_fix_tag_archive_page');
  1644. }
  1645.  
  1646.  
  1647.  
  1648. /*
  1649. * add html5.js script to head section - required for IE compatibility
  1650. */
  1651. if(!function_exists('avia_print_html5_js_script'))
  1652. {
  1653. add_action('wp_head', 'avia_print_html5_js_script');
  1654.  
  1655. function avia_print_html5_js_script()
  1656. {
  1657. $template_url = get_template_directory_uri();
  1658. $output = '';
  1659.  
  1660. $output .= '<!--[if lt IE 9]>';
  1661. $output .= '<script src="'.$template_url.'/js/html5shiv.js"></script>';
  1662. $output .= '<![endif]-->';
  1663. echo $output;
  1664. }
  1665. }
  1666.  
  1667.  
  1668. if(!function_exists('avia_add_compat_header'))
  1669. {
  1670. add_filter('wp_headers', 'avia_add_compat_header');
  1671. function avia_add_compat_header($headers)
  1672. {
  1673. if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)
  1674. {
  1675. $headers['X-UA-Compatible'] = 'IE=edge,chrome=1';
  1676. }
  1677. return $headers;
  1678. }
  1679. }
  1680.  
  1681.  
  1682. if( ! function_exists( 'avia_add_hide_featured_image_select' ) )
  1683. {
  1684. /**
  1685. * Add a selectbox to hide featured image on single post
  1686. *
  1687. * @param array $elements
  1688. * @return array
  1689. */
  1690. function avia_add_hide_featured_image_select( array $elements )
  1691. {
  1692. if( ! is_admin() || ! function_exists( 'get_current_screen' ) )
  1693. {
  1694. return $elements;
  1695. }
  1696.  
  1697. $screen = get_current_screen();
  1698. if( ! $screen instanceof WP_Screen )
  1699. {
  1700. return $elements;
  1701. }
  1702.  
  1703. $hide_pt = apply_filters( 'avf_display_featured_image_posttypes', array( 'post', 'portfolio' ) );
  1704.  
  1705. if( ! in_array( $screen->post_type, $hide_pt ) )
  1706. {
  1707. return $elements;
  1708. }
  1709.  
  1710. switch( $screen->post_type )
  1711. {
  1712. case 'post':
  1713. $desc = __( 'Select to display featured image for a single post entry.', 'avia_framework' );
  1714. break;
  1715. case 'portfolio':
  1716. $desc = __( 'Select to display featured image for a single portfolio entry.', 'avia_framework' );
  1717. break;
  1718. default:
  1719. $desc = apply_filters( 'avf_display_featured_image_desc', __( 'Select to display featured image for a single entry.', 'avia_framework' ) );
  1720. break;
  1721. }
  1722.  
  1723. $elements[] = array(
  1724. 'slug' => 'layout',
  1725. 'name' => __( 'Featured Image', 'avia_framework' ),
  1726. 'desc' => $desc,
  1727. 'id' => '_avia_hide_featured_image',
  1728. 'type' => 'select',
  1729. 'std' => '',
  1730. 'class' => 'avia-style',
  1731. 'subtype' => array(
  1732. __( 'Show on single entry', 'avia_framework' ) => '',
  1733. __( 'Hide on single entry', 'avia_framework' ) => '1'
  1734. )
  1735. );
  1736.  
  1737. return $elements;
  1738. }
  1739.  
  1740. add_filter( 'avf_builder_elements', 'avia_add_hide_featured_image_select', 10, 1 );
  1741. }
  1742.  
  1743. if(!function_exists('avia_active_caching'))
  1744. {
  1745. function avia_active_caching()
  1746. {
  1747. if(defined('W3TC') || defined('WPCACHEHOME') || class_exists('HyperCache') || class_exists('\\quick_cache\\plugin'))
  1748. {
  1749. return true;
  1750. }
  1751. return false;
  1752. }
  1753. }
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759. if(!function_exists('avia_menu_button_style'))
  1760. {
  1761. add_action('wp_nav_menu_item_custom_fields', 'avia_menu_button_style', 10, 4);
  1762.  
  1763. function avia_menu_button_style($output, $item, $depth, $args)
  1764. {
  1765. $item_id = $item->ID;
  1766. $key = "style";
  1767. $name = "menu-item-avia-".$key; //name prefix must be the same for all items
  1768. $value = get_post_meta( $item->ID, '_'.$name, true);
  1769. ?>
  1770.  
  1771. <!-- *************** start conditional logic input fields *************** -->
  1772. <p class="field-avia-link-style description description-wide avia_mega_menu avia_mega_menu_d0">
  1773. <label for="<?php echo $key; ?>">
  1774. <?php _e( 'Menu Style' ); ?><br />
  1775. <select id="<?php echo $name . "-". $item_id;?>" class="widefat edit-menu-item-target" name="<?php echo $name . "[". $item_id ."]";?>">
  1776. <option value="" <?php selected( $value, ''); ?> ><?php _e('Default Style'); ?> </option>
  1777. <option value="av-menu-button av-menu-button-colored" <?php selected( $value, 'av-menu-button av-menu-button-colored'); ?> ><?php _e('Button Style (Colored)' ); ?> </option>
  1778. <option value="av-menu-button av-menu-button-bordered" <?php selected( $value, 'av-menu-button av-menu-button-bordered'); ?> ><?php _e('Button Style (Bordered)'); ?> </option>
  1779. </select>
  1780. </label>
  1781. </p>
  1782.  
  1783. <?php
  1784.  
  1785.  
  1786. }
  1787.  
  1788. add_filter('avf_mega_menu_post_meta_fields','avia_menu_button_style_save',10,3);
  1789. function avia_menu_button_style_save($check, $menu_id, $menu_item_db)
  1790. {
  1791. $check = array_merge($check, array('style'));
  1792. return $check;
  1793. }
  1794.  
  1795.  
  1796. }
  1797. if(!function_exists('avia_generate_grid_dimension'))
  1798. {
  1799. add_action('ava_generate_styles','avia_generate_grid_dimension', 30, 3); /*after theme update*/
  1800.  
  1801. function avia_generate_grid_dimension($options, $color_set, $styles)
  1802. {
  1803. global $avia_config;
  1804. if ( $options !== "" ){ extract($options); }
  1805.  
  1806. if(empty($content_width)) $content_width = 73;
  1807. if(empty($combined_width)) $combined_width = 100;
  1808. if(empty($responsive_size)) $responsive_size = "1130px";
  1809.  
  1810. if($responsive_size != "")
  1811. {
  1812. $avia_config['style'][] = array(
  1813. 'key' => 'direct_input',
  1814. 'value' => ".container {width:".$combined_width."%;} .container .av-content-small.units {width:".$content_width."%; }
  1815.  
  1816. .responsive .boxed#top , .responsive.html_boxed.html_header_sticky #header,
  1817. .responsive.html_boxed.html_header_transparency #header{ width: ".$responsive_size."; max-width:90%; }
  1818. .responsive .container{ max-width: ".$responsive_size."; }
  1819. "
  1820. );
  1821. }
  1822. }
  1823. }
  1824.  
  1825.  
  1826.  
  1827. /*
  1828. function that disables the alb drag and drop for non admins
  1829. */
  1830.  
  1831. if( ! function_exists( 'avia_disable_alb_drag_drop' ) )
  1832. {
  1833. function avia_disable_alb_drag_drop( $disable )
  1834. {
  1835. if( ! current_user_can( 'switch_themes' ) || avia_get_option( 'lock_alb_for_admins', 'disabled' ) != 'disabled' )
  1836. {
  1837. $disable = avia_get_option( 'lock_alb', 'disabled' ) != 'disabled' ? true : false;
  1838. }
  1839.  
  1840. return $disable;
  1841. }
  1842.  
  1843. add_filter( 'avf_allow_drag_drop', 'avia_disable_alb_drag_drop', 30, 1 );
  1844. }
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852. /*
  1853. function to display frame
  1854. */
  1855.  
  1856. if(!function_exists('avia_framed_layout'))
  1857. {
  1858. function avia_framed_layout($options, $color_set, $styles)
  1859. {
  1860. global $avia_config;
  1861. extract($styles);
  1862.  
  1863. if(isset($body_style) && $body_style === "av-framed-box")
  1864. {
  1865. $avia_config['style'][] = array(
  1866. 'key' => 'direct_input',
  1867. 'value' => "
  1868.  
  1869. html.html_av-framed-box{ padding:{$frame_width}px; }
  1870. html.html_av-framed-box{ padding:{$frame_width}px; }
  1871. html.html_av-framed-box .av-frame{ width: {$frame_width}px; height: {$frame_width}px; background:$body_color;}
  1872.  
  1873.  
  1874. .html_header_top.html_header_sticky.html_av-framed-box #header_main,
  1875. .html_header_top.html_header_sticky.html_av-framed-box #header_meta{
  1876. margin:0 {$frame_width}px;
  1877. }
  1878.  
  1879. html .avia-post-prev{left: {$frame_width}px; }
  1880. html .avia-post-next{right:{$frame_width}px; }
  1881.  
  1882. html.html_av-framed-box.html_av-overlay-side .av-burger-overlay-scroll{ right:{$frame_width}px; }
  1883. "
  1884. );
  1885. }
  1886. }
  1887.  
  1888. add_action('ava_generate_styles', 'avia_framed_layout', 40 , 3);
  1889. }
  1890.  
  1891. if(!function_exists('avia_framed_layout_bars'))
  1892. {
  1893. function avia_framed_layout_bars()
  1894. {
  1895. if( avia_get_option('color-body_style') == "av-framed-box" )
  1896. {
  1897. $output = "";
  1898. $output .= "<div class='av-frame av-frame-top av-frame-vert'></div>";
  1899. $output .= "<div class='av-frame av-frame-bottom av-frame-vert'></div>";
  1900. $output .= "<div class='av-frame av-frame-left av-frame-hor'></div>";
  1901. $output .= "<div class='av-frame av-frame-right av-frame-hor'></div>";
  1902.  
  1903. echo $output;
  1904. }
  1905. }
  1906.  
  1907. add_action('wp_footer', 'avia_framed_layout_bars', 10 );
  1908. }
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917. /*
  1918. function that saves the style options array into an external css file rather than fetching the data from the database
  1919. */
  1920.  
  1921. if(!function_exists('avia_generate_stylesheet'))
  1922. {
  1923. add_action('ava_after_theme_update', 'avia_generate_stylesheet', 30, 1); /*after theme update*/
  1924. add_action('ava_after_import_demo_settings', 'avia_generate_stylesheet', 30, 1); /*after demo settings imoport*/
  1925. add_action('avia_ajax_after_save_options_page', 'avia_generate_stylesheet', 30, 1); /*after options page saving*/
  1926.  
  1927. function avia_generate_stylesheet($options = false)
  1928. {
  1929. global $avia;
  1930.  
  1931. $safe_name = avia_backend_safe_string($avia->base_data['prefix']);
  1932. $safe_name = apply_filters('avf_dynamic_stylesheet_filename', $safe_name);
  1933.  
  1934. if( defined('AVIA_CSSFILE') && AVIA_CSSFILE === false )
  1935. {
  1936. $dir_flag = update_option( 'avia_stylesheet_dir_writable'.$safe_name, 'false' );
  1937. $stylesheet_flag = update_option( 'avia_stylesheet_exists'.$safe_name, 'false' );
  1938. return;
  1939. }
  1940.  
  1941. $wp_upload_dir = wp_upload_dir();
  1942. $stylesheet_dir = $wp_upload_dir['basedir'] . '/dynamic_avia';
  1943. $stylesheet_dir = str_replace('\\', '/', $stylesheet_dir);
  1944. $stylesheet_dir = apply_filters('avia_dyn_stylesheet_dir_path', $stylesheet_dir);
  1945. $isdir = avia_backend_create_folder($stylesheet_dir);
  1946.  
  1947. /*
  1948. * directory could not be created (WP upload folder not writeable)
  1949. * @todo save error in db and output error message for user.
  1950. * @todo maybe add mkdirfix: http://php.net/manual/de/function.mkdir.php
  1951. */
  1952.  
  1953. if($isdir === false)
  1954. {
  1955. $dir_flag = update_option( 'avia_stylesheet_dir_writable'.$safe_name, 'false' );
  1956. $stylesheet_flag = update_option( 'avia_stylesheet_exists'.$safe_name, 'false' );
  1957. return;
  1958. }
  1959.  
  1960. /*
  1961. * Go ahead - WP managed to create the folder as expected
  1962. */
  1963. $stylesheet = trailingslashit( $stylesheet_dir ) . $safe_name.'.css';
  1964. $stylesheet = apply_filters('avia_dyn_stylesheet_file_path', $stylesheet);
  1965.  
  1966.  
  1967. //import avia_superobject and reset the options array
  1968. $avia_superobject = $GLOBALS['avia'];
  1969. $avia_superobject->reset_options();
  1970.  
  1971. //regenerate style array after saving options page so we can create a new css file that has the actual values and not the ones that were active when the script was called
  1972. avia_prepare_dynamic_styles();
  1973.  
  1974. //generate stylesheet content
  1975. $generate_style = new avia_style_generator($avia_superobject,false,false,false);
  1976. $styles = $generate_style->create_styles();
  1977.  
  1978. $created = avia_backend_create_file($stylesheet, $styles, true);
  1979.  
  1980. if($created === true)
  1981. {
  1982. $dir_flag = update_option( 'avia_stylesheet_dir_writable'.$safe_name, 'true' );
  1983. $stylesheet_flag = update_option( 'avia_stylesheet_exists'.$safe_name, 'true' );
  1984. $dynamic_id = update_option( 'avia_stylesheet_dynamic_version'.$safe_name, uniqid() );
  1985. }
  1986. else
  1987. {
  1988. $dir_flag = update_option( 'avia_stylesheet_dir_writable'.$safe_name, 'false' );
  1989. $stylesheet_flag = update_option( 'avia_stylesheet_exists'.$safe_name, 'false' );
  1990. $dynamic_id = delete_option( 'avia_stylesheet_dynamic_version'.$safe_name);
  1991. }
  1992. }
  1993. }
  1994.  
  1995.  
  1996.  
  1997. /*favicon in front and backend*/
  1998. add_action('wp_head', 'avia_add_favicon');
  1999. add_action('admin_head', 'avia_add_favicon');
  2000.  
  2001.  
  2002. function avia_add_favicon()
  2003. {
  2004. echo "\n".avia_favicon(avia_get_option('favicon'))."\n";
  2005. }
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012. /**
  2013. * AVIA Mailchimp WIDGET
  2014. */
  2015.  
  2016. if (!class_exists('avia_mailchimp_widget'))
  2017. {
  2018. class avia_mailchimp_widget extends WP_Widget {
  2019.  
  2020. static $script_loaded = 0;
  2021.  
  2022. function __construct() {
  2023. //Constructor
  2024. $widget_ops = array('classname' => 'avia_mailchimp_widget', 'description' => 'A widget that displays a Mailchimp newsletter signup form' );
  2025. parent::__construct( 'avia_mailchimp_widget', THEMENAME.' Mailchimp Newsletter Signup', $widget_ops );
  2026. }
  2027.  
  2028. function widget($args, $instance)
  2029. {
  2030. extract($args, EXTR_SKIP);
  2031. echo $before_widget;
  2032.  
  2033. if ( !empty( $instance['title'] ) ) { echo $before_title . $instance['title'] . $after_title; };
  2034.  
  2035. $shortcode = "[av_mailchimp";
  2036. $shortcode .= " list='".$instance['mailchimp_list']."'";
  2037. $shortcode .= " listonly='true'";
  2038. $shortcode .= " hide_labels='true'";
  2039. $shortcode .= " double_opt_in='".$instance['double_optin']."'";
  2040. $shortcode .= " sent='".$instance['success']."'";
  2041. $shortcode .= " button='".$instance['submit_label']."'";
  2042.  
  2043. $shortcode .= "]";
  2044.  
  2045.  
  2046. echo "<div class='av-mailchimp-widget av-mailchimp-widget-style-".$instance['styling']." '>";
  2047. echo do_shortcode($shortcode );
  2048. echo "</div>";
  2049.  
  2050. echo $after_widget;
  2051.  
  2052. }
  2053.  
  2054.  
  2055. function update($new_instance, $old_instance)
  2056. {
  2057. $instance = $old_instance;
  2058. $instance['title'] = strip_tags($new_instance['title']);
  2059. $instance['success'] = strip_tags($new_instance['success']);
  2060. $instance['styling'] = strip_tags($new_instance['styling']);
  2061. $instance['double_optin'] = strip_tags($new_instance['double_optin']);
  2062. $instance['mailchimp_list'] = strip_tags($new_instance['mailchimp_list']);
  2063. $instance['submit_label'] = strip_tags($new_instance['submit_label']);
  2064.  
  2065. return $instance;
  2066. }
  2067.  
  2068.  
  2069.  
  2070. function form($instance)
  2071. {
  2072. $instance = wp_parse_args( (array) $instance, array(
  2073. 'title' => __('Newsletter','avia_framework'),
  2074. 'mailchimp_list' => '',
  2075. 'styling' => '' ,
  2076. 'double_optin' => 'true',
  2077. 'success' => __('Thank you for subscribing to our newsletter!','avia_framework'),
  2078. 'submit_label' => __('Subscribe','avia_framework'),
  2079. )
  2080. );
  2081.  
  2082. $title = strip_tags($instance['title']);
  2083. $mailchimp_list = strip_tags($instance['mailchimp_list']);
  2084. $styling = strip_tags($instance['styling']);
  2085. $double_optin = strip_tags($instance['double_optin']);
  2086. $success = strip_tags($instance['success']);
  2087. $submit_label = strip_tags($instance['submit_label']);
  2088.  
  2089. $lists = get_option('av_chimplist');
  2090. $newlist = array('Select a Mailchimp list...' => "");
  2091.  
  2092. if(empty($lists))
  2093. {
  2094. return;
  2095. }
  2096.  
  2097. foreach($lists as $key => $list_item)
  2098. {
  2099. $newlist[$list_item['name']] = $key;
  2100. }
  2101. $lists = $newlist;
  2102.  
  2103. ?>
  2104. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title','avia_framework');?>:
  2105. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
  2106.  
  2107. <p>
  2108. <label for="<?php echo $this->get_field_id('mailchimp_list'); ?>"><?php _e('Mailchimp list to subscribe to','avia_framework');?></label>
  2109. <select class="widefat" id="<?php echo $this->get_field_id('mailchimp_list'); ?>" name="<?php echo $this->get_field_name('mailchimp_list'); ?>">
  2110. <?php
  2111. $list = "";
  2112.  
  2113. foreach ($lists as $answer => $key)
  2114. {
  2115. $selected = "";
  2116. if($key == $mailchimp_list) $selected = 'selected="selected"';
  2117.  
  2118. $list .= "<option $selected value='$key'>$answer</option>";
  2119. }
  2120. $list .= "</select>";
  2121. echo $list;
  2122. ?>
  2123.  
  2124.  
  2125. </p>
  2126.  
  2127.  
  2128. <p>
  2129. <label for="<?php echo $this->get_field_id('styling'); ?>"><?php _e('Signup Form Styling','avia_framework');?></label>
  2130. <select class="widefat" id="<?php echo $this->get_field_id('styling'); ?>" name="<?php echo $this->get_field_name('styling'); ?>">
  2131. <?php
  2132. $answers = array(
  2133.  
  2134. __('Default','avia_framework') => "",
  2135. __('Boxed','avia_framework') => "boxed_form",
  2136.  
  2137. );
  2138.  
  2139. $list = "";
  2140.  
  2141. foreach ($answers as $answer => $key)
  2142. {
  2143. $selected = "";
  2144. if($key == $styling) $selected = 'selected="selected"';
  2145.  
  2146. $list .= "<option $selected value='$key'>$answer</option>";
  2147. }
  2148. $list .= "</select>";
  2149. echo $list;
  2150. ?>
  2151. </p>
  2152.  
  2153. <p>
  2154. <label for="<?php echo $this->get_field_id('double_optin'); ?>"><?php _e('Activate double opt-in?','avia_framework');?></label>
  2155. <select class="widefat" id="<?php echo $this->get_field_id('double_optin'); ?>" name="<?php echo $this->get_field_name('double_optin'); ?>">
  2156. <?php
  2157. $answers = array(
  2158.  
  2159. __('Yes','avia_framework') => "true",
  2160. __('No','avia_framework') => "",
  2161.  
  2162. );
  2163.  
  2164. $list = "";
  2165.  
  2166. foreach ($answers as $answer => $key)
  2167. {
  2168. $selected = "";
  2169. if($key == $double_optin) $selected = 'selected="selected"';
  2170.  
  2171. $list .= "<option $selected value='$key'>$answer</option>";
  2172. }
  2173. $list .= "</select>";
  2174. echo $list;
  2175. ?>
  2176. </p>
  2177.  
  2178. <p><label for="<?php echo $this->get_field_id('success'); ?>"><?php _e('Message if user subscribes successfully','avia_framework');?>:
  2179. <input class="widefat" id="<?php echo $this->get_field_id('success'); ?>" name="<?php echo $this->get_field_name('success'); ?>" type="text" value="<?php echo esc_attr($success); ?>" /></label></p>
  2180.  
  2181. <p>
  2182.  
  2183. <p><label for="<?php echo $this->get_field_id('submit_label'); ?>"><?php _e('Submit Button Label','avia_framework');?>:
  2184. <input class="widefat" id="<?php echo $this->get_field_id('submit_label'); ?>" name="<?php echo $this->get_field_name('submit_label'); ?>" type="text" value="<?php echo esc_attr($submit_label); ?>" /></label></p>
  2185.  
  2186. <p>
  2187.  
  2188.  
  2189.  
  2190. <?php
  2191. }
  2192. }
  2193.  
  2194. register_widget( 'avia_mailchimp_widget' );
  2195. }
  2196.  
  2197. /**
  2198. * WP core hack see https://core.trac.wordpress.org/ticket/15551
  2199. *
  2200. * Paging does not work on single custom post type pages - always a redirect to page 1 by WP
  2201. *
  2202. *
  2203. * @since 4.0.6
  2204. */
  2205. if( ! function_exists( 'avia_wp_cpt_request_redirect_fix' ) )
  2206. {
  2207. function avia_wp_cpt_request_redirect_fix( $request )
  2208. {
  2209. $args = array(
  2210. 'public' => true,
  2211. '_builtin' => false
  2212. );
  2213.  
  2214. $cpts = get_post_types( $args, 'names', 'and' );
  2215.  
  2216. if ( isset( $request->query_vars['post_type'] ) &&
  2217. in_array( $request->query_vars['post_type'], $cpts ) &&
  2218. true === $request->is_singular &&
  2219. - 1 == $request->current_post &&
  2220. true === $request->is_paged
  2221. )
  2222. {
  2223. add_filter( 'redirect_canonical', '__return_false' );
  2224. }
  2225.  
  2226. return $request;
  2227. }
  2228.  
  2229. add_action( 'parse_query', 'avia_wp_cpt_request_redirect_fix' );
  2230. }
  2231.  
  2232.  
  2233.  
  2234. /**
  2235. * mobile sizes that overwrite elements default sizes
  2236. */
  2237. if( ! function_exists( 'av_print_custom_font_size' ) )
  2238. {
  2239. function av_print_custom_font_size( $request )
  2240. {
  2241. echo AviaHelper::av_print_mobile_sizes();
  2242. }
  2243.  
  2244. add_action( 'wp_footer', 'av_print_custom_font_size' );
  2245. }
  2246.  
  2247.  
  2248. /**
  2249. * disable element live preview
  2250. */
  2251. if( ! function_exists( 'av_disable_live_preview' ) )
  2252. {
  2253. function av_disable_live_preview( $data )
  2254. {
  2255. if(avia_get_option('preview_disable') == "preview_disable")
  2256. {
  2257. $data['preview'] = 0;
  2258. }
  2259.  
  2260. return $data;
  2261. }
  2262.  
  2263. add_filter( 'avb_backend_editor_element_data_filter', 'av_disable_live_preview' );
  2264. }
  2265.  
  2266.  
  2267. /**
  2268. * Adds a copyright field to the upload and edit dialogue of the media manager
  2269. *
  2270. * @author tinabillinger
  2271. * @since 4.3
  2272. */
  2273.  
  2274.  
  2275. if( ! function_exists( 'av_attachment_copyright_field_edit' ) )
  2276. {
  2277. function av_attachment_copyright_field_edit($form_fields, $post)
  2278. {
  2279.  
  2280. $form_fields['av_copyright_field'] = array(
  2281. 'label' => __('Copyright'),
  2282. 'input' => 'text',
  2283. 'value' => get_post_meta( $post->ID, '_avia_attachment_copyright', true ),
  2284. );
  2285.  
  2286. return $form_fields;
  2287. }
  2288. add_filter( 'attachment_fields_to_edit', 'av_attachment_copyright_field_edit', null, 2 );
  2289. }
  2290.  
  2291.  
  2292. /**
  2293. * Saves the copyright field created by filter above
  2294. *
  2295. * @author tinabillinger
  2296. * @since 4.3
  2297. */
  2298.  
  2299.  
  2300. if( ! function_exists( 'av_attachment_copyright_field_save' ) )
  2301. {
  2302. function av_attachment_copyright_field_save($post, $attachment)
  2303. {
  2304. if ( ! empty( $attachment['av_copyright_field'] ) )
  2305. {
  2306. update_post_meta( $post['ID'], '_avia_attachment_copyright', $attachment['av_copyright_field'] );
  2307. }
  2308. else {
  2309. delete_post_meta( $post['ID'], '_avia_attachment_copyright' );
  2310. }
  2311. return $post;
  2312. }
  2313.  
  2314. add_filter( 'attachment_fields_to_save', 'av_attachment_copyright_field_save', null, 2 );
  2315. }
  2316.  
  2317.  
  2318. /**
  2319. * Attaches the information from the copyright field to get_the_post_thumbnail()
  2320. * The added tag is initally hidden by CSS, and can be made visible by choice
  2321. *
  2322. * @author tinabillinger
  2323. * @since 4.3
  2324. */
  2325. /*
  2326. * Add 'copyright info to get_the_post_thumbnail()
  2327. */
  2328.  
  2329. if( ! function_exists( 'avia_post_thumbnail_html' ) )
  2330. {
  2331. function avia_post_thumbnail_html($html, $post_id, $post_thumbnail_id, $size, $attr)
  2332. {
  2333. $attachment_id = get_post_thumbnail_id($post_id);
  2334. $copyright_text = get_post_meta($attachment_id, '_avia_attachment_copyright', true );
  2335.  
  2336. if ($copyright_text) {
  2337. $html .= "<small class='avia-copyright'>{$copyright_text}</small>";
  2338. }
  2339. return $html;
  2340. }
  2341. if (! is_admin()){
  2342. add_filter('post_thumbnail_html', 'avia_post_thumbnail_html', 99, 5);
  2343. }
  2344. }
  2345.  
  2346.  
  2347. if( ! function_exists( 'av_builder_meta_box_elements_content' ) )
  2348. {
  2349. /**
  2350. * Adjust element content to reflect main option settings
  2351. * e.g. with sdding page as footer feature we need to adjust select box content of footer settings
  2352. *
  2353. * @since 4.2.7
  2354. * @added_by Günter
  2355. * @param array $elements
  2356. * @return array
  2357. */
  2358. function av_builder_meta_box_elements_content( array $elements )
  2359. {
  2360.  
  2361. $footer_options = avia_get_option( 'display_widgets_socket', 'all' );
  2362.  
  2363. if( false !== strpos( $footer_options, 'page' ) )
  2364. {
  2365. $desc = __( 'Display the footer page?', 'avia_framework' );
  2366. $subtype = array(
  2367. __("Default Layout - set in",'avia_framework')." ".THEMENAME." > ". __('Footer','avia_framework') => '',
  2368. __('Use selected page to display as footer and socket','avia_framework') => 'page_in_footer_socket',
  2369. __('Use selected page to display as footer (no socket)','avia_framework') => 'page_in_footer',
  2370. __('Don\'t display the socket & page','avia_framework') => 'nofooterarea'
  2371. );
  2372. }
  2373. else
  2374. {
  2375. $desc = __( 'Display the footer widgets?', 'avia_framework' );
  2376. $subtype = array(
  2377. __("Default Layout - set in",'avia_framework')." ".THEMENAME." > ". __('Footer','avia_framework') => '',
  2378. __('Display the footer widgets & socket','avia_framework') => 'all',
  2379. __('Display only the footer widgets (no socket)','avia_framework') => 'nosocket',
  2380. __('Display only the socket (no footer widgets)','avia_framework') => 'nofooterwidgets',
  2381. __('Don\'t display the socket & footer widgets','avia_framework') => 'nofooterarea'
  2382. );
  2383. }
  2384.  
  2385. foreach( $elements as &$element )
  2386. {
  2387. if( 'footer' == $element['id'] )
  2388. {
  2389. $element['desc'] = $desc;
  2390. $element['subtype'] = $subtype;
  2391. }
  2392. }
  2393.  
  2394. return $elements;
  2395. }
  2396.  
  2397. add_filter( 'avf_builder_elements', 'av_builder_meta_box_elements_content', 10000, 1 );
  2398. }
  2399.  
  2400.  
  2401. if( ! function_exists( 'av_return_100' ) )
  2402. {
  2403. /**
  2404. * Sets the default image to 100% quality for more beautiful images when used in conjunction with img optimization plugins
  2405. *
  2406. * @since 4.3
  2407. * @added_by Kriesi
  2408. */
  2409. function av_return_100(){ return 100; }
  2410. add_filter('jpeg_quality', 'av_return_100');
  2411. add_filter('wp_editor_set_quality', 'av_return_100');
  2412. }
  2413.  
  2414.  
  2415. /**
  2416. * Comment form order
  2417. * Restore comment form order to look like previous versions were comment field is below name/mail/website
  2418. *
  2419. * @author Kriesi
  2420. * @since 4.5
  2421. */
  2422.  
  2423. if( ! function_exists( 'av_comment_field_order_reset' ) )
  2424. {
  2425. function av_comment_field_order_reset( $fields )
  2426. {
  2427. $comment_field = $fields['comment'];
  2428. unset( $fields['comment'] );
  2429. $fields['comment'] = $comment_field;
  2430. return $fields;
  2431. }
  2432.  
  2433. add_filter( 'comment_form_fields', 'av_comment_field_order_reset' );
  2434. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement