Exemple #1
0
         $title = trim(strip_tags(bp_core_get_user_displayname($user_id)));
         $permalink = bp_core_get_user_domain($user_id);
     } else {
         if (function_exists('is_bbpress')) {
             $title = trim(strip_tags(bbp_get_user_display_name($user_id)));
             $permalink = bbp_get_user_profile_url($user_id);
         } else {
             $wp_object = null;
         }
     }
     // If valid WP_User object, retrieve the avatar URL
     if ($wp_object) {
         $thumbnail = ratingwidget()->get_user_avatar($user_id);
     }
 } else {
     $post_id = RatingWidgetPlugin::Urid2PostId($urid);
     $wp_object = get_post($post_id);
     $title = get_the_title($post_id);
     $excerpt = ratingwidget()->GetPostExcerpt($wp_object, 15);
     $permalink = get_permalink($post_id);
     $thumbnail = ratingwidget()->GetPostImage($wp_object);
 }
 if ($wp_object) {
     // Skip null object
     if ($thumbnail) {
         $thumbnail = trim($thumbnail);
     }
     if (empty($thumbnail)) {
         $thumbnail = rw_get_plugin_img_path('top-rated/placeholder.png');
     }
     $short = mb_strlen($title) > 30 ? trim(mb_substr($title, 0, 30)) . '...' : $title;
Exemple #2
0
        public function GetTopRated()
        {
            $rw_ret_obj = $this->GetTopRatedData(array('posts', 'pages'));
            if (false === $rw_ret_obj || count($rw_ret_obj->data) == 0) {
                return '';
            }
            $html = '<div id="rw_top_rated_page">';
            foreach ($rw_ret_obj->data as $type => $ratings) {
                if (is_array($ratings) && count($ratings) > 0) {
                    $html .= '<div id="rw_top_rated_page_' . $type . '" class="rw-wp-ui-top-rated-list-container">';
                    if ($instance["show_{$type}_title"]) {
                        $instance["{$type}_title"] = empty($instance["{$type}_title"]) ? ucwords($type) : $instance["{$type}_title"];
                        $html .= '<p style="margin: 0;">' . $instance["{$type}_title"] . '</p>';
                    }
                    $html .= '<ul class="rw-wp-ui-top-rated-list">';
                    $count = 1;
                    foreach ($ratings as $rating) {
                        $urid = $rating->urid;
                        $rclass = $types[$type]["rclass"];
                        $thumbnail = '';
                        ratingwidget()->QueueRatingData($urid, "", "", $rclass);
                        switch ($type) {
                            case "posts":
                            case "pages":
                                $id = RatingWidgetPlugin::Urid2PostId($urid);
                                $post = get_post($id);
                                $title = trim(strip_tags($post->post_title));
                                $excerpt = $this->GetPostExcerpt($post, 15);
                                $permalink = get_permalink($post->ID);
                                $thumbnail = $this->GetPostFeaturedImage($post->ID);
                                break;
                            case "comments":
                                $id = RatingWidgetPlugin::Urid2CommentId($urid);
                                $comment = get_comment($id);
                                $title = trim(strip_tags($comment->comment_content));
                                $permalink = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
                                break;
                            case "activity_updates":
                            case "activity_comments":
                                $id = RatingWidgetPlugin::Urid2ActivityId($urid);
                                $activity = new bp_activity_activity($id);
                                $title = trim(strip_tags($activity->content));
                                $permalink = bp_activity_get_permalink($id);
                                break;
                            case "users":
                                $id = RatingWidgetPlugin::Urid2UserId($urid);
                                $title = trim(strip_tags(bp_core_get_user_displayname($id)));
                                $permalink = bp_core_get_user_domain($id);
                                break;
                            case "forum_posts":
                                $id = RatingWidgetPlugin::Urid2ForumPostId($urid);
                                $forum_post = bp_forums_get_post($id);
                                $title = trim(strip_tags($forum_post->post_text));
                                $page = bb_get_page_number($forum_post->post_position);
                                $permalink = get_topic_link($id, $page) . "#post-{$id}";
                                break;
                        }
                        $short = mb_strlen($title) > 30 ? trim(mb_substr($title, 0, 30)) . "..." : $title;
                        $html .= '
<li class="rw-wp-ui-top-rated-list-item">
    <div>
        <b class="rw-wp-ui-top-rated-list-count">' . $count . '</b>
        <img class="rw-wp-ui-top-rated-list-item-thumbnail" src="' . $thumbnail . '" alt="" />
        <div class="rw-wp-ui-top-rated-list-item-data">
            <div>
                <a class="rw-wp-ui-top-rated-list-item-title" href="' . $permalink . '" title="' . $title . '">' . $short . '</a>
                <div class="rw-ui-container rw-class-' . $rclass . ' rw-urid-' . $urid . ' rw-size-small rw-prop-readOnly-true"></div>
            </div>
            <p class="rw-wp-ui-top-rated-list-item-excerpt">' . $excerpt . '</p>
        </div>
    </div>
</li>';
                        $count++;
                    }
                    $html .= "</ul>";
                    $html .= "</div>";
                }
            }
            // Set a flag that the widget is loaded.
            RatingWidgetPlugin::TopRatedWidgetLoaded();
            ob_start();
            ?>
<script type="text/javascript">
    // Hook render widget.
    if (typeof(RW_HOOK_READY) === "undefined"){ RW_HOOK_READY = []; }
    RW_HOOK_READY.push(function(){
        RW._foreach(RW._getByClassName("rw-wp-ui-top-rated-list", "ul"), function(list){
            RW._foreach(RW._getByClassName("rw-ui-container", "div", list), function(rating){
                // Deactivate rating.
                RW._Class.remove(rating, "rw-active");
                var i = (RW._getByClassName("rw-report-link", "a", rating))[0];
                if (RW._is(i)){ i.parentNode.removeChild(i); }
            });
        });
    });
</script>
<?php 
            $html .= ob_get_clean();
            $html .= '</div>';
            return $html;
        }
        function widget($args, $instance)
        {
            if (RWLogger::IsOn()) {
                $params = func_get_args();
                RWLogger::LogEnterence("RatingWidgetPlugin_TopRatedWidget.widget", $params, true);
            }
            if (!defined("WP_RW__SITE_PUBLIC_KEY") || false === WP_RW__SITE_PUBLIC_KEY) {
                return;
            }
            if (RatingWidgetPlugin::$WP_RW__HIDE_RATINGS) {
                return;
            }
            extract($args, EXTR_SKIP);
            $bpInstalled = ratingwidget()->IsBuddyPressInstalled();
            $bbInstalled = ratingwidget()->IsBBPressInstalled();
            $types = $this->GetTypesInfo();
            $show_any = false;
            foreach ($types as $type => $data) {
                if (false !== $instance["show_{$type}"]) {
                    $show_any = true;
                    break;
                }
            }
            if (RWLogger::IsOn()) {
                RWLogger::Log('RatingWidgetPlugin_TopRatedWidget', 'show_any = ' . ($show_any ? 'TRUE' : 'FALSE'));
            }
            if (false === $show_any) {
                // Nothing to show.
                return;
            }
            $details = array("uid" => WP_RW__SITE_PUBLIC_KEY);
            $queries = array();
            foreach ($types as $type => $type_data) {
                if (isset($instance["show_{$type}"]) && $instance["show_{$type}"] && $instance["{$type}_count"] > 0) {
                    $options = ratingwidget()->GetOption($type_data["options"]);
                    $queries[$type] = array("rclasses" => $type_data["classes"], "votes" => max(1, (int) $instance["{$type}_min_votes"]), "orderby" => $instance["{$type}_orderby"], "order" => $instance["{$type}_order"], "limit" => (int) $instance["{$type}_count"], "types" => isset($options->type) ? $options->type : "star");
                    $since_created = isset($instance["{$type}_since_created"]) ? (int) $instance["{$type}_since_created"] : WP_RW__TIME_ALL_TIME;
                    // since_created should be at least 24 hours (86400 seconds), skip otherwise.
                    if ($since_created >= WP_RW__TIME_24_HOURS_IN_SEC) {
                        $time = current_time('timestamp', true) - $since_created;
                        // c: ISO 8601 full date/time, e.g.: 2004-02-12T15:19:21+00:00
                        $queries[$type]['since_created'] = date('c', $time);
                    }
                }
            }
            $details["queries"] = urlencode(json_encode($queries));
            $rw_ret_obj = ratingwidget()->RemoteCall("action/query/ratings.php", $details, WP_RW__CACHE_TIMEOUT_TOP_RATED);
            if (false === $rw_ret_obj) {
                return;
            }
            $rw_ret_obj = json_decode($rw_ret_obj);
            if (null === $rw_ret_obj || true !== $rw_ret_obj->success) {
                return;
            }
            $title = empty($instance['title']) ? __('Top Rated', WP_RW__ID) : apply_filters('widget_title', $instance['title']);
            $titleMaxLength = isset($instance['title_max_length']) && is_numeric($instance['title_max_length']) ? (int) $instance['title_max_length'] : 30;
            $empty = true;
            $toprated_data = new stdClass();
            $toprated_data->id = rand(1, 100);
            $toprated_data->title = array('label' => $title, 'show' => true, 'before' => $this->EncodeHtml($before_title), 'after' => $this->EncodeHtml($after_title));
            $toprated_data->options = array('align' => 'vertical', 'direction' => 'ltr', 'html' => array('before' => $this->EncodeHtml($before_widget), 'after' => $this->EncodeHtml($after_widget)));
            $toprated_data->site = array('id' => WP_RW__SITE_ID, 'domain' => $_SERVER['HTTP_HOST'], 'type' => 'WordPress');
            $toprated_data->itemGroups = array();
            if (count($rw_ret_obj->data) > 0) {
                foreach ($rw_ret_obj->data as $type => $ratings) {
                    if (is_array($ratings) && count($ratings) > 0) {
                        $item_group = new stdClass();
                        $item_group->type = $type;
                        $item_group->title = $instance["{$type}_title"];
                        $item_group->showTitle = 1 === $instance["show_{$type}_title"] && '' !== trim($item_group->title);
                        if (is_numeric($instance["{$type}_style"])) {
                            switch ($instance["{$type}_style"]) {
                                case 0:
                                    $instance["{$type}_style"] = 'legacy';
                                    break;
                                case 1:
                                default:
                                    $instance["{$type}_style"] = 'thumbs';
                                    break;
                            }
                        }
                        $item_group->style = $instance["{$type}_style"];
                        $item_group->options = array('title' => array('maxLen' => $titleMaxLength));
                        $item_group->items = array();
                        $has_thumb = strtolower($instance["{$type}_style"]) !== 'legacy';
                        $thumb_width = 160;
                        $thumb_height = 100;
                        if ($has_thumb) {
                            switch ($instance["{$type}_style"]) {
                                case '2':
                                case 'compact_thumbs':
                                    $thumb_width = 50;
                                    $thumb_height = 40;
                                    break;
                                case '1':
                                case 'thumbs':
                                default:
                                    $thumb_width = 160;
                                    $thumb_height = 100;
                                    break;
                            }
                            $item_group->options['thumb'] = array('width' => $thumb_width, 'height' => $thumb_height);
                        }
                        $cell = 0;
                        foreach ($ratings as $rating) {
                            $urid = $rating->urid;
                            $rclass = $types[$type]["rclass"];
                            $rclasses[$rclass] = true;
                            $extension_type = false;
                            if (RWLogger::IsOn()) {
                                RWLogger::Log('HANDLED_ITEM', 'Urid = ' . $urid . '; Class = ' . $rclass . ';');
                            }
                            if ('posts' === $type || 'pages' === $type) {
                                $post = null;
                                $id = RatingWidgetPlugin::Urid2PostId($urid);
                                $status = @get_post_status($id);
                                if (false === $status) {
                                    if (RWLogger::IsOn()) {
                                        RWLogger::Log('POST_NOT_EXIST', $id);
                                    }
                                    // Post not exist.
                                    continue;
                                } else {
                                    if ('publish' !== $status && 'private' !== $status) {
                                        if (RWLogger::IsOn()) {
                                            RWLogger::Log('POST_NOT_VISIBLE', 'status = ' . $status);
                                        }
                                        // Post not yet published.
                                        continue;
                                    } else {
                                        if ('private' === $status && !is_user_logged_in()) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('RatingWidgetPlugin_TopRatedWidget::widget', 'POST_PRIVATE && USER_LOGGED_OUT');
                                            }
                                            // Private post but user is not logged in.
                                            continue;
                                        }
                                    }
                                }
                                $post = @get_post($id);
                                $title = trim(strip_tags($post->post_title));
                                $permalink = get_permalink($post->ID);
                            } else {
                                if ('comments' === $type) {
                                    $comment = null;
                                    $id = RatingWidgetPlugin::Urid2CommentId($urid);
                                    $status = @wp_get_comment_status($id);
                                    if (false === $status) {
                                        if (RWLogger::IsOn()) {
                                            RWLogger::Log('COMMENT_NOT_EXIST', $id);
                                        }
                                        // Comment not exist.
                                        continue;
                                    } else {
                                        if ('approved' !== $status) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('COMMENT_NOT_VISIBLE', 'status = ' . $status);
                                            }
                                            // Comment not approved.
                                            continue;
                                        }
                                    }
                                    $comment = @get_comment($id);
                                    $title = trim(strip_tags($comment->comment_content));
                                    $permalink = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
                                } else {
                                    if ('activity_updates' === $type || 'activity_comments' === $type) {
                                        $id = RatingWidgetPlugin::Urid2ActivityId($urid);
                                        $activity = new bp_activity_activity($id);
                                        if (!is_object($activity)) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('BP_ACTIVITY_NOT_EXIST', $id);
                                            }
                                            // Activity not exist.
                                            continue;
                                        } else {
                                            if (!empty($activity->is_spam)) {
                                                if (RWLogger::IsOn()) {
                                                    RWLogger::Log('BP_ACTIVITY_NOT_VISIBLE (SPAM or TRASH)');
                                                }
                                                // Activity marked as SPAM or TRASH.
                                                continue;
                                            } else {
                                                if (!empty($activity->hide_sitewide)) {
                                                    if (RWLogger::IsOn()) {
                                                        RWLogger::Log('BP_ACTIVITY_HIDE_SITEWIDE');
                                                    }
                                                    // Activity marked as hidden in site.
                                                    continue;
                                                }
                                            }
                                        }
                                        $title = trim(strip_tags($activity->content));
                                        $permalink = bp_activity_get_permalink($id);
                                    } else {
                                        if ('users' === $type) {
                                            $id = RatingWidgetPlugin::Urid2UserId($urid);
                                            if ($bpInstalled) {
                                                $title = trim(strip_tags(bp_core_get_user_displayname($id)));
                                                $permalink = bp_core_get_user_domain($id);
                                            } else {
                                                if ($bbInstalled) {
                                                    $title = trim(strip_tags(bbp_get_user_display_name($id)));
                                                    $permalink = bbp_get_user_profile_url($id);
                                                } else {
                                                    continue;
                                                }
                                            }
                                        } else {
                                            if ('forum_posts' === $type || 'forum_replies' === $type) {
                                                $id = RatingWidgetPlugin::Urid2ForumPostId($urid);
                                                if (function_exists('bp_forums_get_post')) {
                                                    $forum_post = @bp_forums_get_post($id);
                                                    if (!is_object($forum_post)) {
                                                        continue;
                                                    }
                                                    $title = trim(strip_tags($forum_post->post_text));
                                                    $page = bb_get_page_number($forum_post->post_position);
                                                    $permalink = get_topic_link($id, $page) . "#post-{$id}";
                                                } else {
                                                    if (function_exists('bbp_get_reply_id')) {
                                                        $forum_item = bbp_get_topic();
                                                        if (is_object($forum_item)) {
                                                            $is_topic = true;
                                                        } else {
                                                            $is_topic = false;
                                                            $forum_item = bbp_get_reply($id);
                                                            if (!is_object($forum_item)) {
                                                                if (RWLogger::IsOn()) {
                                                                    RWLogger::Log('BBP_FORUM_ITEM_NOT_EXIST', $id);
                                                                }
                                                                // Invalid id (no topic nor reply).
                                                                continue;
                                                            }
                                                            if (RWLogger::IsOn()) {
                                                                RWLogger::Log('BBP_IS_TOPIC_REPLY', $is_topic ? 'FALSE' : 'TRUE');
                                                            }
                                                        }
                                                        // Visible statueses: Public or Closed.
                                                        $visible_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id());
                                                        if (!in_array($forum_item->post_status, $visible_statuses)) {
                                                            if (RWLogger::IsOn()) {
                                                                RWLogger::Log('BBP_FORUM_ITEM_HIDDEN', $forum_item->post_status);
                                                            }
                                                            // Item is not public nor closed.
                                                            continue;
                                                        }
                                                        $is_reply = !$is_topic;
                                                        if ($is_reply) {
                                                            // Get parent topic.
                                                            $forum_topic = bbp_get_topic($forum_post->post_parent);
                                                            if (!in_array($forum_topic->post_status, $visible_statuses)) {
                                                                if (RWLogger::IsOn()) {
                                                                    RWLogger::Log('BBP_PARENT_FORUM_TOPIC_IS_HIDDEN', 'TRUE');
                                                                }
                                                                // Parent topic is not public nor closed.
                                                                continue;
                                                            }
                                                        }
                                                        $title = trim(strip_tags($forum_post->post_title));
                                                        $permalink = get_permalink($forum_post->ID);
                                                    } else {
                                                        continue;
                                                    }
                                                }
                                                $types[$type]['handler']->GetElementInfoByRating();
                                            } else {
                                                $found_handler = false;
                                                $extensions = ratingwidget()->GetExtensions();
                                                foreach ($extensions as $ext) {
                                                    $result = $ext->GetElementInfoByRating($type, $rating);
                                                    if (false !== $result) {
                                                        $found_handler = true;
                                                        break;
                                                    }
                                                }
                                                if ($found_handler) {
                                                    $id = $result['id'];
                                                    $title = $result['title'];
                                                    $permalink = $result['permalink'];
                                                    $img = rw_get_thumb_url($result['img'], $thumb_width, $thumb_height, $result['permalink']);
                                                    $extension_type = true;
                                                } else {
                                                    continue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            $queued = ratingwidget()->QueueRatingData($urid, "", "", $rclass);
                            // Override rating class in case the same rating has already been queued with a different rclass.
                            $rclass = $queued['rclass'];
                            $short = mb_strlen($title) > $titleMaxLength ? trim(mb_substr($title, 0, $titleMaxLength)) . "..." : $title;
                            $item = array('site' => array('id' => WP_RW__SITE_ID, 'domain' => $_SERVER['HTTP_HOST']), 'page' => array('externalID' => $id, 'url' => $permalink, 'title' => $short), 'rating' => array('localID' => $urid, 'options' => array('rclass' => $rclass)));
                            // Add thumb url.
                            if ($extension_type && is_string($img)) {
                                $item['page']['img'] = $img;
                            } else {
                                if ($has_thumb && in_array($type, array('posts', 'pages'))) {
                                    $item['page']['img'] = rw_get_post_thumb_url($post, $thumb_width, $thumb_height);
                                }
                            }
                            $item_group->items[] = $item;
                            $cell++;
                            $empty = false;
                        }
                        $toprated_data->itemGroups[] = $item_group;
                    }
                }
            }
            if (true === $empty) {
                //            echo '<p style="margin: 0;">There are no rated items for this period.</p>';
                //        echo $before_widget;
                //        echo $after_widget;
            } else {
                // Set a flag that the widget is loaded.
                ratingwidget()->TopRatedWidgetLoaded();
                ?>
					<b class="rw-ui-recommendations" data-id="<?php 
                echo $toprated_data->id;
                ?>
"></b>
					<script type="text/javascript">
						var _rwq = _rwq || [];
						_rwq.push(['_setRecommendations', <?php 
                echo json_encode($toprated_data);
                ?>
]);
					</script>
				<?php 
            }
        }
        function widget($args, $instance)
        {
            if (RWLogger::IsOn()) {
                $params = func_get_args();
                RWLogger::LogEnterence("RWTopRated.widget", $params, true);
            }
            if (!defined("WP_RW__USER_KEY") || false === WP_RW__USER_KEY) {
                return;
            }
            if (RatingWidgetPlugin::$WP_RW__HIDE_RATINGS) {
                return;
            }
            extract($args, EXTR_SKIP);
            $types = array("posts" => array("rclass" => "blog-post", "classes" => "front-post,blog-post,new-blog-post,user-post", "options" => WP_RW__BLOG_POSTS_OPTIONS), "pages" => array("rclass" => "page", "classes" => "page,user-page", "options" => WP_RW__PAGES_OPTIONS), "comments" => array("rclass" => "comment", "classes" => "comment,new-blog-comment,user-comment", "options" => WP_RW__COMMENTS_OPTIONS), "activity_updates" => array("rclass" => "activity-update", "classes" => "activity-update,user-activity-update", "options" => WP_RW__ACTIVITY_UPDATES_OPTIONS), "activity_comments" => array("rclass" => "activity-comment", "classes" => "activity-comment,user-activity-comment", "options" => WP_RW__ACTIVITY_COMMENTS_OPTIONS), "forum_posts" => array("rclass" => "forum-post", "classes" => "forum-post,new-forum-post,user-forum-post", "options" => WP_RW__FORUM_POSTS_OPTIONS), "users" => array("rclass" => "user", "classes" => "user", "options" => WP_RW__FORUM_POSTS_OPTIONS));
            $show_any = false;
            foreach ($types as $type => $data) {
                if (false !== $instance["show_{$type}"]) {
                    $show_any = true;
                    break;
                }
            }
            if (false === $show_any) {
                // Nothing to show.
                return;
            }
            $details = array("uid" => WP_RW__USER_KEY);
            $queries = array();
            foreach ($types as $type => $type_data) {
                if ($instance["show_{$type}"] && $instance["{$type}_count"] > 0) {
                    $options = json_decode(RatingWidgetPlugin::_getOption($type_data["options"]));
                    $queries[$type] = array("rclasses" => $type_data["classes"], "votes" => max(1, (int) $instance["{$type}_min_votes"]), "orderby" => $instance["{$type}_orderby"], "order" => $instance["{$type}_order"], "limit" => (int) $instance["{$type}_count"], "types" => isset($options->type) ? $options->type : "star");
                }
            }
            $details["queries"] = urlencode(json_encode($queries));
            $rw_ret_obj = RatingWidgetPlugin::RemoteCall("action/query/ratings.php", $details);
            if (false === $rw_ret_obj) {
                return;
            }
            $rw_ret_obj = json_decode($rw_ret_obj);
            if (null === $rw_ret_obj || true !== $rw_ret_obj->success) {
                return;
            }
            echo $before_widget;
            $title = empty($instance['title']) ? __('Top Rated', WP_RW__ID) : apply_filters('widget_title', $instance['title']);
            echo $before_title . $title . $after_title;
            $empty = true;
            if (count($rw_ret_obj->data) > 0) {
                foreach ($rw_ret_obj->data as $type => $ratings) {
                    if (is_array($ratings) && count($ratings) > 0) {
                        echo '<div id="rw_top_rated_' . $type . '">';
                        if ($instance["show_{$type}_title"]) {
                            /* (1.3.3) - Conditional title display */
                            $instance["{$type}_title"] = empty($instance["{$type}_title"]) ? ucwords($type) : $instance["{$type}_title"];
                            echo '<p style="margin: 0;">' . $instance["{$type}_title"] . '</p>';
                        }
                        echo '<ul class="rw-top-rated-list">';
                        foreach ($ratings as $rating) {
                            $urid = $rating->urid;
                            $rclass = $types[$type]["rclass"];
                            RatingWidgetPlugin::QueueRatingData($urid, "", "", $rclass);
                            switch ($type) {
                                case "posts":
                                case "pages":
                                    $id = RatingWidgetPlugin::Urid2PostId($urid);
                                    $post = get_post($id);
                                    $title = trim(strip_tags($post->post_title));
                                    $permalink = get_permalink($post->ID);
                                    break;
                                case "comments":
                                    $id = RatingWidgetPlugin::Urid2CommentId($urid);
                                    $comment = get_comment($id);
                                    $title = trim(strip_tags($comment->comment_content));
                                    $permalink = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
                                    break;
                                case "activity_updates":
                                case "activity_comments":
                                    $id = RatingWidgetPlugin::Urid2ActivityId($urid);
                                    $activity = new bp_activity_activity($id);
                                    $title = trim(strip_tags($activity->content));
                                    $permalink = bp_activity_get_permalink($id);
                                    break;
                                case "users":
                                    $id = RatingWidgetPlugin::Urid2UserId($urid);
                                    $title = trim(strip_tags(bp_core_get_user_displayname($id)));
                                    $permalink = bp_core_get_user_domain($id);
                                    break;
                                case "forum_posts":
                                    $id = RatingWidgetPlugin::Urid2ForumPostId($urid);
                                    $forum_post = bp_forums_get_post($id);
                                    $title = trim(strip_tags($forum_post->post_text));
                                    $page = bb_get_page_number($forum_post->post_position);
                                    $permalink = get_topic_link($id, $page) . "#post-{$id}";
                                    break;
                            }
                            $short = mb_strlen($title) > 30 ? trim(mb_substr($title, 0, 30)) . "..." : $title;
                            echo '<li>' . '<a href="' . $permalink . '" title="' . $title . '">' . $short . '</a>' . '<br />' . '<div class="rw-ui-container rw-class-' . $rclass . ' rw-urid-' . $urid . '"></div>' . '</li>';
                        }
                        echo "</ul>";
                        echo "</div>";
                        $empty = false;
                    }
                }
            }
            if (true === $empty) {
                echo '<p style="margin: 0;">There are no rated items for this period.</p>';
            } else {
                // Set a flag that the widget is loaded.
                RatingWidgetPlugin::TopRatedWidgetLoaded();
                ?>
<script type="text/javascript">
    // Hook render widget.
    if (typeof(RW_HOOK_READY) === "undefined"){ RW_HOOK_READY = []; }
    RW_HOOK_READY.push(function(){
        RW._foreach(RW._getByClassName("rw-top-rated-list", "ul"), function(list){
            RW._foreach(RW._getByClassName("rw-ui-container", "div", list), function(rating){
                // Deactivate rating.
                RW._Class.remove(rating, "rw-active");
                var i = (RW._getByClassName("rw-report-link", "a", rating))[0];
                if (RW._is(i)){ i.parentNode.removeChild(i); }
                
                // Update size to small.
                if (!RW._Class.has(rating, "rw-size-small"))
                {
                    RW._Class.add(rating, "rw-size-small");
                    RW._Class.remove(rating, "rw-size-medium");
                    RW._Class.remove(rating, "rw-size-large");
                }
                
                if (RW._Class.has(rating, "rw-ui-star"))
                {
                    RW._foreach(RW._getByTagName("li", rating), function(star){
                        // Clear star event handlers.
                        star.onmouseover =
                        star.onmouseout =
                        star.onclick = "";
                    });
                }
                else
                {
                    RW._foreach(RW._getByTagName("i", rating), function(thumb){
                        // Clear star event handlers.
                        thumb.onmouseover =
                        thumb.onmouseout =
                        thumb.onclick = "";
                    });

                    var like_label = RW._getByClassName("rw-ui-like-label", "span", rating);
                    if (like_label.length == 1)
                    {
                        like_label = like_label[0];
                        like_label.style.fontSize = like_label.style.lineHeight = "";
                    }
                    
                    var dislike_label = RW._getByClassName("rw-ui-dislike-label", "span", rating);
                    if (dislike_label.length == 1)
                    {
                        dislike_label = dislike_label[0];
                        dislike_label.style.fontSize = dislike_label.style.lineHeight = "";
                    }
                }
                
                var label = (RW._getByClassName("rw-ui-info", "span", rating))[0];
                label.style.fontSize = label.style.lineHeight = "";
            });
        });
    });
</script>
<?php 
            }
            echo $after_widget;
        }