PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/esquire/functions.php

https://github.com/Bochet/festival_lgbt
PHP | 315 lines | 167 code | 39 blank | 109 comment | 21 complexity | 895bb1fe706a85b75758f8995343439d MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @package Esquire
  4. */
  5. /**
  6. * Load Esquire scripts
  7. */
  8. function esquire_scripts() {
  9. wp_enqueue_script( 'esquire', get_template_directory_uri() .'/js/esquire.js', array( 'jquery'), '2011-07-29' );
  10. if ( ! is_singular() || ( is_singular() && 'audio' == get_post_format() ) )
  11. wp_enqueue_script( 'audio-player', get_template_directory_uri() . '/js/audio-player.js', array( 'swfobject'), '20120525' );
  12. }
  13. add_action( 'wp_enqueue_scripts', 'esquire_scripts' );
  14. /**
  15. * Set the content width based on the theme's design and stylesheet.
  16. */
  17. if ( ! isset( $content_width ) )
  18. $content_width = 560;
  19. /**
  20. * Sets up theme defaults and registers support for various WordPress features.
  21. *
  22. * Note that this function is hooked into the after_setup_theme hook, which runs
  23. * before the init hook. The init hook is too late for some features, such as indicating
  24. * support post thumbnails.
  25. *
  26. * @since Esquire 1.2
  27. */
  28. function esquire_setup() {
  29. /**
  30. * Make theme available for translation
  31. * Translations can be filed in the /languages/ directory
  32. */
  33. load_theme_textdomain( 'esquire', get_template_directory_uri() . '/languages' );
  34. /**
  35. * Add feed links to head
  36. */
  37. add_theme_support( 'automatic-feed-links' );
  38. /**
  39. * This theme uses wp_nav_menu() in one location.
  40. */
  41. register_nav_menus( array(
  42. 'primary' => __( 'Main Menu', 'esquire' ),
  43. ) );
  44. // Add post thumbnail support for audio album art
  45. add_theme_support( 'post-thumbnails' );
  46. add_image_size( 'audio', 207, 207, false );
  47. /**
  48. * Enable Post Formats
  49. */
  50. add_theme_support( 'post-formats', array( 'aside', 'gallery', 'image', 'quote', 'link', 'audio', 'video' ) );
  51. /**
  52. * Load Jetpack compatibility file.
  53. */
  54. require( get_template_directory() . '/inc/jetpack.compat.php' );
  55. /**
  56. * Load up our functions for grabbing content from posts
  57. */
  58. require( get_template_directory() . '/content-grabbers.php' );
  59. }
  60. add_action( 'after_setup_theme', 'esquire_setup' );
  61. /**
  62. * Sniff out the number of categories in use and return the number of categories
  63. */
  64. function esquire_category_counter() {
  65. if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
  66. // Create an array of all the categories that are attached to posts
  67. $all_the_cool_cats = get_categories( array(
  68. 'hide_empty' => 1,
  69. ) );
  70. // Count the number of categories that are attached to the posts
  71. $all_the_cool_cats = count( $all_the_cool_cats );
  72. set_transient( 'all_the_cool_cats', $all_the_cool_cats );
  73. }
  74. return $all_the_cool_cats;
  75. }
  76. /**
  77. * Flush out the transients used in esquire_category_counter
  78. */
  79. function esquire_category_transient_flusher() {
  80. // Like, beat it. Dig?
  81. delete_transient( 'all_the_cool_cats' );
  82. }
  83. add_action( 'edit_category', 'esquire_category_transient_flusher' );
  84. add_action( 'save_post', 'esquire_category_transient_flusher' );
  85. /**
  86. * Add a class to the Older Posts link
  87. */
  88. function esquire_next_posts_link_attributes( $attr ) {
  89. $attr = 'rel="prev"';
  90. return $attr;
  91. }
  92. add_filter( 'next_posts_link_attributes', 'esquire_next_posts_link_attributes' );
  93. /**
  94. * Add a class to the Newer Posts link
  95. */
  96. function esquire_previous_posts_link_attributes( $attr ) {
  97. $attr = 'rel="next"';
  98. return $attr;
  99. }
  100. add_filter( 'previous_posts_link_attributes', 'esquire_previous_posts_link_attributes' );
  101. /**
  102. * Sets the post excerpt length to 40 words.
  103. *
  104. * To override this length in a child theme, remove the filter and add your own
  105. * function tied to the excerpt_length filter hook.
  106. */
  107. function esquire_excerpt_length( $length ) {
  108. return 40;
  109. }
  110. add_filter( 'excerpt_length', 'esquire_excerpt_length' );
  111. /**
  112. * Returns a "Continue Reading" link for excerpts
  113. */
  114. function esquire_continue_reading_link() {
  115. return ' <a href="'. esc_url( get_permalink() ) . '"><em>' .__( 'Continue&nbsp;reading&nbsp;<span class="meta-nav">&rarr;</span>', 'esquire' ) . '</em></a>';
  116. }
  117. /**
  118. * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and esquire_continue_reading_link().
  119. *
  120. * To override this in a child theme, remove the filter and add your own
  121. * function tied to the excerpt_more filter hook.
  122. */
  123. function esquire_auto_excerpt_more( $more ) {
  124. return ' &hellip;' . esquire_continue_reading_link();
  125. }
  126. add_filter( 'excerpt_more', 'esquire_auto_excerpt_more' );
  127. /**
  128. * Adds a pretty "Continue Reading" link to custom post excerpts.
  129. *
  130. * To override this link in a child theme, remove the filter and add your own
  131. * function tied to the get_the_excerpt filter hook.
  132. */
  133. function esquire_custom_excerpt_more( $output ) {
  134. if ( has_excerpt() && ! is_attachment() ) {
  135. $output .= esquire_continue_reading_link();
  136. }
  137. return $output;
  138. }
  139. add_filter( 'get_the_excerpt', 'esquire_custom_excerpt_more' );
  140. /**
  141. * Register our footer widget area
  142. *
  143. * @since Esquire 1.0
  144. */
  145. function esquire_widgets_init() {
  146. register_sidebar( array(
  147. 'name' => __( 'Footer', 'esquire' ),
  148. 'id' => 'sidebar-1',
  149. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  150. 'after_widget' => "</aside>",
  151. 'before_title' => '<h3 class="widget-title">',
  152. 'after_title' => '</h3>',
  153. ) );
  154. }
  155. add_action( 'widgets_init', 'esquire_widgets_init' );
  156. /**
  157. * Template for comments and pingbacks.
  158. * Used as a callback by wp_list_comments() for displaying the comments.
  159. *
  160. * @since Esquire 1.0
  161. */
  162. function esquire_comment( $comment, $args, $depth ) {
  163. $GLOBALS['comment'] = $comment;
  164. switch ( $comment->comment_type ) :
  165. case 'pingback' :
  166. case 'trackback' :
  167. ?>
  168. <li class="post pingback">
  169. <p><?php _e( 'Pingback:', 'esquire' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'esquire' ), '<span class="edit-link">', '</span>' ); ?></p>
  170. <?php
  171. break;
  172. default :
  173. ?>
  174. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  175. <article id="comment-<?php comment_ID(); ?>" class="comment">
  176. <footer class="comment-meta">
  177. <div class="comment-author vcard">
  178. <?php
  179. $avatar_size = 16;
  180. echo get_avatar( $comment, $avatar_size );
  181. /* translators: 1: comment author, 2: date and time */
  182. printf( __( '%1$s on %2$s <span class="says">said:</span>', 'esquire' ),
  183. sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
  184. sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
  185. esc_url( get_comment_link( $comment->comment_ID ) ),
  186. get_comment_time( 'c' ),
  187. /* translators: 1: date, 2: time */
  188. sprintf( __( '%1$s at %2$s', 'esquire' ), get_comment_date(), get_comment_time() )
  189. )
  190. );
  191. ?>
  192. <?php edit_comment_link( __( 'Edit', 'esquire' ), '<span class="edit-link">', '</span>' ); ?>
  193. </div><!-- .comment-author .vcard -->
  194. <?php if ( $comment->comment_approved == '0' ) : ?>
  195. <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'esquire' ); ?></em>
  196. <br />
  197. <?php endif; ?>
  198. </footer>
  199. <div class="comment-content"><?php comment_text(); ?></div>
  200. <div class="reply">
  201. <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>&darr;</span>', 'esquire' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  202. </div><!-- .reply -->
  203. </article><!-- #comment-## -->
  204. <?php
  205. break;
  206. endswitch;
  207. }
  208. /**
  209. * Filter the_content for post formats, and add extra presentational markup as needed.
  210. *
  211. * @param string the_content
  212. * @return string Updated content with extra markup.
  213. */
  214. function esquire_the_content( $content ) {
  215. global $post;
  216. $format = get_post_format();
  217. if ( ! $format )
  218. return $content;
  219. switch ( $format ) {
  220. case 'image':
  221. $first_image = esquire_image_grabber( $post->ID, $content, '<div class="frame"><div class="wrapper">', '</div></div>' );
  222. if ( $first_image )
  223. $content = preg_replace( WPCOM_THEMES_IMAGE_REPLACE_REGEX, $first_image, $content, 1 );
  224. break;
  225. default:
  226. break;
  227. }
  228. return $content;
  229. }
  230. if ( ! is_admin() )
  231. add_filter( 'the_content', 'esquire_the_content', 11 );
  232. /**
  233. * Add extra markup to VideoPress embeds.
  234. *
  235. * @param string html Video content from VideoPress plugin.
  236. * @return string Updated content with extra markup.
  237. */
  238. function esquire_video_embed_html( $html ) {
  239. $html = '<div class="frame"><div class="player">' . $html . '</div></div>';
  240. return $html;
  241. }
  242. /**
  243. * Add extra markup to auto-embedded videos.
  244. *
  245. * @param string html Content from the auto-embed plugin.
  246. * @param string url Link embedded in the post, used to determine if this is a video we want to filter.
  247. * @return string Updated content with extra markup.
  248. */
  249. function esquire_check_video_embeds( $html, $url ) {
  250. if ( false !== ( strstr( $url, 'youtube' ) ) || false !== ( strstr( $url, 'vimeo' ) ) )
  251. $html = esquire_video_embed_html( $html );
  252. return $html;
  253. }
  254. // Add in-head JS block for audio post format
  255. function esquire_add_audio_support() {
  256. if ( ! is_singular() || ( is_singular() && 'audio' == get_post_format() ) ) {
  257. ?>
  258. <script type="text/javascript">
  259. /* <![CDATA[ */
  260. AudioPlayer.setup( "<?php echo get_template_directory_uri(); ?>/swf/player.swf", {
  261. bg: "222222",
  262. leftbg: "444444",
  263. rightbg: "444444",
  264. track: "222222",
  265. text: "ffffff",
  266. lefticon: "eeeeee",
  267. righticon: "eeeeee",
  268. border: "222222",
  269. tracker: "3d87cb",
  270. loader: "666666"
  271. });
  272. /* ]]> */
  273. </script>
  274. <?php }
  275. }
  276. add_action( 'wp_head', 'esquire_add_audio_support' );