Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function live_stream_widget_display_products($item_output = '', $item, $instance) {
- if (is_multisite()) {
- if ((isset($item->blog_id)) && (intval($item->blog_id))) {
- $blog = get_blog_details($item->blog_id);
- }
- } else {
- if (!isset($blog)) {
- $blog = new stdClass;
- $blog->blogname = get_option( 'blogname' );
- $blog->siteurl = get_option( 'siteurl' );
- }
- }
- //echo "blog<pre>"; print_r($blog); echo "</pre>";
- if ((isset($instance['link_target'])) && ($instance['link_target'] == "on")) {
- $link_target = ' target="_blank" ';
- } else {
- $link_target = '';
- }
- $user_data = array();
- if (intval($item->post_author_id) ) {
- $userdata = get_userdata( intval($item->post_author_id) );
- if ($userdata) {
- $user_data['ID'] = $userdata->ID;
- $user_data['user_email'] = $userdata->user_email;
- $user_data['display_name'] = $userdata->display_name;
- }
- }
- if (!isset($user_data['ID']))
- $user_data['ID'] = 0;
- if (!isset($user_data['user_email'])) {
- if ((isset($item->post_author_email)) && (strlen($item->post_author_email))) {
- $user_data['user_email'] = $item->post_author_email;
- } else {
- $user_data['user_email'] = '';
- }
- }
- if (!isset($user_data['display_name'])) {
- if ((isset($item->post_author_name)) && (strlen($item->post_author_name))) {
- $user_data['display_name'] = $item->post_author_name;
- } else {
- $user_data['display_name'] = '';
- }
- }
- /* Build an anchor wrapper for the author which is used in multiple places */
- if ((isset($blog->siteurl)) && (intval($item->post_author_id) )) {
- $author_anchor_begin = '<a '. $link_target .' class="live-stream-item-author" title="'. $user_data['display_name'] .'" href="'. $blog->siteurl .'?author='
- . $item->post_author_id .'">';
- $author_anchor_end = '</a>';
- } else {
- if ($item->post_type == "product") {
- $author_anchor_begin = '<a '. $link_target .' class="live-stream-item-author" title="'. $user_data['display_name'] .'" href="'. $item->post_permalink .'#comment-'. $item->post_id .'">';
- $author_anchor_end = '</a>';
- } else {
- $author_anchor_begin = '';
- $author_anchor_end = '';
- }
- }
- /* User Avatar */
- if ((isset($instance['show_avatar'])) && ($instance['show_avatar'] == "on")) {
- if ((isset($user_data['user_email'])) && (strlen($user_data['user_email']))) {
- $avatar = get_avatar($user_data['user_email'], 30, null, $user_data['display_name']);
- } else {
- $avatar = get_avatar("dummy@dummy.com", 30, null, $user_data['display_name']);
- }
- $avatar = get_avatar($user_data['user_email'], 30, null, $user_data['display_name']);
- if (!empty($avatar)) {
- $item_output .= '<div class="live-stream-avatar">';
- $item_output .= $author_anchor_begin . $avatar . $author_anchor_end;
- $item_output .= '</div>';
- }
- }
- /* Begin text container wrapper */
- $item_output .= '<div class="live-stream-text">';
- if ((!isset($instance['show_avatar'])) || ($instance['show_avatar'] != "on")) {
- /* Show the User Name */
- if (isset($user_data['display_name']))
- $item_output .= $author_anchor_begin . $user_data['display_name'] . $author_anchor_end ." ";
- }
- if ($item->post_type == "product") {
- $item_output .= ' <span class="live-stream-item-action">'. __("Added", 'live-stream-widget') .'</span> ';
- } else {
- $item_output .= ' <span class="live-stream-item-action">'. __('Added', 'live-stream-widget') .'</span> ';
- }
- $item_content = '';
- //echo "content_chars[". $instance['content_chars'] ."]<br />";
- if ((isset($instance['content_chars'])) && (intval($instance['content_chars']))) {
- if ( ($item->post_type == "product") && (isset($item->post_content)) && (strlen($item->post_content)) ) {
- $item_content = strip_tags($item->post_content);
- } else if ((isset($item->post_content)) && (strlen($item->post_content))) {
- $item_content = strip_tags($item->post_content);
- }
- if (strlen($item_content) > $instance['content_chars'])
- $item_content = substr($item_content, 0, $instance['content_chars']) ."...";
- else
- $item_content = substr($item_content, 0, $instance['content_chars']);
- }
- //echo "here ". __LINE__ ."<br />";
- //echo "item_content[". $item_content ."]<br />";
- if (strlen($item_content)) {
- if ($item->post_type == "product") {
- $post_anchor_begin = '<a '. $link_target .' class="live-stream-item-title" href="'. $item->post_permalink.'">';
- $post_anchor_end = '</a>';
- if (!empty($item->post_title)) {
- $post_anchor_end .= " ". __('on', 'live-stream-widget') .' <a class="live-stream-item-title" href="'. $item->post_permalink .'">'
- . $item->post_title ."</a> ";
- }
- } else {
- $site_anchor_begin = '<a '. $link_target .' class="live-stream-item-blog" href="'. $blog->siteurl .'">';
- $site_anchor_end = '</a>';
- }
- $item_output .= " ". $post_anchor_begin . $item_content . $post_anchor_end ." ";
- } else {
- $item_output .= ' <a '. $link_target .' class="live-stream-item-title" href="'. $item->post_permalink .'">'. $item->post_title ."</a> ";
- }
- /* Show the Blog domain */
- if ((isset($instance['show_users_content'])) && ($instance['show_users_content'] != "local")) {
- if (isset($blog->siteurl)) {
- $site_anchor_begin = '<a '. $link_target .' class="live-stream-item-blog" href="'. $blog->siteurl .'">';
- $site_anchor_end = '</a>';
- $item_output .= __("to", 'live-stream-widget') ." ". $site_anchor_begin . $blog->blogname . $site_anchor_end ." ";
- }
- }
- /* Show the Post/Comment human time */
- $item_output .= '<div class="live-stream-text-footer">';
- $item_output .= '<span class="live-stream-text-footer-date">'. sprintf( __( '%s ago ', 'live-stream-widget' ),
- human_time_diff( $item->post_date_gmt ) ) .'</span>';
- $item_output .= ' · ';
- if ($item->post_type == "product") {
- if ($instance['show_users_content'] == "local") {
- $comment_count = get_comments_number( $item->post_id );
- $comment_label = __('comment', 'live-stream-widget') ." (". $comment_count .")";
- $item_output .= '<a '. $link_target .' class="live-stream-text-footer-date" href="'.
- $item->post_permalink .'">'. 'View Product' .'</a>';
- } else {
- $comment_label = __('comments', 'live-stream-widget');
- $item_output .= '<a '. $link_target .' class="live-stream-text-footer-date" href="'.
- $item->post_permalink .'">'. 'View Product' .'</a>';
- }
- } else {
- if (($instance['show_users_content'] == "local") && (array_search("post", $instance['content_types']) !== false)) {
- $comment_count = get_comments_number( $item->post_id );
- $comment_label = __('comment', 'live-stream-widget') ." (". $comment_count .")";
- $item_output .= '<a '. $link_target .' class="live-stream-text-footer-date" href="'. $item->post_permalink .'">'. 'View Product' .'</a>';
- } else {
- $item_output .= '<a '. $link_target .' class="live-stream-text-footer-date" href="'. $item->post_permalink .'">'. __('visit', 'live-stream-widget') .'</a>';
- }
- }
- $item_output .= '</div>';
- /* Closing the 'live-stream-text' wrapper */
- $item_output .= '</div>';
- return $item_output;
- }
- 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