Advertisement
Guest User

tests

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