/** * 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 }
/** * Handles the admin page logic for the sitewide posts plugin. * * @access private * @since 0.2 */ public function _options_admin_page() { if ($_POST) { check_admin_referer($this->get_uid()); $options = $this->get_options(); $options['root_excerpt_words'] = absint(ClassBlogs_Utils::sanitize_user_input($_POST['root_excerpt_words'])); $options['root_show_posts'] = ClassBlogs_Utils::checkbox_as_bool($_POST, 'root_show_posts'); $options['root_strip_formatting'] = ClassBlogs_Utils::checkbox_as_bool($_POST, 'root_strip_formatting'); $options['root_use_excerpt'] = ClassBlogs_Utils::checkbox_as_bool($_POST, 'root_use_excerpt'); $this->update_options($options); ClassBlogs_Admin::show_admin_message(__('Your sitewide post options have been updated', 'classblogs')); } ?> <div class="wrap"> <?php ClassBlogs_Admin::show_admin_icon(); ?> <h2><?php _e('Student Post Options', 'classblogs'); ?> </h2> <p> <?php _e('This page allows you to control options that will affect the display of student posts on the home page of the root blog.', 'classblogs'); ?> </p> <form method="post" action=""> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Show Student Posts On Root Blog', 'classblogs'); ?> </th> <td> <input type="checkbox" name="root_show_posts" id="root-show-posts" <?php echo $this->option_to_selected_attribute('root_show_posts'); ?> /> <label for="root-show-posts"><?php _e('Enabled', 'classblogs'); ?> </label> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Remove Post Formatting', 'classblogs'); ?> </th> <td> <input type="checkbox" name="root_strip_formatting" id="root-strip-formatting" <?php echo $this->option_to_selected_attribute('root_strip_formatting'); ?> /> <label for="root-strip-formatting"><?php _e('Enabled', 'classblogs'); ?> </label> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Only Show Post Excerpt', 'classblogs'); ?> </th> <td> <input type="checkbox" name="root_use_excerpt" id="root-use-excerpt" <?php echo $this->option_to_selected_attribute('root_use_excerpt'); ?> /> <label for="root-use-excerpt"><?php _e('Enabled', 'classblogs'); ?> </label><br /><br /> <input type="text" name="root_excerpt_words" id="root-excerpt-words" value="<?php echo esc_attr($this->get_option('root_excerpt_words')); ?> " size="4" /><br /> <label for="root-excerpt-words"><?php _e('Excerpt length (in words)', '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 Student Post Options', 'classblogs'); ?> " /></p> </form> </div> <?php }
/** * Handles the logic to display the pseudonym admin page to a student. * * @access private * @since 0.1 */ public function _admin_page() { // Get information on the user and their blog URL $current_user = nxt_get_current_user(); $username = $current_user->user_login; $blog_url = home_url(); // Validate the pseudonym $username_valid = true; if ($_POST) { // Apply the pseudonym to the user and their blog if the username // does not conflict with an existing user or blog check_admin_referer($this->get_uid()); $username = ClassBlogs_Utils::sanitize_user_input($_POST['new_username']); $username_valid = $this->_validate_username($username); if ($username_valid) { global $blog_id; $current_user = nxt_get_current_user(); $this->_apply_pseudonym($current_user->ID, $blog_id, $username); // Display the updated information to the user $blog_url = home_url(); $message = array(__('You successfully changed your username. Your new user information is as follows.', 'classblogs'), '<p>'); $message[] = sprintf('<strong>%s</strong><br />%s<br /><br />', __('Username', 'classblogs'), esc_html($username)); if (ClassBlogs_Utils::is_multisite()) { $message[] = sprintf('<strong>%s</strong><br />%s<br /><br />', __('Blog URL', 'classblogs'), sprintf('<a href="%1$s">%1$s</a>', esc_url($blog_url))); } $message[] = '</p>'; ClassBlogs_Admin::show_admin_message(implode("\n", $message)); } else { if (!$username) { $error = __('You cannot have a blank username.', 'classblogs'); } else { $error = sprintf(__('The username %s is invalid or conflicts with another user or blog. Please choose a different username.', 'classblogs'), '<strong>' . esc_html($username) . '</strong>'); } ClassBlogs_Admin::show_admin_error($error); } } ?> <div class="wrap"> <div id="icon-users" class="icon32"></div> <h2><?php _e('Change Username', 'classblogs'); ?> </h2> <p id="student-pseudonym-instructions"> <?php _e('If you have already changed your display name but still wish for there to be no trace of your actual identity on the blog, you can use this page to change the username that you use to log in to the blog.', 'classblogs'); ?> </p> <form method="post" action="" id="cb-username-form"> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('New Username', 'classblogs'); ?> </th> <td> <input type="text" name="new_username" id="new-username" /><br /> <label for="new-username"><?php _e('Changing this will change the username that you use to access your blog and the URL at which it can be found.', 'classblogs'); ?> </label> <hr /> <label for="new-username"> <?php printf(__('Your current username is %s', 'classblogs'), '<strong>' . esc_html($current_user->user_login) . '</strong>'); ?> </label><br /> <?php if (ClassBlogs_Utils::is_multisite()) { ?> <label for="new-username"> <?php printf(__('Your current blog URL is %s', 'classblogs'), sprintf('<a href="%1$s">%1$s</a>', esc_url($blog_url))); ?> </label> <?php } ?> </td> </tr> </table> <?php nxt_nonce_field($this->get_uid()); ?> <p class="submit"><input class="button-primary" type="submit" name="Submit" value="<?php _e('Change Username', 'classblogs'); ?> " /></p> <strong style="color: #a00">You will only be able to change your username once</strong> </form> <script type="text/javascript"> jQuery("#cb-username-form").submit(function() { return confirm( "<?php _e('You can only change your username once. Are you sure that you wish to change it now?', 'classblogs'); ?> " ); }); </script> </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 }