PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/code/cake/app/webroot/cp/wp-content/plugins/commentpress-core/themes/commentpress-theme/functions.php

https://github.com/DigitalPaulScholtenProject/DPSP-Platform
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

  1. <?php /*
  2. ================================================================================
  3. CommentPress Default Theme Functions
  4. ================================================================================
  5. AUTHOR: Christian Wach <needle@haystack.co.uk>
  6. --------------------------------------------------------------------------------
  7. NOTES
  8. --------------------------------------------------------------------------------
  9. */
  10. /**
  11. * Set the content width based on the theme's design and stylesheet.
  12. * This seems to be a Wordpress requirement - though rather dumb in the
  13. * context of our theme, which has a percentage-based default width.
  14. * I have arbitrarily set it to the default content-width when viewing
  15. * on a 1280px-wide screen.
  16. */
  17. if ( !isset( $content_width ) ) { $content_width = 588; }
  18. if ( ! function_exists( 'commentpress_setup' ) ):
  19. /**
  20. * @description: get an ID for the body tag
  21. * @todo:
  22. *
  23. */
  24. function commentpress_setup(
  25. ) { //-->
  26. /**
  27. * Make CommentPress Default Theme available for translation.
  28. * Translations can be added to the /assets/languages/ directory.
  29. */
  30. /*
  31. // we no longer use this: instead, the plugin's textdomain is used
  32. load_theme_textdomain(
  33. 'commentpress-theme',
  34. get_template_directory() . '/assets/languages'
  35. );
  36. */
  37. // add_custom_background function is deprecated in WP 3.4+
  38. global $wp_version;
  39. if ( version_compare( $wp_version, '3.4', '>=' ) ) {
  40. // -------------------------
  41. // TO DO: test 3.4 features
  42. // -------------------------
  43. // allow custom backgrounds
  44. add_theme_support( 'custom-background' );
  45. // allow custom header
  46. add_theme_support( 'custom-header', array(
  47. 'default-text-color' => 'eeeeee',
  48. 'width' => apply_filters( 'cp_header_image_width', 940 ),
  49. 'height' => apply_filters( 'cp_header_image_height', 67 ),
  50. 'wp-head-callback' => 'commentpress_header',
  51. 'admin-head-callback' => 'commentpress_admin_header'
  52. ) );
  53. } else {
  54. // retain old declarations for earlier versions
  55. add_custom_background();
  56. // header text colour
  57. define( 'HEADER_TEXTCOLOR', 'eeeeee' );
  58. // set height and width
  59. define( 'HEADER_IMAGE_WIDTH', apply_filters( 'cp_header_image_width', 940 ) );
  60. define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'cp_header_image_height', 67 ) );
  61. // allow custom header images
  62. add_custom_image_header( 'commentpress_header', 'commentpress_admin_header' );
  63. }
  64. // Default custom headers packaged with the theme (see Twenty Eleven)
  65. // A nice side-effect of supplying a default header image is that it triggers the
  66. // "Header Image" option in the Theme Customizer
  67. // %s is a placeholder for the theme template directory URI
  68. register_default_headers(
  69. array(
  70. 'caves-green' => array(
  71. 'url' => '%s/assets/images/header/caves-green.jpg',
  72. 'thumbnail_url' => '%s/assets/images/header/caves-green-thumbnail.jpg',
  73. /* translators: header image description */
  74. 'description' => __( 'Abstract Green', 'commentpress-core' )
  75. ),
  76. 'caves-red' => array(
  77. 'url' => '%s/assets/images/header/caves-red.jpg',
  78. 'thumbnail_url' => '%s/assets/images/header/caves-red-thumbnail.jpg',
  79. /* translators: header image description */
  80. 'description' => __( 'Abstract Red', 'commentpress-core' )
  81. ),
  82. 'caves-blue' => array(
  83. 'url' => '%s/assets/images/header/caves-blue.jpg',
  84. 'thumbnail_url' => '%s/assets/images/header/caves-blue-thumbnail.jpg',
  85. /* translators: header image description */
  86. 'description' => __( 'Abstract Blue', 'commentpress-core' )
  87. ),
  88. 'caves-violet' => array(
  89. 'url' => '%s/assets/images/header/caves-violet.jpg',
  90. 'thumbnail_url' => '%s/assets/images/header/caves-violet-thumbnail.jpg',
  91. /* translators: header image description */
  92. 'description' => __( 'Abstract Violet', 'commentpress-core' )
  93. )
  94. )
  95. );
  96. // auto feed links
  97. add_theme_support( 'automatic-feed-links' );
  98. // style the visual editor with editor-style.css to match the theme style
  99. add_editor_style();
  100. // testing the use of wp_nav_menu() - first we need to register it
  101. register_nav_menu( 'toc', __( 'Table of Contents', 'commentpress-core' ) );
  102. }
  103. endif; // commentpress_setup
  104. // add after theme setup hook
  105. add_action( 'after_setup_theme', 'commentpress_setup' );
  106. if ( ! function_exists( 'commentpress_enqueue_theme_styles' ) ):
  107. /**
  108. * @description: add buddypress front-end styles
  109. * @todo:
  110. *
  111. */
  112. function commentpress_enqueue_theme_styles() {
  113. // kick out on admin
  114. if ( is_admin() ) { return; }
  115. // init
  116. $dev = '';
  117. // check for dev
  118. if ( defined( 'SCRIPT_DEBUG' ) AND SCRIPT_DEBUG === true ) {
  119. $dev = '.dev';
  120. }
  121. // add BuddyPress css
  122. wp_enqueue_style(
  123. 'cp_buddypress_css',
  124. get_template_directory_uri() . '/assets/css/bp-overrides'.$dev.'.css',
  125. array( 'cp_layout_css' ),
  126. COMMENTPRESS_VERSION, // version
  127. 'all' // media
  128. );
  129. }
  130. endif; // commentpress_enqueue_theme_styles
  131. if ( ! function_exists( 'commentpress_enqueue_bp_theme_styles' ) ):
  132. /**
  133. * @description: enqueue buddypress front-end styles
  134. * @todo:
  135. *
  136. */
  137. function commentpress_enqueue_bp_theme_styles() {
  138. // add a filter to include bp-overrides when buddypress is active
  139. add_action( 'wp_enqueue_scripts', 'commentpress_enqueue_theme_styles', 101 );
  140. }
  141. endif; // commentpress_enqueue_bp_theme_styles
  142. // add an action for the above
  143. add_action( 'bp_setup_globals', 'commentpress_enqueue_theme_styles' );
  144. if ( ! function_exists( 'commentpress_enqueue_scripts_and_styles' ) ):
  145. /**
  146. * @description: add front-end print styles
  147. * @todo:
  148. *
  149. */
  150. function commentpress_enqueue_scripts_and_styles() {
  151. // -------------------------------------------------------------------------
  152. // Stylesheets
  153. // -------------------------------------------------------------------------
  154. // register reset
  155. wp_register_style(
  156. 'cp_reset_css', // unique id
  157. get_template_directory_uri() . '/assets/css/reset.css', // src
  158. array(), // dependencies
  159. COMMENTPRESS_VERSION, // version
  160. 'all' // media
  161. );
  162. // init
  163. $dev = '';
  164. // check for dev
  165. if ( defined( 'SCRIPT_DEBUG' ) AND SCRIPT_DEBUG === true ) {
  166. $dev = '.dev';
  167. }
  168. // add typography css
  169. wp_enqueue_style(
  170. 'cp_typography_css',
  171. get_template_directory_uri() . '/assets/css/typography'.$dev.'.css',
  172. array( 'cp_reset_css' ),
  173. COMMENTPRESS_VERSION, // version
  174. 'all' // media
  175. );
  176. // add layout css
  177. wp_enqueue_style(
  178. 'cp_layout_css',
  179. get_template_directory_uri() . '/assets/css/layout'.$dev.'.css',
  180. array( 'cp_typography_css' ),
  181. COMMENTPRESS_VERSION, // version
  182. 'all' // media
  183. );
  184. // -------------------------------------------------------------------------
  185. // Overrides for styles - for child themes, dequeue these and add you own
  186. // -------------------------------------------------------------------------
  187. // add Google Webfont "Lato"
  188. wp_enqueue_style(
  189. 'cp_webfont_css',
  190. 'http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic',
  191. array( 'cp_layout_css' ),
  192. null, // no version, thanks
  193. null // no media, thanks
  194. );
  195. // add colours css
  196. wp_enqueue_style(
  197. 'cp_colours_css',
  198. get_template_directory_uri() . '/assets/css/colours-01'.$dev.'.css',
  199. array( 'cp_webfont_css' ),
  200. COMMENTPRESS_VERSION, // version
  201. 'all' // media
  202. );
  203. // -------------------------------------------------------------------------
  204. // Javascripts
  205. // -------------------------------------------------------------------------
  206. // access plugin
  207. global $commentpress_core;
  208. // if we have the plugin enabled...
  209. if ( is_object( $commentpress_core ) ) {
  210. // enqueue common js
  211. wp_enqueue_script(
  212. 'cp_common_js',
  213. get_template_directory_uri() . '/assets/js/cp_js_common'.$dev.'.js',
  214. array( 'jquery_commentpress' )
  215. );
  216. // test for buddypress special page
  217. if ( $commentpress_core->is_buddypress() AND $commentpress_core->is_buddypress_special_page() ) {
  218. // skip custom addComment
  219. } else {
  220. // enqueue form js
  221. wp_enqueue_script(
  222. 'cp_form',
  223. get_template_directory_uri() . '/assets/js/cp_js_form'.$dev.'.js',
  224. array( 'cp_common_js' )
  225. );
  226. }
  227. // test for CommentPress Core special page
  228. if ( $commentpress_core->db->is_special_page() ) {
  229. // enqueue accordion-like js
  230. wp_enqueue_script(
  231. 'cp_special',
  232. get_template_directory_uri() . '/assets/js/cp_js_all_comments.js',
  233. array( 'cp_form' )
  234. );
  235. }
  236. // get vars
  237. $vars = $commentpress_core->db->get_javascript_vars();
  238. // localise with wp function
  239. wp_localize_script( 'cp_common_js', 'CommentpressSettings', $vars );
  240. }
  241. }
  242. endif; // commentpress_enqueue_scripts_and_styles
  243. // add a filter for the above, very late so it (hopefully) is last in the queue
  244. add_action( 'wp_enqueue_scripts', 'commentpress_enqueue_scripts_and_styles', 100 );
  245. if ( ! function_exists( 'commentpress_enqueue_print_styles' ) ):
  246. /**
  247. * @description: add front-end print styles
  248. * @todo:
  249. *
  250. */
  251. function commentpress_enqueue_print_styles() {
  252. // init
  253. $dev = '';
  254. // check for dev
  255. if ( defined( 'SCRIPT_DEBUG' ) AND SCRIPT_DEBUG === true ) {
  256. $dev = '.dev';
  257. }
  258. // -------------------------------------------------------------------------
  259. // Print stylesheet included last
  260. // -------------------------------------------------------------------------
  261. // add print css
  262. wp_enqueue_style(
  263. 'cp_print_css',
  264. get_template_directory_uri() . '/assets/css/print'.$dev.'.css',
  265. array( 'cp_layout_css' ),
  266. COMMENTPRESS_VERSION, // version
  267. 'print'
  268. );
  269. }
  270. endif; // commentpress_enqueue_print_styles
  271. // add a filter for the above, very late so it (hopefully) is last in the queue
  272. add_action( 'wp_enqueue_scripts', 'commentpress_enqueue_print_styles', 101 );
  273. if ( ! function_exists( 'commentpress_header' ) ):
  274. /**
  275. * @description: custom header
  276. * @todo:
  277. *
  278. */
  279. function commentpress_header(
  280. ) { //-->
  281. // init (same as bg in layout.css and default in class_commentpress_db.php)
  282. $bg_colour = '2c2622';
  283. // access plugin
  284. global $commentpress_core;
  285. // if we have the plugin enabled...
  286. if ( is_object( $commentpress_core ) ) {
  287. // override
  288. $bg_colour = $commentpress_core->db->option_get_header_bg();
  289. }
  290. // allow overrides
  291. $bg_colour = apply_filters( 'cp_default_header_bgcolor', $bg_colour );
  292. // init background-image
  293. $bg_image = '';
  294. // get header image
  295. $header_image = get_header_image();
  296. // do we have a background-image?
  297. if ( $header_image ) {
  298. $bg_image = 'background-image: url("'.$header_image.'");';
  299. }
  300. // get custom text colour
  301. // note: this does NOT retrieve the default if not manually set in the Theme Customizer in WP3.4
  302. $text_color = get_header_textcolor();
  303. // WP3.4 seems to behave differently.
  304. global $wp_version;
  305. if ( version_compare( $wp_version, '3.4', '>=' ) ) {
  306. // if blank, we're hiding the title
  307. if ( $text_color == 'blank' ) {
  308. $css = 'text-indent: -9999px;';
  309. } else {
  310. // if empty, we need to use default
  311. if ( $text_color == '' ) {
  312. $css = 'color: #'.HEADER_TEXTCOLOR.';';
  313. } else {
  314. // use the custom one. I know this amounts to the same thing.
  315. $css = 'color: #'.$text_color.';';
  316. }
  317. }
  318. } else {
  319. // use previous logic
  320. if ( $text_color == 'blank' OR $text_color == '' ) {
  321. $css = 'text-indent: -9999px;';
  322. } else {
  323. $css = 'color: #'.$text_color.';';
  324. }
  325. }
  326. // build inline styles
  327. echo '
  328. <style type="text/css">
  329. #book_header
  330. {
  331. background-color: #'.$bg_colour.';
  332. '.$bg_image.'
  333. -webkit-background-size: cover;
  334. -moz-background-size: cover;
  335. -o-background-size: cover;
  336. background-size: cover;
  337. background-repeat: no-repeat;
  338. background-position: 50%;
  339. }
  340. #title h1,
  341. #title h1 a
  342. {
  343. '.$css.'
  344. }
  345. #book_header #tagline
  346. {
  347. '.$css.'
  348. }
  349. </style>
  350. ';
  351. }
  352. endif; // commentpress_header
  353. /*
  354. // if no custom options for text are set, ignore
  355. if ( $text_color == HEADER_TEXTCOLOR ) {
  356. // set flag
  357. $ignore = true;
  358. }
  359. // if blank or empty, we're hiding the title
  360. if ( $text_color == 'blank' OR $text_color == '' ) {
  361. }
  362. // If we get this far, we have custom styles. Let's do this.
  363. print_r( ( $text_color ? $text_color : 'nowt<br/>' ) );
  364. print_r( HEADER_TEXTCOLOR ); die();
  365. */
  366. if ( ! function_exists( 'commentpress_admin_header' ) ):
  367. /**
  368. * @description: custom admin header
  369. * @todo:
  370. *
  371. */
  372. function commentpress_admin_header(
  373. ) { //-->
  374. // init (same as bg in layout.css and default in class_commentpress_db.php)
  375. $colour = '2c2622';
  376. // access plugin
  377. global $commentpress_core;
  378. // if we have the plugin enabled...
  379. if ( is_object( $commentpress_core ) ) {
  380. // override
  381. $colour = $commentpress_core->db->option_get_header_bg();
  382. }
  383. // try and recreate the look of the theme header
  384. echo '
  385. <style type="text/css">
  386. .appearance_page_custom-header #headimg
  387. {
  388. min-height: 67px;
  389. }
  390. #headimg
  391. {
  392. background-color: #'.$colour.';
  393. }
  394. #headimg #name,
  395. #headimg #desc
  396. {
  397. margin-left: 20px;
  398. font-family: Helvetica, Arial, sans-serif;
  399. font-weight: normal;
  400. line-height: 1;
  401. color: #'.get_header_textcolor().';
  402. }
  403. #headimg h1
  404. {
  405. margin: 0;
  406. padding: 0;
  407. padding-top: 12px;
  408. }
  409. #headimg #name
  410. {
  411. font-size: 1em;
  412. text-decoration: none;
  413. }
  414. #headimg #desc
  415. {
  416. padding-top: 3px;
  417. font-size: 1.2em;
  418. font-style: italic;
  419. }
  420. </style>
  421. ';
  422. }
  423. endif; // commentpress_admin_header
  424. if ( ! function_exists( 'commentpress_customize_register' ) ) {
  425. /**
  426. * Implements CommentPress Default Theme options into Theme Customizer
  427. *
  428. * @param $wp_customize Theme Customizer object
  429. * @return void
  430. *
  431. */
  432. function commentpress_customize_register(
  433. $wp_customize
  434. ) { //-->
  435. // access plugin
  436. global $commentpress_core;
  437. // kick out if buddypress groupblog...
  438. if ( is_object( $commentpress_core ) AND $commentpress_core->is_groupblog() ) return;
  439. // add customizer section title
  440. $wp_customize->add_section( 'cp_inline_header_image', array(
  441. 'title' => __( 'Site Logo', 'commentpress-core' ),
  442. 'priority' => 35,
  443. ) );
  444. // add image
  445. $wp_customize->add_setting( 'commentpress_theme_settings[cp_inline_header_image]', array(
  446. 'default' => '',
  447. 'capability' => 'edit_theme_options',
  448. 'type' => 'option'
  449. ));
  450. $wp_customize->add_control( new WP_Customize_Image_Control(
  451. $wp_customize, 'cp_inline_header_image', array(
  452. 'label' => __( 'Logo Image', 'commentpress-core' ),
  453. 'section' => 'cp_inline_header_image',
  454. 'settings' => 'commentpress_theme_settings[cp_inline_header_image]',
  455. 'priority' => 1
  456. )));
  457. // add padding
  458. $wp_customize->add_setting( 'commentpress_theme_settings[cp_inline_header_padding]', array(
  459. 'default' => '',
  460. 'capability' => 'edit_theme_options',
  461. 'type' => 'option'
  462. ));
  463. $wp_customize->add_control( 'commentpress_theme_settings[cp_inline_header_padding]', array(
  464. 'label' => __( 'Top padding in px', 'commentpress-core' ),
  465. 'section' => 'cp_inline_header_image',
  466. 'type' => 'text'
  467. ) );
  468. }
  469. }
  470. add_action( 'customize_register', 'commentpress_customize_register' );
  471. if ( ! function_exists( 'commentpress_admin_menu' ) ) {
  472. /**
  473. * @description: adds more prominent menu item
  474. * @todo:
  475. *
  476. */
  477. function commentpress_admin_menu() {
  478. // Only add for WP3.4+
  479. global $wp_version;
  480. if ( version_compare( $wp_version, '3.4', '>=' ) ) {
  481. // add the Customize link to the admin menu
  482. add_theme_page( 'Customize', 'Customize', 'edit_theme_options', 'customize.php' );
  483. }
  484. }
  485. }
  486. add_action( 'admin_menu', 'commentpress_admin_menu' );
  487. if ( ! function_exists( 'commentpress_get_header_image' ) ):
  488. /**
  489. * @description: function that sets a header foreground image (a logo, for example)
  490. * @todo: inform users that header images are using a different method
  491. *
  492. */
  493. function commentpress_get_header_image(
  494. ) { //-->
  495. // access plugin
  496. global $commentpress_core;
  497. // test for groupblog
  498. if ( is_object( $commentpress_core ) AND $commentpress_core->is_groupblog() ) {
  499. // get group ID
  500. $group_id = get_groupblog_group_id( get_current_blog_id() );
  501. // get group avatar
  502. $avatar_options = array (
  503. 'item_id' => $group_id,
  504. 'object' => 'group',
  505. 'type' => 'full',
  506. 'alt' => 'Group avatar',
  507. 'class' => 'cp_logo_image cp_group_avatar',
  508. 'width' => 48,
  509. 'height' => 48,
  510. 'html' => true
  511. );
  512. // show group avatar
  513. echo bp_core_fetch_avatar( $avatar_options );
  514. // --<
  515. return;
  516. }
  517. // -------------------------------------------------------------------------
  518. // implement compatibility with WordPress Theme Customizer
  519. // -------------------------------------------------------------------------
  520. // get the new options
  521. $options = get_option( 'commentpress_theme_settings' );
  522. //print_r( $options ); die();
  523. // test for our new theme customizer option
  524. if ( isset( $options['cp_inline_header_image'] ) AND !empty( $options['cp_inline_header_image'] ) ) {
  525. // init top padding
  526. $style = '';
  527. // test for top padding
  528. if ( isset( $options['cp_inline_header_padding'] ) AND !empty( $options['cp_inline_header_padding'] ) ) {
  529. // override
  530. $style = ' style="padding-top: '.$options['cp_inline_header_padding'].'px"';
  531. }
  532. // show the uploaded image
  533. echo '<img src="'.$options['cp_inline_header_image'].'" class="cp_logo_image" '.$style.'alt="Logo" />';
  534. // --<
  535. return;
  536. }
  537. // -------------------------------------------------------------------------
  538. // our fallback is to go with the legacy method that some people might still be using
  539. // -------------------------------------------------------------------------
  540. // if we have the plugin enabled...
  541. if ( is_object( $commentpress_core ) AND $commentpress_core->db->option_get( 'cp_toc_page' ) ) {
  542. // set defaults
  543. $args = array(
  544. 'post_type' => 'attachment',
  545. 'numberposts' => 1,
  546. 'post_status' => null,
  547. 'post_parent' => $commentpress_core->db->option_get( 'cp_toc_page' )
  548. );
  549. // get them...
  550. $attachments = get_posts( $args );
  551. // well?
  552. if ( $attachments ) {
  553. // we only want the first
  554. $attachment = $attachments[0];
  555. }
  556. // if we have an image
  557. if ( isset( $attachment ) ) {
  558. // show it
  559. echo wp_get_attachment_image( $attachment->ID, 'full' );
  560. }
  561. }
  562. }
  563. endif; // commentpress_get_header_image
  564. if ( ! function_exists( 'commentpress_get_body_id' ) ):
  565. /**
  566. * @description: get an ID for the body tag
  567. * @todo:
  568. *
  569. */
  570. function commentpress_get_body_id(
  571. ) { //-->
  572. // init
  573. $_body_id = '';
  574. // is this multisite?
  575. if ( is_multisite() ) {
  576. // is this the main blog?
  577. if ( is_main_site() ) {
  578. // set main blog id
  579. $_body_id = ' id="main_blog"';
  580. }
  581. }
  582. // --<
  583. return $_body_id;
  584. }
  585. endif; // commentpress_get_body_id
  586. if ( ! function_exists( 'commentpress_get_body_classes' ) ):
  587. /**
  588. * @description: get classes for the body tag
  589. * @todo:
  590. *
  591. */
  592. function commentpress_get_body_classes(
  593. $raw = false
  594. ) { //-->
  595. // init
  596. $_body_classes = '';
  597. // access post and plugin
  598. global $post, $commentpress_core;
  599. // set default sidebar
  600. $sidebar_flag = 'toc';
  601. // if we have the plugin enabled...
  602. if ( is_object( $commentpress_core ) ) {
  603. // get sidebar
  604. $sidebar_flag = $commentpress_core->get_default_sidebar();
  605. }
  606. // set class by sidebar
  607. $sidebar_class = 'cp_sidebar_'.$sidebar_flag;
  608. // init commentable class
  609. $commentable = '';
  610. // if we have the plugin enabled...
  611. if ( is_object( $commentpress_core ) ) {
  612. // set class
  613. $commentable = ( $commentpress_core->is_commentable() ) ? ' commentable' : ' not_commentable';
  614. }
  615. // init layout class
  616. $layout_class = '';
  617. // if we have the plugin enabled...
  618. if ( is_object( $commentpress_core ) ) {
  619. // is this the title page?
  620. if (
  621. // be more defensive
  622. is_object( $post )
  623. AND isset( $post->ID )
  624. AND $post->ID == $commentpress_core->db->option_get( 'cp_welcome_page' )
  625. ) {
  626. // init layout
  627. $layout = '';
  628. // set key
  629. $key = '_cp_page_layout';
  630. // if the custom field already has a value...
  631. if ( get_post_meta( $post->ID, $key, true ) != '' ) {
  632. // get it
  633. $layout = get_post_meta( $post->ID, $key, true );
  634. }
  635. // if wide layout...
  636. if ( $layout == 'wide' ) {
  637. // set layout class
  638. $layout_class = ' full_width';
  639. }
  640. }
  641. }
  642. // set default page type
  643. $page_type = '';
  644. // if blog post...
  645. if ( is_single() ) {
  646. // add blog post class
  647. $page_type = ' blog_post';
  648. }
  649. // if we have the plugin enabled...
  650. if ( is_object( $commentpress_core ) ) {
  651. // is it a BP special page?
  652. if ( $commentpress_core->is_buddypress_special_page() ) {
  653. // add buddypress page class
  654. $page_type = ' buddypress_page';
  655. }
  656. // is it a CP special page?
  657. if ( $commentpress_core->db->is_special_page() ) {
  658. // add buddypress page class
  659. $page_type = ' commentpress_page';
  660. }
  661. }
  662. // set default type
  663. $groupblog_type = ' not-groupblog';
  664. // if we have the plugin enabled...
  665. if ( is_object( $commentpress_core ) ) {
  666. // if it's a groupblog
  667. if ( $commentpress_core->is_groupblog() ) {
  668. $groupblog_type = ' is-groupblog';
  669. }
  670. }
  671. // set default type
  672. $blog_type = '';
  673. // if we have the plugin enabled...
  674. if ( is_object( $commentpress_core ) ) {
  675. // get type
  676. $_type = $commentpress_core->db->option_get( 'cp_blog_type' );
  677. //print_r( $_type ); die();
  678. // get workflow
  679. $_workflow = $commentpress_core->db->option_get( 'cp_blog_workflow' );
  680. // allow plugins to override the blog type - for example if workflow is enabled,
  681. // it might be a new blog type as far as buddypress is concerned
  682. $_blog_type = apply_filters( 'cp_get_group_meta_for_blog_type', $_type, $_workflow );
  683. // if it's not the main site, add class
  684. if ( is_multisite() AND !is_main_site() ) {
  685. $blog_type = ' blogtype-'.intval( $_blog_type );
  686. }
  687. }
  688. // construct attribute
  689. $_body_classes = $sidebar_class.$commentable.$layout_class.$page_type.$groupblog_type.$blog_type;
  690. // if we want them wrapped, do so
  691. if ( !$raw ) {
  692. // preserve backwards compat for older child themes
  693. $_body_classes = ' class="'.$_body_classes.'"';
  694. }
  695. // --<
  696. return $_body_classes;
  697. }
  698. endif; // commentpress_get_body_classes
  699. if ( ! function_exists( 'commentpress_site_title' ) ):
  700. /**
  701. * @description: disable more link jump - from: http://codex.wordpress.org/Customizing_the_Read_More
  702. * @todo:
  703. *
  704. */
  705. function commentpress_site_title( $sep = '', $echo = true ){
  706. // is this multisite?
  707. if ( is_multisite() ) {
  708. // if we're on a sub-blog
  709. if ( !is_main_site() ) {
  710. global $current_site;
  711. // print?
  712. if( $echo ) {
  713. // add site name
  714. echo ' '.trim($sep).' '.$current_site->site_name;
  715. } else {
  716. // add site name
  717. return ' '.trim($sep).' '.$current_site->site_name;
  718. }
  719. }
  720. }
  721. }
  722. endif; // commentpress_site_title
  723. if ( ! function_exists( 'commentpress_remove_more_jump_link' ) ):
  724. /**
  725. * @description: disable more link jump - from: http://codex.wordpress.org/Customizing_the_Read_More
  726. * @todo:
  727. *
  728. */
  729. function commentpress_remove_more_jump_link( $link ) {
  730. $offset = strpos($link, '#more-');
  731. if ($offset) {
  732. $end = strpos($link, '"',$offset);
  733. }
  734. if ($end) {
  735. $link = substr_replace($link, '', $offset, $end-$offset);
  736. }
  737. // --<
  738. return $link;
  739. }
  740. endif; // commentpress_remove_more_jump_link
  741. // add a filter for the above
  742. add_filter( 'the_content_more_link', 'commentpress_remove_more_jump_link' );
  743. if ( ! function_exists( 'commentpress_page_navigation' ) ):
  744. /**
  745. * @description: builds a list of previous and next pages, optionally with comments
  746. * @todo:
  747. *
  748. */
  749. function commentpress_page_navigation( $with_comments = false ) {
  750. // declare access to globals
  751. global $commentpress_core;
  752. // is the plugin active?
  753. if ( !is_object( $commentpress_core ) ) {
  754. // --<
  755. return;
  756. }
  757. // init formatting
  758. $before_next = '<li class="alignright">';
  759. $after_next = ' </li>';
  760. $before_prev = '<li class="alignleft">';
  761. $after_prev = '</li>';
  762. // init
  763. $next_page_html = '';
  764. // get next page
  765. $next_page = $commentpress_core->nav->get_next_page( $with_comments );
  766. //var_dump( $next_page );
  767. // did we get a next page?
  768. if ( is_object( $next_page ) ) {
  769. // init title
  770. $img = '';
  771. $title = __( 'Next page', 'commentpress-core' ); //htmlentities( $next_page->post_title );
  772. // if we wanted pages with comments...
  773. if ( $with_comments ) {
  774. // set title
  775. $title = __( 'Next page with comments', 'commentpress-core' );
  776. $img = '<img src="'.get_template_directory_uri().'/assets/images/next.png" />';
  777. }
  778. // define list item
  779. $next_page_html = $before_next.
  780. $img.'<a href="'.get_permalink( $next_page->ID ).'" id="next_page" class="css_btn" title="'.$title.'">'.$title.'</a>'.$after_next;
  781. }
  782. // init
  783. $prev_page_html = '';
  784. // get next page
  785. $prev_page = $commentpress_core->nav->get_previous_page( $with_comments );
  786. // did we get a next page?
  787. if ( is_object( $prev_page ) ) {
  788. // init title
  789. $img = '';
  790. $title = __( 'Previous page', 'commentpress-core' ); //htmlentities( $prev_page->post_title );
  791. // if we wanted pages with comments...
  792. if ( $with_comments ) {
  793. // set title
  794. $title = __( 'Previous page with comments', 'commentpress-core' );
  795. $img = '<img src="'.get_template_directory_uri().'/assets/images/prev.png" />';
  796. }
  797. // define list item
  798. $prev_page_html = $before_prev.
  799. $img.'<a href="'.get_permalink( $prev_page->ID ).'" id="previous_page" class="css_btn" title="'.$title.'">'.$title.'</a>'.$after_prev;
  800. }
  801. // init return
  802. $nav_list = '';
  803. // did we get either?
  804. if ( $next_page_html != '' OR $prev_page_html != '' ) {
  805. // construct nav list items
  806. $nav_list = $prev_page_html."\n".$next_page_html."\n";
  807. }
  808. // --<
  809. return $nav_list;
  810. }
  811. endif; // commentpress_page_navigation
  812. if ( ! function_exists( 'commentpress_page_title' ) ):
  813. /**
  814. * @description: builds a list of previous and next pages, optionally with comments
  815. * @todo:
  816. *
  817. */
  818. function commentpress_page_title( $with_comments = false ) {
  819. // declare access to globals
  820. global $commentpress_core, $post;
  821. // init
  822. $_title = '';
  823. $_sep = ' &#8594; ';
  824. //$_title .= get_bloginfo('name');
  825. if ( is_page() OR is_single() OR is_category() ) {
  826. if (is_page()) {
  827. $ancestors = get_post_ancestors($post);
  828. if ($ancestors) {
  829. $ancestors = array_reverse($ancestors);
  830. $_crumb = array();
  831. foreach ($ancestors as $crumb) {
  832. $_crumb[] = get_the_title($crumb);
  833. }
  834. $_title .= implode( $_sep, $_crumb ).$_sep;
  835. }
  836. }
  837. if (is_single()) {
  838. //$category = get_the_category();
  839. //$_title .= $_sep.$category[0]->cat_name;
  840. }
  841. if (is_category()) {
  842. $category = get_the_category();
  843. $_title .= $category[0]->cat_name.$_sep;
  844. }
  845. // Current page
  846. if (is_page() OR is_single()) {
  847. $_title .= get_the_title();
  848. }
  849. }
  850. // --<
  851. return $_title;
  852. }
  853. endif; // commentpress_page_title
  854. if ( ! function_exists( 'commentpress_has_page_children' ) ):
  855. /**
  856. * @description: query whether a given page has children
  857. * @todo:
  858. *
  859. */
  860. function commentpress_has_page_children(
  861. $page_obj
  862. ) { //-->
  863. // init to look for published pages
  864. $defaults = array(
  865. 'post_parent' => $page_obj->ID,
  866. 'post_type' => 'page',
  867. 'numberposts' => -1,
  868. 'post_status' => 'publish'
  869. );
  870. // get page children
  871. $kids =& get_children( $defaults );
  872. // do we have any?
  873. return ( empty( $kids ) ) ? false : true;
  874. }
  875. endif; // commentpress_has_page_children
  876. if ( ! function_exists( 'commentpress_get_children' ) ):
  877. /**
  878. * @description: retrieve comment children
  879. * @todo:
  880. *
  881. */
  882. function commentpress_get_children(
  883. $comment,
  884. $page_or_post
  885. ) { //-->
  886. // declare access to globals
  887. global $wpdb;
  888. // construct query for comment children
  889. $query = "
  890. SELECT $wpdb->comments.*, $wpdb->posts.post_title, $wpdb->posts.post_name
  891. FROM $wpdb->comments, $wpdb->posts
  892. WHERE $wpdb->comments.comment_post_ID = $wpdb->posts.ID
  893. AND $wpdb->posts.post_type = '$page_or_post'
  894. AND $wpdb->comments.comment_approved = '1'
  895. AND $wpdb->comments.comment_parent = '$comment->comment_ID'
  896. ORDER BY $wpdb->comments.comment_date ASC
  897. ";
  898. // does it have children?
  899. return $wpdb->get_results( $query );
  900. }
  901. endif; // commentpress_get_children
  902. if ( ! function_exists( 'commentpress_get_comments' ) ):
  903. /**
  904. * @description: generate comments recursively
  905. * @todo:
  906. *
  907. */
  908. function commentpress_get_comments(
  909. $comments,
  910. $page_or_post
  911. ) { //-->
  912. // declare access to globals
  913. global $cp_comment_output;
  914. // do we have any comments?
  915. if( count( $comments ) > 0 ) {
  916. // open ul
  917. $cp_comment_output .= '<ul class="item_ul">'."\n\n";
  918. // produce a checkbox for each
  919. foreach( $comments as $comment ) {
  920. // open li
  921. $cp_comment_output .= '<li class="item_li">'."\n\n";
  922. // format this comment
  923. $cp_comment_output .= commentpress_format_comment( $comment );
  924. // get comment children
  925. $children = commentpress_get_children( $comment, $page_or_post );
  926. // do we have any?
  927. if( count( $children ) > 0 ) {
  928. // recurse
  929. commentpress_get_comments( $children, $page_or_post );
  930. }
  931. // close li
  932. $cp_comment_output .= '</li>'."\n\n";
  933. }
  934. // close ul
  935. $cp_comment_output .= '</ul>'."\n\n";
  936. }
  937. }
  938. endif; // commentpress_get_comments
  939. if ( ! function_exists( 'commentpress_get_user_link' ) ):
  940. /**
  941. * @description: get user link in vanilla WP scenarios
  942. * @todo:
  943. *
  944. */
  945. function commentpress_get_user_link(
  946. &$user
  947. ) { //-->
  948. /**
  949. * In default single install mode, just link to their URL, unless
  950. * they are an author, in which case we link to their author page.
  951. *
  952. * In multisite, the same.
  953. *
  954. * When BuddyPress is enabled, always link to their profile
  955. */
  956. // kick out if not a user
  957. if ( !is_object( $user ) ) { return false; }
  958. // we're through: the user is on the system
  959. global $commentpress_core;
  960. // if buddypress...
  961. if ( is_object( $commentpress_core ) AND $commentpress_core->is_buddypress() ) {
  962. // buddypress link ($no_anchor = null, $just_link = true)
  963. $url = bp_core_get_userlink( $user->ID, null, true );
  964. } else {
  965. // get standard WP author url
  966. // get author url
  967. $url = '';//JVDP
  968. //print_r( $url ); die();
  969. // WP sometimes leaves 'http://' or 'https://' in the field
  970. if ( $url == 'http://' OR $url == 'https://' ) {
  971. // clear
  972. $url = '';
  973. }
  974. }
  975. // --<
  976. return $url;
  977. }
  978. endif; // commentpress_get_user_link
  979. if ( ! function_exists( 'commentpress_echo_post_meta' ) ):
  980. /**
  981. * @description: show user(s) in the loop
  982. * @todo:
  983. *
  984. */
  985. function commentpress_echo_post_meta() {
  986. // compat with Co-Authors Plus
  987. if ( function_exists( 'get_coauthors' ) ) {
  988. // get multiple authors
  989. $authors = get_coauthors();
  990. //print_r( $authors ); die();
  991. // if we get some
  992. if ( !empty( $authors ) ) {
  993. // use the Co-Authors format of "name, name, name & name"
  994. $author_html = '';
  995. // init counter
  996. $n = 1;
  997. // find out how many author we have
  998. $author_count = count( $authors );
  999. // loop
  1000. foreach( $authors AS $author ) {
  1001. // default to comma
  1002. $sep = ', ';
  1003. // if we're on the penultimate
  1004. if ( $n == ($author_count - 1) ) {
  1005. // use ampersand
  1006. $sep = __( ' &amp; ', 'commentpress-core' );
  1007. }
  1008. // if we're on the last, don't add
  1009. if ( $n == $author_count ) { $sep = ''; }
  1010. // get name
  1011. $author_html .= commentpress_echo_post_author( $author->ID, false );
  1012. // and separator
  1013. $author_html .= $sep;
  1014. // increment
  1015. $n++;
  1016. // yes - are we showing avatars?
  1017. if ( get_option('show_avatars') ) {
  1018. // get avatar
  1019. echo get_avatar( $author->ID, $size='32' );
  1020. }
  1021. }
  1022. ?><cite class="fn"><?php echo $author_html; ?></cite>
  1023. <p><a href="<?php the_permalink() ?>"><?php the_time('l, F jS, Y') ?></a></p>
  1024. <?php
  1025. }
  1026. } else {
  1027. // get avatar
  1028. $author_id = get_the_author_meta( 'ID' );
  1029. echo get_avatar( $author_id, $size='32' );
  1030. ?>
  1031. <cite class="fn"><?php commentpress_echo_post_author( $author_id ) ?></cite>
  1032. <p><a href="<?php the_permalink() ?>"><?php the_time('l, F jS, Y') ?></a></p>
  1033. <?php
  1034. }
  1035. }
  1036. endif; // commentpress_echo_post_meta
  1037. if ( ! function_exists( 'commentpress_show_source_url' ) ):
  1038. /**
  1039. * @description: show source URL for print
  1040. * @todo:
  1041. *
  1042. */
  1043. function commentpress_show_source_url() {
  1044. // add the URL - hidden, but revealed by print stylesheet
  1045. ?><p class="hidden_page_url"><?php
  1046. // label
  1047. echo __( 'Source: ', 'commentpress-core' );
  1048. // path from server array, if set
  1049. $path = ( isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : '';
  1050. // get server, if set
  1051. $server = ( isset( $_SERVER['SERVER_NAME'] ) ) ? $_SERVER['SERVER_NAME'] : '';
  1052. // get protocol, if set
  1053. $protocol = ( !empty( $_SERVER['HTTPS'] ) ) ? 'https' : 'http';
  1054. // construct URL
  1055. $url = $protocol.'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  1056. // echo
  1057. echo $url;
  1058. ?></p><?php
  1059. }
  1060. endif; // commentpress_show_source_url
  1061. // add after theme setup hook
  1062. add_action( 'wp_footer', 'commentpress_show_source_url' );
  1063. if ( ! function_exists( 'commentpress_echo_post_author' ) ):
  1064. /**
  1065. * @description: show username (with link) in the loop
  1066. * @todo:
  1067. *
  1068. */
  1069. function commentpress_echo_post_author( $author_id, $echo = true ) {
  1070. // get author details
  1071. $user = get_userdata( $author_id );
  1072. // kick out if we don't have a user with that ID
  1073. if ( !is_object( $user ) ) { return; }
  1074. // access plugin
  1075. global $commentpress_core, $post;
  1076. // if we have the plugin enabled and it's BP
  1077. if ( is_object( $post ) AND is_object( $commentpress_core ) AND $commentpress_core->is_buddypress() ) {
  1078. // construct user link
  1079. $author = bp_core_get_userlink( $user->ID );
  1080. } else {
  1081. // link to theme's author page
  1082. $link = sprintf(
  1083. '%1$s',//JVDP
  1084. esc_html( $user->display_name )
  1085. );
  1086. $author = apply_filters( 'the_author_posts_link', $link );
  1087. }
  1088. // if we're echoing
  1089. if ( $echo ) {
  1090. echo $author;
  1091. } else {
  1092. return $author;
  1093. }
  1094. }
  1095. endif; // commentpress_echo_post_author
  1096. if ( ! function_exists( 'commentpress_format_comment' ) ):
  1097. /**
  1098. * @description: format comment on comments pages
  1099. * @todo:
  1100. *
  1101. */
  1102. function commentpress_format_comment( $comment, $context = 'all' ) {
  1103. // declare access to globals
  1104. global $wpdb, $commentpress_core, $cp_comment_output;
  1105. // enable Wordpress API on comment
  1106. //$GLOBALS['comment'] = $comment;
  1107. // if context is 'all comments'...
  1108. if ( $context == 'all' ) {
  1109. // get author
  1110. if ( $comment->comment_author != '' ) {
  1111. // was it a registered user?
  1112. if ( $comment->user_id != '0' ) {
  1113. // get user details
  1114. $user = get_userdata( $comment->user_id );
  1115. //print_r( $user->display_name ); die();
  1116. // get user link
  1117. $user_link = commentpress_get_user_link( $user );
  1118. // construct link to user url
  1119. $_context = ( $user_link != '' AND $user_link != 'http://' ) ?
  1120. 'by <a href="'.$user_link.'">'.$comment->comment_author.'</a>' :
  1121. 'by '.$comment->comment_author;
  1122. } else {
  1123. // construct link to commenter url
  1124. $_context = ( $comment->comment_author_url != '' AND $comment->comment_author_url != 'http://' ) ?
  1125. 'by <a href="'.$comment->comment_author_url.'">'.$comment->comment_author.'</a>' :
  1126. 'by '.$comment->comment_author;
  1127. }
  1128. } else {
  1129. // we don't have a name
  1130. $_context = __( 'by Anonymous', 'commentpress-core' );
  1131. }
  1132. // if context is 'by commenter'
  1133. } elseif ( $context == 'by' ) {
  1134. // construct link
  1135. $_page_link = trailingslashit( get_permalink( $comment->comment_post_ID ) );
  1136. // construct context
  1137. $_context = 'on <a href="'.$_page_link.'">'.$comment->post_title.'</a>';
  1138. }
  1139. // construct link
  1140. $_comment_link = get_comment_link( $comment->comment_ID );
  1141. // comment header
  1142. $_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";
  1143. // comment content
  1144. $_comment_body = '<div class="comment-content">'.wpautop(convert_chars(wptexturize($comment->comment_content))).'</div>'."\n";
  1145. // construct comment
  1146. return '<div class="comment_wrapper">'."\n".$_comment_meta.$_comment_body.'</div>'."\n\n";
  1147. }
  1148. endif; // commentpress_format_comment
  1149. if ( ! function_exists( 'commentpress_get_all_comments_content' ) ):
  1150. /**
  1151. * @description: all-comments page display function
  1152. * @todo:
  1153. *
  1154. */
  1155. function commentpress_get_all_comments_content( $page_or_post = 'page' ) {
  1156. // declare access to globals
  1157. global $wpdb, $commentpress_core, $cp_comment_output;
  1158. // init page content
  1159. $_page_content = '';
  1160. // construct query
  1161. $querystr = "
  1162. SELECT $wpdb->comments.*, $wpdb->posts.post_title, $wpdb->posts.post_name, $wpdb->posts.comment_count
  1163. FROM $wpdb->comments, $wpdb->posts
  1164. WHERE $wpdb->comments.comment_post_ID = $wpdb->posts.ID
  1165. AND $wpdb->posts.post_type = '$page_or_post'
  1166. AND $wpdb->comments.comment_approved = '1'
  1167. AND $wpdb->comments.comment_parent = '0'
  1168. AND $wpdb->comments.comment_type != 'pingback'
  1169. AND $wpdb->posts.post_status = 'publish'
  1170. ORDER BY $wpdb->posts.comment_count DESC, $wpdb->comments.comment_post_ID, $wpdb->comments.comment_date ASC
  1171. ";
  1172. //echo $querystr; exit();
  1173. // get data
  1174. $_data = $wpdb->get_results($querystr, OBJECT);
  1175. // did we get any?
  1176. if ( count( $_data ) > 0 ) {
  1177. // open ul
  1178. $_page_content .= '<ul class="all_comments_listing">'."\n\n";
  1179. // init title
  1180. $_title = '';
  1181. // init global comment output
  1182. $cp_comment_output = '';
  1183. // loop
  1184. foreach ($_data as $comment) {
  1185. // show page title, if not shown
  1186. if ( $_title != $comment->post_title ) {
  1187. // if not first...
  1188. if ( $_title != '' ) {
  1189. // close ul
  1190. $_page_content .= '</ul>'."\n\n";
  1191. // close item div
  1192. $_page_content .= '</div><!-- /item_body -->'."\n\n";
  1193. // close li
  1194. $_page_content .= '</li><!-- /page li -->'."\n\n\n\n";
  1195. }
  1196. // open li
  1197. $_page_content .= '<li class="page_li"><!-- page li -->'."\n\n";
  1198. // count comments
  1199. if ( $comment->comment_count > 1 ) { $_comment_count_text = 'comments'; } else { $_comment_count_text = 'comment'; }
  1200. // show it
  1201. $_page_content .= '<h3>'.$comment->post_title.' <span>('.$comment->comment_count.' '.$_comment_count_text.')</span></h3>'."\n\n";
  1202. // open comments div
  1203. $_page_content .= '<div class="item_body">'."\n\n";
  1204. // open ul
  1205. $_page_content .= '<ul class="item_ul">'."\n\n";
  1206. // set mem
  1207. $_title = $comment->post_title;
  1208. }
  1209. // open li
  1210. $_page_content .= '<li class="item_li"><!-- item li -->'."\n\n";
  1211. // show the comment
  1212. $_page_content .= commentpress_format_comment( $comment );
  1213. // get comment children
  1214. $children = commentpress_get_children( $comment, $page_or_post );
  1215. // do we have any?
  1216. if( count( $children ) > 0 ) {
  1217. // recurse
  1218. commentpress_get_comments( $children, $page_or_post );
  1219. // show them
  1220. $_page_content .= $cp_comment_output;
  1221. // clear global comment output
  1222. $cp_comment_output = '';
  1223. }
  1224. // close li
  1225. $_page_content .= '</li><!-- /item li -->'."\n\n";
  1226. }
  1227. // close ul
  1228. $_page_content .= '</ul>'."\n\n";
  1229. // close item div
  1230. $_page_content .= '</div><!-- /item_body -->'."\n\n";
  1231. // close li
  1232. $_page_content .= '</li><!-- /page li -->'."\n\n\n\n";
  1233. // close ul
  1234. $_page_content .= '</ul><!-- /all_comments_listing -->'."\n\n";
  1235. }
  1236. // --<
  1237. return $_page_content;
  1238. }
  1239. endif; // commentpress_get_all_comments_content
  1240. if ( ! function_exists( 'commentpress_get_all_comments_page_content' ) ):
  1241. /**
  1242. * @description: all-comments page display function
  1243. * @todo:
  1244. *
  1245. */
  1246. function commentpress_get_all_comments_page_content() {
  1247. // declare access to globals
  1248. global $commentpress_core;
  1249. // set default
  1250. $pagetitle = apply_filters(
  1251. 'cp_page_all_comments_title',
  1252. __( 'All Comments', 'commentpress-core' )
  1253. );
  1254. // set title
  1255. $_page_content = '<h2 class="post_title">'.$pagetitle.'</h2>'."\n\n";
  1256. // get page or post
  1257. $page_or_post = $commentpress_core->get_list_option();
  1258. // set default
  1259. $blogtitle = apply_filters(
  1260. 'cp_page_all_comments_blog_title',
  1261. __( 'Comments on the Blog', 'commentpress-core' )
  1262. );
  1263. // set default
  1264. $booktitle = apply_filters(
  1265. 'cp_page_all_comments_book_title',
  1266. __( 'Comments on the Pages', 'commentpress-core' )
  1267. );
  1268. // get title
  1269. $title = ( $page_or_post == 'page' ) ? $booktitle : $blogtitle;
  1270. // set title
  1271. $_page_content .= '<p class="comments_hl">'.$title.'</p>'."\n\n";
  1272. // get data
  1273. $_page_content .= commentpress_get_all_comments_content( $page_or_post );
  1274. // get data for other page type
  1275. $other_type = ( $page_or_post == 'page' ) ? 'post': 'page';
  1276. // get title
  1277. $title = ( $page_or_post == 'page' ) ? $blogtitle : $booktitle;
  1278. // set title
  1279. $_page_content .= '<p class="comments_hl">'.$title.'</p>'."\n\n";
  1280. // get data
  1281. $_page_content .= commentpress_get_all_comments_content( $other_type );
  1282. // --<
  1283. return $_page_content;
  1284. }
  1285. endif; // commentpress_get_all_comments_page_content
  1286. if ( ! function_exists( 'commentpress_get_comments_by_content' ) ):
  1287. /**
  1288. * @description: comments-by page display function
  1289. * @todo: do we want trackbacks?
  1290. *
  1291. */
  1292. function commentpress_get_comments_by_content() {
  1293. // declare access to globals
  1294. global $wpdb, $commentpress_core;
  1295. // init page content
  1296. $_page_content = '';
  1297. // construct query
  1298. $querystr = "
  1299. SELECT $wpdb->comments.*, $wpdb->posts.post_title, $wpdb->posts.post_name
  1300. FROM $wpdb->comments, $wpdb->posts
  1301. WHERE $wpdb->comments.comment_post_ID = $wpdb->posts.ID
  1302. AND $wpdb->comments.comment_type != 'pingback'
  1303. AND $wpdb->comments.comment_approved = '1'
  1304. AND $wpdb->posts.post_status = 'publish'
  1305. ORDER BY $wpdb->comments.comment_author, $wpdb->posts.post_title, $wpdb->comments.comment_post_ID, $wpdb->comments.comment_date ASC
  1306. ";
  1307. //echo $querystr; exit();
  1308. // get data
  1309. $_data = $wpdb->get_results( $querystr, OBJECT );
  1310. //print_r( $_data ); exit();
  1311. // did we get any?
  1312. if ( count( $_data ) > 0 ) {
  1313. // open ul
  1314. $_page_content .= '<ul class="all_comments_listing">'."\n\n";
  1315. // init title
  1316. $_title = '';
  1317. // loop
  1318. foreach ($_data as $comment) {
  1319. // test for anonymous comment (usually generated by WP itself in multisite installs)
  1320. if ( empty( $comment->comment_author ) ) {
  1321. $comment->comment_author = 'Anonymous';
  1322. }
  1323. // show commenter, if not shown
  1324. if ( $_title != $comment->comment_author ) {
  1325. // if not first...
  1326. if ( $_title != '' ) {
  1327. // close ul
  1328. $_page_content .= '</ul>'."\n\n";
  1329. // close item div
  1330. $_page_content .= '</div><!-- /item_body -->'."\n\n";
  1331. // close li
  1332. $_page_content .= '</li><!-- /author li -->'."\n\n\n\n";
  1333. }
  1334. // open li
  1335. $_page_content .= '<li class="author_li"><!-- author li -->'."\n\n";
  1336. // count comments
  1337. //if ( $comment->comment_count > 1 ) { $_comment_count_text = 'comments'; } else { $_comment_count_text = 'comment'; }
  1338. // show it -- <span>('.$comment->comment_count.' '.$_comment_count_text.')</span>
  1339. // add gravatar
  1340. $_page_content .= '<h3>'.get_avatar( $comment, $size='24' ).$comment->comment_author.'</h3>'."\n\n";
  1341. // open comments div
  1342. $_page_content .= '<div class="item_body">'."\n\n";
  1343. // open ul
  1344. $_page_content .= '<ul class="item_ul">'."\n\n";
  1345. // set mem
  1346. $_title = $comment->comment_author;
  1347. }
  1348. // open li
  1349. $_page_content .= '<li class="item_li"><!-- item li -->'."\n\n";
  1350. // show the comment
  1351. $_page_content .= commentpress_format_comment( $comment, 'by' );
  1352. // close li
  1353. $_page_content .= '</li><!-- /item li -->'."\n\n";
  1354. }
  1355. // close ul
  1356. $_page_content .= '</ul>'."\n\n";
  1357. // close item div
  1358. $_page_content .= '</div><!-- /item_body -->'."\n\n";
  1359. // close li
  1360. $_page_content .= '</li><!-- /author li -->'."\n\n\n\n";
  1361. // close ul
  1362. $_page_content .= '</ul><!-- /all_comments_listing -->'."\n\n";
  1363. }
  1364. // --<
  1365. return $_page_content;
  1366. }
  1367. endif; // commentpress_get_comments_by_content
  1368. if ( ! function_exists( 'commentpress_get_comments_by_page_content' ) ):
  1369. /**
  1370. * @description: comments-by page display function
  1371. * @todo:
  1372. *
  1373. */
  1374. function commentpress_get_comments_by_page_content() {
  1375. // declare access to globals
  1376. global $commentpress_core;
  1377. // set title
  1378. $_page_content = '<h2 class="post_title">Comments by Commenter</h2>'."\n\n";
  1379. // get data
  1380. $_page_content .= commentpress_get_comments_by_content();
  1381. // --<
  1382. return $_page_content;
  1383. }
  1384. endif; // commentpress_get_comments_by_page_content
  1385. if ( ! function_exists( 'commentpress_show_activity_tab' ) ):
  1386. /**
  1387. * @description: decide whether or not to show the Activity Sidebar
  1388. * @todo:
  1389. *
  1390. */
  1391. function commentpress_show_activity_tab() {
  1392. // declare access to globals
  1393. global $commentpress_core, $post;
  1394. /*
  1395. // if we have the plugin enabled...
  1396. if ( is_object( $commentpress_core ) ) {
  1397. // is this multisite?
  1398. if (
  1399. ( is_multisite()
  1400. AND is_main_site()
  1401. AND $commentpress_core->is_buddypress_special_page() )
  1402. OR !is_object( $post )
  1403. ) {
  1404. // ignore activity
  1405. return false;
  1406. }
  1407. }
  1408. */
  1409. // --<
  1410. return true;
  1411. }
  1412. endif; // commentpress_show_activity_tab
  1413. if ( ! function_exists( 'commentpress_is_commentable' ) ):
  1414. /**
  1415. * @description: decide whether or not to show the Activity Sidebar
  1416. * @todo:
  1417. *
  1418. */
  1419. function commentpress_is_commentable() {
  1420. // declare access to plugin
  1421. global $commentpress_core;
  1422. // if we have it...
  1423. if ( is_object( $commentpress_core ) ) {
  1424. // return what it reports
  1425. return $commentpress_core->is_commentable();
  1426. }
  1427. // --<
  1428. return false;
  1429. }
  1430. endif; // commentpress_is_commentable
  1431. if ( ! function_exists( 'commentpress_get_comment_activity' ) ):
  1432. /**
  1433. * @description: activity sidebar display function
  1434. * @todo: do we want trackbacks?
  1435. *
  1436. */
  1437. function commentpress_get_comment_activity( $scope = 'all' ) {
  1438. // declare access to globals
  1439. global $wpdb, $commentpress_core, $post;
  1440. // init page content
  1441. $_page_content = '';
  1442. // define defaults
  1443. $args = array(
  1444. 'number' => 10,
  1445. 'status' => 'approve',
  1446. // exclude trackbacks and pingbacks until we decide what to do with them
  1447. 'type' => ''
  1448. );
  1449. // if we are on a 404, for example
  1450. if ( $scope == 'post' AND is_object( $post ) ) {
  1451. // get all comments
  1452. $args['post_id'] = $post->ID;
  1453. }
  1454. // get 'em
  1455. $_data = get_comments( $args );
  1456. //print_r( $_data ); exit();
  1457. // did we get any?
  1458. if ( count( $_data ) > 0 ) {
  1459. // open ul
  1460. $_page_content .= '<ol class="comment_activity">'."\n\n";
  1461. // init title
  1462. $_title = '';
  1463. // loop
  1464. foreach ($_data as $comment) {
  1465. // enable Wordpress API on comment
  1466. $GLOBALS['comment'] = $comment;
  1467. // only comments until we decide what to do with pingbacks
  1468. if ( $comment->comment_type != 'pingback' ) //{
  1469. // test for anonymous comment (usually generated by WP itself in multisite installs)
  1470. if ( empty( $comment->comment_author ) ) {
  1471. $comment->comment_author = 'Anonymous';
  1472. }
  1473. // was it a registered user?
  1474. if ( $comment->user_id != '0' ) {
  1475. // get user details
  1476. $user = get_userdata( $comment->user_id );
  1477. //print_r( $user->display_name ); die();
  1478. // get user link
  1479. $user_link = commentpress_get_user_link( $user );
  1480. // construct author citation
  1481. $author = '<cite class="fn"><a href="'.$user_link.'">'.esc_html( $comment->comment_author ).'</a></cite>';
  1482. // construct link to user url
  1483. $author = ( $user_link != '' AND $user_link != 'http://' ) ?
  1484. '<cite class="fn"><a href="'.$user_link.'">'.esc_html( $comment->comment_author ).'</a></cite>' :
  1485. '<cite class="fn">'.esc_html( $comment->comment_author ).'</cite>';
  1486. } else {
  1487. // construct link to commenter url
  1488. $author = ( $comment->comment_author_url != '' AND $comment->comment_author_url != 'http://' ) ?
  1489. '<cite class="fn"><a href="'.$comment->comment_author_url.'">'.esc_html( $comment->comment_author ).'</a></cite>' :
  1490. '<cite class="fn">'.esc_html( $comment->comment_author ).'</cite>';
  1491. }
  1492. // approved comment?
  1493. if ($comment->comment_approved == '0') {
  1494. $comment_text = '<p><em>Comment awaiting moderation</em></p>';
  1495. } else {
  1496. $comment_text = get_comment_text( $comment->comment_ID );
  1497. }
  1498. // default to not on post
  1499. $is_on_current_post = '';
  1500. // on current post?
  1501. if ( is_singular() AND is_object( $post ) AND $comment->comment_post_ID == $post->ID ) {
  1502. // access paging globals
  1503. global $multipage, $page;
  1504. // is it the same page, if paged?
  1505. if ( $multipage ) {
  1506. /*
  1507. print_r( array(
  1508. 'multipage' => $multipage,
  1509. 'page' => $page
  1510. ) ); die();
  1511. */
  1512. // if it has a text sig
  1513. if (
  1514. !is_null( $comment->comment_signature )
  1515. AND $comment->comment_signature != ''
  1516. ) {
  1517. // set key
  1518. $key = '_cp_comment_page';
  1519. // if the custom field already has a value...
  1520. if ( get_comment_meta( $comment->comment_ID, $key, true ) != '' ) {
  1521. // get comment's page from meta
  1522. $page_num = get_comment_meta( $comment->comment_ID, $key, true );
  1523. // is it this one?
  1524. if ( $page_num == $page ) {
  1525. // is the right page
  1526. $is_on_current_post = ' comment_on_post';
  1527. }

Large files files are truncated, but you can click here to view the full file