PageRenderTime 51ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/ifeature/cyberchimps/functions.php

https://github.com/Bochet/festival_lgbt
PHP | 976 lines | 739 code | 125 blank | 112 comment | 134 complexity | a894c4b4f15c39cb32dd8b0eb5cb7bb5 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Framework Functions File
  4. *
  5. * Please do not edit this file. This file is part of the Cyber Chimps Framework and all modifications
  6. * should be made in a child theme.
  7. *
  8. * @category CyberChimps Framework
  9. * @package Framework
  10. * @since 1.0
  11. * @author CyberChimps
  12. * @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
  13. * @link http://www.cyberchimps.com/
  14. */
  15. // Set options function
  16. function cyberchimps_option( $name = false, $subname = false ){
  17. $options = get_option( 'cyberchimps_options' );
  18. if( $name ) {
  19. $value = $options[$name];
  20. return $value;
  21. }
  22. }
  23. if ( ! function_exists( 'cyberchimps_get_option' ) ) {
  24. /**
  25. * Get Option.
  26. *
  27. * Helper function to return the theme option value.
  28. * If no value has been saved, it returns $default.
  29. * Needed because options are saved as serialized strings.
  30. */
  31. function cyberchimps_get_option( $name, $default = false ) {
  32. $options = get_option( 'cyberchimps_options' );
  33. if ( isset( $options[$name] ) ) {
  34. return $options[$name];
  35. }
  36. return $default;
  37. }
  38. }
  39. // Enqueue core scripts and core styles
  40. function cyberchimps_core_scripts() {
  41. global $post;
  42. // Define paths
  43. $directory_uri = get_template_directory_uri();
  44. $js_path = $directory_uri . '/cyberchimps/lib/js/';
  45. $bootstrap_path = $directory_uri . '/cyberchimps/lib/bootstrap/';
  46. // Load JS for slimbox
  47. wp_enqueue_script( 'slimbox', $js_path . 'jquery.slimbox.js', array( 'jquery' ), true );
  48. // Load library for jcarousel
  49. wp_enqueue_script( 'jcarousel', $js_path . 'jquery.jcarousel.min.js', array( 'jquery' ), true );
  50. // Load Custom JS
  51. wp_enqueue_script( 'custom', $js_path . 'custom.js', array( 'jquery' ), true );
  52. //touch swipe gestures
  53. wp_enqueue_script( 'jquery-mobile-touch', $js_path . 'jquery.mobile.custom.min.js', array('jquery') );
  54. wp_enqueue_script( 'slider-call', $js_path . 'swipe-call.js', array('jquery', 'jquery-mobile-touch') );
  55. // Load Bootstrap Library Items
  56. wp_enqueue_style( 'bootstrap-style', $bootstrap_path . 'css/bootstrap.min.css', false, '2.0.4' );
  57. wp_enqueue_style( 'bootstrap-responsive-style', $bootstrap_path . 'css/bootstrap-responsive.min.css', array('bootstrap-style'), '2.0.4' );
  58. wp_enqueue_script( 'bootstrap-js', $bootstrap_path . 'js/bootstrap.min.js', array( 'jquery' ), '2.0.4', true );
  59. //responsive design
  60. if( cyberchimps_get_option( 'responsive_design', 'checked' ) ){
  61. wp_enqueue_style( 'cyberchimps_responsive', get_template_directory_uri() . '/cyberchimps/lib/bootstrap/css/cyberchimps-responsive.min.css', array('bootstrap-responsive-style', 'bootstrap-style'), '1.0' );
  62. }
  63. else {
  64. wp_dequeue_style( 'cyberchimps_responsive' );
  65. }
  66. // Load Core Stylesheet
  67. wp_enqueue_style( 'core-style', $directory_uri . '/cyberchimps/lib/css/core.css', array( 'bootstrap-responsive-style', 'bootstrap-style' ), '1.0' );
  68. // Load Theme Stylesheet
  69. wp_enqueue_style( 'style', get_stylesheet_uri(), array( 'core-style' ), '1.0' );
  70. // Add thumbnail size
  71. if ( function_exists( 'add_image_size' ) ) {
  72. add_image_size( 'featured-thumb', 100, 80, true);
  73. add_image_size( 'headline-thumb', 200, 225, true);
  74. }
  75. // add javascript for comments
  76. if ( is_singular() ) wp_enqueue_script( 'comment-reply' );
  77. if (cyberchimps_get_option( 'responsive_videos' ) == '1' ) {
  78. wp_register_script( 'video' , $js_path . 'video.js');
  79. wp_enqueue_script ('video');
  80. }
  81. }
  82. add_action( 'wp_enqueue_scripts', 'cyberchimps_core_scripts', 20 );
  83. function cyberchimps_create_layout() {
  84. global $post;
  85. if ( is_single() ) {
  86. $layout_type = cyberchimps_get_option( 'single_post_sidebar_options', 'right_sidebar' );
  87. } elseif ( is_home() ) {
  88. $layout_type = cyberchimps_get_option( 'sidebar_images', 'right_sidebar' );
  89. } elseif ( is_page() ) {
  90. $page_sidebar = get_post_meta( $post->ID, 'cyberchimps_page_sidebar' );
  91. $layout_type = ( isset( $page_sidebar[0] ) ) ? $page_sidebar[0] : 'right_sidebar';
  92. } elseif ( is_archive() ) {
  93. $layout_type = cyberchimps_get_option( 'archive_sidebar_options', 'right_sidebar' );
  94. } elseif ( is_search() ) {
  95. $layout_type = cyberchimps_get_option( 'search_sidebar_options', 'right_sidebar' );
  96. } elseif ( is_404() ) {
  97. $layout_type = cyberchimps_get_option( 'error_sidebar_options', 'right_sidebar' );
  98. } else {
  99. $layout_type = apply_filters( 'cyberchimps_default_layout', 'right_sidebar' );
  100. }
  101. cyberchimps_get_layout($layout_type);
  102. }
  103. add_action('wp', 'cyberchimps_create_layout');
  104. function cyberchimps_get_layout( $layout_type ) {
  105. $layout_type = ( $layout_type ) ? $layout_type : 'right_sidebar';
  106. switch($layout_type) {
  107. case 'full_width' :
  108. add_filter( 'cyberchimps_content_class', 'cyberchimps_class_span12');
  109. break;
  110. case 'right_sidebar' :
  111. add_action( 'cyberchimps_after_content_container', 'cyberchimps_add_sidebar_right');
  112. add_filter( 'cyberchimps_content_class', 'cyberchimps_class_span9');
  113. add_filter( 'cyberchimps_sidebar_right_class', 'cyberchimps_class_span3');
  114. break;
  115. case 'left_sidebar' :
  116. add_action( 'cyberchimps_before_content_container', 'cyberchimps_add_sidebar_left');
  117. add_filter( 'cyberchimps_content_class', 'cyberchimps_class_span9');
  118. add_filter( 'cyberchimps_sidebar_left_class', 'cyberchimps_class_span3');
  119. break;
  120. case 'content_middle' :
  121. add_action( 'cyberchimps_before_content_container', 'cyberchimps_add_sidebar_left');
  122. add_action( 'cyberchimps_after_content_container', 'cyberchimps_add_sidebar_right');
  123. add_filter( 'cyberchimps_content_class', 'cyberchimps_class_span6');
  124. add_filter( 'cyberchimps_sidebar_left_class', 'cyberchimps_class_span3');
  125. add_filter( 'cyberchimps_sidebar_right_class', 'cyberchimps_class_span3');
  126. break;
  127. case 'left_right_sidebar' :
  128. add_action( 'cyberchimps_after_content_container', 'cyberchimps_add_sidebar_left');
  129. add_action( 'cyberchimps_after_content_container', 'cyberchimps_add_sidebar_right');
  130. add_filter( 'cyberchimps_content_class', 'cyberchimps_class_span6');
  131. add_filter( 'cyberchimps_sidebar_left_class', 'cyberchimps_class_span3');
  132. add_filter( 'cyberchimps_sidebar_right_class', 'cyberchimps_class_span3');
  133. break;
  134. }
  135. }
  136. class cyberchimps_Walker extends Walker_Nav_Menu {
  137. function start_lvl( &$output, $depth ) {
  138. //In a child UL, add the 'dropdown-menu' class
  139. if( $depth == 0 ) {
  140. $indent = str_repeat( "\t", $depth );
  141. $output .= "\n$indent<ul class=\"dropdown-menu\">\n";
  142. } else {
  143. $indent = str_repeat( "\t", $depth );
  144. $output .= "\n$indent<ul>\n";
  145. }
  146. }
  147. function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
  148. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  149. $li_attributes = '';
  150. $class_names = $value = '';
  151. $classes = empty( $item->classes ) ? array() : ( array ) $item->classes;
  152. //Add class and attribute to LI element that contains a submenu UL.
  153. if ( $args->has_children && $depth < 1 ){
  154. $classes[] = 'dropdown';
  155. $li_attributes .= 'data-dropdown="dropdown"';
  156. }
  157. $classes[] = 'menu-item-' . $item->ID;
  158. //If we are on the current page, add the active class to that menu item.
  159. $classes[] = ($item->current) ? 'active' : '';
  160. //Make sure you still add all of the WordPress classes.
  161. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
  162. $class_names = ' class="' . esc_attr( $class_names ) . '"';
  163. $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
  164. $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
  165. $output .= $indent . '<li' . $id . $value . $class_names . $li_attributes . '>';
  166. //Add attributes to link element.
  167. $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
  168. $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
  169. $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
  170. $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
  171. $attributes .= ($args->has_children && $depth < 1) ? ' class="dropdown-toggle"' : '';
  172. $item_output = $args->before;
  173. $item_output .= '<a'. $attributes .'>';
  174. $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
  175. $item_output .= ($args->has_children && $depth < 1) ? ' <b class="caret"></b> ' : '';
  176. $item_output .= '</a>';
  177. $item_output .= $args->after;
  178. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  179. }
  180. //Overwrite display_element function to add has_children attribute. Not needed in >= Wordpress 3.4
  181. function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
  182. if ( !$element )
  183. return;
  184. $id_field = $this->db_fields['id'];
  185. //display this element
  186. if ( is_array( $args[0] ) )
  187. $args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );
  188. else if ( is_object( $args[0] ) )
  189. $args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
  190. $cb_args = array_merge( array(&$output, $element, $depth), $args);
  191. call_user_func_array(array(&$this, 'start_el'), $cb_args);
  192. $id = $element->$id_field;
  193. // descend only when the depth is right and there are childrens for this element
  194. if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {
  195. foreach( $children_elements[ $id ] as $child ){
  196. if ( !isset($newlevel) ) {
  197. $newlevel = true;
  198. //start the child delimiter
  199. $cb_args = array_merge( array(&$output, $depth), $args);
  200. call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
  201. }
  202. $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
  203. }
  204. unset( $children_elements[ $id ] );
  205. }
  206. if ( isset($newlevel) && $newlevel ){
  207. //end the child delimiter
  208. $cb_args = array_merge( array(&$output, $depth), $args);
  209. call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
  210. }
  211. //end this element
  212. $cb_args = array_merge( array(&$output, $element, $depth), $args);
  213. call_user_func_array(array(&$this, 'end_el'), $cb_args);
  214. }
  215. }
  216. // Sets fallback menu for 1 level. Could use preg_split to have children displayed too
  217. function cyberchimps_fallback_menu() {
  218. $args = array(
  219. 'depth' => 1,
  220. 'show_date' => '',
  221. 'date_format' => '',
  222. 'child_of' => 0,
  223. 'exclude' => '',
  224. 'include' => '',
  225. 'title_li' => '',
  226. 'echo' => 0,
  227. 'authors' => '',
  228. 'sort_column' => 'menu_order, post_title',
  229. 'link_before' => '',
  230. 'link_after' => '',
  231. 'walker' => '',
  232. 'post_type' => 'page',
  233. 'post_status' => 'publish'
  234. );
  235. $pages = wp_list_pages( $args );
  236. $prepend = '<ul id="menu-menu" class="nav">';
  237. $append = '</ul>';
  238. echo $prepend.$pages.$append;
  239. }
  240. if ( ! function_exists( 'cyberchimps_posted_on' ) ) :
  241. //Prints HTML with meta information for the current post-date/time and author.
  242. function cyberchimps_posted_on() {
  243. if( is_single() ) {
  244. $show_date = ( cyberchimps_get_option( 'single_post_byline_date', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_date', 1 ) : false;
  245. $show_author = ( cyberchimps_get_option( 'single_post_byline_author', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_author', 1 ) : false;
  246. $show_categories = ( cyberchimps_get_option( 'single_post_byline_categories', 1 ) ) ? cyberchimps_option( 'single_post_byline_categories', 1 ) : false;
  247. }
  248. elseif( is_archive() ) {
  249. $show_date = ( cyberchimps_get_option( 'archive_post_byline_date', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_date', 1 ) : false;
  250. $show_author = ( cyberchimps_get_option( 'archive_post_byline_author', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_author', 1 ) : false;
  251. $show_categories = ( cyberchimps_get_option( 'archive_post_byline_categories', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_categories', 1 ) : false;
  252. }
  253. else {
  254. $show_date = ( cyberchimps_get_option( 'post_byline_date', 1 ) ) ? cyberchimps_get_option( 'post_byline_date', 1 ) : false;
  255. $show_author = ( cyberchimps_get_option( 'post_byline_author', 1 ) ) ? cyberchimps_get_option( 'post_byline_author', 1 ) : false;
  256. $show_categories = ( cyberchimps_get_option( 'post_byline_categories', 1 ) ) ? cyberchimps_get_option( 'post_byline_categories', 1 ) : false;
  257. }
  258. $posted_on = sprintf( '%8$s<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>%10$s %9$s<span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span>%11$s',
  259. esc_url( get_permalink() ),
  260. esc_attr( get_the_time() ),
  261. esc_attr( get_the_date( 'c' ) ),
  262. ( $show_date ) ? esc_html( get_the_date() ) : '',
  263. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  264. esc_attr( sprintf( __( 'View all posts by', 'cyberchimps' ) . ' %s', get_the_author() ) ),
  265. ( $show_author ) ? esc_html( get_the_author() ) : '',
  266. ( $show_date ) ? __( 'Posted on ', 'cyberchimps' ) : '',
  267. ( $show_author ) ? __( ' by ', 'cyberchimps' ) : '',
  268. ( $show_author || $show_categories ) ? '<span class="byline">' : '',
  269. ( $show_author || $show_categories ) ? '</span>' : ''
  270. );
  271. apply_filters( 'cyberchimps_posted_on', $posted_on );
  272. echo $posted_on;
  273. }
  274. endif;
  275. //add meta entry category to single post, archive and blog list if set in options
  276. function cyberchimps_posted_in() {
  277. global $post;
  278. if( is_single() ) {
  279. $show = ( cyberchimps_get_option( 'single_post_byline_categories', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_categories', 1 ) : false;
  280. }
  281. elseif( is_archive() ) {
  282. $show = ( cyberchimps_get_option( 'archive_post_byline_categories', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_categories', 1 ) : false;
  283. }
  284. else {
  285. $show = ( cyberchimps_get_option( 'post_byline_categories', 1 ) ) ? cyberchimps_get_option( 'post_byline_categories', 1 ) : false;
  286. }
  287. if( $show ):
  288. $categories_list = get_the_category_list( ', ' );
  289. if ( $categories_list ) :
  290. $cats = sprintf( __( 'Posted in', 'cyberchimps' ) . ' %1$s', $categories_list );
  291. ?>
  292. <span class="cat-links">
  293. <?php echo apply_filters( 'cyberchimps_post_categories', $cats ); ?>
  294. </span>
  295. <span class="sep"> <?php echo apply_filters( 'cyberchimps_entry_meta_sep', '|' ); ?> </span>
  296. <?php endif;
  297. endif;
  298. }
  299. //add meta entry tags to single post, archive and blog list if set in options
  300. function cyberchimps_post_tags() {
  301. global $post;
  302. if( is_single() ) {
  303. $show = ( cyberchimps_get_option( 'single_post_byline_tags', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_tags', 1 ) : false;
  304. }
  305. elseif( is_archive() ) {
  306. $show = ( cyberchimps_get_option( 'archive_post_byline_tags', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_tags', 1 ) : false;
  307. }
  308. else {
  309. $show = ( cyberchimps_get_option( 'post_byline_tags', 1 ) ) ? cyberchimps_get_option( 'post_byline_tags', 1 ) : false;
  310. }
  311. if( $show ):
  312. $tags_list = get_the_tag_list( '', ', ' );
  313. if ( $tags_list ) :
  314. $tags = sprintf( __( 'Tags:', 'cyberchimps' ) . ' %1$s', $tags_list );
  315. ?>
  316. <span class="tag-links">
  317. <?php echo apply_filters( 'cyberchimps_post_tags', $tags ); ?>
  318. </span>
  319. <span class="sep"> <?php echo apply_filters( 'cyberchimps_entry_meta_sep', '|' ); ?> </span>
  320. <?php endif; // End if $tags_list
  321. endif;
  322. }
  323. //add meta entry comments to single post, archive and blog list if set in options
  324. function cyberchimps_post_comments() {
  325. global $post;
  326. if( is_single() ) {
  327. $show = ( cyberchimps_get_option( 'single_post_byline_comments', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_comments', 1 ) : false;
  328. }
  329. elseif( is_archive() ) {
  330. $show = ( cyberchimps_get_option( 'archive_post_byline_comments', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_comments', 1 ) : false;
  331. }
  332. else {
  333. $show = ( cyberchimps_get_option( 'post_byline_comments', 1 ) ) ? cyberchimps_get_option( 'post_byline_comments', 1 ) : false;
  334. }
  335. $leave_comment = ( is_single() || is_page() ) ? '' : __( 'Leave a comment', 'cyberchimps' );
  336. if( $show ):
  337. if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
  338. <span class="comments-link"><?php comments_popup_link( $leave_comment, __( '1 Comment', 'cyberchimps' ), '% ' . __( 'Comments', 'cyberchimps' ) ); ?></span>
  339. <span class="sep"> <?php echo ( $leave_comment != '' ) ? apply_filters( 'cyberchimps_entry_meta_sep', '|' ) : ''; ?> </span>
  340. <?php endif;
  341. endif;
  342. }
  343. // change default comments labels and form
  344. add_filter( 'comment_form_defaults', 'cyberchimps_comment_form_filter' );
  345. function cyberchimps_comment_form_filter( $defaults ) {
  346. $defaults['title_reply'] = __( 'Leave a comment', 'cyberchimps' );
  347. return $defaults;
  348. }
  349. // add featured image to single post, archive and blog page if set in options
  350. function cyberchimps_featured_image() {
  351. global $post;
  352. if( is_single() ) {
  353. $show = ( cyberchimps_get_option( 'single_post_featured_images', 1 ) ) ? cyberchimps_get_option( 'single_post_featured_images', 1 ) : false;
  354. }
  355. elseif( is_archive() ) {
  356. $show = ( cyberchimps_get_option( 'archive_featured_images', 1 ) ) ? cyberchimps_get_option( 'archive_featured_images', 1 ) : false;
  357. }
  358. else {
  359. $show = ( cyberchimps_get_option( 'post_featured_images', 1 ) ) ? cyberchimps_get_option( 'post_featured_images', 1 ) : false;
  360. }
  361. if( $show ):
  362. if( has_post_thumbnail() ): ?>
  363. <div class="featured-image">
  364. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'cyberchimps' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
  365. <?php the_post_thumbnail( apply_filters( 'cyberchimps_post_thumbnail_size', 'thumbnail' ) ); ?>
  366. </a>
  367. </div>
  368. <?php endif;
  369. endif;
  370. }
  371. function cyberchimps_post_format_icon() {
  372. global $post;
  373. $format = get_post_format( $post->ID );
  374. if( $format == '' ) {
  375. $format = 'default';
  376. }
  377. if( is_single() ) {
  378. $show = ( cyberchimps_get_option( 'single_post_format_icons', 1 ) ) ? cyberchimps_get_option( 'single_post_format_icons', 1 ) : false;
  379. }
  380. elseif( is_archive() ) {
  381. $show = ( cyberchimps_get_option( 'archive_format_icons', 1 ) ) ? cyberchimps_get_option( 'archive_format_icons', 1 ) : false;
  382. }
  383. else {
  384. $show = ( cyberchimps_get_option( 'post_format_icons', 1 ) ) ? cyberchimps_get_option( 'post_format_icons', 1 ) : false;
  385. }
  386. if( $show ):
  387. ?>
  388. <div class="postformats"><!--begin format icon-->
  389. <img src="<?php echo get_template_directory_uri(); ?>/images/formats/<?php echo $format; ?>.png" alt="formats" />
  390. </div><!--end format-icon-->
  391. <?php
  392. endif;
  393. }
  394. // Returns true if a blog has more than 1 category
  395. function cyberchimps_categorized_blog() {
  396. if ( false === ( $cyberchimps_categorized_transient = get_transient( 'cyberchimps_categorized_transient' ) ) ) {
  397. // Create an array of all the categories that are attached to posts
  398. $cyberchimps_categorized_transient = get_categories( array(
  399. 'hide_empty' => 1,
  400. ) );
  401. // Count the number of categories that are attached to the posts
  402. $cyberchimps_categorized_transient = count( $cyberchimps_categorized_transient );
  403. set_transient( 'cyberchimps_categorized_transient', $cyberchimps_categorized_transient );
  404. }
  405. if ( '1' != $cyberchimps_categorized_transient ) {
  406. // This blog has more than 1 category so cyberchimps_categorized_blog should return true
  407. return true;
  408. } else {
  409. // This blog has only 1 category so cyberchimps_categorized_blog should return false
  410. return false;
  411. }
  412. }
  413. // Flush out the transients used in cyberchimps_categorized_blog
  414. function cyberchimps_category_transient_flusher() {
  415. // Remove transient
  416. delete_transient( 'cyberchimps_categorized_transient' );
  417. }
  418. add_action( 'edit_category', 'cyberchimps_category_transient_flusher' );
  419. add_action( 'save_post', 'cyberchimps_category_transient_flusher' );
  420. // Prints out default title of the site.
  421. function cyberchimps_default_site_title() {
  422. global $page, $paged;
  423. // Add the blog name.
  424. bloginfo( 'name' );
  425. // Add the blog description for the home/front page.
  426. $site_description = get_bloginfo( 'description', 'display' );
  427. if ( $site_description && ( is_home() || is_front_page() ) )
  428. echo " | $site_description";
  429. // Add a page number if necessary:
  430. if ( $paged >= 2 || $page >= 2 )
  431. echo ' | ' . sprintf( __( 'Page', 'cyberchimps' ) . ' %s', max( $paged, $page ) );
  432. }
  433. add_filter('wp_title', 'cyberchimps_default_site_title');
  434. // Remove default site title if seo plugin is active
  435. function cyberchimps_seo_compatibility_check() {
  436. if ( cyberchimps_detect_seo_plugins() ) {
  437. remove_filter( 'wp_title', 'cyberchimps_default_site_title', 10, 3 );
  438. }
  439. }
  440. add_action( 'after_setup_theme', 'cyberchimps_seo_compatibility_check', 5 );
  441. // Detect some SEO Plugin that add constants, classes or functions.
  442. function cyberchimps_detect_seo_plugins() {
  443. return cyberchimps_detect_plugin(
  444. // Use this filter to adjust plugin tests.
  445. apply_filters(
  446. 'cyberchimps_detect_seo_plugins',
  447. /** Add to this array to add new plugin checks. */
  448. array(
  449. // Classes to detect.
  450. 'classes' => array(
  451. 'wpSEO',
  452. 'All_in_One_SEO_Pack',
  453. 'HeadSpace_Plugin',
  454. 'Platinum_SEO_Pack',
  455. ),
  456. // Functions to detect.
  457. 'functions' => array(),
  458. // Constants to detect.
  459. 'constants' => array( 'WPSEO_VERSION', ),
  460. )
  461. )
  462. );
  463. }
  464. // Detect event plugins
  465. function cyberchimps_detect_event_plugins() {
  466. return cyberchimps_detect_plugin(
  467. // Use this filter to adjust plugin tests.
  468. apply_filters(
  469. 'cyberchimps_detect_event_plugins',
  470. /** Add to this array to add new plugin checks. */
  471. array(
  472. // Classes to detect.
  473. 'classes' => array( 'TribeEvents' ),
  474. // Functions to detect.
  475. 'functions' => array(),
  476. // Constants to detect.
  477. 'constants' => array(),
  478. )
  479. )
  480. );
  481. }
  482. // Detect plugin by constant, class or function existence.
  483. function cyberchimps_detect_plugin( $plugins ) {
  484. /** Check for classes */
  485. if ( isset( $plugins['classes'] ) ) {
  486. foreach ( $plugins['classes'] as $name ) {
  487. if ( class_exists( $name ) )
  488. return true;
  489. }
  490. }
  491. /** Check for functions */
  492. if ( isset( $plugins['functions'] ) ) {
  493. foreach ( $plugins['functions'] as $name ) {
  494. if ( function_exists( $name ) )
  495. return true;
  496. }
  497. }
  498. /** Check for constants */
  499. if ( isset( $plugins['constants'] ) ) {
  500. foreach ( $plugins['constants'] as $name ) {
  501. if ( defined( $name ) )
  502. return true;
  503. }
  504. }
  505. /** No class, function or constant found to exist */
  506. return false;
  507. }
  508. // Set read more link for recent post element
  509. function cyberchimps_recent_post_excerpt_more($more) {
  510. global $custom_excerpt, $post;
  511. if ($custom_excerpt == 'recent') {
  512. $linktext = __( 'Continue Reading', 'cyberchimps' );
  513. }
  514. return '&hellip;
  515. </p>
  516. <div class="more-link">
  517. <span class="continue-arrow"><img src="'. get_template_directory_uri() .'/cyberchimps/lib/images/continue.png"></span><a href="'. get_permalink($post->ID) . '"> '.$linktext.'</a>
  518. </div>';
  519. }
  520. // Set read more link for featured post element
  521. function cyberchimps_featured_post_excerpt_more($more) {
  522. global $post;
  523. return '&hellip;</p></span><a class="excerpt-more featured-post-excerpt" href="'. get_permalink($post->ID) . '">Read More...</a>';
  524. }
  525. // Set length of the excerpt
  526. function cyberchimps_featured_post_length( $length ) {
  527. return 70;
  528. }
  529. // Set read more link for magazine featured post element
  530. function cyberchimps_magazine_featured_post_excerpt_more($more) {
  531. global $post;
  532. return '&hellip;</p></span><a class="excerpt-more magazine-featured-post-excerpt" href="'. get_permalink($post->ID) . '">Read More...</a>';
  533. }
  534. // Set length of the magazine featured post excerpt
  535. function cyberchimps_magazine_featured_post_length( $length ) {
  536. $new_length = cyberchimps_get_option( 'blog_magazine_excerpt_length', 70 );
  537. return $new_length;
  538. }
  539. // For magazine wide post
  540. function cyberchimps_magazine_post_wide( $length ) {
  541. $new_length = cyberchimps_get_option( 'blog_magazine_wide_excerpt_length', 130 );
  542. return $new_length;
  543. }
  544. // more text for search results excerpt
  545. function cyberchimps_search_excerpt_more( $more ){
  546. global $post;
  547. if( cyberchimps_option( 'search_post_read_more' ) != '' ){
  548. $more = '<p><a href="'. get_permalink($post->ID) . '">'.cyberchimps_option( 'search_post_read_more' ).'</a></p>';
  549. return $more;
  550. }
  551. else {
  552. $more = '<p><a class="excerpt-more search-excerpt" href="'. get_permalink($post->ID) . '">Read More...</a></p>';
  553. return $more;
  554. }
  555. }
  556. // excerpt length for search results
  557. function cyberchimps_search_excerpt_length( $length ){
  558. global $post;
  559. if( cyberchimps_option( 'search_post_excerpt_length' ) != '' ) {
  560. $length = cyberchimps_option( 'search_post_excerpt_length' );
  561. return $length;
  562. }
  563. else {
  564. $length = 55;
  565. return $length;
  566. }
  567. }
  568. //For archive posts
  569. function cyberchimps_archive_excerpt_more( $more ){
  570. global $post;
  571. if( cyberchimps_option( 'blog_read_more_text' ) != '' ){
  572. $more = '<p><a class="excerpt-more archive-excerpt" href="'. get_permalink($post->ID) . '">'.cyberchimps_option( 'blog_read_more_text' ).'</a></p>';
  573. return $more;
  574. }
  575. else {
  576. $more = '<p><a class="excerpt-more archive-excerpt" href="'. get_permalink($post->ID) . '">Read More...</a></p>';
  577. return $more;
  578. }
  579. }
  580. if( cyberchimps_get_option( 'archive_post_excerpts', 0 ) != 0 ){
  581. add_filter( 'excerpt_more', 'cyberchimps_blog_excerpt_more', 999 );
  582. }
  583. //For blog posts
  584. function cyberchimps_blog_excerpt_more( $more ){
  585. global $post;
  586. if( cyberchimps_option( 'blog_read_more_text' ) != '' ){
  587. $more = '<p><a class="excerpt-more blog-excerpt" href="'. get_permalink($post->ID) . '">'.cyberchimps_option( 'blog_read_more_text' ).'</a></p>';
  588. return $more;
  589. }
  590. else {
  591. $more = '<p><a class="excerpt-more blog-excerpt" href="'. get_permalink($post->ID) . '">Read More...</a></p>';
  592. return $more;
  593. }
  594. }
  595. if( cyberchimps_get_option( 'post_excerpts', 0 ) != 0 ){
  596. add_filter( 'excerpt_more', 'cyberchimps_blog_excerpt_more', 999 );
  597. }
  598. function cyberchimps_blog_excerpt_length( $length ) {
  599. global $post;
  600. if( cyberchimps_option( 'blog_excerpt_length' ) != '' ) {
  601. $length = cyberchimps_option( 'blog_excerpt_length' );
  602. return $length;
  603. }
  604. else {
  605. $length = 55;
  606. return $length;
  607. }
  608. }
  609. if( cyberchimps_get_option( 'post_excerpts', 0 ) != 0 ){
  610. add_filter( 'excerpt_length', 'cyberchimps_blog_excerpt_length', 999 );
  611. }
  612. /* gets post views */
  613. function cyberchimps_getPostViews($postID){
  614. $count_key = 'post_views_count';
  615. $count = get_post_meta($postID, $count_key, true);
  616. if($count==''){
  617. delete_post_meta($postID, $count_key);
  618. add_post_meta($postID, $count_key, '0');
  619. return "0 View";
  620. }
  621. return $count.' Views';
  622. }
  623. /* Sets post views */
  624. function cyberchimps_setPostViews($postID) {
  625. $count_key = 'post_views_count';
  626. $count = get_post_meta($postID, $count_key, true);
  627. if($count==''){
  628. $count = 0;
  629. delete_post_meta($postID, $count_key);
  630. add_post_meta($postID, $count_key, '0');
  631. }else{
  632. $count++;
  633. update_post_meta($postID, $count_key, $count);
  634. }
  635. }
  636. /* To correct issue: adjacent_posts_rel_link_wp_head causes meta to be updated multiple times */
  637. remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
  638. // Set up half slide for iFeature pro slider, adds it before post/page content
  639. function cyberchimps_half_slider() {
  640. global $post;
  641. if( is_page() ) {
  642. $page_section_order = get_post_meta($post->ID, 'cyberchimps_page_section_order' , true);
  643. //if page_section_order is empty sets page as default
  644. $page_section_order = ( $page_section_order == '' ) ? array( 'page_section' ) : $page_section_order;
  645. if( in_array( 'page_slider', $page_section_order, true ) ) {
  646. $slider_size = get_post_meta( $post->ID, 'cyberchimps_slider_size', true );
  647. if( $slider_size == 'half' ) {
  648. do_action( 'page_slider' );
  649. }
  650. }
  651. }
  652. else {
  653. $blog_section_order = cyberchimps_get_option( 'blog_section_order' );
  654. //select default in case options are empty
  655. $blog_section_order = ( $blog_section_order == '' ) ? array( 'blog_post_page' ) : $blog_section_order;
  656. if( in_array( 'page_slider', $blog_section_order, true ) ) {
  657. $slider_size = cyberchimps_get_option( 'blog_slider_size' );
  658. if( $slider_size == 'half' ) {
  659. do_action( 'page_slider' );
  660. }
  661. }
  662. }
  663. }
  664. add_action( 'cyberchimps_before_content', 'cyberchimps_half_slider' );
  665. // Modal welcome note
  666. function cyberchimps_modal_welcome_note() {
  667. if( cyberchimps_get_option( 'modal_welcome_note_display', 0 ) == 1 ): ?>
  668. <div class="modal" id="welcomeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  669. <div class="modal-header">
  670. <h3 id="myModalLabel"><?php _e( 'Welcome', 'cyberchimps' ); ?></h3>
  671. </div>
  672. <div class="modal-body">
  673. <?php printf( '
  674. <p>' . __( 'Congratulations you have successfully installed', 'cyberchimps' ) . ' %1$s!</p>
  675. <p>' . __( 'Your website is important to us, so please read the', 'cyberchimps' ) . ' <a href="%3$s" target="_blank">' . __( 'instructions', 'cyberchimps' ) . '</a> ' . __( 'to learn how to use', 'cyberchimps' ) . ' %1$s.</p>
  676. <p>' . __( 'If you have any questions please post in our', 'cyberchimps' ) . ' <a href="%4$s" target="_blank">' . __( 'support forum', 'cyberchimps' ) . '</a>, ' . __( 'and we will get back to you as soon as we can', 'cyberchimps' ) . '.</p>
  677. <p>' . __( 'Thank you for choosing CyberChimps Professional WordPress Themes', 'cyberchimps' ) . '!</p>',
  678. apply_filters( 'cyberchimps_current_theme_name', 'CyberChimps' ),
  679. apply_filters( 'cyberchimps_upgrade_link', 'http://cyberchimps.com/store/' ),
  680. apply_filters( 'cyberchimps_upgrade_pro_title', __( 'Pro', 'cyberchimps' ) ),
  681. apply_filters( 'cyberchimps_documentation', 'http://cyberchimps.com/help/' ),
  682. apply_filters( 'cyberchimps_support_forum', 'http://cyberchimps.com/forum/pro/' )
  683. );
  684. ?>
  685. </div>
  686. <div class="modal-footer">
  687. <input type="submit" id="welcomeModalSave" class="btn btn-primary" name="update" value="<?php esc_attr_e( 'Complete Installation', 'cyberchimps' ); ?>" />
  688. </div>
  689. </div>
  690. <?php
  691. endif;
  692. }
  693. add_action( 'cyberchimps_options_form_start', 'cyberchimps_modal_welcome_note' );
  694. // Help text
  695. function cyberchimps_options_help_text() {
  696. $text = '';
  697. $instruction_img = get_template_directory_uri().'/cyberchimps/options/lib/images/document.png';
  698. $support_img = get_template_directory_uri().'/cyberchimps/options/lib/images/questionsupport.png';
  699. $text .= '<div class="cc_help_section">
  700. <div class="row-fluid"><div class="span3">
  701. <a href="'.apply_filters( 'cyberchimps_documentation', 'http://cyberchimps.com' ).'" title="CyberChimps Instructions">
  702. <img src="'.$instruction_img.'" alt="CyberChimps Instructions" />
  703. <div class="cc_help_caption"><p>'.__( 'Instructions', 'cyberchimps' ).'</p></div>
  704. </a>
  705. </div>
  706. <div class="span3">
  707. <a href="'.apply_filters( 'cyberchimps_support_forum', 'http://cyberchimps.com' ).'" title="CyberChimps Support">
  708. <img src="'.$support_img.'" alt="CyberChimps Help" />
  709. <div class="cc_help_caption"><p>'.__( 'Support', 'cyberchimps' ).'</p></div>
  710. </a>
  711. </div>
  712. </div>';
  713. // Upgrade Button and text for free themes
  714. if( cyberchimps_theme_check() == 'free' ) {
  715. $text .= '<div class="row-fluid">
  716. <div class="span6">
  717. <a href="'. apply_filters( 'cyberchimps_upgrade_link', 'http://cyberchimps.com' ). '" title="'. apply_filters( 'cyberchimps_upgrade_pro_title', 'CyberChimps Pro' ). '">
  718. <div class="cc_help_upgrade_bar">'. sprintf( __( 'Upgrade to', 'cyberchimps' ) . ' %1$s', apply_filters( 'cyberchimps_upgrade_pro_title', 'CyberChimps Pro' ) ) .'</div>
  719. </a>
  720. </div>
  721. </div>
  722. </div>
  723. <div class="clear"></div>';
  724. $text .= sprintf( '<p>' . __( 'If you want even more amazing new features upgrade to', 'cyberchimps' ) . ' <a href="%1$s" title="%2$s">%2$s</a> ' . __( 'which includes a Custom Features Slider, Image Carousel, Widgetized Boxes, Callout Section, expanded typography including Google Fonts, more color skins, and many more powerful new features. Please visit', 'cyberchimps' ) . ' <a href="cyberchimps.com" title="CyberChimps">CyberChimps.com</a> ' . __( 'to learn more!', 'cyberchimps' ) . '</p>',
  725. apply_filters( 'cyberchimps_upgrade_link', 'http://cyberchimps.com' ),
  726. apply_filters( 'cyberchimps_upgrade_pro_title', 'CyberChimps Pro' )
  727. );
  728. }
  729. //text for pro themes
  730. else {
  731. $text .= '</div><div class="clear"></div>';
  732. }
  733. return $text;
  734. }
  735. add_filter( 'cyberchimps_help_description', 'cyberchimps_options_help_text' );
  736. // upgrade bar for free themes
  737. function cyberchimps_upgrade_bar() { ?>
  738. <div class="upgrade-callout">
  739. <p><img src="<?php echo get_template_directory_uri() ;?>/cyberchimps/options/lib/images/chimp.png" alt="CyberChimps" />
  740. <?php printf( __( 'Welcome to %1$s! Learn more now about upgrading to', 'cyberchimps' ) . ' <a href="%2$s" target="_blank" title="%3$s">%3$s</a> ' . __( 'today.', 'cyberchimps' ),
  741. apply_filters( 'cyberchimps_current_theme_name', 'CyberChimps' ),
  742. apply_filters( 'cyberchimps_upgrade_link', 'http://cyberchimps.com' ),
  743. apply_filters( 'cyberchimps_upgrade_pro_title', 'Pro' )
  744. ); ?>
  745. </p>
  746. <div class="social-container">
  747. <div class="social">
  748. <a href="https://twitter.com/cyberchimps" class="twitter-follow-button" data-show-count="false" data-size="small">Follow @cyberchimps</a>
  749. <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
  750. </div>
  751. <div class="social">
  752. <iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fcyberchimps.com%2F&amp;send=false&amp;layout=button_count&amp;width=200&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:21px;" allowTransparency="true"></iframe>
  753. </div>
  754. </div>
  755. </div>
  756. <?php
  757. }
  758. if( cyberchimps_theme_check() == 'free' ) {
  759. add_action( 'cyberchimps_options_before_container', 'cyberchimps_upgrade_bar' );
  760. }
  761. // Hide preview and view on custom post types
  762. function cyberchimps_posttype_admin_css() {
  763. global $post_type;
  764. if($post_type == 'custom_slides' || $post_type == 'boxes' || $post_type == 'featured_posts' || $post_type == 'portfolio_images') {
  765. echo '<style type="text/css">#view-post-btn,#post-preview{display: none;}</style>';
  766. }
  767. }
  768. add_action('admin_head', 'cyberchimps_posttype_admin_css');
  769. /**
  770. * Add link to theme options in Admin bar.
  771. */
  772. function cyberchimps_admin_link() {
  773. global $wp_admin_bar;
  774. $wp_admin_bar->add_menu( array(
  775. 'id' => 'cyberchimps',
  776. 'title' => apply_filters( 'cyberchimps_current_theme_name', 'CyberChimps '. __( 'Options', 'cyberchimps' ) ) . __( ' Options', 'cyberchimps' ),
  777. 'href' => admin_url('themes.php?page=cyberchimps-theme-options')
  778. ) );
  779. }
  780. add_action( 'admin_bar_menu', 'cyberchimps_admin_link', 113 );
  781. function cyberchimps_google_analytics() {
  782. $code = cyberchimps_get_option( 'google_analytics', '' );
  783. if( $code != '' ) {
  784. echo '<script type="text/javascript">'.$code.'</script>';
  785. }
  786. }
  787. add_action( 'cyberchimps_after_wrapper', 'cyberchimps_google_analytics' );
  788. // Add an array to an existing array in a certain position, used by options
  789. function cyberchimps_heading_filter( $orig, $new ) {
  790. foreach( $new as $key => $value ){
  791. array_splice( $orig, $key, 0, $value );
  792. }
  793. return $orig;
  794. }
  795. // the following 2 functions help retrieve the starting key number of the whole array of sections. There by allowing you to select the position of the custom section within that heading. 2 array's are passed to cyberchimps_array_section_organizer(). The initial array and the array of new sections. The array of new sections should have the format: $new_section[][10] = array( field-data ). 10 being the position within that heading.
  796. //this function finds the initial key number where the heading name exists in the original array. If it does not yet exist then this must be a new heading and it returns the last key number of the array.
  797. function cyberchimps_section_start_no( $heading, $orig ) {
  798. foreach( $orig as $key => $value ) {
  799. if( $value['heading'] == $heading ) {
  800. $first_key_value = $key;
  801. break;
  802. }
  803. else {
  804. end( $orig );
  805. $first_key_value = key( $orig ) + 1; //this counter acts the minus 1 from the organizer so the last element doesn't get built in front of
  806. }
  807. }
  808. return $first_key_value;
  809. }
  810. //this function takes the new and old array and combines them adding the new array elements in the position indicated by their key
  811. function cyberchimps_array_section_organizer( $orig, $new ) {
  812. foreach( $new as $value ) {
  813. foreach( $value as $key => $val ) {
  814. $section_start_no = cyberchimps_section_start_no( $val['heading'], $orig );
  815. $position = $section_start_no + ( $key - 1 );
  816. $position = intval( $position );
  817. array_splice( $orig, $position, 0, $value );
  818. }
  819. }
  820. return $orig;
  821. }
  822. // the following 2 functions help retrieve the starting key number of the whole array of fields. There by allowing you to select the position of the custom field within that section. 2 array's are passed to cyberchimps_array_field_organizer(). The initial array and the array of new fields. The array of new fields should have the format: $new_field[][10] = array( field-data ). 10 being the position within that section.
  823. //this function finds the initial key number wherethe section name exists in the original array. If it does not yet exist then this must be a new section and it returns the last key number of the array.
  824. function cyberchimps_field_start_no( $section, $orig ) {
  825. foreach( $orig as $key => $value ) {
  826. if( $value['section'] == $section ) {
  827. $first_key_value = $key;
  828. break;
  829. }
  830. else {
  831. end( $orig );
  832. $first_key_value = key( $orig ) + 1;
  833. }
  834. }
  835. return $first_key_value;
  836. }
  837. //this function takes the new and old array and combines them adding the new array elements in the position indicated by their key
  838. function cyberchimps_array_field_organizer( $orig, $new ) {
  839. foreach( $new as $value ) {
  840. foreach( $value as $key => $val ) {
  841. $section_start_no = cyberchimps_field_start_no( $val['section'], $orig );
  842. $position = $section_start_no + ( $key - 1 );
  843. $position = intval( $position );
  844. array_splice( $orig, $position, 0, $value );
  845. }
  846. }
  847. return $orig;
  848. }