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', 'widgets/recent-tags', 'widgets/recent-comments', 'list-creator' ); require_once( P2_INC_PATH . "/template-tags.php" ); // Logged-out/unprivileged users use the add_feed() + ::ajax_read() API rather than the /admin-ajax.php API // current_user_can( 'read' ) should be equivalent to is_user_member_of_blog() if ( defined( 'DOING_AJAX' ) && DOING_AJAX && ( p2_user_can_post() || current_user_can( 'read' ) ) ) $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' ); $this->add( 'post-list-creator', 'P2_Post_List_Creator' ); $this->add( 'comment-list-creator', 'P2_Comment_List_Creator' ); // Bind actions add_action( 'init', array( &$this, 'init' ) ); add_action( 'admin_init', array( &$this, 'maybe_upgrade_db' ), 5 ); } function init() { // Load language pack load_theme_textdomain( 'p2', get_template_directory() . '/languages' ); // Set up the AJAX read handler add_feed( 'p2.ajax', array( $this, 'ajax_read' ) ); } function ajax_read() { if ( ! defined( 'DOING_AJAX' ) ) { define( 'DOING_AJAX', true ); } require_once( P2_INC_PATH . '/ajax-read.php' ); P2Ajax_Read::dispatch(); } /** * 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. * ---------------------------------------------------------------------------- */ if ( ! isset( $content_width ) ) $content_width = 632; $themecolors = array( 'bg' => 'ffffff', 'text' => '555555', 'link' => '3478e3', 'border' => 'f1f1f1', 'url' => 'd54e21', ); /** * Setup P2 Theme. * * Hooks into the after_setup_theme action. * * @uses p2_get_supported_post_formats() */ function p2_setup() { require_once( get_template_directory() . '/inc/custom-header.php' ); p2_setup_custom_header(); add_theme_support( 'automatic-feed-links' ); add_theme_support( 'post-formats', p2_get_supported_post_formats( 'post-format' ) ); add_theme_support( 'custom-background', apply_filters( 'p2_custom_background_args', array( 'default-color' => 'f1f1f1' ) ) ); add_filter( 'the_content', 'make_clickable', 12 ); // Run later to avoid shortcode conflicts register_nav_menus( array( 'primary' => __( 'Primary Menu', 'p2' ), ) ); if ( is_admin() && false === get_option( 'prologue_show_titles' ) ) add_option( 'prologue_show_titles', 1 ); } add_filter( 'after_setup_theme', 'p2_setup' ); function p2_register_sidebar() { register_sidebar( array( 'name' => __( 'Sidebar', 'p2' ), 'id' => 'sidebar-1', ) ); } add_action( 'widgets_init', 'p2_register_sidebar' ); function p2_background_color() { $background_color = get_option( 'p2_background_color' ); if ( '' != $background_color ) : ?> ', $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, $temp->ID ); $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' ) && false !== strpos( $content, 'http' ) ) { $http_pos_content = strpos( $content, 'http' ); if ( $http_pos_content > 0 ) { $content = substr( $content, 0, $http_pos_content ); } $http_pos_title = strpos( $title, 'http' ); if ( $http_pos_title > 0 ) { $title = substr( $title, 0, $http_pos_title ); } } // 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 ( '' == get_post_format() || 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'; ?>
  • >

    comment_content, $comment ); if ( $comment->comment_approved == '0' ): ?>

    ID, 'post_tag' ); $tag_links = []; if ( !$posttags ) return ''; foreach ( $posttags as $tag ) { if ( $tag->count > 1 && !is_tag($tag->slug) ) { $tag_link = ''; } else { $tag_link = $tag->name; } if ( $format == 'list' ) $tag_link = '
  • ' . $tag_link . '
  • '; $tag_links[] = $tag_link; } return apply_filters( 'tags_with_count', $before . implode( $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("/\r\n\t"]|\.$|(?<=\D)[:,.\-]|[:,.\-](?=\D))/', $content, $word_count + 1, PREG_SPLIT_NO_EMPTY ); if ( is_countable( $words ) && count( $words ) > $word_count ) { array_pop( $words ); // remove remainder of words $content = implode( ' ', $words ); $content = $content . '...'; } else { $content = implode( ' ', $words ); } $content = trim( strip_tags( $content ) ); return $content; } function p2_add_reply_title_attribute( $link ) { return str_replace( "rel='nofollow'", "rel='nofollow' title='" . __( 'Reply', 'p2' ) . "'", $link ); } add_filter( 'post_comments_link', 'p2_add_reply_title_attribute' ); function p2_fix_empty_titles( $data, $postarr ) { if ( 'post' != $data['post_type'] ) return $data; if ( ! empty( $postarr['post_title'] ) ) return $data; $data['post_title'] = p2_title_from_content( $data['post_content'] ); return $data; } add_filter( 'wp_insert_post_data', 'p2_fix_empty_titles', 10, 2 ); function p2_add_head_content() { if ( is_home() && is_user_logged_in() ) { include_once( ABSPATH . '/wp-admin/includes/media.php' ); } } add_action( 'wp_head', 'p2_add_head_content' ); function p2_new_post_noajax() { if ( empty( $_POST['action'] ) || $_POST['action'] != 'post' ) return; if ( !is_user_logged_in() ) auth_redirect(); if ( !current_user_can( 'publish_posts' ) ) { wp_redirect( home_url( '/' ) ); exit; } $current_user = wp_get_current_user(); check_admin_referer( 'new-post' ); $user_id = $current_user->ID; $post_content = $_POST['posttext']; $tags = $_POST['tags']; $post_title = p2_title_from_content( $post_content ); $post_id = wp_insert_post( array( 'post_author' => $user_id, 'post_title' => $post_title, 'post_content' => $post_content, 'tags_input' => $tags, 'post_status' => 'publish' ) ); $post_format = 'status'; if ( in_array( $_POST['post_format'], p2_get_supported_post_formats() ) ) $post_format = $_POST['post_format']; set_post_format( $post_id, $post_format ); wp_redirect( home_url( '/' ) ); exit; } add_filter( 'template_redirect', 'p2_new_post_noajax' ); /** * iPhone Stylesheet. * * Hooks into the wp_enqueue_scripts action late. * * @uses p2_is_iphone() * @since P2 1.4 */ function p2_iphone_style() { if ( p2_is_iphone() ) { wp_enqueue_style( 'p2-iphone-style', get_template_directory_uri() . '/style-iphone.css', array(), '20120402' ); } } add_action( 'wp_enqueue_scripts', 'p2_iphone_style', 1000 ); /** * Print Stylesheet. * * Hooks into the wp_enqueue_scripts action. * * @since P2 1.5 */ function p2_print_style() { wp_enqueue_style( 'p2', get_stylesheet_uri() ); wp_enqueue_style( 'p2-print-style', get_template_directory_uri() . '/style-print.css', array( 'p2' ), '20120807', 'print' ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' ); } add_action( 'wp_enqueue_scripts', 'p2_print_style' ); /* Modified to replace query string with blog url in output string */ function prologue_get_comment_reply_link( $args = array(), $comment = null, $post = null ) { global $user_ID; if ( post_password_required() ) return; $defaults = array( 'add_below' => 'commentcontent', 'respond_id' => 'respond', 'reply_text' => __( 'Reply', 'p2' ), 'login_text' => __( 'Log in to Reply', 'p2' ), 'depth' => 0, 'before' => '', 'after' => '' ); $args = wp_parse_args($args, $defaults); if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) return; extract($args, EXTR_SKIP); $reply_text ??= null; $login_text ??= null; $respond_id ??= null; $add_below ??= null; $before ??= null; $after ??= null; $comment = get_comment($comment); $post = get_post($post); if ( 'open' != $post->comment_status ) return false; $link = ''; $reply_text = esc_html( $reply_text ); if ( get_option( 'comment_registration' ) && !$user_ID ) $link = '' . esc_html( $login_text ) . ''; else $link = "$reply_text"; return apply_filters( 'comment_reply_link', $before . $link . $after, $args, $comment, $post); } function prologue_comment_depth_loop( $comment_id, $depth ) { $comment = get_comment( $comment_id ); if ( isset( $comment->comment_parent ) && 0 != $comment->comment_parent ) { return prologue_comment_depth_loop( $comment->comment_parent, $depth + 1 ); } return $depth; } function prologue_get_comment_depth( $comment_id ) { return prologue_comment_depth_loop( $comment_id, 1 ); } function prologue_comment_depth( $comment_id ) { echo prologue_get_comment_depth( $comment_id ); } function prologue_poweredby_link() { return apply_filters( 'prologue_poweredby_link', sprintf( '%2$s', esc_url( __('http://wordpress.org/', 'p2') ), sprintf( __('Proudly powered by %s.', 'p2'), 'WordPress' ) ) ); } function p2_hidden_sidebar_css() { $hide_sidebar = get_option( 'p2_hide_sidebar' ); $sleeve_margin = ( is_rtl() ) ? 'margin-left: 0;' : 'margin-right: 0;'; if ( '' != $hide_sidebar ) : ?>
    '; } add_action( 'before_signup_form', 'p2_before_signup_form' ); function p2_after_signup_form() { echo '
    '; } add_action( 'after_signup_form', 'p2_after_signup_form' ); /** * Returns accepted post formats. * * The value should be a valid post format registered for P2, or one of the back compat categories. * post formats: link, quote, standard, status * categories: link, post, quote, status * * @since P2 1.3.4 * * @param string type Which data to return (all|category|post-format) * @return array */ function p2_get_supported_post_formats( $type = 'all' ) { $post_formats = array( 'link', 'quote', 'status' ); switch ( $type ) { case 'post-format': break; case 'category': $post_formats[] = 'post'; break; case 'all': default: array_push( $post_formats, 'post', 'standard' ); break; } return apply_filters( 'p2_get_supported_post_formats', $post_formats ); } /** * Is site being viewed on an iPhone or iPod Touch? * * For testing you can modify the output with a filter: * add_filter( 'p2_is_iphone', '__return_true' ); * * @return bool * @since P2 1.4 */ function p2_is_iphone() { $output = false; if ( ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strstr( $_SERVER['HTTP_USER_AGENT'], 'iPhone' ) && ! strstr( $_SERVER['HTTP_USER_AGENT'], 'iPad' ) ) || isset( $_GET['iphone'] ) && $_GET['iphone'] ) $output = true; $output = (bool) apply_filters( 'p2_is_iphone', $output ); return $output; } /** * Filters wp_title to print a neat tag based on what is being viewed. * * @since P2 1.5 */ function p2_wp_title( $title, $sep ) { global $page, $paged; if ( is_feed() ) return $title; // Add the blog name $title .= get_bloginfo( 'name' ); // Add the blog description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); if ( $site_description && ( is_home() || is_front_page() ) ) $title .= " $sep $site_description"; // Add a page number if necessary: if ( $paged >= 2 || $page >= 2 ) $title .= " $sep " . sprintf( __( 'Page %s', 'p2' ), max( $paged, $page ) ); return $title; } add_filter( 'wp_title', 'p2_wp_title', 10, 2 );