/**
  * 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'));
     }
 }
 /**
  * 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 #3
0
 /**
  * Returns a list of all non-root blog IDs on the site.
  *
  * When not running in multisite mode, this will always return an empty array.
  *
  * @return array a list of all non-root blog IDs on the site
  *
  * @since 0.5
  */
 public static function get_non_root_blog_ids()
 {
     $blogs = self::get_all_blog_ids();
     $root_index = array_search(ClassBlogs_Settings::get_root_blog_id(), $blogs);
     if ($root_index !== false) {
         unset($blogs[$root_index]);
     }
     return $blogs;
 }
 /**
  * Creates the page used for showing all embedded videos.
  *
  * @access private
  * @since 0.4
  */
 private function _create_playlist_page()
 {
     ClassBlogs_NXTClass::switch_to_blog(ClassBlogs_Settings::get_root_blog_id());
     $current_page = $this->get_option('playlist_page_id');
     $page_id = ClassBlogs_PluginPage::create_plugin_page(self::_PLAYLIST_PAGE_DEFAULT_NAME, sprintf('[%s]', self::_PLAYLIST_SHORTCODE), $current_page);
     if ($page_id != $current_page) {
         $this->update_option('playlist_page_id', $page_id);
     }
     ClassBlogs_NXTClass::restore_current_blog();
 }
Example #5
0
 /**
  * Creates a page for the plugin with the given name on the root blog.
  *
  * This makes a new page for the plugin, and adds it to the list of plugin
  * pages, which is used to make the page visible but not shown automatically
  * in the list of pages on a site that appears at the top of manyt hemes.
  *
  * An optional existing page ID can be passed in.  If this argument is given
  * and the page ID does not map to a valid page, the page is recreated.  If
  * the page ID represents an extant and valid page, however, no action is
  * taken except for making sure that the page is registered in the list
  * of plugin-created pages.
  *
  * @param  string $name    the name of the page to create
  * @param  string $content the desired content of the page
  * @param  int    $page_id the optional ID of an already created page
  * @return int             the ID of the created page
  *
  * @access protected
  * @since 0.1
  */
 public static function create_plugin_page($name, $content = '', $page_id = null)
 {
     $conflicts = true;
     $counter = 0;
     $page_name = $name;
     // If a page with the given ID already exists, abort early
     if ($page_id && get_page($page_id)) {
         self::_register_plugin_page($page_id);
         return $page_id;
     }
     // Find a name for the new page that doesn't conflict with others
     while ($conflicts) {
         $page = get_page_by_title($page_name);
         if (isset($page)) {
             $counter++;
             $page_name = sprintf('%s %d', $name, $counter);
         } else {
             $conflicts = false;
         }
     }
     // Create the new page and store its ID
     $new_page = array('post_author' => ClassBlogs_Settings::get_admin_user_id(), 'post_content' => $content, 'post_status' => 'publish', 'post_title' => $page_name, 'post_type' => 'page');
     $page_id = nxt_insert_post($new_page);
     self::_register_plugin_page($page_id);
     return $page_id;
 }
 /**
  * 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;
 }
Example #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();
 }