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

/data/wpcom-themes/arras/library/template.php

https://gitlab.com/Blueprint-Marketing/wordpress-unit-tests
PHP | 352 lines | 274 code | 50 blank | 28 comment | 64 complexity | 065cc58ecd79a78f85c77d9833a4192b MD5 | raw file
  1. <?php
  2. function arras_get_page_no() {
  3. if ( get_query_var('paged') ) print ' | Page ' . get_query_var('paged');
  4. }
  5. function arras_document_title() {
  6. if ( function_exists('seo_title_tag') ) {
  7. seo_title_tag();
  8. } else if ( class_exists('All_in_One_SEO_Pack') || class_exists('HeadSpace2_Admin') ) {
  9. if(is_front_page() || is_home()) {
  10. echo get_bloginfo('name') . ': ' . get_bloginfo('description');
  11. } else {
  12. wp_title('');
  13. }
  14. } else {
  15. if ( is_attachment() ) { bloginfo('name'); print ' | '; single_post_title(''); }
  16. elseif ( is_single() ) { single_post_title(); }
  17. elseif ( is_home() ) { bloginfo('name'); print ' | '; bloginfo('description'); arras_get_page_no(); }
  18. elseif ( is_page() ) { single_post_title(''); }
  19. elseif ( is_search() ) { bloginfo('name'); print ' | Search results for ' . wp_specialchars($s); arras_get_page_no(); }
  20. elseif ( is_404() ) { bloginfo('name'); print ' | Not Found'; }
  21. else { bloginfo('name'); wp_title('|'); arras_get_page_no(); }
  22. }
  23. }
  24. function arras_override_styles() {
  25. ?>
  26. <?php global $arras_registered_alt_layouts; if ( count($arras_registered_alt_layouts) > 0 ) : ?>
  27. <link rel="stylesheet" href="<?php bloginfo('template_url') ?>/css/layouts/<?php echo arras_get_option('layout') ?>.css" type="text/css" />
  28. <?php endif; ?>
  29. <?php
  30. $bg_exists = file_exists(TEMPLATEPATH . '/images/bg/' . arras_get_option('background'));
  31. if ($bg_exists || arras_get_option('background_color')) {
  32. echo '<style type="text/css">';
  33. echo 'body {';
  34. if ($bg_exists) echo 'background: url(' . get_bloginfo('stylesheet_directory') . '/images/bg/' . arras_get_option('background') . ') ' . arras_get_option('background_tiling') . ' top center;';
  35. if (arras_get_option('background_color')) echo 'background-color: ' . arras_get_option('background_color') . ';';
  36. echo '}';
  37. echo '</style>';
  38. }
  39. }
  40. function arras_alternate_style() {
  41. global $theme_data, $arras_registered_alt_styles;
  42. if (ARRAS_CHILD && count($arras_registered_alt_styles) > 0) {
  43. echo '<link rel="stylesheet=" href="' . get_bloginfo('stylesheet_url') . '" type="text/css" media="screen, projector" />';
  44. } else {
  45. $scheme = arras_get_option('style');
  46. if ( $scheme != 'default' )
  47. echo '<link rel="stylesheet" href="' . get_bloginfo('stylesheet_directory') . '/css/styles/' . $scheme . '.css" type="text/css" media="screen" />';
  48. else
  49. echo '<link rel="stylesheet" href="' . get_bloginfo('stylesheet_directory') . '/css/styles/default.css" type="text/css" media="screen" />';
  50. if (!ARRAS_CHILD) {
  51. echo '<link rel="stylesheet" href="' . get_bloginfo('template_url') . '/css/user.css" type="text/css" media="screen" />';
  52. }
  53. }
  54. }
  55. /**
  56. * Generates semantic classes for BODY element. Based on Sandbox.
  57. */
  58. function arras_body_class() {
  59. if ( function_exists('body_class') )
  60. return body_class();
  61. global $wp_query, $current_user;
  62. // It's surely a WordPress blog, right?
  63. $c = array('wordpress');
  64. // Applies the time- and date-based classes (below) to BODY element
  65. arras_date_classes( time(), $c );
  66. // Generic semantic classes for what type of content is displayed
  67. is_front_page() ? $c[] = 'home' : null; // For the front page, if set
  68. is_home() ? $c[] = 'blog' : null; // For the blog posts page, if set
  69. is_archive() ? $c[] = 'archive' : null;
  70. is_date() ? $c[] = 'date' : null;
  71. is_search() ? $c[] = 'search' : null;
  72. is_paged() ? $c[] = 'paged' : null;
  73. is_attachment() ? $c[] = 'attachment' : null;
  74. is_404() ? $c[] = 'four04' : null; // CSS does not allow a digit as first character
  75. // Special classes for BODY element when a single post
  76. if ( is_single() ) {
  77. $postID = $wp_query->post->ID;
  78. the_post();
  79. // Adds 'single' class and class with the post ID
  80. $c[] = 'single postid-' . $postID;
  81. // Adds classes for the month, day, and hour when the post was published
  82. if ( isset( $wp_query->post->post_date ) )
  83. arras_date_classes( mysql2date( 'U', $wp_query->post->post_date ), $c, 's-' );
  84. // Adds category classes for each category on single posts
  85. if ( $cats = get_the_category() )
  86. foreach ( $cats as $cat )
  87. $c[] = 's-category-' . $cat->slug;
  88. // Adds tag classes for each tags on single posts
  89. if ( $tags = get_the_tags() )
  90. foreach ( $tags as $tag )
  91. $c[] = 's-tag-' . $tag->slug;
  92. // Adds MIME-specific classes for attachments
  93. if ( is_attachment() ) {
  94. $mime_type = get_post_mime_type();
  95. $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
  96. $c[] = 'attachmentid-' . $postID . ' attachment-' . str_replace( $mime_prefix, "", "$mime_type" );
  97. }
  98. // Adds author class for the post author
  99. $c[] = 's-author-' . sanitize_title_with_dashes(strtolower(get_the_author_login()));
  100. rewind_posts();
  101. }
  102. // Author name classes for BODY on author archives
  103. elseif ( is_author() ) {
  104. $author = $wp_query->get_queried_object();
  105. $c[] = 'author';
  106. $c[] = 'author-' . $author->user_nicename;
  107. }
  108. // Category name classes for BODY on category archvies
  109. elseif ( is_category() ) {
  110. $cat = $wp_query->get_queried_object();
  111. $c[] = 'category';
  112. $c[] = 'category-' . $cat->slug;
  113. }
  114. // Tag name classes for BODY on tag archives
  115. elseif ( is_tag() ) {
  116. $tags = $wp_query->get_queried_object();
  117. $c[] = 'tag';
  118. $c[] = 'tag-' . $tags->slug;
  119. }
  120. // Page author for BODY on 'pages'
  121. elseif ( is_page() ) {
  122. $pageID = $wp_query->post->ID;
  123. $page_children = wp_list_pages("child_of=$pageID&echo=0");
  124. the_post();
  125. $c[] = 'page pageid-' . $pageID;
  126. $c[] = 'page-author-' . sanitize_title_with_dashes(strtolower(get_the_author('login')));
  127. // Checks to see if the page has children and/or is a child page; props to Adam
  128. if ( $page_children )
  129. $c[] = 'page-parent';
  130. if ( $wp_query->post->post_parent )
  131. $c[] = 'page-child parent-pageid-' . $wp_query->post->post_parent;
  132. if ( is_page_template() ) // Hat tip to Ian, themeshaper.com
  133. $c[] = 'page-template page-template-' . str_replace( '.php', '-php', get_post_meta( $pageID, '_wp_page_template', true ) );
  134. rewind_posts();
  135. }
  136. // Search classes for results or no results
  137. elseif ( is_search() ) {
  138. the_post();
  139. if ( have_posts() ) {
  140. $c[] = 'search-results';
  141. } else {
  142. $c[] = 'search-no-results';
  143. }
  144. rewind_posts();
  145. }
  146. // For when a visitor is logged in while browsing
  147. if ( $current_user->ID )
  148. $c[] = 'loggedin';
  149. // Paged classes; for 'page X' classes of index, single, etc.
  150. if ( ( ( $page = $wp_query->get('paged') ) || ( $page = $wp_query->get('page') ) ) && $page > 1 ) {
  151. $c[] = 'paged-' . $page;
  152. if ( is_single() ) {
  153. $c[] = 'single-paged-' . $page;
  154. } elseif ( is_page() ) {
  155. $c[] = 'page-paged-' . $page;
  156. } elseif ( is_category() ) {
  157. $c[] = 'category-paged-' . $page;
  158. } elseif ( is_tag() ) {
  159. $c[] = 'tag-paged-' . $page;
  160. } elseif ( is_date() ) {
  161. $c[] = 'date-paged-' . $page;
  162. } elseif ( is_author() ) {
  163. $c[] = 'author-paged-' . $page;
  164. } elseif ( is_search() ) {
  165. $c[] = 'search-paged-' . $page;
  166. }
  167. }
  168. // Get current layout
  169. $c[] = 'layout-' . arras_get_option('layout');
  170. $c[] = 'style-' . arras_get_option('style');
  171. // Separates classes with a single space, collates classes for BODY
  172. $c = join( ' ', apply_filters( 'arras_body_class', $c ) ); // Available filter: body_class
  173. // And tada!
  174. echo 'class="' . $c . '"';
  175. }
  176. function arras_date_classes($t, &$c, $p = '') {
  177. $t = $t + ( get_option('gmt_offset') * 3600 );
  178. $c[] = $p . 'y' . gmdate( 'Y', $t ); // Year
  179. $c[] = $p . 'm' . gmdate( 'm', $t ); // Month
  180. $c[] = $p . 'd' . gmdate( 'd', $t ); // Day
  181. $c[] = $p . 'h' . gmdate( 'H', $t ); // Hour
  182. }
  183. function arras_get_thumbnail($w = 630, $h = 250) {
  184. global $post;
  185. $thumbnail = get_post_meta($post->ID, ARRAS_POST_THUMBNAIL, true);
  186. if (!$thumbnail) {
  187. return false;
  188. } else {
  189. if (ARRAS_THUMB == 'phpthumb') {
  190. return get_bloginfo('template_directory') . '/library/phpthumb/phpThumb.php?src=' . $thumbnail . '&amp;w=' . $w . '&amp;h=' . $h . '&amp;zc=1';
  191. } else {
  192. return get_bloginfo('template_directory') . '/library/timthumb.php?src=' . $thumbnail . '&amp;w=' . $w . '&amp;h=' . $h . '&amp;zc=1';
  193. }
  194. }
  195. }
  196. function arras_get_posts($page_type, $query = null) {
  197. global $post, $wp_query;
  198. if (!$query) $query = $wp_query;
  199. if ( $query->have_posts() ) : ?>
  200. <?php if (arras_get_option($page_type . '_news_display') == 'traditional') : ?>
  201. <div class="traditional hfeed">
  202. <?php while ($query->have_posts()) : $query->the_post() ?>
  203. <div <?php arras_single_post_class() ?>>
  204. <?php arras_postheader() ?>
  205. <div class="entry-content"><?php the_content( __('<p>Read the rest of this entry &raquo;</p>', 'arras') ); ?></div>
  206. <?php arras_postfooter() ?>
  207. </div>
  208. <?php endwhile; ?>
  209. </div><!-- .traditional -->
  210. <?php elseif (arras_get_option($page_type . '_news_display') == 'line') : ?>
  211. <ul class="hfeed posts-line clearfix">
  212. <?php while ($query->have_posts()) : $query->the_post() ?>
  213. <li <?php arras_post_class() ?>>
  214. <?php if(!is_archive()) : ?>
  215. <span class="entry-cat"><?php $cats = get_the_category(); if (arras_get_option('news_cat')) echo $cats[1]->cat_name; else echo $cats[0]->cat_name; ?></span>
  216. <?php endif ?>
  217. <h3 class="entry-title"><a rel="bookmark" href="<?php the_permalink() ?>" title="<?php printf( __('Permalink to %s', 'arras'), get_the_title() ) ?>"><?php the_title() ?></a></h3>
  218. <span class="entry-comments"><?php comments_number() ?></span>
  219. </li>
  220. <?php endwhile; ?>
  221. </ul>
  222. <?php else : ?>
  223. <ul class="hfeed posts-<?php echo arras_get_option($page_type . '_news_display') ?> clearfix">
  224. <?php while ($query->have_posts()) : $query->the_post() ?>
  225. <li <?php arras_post_class() ?>>
  226. <?php arras_newsheader($page_type) ?>
  227. <div class="entry-summary"><?php echo arras_strip_content(get_the_excerpt(), 20); ?></div>
  228. <?php arras_newsfooter($page_type) ?>
  229. </li>
  230. <?php endwhile; ?>
  231. </ul>
  232. <?php endif; ?>
  233. <?php endif; ?>
  234. <?php
  235. }
  236. function arras_list_trackbacks($comment, $args, $depth) {
  237. $GLOBALS['comment'] = $comment;
  238. ?>
  239. <li <?php comment_class(); ?> id="li-trackback-<?php comment_ID() ?>">
  240. <div id="trackback-<?php comment_ID(); ?>">
  241. <?php echo get_comment_author_link() ?>
  242. </div>
  243. <?php
  244. }
  245. function arras_list_comments($comment, $args, $depth) {
  246. $GLOBALS['comment'] = $comment;
  247. ?>
  248. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  249. <div class="comment-node" id="comment-<?php comment_ID(); ?>">
  250. <div class="comment-author vcard">
  251. <?php echo get_avatar($comment, $size = 24) ?>
  252. <cite class="fn"><?php echo get_comment_author_link() ?></cite>
  253. </div>
  254. <?php if ( $comment->comment_approved == '0' ) : ?>
  255. <span class="comment-moderation"><?php _e('Your comment is awaiting moderation.', 'arras') ?></span>
  256. <?php endif; ?>
  257. <div class="comment-meta commentmetadata">
  258. <?php printf( __('Posted %1$s at %2$s', 'arras'), '<abbr class="comment-datetime" title="' . get_comment_time( __('c', 'arras') ) . '">' . get_comment_time( __('F j, Y', 'arras') ), get_comment_time( __('g:i A', 'arras') ) . '</abbr>' ); ?>
  259. </div>
  260. <div class="comment-content"><?php comment_text() ?></div>
  261. <div class="comment-controls">
  262. <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  263. </div>
  264. </div>
  265. <?php
  266. }
  267. function arras_post_class() {
  268. if ( function_exists('post_class') )
  269. return post_class('clearfix');
  270. else return 'class="clearfix"';
  271. }
  272. function arras_single_post_class() {
  273. if ( function_exists('post_class') )
  274. return post_class(array('clearfix', 'single-post'));
  275. else return 'class="single-post clearfix"';
  276. }
  277. function arras_parse_single_custom_fields() {
  278. $arr = explode( ',', arras_get_option('single_custom_fields') );
  279. $final = array();
  280. if ( !is_array($arr) ) return false;
  281. foreach ( $arr as $val ) {
  282. $field_arr = explode(':', $val);
  283. $final[ $field_arr[1] ] = $field_arr[0];
  284. }
  285. return $final;
  286. }
  287. function arras_strip_content($content, $limit) {
  288. $content = apply_filters('the_content', $content);
  289. $content = strip_tags($content);
  290. $content = str_replace(']]>', ']]&gt;', $content);
  291. $words = explode(' ', $content, ($limit + 1));
  292. if(count($words) > $limit) {
  293. array_pop($words);
  294. //add a ... at last article when more than limit word count
  295. return implode(' ', $words) . '...';
  296. } else {
  297. //otherwise
  298. return implode(' ', $words);
  299. }
  300. }
  301. /* End of file template.php */
  302. /* Location: ./library/template.php */