PageRenderTime 25ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/ctf-f2015/www/wp-content/themes/twentyfifteen/inc/template-tags.php

https://github.com/mchow01/Security
PHP | 298 lines | 188 code | 37 blank | 73 comment | 50 complexity | e32ba7625dfdef4b6aabf8c4f34bc635 MD5 | raw file
  1. <?php
  2. /**
  3. * Custom template tags for this theme.
  4. *
  5. * Eventually, some of the functionality here could be replaced by core features.
  6. *
  7. * @package WordPress
  8. * @subpackage Twenty_Fifteen
  9. * @since Twenty Fifteen 1.0
  10. */
  11. if ( ! function_exists( 'twentyfifteen_paging_nav' ) ) :
  12. /**
  13. * Display navigation to next/previous set of posts when applicable.
  14. *
  15. * @since Twenty Fifteen 1.0
  16. * @uses paginate_links()
  17. *
  18. * @global WP_Query $wp_query WordPress Query object.
  19. */
  20. function twentyfifteen_paging_nav() {
  21. // Don't print empty markup if there's only one page.
  22. if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
  23. return;
  24. }
  25. // Set up paginated links.
  26. $links = paginate_links( array(
  27. 'prev_text' => esc_html__( 'Previous', 'twentyfifteen' ),
  28. 'next_text' => esc_html__( 'Next', 'twentyfifteen' ),
  29. 'before_page_number' => '<span class="meta-nav">' . esc_html__( 'Page', 'twentyfifteen' ) . '</span>',
  30. ) );
  31. if ( $links ) :
  32. ?>
  33. <nav class="navigation pagination" role="navigation">
  34. <h1 class="screen-reader-text"><?php esc_html_e( 'Posts navigation', 'twentyfifteen' ); ?></h1>
  35. <div class="nav-links">
  36. <?php echo $links; ?>
  37. </div><!-- .nav-links -->
  38. </nav><!-- .pagination -->
  39. <?php
  40. endif;
  41. }
  42. endif;
  43. if ( ! function_exists( 'twentyfifteen_post_nav' ) ) :
  44. /**
  45. * Display navigation to next/previous post when applicable.
  46. *
  47. * @since Twenty Fifteen 1.0
  48. */
  49. function twentyfifteen_post_nav() {
  50. // Don't print empty markup if there's nowhere to navigate.
  51. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  52. $next = get_adjacent_post( false, '', false );
  53. if ( ( ! $next && ! $previous ) || ( is_attachment() && 'attachment' == $previous->post_type ) ) {
  54. return;
  55. }
  56. $prev_class = $next_class = '';
  57. if ( $previous && has_post_thumbnail( $previous->ID ) ) {
  58. $prev_class = " has-post-thumbnail";
  59. }
  60. if ( $next && has_post_thumbnail( $next->ID ) ) {
  61. $next_class = " has-post-thumbnail";
  62. }
  63. ?>
  64. <nav class="navigation post-navigation" role="navigation">
  65. <h1 class="screen-reader-text"><?php esc_html_e( 'Post navigation', 'twentyfifteen' ); ?></h1>
  66. <div class="nav-links">
  67. <?php
  68. if ( is_attachment() ) :
  69. previous_post_link( '<div class="nav-previous' . $prev_class . '">%link</div>', _x( '<span class="meta-nav">Published In</span><span class="post-title">%title</span>', 'Parent post link', 'twentyfifteen' ) );
  70. else :
  71. previous_post_link( '<div class="nav-previous' . $prev_class . '">%link</div>', _x( '<span class="meta-nav">Previous</span><span class="post-title">%title</span>', 'Previous post link', 'twentyfifteen' ) );
  72. next_post_link( '<div class="nav-next' . $next_class . '">%link</div>', _x( '<span class="meta-nav">Next</span><span class="post-title">%title</span>', 'Next post link', 'twentyfifteen' ) );
  73. endif;
  74. ?>
  75. </div><!-- .nav-links -->
  76. </nav><!-- .post-navigation -->
  77. <?php
  78. }
  79. endif;
  80. if ( ! function_exists( 'twentyfifteen_comment_nav' ) ) :
  81. /**
  82. * Display navigation to next/previous comments when applicable.
  83. *
  84. * @since Twenty Fifteen 1.0
  85. */
  86. function twentyfifteen_comment_nav() {
  87. // Are there comments to navigate through?
  88. if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
  89. ?>
  90. <nav class="navigation comment-navigation" role="navigation">
  91. <h1 class="screen-reader-text"><?php esc_html_e( 'Comment navigation', 'twentyfifteen' ); ?></h1>
  92. <div class="nav-links">
  93. <?php
  94. if ( $prev_link = get_previous_comments_link( esc_html__( 'Older Comments', 'twentyfifteen' ) ) ) :
  95. printf( '<div class="nav-previous">%s</div>', $prev_link );
  96. endif;
  97. if ( $next_link = get_next_comments_link( esc_html__( 'Newer Comments', 'twentyfifteen' ) ) ) :
  98. printf( '<div class="nav-next">%s</div>', $next_link );
  99. endif;
  100. ?>
  101. </div><!-- .nav-links -->
  102. </nav><!-- .comment-navigation -->
  103. <?php
  104. endif;
  105. }
  106. endif;
  107. if ( ! function_exists( 'twentyfifteen_entry_meta' ) ) :
  108. /**
  109. * Prints HTML with meta information for the categories, tags.
  110. *
  111. * @since Twenty Fifteen 1.0
  112. */
  113. function twentyfifteen_entry_meta() {
  114. if ( is_sticky() && is_home() && ! is_paged() ) {
  115. printf( '<span class="sticky-post">%s</span>', esc_html__( 'Featured', 'twentyfifteen' ) );
  116. }
  117. $format = get_post_format();
  118. if ( current_theme_supports( 'post-formats', $format ) ) {
  119. printf( '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
  120. sprintf( '<span class="screen-reader-text">%s</span>', esc_html_x( 'Format', 'Used before post format.', 'twentyfifteen' ) ),
  121. esc_url( get_post_format_link( $format ) ),
  122. get_post_format_string( $format )
  123. );
  124. }
  125. if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
  126. $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
  127. if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  128. $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
  129. }
  130. $time_string = sprintf( $time_string,
  131. esc_attr( get_the_date( 'c' ) ),
  132. esc_html( get_the_date() ),
  133. esc_attr( get_the_modified_date( 'c' ) ),
  134. esc_html( get_the_modified_date() )
  135. );
  136. printf( '<span class="posted-on">%1$s<a href="%2$s" rel="bookmark">%3$s</a></span>',
  137. sprintf( _x( '<span class="screen-reader-text">Posted on</span>', 'Used before publish date.', 'twentyfifteen' ) ),
  138. esc_url( get_permalink() ),
  139. $time_string
  140. );
  141. }
  142. if ( 'post' == get_post_type() ) {
  143. if ( is_singular() || is_multi_author() ) {
  144. printf( '<span class="byline"><span class="author vcard">%1$s<a class="url fn n" href="%2$s">%3$s</a></span></span>',
  145. sprintf( _x( '<span class="screen-reader-text">Author</span>', 'Used before post author name.', 'twentyfifteen' ) ),
  146. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  147. esc_html( get_the_author() )
  148. );
  149. }
  150. $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) );
  151. if ( $categories_list && twentyfifteen_categorized_blog() ) {
  152. printf( '<span class="cat-links">%1$s%2$s</span>',
  153. sprintf( _x( '<span class="screen-reader-text">Categories</span>', 'Used before category names.', 'twentyfifteen' ) ),
  154. $categories_list
  155. );
  156. }
  157. $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) );
  158. if ( $tags_list ) {
  159. printf( '<span class="tags-links">%1$s%2$s</span>',
  160. sprintf( _x( '<span class="screen-reader-text">Tags</span>', 'Used before tag names.', 'twentyfifteen' ) ),
  161. $tags_list
  162. );
  163. }
  164. }
  165. if ( is_attachment() && wp_attachment_is_image() ) {
  166. // Retrieve attachment metadata.
  167. $metadata = wp_get_attachment_metadata();
  168. printf( '<span class="full-size-link">%1$s<a href="%2$s">%3$s &times; %4$s</a></span>',
  169. sprintf( _x( '<span class="screen-reader-text">Full size</span>', 'Used before full size attachment link.', 'twentyfifteen' ) ),
  170. esc_url( wp_get_attachment_url() ),
  171. $metadata['width'],
  172. $metadata['height']
  173. );
  174. }
  175. if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
  176. echo '<span class="comments-link">';
  177. comments_popup_link( esc_html__( 'Leave a comment', 'twentyfifteen' ), esc_html__( '1 Comment', 'twentyfifteen' ), esc_html__( '% Comments', 'twentyfifteen' ) );
  178. echo '</span>';
  179. }
  180. }
  181. endif;
  182. /**
  183. * Returns true if a blog has more than 1 category.
  184. *
  185. * @since Twenty Fifteen 1.0
  186. *
  187. * @return bool
  188. */
  189. function twentyfifteen_categorized_blog() {
  190. if ( false === ( $all_the_cool_cats = get_transient( 'twentyfifteen_categories' ) ) ) {
  191. // Create an array of all the categories that are attached to posts.
  192. $all_the_cool_cats = get_categories( array(
  193. 'fields' => 'ids',
  194. 'hide_empty' => 1,
  195. // We only need to know if there is more than one category.
  196. 'number' => 2,
  197. ) );
  198. // Count the number of categories that are attached to the posts.
  199. $all_the_cool_cats = count( $all_the_cool_cats );
  200. set_transient( 'twentyfifteen_categories', $all_the_cool_cats );
  201. }
  202. if ( $all_the_cool_cats > 1 ) {
  203. // This blog has more than 1 category so twentyfifteen_categorized_blog should return true.
  204. return true;
  205. } else {
  206. // This blog has only 1 category so twentyfifteen_categorized_blog should return false.
  207. return false;
  208. }
  209. }
  210. /**
  211. * Flush out the transients used in twentyfifteen_categorized_blog.
  212. *
  213. * @since Twenty Fifteen 1.0
  214. */
  215. function twentyfifteen_category_transient_flusher() {
  216. // Like, beat it. Dig?
  217. delete_transient( 'twentyfifteen_categories' );
  218. }
  219. add_action( 'edit_category', 'twentyfifteen_category_transient_flusher' );
  220. add_action( 'save_post', 'twentyfifteen_category_transient_flusher' );
  221. if ( ! function_exists( 'twentyfifteen_post_thumbnail' ) ) :
  222. /**
  223. * Display an optional post thumbnail.
  224. *
  225. * Wraps the post thumbnail in an anchor element on index views, or a div
  226. * element when on single views.
  227. *
  228. * @since Twenty Fifteen 1.0
  229. */
  230. function twentyfifteen_post_thumbnail() {
  231. if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
  232. return;
  233. }
  234. if ( is_singular() ) :
  235. ?>
  236. <div class="post-thumbnail">
  237. <?php the_post_thumbnail(); ?>
  238. </div><!-- .post-thumbnail -->
  239. <?php else : ?>
  240. <a class="post-thumbnail" href="<?php the_permalink(); ?>">
  241. <?php the_post_thumbnail(); ?>
  242. </a>
  243. <?php endif; // End is_singular()
  244. }
  245. endif;
  246. if ( ! function_exists( 'twentyfifteen_get_link_url' ) ) :
  247. /**
  248. * Return the post URL.
  249. *
  250. * Falls back to the post permalink if no URL is found in the post.
  251. *
  252. * @since Twenty Fifteen 1.0
  253. * @uses get_url_in_content()
  254. *
  255. * @return string The Link format URL.
  256. */
  257. function twentyfifteen_get_link_url() {
  258. $has_url = get_url_in_content( get_the_content() );
  259. return $has_url ? $has_url : apply_filters( 'the_permalink', get_permalink() );
  260. }
  261. endif;