Advertisement
Guest User

Untitled

a guest
Feb 25th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class recentproshortcode {
  4.  
  5. var $build = 1;
  6.  
  7. var $db;
  8.  
  9. function __construct() {
  10.  
  11. global $wpdb;
  12.  
  13. $this->db =& $wpdb;
  14.  
  15. if($this->db->blogid == 1) {
  16. // Only add the feed for the main site
  17. add_action('init', array(&$this, 'initialise_recentproshortcode') );
  18. }
  19.  
  20. add_shortcode( 'globalproposts', array( &$this, 'display_pro_posts_shortcode') );
  21.  
  22. }
  23.  
  24. function recentproshortcode() {
  25. $this->__construct();
  26. }
  27.  
  28. function initialise_recentproshortcode() {
  29. // In case we need it in future :)
  30. }
  31.  
  32. function display_pro_posts($tmp_number,$tmp_title_characters = 0,$tmp_content_characters = 0,
  33. $tmp_title_content_divider = '<br />',$tmp_title_before,$tmp_title_after,$tmp_global_before,
  34. $tmp_global_after,$tmp_before,$tmp_after,$tmp_title_link = 'no',$tmp_show_avatars = 'yes',
  35. $tmp_avatar_size = 16, $posttype = 'post', $output = true) {
  36.  
  37. global $network_query, $network_post, $wpdb;
  38.  
  39. // http://premium.wpmudev.org/forums/topic/restricting-specific-page-templates-within-prosites#post-652329
  40.  
  41. $network_query = network_query_posts( array( 'post_type' => $posttype, 'posts_per_page' => $tmp_number ));
  42.  
  43. $html = '';
  44.  
  45. global $wpdb;
  46. $blog_id = $wpdb->blogid;
  47. $sql = "SELECT level FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = '$blog_id'";
  48. $level = $wpdb->get_var( $sql );
  49. $pro = $wpdb->get_results("SELECT * FROM {$wpdb->base_prefix}pro_sites WHERE level = 1");
  50. $temp = array();
  51. foreach( $pro as $p ){
  52. array_push( $temp, $p->blog_ID );
  53. }
  54.  
  55.  
  56. // if ( $level == 2 ) {
  57.  
  58. $html .= $tmp_global_before;
  59.  
  60. while( network_have_posts() ) {
  61.  
  62. network_the_post();
  63.  
  64. if( ! in_array( $network_post->BLOG_ID, $temp ) ) continue;
  65.  
  66. switch_to_blog( $network_post->BLOG_ID );
  67.  
  68. //Get network blog post featured image
  69. $n_post = network_get_post();
  70. // }
  71. $featured_image = get_the_post_thumbnail( $n_post->ID, 'large' );
  72. //Network blog name
  73. $blogname = get_blog_option( $network_post->BLOG_ID, 'blogname' );
  74.  
  75. restore_current_blog();
  76. $html .= $tmp_before;
  77.  
  78. $html .= $tmp_title_before . '<a href="' . network_get_permalink() . '" class="crop">';
  79.  
  80. $the_title = network_get_the_title();
  81.  
  82. $html .= '<div id="npost-meta"><div class="blog-name">' . $blogname . '</div> <hr> <div id="net-post-title">' . substr($the_title,0,$tmp_title_characters) . '</div></div>';
  83.  
  84.  
  85. $tile_img = '';
  86.  
  87. if(!empty($featured_image)) {
  88. $tile_img = $featured_image;
  89.  
  90. } else {
  91. $options = get_option( 'bpb_settings' );
  92. // $tile_img = '<img src="' . plugins_url( '/images/wparm33w.png', dirname(__FILE__) ) . '" >';
  93. // $tile_img = '<img src="' . get_option( $bpb_placehold_it , plugins_url( '/images/wparm33w.png', dirname(__FILE__) ) ). '" >';
  94. $tile_img = '<img src="' . $options['bpb_btn_6'] . '" >';
  95. }
  96.  
  97. if ( $tmp_title_characters > 0 ) {
  98. $html .= $tile_img;
  99.  
  100.  
  101.  
  102. $html .= $tmp_title_after;
  103. }
  104.  
  105. $html .= $tmp_after;
  106.  
  107. }
  108. $html .= $tmp_global_after;
  109. // }
  110.  
  111. if($output) {
  112. echo $html;
  113. } else {
  114. return $html;
  115. }
  116.  
  117. }
  118.  
  119. function display_pro_posts_shortcode($atts, $content = null, $code = "") {
  120.  
  121. $defaults = array( 'number' => 28,
  122. 'title_characters' => 35,
  123. 'content_characters' => 50,
  124. 'title_content_divider' => '<br />',
  125. 'title_before' => '<div>',
  126. 'title_after' => '</div>',
  127. 'global_before' => '<ul>',
  128. 'global_after' => '</ul>',
  129. 'before' => '<li class="crop-square">',
  130. 'after' => '</a></li>',
  131. 'title_link' => 'yes',
  132. 'show_avatars' => 'no',
  133. 'show_images' => 'yes',
  134. 'avatar_size' => 16,
  135. 'posttype' => 'post'
  136. );
  137.  
  138. extract(shortcode_atts($defaults, $atts));
  139.  
  140. $html = '';
  141.  
  142. $html .= $this->display_pro_posts( $number, $title_characters, $content_characters, $title_content_divider, $title_before, $title_after, $global_before, $global_after, $before, $after, $title_link, $show_avatars, $avatar_size, $posttype, false);
  143.  
  144. return $html;
  145.  
  146. }
  147.  
  148. }
  149.  
  150. function display_pro_posts($tmp_number,$tmp_title_characters = 0,$tmp_content_characters = 0,$tmp_title_content_divider = '<br />',$tmp_title_before,$tmp_title_after,$tmp_global_before,$tmp_global_after,$tmp_before,$tmp_after,$tmp_title_link = 'no',$tmp_show_avatars = 'yes', $tmp_avatar_size = 16, $posttype = 'post', $output = true) {
  151. global $recentproshortcode;
  152.  
  153. $recentproshortcode->display_pro_posts( $tmp_number, $tmp_title_characters, $tmp_content_characters, $tmp_title_content_divider, $tmp_title_before, $tmp_title_after, $tmp_global_before, $tmp_global_after, $tmp_before, $tmp_after, $tmp_title_link, $tmp_show_avatars, $tmp_avatar_size, $posttype, $output );
  154. }
  155.  
  156. $recentproshortcode = new recentproshortcode();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement