/code/cake/app/webroot/cp/wp-content/plugins/commentpress-core/themes/commentpress-theme/functions.php
PHP | 4497 lines | 1704 code | 1617 blank | 1176 comment | 359 complexity | 1941337d6cb641f5cf0ef6c586c944fa MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, AGPL-1.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php /*
- ================================================================================
- CommentPress Default Theme Functions
- ================================================================================
- AUTHOR: Christian Wach <needle@haystack.co.uk>
- --------------------------------------------------------------------------------
- NOTES
- --------------------------------------------------------------------------------
- */
- /**
- * Set the content width based on the theme's design and stylesheet.
- * This seems to be a Wordpress requirement - though rather dumb in the
- * context of our theme, which has a percentage-based default width.
- * I have arbitrarily set it to the default content-width when viewing
- * on a 1280px-wide screen.
- */
- if ( !isset( $content_width ) ) { $content_width = 588; }
- if ( ! function_exists( 'commentpress_setup' ) ):
- /**
- * @description: get an ID for the body tag
- * @todo:
- *
- */
- function commentpress_setup(
-
- ) { //-->
- /**
- * Make CommentPress Default Theme available for translation.
- * Translations can be added to the /assets/languages/ directory.
- */
-
- /*
- // we no longer use this: instead, the plugin's textdomain is used
- load_theme_textdomain(
-
- 'commentpress-theme',
- get_template_directory() . '/assets/languages'
-
- );
- */
- // add_custom_background function is deprecated in WP 3.4+
- global $wp_version;
- if ( version_compare( $wp_version, '3.4', '>=' ) ) {
-
- // -------------------------
- // TO DO: test 3.4 features
- // -------------------------
-
- // allow custom backgrounds
- add_theme_support( 'custom-background' );
-
- // allow custom header
- add_theme_support( 'custom-header', array(
-
- 'default-text-color' => 'eeeeee',
- 'width' => apply_filters( 'cp_header_image_width', 940 ),
- 'height' => apply_filters( 'cp_header_image_height', 67 ),
- 'wp-head-callback' => 'commentpress_header',
- 'admin-head-callback' => 'commentpress_admin_header'
-
- ) );
-
- } else {
-
- // retain old declarations for earlier versions
- add_custom_background();
-
- // header text colour
- define( 'HEADER_TEXTCOLOR', 'eeeeee' );
-
- // set height and width
- define( 'HEADER_IMAGE_WIDTH', apply_filters( 'cp_header_image_width', 940 ) );
- define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'cp_header_image_height', 67 ) );
-
- // allow custom header images
- add_custom_image_header( 'commentpress_header', 'commentpress_admin_header' );
-
- }
-
- // Default custom headers packaged with the theme (see Twenty Eleven)
- // A nice side-effect of supplying a default header image is that it triggers the
- // "Header Image" option in the Theme Customizer
- // %s is a placeholder for the theme template directory URI
- register_default_headers(
- array(
- 'caves-green' => array(
- 'url' => '%s/assets/images/header/caves-green.jpg',
- 'thumbnail_url' => '%s/assets/images/header/caves-green-thumbnail.jpg',
- /* translators: header image description */
- 'description' => __( 'Abstract Green', 'commentpress-core' )
- ),
- 'caves-red' => array(
- 'url' => '%s/assets/images/header/caves-red.jpg',
- 'thumbnail_url' => '%s/assets/images/header/caves-red-thumbnail.jpg',
- /* translators: header image description */
- 'description' => __( 'Abstract Red', 'commentpress-core' )
- ),
- 'caves-blue' => array(
- 'url' => '%s/assets/images/header/caves-blue.jpg',
- 'thumbnail_url' => '%s/assets/images/header/caves-blue-thumbnail.jpg',
- /* translators: header image description */
- 'description' => __( 'Abstract Blue', 'commentpress-core' )
- ),
- 'caves-violet' => array(
- 'url' => '%s/assets/images/header/caves-violet.jpg',
- 'thumbnail_url' => '%s/assets/images/header/caves-violet-thumbnail.jpg',
- /* translators: header image description */
- 'description' => __( 'Abstract Violet', 'commentpress-core' )
- )
- )
- );
-
- // auto feed links
- add_theme_support( 'automatic-feed-links' );
-
- // style the visual editor with editor-style.css to match the theme style
- add_editor_style();
- // testing the use of wp_nav_menu() - first we need to register it
- register_nav_menu( 'toc', __( 'Table of Contents', 'commentpress-core' ) );
- }
- endif; // commentpress_setup
- // add after theme setup hook
- add_action( 'after_setup_theme', 'commentpress_setup' );
- if ( ! function_exists( 'commentpress_enqueue_theme_styles' ) ):
- /**
- * @description: add buddypress front-end styles
- * @todo:
- *
- */
- function commentpress_enqueue_theme_styles() {
- // kick out on admin
- if ( is_admin() ) { return; }
- // init
- $dev = '';
-
- // check for dev
- if ( defined( 'SCRIPT_DEBUG' ) AND SCRIPT_DEBUG === true ) {
- $dev = '.dev';
- }
- // add BuddyPress css
- wp_enqueue_style(
-
- 'cp_buddypress_css',
- get_template_directory_uri() . '/assets/css/bp-overrides'.$dev.'.css',
- array( 'cp_layout_css' ),
- COMMENTPRESS_VERSION, // version
- 'all' // media
-
- );
-
- }
- endif; // commentpress_enqueue_theme_styles
- if ( ! function_exists( 'commentpress_enqueue_bp_theme_styles' ) ):
- /**
- * @description: enqueue buddypress front-end styles
- * @todo:
- *
- */
- function commentpress_enqueue_bp_theme_styles() {
- // add a filter to include bp-overrides when buddypress is active
- add_action( 'wp_enqueue_scripts', 'commentpress_enqueue_theme_styles', 101 );
-
- }
- endif; // commentpress_enqueue_bp_theme_styles
- // add an action for the above
- add_action( 'bp_setup_globals', 'commentpress_enqueue_theme_styles' );
- if ( ! function_exists( 'commentpress_enqueue_scripts_and_styles' ) ):
- /**
- * @description: add front-end print styles
- * @todo:
- *
- */
- function commentpress_enqueue_scripts_and_styles() {
- // -------------------------------------------------------------------------
- // Stylesheets
- // -------------------------------------------------------------------------
-
- // register reset
- wp_register_style(
-
- 'cp_reset_css', // unique id
- get_template_directory_uri() . '/assets/css/reset.css', // src
- array(), // dependencies
- COMMENTPRESS_VERSION, // version
- 'all' // media
- );
-
- // init
- $dev = '';
-
- // check for dev
- if ( defined( 'SCRIPT_DEBUG' ) AND SCRIPT_DEBUG === true ) {
- $dev = '.dev';
- }
-
- // add typography css
- wp_enqueue_style(
-
- 'cp_typography_css',
- get_template_directory_uri() . '/assets/css/typography'.$dev.'.css',
- array( 'cp_reset_css' ),
- COMMENTPRESS_VERSION, // version
- 'all' // media
-
- );
-
- // add layout css
- wp_enqueue_style(
-
- 'cp_layout_css',
- get_template_directory_uri() . '/assets/css/layout'.$dev.'.css',
- array( 'cp_typography_css' ),
- COMMENTPRESS_VERSION, // version
- 'all' // media
-
- );
-
- // -------------------------------------------------------------------------
- // Overrides for styles - for child themes, dequeue these and add you own
- // -------------------------------------------------------------------------
-
- // add Google Webfont "Lato"
- wp_enqueue_style(
-
- 'cp_webfont_css',
- 'http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic',
- array( 'cp_layout_css' ),
- null, // no version, thanks
- null // no media, thanks
-
- );
-
- // add colours css
- wp_enqueue_style(
-
- 'cp_colours_css',
- get_template_directory_uri() . '/assets/css/colours-01'.$dev.'.css',
- array( 'cp_webfont_css' ),
- COMMENTPRESS_VERSION, // version
- 'all' // media
-
- );
-
- // -------------------------------------------------------------------------
- // Javascripts
- // -------------------------------------------------------------------------
-
- // access plugin
- global $commentpress_core;
- // if we have the plugin enabled...
- if ( is_object( $commentpress_core ) ) {
- // enqueue common js
- wp_enqueue_script(
-
- 'cp_common_js',
- get_template_directory_uri() . '/assets/js/cp_js_common'.$dev.'.js',
- array( 'jquery_commentpress' )
-
- );
-
- // test for buddypress special page
- if ( $commentpress_core->is_buddypress() AND $commentpress_core->is_buddypress_special_page() ) {
-
- // skip custom addComment
-
- } else {
-
- // enqueue form js
- wp_enqueue_script(
-
- 'cp_form',
- get_template_directory_uri() . '/assets/js/cp_js_form'.$dev.'.js',
- array( 'cp_common_js' )
-
- );
-
- }
-
- // test for CommentPress Core special page
- if ( $commentpress_core->db->is_special_page() ) {
-
- // enqueue accordion-like js
- wp_enqueue_script(
-
- 'cp_special',
- get_template_directory_uri() . '/assets/js/cp_js_all_comments.js',
- array( 'cp_form' )
-
- );
-
- }
-
- // get vars
- $vars = $commentpress_core->db->get_javascript_vars();
-
- // localise with wp function
- wp_localize_script( 'cp_common_js', 'CommentpressSettings', $vars );
-
- }
-
- }
- endif; // commentpress_enqueue_scripts_and_styles
- // add a filter for the above, very late so it (hopefully) is last in the queue
- add_action( 'wp_enqueue_scripts', 'commentpress_enqueue_scripts_and_styles', 100 );
- if ( ! function_exists( 'commentpress_enqueue_print_styles' ) ):
- /**
- * @description: add front-end print styles
- * @todo:
- *
- */
- function commentpress_enqueue_print_styles() {
- // init
- $dev = '';
-
- // check for dev
- if ( defined( 'SCRIPT_DEBUG' ) AND SCRIPT_DEBUG === true ) {
- $dev = '.dev';
- }
-
- // -------------------------------------------------------------------------
- // Print stylesheet included last
- // -------------------------------------------------------------------------
-
- // add print css
- wp_enqueue_style(
-
- 'cp_print_css',
- get_template_directory_uri() . '/assets/css/print'.$dev.'.css',
- array( 'cp_layout_css' ),
- COMMENTPRESS_VERSION, // version
- 'print'
-
- );
-
- }
- endif; // commentpress_enqueue_print_styles
- // add a filter for the above, very late so it (hopefully) is last in the queue
- add_action( 'wp_enqueue_scripts', 'commentpress_enqueue_print_styles', 101 );
- if ( ! function_exists( 'commentpress_header' ) ):
- /**
- * @description: custom header
- * @todo:
- *
- */
- function commentpress_header(
-
- ) { //-->
- // init (same as bg in layout.css and default in class_commentpress_db.php)
- $bg_colour = '2c2622';
- // access plugin
- global $commentpress_core;
- // if we have the plugin enabled...
- if ( is_object( $commentpress_core ) ) {
-
- // override
- $bg_colour = $commentpress_core->db->option_get_header_bg();
-
- }
-
- // allow overrides
- $bg_colour = apply_filters( 'cp_default_header_bgcolor', $bg_colour );
-
-
-
- // init background-image
- $bg_image = '';
-
- // get header image
- $header_image = get_header_image();
-
- // do we have a background-image?
- if ( $header_image ) {
-
- $bg_image = 'background-image: url("'.$header_image.'");';
-
- }
-
-
-
- // get custom text colour
- // note: this does NOT retrieve the default if not manually set in the Theme Customizer in WP3.4
- $text_color = get_header_textcolor();
-
-
- // WP3.4 seems to behave differently.
- global $wp_version;
- if ( version_compare( $wp_version, '3.4', '>=' ) ) {
-
- // if blank, we're hiding the title
- if ( $text_color == 'blank' ) {
- $css = 'text-indent: -9999px;';
- } else {
-
- // if empty, we need to use default
- if ( $text_color == '' ) {
- $css = 'color: #'.HEADER_TEXTCOLOR.';';
- } else {
-
- // use the custom one. I know this amounts to the same thing.
- $css = 'color: #'.$text_color.';';
- }
-
- }
- } else {
-
- // use previous logic
- if ( $text_color == 'blank' OR $text_color == '' ) {
- $css = 'text-indent: -9999px;';
- } else {
- $css = 'color: #'.$text_color.';';
- }
-
- }
-
- // build inline styles
- echo '
- <style type="text/css">
- #book_header
- {
- background-color: #'.$bg_colour.';
- '.$bg_image.'
- -webkit-background-size: cover;
- -moz-background-size: cover;
- -o-background-size: cover;
- background-size: cover;
- background-repeat: no-repeat;
- background-position: 50%;
- }
- #title h1,
- #title h1 a
- {
- '.$css.'
- }
- #book_header #tagline
- {
- '.$css.'
- }
- </style>
- ';
-
- }
- endif; // commentpress_header
- /*
- // if no custom options for text are set, ignore
- if ( $text_color == HEADER_TEXTCOLOR ) {
-
- // set flag
- $ignore = true;
-
- }
-
- // if blank or empty, we're hiding the title
- if ( $text_color == 'blank' OR $text_color == '' ) {
-
- }
- // If we get this far, we have custom styles. Let's do this.
- print_r( ( $text_color ? $text_color : 'nowt<br/>' ) );
- print_r( HEADER_TEXTCOLOR ); die();
-
- */
- if ( ! function_exists( 'commentpress_admin_header' ) ):
- /**
- * @description: custom admin header
- * @todo:
- *
- */
- function commentpress_admin_header(
-
- ) { //-->
- // init (same as bg in layout.css and default in class_commentpress_db.php)
- $colour = '2c2622';
- // access plugin
- global $commentpress_core;
- // if we have the plugin enabled...
- if ( is_object( $commentpress_core ) ) {
-
- // override
- $colour = $commentpress_core->db->option_get_header_bg();
-
- }
-
- // try and recreate the look of the theme header
- echo '
- <style type="text/css">
-
- .appearance_page_custom-header #headimg
- {
- min-height: 67px;
- }
- #headimg
- {
- background-color: #'.$colour.';
- }
- #headimg #name,
- #headimg #desc
- {
- margin-left: 20px;
- font-family: Helvetica, Arial, sans-serif;
- font-weight: normal;
- line-height: 1;
- color: #'.get_header_textcolor().';
- }
- #headimg h1
- {
- margin: 0;
- padding: 0;
- padding-top: 12px;
- }
- #headimg #name
- {
- font-size: 1em;
- text-decoration: none;
- }
- #headimg #desc
- {
- padding-top: 3px;
- font-size: 1.2em;
- font-style: italic;
- }
- </style>
- ';
- }
- endif; // commentpress_admin_header
- if ( ! function_exists( 'commentpress_customize_register' ) ) {
- /**
- * Implements CommentPress Default Theme options into Theme Customizer
- *
- * @param $wp_customize Theme Customizer object
- * @return void
- *
- */
- function commentpress_customize_register(
- $wp_customize
- ) { //-->
- // access plugin
- global $commentpress_core;
-
- // kick out if buddypress groupblog...
- if ( is_object( $commentpress_core ) AND $commentpress_core->is_groupblog() ) return;
-
-
-
- // add customizer section title
- $wp_customize->add_section( 'cp_inline_header_image', array(
- 'title' => __( 'Site Logo', 'commentpress-core' ),
- 'priority' => 35,
- ) );
-
-
-
- // add image
- $wp_customize->add_setting( 'commentpress_theme_settings[cp_inline_header_image]', array(
- 'default' => '',
- 'capability' => 'edit_theme_options',
- 'type' => 'option'
- ));
-
- $wp_customize->add_control( new WP_Customize_Image_Control(
- $wp_customize, 'cp_inline_header_image', array(
- 'label' => __( 'Logo Image', 'commentpress-core' ),
- 'section' => 'cp_inline_header_image',
- 'settings' => 'commentpress_theme_settings[cp_inline_header_image]',
- 'priority' => 1
- )));
-
-
-
- // add padding
- $wp_customize->add_setting( 'commentpress_theme_settings[cp_inline_header_padding]', array(
- 'default' => '',
- 'capability' => 'edit_theme_options',
- 'type' => 'option'
- ));
-
- $wp_customize->add_control( 'commentpress_theme_settings[cp_inline_header_padding]', array(
- 'label' => __( 'Top padding in px', 'commentpress-core' ),
- 'section' => 'cp_inline_header_image',
- 'type' => 'text'
- ) );
- }
- }
- add_action( 'customize_register', 'commentpress_customize_register' );
- if ( ! function_exists( 'commentpress_admin_menu' ) ) {
- /**
- * @description: adds more prominent menu item
- * @todo:
- *
- */
- function commentpress_admin_menu() {
- // Only add for WP3.4+
- global $wp_version;
- if ( version_compare( $wp_version, '3.4', '>=' ) ) {
- // add the Customize link to the admin menu
- add_theme_page( 'Customize', 'Customize', 'edit_theme_options', 'customize.php' );
-
- }
-
- }
- }
- add_action( 'admin_menu', 'commentpress_admin_menu' );
- if ( ! function_exists( 'commentpress_get_header_image' ) ):
- /**
- * @description: function that sets a header foreground image (a logo, for example)
- * @todo: inform users that header images are using a different method
- *
- */
- function commentpress_get_header_image(
-
- ) { //-->
- // access plugin
- global $commentpress_core;
- // test for groupblog
- if ( is_object( $commentpress_core ) AND $commentpress_core->is_groupblog() ) {
-
- // get group ID
- $group_id = get_groupblog_group_id( get_current_blog_id() );
-
- // get group avatar
- $avatar_options = array (
- 'item_id' => $group_id,
- 'object' => 'group',
- 'type' => 'full',
- 'alt' => 'Group avatar',
- 'class' => 'cp_logo_image cp_group_avatar',
- 'width' => 48,
- 'height' => 48,
- 'html' => true
- );
-
- // show group avatar
- echo bp_core_fetch_avatar( $avatar_options );
-
- // --<
- return;
-
- }
-
-
-
- // -------------------------------------------------------------------------
- // implement compatibility with WordPress Theme Customizer
- // -------------------------------------------------------------------------
- // get the new options
- $options = get_option( 'commentpress_theme_settings' );
- //print_r( $options ); die();
-
- // test for our new theme customizer option
- if ( isset( $options['cp_inline_header_image'] ) AND !empty( $options['cp_inline_header_image'] ) ) {
-
- // init top padding
- $style = '';
-
- // test for top padding
- if ( isset( $options['cp_inline_header_padding'] ) AND !empty( $options['cp_inline_header_padding'] ) ) {
-
- // override
- $style = ' style="padding-top: '.$options['cp_inline_header_padding'].'px"';
-
- }
-
- // show the uploaded image
- echo '<img src="'.$options['cp_inline_header_image'].'" class="cp_logo_image" '.$style.'alt="Logo" />';
-
- // --<
- return;
-
- }
-
-
-
- // -------------------------------------------------------------------------
- // our fallback is to go with the legacy method that some people might still be using
- // -------------------------------------------------------------------------
- // if we have the plugin enabled...
- if ( is_object( $commentpress_core ) AND $commentpress_core->db->option_get( 'cp_toc_page' ) ) {
-
- // set defaults
- $args = array(
-
- 'post_type' => 'attachment',
- 'numberposts' => 1,
- 'post_status' => null,
- 'post_parent' => $commentpress_core->db->option_get( 'cp_toc_page' )
-
- );
-
- // get them...
- $attachments = get_posts( $args );
-
- // well?
- if ( $attachments ) {
-
- // we only want the first
- $attachment = $attachments[0];
-
- }
-
- // if we have an image
- if ( isset( $attachment ) ) {
-
- // show it
- echo wp_get_attachment_image( $attachment->ID, 'full' );
-
- }
-
- }
-
- }
- endif; // commentpress_get_header_image
- if ( ! function_exists( 'commentpress_get_body_id' ) ):
- /**
- * @description: get an ID for the body tag
- * @todo:
- *
- */
- function commentpress_get_body_id(
-
- ) { //-->
- // init
- $_body_id = '';
-
- // is this multisite?
- if ( is_multisite() ) {
-
- // is this the main blog?
- if ( is_main_site() ) {
-
- // set main blog id
- $_body_id = ' id="main_blog"';
-
- }
-
- }
-
- // --<
- return $_body_id;
-
- }
- endif; // commentpress_get_body_id
- if ( ! function_exists( 'commentpress_get_body_classes' ) ):
- /**
- * @description: get classes for the body tag
- * @todo:
- *
- */
- function commentpress_get_body_classes(
- $raw = false
-
- ) { //-->
- // init
- $_body_classes = '';
-
- // access post and plugin
- global $post, $commentpress_core;
- // set default sidebar
- $sidebar_flag = 'toc';
-
- // if we have the plugin enabled...
- if ( is_object( $commentpress_core ) ) {
-
- // get sidebar
- $sidebar_flag = $commentpress_core->get_default_sidebar();
-
- }
-
- // set class by sidebar
- $sidebar_class = 'cp_sidebar_'.$sidebar_flag;
-
- // init commentable class
- $commentable = '';
-
- // if we have the plugin enabled...
- if ( is_object( $commentpress_core ) ) {
-
- // set class
- $commentable = ( $commentpress_core->is_commentable() ) ? ' commentable' : ' not_commentable';
-
- }
-
-
-
- // init layout class
- $layout_class = '';
-
- // if we have the plugin enabled...
- if ( is_object( $commentpress_core ) ) {
-
- // is this the title page?
- if (
-
- // be more defensive
- is_object( $post )
- AND isset( $post->ID )
- AND $post->ID == $commentpress_core->db->option_get( 'cp_welcome_page' )
-
- ) {
-
- // init layout
- $layout = '';
-
- // set key
- $key = '_cp_page_layout';
-
- // if the custom field already has a value...
- if ( get_post_meta( $post->ID, $key, true ) != '' ) {
-
- // get it
- $layout = get_post_meta( $post->ID, $key, true );
-
- }
-
- // if wide layout...
- if ( $layout == 'wide' ) {
-
- // set layout class
- $layout_class = ' full_width';
-
- }
-
- }
-
- }
-
- // set default page type
- $page_type = '';
-
- // if blog post...
- if ( is_single() ) {
-
- // add blog post class
- $page_type = ' blog_post';
-
- }
-
- // if we have the plugin enabled...
- if ( is_object( $commentpress_core ) ) {
-
- // is it a BP special page?
- if ( $commentpress_core->is_buddypress_special_page() ) {
-
- // add buddypress page class
- $page_type = ' buddypress_page';
-
- }
-
- // is it a CP special page?
- if ( $commentpress_core->db->is_special_page() ) {
-
- // add buddypress page class
- $page_type = ' commentpress_page';
-
- }
-
- }
-
-
- // set default type
- $groupblog_type = ' not-groupblog';
-
- // if we have the plugin enabled...
- if ( is_object( $commentpress_core ) ) {
-
- // if it's a groupblog
- if ( $commentpress_core->is_groupblog() ) {
- $groupblog_type = ' is-groupblog';
- }
-
- }
-
- // set default type
- $blog_type = '';
-
- // if we have the plugin enabled...
- if ( is_object( $commentpress_core ) ) {
-
- // get type
- $_type = $commentpress_core->db->option_get( 'cp_blog_type' );
- //print_r( $_type ); die();
-
- // get workflow
- $_workflow = $commentpress_core->db->option_get( 'cp_blog_workflow' );
-
- // allow plugins to override the blog type - for example if workflow is enabled,
- // it might be a new blog type as far as buddypress is concerned
- $_blog_type = apply_filters( 'cp_get_group_meta_for_blog_type', $_type, $_workflow );
- // if it's not the main site, add class
- if ( is_multisite() AND !is_main_site() ) {
- $blog_type = ' blogtype-'.intval( $_blog_type );
- }
-
- }
-
- // construct attribute
- $_body_classes = $sidebar_class.$commentable.$layout_class.$page_type.$groupblog_type.$blog_type;
- // if we want them wrapped, do so
- if ( !$raw ) {
-
- // preserve backwards compat for older child themes
- $_body_classes = ' class="'.$_body_classes.'"';
- }
- // --<
- return $_body_classes;
-
- }
- endif; // commentpress_get_body_classes
- if ( ! function_exists( 'commentpress_site_title' ) ):
- /**
- * @description: disable more link jump - from: http://codex.wordpress.org/Customizing_the_Read_More
- * @todo:
- *
- */
- function commentpress_site_title( $sep = '', $echo = true ){
- // is this multisite?
- if ( is_multisite() ) {
-
- // if we're on a sub-blog
- if ( !is_main_site() ) {
-
- global $current_site;
-
- // print?
- if( $echo ) {
-
- // add site name
- echo ' '.trim($sep).' '.$current_site->site_name;
-
- } else {
-
- // add site name
- return ' '.trim($sep).' '.$current_site->site_name;
-
- }
-
- }
-
- }
-
- }
- endif; // commentpress_site_title
- if ( ! function_exists( 'commentpress_remove_more_jump_link' ) ):
- /**
- * @description: disable more link jump - from: http://codex.wordpress.org/Customizing_the_Read_More
- * @todo:
- *
- */
- function commentpress_remove_more_jump_link( $link ) {
- $offset = strpos($link, '#more-');
-
- if ($offset) {
- $end = strpos($link, '"',$offset);
- }
-
- if ($end) {
- $link = substr_replace($link, '', $offset, $end-$offset);
- }
-
- // --<
- return $link;
-
- }
- endif; // commentpress_remove_more_jump_link
- // add a filter for the above
- add_filter( 'the_content_more_link', 'commentpress_remove_more_jump_link' );
- if ( ! function_exists( 'commentpress_page_navigation' ) ):
- /**
- * @description: builds a list of previous and next pages, optionally with comments
- * @todo:
- *
- */
- function commentpress_page_navigation( $with_comments = false ) {
- // declare access to globals
- global $commentpress_core;
-
-
-
- // is the plugin active?
- if ( !is_object( $commentpress_core ) ) {
-
- // --<
- return;
-
- }
-
-
-
- // init formatting
- $before_next = '<li class="alignright">';
- $after_next = ' </li>';
- $before_prev = '<li class="alignleft">';
- $after_prev = '</li>';
-
-
-
- // init
- $next_page_html = '';
-
- // get next page
- $next_page = $commentpress_core->nav->get_next_page( $with_comments );
-
- //var_dump( $next_page );
-
- // did we get a next page?
- if ( is_object( $next_page ) ) {
-
- // init title
- $img = '';
- $title = __( 'Next page', 'commentpress-core' ); //htmlentities( $next_page->post_title );
-
- // if we wanted pages with comments...
- if ( $with_comments ) {
-
- // set title
- $title = __( 'Next page with comments', 'commentpress-core' );
- $img = '<img src="'.get_template_directory_uri().'/assets/images/next.png" />';
- }
-
- // define list item
- $next_page_html = $before_next.
- $img.'<a href="'.get_permalink( $next_page->ID ).'" id="next_page" class="css_btn" title="'.$title.'">'.$title.'</a>'.$after_next;
-
- }
-
-
-
- // init
- $prev_page_html = '';
-
- // get next page
- $prev_page = $commentpress_core->nav->get_previous_page( $with_comments );
-
- // did we get a next page?
- if ( is_object( $prev_page ) ) {
-
- // init title
- $img = '';
- $title = __( 'Previous page', 'commentpress-core' ); //htmlentities( $prev_page->post_title );
-
- // if we wanted pages with comments...
- if ( $with_comments ) {
-
- // set title
- $title = __( 'Previous page with comments', 'commentpress-core' );
- $img = '<img src="'.get_template_directory_uri().'/assets/images/prev.png" />';
-
- }
-
- // define list item
- $prev_page_html = $before_prev.
- $img.'<a href="'.get_permalink( $prev_page->ID ).'" id="previous_page" class="css_btn" title="'.$title.'">'.$title.'</a>'.$after_prev;
-
- }
-
-
-
- // init return
- $nav_list = '';
-
- // did we get either?
- if ( $next_page_html != '' OR $prev_page_html != '' ) {
-
- // construct nav list items
- $nav_list = $prev_page_html."\n".$next_page_html."\n";
- }
-
-
-
- // --<
- return $nav_list;
- }
- endif; // commentpress_page_navigation
- if ( ! function_exists( 'commentpress_page_title' ) ):
- /**
- * @description: builds a list of previous and next pages, optionally with comments
- * @todo:
- *
- */
- function commentpress_page_title( $with_comments = false ) {
- // declare access to globals
- global $commentpress_core, $post;
-
-
-
- // init
- $_title = '';
- $_sep = ' → ';
-
-
- //$_title .= get_bloginfo('name');
-
- if ( is_page() OR is_single() OR is_category() ) {
- if (is_page()) {
- $ancestors = get_post_ancestors($post);
-
- if ($ancestors) {
- $ancestors = array_reverse($ancestors);
-
- $_crumb = array();
-
- foreach ($ancestors as $crumb) {
- $_crumb[] = get_the_title($crumb);
- }
-
- $_title .= implode( $_sep, $_crumb ).$_sep;
- }
- }
-
- if (is_single()) {
- //$category = get_the_category();
- //$_title .= $_sep.$category[0]->cat_name;
- }
-
- if (is_category()) {
- $category = get_the_category();
- $_title .= $category[0]->cat_name.$_sep;
- }
-
- // Current page
- if (is_page() OR is_single()) {
- $_title .= get_the_title();
- }
- }
-
- // --<
- return $_title;
- }
- endif; // commentpress_page_title
- if ( ! function_exists( 'commentpress_has_page_children' ) ):
- /**
- * @description: query whether a given page has children
- * @todo:
- *
- */
- function commentpress_has_page_children(
- $page_obj
-
- ) { //-->
- // init to look for published pages
- $defaults = array(
- 'post_parent' => $page_obj->ID,
- 'post_type' => 'page',
- 'numberposts' => -1,
- 'post_status' => 'publish'
- );
-
- // get page children
- $kids =& get_children( $defaults );
-
- // do we have any?
- return ( empty( $kids ) ) ? false : true;
- }
- endif; // commentpress_has_page_children
- if ( ! function_exists( 'commentpress_get_children' ) ):
- /**
- * @description: retrieve comment children
- * @todo:
- *
- */
- function commentpress_get_children(
- $comment,
- $page_or_post
-
- ) { //-->
- // declare access to globals
- global $wpdb;
- // construct query for comment children
- $query = "
- SELECT $wpdb->comments.*, $wpdb->posts.post_title, $wpdb->posts.post_name
- FROM $wpdb->comments, $wpdb->posts
- WHERE $wpdb->comments.comment_post_ID = $wpdb->posts.ID
- AND $wpdb->posts.post_type = '$page_or_post'
- AND $wpdb->comments.comment_approved = '1'
- AND $wpdb->comments.comment_parent = '$comment->comment_ID'
- ORDER BY $wpdb->comments.comment_date ASC
- ";
-
- // does it have children?
- return $wpdb->get_results( $query );
- }
- endif; // commentpress_get_children
- if ( ! function_exists( 'commentpress_get_comments' ) ):
- /**
- * @description: generate comments recursively
- * @todo:
- *
- */
- function commentpress_get_comments(
- $comments,
- $page_or_post
-
- ) { //-->
- // declare access to globals
- global $cp_comment_output;
- // do we have any comments?
- if( count( $comments ) > 0 ) {
-
- // open ul
- $cp_comment_output .= '<ul class="item_ul">'."\n\n";
- // produce a checkbox for each
- foreach( $comments as $comment ) {
-
- // open li
- $cp_comment_output .= '<li class="item_li">'."\n\n";
-
- // format this comment
- $cp_comment_output .= commentpress_format_comment( $comment );
- // get comment children
- $children = commentpress_get_children( $comment, $page_or_post );
- // do we have any?
- if( count( $children ) > 0 ) {
- // recurse
- commentpress_get_comments( $children, $page_or_post );
- }
-
- // close li
- $cp_comment_output .= '</li>'."\n\n";
- }
- // close ul
- $cp_comment_output .= '</ul>'."\n\n";
- }
- }
- endif; // commentpress_get_comments
- if ( ! function_exists( 'commentpress_get_user_link' ) ):
- /**
- * @description: get user link in vanilla WP scenarios
- * @todo:
- *
- */
- function commentpress_get_user_link(
- &$user
-
- ) { //-->
- /**
- * In default single install mode, just link to their URL, unless
- * they are an author, in which case we link to their author page.
- *
- * In multisite, the same.
- *
- * When BuddyPress is enabled, always link to their profile
- */
-
- // kick out if not a user
- if ( !is_object( $user ) ) { return false; }
-
- // we're through: the user is on the system
- global $commentpress_core;
-
- // if buddypress...
- if ( is_object( $commentpress_core ) AND $commentpress_core->is_buddypress() ) {
-
- // buddypress link ($no_anchor = null, $just_link = true)
- $url = bp_core_get_userlink( $user->ID, null, true );
-
- } else {
-
- // get standard WP author url
-
- // get author url
- $url = '';//JVDP
- //print_r( $url ); die();
-
- // WP sometimes leaves 'http://' or 'https://' in the field
- if ( $url == 'http://' OR $url == 'https://' ) {
-
- // clear
- $url = '';
-
- }
-
- }
-
-
-
- // --<
- return $url;
-
- }
- endif; // commentpress_get_user_link
- if ( ! function_exists( 'commentpress_echo_post_meta' ) ):
- /**
- * @description: show user(s) in the loop
- * @todo:
- *
- */
- function commentpress_echo_post_meta() {
- // compat with Co-Authors Plus
- if ( function_exists( 'get_coauthors' ) ) {
-
- // get multiple authors
- $authors = get_coauthors();
- //print_r( $authors ); die();
-
- // if we get some
- if ( !empty( $authors ) ) {
-
- // use the Co-Authors format of "name, name, name & name"
- $author_html = '';
-
- // init counter
- $n = 1;
-
- // find out how many author we have
- $author_count = count( $authors );
-
- // loop
- foreach( $authors AS $author ) {
-
- // default to comma
- $sep = ', ';
-
- // if we're on the penultimate
- if ( $n == ($author_count - 1) ) {
-
- // use ampersand
- $sep = __( ' & ', 'commentpress-core' );
-
- }
-
- // if we're on the last, don't add
- if ( $n == $author_count ) { $sep = ''; }
-
- // get name
- $author_html .= commentpress_echo_post_author( $author->ID, false );
-
- // and separator
- $author_html .= $sep;
-
- // increment
- $n++;
-
- // yes - are we showing avatars?
- if ( get_option('show_avatars') ) {
-
- // get avatar
- echo get_avatar( $author->ID, $size='32' );
-
- }
-
- }
-
- ?><cite class="fn"><?php echo $author_html; ?></cite>
-
- <p><a href="<?php the_permalink() ?>"><?php the_time('l, F jS, Y') ?></a></p>
-
- <?php
-
- }
-
- } else {
-
- // get avatar
- $author_id = get_the_author_meta( 'ID' );
- echo get_avatar( $author_id, $size='32' );
-
- ?>
-
- <cite class="fn"><?php commentpress_echo_post_author( $author_id ) ?></cite>
-
- <p><a href="<?php the_permalink() ?>"><?php the_time('l, F jS, Y') ?></a></p>
-
- <?php
-
- }
-
- }
- endif; // commentpress_echo_post_meta
- if ( ! function_exists( 'commentpress_show_source_url' ) ):
- /**
- * @description: show source URL for print
- * @todo:
- *
- */
- function commentpress_show_source_url() {
- // add the URL - hidden, but revealed by print stylesheet
- ?><p class="hidden_page_url"><?php
-
- // label
- echo __( 'Source: ', 'commentpress-core' );
-
- // path from server array, if set
- $path = ( isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : '';
-
- // get server, if set
- $server = ( isset( $_SERVER['SERVER_NAME'] ) ) ? $_SERVER['SERVER_NAME'] : '';
-
- // get protocol, if set
- $protocol = ( !empty( $_SERVER['HTTPS'] ) ) ? 'https' : 'http';
-
- // construct URL
- $url = $protocol.'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
-
- // echo
- echo $url;
-
- ?></p><?php
- }
- endif; // commentpress_show_source_url
- // add after theme setup hook
- add_action( 'wp_footer', 'commentpress_show_source_url' );
- if ( ! function_exists( 'commentpress_echo_post_author' ) ):
- /**
- * @description: show username (with link) in the loop
- * @todo:
- *
- */
- function commentpress_echo_post_author( $author_id, $echo = true ) {
- // get author details
- $user = get_userdata( $author_id );
-
- // kick out if we don't have a user with that ID
- if ( !is_object( $user ) ) { return; }
-
-
-
- // access plugin
- global $commentpress_core, $post;
- // if we have the plugin enabled and it's BP
- if ( is_object( $post ) AND is_object( $commentpress_core ) AND $commentpress_core->is_buddypress() ) {
-
- // construct user link
- $author = bp_core_get_userlink( $user->ID );
- } else {
-
- // link to theme's author page
- $link = sprintf(
- '%1$s',//JVDP
- esc_html( $user->display_name )
- );
- $author = apply_filters( 'the_author_posts_link', $link );
- }
-
- // if we're echoing
- if ( $echo ) {
- echo $author;
- } else {
- return $author;
- }
-
- }
- endif; // commentpress_echo_post_author
- if ( ! function_exists( 'commentpress_format_comment' ) ):
- /**
- * @description: format comment on comments pages
- * @todo:
- *
- */
- function commentpress_format_comment( $comment, $context = 'all' ) {
- // declare access to globals
- global $wpdb, $commentpress_core, $cp_comment_output;
- // enable Wordpress API on comment
- //$GLOBALS['comment'] = $comment;
- // if context is 'all comments'...
- if ( $context == 'all' ) {
-
- // get author
- if ( $comment->comment_author != '' ) {
-
- // was it a registered user?
- if ( $comment->user_id != '0' ) {
-
- // get user details
- $user = get_userdata( $comment->user_id );
- //print_r( $user->display_name ); die();
-
- // get user link
- $user_link = commentpress_get_user_link( $user );
-
- // construct link to user url
- $_context = ( $user_link != '' AND $user_link != 'http://' ) ?
- 'by <a href="'.$user_link.'">'.$comment->comment_author.'</a>' :
- 'by '.$comment->comment_author;
-
- } else {
-
- // construct link to commenter url
- $_context = ( $comment->comment_author_url != '' AND $comment->comment_author_url != 'http://' ) ?
- 'by <a href="'.$comment->comment_author_url.'">'.$comment->comment_author.'</a>' :
- 'by '.$comment->comment_author;
-
- }
-
-
- } else {
-
- // we don't have a name
- $_context = __( 'by Anonymous', 'commentpress-core' );
-
- }
-
- // if context is 'by commenter'
- } elseif ( $context == 'by' ) {
-
- // construct link
- $_page_link = trailingslashit( get_permalink( $comment->comment_post_ID ) );
-
- // construct context
- $_context = 'on <a href="'.$_page_link.'">'.$comment->post_title.'</a>';
-
- }
-
- // construct link
- $_comment_link = get_comment_link( $comment->comment_ID );
- // comment header
- $_comment_meta = '<div class="comment_meta"><a href="'.$_comment_link.'" title="See comment in context">Comment</a> '.$_context.' on '.date('F jS, Y',strtotime($comment->comment_date)).'</div>'."\n";
- // comment content
- $_comment_body = '<div class="comment-content">'.wpautop(convert_chars(wptexturize($comment->comment_content))).'</div>'."\n";
-
- // construct comment
- return '<div class="comment_wrapper">'."\n".$_comment_meta.$_comment_body.'</div>'."\n\n";
-
- }
- endif; // commentpress_format_comment
- if ( ! function_exists( 'commentpress_get_all_comments_content' ) ):
- /**
- * @description: all-comments page display function
- * @todo:
- *
- */
- function commentpress_get_all_comments_content( $page_or_post = 'page' ) {
- // declare access to globals
- global $wpdb, $commentpress_core, $cp_comment_output;
- // init page content
- $_page_content = '';
-
-
-
- // construct query
- $querystr = "
- SELECT $wpdb->comments.*, $wpdb->posts.post_title, $wpdb->posts.post_name, $wpdb->posts.comment_count
- FROM $wpdb->comments, $wpdb->posts
- WHERE $wpdb->comments.comment_post_ID = $wpdb->posts.ID
- AND $wpdb->posts.post_type = '$page_or_post'
- AND $wpdb->comments.comment_approved = '1'
- AND $wpdb->comments.comment_parent = '0'
- AND $wpdb->comments.comment_type != 'pingback'
- AND $wpdb->posts.post_status = 'publish'
- ORDER BY $wpdb->posts.comment_count DESC, $wpdb->comments.comment_post_ID, $wpdb->comments.comment_date ASC
- ";
-
- //echo $querystr; exit();
-
-
- // get data
- $_data = $wpdb->get_results($querystr, OBJECT);
-
-
-
- // did we get any?
- if ( count( $_data ) > 0 ) {
-
-
-
- // open ul
- $_page_content .= '<ul class="all_comments_listing">'."\n\n";
-
- // init title
- $_title = '';
-
- // init global comment output
- $cp_comment_output = '';
-
- // loop
- foreach ($_data as $comment) {
-
-
-
- // show page title, if not shown
- if ( $_title != $comment->post_title ) {
-
- // if not first...
- if ( $_title != '' ) {
-
- // close ul
- $_page_content .= '</ul>'."\n\n";
-
- // close item div
- $_page_content .= '</div><!-- /item_body -->'."\n\n";
-
- // close li
- $_page_content .= '</li><!-- /page li -->'."\n\n\n\n";
-
- }
-
- // open li
- $_page_content .= '<li class="page_li"><!-- page li -->'."\n\n";
-
- // count comments
- if ( $comment->comment_count > 1 ) { $_comment_count_text = 'comments'; } else { $_comment_count_text = 'comment'; }
-
- // show it
- $_page_content .= '<h3>'.$comment->post_title.' <span>('.$comment->comment_count.' '.$_comment_count_text.')</span></h3>'."\n\n";
-
- // open comments div
- $_page_content .= '<div class="item_body">'."\n\n";
-
- // open ul
- $_page_content .= '<ul class="item_ul">'."\n\n";
-
- // set mem
- $_title = $comment->post_title;
-
- }
-
-
- // open li
- $_page_content .= '<li class="item_li"><!-- item li -->'."\n\n";
-
- // show the comment
- $_page_content .= commentpress_format_comment( $comment );
-
- // get comment children
- $children = commentpress_get_children( $comment, $page_or_post );
-
- // do we have any?
- if( count( $children ) > 0 ) {
-
- // recurse
- commentpress_get_comments( $children, $page_or_post );
-
- // show them
- $_page_content .= $cp_comment_output;
-
- // clear global comment output
- $cp_comment_output = '';
-
- }
-
- // close li
- $_page_content .= '</li><!-- /item li -->'."\n\n";
-
-
-
- }
-
- // close ul
- $_page_content .= '</ul>'."\n\n";
-
- // close item div
- $_page_content .= '</div><!-- /item_body -->'."\n\n";
-
- // close li
- $_page_content .= '</li><!-- /page li -->'."\n\n\n\n";
-
- // close ul
- $_page_content .= '</ul><!-- /all_comments_listing -->'."\n\n";
-
- }
-
-
-
- // --<
- return $_page_content;
-
- }
- endif; // commentpress_get_all_comments_content
-
-
-
- if ( ! function_exists( 'commentpress_get_all_comments_page_content' ) ):
- /**
- * @description: all-comments page display function
- * @todo:
- *
- */
- function commentpress_get_all_comments_page_content() {
- // declare access to globals
- global $commentpress_core;
-
-
- // set default
- $pagetitle = apply_filters(
- 'cp_page_all_comments_title',
- __( 'All Comments', 'commentpress-core' )
- );
- // set title
- $_page_content = '<h2 class="post_title">'.$pagetitle.'</h2>'."\n\n";
-
- // get page or post
- $page_or_post = $commentpress_core->get_list_option();
-
-
-
- // set default
- $blogtitle = apply_filters(
- 'cp_page_all_comments_blog_title',
- __( 'Comments on the Blog', 'commentpress-core' )
- );
- // set default
- $booktitle = apply_filters(
- 'cp_page_all_comments_book_title',
- __( 'Comments on the Pages', 'commentpress-core' )
- );
- // get title
- $title = ( $page_or_post == 'page' ) ? $booktitle : $blogtitle;
-
- // set title
- $_page_content .= '<p class="comments_hl">'.$title.'</p>'."\n\n";
-
- // get data
- $_page_content .= commentpress_get_all_comments_content( $page_or_post );
-
-
-
- // get data for other page type
- $other_type = ( $page_or_post == 'page' ) ? 'post': 'page';
-
- // get title
- $title = ( $page_or_post == 'page' ) ? $blogtitle : $booktitle;
-
- // set title
- $_page_content .= '<p class="comments_hl">'.$title.'</p>'."\n\n";
-
- // get data
- $_page_content .= commentpress_get_all_comments_content( $other_type );
-
-
-
- // --<
- return $_page_content;
-
- }
- endif; // commentpress_get_all_comments_page_content
-
-
- if ( ! function_exists( 'commentpress_get_comments_by_content' ) ):
- /**
- * @description: comments-by page display function
- * @todo: do we want trackbacks?
- *
- */
- function commentpress_get_comments_by_content() {
- // declare access to globals
- global $wpdb, $commentpress_core;
- // init page content
- $_page_content = '';
-
-
-
- // construct query
- $querystr = "
- SELECT $wpdb->comments.*, $wpdb->posts.post_title, $wpdb->posts.post_name
- FROM $wpdb->comments, $wpdb->posts
- WHERE $wpdb->comments.comment_post_ID = $wpdb->posts.ID
- AND $wpdb->comments.comment_type != 'pingback'
- AND $wpdb->comments.comment_approved = '1'
- AND $wpdb->posts.post_status = 'publish'
- ORDER BY $wpdb->comments.comment_author, $wpdb->posts.post_title, $wpdb->comments.comment_post_ID, $wpdb->comments.comment_date ASC
- ";
-
- //echo $querystr; exit();
-
-
- // get data
- $_data = $wpdb->get_results( $querystr, OBJECT );
-
- //print_r( $_data ); exit();
-
-
- // did we get any?
- if ( count( $_data ) > 0 ) {
-
-
-
- // open ul
- $_page_content .= '<ul class="all_comments_listing">'."\n\n";
-
- // init title
- $_title = '';
-
- // loop
- foreach ($_data as $comment) {
-
- // test for anonymous comment (usually generated by WP itself in multisite installs)
- if ( empty( $comment->comment_author ) ) {
-
- $comment->comment_author = 'Anonymous';
-
- }
-
- // show commenter, if not shown
- if ( $_title != $comment->comment_author ) {
-
- // if not first...
- if ( $_title != '' ) {
-
- // close ul
- $_page_content .= '</ul>'."\n\n";
-
- // close item div
- $_page_content .= '</div><!-- /item_body -->'."\n\n";
-
- // close li
- $_page_content .= '</li><!-- /author li -->'."\n\n\n\n";
-
- }
-
- // open li
- $_page_content .= '<li class="author_li"><!-- author li -->'."\n\n";
-
- // count comments
- //if ( $comment->comment_count > 1 ) { $_comment_count_text = 'comments'; } else { $_comment_count_text = 'comment'; }
-
- // show it -- <span>('.$comment->comment_count.' '.$_comment_count_text.')</span>
-
- // add gravatar
- $_page_content .= '<h3>'.get_avatar( $comment, $size='24' ).$comment->comment_author.'</h3>'."\n\n";
-
- // open comments div
- $_page_content .= '<div class="item_body">'."\n\n";
-
- // open ul
- $_page_content .= '<ul class="item_ul">'."\n\n";
-
- // set mem
- $_title = $comment->comment_author;
-
- }
-
-
- // open li
- $_page_content .= '<li class="item_li"><!-- item li -->'."\n\n";
-
- // show the comment
- $_page_content .= commentpress_format_comment( $comment, 'by' );
-
- // close li
- $_page_content .= '</li><!-- /item li -->'."\n\n";
-
-
-
- }
-
- // close ul
- $_page_content .= '</ul>'."\n\n";
-
- // close item div
- $_page_content .= '</div><!-- /item_body -->'."\n\n";
-
- // close li
- $_page_content .= '</li><!-- /author li -->'."\n\n\n\n";
-
- // close ul
- $_page_content .= '</ul><!-- /all_comments_listing -->'."\n\n";
-
- }
-
-
-
- // --<
- return $_page_content;
-
- }
- endif; // commentpress_get_comments_by_content
-
-
- if ( ! function_exists( 'commentpress_get_comments_by_page_content' ) ):
- /**
- * @description: comments-by page display function
- * @todo:
- *
- */
- function commentpress_get_comments_by_page_content() {
- // declare access to globals
- global $commentpress_core;
-
-
- // set title
- $_page_content = '<h2 class="post_title">Comments by Commenter</h2>'."\n\n";
- // get data
- $_page_content .= commentpress_get_comments_by_content();
-
-
- // --<
- return $_page_content;
-
- }
- endif; // commentpress_get_comments_by_page_content
-
-
- if ( ! function_exists( 'commentpress_show_activity_tab' ) ):
- /**
- * @description: decide whether or not to show the Activity Sidebar
- * @todo:
- *
- */
- function commentpress_show_activity_tab() {
- // declare access to globals
- global $commentpress_core, $post;
-
-
- /*
- // if we have the plugin enabled...
- if ( is_object( $commentpress_core ) ) {
-
- // is this multisite?
- if (
-
- ( is_multisite()
- AND is_main_site()
- AND $commentpress_core->is_buddypress_special_page() )
- OR !is_object( $post )
-
- ) {
-
- // ignore activity
- return false;
-
- }
-
- }
- */
- // --<
- return true;
-
- }
- endif; // commentpress_show_activity_tab
-
-
- if ( ! function_exists( 'commentpress_is_commentable' ) ):
- /**
- * @description: decide whether or not to show the Activity Sidebar
- * @todo:
- *
- */
- function commentpress_is_commentable() {
- // declare access to plugin
- global $commentpress_core;
-
- // if we have it...
- if ( is_object( $commentpress_core ) ) {
-
- // return what it reports
- return $commentpress_core->is_commentable();
-
- }
-
- // --<
- return false;
-
- }
- endif; // commentpress_is_commentable
-
-
- if ( ! function_exists( 'commentpress_get_comment_activity' ) ):
- /**
- * @description: activity sidebar display function
- * @todo: do we want trackbacks?
- *
- */
- function commentpress_get_comment_activity( $scope = 'all' ) {
- // declare access to globals
- global $wpdb, $commentpress_core, $post;
- // init page content
- $_page_content = '';
-
-
-
- // define defaults
- $args = array(
-
- 'number' => 10,
- 'status' => 'approve',
-
- // exclude trackbacks and pingbacks until we decide what to do with them
- 'type' => ''
-
- );
-
- // if we are on a 404, for example
- if ( $scope == 'post' AND is_object( $post ) ) {
-
- // get all comments
- $args['post_id'] = $post->ID;
- }
-
- // get 'em
- $_data = get_comments( $args );
- //print_r( $_data ); exit();
-
-
-
- // did we get any?
- if ( count( $_data ) > 0 ) {
-
-
-
- // open ul
- $_page_content .= '<ol class="comment_activity">'."\n\n";
-
- // init title
- $_title = '';
-
- // loop
- foreach ($_data as $comment) {
-
- // enable Wordpress API on comment
- $GLOBALS['comment'] = $comment;
-
- // only comments until we decide what to do with pingbacks
- if ( $comment->comment_type != 'pingback' ) //{
- // test for anonymous comment (usually generated by WP itself in multisite installs)
- if ( empty( $comment->comment_author ) ) {
-
- $comment->comment_author = 'Anonymous';
-
- }
-
-
- // was it a registered user?
- if ( $comment->user_id != '0' ) {
-
- // get user details
- $user = get_userdata( $comment->user_id );
- //print_r( $user->display_name ); die();
-
- // get user link
- $user_link = commentpress_get_user_link( $user );
-
- // construct author citation
- $author = '<cite class="fn"><a href="'.$user_link.'">'.esc_html( $comment->comment_author ).'</a></cite>';
-
- // construct link to user url
- $author = ( $user_link != '' AND $user_link != 'http://' ) ?
- '<cite class="fn"><a href="'.$user_link.'">'.esc_html( $comment->comment_author ).'</a></cite>' :
- '<cite class="fn">'.esc_html( $comment->comment_author ).'</cite>';
-
- } else {
-
- // construct link to commenter url
- $author = ( $comment->comment_author_url != '' AND $comment->comment_author_url != 'http://' ) ?
- '<cite class="fn"><a href="'.$comment->comment_author_url.'">'.esc_html( $comment->comment_author ).'</a></cite>' :
- '<cite class="fn">'.esc_html( $comment->comment_author ).'</cite>';
-
- }
-
-
-
- // approved comment?
- if ($comment->comment_approved == '0') {
- $comment_text = '<p><em>Comment awaiting moderation</em></p>';
- } else {
- $comment_text = get_comment_text( $comment->comment_ID );
- }
-
-
-
- // default to not on post
- $is_on_current_post = '';
- // on current post?
- if ( is_singular() AND is_object( $post ) AND $comment->comment_post_ID == $post->ID ) {
-
- // access paging globals
- global $multipage, $page;
-
- // is it the same page, if paged?
- if ( $multipage ) {
-
- /*
- print_r( array(
- 'multipage' => $multipage,
- 'page' => $page
- ) ); die();
- */
-
- // if it has a text sig
- if (
-
- !is_null( $comment->comment_signature )
- AND $comment->comment_signature != ''
-
- ) {
-
- // set key
- $key = '_cp_comment_page';
-
- // if the custom field already has a value...
- if ( get_comment_meta( $comment->comment_ID, $key, true ) != '' ) {
-
- // get comment's page from meta
- $page_num = get_comment_meta( $comment->comment_ID, $key, true );
-
- // is it this one?
- if ( $page_num == $page ) {
-
- // is the right page
- $is_on_current_post = ' comment_on_post';
-
- }
- …
Large files files are truncated, but you can click here to view the full file