PageRenderTime 65ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/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
  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. }
  1528. }
  1529. } else {
  1530. // it's always the right page for page-level comments
  1531. $is_on_current_post = ' comment_on_post';
  1532. }
  1533. } else {
  1534. // must be the right page
  1535. $is_on_current_post = ' comment_on_post';
  1536. }
  1537. }
  1538. // open li
  1539. $_page_content .= '<li><!-- item li -->'."\n\n";
  1540. // show the comment
  1541. $_page_content .= '
  1542. <div class="comment-wrapper">
  1543. <div class="comment-identifier">
  1544. '.get_avatar( $comment, $size='32' ).'
  1545. '.$author.'
  1546. <p class="comment_activity_date"><a class="comment_activity_link'.$is_on_current_post.'" href="'.htmlspecialchars( get_comment_link() ).'">'.get_comment_date().' at '.get_comment_time().'</a></p>
  1547. </div><!-- /comment-identifier -->
  1548. <div class="comment-content">
  1549. '.apply_filters('comment_text', $comment_text ).'
  1550. </div><!-- /comment-content -->
  1551. <div class="reply"><p><a class="comment_activity_link'.$is_on_current_post.'" href="'.htmlspecialchars( get_comment_link() ).'">'.__( 'See in context', 'commentpress-core' ).'</a></p></div><!-- /reply -->
  1552. </div><!-- /comment-wrapper -->
  1553. ';
  1554. // close li
  1555. $_page_content .= '</li><!-- /item li -->'."\n\n";
  1556. }
  1557. // close ul
  1558. $_page_content .= '</ol><!-- /comment_activity -->'."\n\n";
  1559. }
  1560. // --<
  1561. return $_page_content;
  1562. }
  1563. endif; // commentpress_get_comment_activity
  1564. if ( ! function_exists( 'commentpress_get_comments_by_para' ) ):
  1565. /**
  1566. * @description: get comments delimited by paragraph
  1567. * @todo: translation
  1568. *
  1569. */
  1570. function commentpress_get_comments_by_para() {
  1571. // declare access to globals
  1572. global $post, $commentpress_core;
  1573. // get approved comments for this post, sorted comments by text signature
  1574. $comments_sorted = $commentpress_core->get_sorted_comments( $post->ID );
  1575. //print_r( $comments_sorted ); die();
  1576. // get text signatures
  1577. //$text_sigs = $commentpress_core->db->get_text_sigs();
  1578. // if we have any...
  1579. if ( count( $comments_sorted ) > 0 ) {
  1580. // default comment type to get
  1581. $comment_type = 'all';
  1582. // if we don't allow pingbacks...
  1583. if ( !('open' == $post->ping_status) ) {
  1584. // just get comments
  1585. $comment_type = 'comment';
  1586. }
  1587. // init new walker
  1588. $walker = new Walker_Comment_Press;
  1589. // define args
  1590. $args = array(
  1591. // list comments params
  1592. 'walker' => $walker,
  1593. 'style'=> 'ol',
  1594. 'type'=> $comment_type,
  1595. 'callback' => 'commentpress_comments'
  1596. );
  1597. // init counter for text_signatures array
  1598. $sig_counter = 0;
  1599. // init array for tracking text sigs
  1600. $used_text_sigs = array();
  1601. //var_dump(sizeof($comments_sorted));
  1602. // loop through each paragraph
  1603. foreach( $comments_sorted AS $text_signature => $_comments ) {
  1604. // count comments
  1605. $comment_count = count( $_comments );
  1606. // switch, depending on key
  1607. switch( $text_signature ) {
  1608. // whole page comments
  1609. case 'WHOLE_PAGE_OR_POST_COMMENTS':
  1610. // clear text signature
  1611. $text_sig = '';
  1612. // clear the paragraph number
  1613. $para_num = '';
  1614. // define default phrase
  1615. $paragraph_text = __( 'the whole page', 'commentpress-core' );
  1616. $current_type = get_post_type();
  1617. //print_r( $current_type ); die();
  1618. switch( $current_type ) {
  1619. // we can add more of these if needed
  1620. case 'post': $paragraph_text = __( 'the whole post', 'commentpress-core' ); break;
  1621. case 'page': $paragraph_text = __( 'the whole page', 'commentpress-core' ); break;
  1622. }
  1623. // set permalink text
  1624. $permalink_text = __('Permalink for comments on ', 'commentpress-core' ).$paragraph_text;
  1625. // define heading text
  1626. $heading_text = sprintf( _n(
  1627. // singular
  1628. '<span>%d</span> Comment on ',
  1629. // plural
  1630. '<span>%d</span> Comments on ',
  1631. // number
  1632. $comment_count,
  1633. // domain
  1634. 'commentpress-core'
  1635. // substitution
  1636. ), $comment_count );
  1637. // append para text
  1638. $heading_text .= $paragraph_text;
  1639. break;
  1640. // pingbacks etc
  1641. case 'PINGS_AND_TRACKS':
  1642. // set "unique-enough" text signature
  1643. $text_sig = 'pingbacksandtrackbacks';
  1644. // clear the paragraph number
  1645. $para_num = '';
  1646. // define heading text
  1647. $heading_text = sprintf( _n(
  1648. // singular
  1649. '<span>%d</span> Pingback or trackback',
  1650. // plural
  1651. '<span>%d</span> Pingbacks and trackbacks',
  1652. // number
  1653. $comment_count,
  1654. // domain
  1655. 'commentpress-core'
  1656. // substitution
  1657. ), $comment_count );
  1658. // set permalink text
  1659. $permalink_text = __('Permalink for pingbacks and trackbacks', 'commentpress-core' );
  1660. break;
  1661. // textblock comments
  1662. default:
  1663. // get text signature
  1664. $text_sig = $text_signature;
  1665. // paragraph number
  1666. $para_num = $sig_counter;
  1667. // which parsing method?
  1668. if ( defined( 'COMMENTPRESS_BLOCK' ) ) {
  1669. switch ( COMMENTPRESS_BLOCK ) {
  1670. case 'tag' :
  1671. // set block identifier
  1672. $block_name = __( 'paragraph', 'commentpress-core' );
  1673. break;
  1674. case 'block' :
  1675. // set block identifier
  1676. $block_name = __( 'block', 'commentpress-core' );
  1677. break;
  1678. case 'line' :
  1679. // set block identifier
  1680. $block_name = __( 'line', 'commentpress-core' );
  1681. break;
  1682. }
  1683. } else {
  1684. // set block identifier
  1685. $block_name = __( 'paragraph', 'commentpress-core' );
  1686. }
  1687. // set paragraph text
  1688. $paragraph_text = $block_name.' '.$para_num;
  1689. // set permalink text
  1690. $permalink_text = __('Permalink for comments on ', 'commentpress-core' ).$paragraph_text;
  1691. // define heading text
  1692. $heading_text = sprintf( _n(
  1693. // singular
  1694. '<span>%d</span> Comment on ',
  1695. // plural
  1696. '<span>%d</span> Comments on ',
  1697. // number
  1698. $comment_count,
  1699. // domain
  1700. 'commentpress-core'
  1701. // substitution
  1702. ), $comment_count );
  1703. // append para text
  1704. $heading_text .= $paragraph_text;
  1705. } // end switch
  1706. // init no comment class
  1707. $no_comments_class = '';
  1708. // override if there are no comments (for print stylesheet to hide them)
  1709. if ( $comment_count == 0 ) { $no_comments_class = ' class="no_comments"'; }
  1710. // eclude pings if there are none
  1711. if ( $comment_count == 0 AND $text_signature == 'PINGS_AND_TRACKS' ) {
  1712. // skip
  1713. } else {
  1714. // show heading
  1715. echo '<h3 id="para_heading-'.$text_sig.'"'.$no_comments_class.'><a class="comment_block_permalink" title="'.$permalink_text.'" href="#para_heading-'.$text_sig.'">'.$heading_text.'</a></h3>'."\n\n";
  1716. // override if there are no comments (for print stylesheet to hide them)
  1717. if ( $comment_count == 0 ) { $no_comments_class = ' no_comments'; }
  1718. // open paragraph wrapper
  1719. echo '<div id="para_wrapper-'.$text_sig.'" class="paragraph_wrapper'.$no_comments_class.'">'."\n\n";
  1720. // have we already used this text signature?
  1721. if( in_array( $text_sig, $used_text_sigs ) ) {
  1722. // show some kind of message TO DO: incorporate para order too
  1723. echo '<div class="reply_to_para" id="reply_to_para-'.$para_num.'">'."\n".
  1724. '<p>'.
  1725. 'It appears that this paragraph is a duplicate of a previous one.'.
  1726. '</p>'."\n".
  1727. '</div>'."\n\n";
  1728. } else {
  1729. // if we have comments...
  1730. if ( count( $_comments ) > 0 ) {
  1731. // open commentlist
  1732. echo '<ol class="commentlist">'."\n\n";
  1733. // use WP 2.7+ functionality
  1734. wp_list_comments( $args, $_comments );
  1735. // close commentlist
  1736. echo '</ol>'."\n\n";
  1737. }
  1738. // add to used array
  1739. $used_text_sigs[] = $text_sig;
  1740. // only add comment-on-para link if comments are open and it's not the pingback section
  1741. if ( 'open' == $post->comment_status AND $text_signature != 'PINGS_AND_TRACKS' ) {
  1742. // construct onclick
  1743. $onclick = "return addComment.moveFormToPara( '$para_num', '$text_sig', '$post->ID' )";
  1744. // just show replytopara
  1745. $query = remove_query_arg( array( 'replytocom' ) );
  1746. // add param to querystring
  1747. $query = esc_html(
  1748. add_query_arg(
  1749. array( 'replytopara' => $para_num ),
  1750. $query
  1751. )
  1752. );
  1753. $value = 'something from somewhere';
  1754. // setcookie("TestCookie", $value, time()+3600, "/", "localhost", 30);
  1755. // Print an individual cookie
  1756. // var_dump($_COOKIE["TestCookie"]);
  1757. // var_dump($HTTP_COOKIE_VARS["TestCookie"]);
  1758. // echo "Logged in:";
  1759. // var_dump($_SESSION);
  1760. // var_dump($_COOKIE);
  1761. //var_dump('wp_parse_auth_cookie');
  1762. //var_dump($cookie);
  1763. //var_dump('scheme ');
  1764. //var_dump($scheme);
  1765. //var_dump('wp_parse');
  1766. //var_dump(wp_parse_auth_cookie($cookie, $scheme));
  1767. if ( ! $cookie_elements = wp_parse_auth_cookie($cookie, $scheme) ) {
  1768. do_action('auth_cookie_malformed', $cookie, $scheme);
  1769. }
  1770. extract($cookie_elements, EXTR_OVERWRITE);
  1771. //var_dump('cookie_elements');
  1772. //var_dump($cookie_elements);
  1773. $expired = $expiration;
  1774. //var_dump('expired');
  1775. //var_dump($expired);
  1776. // Allow a grace period for POST and AJAX requests
  1777. if ( defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD'] )
  1778. $expired += HOUR_IN_SECONDS;
  1779. // Quick check to see if an honest cookie has expired
  1780. if ( $expired < time() ) {
  1781. do_action('auth_cookie_expired', $cookie_elements);
  1782. }
  1783. $user = get_user_by('login', $username);
  1784. if ( ! $user ) {
  1785. do_action('auth_cookie_bad_username', $cookie_elements);
  1786. }
  1787. $pass_frag = substr($user->user_pass, 8, 4);
  1788. $key = wp_hash($username . $pass_frag . '|' . $expiration, $scheme);
  1789. $hash = hash_hmac('md5', $username . '|' . $expiration, $key);
  1790. //var_dump($pass_frag);
  1791. //var_dump($key);
  1792. //var_dump($hash);
  1793. //var_dump($hmac);
  1794. if ( $hmac != $hash ) {
  1795. do_action('auth_cookie_bad_hash', $cookie_elements);
  1796. }
  1797. if ( $expiration < time() ) // AJAX/POST grace period set above
  1798. $GLOBALS['login_grace_period'] = 1;
  1799. do_action('auth_cookie_valid', $cookie_elements, $user);
  1800. //var_dump($user);
  1801. // if we have to log in to comment...
  1802. if ( get_option('comment_registration') AND !is_user_logged_in() ) {
  1803. // leave comment link
  1804. echo '<div class="reply_to_para" id="reply_to_para-'.$para_num.'">'."\n".
  1805. '<p><a class="reply_to_para" rel="nofollow" href="/research/wp-login.php?redirect_to=' . $_SERVER['HTTP_REFERER'] . '">'.//JVDP
  1806. __( 'Login to leave a comment on ', 'commentpress-core' ).$paragraph_text.
  1807. '</a></p>'."\n".
  1808. '</div>'."\n\n";
  1809. } else {
  1810. // leave comment link
  1811. echo '<div class="reply_to_para" id="reply_to_para-'.$para_num.'">'."\n".
  1812. '<p><a class="reply_to_para" href="'.$query.'#respond" onclick="'.$onclick.'">'.
  1813. __( 'Leave a comment on ', 'commentpress-core' ).$paragraph_text.
  1814. '</a></p>'."\n".
  1815. '</div>'."\n\n";
  1816. }
  1817. }
  1818. }
  1819. // close paragraph wrapper
  1820. echo '</div>'."\n\n\n\n";
  1821. }
  1822. // increment signature array counter
  1823. $sig_counter++;
  1824. }
  1825. }
  1826. }
  1827. endif; // commentpress_get_comments_by_para
  1828. /**
  1829. * HTML comment list class.
  1830. *
  1831. * @package WordPress
  1832. * @uses Walker
  1833. * @since unknown
  1834. */
  1835. class Walker_Comment_Press extends Walker_Comment {
  1836. /**
  1837. * @see Walker_Comment::start_lvl()
  1838. *
  1839. * @param string $output Passed by reference. Used to append additional content.
  1840. * @param int $depth Depth of comment.
  1841. * @param array $args Uses 'style' argument for type of HTML list.
  1842. */
  1843. function start_lvl( &$output, $depth, $args ) {
  1844. // if on top level
  1845. if( $depth === 0 ) {
  1846. //echo '<h3>New Top Level</h3>'."\n";
  1847. }
  1848. // store depth
  1849. $GLOBALS['comment_depth'] = $depth + 1;
  1850. // open children if necessary
  1851. switch ( $args['style'] ) {
  1852. case 'div':
  1853. break;
  1854. case 'ol':
  1855. echo '<ol class="children">'."\n";
  1856. break;
  1857. default:
  1858. case 'ul':
  1859. echo '<ul class="children">'."\n";
  1860. break;
  1861. }
  1862. }
  1863. }
  1864. if ( ! function_exists( 'commentpress_comment_form_title' ) ):
  1865. /**
  1866. * @description: alternative to the built-in WP function
  1867. * @todo:
  1868. *
  1869. */
  1870. function commentpress_comment_form_title(
  1871. $no_reply_text = 'Leave a Reply',
  1872. $reply_to_comment_text = 'Leave a Reply to %s',
  1873. $reply_to_para_text = 'Leave a Comment on %s',
  1874. $link_to_parent = TRUE
  1875. ) {
  1876. // declare access to globals
  1877. global $comment, $commentpress_core;
  1878. // get comment ID to reply to from URL query string
  1879. $reply_to_comment_id = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
  1880. // get paragraph number to reply to from URL query string
  1881. $reply_to_para_id = isset($_GET['replytopara']) ? (int) $_GET['replytopara'] : 0;
  1882. // if we have no comment ID AND no paragraph ID to reply to
  1883. if ( $reply_to_comment_id == 0 AND $reply_to_para_id == 0 ) {
  1884. // write default title to page
  1885. echo $no_reply_text;
  1886. } else {
  1887. // if we have a comment ID AND NO paragraph ID to reply to
  1888. if ( $reply_to_comment_id != 0 AND $reply_to_para_id == 0 ) {
  1889. // get comment
  1890. $comment = get_comment( $reply_to_comment_id );
  1891. // get link to comment
  1892. $author = ( $link_to_parent ) ?
  1893. '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' :
  1894. get_comment_author();
  1895. // write to page
  1896. printf( $reply_to_comment_text, $author );
  1897. } else {
  1898. // get paragraph text signature
  1899. $text_sig = $commentpress_core->get_text_signature( $reply_to_para_id );
  1900. // get link to paragraph
  1901. $paragraph = ( $link_to_parent ) ?
  1902. '<a href="#para_heading-' . $text_sig . '">Paragraph ' .$reply_to_para_id. '</a>' :
  1903. 'Paragraph ' .$para_num;
  1904. // write to page
  1905. printf( $reply_to_para_text, $paragraph );
  1906. }
  1907. }
  1908. }
  1909. endif; // commentpress_comment_form_title
  1910. if ( ! function_exists( 'commentpress_comment_reply_link' ) ):
  1911. /**
  1912. * @description: alternative to the built-in WP function
  1913. * @todo:
  1914. *
  1915. */
  1916. function commentpress_comment_reply_link( $args = array(), $comment = null, $post = null ) {
  1917. global $user_ID;
  1918. $defaults = array(
  1919. 'add_below' => 'comment',
  1920. 'respond_id' => 'respond',
  1921. 'reply_text' => __('Reply','commentpress-core'),
  1922. 'login_text' => __('Log in to Reply','commentpress-core'),
  1923. 'depth' => 0,
  1924. 'before' => '',
  1925. 'after' => ''
  1926. );
  1927. $args = wp_parse_args($args, $defaults);
  1928. if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
  1929. return;
  1930. }
  1931. extract($args, EXTR_SKIP);
  1932. $comment = get_comment($comment);
  1933. $post = get_post($post);
  1934. // kick out if comments closed
  1935. if ( 'open' != $post->comment_status ) { return false; }
  1936. $link = '';
  1937. // if we have to log in to comment...
  1938. if ( get_option('comment_registration') AND !$user_ID ) {
  1939. $link = '<a rel="nofollow" href="/research/wp-login.php?redirect_to=' . get_permalink() . '">' . $login_text . '</a>';
  1940. } else {
  1941. // just show replytocom
  1942. $query = remove_query_arg( array( 'replytopara' ), get_permalink( $post->ID ) );
  1943. // define query string
  1944. $addquery = esc_html(
  1945. add_query_arg(
  1946. array( 'replytocom' => $comment->comment_ID ),
  1947. $query
  1948. )
  1949. );
  1950. // define link
  1951. $link = "<a rel='nofollow' class='comment-reply-link' href='" . $addquery . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\", \"$comment->comment_signature\")'>$reply_text</a>";
  1952. }
  1953. // --<
  1954. return apply_filters( 'comment_reply_link', $before . $link . $after, $args, $comment, $post );
  1955. }
  1956. endif; // commentpress_comment_reply_link
  1957. if ( ! function_exists( 'commentpress_comments' ) ):
  1958. /**
  1959. * @description: custom comments display function
  1960. * @todo:
  1961. *
  1962. */
  1963. function commentpress_comments( $comment, $args, $depth ) {
  1964. // build comment as html
  1965. echo commentpress_get_comment_markup( $comment, $args, $depth );
  1966. }
  1967. endif; // commentpress_comments
  1968. if ( ! function_exists( 'commentpress_get_comment_markup' ) ):
  1969. /**
  1970. * @description: wrap comment in its markup
  1971. * @todo:
  1972. *
  1973. */
  1974. function commentpress_get_comment_markup( $comment, $args, $depth ) {
  1975. //print_r( $comment );
  1976. //print_r( $args );
  1977. // enable Wordpress API on comment
  1978. $GLOBALS['comment'] = $comment;
  1979. // was it a registered user?
  1980. if ( $comment->user_id != '0' ) {
  1981. // get user details
  1982. $user = get_userdata( $comment->user_id );
  1983. //print_r( $user->display_name ); die();
  1984. // get user link
  1985. $user_link = commentpress_get_user_link( $user );
  1986. //print_r( array( 'u' => $user_link ) ); die();
  1987. // construct author citation
  1988. $author = ( $user_link != '' AND $user_link != 'http://' ) ?
  1989. '<cite class="fn"><a href="'.$user_link.'">'.get_comment_author().'</a></cite>' :
  1990. '<cite class="fn">'.get_comment_author().'</cite>';
  1991. //print_r( array( 'a' => $author ) ); die();
  1992. } else {
  1993. // construct link to commenter url
  1994. $author = ( $comment->comment_author_url != '' AND $comment->comment_author_url != 'http://' AND $comment->comment_approved != '0' ) ?
  1995. '<cite class="fn"><a href="'.$comment->comment_author_url.'">'.get_comment_author().'</a></cite>' :
  1996. '<cite class="fn">'.get_comment_author().'</cite>';
  1997. }
  1998. /*
  1999. if ($comment->comment_approved == '0') {
  2000. $author = '<cite class="fn">'.get_comment_author().'</cite>';
  2001. } else {
  2002. $author = '<cite class="fn">'.get_comment_author_link().'</cite>';
  2003. }
  2004. */
  2005. if ( $comment->comment_approved == '0' ) {
  2006. $comment_text = '<p><em>'.__( 'Comment awaiting moderation', 'commentpress-core' ).'</em></p>';
  2007. } else {
  2008. $comment_text = get_comment_text();
  2009. }
  2010. // empty reply div by default
  2011. $comment_reply = '';
  2012. // enable access to post
  2013. global $post;
  2014. // can we reply?
  2015. if (
  2016. // not if comments are closed
  2017. $post->comment_status == 'open'
  2018. // we don't want reply to on pingbacks
  2019. AND $comment->comment_type != 'pingback'
  2020. // nor on unapproved comments
  2021. AND $comment->comment_approved == '1'
  2022. ) {
  2023. // are we threading comments?
  2024. if ( get_option( 'thread_comments', false ) ) {
  2025. // custom comment_reply_link
  2026. $comment_reply = commentpress_comment_reply_link(
  2027. array_merge(
  2028. $args,
  2029. array(
  2030. 'reply_text' => 'Reply to '.get_comment_author(),
  2031. 'depth' => $depth,
  2032. 'max_depth' => $args['max_depth']
  2033. )
  2034. )
  2035. );
  2036. // wrap in div
  2037. $comment_reply = '<div class="reply">'.$comment_reply.'</div><!-- /reply -->';
  2038. }
  2039. }
  2040. // init edit link
  2041. $editlink = '';
  2042. // if logged in and has capability
  2043. if (
  2044. is_user_logged_in()
  2045. AND
  2046. current_user_can('edit_posts')
  2047. AND
  2048. current_user_can( 'edit_comment', $comment->comment_ID )
  2049. ) {
  2050. // set default edit link title text
  2051. $edit_title_text = apply_filters(
  2052. 'cp_comment_edit_link_title_text',
  2053. __( 'Edit this comment', 'commentpress-core' )
  2054. );
  2055. // set default edit link text
  2056. $edit_text = apply_filters(
  2057. 'cp_comment_edit_link_text',
  2058. __( 'Edit', 'commentpress-core' )
  2059. );
  2060. // get edit comment link
  2061. $editlink = '<span class="alignright comment-edit"><a class="comment-edit-link" href="'.get_edit_comment_link().'" title="'.$edit_title_text.'">'.$edit_text.'</a></span>';
  2062. // add a filter for plugins
  2063. $editlink = apply_filters( 'cp_comment_edit_link', $editlink, $comment );
  2064. }
  2065. // get comment class(es)
  2066. $_comment_class = comment_class( null, $comment->comment_ID, $post->ID, false );
  2067. // if orphaned, add class to identify as such
  2068. $_comment_orphan = ( isset( $comment->orphan ) ) ? ' comment-orphan' : '';
  2069. // stripped source
  2070. $html = '
  2071. <li id="li-comment-'.$comment->comment_ID.'"'.$_comment_class.'>
  2072. <div class="comment-wrapper">
  2073. <div id="comment-'.$comment->comment_ID.'">
  2074. <div class="comment-identifier'.$_comment_orphan.'">
  2075. '.get_avatar( $comment, $size='32' ).'
  2076. '.$editlink.'
  2077. '.$author.'
  2078. <a class="comment_permalink" href="'.htmlspecialchars( get_comment_link() ).'">'.get_comment_date().' at '.get_comment_time().'</a>
  2079. </div><!-- /comment-identifier -->
  2080. <div class="comment-content">
  2081. '.apply_filters('comment_text', $comment_text ).'
  2082. </div><!-- /comment-content -->
  2083. '.$comment_reply.'
  2084. </div><!-- /comment-'.$comment->comment_ID.' -->
  2085. </div><!-- /comment-wrapper -->
  2086. ';
  2087. // --<
  2088. return $html;
  2089. }
  2090. endif; // commentpress_get_comment_markup
  2091. if ( ! function_exists( 'commentpress_get_full_name' ) ):
  2092. /**
  2093. * @description: utility to concatenate names
  2094. * @todo:
  2095. *
  2096. */
  2097. function commentpress_get_full_name( $forename, $surname ) {
  2098. // init return
  2099. $fullname = '';
  2100. // add forename
  2101. if ($forename != '' ) { $fullname .= $forename; }
  2102. // add surname
  2103. if ($surname != '' ) { $fullname .= ' '.$surname; }
  2104. // strip any whitespace
  2105. $fullname = trim( $fullname );
  2106. // --<
  2107. return $fullname;
  2108. }
  2109. endif; // commentpress_get_full_name
  2110. if ( ! function_exists( 'commentpress_excerpt_length' ) ):
  2111. /**
  2112. * @description: utility to define length of excerpt
  2113. * @todo:
  2114. *
  2115. */
  2116. function commentpress_excerpt_length() {
  2117. // declare access to globals
  2118. global $commentpress_core;
  2119. // is the plugin active?
  2120. if ( !is_object( $commentpress_core ) ) {
  2121. // --<
  2122. return 55; // Wordpress default
  2123. }
  2124. // get length of excerpt from option
  2125. $length = $commentpress_core->db->option_get( 'cp_excerpt_length' );
  2126. // --<
  2127. return $length;
  2128. }
  2129. endif; // commentpress_excerpt_length
  2130. // add filter for excerpt length
  2131. add_filter( 'excerpt_length', 'commentpress_excerpt_length' );
  2132. if ( ! function_exists( 'commentpress_add_link_css' ) ):
  2133. /**
  2134. * @description: utility to add button css class to blog nav links
  2135. * @todo:
  2136. *
  2137. */
  2138. function commentpress_add_link_css( $link ) {
  2139. // add css
  2140. $link = str_replace( '<a ', '<a class="css_btn" ', $link );
  2141. // --<
  2142. return $link;
  2143. }
  2144. endif; // commentpress_add_link_css
  2145. // add filter for next/previous links
  2146. add_filter( 'previous_post_link', 'commentpress_add_link_css' );
  2147. add_filter( 'next_post_link', 'commentpress_add_link_css' );
  2148. if ( ! function_exists( 'commentpress_get_link_css' ) ):
  2149. /**
  2150. * @description: utility to add button css class to blog nav links
  2151. * @todo:
  2152. *
  2153. */
  2154. function commentpress_get_link_css() {
  2155. // add css
  2156. $link = 'class="css_btn"';
  2157. // --<
  2158. return $link;
  2159. }
  2160. endif; // commentpress_get_link_css
  2161. // add filter for next/previous posts links
  2162. add_filter( 'previous_posts_link_attributes', 'commentpress_get_link_css' );
  2163. add_filter( 'next_posts_link_attributes', 'commentpress_get_link_css' );
  2164. if ( ! function_exists( 'commentpress_add_loginout_id' ) ):
  2165. /**
  2166. * @description: utility to add button css id to login links
  2167. * @todo:
  2168. *
  2169. */
  2170. function commentpress_add_loginout_id( $link ) {
  2171. // if logged in
  2172. if ( is_user_logged_in() ) {
  2173. // logout
  2174. $_id = 'btn_logout';
  2175. } else {
  2176. // login
  2177. $_id = 'btn_login';
  2178. }
  2179. // add css
  2180. $link = str_replace( '<a ', '<a id="'.$_id.'" class="button"', $link );
  2181. // --<
  2182. return $link;
  2183. }
  2184. endif; // commentpress_add_loginout_id
  2185. // add filters for WordPress admin links
  2186. add_filter( 'loginout', 'commentpress_add_link_css' );
  2187. add_filter( 'loginout', 'commentpress_add_loginout_id' );
  2188. add_filter( 'register', 'commentpress_add_loginout_id' );
  2189. if ( ! function_exists( 'commentpress_multipage_comment_link' ) ):
  2190. /**
  2191. * @description: filter comment permalinks for multipage posts
  2192. * @todo: should this go in the plugin?
  2193. *
  2194. */
  2195. function commentpress_multipage_comment_link( $link, $comment, $args ) {
  2196. // get multipage and post
  2197. global $multipage, $post;
  2198. // are there multiple (sub)pages?
  2199. //if ( is_object( $post ) AND $multipage ) {
  2200. // exclude page level comments
  2201. if ( $comment->comment_signature != '' ) {
  2202. // init page num
  2203. $page_num = 1;
  2204. // set key
  2205. $key = '_cp_comment_page';
  2206. // if the custom field already has a value...
  2207. if ( get_comment_meta( $comment->comment_ID, $key, true ) != '' ) {
  2208. // get the page number
  2209. $page_num = get_comment_meta( $comment->comment_ID, $key, true );
  2210. }
  2211. // get current comment info
  2212. $comment_path_info = parse_url( $link );
  2213. // set comment path
  2214. return commentpress_get_post_multipage_url( $page_num, get_post( $comment->comment_post_ID ) ).'#'.$comment_path_info['fragment'];
  2215. }
  2216. //}
  2217. // --<
  2218. return $link;
  2219. }
  2220. endif; // commentpress_multipage_comment_link
  2221. // add filter for the above
  2222. add_filter( 'get_comment_link', 'commentpress_multipage_comment_link', 10, 3 );
  2223. /**
  2224. * Copied from wp-includes/post-template.php _wp_link_page()
  2225. * @param int $i Page number.
  2226. * @return string url.
  2227. */
  2228. function commentpress_get_post_multipage_url( $i, $post = '' ) {
  2229. // if we have no passed value
  2230. if ( $post == '' ) {
  2231. // we assume we're in the loop
  2232. global $post, $wp_rewrite;
  2233. if ( 1 == $i ) {
  2234. $url = get_permalink();
  2235. } else {
  2236. if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
  2237. $url = add_query_arg( 'page', $i, get_permalink() );
  2238. elseif ( 'page' == get_option('show_on_front') AND get_option('page_on_front') == $post->ID )
  2239. $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged');
  2240. else
  2241. $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged');
  2242. }
  2243. } else {
  2244. // use passed post object
  2245. if ( 1 == $i ) {
  2246. $url = get_permalink( $post->ID );
  2247. } else {
  2248. if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
  2249. $url = add_query_arg( 'page', $i, get_permalink( $post->ID ) );
  2250. elseif ( 'page' == get_option('show_on_front') AND get_option('page_on_front') == $post->ID )
  2251. $url = trailingslashit(get_permalink( $post->ID )) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged');
  2252. else
  2253. $url = trailingslashit(get_permalink( $post->ID )) . user_trailingslashit($i, 'single_paged');
  2254. }
  2255. }
  2256. return esc_url( $url );
  2257. }
  2258. if ( ! function_exists( 'commentpress_multipager' ) ):
  2259. /**
  2260. * @description: adds some style
  2261. * @todo:
  2262. *
  2263. */
  2264. function commentpress_multipager() {
  2265. // set default behaviour
  2266. $defaults = array(
  2267. 'before' => '<div class="multipager">',
  2268. 'after' => '</div>',
  2269. 'link_before' => '',
  2270. 'link_after' => '',
  2271. 'next_or_number' => 'next',
  2272. 'nextpagelink' => '<span class="alignright">'.__('Next page','commentpress-core').' &raquo;</span>',
  2273. 'previouspagelink' => '<span class="alignleft">&laquo; '.__('Previous page','commentpress-core').'</span>',
  2274. 'pagelink' => '%',
  2275. 'more_file' => '',
  2276. 'echo' => 0
  2277. );
  2278. // get page links
  2279. $page_links = wp_link_pages( $defaults );
  2280. //print_r( $page_links ); die();
  2281. // add separator when there are two links
  2282. $page_links = str_replace(
  2283. 'a><a',
  2284. 'a> <span class="multipager_sep">|</span> <a',
  2285. $page_links
  2286. );
  2287. // get page links
  2288. $page_links .= wp_link_pages( array(
  2289. 'before' => '<div class="multipager multipager_all"><span>' . __('Pages: ','commentpress-core') . '</span>',
  2290. 'after' => '</div>',
  2291. 'pagelink' => '<span class="multipager_link">%</span>',
  2292. 'echo' => 0
  2293. ) );
  2294. // --<
  2295. return $page_links;
  2296. }
  2297. endif; // commentpress_multipager
  2298. /**
  2299. * @description; adds our styles to the TinyMCE editor
  2300. * @param string $mce_css The default TinyMCE stylesheets as set by WordPress
  2301. * @return string $mce_css The list of stylesheets with ours added
  2302. */
  2303. function commentpress_add_wp_editor() {
  2304. // init option
  2305. $rich_text = false;
  2306. global $commentpress_core;
  2307. // kick out if wp_editor doesn't exist
  2308. // TinyMCE will be handled by including the script using the pre- wp_editor() method
  2309. if ( !function_exists( 'wp_editor' ) ) {
  2310. // --<
  2311. return false;
  2312. }
  2313. // kick out if plugin not active
  2314. if ( !is_object( $commentpress_core ) ) {
  2315. // --<
  2316. return false;
  2317. }
  2318. // only allow through if plugin says so
  2319. if ( !$commentpress_core->display->is_tinymce_allowed() ) {
  2320. // --<
  2321. return false;
  2322. }
  2323. // add our buttons
  2324. $mce_buttons = apply_filters(
  2325. // filter for plugins
  2326. 'cp_tinymce_buttons',
  2327. // basic buttons
  2328. array(
  2329. 'bold',
  2330. 'italic',
  2331. 'underline',
  2332. '|',
  2333. 'bullist',
  2334. 'numlist',
  2335. '|',
  2336. 'link',
  2337. 'unlink',
  2338. '|',
  2339. 'removeformat',
  2340. 'fullscreen'
  2341. )
  2342. );
  2343. // our settings
  2344. $settings = array(
  2345. // configure comment textarea
  2346. 'media_buttons' => false,
  2347. 'textarea_name' => 'comment',
  2348. 'textarea_rows' => 10,
  2349. // might as well start with teeny
  2350. 'teeny' => true,
  2351. // give the iframe a white background
  2352. 'editor_css' => '
  2353. <style type="text/css">
  2354. /* <![CDATA[ */
  2355. .wp_themeSkin iframe
  2356. {
  2357. background: #fff;
  2358. }
  2359. /* ]]> */
  2360. </style>
  2361. ',
  2362. // configure TinyMCE
  2363. 'tinymce' => array(
  2364. 'theme' => 'advanced',
  2365. 'theme_advanced_buttons1' => implode( ',', $mce_buttons ),
  2366. 'theme_advanced_statusbar_location' => 'none',
  2367. ),
  2368. // no quicktags
  2369. 'quicktags' => false
  2370. );
  2371. /*
  2372. had we wanted quicktags, we could have used:
  2373. 'quicktags' => array(
  2374. 'buttons' => 'strong,em,ul,ol,li,link,close'
  2375. )
  2376. */
  2377. // create editor
  2378. wp_editor(
  2379. '', // initial content
  2380. 'comment', // id of comment textarea
  2381. $settings
  2382. );
  2383. // don't show textarea
  2384. return true;
  2385. }
  2386. /**
  2387. * @description; makes TinyMCE the default editor on the front end
  2388. * @param string $r The default editor as set by WordPress
  2389. * @return string 'tinymce' our overridden default editor
  2390. */
  2391. function commentpress_assign_default_editor( $r ) {
  2392. // only on front-end
  2393. if ( is_admin() ) { return $r; }
  2394. // always return 'tinymce' as the default editor, or else the comment form will not show up!
  2395. // --<
  2396. return 'tinymce';
  2397. }
  2398. add_filter( 'wp_default_editor', 'commentpress_assign_default_editor', 10, 1 );
  2399. /**
  2400. * @description; adds our styles to the TinyMCE editor
  2401. * @param string $mce_css The default TinyMCE stylesheets as set by WordPress
  2402. * @return string $mce_css The list of stylesheets with ours added
  2403. */
  2404. function commentpress_add_tinymce_styles( $mce_css ) {
  2405. // only on front-end
  2406. if ( is_admin() ) { return $mce_css; }
  2407. // add comma if not empty
  2408. if ( !empty( $mce_css ) ) { $mce_css .= ','; }
  2409. // add our editor styles
  2410. $mce_css .= get_template_directory_uri().'/assets/css/comment-form.css';
  2411. return $mce_css;
  2412. }
  2413. // add filter for the above
  2414. add_filter( 'mce_css', 'commentpress_add_tinymce_styles' );
  2415. /**
  2416. * @description; adds the Next Page button to the TinyMCE editor
  2417. * @param array $buttons The default TinyMCE buttons as set by WordPress
  2418. * @return array $buttons The buttons with More removed
  2419. */
  2420. function commentpress_add_tinymce_nextpage_button( $buttons ) {
  2421. // only on back-end
  2422. if ( !is_admin() ) { return $buttons; }
  2423. // try and place Next Page after More button
  2424. $pos = array_search( 'wp_more', $buttons, true );
  2425. // is it there?
  2426. if ($pos !== false) {
  2427. // get array up to that point
  2428. $tmp_buttons = array_slice( $buttons, 0, $pos + 1 );
  2429. // add Next Page button
  2430. $tmp_buttons[] = 'wp_page';
  2431. // recombine
  2432. $buttons = array_merge( $tmp_buttons, array_slice( $buttons, $pos + 1 ) );
  2433. }
  2434. // --<
  2435. return $buttons;
  2436. }
  2437. // add filter for the above
  2438. add_filter( 'mce_buttons', 'commentpress_add_tinymce_nextpage_button' );
  2439. if ( ! function_exists( 'commentpress_comment_post_redirect' ) ):
  2440. /**
  2441. * @description: filter comment post redirects for multipage posts
  2442. * @todo: should this go in the plugin?
  2443. *
  2444. */
  2445. function commentpress_comment_post_redirect( $link ) {
  2446. // get page var, indicating subpage
  2447. $page = (isset($_POST['page'])) ? $_POST['page'] : 0;
  2448. // are we on a subpage?
  2449. if ( $page ) {
  2450. // get current redirect
  2451. $current_redirect = parse_url( $link );
  2452. // we need to use the page that submitted the comment
  2453. $page_info = $_SERVER['HTTP_REFERER'];
  2454. // set redirect to comment on subpage
  2455. return $page_info.'#'.$current_redirect['fragment'];
  2456. }
  2457. // --<
  2458. return $link;
  2459. }
  2460. endif; // commentpress_comment_post_redirect
  2461. // add filter for the above, making it run early so it can be overridden by AJAX commenting
  2462. add_filter( 'comment_post_redirect', 'commentpress_comment_post_redirect', 4, 1 );
  2463. if ( ! function_exists( 'commentpress_image_caption_shortcode' ) ):
  2464. /**
  2465. * @description: rebuild caption shortcode output
  2466. * @param array $empty WordPress passes '' as the first param!
  2467. * @param array $attr Attributes attributed to the shortcode.
  2468. * @param string $content Optional. Shortcode content.
  2469. * @return string
  2470. * @todo:
  2471. *
  2472. */
  2473. function commentpress_image_caption_shortcode( $empty=null, $attr, $content ) {
  2474. // get our shortcode vars
  2475. extract(shortcode_atts(array(
  2476. 'id' => '',
  2477. 'align' => 'alignnone',
  2478. 'width' => '',
  2479. 'caption' => ''
  2480. ), $attr));
  2481. /*
  2482. print_r( array(
  2483. 'content' => $content,
  2484. 'caption' => $caption,
  2485. ) ); die();
  2486. */
  2487. if ( 1 > (int) $width || empty($caption) )
  2488. return $content;
  2489. // sanitise id
  2490. if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
  2491. // add space prior to alignment
  2492. $_alignment = ' '.esc_attr($align);
  2493. // get width
  2494. $_width = (0 + (int) $width);
  2495. // construct
  2496. $_caption = '<!-- cp_caption_start --><span class="captioned_image'.$_alignment.'" style="width: '.$_width.'px"><span '.$id.' class="wp-caption">'
  2497. . do_shortcode( $content ) . '</span><small class="wp-caption-text">'.$caption.'</small></span><!-- cp_caption_end -->';
  2498. // --<
  2499. return $_caption;
  2500. }
  2501. endif; // commentpress_image_caption_shortcode
  2502. // add a filter for the above
  2503. add_filter( 'img_caption_shortcode', 'commentpress_image_caption_shortcode', 10, 3 );
  2504. if ( ! function_exists( 'commentpress_add_commentblock_button' ) ):
  2505. /**
  2506. * @description: add filters for adding our custom TinyMCE button
  2507. * @todo:
  2508. *
  2509. */
  2510. function commentpress_add_commentblock_button() {
  2511. // only on back-end
  2512. if ( !is_admin() ) { return; }
  2513. // don't bother doing this stuff if the current user lacks permissions
  2514. if ( ! current_user_can('edit_posts') AND ! current_user_can('edit_pages') ) {
  2515. return;
  2516. }
  2517. // add only if user can edit in Rich-text Editor mode
  2518. if ( get_user_option('rich_editing') == 'true') {
  2519. add_filter( 'mce_external_plugins', 'commentpress_add_commentblock_tinymce_plugin' );
  2520. add_filter( 'mce_buttons', 'commentpress_register_commentblock_button' );
  2521. }
  2522. }
  2523. endif; // commentpress_add_commentblock_button
  2524. if ( ! function_exists( 'commentpress_register_commentblock_button' ) ):
  2525. /**
  2526. * @description: add filters for adding our custom TinyMCE button
  2527. * @todo:
  2528. *
  2529. */
  2530. function commentpress_register_commentblock_button( $buttons ) {
  2531. // add our button to the editor button array
  2532. array_push( $buttons, '|', 'commentblock' );
  2533. // --<
  2534. return $buttons;
  2535. }
  2536. endif; // commentpress_register_commentblock_button
  2537. if ( ! function_exists( 'commentpress_add_commentblock_tinymce_plugin' ) ):
  2538. /**
  2539. * @description: load the TinyMCE plugin : cp_editor_plugin.js
  2540. * @todo:
  2541. *
  2542. */
  2543. function commentpress_add_commentblock_tinymce_plugin( $plugin_array ) {
  2544. // add comment block
  2545. $plugin_array['commentblock'] = get_template_directory_uri().'/assets/js/tinymce/cp_editor_plugin.js';
  2546. // --<
  2547. return $plugin_array;
  2548. }
  2549. endif; // commentpress_add_commentblock_tinymce_plugin
  2550. if ( ! function_exists( 'commentpress_refresh_mce' ) ):
  2551. /**
  2552. * @description: load the TinyMCE plugin : cp_editor_plugin.js
  2553. * @todo: can this be removed? doesn't seem to affect things...
  2554. *
  2555. */
  2556. function commentpress_refresh_mce($ver) {
  2557. $ver += 3;
  2558. return $ver;
  2559. }
  2560. endif; // commentpress_refresh_mce
  2561. // init process for button control
  2562. //add_filter( 'tiny_mce_version', 'commentpress_refresh_mce');
  2563. add_action( 'init', 'commentpress_add_commentblock_button' );
  2564. if ( ! function_exists( 'commentpress_trap_empty_search' ) ):
  2565. /**
  2566. * @description: trap empty search queries and redirect
  2567. * @todo: this isn't ideal, but works - awaiting core updates
  2568. *
  2569. */
  2570. function commentpress_trap_empty_search() {
  2571. // take care of empty searches
  2572. if ( isset( $_GET['s'] ) AND empty( $_GET['s'] ) ) {
  2573. // send to search page
  2574. return locate_template( array( 'search.php' ) );
  2575. }
  2576. }
  2577. endif; // commentpress_trap_empty_search
  2578. // front_page_template filter is deprecated in WP 3.2+
  2579. if ( version_compare( $wp_version, '3.2', '>=' ) ) {
  2580. // add filter for the above
  2581. add_filter( 'home_template', 'commentpress_trap_empty_search' );
  2582. } else {
  2583. // retain old filter for earlier versions
  2584. add_filter( 'front_page_template', 'commentpress_trap_empty_search' );
  2585. }
  2586. if ( ! function_exists( 'commentpress_amend_password_form' ) ):
  2587. /**
  2588. * @description: adds some style
  2589. * @todo:
  2590. *
  2591. */
  2592. function commentpress_amend_password_form( $output ) {
  2593. // add css class to form
  2594. $output = str_replace( '<form ', '<form class="post_password_form" ', $output );
  2595. // add css class to text field
  2596. $output = str_replace( '<input name="post_password" ', '<input class="post_password_field" name="post_password" ', $output );
  2597. // add css class to submit button
  2598. $output = str_replace( '<input type="submit" ', '<input class="post_password_button" type="submit" ', $output );
  2599. // --<
  2600. return $output;
  2601. }
  2602. endif; // commentpress_amend_password_form
  2603. // add filter for the above
  2604. add_filter( 'the_password_form', 'commentpress_amend_password_form' );
  2605. if ( ! function_exists( 'commentpress_widgets_init' ) ):
  2606. /**
  2607. * Register our widgets
  2608. */
  2609. function commentpress_widgets_init() {
  2610. // define an area where a widget may be placed
  2611. register_sidebar( array(
  2612. 'name' => __( 'CommentPress Footer', 'commentpress-core' ),
  2613. 'id' => 'cp-license-8',
  2614. 'description' => __( 'An optional widget area in the page footer of the CommentPress theme', 'commentpress-core' ),
  2615. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  2616. 'after_widget' => "</div>",
  2617. 'before_title' => '<h3 class="widget-title">',
  2618. 'after_title' => '</h3>',
  2619. ) );
  2620. // widget definitions
  2621. require( get_template_directory() . '/assets/widgets/widgets.php' );
  2622. // and the widget
  2623. register_widget( 'Commentpress_License_Widget' );
  2624. }
  2625. endif; // commentpress_widgets_init
  2626. add_action( 'widgets_init', 'commentpress_widgets_init' );
  2627. if ( ! function_exists( 'commentpress_license_image_css' ) ):
  2628. /**
  2629. * Amend display of license plugin image
  2630. */
  2631. function commentpress_license_image_css() {
  2632. // give a bit more room to the image
  2633. return 'display: block; float: left; margin: 0 6px 3px 0;';
  2634. }
  2635. endif; // commentpress_license_image_css
  2636. add_action( 'license_img_style', 'commentpress_license_image_css' );
  2637. if ( ! function_exists( 'commentpress_license_widget_compat' ) ):
  2638. /**
  2639. * Remove license from footer when widget not active - wp_footer() is not inside #footer
  2640. */
  2641. function commentpress_license_widget_compat() {
  2642. // if the widget is not active, (i.e. the plugin is installed but the widget has not been
  2643. // dragged to a sidebar), then DO NOT display the license in the footer as a default
  2644. if (!is_active_widget(false, false, 'license-widget', true) ) {
  2645. remove_action( 'wp_footer', 'license_print_license_html' );
  2646. }
  2647. }
  2648. endif; // commentpress_license_widget_compat
  2649. // do this late, so license ought to be declared by then
  2650. add_action( 'widgets_init', 'commentpress_license_widget_compat', 100 );
  2651. if ( ! function_exists( 'commentpress_wplicense_compat' ) ):
  2652. /**
  2653. * Remove license from footer - wp_footer() is not inside #footer
  2654. */
  2655. function commentpress_wplicense_compat() {
  2656. // let's not have the default footer
  2657. remove_action('wp_footer', 'cc_showLicenseHtml');
  2658. }
  2659. endif; // commentpress_wplicense_compat
  2660. // do this late, so license ought to be declared by then
  2661. add_action( 'init', 'commentpress_wplicense_compat', 100 );
  2662. if ( ! function_exists( 'commentpress_groupblog_classes' ) ):
  2663. /**
  2664. * Add classes to #content in BuddyPress, so that we can distinguish different groupblog types
  2665. */
  2666. function commentpress_groupblog_classes() {
  2667. // init empty
  2668. $groupblog_class = '';
  2669. // only add classes when bp-groupblog is active
  2670. if ( function_exists( 'get_groupblog_group_id' ) ) {
  2671. // init groupblogtype
  2672. $groupblogtype = 'groupblog';
  2673. // get group blogtype
  2674. $groupblog_type = groups_get_groupmeta( bp_get_current_group_id(), 'groupblogtype' );
  2675. // did we get one?
  2676. if ( $groupblog_type ) {
  2677. // add to default
  2678. $groupblogtype .= ' '.$groupblog_type;
  2679. }
  2680. // complete
  2681. $groupblog_class = ' class="'.$groupblogtype.'"';
  2682. }
  2683. // --<
  2684. return $groupblog_class;
  2685. }
  2686. endif; // commentpress_groupblog_classes
  2687. if ( ! function_exists( 'commentpress_get_post_version_info' ) ):
  2688. /**
  2689. * Get links to previous and next versions, should they exist
  2690. */
  2691. function commentpress_get_post_version_info( $post ) {
  2692. // check for newer version
  2693. $newer_link = '';
  2694. // assume no newer version
  2695. $newer_id = '';
  2696. // set key
  2697. $key = '_cp_newer_version';
  2698. // if the custom field already has a value...
  2699. if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
  2700. // get it
  2701. $newer_id = get_post_meta( $post->ID, $key, true );
  2702. }
  2703. // if we've got one...
  2704. if ( $newer_id !== '' ) {
  2705. // get post
  2706. $newer_post = get_post( $newer_id );
  2707. // is it published?
  2708. if ( $newer_post->post_status == 'publish' ) {
  2709. // get link
  2710. $_link = get_permalink( $newer_post->ID );
  2711. // construct anchor
  2712. $newer_link = '<a href="'.$_link.'" title="Newer version">Newer version &rarr;</a>';
  2713. }
  2714. }
  2715. // check for older version
  2716. $older_link = '';
  2717. // get post with this post's ID as their _cp_newer_version meta value
  2718. $args = array(
  2719. 'numberposts' => 1,
  2720. 'meta_key' => '_cp_newer_version',
  2721. 'meta_value' => $post->ID
  2722. );
  2723. // get the array
  2724. $previous_posts = get_posts( $args );
  2725. // did we get one?
  2726. if ( is_array( $previous_posts ) AND count( $previous_posts ) == 1 ) {
  2727. // get it
  2728. $older_post = $previous_posts[0];
  2729. // is it published?
  2730. if ( $older_post->post_status == 'publish' ) {
  2731. // get link
  2732. $_link = get_permalink( $older_post->ID );
  2733. // construct anchor
  2734. $older_link = '<a href="'.$_link.'" title="Older version">&larr; Older version</a>';
  2735. }
  2736. }
  2737. // did we get either?
  2738. if ( $newer_link != '' OR $older_link != '' ) {
  2739. ?>
  2740. <div class="version_info">
  2741. <ul>
  2742. <?php if ( $newer_link != '' ) echo '<li class="newer_version">'.$newer_link.'</li>'; ?>
  2743. <?php if ( $older_link != '' ) echo '<li class="older_version">'.$older_link.'</li>'; ?>
  2744. </ul>
  2745. </div>
  2746. <?php
  2747. }
  2748. }
  2749. endif; // commentpress_get_post_version_info
  2750. if ( ! function_exists( 'commentpress_get_post_css_override' ) ):
  2751. /**
  2752. * Get links to previous and next versions, should they exist
  2753. */
  2754. function commentpress_get_post_css_override( $post_id ) {
  2755. // add a class for overridden page types
  2756. $type_overridden = '';
  2757. // declare access to globals
  2758. global $commentpress_core;
  2759. //print_r(array( 'here' )); die();
  2760. // if we have the plugin enabled...
  2761. if ( is_object( $commentpress_core ) ) {
  2762. // default to current blog type
  2763. $type = $commentpress_core->db->option_get( 'cp_blog_type' );
  2764. //print_r($type); die();
  2765. // set post meta key
  2766. $key = '_cp_post_type_override';
  2767. // but, if the custom field has a value...
  2768. if ( get_post_meta( $post_id, $key, true ) !== '' ) {
  2769. // get it
  2770. $overridden_type = get_post_meta( $post_id, $key, true );
  2771. // is it different to the current blog type?
  2772. if ( $overridden_type != $type ) {
  2773. $type_overridden = ' overridden_type-'.$overridden_type;
  2774. }
  2775. }
  2776. }
  2777. // --<
  2778. return $type_overridden;
  2779. }
  2780. endif; // commentpress_get_post_css_override
  2781. if ( ! function_exists( 'commentpress_get_post_title_visibility' ) ):
  2782. /**
  2783. * Get links to previous and next versions, should they exist
  2784. */
  2785. function commentpress_get_post_title_visibility( $post_id ) {
  2786. // init hide (show by default)
  2787. $hide = 'show';
  2788. // declare access to globals
  2789. global $commentpress_core;
  2790. // if we have the plugin enabled...
  2791. if ( is_object( $commentpress_core ) ) {
  2792. // get global hide
  2793. $hide = $commentpress_core->db->option_get( 'cp_title_visibility' );;
  2794. }
  2795. // set key
  2796. $key = '_cp_title_visibility';
  2797. //if the custom field already has a value...
  2798. if ( get_post_meta( $post_id, $key, true ) != '' ) {
  2799. // get it
  2800. $hide = get_post_meta( $post_id, $key, true );
  2801. }
  2802. // --<
  2803. return ( $hide == 'show' ) ? true : false;
  2804. }
  2805. endif; // commentpress_get_post_title_visibility
  2806. if ( ! function_exists( 'commentpress_get_post_meta_visibility' ) ):
  2807. /**
  2808. * Get links to previous and next versions, should they exist
  2809. */
  2810. function commentpress_get_post_meta_visibility( $post_id ) {
  2811. // init hide (hide by default)
  2812. $hide_meta = 'hide';
  2813. // declare access to globals
  2814. global $commentpress_core;
  2815. // if we have the plugin enabled...
  2816. if ( is_object( $commentpress_core ) ) {
  2817. // get global hide_meta
  2818. $hide_meta = $commentpress_core->db->option_get( 'cp_page_meta_visibility' );;
  2819. // set key
  2820. $key = '_cp_page_meta_visibility';
  2821. // if the custom field already has a value...
  2822. if ( get_post_meta( $post_id, $key, true ) != '' ) {
  2823. // override with local value
  2824. $hide_meta = get_post_meta( $post_id, $key, true );
  2825. }
  2826. }
  2827. // --<
  2828. return ( $hide_meta == 'show' ) ? true : false;
  2829. }
  2830. endif; // commentpress_get_post_meta_visibility