예제 #1
1
    /**
     * 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);
        }
    }
예제 #2
0
    /**
     * Handles the admin logic for the student-blogs widget.
     */
    public function form($instance)
    {
        $instance = $this->maybe_apply_instance_defaults($instance);
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title', 'classblogs');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo $this->safe_instance_attr($instance, 'title');
        ?>
" />
		</p>
		<p>
			<label for="<?php 
        echo $this->get_field_id('display');
        ?>
"><?php 
        _e('Display Format', 'classblogs');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('display');
        ?>
" name="<?php 
        echo $this->get_field_name('display');
        ?>
" type="text" value="<?php 
        echo $this->safe_instance_attr($instance, 'display');
        ?>
" />
		</p>
		<h4><?php 
        _e('Format variables you can use', 'classblogs');
        ?>
:</h4>
		<p>
			<?php 
        if (ClassBlogs_Utils::is_multisite()) {
            ?>
				<strong>%blog%</strong><br />
				<?php 
            _e("The name of the student's blog", 'classblogs');
            ?>
<br /><br />
			<?php 
        }
        ?>
			<strong>%firstname%</strong><br />
			<?php 
        _e("The student's first name", 'classblogs');
        ?>
<br /><br />
			<strong>%lastname%</strong><br />
			<?php 
        _e("The student's last name", 'classblogs');
        ?>
<br /><br />
			<strong>%nickname%</strong><br />
			<?php 
        _e("The student's nickname", 'classblogs');
        ?>
		</p>
<?php 
    }
예제 #3
0
    /**
     * 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 
    }
예제 #4
0
 /**
  * Adds an admin page for the plugin to the class blogs admin menu.
  *
  * @access protected
  * @since 0.2
  */
 protected function enable_admin_page($admin)
 {
     if (ClassBlogs_Utils::is_multisite()) {
         $admin->add_admin_page($this->get_uid(), __('Student Blog Links', 'classblogs'), array($this, '_admin_page'));
     }
 }
예제 #5
0
 /**
  * Returns a list of information about each student blog.
  *
  * The blog information will be returned as an array, with keys of user IDs.
  * Each key's values will be an object with the following attributes:
  *
  *     blog_id - the possible ID of the blog
  *     url     - the URL of the blog
  *
  * If running in multisite mode, `blog_id` will be the ID of the user's
  * blog.  If running in single-site mode, however, it will be null, as only
  * one blog exists, and the blog URL is of the author archive page.
  *
  * @return array information on all student blogs
  *
  * @since 0.5
  */
 public static function get_student_blogs()
 {
     $blogs = array();
     // Cycle through every student
     foreach (self::get_student_user_ids() as $student_id) {
         // Add the first non-root blog on which the student is an admin if
         // running in multisite mode, or use their author archive URL if
         // running in single-site mode
         $blog_info = array();
         if (ClassBlogs_Utils::is_multisite()) {
             foreach (ClassBlogs_Utils::get_non_root_blog_ids() as $blog_id) {
                 $admins = get_users("blog_id={$blog_id}&include={$student_id}&role=administrator");
                 if (count($admins) == 1) {
                     $blog_info = array('blog_id' => $blog_id, 'url' => ClassBlogs_NXTClass::get_blogaddress_by_id($blog_id));
                     break;
                 }
             }
         } else {
             $blog_info = array('blog_id' => null, 'url' => get_author_posts_url($student_id));
         }
         if (!empty($blog_info)) {
             $blogs[$student_id] = (object) $blog_info;
         }
     }
     return $blogs;
 }
예제 #6
0
 /**
  * Prevents sitewide post IDs from conflicting with pages or posts on the
  * blog that is displaying them.
  *
  * This function should be called whenever a sitewide plugin overrides the
  * posts for a given page using the `the_posts` filter.  Since one or more
  * of the sitewide posts might have an ID that is the same as a post or page
  * on the blog that is displaying them, this function gives every sitewide
  * post an invalid ID.  It also keeps a record of the actual post IDs, which
  * can be used to restore the sitewide posts' IDs when needed, such as when
  * a theme enters the loop.
  *
  * @param  array $posts the posts used to replace the normal page's posts
  * @return array        the posts with invalid IDs
  *
  * @access protected
  * @since 0.2
  */
 protected function prevent_sitewide_post_id_conflicts($posts)
 {
     // Don't do any manipulating if we're not running in multisite mode, as
     // each post's ID will already have the correct value
     if (!ClassBlogs_Utils::is_multisite()) {
         return;
     }
     // Give each post an invalid ID, but store the correct IDs for later use
     $this->_sitewide_post_ids = array();
     for ($i = 0; $i < count($posts); $i++) {
         $this->_sitewide_post_ids[$i] = $posts[$i]->ID;
         $posts[$i]->ID = -1;
     }
     return $posts;
 }
예제 #7
0
 /**
  * Applies the student's chosen pseudonym.
  *
  * This updates the student's user and blog information, then attempts to
  * update any references to the old URL, such as those used by media embedded
  * into posts on the blog whose URL is being changed.
  *
  * The inputs for this function will have already been validated by another
  * method, so it can be assumed that they are valid.
  *
  * @param  int    $user_id        the student's user ID
  * @param  int    $blog_id        the ID of the student's primary blog
  * @param  string $new_username   the student's new username
  *
  * @access private
  * @since 0.1
  */
 private function _apply_pseudonym($user_id, $blog_id, $new_username)
 {
     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);
 }
예제 #8
0
 /**
  * Returns a list of all blog IDs on the site.
  *
  * @return array a list of all blog IDs on the site
  *
  * @since 0.2
  */
 public static function get_all_blog_ids()
 {
     global $nxtdb;
     // If running in single-site mode, just return the ID of the only blog
     if (!ClassBlogs_Utils::is_multisite()) {
         return array(ClassBlogs_Settings::get_root_blog_id());
     }
     // If running in multisite, fetch all blog IDs
     $blog_ids = array();
     $blogs = $nxtdb->get_results($nxtdb->prepare("\n\t\t\tSELECT blog_id FROM {$nxtdb->blogs}\n\t\t\tWHERE site_id = %d AND archived = '0' AND deleted = '0'", $nxtdb->siteid));
     foreach ($blogs as $blog) {
         $blog_ids[] = $blog->blog_id;
     }
     return $blog_ids;
 }
예제 #9
0
 /**
  * Enables the sitewide tag cloud widget.
  *
  * @access private
  * @since 0.1
  */
 public function _enable_widget()
 {
     // Only enable the widget if we're running in multisite mode
     if (ClassBlogs_Utils::is_multisite()) {
         ClassBlogs_Widget::register_root_only_widget('_ClassBlogs_Plugins_Aggregation_SitewideTagsWidget');
     }
 }