PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/library/template.php

https://github.com/MKxDev/arras-theme
PHP | 507 lines | 384 code | 81 blank | 42 comment | 81 complexity | 5b7da9edcf5fe0db5c63b307a9da4c65 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. jQuery(document).ready( function($) {
  77. $('.sf-menu').superfish({autoArrows: true, speed: 'fast', dropShadows: 'true'});
  78. <?php if ( is_single() ) : ?>
  79. $( '#commentform' ).validate();
  80. <?php endif ?>
  81. <?php do_action( 'arras_custom_js-header' ) ?>
  82. } );
  83. </script>
  84. <?php
  85. }
  86. function arras_add_footer_js() {
  87. ?>
  88. <script type="text/javascript">
  89. jQuery(document).ready( function($) {
  90. $('.sf-menu-wrp').menuExpand();
  91. <?php do_action( 'arras_custom_js-footer' ) ?>
  92. } );
  93. </script>
  94. <?php
  95. }
  96. /**
  97. * Based on Thematic's thematic_tag_query()
  98. */
  99. function arras_tag_query() {
  100. $nice_tag_query = get_query_var('tag'); // tags in current query
  101. $nice_tag_query = str_replace(' ', '+', $nice_tag_query); // get_query_var returns ' ' for AND, replace by +
  102. $tag_slugs = preg_split('%[,+]%', $nice_tag_query, -1, PREG_SPLIT_NO_EMPTY); // create array of tag slugs
  103. $tag_ops = preg_split('%[^,+]*%', $nice_tag_query, -1, PREG_SPLIT_NO_EMPTY); // create array of operators
  104. $tag_ops_counter = 0;
  105. $nice_tag_query = '';
  106. foreach ($tag_slugs as $tag_slug) {
  107. $tag = get_term_by('slug', $tag_slug ,'post_tag');
  108. // prettify tag operator, if any
  109. if ( isset($tag_ops[$tag_ops_counter]) && $tag_ops[$tag_ops_counter] == ',') {
  110. $tag_ops[$tag_ops_counter] = ', ';
  111. } elseif ( isset($tag_ops[$tag_ops_counter]) && $tag_ops[$tag_ops_counter] == '+') {
  112. $tag_ops[$tag_ops_counter] = ' + ';
  113. } else {
  114. $tag_ops[$tag_ops_counter] = '';
  115. }
  116. // concatenate display name and prettified operators
  117. $nice_tag_query = $nice_tag_query.$tag->name.$tag_ops[$tag_ops_counter];
  118. $tag_ops_counter += 1;
  119. }
  120. return $nice_tag_query;
  121. }
  122. /**
  123. * SEO-Friendly META description, based on Thematic Framework.
  124. */
  125. function arras_document_description() {
  126. if ( class_exists('All_in_One_SEO_Pack') || class_exists('Platinum_SEO_Pack') ) return false;
  127. if ( is_single() || is_page() ) {
  128. if ( have_posts() ) {
  129. while( have_posts() ) {
  130. the_post();
  131. echo '<meta name="description" content="' . get_the_excerpt() . '" />';
  132. }
  133. }
  134. } else {
  135. echo '<meta name="description" content="' . get_bloginfo('description') . '" />';
  136. }
  137. }
  138. /**
  139. * Generates semantic classes for BODY element.
  140. * Sandbox's version was removed from 1.4 onwards.
  141. */
  142. function arras_body_class() {
  143. if ( function_exists('body_class') ) {
  144. $body_class = array('layout-' . arras_get_option('layout'), 'no-js');
  145. if ( !defined('ARRAS_INHERIT_STYLES') || ARRAS_INHERIT_STYLES == true ) {
  146. $body_class[] = 'style-' . arras_get_option('style');
  147. }
  148. return body_class( apply_filters('arras_body_class', $body_class) );
  149. }
  150. }
  151. /**
  152. * Use arras_featured_loop() for front page loops.
  153. */
  154. function arras_render_posts($args = null, $display_type = 'default', $taxonomy = 'category') {
  155. global $post, $wp_query, $arras_tapestries;
  156. if (!$args) {
  157. $query = $wp_query;
  158. } else {
  159. $query = new WP_Query($args);
  160. }
  161. if ($query->have_posts()) {
  162. arras_get_tapestry_callback($display_type, $query, $taxonomy);
  163. }
  164. wp_reset_query();
  165. }
  166. function arras_featured_loop( $display_type = 'default', $arras_args = array(), $query_posts = false ) {
  167. global $wp_query;
  168. if ($query_posts) {
  169. $q = $wp_query;
  170. } else {
  171. $arras_args = arras_prep_query($arras_args);
  172. $q = new WP_Query($arras_args);
  173. }
  174. if ($q->have_posts()) {
  175. if ( !isset($arras_args['taxonomy']) ) $arras_args['taxonomy'] = 'category';
  176. arras_get_tapestry_callback($display_type, $q, $arras_args['taxonomy']);
  177. }
  178. wp_reset_query();
  179. }
  180. /**
  181. * This function replaces arras_parse_query() starting from 1.5.1.
  182. */
  183. function arras_prep_query( $args = array() ) {
  184. $_defaults = array(
  185. 'list' => array(),
  186. 'taxonomy' => 'category',
  187. 'query' => array(
  188. 'exclude' => array(),
  189. 'post_type' => 'post',
  190. 'posts_per_page' => 10,
  191. 'orderby' => 'date',
  192. 'order' => 'DESC'
  193. )
  194. );
  195. $args['query'] = wp_parse_args($args['query'], $_defaults['query']);
  196. $args = wp_parse_args($args, $_defaults);
  197. if ( !is_array($args['list']) ) {
  198. $args['list'] = array($args['list']);
  199. }
  200. // sticky posts
  201. if ( in_array('-5', $args['list']) ) {
  202. $stickies = get_option('sticky_posts');
  203. rsort($stickies);
  204. if ( count($stickies) > 0 ) {
  205. $args['query']['post__in'] = $stickies;
  206. } else {
  207. // if no sticky posts are available, return empty value
  208. return false;
  209. }
  210. $key = array_search('-5', $args['list']);
  211. unset($args['list'][$key]);
  212. }
  213. // taxonomies
  214. switch( $args['taxonomy'] ) {
  215. case 'category':
  216. $zero_key = array_search('0', $args['list']);
  217. if (is_numeric($zero_key)) unset($args['list'][$zero_key]);
  218. $args['query']['category__in'] = $args['list'];
  219. break;
  220. case 'post_tag':
  221. $args['query']['tag__in'] = $args['list'];
  222. break;
  223. default:
  224. $taxonomy_obj = get_taxonomy($args['taxonomy']);
  225. $args['list'] = implode($args['list'], ',');
  226. $args['query'][$taxonomy_obj->query_var] = $args['list'];
  227. }
  228. if (is_home() && arras_get_option('hide_duplicates')) {
  229. $args['query']['post__not_in'] = array_unique($args['query']['exclude']);
  230. }
  231. if ($args['query']['post_type'] == 'attachment') {
  232. $args['query']['post_status'] = 'inherit';
  233. }
  234. //arras_debug($args['query']);
  235. return $args['query'];
  236. }
  237. function arras_list_trackbacks($comment, $args, $depth) {
  238. $GLOBALS['comment'] = $comment;
  239. ?>
  240. <li <?php comment_class(); ?> id="li-trackback-<?php comment_ID() ?>">
  241. <div id="trackback-<?php comment_ID(); ?>">
  242. <?php echo get_comment_author_link() ?>
  243. </div>
  244. <?php
  245. }
  246. function arras_list_comments($comment, $args, $depth) {
  247. $GLOBALS['comment'] = $comment;
  248. ?>
  249. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  250. <div class="comment-node" id="comment-<?php comment_ID(); ?>">
  251. <div class="comment-controls">
  252. <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  253. </div>
  254. <div class="comment-author vcard">
  255. <?php echo get_avatar($comment, $size = 32) ?>
  256. <cite class="fn"><?php echo get_comment_author_link() ?></cite>
  257. </div>
  258. <?php if ( $comment->comment_approved == '0' ) : ?>
  259. <span class="comment-moderation"><?php _e('Your comment is awaiting moderation.', 'arras') ?></span>
  260. <?php endif; ?>
  261. <div class="comment-meta commentmetadata">
  262. <?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>' ); ?>
  263. </div>
  264. <div class="comment-content"><?php comment_text() ?></div>
  265. </div>
  266. <?php
  267. }
  268. function arras_post_class() {
  269. return post_class( apply_filters('arras_post_class', array( 'entry', 'clearfix' ) ) );
  270. }
  271. function arras_single_post_class() {
  272. return post_class( apply_filters('arras_single_post_class', array('clearfix', 'single-post')) );
  273. }
  274. function arras_parse_single_custom_fields() {
  275. if (arras_get_option('single_custom_fields') == '') return false;
  276. $arr = explode( ',', arras_get_option('single_custom_fields') );
  277. $final = array();
  278. if ( !is_array($arr) ) return false;
  279. foreach ( $arr as $val ) {
  280. $field_arr = explode(':', $val);
  281. $final[ $field_arr[1] ] = $field_arr[0];
  282. }
  283. return $final;
  284. }
  285. function arras_excerpt_more($excerpt) {
  286. return str_replace(' [...]', '...', $excerpt);
  287. }
  288. add_filter('excerpt_more', 'arras_excerpt_more');
  289. function arras_excerpt_length($length) {
  290. if (!arras_get_option('excerpt_limit')) $limit = 30;
  291. else $limit = arras_get_option('excerpt_limit');
  292. return $limit;
  293. }
  294. add_filter('excerpt_length', 'arras_excerpt_length');
  295. /**
  296. * @todo
  297. * Function adapted from http://graveyard.maniacalrage.net/etc/relative/.
  298. * @since 1.6
  299. */
  300. function arras_posted_on( $echo = 1 ) {
  301. $result = '';
  302. if ( !arras_get_option( 'relative_postdates' ) ) {
  303. $result = sprintf( __( 'on %s', 'arras' ), get_the_time( get_option( 'date_format' ) ) );
  304. } else {
  305. $diff = current_time( 'timestamp' ) - get_the_time( 'U' );
  306. $months = floor( $diff / 2592000 );
  307. $diff -= $months * 2419200;
  308. $weeks = floor( $diff / 604800 );
  309. $diff -= $weeks * 604800;
  310. $days = floor( $diff / 86400 );
  311. $diff -= $days * 86400;
  312. $hours = floor( $diff / 3600 );
  313. $diff -= $hours * 3600;
  314. $minutes = floor( $diff / 60 );
  315. $diff -= $minutes * 60;
  316. if ( $months > 0 || $months < 0 ) {
  317. // over a month old, just show date
  318. $result = sprintf( __( 'on %s', 'arras' ), get_the_time( get_option( 'date_format' ) ) );
  319. } else {
  320. if ( $weeks > 0 ) {
  321. // weeks
  322. if ( $weeks > 1 )
  323. $result = sprintf( __( '%s weeks ago', 'arras' ), number_format_i18n( $weeks ) );
  324. else
  325. $result = __( '1 week ago', 'arras' );
  326. } elseif ( $days > 0 ) {
  327. // days
  328. if ( $days > 1 )
  329. $result = sprintf( __( '%s days ago', 'arras' ), number_format_i18n( $days ) );
  330. else
  331. $result = __( '1 day ago', 'arras' );
  332. } elseif ( $hours > 0 ) {
  333. // hours
  334. if ( $hours > 1 )
  335. $result = sprintf( __( '%s hours ago', 'arras' ), number_format_i18n( $hours ) );
  336. else
  337. $result = __( '1 hour ago', 'arras' );
  338. } elseif ( $minutes > 0 ) {
  339. // minutes
  340. if ( $minutes > 1 )
  341. $result = sprintf( __( '%s minutes ago', 'arras' ), number_format_i18n( $minutes ) );
  342. else
  343. $result = __( '1 minute ago', 'arras' );
  344. } else {
  345. // seconds
  346. $result = __( 'less than a minute ago', 'arras' );
  347. }
  348. }
  349. }
  350. if ( $echo ) echo $result;
  351. return $result;
  352. }
  353. function arras_social_nav() {
  354. ?>
  355. <ul class="quick-nav clearfix">
  356. <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>
  357. <?php $facebook_profile = arras_get_option('facebook_profile'); ?>
  358. <?php if ($facebook_profile != '') : ?>
  359. <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>
  360. <?php endif ?>
  361. <?php $flickr_profile = arras_get_option('flickr_profile'); ?>
  362. <?php if ($flickr_profile != '') : ?>
  363. <li><a id="flickr" title="<?php printf( __( '%s Flickr', 'arras' ), esc_html( get_bloginfo('name'), 1 ) ) ?>" href="<?php echo $flickr_profile ?>" target="_blank"><?php _e('Flickr', 'arras') ?></a></li>
  364. <?php endif ?>
  365. <?php $gplus_profile = arras_get_option('gplus_profile'); ?>
  366. <?php if ($gplus_profile != '') : ?>
  367. <li><a id="gplus" title="<?php printf( __( '%s Google+', 'arras' ), esc_html( get_bloginfo('name'), 1 ) ) ?>" href="<?php echo $gplus_profile ?>" target="_blank"><?php _e('Google+', 'arras') ?></a></li>
  368. <?php endif ?>
  369. <?php $twitter_username = arras_get_option('twitter_username'); ?>
  370. <?php if ($twitter_username != '') : ?>
  371. <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>
  372. <?php endif ?>
  373. <?php $youtube_profile = arras_get_option('youtube_profile'); ?>
  374. <?php if ($youtube_profile != '') : ?>
  375. <li><a id="youtube" title="<?php printf( __( '%s YouTube', 'arras' ), esc_html( get_bloginfo('name'), 1 ) ) ?>" href="<?php echo $youtube_profile ?>" target="_blank"><?php _e('YouTube', 'arras') ?></a></li>
  376. <?php endif ?>
  377. <?php do_action('arras_quick_nav'); // hook to include additional social icons, etc. ?>
  378. </ul>
  379. <?php
  380. }
  381. function arras_add_searchbar() {
  382. ?><div id="searchbar"><?php get_search_form() ?></div><?php
  383. }
  384. function arras_blacklist_duplicates() {
  385. global $post, $post_blacklist;
  386. if (is_home() && arras_get_option('hide_duplicates')) {
  387. $post_blacklist[] = $post->ID;
  388. }
  389. }
  390. function arras_constrain_footer_sidebars() {
  391. $footer_sidebars = arras_get_option('footer_sidebars');
  392. if ($footer_sidebars == '') $footer_sidebars = 1;
  393. $width = ceil(920 / $footer_sidebars);
  394. ?>
  395. .footer-sidebar { width: <?php echo $width ?>px; }
  396. <?php
  397. }
  398. function arras_nav_fallback_cb() {
  399. echo '<ul class="sf-menu menu clearfix">';
  400. wp_list_categories('hierarchical=1&orderby=id&hide_empty=1&title_li=');
  401. echo '</ul>';
  402. }
  403. function arras_debug($exp) {
  404. //if (current_user_can('manage_options')) {
  405. echo '<pre><code style="max-height: 200px; overflow: scroll">' . htmlentities( print_r($exp, true) ) . '</code></pre>';
  406. //}
  407. }
  408. function arras_add_facebook_share_meta() {
  409. global $post;
  410. if ( is_single() ) {
  411. if ( has_post_thumbnail( $post->ID ) )
  412. $thumb_id = get_post_thumbnail_id( $post->ID );
  413. elseif ( arras_get_option( 'auto_thumbs' ) )
  414. $thumb_id = arras_get_first_post_image_id();
  415. if ( !$thumb_id ) return false;
  416. $image = wp_get_attachment_image_src( $thumb_id );
  417. $src = $image[0];
  418. ?>
  419. <meta property="og:title" content="<?php echo get_the_title( $post->ID ) ?>" />
  420. <meta property="og:description" content="<?php echo get_the_excerpt() ?>" />
  421. <meta property="og:image" content="<?php echo $image[0] ?>" />
  422. <?php
  423. }
  424. }
  425. /* End of file template.php */
  426. /* Location: ./library/template.php */