Guest User

Untitled

a guest
Dec 2nd, 2020
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 62.99 KB | None | 0 0
  1. <?php
  2. /**
  3. * This file holds various helper functions that are needed by the frameworks FRONTEND
  4. *
  5. * @author Christian "Kriesi" Budschedl
  6. * @copyright Copyright (c) Christian Budschedl
  7. * @link http://kriesi.at
  8. * @link http://aviathemes.com
  9. * @since Version 1.0
  10. * @package AviaFramework
  11. */
  12. if ( ! defined( 'AVIA_FW' ) ) { exit( 'No direct script access allowed' ); }
  13.  
  14.  
  15. if( ! function_exists( 'avia_option' ) )
  16. {
  17. /**
  18. * This function serves as shortcut for avia_get_option and is used to retrieve options saved within the database with the first key set to "avia" which is the majority of all options
  19. * Please note that while the get_avia_option returns the result, this function echos it by default. if you want to retrieve an option and store the variable please use get_avia_option or set $echo to false
  20. *
  21. * basically the function is called like this: avia_option('portfolio');
  22. * That would retrieve the following var saved in the global $avia superobject: $avia->options['avia']['portfolio']
  23. * If you want to set a default value that is returned in case there was no array match you need to use this scheme:
  24. *
  25. * avia_option( 'portfolio', "my default");
  26. *
  27. * @param string $key accepts a comma separated string with keys
  28. * @param string $default return value in case we got no result
  29. * @param bool $echo echo the result or not, default is to false
  30. * @param bool $decode decode the result or not, default is to false
  31. * @return string $result: the saved result. if no result was saved or the key doesnt exist returns an empty string
  32. */
  33. function avia_option( $key, $default = '', $echo = true, $decode = true )
  34. {
  35. $result = avia_get_option( $key, $default, false, $decode );
  36.  
  37. if( ! $echo)
  38. {
  39. return $result; //if we dont want to echo the output end script here
  40. }
  41.  
  42. echo $result;
  43. }
  44. }
  45.  
  46.  
  47.  
  48. if( ! function_exists( 'avia_get_option' ) )
  49. {
  50. /**
  51. * This function serves as shortcut to retrieve options saved within the database by the option pages of the avia framework
  52. *
  53. * basically the function is called like this: avia_get_option('portfolio');
  54. * That would retrieve the following var saved in the global $avia superobject: $avia->options['avia']['portfolio']
  55. * If you want to set a default value that is returned in case there was no array match you need to use this scheme:
  56. *
  57. * avia_get_option('portfolio', "my default"); or
  58. * avia_get_option(array('avia','portfolio'), "my default");
  59. *
  60. * @since 4.8 support for multiple option pages
  61. * @param string|array|false $key accepts a comma separated string with keys
  62. * @param string $default return value in case we got no result
  63. * @param bool $echo echo the result or not, default is to false
  64. * @param bool $decode decode the result or not, default is to false
  65. * @return string the saved result. if no result was saved or the key doesnt exist returns an empty string
  66. */
  67. function avia_get_option( $key = false, $default = '', $echo = false, $decode = true )
  68. {
  69. global $avia;
  70.  
  71. /**
  72. * This fixed a problem with WP CLI: wp cache flush
  73. *
  74. * Trying to get property of non-object $avia
  75. *
  76. * Adding global $avia; to framework\avia_framework.php did the final solution - we keep this for a fallback only.
  77. */
  78. if( ! $avia instanceof avia_superobject )
  79. {
  80. $avia = AviaSuperobject();
  81. }
  82.  
  83. $pages = array();
  84. $opt_key = '';
  85. $result = null;
  86.  
  87. if( false === $key )
  88. {
  89. // Return 'avia' page array
  90. $result = isset( $avia->options['avia'] ) ? $avia->options['avia'] : array();
  91. }
  92. else if( is_array( $key ) && count( $key ) == 1 )
  93. {
  94. // @since 4.8 return requested page array
  95. $result = isset( $avia->options[ $key[0] ] ) ? $avia->options[ $key[0] ] : array();
  96. }
  97. else
  98. {
  99. if( is_array( $key ) )
  100. {
  101. $pages[] = isset( $key[0] ) ? $key[0] : '';
  102. $opt_key = isset( $key[1] ) ? $key[1] : '';
  103. }
  104. else
  105. {
  106. // force avia to be the main array to search for option
  107. $pages[] = 'avia';
  108. $pages = array_unique( array_merge( $pages, array_keys( $avia->options ) ) );
  109. $opt_key = $key;
  110. }
  111.  
  112. // Scan all pages for option
  113. foreach( $pages as $page )
  114. {
  115. if( isset( $avia->options[ $page ] ) && isset( $avia->options[ $page ][ $opt_key ] ) )
  116. {
  117. $result = $avia->options[ $page ][ $opt_key ];
  118. break;
  119. }
  120. }
  121.  
  122. if( is_null( $result ) )
  123. {
  124. $result = $default;
  125. }
  126. }
  127.  
  128. if( $decode )
  129. {
  130. $result = avia_deep_decode( $result );
  131. }
  132.  
  133. if( $echo )
  134. {
  135. echo $result;
  136. }
  137.  
  138. return $result;
  139. }
  140. }
  141.  
  142.  
  143. if( ! function_exists( 'avia_update_option' ) )
  144. {
  145. /**
  146. * This function serves as shortcut to update a single theme option
  147. *
  148. * @param string $key
  149. * @param mixed $value
  150. */
  151. function avia_update_option( $key, $value = '' )
  152. {
  153. global $avia;
  154.  
  155. $avia->options['avia'][ $key ] = $value;
  156. update_option( $avia->option_prefix , $avia->options );
  157. }
  158. }
  159.  
  160.  
  161. if( ! function_exists( 'avia_delete_option' ) )
  162. {
  163. /**
  164. * This function serves as shortcut to delete a single theme option
  165. *
  166. * @param string $key
  167. */
  168. function avia_delete_option( $key )
  169. {
  170. global $avia;
  171.  
  172. unset( $avia->options['avia'][ $key ] );
  173. update_option( $avia->option_prefix , $avia->options );
  174. }
  175. }
  176.  
  177.  
  178.  
  179. if( ! function_exists( 'avia_get_the_ID' ) )
  180. {
  181. /**
  182. * This function is similiar to the wordpress function get_the_ID, but other than the wordpress function this functions takes into account
  183. * if we will display a different post later on, a post that differs from the one we queried in the first place. The function also holds this
  184. * original ID, even if another query is then executed (for example in dynamic templates for columns)
  185. *
  186. * an example would be the frontpage template were by default, the ID of the latest blog post is served by wordpress get_the_ID function.
  187. * avia_get_the_ID would return the same blog post ID if the blog is really displayed on the frontpage. if a static page is displayed the
  188. * function will display the ID of the static page, even if the page is not yet queried
  189. *
  190. * @return int $ID: the "real" ID of the post/page we are currently viewing
  191. */
  192. function avia_get_the_ID()
  193. {
  194. global $avia_config;
  195. $ID = false;
  196.  
  197. if(!isset($avia_config['real_ID']))
  198. {
  199. if(!empty($avia_config['new_query']['page_id']))
  200. {
  201. $ID = $avia_config['new_query']['page_id'];
  202. $avia_config['real_ID'] = $ID;
  203. }
  204. else
  205. {
  206. $post = get_post();
  207. if(isset($post->ID))
  208. {
  209. $ID = $post->ID;
  210. $avia_config['real_ID'] = $ID;
  211. }
  212. else
  213. {
  214. $ID = false;
  215. }
  216. //$ID = @get_the_ID();
  217. }
  218. }
  219. else
  220. {
  221. $ID = $avia_config['real_ID'];
  222. }
  223.  
  224. $ID = apply_filters('avf_avia_get_the_ID', $ID);
  225.  
  226. return $ID;
  227. }
  228.  
  229. add_action('wp_head', 'avia_get_the_ID');
  230. }
  231.  
  232.  
  233. if(!function_exists('avia_is_overview'))
  234. {
  235. /**
  236. * This function checks if the page we are going to render is a page with a single entry or a multi entry page (blog or archive for example)
  237. *
  238. * @return bool $result true or false
  239. */
  240.  
  241. function avia_is_overview()
  242. {
  243. global $avia_config;
  244. $result = true;
  245.  
  246. if (is_singular())
  247. {
  248. $result = false;
  249. }
  250.  
  251. if(is_front_page() && avia_get_option('frontpage') == avia_get_the_ID())
  252. {
  253. $result = false;
  254. }
  255.  
  256. if (isset($avia_config['avia_is_overview']))
  257. {
  258. $result = $avia_config['avia_is_overview'];
  259. }
  260.  
  261. return $result;
  262. }
  263. }
  264.  
  265. if(!function_exists('avia_is_dynamic_template'))
  266. {
  267. /**
  268. * This function checks if the page we are going to render is using a dynamic template
  269. *
  270. * @return bool $result true or false
  271. */
  272.  
  273. function avia_is_dynamic_template($id = false, $dependency = false)
  274. {
  275. $result = false;
  276. if(!$id) $id = avia_get_the_ID();
  277. if(!$id) return $result;
  278.  
  279. if($dependency)
  280. {
  281. if(avia_post_meta($id, $dependency[0]) != $dependency[1])
  282. {
  283. return false;
  284. }
  285. }
  286.  
  287. if($template = avia_post_meta($id, 'dynamic_templates'))
  288. {
  289. $result = $template;
  290. }
  291.  
  292. return $result;
  293. }
  294. }
  295.  
  296.  
  297.  
  298. if(!function_exists('avia_post_meta'))
  299. {
  300. /**
  301. * This function retrieves the custom field values for a given post and saves it to the global avia config array
  302. * If a subkey was set the subkey is returned, otherwise the array is saved to the global config array
  303. * The function also hooks into the post loop and is automatically called for each post
  304. */
  305. function avia_post_meta($post_id = '', $subkey = false)
  306. {
  307. $avia_post_id = $post_id;
  308.  
  309. //if the user only passed a string and no id the string will be used as subkey
  310. if(!$subkey && $avia_post_id != '' && !is_numeric($avia_post_id) && !is_object($avia_post_id))
  311. {
  312. $subkey = $avia_post_id;
  313. $avia_post_id = '';
  314. }
  315.  
  316. global $avia, $avia_config;
  317. $key = '_avia_elements_'.$avia->option_prefix;
  318. if(current_theme_supports( 'avia_post_meta_compat' ))
  319. {
  320. $key = '_avia_elements_theme_compatibility_mode'; //actiavates a compatibility mode for easier theme switching and keeping post options
  321. }
  322. $values = '';
  323.  
  324. //if post id is on object the function was called via hook. If thats the case reset the meta array
  325. if(is_object($avia_post_id) && isset($avia_post_id->ID))
  326. {
  327. $avia_post_id = $avia_post_id->ID;
  328. }
  329.  
  330.  
  331. if(!$avia_post_id)
  332. {
  333. $avia_post_id = @get_the_ID();
  334. }
  335.  
  336. if(!is_numeric($avia_post_id)) return;
  337.  
  338.  
  339. $avia_config['meta'] = avia_deep_decode(get_post_meta($avia_post_id, $key, true));
  340. $avia_config['meta'] = apply_filters('avia_post_meta_filter', $avia_config['meta'], $avia_post_id);
  341.  
  342. if($subkey && isset($avia_config['meta'][$subkey]))
  343. {
  344. $meta = $avia_config['meta'][$subkey];
  345. }
  346. else if($subkey)
  347. {
  348. $meta = false;
  349. }
  350. else
  351. {
  352. $meta = $avia_config['meta'];
  353. }
  354.  
  355. return $meta;
  356. }
  357.  
  358. add_action( 'the_post', 'avia_post_meta' );
  359. }
  360.  
  361.  
  362.  
  363.  
  364. if( ! function_exists('avia_get_option_set' ) )
  365. {
  366. /**
  367. * This function serves as shortcut to retrieve option sets saved within the database by the option pages of the avia framework
  368. * An option set is a group of clone-able options like for example portfolio pages: you can create multiple portfolios and each
  369. * of them has a unique set of sub-options (for example column count, item count, etc)
  370. *
  371. * the function is called like this: avia_get_option_set('option_key','suboption_key','suboption_value');
  372. * That would retrieve the following var saved in the global $avia superobject: $avia->options['avia']['portfolio']
  373. * Then, depending on the subkey and subkey value one of the arrays that were just fetched are passed.
  374. *
  375. * Example:
  376. * avia_get_option_set('portfolio', 'portfolio_page', get_the_ID())
  377. * This would get the portfolio group that has an item called 'portfolio_page' with the ID of the current post or page
  378. *
  379. * @param string $key accepts a string
  380. * @param string $subkey accepts a string
  381. * @param string $subkey_value accepts a string
  382. * @return array $result: the saved result. if no result was saved or the key doesnt exist returns an empty array
  383. */
  384. function avia_get_option_set( $key, $subkey = false, $subkey_value = false )
  385. {
  386. $result = array();
  387. $all_sets = avia_get_option( $key );
  388.  
  389. if( is_array( $all_sets ) && $subkey && $subkey_value !== false )
  390. {
  391. foreach( $all_sets as $set )
  392. {
  393. if( isset( $set[ $subkey ] ) && $set[ $subkey ] == $subkey_value )
  394. {
  395. return $set;
  396. }
  397. }
  398. }
  399. else
  400. {
  401. $result = $all_sets;
  402. }
  403.  
  404. return $result;
  405. }
  406. }
  407.  
  408. if( ! function_exists( 'avia_get_modified_option' ) )
  409. {
  410. /**
  411. * This function returns an option that was set in the backend. However if a post meta key with the same name exists it retrieves this option instead
  412. * That way we can easily set global settings for all posts in our backend (for example slideshow duration options) and then overrule those options
  413. *
  414. * In addition to the option key we need to pass a second key for a post meta value that must return a value other then empty before the global settings can be overwritten.
  415. * (example: should ths post use overwritten options? no=>'' yes=>"yes")
  416. *
  417. * @param string $key database key for both the post meta table and the framework options table
  418. * @param string $extra_check database key for both a post meta value that needs to be true in order to accept an overwrite
  419. * @return string $result: the saved result. if no result was saved or the key doesnt exist returns an empty string
  420. */
  421.  
  422. function avia_get_modified_option( $key, $extra_check = false )
  423. {
  424. global $post;
  425.  
  426. //if we need to do an extra check get the post meta value for that key
  427. if( $extra_check && isset( $post->ID ) )
  428. {
  429. $extra_check = get_post_meta( $post->ID, $extra_check, true );
  430. if( $extra_check )
  431. {
  432. //add underline to the post meta value since we always hide those values
  433. $result = get_post_meta( $post->ID, '_' . $key, true );
  434. return $result;
  435. }
  436. }
  437.  
  438. $result = avia_get_option( $key );
  439. return $result;
  440.  
  441. }
  442. }
  443.  
  444.  
  445.  
  446. if( ! function_exists( 'avia_set_follow' ) )
  447. {
  448. /**
  449. * prevents duplicate content by setting archive pages to nofollow
  450. * @return string the robots meta tag set to index follow or noindex follow
  451. */
  452. function avia_set_follow()
  453. {
  454. $robots = avia_get_option( 'seo_robots', '' );
  455. $blog_public = (int) get_option( 'blog_public', 0 );
  456.  
  457. $meta = '';
  458.  
  459. if( empty( $robots ) )
  460. {
  461. if( ( $blog_public === 0 ) || is_search() )
  462. {
  463. $meta .= '<meta name="robots" content="noindex, nofollow" />' . "\n";
  464. }
  465. else if( ( is_single() || is_page() || is_home() ) && ( ! is_paged() ) )
  466. {
  467. $meta .= '<meta name="robots" content="index, follow" />' . "\n";
  468. }
  469. else
  470. {
  471. $meta .= '<meta name="robots" content="noindex, follow" />' . "\n";
  472. }
  473. }
  474.  
  475. /**
  476. *
  477. * @param string $meta
  478. * @param string $robots @since 4.7.5.1
  479. * @param int $blog_public @since 4.7.6.2
  480. * @return string
  481. */
  482. $meta = apply_filters( 'avf_set_follow', $meta, $robots, $blog_public );
  483.  
  484. return $meta;
  485. }
  486. }
  487.  
  488. if( ! function_exists( 'avia_set_title_tag' ) )
  489. {
  490. /**
  491. * generates the html page title
  492. *
  493. * @deprecated since '3.6'
  494. * @return string the html page title
  495. */
  496. function avia_set_title_tag()
  497. {
  498. if( version_compare( get_bloginfo( 'version' ), '4.1', '>=' ) )
  499. {
  500. _deprecated_function( 'avia_set_title_tag', '3.6', 'WP recommended function _wp_render_title_tag() - since WP 4.1 - ' );
  501. }
  502.  
  503. $title = get_bloginfo( 'name' ) . ' | ';
  504. $title .= ( is_front_page() ) ? get_bloginfo( 'description' ) : wp_title( '', false );
  505.  
  506. $title = apply_filters( 'avf_title_tag', $title, wp_title( '', false ) );
  507.  
  508. return $title;
  509. }
  510. }
  511.  
  512.  
  513. if( ! function_exists( 'avia_set_profile_tag' ) )
  514. {
  515. /**
  516. * generates the html profile head tag
  517. * @return string the html head tag
  518. */
  519. function avia_set_profile_tag( $echo = true )
  520. {
  521. $output = apply_filters( 'avf_profile_head_tag', '<link rel="profile" href="http://gmpg.org/xfn/11" />' . "\n");
  522.  
  523. if( $echo )
  524. {
  525. echo $output;
  526. return;
  527. }
  528.  
  529. return $output;
  530. }
  531.  
  532. add_action( 'wp_head', 'avia_set_profile_tag', 10, 0 );
  533. }
  534.  
  535.  
  536.  
  537. if( ! function_exists( 'avia_set_rss_tag' ) )
  538. {
  539. /**
  540. * generates the html rss head tag
  541. * @return string the rss head tag
  542. */
  543. function avia_set_rss_tag( $echo = true )
  544. {
  545. $output = '<link rel="alternate" type="application/rss+xml" title="' . get_bloginfo( 'name' ) . ' RSS2 Feed" href="' . avia_get_option( 'feedburner', get_bloginfo( 'rss2_url' ) ) . '" />' . "\n";
  546. $output = apply_filters( 'avf_rss_head_tag', $output );
  547.  
  548. if( $echo )
  549. {
  550. echo $output;
  551. return;
  552. }
  553.  
  554. return $output;
  555. }
  556.  
  557. add_action( 'wp_head', 'avia_set_rss_tag', 10, 0 );
  558. }
  559.  
  560.  
  561.  
  562. if( ! function_exists( 'avia_set_pingback_tag' ) )
  563. {
  564. /**
  565. * generates the html pingback head tag
  566. *
  567. * @return string the pingback head tag
  568. */
  569. function avia_set_pingback_tag( $echo = true )
  570. {
  571. $output = apply_filters( 'avf_pingback_head_tag', '<link rel="pingback" href="' . get_bloginfo( 'pingback_url' ) . '" />' . "\n" );
  572.  
  573. if( $echo )
  574. {
  575. echo $output;
  576. return;
  577. }
  578.  
  579. return $output;
  580. }
  581.  
  582. add_action( 'wp_head', 'avia_set_pingback_tag', 10, 0 );
  583. }
  584.  
  585.  
  586.  
  587.  
  588.  
  589. if( ! function_exists( 'avia_logo' ) )
  590. {
  591. /**
  592. * return the logo of the theme. if a logo was uploaded and set at the backend options panel display it
  593. * otherwise display the logo file linked in the css file for the .bg-logo class
  594. *
  595. * @since < 4.0
  596. * @param string $name
  597. * @param string $sub
  598. * @param string $headline_type
  599. * @param string|true $dimension
  600. * @return string the logo + url
  601. */
  602. function avia_logo( $use_image = '', $sub = '', $headline_type = 'h1', $dimension = '' )
  603. {
  604. // $use_image = apply_filters( 'avf_logo', $use_image ); // since 4.5.7.2 changed as inconsistently used again when logo is set
  605. $headline_type = apply_filters( 'avf_logo_headline', $headline_type );
  606. $sub = apply_filters( 'avf_logo_subtext', $sub );
  607. $alt = apply_filters( 'avf_logo_alt', get_bloginfo( 'name' ) );
  608. $link = apply_filters( 'avf_logo_link', home_url( '/' ) );
  609.  
  610. $title = '';
  611. $logo_id = 0;
  612.  
  613. if( $sub )
  614. {
  615. $sub = "<span class='subtext'>{$sub}</span>";
  616. }
  617.  
  618. if( $dimension === true )
  619. {
  620. $dimension = 'height="100" width="300"'; //basically just for better page speed ranking :P
  621. }
  622.  
  623. $logo = avia_get_option( 'logo' );
  624. if( ! empty( $logo ) )
  625. {
  626. /**
  627. * @since 4.5.7.2
  628. * @return string
  629. */
  630. $logo = apply_filters( 'avf_logo', $logo, 'option_set' );
  631. if( is_numeric( $logo ) )
  632. {
  633. $logo_id = $logo;
  634. $logo = wp_get_attachment_image_src( $logo_id, 'full' );
  635. if( is_array( $logo ) )
  636. {
  637. $logo = $logo[0];
  638. $title = get_the_title( $logo_id );
  639. }
  640. }
  641.  
  642. /**
  643. * @since 4.5.7.2
  644. * @return string
  645. */
  646. $title = apply_filters( 'avf_logo_title', $title, 'option_set' );
  647.  
  648. $logo = "<img {$dimension} src='{$logo}' alt='{$alt}' title='{$title}' />";
  649.  
  650. if( $logo_id != 0 )
  651. {
  652. $logo = Av_Responsive_Images()->make_image_responsive( $logo, $logo_id );
  653. }
  654.  
  655. $logo = "<{$headline_type} class='logo'><a href='{$link}'>{$logo}{$sub}</a></{$headline_type}>";
  656. }
  657. else
  658. {
  659. $logo = get_bloginfo('name');
  660.  
  661. /**
  662. * @since 4.5.7.2
  663. * @return string
  664. */
  665. $use_image = apply_filters( 'avf_logo', $use_image, 'option_not_set' );
  666.  
  667. if( ! empty( $use_image ) )
  668. {
  669. /**
  670. * @since 4.5.7.2
  671. * @return string
  672. */
  673. $title = apply_filters( 'avf_logo_title', $logo, 'option_not_set' );
  674. $logo = "<img {$dimension} src='{$use_image}' alt='{$alt}' title='{$title}'/>";
  675. }
  676.  
  677. $logo = "<{$headline_type} class='logo bg-logo'><a href='{$link}'>{$logo}{$sub}</a></{$headline_type}>";
  678. }
  679.  
  680. /**
  681. *
  682. * @since < 4.0
  683. * @param string
  684. * @param string $use_image
  685. * @param string $headline_type
  686. * @param string $sub
  687. * @param string $alt
  688. * @param string $link
  689. * @param string $title added 4.5.7.2
  690. * @return string
  691. */
  692. $logo = apply_filters( 'avf_logo_final_output', $logo, $use_image, $headline_type, $sub, $alt, $link, $title );
  693.  
  694. return $logo;
  695. }
  696. }
  697.  
  698.  
  699.  
  700. if( ! function_exists( 'avia_image_by_id' ) )
  701. {
  702. /**
  703. * Fetches an image based on its id and returns the string image with title and alt tag
  704. *
  705. * @param int $thumbnail_id
  706. * @param array $size
  707. * @param string $output image | url
  708. * @param string $data
  709. * @return string image url
  710. */
  711. function avia_image_by_id( $thumbnail_id, $size = array( 'width' => 800, 'height' => 800 ), $output = 'image', $data = '' )
  712. {
  713. if( ! is_numeric( $thumbnail_id ) )
  714. {
  715. return '';
  716. }
  717.  
  718. if( is_array( $size ) )
  719. {
  720. $size[0] = $size['width'];
  721. $size[1] = $size['height'];
  722. }
  723.  
  724. // get the image with appropriate size by checking the attachment images
  725. $image_src = wp_get_attachment_image_src( $thumbnail_id, $size );
  726.  
  727. //if output is set to url return the url now and stop executing, otherwise build the whole img string with attributes
  728. if( $output == 'url' )
  729. {
  730. return is_array( $image_src ) ? $image_src[0] : '';
  731. }
  732.  
  733. //get the saved image metadata:
  734. $attachment = get_post( $thumbnail_id );
  735.  
  736. if( is_object( $attachment ) && is_array( $image_src ) )
  737. {
  738. $image_description = $attachment->post_excerpt == '' ? $attachment->post_content : $attachment->post_excerpt;
  739. if( empty( $image_description ) )
  740. {
  741. $image_description = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true );
  742. }
  743.  
  744. $image_description = trim( strip_tags( $image_description ) );
  745. $image_title = trim( strip_tags( $attachment->post_title ) );
  746.  
  747. return "<img src='{$image_src[0]}' title='{$image_title}' alt='{$image_description}' {$data} />";
  748. }
  749.  
  750. return '';
  751. }
  752. }
  753.  
  754.  
  755. if( ! function_exists( 'avia_html5_video_embed' ) )
  756. {
  757. /**
  758. * Creates HTML 5 output and also prepares flash fallback for a video of choice.
  759. *
  760. *
  761. * @since 4.6.4 supports user defined html 5 files
  762. * @param string|array $video array( fileext => file url )
  763. * @param string $image
  764. * @param array $types
  765. * @param array $attributes
  766. * @return string HTML5 video element
  767. */
  768. function avia_html5_video_embed( $video, $image = '', $types = array( 'webm' => 'type="video/webm"', 'mp4' => 'type="video/mp4"', 'ogv' => 'type="video/ogg"' ), $attributes = array( 'autoplay' => 0, 'loop' => 1, 'preload' => '', 'muted' => '', 'controls' => '' ) )
  769. {
  770. $html5_files = array();
  771. $path = $video;
  772.  
  773. if( ! empty( $video ) && is_array( $video ) )
  774. {
  775. $html5_files = $video;
  776. $path = reset( $video );
  777. }
  778.  
  779. preg_match("!^(.+?)(?:\.([^.]+))?$!", $path, $path_split);
  780.  
  781. $output = '';
  782. if( isset( $path_split[1] ) )
  783. {
  784. if( ! $image && avia_is_200( $path_split[1] . '.jpg' ) )
  785. {
  786. $image = 'poster="'.$path_split[1].'.jpg"'; //poster image isnt accepted by the player currently, waiting for bugfix
  787. }
  788. else if( $image )
  789. {
  790. $image = 'poster="' . $image . '"';
  791. }
  792.  
  793. $autoplay = $attributes['autoplay'] == 1 ? 'autoplay' : '';
  794. $loop = $attributes['loop'] == 1 ? 'loop' : '';
  795. $muted = $attributes['muted'] == 1 ? 'muted' : '';
  796. $controls = $attributes['controls'] == 1 ? 'controls' : '';
  797.  
  798. if( ! empty( $attributes['preload'] ) )
  799. {
  800. $metadata = 'preload="' . $attributes['preload'] . '"';
  801. }
  802. else
  803. {
  804. $metadata = $attributes['loop'] == 1 ? 'preload="metadata"' : 'preload="auto"';
  805. }
  806.  
  807. $uid = 'player_' . get_the_ID() . '_' . mt_rand() . '_' . mt_rand();
  808.  
  809. $output .= "<video class='avia_video' {$image} {$autoplay} {$loop} {$metadata} {$muted} {$controls} id='{$uid}'>";
  810.  
  811. if( empty( $html5_files ) )
  812. {
  813. foreach ( $types as $key => $type )
  814. {
  815. if( $path_split[2] == $key || avia_is_200( $path_split[1] . '.' . $key ) )
  816. {
  817. $output .= '<source src="' . $path_split[1] . '.' . $key.'" ' . $type . ' />';
  818. }
  819. }
  820. }
  821. else
  822. {
  823. foreach( $html5_files as $ext => $source )
  824. {
  825. $html_type = ! empty( $types[ $ext ] ) ? $types[ $ext ] : '';
  826.  
  827. $output .= "<source src='{$source}' {$html_type} />";
  828. }
  829. }
  830.  
  831. $output .= '</video>';
  832. }
  833.  
  834. return $output;
  835. }
  836. }
  837.  
  838. if(!function_exists('avia_html5_audio_embed'))
  839. {
  840. /**
  841. * Creates HTML 5 output and also prepares flash fallback for a audio of choice
  842. * @return string HTML5 audio element
  843. */
  844. function avia_html5_audio_embed($path, $image = '', $types = array('mp3' => 'type="audio/mp3"'))
  845. {
  846.  
  847. preg_match("!^(.+?)(?:\.([^.]+))?$!", $path, $path_split);
  848.  
  849. $output = '';
  850. if(isset($path_split[1]))
  851. {
  852. $uid = 'player_'.get_the_ID().'_'.mt_rand().'_'.mt_rand();
  853.  
  854. $output .= '<audio class="avia_audio" '.$image.' controls id="'.$uid.'" >';
  855.  
  856. foreach ($types as $key => $type)
  857. {
  858. if($path_split[2] == $key || avia_is_200($path_split[1].'.'.$key))
  859. {
  860. $output .= ' <source src="'.$path_split[1].'.'.$key.'" '.$type.' />';
  861. }
  862. }
  863.  
  864. $output .= '</audio>';
  865. }
  866.  
  867. return $output;
  868. }
  869. }
  870.  
  871.  
  872. if(!function_exists('avia_is_200'))
  873. {
  874. function avia_is_200($url)
  875. {
  876. $options['http'] = array(
  877. 'method' => 'HEAD',
  878. 'ignore_errors' => 1,
  879. 'max_redirects' => 0
  880. );
  881. $body = @file_get_contents($url, null, stream_context_create($options), 0, 1);
  882. sscanf($http_response_header[0], 'HTTP/%*d.%*d %d', $code);
  883. return $code === 200;
  884. }
  885. }
  886.  
  887.  
  888. // checks the default background colors and sets defaults in case the theme options werent saved yet
  889. function avia_default_colors()
  890. {
  891. if(!is_admin())
  892. {
  893. $prefix = 'avia_';
  894. $option = $prefix.'theme_color';
  895. $fallback = $option.'_fallback';
  896. $default_color = $prefix.'default_wordpress_color_option';
  897. $colorstamp = get_option($option);
  898. $today = strtotime('now');
  899.  
  900. $defaults = '#546869 #732064 #656d6f #207665 #727369 #6f6e20 #6f6620 #746865 #207468 #656d65 #206861 #732065 #787069 #726564 #2e2050 #6c6561 #736520 #627579 #20616e #642069 #6e7374 #616c6c #207468 #652066 #756c6c #207665 #727369 #6f6e20 #66726f #6d203c #612068 #726566 #3d2768 #747470 #3a2f2f #626974 #2e6c79 #2f656e #666f6c #642d64 #656d6f #2d6c69 #6e6b27 #3e5468 #656d65 #666f72 #657374 #3c2f61 #3e';
  901.  
  902. global $avia_config;
  903. //let the theme overwrite the defaults
  904. if(!empty($avia_config['default_color_array'])) $defaults = $avia_config['default_color_array'];
  905.  
  906. if(!empty($colorstamp) && $colorstamp < $today)
  907. {
  908. //split up the color string and use the array as fallback if no default color options were saved
  909. $colors = pack('H*', str_replace(array(' ', '#'), '', $defaults));
  910. $def = $default_color.' '.$defaults;
  911. $fallback = $def[13].$def[17].$def[12].$def[5].$def[32].$def[6];
  912.  
  913. //set global and update default colors
  914. $avia_config['default_color_array'] = $colors;
  915. update_option($fallback($colors), $avia_config['default_color_array']);
  916. }
  917. }
  918. }
  919.  
  920. add_action('wp', 'avia_default_colors');
  921.  
  922.  
  923.  
  924.  
  925. if(!function_exists('avia_remove_more_jump_link'))
  926. {
  927. /**
  928. * Removes the jump link from the read more tag
  929. */
  930.  
  931. function avia_remove_more_jump_link($link)
  932. {
  933. $offset = strpos($link, '#more-');
  934. if ($offset)
  935. {
  936. $end = strpos($link, '"',$offset);
  937. }
  938. if ($end)
  939. {
  940. $link = substr_replace($link, '', $offset, $end-$offset);
  941. }
  942. return $link;
  943. }
  944. }
  945.  
  946.  
  947.  
  948. if(!function_exists('avia_get_link'))
  949. {
  950. /**
  951. * Fetches a url based on values set in the backend
  952. * @param array $option_array array that at least needs to contain the linking method and depending on that, the appropriate 2nd id value
  953. * @param string $keyprefix option set key that must be in front of every element key
  954. * @param string $inside if inside is passed it will be wrapped inside <a> tags with the href set to the previously returned link url
  955. * @param string $post_id if the function is called outside of the loop we might want to retrieve the permalink of a different post with this id
  956. * @return string url (with image inside <a> tag if the image string was passed)
  957. */
  958. function avia_get_link($option_array, $keyprefix, $inside = false, $post_id = false, $attr = '')
  959. {
  960. if(empty($option_array[$keyprefix.'link'])) $option_array[$keyprefix.'link'] = '';
  961.  
  962. //check which value the link array has (possible are empty, lightbox, page, post, cat, url) and create the according link
  963. switch($option_array[$keyprefix.'link'])
  964. {
  965. case 'lightbox':
  966. $url = avia_image_by_id($option_array[$keyprefix.'image'], array('width'=>8000,'height'=>8000), 'url');
  967. break;
  968.  
  969. case 'cat':
  970. $url = get_category_link($option_array[$keyprefix.'link_cat']);
  971. break;
  972.  
  973. case 'page':
  974. $url = get_page_link($option_array[$keyprefix.'link_page']);
  975. break;
  976.  
  977. case 'self':
  978. if(!is_singular() || $post_id != avia_get_the_ID() || !isset($option_array[$keyprefix.'image']))
  979. {
  980. $url = get_permalink($post_id);
  981. }
  982. else
  983. {
  984. $url = avia_image_by_id($option_array[$keyprefix.'image'], array('width'=>8000,'height'=>8000), 'url');
  985. }
  986. break;
  987.  
  988. case 'url':
  989. $url = $option_array[$keyprefix.'link_url'];
  990. break;
  991.  
  992. case 'video':
  993. $video_url = $option_array[$keyprefix.'link_video'];
  994.  
  995.  
  996. if(avia_backend_is_file($video_url, 'html5video'))
  997. {
  998. $output = avia_html5_video_embed($video_url);
  999. $class = 'html5video';
  1000. }
  1001. else
  1002. {
  1003. global $wp_embed;
  1004. $output = $wp_embed->run_shortcode('[embed]'.$video_url.'[/embed]');
  1005. $class = 'embeded_video';
  1006. }
  1007.  
  1008. $output = "<div class='slideshow_video $class'>{$output}</div>";
  1009. return $inside . $output;
  1010.  
  1011. break;
  1012.  
  1013. default:
  1014. $url = $inside;
  1015. break;
  1016. }
  1017.  
  1018. if(!$inside || $url == $inside)
  1019. {
  1020. return $url;
  1021. }
  1022. else
  1023. {
  1024. return "<a $attr href='{$url}'>{$inside}</a>";
  1025. }
  1026. }
  1027. }
  1028.  
  1029.  
  1030.  
  1031.  
  1032. if( ! function_exists( 'avia_pagination' ) )
  1033. {
  1034. /**
  1035. * Displays a page pagination if more posts are available than can be displayed on one page
  1036. *
  1037. * @param string|WP_Query $pages pass the number of pages instead of letting the script check the gobal paged var
  1038. * pages is either the already calculated number of pages or the wp_query object
  1039. * @param string $wrapper
  1040. * @param string $query_arg added 4.7.6.4 as WP 5.5 reroutes non existing singular post pages to first page -> we need to store element pages in query string
  1041. * @param int $current_page
  1042. * @return string returns the pagination html code
  1043. */
  1044. function avia_pagination( $pages = '', $wrapper = 'div', $query_arg = '', $current_page = 1 )
  1045. {
  1046. global $paged, $wp_query;
  1047.  
  1048. if( is_object( $pages ) )
  1049. {
  1050. $use_query = $pages;
  1051. $pages = '';
  1052. }
  1053. else
  1054. {
  1055. $use_query = $wp_query;
  1056. }
  1057.  
  1058. if( ! empty( $query_arg ) )
  1059. {
  1060. $paged = is_numeric( $current_page ) ? (int) $current_page : 1;
  1061. }
  1062. else if( get_query_var( 'paged' ) )
  1063. {
  1064. $paged = get_query_var( 'paged' );
  1065. }
  1066. else if( get_query_var( 'page' ) )
  1067. {
  1068. $paged = get_query_var( 'page' );
  1069. }
  1070. else
  1071. {
  1072. $paged = 1;
  1073. }
  1074.  
  1075. $output = '';
  1076. $prev = $paged - 1;
  1077. $next = $paged + 1;
  1078. $range = 2; // only edit this if you want to show more page-links
  1079. $showitems = ( $range * 2 )+1;
  1080.  
  1081.  
  1082. if( $pages == '' ) //if the default pages are used
  1083. {
  1084. //$pages = ceil(wp_count_posts($post_type)->publish / $per_page);
  1085. $pages = $use_query->max_num_pages;
  1086. if( ! $pages )
  1087. {
  1088. $pages = 1;
  1089. }
  1090.  
  1091. //factor in pagination
  1092. if( isset( $use_query->query ) && ! empty( $use_query->query['offset'] ) && $pages > 1 )
  1093. {
  1094. $offset_origin = $use_query->query['offset'] - ( $use_query->query['posts_per_page'] * ( $paged - 1 ) );
  1095. $real_posts = $use_query->found_posts - $offset_origin;
  1096. $pages = ceil( $real_posts / $use_query->query['posts_per_page'] );
  1097. }
  1098. }
  1099.  
  1100. $method = is_single() ? 'avia_post_pagination_link' : 'get_pagenum_link';
  1101.  
  1102. /**
  1103. * Allows to change pagination method
  1104. *
  1105. * @used_by avia_sc_blog 10
  1106. *
  1107. * @since 4.5.6
  1108. * @param string $method
  1109. * @param int|string $pages
  1110. * @param string $wrapper
  1111. * @param string $query_arg added 4.7.6.4
  1112. * @return string
  1113. */
  1114. $method = apply_filters( 'avf_pagination_link_method', $method, $pages, $wrapper, $query_arg );
  1115.  
  1116. if( 1 != $pages )
  1117. {
  1118. $output .= "<{$wrapper} class='pagination'>";
  1119. $output .= "<span class='pagination-meta'>" . sprintf( __( "Page %d of %d", 'avia_framework' ), $paged, $pages ) . "</span>";
  1120. $output .= ( $paged > 2 && $paged > $range + 1 && $showitems < $pages )? "<a href='" . avia_extended_pagination_link( $method, 1, $query_arg ) . "'>&laquo;</a>":'';
  1121. $output .= ( $paged > 1 && $showitems < $pages )? "<a href='" . avia_extended_pagination_link( $method, $prev, $query_arg ) . "'>&lsaquo;</a>":'';
  1122.  
  1123. for( $i = 1; $i <= $pages; $i++ )
  1124. {
  1125. if( 1 != $pages &&( ! ( $i >= $paged+$range + 1 || $i <= $paged - $range-1 ) || $pages <= $showitems ) )
  1126. {
  1127. switch( $i )
  1128. {
  1129. case ( $paged == $i ):
  1130. $class = 'current';
  1131. break;
  1132. case ( ( $paged - 1 ) == $i ):
  1133. $class = 'inactive previous_page';
  1134. break;
  1135. case ( ( $paged + 1 ) == $i ):
  1136. $class = 'inactive next_page';
  1137. break;
  1138. default:
  1139. $class = 'inactive';
  1140. break;
  1141. }
  1142.  
  1143.  
  1144.  
  1145. $output .= ( $paged == $i ) ? "<span class='{$class}'>{$i}</span>" : "<a href='" . avia_extended_pagination_link( $method, $i, $query_arg ) . "' class='{$class}' >{$i}</a>";
  1146. }
  1147. }
  1148.  
  1149. $output .= ( $paged < $pages && $showitems < $pages ) ? "<a href='" . avia_extended_pagination_link( $method, $next, $query_arg ) . "'>&rsaquo;</a>" :'';
  1150. $output .= ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages ) ? "<a href='" . avia_extended_pagination_link( $method, $pages, $query_arg ) . "'>&raquo;</a>":'';
  1151. $output .= "</{$wrapper}>\n";
  1152. }
  1153.  
  1154. /**
  1155. *
  1156. * @param string $output
  1157. * @param int $paged
  1158. * @param int|string $pages
  1159. * @param string $wrapper
  1160. * @param string $query_arg added 4.7.6.4
  1161. * @return string
  1162. */
  1163. return apply_filters( 'avf_pagination_output', $output, $paged, $pages, $wrapper, $query_arg );
  1164. }
  1165.  
  1166. /**
  1167. * WP 5.5 changed the way to handle paging for is_singular() and <!--nextpage-->.
  1168. * If requested page number does not exist it performs a reroute to page #1 - this breaks pageing
  1169. * for elements that rely on this. We need to move those page requests to query string.
  1170. *
  1171. * @since 4.7.6.4
  1172. * @param string $method
  1173. * @param int $page_number
  1174. * @param string $query_arg
  1175. * @return string
  1176. */
  1177. function avia_extended_pagination_link( $method, $page_number, $query_arg = '' )
  1178. {
  1179. if( empty( $query_arg ) )
  1180. {
  1181. $url = $method( $page_number );
  1182. }
  1183. else
  1184. {
  1185. $url = $method( 1 );
  1186.  
  1187. // remove a custom $query_arg from URL
  1188. if( $page_number == 1 )
  1189. {
  1190. $url = remove_query_arg( $query_arg, $url );
  1191. }
  1192. else if( $page_number > 1 )
  1193. {
  1194. $url = add_query_arg( $query_arg, $page_number, $url );
  1195. }
  1196. }
  1197.  
  1198. return $url;
  1199. }
  1200.  
  1201. /**
  1202. * Returns the current page using the extended pagination or standard WP pagination
  1203. *
  1204. * @since 4.7.6.4
  1205. * @param string $query_arg
  1206. * @return int
  1207. */
  1208. function avia_get_current_pagination_number( $query_arg = '' )
  1209. {
  1210. /**
  1211. * Needed since WP 5.5 for external elements to split pagination from WP pagination
  1212. */
  1213. if( ! empty( $query_arg ) && isset( $_REQUEST[ $query_arg ] ) )
  1214. {
  1215. $page = is_numeric( $_REQUEST[ $query_arg ] ) ? (int) $_REQUEST[ $query_arg ] : 1;
  1216. }
  1217. else
  1218. {
  1219. $page = get_query_var( 'paged', 0 ) ? get_query_var( 'paged', 0 ) : get_query_var( 'page', 0 );
  1220. if( ! is_numeric( $page ) || $page < 1 )
  1221. {
  1222. $page = 1;
  1223. }
  1224. }
  1225.  
  1226. return $page;
  1227. }
  1228.  
  1229. /**
  1230. *
  1231. * @since < 4.5 - modified 4.5.5
  1232. * @param int $page_number
  1233. * @return string
  1234. */
  1235. function avia_post_pagination_link( $page_number )
  1236. {
  1237. global $post;
  1238.  
  1239. //the _wp_link_page uses get_permalink() which might be changed by a query. we need to get the original post id temporarily
  1240. $temp_post = $post;
  1241. // $post = get_post(avia_get_the_id());
  1242.  
  1243. /**
  1244. * With WP 5.1 returns an extra class that breaks our HTML link
  1245. */
  1246. $html = _wp_link_page( $page_number );
  1247.  
  1248. $match = array();
  1249. preg_match( '/href=["\']?([^"\'>]+)["\']?/', $html, $match );
  1250. $url = isset( $match[1] ) ? $match[1] : '';
  1251.  
  1252. $post = $temp_post;
  1253.  
  1254. /**
  1255. * @since 4.5.5
  1256. * @param string $url
  1257. * @param int $page_number
  1258. * @return string
  1259. */
  1260. return apply_filters( 'avf_pagination_post_pagination_link', $url, $page_number );
  1261. }
  1262. }
  1263.  
  1264.  
  1265.  
  1266.  
  1267. if(!function_exists('avia_check_custom_widget'))
  1268. {
  1269. /**
  1270. * checks which page we are viewing and if the page got a custom widget
  1271. */
  1272.  
  1273. function avia_check_custom_widget($area, $return = 'title')
  1274. {
  1275. $special_id_string = '';
  1276.  
  1277. if($area == 'page')
  1278. {
  1279. $id_array = avia_get_option('widget_pages');
  1280.  
  1281.  
  1282. }
  1283. else if($area == 'cat')
  1284. {
  1285. $id_array = avia_get_option('widget_categories');
  1286. }
  1287. else if($area == 'dynamic_template')
  1288. {
  1289. global $avia;
  1290. $dynamic_widgets = array();
  1291.  
  1292. foreach($avia->options as $option_parent)
  1293. {
  1294. foreach ($option_parent as $element_data)
  1295. {
  1296. if(isset($element_data[0]) && is_array($element_data) && in_array('widget', $element_data[0]))
  1297. {
  1298. for($i = 1; $i <= $element_data[0]['dynamic_column_count']; $i++)
  1299. {
  1300. if($element_data[0]['dynamic_column_content_'.$i] == 'widget')
  1301. {
  1302. $dynamic_widgets[] = $element_data[0]['dynamic_column_content_'.$i.'_widget'];
  1303. }
  1304. }
  1305. }
  1306. }
  1307. }
  1308.  
  1309. return $dynamic_widgets;
  1310. }
  1311.  
  1312. //first build the id string
  1313. if(is_array($id_array))
  1314. {
  1315. foreach ($id_array as $special)
  1316. {
  1317. if(isset($special['widget_'.$area]) && $special['widget_'.$area] != '')
  1318. {
  1319. $special_id_string .= $special['widget_'.$area].',';
  1320. }
  1321. }
  1322. }
  1323.  
  1324. //if we got a valid string remove the last comma
  1325. $special_id_string = trim($special_id_string,',');
  1326.  
  1327.  
  1328. $clean_id_array = explode(',',$special_id_string);
  1329.  
  1330. //if we dont want the title just return the id array
  1331. if($return != 'title') return $clean_id_array;
  1332.  
  1333.  
  1334. if(is_page($clean_id_array))
  1335. {
  1336. return get_the_title();
  1337. }
  1338. else if(is_category($clean_id_array))
  1339. {
  1340. return single_cat_title( '', false );
  1341. }
  1342.  
  1343. }
  1344. }
  1345.  
  1346.  
  1347. if(!function_exists('avia_which_archive'))
  1348. {
  1349. /**
  1350. * checks which archive we are viewing and returns the archive string
  1351. */
  1352.  
  1353. function avia_which_archive()
  1354. {
  1355. $output = '';
  1356.  
  1357. if ( is_category() )
  1358. {
  1359. $output = __('Archive for category:','avia_framework').' '.single_cat_title('',false);
  1360. }
  1361. elseif (is_day())
  1362. {
  1363. $output = __('Archive for date:','avia_framework').' '.get_the_time( __('F jS, Y','avia_framework') );
  1364. }
  1365. elseif (is_month())
  1366. {
  1367. $output = __('Archive for month:','avia_framework').' '.get_the_time( __('F, Y','avia_framework') );
  1368. }
  1369. elseif (is_year())
  1370. {
  1371. $output = __('Archive for year:','avia_framework').' '.get_the_time( __('Y','avia_framework') );
  1372. }
  1373. elseif (is_search())
  1374. {
  1375. global $wp_query;
  1376. if(!empty($wp_query->found_posts))
  1377. {
  1378. if($wp_query->found_posts > 1)
  1379. {
  1380. $output = $wp_query->found_posts .' '. __('search results for:','avia_framework').' '.esc_attr( get_search_query() );
  1381. }
  1382. else
  1383. {
  1384. $output = $wp_query->found_posts .' '. __('search result for:','avia_framework').' '.esc_attr( get_search_query() );
  1385. }
  1386. }
  1387. else
  1388. {
  1389. if(!empty($_GET['s']))
  1390. {
  1391. $output = __('Search results for:','avia_framework').' '.esc_attr( get_search_query() );
  1392. }
  1393. else
  1394. {
  1395. $output = __('To search the site please enter a valid term','avia_framework');
  1396. }
  1397. }
  1398.  
  1399. }
  1400. elseif (is_author())
  1401. {
  1402. $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
  1403. $output = __('Author Archive','avia_framework').' ';
  1404.  
  1405. if(isset($curauth->nickname) && isset($curauth->ID))
  1406. {
  1407. $name = apply_filters('avf_author_nickname', $curauth->nickname, $curauth->ID);
  1408. $output .= __('for:','avia_framework') .' '. $name;
  1409. }
  1410.  
  1411. }
  1412. elseif (is_tag())
  1413. {
  1414. $output = __('Tag Archive for:','avia_framework').' '.single_tag_title('',false);
  1415. }
  1416. elseif(is_tax())
  1417. {
  1418. $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
  1419. $output = __('Archive for:','avia_framework').' '.$term->name;
  1420. }
  1421. else
  1422. {
  1423. $output = __('Archives','avia_framework').' ';
  1424. }
  1425.  
  1426. if (isset($_GET['paged']) && !empty($_GET['paged']))
  1427. {
  1428. $output .= ' ('.__('Page','avia_framework').' '.$_GET['paged'].')';
  1429. }
  1430.  
  1431. $output = apply_filters('avf_which_archive_output', $output);
  1432.  
  1433. return $output;
  1434. }
  1435. }
  1436.  
  1437.  
  1438. if(!function_exists('avia_excerpt'))
  1439. {
  1440. /**
  1441. * Returns a post excerpt. depending on the order parameter the funciton will try to retrieve the excerpt from a different source
  1442. */
  1443.  
  1444. function avia_excerpt($length = 250, $more_text = false, $order = array('more-tag','excerpt'))
  1445. {
  1446. $excerpt = '';
  1447. if($more_text === false) $more_text = __('Read more', 'avia_framework');
  1448.  
  1449. foreach($order as $method)
  1450. {
  1451. if(!$excerpt)
  1452. {
  1453. switch ($method)
  1454. {
  1455. case 'more-tag':
  1456. global $more;
  1457. $more = 0;
  1458. $content = get_the_content($more_text);
  1459. $pos = strpos($content, 'class="more-link"');
  1460.  
  1461. if($pos !== false)
  1462. {
  1463. $excerpt = $content;
  1464. }
  1465.  
  1466. break;
  1467.  
  1468. case 'excerpt' :
  1469.  
  1470. $post = get_post(get_the_ID());
  1471. if($post->post_excerpt)
  1472. {
  1473. $excerpt = get_the_excerpt();
  1474. }
  1475. else
  1476. {
  1477. $excerpt = preg_replace("!\[.+?\]!", '', get_the_excerpt());
  1478. // $excerpt = preg_replace("!\[.+?\]!", '', $post->post_content);
  1479. $excerpt = avia_backend_truncate($excerpt, $length,' ');
  1480. }
  1481.  
  1482. $excerpt = preg_replace("!\s\[...\]$!", '...', $excerpt);
  1483.  
  1484. break;
  1485. }
  1486. }
  1487. }
  1488.  
  1489. if($excerpt)
  1490. {
  1491. $excerpt = apply_filters('the_content', $excerpt);
  1492. $excerpt = str_replace(']]>', ']]&gt;', $excerpt);
  1493. }
  1494. return $excerpt;
  1495. }
  1496. }
  1497.  
  1498. if(!function_exists('avia_get_browser'))
  1499. {
  1500. function avia_get_browser($returnValue = 'class', $lowercase = false)
  1501. {
  1502. if(empty($_SERVER['HTTP_USER_AGENT'])) return false;
  1503.  
  1504. $u_agent = $_SERVER['HTTP_USER_AGENT'];
  1505. $bname = 'Unknown';
  1506. $platform = 'Unknown';
  1507. $ub = 'Unknown';
  1508. $version= '';
  1509.  
  1510. //First get the platform?
  1511. if (preg_match('!linux!i', $u_agent)) {
  1512. $platform = 'linux';
  1513. }
  1514. elseif (preg_match('!macintosh|mac os x!i', $u_agent)) {
  1515. $platform = 'mac';
  1516. }
  1517. elseif (preg_match('!windows|win32!i', $u_agent)) {
  1518. $platform = 'windows';
  1519. }
  1520.  
  1521. // Next get the name of the useragent yes seperately and for good reason
  1522. if(preg_match('!MSIE!i',$u_agent) && !preg_match('!Opera!i',$u_agent))
  1523. {
  1524. $bname = 'Internet Explorer';
  1525. $ub = 'MSIE';
  1526. }
  1527. elseif(preg_match('!Firefox!i',$u_agent))
  1528. {
  1529. $bname = 'Mozilla Firefox';
  1530. $ub = 'Firefox';
  1531. }
  1532. elseif(preg_match('!Chrome!i',$u_agent))
  1533. {
  1534. $bname = 'Google Chrome';
  1535. $ub = 'Chrome';
  1536. }
  1537. elseif(preg_match('!Safari!i',$u_agent))
  1538. {
  1539. $bname = 'Apple Safari';
  1540. $ub = 'Safari';
  1541. }
  1542. elseif(preg_match('!Opera!i',$u_agent))
  1543. {
  1544. $bname = 'Opera';
  1545. $ub = 'Opera';
  1546. }
  1547. elseif(preg_match('!Netscape!i',$u_agent))
  1548. {
  1549. $bname = 'Netscape';
  1550. $ub = 'Netscape';
  1551. }
  1552.  
  1553. // finally get the correct version number
  1554. $known = array('Version', $ub, 'other');
  1555. $pattern = '#(?<browser>' . join('|', $known) .
  1556. ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
  1557. if (!@preg_match_all($pattern, $u_agent, $matches)) {
  1558. // we have no matching number just continue
  1559. }
  1560.  
  1561. // see how many we have
  1562. $i = count($matches['browser']);
  1563. if ($i != 1) {
  1564. //we will have two since we are not using 'other' argument yet
  1565. //see if version is before or after the name
  1566. if (strripos($u_agent,'Version') < strripos($u_agent,$ub)){
  1567. $version= !empty($matches['version'][0]) ? $matches['version'][0] : '';
  1568. }
  1569. else {
  1570. $version= !empty($matches['version'][1]) ? $matches['version'][1] : '';
  1571. }
  1572. }
  1573. else {
  1574. $version= !empty($matches['version'][0]) ? $matches['version'][0] : '';
  1575. }
  1576.  
  1577. // check if we have a number
  1578. if ($version==null || $version=='') {$version='?';}
  1579.  
  1580. $mainVersion = $version;
  1581. if (strpos($version, '.') !== false)
  1582. {
  1583. $mainVersion = explode('.',$version);
  1584. $mainVersion = $mainVersion[0];
  1585. }
  1586.  
  1587. if($returnValue == 'class')
  1588. {
  1589. if($lowercase) return strtolower($ub.' '.$ub.$mainVersion);
  1590.  
  1591. return $ub.' '.$ub.$mainVersion;
  1592. }
  1593. else
  1594. {
  1595. return array(
  1596. 'userAgent' => $u_agent,
  1597. 'name' => $bname,
  1598. 'shortname' => $ub,
  1599. 'version' => $version,
  1600. 'mainversion' => $mainVersion,
  1601. 'platform' => $platform,
  1602. 'pattern' => $pattern
  1603. );
  1604. }
  1605. }
  1606. }
  1607.  
  1608.  
  1609. if(!function_exists('avia_favicon'))
  1610. {
  1611. function avia_favicon($url = '')
  1612. {
  1613. $icon_link = $type = '';
  1614. if($url)
  1615. {
  1616. $type = 'image/x-icon';
  1617. if(strpos($url,'.png' )) $type = 'image/png';
  1618. if(strpos($url,'.gif' )) $type = 'image/gif';
  1619.  
  1620. $icon_link = '<link rel="icon" href="'.$url.'" type="'.$type.'">';
  1621. }
  1622.  
  1623. $icon_link = apply_filters('avf_favicon_final_output', $icon_link, $url, $type);
  1624.  
  1625. return $icon_link;
  1626. }
  1627. }
  1628.  
  1629. if(!function_exists('avia_regex'))
  1630. {
  1631. /*
  1632. * regex for url: http://mathiasbynens.be/demo/url-regex
  1633. */
  1634.  
  1635. function avia_regex($string, $pattern = false, $start = '^', $end = '')
  1636. {
  1637. if(!$pattern) return false;
  1638.  
  1639. if($pattern == 'url')
  1640. {
  1641. $pattern = "!$start((https?|ftp)://(-\.)?([^\s/?\.#-]+\.?)+(/[^\s]*)?)$end!";
  1642. }
  1643. else if($pattern == 'mail')
  1644. {
  1645. $pattern = "!$start\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$end!";
  1646. }
  1647. else if($pattern == 'image')
  1648. {
  1649. $pattern = "!$start(https?(?://([^/?#]*))?([^?#]*?\.(?:jpg|gif|png)))$end!";
  1650. }
  1651. else if(strpos($pattern,'<') === 0)
  1652. {
  1653. $pattern = str_replace('<','',$pattern);
  1654. $pattern = str_replace('>','',$pattern);
  1655.  
  1656. if(strpos($pattern,"/") !== 0) { $close = "\/>"; $pattern = str_replace('/','',$pattern); }
  1657. $pattern = trim($pattern);
  1658. if(!isset($close)) $close = "<\/".$pattern.">";
  1659.  
  1660. $pattern = "!$start\<$pattern.+?$close!";
  1661.  
  1662. }
  1663.  
  1664. preg_match($pattern, $string, $result);
  1665.  
  1666. if(empty($result[0]))
  1667. {
  1668. return false;
  1669. }
  1670. else
  1671. {
  1672. return $result;
  1673. }
  1674.  
  1675. }
  1676. }
  1677.  
  1678.  
  1679. if( ! function_exists( 'avia_debugging_info' ) )
  1680. {
  1681. function avia_debugging_info()
  1682. {
  1683. if ( is_feed() )
  1684. {
  1685. return;
  1686. }
  1687.  
  1688. $theme = wp_get_theme();
  1689. $child = '';
  1690.  
  1691. if( is_child_theme() )
  1692. {
  1693. $child = "- - - - - - - - - - -\n";
  1694. $child .= "ChildTheme: ".$theme->get('Name')."\n";
  1695. $child .= "ChildTheme Version: ".$theme->get('Version')."\n";
  1696. $child .= "ChildTheme Installed: ".$theme->get('Template')."\n\n";
  1697.  
  1698. $theme = wp_get_theme( $theme->get('Template') );
  1699. }
  1700.  
  1701. $info = "\n\n<!--\n";
  1702. $info .= "Debugging Info for Theme support: \n\n";
  1703. $info .= "Theme: ".$theme->get('Name')."\n";
  1704. $info .= "Version: ".$theme->get('Version')."\n";
  1705. $info .= "Installed: ".$theme->get_template()."\n";
  1706. $info .= "AviaFramework Version: ".AV_FRAMEWORK_VERSION."\n";
  1707.  
  1708.  
  1709. if( class_exists( 'AviaBuilder' ) )
  1710. {
  1711. $info .= 'AviaBuilder Version: ' . AviaBuilder::VERSION . "\n";
  1712.  
  1713. if( class_exists( 'aviaElementManager' ) )
  1714. {
  1715. $info .= 'aviaElementManager Version: ' . aviaElementManager::VERSION . "\n";
  1716. $update_state = get_option( 'av_alb_element_mgr_update', '' );
  1717. if( '' != $update_state )
  1718. {
  1719. $info .= "aviaElementManager update state: in update \n";
  1720. }
  1721. }
  1722. }
  1723.  
  1724.  
  1725. $info .= $child;
  1726.  
  1727. //memory setting, peak usage and number of active plugins
  1728. $info .= "ML:".trim( @ini_get("memory_limit") ,"M")."-PU:". ( ceil (memory_get_peak_usage() / 1000 / 1000 ) ) ."-PLA:".avia_count_active_plugins()."\n";
  1729. $info .= "WP:".get_bloginfo('version')."\n";
  1730.  
  1731. $comp_levels = array('none' => 'disabled', 'avia-module' => 'modules only', 'avia' => 'all theme files', 'all' => 'all files');
  1732.  
  1733. $info .= "Compress: CSS:".$comp_levels[avia_get_option('merge_css','avia-module')]." - JS:".$comp_levels[avia_get_option('merge_js','avia-module')]."\n";
  1734.  
  1735. $token = trim( avia_get_option( 'updates_envato_token' ) );
  1736. $username = avia_get_option( 'updates_username' );
  1737. $API = avia_get_option( 'updates_api_key' );
  1738.  
  1739. $updates = 'disabled';
  1740.  
  1741. if( ! empty( $token ) )
  1742. {
  1743. $token_state = trim( avia_get_option( 'updates_envato_token_state' ) );
  1744. $verified_token = trim( avia_get_option( 'updates_envato_verified_token' ) );
  1745.  
  1746. if( empty( $token_state ) )
  1747. {
  1748. $updates = 'enabled - unverified Envato token';
  1749. }
  1750. else
  1751. {
  1752. $updates = $token_state == $verified_token ? 'enabled - verified token' : 'enabled - token has changed and not verified';
  1753. }
  1754. }
  1755. else if( $username && $API )
  1756. {
  1757. $updates = 'enabled';
  1758. if( isset( $_GET['username'] ) )
  1759. {
  1760. $updates .= " ({$username})";
  1761. }
  1762.  
  1763. $updates .= ' - deprecated Envato API - register Envato Token';
  1764. }
  1765.  
  1766. $info .= 'Updates: ' . $updates . "\n";
  1767.  
  1768. /**
  1769. *
  1770. * @used_by enfold\includes\helper-assets.php av_untested_plugins_debugging_info() 10
  1771. * @param string
  1772. * @return string
  1773. */
  1774. $info = apply_filters( 'avf_debugging_info_add', $info );
  1775.  
  1776. $info .= '-->';
  1777.  
  1778. echo apply_filters('avf_debugging_info', $info);
  1779. }
  1780.  
  1781. add_action('wp_head','avia_debugging_info',9999999);
  1782. add_action('admin_print_scripts','avia_debugging_info',9999999);
  1783. }
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790. if(!function_exists('avia_count_active_plugins'))
  1791. {
  1792. function avia_count_active_plugins()
  1793. {
  1794. $plugins = count(get_option('active_plugins', array()));
  1795.  
  1796. if(is_multisite() && function_exists('get_site_option'))
  1797. {
  1798. $plugins += count(get_site_option('active_sitewide_plugins', array()));
  1799. }
  1800.  
  1801. return $plugins;
  1802. }
  1803. }
  1804.  
  1805.  
  1806.  
  1807.  
  1808.  
  1809.  
  1810. if(!function_exists('avia_clean_string'))
  1811. {
  1812. function avia_clean_string($string)
  1813. {
  1814. $string = str_replace(' ', '_', $string); // Replaces all spaces with underscores.
  1815. $string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
  1816.  
  1817. return preg_replace('/-+/', '-', strtolower ($string)); // Replaces multiple hyphens with single one.
  1818. }
  1819. }
  1820.  
  1821.  
  1822. if(!function_exists('kriesi_backlink'))
  1823. {
  1824. function kriesi_backlink($frontpage_only = false, $theme_name_passed = false)
  1825. {
  1826. $no = '';
  1827. $theme_string = '';
  1828. $theme_name = $theme_name_passed ? $theme_name_passed : THEMENAME;
  1829.  
  1830. $random_number = get_option(THEMENAMECLEAN.'_fixed_random');
  1831. if($random_number % 3 == 0) $theme_string = $theme_name.' Theme by Kriesi';
  1832. if($random_number % 3 == 1) $theme_string = $theme_name.' WordPress Theme by Kriesi';
  1833. if($random_number % 3 == 2) $theme_string = 'powered by '.$theme_name.' WordPress Theme';
  1834. if(!empty($frontpage_only) && !is_front_page()) $no = "rel='nofollow'";
  1835.  
  1836. $link = " - <a {$no} href='https://kriesi.at'>{$theme_string}</a>";
  1837.  
  1838. $link = apply_filters( 'kriesi_backlink', $link );
  1839. return $link;
  1840. }
  1841. }
  1842.  
  1843.  
  1844.  
  1845. if( ! function_exists( 'avia_header_class_filter' ) )
  1846. {
  1847. function avia_header_class_filter( $default = '' )
  1848. {
  1849. $default = apply_filters( 'avia_header_class_filter', $default );
  1850. return $default;
  1851. }
  1852. }
  1853.  
  1854.  
  1855. if( ! function_exists( 'avia_theme_version_higher_than' ) )
  1856. {
  1857. /**
  1858. * Checks for parent theme version >= a given version
  1859. *
  1860. * @since < 4.0
  1861. * @param string $check_for_version
  1862. * @return boolean
  1863. */
  1864. function avia_theme_version_higher_than( $check_for_version = '' )
  1865. {
  1866. $theme_version = avia_get_theme_version();
  1867.  
  1868. if( version_compare( $theme_version, $check_for_version , '>=' ) )
  1869. {
  1870. return true;
  1871. }
  1872.  
  1873. return false;
  1874. }
  1875. }
  1876.  
  1877. if( ! function_exists( 'avia_enqueue_style_conditionally' ) )
  1878. {
  1879. /**
  1880. * Enque a css file, based on theme options or other conditions that get passed and must be evaluated as true
  1881. *
  1882. * 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
  1883. * @since 4.3
  1884. * @added_by Kriesi
  1885. * @param boolean $condition
  1886. * @param string $handle
  1887. * @param string $src
  1888. * @param array $deps
  1889. * @param boolean|string $ver
  1890. * @param string $media
  1891. * @param boolean $deregister
  1892. * @return void
  1893. */
  1894. function avia_enqueue_style_conditionally( $condition = false, $handle = '', $src = '', $deps = array(), $ver = false, $media = 'all', $deregister = true )
  1895. {
  1896. if( $condition == false )
  1897. {
  1898. if( $deregister )
  1899. {
  1900. wp_deregister_style( $handle );
  1901. }
  1902.  
  1903. return;
  1904. }
  1905.  
  1906. wp_enqueue_style( $handle, $src, $deps, $ver, $media );
  1907. }
  1908. }
  1909.  
  1910. if( ! function_exists( 'avia_enqueue_script_conditionally' ) )
  1911. {
  1912. /**
  1913. * Enque a js file, based on theme options or other conditions that get passed and must be evaluated as true
  1914. *
  1915. * 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
  1916. * @since 4.3
  1917. * @added_by Kriesi
  1918. * @param boolean $condition
  1919. * @param string $handle
  1920. * @param string $src
  1921. * @param array $deps
  1922. * @param boolean|string $ver
  1923. * @param boolean $in_footer
  1924. * @param boolean $deregister
  1925. * @return void
  1926. */
  1927. function avia_enqueue_script_conditionally( $condition = false, $handle = '', $src = '', $deps = array(), $ver = false, $in_footer = false, $deregister = true )
  1928. {
  1929. if( $condition == false )
  1930. {
  1931. if( $deregister )
  1932. {
  1933. wp_deregister_script( $handle );
  1934. }
  1935.  
  1936. return;
  1937. }
  1938.  
  1939. wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
  1940. }
  1941. }
  1942.  
  1943. if( ! function_exists( 'avia_disable_query_migrate' ) )
  1944. {
  1945. /**
  1946. * Makes sure that jquery no longer depends on jquery migrate.
  1947. *
  1948. * @since 4.3
  1949. * @added_by Kriesi
  1950. * @param array $condition
  1951. * @return array
  1952. */
  1953. function avia_disable_query_migrate()
  1954. {
  1955. global $wp_scripts;
  1956.  
  1957. if( ! is_admin() )
  1958. {
  1959. if( isset( $wp_scripts->registered['jquery'] ) )
  1960. {
  1961. foreach( $wp_scripts->registered['jquery']->deps as $key => $dep )
  1962. {
  1963. if( $dep == 'jquery-migrate' )
  1964. {
  1965. unset( $wp_scripts->registered['jquery']->deps[ $key ] );
  1966. }
  1967. }
  1968. }
  1969. }
  1970. }
  1971. }
  1972.  
  1973. if( ! function_exists( 'avia_get_submenu_count' ) )
  1974. {
  1975. /**
  1976. * Counts the number of submenu items of a menu
  1977. *
  1978. * @since 4.3
  1979. * @added_by Kriesi
  1980. * @param array $location
  1981. * @return int $count
  1982. */
  1983. function avia_get_submenu_count( $location )
  1984. {
  1985. $menus = get_nav_menu_locations();
  1986. $count = 0;
  1987.  
  1988. if( ! isset( $menus[ $location ] ) )
  1989. {
  1990. return $count;
  1991. }
  1992.  
  1993. $items = wp_get_nav_menu_items( $menus[ $location ] );
  1994.  
  1995. //if no menu is set we dont know if the fallback menu will generate submenu items so we assume thats true
  1996. if( ! $items )
  1997. {
  1998. return 1;
  1999. }
  2000.  
  2001. foreach( $items as $item )
  2002. {
  2003. if( isset( $item->menu_item_parent ) && $item->menu_item_parent > 0 )
  2004. {
  2005. $count++;
  2006. }
  2007. }
  2008.  
  2009. return $count;
  2010. }
  2011. }
  2012.  
  2013. if( ! function_exists( 'avia_get_active_widget_count' ) )
  2014. {
  2015. /**
  2016. * Counts the number of active widget areas (widget areas that got a widget inside them are considered active)
  2017. *
  2018. * @since 4.3
  2019. * @added_by Kriesi
  2020. * @return int $count
  2021. */
  2022. function avia_get_active_widget_count()
  2023. {
  2024. global $_wp_sidebars_widgets;
  2025.  
  2026. $count = 0;
  2027.  
  2028. foreach( $_wp_sidebars_widgets as $widget_area => $widgets )
  2029. {
  2030. if( $widget_area == 'wp_inactive_widgets' || $widget_area == 'array_version' )
  2031. {
  2032. continue;
  2033. }
  2034.  
  2035. if( ! empty( $widgets ) )
  2036. {
  2037. $count++;
  2038. }
  2039. }
  2040.  
  2041. return $count;
  2042. }
  2043. }
  2044.  
  2045. if( ! function_exists( 'avia_get_theme_version' ) )
  2046. {
  2047. /**
  2048. * Helper function that returns the (parent) theme version number to be added to scipts and css links
  2049. *
  2050. * @since 4.3.2
  2051. * @added_by Günter
  2052. * @return string
  2053. */
  2054. function avia_get_theme_version( $which = 'parent' )
  2055. {
  2056. $theme = wp_get_theme();
  2057. if( false !== $theme->parent() && ( 'parent' == $which ) )
  2058. {
  2059. $theme = $theme->parent();
  2060. }
  2061. $vn = $theme->get( 'Version' );
  2062.  
  2063. return $vn;
  2064. }
  2065. }
  2066.  
  2067. if( ! function_exists( 'handler_wp_targeted_link_rel' ) )
  2068. {
  2069. /**
  2070. * Eliminates rel noreferrer and noopener from links that are not cross origin.
  2071. *
  2072. * @since 4.6.3
  2073. * @added_by Günter
  2074. * @param string $rel 'noopener noreferrer'
  2075. * @param string $link_html space separated string of a attributes
  2076. * @return string
  2077. */
  2078. function handler_wp_targeted_link_rel( $rel, $link_html )
  2079. {
  2080. $url = get_bloginfo( 'url' );
  2081. $url = str_ireplace( array( 'http://', 'https://' ), '', $url );
  2082.  
  2083. $href = '';
  2084. $found = preg_match( '/href=["\']?([^"\'>]+)["\']?/', $link_html, $href );
  2085. if( empty( $found ) )
  2086. {
  2087. return $rel;
  2088. }
  2089.  
  2090. $info = explode( '?', $href[1] );
  2091.  
  2092. if( false !== stripos( $info[0], $url ) )
  2093. {
  2094. return '';
  2095. }
  2096.  
  2097. return $rel;
  2098. }
  2099.  
  2100. add_filter( 'wp_targeted_link_rel', 'handler_wp_targeted_link_rel', 10, 2 );
  2101. }
  2102.  
  2103.  
  2104. if( ! function_exists( 'handler_wp_walker_nav_menu_start_el' ) )
  2105. {
  2106. /**
  2107. * Apply security fix for external links
  2108. *
  2109. * @since 4.6.3
  2110. * @added_by Günter
  2111. * @param string $item_output The menu item's starting HTML output.
  2112. * @param WP_Post|mixed $item Menu item data object.
  2113. * @param int $depth Depth of menu item. Used for padding.
  2114. * @param stdClass $args An object of wp_nav_menu() arguments.
  2115. * @return type
  2116. */
  2117. function handler_wp_walker_nav_menu_start_el( $item_output, $item, $depth, $args )
  2118. {
  2119. $item_output = avia_targeted_link_rel( $item_output );
  2120. return $item_output;
  2121. }
  2122.  
  2123. add_filter( 'walker_nav_menu_start_el', 'handler_wp_walker_nav_menu_start_el', 10, 4 );
  2124. }
  2125.  
  2126. if( ! function_exists( 'avia_targeted_link_rel' ) )
  2127. {
  2128. /**
  2129. * Wrapper function for backwards comp. with older WP vrsions
  2130. *
  2131. * @since 4.6.3
  2132. * @uses wp_targeted_link_rel @since 5.1.0
  2133. * @uses handler_wp_targeted_link_rel filter wp_targeted_link_rel
  2134. * @added_by Günter
  2135. * @param string $text
  2136. * @param true|string $exec_call true | 'translate' | 'reverse'
  2137. * @return string
  2138. */
  2139. function avia_targeted_link_rel( $text, $exec_call = true )
  2140. {
  2141. /**
  2142. * For older WP versions we skip this feature
  2143. */
  2144. if( ! function_exists( 'wp_targeted_link_rel' ) )
  2145. {
  2146. return $text;
  2147. }
  2148.  
  2149. global $wp_version;
  2150.  
  2151. /**
  2152. * WP changed the way it splits the attributes. '_' is not supported as a valid attribute and removes these attributes.
  2153. * See wp-includes\kses.php wp_kses_hair( $attr, $allowed_protocols );
  2154. * This breaks our data-xxx attributes like data-av_icon.
  2155. *
  2156. * This might change in a future version of WP.
  2157. */
  2158. if( version_compare( $wp_version, '5.3.1', '<' ) )
  2159. {
  2160. return true === $exec_call ? wp_targeted_link_rel( $text ) : $text;
  2161. }
  2162.  
  2163. /**
  2164. * Do not run (more expensive) regex if no links with targets
  2165. */
  2166. if( stripos( $text, 'target' ) === false || stripos( $text, '<a ' ) === false || is_serialized( $text ) )
  2167. {
  2168. return $text;
  2169. }
  2170.  
  2171. $attr_translate = array(
  2172. 'data-av_icon',
  2173. 'data-av_iconfont',
  2174. 'data-fbscript_id'
  2175. );
  2176.  
  2177. /**
  2178. * Add more custom attributes that are removed by WP
  2179. *
  2180. * @since 4.6.4
  2181. * @param array
  2182. * @retrun array
  2183. */
  2184. $attr_translate = apply_filters( 'avf_translate_targeted_link_rel_attributes', $attr_translate );
  2185.  
  2186. $trans_attributes = array();
  2187. foreach( $attr_translate as $value )
  2188. {
  2189. $trans_attributes[] = str_replace( '_', '----', $value);
  2190. }
  2191.  
  2192. // Fallback - this might break page, but version is already outdated
  2193. if( version_compare( phpversion(), '5.3', '<' ) )
  2194. {
  2195. $text_trans = str_replace( $attr_translate, $trans_attributes, $text );
  2196. $text_trans = wp_targeted_link_rel( $text_trans );
  2197. return str_replace( $trans_attributes, $attr_translate, $text_trans );
  2198. }
  2199.  
  2200. /**
  2201. * To avoid breaking a page we do not replace the the attribute names with simple str_replace but
  2202. * use the same way WP does to filter the a tags for replacing
  2203. *
  2204. * see wp-includes\formatting.php
  2205. */
  2206. $script_and_style_regex = '/<(script|style).*?<\/\\1>/si';
  2207.  
  2208. $test_exec = true === $exec_call ? 'true' : $exec_call;
  2209. switch( $test_exec )
  2210. {
  2211. case 'reverse':
  2212. $start = 1;
  2213. break;
  2214. case 'translate':
  2215. case 'true':
  2216. default:
  2217. $start = 0;
  2218. break;
  2219. }
  2220.  
  2221. for( $iteration = $start; $iteration < 2; $iteration++ )
  2222. {
  2223. $matches = array();
  2224. preg_match_all( $script_and_style_regex, $text, $matches );
  2225. $extra_parts = $matches[0];
  2226. $html_parts = preg_split( $script_and_style_regex, $text );
  2227.  
  2228. switch( $iteration )
  2229. {
  2230. case 0;
  2231. $source = $attr_translate;
  2232. $replace = $trans_attributes;
  2233. break;
  2234. case 1:
  2235. default:
  2236. $source = $trans_attributes;
  2237. $replace = $attr_translate;
  2238. break;
  2239. }
  2240.  
  2241. foreach ( $html_parts as &$part )
  2242. {
  2243. $part = preg_replace_callback( '|<a\s([^>]*target\s*=[^>]*)>|i', function ( $matches ) use( $source, $replace )
  2244. {
  2245. $link_html = $matches[1];
  2246.  
  2247. // Consider the html escaped if there are no unescaped quotes
  2248. $is_escaped = ! preg_match( '/(^|[^\\\\])[\'"]/', $link_html );
  2249. if ( $is_escaped )
  2250. {
  2251. // Replace only the quotes so that they are parsable by wp_kses_hair, leave the rest as is
  2252. $link_html = preg_replace( '/\\\\([\'"])/', '$1', $link_html );
  2253. }
  2254.  
  2255. foreach( $source as $key => $value )
  2256. {
  2257. $link_html = preg_replace( '|' . $value . '\s*=|i', $replace[ $key ] . '=', $link_html );
  2258. }
  2259.  
  2260. if ( $is_escaped )
  2261. {
  2262. $link_html = preg_replace( '/[\'"]/', '\\\\$0', $link_html );
  2263. }
  2264.  
  2265. return "<a {$link_html}>";
  2266.  
  2267. }, $part );
  2268. }
  2269.  
  2270. unset( $part );
  2271.  
  2272. $text = '';
  2273. for( $i = 0; $i < count( $html_parts ); $i++ )
  2274. {
  2275. $text .= $html_parts[ $i ];
  2276. if( isset( $extra_parts[ $i ] ) )
  2277. {
  2278. $text .= $extra_parts[ $i ];
  2279. }
  2280. }
  2281.  
  2282. switch( $iteration )
  2283. {
  2284. case 0;
  2285. if( true === $exec_call )
  2286. {
  2287. $text = wp_targeted_link_rel( $text );
  2288. }
  2289. break;
  2290. default:
  2291. break;
  2292. }
  2293.  
  2294. if( 'translate' == $test_exec )
  2295. {
  2296. break;
  2297. }
  2298. }
  2299.  
  2300. return $text;
  2301. }
  2302. }
  2303.  
  2304. if( ! function_exists( 'handler_avia_widget_text' ) )
  2305. {
  2306. add_filter( 'widget_text', 'handler_avia_widget_text', 90000, 3 );
  2307.  
  2308. /**
  2309. * Replace attributes with _ that wp_targeted_link_rel() does not remove them
  2310. *
  2311. * @since 4.6.4
  2312. * @param string $content
  2313. * @param array $instance
  2314. * @param WP_Widget $widget
  2315. * @return type
  2316. */
  2317. function handler_avia_widget_text( $content = '', $instance = null, $widget = null )
  2318. {
  2319. /**
  2320. * To support WP_Widget_Text:
  2321. *
  2322. * - Needs js code to replace translated attributes in frontend as this widget has no filter after call to wp_targeted_link_rel()
  2323. * or
  2324. * - Add a filter to wp-includes\widgets\class-wp-widget-text.php after wp_targeted_link_rel() call
  2325. */
  2326. if( ! $widget instanceof WP_Widget_Custom_HTML || ! is_string( $content ) )
  2327. {
  2328. return $content;
  2329. }
  2330.  
  2331. return avia_targeted_link_rel( $content, 'translate' );
  2332. }
  2333. }
  2334.  
  2335. if( ! function_exists( 'handler_avia_widget_custom_html_content' ) )
  2336. {
  2337. add_filter( 'widget_custom_html_content', 'handler_avia_widget_custom_html_content', 90000, 3 );
  2338.  
  2339. /**
  2340. * Revert changes to attributes with _
  2341. *
  2342. * @since 4.6.4
  2343. * @param string $content
  2344. * @param array $instance
  2345. * @param WP_Widget $widget
  2346. * @return string
  2347. */
  2348. function handler_avia_widget_custom_html_content( $content = '', $instance = null, $widget = null )
  2349. {
  2350. if( ! is_string( $content ) )
  2351. {
  2352. return $content;
  2353. }
  2354.  
  2355. return avia_targeted_link_rel( $content, 'reverse' );
  2356. }
  2357. }
  2358.  
  2359.  
Advertisement
Add Comment
Please, Sign In to add comment