options = get_option( $this->option_name );
		if ( false === $this->options )
			$this->options = array();
		// Include the P2 components
		$includes = array( 'compat', 'terms-in-comments', 'js-locale',
			'mentions', 'search', 'js', 'options-page',
			'template-tags', 'widgets/recent-tags', 'widgets/recent-comments',
			'list-creator' );
		if ( defined('DOING_AJAX') && DOING_AJAX )
			$includes[] = 'ajax';
		foreach ( $includes as $name ) {
			require_once( P2_INC_PATH . "/$name.php" );
		}
		// Add the default P2 components
		$this->add( 'mentions',         'P2_Mentions'         );
		$this->add( 'search',           'P2_Search'           );
		// Bind actions
		add_action( 'init',       array( &$this, 'init'             ) );
		add_action( 'admin_init', array( &$this, 'maybe_upgrade_db' ) );
	}
	function init() {
		// Load language pack
		load_theme_textdomain( 'p2', get_template_directory() . '/languages' );
	}
	/**
	 * Will upgrade the database if necessary.
	 *
	 * When upgrading, triggers actions:
	 *    'p2_upgrade_db_version'
	 *    'p2_upgrade_db_version_$number'
	 *
	 * Flushes rewrite rules automatically on upgrade.
	 */
	function maybe_upgrade_db() {
		if ( ! isset( $this->options['db_version'] ) || $this->options['db_version'] < $this->db_version ) {
			$current_db_version = isset( $this->options['db_version'] ) ? $this->options['db_version'] : 0;
			do_action( 'p2_upgrade_db_version', $current_db_version );
			for ( ; $current_db_version <= $this->db_version; $current_db_version++ ) {
				do_action( "p2_upgrade_db_version_$current_db_version" );
			}
			// Flush rewrite rules once, so callbacks don't have to.
			flush_rewrite_rules();
			$this->set_option( 'db_version', $this->db_version );
			$this->save_options();
		}
	}
	/**
	 * COMPONENTS API
	 */
	function add( $component, $class ) {
		$class = apply_filters( "p2_add_component_$component", $class );
		if ( class_exists( $class ) )
			$this->components[ $component ] = new $class();
	}
	function get( $component ) {
		return $this->components[ $component ];
	}
	function remove( $component ) {
		unset( $this->components[ $component ] );
	}
	/**
	 * OPTIONS API
	 */
	function get_option( $key ) {
		return isset( $this->options[ $key ] ) ? $this->options[ $key ] : null;
	}
	function set_option( $key, $value ) {
		return $this->options[ $key ] = $value;
	}
	function save_options() {
		update_option( $this->option_name, $this->options );
	}
}
$GLOBALS['p2'] = new P2;
function p2_get( $component = '' ) {
	global $p2;
	return empty( $component ) ? $p2 : $p2->get( $component );
}
function p2_get_option( $key ) {
	return $GLOBALS['p2']->get_option( $key );
}
function p2_set_option( $key, $value ) {
	return $GLOBALS['p2']->set_option( $key, $value );
}
function p2_save_options() {
	return $GLOBALS['p2']->save_options();
}
/**
 * ----------------------------------------------------------------------------
 * NOTE: Ideally, the rest of this file should be moved elsewhere.
 * ----------------------------------------------------------------------------
 */
$content_width = 632;
$themecolors = array(
	'bg' => 'ffffff',
	'text' => '555555',
	'link' => '3478e3',
	'border' => 'f1f1f1',
	'url' => 'd54e21',
);
register_sidebar( array(
	'name' => __( 'Sidebar', 'p2' ),
) );
// Run make_clickable later to avoid shortcode conflicts
add_filter( 'the_content', 'make_clickable', 12 );
// Content Filters
// Filter to be ran on the_content, calls the do_list function from our class
function p2_list_creator( $content ) {
	$list_creator = new P2_List_Creator;
	return $list_creator->do_list( $content );
}
// Call the filter on normal, non admin calls (this code exists in ajax.php for the special p2 instances)
if ( ! is_admin() )
	add_filter( 'pre_kses', 'p2_list_creator', 1 );
add_filter( 'pre_comment_content', 'p2_list_creator', 1 );
function p2_title( $before = '
', $after = '
', $echo = true ) {
	if ( is_page() )
		return;
	if ( is_single() && false === p2_the_title( '', '', false ) ) { ?>
		', $after = '', $echo = true ) {
	global $post;
	$temp = $post;
	$t = apply_filters( 'the_title', $temp->post_title );
	$title = $temp->post_title;
	$content = $temp->post_content;
	$pos = 0;
	$out = '';
	// Don't show post title if turned off in options or title is default text
	if ( 1 != (int) get_option( 'prologue_show_titles' ) || 'Post Title' == $title )
		return false;
	$content = trim( $content );
	$title = trim( $title );
	$title = preg_replace( '/\.\.\.$/', '', $title );
	$title = str_replace( "\n", ' ', $title );
	$title = str_replace( '  ', ' ', $title);
	$content = str_replace( "\n", ' ', strip_tags( $content) );
	$content = str_replace( '  ', ' ', $content );
	$content = trim( $content );
	$title = trim( $title );
	// Clean up links in the title
	if ( false !== strpos( $title, 'http' ) )  {
		$split = @str_split( $content, strpos( $content, 'http' ) );
		$content = $split[0];
		$split2 = @str_split( $title, strpos( $title, 'http' ) );
		$title = $split2[0];
	}
	// Avoid processing an empty title
	if ( '' == $title )
		return false;
	// Avoid processing the title if it's the very first part of the post content
	// Which is the case with most "status" posts
	$pos = strpos( $content, $title );
	if ( false === $pos || 0 < $pos ) {
		if ( is_single() )
			$out = $before . $t . $after;
		else
			$out = $before . '' . $t . ' ' . $after;
		if ( $echo )
			echo $out;
		else
			return $out;
	}
	return false;
}
function p2_comments( $comment, $args ) {
	$GLOBALS['comment'] = $comment;
	if ( !is_single() && get_comment_type() != 'comment' )
		return;
	$depth          = prologue_get_comment_depth( get_comment_ID() );
	$can_edit_post  = current_user_can( 'edit_post', $comment->comment_post_ID );
	$reply_link     = prologue_get_comment_reply_link(
		array( 'depth' => $depth, 'max_depth' => $args['max_depth'], 'before' => ' | ', 'reply_text' => __( 'Reply', 'p2' ) ),
		$comment->comment_ID, $comment->comment_post_ID );
	$content_class  = 'commentcontent';
	if ( $can_edit_post )
		$content_class .= ' comment-edit';
	?>
	' . $tag_link . '';
		$tag_links[] = $tag_link;
	}
	return apply_filters( 'tags_with_count', $before . join( $sep, $tag_links ) . $after, $post );
}
function tags_with_count( $format = 'list', $before = '', $sep = '', $after = '' ) {
	global $post;
	echo get_tags_with_count( $post, $format, $before, $sep, $after );
}
function p2_title_from_content( $content ) {
	$title = p2_excerpted_title( $content, 8 ); // limit title to 8 full words
	// Try to detect image or video only posts, and set post title accordingly
	if ( empty( $title ) ) {
		if ( preg_match("/