PageRenderTime 75ms CodeModel.GetById 42ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/DigitalPaulScholtenProject/DPSP-Platform
PHP | 2343 lines | 782 code | 892 blank | 669 comment | 114 complexity | c923b991ff701fb260b706afd81d65d8 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 CommentpressMultisiteBuddypress
  4. ================================================================================
  5. AUTHOR: Christian Wach <needle@haystack.co.uk>
  6. --------------------------------------------------------------------------------
  7. NOTES
  8. =====
  9. This class encapsulates all BuddyPress compatibility
  10. --------------------------------------------------------------------------------
  11. */
  12. /*
  13. ================================================================================
  14. Class Name
  15. ================================================================================
  16. */
  17. class CommentpressMultisiteBuddypress {
  18. /*
  19. ============================================================================
  20. Properties
  21. ============================================================================
  22. */
  23. // parent object reference
  24. var $parent_obj;
  25. // admin object reference
  26. var $db;
  27. // BP: CommentPress Core enabled on all groupblogs, default is "false"
  28. var $cpmu_bp_force_commentpress = '0';
  29. // BP: default theme stylesheet for groupblogs (WP3.4+)
  30. var $cpmu_bp_groupblog_theme = 'commentpress-theme';
  31. // BP: default theme name for groupblogs (pre-WP3.4)
  32. var $cpmu_bp_groupblog_theme_name = 'CommentPress Default Theme';
  33. // BP: make groupblogs private by default
  34. var $cpmu_bp_groupblog_privacy = 1;
  35. // anon comments on groupblogs (commenters must be logged in and members)
  36. var $cpmu_bp_require_comment_registration = 1;
  37. /**
  38. * @description: initialises this object
  39. * @param object $parent_obj a reference to the parent object
  40. * @return object
  41. * @todo:
  42. *
  43. */
  44. function __construct( $parent_obj = null ) {
  45. // store reference to "parent" (calling obj, not OOP parent)
  46. $this->parent_obj = $parent_obj;
  47. // store reference to database wrapper (child of calling obj)
  48. $this->db = $this->parent_obj->db;
  49. // init
  50. $this->_init();
  51. // --<
  52. return $this;
  53. }
  54. /**
  55. * PHP 4 constructor
  56. */
  57. function CommentpressMultisiteBuddypress( $parent_obj = null ) {
  58. // is this php5?
  59. if ( version_compare( PHP_VERSION, "5.0.0", "<" ) ) {
  60. // call php5 constructor
  61. $this->__construct( $parent_obj );
  62. }
  63. // --<
  64. return $this;
  65. }
  66. /**
  67. * @description: set up all items associated with this object
  68. * @todo:
  69. *
  70. */
  71. function initialise() {
  72. }
  73. /**
  74. * @description: if needed, destroys all items associated with this object
  75. * @todo:
  76. *
  77. */
  78. function destroy() {
  79. }
  80. //##############################################################################
  81. /*
  82. ============================================================================
  83. PUBLIC METHODS
  84. ============================================================================
  85. */
  86. /*
  87. ----------------------------------------------------------------------------
  88. BuddyPress Compatibility
  89. ----------------------------------------------------------------------------
  90. */
  91. /**
  92. * @description: enqueue any styles and scripts needed by our public page
  93. * @todo:
  94. *
  95. */
  96. function add_frontend_styles() {
  97. /*
  98. // EXAMPLES:
  99. // add css
  100. wp_enqueue_style('cpbp-admin-style', CPBP_PLUGIN_URL . 'assets/css/admin.css');
  101. // add javascripts
  102. wp_enqueue_script( 'cpbp-admin-js', CPBP_PLUGIN_URL . 'assets/js/admin.js' );
  103. */
  104. // dequeue BP Tempate Pack CSS, even if queued
  105. wp_dequeue_style( 'bp' );
  106. }
  107. /*
  108. ----------------------------------------------------------------------------
  109. BP Groupblog Compatibility
  110. ----------------------------------------------------------------------------
  111. */
  112. /**
  113. * Allow HTML comments and content in Multisite blogs
  114. */
  115. function allow_html_content() {
  116. // using publish_posts for now - means author+
  117. if ( current_user_can( 'publish_posts' ) ) {
  118. // remove html filtering on content. Note - this has possible consequences...
  119. // see: http://wordpress.org/extend/plugins/unfiltered-mu/
  120. kses_remove_filters();
  121. }
  122. }
  123. /**
  124. * Allow HTML in Activity items
  125. */
  126. function activity_allowed_tags( $activity_allowedtags ) {
  127. // pretty pointless not to allow p tags when we encourage the use of TinyMCE!
  128. $activity_allowedtags['p'] = array();
  129. // --<
  130. return $activity_allowedtags;
  131. }
  132. /**
  133. * @description: add capability to edit own comments
  134. * @todo:
  135. * @see: http://scribu.net/wordpress/prevent-blog-authors-from-editing-comments.html
  136. */
  137. function enable_comment_editing( $caps, $cap, $user_id, $args ) {
  138. // only apply this to queries for edit_comment cap
  139. if ( 'edit_comment' == $cap ) {
  140. // get comment
  141. $comment = get_comment( $args[0] );
  142. //print_r( array( 'comment' => $comment, 'user' => $user_id ) ); die();
  143. //print_r( array( 'caps' => $caps, 'cap' => $cap ) ); die();
  144. // is the user the same as the comment author?
  145. if ( $comment->user_id == $user_id ) {
  146. //$caps[] = 'moderate_comments';
  147. $caps = array('edit_posts');
  148. }
  149. }
  150. // --<
  151. return $caps;
  152. }
  153. /**
  154. * @description: override capability to comment based on group membership.
  155. * @todo:
  156. *
  157. */
  158. function pre_comment_approved( $approved, $commentdata ) {
  159. //print_r( $commentdata ); die();
  160. global $wpdb;
  161. $blog_id = (int)$wpdb->blogid;
  162. // do we have groupblogs?
  163. if ( function_exists( 'get_groupblog_group_id' ) ) {
  164. // check if this blog is a group blog...
  165. $group_id = get_groupblog_group_id( $blog_id );
  166. }
  167. // when this blog is a groupblog
  168. if ( isset( $group_id ) AND is_numeric( $group_id ) ) {
  169. // is this user a member?
  170. if ( groups_is_user_member( $commentdata['user_id'], $group_id ) ) {
  171. // allow un-moderated commenting
  172. return 1;
  173. }
  174. }
  175. // pass through
  176. return $approved;
  177. }
  178. /*
  179. // a nicer way?
  180. add_action( 'preprocess_comment', 'my_check_comment', 1 );
  181. function my_check_comment( $commentdata ) {
  182. // Get the user ID of the comment author.
  183. $user_id = absint( $commentdata['user_ID'] );
  184. // If comment author is a registered user, approve the comment.
  185. if ( 0 < $user_id )
  186. add_filter( 'pre_comment_approved', 'my_approve_comment' );
  187. else
  188. add_filter( 'pre_comment_approved', 'my_moderate_comment' );
  189. return $commentdata;
  190. }
  191. function my_approve_comment( $approved ) {
  192. $approved = 1;
  193. return $approved;
  194. }
  195. function my_moderate_comment( $approved ) {
  196. if ( 'spam' !== $approved )
  197. $approved = 0;
  198. return $approved;
  199. }
  200. */
  201. /**
  202. * @description: override "publicness" of groupblogs so that we can set the hide_sitewide
  203. * property of the activity item (post or comment) depending on the group's setting.
  204. * @todo: test if they are CP-enabled?
  205. *
  206. */
  207. function is_blog_public( $blog_public_option ) {
  208. global $wpdb;
  209. $blog_id = (int)$wpdb->blogid;
  210. // do we have groupblogs?
  211. if ( function_exists( 'get_groupblog_group_id' ) ) {
  212. // check if this blog is a group blog...
  213. $group_id = get_groupblog_group_id( $blog_id );
  214. }
  215. // when this blog is a groupblog
  216. if ( isset( $group_id ) AND is_numeric( $group_id ) ) {
  217. // always true - so that activities are registered
  218. return 1;
  219. } else {
  220. return $blog_public_option;
  221. }
  222. }
  223. /**
  224. * groupblog_set_group_to_post_activity ( $activity )
  225. *
  226. * Record the blog activity for the group - amended from bp_groupblog_set_group_to_post_activity
  227. */
  228. function groupblog_custom_comment_activity( $activity ) {
  229. //print_r( array( 'a1' => $activity ) );// die();
  230. // only deal with comments
  231. if ( ( $activity->type != 'new_blog_comment' ) ) return;
  232. // only do this on CP-enabled groupblogs
  233. if ( ( false === $this->_is_commentpress_groupblog() ) ) return;
  234. // get the group
  235. $blog_id = $activity->item_id;
  236. $group_id = get_groupblog_group_id( $blog_id );
  237. if ( !$group_id ) return;
  238. $group = groups_get_group( array( 'group_id' => $group_id ) );
  239. //print_r( $group ); die();
  240. // see if we already have the modified activity for this blog post
  241. $id = bp_activity_get_activity_id( array(
  242. 'user_id' => $activity->user_id,
  243. 'type' => 'new_groupblog_comment',
  244. 'item_id' => $group_id,
  245. 'secondary_item_id' => $activity->secondary_item_id
  246. ) );
  247. // if we don't find a modified item...
  248. if ( !$id ) {
  249. // see if we have an unmodified activity item
  250. $id = bp_activity_get_activity_id( array(
  251. 'user_id' => $activity->user_id,
  252. 'type' => $activity->type,
  253. 'item_id' => $activity->item_id,
  254. 'secondary_item_id' => $activity->secondary_item_id
  255. ) );
  256. }
  257. // If we found an activity for this blog comment then overwrite that to avoid having
  258. // multiple activities for every blog comment edit
  259. if ( $id ) $activity->id = $id;
  260. // get the comment
  261. $comment = get_comment( $activity->secondary_item_id );
  262. //print_r( $comment ); //die();
  263. // get the post
  264. $post = get_post( $comment->comment_post_ID );
  265. //print_r( $post ); die();
  266. // was it a registered user?
  267. if ($comment->user_id != '0') {
  268. // get user details
  269. $user = get_userdata( $comment->user_id );
  270. // construct user link
  271. $user_link = bp_core_get_userlink( $activity->user_id );
  272. } else {
  273. // show anonymous user
  274. $user_link = '<span class="anon-commenter">'.__( 'Anonymous', 'commentpress-core' ).'</span>';
  275. }
  276. // allow plugins to override the name of the activity item
  277. $activity_name = apply_filters(
  278. 'cp_activity_post_name',
  279. __( 'post', 'commentpress-core' )
  280. );
  281. // set key
  282. $key = '_cp_comment_page';
  283. // if the custom field has a value, we have a subpage comment...
  284. if ( get_comment_meta( $comment->comment_ID, $key, true ) != '' ) {
  285. // get comment's page from meta
  286. $page_num = get_comment_meta( $comment->comment_ID, $key, true );
  287. // get the url for the comment
  288. $link = commentpress_get_post_multipage_url( $page_num ).'#comment-'.$comment->comment_ID;
  289. // amend the primary link
  290. $activity->primary_link = $link;
  291. // init target link
  292. $target_post_link = '<a href="' . commentpress_get_post_multipage_url( $page_num, $post ) .'">' . esc_html( $post->post_title ) . '</a>';
  293. } else {
  294. // init target link
  295. $target_post_link = '<a href="' . get_permalink( $post->ID ) .'">' . esc_html( $post->post_title ) . '</a>';
  296. }
  297. // Replace the necessary values to display in group activity stream
  298. $activity->action = sprintf(
  299. __( '%s left a %s on a %s %s in the group %s:', 'commentpress-core' ),
  300. $user_link,
  301. '<a href="' . $activity->primary_link .'">' . __( 'comment', 'commentpress-core' ) . '</a>',
  302. $activity_name,
  303. $target_post_link,
  304. '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_html( $group->name ) . '</a>'
  305. );
  306. // apply group id
  307. $activity->item_id = (int)$group_id;
  308. // change to groups component
  309. $activity->component = 'groups';
  310. // having marked all groupblogs as public, we need to hide activity from them if the group is private
  311. // or hidden, so they don't show up in sitewide activity feeds.
  312. if ( 'public' != $group->status ) {
  313. $activity->hide_sitewide = true;
  314. } else {
  315. $activity->hide_sitewide = false;
  316. }
  317. // set unique type
  318. $activity->type = 'new_groupblog_comment';
  319. // note: BP seemingly runs content through wp_filter_kses (sad face)
  320. // prevent from firing again
  321. remove_action( 'bp_activity_before_save', array( $this, 'groupblog_custom_comment_activity' ) );
  322. // --<
  323. return $activity;
  324. }
  325. /**
  326. * @description: add some meta for the activity item - bp_activity_after_save doesn't seem to fire
  327. * @todo:
  328. *
  329. */
  330. function groupblog_custom_comment_meta( $activity ) {
  331. print_r( array( 'a' => $activity ) );
  332. // only deal with comments
  333. if ( ( $activity->type != 'new_groupblog_comment' ) ) return;
  334. // only do this on CP-enabled groupblogs
  335. if ( ( false === $this->_is_commentpress_groupblog() ) ) return;
  336. // set a meta value for the blog type of the post
  337. $meta_value = $this->_get_groupblog_type();
  338. print_r( array( 'a' => $activity ) );
  339. print_r( array( 'm' => $meta_value ) );
  340. $result = bp_activity_update_meta( $activity->id, 'groupblogtype', 'groupblogtype-'.$meta_value );
  341. print_r( array( 'r' => ( ( $result === true ) ? 't' : 'f' ) ) ); die();
  342. // prevent from firing again
  343. remove_action( 'bp_activity_after_save', array( $this, 'groupblog_custom_comment_meta' ) );
  344. // --<
  345. return $activity;
  346. }
  347. /**
  348. * see: bp_groupblog_set_group_to_post_activity ( $activity )
  349. *
  350. * Record the blog post activity for the group - by Luiz Armesto
  351. */
  352. function groupblog_custom_post_activity( $activity ) {
  353. // only on new blog posts
  354. if ( ( $activity->type != 'new_blog_post' ) ) return;
  355. // only on CP-enabled groupblogs
  356. if ( ( false === $this->_is_commentpress_groupblog() ) ) return;
  357. //print_r( array( 'a1' => $activity ) ); //die();
  358. // clarify data
  359. $blog_id = $activity->item_id;
  360. $post_id = $activity->secondary_item_id;
  361. $post = get_post( $post_id );
  362. // get group id
  363. $group_id = get_groupblog_group_id( $blog_id );
  364. if ( !$group_id ) return;
  365. // get group
  366. $group = groups_get_group( array( 'group_id' => $group_id ) );
  367. // see if we already have the modified activity for this blog post
  368. $id = bp_activity_get_activity_id( array(
  369. 'user_id' => $activity->user_id,
  370. 'type' => 'new_groupblog_post',
  371. 'item_id' => $group_id,
  372. 'secondary_item_id' => $activity->secondary_item_id
  373. ) );
  374. // if we don't find a modified item...
  375. if ( !$id ) {
  376. // see if we have an unmodified activity item
  377. $id = bp_activity_get_activity_id( array(
  378. 'user_id' => $activity->user_id,
  379. 'type' => $activity->type,
  380. 'item_id' => $activity->item_id,
  381. 'secondary_item_id' => $activity->secondary_item_id
  382. ) );
  383. }
  384. // If we found an activity for this blog post then overwrite that to avoid
  385. // having multiple activities for every blog post edit
  386. if ( $id ) {
  387. $activity->id = $id;
  388. }
  389. // allow plugins to override the name of the activity item
  390. $activity_name = apply_filters(
  391. 'cp_activity_post_name',
  392. __( 'post', 'commentpress-core' )
  393. );
  394. // default to standard BP author
  395. $activity_author = bp_core_get_userlink( $post->post_author );
  396. // compat with Co-Authors Plus
  397. if ( function_exists( 'get_coauthors' ) ) {
  398. // get multiple authors
  399. $authors = get_coauthors();
  400. //print_r( $authors ); die();
  401. // if we get some
  402. if ( !empty( $authors ) ) {
  403. // we only want to override if we have more than one...
  404. if ( count( $authors ) > 1 ) {
  405. // use the Co-Authors format of "name, name, name and name"
  406. $activity_author = '';
  407. // init counter
  408. $n = 1;
  409. // find out how many author we have
  410. $author_count = count( $authors );
  411. // loop
  412. foreach( $authors AS $author ) {
  413. // default to comma
  414. $sep = ', ';
  415. // if we're on the penultimate
  416. if ( $n == ($author_count - 1) ) {
  417. // use ampersand
  418. $sep = __( ' &amp; ', 'commentpress-core' );
  419. }
  420. // if we're on the last, don't add
  421. if ( $n == $author_count ) { $sep = ''; }
  422. // add name
  423. $activity_author .= bp_core_get_userlink( $author->ID );
  424. // and separator
  425. $activity_author .= $sep;
  426. // increment
  427. $n++;
  428. }
  429. }
  430. }
  431. }
  432. // if we're replacing an item, show different message...
  433. if ( $id ) {
  434. // replace the necessary values to display in group activity stream
  435. $activity->action = sprintf(
  436. __( '%s updated a %s %s in the group %s:', 'commentpress-core' ),
  437. $activity_author,
  438. $activity_name,
  439. '<a href="' . get_permalink( $post->ID ) .'">' . esc_attr( $post->post_title ) . '</a>',
  440. '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>'
  441. );
  442. } else {
  443. // replace the necessary values to display in group activity stream
  444. $activity->action = sprintf(
  445. __( '%s wrote a new %s %s in the group %s:', 'commentpress-core' ),
  446. $activity_author,
  447. $activity_name,
  448. '<a href="' . get_permalink( $post->ID ) .'">' . esc_attr( $post->post_title ) . '</a>',
  449. '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>'
  450. );
  451. }
  452. $activity->item_id = (int)$group_id;
  453. $activity->component = 'groups';
  454. // having marked all groupblogs as public, we need to hide activity from them if the group is private
  455. // or hidden, so they don't show up in sitewide activity feeds.
  456. if ( 'public' != $group->status ) {
  457. $activity->hide_sitewide = true;
  458. } else {
  459. $activity->hide_sitewide = false;
  460. }
  461. // CMW: assume groupblog_post is intended
  462. $activity->type = 'new_groupblog_post';
  463. //print_r( array( 'a2' => $activity ) ); die();
  464. // prevent from firing again
  465. remove_action( 'bp_activity_before_save', array( $this, 'groupblog_custom_post_activity' ) );
  466. // --<
  467. return $activity;
  468. }
  469. /**
  470. * @description: add some meta for the activity item
  471. * @todo:
  472. *
  473. */
  474. function groupblog_custom_post_meta( $activity ) {
  475. // only on new blog posts
  476. if ( ( $activity->type != 'new_groupblog_post' ) ) return;
  477. // only on CP-enabled groupblogs
  478. if ( ( false === $this->_is_commentpress_groupblog() ) ) return;
  479. // set a meta value for the blog type of the post
  480. $meta_value = $this->_get_groupblog_type();
  481. bp_activity_update_meta( $activity->id, 'groupblogtype', 'groupblogtype-'.$meta_value );
  482. // --<
  483. return $activity;
  484. }
  485. /**
  486. * Add a filter option to the filter select box on group activity pages.
  487. */
  488. function groupblog_comments_filter_option() {
  489. // default name
  490. $comment_name = __( 'CommentPress Comments', 'commentpress-core' );
  491. // allow plugins to override the name of the option
  492. $comment_name = apply_filters( 'cp_groupblog_comment_name', $comment_name );
  493. // construct option
  494. $option = '<option value="new_groupblog_comment">'.$comment_name.'</option>'."\n";
  495. // print
  496. echo $option;
  497. }
  498. /**
  499. * @description: override the name of the filter item
  500. * @todo:
  501. *
  502. */
  503. function groupblog_posts_filter_option( $slug ) {
  504. // default name
  505. $_name = __( 'CommentPress Posts', 'commentpress-core' );
  506. // allow plugins to override the name of the option
  507. $_name = apply_filters( 'cp_groupblog_post_name', $_name );
  508. // construct option
  509. $option = '<option value="new_groupblog_post">'.$_name.'</option>'."\n";
  510. // print
  511. echo $option;
  512. }
  513. /**
  514. * @description: for group blogs, override the avatar with that of the group
  515. * @todo:
  516. *
  517. */
  518. function get_blog_avatar( $avatar, $blog_id = '', $args ){
  519. // did we get anything?
  520. //print_r( $blog_id ); die();
  521. // do we have groupblogs?
  522. if ( function_exists( 'get_groupblog_group_id' ) ) {
  523. // get the group id
  524. $group_id = get_groupblog_group_id( $blog_id );
  525. }
  526. // did we get a group for which this is the group blog?
  527. if ( isset( $group_id ) ) {
  528. // --<
  529. return bp_core_fetch_avatar( array( 'item_id' => $group_id, 'object' => 'group' ) );
  530. } else {
  531. // --<
  532. return $avatar;
  533. }
  534. }
  535. /**
  536. * @description: override the name of the sub-nav item
  537. * @todo:
  538. *
  539. */
  540. function filter_blog_name( $name ) {
  541. // get group blogtype
  542. $groupblog_type = groups_get_groupmeta( bp_get_current_group_id(), 'groupblogtype' );
  543. // did we get one?
  544. if ( $groupblog_type ) {
  545. // yes, it's a CommentPress Core-enabled groupblog
  546. return apply_filters(
  547. 'cpmu_bp_groupblog_subnav_item_name',
  548. __( 'Document', 'commentpress-core' )
  549. );
  550. }
  551. // --<
  552. return $name;
  553. }
  554. /**
  555. * @description: override the slug of the sub-nav item
  556. * @todo:
  557. *
  558. */
  559. function filter_blog_slug( $slug ) {
  560. // get group blogtype
  561. $groupblog_type = groups_get_groupmeta( bp_get_current_group_id(), 'groupblogtype' );
  562. // did we get one?
  563. if ( $groupblog_type ) {
  564. // yes, it's a CommentPress Core-enabled groupblog
  565. return apply_filters(
  566. 'cpmu_bp_groupblog_subnav_item_slug',
  567. 'document'
  568. );
  569. }
  570. // --<
  571. return $slug;
  572. }
  573. /**
  574. * @description: override CommentPress "Title Page"
  575. * @todo:
  576. *
  577. */
  578. function filter_nav_title_page_title( $title ) {
  579. // --<
  580. return __( 'Document Home Page', 'cpmsextras' );
  581. }
  582. /**
  583. * @description: remove group blogs from blog list
  584. * @todo:
  585. *
  586. */
  587. function remove_groupblog_from_loop( $b, $blogs ) {
  588. //print_r( array( 'b' => $b, 'blogs' => $blogs ) ); die();
  589. // loop through them
  590. foreach ( $blogs->blogs as $key => $blog ) {
  591. // exclude if it's a group blog
  592. if ( function_exists( 'groupblog_group_id' ) ) {
  593. // get group id
  594. $group_id = get_groupblog_group_id( $blog->blog_id );
  595. //print_r( array( 'g' => $group_id ) );
  596. // did we get one?
  597. if ( is_numeric( $group_id ) ) {
  598. // exclude
  599. unset( $blogs->blogs[$key] );
  600. // recalculate global values
  601. $blogs->blog_count = $blogs->blog_count - 1;
  602. $blogs->total_blog_count = $blogs->total_blog_count - 1;
  603. $blogs->pag_num = $blogs->pag_num - 1;
  604. }
  605. }
  606. }
  607. //die();
  608. //print_r( array( 'b' => $b, 'blogs' => $blogs ) ); die();
  609. /* Renumber the array keys to account for missing items */
  610. $blogs_new = array_values( $blogs->blogs );
  611. $blogs->blogs = $blogs_new;
  612. return $blogs;
  613. }
  614. /**
  615. * @description: override the name of the button on the BP "blogs" screen
  616. * @todo:
  617. *
  618. */
  619. function get_blogs_visit_blog_button( $button ) {
  620. /*
  621. [id] => visit_blog
  622. [component] => blogs
  623. [must_be_logged_in] =>
  624. [block_self] =>
  625. [wrapper_class] => blog-button visit
  626. [link_href] => http://domain/site-slug/
  627. [link_class] => blog-button visit
  628. [link_text] => Visit Site
  629. [link_title] => Visit Site
  630. */
  631. //print_r( $button ); die();
  632. // init
  633. $blogtype = 'blog';
  634. // access global
  635. global $blogs_template;
  636. // do we have groupblogs enabled?
  637. if ( function_exists( 'get_groupblog_group_id' ) ) {
  638. // get group id
  639. $group_id = get_groupblog_group_id( $blogs_template->blog->blog_id );
  640. // yes, is this blog a groupblog?
  641. if ( is_numeric( $group_id ) ) {
  642. // is it CommentPress Core-enabled?
  643. // get group blogtype
  644. $groupblog_type = groups_get_groupmeta( $group_id, 'groupblogtype' );
  645. // did we get one?
  646. if ( $groupblog_type ) {
  647. // yes
  648. $blogtype = 'commentpress-groupblog';
  649. } else {
  650. // standard groupblog
  651. $blogtype = 'groupblog';
  652. }
  653. }
  654. } else {
  655. // TODO: is this blog CommentPress Core-enabled?
  656. // we cannot do this without switch_to_blog at the moment...
  657. $blogtype = 'blog';
  658. }
  659. // switch by blogtype
  660. switch ( $blogtype ) {
  661. // standard sub-site
  662. case 'blog':
  663. $label = __( 'View Site', 'commentpress-core' );
  664. $button['link_text'] = $label;
  665. $button['link_title'] = $label;
  666. break;
  667. // CommentPress sub-site
  668. case 'commentpress':
  669. $label = __( 'View Document', 'commentpress-core' );
  670. $button['link_text'] = apply_filters( 'cp_get_blogs_visit_blog_button', $label );
  671. $button['link_title'] = apply_filters( 'cp_get_blogs_visit_blog_button', $label );
  672. break;
  673. // standard groupblog
  674. case 'groupblog':
  675. $label = __( 'View Group Blog', 'commentpress-core' );
  676. $button['link_text'] = $label;
  677. $button['link_title'] = $label;
  678. break;
  679. // CommentPress sub-site
  680. case 'commentpress-groupblog':
  681. $label = __( 'View Document', 'commentpress-core' );
  682. $button['link_text'] = apply_filters( 'cp_get_blogs_visit_groupblog_button', $label );
  683. $button['link_title'] = apply_filters( 'cp_get_blogs_visit_groupblog_button', $label );
  684. break;
  685. }
  686. // --<
  687. return $button;
  688. }
  689. /**
  690. * @description: hook into the group blog signup form
  691. * @todo:
  692. *
  693. */
  694. function signup_blogform( $errors ) {
  695. // apply to group blog signup form?
  696. if ( bp_is_groups_component() ) {
  697. // hand off to private method
  698. $this->_create_groupblog_options();
  699. } else {
  700. // hand off to private method
  701. $this->_create_blog_options();
  702. }
  703. }
  704. /**
  705. * @description: hook into wpmu_new_blog and target plugins to be activated
  706. * @todo:
  707. *
  708. */
  709. function wpmu_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
  710. // test for presence of our checkbox variable in _POST
  711. if ( isset( $_POST['cpbp-groupblog'] ) AND $_POST['cpbp-groupblog'] == '1' ) {
  712. // hand off to private method
  713. $this->_create_groupblog( $blog_id, $user_id, $domain, $path, $site_id, $meta );
  714. } else {
  715. // test for presence of our checkbox variable in _POST
  716. if ( isset( $_POST['cpbp-new-blog'] ) AND $_POST['cpbp-new-blog'] == '1' ) {
  717. // hand off to private method
  718. $this->_create_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta );
  719. }
  720. }
  721. }
  722. /**
  723. * @description: override the title of the "Create a new document" link
  724. * @todo:
  725. *
  726. */
  727. function user_links_new_site_title() {
  728. // override default link name
  729. return apply_filters(
  730. 'cpmu_bp_create_new_site_title',
  731. __( 'Create a New Site', 'commentpress-core' )
  732. );
  733. }
  734. /**
  735. * groupblog_privacy_check()
  736. *
  737. * Check if a non-public group is being accessed by a user who is not a member of the group
  738. * Adapted from code in mahype's fork of BP Groupblog plugin, but not accepted because there
  739. * may be cases where private groups have public groupblogs. Ours is not such a case.
  740. */
  741. function groupblog_privacy_check() {
  742. // check our site option
  743. if ( $this->db->option_get( 'cpmu_bp_groupblog_privacy' ) != '1' ) { return; }
  744. global $blog_id, $current_user;
  745. // if is not the main blog but we do have a blog ID...
  746. if( !is_main_site() AND isset( $blog_id ) AND is_numeric( $blog_id ) ) {
  747. // do we have groupblog active?
  748. if ( function_exists( 'get_groupblog_group_id' ) ) {
  749. // get group ID for this blog
  750. $group_id = get_groupblog_group_id( $blog_id );
  751. // if we get one...
  752. if( is_numeric( $group_id ) ) {
  753. // get the group object
  754. $group = new BP_Groups_Group( $group_id );
  755. // if group is not public...
  756. if( $group->status != 'public' ) {
  757. // is the current user a member of the blog?
  758. if ( !is_user_member_of_blog( $current_user->ID, $blog_id ) ) {
  759. // no - redirect to network home, but allow overrides
  760. wp_redirect( apply_filters( 'bp_groupblog_privacy_redirect_url', network_site_url() ) );
  761. exit;
  762. }
  763. }
  764. }
  765. }
  766. }
  767. }
  768. //##############################################################################
  769. /*
  770. ============================================================================
  771. PRIVATE METHODS
  772. ============================================================================
  773. */
  774. /**
  775. * @description: object initialisation
  776. * @todo:
  777. *
  778. */
  779. function _init() {
  780. // register hooks
  781. $this->_register_hooks();
  782. }
  783. /**
  784. * @description: register Wordpress hooks
  785. * @todo:
  786. *
  787. */
  788. function _register_hooks() {
  789. // enable html comments and content for authors
  790. add_action( 'init', array( $this, 'allow_html_content' ) );
  791. // check for the privacy of a groupblog
  792. add_action( 'init', array( $this, 'groupblog_privacy_check' ) );
  793. // add some tags to the allowed tags in activities
  794. add_filter( 'bp_activity_allowed_tags', array( $this, 'activity_allowed_tags' ), 20 );
  795. // allow comment authors to edit their own comments
  796. add_filter( 'map_meta_cap', array( $this, 'enable_comment_editing' ), 10, 4 );
  797. // amend comment activity
  798. add_filter( 'pre_comment_approved', array( $this, 'pre_comment_approved' ), 99, 2 );
  799. //add_action( 'preprocess_comment', 'my_check_comment', 1 );
  800. // override "publicness" of groupblogs
  801. add_filter( 'bp_is_blog_public', array( $this, 'is_blog_public' ), 20, 1 );
  802. // amend activity
  803. add_action( 'bp_loaded', array( $this, '_groupblog_activity_mods' ), 30 );
  804. // get group avatar when listing groupblogs
  805. add_filter( 'bp_get_blog_avatar', array( $this, 'get_blog_avatar' ), 20, 3 );
  806. // filter bp-groupblog defaults
  807. add_filter( 'bp_groupblog_subnav_item_name', array( $this, 'filter_blog_name' ), 20 );
  808. add_filter( 'bp_groupblog_subnav_item_slug', array( $this, 'filter_blog_slug' ), 20 );
  809. // override CommentPress "Title Page"
  810. add_filter( 'cp_nav_title_page_title', array( $this, 'filter_nav_title_page_title' ), 20 );
  811. // override the name of the button on the BP "blogs" screen
  812. // to override this, just add the same filter with a priority of 21 or greater
  813. add_filter( 'bp_get_blogs_visit_blog_button', array( $this, 'get_blogs_visit_blog_button' ), 20 );
  814. // we can remove groupblogs from the blog list, but cannot update the total_blog_count_for_user
  815. // that is displayed on the tab *before* the blog list is built - hence filter disabled for now
  816. //add_filter( 'bp_has_blogs', array( $this, 'remove_groupblog_from_loop' ), 20, 2 );
  817. // add form elements to groupblog form
  818. add_action( 'signup_blogform', array( $this, 'signup_blogform' ) );
  819. // add form elements to signup form
  820. add_action( 'cpmu_bp_after_blog_details_fields', array( $this, 'signup_blogform' ) );
  821. // activate blog-specific CommentPress Core plugin
  822. // added @ priority 20 because BP Groupblog adds its action at the default 10 and
  823. // we want it to have done its stuff before we do ours...
  824. add_action( 'wpmu_new_blog', array( $this, 'wpmu_new_blog' ), 20, 6 );
  825. // register any public styles
  826. add_action( 'wp_enqueue_scripts', array( $this, 'add_frontend_styles' ), 20 );
  827. // override CommentPress "Create New Document" text
  828. add_filter( 'cp_user_links_new_site_title', array( $this, 'user_links_new_site_title' ), 21 );
  829. add_filter( 'cp_site_directory_link_title', array( $this, 'user_links_new_site_title' ), 21 );
  830. add_filter( 'cp_register_new_site_page_title', array( $this, 'user_links_new_site_title' ), 21 );
  831. // override groupblog theme, if the bp-groupblog default theme is not a CommentPress Core one
  832. add_filter( 'cp_forced_theme_slug', array( $this, '_get_groupblog_theme' ), 20, 1 );
  833. add_filter( 'cp_forced_theme_name', array( $this, '_get_groupblog_theme' ), 20, 1 );
  834. // is this the back end?
  835. if ( is_admin() ) {
  836. // anything specifically for WP Admin
  837. // add options to network settings form
  838. add_filter( 'cpmu_network_options_form', array( $this, '_network_admin_form' ), 20 );
  839. // add options to reset array
  840. add_filter( 'cpmu_db_bp_options_get_defaults', array( $this, '_get_default_settings' ), 20, 1 );
  841. // hook into Network BuddyPress form update
  842. add_action( 'cpmu_db_options_update', array( $this, '_buddypress_admin_update' ), 20 );
  843. } else {
  844. // anything specifically for Front End
  845. // add filter options for the post and comment activities as late as we can
  846. // so that bp-groupblog's action can be removed
  847. add_action( 'bp_setup_globals', array( $this, '_groupblog_filter_options' ) );
  848. }
  849. }
  850. /**
  851. * _groupblog_filter_options()
  852. *
  853. * Add a filter actions once BuddyPress is loaded.
  854. */
  855. function _groupblog_filter_options() {
  856. // remove bp-groupblog's contradictory option
  857. remove_action( 'bp_group_activity_filter_options', 'bp_groupblog_posts' );
  858. // add our consistent one
  859. add_action( 'bp_activity_filter_options', array( $this, 'groupblog_posts_filter_option' ) );
  860. add_action( 'bp_group_activity_filter_options', array( $this, 'groupblog_posts_filter_option' ) );
  861. add_action( 'bp_member_activity_filter_options', array( $this, 'groupblog_posts_filter_option' ) );
  862. // add our comments
  863. add_action( 'bp_activity_filter_options', array( $this, 'groupblog_comments_filter_option' ) );
  864. add_action( 'bp_group_activity_filter_options', array( $this, 'groupblog_comments_filter_option' ) );
  865. add_action( 'bp_member_activity_filter_options', array( $this, 'groupblog_comments_filter_option' ) );
  866. }
  867. /**
  868. * _groupblog_activity_mods()
  869. *
  870. * Amend Activity Methods once BuddyPress is loaded.
  871. */
  872. function _groupblog_activity_mods() {
  873. // allow lists in activity content
  874. add_action( 'bp_activity_allowed_tags', array( $this, '_activity_allowed_tags' ), 20, 1 );
  875. // ditch bp-groupblog's post activity action
  876. remove_action( 'bp_activity_before_save', 'bp_groupblog_set_group_to_post_activity' );
  877. // add custom comment activity to bp-groupblog
  878. add_action( 'bp_activity_before_save', array( $this, 'groupblog_custom_comment_activity' ), 20, 1 );
  879. // implement our own post activity
  880. add_action( 'bp_activity_before_save', array( $this, 'groupblog_custom_post_activity' ), 20, 1 );
  881. // these don't seem to fire to allow us to add our meta values for the items...
  882. // instead, I'm trying to store the blog_type as group meta data
  883. //add_action( 'bp_activity_after_save', array( $this, 'groupblog_custom_comment_meta' ), 20, 1 );
  884. //add_action( 'bp_activity_after_save', array( $this, 'groupblog_custom_post_meta' ), 20, 1 );
  885. }
  886. /**
  887. * @description: allow our TinyMCE comment markup in activity content
  888. * @todo:
  889. */
  890. function _activity_allowed_tags( $activity_allowedtags ) {
  891. //print_r( $activity_allowedtags ); die();
  892. // lists
  893. $activity_allowedtags['ul'] = array();
  894. $activity_allowedtags['ol'] = array();
  895. $activity_allowedtags['li'] = array();
  896. // bold
  897. $activity_allowedtags['strong'] = array();
  898. // italic
  899. $activity_allowedtags['em'] = array();
  900. // underline
  901. $activity_allowedtags['span']['style'] = array();
  902. // --<
  903. return $activity_allowedtags;
  904. }
  905. /**
  906. * @description: hook into the groupblog create screen
  907. * @todo:
  908. *
  909. */
  910. function _create_groupblog_options() {
  911. global $bp, $groupblog_create_screen;
  912. $blog_id = get_groupblog_blog_id();
  913. if ( !$groupblog_create_screen && $blog_id != '' ) {
  914. // existing blog and group - do we need to present any options?
  915. } else {
  916. // creating a new group - no groupblog exists yet
  917. // NOTE: need to check that our context is right
  918. // get force option
  919. $forced = $this->db->option_get( 'cpmu_bp_force_commentpress' );
  920. // are we force-enabling CommentPress Core?
  921. if ( $forced ) {
  922. // set hidden element
  923. $forced_html = '
  924. <input type="hidden" value="1" id="cpbp-groupblog" name="cpbp-groupblog" />
  925. ';
  926. // define text, but allow overrides
  927. $text = apply_filters(
  928. 'cp_groupblog_options_signup_text_forced',
  929. __( 'Select the options for your new CommentPress-enabled blog. Note: if you choose an existing blog as a group blog, setting these options will have no effect.', 'commentpress-core' )
  930. );
  931. } else {
  932. // set checkbox
  933. $forced_html = '
  934. <div class="checkbox">
  935. <label for="cpbp-groupblog"><input type="checkbox" value="1" id="cpbp-groupblog" name="cpbp-groupblog" /> '.__( 'Enable CommentPress', 'commentpress-core' ).'</label>
  936. </div>
  937. ';
  938. // define text, but allow overrides
  939. $text = apply_filters(
  940. 'cp_groupblog_options_signup_text',
  941. __( 'When you create a group blog, you can choose to enable it as a CommentPress blog. This is a "one time only" option because you cannot disable CommentPress from here once the group blog is created. Note: if you choose an existing blog as a group blog, setting this option will have no effect.', 'commentpress-core' )
  942. );
  943. }
  944. // off by default
  945. $has_workflow = false;
  946. // init output
  947. $workflow_html = '';
  948. // allow overrides
  949. $has_workflow = apply_filters( 'cp_blog_workflow_exists', $has_workflow );
  950. // if we have workflow enabled, by a plugin, say...
  951. if ( $has_workflow !== false ) {
  952. // define workflow label
  953. $workflow_label = __( 'Enable Custom Workflow', 'commentpress-core' );
  954. // allow overrides
  955. $workflow_label = apply_filters( 'cp_blog_workflow_label', $workflow_label );
  956. // show it
  957. $workflow_html = '
  958. <div class="checkbox">
  959. <label for="cp_blog_workflow"><input type="checkbox" value="1" id="cp_blog_workflow" name="cp_blog_workflow" /> '.$workflow_label.'</label>
  960. </div>
  961. ';
  962. }
  963. // assume no types
  964. $types = array();
  965. // init output
  966. $type_html = '';
  967. // but allow overrides for plugins to supply some
  968. $types = apply_filters( 'cp_blog_type_options', $types );
  969. // if we got any, use them
  970. if ( !empty( $types ) ) {
  971. // define blog type label
  972. $type_label = __( 'Document Type', 'commentpress-core' );
  973. // allow overrides
  974. $type_label = apply_filters( 'cp_blog_type_label', $type_label );
  975. // construct options
  976. $type_option_list = array();
  977. $n = 0;
  978. foreach( $types AS $type ) {
  979. $type_option_list[] = '<option value="'.$n.'">'.$type.'</option>';
  980. $n++;
  981. }
  982. $type_options = implode( "\n", $type_option_list );
  983. // show it
  984. $type_html = '
  985. <div class="dropdown">
  986. <label for="cp_blog_type">'.$type_label.'</label> <select id="cp_blog_type" name="cp_blog_type">
  987. '.$type_options.'
  988. </select>
  989. </div>
  990. ';
  991. }
  992. // construct form
  993. $form = '
  994. <br />
  995. <div id="cp-multisite-options">
  996. <h3>'.__( 'CommentPress Options', 'commentpress-core' ).'</h3>
  997. <p>'.$text.'</p>
  998. '.$forced_html.'
  999. '.$workflow_html.'
  1000. '.$type_html.'
  1001. </div>
  1002. ';
  1003. echo $form;
  1004. }
  1005. }
  1006. /**
  1007. * @description: create a blog that is a groupblog
  1008. * @todo:
  1009. *
  1010. */
  1011. function _create_groupblog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
  1012. // get group id before switch
  1013. $group_id = isset( $_COOKIE['bp_new_group_id'] )
  1014. ? $_COOKIE['bp_new_group_id']
  1015. : bp_get_current_group_id();
  1016. // wpmu_new_blog calls this *after* restore_current_blog, so we need to do it again
  1017. switch_to_blog( $blog_id );
  1018. // activate CommentPress Core
  1019. $this->db->install_commentpress();
  1020. // access core
  1021. global $commentpress_core;
  1022. // TODO: create admin page settings for WordPress options
  1023. // show posts by default (may be overridden)
  1024. $posts_or_pages = 'post';
  1025. // allow plugin overrides
  1026. $posts_or_pages = apply_filters( 'cp_posts_or_pages_in_toc', $posts_or_pages );
  1027. // TOC = posts
  1028. $commentpress_core->db->option_set( 'cp_show_posts_or_pages_in_toc', $posts_or_pages );
  1029. // if we opted for posts...
  1030. if ( $posts_or_pages == 'post' ) {
  1031. // TOC shows extended posts by default (may be overridden)
  1032. $extended_toc = 1;
  1033. // allow plugin overrides
  1034. $extended_toc = apply_filters( 'cp_extended_toc', $extended_toc );
  1035. // TOC shows extended posts
  1036. $commentpress_core->db->option_set( 'cp_show_extended_toc', $extended_toc );
  1037. }
  1038. // get blog type (saved already)
  1039. $cp_blog_type = $commentpress_core->db->option_get( 'cp_blog_type' );
  1040. // did we get a group id before we switched blogs?
  1041. if ( isset( $group_id ) ) {
  1042. // allow plugins to override the blog type - for example if workflow is enabled,
  1043. // it might become a new blog type as far as buddypress is concerned
  1044. $_blog_type = apply_filters( 'cp_get_group_meta_for_blog_type', $cp_blog_type, $cp_blog_workflow );
  1045. // set the type as group meta info
  1046. // we also need to change this when the type is changed from the CP admin page
  1047. groups_update_groupmeta( $group_id, 'groupblogtype', 'groupblogtype-'.$_blog_type );
  1048. }
  1049. // save
  1050. $commentpress_core->db->options_save();
  1051. // ---------------------------------------------------------------------
  1052. // WordPress Internal Configuration
  1053. // ---------------------------------------------------------------------
  1054. // get commenting option
  1055. $anon_comments = $this->db->option_get( 'cpmu_bp_require_comment_registration' ) == '1' ? 1 : 0;
  1056. // anonymous commenting (may be overridden by admin option)
  1057. $anon_comments = apply_filters(
  1058. 'cp_require_comment_registration',
  1059. $anon_comments
  1060. );
  1061. // update wp option
  1062. update_option( 'comment_registration', $anon_comments );
  1063. // get all network-activated plugins
  1064. $active_sitewide_plugins = maybe_unserialize( get_site_option( 'active_sitewide_plugins' ) );
  1065. // did we get any?
  1066. if ( is_array( $active_sitewide_plugins ) AND count( $active_sitewide_plugins ) > 0 ) {
  1067. // loop through them
  1068. foreach( $active_sitewide_plugins AS $plugin_path => $plugin_data ) {
  1069. // if we've got BuddyPress Group Email Subscription network-installed
  1070. if ( false !== strstr( $plugin_path, 'bp-activity-subscription.php' ) ) {
  1071. // switch comments_notify off
  1072. update_option( 'comments_notify', 0 );
  1073. // no need to carry on
  1074. break;
  1075. }
  1076. }
  1077. }
  1078. // switch back
  1079. restore_current_blog();
  1080. }
  1081. /**
  1082. * @description: hook into the blog create screen on registration page
  1083. * @todo:
  1084. *
  1085. */
  1086. function _create_blog_options() {
  1087. // get force option
  1088. $forced = $this->db->option_get( 'cpmu_force_commentpress' );
  1089. // are we force-enabling CommentPress Core?
  1090. if ( $forced ) {
  1091. // set hidden element
  1092. $forced_html = '
  1093. <input type="hidden" value="1" id="cpmu-new-blog" name="cpmu-new-blog" />
  1094. ';
  1095. // define text
  1096. $text = __( 'Select the options for your new CommentPress document.', 'commentpress-core' );
  1097. } else {
  1098. // set checkbox
  1099. $forced_html = '
  1100. <div class="checkbox">
  1101. <label for="cpmu-new-blog"><input type="checkbox" value="1" id="cpmu-new-blog" name="cpmu-new-blog" /> '.__( 'Enable CommentPress', 'commentpress-core' ).'</label>
  1102. </div>
  1103. ';
  1104. // define text
  1105. $text = __( 'Do you want to make the new site a CommentPress document?', 'commentpress-core' );
  1106. }
  1107. // off by default
  1108. $has_workflow = false;
  1109. // init output
  1110. $workflow_html = '';
  1111. // allow overrides
  1112. $has_workflow = apply_filters( 'cp_blog_workflow_exists', $has_workflow );
  1113. // if we have workflow enabled, by a plugin, say...
  1114. if ( $has_workflow !== false ) {
  1115. // define workflow label
  1116. $workflow_label = __( 'Enable Custom Workflow', 'commentpress-core' );
  1117. // allow overrides
  1118. $workflow_label = apply_filters( 'cp_blog_workflow_label', $workflow_label );
  1119. // show it
  1120. $workflow_html = '
  1121. <div class="checkbox">
  1122. <label for="cp_blog_workflow"><input type="checkbox" value="1" id="cp_blog_workflow" name="cp_blog_workflow" /> '.$workflow_label.'</label>
  1123. </div>
  1124. ';
  1125. }
  1126. // assume no types
  1127. $types = array();
  1128. // init output
  1129. $type_html = '';
  1130. // but allow overrides for plugins to supply some
  1131. $types = apply_filters( 'cp_blog_type_options', $types );
  1132. // if we got any, use them
  1133. if ( !empty( $types ) ) {
  1134. // define blog type label
  1135. $type_label = __( 'Document Type', 'commentpress-core' );
  1136. // allow overrides
  1137. $type_label = apply_filters( 'cp_blog_type_label', $type_label );
  1138. // construct options
  1139. $type_option_list = array();
  1140. $n = 0;
  1141. foreach( $types AS $type ) {
  1142. $type_option_list[] = '<option value="'.$n.'">'.$type.'</option>';
  1143. $n++;
  1144. }
  1145. $type_options = implode( "\n", $type_option_list );
  1146. // show it
  1147. $type_html = '
  1148. <div class="dropdown cp-workflow-type">
  1149. <label for="cp_blog_type">'.$type_label.'</label> <select id="cp_blog_type" name="cp_blog_type">
  1150. '.$type_options.'
  1151. </select>
  1152. </div>
  1153. ';
  1154. }
  1155. // construct form
  1156. $form = '
  1157. <br />
  1158. <div id="cp-multisite-options">
  1159. <h4>'.__( 'CommentPress Options', 'commentpress-core' ).'</h4>
  1160. <p>'.$text.'</p>
  1161. '.$forced_html.'
  1162. '.$workflow_html.'
  1163. '.$type_html.'
  1164. </div>
  1165. ';
  1166. echo $form;
  1167. }
  1168. /**
  1169. * @description: create a blog that is not a groupblog
  1170. * @todo:
  1171. *
  1172. */
  1173. function _create_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
  1174. // wpmu_new_blog calls this *after* restore_current_blog, so we need to do it again
  1175. switch_to_blog( $blog_id );
  1176. // activate CommentPress Core
  1177. $this->db->install_commentpress();
  1178. // switch back
  1179. restore_current_blog();
  1180. }
  1181. /**
  1182. * @description: utility to wrap is_groupblog()
  1183. * @todo:
  1184. *
  1185. */
  1186. function _is_commentpress_groupblog() {
  1187. // check if this blog is a CP groupblog
  1188. global $commentpress_core;
  1189. if (
  1190. !is_null( $commentpress_core )
  1191. AND is_object( $commentpress_core )
  1192. AND $commentpress_core->is_groupblog()
  1193. ) {
  1194. return true;
  1195. }
  1196. return false;
  1197. }
  1198. /**
  1199. * @description: utility to get blog_type
  1200. * @todo:
  1201. *
  1202. */
  1203. function _get_groupblog_type() {
  1204. global $commentpress_core;
  1205. // if we have the plugin
  1206. if (
  1207. !is_null( $commentpress_core )
  1208. AND is_object( $commentpress_core )
  1209. ) {
  1210. // --<
  1211. return $commentpress_core->db->option_get( 'cp_blog_type' ) ;
  1212. }
  1213. // --<
  1214. return false;
  1215. }
  1216. /**
  1217. * @description: add our options to the network admin form
  1218. * @todo:
  1219. *
  1220. */
  1221. function _network_admin_form() {
  1222. // define admin page
  1223. $admin_page = '
  1224. <div id="cpmu_bp_admin_options">
  1225. <h3>'.__( 'BuddyPress &amp; Groupblog Settings', 'commentpress-core' ).'</h3>
  1226. <p>'.__( 'Configure how CommentPress interacts with BuddyPress and BP Groupblog.', 'commentpress-core' ).'</p>
  1227. <table class="form-table">
  1228. <tr valign="top">
  1229. <th scope="row"><label for="cpmu_bp_reset">'.__( 'Reset BuddyPress settings', 'commentpress-core' ).'</label></th>
  1230. <td><input id="cpmu_bp_reset" name="cpmu_bp_reset" value="1" type="checkbox" /></td>
  1231. </tr>
  1232. <tr valign="top">
  1233. <th scope="row"><label for="cpmu_bp_force_commentpress">'.__( 'Make all new Groupblogs CommentPress-enabled', 'commentpress-core' ).'</label></th>
  1234. <td><input id="cpmu_bp_force_commentpress" name="cpmu_bp_force_commentpress" value="1" type="checkbox"'.( $this->db->option_get( 'cpmu_bp_force_commentpress' ) == '1' ? ' checked="checked"' : '' ).' /></td>
  1235. </tr>
  1236. '.$this->_get_commentpress_themes().'
  1237. <tr valign="top">
  1238. <th scope="row"><label for="cpmu_bp_groupblog_privacy">'.__( 'Private Groups must have Private Groupblogs', 'commentpress-core' ).'</label></th>
  1239. <td><input id="cpmu_bp_groupblog_privacy" name="cpmu_bp_groupblog_privacy" value="1" type="checkbox"'.( $this->db->option_get( 'cpmu_bp_groupblog_privacy' ) == '1' ? ' checked="checked"' : '' ).' /></td>
  1240. </tr>
  1241. <tr valign="top">
  1242. <th scope="row"><label for="cpmu_bp_require_comment_registration">'.__( 'Require user login to post comments on Groupblogs', 'commentpress-core' ).'</label></th>
  1243. <td><input id="cpmu_bp_require_comment_registration" name="cpmu_bp_require_comment_registration" value="1" type="checkbox"'.( $this->db->option_get( 'cpmu_bp_require_comment_registration' ) == '1' ? ' checked="checked"' : '' ).' /></td>
  1244. </tr>
  1245. '.$this->_additional_buddypress_options().'
  1246. </table>
  1247. </div>
  1248. ';
  1249. // --<
  1250. return $admin_page;
  1251. }
  1252. /**
  1253. * @description: get all CommentPress Core themes
  1254. * @todo:
  1255. *
  1256. */
  1257. function _get_commentpress_themes() {
  1258. // get all themes
  1259. if ( function_exists( 'wp_get_themes' ) ) {
  1260. // get theme data the WP3.4 way...
  1261. $themes = wp_get_themes(
  1262. false, // only error-free themes
  1263. 'network', // only network-allowed themes
  1264. 0 // use current blog as reference
  1265. );
  1266. // get currently selected theme
  1267. $current_theme = $this->db->option_get('cpmu_bp_groupblog_theme');
  1268. } else {
  1269. // pre WP3.4 functions
  1270. $themes = get_themes();
  1271. // get currently selected theme
  1272. $current_theme = $this->db->option_get('cpmu_bp_groupblog_theme_name');
  1273. }
  1274. // init
  1275. $options = array();
  1276. $element = '';
  1277. // we must get *at least* one (the Default), but let's be safe
  1278. if ( !empty( $themes ) ) {
  1279. // loop
  1280. foreach( $themes AS $theme ) {
  1281. // is it a CommentPress Groupblog theme?
  1282. if (
  1283. in_array( 'commentpress', (array) $theme['Tags'] ) AND
  1284. in_array( 'groupblog', (array) $theme['Tags'] )
  1285. ) {
  1286. // is this WP3.4+?
  1287. if ( function_exists( 'wp_get_themes' ) ) {
  1288. // use stylesheet as theme data
  1289. $theme_data = $theme->get_stylesheet();
  1290. } else {
  1291. // use name as theme data
  1292. $theme_data = $theme['Title'];
  1293. }
  1294. // is it the currently selected theme?
  1295. $selected = ( $current_theme == $theme_data ) ? ' selected="selected"' : '';
  1296. // add to array
  1297. $options[] = '<option value="'.$theme_data.'" '.$selected.'>'.$theme['Title'].'</option>';
  1298. }
  1299. }
  1300. // did we get any?
  1301. if ( !empty( $options ) ) {
  1302. // implode
  1303. $opts = implode( "\n", $options );
  1304. // define element
  1305. $element = '
  1306. <tr valign="top">
  1307. <th scope="row"><label for="cpmu_bp_groupblog_theme">'.__( 'Select theme for CommentPress Groupblogs', 'commentpress-core' ).'</label></th>
  1308. <td><select id="cpmu_bp_groupblog_theme" name="cpmu_bp_groupblog_theme">
  1309. '.$opts.'
  1310. </select>
  1311. </td>
  1312. </tr>
  1313. ';
  1314. }
  1315. }
  1316. // --<
  1317. return $element;
  1318. }
  1319. /**
  1320. * @description: get Groupblog theme as defined in Network BuddyPress admin
  1321. * @todo:
  1322. *
  1323. */
  1324. function _get_groupblog_theme( $default_theme ) {
  1325. // get the theme we've defined as the default for groupblogs
  1326. $theme = $this->db->optio

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