/**
  * Updates the sitewide tag cloud widget.
  */
 public function update($new, $old)
 {
     $instance = $old;
     $instance['max_font_size'] = absint(ClassBlogs_Utils::sanitize_user_input($new['max_font_size']));
     $instance['min_font_size'] = absint(ClassBlogs_Utils::sanitize_user_input($new['min_font_size']));
     $instance['min_usage'] = absint(ClassBlogs_Utils::sanitize_user_input($new['min_usage']));
     $instance['title'] = ClassBlogs_Utils::sanitize_user_input($new['title']);
     return $instance;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Example #4
0
    /**
     * 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 
    }
Example #6
0
 /**
  * Updates the random-image widget.
  */
 public function update($new, $old)
 {
     $old['title'] = ClassBlogs_Utils::sanitize_user_input($new['title']);
     return $old;
 }
    /**
     * 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 
    }