Guest User

Untitled

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