Advertisement
Guest User

Untitled

a guest
Sep 11th, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. <?php
  2. class recentproshortcode {
  3.  
  4. var $build = 1;
  5.  
  6. var $db;
  7.  
  8. function __construct() {
  9.  
  10. global $wpdb;
  11.  
  12. $this->db =& $wpdb;
  13.  
  14. if($this->db->blogid == 1) {
  15. // Only add the feed for the main site
  16. add_action('init', array(&$this, 'initialise_recentproshortcode') );
  17. }
  18.  
  19. add_shortcode( 'globalproposts', array( &$this, 'display_pro_posts_shortcode') );
  20.  
  21. }
  22.  
  23. function recentproshortcode() {
  24. $this->__construct();
  25. }
  26.  
  27. function initialise_recentproshortcode() {
  28. // In case we need it in future :)
  29. }
  30.  
  31. function time_elapsed_string($datetime, $full = false) {
  32. $now = new DateTime;
  33. $ago = new DateTime($datetime);
  34. $diff = $now->diff($ago);
  35.  
  36. $diff->w = floor($diff->d / 7);
  37. $diff->d -= $diff->w * 7;
  38.  
  39. $string = array(
  40. 'y' => 'year',
  41. 'm' => 'month',
  42. 'w' => 'U',
  43. 'd' => 'D',
  44. 'h' => 'T',
  45. 'i' => 'M',
  46. 's' => 'S',
  47. );
  48. foreach ($string as $k => &$v) {
  49. if ($diff->$k) {
  50. $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? '' : '');
  51. } else {
  52. unset($string[$k]);
  53. }
  54. }
  55.  
  56. if (!$full) $string = array_slice($string, 0, 1);
  57. return $string ? implode(', ', $string) . '' : 'lige nu';
  58. }
  59.  
  60. function display_pro_posts($pro_level, $tmp_number,$tmp_title_characters = 0,$tmp_content_characters = 0,
  61. $tmp_title_content_divider = '<br />',$tmp_title_before,$tmp_title_after,$tmp_global_before,
  62. $tmp_global_after,$tmp_before,$tmp_after,$tmp_title_link = 'no',$tmp_show_avatars = 'yes',
  63. $tmp_avatar_size = 16, $posttype = 'post', $output = true) {
  64.  
  65. global $network_query, $network_post, $wpdb;
  66.  
  67. // http://premium.wpmudev.org/forums/topic/restricting-specific-page-templates-within-prosites#post-652329
  68.  
  69. $network_query = network_query_posts( array( 'post_type' => $posttype, 'posts_per_page' => $tmp_number ));
  70.  
  71. $html = '';
  72.  
  73. global $wpdb;
  74. $blog_id = $wpdb->blogid;
  75. $sql = "SELECT level FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = '$blog_id'";
  76. $level = $wpdb->get_var( $sql );
  77. if( $pro_level == 'all' ){
  78. $pro = $wpdb->get_results("SELECT * FROM {$wpdb->base_prefix}pro_sites");
  79. }else{
  80. $pro = $wpdb->get_results("SELECT * FROM {$wpdb->base_prefix}pro_sites WHERE level = {$pro_level}");
  81. }
  82.  
  83. $temp = array();
  84. foreach( $pro as $p ){
  85. array_push( $temp, $p->blog_ID );
  86. }
  87.  
  88. // if ( $level == 2 ) {
  89.  
  90. $html .= $tmp_global_before;
  91.  
  92. while( network_have_posts() ) {
  93.  
  94. network_the_post();
  95.  
  96. if( ! in_array( $network_post->BLOG_ID, $temp ) ) continue;
  97.  
  98. switch_to_blog( $network_post->BLOG_ID );
  99.  
  100. //Get network blog post featured image
  101. $n_post = network_get_post();
  102. // }
  103. $featured_image = get_the_post_thumbnail( $n_post->ID, 'misc-thumb-front' );
  104. //Network blog name
  105. $blogname = get_blog_option( $network_post->BLOG_ID, 'blogname' );
  106.  
  107. restore_current_blog();
  108. $html .= $tmp_before;
  109.  
  110. $html .= $tmp_title_before . '<a href="' . network_get_permalink() . '"target="_blank" class="crop">';
  111.  
  112. $the_title = network_get_the_title();
  113.  
  114. $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 class="net-post-date"><i class="fa fa-clock-o" style="color: black;"></i>&nbsp;&nbsp;'. $this->time_elapsed_string($n_post->post_date).'</div></div>';
  115.  
  116. $tile_img = '';
  117.  
  118. if(!empty($featured_image)) {
  119. $tile_img = $featured_image;
  120.  
  121. } else {
  122. $options = get_option( 'bpb_settings' );
  123. $tile_img = '<img src="' . plugins_url( '/images/wparm33w.png', dirname(__FILE__) ) . '" >';
  124. $tile_img = '<img src="' . get_option( $bpb_placehold_it , plugins_url( '/images/wparm33w.png', dirname(__FILE__) ) ). '" >';
  125. $tile_img = '<img src="' . $options['bpb_btn_6'] . '" >';
  126. }
  127.  
  128. if ( $tmp_title_characters > 0 ) {
  129. $html .= $tile_img;
  130.  
  131. $html .= $tmp_title_after;
  132. }
  133.  
  134. $html .= $tmp_after;
  135.  
  136. }
  137. $html .= $tmp_global_after;
  138. // }
  139.  
  140. if($output) {
  141. echo $html;
  142. } else {
  143. return $html;
  144. }
  145.  
  146. }
  147.  
  148. function display_pro_posts_shortcode($atts, $content = null, $code = "") {
  149.  
  150. $defaults = array( 'number' => 500,
  151. 'title_characters' => 35,
  152. 'content_characters' => 50,
  153. 'title_content_divider' => '<br />',
  154. 'title_before' => '<div>',
  155. 'title_after' => '</div>',
  156. 'global_before' => '<ul>',
  157. 'global_after' => '</ul>',
  158. 'before' => '<li class="crop-square">',
  159. 'after' => '</a></li>',
  160. 'title_link' => 'yes',
  161. 'show_avatars' => 'no',
  162. 'show_images' => 'no',
  163. 'avatar_size' => 16,
  164. 'posttype' => 'post',
  165. 'pro_level' => 'all'
  166. );
  167.  
  168. extract(shortcode_atts($defaults, $atts));
  169.  
  170. $html = '';
  171.  
  172. $html .= $this->display_pro_posts( $pro_level, $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);
  173.  
  174. return $html;
  175.  
  176. }
  177.  
  178. }
  179.  
  180. function display_pro_posts($pro_level, $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) {
  181. global $recentproshortcode;
  182.  
  183. $recentproshortcode->display_pro_posts( $pro_level, $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 );
  184. }
  185.  
  186. $recentproshortcode = new recentproshortcode();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement