예제 #1
0
 /**
  * Registers hooks and sets default options for the plugin.
  *
  * @access private
  * @since 0.3
  */
 public function _register_hooks()
 {
     // If we're not running multisite, this plugin has no purpose, so we
     // should abort
     if (!ClassBlogs_Utils::is_multisite()) {
         return;
     }
     // Update the default links options to be a single link pointing back
     // to the main class blog
     ClassBlogs_NXTClass::switch_to_blog(ClassBlogs_Settings::get_root_blog_id());
     $this->default_options['links'] = array(array('url' => site_url(), 'title' => __('Return to Course Blog', 'classblogs')));
     ClassBlogs_NXTClass::restore_current_blog();
     // If there are any links defined and we're not in the admin side,
     // inject the professor's links into a widget in the first widgetized
     // area of all student blogs in the network
     $links = $this->get_option('links');
     if (!is_admin() && !empty($links)) {
         add_action('init', array($this, '_register_widget'));
         add_filter('sidebars_widgets', array($this, '_add_widget'));
     }
 }
예제 #2
0
 /**
  * Restores the root blog after the loop has ended.
  *
  * This needs to be called to prevent the blog from thinking it is on the
  * blog on which the last sitewide post displayed was made, which will result
  * in display and URL-resolution issues.
  *
  * @since 0.3
  */
 public function reset_blog_on_loop_end()
 {
     global $nxt_query, $nxt_rewrite;
     ClassBlogs_NXTClass::restore_current_blog();
     if (isset($this->root_blog_posts)) {
         $nxt_query->posts = $this->root_blog_posts;
     }
     if (isset($this->_rewrite)) {
         $nxt_rewrite = $this->_rewrite;
     }
 }
예제 #3
0
 /**
  * Finds the post object for the first post that uses the given image.
  *
  * @param  int    $blog_id the ID of the blog on which the image was uploaded
  * @param  string $url     the absolute URL of the image
  * @return object          a NXTClass post instance for the image
  *
  * @access private
  * @since 0.1
  */
 private function _find_first_post_to_use_image($blog_id, $url)
 {
     global $nxtdb;
     $post = null;
     // Search for the first post that references the image
     ClassBlogs_NXTClass::switch_to_blog($blog_id);
     $post_search = $nxtdb->prepare("\n\t\t\tSELECT * FROM {$nxtdb->posts}\n\t\t\tWHERE post_status='publish'\n\t\t\tAND post_content LIKE '%%" . like_escape($url) . "%%'\n\t\t\tORDER BY post_date\n\t\t\tLIMIT 1");
     $post = $nxtdb->get_row($post_search);
     ClassBlogs_NXTClass::restore_current_blog();
     return $post;
 }
예제 #4
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);
 }
 /**
  * Returns markup for the local videos page.
  *
  * @return string markup for the local playlist page
  *
  * @access private
  * @since 0.1
  */
 public function _render_playlist_page()
 {
     $markup = "";
     foreach ($this->get_playlist_videos() as $index => $video) {
         // Add the video with a title
         $markup .= '<div class="cb-youtube-local-playlist-page-video post hentry">';
         $markup .= '<h2 class="cb-youtube-local-playlist-page-title"><a href="' . esc_url($video->link) . '" title="' . __('View on YouTube', 'classblogs') . '">' . esc_html($video->title) . '</a></h2>';
         $markup .= '<div class="cb-youtube-local-playlist-page-video-thumbnail-container">';
         $markup .= sprintf('<a href="%1$s"><img src="%2$s" title="%3$s" alt="%3$s" data-youtube-id="%4$s" class="cb-youtube-local-playlist-page-video-thumbnail" /></a>', esc_url($video->link), esc_url($this->_get_large_thumbnail_url($video->youtube_id)), esc_attr($video->title), esc_attr($video->youtube_id));
         $markup .= '</div>';
         // Add metadata for the video
         $markup .= sprintf('<p class="cb-youtube-local-playlist-page-meta">%s</p>', sprintf(__('Added to the playlist on %s', 'classblogs'), sprintf('<time datetime="%s" class="cb-youtube-local-playlist-page-date">%s</time>', date('c', strtotime($video->date_added)), esc_html(date_i18n(get_option('date_format'), strtotime($video->date_added))))));
         if (!empty($video->used_by)) {
             $markup .= '<p class="cb-youtube-local-playlist-page-usage">' . __('Embedded in', 'classblogs') . ' ';
             $links = array();
             foreach ($video->used_by as $usage) {
                 $link = '<a class="cb-youtube-local-playlist-page-usage-post" ';
                 ClassBlogs_NXTClass::switch_to_blog($usage->blog_id);
                 $link .= sprintf(' href="%s">%s</a>', esc_url(get_permalink($usage->post_id)), get_post($usage->post_id)->post_title);
                 ClassBlogs_NXTClass::restore_current_blog();
                 $links[] = $link;
             }
             $markup .= implode(', ', $links) . '</p>';
         }
         $markup .= '</div>';
     }
     return $markup;
 }
예제 #6
0
 /**
  * Returns the URL for the tag-list page.
  *
  * @return string the URL for the tag-list page
  *
  * @access private
  * @since 0.2
  */
 private function _get_tag_page_url()
 {
     ClassBlogs_NXTClass::switch_to_blog(ClassBlogs_Settings::get_root_blog_id());
     $url = get_permalink($this->get_option('tag_page_id'));
     ClassBlogs_NXTClass::restore_current_blog();
     return $url;
 }
예제 #7
0
 /**
  * Toggles the active status of the class blogs suite.
  *
  * @param bool $activate whether to activate or deactivate the plugin suite
  *
  * @since 0.4
  */
 public static function _set_activation($activate)
 {
     $method = $activate ? 'activate' : 'deactivate';
     ClassBlogs_NXTClass::switch_to_blog(ClassBlogs_Settings::get_root_blog_id());
     foreach (self::get_all_plugins() as $plugin) {
         if (is_callable(array($plugin->plugin, $method))) {
             call_user_func(array($plugin->plugin, $method));
         }
     }
     ClassBlogs_NXTClass::restore_current_blog();
 }
예제 #8
0
 /**
  * Aggregates all sitewide posts, comments and tags into separate tables.
  *
  * @access private
  * @since 0.2
  */
 private function _sync_tables()
 {
     global $nxtdb;
     // Drop all data before proceeding
     $this->_clear_tables();
     $this->clear_site_cache();
     // Export the post and comment data for each blog to our tables, which
     // will also update the tag-usage data
     foreach ($this->_get_usable_blog_ids() as $blog_id) {
         ClassBlogs_NXTClass::switch_to_blog($blog_id);
         foreach ($nxtdb->get_results("SELECT ID FROM {$nxtdb->posts}") as $post) {
             $this->_track_single_post($post->ID);
         }
         foreach ($nxtdb->get_results("SELECT comment_ID FROM {$nxtdb->comments}") as $comment) {
             $this->_track_single_comment($comment->comment_ID);
         }
         ClassBlogs_NXTClass::restore_current_blog();
     }
 }