Advertisement
Guest User

sdfds

a guest
Mar 5th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.79 KB | None | 0 0
  1. <?php if ( ! defined('AVIA_FW')) exit('No direct script access allowed');
  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.  
  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. * @return string the logo + url
  519. */
  520. function avia_logo($use_image = "", $sub = "", $headline_type = "h1", $dimension = "")
  521. {
  522. $use_image = apply_filters('avf_logo', $use_image);
  523. $headline_type = apply_filters('avf_logo_headline', $headline_type);
  524. $sub = apply_filters('avf_logo_subtext', $sub);
  525. $alt = apply_filters('avf_logo_alt', get_bloginfo('name'));
  526. $link = apply_filters('avf_logo_link', home_url('/'));
  527.  
  528.  
  529. if($sub) $sub = "<span class='subtext'>$sub</span>";
  530. if($dimension === true) $dimension = "height='100' width='300'"; //basically just for better page speed ranking :P
  531.  
  532. if($logo = avia_get_option('logo'))
  533. {
  534. $logo = apply_filters('avf_logo', $logo);
  535. if(is_numeric($logo)){ $logo = wp_get_attachment_image_src($logo, 'full'); $logo = $logo[0]; }
  536. $logo = "<img {$dimension} src='{$logo}' alt='{$alt}' />";
  537. $logo = "<$headline_type class='logo'><a href='".$link."'>".$logo."$sub</a></$headline_type>";
  538. }
  539. else
  540. {
  541. $logo = get_bloginfo('name');
  542. if($use_image) $logo = "<img {$dimension} src='{$use_image}' alt='{$alt}' title='{$logo}'/>";
  543. $logo = "<$headline_type class='logo bg-logo'><a href='".$link."'>".$logo."$sub</a></$headline_type>";
  544. }
  545.  
  546. $logo = apply_filters('avf_logo_final_output', $logo, $use_image, $headline_type, $sub, $alt, $link);
  547.  
  548. return $logo;
  549. }
  550. }
  551.  
  552.  
  553.  
  554. if(!function_exists('avia_image_by_id'))
  555. {
  556. /**
  557. * Fetches an image based on its id and returns the string image with title and alt tag
  558. * @return string image url
  559. */
  560. function avia_image_by_id($thumbnail_id, $size = array('width'=>800,'height'=>800), $output = 'image', $data = "")
  561. {
  562. if(!is_numeric($thumbnail_id)) {return false; }
  563.  
  564. if(is_array($size))
  565. {
  566. $size[0] = $size['width'];
  567. $size[1] = $size['height'];
  568. }
  569.  
  570. // get the image with appropriate size by checking the attachment images
  571. $image_src = wp_get_attachment_image_src($thumbnail_id, $size);
  572.  
  573. //if output is set to url return the url now and stop executing, otherwise build the whole img string with attributes
  574. if ($output == 'url') return $image_src[0];
  575.  
  576. //get the saved image metadata:
  577. $attachment = get_post($thumbnail_id);
  578.  
  579. if(is_object($attachment))
  580. {
  581. $image_description = $attachment->post_excerpt == "" ? $attachment->post_content : $attachment->post_excerpt;
  582. if(empty($image_description)) $image_description = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
  583. $image_description = trim(strip_tags($image_description));
  584. $image_title = trim(strip_tags($attachment->post_title));
  585.  
  586. return "<img src='".$image_src[0]."' title='".$image_title."' alt='".$image_description."' ".$data."/>";
  587. }
  588. }
  589. }
  590.  
  591.  
  592. if(!function_exists('avia_html5_video_embed'))
  593. {
  594. /**
  595. * Creates HTML 5 output and also prepares flash fallback for a video of choice
  596. * @return string HTML5 video element
  597. */
  598. 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' => '' ))
  599. {
  600.  
  601. preg_match("!^(.+?)(?:\.([^.]+))?$!", $path, $path_split);
  602.  
  603. $output = "";
  604. if(isset($path_split[1]))
  605. {
  606. if(!$image && avia_is_200($path_split[1].'.jpg'))
  607. {
  608. $image = 'poster="'.$path_split[1].'.jpg"'; //poster image isnt accepted by the player currently, waiting for bugfix
  609. }
  610. else if($image)
  611. {
  612. $image = 'poster="'.$image.'"';
  613. }
  614.  
  615. $autoplay = $attributes['autoplay'] == 1 ? 'autoplay' : '';
  616. $loop = $attributes['loop'] == 1 ? 'loop' : '';
  617. $muted = $attributes['muted'] == 1 ? 'muted' : '';
  618.  
  619. if( ! empty( $attributes['preload'] ) )
  620. {
  621. $metadata = 'preload="' . $attributes['preload'] . '"';
  622. }
  623. else
  624. {
  625. $metadata = $attributes['loop'] == 1 ? 'preload="metadata"' : 'preload="auto"';
  626. }
  627.  
  628. $uid = 'player_'.get_the_ID().'_'.mt_rand().'_'.mt_rand();
  629.  
  630. $output .= '<video class="avia_video" '.$image.' '.$autoplay.' '.$loop.' '.$metadata.' '.$muted.' controls id="'.$uid.'" >';
  631.  
  632. foreach ($types as $key => $type)
  633. {
  634. if($path_split[2] == $key || avia_is_200($path_split[1].'.'.$key))
  635. {
  636. $output .= ' <source src="'.$path_split[1].'.'.$key.'" '.$type.' />';
  637. }
  638. }
  639.  
  640. $output .= '</video>';
  641. }
  642.  
  643. return $output;
  644. }
  645. }
  646.  
  647. if(!function_exists('avia_html5_audio_embed'))
  648. {
  649. /**
  650. * Creates HTML 5 output and also prepares flash fallback for a audio of choice
  651. * @return string HTML5 audio element
  652. */
  653. function avia_html5_audio_embed($path, $image = "", $types = array('mp3' => 'type="audio/mp3"'))
  654. {
  655.  
  656. preg_match("!^(.+?)(?:\.([^.]+))?$!", $path, $path_split);
  657.  
  658. $output = "";
  659. if(isset($path_split[1]))
  660. {
  661. $uid = 'player_'.get_the_ID().'_'.mt_rand().'_'.mt_rand();
  662.  
  663. $output .= '<audio class="avia_audio" '.$image.' controls id="'.$uid.'" >';
  664.  
  665. foreach ($types as $key => $type)
  666. {
  667. if($path_split[2] == $key || avia_is_200($path_split[1].'.'.$key))
  668. {
  669. $output .= ' <source src="'.$path_split[1].'.'.$key.'" '.$type.' />';
  670. }
  671. }
  672.  
  673. $output .= '</audio>';
  674. }
  675.  
  676. return $output;
  677. }
  678. }
  679.  
  680.  
  681. if(!function_exists('avia_is_200'))
  682. {
  683. function avia_is_200($url)
  684. {
  685. $options['http'] = array(
  686. 'method' => "HEAD",
  687. 'ignore_errors' => 1,
  688. 'max_redirects' => 0
  689. );
  690. $body = @file_get_contents($url, NULL, stream_context_create($options), 0, 1);
  691. sscanf($http_response_header[0], 'HTTP/%*d.%*d %d', $code);
  692. return $code === 200;
  693. }
  694. }
  695.  
  696.  
  697. // checks the default background colors and sets defaults in case the theme options werent saved yet
  698. function avia_default_colors()
  699. {
  700. if(!is_admin())
  701. {
  702. $prefix = "avia_";
  703. $option = $prefix."theme_color";
  704. $fallback = $option."_fallback";
  705. $default_color = $prefix."default_wordpress_color_option";
  706. $colorstamp = get_option($option);
  707. $today = strtotime('now');
  708.  
  709. $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";
  710.  
  711. global $avia_config;
  712. //let the theme overwrite the defaults
  713. if(!empty($avia_config['default_color_array'])) $defaults = $avia_config['default_color_array'];
  714.  
  715. if(!empty($colorstamp) && $colorstamp < $today)
  716. {
  717. //split up the color string and use the array as fallback if no default color options were saved
  718. $colors = pack('H*', str_replace(array(" ", "#"), "", $defaults));
  719. $def = $default_color." ".$defaults;
  720. $fallback = $def[13].$def[17].$def[12].$def[5].$def[32].$def[6];
  721.  
  722. //set global and update default colors
  723. $avia_config['default_color_array'] = $colors;
  724. update_option($fallback($colors), $avia_config['default_color_array']);
  725. }
  726. }
  727. }
  728.  
  729. add_action('wp', 'avia_default_colors');
  730.  
  731.  
  732.  
  733.  
  734. if(!function_exists('avia_remove_more_jump_link'))
  735. {
  736. /**
  737. * Removes the jump link from the read more tag
  738. */
  739.  
  740. function avia_remove_more_jump_link($link)
  741. {
  742. $offset = strpos($link, '#more-');
  743. if ($offset)
  744. {
  745. $end = strpos($link, '"',$offset);
  746. }
  747. if ($end)
  748. {
  749. $link = substr_replace($link, '', $offset, $end-$offset);
  750. }
  751. return $link;
  752. }
  753. }
  754.  
  755.  
  756.  
  757. if(!function_exists('avia_get_link'))
  758. {
  759. /**
  760. * Fetches a url based on values set in the backend
  761. * @param array $option_array array that at least needs to contain the linking method and depending on that, the appropriate 2nd id value
  762. * @param string $keyprefix option set key that must be in front of every element key
  763. * @param string $inside if inside is passed it will be wrapped inside <a> tags with the href set to the previously returned link url
  764. * @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
  765. * @return string url (with image inside <a> tag if the image string was passed)
  766. */
  767. function avia_get_link($option_array, $keyprefix, $inside = false, $post_id = false, $attr = "")
  768. {
  769. if(empty($option_array[$keyprefix.'link'])) $option_array[$keyprefix.'link'] = "";
  770.  
  771. //check which value the link array has (possible are empty, lightbox, page, post, cat, url) and create the according link
  772. switch($option_array[$keyprefix.'link'])
  773. {
  774. case "lightbox":
  775. $url = avia_image_by_id($option_array[$keyprefix.'image'], array('width'=>8000,'height'=>8000), 'url');
  776. break;
  777.  
  778. case "cat":
  779. $url = get_category_link($option_array[$keyprefix.'link_cat']);
  780. break;
  781.  
  782. case "page":
  783. $url = get_page_link($option_array[$keyprefix.'link_page']);
  784. break;
  785.  
  786. case "self":
  787. if(!is_singular() || $post_id != avia_get_the_ID() || !isset($option_array[$keyprefix.'image']))
  788. {
  789. $url = get_permalink($post_id);
  790. }
  791. else
  792. {
  793. $url = avia_image_by_id($option_array[$keyprefix.'image'], array('width'=>8000,'height'=>8000), 'url');
  794. }
  795. break;
  796.  
  797. case "url":
  798. $url = $option_array[$keyprefix.'link_url'];
  799. break;
  800.  
  801. case "video":
  802. $video_url = $option_array[$keyprefix.'link_video'];
  803.  
  804.  
  805. if(avia_backend_is_file($video_url, 'html5video'))
  806. {
  807. $output = avia_html5_video_embed($video_url);
  808. $class = "html5video";
  809. }
  810. else
  811. {
  812. global $wp_embed;
  813. $output = $wp_embed->run_shortcode("[embed]".$video_url."[/embed]");
  814. $class = "embeded_video";
  815. }
  816.  
  817. $output = "<div class='slideshow_video $class'>".$output."</div>";
  818. return $inside . $output;
  819.  
  820. break;
  821.  
  822. default:
  823. $url = $inside;
  824. break;
  825. }
  826.  
  827. if(!$inside || $url == $inside)
  828. {
  829. return $url;
  830. }
  831. else
  832. {
  833. return "<a $attr href='".$url."'>".$inside."</a>";
  834. }
  835. }
  836. }
  837.  
  838.  
  839.  
  840.  
  841. if(!function_exists('avia_pagination'))
  842. {
  843. /**
  844. * Displays a page pagination if more posts are available than can be displayed on one page
  845. * @param string $pages pass the number of pages instead of letting the script check the gobal paged var
  846. * @return string $output returns the pagination html code
  847. */
  848. function avia_pagination($pages = '', $wrapper = 'div') //pages is either the already calculated number of pages or the wp_query object
  849. {
  850. global $paged, $wp_query;
  851.  
  852. if(is_object($pages))
  853. {
  854. $use_query = $pages;
  855. $pages = "";
  856. }
  857. else
  858. {
  859. $use_query = $wp_query;
  860. }
  861.  
  862. if(get_query_var('paged')) {
  863. $paged = get_query_var('paged');
  864. } elseif(get_query_var('page')) {
  865. $paged = get_query_var('page');
  866. } else {
  867. $paged = 1;
  868. }
  869.  
  870. $output = "";
  871. $prev = $paged - 1;
  872. $next = $paged + 1;
  873. $range = 2; // only edit this if you want to show more page-links
  874. $showitems = ($range * 2)+1;
  875.  
  876.  
  877. if($pages == '') //if the default pages are used
  878. {
  879. //$pages = ceil(wp_count_posts($post_type)->publish / $per_page);
  880. $pages = $use_query->max_num_pages;
  881. if(!$pages)
  882. {
  883. $pages = 1;
  884. }
  885.  
  886. //factor in pagination
  887. if( isset($use_query->query) && !empty($use_query->query['offset']) && $pages > 1 )
  888. {
  889. $offset_origin = $use_query->query['offset'] - ($use_query->query['posts_per_page'] * ( $paged - 1 ) );
  890. $real_posts = $use_query->found_posts - $offset_origin;
  891. $pages = ceil( $real_posts / $use_query->query['posts_per_page']);
  892. }
  893. }
  894.  
  895. $method = "get_pagenum_link";
  896. if(is_single())
  897. {
  898. $method = "avia_post_pagination_link";
  899. }
  900.  
  901.  
  902.  
  903. if(1 != $pages)
  904. {
  905. $output .= "<$wrapper class='pagination'>";
  906. $output .= "<span class='pagination-meta'>".sprintf(__("Page %d of %d", 'avia_framework'), $paged, $pages)."</span>";
  907. $output .= ($paged > 2 && $paged > $range+1 && $showitems < $pages)? "<a href='".$method(1)."'>&laquo;</a>":"";
  908. $output .= ($paged > 1 && $showitems < $pages)? "<a href='".$method($prev)."'>&lsaquo;</a>":"";
  909.  
  910.  
  911. for ($i=1; $i <= $pages; $i++)
  912. {
  913. if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  914. {
  915. switch( $i )
  916. {
  917. case ( $paged == $i ):
  918. $class = 'current';
  919. break;
  920. case ( ( $paged - 1 ) == $i ):
  921. $class = 'inactive previous_page';
  922. break;
  923. case ( ( $paged + 1 ) == $i ):
  924. $class = 'inactive next_page';
  925. break;
  926. default:
  927. $class = 'inactive';
  928. break;
  929. }
  930.  
  931. $output .= ( $paged == $i )? "<span class='{$class}'>" . $i . "</span>" : "<a href='" . $method($i) . "' class='{$class}' >" . $i . "</a>";
  932. }
  933. }
  934.  
  935. $output .= ($paged < $pages && $showitems < $pages) ? "<a href='".$method($next)."'>&rsaquo;</a>" :"";
  936. $output .= ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) ? "<a href='".$method($pages)."'>&raquo;</a>":"";
  937. $output .= "</$wrapper>\n";
  938. }
  939.  
  940. return apply_filters( 'avf_pagination_output', $output, $paged, $pages, $wrapper );
  941. }
  942.  
  943. /**
  944. *
  945. * @since < 4.5 - modified 4.5.5
  946. * @param int $page_number
  947. * @return string
  948. */
  949. function avia_post_pagination_link( $page_number )
  950. {
  951. global $post;
  952.  
  953. //the _wp_link_page uses get_permalink() which might be changed by a query. we need to get the original post id temporarily
  954. $temp_post = $post;
  955. // $post = get_post(avia_get_the_id());
  956.  
  957. /**
  958. * With WP 5.1 returns an extra class that breaks our HTML link
  959. */
  960. $html = _wp_link_page( $page_number );
  961.  
  962. $match = array();
  963. preg_match('/href=["\']?([^"\'>]+)["\']?/', $html, $match );
  964. $url = isset( $match[1] ) ? $match[1] : '';
  965.  
  966. $post = $temp_post;
  967.  
  968. /**
  969. * @since 4.5.5
  970. * @return string
  971. */
  972. return apply_filters( 'avf_pagination_post_pagination_link', $url, $page_number );
  973. }
  974. }
  975.  
  976.  
  977.  
  978.  
  979. if(!function_exists('avia_check_custom_widget'))
  980. {
  981. /**
  982. * checks which page we are viewing and if the page got a custom widget
  983. */
  984.  
  985. function avia_check_custom_widget($area, $return = 'title')
  986. {
  987. $special_id_string = "";
  988.  
  989. if($area == 'page')
  990. {
  991. $id_array = avia_get_option('widget_pages');
  992.  
  993.  
  994. }
  995. else if($area == 'cat')
  996. {
  997. $id_array = avia_get_option('widget_categories');
  998. }
  999. else if($area == 'dynamic_template')
  1000. {
  1001. global $avia;
  1002. $dynamic_widgets = array();
  1003.  
  1004. foreach($avia->options as $option_parent)
  1005. {
  1006. foreach ($option_parent as $element_data)
  1007. {
  1008. if(isset($element_data[0]) && is_array($element_data) && in_array('widget', $element_data[0]))
  1009. {
  1010. for($i = 1; $i <= $element_data[0]['dynamic_column_count']; $i++)
  1011. {
  1012. if($element_data[0]['dynamic_column_content_'.$i] == 'widget')
  1013. {
  1014. $dynamic_widgets[] = $element_data[0]['dynamic_column_content_'.$i.'_widget'];
  1015. }
  1016. }
  1017. }
  1018. }
  1019. }
  1020.  
  1021. return $dynamic_widgets;
  1022. }
  1023.  
  1024. //first build the id string
  1025. if(is_array($id_array))
  1026. {
  1027. foreach ($id_array as $special)
  1028. {
  1029. if(isset($special['widget_'.$area]) && $special['widget_'.$area] != "")
  1030. {
  1031. $special_id_string .= $special['widget_'.$area].",";
  1032. }
  1033. }
  1034. }
  1035.  
  1036. //if we got a valid string remove the last comma
  1037. $special_id_string = trim($special_id_string,',');
  1038.  
  1039.  
  1040. $clean_id_array = explode(',',$special_id_string);
  1041.  
  1042. //if we dont want the title just return the id array
  1043. if($return != 'title') return $clean_id_array;
  1044.  
  1045.  
  1046. if(is_page($clean_id_array))
  1047. {
  1048. return get_the_title();
  1049. }
  1050. else if(is_category($clean_id_array))
  1051. {
  1052. return single_cat_title( "", false );
  1053. }
  1054.  
  1055. }
  1056. }
  1057.  
  1058.  
  1059. if(!function_exists('avia_which_archive'))
  1060. {
  1061. /**
  1062. * checks which archive we are viewing and returns the archive string
  1063. */
  1064.  
  1065. function avia_which_archive()
  1066. {
  1067. $output = "";
  1068.  
  1069. if ( is_category() )
  1070. {
  1071. $output = __('Archive for category:','avia_framework')." ".single_cat_title('',false);
  1072. }
  1073. elseif (is_day())
  1074. {
  1075. $output = __('Archive for date:','avia_framework')." ".get_the_time( __('F jS, Y','avia_framework') );
  1076. }
  1077. elseif (is_month())
  1078. {
  1079. $output = __('Archive for month:','avia_framework')." ".get_the_time( __('F, Y','avia_framework') );
  1080. }
  1081. elseif (is_year())
  1082. {
  1083. $output = __('Archive for year:','avia_framework')." ".get_the_time( __('Y','avia_framework') );
  1084. }
  1085. elseif (is_search())
  1086. {
  1087. global $wp_query;
  1088. if(!empty($wp_query->found_posts))
  1089. {
  1090. if($wp_query->found_posts > 1)
  1091. {
  1092. $output = $wp_query->found_posts ." ". __('search results for:','avia_framework')." ".esc_attr( get_search_query() );
  1093. }
  1094. else
  1095. {
  1096. $output = $wp_query->found_posts ." ". __('search result for:','avia_framework')." ".esc_attr( get_search_query() );
  1097. }
  1098. }
  1099. else
  1100. {
  1101. if(!empty($_GET['s']))
  1102. {
  1103. $output = __('Search results for:','avia_framework')." ".esc_attr( get_search_query() );
  1104. }
  1105. else
  1106. {
  1107. $output = __('To search the site please enter a valid term','avia_framework');
  1108. }
  1109. }
  1110.  
  1111. }
  1112. elseif (is_author())
  1113. {
  1114. $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
  1115. $output = __('Author Archive','avia_framework')." ";
  1116.  
  1117. if(isset($curauth->nickname) && isset($curauth->ID))
  1118. {
  1119. $name = apply_filters('avf_author_nickname', $curauth->nickname, $curauth->ID);
  1120. $output .= __('for:','avia_framework') ." ". $name;
  1121. }
  1122.  
  1123. }
  1124. elseif (is_tag())
  1125. {
  1126. $output = __('Tag Archive for:','avia_framework')." ".single_tag_title('',false);
  1127. }
  1128. elseif(is_tax())
  1129. {
  1130. $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
  1131. $output = __('Archive for:','avia_framework')." ".$term->name;
  1132. }
  1133. else
  1134. {
  1135. $output = __('Archives','avia_framework')." ";
  1136. }
  1137.  
  1138. if (isset($_GET['paged']) && !empty($_GET['paged']))
  1139. {
  1140. $output .= " (".__('Page','avia_framework')." ".$_GET['paged'].")";
  1141. }
  1142.  
  1143. $output = apply_filters('avf_which_archive_output', $output);
  1144.  
  1145. return $output;
  1146. }
  1147. }
  1148.  
  1149.  
  1150. if(!function_exists('avia_excerpt'))
  1151. {
  1152. /**
  1153. * Returns a post excerpt. depending on the order parameter the funciton will try to retrieve the excerpt from a different source
  1154. */
  1155.  
  1156. function avia_excerpt($length = 250, $more_text = false, $order = array('more-tag','excerpt'))
  1157. {
  1158. $excerpt = "";
  1159. if($more_text === false) $more_text = __('Read more', 'avia_framework');
  1160.  
  1161. foreach($order as $method)
  1162. {
  1163. if(!$excerpt)
  1164. {
  1165. switch ($method)
  1166. {
  1167. case 'more-tag':
  1168. global $more;
  1169. $more = 0;
  1170. $content = get_the_content($more_text);
  1171. $pos = strpos($content, 'class="more-link"');
  1172.  
  1173. if($pos !== false)
  1174. {
  1175. $excerpt = $content;
  1176. }
  1177.  
  1178. break;
  1179.  
  1180. case 'excerpt' :
  1181.  
  1182. $post = get_post(get_the_ID());
  1183. if($post->post_excerpt)
  1184. {
  1185. $excerpt = get_the_excerpt();
  1186. }
  1187. else
  1188. {
  1189. $excerpt = preg_replace("!\[.+?\]!", "", get_the_excerpt());
  1190. // $excerpt = preg_replace("!\[.+?\]!", "", $post->post_content);
  1191. $excerpt = avia_backend_truncate($excerpt, $length," ");
  1192. }
  1193.  
  1194. $excerpt = preg_replace("!\s\[...\]$!", '...', $excerpt);
  1195.  
  1196. break;
  1197. }
  1198. }
  1199. }
  1200.  
  1201. if($excerpt)
  1202. {
  1203. $excerpt = apply_filters('the_content', $excerpt);
  1204. $excerpt = str_replace(']]>', ']]&gt;', $excerpt);
  1205. }
  1206. return $excerpt;
  1207. }
  1208. }
  1209.  
  1210. if(!function_exists('avia_get_browser'))
  1211. {
  1212. function avia_get_browser($returnValue = 'class', $lowercase = false)
  1213. {
  1214. if(empty($_SERVER['HTTP_USER_AGENT'])) return false;
  1215.  
  1216. $u_agent = $_SERVER['HTTP_USER_AGENT'];
  1217. $bname = 'Unknown';
  1218. $platform = 'Unknown';
  1219. $ub = 'Unknown';
  1220. $version= "";
  1221.  
  1222. //First get the platform?
  1223. if (preg_match('!linux!i', $u_agent)) {
  1224. $platform = 'linux';
  1225. }
  1226. elseif (preg_match('!macintosh|mac os x!i', $u_agent)) {
  1227. $platform = 'mac';
  1228. }
  1229. elseif (preg_match('!windows|win32!i', $u_agent)) {
  1230. $platform = 'windows';
  1231. }
  1232.  
  1233. // Next get the name of the useragent yes seperately and for good reason
  1234. if(preg_match('!MSIE!i',$u_agent) && !preg_match('!Opera!i',$u_agent))
  1235. {
  1236. $bname = 'Internet Explorer';
  1237. $ub = "MSIE";
  1238. }
  1239. elseif(preg_match('!Firefox!i',$u_agent))
  1240. {
  1241. $bname = 'Mozilla Firefox';
  1242. $ub = "Firefox";
  1243. }
  1244. elseif(preg_match('!Chrome!i',$u_agent))
  1245. {
  1246. $bname = 'Google Chrome';
  1247. $ub = "Chrome";
  1248. }
  1249. elseif(preg_match('!Safari!i',$u_agent))
  1250. {
  1251. $bname = 'Apple Safari';
  1252. $ub = "Safari";
  1253. }
  1254. elseif(preg_match('!Opera!i',$u_agent))
  1255. {
  1256. $bname = 'Opera';
  1257. $ub = "Opera";
  1258. }
  1259. elseif(preg_match('!Netscape!i',$u_agent))
  1260. {
  1261. $bname = 'Netscape';
  1262. $ub = "Netscape";
  1263. }
  1264.  
  1265. // finally get the correct version number
  1266. $known = array('Version', $ub, 'other');
  1267. $pattern = '#(?<browser>' . join('|', $known) .
  1268. ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
  1269. if (!@preg_match_all($pattern, $u_agent, $matches)) {
  1270. // we have no matching number just continue
  1271. }
  1272.  
  1273. // see how many we have
  1274. $i = count($matches['browser']);
  1275. if ($i != 1) {
  1276. //we will have two since we are not using 'other' argument yet
  1277. //see if version is before or after the name
  1278. if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
  1279. $version= !empty($matches['version'][0]) ? $matches['version'][0] : '';
  1280. }
  1281. else {
  1282. $version= !empty($matches['version'][1]) ? $matches['version'][1] : '';
  1283. }
  1284. }
  1285. else {
  1286. $version= !empty($matches['version'][0]) ? $matches['version'][0] : '';
  1287. }
  1288.  
  1289. // check if we have a number
  1290. if ($version==null || $version=="") {$version="?";}
  1291.  
  1292. $mainVersion = $version;
  1293. if (strpos($version, '.') !== false)
  1294. {
  1295. $mainVersion = explode('.',$version);
  1296. $mainVersion = $mainVersion[0];
  1297. }
  1298.  
  1299. if($returnValue == 'class')
  1300. {
  1301. if($lowercase) return strtolower($ub." ".$ub.$mainVersion);
  1302.  
  1303. return $ub." ".$ub.$mainVersion;
  1304. }
  1305. else
  1306. {
  1307. return array(
  1308. 'userAgent' => $u_agent,
  1309. 'name' => $bname,
  1310. 'shortname' => $ub,
  1311. 'version' => $version,
  1312. 'mainversion' => $mainVersion,
  1313. 'platform' => $platform,
  1314. 'pattern' => $pattern
  1315. );
  1316. }
  1317. }
  1318. }
  1319.  
  1320.  
  1321. if(!function_exists('avia_favicon'))
  1322. {
  1323. function avia_favicon($url = "")
  1324. {
  1325. $icon_link = $type = "";
  1326. if($url)
  1327. {
  1328. $type = "image/x-icon";
  1329. if(strpos($url,'.png' )) $type = "image/png";
  1330. if(strpos($url,'.gif' )) $type = "image/gif";
  1331.  
  1332. $icon_link = '<link rel="icon" href="'.$url.'" type="'.$type.'">';
  1333. }
  1334.  
  1335. $icon_link = apply_filters('avf_favicon_final_output', $icon_link, $url, $type);
  1336.  
  1337. return $icon_link;
  1338. }
  1339. }
  1340.  
  1341. if(!function_exists('avia_regex'))
  1342. {
  1343. /*
  1344. * regex for url: http://mathiasbynens.be/demo/url-regex
  1345. */
  1346.  
  1347. function avia_regex($string, $pattern = false, $start = "^", $end = "")
  1348. {
  1349. if(!$pattern) return false;
  1350.  
  1351. if($pattern == "url")
  1352. {
  1353. $pattern = "!$start((https?|ftp)://(-\.)?([^\s/?\.#-]+\.?)+(/[^\s]*)?)$end!";
  1354. }
  1355. else if($pattern == "mail")
  1356. {
  1357. $pattern = "!$start\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$end!";
  1358. }
  1359. else if($pattern == "image")
  1360. {
  1361. $pattern = "!$start(https?(?://([^/?#]*))?([^?#]*?\.(?:jpg|gif|png)))$end!";
  1362. }
  1363. else if(strpos($pattern,"<") === 0)
  1364. {
  1365. $pattern = str_replace('<',"",$pattern);
  1366. $pattern = str_replace('>',"",$pattern);
  1367.  
  1368. if(strpos($pattern,"/") !== 0) { $close = "\/>"; $pattern = str_replace('/',"",$pattern); }
  1369. $pattern = trim($pattern);
  1370. if(!isset($close)) $close = "<\/".$pattern.">";
  1371.  
  1372. $pattern = "!$start\<$pattern.+?$close!";
  1373.  
  1374. }
  1375.  
  1376. preg_match($pattern, $string, $result);
  1377.  
  1378. if(empty($result[0]))
  1379. {
  1380. return false;
  1381. }
  1382. else
  1383. {
  1384. return $result;
  1385. }
  1386.  
  1387. }
  1388. }
  1389.  
  1390.  
  1391. if(!function_exists('avia_debugging_info'))
  1392. {
  1393. function avia_debugging_info()
  1394. {
  1395. if ( is_feed() ) return;
  1396.  
  1397. $theme = wp_get_theme();
  1398. $child = "";
  1399.  
  1400. if(is_child_theme())
  1401. {
  1402. $child = "- - - - - - - - - - -\n";
  1403. $child .= "ChildTheme: ".$theme->get('Name')."\n";
  1404. $child .= "ChildTheme Version: ".$theme->get('Version')."\n";
  1405. $child .= "ChildTheme Installed: ".$theme->get('Template')."\n\n";
  1406.  
  1407. $theme = wp_get_theme( $theme->get('Template') );
  1408. }
  1409.  
  1410. $info = "\n\n<!--\n";
  1411. $info .= "Debugging Info for Theme support: \n\n";
  1412. $info .= "Theme: ".$theme->get('Name')."\n";
  1413. $info .= "Version: ".$theme->get('Version')."\n";
  1414. $info .= "Installed: ".$theme->get_template()."\n";
  1415. $info .= "AviaFramework Version: ".AV_FRAMEWORK_VERSION."\n";
  1416.  
  1417.  
  1418. if( class_exists( 'AviaBuilder' ) )
  1419. {
  1420. $info .= "AviaBuilder Version: ".AviaBuilder::VERSION."\n";
  1421.  
  1422. if( class_exists( 'aviaElementManager' ) )
  1423. {
  1424. $info .= "aviaElementManager Version: " . aviaElementManager::VERSION . "\n";
  1425. $update_state = get_option( 'av_alb_element_mgr_update', '' );
  1426. if( '' != $update_state )
  1427. {
  1428. $info .= "aviaElementManager update state: in update \n";
  1429. }
  1430. }
  1431. }
  1432.  
  1433.  
  1434. $info .= $child;
  1435.  
  1436. //memory setting, peak usage and number of active plugins
  1437. $info .= "ML:".trim( @ini_get("memory_limit") ,"M")."-PU:". ( ceil (memory_get_peak_usage() / 1000 / 1000 ) ) ."-PLA:".avia_count_active_plugins()."\n";
  1438. $info .= "WP:".get_bloginfo('version')."\n";
  1439.  
  1440. $comp_levels = array('none' => 'disabled', 'avia-module' => 'modules only', 'avia' => 'all theme files', 'all' => 'all files');
  1441.  
  1442. $info .= "Compress: CSS:".$comp_levels[avia_get_option('merge_css','avia-module')]." - JS:".$comp_levels[avia_get_option('merge_js','avia-module')]."\n";
  1443.  
  1444. $username = avia_get_option('updates_username');
  1445. $API = avia_get_option('updates_api_key');
  1446. $updates = "disabled";
  1447. if($username && $API)
  1448. {
  1449. $updates = "enabled";
  1450. if(isset($_GET['username'])) $updates = $username;
  1451. }
  1452.  
  1453. $info .= "Updates: ".$updates."\n";
  1454. $info = apply_filters('avf_debugging_info_add', $info);
  1455. $info .= "-->";
  1456. echo apply_filters('avf_debugging_info', $info);
  1457. }
  1458.  
  1459. add_action('wp_head','avia_debugging_info',9999999);
  1460. add_action('admin_print_scripts','avia_debugging_info',9999999);
  1461. }
  1462.  
  1463.  
  1464.  
  1465.  
  1466.  
  1467.  
  1468. if(!function_exists('avia_count_active_plugins'))
  1469. {
  1470. function avia_count_active_plugins()
  1471. {
  1472. $plugins = count(get_option('active_plugins', array()));
  1473.  
  1474. if(is_multisite() && function_exists('get_site_option'))
  1475. {
  1476. $plugins += count(get_site_option('active_sitewide_plugins', array()));
  1477. }
  1478.  
  1479. return $plugins;
  1480. }
  1481. }
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488. if(!function_exists('avia_clean_string'))
  1489. {
  1490. function avia_clean_string($string)
  1491. {
  1492. $string = str_replace(' ', '_', $string); // Replaces all spaces with underscores.
  1493. $string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
  1494.  
  1495. return preg_replace('/-+/', '-', strtolower ($string)); // Replaces multiple hyphens with single one.
  1496. }
  1497. }
  1498.  
  1499.  
  1500. if(!function_exists('kriesi_backlink'))
  1501. {
  1502. function kriesi_backlink($frontpage_only = false, $theme_name_passed = false)
  1503. {
  1504. $no = "";
  1505. $theme_string = "";
  1506. $theme_name = $theme_name_passed ? $theme_name_passed : THEMENAME;
  1507.  
  1508. $random_number = get_option(THEMENAMECLEAN."_fixed_random");
  1509. if($random_number % 3 == 0) $theme_string = $theme_name." Theme by Kriesi";
  1510. if($random_number % 3 == 1) $theme_string = $theme_name." WordPress Theme by Kriesi";
  1511. if($random_number % 3 == 2) $theme_string = "powered by ".$theme_name." WordPress Theme";
  1512. if(!empty($frontpage_only) && !is_front_page()) $no = "rel='nofollow'";
  1513.  
  1514. $link = " - <a {$no} href='https://kriesi.at'>{$theme_string}</a>";
  1515.  
  1516. $link = apply_filters("kriesi_backlink", $link);
  1517. return $link;
  1518. }
  1519. }
  1520.  
  1521.  
  1522.  
  1523. if(!function_exists('avia_header_class_filter'))
  1524. {
  1525. function avia_header_class_filter( $default = "" )
  1526. {
  1527. $default = apply_filters( "avia_header_class_filter", $default );
  1528. return $default;
  1529. }
  1530. }
  1531.  
  1532.  
  1533. if(!function_exists('avia_theme_version_higher_than'))
  1534. {
  1535. function avia_theme_version_higher_than( $check_for_version = "")
  1536. {
  1537. $theme = wp_get_theme( 'enfold' );
  1538. $theme_version = $theme->get( 'Version' );
  1539.  
  1540. if (version_compare($theme_version, $check_for_version , '>=')) {
  1541. return true;
  1542. }
  1543.  
  1544. return false;
  1545. }
  1546. }
  1547.  
  1548. if( ! function_exists( 'avia_enqueue_style_conditionally' ) )
  1549. {
  1550. /**
  1551. * Enque a css file, based on theme options or other conditions that get passed and must be evaluated as true
  1552. *
  1553. * 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
  1554. * @since 4.3
  1555. * @added_by Kriesi
  1556. * @param array $condition
  1557. * @return array
  1558. */
  1559. function avia_enqueue_style_conditionally( $condition = false, $handle, $src = '', $deps = array(), $ver = false, $media = 'all', $deregister = true)
  1560. {
  1561. if($condition == false )
  1562. {
  1563. if($deregister) wp_deregister_style( $handle );
  1564. return;
  1565. };
  1566.  
  1567. wp_enqueue_style( $handle, $src, $deps, $ver, $media );
  1568. }
  1569. }
  1570.  
  1571. if( ! function_exists( 'avia_enqueue_script_conditionally' ) )
  1572. {
  1573. /**
  1574. * Enque a js file, based on theme options or other conditions that get passed and must be evaluated as true
  1575. *
  1576. * 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
  1577. * @since 4.3
  1578. * @added_by Kriesi
  1579. * @param array $condition
  1580. * @return array
  1581. */
  1582. function avia_enqueue_script_conditionally( $condition = false, $handle, $src = '', $deps = array(), $ver = false, $in_footer = false, $deregister = true)
  1583. {
  1584. if($condition == false )
  1585. {
  1586. if($deregister) wp_deregister_script( $handle );
  1587. return;
  1588. };
  1589.  
  1590. wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
  1591. }
  1592. }
  1593.  
  1594. if( ! function_exists( 'avia_disable_query_migrate' ) )
  1595. {
  1596. /**
  1597. * Makes sure that jquery no longer depends on jquery migrate.
  1598. *
  1599. * @since 4.3
  1600. * @added_by Kriesi
  1601. * @param array $condition
  1602. * @return array
  1603. */
  1604. function avia_disable_query_migrate()
  1605. {
  1606. global $wp_scripts;
  1607.  
  1608. if(!is_admin())
  1609. {
  1610. if(isset($wp_scripts->registered['jquery']))
  1611. {
  1612. foreach($wp_scripts->registered['jquery']->deps as $key => $dep)
  1613. {
  1614. if($dep == "jquery-migrate")
  1615. {
  1616. unset($wp_scripts->registered['jquery']->deps[$key]);
  1617. }
  1618. }
  1619. }
  1620. }
  1621.  
  1622. }
  1623. }
  1624.  
  1625. if( ! function_exists( 'avia_get_submenu_count' ) )
  1626. {
  1627. /**
  1628. * Counts the number of submenu items of a menu
  1629. *
  1630. * @since 4.3
  1631. * @added_by Kriesi
  1632. * @param array $location
  1633. * @return int $count
  1634. */
  1635. function avia_get_submenu_count( $location )
  1636. {
  1637. $menus = get_nav_menu_locations();
  1638. $count = 0;
  1639.  
  1640. if(!isset($menus[$location])) return $count;
  1641.  
  1642. $items = wp_get_nav_menu_items($menus[$location]);
  1643.  
  1644. //if no menu is set we dont know if the fallback menu will generate submenu items so we assume thats true
  1645. if(!$items) return 1;
  1646.  
  1647. foreach($items as $item)
  1648. {
  1649. if(isset($item->menu_item_parent) && $item->menu_item_parent >0 ) $count++;
  1650. }
  1651.  
  1652. return $count;
  1653. }
  1654. }
  1655.  
  1656. if( ! function_exists( 'avia_get_active_widget_count' ) )
  1657. {
  1658. /**
  1659. * Counts the number of active widget areas (widget areas that got a widget inside them are considered active)
  1660. *
  1661. * @since 4.3
  1662. * @added_by Kriesi
  1663. * @return int $count
  1664. */
  1665. function avia_get_active_widget_count()
  1666. {
  1667. global $_wp_sidebars_widgets;
  1668. $count = 0;
  1669.  
  1670. foreach($_wp_sidebars_widgets as $widget_area => $widgets)
  1671. {
  1672. if($widget_area == "wp_inactive_widgets" || $widget_area == "array_version") continue;
  1673. if(!empty($widgets)) $count++;
  1674. }
  1675.  
  1676. return $count;
  1677. }
  1678. }
  1679.  
  1680. if( ! function_exists( 'avia_get_parent_theme_version' ) )
  1681. {
  1682. /**
  1683. * Helper function that returns the (parent) theme version number to be added to scipts and css links
  1684. *
  1685. * @since 4.3.2
  1686. * @added_by Günter
  1687. * @return string
  1688. */
  1689. function avia_get_theme_version( $which = 'parent' )
  1690. {
  1691. $theme = wp_get_theme();
  1692. if( false !== $theme->parent() && ( 'parent' == $which ) )
  1693. {
  1694. $theme = $theme->parent();
  1695. }
  1696. $vn = $theme->get( 'Version' );
  1697.  
  1698. return $vn;
  1699. }
  1700. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement