/**
     * 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 #2
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 
    }
 /**
  * Gets a list of recent posts formatted for display in a widget.
  *
  * The array of returned posts contains custom object instances with the
  * following properties that can be used by the widget:
  *
  *      content   - the content of the post
  *      meta      - a string describing the post's meta, constructed from
  *                  the meta formatting string passed to this method
  *      permalink - the permalink URL for the post
  *      title     - the title of the post
  *
  * @param  int    $max_posts          the maximum number of posts to return
  * @param  int    $max_posts_per_blog the most posts allowed per blog
  * @param  string $meta_format        the formatting string for the post meta
  * @return array                      an array of formatted posts
  *
  * @since 0.2
  */
 public function get_posts_for_widget($max_posts, $max_posts_per_blog, $meta_format)
 {
     // Use cache values if possible
     $cached = $this->get_site_cache('widget');
     if ($cached !== null) {
         return $cached;
     }
     $posts = array();
     $raw_posts = $this->limit_sitewide_resources($this->get_sitewide_posts(), $max_posts, $max_posts_per_blog);
     $student_ids = ClassBlogs_Students::get_student_user_ids();
     foreach ($raw_posts as $post) {
         // Ignore the post if it's not by a student
         if (!in_array($post->post_author, $student_ids)) {
             continue;
         }
         // Create a string for the post metadata
         $meta = "";
         if ($meta_format) {
             $user_data = get_userdata($post->post_author);
             $blog = sprintf('<a href="%s" class="cb-sitewide-post-blog">%s</a>', ClassBlogs_NXTClass::get_blogaddress_by_id($post->cb_sw_blog_id), ClassBlogs_NXTClass::get_blog_option($post->cb_sw_blog_id, 'blogname'));
             $meta = ClassBlogs_Utils::format_user_string($meta_format, array('author' => $user_data->display_name, 'blog' => $blog, 'date' => mysql2date(get_option('date_format'), $post->post_date), 'time' => mysql2date(get_option('time_format'), $post->post_date)), 'cb-sitewide-post');
         }
         $posts[] = (object) array('content' => $post->post_content, 'meta' => $meta, 'permalink' => ClassBlogs_NXTClass::get_blog_permalink($post->cb_sw_blog_id, $post->ID), 'title' => $post->post_title);
     }
     $this->set_site_cache('widget', $posts);
     return $posts;
 }
Example #4
0
 /**
  * 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;
 }
 /**
  * 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;
 }
Example #6
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;
 }
 /**
  * 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);
 }
Example #8
0
    /**
     * 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 
    }
 /**
  * Gets information about all queued YouTube videos and applies it to the
  * stored videos in the local playlist.
  *
  * After fetching the video info, the queue of videos is cleared.
  *
  * @access private
  * @since 0.4
  */
 private function _retrieve_queued_video_info()
 {
     // Abort if we have no videos in the queue
     global $nxtdb;
     $queue = $this->get_option('info_queue');
     if (empty($queue)) {
         return;
     }
     // Request information on all videos in the queue using a single connection
     $conn = new ClassBlogs_Http(self::_YOUTUBE_VIDEO_INFO_URL_TEMPLATE);
     $queue_length = count($queue) - 1;
     for ($i = 0; $i <= $queue_length; $i++) {
         $request = sprintf(self::_YOUTUBE_VIDEO_INFO_URL_TEMPLATE, $queue[$i]);
         $conn->add_request_line("GET {$request} HTTP/1.1\r\n");
         if ($i != $queue_length) {
             $conn->add_request_line("\r\n");
         }
     }
     $responses = $conn->get_responses();
     $conn->close_connection();
     // Update each video in the local playlist with the information found
     // in the YouTube API response
     foreach ($responses as $response) {
         $xml = ClassBlogs_Utils::xml_from_string($response->body);
         $title = ClassBlogs_Utils::get_single_xml_tag_value($xml, 'title');
         $youtube_id = ClassBlogs_Utils::get_single_xml_tag_value($xml, 'videoid', self::_YT_NAMESPACE);
         if ($title && $youtube_id) {
             $nxtdb->query($nxtdb->prepare("\n\t\t\t\t\tUPDATE {$this->tables->videos}\n\t\t\t\t\tSET title = %s\n\t\t\t\t\tWHERE youtube_id = %s", $title, $youtube_id));
         }
     }
     // Clear the queue
     $this->update_option('info_queue', array());
 }
Example #10
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;
 }
Example #11
0
    /**
     * Outputs markup for making minor changes to the admin page's styles
     *
     * @access private
     * @since 0.2
     */
    public function _add_admin_styles()
    {
        printf('
			<style type="text/css">
				#icon-class-blogs {
					background-image: url("%1$s/%2$s");
					height: 32px;
					width: 32px;
				}
			</style>
			<link rel="stylesheet" href="%3$sadmin.css" />', ClassBlogs_Utils::get_base_images_url(), $this->_get_admin_color_scheme() === 'fresh' ? 'icon32.png' : 'icon32-vs.png', ClassBlogs_Utils::get_base_css_url());
    }
Example #12
0
 /**
  * Returns all sitewide posts that use the given tag slug.
  *
  * @param  string $slug the tag of the slug
  * @return array        a list of posts using the given tag
  *
  * @since 0.1
  */
 public function get_tagged_posts($slug)
 {
     global $nxtdb;
     return $nxtdb->get_results($nxtdb->prepare("\n\t\t\tSELECT p.*, p.cb_sw_blog_id\n\t\t\tFROM {$this->sw_tables->posts} AS p, {$this->sw_tables->tags} AS t, {$this->sw_tables->tag_usage} AS tu\n\t\t\tWHERE t.slug = %s AND t.term_id = tu.uses_tag AND tu.post_id = p.ID AND tu.blog_id = p.cb_sw_blog_id\n\t\t\tORDER BY post_date DESC ", ClassBlogs_Utils::slugify($slug)));
 }
Example #13
0
 /**
  * Returns the escaped URL for the given page of a paginated data set.
  *
  * @param  int    $page the page number
  * @return string       the escaped URL of the page
  *
  * @access private
  * @since 0.1
  */
 private function _make_page_url($page)
 {
     $url = ClassBlogs_Utils::get_current_url();
     $query = parse_url($url, PHP_URL_QUERY);
     if ($query) {
         $url = preg_replace('/\\?.*/', '', $url);
     }
     $query = $_GET;
     $query['paged'] = $page;
     return esc_url($url . '?' . http_build_query($query));
 }
 /**
  * Gets a list of recent comments formatted for display in a widget.
  *
  * The array of returned comments contains custom object instances with the
  * following properties that can be used by the widget:
  *
  *      author_name - the display name of the comment's author
  *      content     - the content of the comment
  *      meta        - a string describing the comment's meta, constructed from
  *                    the meta formatting string passed to this method
  *      permalink   - the permalink URL for the comment
  *      post_title  - the name of the post on which the comment was made
  *
  * @param  int    $max_comments          the maximum number of comments to return
  * @param  int    $max_comments_per_blog the most comments allowed per blog
  * @param  string $meta_format           the formatting string for the comment meta
  * @return array                         an array of formatted comments
  *
  * @since 0.2
  */
 public function get_comments_for_widget($max_comments, $max_comments_per_blog, $meta_format)
 {
     // Use cached values if possible
     $cached = $this->get_site_cache('widget');
     if ($cached !== null) {
         return $cached;
     }
     $comments = array();
     $raw_comments = $this->limit_sitewide_resources($this->get_sitewide_comments(), $max_comments, $max_comments_per_blog);
     $student_ids = ClassBlogs_Students::get_student_user_ids();
     foreach ($raw_comments as $comment) {
         // Ignore the comment if it's not by a student
         if (!in_array($comment->user_id, $student_ids)) {
             continue;
         }
         // Create a string for the comment metadata
         $meta = "";
         if ($meta_format) {
             $blog = sprintf('<a href="%s">%s</a>', ClassBlogs_NXTClass::get_blogaddress_by_id($comment->cb_sw_blog_id), ClassBlogs_NXTClass::get_blog_option($comment->cb_sw_blog_id, 'blogname'));
             $meta = ClassBlogs_Utils::format_user_string($meta_format, array('blog' => $blog, 'date' => mysql2date(get_option('date_format'), $comment->comment_date), 'time' => mysql2date(get_option('time_format'), $comment->comment_date)), 'cb-sitewide-comment');
         }
         // Build the permalink to the comment using the post URL and an anchor
         $permalink = sprintf('%s#comment-%d', ClassBlogs_NXTClass::get_blog_permalink($comment->cb_sw_blog_id, $comment->comment_post_ID), $comment->comment_ID);
         $comments[] = (object) array('author_name' => $comment->comment_author, 'content' => $comment->comment_content, 'meta' => $meta, 'permalink' => $permalink, 'post_title' => $comment->post_title);
     }
     $this->set_site_cache('widget', $comments);
     return $comments;
 }
Example #15
0
 /**
  * Registers a widget that should only be available on the root blog.
  *
  * This makes the widget only appear as a selection on the admin side if the
  * user is an admin on the root blog and the root blog is being edited, but
  * will show the widget to any user viewing the root blog.
  *
  * @param object $widget an instance of the widget class
  *
  * @since 0.2
  */
 public static function register_root_only_widget($widget)
 {
     global $blog_id;
     // If we're currently on the root blog, see if we're either viewing the
     // public-facing part of the blog or are a user with admin rights viewing
     // the admin side.  If so, register the widget.
     if (ClassBlogs_Utils::is_root_blog() && (!is_admin() || ClassBlogs_Utils::current_user_is_admin_on_root_blog())) {
         register_widget($widget);
     }
 }
 /**
  * Formats the blog display name based upon the formatting string.
  *
  * @param  string $format  the formatting string for the display name
  * @param  int    $user_id the ID of the student who owns the blog
  * @param  int    $blog_id the ID of the blog
  * @return string          the formatted blog display name
  *
  * @access private
  * @since 0.2
  */
 private function _format_blog_display_name($format, $user_id, $blog_id)
 {
     $blog_title = ClassBlogs_NXTClass::get_blog_option($blog_id, 'blogname');
     $first_name = get_user_meta($user_id, 'first_name', true);
     $last_name = get_user_meta($user_id, 'last_name', true);
     $blog_name = ClassBlogs_Utils::format_user_string($format, array('blog' => $blog_title, 'firstname' => $first_name, 'lastname' => $last_name, 'nickname' => get_user_meta($user_id, 'nickname', true)), 'cb-student-blog');
     // If the blog name is the same as that of the main blog, use the
     // student's full name instead
     $main_blog_title = ClassBlogs_NXTClass::get_blog_option(ClassBlogs_Settings::get_root_blog_id(), 'blogname');
     if ($blog_title === $main_blog_title) {
         $blog_name = $first_name . " " . $last_name;
     }
     return $blog_name;
 }
Example #17
0
 /**
  * Enables a possible admin page associated with a child plugin.
  *
  * This simply provides a shortcut for any child plugins to register an admin
  * page that is part of the class blogs menu group.  A child plugin can override
  * the `enable_admin_page` method called by this to register an admin page.
  *
  * @access private
  * @since 0.1
  */
 public function _maybe_enable_admin_page()
 {
     if (ClassBlogs_Utils::on_root_blog_admin()) {
         $admin = ClassBlogs_Admin::get_admin();
         $this->enable_admin_page($admin);
     }
 }