bp_docs_doc_permissions_snapshot

Markup for the Doc Permissions snapshot.

Description

bp_docs_doc_permissions_snapshot( (array) $args = array() ); 

Markup is built inline. Someday I may abstract it. In the meantime, suck a lemon

Parameters (1)

0. $args — Optional. (array) => array()
The args.

Usage

  1. if ( !function_exists( 'bp_docs_doc_permissions_snapshot' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-docs/includes/templatetags.php'; 
  3.  
  4. // The args. 
  5. $args = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_docs_doc_permissions_snapshot($args); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/templatetags.php  
  1. function bp_docs_doc_permissions_snapshot( $args = array() ) { 
  2. $html = ''; 
  3.  
  4. $defaults = array( 
  5. 'summary_before_content' => '',  
  6. 'summary_after_content' => '' 
  7. ); 
  8.  
  9. $args = wp_parse_args( $args, $defaults ); 
  10. extract( $args, EXTR_SKIP ); 
  11.  
  12. if ( bp_is_active( 'groups' ) ) { 
  13. $doc_group_ids = bp_docs_get_associated_group_id( get_the_ID(), false, true ); 
  14. $doc_groups = array(); 
  15. foreach( $doc_group_ids as $dgid ) { 
  16. $maybe_group = groups_get_group( array( 'group_id' => $dgid ) ); 
  17.  
  18. // Don't show hidden groups if the 
  19. // current user is not a member 
  20. if ( isset( $maybe_group->status ) && 'hidden' === $maybe_group->status ) { 
  21. // @todo this is slow 
  22. if ( ! current_user_can( 'bp_moderate' ) && ! groups_is_user_member( bp_loggedin_user_id(), $dgid ) ) { 
  23. continue; 
  24.  
  25. if ( !empty( $maybe_group->name ) ) { 
  26. $doc_groups[] = $maybe_group; 
  27.  
  28. // First set up the Group snapshot, if there is one 
  29. if ( ! empty( $doc_groups ) ) { 
  30. $group_link = bp_get_group_permalink( $doc_groups[0] ); 
  31. $html .= '<div id="doc-group-summary">'; 
  32.  
  33. $html .= $summary_before_content ; 
  34. $html .= '<span>' . __('Group: ', 'bp-docs') . '</span>'; 
  35.  
  36. $html .= sprintf( __( ' %s', 'bp-docs' ), '<a href="' . $group_link . '">' . bp_core_fetch_avatar( 'item_id=' . $doc_groups[0]->id . '&object=group&type=thumb&width=25&height=25' ) . '</a> ' . '<a href="' . $group_link . '">' . esc_html( $doc_groups[0]->name ) . '</a>' ); 
  37.  
  38. $html .= $summary_after_content; 
  39.  
  40. $html .= '</div>'; 
  41.  
  42. // we'll need a list of comma-separated group names 
  43. $group_names = implode( ', ', wp_list_pluck( $doc_groups, 'name' ) ); 
  44.  
  45. $levels = array( 
  46. 'anyone' => __( 'Anyone', 'bp-docs' ),  
  47. 'loggedin' => __( 'Logged-in Users', 'bp-docs' ),  
  48. 'friends' => __( 'My Friends', 'bp-docs' ),  
  49. 'creator' => __( 'The Doc author only', 'bp-docs' ),  
  50. 'no-one' => __( 'Just Me', 'bp-docs' ) 
  51. ); 
  52.  
  53. if ( bp_is_active( 'groups' ) ) { 
  54. $levels['group-members'] = sprintf( __( 'Members of: %s', 'bp-docs' ), $group_names ); 
  55. $levels['admins-mods'] = sprintf( __( 'Admins and mods of the group %s', 'bp-docs' ), $group_names ); 
  56.  
  57. if ( get_the_author_meta( 'ID' ) == bp_loggedin_user_id() ) { 
  58. $levels['creator'] = __( 'The Doc author only (that\'s you!)', 'bp-docs' ); 
  59.  
  60. $settings = bp_docs_get_doc_settings(); 
  61.  
  62. // Read 
  63. $read_class = bp_docs_get_permissions_css_class( $settings['read'] ); 
  64. $read_text = sprintf( __( 'This Doc can be read by: <strong>%s</strong>', 'bp-docs' ), $levels[ $settings['read'] ] ); 
  65.  
  66. // Edit 
  67. $edit_class = bp_docs_get_permissions_css_class( $settings['edit'] ); 
  68. $edit_text = sprintf( __( 'This Doc can be edited by: <strong>%s</strong>', 'bp-docs' ), $levels[ $settings['edit'] ] ); 
  69.  
  70. // Read Comments 
  71. $read_comments_class = bp_docs_get_permissions_css_class( $settings['read_comments'] ); 
  72. $read_comments_text = sprintf( __( 'Comments are visible to: <strong>%s</strong>', 'bp-docs' ), $levels[ $settings['read_comments'] ] ); 
  73.  
  74. // Post Comments 
  75. $post_comments_class = bp_docs_get_permissions_css_class( $settings['post_comments'] ); 
  76. $post_comments_text = sprintf( __( 'Comments can be posted by: <strong>%s</strong>', 'bp-docs' ), $levels[ $settings['post_comments'] ] ); 
  77.  
  78. // View History 
  79. $view_history_class = bp_docs_get_permissions_css_class( $settings['view_history'] ); 
  80. $view_history_text = sprintf( __( 'History can be viewed by: <strong>%s</strong>', 'bp-docs' ), $levels[ $settings['view_history'] ] ); 
  81.  
  82. // Calculate summary 
  83. // Summary works like this: 
  84. // 'public' - all read_ items set to 'anyone', all others to 'anyone' or 'loggedin' 
  85. // 'private' - everything set to 'admins-mods', 'creator', 'no-one', 'friends', or 'group-members' where the associated group is non-public 
  86. // 'limited' - everything else 
  87. $anyone_count = 0; 
  88. $private_count = 0; 
  89. $public_settings = array( 
  90. 'read' => 'anyone',  
  91. 'edit' => 'loggedin',  
  92. 'read_comments' => 'anyone',  
  93. 'post_comments' => 'loggedin',  
  94. 'view_history' => 'anyone' 
  95. ); 
  96.  
  97. foreach ( $settings as $l => $v ) { 
  98. if ( 'anyone' == $v || ( isset( $public_settings[ $l ] ) && $public_settings[ $l ] == $v ) ) { 
  99.  
  100. $anyone_count++; 
  101.  
  102. } else if ( in_array( $v, array( 'admins-mods', 'creator', 'no-one', 'friends', 'group-members' ) ) ) { 
  103.  
  104. if ( 'group-members' == $v ) { 
  105. if ( ! isset( $group_status ) ) { 
  106. $group_status = 'foo'; // todo 
  107.  
  108. if ( 'public' != $group_status ) { 
  109. $private_count++; 
  110. } else { 
  111. $private_count++; 
  112.  
  113.  
  114. $settings_count = count( $public_settings ); 
  115. if ( $settings_count == $private_count ) { 
  116. $summary = 'private'; 
  117. $summary_label = __( 'Private', 'bp-docs' ); 
  118. } else if ( $settings_count == $anyone_count ) { 
  119. $summary = 'public'; 
  120. $summary_label = __( 'Public', 'bp-docs' ); 
  121. } else { 
  122. $summary = 'limited'; 
  123. $summary_label = __( 'Limited', 'bp-docs' ); 
  124.  
  125. $html .= '<div id="doc-permissions-summary" class="doc-' . $summary . '">'; 
  126. $html .= $summary_before_content; 
  127. $html .= sprintf( __( 'Access: <strong>%s</strong>', 'bp-docs' ), $summary_label ); 
  128. $html .= '<a href="#" class="doc-permissions-toggle" id="doc-permissions-more">' . __( 'Show Details', 'bp-docs' ) . '</a>'; 
  129. $html .= $summary_after_content; 
  130. $html .= '</div>'; 
  131.  
  132. $html .= '<div id="doc-permissions-details">'; 
  133. $html .= '<ul>'; 
  134. $html .= '<li class="bp-docs-can-read ' . $read_class . '"><span class="bp-docs-level-icon"></span>' . '<span class="perms-text">' . $read_text . '</span></li>'; 
  135. $html .= '<li class="bp-docs-can-edit ' . $edit_class . '"><span class="bp-docs-level-icon"></span>' . '<span class="perms-text">' . $edit_text . '</span></li>'; 
  136. $html .= '<li class="bp-docs-can-read_comments ' . $read_comments_class . '"><span class="bp-docs-level-icon"></span>' . '<span class="perms-text">' . $read_comments_text . '</span></li>'; 
  137. $html .= '<li class="bp-docs-can-post_comments ' . $post_comments_class . '"><span class="bp-docs-level-icon"></span>' . '<span class="perms-text">' . $post_comments_text . '</span></li>'; 
  138. $html .= '<li class="bp-docs-can-view_history ' . $view_history_class . '"><span class="bp-docs-level-icon"></span>' . '<span class="perms-text">' . $view_history_text . '</span></li>'; 
  139. $html .= '</ul>'; 
  140.  
  141. if ( current_user_can( 'bp_docs_manage' ) ) 
  142. $html .= '<a href="' . bp_docs_get_doc_edit_link() . '#doc-settings" id="doc-permissions-edit">' . __( 'Edit', 'bp-docs' ) . '</a>'; 
  143.  
  144. $html .= '<a href="#" class="doc-permissions-toggle" id="doc-permissions-less">' . __( 'Hide Details', 'bp-docs' ) . '</a>'; 
  145. $html .= '</div>'; 
  146.  
  147. echo $html;