Advertisement
Guest User

Untitled

a guest
Apr 30th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.31 KB | None | 0 0
  1. <?php
  2. function live_stream_widget_display_products($item_output = '', $item, $instance) {
  3.     if (is_multisite()) {
  4.         if ((isset($item->blog_id)) && (intval($item->blog_id))) {
  5.             $blog = get_blog_details($item->blog_id);
  6.         }
  7.     } else {
  8.         if (!isset($blog)) {
  9.             $blog = new stdClass;
  10.             $blog->blogname     = get_option( 'blogname' );
  11.             $blog->siteurl      = get_option( 'siteurl' );                                                 
  12.         }
  13.     }
  14.     //echo "blog<pre>"; print_r($blog); echo "</pre>";
  15.    
  16.     if ((isset($instance['link_target'])) && ($instance['link_target'] == "on")) {
  17.         $link_target = ' target="_blank" ';
  18.     } else {
  19.         $link_target = '';
  20.     }
  21.    
  22.     $user_data = array();
  23.  
  24.     if (intval($item->post_author_id) ) {
  25.         $userdata = get_userdata( intval($item->post_author_id) );
  26.         if ($userdata) {
  27.             $user_data['ID']            = $userdata->ID;
  28.             $user_data['user_email']    = $userdata->user_email;
  29.             $user_data['display_name']  = $userdata->display_name;         
  30.         }          
  31.     }
  32.  
  33.     if (!isset($user_data['ID']))
  34.         $user_data['ID']            = 0;
  35.  
  36.     if (!isset($user_data['user_email'])) {
  37.         if ((isset($item->post_author_email)) && (strlen($item->post_author_email))) {
  38.             $user_data['user_email']    = $item->post_author_email;
  39.         } else {
  40.             $user_data['user_email']    = '';
  41.         }          
  42.     }
  43.  
  44.     if (!isset($user_data['display_name'])) {
  45.        
  46.         if ((isset($item->post_author_name)) && (strlen($item->post_author_name))) {
  47.             $user_data['display_name']  = $item->post_author_name;
  48.         } else {
  49.             $user_data['display_name']  = '';
  50.         }
  51.     }
  52.    
  53.     /* Build an anchor wrapper for the author which is used in multiple places */
  54.     if ((isset($blog->siteurl)) && (intval($item->post_author_id) )) {
  55.         $author_anchor_begin    = '<a '. $link_target .' class="live-stream-item-author" title="'. $user_data['display_name'] .'" href="'. $blog->siteurl .'?author='
  56.             . $item->post_author_id .'">';
  57.         $author_anchor_end      = '</a>';
  58.        
  59.     } else {
  60.         if ($item->post_type == "product") {
  61.             $author_anchor_begin    = '<a '. $link_target .' class="live-stream-item-author" title="'. $user_data['display_name'] .'" href="'. $item->post_permalink .'#comment-'. $item->post_id .'">';
  62.             $author_anchor_end      = '</a>';
  63.         } else {           
  64.             $author_anchor_begin    = '';
  65.             $author_anchor_end      = '';
  66.         }
  67.     }
  68.    
  69.     /* User Avatar */
  70.     if ((isset($instance['show_avatar'])) && ($instance['show_avatar'] == "on")) {
  71.         if ((isset($user_data['user_email'])) && (strlen($user_data['user_email']))) {
  72.             $avatar = get_avatar($user_data['user_email'], 30, null, $user_data['display_name']);
  73.         } else {
  74.             $avatar = get_avatar("dummy@dummy.com", 30, null, $user_data['display_name']);             
  75.         }
  76.         $avatar = get_avatar($user_data['user_email'], 30, null, $user_data['display_name']);
  77.         if (!empty($avatar)) {
  78.             $item_output .= '<div class="live-stream-avatar">';
  79.             $item_output .= $author_anchor_begin . $avatar . $author_anchor_end;
  80.             $item_output .= '</div>';  
  81.         }
  82.     }
  83.    
  84.     /* Begin text container wrapper */
  85.     $item_output .= '<div class="live-stream-text">';
  86.    
  87.         if ((!isset($instance['show_avatar'])) || ($instance['show_avatar'] != "on")) {
  88.             /* Show the User Name */                       
  89.             if (isset($user_data['display_name']))
  90.                 $item_output .= $author_anchor_begin . $user_data['display_name'] . $author_anchor_end ." ";
  91.  
  92.         }
  93.    
  94.    
  95.         if ($item->post_type == "product") {
  96.             $item_output .= ' <span class="live-stream-item-action">'. __("Added", 'live-stream-widget') .'</span> ';
  97.         } else {
  98.             $item_output .= ' <span class="live-stream-item-action">'. __('Added', 'live-stream-widget') .'</span> ';
  99.         }
  100.    
  101.         $item_content = '';
  102.         //echo "content_chars[". $instance['content_chars'] ."]<br />";
  103.         if ((isset($instance['content_chars'])) && (intval($instance['content_chars']))) {
  104.             if ( ($item->post_type == "product") && (isset($item->post_content)) && (strlen($item->post_content)) ) {
  105.                 $item_content = strip_tags($item->post_content);
  106.             } else if ((isset($item->post_content)) && (strlen($item->post_content))) {
  107.                 $item_content = strip_tags($item->post_content);                   
  108.             }
  109.             if (strlen($item_content) > $instance['content_chars'])
  110.                 $item_content = substr($item_content, 0, $instance['content_chars']) ."...";
  111.             else
  112.                 $item_content = substr($item_content, 0, $instance['content_chars']);
  113.         }
  114.         //echo "here ". __LINE__ ."<br />";
  115.         //echo "item_content[". $item_content ."]<br />";
  116.         if (strlen($item_content)) {
  117.             if ($item->post_type == "product") {
  118.                 $post_anchor_begin  = '<a '. $link_target .' class="live-stream-item-title" href="'. $item->post_permalink.'">';
  119.                 $post_anchor_end    = '</a>';
  120.                
  121.                 if (!empty($item->post_title)) {
  122.                     $post_anchor_end .= " ". __('on', 'live-stream-widget') .' <a class="live-stream-item-title" href="'. $item->post_permalink .'">'
  123.                         . $item->post_title ."</a> ";
  124.                 }
  125.             } else {
  126.                 $site_anchor_begin = '<a '. $link_target .' class="live-stream-item-blog" href="'. $blog->siteurl .'">';
  127.                 $site_anchor_end    = '</a>';                  
  128.             }
  129.             $item_output .= " ". $post_anchor_begin . $item_content . $post_anchor_end ." ";
  130.         } else {
  131.             $item_output .= ' <a '. $link_target .' class="live-stream-item-title" href="'. $item->post_permalink .'">'. $item->post_title ."</a> ";
  132.            
  133.         }
  134.  
  135.         /* Show the Blog domain */
  136.         if ((isset($instance['show_users_content'])) && ($instance['show_users_content'] != "local")) {
  137.             if (isset($blog->siteurl)) {
  138.                 $site_anchor_begin = '<a '. $link_target .' class="live-stream-item-blog" href="'. $blog->siteurl .'">';
  139.                 $site_anchor_end    = '</a>';
  140.                 $item_output .= __("to", 'live-stream-widget') ." ". $site_anchor_begin . $blog->blogname . $site_anchor_end ." ";
  141.             }
  142.         }
  143.    
  144.    
  145.         /* Show the Post/Comment human time */
  146.         $item_output .= '<div class="live-stream-text-footer">';
  147.             $item_output .= '<span class="live-stream-text-footer-date">'. sprintf( __( '%s ago ', 'live-stream-widget' ),
  148.                 human_time_diff( $item->post_date_gmt ) ) .'</span>';
  149.             $item_output .= ' &middot; ';
  150.        
  151.             if ($item->post_type == "product") {
  152.                 if ($instance['show_users_content'] == "local") {
  153.                     $comment_count = get_comments_number( $item->post_id );
  154.                     $comment_label = __('comment', 'live-stream-widget') ." (". $comment_count .")";
  155.  
  156.                     $item_output .= '<a '. $link_target .' class="live-stream-text-footer-date" href="'.
  157.                         $item->post_permalink .'">'. 'View Product' .'</a>';
  158.                 } else {
  159.                     $comment_label = __('comments', 'live-stream-widget');                 
  160.                     $item_output .= '<a '. $link_target .' class="live-stream-text-footer-date" href="'.
  161.                         $item->post_permalink .'">'. 'View Product' .'</a>';
  162.                 }
  163.             } else {
  164.                 if (($instance['show_users_content'] == "local") && (array_search("post", $instance['content_types']) !== false)) {
  165.                     $comment_count = get_comments_number( $item->post_id );
  166.                     $comment_label = __('comment', 'live-stream-widget') ." (". $comment_count .")";
  167.                     $item_output .= '<a '. $link_target .' class="live-stream-text-footer-date" href="'. $item->post_permalink .'">'. 'View Product' .'</a>';
  168.                
  169.                 } else {
  170.                     $item_output .= '<a '. $link_target .' class="live-stream-text-footer-date" href="'. $item->post_permalink .'">'. __('visit', 'live-stream-widget') .'</a>';                   
  171.                 }
  172.             }
  173.         $item_output .= '</div>';
  174.  
  175.        
  176.     /* Closing the 'live-stream-text' wrapper */
  177.     $item_output .= '</div>';
  178.  
  179.     return $item_output;
  180. }
  181. add_filter('live-stream-display-post-type-product', 'live_stream_widget_display_products', 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement