/** * Returns a random image from one of the blogs on the site. * * The returned image object, if not null, will have the following properties: * * blog_id - the ID of the blog on which the image was posted * title - the image's title * url - the absolute URL to the image * * If the image is associated with a particular post, it will also have * the following properties on it: * * post_id - the ID of the post that uses the image * user_id - the ID of the user who created a post using the image * * @return mixed the random image object, or null if none can be found * * @since 0.1 */ public function get_random_image() { global $blog_id, $nxtdb; $current_blog_id = $blog_id; $image = null; $urls = array(); // Search through every blog for a usable image. If an image is found, build // the link to it and add a possible caption. $blogs = ClassBlogs_Utils::get_all_blog_ids(); shuffle($blogs); foreach ($blogs as $blog) { ClassBlogs_NXTClass::switch_to_blog($blog); $images = $nxtdb->get_results("\n\t\t\t\tSELECT ID, post_title, GUID FROM {$nxtdb->posts}\n\t\t\t\tWHERE post_mime_type LIKE 'image/%%'\n\t\t\t\tAND post_content <> guid"); if ($images) { $image = $images[array_rand($images)]; $urls[] = $image->GUID; $info = nxt_get_attachment_image_src($image->ID); if (!empty($info)) { $image = array('blog_id' => $blog, 'title' => $image->post_title, 'url' => $info[0]); $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; }
/** * Renders the student-only page showing all a list of all comments that * they have left on other blogs on the site. * * @access private * @since 0.2 */ public function _student_admin_page() { global $blog_id; $current_blog_id = $blog_id; $student_id = nxt_get_current_user()->ID; // Create a lookup table for blog names and URLs $all_blogs = array(); foreach (ClassBlogs_Utils::get_all_blog_ids() as $blog_id) { $all_blogs[$blog_id] = array('name' => ClassBlogs_NXTClass::get_blog_option($blog_id, 'blogname'), 'url' => ClassBlogs_NXTClass::get_blogaddress_by_id($blog_id)); } // Paginate the data, restricting the data set to only comments that the // current student wrote $comments = array(); foreach ($this->get_sitewide_comments(false) as $comment) { if ((int) $comment->user_id === $student_id) { $comments[] = $comment; } } $paginator = new ClassBlogs_Paginator($comments, self::COMMENTS_PER_ADMIN_PAGE); $current_page = array_key_exists('paged', $_GET) ? absint($_GET['paged']) : 1; ?> <div class="wrap"> <div id="icon-edit-comments" class="icon32"></div> <h2><?php _e('My Comments', 'classblogs'); ?> </h2> <p> <?php _e("This page allows you to view all of the comments that you have left on other students' blogs.", 'classblogs'); ?> </p> <?php $paginator->show_admin_page_links($current_page); ?> <table class="widefat cb-sw-comments-table" id="cb-sw-my-comments-list"> <thead> <tr> <th class="blog"><?php _e('Blog', 'classblogs'); ?> </th> <th class="post"><?php _e('Post', 'classblogs'); ?> </th> <th class="content"><?php _e('Content', 'classblogs'); ?> </th> <th class="status"><?php _e('Status', 'classblogs'); ?> </th> <th class="posted"><?php _e('Date', 'classblogs'); ?> </th> </tr> </thead> <tfoot> <tr> <th class="blog"><?php _e('Blog', 'classblogs'); ?> </th> <th class="post"><?php _e('Post', 'classblogs'); ?> </th> <th class="content"><?php _e('Content', 'classblogs'); ?> </th> <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="blog"> <strong> <?php printf('<a href="%s">%s</a>', esc_url($all_blogs[$comment->cb_sw_blog_id]['url']), esc_html($all_blogs[$comment->cb_sw_blog_id]['name'])); ?> </strong> </td> <td class="post"> <strong> <?php printf('<a href="%s">%s</a>', esc_url(get_comment_link($comment)), esc_html($comment->post_title)); ?> </strong> </td> <td class="content"> <?php comment_text($comment->comment_ID); ?> </td> <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 }
/** * 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 }