* * blog_id - the ID of the blog * name - the formatted display name of the blog * user_id - the ID of the student who owns the blog * url - the URL of the blog * * @param string $format the formatting string to use for the blog title * @return array a list of information on all student blogs * * @since 0.1 */ public function get_student_blogs($title_format = "") { // Use cached data if possible $cached = $this->get_site_cache('student_blogs'); if ($cached !== null) { return $cached; } // Format the display of the $student_blogs = array(); foreach (ClassBlogs_Students::get_student_blogs() as $student_id => $blog) { $student_blogs[$student_id] = (object) array('blog_id' => $blog->blog_id, 'name' => $this->_format_blog_display_name($title_format, $student_id, $blog->blog_id), 'user_id' => $student_id, 'url' => $blog->url); } // Return the blogs sorted by their computed display name usort($student_blogs, array($this, "_sort_blogs_by_name")); $this->set_site_cache('student_blogs', $student_blogs, 300); return $student_blogs; } } ClassBlogs::register_plugin('student_blogs', 'ClassBlogs_Plugins_StudentBlogList', __('Student List', 'classblogs'), __('Provides a widget that shows a list of all the student bloggers in your class.', 'classblogs'));
public function get_comments_for_widget($max_comments, $max_comments_per_blog, $meta_format) { // Use cached values if possible $cached = $this->get_site_cache('widget'); if ($cached !== null) { return $cached; } $comments = array(); $raw_comments = $this->limit_sitewide_resources($this->get_sitewide_comments(), $max_comments, $max_comments_per_blog); $student_ids = ClassBlogs_Students::get_student_user_ids(); foreach ($raw_comments as $comment) { // Ignore the comment if it's not by a student if (!in_array($comment->user_id, $student_ids)) { continue; } // Create a string for the comment metadata $meta = ""; if ($meta_format) { $blog = sprintf('<a href="%s">%s</a>', ClassBlogs_NXTClass::get_blogaddress_by_id($comment->cb_sw_blog_id), ClassBlogs_NXTClass::get_blog_option($comment->cb_sw_blog_id, 'blogname')); $meta = ClassBlogs_Utils::format_user_string($meta_format, array('blog' => $blog, 'date' => mysql2date(get_option('date_format'), $comment->comment_date), 'time' => mysql2date(get_option('time_format'), $comment->comment_date)), 'cb-sitewide-comment'); } // Build the permalink to the comment using the post URL and an anchor $permalink = sprintf('%s#comment-%d', ClassBlogs_NXTClass::get_blog_permalink($comment->cb_sw_blog_id, $comment->comment_post_ID), $comment->comment_ID); $comments[] = (object) array('author_name' => $comment->comment_author, 'content' => $comment->comment_content, 'meta' => $meta, 'permalink' => $permalink, 'post_title' => $comment->post_title); } $this->set_site_cache('widget', $comments); return $comments; } } ClassBlogs::register_plugin('sitewide_comments', 'ClassBlogs_Plugins_Aggregation_SitewideComments', __('Student Comments', 'classblogs'), __('Allows you to view data on all comments left by your students.', 'classblogs'), false);
?> </label> <input type="radio" name="comment_status" value="disabled" id="comments-disabled" <?php if ($this->get_option('comments_disabled')) { ?> checked="checked"<?php } ?> /> <label for="comments-disabled"><?php _e('Disabled', 'classblogs'); ?> </label> </td> </tr> </table> <?php nxt_nonce_field($this->get_uid()); ?> <p class="submit"><input type="submit" class="button-primary" name="Submit" value="<?php _e('Update Commenting Status', 'classblogs'); ?> " /></p> </form> </div> <?php } } ClassBlogs::register_plugin('disable_comments', 'ClassBlogs_Plugins_DisableComments', __('Disable Comments', 'classblogs'), __('Provides you with the option of disabling commenting on all current and future posts published by you and your students.', 'classblogs'));
" value="<?php echo esc_url($link['url']); ?> " /> <a href="#delete-link" class="delete-link"><?php _e('Delete', 'classblogs'); ?> </a> </td> </tr> <?php } ?> </tbody> </table> <?php nxt_nonce_field($this->get_uid()); ?> <p class="submit"><input type="submit" class="button-primary" name="Submit" value="<?php _e('Update Links', 'classblogs'); ?> " /></p> </form> </div> <?php } } ClassBlogs::register_plugin('student_links', 'ClassBlogs_Plugins_StudentBlogLinks', __('Student Blog Links', 'classblogs'), __('Allows you to put links of your choosing in a sidebar on all student blogs.', 'classblogs'));
} return $words; } /** * Determines the number of words in the given text. * * This first strips all formatting and then calculates the number of words * using PHP's native `str_word_count` function. * * @param string $text the text whose words should be counted * @return int the number of words in the text * * @access private * @since 0.1 */ private function _get_word_count_for_text($text) { // Code derived from http://www.php.net/manual/en/function.str-word-count.php#85579, // which allows this word counter to make a good-faith effort at counting // words in Unicode strings $plaintext = strip_shortcodes(strip_tags($text)); preg_match_all("/\\p{L}[\\p{L}\\p{Mn}\\p{Pd}'\\x{2019}]*/u", $plaintext, $matches); if (!empty($matches)) { return count($matches[0]); } else { return 0; } } } ClassBlogs::register_plugin('word_counter', 'ClassBlogs_Plugins_WordCounter', __('Word Counter', 'classblogs'), __('Adds an admin page for you to view student word counts by week, taken from their posts and comments.', 'classblogs'));
* * @since 0.1 */ public function get_posts_by_user($limit = 5) { $by_user = array(); // Use cached values if possible $cached = $this->get_site_cache('by_user'); if ($cached !== null) { return $cached; } // Build the list of posts by user foreach ($this->get_sitewide_posts() as $post) { if (!array_key_exists($post->post_author, $by_user)) { $by_user[$post->post_author] = (object) array('posts' => array(), 'total_posts' => 0, 'user_id' => $post->post_author); } if ($by_user[$post->post_author]->total_posts < $limit) { $post->from_blog = $post->cb_sw_blog_id; $by_user[$post->post_author]->posts[] = $post; } $by_user[$post->post_author]->total_posts++; } // Sort the posts by the published date of the first post of each user usort($by_user, array($this, '_sort_posts_by_user_by_date')); $values = array_values($by_user); $this->set_site_cache('by_user', $values); return $values; } } ClassBlogs::register_plugin('sitewide_posts', 'ClassBlogs_Plugins_Aggregation_SitewidePosts', __('Student Posts', 'classblogs'), __('Allows you to view data on all posts made by your students.', 'classblogs'), false);
$urls[] = $info[0]; } break; } } ClassBlogs_Utils::restore_blog($current_blog_id); // If we have a valid image, try to find the first post on which it was // used and add its ID to the image data if ($image) { $info = array(); $post_id = null; $user_id = null; foreach ($urls as $url) { $post = $this->_find_first_post_to_use_image($image['blog_id'], $url); if (!empty($post)) { break; } } if (!empty($post)) { $post_id = $post->ID; $user_id = $post->post_author; } $image['post_id'] = $post_id; $image['user_id'] = $user_id; $image = (object) $image; } return $image; } } ClassBlogs::register_plugin('random_image', 'ClassBlogs_Plugins_RandomImage', __('Random Image', 'classblogs'), __('Provides a widget that shows a random image.', 'classblogs'));
*/ class ClassBlogs_Plugins_ClassmateComments extends ClassBlogs_BasePlugin { /** * Registers the auto-approval comment hook. */ public function __construct() { add_action('nxt_insert_comment', array($this, '_approve_classmate_comments'), 10, 2); } /** * Automatically approve any comments left by a classmate. * * @param int $id the database ID of the comment * @param object $comment the saved comment object * * @access private * @since 0.1 */ public function _approve_classmate_comments($id, $comment) { if (!$comment->comment_approved) { if ($comment->user_id || get_user_by('email', $comment->comment_author_email)) { $comment->comment_approved = 1; nxt_update_comment((array) $comment); } } } } ClassBlogs::register_plugin('classmate_comments', 'ClassBlogs_Plugins_ClassmateComments', __('Classmate Comments', 'classblogs'), __("Automatically approves any comment left by a logged-in student on another student's blog.", 'classblogs'));
* * @access private * @since 0.1 */ private function _add_gravatar_signup_link_to_message($user_id, $message) { // Get the user, aborting if none can be found $user_data = get_userdata($user_id); if (empty($user_data)) { return $message; } // Add the messge and link to the Gravatar signup page to the email $parts = array("\n", __('To keep track of your posts on the class blog, you should configure a Gravatar, which is an image of your choosing that will appear next to any posts or comments that you create. You can sign up for a Gravatar for free by visiting the following URL:', 'classblogs'), $this->_get_gravatar_signup_url($user_data), "\n"); return $message . implode("\n", $parts); } /** * Returns the URL at which the given user can sign up for a gravatar. * * @param object $user an instance of a NXTClass user * @return string the URL at which the user can sign up for a Gravatar * * @access private * @since 0.1 */ private function _get_gravatar_signup_url($user) { return self::_GRAVATAR_SIGNUP_URL . urlencode($user->user_email); } } ClassBlogs::register_plugin('gravatar_signup', 'ClassBlogs_Plugins_GravatarSignup', __('Gravatar Signup', 'classblogs'), __('Adds a link allowing your students to sign up for a gravatar to their account activation emails.', 'classblogs'));
{ global $nxtdb; // Update the student's username $nxtdb->update($nxtdb->users, array('user_login' => $new_username), array('ID' => $user_id), array('%s'), array('%d')); // Deal with the implications of the updated username in multisite if (ClassBlogs_Utils::is_multisite()) { ClassBlogs_NXTClass::switch_to_blog($blog_id); $old_url = trailingslashit(home_url()); // Update the blog URL to reflect their new username $site = get_current_site(); $new_path = trailingslashit($site->path . $new_username); $new_url = 'http://' . $site->domain . $new_path; update_option('siteurl', $new_url); update_option('home', $new_url); update_blog_details($blog_id, array('path' => $new_path)); delete_option('rewrite_rules'); // Replace any occurrences of the old URL in the blog's posts $referring_posts = $nxtdb->get_results("\n\t\t\t\tSELECT ID, post_content FROM {$nxtdb->posts}\n\t\t\t\tWHERE post_content LIKE '%%" . like_escape($old_url) . "%%' "); foreach ($referring_posts as $post) { $nxtdb->update($nxtdb->posts, array('post_content' => str_replace($old_url, $new_url, $post->post_content)), array('ID' => $post->ID), array('%s'), array('%d')); } ClassBlogs_NXTClass::restore_current_blog(); } // Flag that the user has changed their username $changed = $this->get_option('changed_users'); $changed[$new_username] = true; $this->update_option('changed_users', $changed); } } ClassBlogs::register_plugin('student_pseudonym', 'ClassBlogs_Plugins_StudentPseudonym', __('Student Pseudonym', 'classblogs'), __('Adds a student admin page that allows them to change their username.', 'classblogs'));
* * @access private * @since 0.1 */ private function _titlecase_name($name) { $name = preg_replace('/[^a-z\\-\\s\\.]/', "", $name); $name = preg_replace('/\\s{2,}/', " ", $name); return preg_replace_callback('/(^\\w)|(\\-\\w)|(\\s\\w)/', array($this, '_titlecase_name_parts'), $name); } /** * Titlecases parts of names as found by a name part regex. * * This is the callback function used to titlecase name parts found by the * `_titlecase_name` function. When given a name of "first", it returns "First". * * @param array $name_matches a matches array as returned by a * `preg_replace_callback` function, with the * array containing strings * @return string a titlecased version of the matched string * * @access private * @since 0.1 */ private function _titlecase_name_parts($name_matches) { return strtoupper($name_matches[0]); } } ClassBlogs::register_plugin('new_user_configuration', 'ClassBlogs_Plugins_NewUserConfiguration', __('New User Configuration', 'classblogs'), __('Creates a first and last name for a newly added student based on their email address.', 'classblogs'));
{ $playlist = $this->get_playlist_videos(); if ($limit <= count($playlist)) { return array_slice($playlist, 0, $limit); } else { return $playlist; } } /** * Returns the URL for viewing the local class playlist page. * * @return string the URL of the local class playlist page * * @since 0.1 */ public function get_local_playlist_page_url() { return get_page_link($this->get_option('playlist_page_id')); } /** * Update the tables whenever an upgrade is needed. * * @since 0.3 */ public function upgrade($old, $new) { $this->_create_tables(); } } ClassBlogs::register_plugin('youtube_class_playlist', 'ClassBlogs_Plugins_YouTubeClassPlaylist', __('YouTube Class Playlist', 'classblogs'), __('Maintains a playlist of all embedded YouTube videos on the class blog.', 'classblogs'));
* @since 0.1 */ public static function create_plugin_page($name, $content = '', $page_id = null) { $conflicts = true; $counter = 0; $page_name = $name; // If a page with the given ID already exists, abort early if ($page_id && get_page($page_id)) { self::_register_plugin_page($page_id); return $page_id; } // Find a name for the new page that doesn't conflict with others while ($conflicts) { $page = get_page_by_title($page_name); if (isset($page)) { $counter++; $page_name = sprintf('%s %d', $name, $counter); } else { $conflicts = false; } } // Create the new page and store its ID $new_page = array('post_author' => ClassBlogs_Settings::get_admin_user_id(), 'post_content' => $content, 'post_status' => 'publish', 'post_title' => $page_name, 'post_type' => 'page'); $page_id = nxt_insert_post($new_page); self::_register_plugin_page($page_id); return $page_id; } } ClassBlogs::register_plugin('plugin_page', 'ClassBlogs_PluginPage', __('Plugin Page', 'classblogs'), __('Manages pages associated with a plugin.', 'classblogs'), false);
// Use cached values if possible $key = 'cloud_' . $threshold; $cached = $this->get_site_cache($key); if ($cached !== null) { return $cached; } $tags = array(); foreach ($this->get_sitewide_tags() as $slug => $tag) { if ($tag['count'] >= $threshold) { $tags[] = (object) array('count' => $tag['count'], 'name' => $tag['name'], 'url' => $this->get_tag_url($slug)); } } $this->set_site_cache($key, $tags); return $tags; } /** * Returns all sitewide posts that use the given tag slug. * * @param string $slug the tag of the slug * @return array a list of posts using the given tag * * @since 0.1 */ public function get_tagged_posts($slug) { global $nxtdb; return $nxtdb->get_results($nxtdb->prepare("\n\t\t\tSELECT p.*, p.cb_sw_blog_id\n\t\t\tFROM {$this->sw_tables->posts} AS p, {$this->sw_tables->tags} AS t, {$this->sw_tables->tag_usage} AS tu\n\t\t\tWHERE t.slug = %s AND t.term_id = tu.uses_tag AND tu.post_id = p.ID AND tu.blog_id = p.cb_sw_blog_id\n\t\t\tORDER BY post_date DESC ", ClassBlogs_Utils::slugify($slug))); } } ClassBlogs::register_plugin('sitewide_tags', 'ClassBlogs_Plugins_Aggregation_SitewideTags', __('Student Tags', 'classblogs'), __('Provides a sitewide tag cloud widget, and allows uses of a single tag to be viewed across all student blogs.', 'classblogs'), false);
* Possibly upgrade the plugin if a version difference is detected. * * This checks whether the stored version on the database is greater than * the current version of the plugin. * * @since 0.3 */ public static function maybe_upgrade() { // Check the version stored on the database, setting it if none is found $db_version = get_site_option('cb_version'); if (empty($db_version)) { $db_version = ClassBlogs_Settings::VERSION; update_site_option('cb_version', $db_version); } // If the version on the database is less than the current version, call // the upgrade script on all of the plugins if (version_compare($db_version, ClassBlogs_Settings::VERSION, '<')) { foreach (self::get_all_plugins() as $plugin) { if (is_callable(array($plugin->plugin, 'upgrade'))) { $plugin->plugin->upgrade($db_version, ClassBlogs_Settings::VERSION); } } update_site_option('cb_version', ClassBlogs_Settings::VERSION); } } } ClassBlogs::register_plugin('class_blogs', 'ClassBlogs', __('Class Blogs', 'classblogs'), __('The base class-blogs plugin that is used to manage plugin registration.', 'classblogs'), false); // Delay including dependencies ClassBlogs::require_cb_file('Settings.php'); ClassBlogs::require_cb_file('NXTClass.php');
<?php nxt_nonce_field($this->get_uid()); ?> <p class="submit"> <input type="submit" class="button-primary" name="Submit" value="<?php _e('Update Sudent Data Options', 'classblogs'); ?> " /> <input type="submit" name="Refresh" value="<?php _e('Refresh Student Data', 'classblogs'); ?> " /> </p> </form> </div> <?php } /** * Update the tables whenever an upgrade is needed. * * @since 0.3 */ public function upgrade($old, $new) { $this->_create_tables(); } } ClassBlogs::register_plugin('sitewide_aggregator', 'ClassBlogs_Plugins_Aggregation_Aggregator', __('Sitewide Aggregator', 'classblogs'), __('Handles post, comment and tag data from all blogs on the site.', 'classblogs'), false);