/** * Shows a professor a list of all student comments. * * @uses ClassBlogs_Plugins_StudentBlogList to get student blog URLs * * @access private * @since 0.2 */ public function _admin_page() { global $blog_id; $current_blog_id = $blog_id; // Create a lookup table of student data keyed by blog ID for multisite mode $students = array(); if (ClassBlogs_Utils::is_multisite()) { foreach (ClassBlogs_Students::get_student_blogs() as $student_id => $blog) { $user_data = get_userdata($student_id); $students[$blog->blog_id] = array('blog_url' => $blog->url, 'name' => sprintf('%s %s', $user_data->first_name, $user_data->last_name)); } } // Paginate the comment data $comments = $this->get_sitewide_comments(false); $paginator = new ClassBlogs_Paginator($comments, self::COMMENTS_PER_ADMIN_PAGE); $current_page = array_key_exists('paged', $_GET) ? absint($_GET['paged']) : 1; ?> <div class="wrap"> <?php ClassBlogs_Admin::show_admin_icon(); ?> <h2><?php _e('Student Comments', 'classblogs'); ?> </h2> <p> <?php _e("This page allows you to view all of the comments that have been left on yours students' blogs.", 'classblogs'); ?> </p> <?php $paginator->show_admin_page_links($current_page); ?> <table class="widefat cb-cw-comments-table" id="cb-sw-student-comments-list"> <thead> <tr> <th class="author"><?php _e('Author', 'classblogs'); ?> </th> <th class="content"><?php _e('Comment', 'classblogs'); ?> </th> <th class="post"><?php _e('Post', 'classblogs'); ?> </th> <?php if (ClassBlogs_Utils::is_multisite()) { ?> <th class="student"><?php _e('Student Blog', 'classblogs'); ?> </th> <?php } ?> <th class="status"><?php _e('Status', 'classblogs'); ?> </th> <th class="posted"><?php _e('Date', 'classblogs'); ?> </th> </tr> </thead> <tfoot> <tr> <th class="author"><?php _e('Author', 'classblogs'); ?> </th> <th class="content"><?php _e('Comment', 'classblogs'); ?> </th> <th class="post"><?php _e('Post', 'classblogs'); ?> </th> <?php if (ClassBlogs_Utils::is_multisite()) { ?> <th class="student"><?php _e('Student Blog', 'classblogs'); ?> </th> <?php } ?> <th class="status"><?php _e('Status', 'classblogs'); ?> </th> <th class="posted"><?php _e('Date', 'classblogs'); ?> </th> </tr> </tfoot> <tbody> <?php foreach ($paginator->get_items_for_page($current_page) as $comment) { ClassBlogs_NXTClass::switch_to_blog($comment->cb_sw_blog_id); $status = nxt_get_comment_status($comment->comment_ID); ?> <tr class="<?php echo $status; ?> "> <td class="author"> <?php printf('%s <strong>%s</strong> <br /> <a href="mailto:%s">%s</a>', get_avatar($comment->comment_author_email, 32), esc_html($comment->comment_author), esc_attr($comment->comment_author_email), esc_html($comment->comment_author_email)); ?> </td> <td class="content"> <?php comment_text($comment->comment_ID); ?> </td> <td class="post"> <strong> <?php printf('<a href="%s">%s</a>', esc_url(ClassBlogs_NXTClass::get_blog_permalink($comment->cb_sw_blog_id, $comment->comment_post_ID)), esc_html($comment->post_title)); ?> </strong> </td> <?php if (ClassBlogs_Utils::is_multisite()) { ?> <td class="student"> <strong> <?php if (array_key_exists($comment->cb_sw_blog_id, $students)) { $blog = $students[$comment->cb_sw_blog_id]; printf('<a href="%s">%s</a>', esc_url($blog['blog_url']), esc_html($blog['name'])); } ?> </strong> </td> <?php } ?> <td class="status"> <?php if ($status == 'approved') { _e('Approved', 'classblogs'); } elseif ($status == 'deleted' || $status == 'trash') { _e('Deleted', 'classblogs'); } elseif ($status == 'spam') { _e('Spam', 'classblogs'); } elseif ($status == 'unapproved') { _e('Unapproved', 'classblogs'); } else { _e('Unknown', 'classblogs'); } ?> </td> <td class="posted"> <?php printf('<span class="date">%s</span> <span class="time">%s</span>', mysql2date(get_option('date_format'), $comment->comment_date), mysql2date(get_option('time_format'), $comment->comment_date)); ?> </td> </tr> <?php } ClassBlogs_Utils::restore_blog($current_blog_id); ?> </tbody> </table> <?php $paginator->show_admin_page_links($current_page, 'bottom'); ?> </div> <?php }
/** * Displays the plugin's admin page. * * @access private * @since 0.2 */ public function _admin_page() { // Change the state of sitewide commenting if switching if ($_POST) { check_admin_referer($this->get_uid()); $this->update_option('comments_disabled', $_POST['comment_status'] === 'disabled'); ClassBlogs_Admin::show_admin_message(__('Your sitewide commenting options have been updated', 'classblogs')); } ?> <div class="wrap"> <?php ClassBlogs_Admin::show_admin_icon(); ?> <h2><?php _e('Disable Commenting', 'classblogs'); ?> </h2> <p> <?php _e('This page allows you to disable commenting on every blog on this site, which includes both the root blog and the student blogs. Any new posts will have commenting disabled by default, and all existing posts will not be able to receive comments.', 'classblogs'); ?> </p> <form method="post" action=""> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Commenting on All Blogs is', 'classblogs'); ?> </th> <td> <input type="radio" name="comment_status" value="enabled" id="comments-enabled" <?php if (!$this->get_option('comments_disabled')) { ?> checked="checked"<?php } ?> /> <label for="comments-enabled"><?php _e('Enabled', 'classblogs'); ?> </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 }
/** * Handles the logic to display the admin page for the plugin. * * @access private * @since 0.2 */ public function _admin_page() { // Update the plugin options if ($_POST) { check_admin_referer($this->get_uid()); $this->update_option('required_weekly_words', absint(ClassBlogs_Utils::sanitize_user_input($_POST['required_weekly_words']))); ClassBlogs_Admin::show_admin_message(__('Your word-counter options been updated.', 'classblogs')); } ?> <div class="wrap"> <?php ClassBlogs_Admin::show_admin_icon(); ?> <h2><?php _e('Student Word Counts', 'classblogs'); ?> </h2> <?php // Show the word-count table if we have word counts $word_counts = $this->_get_weekly_word_counts(); $student_ids = ClassBlogs_Students::get_student_user_ids(); if (!empty($word_counts)) { // Compute the total word counts for each student $total_counts = array(); foreach ($student_ids as $student_id) { $total_counts[$student_id] = 0; foreach ($word_counts as $week_counts) { $total_counts[$student_id] += $week_counts['user_counts'][$student_id]; } } // Precompute each student's name $student_names = array(); foreach ($student_ids as $student_id) { $user_data = get_userdata($student_id); $student_names[$student_id] = $user_data->display_name; } ?> <h3><?php _e('Word Counts by Week', 'classblogs'); ?> </h3> <p id="student-word-counts-instructions"> <?php _e('The table below shows the word counts for each student, drawn from any posts and comments that they have written, broken down by the week for which those counts are calculated. The date displayed in the "Week of" column is for the Monday that started that week.', 'classblogs'); ?> </p> <div id="student-word-counts-wrap"> <table id="student-word-counts"> <thead> <tr> <th class="week"><?php _e('Week of', 'classblogs'); ?> </th> <?php // Show each student's name in the header foreach ($student_ids as $student_id) { printf('<th>%s</th>', esc_html($student_names[$student_id])); } ?> </tr> </thead> <tfoot> <th><?php _e('Totals', 'classblogs'); ?> </th> <?php // Display each student's total words in the footer foreach ($student_ids as $student_id) { printf('<td title="%s">%s</td>', esc_attr($student_names[$student_id]), number_format($total_counts[$student_id])); } ?> </tfoot> <tbody> <?php // Show each week and every student's total words for that week $required_words = $this->get_option('required_weekly_words'); foreach ($word_counts as $week_counts) { echo "<tr>"; $verbose_date = date_i18n('M j, Y', (int) $week_counts['week_start']->format('U')); printf('<th class="week">%s</th>', $verbose_date); $counter = 0; foreach ($student_ids as $student_id) { $classes = array(); $count = $week_counts['user_counts'][$student_id]; if (!$count) { $classes[] = 'null'; } else { if ($count < $required_words) { $classes[] = 'under'; } else { if ($count >= $required_words) { $classes[] = 'over'; } } } $classes[] = $counter % 2 ? 'even' : 'odd'; $counter++; printf('<td title="%s" class="%s">%s</td>', esc_attr(sprintf(__('%1$s on %2$s'), $student_names[$student_id], $verbose_date)), implode(' ', $classes), number_format($count)); } echo "</tr>"; } ?> </tbody> </table> </div> <?php } ?> <h3><?php _e('Options', 'classblogs'); ?> </h3> <form method="post" action=""> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Required Weekly Words', 'classblogs'); ?> </th> <td> <input type="text" name="required_weekly_words" id="required-weekly-words" value="<?php echo esc_attr($this->get_option('required_weekly_words')); ?> " /><br /> <label for="required-weekly-words"><?php _e('The number of words a student must write per week.', '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 Required Word Count', 'classblogs'); ?> " /></p> </form> </div> <?php }
/** * Handles the admin page for the plugin. * * @access private * @since 0.2 */ public function _admin_page() { // Update the plugin options if ($_POST) { check_admin_referer($this->get_uid()); $this->update_option('title', ClassBlogs_Utils::sanitize_user_input($_POST['widget_title'])); $this->update_option('links', $this->_parse_link_list($_POST)); ClassBlogs_Admin::show_admin_message(__('Your links have been updated.', 'classblogs')); } ?> <div class="wrap"> <?php ClassBlogs_Admin::show_admin_icon(); ?> <h2><?php _e('Student Blog Links', 'classblogs'); ?> </h2> <p> <?php _e("This plugin lets you display links of your choosing in the first widgetized area of every student's blog. You can use this to have a link back to the main blog appear on every student's blog, for example.", 'classblogs'); ?> </p> <form method="post" action=""> <h3><?php _e('Options', 'classblogs'); ?> </h3> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Widget Title', 'classblogs'); ?> </th> <td> <input type="text" name="widget_title" id="widget-title" value="<?php echo esc_attr($this->get_option('title')); ?> " /><br /> <label for="widget-title"><?php _e('The title for the the list of links.', 'classblogs'); ?> </label> </td> </tr> </table> <h3><?php _e('Links', 'classblogs'); ?> </h3> <table class="form-table" id="student-blog-links"> <tfoot> <th scope="row"> <a href="#add-link" class="add-link"><?php _e('Add another link', 'classblogs'); ?> </a> </th> <td></td> </tfoot> <tbody> <?php $link_count = max(count($this->get_option('links')), 1); for ($i = 0; $i < $link_count; $i++) { $url_id = 'link_url_' . $i; $title_id = 'link_title_' . $i; $links = $this->get_option('links'); $link = $links[$i]; ?> <tr valign="top" class="link"> <th scope="row"><?php _e('Link', 'classblogs'); ?> </th> <td> <label for="<?php echo esc_attr($title_id); ?> "><?php _e('Title', 'classblogs'); ?> </label> <input type="text" name="<?php echo esc_attr($title_id); ?> " id="<?php echo esc_attr($title_id); ?> " value="<?php echo esc_attr($link['title']); ?> " /> <label style="margin-left: 2em;" for="<?php echo esc_attr($url_id); ?> "><?php _e('URL', 'classblogs'); ?> </label> <input size="40" type="text" name="<?php echo esc_attr($url_id); ?> " id="<?php echo esc_attr($url_id); ?> " 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 }
/** * Shows a professor a list of student posts. * * @uses ClassBlogs_Plugins_StudentBlogList to get student blog URLs * * @access private * @since 0.2 */ public function _posts_admin_page() { // Create a lookup table for student names and blogs keyed by user ID $students = array(); foreach (ClassBlogs_Students::get_student_blogs() as $student_id => $blog) { $user_data = get_userdata($student_id); $students[$student_id] = array('blog_url' => $blog->url, 'name' => sprintf('%s %s', $user_data->first_name, $user_data->last_name)); } // Paginate the data, restricting the data set to student-only posts $student_posts = array(); foreach ($this->get_sitewide_posts() as $post) { if (array_key_exists($post->post_author, $students)) { $student_posts[] = $post; } } $paginator = new ClassBlogs_Paginator($student_posts, self::POSTS_PER_ADMIN_PAGE); $current_page = array_key_exists('paged', $_GET) ? absint($_GET['paged']) : 1; ?> <div class="wrap"> <?php ClassBlogs_Admin::show_admin_icon(); ?> <h2><?php _e('Student Posts', 'classblogs'); ?> </h2> <p> <?php _e('This page allows you to view all of the posts that your students have published.', 'classblogs'); ?> </p> <?php $paginator->show_admin_page_links($current_page); ?> <table class="widefat" id="cb-sw-student-posts-list"> <thead> <tr> <th class="student"><?php _e('Student', 'classblogs'); ?> </th> <th class="post"><?php _e('Post', 'classblogs'); ?> </th> <th class="excerpt"><?php _e('Excerpt', 'classblogs'); ?> </th> <th class="posted"><?php _e('Posted', 'classblogs'); ?> </th> </tr> </thead> <tfoot> <tr> <th class="student"><?php _e('Student', 'classblogs'); ?> </th> <th class="post"><?php _e('Post', 'classblogs'); ?> </th> <th class="excerpt"><?php _e('Excerpt', 'classblogs'); ?> </th> <th class="posted"><?php _e('Posted', 'classblogs'); ?> </th> </tr> </tfoot> <tbody> <?php foreach ($paginator->get_items_for_page($current_page) as $post) { ?> <tr> <td class="student"> <strong> <?php echo get_avatar($post->post_author, 32) . ' '; printf('<a href="%s">%s</a>', $students[$post->post_author]['blog_url'], $students[$post->post_author]['name']); ?> </strong> </td> <td class="post"> <strong> <?php printf('<a href="%s">%s</a>', ClassBlogs_NXTClass::get_blog_permalink($post->cb_sw_blog_id, $post->ID), $post->post_title); ?> </strong> </td> <td class="excerpt"><?php echo ClassBlogs_Utils::make_post_excerpt($post->post_content, 25); ?> </td> <td class="posted"> <?php echo mysql2date(get_option('date_format'), $post->post_date); ?> </td> </tr> <?php } ?> </tbody> </table> <?php $paginator->show_admin_page_links($current_page, 'bottom'); ?> </div> <?php }
/** * Handles the display of the class blogs base admin page. * * @access private * @since 0.2 */ public function _class_blogs_admin_page() { // Disable any plugins that are not checked if ($_POST) { check_admin_referer('classblogs_admin'); // Get a list of all plugins that are checked to be enabled $enabled = array(); foreach ($_POST as $field => $value) { $plugin = str_replace('plugin_', '', $field); if ($plugin !== $field) { $enabled[$plugin] = true; } } // Enable any plugins that were previously disabled, and disable any // that were previously enabled foreach (ClassBlogs::get_user_controlled_plugins() as $plugin) { if (array_key_exists($plugin->id, $enabled)) { if (!$plugin->enabled) { ClassBlogs::enable_plugin($plugin->id); } } else { if ($plugin->enabled) { ClassBlogs::disable_plugin($plugin->id); } } } self::show_admin_message(__('Enabled class-blogs plugins have been updated. You must refresh the page to see the effects of this.'), 'classblogs'); } ?> <div class="wrap"> <?php ClassBlogs_Admin::show_admin_icon(); ?> <h2><?php _e('Class Blogs', 'classblogs'); ?> </h2> <p> <?php _e('The class blogs plugin suite will help you manage a blog for a class where you have control over the main blog and each student has full ownership of a child blog.', 'classblogs'); ?> </p> <p> <?php _e('The plugins that are part of this suite are provided in the list below. Not every plugin has configurable options, but the ones that do will appear as links in the Class Blogs admin menu. If you do not wish to use a certain component of the class-blogs suite, you can uncheck it in the list below and click on the "Update Enabled Plugins" button.', 'classblogs'); ?> </p> <h3><?php _e('Enabled Plugins', 'classblogs'); ?> </h3> <form method="post" action=""> <table id="cb-enabled-plugins"> <thead> <tr> <th class="toggle"><?php _e('Enabled', 'classblogs'); ?> </th> <th class="name"><?php _e('Name', 'classblogs'); ?> </th> <th class="description"><?php _e('Description', 'classblogs'); ?> </th> </tr> </thead> <tbody> <?php // Display each user-controlled plugin $plugins = ClassBlogs::get_user_controlled_plugins(); foreach ($plugins as $plugin) { $field = 'plugin_' . $plugin->id; $name = $plugin->name ? $plugin->name : get_class($plugin->plugin); printf(' <tr> <td class="toggle"> <input type="checkbox" id="%1$s" name="%1$s" %2$s /> </td> <td class="name"> <label for="%1$s">%3$s</label> </td> <td class="description">%4$s</td> </tr>', esc_attr($field), $plugin->enabled ? 'checked="checked"' : '', esc_html($name), esc_html($plugin->description)); } ?> </tbody> </table> <?php nxt_nonce_field('classblogs_admin'); ?> <p class="submit"> <input type="submit" class="button-primary" name="Submit" value="<?php _e('Update Enabled Plugins', 'classblogs'); ?> " /> </p> </form> </div> <?php }
/** * Handles the admin page logic for the plugin. * * @access private * @since 0.1 */ public function _admin_page() { // Perform an update action of some sort if ($_POST) { check_admin_referer($this->get_uid()); // If we're just refreshing the sitewide data, do so now if (array_key_exists('Refresh', $_POST)) { $synced = $this->_create_tables(); if (!$synced) { $this->_sync_tables(); } ClassBlogs_Admin::show_admin_message(__('The sitewide data has been refreshed.', 'classblogs')); } else { $this->update_option('excluded_blogs', $this->_parse_excluded_blog_list($_POST)); $this->update_option('aggregation_enabled', $_POST['aggregation_enabled'] == 'enabled'); $this->_sync_tables(); ClassBlogs_Admin::show_admin_message(__('Your options have been updated.', 'classblogs')); } } ?> <div class="wrap"> <?php ClassBlogs_Admin::show_admin_icon(); ?> <h2><?php _e('Student Data Options', 'classblogs'); ?> </h2> <p> <?php _e("This page allows you to manage the options for collecting data on posts, comments and tags from your students' blogs.", 'classblogs'); ?> </p> <form method="post" action=""> <h3><?php _e('Data Sources', 'classblogs'); ?> </h3> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Aggregation Enabled', 'classblogs'); ?> </th> <td> <input type="radio" name="aggregation_enabled" id="aggregation-enabled" value="enabled" <?php if ($this->get_option('aggregation_enabled')) { ?> checked="checked"<?php } ?> /> <label for="aggregation-enabled"><?php _e('Enabled', 'classblogs'); ?> </label> <input style="margin-left: 1em;" type="radio" name="aggregation_enabled" id="aggregation-disabled" value="disabled" <?php if (!$this->get_option('aggregation_enabled')) { ?> checked="checked"<?php } ?> /> <label for="aggregation-disabled"><?php _e('Disabled', 'classblogs'); ?> </label> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Excluded Blogs', 'classblogs'); ?> </th> <td> <ul> <?php // Display a checkbox for every blog, selecting it if the blog is // currently on the exclusion blacklist $excluded_blogs = $this->get_option('excluded_blogs'); foreach (ClassBlogs_Utils::get_all_blog_ids() as $blog_id) { $details = get_blog_details($blog_id, true); printf('<li><input type="checkbox" id="%1$s" name="%1$s" %2$s /> <label for="%1$s"><strong>%3$s</strong> ( <a href="%4$s">%4$s</a> )</label></li>', 'exclude_blog_' . $blog_id, array_search($blog_id, $excluded_blogs) !== false ? 'checked="checked"' : "", $details->blogname, esc_url($details->siteurl)); } ?> </ul> </td> </tr> </table> <h3><?php _e('Refresh Student Data', 'classblogs'); ?> </h3> <p><?php _e(sprintf('If you find that the student data does not accurately reflect the data in each blog, you can click the %1$s button below to rebuild the student data tables.', '<strong>' . __('Refresh Student Data', 'classblogs') . '</strong>'), 'classblogs'); ?> </p> <?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 }