Advertisement
Guest User

Untitled

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