/** * Displays the random-image widget. * * @uses ClassBlogs_Plugins_RandomImage to get a random image to display */ public function widget($args, $instance) { $instance = $this->maybe_apply_instance_defaults($instance); $plugin = ClassBlogs::get_plugin('random_image'); $image = $plugin->get_random_image(); if ($image) { $this->start_widget($args, $instance); ClassBlogs_NXTClass::switch_to_blog($image->blog_id); // If the image is associated with a specific post, provide a link // to the post. If it has no post linkages, show a link to the blog. if ($image->post_id) { $post_link = sprintf('<a href="%s">%s</a>', esc_url(get_permalink($image->post_id)), esc_html(get_post($image->post_id)->post_title)); // Show a link to a post on a blog when running in multisite // mode, or a link to the post by a particular user when not if (ClassBlogs_Utils::is_multisite()) { $caption = sprintf(__('From the post %1$s on %2$s', 'classblogs'), $post_link, sprintf('<a href="%s">%s</a>', esc_url(ClassBlogs_NXTClass::get_blogaddress_by_id($image->blog_id)), esc_html(ClassBlogs_NXTClass::get_blog_option($image->blog_id, 'blogname')))); } else { $user = get_userdata($image->user_id); $caption = sprintf(__('From the post %1$s by %2$s', 'classblogs'), $post_link, sprintf('<a href="%s">%s</a>', esc_url(get_author_posts_url($image->user_id)), esc_html($user->display_name))); } } else { // Show a link to the source blog when running in multisite mode, // or show the image's title when not if (ClassBlogs_Utils::is_multisite()) { $caption = sprintf(__('From the blog %s', 'classblogs'), sprintf('<a href="%s">%s</a>', esc_url(ClassBlogs_NXTClass::get_blogaddress_by_id($image->blog_id)), esc_html(ClassBlogs_NXTClass::get_blog_option($image->blog_id, 'blogname')))); } else { $caption = sprintf('<a href="%s">%s</a>', esc_url($image->url), esc_attr($image->title)); } } // Display the link to the image with an appropriate caption printf('<ul> <li> <a href="%1$s"><img src="%1$s" alt="%2$s" title="%2$s" width="80%%" /></a> <br /> %3$s </li> </ul>', esc_url($image->url), esc_attr($image->title), $caption); ClassBlogs_NXTClass::restore_current_blog(); $this->end_widget($args); } }
/** * Updates the student-blogs widget. * * @uses ClassBlogs_Plugins_StudentBlogList to clear the blog cache */ public function update($new, $old) { // Update the widget options $instance = $old; $instance['display'] = ClassBlogs_Utils::sanitize_user_input($new['display']); $instance['title'] = ClassBlogs_Utils::sanitize_user_input($new['title']); // Clear the cached blog list and return the new instance $plugin = ClassBlogs::get_plugin('student_blogs'); $plugin->clear_blog_cache(); return $instance; }
/** * Displays the sitewide tag cloud widget. * * @uses ClassBlogs_Plugins_Aggregation_SitewideTags to get all sitewide tags */ public function widget($args, $instance) { $instance = $this->maybe_apply_instance_defaults($instance); $plugin = ClassBlogs::get_plugin('sitewide_tags'); $most_usage = $plugin->get_max_usage_count(); $least_usage = $plugin->get_min_usage_count(); if (!$most_usage && !$least_usage) { return; } $this->start_widget($args, $instance); $most_usage = max($most_usage, $instance['min_usage']); $least_usage = max($least_usage, $instance['min_usage']); $max_font = $instance['max_font_size']; $min_font = $instance['min_font_size']; // Display each tag as a weighted link a list echo "<div class='tagcloud'>"; foreach ($plugin->get_tags_for_tag_cloud($instance['min_usage']) as $tag) { printf('<a class="tag-link" href="%s" rel="tag" title="%s" style="font-size: %dpt;">%s</a> ', esc_url($tag->url), esc_attr(sprintf(_n('%d topic', '%d topics', $tag->count), $tag->count)), $min_font + floor(($tag->count - $least_usage) / max($most_usage - $least_usage, 1) * ($max_font - $min_font)), esc_html($tag->name)); } echo "</div>"; $this->end_widget($args); }
/** * Updates the sitewide comments widget. * * @uses ClassBlogs_Plugins_Aggregation_SitewideComments to clear the cached widget */ public function update($new, $old) { // Update the widget options $instance = $old; $instance['max_comments'] = absint(ClassBlogs_Utils::sanitize_user_input($new['max_comments'])); $instance['max_comments_per_blog'] = absint(ClassBlogs_Utils::sanitize_user_input($new['max_comments_per_blog'])); $instance['meta_format'] = ClassBlogs_Utils::sanitize_user_input($new['meta_format']); $instance['show_excerpt'] = ClassBlogs_Utils::checkbox_as_bool($new, 'show_excerpt'); $instance['title'] = ClassBlogs_Utils::sanitize_user_input($new['title']); // Clear the cached sidebar widget $plugin = ClassBlogs::get_plugin('sitewide_comments'); $plugin->clear_cached_widget(); return $instance; }
/** * Calculates the number of words produced by a student in the given date window. * * @param int $user_id the ID of the user * @param object $start_dt a DateTime of the start date * @param object $end_dt a DateTime of the end date * @return int the number of words produced by the student * * @uses ClassBlogs_Plugins_Aggregation_SitewidePosts to get all sitewide posts * @uses ClassBlogs_Plugins_Aggregation_SitewideComments to get all sitewide comments * * @access private * @since 0.1 */ private function _get_word_count_for_student($user_id, $start_dt, $end_dt) { $words = 0; // Be explicit about the times of the given dates, making the start date // begin at midnight an the end date end at one second before midnight $start_dt->setTime(0, 0, 0); $end_dt->setTime(23, 59, 59); // Start with the word counts from the posts $sitewide_posts = ClassBlogs::get_plugin('sitewide_posts'); $posts = $sitewide_posts->filter_posts($user_id, $start_dt, $end_dt); foreach ($posts as $post) { $words += $this->_get_word_count_for_text($post->post_content); } // Add the word count from all comments $sitewide_comments = ClassBlogs::get_plugin('sitewide_comments'); $comments = $sitewide_comments->filter_comments($user_id, $start_dt, $end_dt); foreach ($comments as $comment) { $words += $this->_get_word_count_for_text($comment->comment_content); } return $words; }
/** * Populates the YouTube playlist from the videos in all posts on the site. * * @access private * @since 0.4 */ private function _sync_playlist() { $plugin = ClassBlogs::get_plugin('sitewide_posts'); if (!empty($plugin)) { // Create records of all videos used foreach ($plugin->get_sitewide_posts() as $post) { ClassBlogs_NXTClass::switch_to_blog($post->cb_sw_blog_id); $this->_update_videos_on_post_save($post->ID); ClassBlogs_NXTClass::restore_current_blog(); } // Request information on all added videos from YouTube $this->_retrieve_queued_video_info(); } }
/** * Returns the number of comments that a student has left * * @param int $user_id the user ID of a student * @return string the number of comments left by the student */ function classblogging_get_total_comments_for_student($user_id) { $sitewide_comments = ClassBlogs::get_plugin('sitewide_comments'); return $sitewide_comments->get_total_comments_for_student($user_id); }