PageRenderTime 114ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/code/cake/app/webroot/cp/wp-content/plugins/commentpress-core/commentpress-core/class_commentpress.php

https://github.com/DigitalPaulScholtenProject/DPSP-Platform
PHP | 2731 lines | 752 code | 1167 blank | 812 comment | 134 complexity | 6731f791fba4ae2f3af936f38609a5df MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, AGPL-1.0, LGPL-2.1

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

  1. <?php /*
  2. ================================================================================
  3. Class CommentpressCore
  4. ================================================================================
  5. AUTHOR: Christian Wach <needle@haystack.co.uk>
  6. --------------------------------------------------------------------------------
  7. NOTES
  8. =====
  9. --------------------------------------------------------------------------------
  10. */
  11. /*
  12. ================================================================================
  13. Class Name
  14. ================================================================================
  15. */
  16. class CommentpressCore {
  17. /*
  18. ============================================================================
  19. Properties
  20. ============================================================================
  21. */
  22. // database object
  23. var $db;
  24. // display object
  25. var $display;
  26. // nav object
  27. var $nav;
  28. // parser object
  29. var $parser;
  30. // formatter object
  31. var $formatter;
  32. // workflow object
  33. var $workflow;
  34. // options page
  35. var $options_page;
  36. // buddypress present
  37. var $buddypress = false;
  38. // bp-groupblog present
  39. var $bp_groupblog = false;
  40. /**
  41. * @description: initialises this object
  42. * @return object
  43. * @todo:
  44. *
  45. */
  46. function __construct() {
  47. // init
  48. $this->_init();
  49. //$this->groupblog_theme_is_set();
  50. // --<
  51. return $this;
  52. }
  53. /**
  54. * PHP 4 constructor
  55. */
  56. function CommentpressCore() {
  57. // is this php5?
  58. if ( version_compare( PHP_VERSION, "5.0.0", "<" ) ) {
  59. // call php5 constructor
  60. $this->__construct();
  61. }
  62. // --<
  63. return $this;
  64. }
  65. /**
  66. * @description: if needed, destroys this object
  67. * @todo:
  68. *
  69. */
  70. function destroy() {
  71. // nothing
  72. }
  73. //##############################################################################
  74. /*
  75. ============================================================================
  76. PUBLIC METHODS
  77. ============================================================================
  78. */
  79. /**
  80. * @description: runs when plugin is activated
  81. * @todo:
  82. *
  83. */
  84. function activate() {
  85. // initialise display - sets the theme
  86. $this->display->activate();
  87. // initialise database
  88. $this->db->activate();
  89. }
  90. /**
  91. * @description: runs when plugin is deactivated
  92. * @todo:
  93. *
  94. */
  95. function deactivate() {
  96. // call database destroy method
  97. $this->db->deactivate();
  98. // call display destroy method
  99. $this->display->deactivate();
  100. }
  101. /**
  102. * @description: loads translation, if present
  103. * @todo:
  104. *
  105. */
  106. function translation() {
  107. // only use, if we have it...
  108. if( function_exists('load_plugin_textdomain') ) {
  109. // not used, as there are no translations as yet
  110. load_plugin_textdomain(
  111. // unique name
  112. 'commentpress-core',
  113. // deprecated argument
  114. false,
  115. // relative path to directory containing translation files
  116. dirname( plugin_basename( COMMENTPRESS_PLUGIN_FILE ) ) . '/languages/'
  117. );
  118. }
  119. }
  120. /**
  121. * @description: called when BuddyPress is active
  122. * @todo:
  123. *
  124. */
  125. function buddypress_init() {
  126. // we've got BuddyPress installed
  127. $this->buddypress = true;
  128. }
  129. /**
  130. * @description: configure when BuddyPress is loaded
  131. * @todo:
  132. *
  133. */
  134. function buddypress_globals_loaded() {
  135. // for bp-groupblog integration...
  136. if (
  137. // require multisite
  138. is_multisite()
  139. // and groups
  140. AND bp_is_active( 'groups' )
  141. // and bp-groupblog
  142. AND defined( 'BP_GROUPBLOG_IS_INSTALLED' )
  143. ) {
  144. // check if this blog is a group blog...
  145. $group_id = get_groupblog_group_id( get_current_blog_id() );
  146. if ( is_numeric( $group_id ) ) {
  147. // okay, we're properly configured
  148. $this->bp_groupblog = true;
  149. }
  150. }
  151. }
  152. /**
  153. * @description: is BuddyPress active?
  154. * @todo:
  155. *
  156. */
  157. function is_buddypress() {
  158. // --<
  159. return $this->buddypress;
  160. }
  161. /**
  162. * @description: is this a BuddyPress Group Blog?
  163. * @todo:
  164. *
  165. */
  166. function is_groupblog() {
  167. // --<
  168. return $this->bp_groupblog;
  169. }
  170. /**
  171. * @description: is a BP Group Blog theme set?
  172. * @todo:
  173. *
  174. */
  175. function get_groupblog_theme() {
  176. // kick out if not in a group context
  177. if ( !function_exists( 'bp_is_groups_component' ) ) { return false; }
  178. if ( !bp_is_groups_component() ) { return false; }
  179. // get groupblog options
  180. $options = get_site_option( 'bp_groupblog_blog_defaults_options' );
  181. // get theme setting
  182. if ( !empty( $options['theme'] ) ) {
  183. // we have a groupblog theme set
  184. // split the options
  185. list( $stylesheet, $template ) = explode( "|", $options['theme'] );
  186. // test for WP3.4...
  187. if ( function_exists( 'wp_get_theme' ) ) {
  188. // get the registered theme
  189. $theme = wp_get_theme( $stylesheet );
  190. // test if it's a CommentPress Core theme
  191. if ( in_array( 'commentpress', (array) $theme->Tags ) ) {
  192. // --<
  193. return array( $stylesheet, $template );
  194. }
  195. } else {
  196. // get the registered theme
  197. $theme = get_theme( $stylesheet );
  198. // test if it's a CommentPress Core theme
  199. if ( in_array( 'commentpress', (array) $theme['Tags'] ) ) {
  200. // --<
  201. return array( $stylesheet, $template );
  202. }
  203. }
  204. }
  205. // --<
  206. return false;
  207. }
  208. /**
  209. * @description: is this a BuddyPress "special page" - a component homepage?
  210. * @todo:
  211. *
  212. */
  213. function is_buddypress_special_page() {
  214. // kick out if not BP
  215. if ( !$this->is_buddypress() ) {
  216. return false;
  217. }
  218. // let's see...
  219. return !bp_is_blog_page();
  220. }
  221. /**
  222. * @description: utility to add a message to admin pages when upgrade required
  223. * @todo:
  224. *
  225. */
  226. function admin_upgrade_alert() {
  227. // sanity check function exists
  228. if ( function_exists('current_user_can') ) {
  229. // check user permissions
  230. if ( current_user_can('manage_options') ) {
  231. // show it
  232. echo '<div id="message" class="error"><p>'.__( 'CommentPress Core has been updated. Please visit the ' ).'<a href="options-general.php?page=commentpress_admin">'.__( 'Settings Page', 'commentpress-core' ).'</a>.</p></div>';
  233. }
  234. }
  235. }
  236. /**
  237. * @description: appends option to admin menu
  238. * @todo:
  239. *
  240. */
  241. function admin_menu() {
  242. // sanity check function exists
  243. if ( function_exists('current_user_can') ) {
  244. // check user permissions
  245. if ( current_user_can('manage_options') ) {
  246. // try and update options
  247. $saved = $this->db->options_update();
  248. // if upgrade required...
  249. if ( $this->db->check_upgrade() ) {
  250. // access globals
  251. global $pagenow;
  252. // show on pages other than the CP admin page
  253. if (
  254. $pagenow == 'options-general.php'
  255. AND !empty( $_GET['page'] )
  256. AND 'commentpress_admin' == $_GET['page']
  257. ) {
  258. // we're on our admin page
  259. } else {
  260. // show message
  261. add_action( 'admin_notices', array( $this, 'admin_upgrade_alert' ) );
  262. }
  263. }
  264. // insert item in relevant menu
  265. $this->options_page = add_options_page(
  266. __( 'CommentPress Core Settings', 'commentpress-core' ),
  267. __( 'CommentPress Core', 'commentpress-core' ),
  268. 'manage_options',
  269. 'commentpress_admin',
  270. array( $this, 'options_page' )
  271. );
  272. //print_r( $this->options_page );die();
  273. // add scripts and styles
  274. add_action( 'admin_print_scripts-'.$this->options_page, array( $this, 'admin_js' ) );
  275. add_action( 'admin_print_styles-'.$this->options_page, array( $this, 'admin_css' ) );
  276. add_action( 'admin_head-'.$this->options_page, array( $this, 'admin_head' ), 50 );
  277. }
  278. }
  279. }
  280. /**
  281. * @description: prints plugin options page header
  282. * @todo:
  283. *
  284. */
  285. function admin_head() {
  286. // get admin javascript
  287. echo $this->display->get_admin_js();
  288. // there's a new screen object for help in 3.3
  289. global $wp_version;
  290. if ( version_compare( $wp_version, '3.2.99999', '>=' ) ) {
  291. $screen = get_current_screen();
  292. //print_r( $screen ); die();
  293. // use method in this class
  294. $this->options_help( $screen );
  295. }
  296. // do we have a custom header bg colour?
  297. if ( $this->db->option_get_header_bg() != $this->db->header_bg_colour ) {
  298. // echo inline style
  299. echo '
  300. <style type="text/css">
  301. #book_header {
  302. background: #'.$this->db->option_get_header_bg().';
  303. }
  304. </style>
  305. ';
  306. }
  307. }
  308. /**
  309. * @description: queue plugin options page css
  310. * @todo:
  311. *
  312. */
  313. function admin_css() {
  314. // enqueue farbtastic
  315. wp_enqueue_style( 'farbtastic' );
  316. // add admin stylesheet
  317. wp_enqueue_style(
  318. 'commentpress_admin_css',
  319. plugins_url( 'commentpress-core/assets/css/admin.css', COMMENTPRESS_PLUGIN_FILE ),
  320. false,
  321. COMMENTPRESS_VERSION, // version
  322. 'all' // media
  323. );
  324. }
  325. /**
  326. * @description: queue plugin options page javascript
  327. * @todo:
  328. *
  329. */
  330. function admin_js() {
  331. // enqueue farbtastic
  332. wp_enqueue_script( 'farbtastic' );
  333. }
  334. /**
  335. * @description: prints plugin options page
  336. * @todo:
  337. *
  338. */
  339. function options_page() {
  340. // sanity check function exists
  341. if ( function_exists( 'current_user_can' ) ) {
  342. // check user permissions
  343. if ( current_user_can( 'manage_options' ) ) {
  344. // get our admin options page
  345. echo $this->display->get_admin_page();
  346. }
  347. }
  348. }
  349. /**
  350. * @description: add scripts needed across all WP admin pages
  351. * @todo:
  352. *
  353. */
  354. function enqueue_admin_scripts() {
  355. // add quicktag button to page editor
  356. $this->display->get_custom_quicktags();
  357. }
  358. /**
  359. * @description: adds script libraries
  360. * @todo:
  361. *
  362. */
  363. function enqueue_scripts() {
  364. // don't include in admin or wp-login.php
  365. if ( is_admin() OR ( isset( $GLOBALS['pagenow'] ) AND 'wp-login.php' == $GLOBALS['pagenow'] ) ) {
  366. return;
  367. }
  368. // test for mobile user agents
  369. $this->db->test_for_mobile();
  370. // add jQuery libraries
  371. $this->display->get_jquery();
  372. // if comments are enabled on this post/page
  373. if ( $this->db->comments_enabled() ) {
  374. // add tinyMCE scripts
  375. $this->display->get_tinymce();
  376. }
  377. }
  378. /**
  379. * @description: adds CSS
  380. * @todo:
  381. *
  382. */
  383. function enqueue_styles() {
  384. // add plugin styles
  385. $this->display->get_frontend_styles();
  386. }
  387. /**
  388. * @description: redirect to child page
  389. * @todo:
  390. *
  391. */
  392. function redirect_to_child() {
  393. // do redirect
  394. $this->nav->redirect_to_child();
  395. }
  396. /**
  397. * @description: inserts plugin-specific header items
  398. * @param string $headers
  399. * @return string $headers
  400. * @todo:
  401. *
  402. */
  403. function head( $headers ) {
  404. // do we have navigation?
  405. if ( is_single() OR is_page() OR is_attachment() ) {
  406. // initialise nav
  407. $this->nav->initialise();
  408. }
  409. }
  410. /**
  411. * @description: parses page/post content
  412. * @param string $content the content of the page/post
  413. * @return string $content
  414. * @todo:
  415. *
  416. */
  417. function the_content( $content ) {
  418. // reference our post
  419. global $post;
  420. // compat with Subscribe to Comments Reloaded
  421. if( $this->is_subscribe_to_comments_reloaded_page() ) {
  422. // --<
  423. return $content;
  424. }
  425. // compat with Theme My Login
  426. if( $this->is_theme_my_login_page() ) {
  427. // --<
  428. return $content;
  429. }
  430. // test for buddypress special page (compat with BP Docs)
  431. if ( $this->is_buddypress() ) {
  432. // is it a component homepage?
  433. if ( $this->is_buddypress_special_page() ) {
  434. // --<
  435. return $content;
  436. }
  437. }
  438. // only parse posts or pages...
  439. if( ( is_single() OR is_page() OR is_attachment() ) AND !$this->db->is_special_page() ) {
  440. // delegate to parser
  441. $content = $this->parser->the_content( $content );
  442. }
  443. // --<
  444. return $content;
  445. }
  446. /**
  447. * @description: retrieves option for displaying TOC
  448. * @return mixed $result
  449. * @todo:
  450. *
  451. */
  452. function get_list_option() {
  453. // get list option flag
  454. $result = $this->db->option_get( 'cp_show_posts_or_pages_in_toc' );
  455. // --<
  456. return $result;
  457. }
  458. /**
  459. * @description: retrieves minimise all button
  460. * @param: string $sidebar type of sidebar (comments, toc, activity)
  461. * @return string $result HTML for minimise button
  462. * @todo:
  463. *
  464. */
  465. function get_minimise_all_button( $sidebar = 'comments' ) {
  466. // get minimise image
  467. $result = $this->display->get_minimise_all_button( $sidebar );
  468. // --<
  469. return $result;
  470. }
  471. /**
  472. * @description: retrieves header minimise button
  473. * @return string $result HTML for minimise button
  474. * @todo:
  475. *
  476. */
  477. function get_header_min_link() {
  478. // get minimise image
  479. $result = $this->display->get_header_min_link();
  480. // --<
  481. return $result;
  482. }
  483. /**
  484. * @description: retrieves text_signature hidden input
  485. * @return string $result HTML input
  486. * @todo:
  487. *
  488. */
  489. function get_signature_field() {
  490. // init text signature
  491. $text_sig = '';
  492. // get comment ID to reply to from URL query string
  493. $reply_to_comment_id = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
  494. // did we get a comment ID?
  495. if ( $reply_to_comment_id != 0 ) {
  496. // get paragraph text signature
  497. $text_sig = $this->db->get_text_signature_by_comment_id( $reply_to_comment_id );
  498. } else {
  499. // do we have a paragraph number in the query string?
  500. $reply_to_para_id = isset($_GET['replytopara']) ? (int) $_GET['replytopara'] : 0;
  501. // did we get a comment ID?
  502. if ( $reply_to_para_id != 0 ) {
  503. // get paragraph text signature
  504. $text_sig = $this->get_text_signature( $reply_to_para_id );
  505. }
  506. }
  507. // get list option flag
  508. $result = $this->display->get_signature_input( $text_sig );
  509. // --<
  510. return $result;
  511. }
  512. /**
  513. * @description: add reserved names
  514. * @param array $reserved_names the existing list of illegal names
  515. * @todo:
  516. *
  517. */
  518. function add_reserved_names( $reserved_names ) {
  519. // get all image attachments to our title page
  520. $reserved_names = array_merge(
  521. $reserved_names,
  522. array(
  523. 'title-page',
  524. 'general-comments',
  525. 'all-comments',
  526. 'comments-by-commenter',
  527. 'table-of-contents',
  528. 'author', // not currently used
  529. 'login', // for Theme My Login
  530. )
  531. );
  532. // --<
  533. return $reserved_names;
  534. }
  535. /**
  536. * @description: add sidebar to signup form
  537. * @todo:
  538. *
  539. */
  540. function after_signup_form() {
  541. // add sidebar
  542. get_sidebar();
  543. }
  544. /**
  545. * @description: adds meta boxes to admin screens
  546. * @todo:
  547. *
  548. */
  549. function add_meta_boxes() {
  550. // add our meta boxes to pages
  551. add_meta_box(
  552. 'commentpress_page_options',
  553. __( 'CommentPress Core Options', 'commentpress-core' ),
  554. array( $this, 'custom_box_page' ),
  555. 'page',
  556. 'side'
  557. );
  558. // add our meta box to posts
  559. add_meta_box(
  560. 'commentpress_post_options',
  561. __( 'CommentPress Core Options', 'commentpress-core' ),
  562. array( $this, 'custom_box_post' ),
  563. 'post',
  564. 'side'
  565. );
  566. // get workflow
  567. $_workflow = $this->db->option_get( 'cp_blog_workflow' );
  568. // if it's enabled...
  569. if ( $_workflow == '1' ) {
  570. // init title
  571. $title = __( 'Workflow', 'commentpress-core' );
  572. // allow overrides
  573. $title = apply_filters( 'cp_workflow_metabox_title', $title );
  574. // add our meta box to posts
  575. add_meta_box(
  576. 'commentpress_workflow_fields',
  577. $title,
  578. array( $this, 'custom_box_workflow' ),
  579. 'post',
  580. 'normal'
  581. );
  582. }
  583. }
  584. /**
  585. * @description: adds meta box to page edit screens
  586. * @todo:
  587. *
  588. */
  589. function custom_box_page() {
  590. // access post
  591. global $post;
  592. // Use nonce for verification
  593. wp_nonce_field( 'commentpress_page_settings', 'commentpress_nonce' );
  594. // ---------------------------------------------------------------------
  595. // Show or Hide Page Title
  596. // ---------------------------------------------------------------------
  597. // show a title
  598. echo '<p><strong><label for="cp_title_visibility">' . __( 'Page Title Visibility' , 'commentpress-core' ) . '</label></strong></p>';
  599. // set key
  600. $key = '_cp_title_visibility';
  601. // default to show
  602. $viz = $this->db->option_get( 'cp_title_visibility' );
  603. // if the custom field already has a value...
  604. if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
  605. // get it
  606. $viz = get_post_meta( $post->ID, $key, true );
  607. }
  608. // select
  609. echo '
  610. <p>
  611. <select id="cp_title_visibility" name="cp_title_visibility">
  612. <option value="show" '.(($viz == 'show') ? ' selected="selected"' : '').'>'.__('Show page title', 'commentpress-core').'</option>
  613. <option value="hide" '.(($viz == 'hide') ? ' selected="selected"' : '').'>'.__('Hide page title', 'commentpress-core').'</option>
  614. </select>
  615. </p>
  616. ';
  617. // ---------------------------------------------------------------------
  618. // Show or Hide Page Meta
  619. // ---------------------------------------------------------------------
  620. // show a label
  621. echo '<p><strong><label for="cp_page_meta_visibility">' . __( 'Page Meta Visibility' , 'commentpress-core' ) . '</label></strong></p>';
  622. // set key
  623. $key = '_cp_page_meta_visibility';
  624. // default to show
  625. $viz = $this->db->option_get( 'cp_page_meta_visibility' );
  626. // if the custom field already has a value...
  627. if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
  628. // get it
  629. $viz = get_post_meta( $post->ID, $key, true );
  630. }
  631. // select
  632. echo '
  633. <p>
  634. <select id="cp_page_meta_visibility" name="cp_page_meta_visibility">
  635. <option value="show" '.(($viz == 'show') ? ' selected="selected"' : '').'>'.__('Show page meta', 'commentpress-core').'</option>
  636. <option value="hide" '.(($viz == 'hide') ? ' selected="selected"' : '').'>'.__('Hide page meta', 'commentpress-core').'</option>
  637. </select>
  638. </p>
  639. ';
  640. // ---------------------------------------------------------------------
  641. // Page Numbering - only shown on first top level page
  642. // ---------------------------------------------------------------------
  643. //print_r( $this->nav->get_first_page() ); die();
  644. // if page has no parent and it's not a special page and it's the first...
  645. if (
  646. $post->post_parent == '0' AND
  647. !$this->db->is_special_page() AND
  648. $post->ID == $this->nav->get_first_page()
  649. ) { // -->
  650. // label
  651. echo '<p><strong><label for="cp_number_format">' . __('Page Number Format', 'commentpress-core' ) . '</label></strong></p>';
  652. // set key
  653. $key = '_cp_number_format';
  654. // default to arabic
  655. $format = 'arabic';
  656. // if the custom field already has a value...
  657. if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
  658. // get it
  659. $format = get_post_meta( $post->ID, $key, true );
  660. }
  661. //print_r( $format ); die();
  662. // select
  663. echo '
  664. <p>
  665. <select id="cp_number_format" name="cp_number_format">
  666. <option value="arabic" '.(($format == 'arabic') ? ' selected="selected"' : '').'>'.__('Arabic numerals', 'commentpress-core' ).'</option>
  667. <option value="roman" '.(($format == 'roman') ? ' selected="selected"' : '').'>'.__('Roman numerals', 'commentpress-core' ).'</option>
  668. </select>
  669. </p>
  670. ';
  671. }
  672. // ---------------------------------------------------------------------
  673. // Page Layout for Title Page -> to allow for Book Cover image
  674. // ---------------------------------------------------------------------
  675. // is this the title page?
  676. if ( $post->ID == $this->db->option_get( 'cp_welcome_page' ) ) {
  677. // label
  678. echo '<p><strong><label for="cp_page_layout">' . __('Page Layout', 'commentpress-core' ) . '</label></strong></p>';
  679. // set key
  680. $key = '_cp_page_layout';
  681. // default to text
  682. $value = 'text';
  683. // if the custom field already has a value...
  684. if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
  685. // get it
  686. $value = get_post_meta( $post->ID, $key, true );
  687. }
  688. // select
  689. echo '
  690. <p>
  691. <select id="cp_page_layout" name="cp_page_layout">
  692. <option value="text" '.(($value == 'text') ? ' selected="selected"' : '').'>'.__('Standard', 'commentpress-core' ).'</option>
  693. <option value="wide" '.(($value == 'wide') ? ' selected="selected"' : '').'>'.__('Wide', 'commentpress-core' ).'</option>
  694. </select>
  695. </p>
  696. ';
  697. }
  698. // get post formatter
  699. $this->_get_post_formatter_metabox( $post );
  700. // get default sidebar
  701. $this->_get_default_sidebar_metabox( $post );
  702. }
  703. /**
  704. * @description: adds meta box to post edit screens
  705. * @todo:
  706. *
  707. */
  708. function custom_box_post() {
  709. // access post
  710. global $post;
  711. // Use nonce for verification
  712. wp_nonce_field( 'commentpress_post_settings', 'commentpress_nonce' );
  713. // set key
  714. $key = '_cp_newer_version';
  715. // if the custom field already has a value...
  716. if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
  717. // get it
  718. $new_post_id = get_post_meta( $post->ID, $key, true );
  719. // -----------------------------------------------------------------
  720. // Show link to newer post
  721. // -----------------------------------------------------------------
  722. // define label
  723. $label = __( 'This post already has a new version', 'commentpress-core' );
  724. // get the edit post link
  725. $edit_link = get_edit_post_link( $new_post_id );
  726. // define label
  727. $link = __( 'Edit new version', 'commentpress-core' );
  728. // show link
  729. echo '
  730. <p><a href="'.$edit_link.'">'.$link.'</a></p>'."\n";
  731. } else {
  732. // -----------------------------------------------------------------
  733. // Create new post with content of current post
  734. // -----------------------------------------------------------------
  735. // label
  736. echo '<p><strong><label for="cp_page_layout">' . __('Versioning', 'commentpress-core' ) . '</label></strong></p>';
  737. // define label
  738. $label = __( 'Create new version', 'commentpress-core' );
  739. // show a title
  740. echo '
  741. <div class="checkbox">
  742. <label for="commentpress_new_post"><input type="checkbox" value="1" id="commentpress_new_post" name="commentpress_new_post" /> '.$label.'</label>
  743. </div>'."\n";
  744. }
  745. // get post formatter
  746. $this->_get_post_formatter_metabox( $post );
  747. // get default sidebar
  748. $this->_get_default_sidebar_metabox( $post );
  749. }
  750. /**
  751. * @description: adds workflow meta box to post edit screens
  752. * @todo:
  753. *
  754. */
  755. function custom_box_workflow() {
  756. // we now need to add any workflow that a plugin might want
  757. do_action( 'cp_workflow_metabox' );
  758. }
  759. /**
  760. * @description: adds help copy to admin page in WP <= 3.2
  761. * @todo:
  762. *
  763. */
  764. function contextual_help( $text ) {
  765. $text = '';
  766. $screen = isset( $_GET['page'] ) ? $_GET['page'] : '';
  767. if ($screen == 'commentpress_admin') {
  768. // get help text
  769. $text = '<h5>'.__('CommentPress Core Help', 'commentpress-core' ).'</h5>';
  770. $text .= $this->display->get_help();
  771. }
  772. // --<
  773. return $text;
  774. }
  775. /**
  776. * @description: adds help copy to admin page in WP3.3+
  777. * @todo:
  778. *
  779. */
  780. function options_help( $screen ) {
  781. //print_r( $screen ); die();
  782. // is this our screen?
  783. if ( $screen->id != $this->options_page ) {
  784. // no, kick out
  785. return;
  786. }
  787. // add a tab
  788. $screen->add_help_tab( array(
  789. 'id' => 'commentpress-base',
  790. 'title' => __('CommentPress Core Help', 'commentpress-core'),
  791. 'content' => $this->display->get_help(),
  792. ));
  793. // --<
  794. return $screen;
  795. }
  796. /**
  797. * @description: stores our additional params
  798. * @param integer $post_id the ID of the post (or revision)
  799. * @param integer $post the post object
  800. * @todo:
  801. *
  802. */
  803. function save_post( $post_id, $post ) {
  804. // we don't use post_id because we're not interested in revisions
  805. // store our meta data
  806. $result = $this->db->save_meta( $post );
  807. }
  808. /**
  809. * @description: check for data integrity of other posts when one is deleted
  810. * @param integer $post_id the ID of the post (or revision)
  811. * @param integer $post the post object
  812. * @todo:
  813. *
  814. */
  815. function delete_post( $post_id ) {
  816. // store our meta data
  817. $result = $this->db->delete_meta( $post_id );
  818. }
  819. /**
  820. * @description: stores our additional param - the text signature
  821. * @param integer $comment_ID the ID of the comment
  822. * @param integer $comment_status the status of the comment
  823. * @todo:
  824. *
  825. */
  826. function save_comment( $comment_ID, $comment_status ) {
  827. // we don't use comment_status
  828. // store our comment signature
  829. $result = $this->db->save_comment_signature( $comment_ID );
  830. // in multipage situations, store our comment's page
  831. $result = $this->db->save_comment_page( $comment_ID );
  832. }
  833. /**
  834. * @description: get table of contents
  835. * @todo:
  836. *
  837. */
  838. function get_toc() {
  839. // switch pages or posts
  840. if( $this->get_list_option() == 'post' ) {
  841. // list posts
  842. $this->display->list_posts();
  843. } else {
  844. // list pages
  845. $this->display->list_pages();
  846. }
  847. }
  848. /**
  849. * @description: get table of contents
  850. * @todo:
  851. *
  852. */
  853. function get_toc_list() {
  854. // switch pages or posts
  855. if( $this->get_list_option() == 'post' ) {
  856. // list posts
  857. $this->display->list_posts();
  858. } else {
  859. // list pages
  860. $this->display->list_pages();
  861. }
  862. }
  863. /**
  864. * @description: exclude special pages from page listings
  865. * @todo:
  866. *
  867. */
  868. function exclude_special_pages( $excluded_array ) {
  869. //print_r( $excluded_array ); die();
  870. // get special pages array, if it's there
  871. $special_pages = $this->db->option_get( 'cp_special_pages' );
  872. // do we have an array?
  873. if ( is_array( $special_pages ) ) {
  874. // merge and make unique
  875. $excluded_array = array_unique( array_merge( $excluded_array, $special_pages ) );
  876. }
  877. // --<
  878. return $excluded_array;
  879. }
  880. /**
  881. * @description: exclude special pages from admin page listings
  882. * @todo:
  883. *
  884. */
  885. function exclude_special_pages_from_admin( $query ) {
  886. //print_r( $query ); die();
  887. global $pagenow, $post_type;
  888. // check admin location
  889. if ( is_admin() AND $pagenow=='edit.php' AND $post_type =='page' ) {
  890. // get special pages array, if it's there
  891. $special_pages = $this->db->option_get( 'cp_special_pages' );
  892. // do we have an array?
  893. if ( is_array( $special_pages ) AND count( $special_pages ) > 0 ) {
  894. // modify query
  895. $query->query_vars['post__not_in'] = $special_pages;
  896. }
  897. }
  898. }
  899. /**
  900. * @description: page counts still need amending
  901. * @todo:
  902. *
  903. */
  904. function update_page_counts_in_admin( $vars ) {
  905. //print_r( $vars ); die();
  906. global $pagenow, $post_type;
  907. // check admin location
  908. if (is_admin() AND $pagenow=='edit.php' AND $post_type =='page') {
  909. // get special pages array, if it's there
  910. $special_pages = $this->db->option_get( 'cp_special_pages' );
  911. // do we have an array?
  912. if ( is_array( $special_pages ) ) {
  913. /*
  914. Data comes in like this:
  915. [all] => <a href='edit.php?post_type=page' class="current">All <span class="count">(8)</span></a>
  916. [publish] => <a href='edit.php?post_status=publish&amp;post_type=page'>Published <span class="count">(8)</span></a>
  917. */
  918. // capture existing value enclosed in brackets
  919. preg_match( '/\((\d+)\)/', $vars['all'], $matches );
  920. //print_r( $matches ); die();
  921. // did we get a result?
  922. if ( isset( $matches[1] ) ) {
  923. // subtract special page count
  924. $new_count = $matches[1] - count( $special_pages );
  925. // rebuild 'all' and 'publish' items
  926. $vars['all'] = preg_replace(
  927. '/\(\d+\)/',
  928. '('.$new_count.')',
  929. $vars['all']
  930. );
  931. }
  932. // capture existing value enclosed in brackets
  933. preg_match( '/\((\d+)\)/', $vars['publish'], $matches );
  934. //print_r( $matches ); die();
  935. // did we get a result?
  936. if ( isset( $matches[1] ) ) {
  937. // subtract special page count
  938. $new_count = $matches[1] - count( $special_pages );
  939. // rebuild 'all' and 'publish' items
  940. $vars['publish'] = preg_replace(
  941. '/\(\d+\)/',
  942. '('.$new_count.')',
  943. $vars['publish']
  944. );
  945. }
  946. }
  947. }
  948. return $vars;
  949. }
  950. /**
  951. * @description: get comments sorted by text signature and paragraph
  952. * @param integer $post_ID the ID of the post
  953. * @return array $_comments
  954. * @todo:
  955. *
  956. */
  957. function get_sorted_comments( $post_ID ) {
  958. // --<
  959. //print('in get sorted comments class commentpress');
  960. //var_dump(sizeof($this->parser->get_sorted_comments( $post_ID )));
  961. return $this->parser->get_sorted_comments( $post_ID );
  962. }
  963. /**
  964. * @description: get paragraph number for a particular text signature
  965. * @param string $text_signature the text signature
  966. * @return integer $num position in text signature array
  967. * @todo: deal with duplicates
  968. *
  969. */
  970. function get_para_num( $text_signature ) {
  971. // get position in array
  972. $num = array_search( $text_signature, $this->db->get_text_sigs() );
  973. // --<
  974. return $num + 1;
  975. }
  976. /**
  977. * @description: get text signature for a particular paragraph number
  978. * @param integer $para_num paragraph number in a post
  979. * @return string $text_signature the text signature
  980. * @todo:
  981. *
  982. */
  983. function get_text_signature( $para_num ) {
  984. // get text sigs
  985. $_sigs = $this->db->get_text_sigs();
  986. // get value at that position in array
  987. $text_sig = ( isset( $_sigs[$para_num-1] ) ) ? $_sigs[$para_num-1] : '';
  988. // --<
  989. return $text_sig;
  990. }
  991. /**
  992. * @description: get a link to a "special" page
  993. * @param string $page_type CommentPress Core name of a special page
  994. * @return string $link HTML link to that page
  995. * @todo:
  996. *
  997. */
  998. function get_page_link( $page_type = 'cp_all_comments_page' ) {
  999. // init
  1000. $link = '';
  1001. // get page ID
  1002. $_page_id = $this->db->option_get( $page_type );
  1003. // do we have a page?
  1004. if ( $_page_id != '' ) {
  1005. // get page
  1006. $_page = get_post( $_page_id );
  1007. // get link
  1008. $_url = get_permalink( $_page );
  1009. // switch title by type
  1010. switch( $page_type ) {
  1011. case 'cp_welcome_page':
  1012. $_link_title = __( 'Title Page', 'commentpress-core' );
  1013. $_button = 'cover';
  1014. break;
  1015. case 'cp_all_comments_page':
  1016. $_link_title = __( 'All Comments', 'commentpress-core' );
  1017. $_button = 'allcomments'; break;
  1018. case 'cp_general_comments_page':
  1019. $_link_title = __( 'General Comments', 'commentpress-core' );
  1020. $_button = 'general'; break;
  1021. case 'cp_blog_page':
  1022. $_link_title = __( 'Blog', 'commentpress-core' );
  1023. $_button = 'blog'; break;
  1024. case 'cp_blog_archive_page':
  1025. $_link_title = __( 'Blog Archive', 'commentpress-core' );
  1026. $_button = 'archive'; break;
  1027. case 'cp_comments_by_page':
  1028. $_link_title = __( 'Comments by Commenter', 'commentpress-core' );
  1029. $_button = 'members'; break;
  1030. default:
  1031. $_link_title = __( 'Members', 'commentpress-core' );
  1032. $_button = 'members';
  1033. }
  1034. // let plugins override titles
  1035. $_title = apply_filters( 'commentpress_page_link_title', $_link_title );
  1036. // show link
  1037. $link = '<li><a href="'.$_url.'" id="btn_'.$_button.'" class="css_btn" title="'.$_title.'">'.$_title.'</a></li>'."\n";
  1038. }
  1039. // --<
  1040. return $link;
  1041. }
  1042. /**
  1043. * @description: get a url for a "special" page
  1044. * @param string $page_type CommentPress Core name of a special page
  1045. * @return string $_url URL of that page
  1046. * @todo:
  1047. *
  1048. */
  1049. function get_page_url( $page_type = 'cp_all_comments_page' ) {
  1050. // init
  1051. $_url = '';
  1052. // get page ID
  1053. $_page_id = $this->db->option_get( $page_type );
  1054. // do we have a page?
  1055. if ( $_page_id != '' ) {
  1056. // get page
  1057. $_page = get_post( $_page_id );
  1058. // get link
  1059. $_url = get_permalink( $_page );
  1060. }
  1061. // --<
  1062. return $_url;
  1063. }
  1064. /**
  1065. * @description: get book cover
  1066. * @todo:
  1067. *
  1068. */
  1069. function get_book_cover() {
  1070. // get image SRC
  1071. $src = $this->db->option_get( 'cp_book_picture' );
  1072. // get link URL
  1073. $url = $this->db->option_get( 'cp_book_picture_link' );
  1074. // --<
  1075. return $this->display->get_linked_image( $src, $url );
  1076. }
  1077. /**
  1078. * @description: check if we are on the signup page
  1079. * @return boolean $is_signup
  1080. * @todo:
  1081. *
  1082. */
  1083. function is_signup_page() {
  1084. // init
  1085. $is_signup = false;
  1086. // if multisite
  1087. if ( is_multisite() ) {
  1088. // test script filename
  1089. if ( 'wp-signup.php' == basename($_SERVER['SCRIPT_FILENAME']) ) {
  1090. // override
  1091. $is_signup = true;
  1092. }
  1093. }
  1094. // --<
  1095. return $is_signup;
  1096. }
  1097. /**
  1098. * @description: utility to check for presence of Theme My Login
  1099. * @return boolean $success
  1100. * @todo:
  1101. *
  1102. */
  1103. function is_theme_my_login_page() {
  1104. // access page
  1105. global $post;
  1106. // compat with Theme My Login
  1107. if(
  1108. is_page() AND
  1109. !$this->db->is_special_page() AND
  1110. $post->post_name == 'login' AND
  1111. $post->post_content == '[theme-my-login]'
  1112. ) {
  1113. // --<
  1114. return true;
  1115. }
  1116. // --<
  1117. return false;
  1118. }
  1119. /**
  1120. * @description: utility to check for presence of Subscribe to Comments Reloaded
  1121. * @return boolean $success
  1122. * @todo:
  1123. *
  1124. */
  1125. function is_subscribe_to_comments_reloaded_page() {
  1126. // access page
  1127. global $post;
  1128. // compat with Subscribe to Comments Reloaded
  1129. if(
  1130. is_page() AND
  1131. !$this->db->is_special_page() AND
  1132. $post->ID == '9999999' AND
  1133. $post->guid == get_bloginfo('url').'/?page_id=9999999'
  1134. ) {
  1135. // --<
  1136. return true;
  1137. }
  1138. // --<
  1139. return false;
  1140. }
  1141. /**
  1142. * @description: return the name of the default sidebar
  1143. * @return array $settings
  1144. * @todo:
  1145. */
  1146. function get_default_sidebar() {
  1147. // set sensible default
  1148. $return = 'toc';
  1149. // is this a commentable page?
  1150. if ( !$this->is_commentable() ) {
  1151. // no - we must use either 'activity' or 'toc'
  1152. if ( $this->db->option_exists( 'cp_sidebar_default' ) ) {
  1153. // get option (we don't need to look at the page meta in this case)
  1154. $default = $this->db->option_get( 'cp_sidebar_default' );
  1155. // use it unless it's 'comments'
  1156. if ( $default != 'comments' ) { $return = $default; }
  1157. }
  1158. // --<
  1159. return $return;
  1160. }
  1161. // get CPTs
  1162. //$_types = $this->_get_commentable_cpts();
  1163. // testing what we do with CPTs...
  1164. //if ( is_singular() OR is_singular( $_types ) ) {
  1165. // is it a commentable page?
  1166. if ( is_singular() ) {
  1167. // some people have reported that db is not an object at this point -
  1168. // though I cannot figure out how this might be occurring - so we
  1169. // avoid the issue by checking if it is
  1170. if ( is_object( $this->db ) ) {
  1171. // is it a special page which have comments in page (or are not commentable)?
  1172. if ( !$this->db->is_special_page() ) {
  1173. // access page
  1174. global $post;
  1175. // is it our title page?
  1176. if ( $post->ID == $this->db->option_get( 'cp_welcome_page' ) ) {
  1177. // use 'toc', but should this be a special case?
  1178. return 'toc';
  1179. } else {
  1180. // either 'comments', 'activity' or 'toc'
  1181. if ( $this->db->option_exists( 'cp_sidebar_default' ) ) {
  1182. // get global option
  1183. $return = $this->db->option_get( 'cp_sidebar_default' );
  1184. // check if the post/page has a meta value
  1185. $key = '_cp_sidebar_default';
  1186. // if the custom field already has a value...
  1187. if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
  1188. // get it
  1189. $return = get_post_meta( $post->ID, $key, true );
  1190. }
  1191. }
  1192. // --<
  1193. return $return;
  1194. }
  1195. }
  1196. }
  1197. }
  1198. // not singular... must be either activity or toc
  1199. if ( $this->db->option_exists( 'cp_sidebar_default' ) ) {
  1200. // override
  1201. $default = $this->db->option_get( 'cp_sidebar_default' );
  1202. // use it unless it's 'comments'
  1203. if ( $default != 'comments' ) { $return = $default; }
  1204. }
  1205. // --<
  1206. return $return;
  1207. }
  1208. /**
  1209. * @description: get the order of the sidebars
  1210. * @return array sidebars in order of display
  1211. * @todo:
  1212. */
  1213. function get_sidebar_order() {
  1214. // set default but allow overrides
  1215. $order = apply_filters(
  1216. // hook name
  1217. 'cp_sidebar_tab_order',
  1218. // default order
  1219. array( 'contents', 'comments', 'activity' )
  1220. );
  1221. // --<
  1222. return $order;
  1223. }
  1224. /**
  1225. * @description: check if a page/post can be commented on
  1226. * @return boolean true if commentable, false otherwise
  1227. * @todo:
  1228. */
  1229. function is_commentable() {
  1230. // declare access to globals
  1231. global $post;
  1232. // not if we're not on a page/post and especially not if there's no post object
  1233. if ( !is_singular() OR !is_object( $post ) ) { return false; }
  1234. // CP Special Pages special pages are not
  1235. if ( $this->db->is_special_page() ) { return false; }
  1236. // BuddyPress special pages are not
  1237. if ( $this->is_buddypress_special_page() ) { return false; }
  1238. // Theme My Login page is not
  1239. if ( $this->is_theme_my_login_page() ) { return false; }
  1240. // Subscribe to Comments Reloaded page is not
  1241. if ( $this->is_subscribe_to_comments_reloaded_page() ) { return false; }
  1242. // --<
  1243. return true;
  1244. }
  1245. //##############################################################################
  1246. /*
  1247. ============================================================================
  1248. PRIVATE METHODS
  1249. ============================================================================
  1250. */
  1251. /*
  1252. ---------------------------------------------------------------
  1253. Object Initialisation
  1254. ---------------------------------------------------------------
  1255. */
  1256. /**
  1257. * @description: object initialisation
  1258. * @todo:
  1259. *
  1260. */
  1261. function _init() {
  1262. // ---------------------------------------------------------------------
  1263. // Database Object
  1264. // ---------------------------------------------------------------------
  1265. // define filename
  1266. $class_file = 'commentpress-core/class_commentpress_db.php';
  1267. // get path
  1268. $class_file_path = commentpress_file_is_present( $class_file );
  1269. // we're fine, include class definition
  1270. require_once( $class_file_path );
  1271. // init autoload database object
  1272. $this->db = new CommentpressCoreDatabase( $this );
  1273. // ---------------------------------------------------------------------
  1274. // Display Object
  1275. // ---------------------------------------------------------------------
  1276. // define filename
  1277. $class_file = 'commentpress-core/class_commentpress_display.php';
  1278. // get path
  1279. $class_file_path = commentpress_file_is_present( $class_file );
  1280. // we're fine, include class definition
  1281. require_once( $class_file_path );
  1282. // init display object
  1283. $this->display = new CommentpressCoreDisplay( $this );
  1284. // ---------------------------------------------------------------------
  1285. // Navigation Object
  1286. // ---------------------------------------------------------------------
  1287. // define filename
  1288. $class_file = 'commentpress-core/class_commentpress_nav.php';
  1289. // get path
  1290. $class_file_path = commentpress_file_is_present( $class_file );
  1291. // we're fine, include class definition
  1292. require_once( $class_file_path );
  1293. // init display object
  1294. $this->nav = new CommentpressCoreNavigator( $this );
  1295. // ---------------------------------------------------------------------
  1296. // Parser Object
  1297. // ---------------------------------------------------------------------
  1298. // define filename
  1299. $class_file = 'commentpress-core/class_commentpress_parser.php';
  1300. // get path
  1301. $class_file_path = commentpress_file_is_present( $class_file );
  1302. // we're fine, include class definition
  1303. require_once( $class_file_path );
  1304. // init parser object
  1305. $this->parser = new CommentpressCoreParser( $this );
  1306. // ---------------------------------------------------------------------
  1307. // Formatter Object
  1308. // ---------------------------------------------------------------------
  1309. // define filename
  1310. $class_file = 'commentpress-core/class_commentpress_formatter.php';
  1311. // get path
  1312. $class_file_path = commentpress_file_is_present( $class_file );
  1313. // allow plugins to override this and supply their own
  1314. $class_file_path = apply_filters(
  1315. 'cp_class_commentpress_formatter',
  1316. $class_file_path
  1317. );
  1318. // we're fine, include class definition
  1319. require_once( $class_file_path );
  1320. // init formatter object
  1321. $this->formatter = new CommentpressCoreFormatter( $this );
  1322. // ---------------------------------------------------------------------
  1323. // Workflow Object
  1324. // ---------------------------------------------------------------------
  1325. // define filename
  1326. $class_file = 'commentpress-core/class_commentpress_workflow.php';
  1327. // get path
  1328. $class_file_path = commentpress_file_is_present( $class_file );
  1329. // allow plugins to override this and supply their own
  1330. $class_file_path = apply_filters(
  1331. 'cp_class_commentpress_workflow',
  1332. $class_file_path
  1333. );
  1334. // we're fine, include class definition
  1335. require_once( $class_file_path );
  1336. // init workflow object
  1337. $this->workflow = new CommentpressCoreWorkflow( $this );
  1338. // register hooks
  1339. $this->_register_hooks();
  1340. }
  1341. /**
  1342. * @description: register Wordpress hooks
  1343. * @todo:
  1344. *
  1345. */
  1346. function _register_hooks() {
  1347. // access version
  1348. global $wp_version;
  1349. // use translation
  1350. add_action( 'plugins_loaded', array( $this, 'translation' ) );
  1351. // check for plugin deactivation
  1352. add_action( 'deactivated_plugin', array( $this, '_plugin_deactivated' ), 10, 2 );
  1353. // modify comment posting
  1354. add_action( 'comment_post', array( $this, 'save_comment' ), 10, 2 );
  1355. // exclude special pages from listings
  1356. add_filter( 'wp_list_pages_excludes', array( $this, 'exclude_special_pages' ), 10, 1 );
  1357. add_filter( 'parse_query', array( $this, 'exclude_special_pages_from_admin' ), 10, 1 );
  1358. // is this the back end?
  1359. if ( is_admin() ) {
  1360. // modify all
  1361. add_filter( 'views_edit-page', array( $this, 'update_page_counts_in_admin' ), 10, 1 );
  1362. // modify admin menu
  1363. add_action( 'admin_menu', array( $this, 'admin_menu' ) );
  1364. // add meta boxes
  1365. add_action( 'add_meta_boxes' , array( $this, 'add_meta_boxes' ) );
  1366. // intercept save
  1367. add_action( 'save_post', array( $this, 'save_post' ), 10, 2 );
  1368. // intercept delete
  1369. add_action( 'before_delete_post', array( $this, 'delete_post' ), 10, 1 );
  1370. // there's a new screen object in 3.3
  1371. if ( version_compare( $wp_version, '3.2.99999', '>=' ) ) {
  1372. // use new help functionality
  1373. //add_action('add_screen_help_and_options', array( $this, 'options_help' ) );
  1374. // NOTE: help is actually called in $this->admin_head() because the
  1375. // 'add_screen_help_and_options' action does not seem to be working in 3.3-beta1
  1376. } else {
  1377. // previous help method
  1378. add_action( 'contextual_help', array( $this, 'contextual_help' ) );
  1379. }
  1380. // comment block quicktag
  1381. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
  1382. } else {
  1383. // modify the document head
  1384. add_filter( 'wp_head', array( $this, 'head' ) );
  1385. // add script libraries
  1386. add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
  1387. // add CSS files
  1388. add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
  1389. // add template redirect for TOC behaviour
  1390. add_action( 'template_redirect', array( $this, 'redirect_to_child' ) );
  1391. // modify the content (after all's done)
  1392. add_filter( 'the_content', array( $this, 'the_content' ), 20 );
  1393. }
  1394. // if we're in a multisite scenario
  1395. if ( is_multisite() ) {
  1396. // add filter for signup page to include sidebar
  1397. add_filter( 'after_signup_form', array( $this, 'after_signup_form' ) );
  1398. // if subdirectory install
  1399. if ( !is_subdomain_install() ) {
  1400. // add filter for reserved commentpress special page names
  1401. add_filter( 'subdirectory_reserved_names', array( $this, 'add_reserved_names' ) );
  1402. }
  1403. }
  1404. // if BP installed, then the following actions will fire...
  1405. // enable BuddyPress functionality
  1406. add_action( 'bp_include', array( $this, 'buddypress_init' ) );
  1407. // add BuddyPress functionality (really late, so group object is set up)
  1408. add_action( 'bp_setup_globals', array( $this, 'buddypress_globals_loaded' ), 1000 );
  1409. }
  1410. /**
  1411. * @description: utility to check for commentable CPT
  1412. * @return string $types array of post types
  1413. * @todo: in development
  1414. *
  1415. */
  1416. function _get_commentable_cpts() {
  1417. // init
  1418. $_types = false;
  1419. // NOTE: exactly how do we support CPTs?
  1420. $args = array(
  1421. //'public' => true,
  1422. '_builtin' => false
  1423. );
  1424. $output = 'names'; // names or objects, note names is the default
  1425. $operator = 'and'; // 'and' or 'or'
  1426. // get post types
  1427. $post_types = get_post_types( $args, $output, $operator );
  1428. // trace
  1429. //print_r( $post_types ); die();
  1430. // did we get any?
  1431. if ( count( $post_types ) > 0 ) {
  1432. // init as array
  1433. $_types = false;
  1434. // loop
  1435. foreach ($post_types AS $post_type ) {
  1436. // add name to array (is_singular expects this)
  1437. $_types[] = $post_type;
  1438. }
  1439. }
  1440. // trace
  1441. //print_r( $_types ); die();
  1442. // --<
  1443. return $_types;
  1444. }
  1445. /**
  1446. * @description: adds the formatter to the page/post metabox
  1447. * @todo:
  1448. *
  1449. */
  1450. function _get_post_formatter_metabox( $post ) {
  1451. // ---------------------------------------------------------------------
  1452. // Override post formatter
  1453. // ---------------------------------------------------------------------
  1454. // do we have the option to choose blog type (new in 3.3.1)?
  1455. if ( $this->db->option_exists( 'cp_blog_type' ) ) {
  1456. // define no types
  1457. $types = array();
  1458. // allow overrides
  1459. $types = apply_filters( 'cp_blog_type_options', $types );
  1460. // if we get some from a plugin, say...
  1461. if ( !empty( $types ) ) {
  1462. // define title
  1463. $type_title = __( 'Text Formatting', 'commentpress-core' );
  1464. // allow overrides
  1465. $type_title = apply_filters( 'cp_post_type_override_label', $type_title );
  1466. // label
  1467. echo '<p><strong><label for="cp_post_type_override">'.$type_title.'</label></strong></p>';
  1468. // construct options
  1469. $type_option_list = array();
  1470. $n = 0;
  1471. // set key
  1472. $key = '_cp_post_type_override';
  1473. // default to current blog type
  1474. $value = $this->db->option_get( 'cp_blog_type' );
  1475. // but, if the custom field has a value...
  1476. if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
  1477. // get it
  1478. $value = get_post_meta( $post->ID, $key, true );
  1479. }
  1480. foreach( $types AS $type ) {
  1481. if ( $n == $value ) {
  1482. $type_option_list[] = '<option value="'.$n.'" selected="selected">'.$type.'</option>';
  1483. } else {
  1484. $type_option_list[] = '<option value="'.$n.'">'.$type.'</option>';
  1485. }
  1486. $n++;
  1487. }
  1488. $type_options = implode( "\n", $type_option_list );
  1489. // select
  1490. echo '
  1491. <p>
  1492. <select id="cp_post_type_override" name="cp_post_type_override">
  1493. '.$type_options.'
  1494. </select>
  1495. </p>
  1496. ';
  1497. }
  1498. }
  1499. }
  1500. /**
  1501. * @description: adds the default sidebar preference to the page/post metabox
  1502. * @todo:
  1503. *
  1504. */
  1505. function _get_default_sidebar_metabox( $post ) {
  1506. // ---------------------------------------------------------------------
  1507. // Override post formatter
  1508. // ---------------------------------------------------------------------
  1509. // do we have the option to choose the default sidebar (new in 3.3.3)?
  1510. if ( $this->db->option_exists( 'cp_sidebar_default' ) ) {
  1511. // show a title
  1512. echo '<p><strong><label for="cp_sidebar_default">' . __( 'Default Sidebar' , 'commentpress-core' ) . '</label></strong></p>';
  1513. // set key
  1514. $key = '_cp_sidebar_default';
  1515. // default to show
  1516. $_sidebar = $this->db->option_get( 'cp_sidebar_default' );
  1517. // if the custom field already has a value...
  1518. if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
  1519. // get it
  1520. $_sidebar = get_post_meta( $post->ID, $key, true );
  1521. }
  1522. // select
  1523. echo '
  1524. <p>
  1525. <select id="cp_sidebar_default" name="cp_sidebar_default">
  1526. <option value="toc" '.(($_sidebar == 'toc') ? ' selected="selected"' : '').'>'.__('Contents', 'commentpress-core').'</option>
  1527. <option value="activity" '.(($_sidebar == 'activity') ? ' selected="selected"' : '').'>'.__('Activity', 'commentpress-core').'</option>
  1528. <option value="comments" '.(($_sidebar == 'comments') ? ' selected="selected"' : '').'>'.__('Comments', 'commentpress-core').'</option>
  1529. </select>
  1530. </p>
  1531. ';
  1532. }
  1533. }
  1534. /**
  1535. * @description: deactivate this plugin
  1536. * @todo:
  1537. *
  1538. */
  1539. function _plugin_deactivated( $plugin, $network_wide = null ) {
  1540. // is it the old Commentpress plugin still active?
  1541. if ( defined( 'CP_PLUGIN_FILE' ) ) {
  1542. // is it the old Commentpress plugin being deactivated?
  1543. if ( $plugin == plugin_basename( CP_PLUGIN_FILE ) ) {
  1544. //print_r( array( $plugin, $network_wide ) …

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