plugins.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /*
  3. Bones Plugins & Extra Functionality
  4. Author: Eddie Machado
  5. URL: http://themble.com/bones/
  6. This file contains extra features not 100% ready to be included
  7. in the core. Feel free to edit anything here or even help us fix
  8. and optimize the code!
  9. IF YOU WANT TO SUBMIT A FIX OR CORRECTION, PLEASE CONTACT US HERE:
  10. http://themble.com/bones/dev
  11. IF YOU WANT TO DISABLE THIS FILE, REMOVE IT'S CALL IN THE FUNCTIONS.PHP FILE
  12. */
  13. /*
  14. Built in Page Navi w/out Plugin
  15. This feature is meant to add page navi functionality w/out
  16. using a plugin. It's currently in use but does contain a few
  17. bugs. Mainly it displays something even if there's only one page.
  18. THIS FEATURE IS IN DEVELOPMENT BUT FUNCTIONAL
  19. */
  20. // page navigation
  21. function page_navi($before = '', $after = '') {
  22. global $wpdb, $wp_query;
  23. $request = $wp_query->request;
  24. $posts_per_page = intval(get_query_var('posts_per_page'));
  25. $paged = intval(get_query_var('paged'));
  26. $numposts = $wp_query->found_posts;
  27. $max_page = $wp_query->max_num_pages;
  28. if ( $numposts <= $posts_per_page ) { return; }
  29. if(empty($paged) || $paged == 0) {
  30. $paged = 1;
  31. }
  32. $pages_to_show = 7;
  33. $pages_to_show_minus_1 = $pages_to_show-1;
  34. $half_page_start = floor($pages_to_show_minus_1/2);
  35. $half_page_end = ceil($pages_to_show_minus_1/2);
  36. $start_page = $paged - $half_page_start;
  37. if($start_page <= 0) {
  38. $start_page = 1;
  39. }
  40. $end_page = $paged + $half_page_end;
  41. if(($end_page - $start_page) != $pages_to_show_minus_1) {
  42. $end_page = $start_page + $pages_to_show_minus_1;
  43. }
  44. if($end_page > $max_page) {
  45. $start_page = $max_page - $pages_to_show_minus_1;
  46. $end_page = $max_page;
  47. }
  48. if($start_page <= 0) {
  49. $start_page = 1;
  50. }
  51. echo $before.'<div class="page-navigation"><ul class="bones_page_navi clear">'."";
  52. if ($start_page >= 2 && $pages_to_show < $max_page) {
  53. $first_page_text = "First";
  54. echo '<li class="bpn-first-page-link"><a href="'.get_pagenum_link().'" title="'.$first_page_text.'">'.$first_page_text.'</a></li>';
  55. }
  56. echo '<li class="bpn-prev-link">';
  57. previous_posts_link('<<');
  58. echo '</li>';
  59. for($i = $start_page; $i <= $end_page; $i++) {
  60. if($i == $paged) {
  61. echo '<li class="bpn-current">'.$i.'</li>';
  62. } else {
  63. echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
  64. }
  65. }
  66. echo '<li class="bpn-next-link">';
  67. next_posts_link('>>');
  68. echo '</li>';
  69. if ($end_page < $max_page) {
  70. $last_page_text = "Last";
  71. echo '<li class="bpn-last-page-link"><a href="'.get_pagenum_link($max_page).'" title="'.$last_page_text.'">'.$last_page_text.'</a></li>';
  72. }
  73. echo '</ul></div>'.$after."";
  74. }
  75. /*
  76. Facebook Connect Image Fix
  77. This was built of a post from Yoast that should
  78. fix the facebook issue when sharing something w/
  79. facebook where it selects a random photo from
  80. your site. This should use a photo from the actual post.
  81. */
  82. // facebook share correct image fix (thanks to yoast)
  83. function bones_facebook_connect() {
  84. if (is_singular()) {
  85. global $post;
  86. if ( current_theme_supports('post-thumbnails')
  87. && has_post_thumbnail( $post->ID ) ) {
  88. $thumbnail = wp_get_attachment_image_src(
  89. get_post_thumbnail_id( $post->ID ), 'thumbnail', false);
  90. echo '<meta property="og:image"
  91. content="'.$thumbnail[0].'" />';
  92. }
  93. echo '<meta property="og:title"
  94. content="'.get_the_title().'" />';
  95. if ( get_the_excerpt() != '' )
  96. echo '<meta property="og:description"
  97. content="'.strip_tags( get_the_excerpt() ).'" />';
  98. }
  99. }
  100. // add this in the header
  101. add_action('wp_head', 'bones_facebook_connect');
  102. /*
  103. HTML5 Video using Shortcode within WP
  104. This feature is meant to make HTML5 Video easy to use.
  105. to post a video, you simply have to use the shortcode:
  106. [video src="filename" width="640px" height="340px" poster="imagename.jpg"]
  107. Don't add a file extention as this will be added depending on what
  108. browser you are using. Remember you need two file formats for it to
  109. work consistently across all browsers:
  110. filename.mp4 (used for Safari, Chrome, Flash Fallback)
  111. filename.ogv (used for Firefox)
  112. Be sure to make sure your directories are correct.
  113. Defaults are in your uploads folder in wp-contents,
  114. but you can change it if you use a CDN or another
  115. hosting service.
  116. This code was built upon a plugin created by Rob McGuire (http://robmcguire.net/)
  117. */
  118. // html5 video & fallback (still expirimental)
  119. function bones_html5( $atts, $content = null ) {
  120. extract( shortcode_atts( array(
  121. 'src' => '', /* this one is handled using the code below */
  122. 'options' => 'controls autobuffer', /* adds controls & autobuffer automatically */
  123. 'width' => '', /* depends on the width you enter */
  124. 'height' => '', /* depends on the width you enter */
  125. 'poster' => '', /* the background image (you need to use poster=) */
  126. 'format' => 'auto', /* auto adds the file format */
  127. 'class' => '', /* this adds a class to the video for further customization */
  128. ), $atts ) );
  129. $fallbacktype='.mp4'; /* the file extension of the file that will play in the flash player */
  130. $fallbackpath = get_template_directory_uri(). '/library/js/flowplayer/flowplayer-3.2.5.swf'; /* location of the fallback player */
  131. $videostorage = WP_CONTENT_URL .'/uploads/'; /* this can be changed to a cdn if you like */
  132. $fallbackvid = '<object id="flowplayer" width="'.$width.'" height="'.$height.'" data="'.$fallbackpath.'"
  133. type="application/x-shockwave-flash"><param name="movie" value="'.$fallbackpath.'" /><param name="allowfullscreen" value="true" /><param name="flashvars" value=\'config={"clip": {"url": "'.$videostorage.''.$src.''.$fallbacktype.'", "autoPlay":false, "autoBuffering":true}}\' /></object>';
  134. $output .= '<video class="'.$class.'" width="'.$width.'" height="'.$height.'" poster="'.$videostorage.''.$poster.'" '.$options.'>' . "\n"; /* opening the video & inputting variables */
  135. $output .= '<source src="'.$videostorage.''.$src.'.mp4" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\' />' . "\n"; /* this is the safari version */
  136. $output .= '<source src="'.$videostorage.''.$src.'.ogv" type=\'video/ogg; codecs="theora, vorbis"\' />' . "\n"; /* this is the firefox version */
  137. $output .= $fallbackvid.'</video>'; /* this is the fallback & closing tag */
  138. return $output;
  139. }
  140. // adding the shortcode to wordpress
  141. add_shortcode('video', 'bones_html5'); /* creates the video using wordpress shortcodes */
  142. ?>