PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/arras/library/template.php

https://github.com/digitalstrategyworks/Reese-WordPress
PHP | 692 lines | 271 code | 391 blank | 30 comment | 62 complexity | dc8c97490d6fe19d6f25b1bf3f4aa4ee 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. /**
  6. * SEO-Friendly title tag, based on Thematic Framework, which is based on Tarski :)
  7. */
  8. function arras_document_title() {
  9. $site_name = get_bloginfo('name');
  10. $separator = '|';
  11. if ( is_single() ) {
  12. $content = single_post_title('', FALSE);
  13. }
  14. elseif ( is_home() || is_front_page() ) {
  15. $content = get_bloginfo('description');
  16. }
  17. elseif ( is_page() ) {
  18. $content = single_post_title('', FALSE);
  19. }
  20. elseif ( is_search() ) {
  21. $content = __('Search Results for:', 'arras');
  22. $content .= ' ' . esc_html(stripslashes(get_search_query()), true);
  23. }
  24. elseif ( is_category() ) {
  25. $content = __('Category Archives:', 'arras');
  26. $content .= ' ' . single_cat_title("", false);;
  27. }
  28. elseif ( is_tag() ) {
  29. $content = __('Tag Archives:', 'arras');
  30. $content .= ' ' . arras_tag_query();
  31. }
  32. elseif ( is_404() ) {
  33. $content = __('Not Found', 'arras');
  34. }
  35. else {
  36. $content = get_bloginfo('description');
  37. }
  38. if (get_query_var('paged')) {
  39. $content .= ' ' .$separator. ' ';
  40. $content .= 'Page';
  41. $content .= ' ';
  42. $content .= get_query_var('paged');
  43. }
  44. if($content) {
  45. if ( is_home() || is_front_page() ) {
  46. $elements = array(
  47. 'site_name' => $site_name,
  48. 'separator' => $separator,
  49. 'content' => $content
  50. );
  51. }
  52. else {
  53. $elements = array(
  54. 'content' => $content
  55. );
  56. }
  57. } else {
  58. $elements = array(
  59. 'site_name' => $site_name
  60. );
  61. }
  62. // Filters should return an array
  63. $elements = apply_filters('arras_doctitle', $elements);
  64. // But if they don't, it won't try to implode
  65. if(is_array($elements)) {
  66. $doctitle = implode(' ', $elements);
  67. }
  68. else {
  69. $doctitle = $elements;
  70. }
  71. echo $doctitle;
  72. }
  73. function arras_add_header_js() {
  74. ?>
  75. <script type="text/javascript">
  76. <?php @include ARRAS_DIR . '/js/header.js.php'; ?>
  77. </script>
  78. <?php
  79. }
  80. /**
  81. * Based on Thematic's thematic_tag_query()
  82. */
  83. function arras_tag_query() {
  84. $nice_tag_query = get_query_var('tag'); // tags in current query
  85. $nice_tag_query = str_replace(' ', '+', $nice_tag_query); // get_query_var returns ' ' for AND, replace by +
  86. $tag_slugs = preg_split('%[,+]%', $nice_tag_query, -1, PREG_SPLIT_NO_EMPTY); // create array of tag slugs
  87. $tag_ops = preg_split('%[^,+]*%', $nice_tag_query, -1, PREG_SPLIT_NO_EMPTY); // create array of operators
  88. $tag_ops_counter = 0;
  89. $nice_tag_query = '';
  90. foreach ($tag_slugs as $tag_slug) {
  91. $tag = get_term_by('slug', $tag_slug ,'post_tag');
  92. // prettify tag operator, if any
  93. if ( isset($tag_ops[$tag_ops_counter]) && $tag_ops[$tag_ops_counter] == ',') {
  94. $tag_ops[$tag_ops_counter] = ', ';
  95. } elseif ( isset($tag_ops[$tag_ops_counter]) && $tag_ops[$tag_ops_counter] == '+') {
  96. $tag_ops[$tag_ops_counter] = ' + ';
  97. } else {
  98. $tag_ops[$tag_ops_counter] = '';
  99. }
  100. // concatenate display name and prettified operators
  101. $nice_tag_query = $nice_tag_query.$tag->name.$tag_ops[$tag_ops_counter];
  102. $tag_ops_counter += 1;
  103. }
  104. return $nice_tag_query;
  105. }
  106. /**
  107. * SEO-Friendly META description, based on Thematic Framework.
  108. */
  109. function arras_document_description() {
  110. if ( class_exists('All_in_One_SEO_Pack') || class_exists('Platinum_SEO_Pack') ) return false;
  111. if ( is_single() || is_page() ) {
  112. if ( have_posts() ) {
  113. while( have_posts() ) {
  114. the_post();
  115. echo '<meta name="description" content="' . get_the_excerpt() . '" />';
  116. }
  117. }
  118. } else {
  119. echo '<meta name="description" content="' . get_bloginfo('description') . '" />';
  120. }
  121. }
  122. /**
  123. * Generates semantic classes for BODY element.
  124. * Sandbox's version was removed from 1.4 onwards.
  125. */
  126. function arras_body_class() {
  127. if ( function_exists('body_class') ) {
  128. $body_class = array('layout-' . arras_get_option('layout'), 'no-js');
  129. if ( !defined('ARRAS_INHERIT_STYLES') || ARRAS_INHERIT_STYLES == true ) {
  130. $body_class[] = 'style-' . arras_get_option('style');
  131. }
  132. return body_class( apply_filters('arras_body_class', $body_class) );
  133. }
  134. }
  135. function arras_render_posts($args = null, $display_type = 'default', $taxonomy = 'category') {
  136. global $post, $wp_query, $arras_tapestries;
  137. if (!$args) {
  138. $query = $wp_query;
  139. } else {
  140. $query = new WP_Query($args);
  141. }
  142. if ($query->have_posts()) {
  143. arras_get_tapestry_callback($display_type, $query, $taxonomy);
  144. }
  145. wp_reset_query();
  146. }
  147. function arras_list_trackbacks($comment, $args, $depth) {
  148. $GLOBALS['comment'] = $comment;
  149. ?>
  150. <li <?php comment_class(); ?> id="li-trackback-<?php comment_ID() ?>">
  151. <div id="trackback-<?php comment_ID(); ?>">
  152. <?php echo get_comment_author_link() ?>
  153. </div>
  154. <?php
  155. }
  156. function arras_list_comments($comment, $args, $depth) {
  157. $GLOBALS['comment'] = $comment;
  158. ?>
  159. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  160. <div class="comment-node" id="comment-<?php comment_ID(); ?>">
  161. <div class="comment-controls">
  162. <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  163. </div>
  164. <div class="comment-author vcard">
  165. <?php echo get_avatar($comment, $size = 32) ?>
  166. <cite class="fn"><?php echo get_comment_author_link() ?></cite>
  167. </div>
  168. <?php if ( $comment->comment_approved == '0' ) : ?>
  169. <span class="comment-moderation"><?php _e('Your comment is awaiting moderation.', 'arras') ?></span>
  170. <?php endif; ?>
  171. <div class="comment-meta commentmetadata">
  172. <?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>' ); ?>
  173. </div>
  174. <div class="comment-content"><?php comment_text() ?></div>
  175. </div>
  176. <?php
  177. }
  178. function arras_post_class() {
  179. return post_class( apply_filters('arras_post_class', 'clearfix') );
  180. }
  181. function arras_single_post_class() {
  182. return post_class( apply_filters('arras_single_post_class', array('clearfix', 'single-post')) );
  183. }
  184. function arras_parse_single_custom_fields() {
  185. if (arras_get_option('single_custom_fields') == '') return false;
  186. $arr = explode( ',', arras_get_option('single_custom_fields') );
  187. $final = array();
  188. if ( !is_array($arr) ) return false;
  189. foreach ( $arr as $val ) {
  190. $field_arr = explode(':', $val);
  191. $final[ $field_arr[1] ] = $field_arr[0];
  192. }
  193. return $final;
  194. }
  195. function arras_excerpt_more($excerpt) {
  196. return str_replace(' [...]', '...', $excerpt);
  197. }
  198. add_filter('excerpt_more', 'arras_excerpt_more');
  199. function arras_excerpt_length($length) {
  200. if (!arras_get_option('excerpt_limit')) $limit = 30;
  201. else $limit = arras_get_option('excerpt_limit');
  202. return $limit;
  203. }
  204. add_filter('excerpt_length', 'arras_excerpt_length');
  205. function arras_parse_query($list, $count, $exclude = null, $post_type = '', $taxonomy = '') {
  206. $query = array();
  207. if ($post_type == '') $post_type = 'post';
  208. if ($taxonomy == '') $taxonomy = 'category';
  209. if ($list != false) {
  210. if ((array)$list !== $list) {
  211. $list = array($list);
  212. }
  213. if ( in_array('-5', $list) ) {
  214. $stickies = get_option('sticky_posts');
  215. rsort($stickies);
  216. if (count($stickies) > 0) {
  217. $query['post__in'] = $stickies;
  218. } else {
  219. // if no sticky posts are available, return empty value
  220. return false;
  221. }
  222. $key = array_search('-5', $list);
  223. unset($list[$key]);
  224. }
  225. switch($taxonomy) {
  226. case 'category':
  227. if ( ($zero_cat = array_search('0', $list)) === true )
  228. unset($list[$zero_cat]);
  229. $query['category__in'] = $list;
  230. break;
  231. case 'post_tag':
  232. $query['tag__in'] = $list;
  233. break;
  234. default:
  235. $list = implode($list, ',');
  236. $query[$taxonomy] = $list;
  237. }
  238. }
  239. $query['post_type'] = $post_type;
  240. $query['posts_per_page'] = $count;
  241. if (is_home() && arras_get_option('hide_duplicates')) {
  242. $query['post__not_in'] = $exclude;
  243. }
  244. //print_r($query);
  245. return $query;
  246. }
  247. function arras_social_nav() {
  248. $feed = arras_get_option('feed_url');
  249. $comments_feed = arras_get_option('comments_feed_url');
  250. ?>
  251. <ul class="quick-nav clearfix">
  252. <?php if ($feed == '') : ?>
  253. <li><a id="rss" title="<?php printf( __( '%s RSS Feed', 'arras' ), esc_html( get_bloginfo('name'), 1 ) ) ?>" href="<?php bloginfo('rss2_url'); ?>"><?php _e('RSS Feed', 'arras') ?></a></li>
  254. <?php else : ?>
  255. <li><a id="rss" title="<?php printf( __( '%s RSS Feed', 'arras' ), esc_html( get_bloginfo('name'), 1 ) ) ?>" href="<?php echo $feed; ?>"><?php _e('RSS Feed', 'arras') ?></a></li>
  256. <?php endif; ?>
  257. <?php $twitter_username = arras_get_option('twitter_username'); ?>
  258. <?php if ($twitter_username != '') : ?>
  259. <li><a id="twitter" title="<?php printf( __( '%s Twitter', 'arras' ), esc_html( get_bloginfo('name'), 1 ) ) ?>" href="http://www.twitter.com/<?php echo $twitter_username ?>/" target="_blank"><?php _e('Twitter', 'arras') ?></a></li>
  260. <?php endif ?>
  261. <?php $facebook_profile = arras_get_option('facebook_profile'); ?>
  262. <?php if ($facebook_profile != '') : ?>
  263. <li><a id="facebook" title="<?php printf( __( '%s Facebook', 'arras' ), esc_html( get_bloginfo('name'), 1 ) ) ?>" href="<?php echo $facebook_profile ?>" target="_blank"><?php _e('Facebook', 'arras') ?></a></li>
  264. <?php endif ?>
  265. <?php do_action('arras_quick_nav'); // hook to include additional social icons, etc. ?>
  266. </ul>
  267. <?php
  268. }
  269. function arras_add_searchbar() {
  270. ?><div id="searchbar"><?php get_search_form() ?></div><?php
  271. }
  272. function arras_blacklist_duplicates() {
  273. global $post, $post_blacklist;
  274. if (is_home() && arras_get_option('hide_duplicates')) {
  275. $post_blacklist[] = $post->ID;
  276. }
  277. }
  278. function arras_constrain_footer_sidebars() {
  279. $footer_sidebars = arras_get_option('footer_sidebars');
  280. if ($footer_sidebars == '') $footer_sidebars = 1;
  281. $width = ceil(920 / $footer_sidebars);
  282. ?>
  283. .footer-sidebar { width: <?php echo $width ?>px; }
  284. <?php
  285. }
  286. function arras_nav_fallback_cb() {
  287. echo '<ul class="sf-menu menu clearfix">';
  288. wp_list_categories('hierarchical=1&orderby=id&hide_empty=1&title_li=');
  289. echo '</ul>';
  290. }
  291. /* End of file template.php */
  292. /* Location: ./library/template.php */