@@ -108,111 +108,86 @@ function add_internal_category_to_member_items($the_list, $type) {
108108 return $ result ;
109109 }
110110
111- function add_custom_elements_to_items ($ the_list ){
111+ function add_custom_elements_to_items ($ the_list ) {
112112 $ this ->add_visibility_and_groups_to_items ($ the_list );
113113 $ this ->add_post_type_to_items ($ the_list );
114114 $ this ->add_original_language_to_items ($ the_list );
115115 }
116116
117-
118-
119- function array_union ($ x , $ y )
120- {
121- if (empty ($ x ) && empty ($ y )){
122- return [];
123- }
124- if (empty ($ x )){
125- return $ y ;
126- }
127- if (empty ($ y )){
128- return $ x ;
129- }
130- // Use array_merge to combine three arrays:
131- // 1. Intersection of $x and $y
132- // 2. Elements in $x that are not in $y
133- // 3. Elements in $y that are not in $x
134- $ aunion = array_merge (
135- array_intersect ($ x , $ y ), // Intersection of $x and $y
136- array_diff ($ x , $ y ), // Elements in $x but not in $y
137- array_diff ($ y , $ x ) // Elements in $y but not in $x
138- );
139-
140- // Return the resulting array representing the union
141- return $ aunion ;
142- }
143-
144- function add_visibility_and_groups_to_items ($ the_list ){
117+ function add_visibility_and_groups_to_items ($ the_list ) {
145118 global $ post ;
146119 $ visibility = $ this ->_settings ->default_visibility ;
120+
147121 if ( $ bcc_login_visibility = (int ) get_post_meta ( $ post ->ID , 'bcc_login_visibility ' , true ) ) {
148122 $ visibility = $ bcc_login_visibility ;
149123 }
124+
150125 if ( !empty ($ this ->_settings ->site_groups )) {
151126 // Get groups that are checked on post
152- $ post_groups = get_post_meta ($ post ->ID , 'bcc_groups ' , false );
127+ $ post_target_groups = get_post_meta ($ post ->ID , 'bcc_groups ' , false );
128+ $ post_visibility_groups = get_post_meta ($ post ->ID , 'bcc_visibility_groups ' , false );
153129
154- // Make sure posts with a group set don't have public visiblity
155- if (!empty ($ post_groups ) )
130+ // Make sure posts with a group set don't have public visibility
131+ if ( !empty ($ post_target_groups ) || ! empty ( $ post_visibility_groups ) )
156132 {
157133 if ($ visibility == BCC_Login_Visibility::VISIBILITY_PUBLIC ) {
158134 $ visibility = BCC_Login_Visibility::VISIBILITY_SUBSCRIBER ;
159135 }
160136 }
161-
162137 }
163- $ this ->add_visibility_to_items ($ the_list ,$ visibility );
164- $ this ->add_groups_to_items ($ the_list , $ visibility );
165138
139+ $ this ->add_visibility_to_items ($ the_list , $ visibility );
140+ $ this ->add_groups_to_items ($ the_list , $ visibility );
166141 }
167142
168143 // Include basic visibility settings in feed:
169144 // - public (no authentication required)
170145 // - user (requires authentication)
171146 // - internal:{district name} (requires affiliation with organization in specified district)
172- function add_visibility_to_items ($ the_list , $ visibility ) {
173-
174- if ($ visibility == BCC_Login_Visibility::VISIBILITY_PUBLIC ){
147+ function add_visibility_to_items ($ the_list , $ visibility ) {
148+ if ($ visibility == BCC_Login_Visibility::VISIBILITY_PUBLIC ) {
175149 echo "<bcc:visibility>public</bcc:visibility> \n" ;
176-
177- } else if ($ visibility == BCC_Login_Visibility::VISIBILITY_SUBSCRIBER ){
150+ } else if ($ visibility == BCC_Login_Visibility::VISIBILITY_SUBSCRIBER ) {
178151 echo "<bcc:visibility>user</bcc:visibility> \n" ;
179- } else if ($ visibility == BCC_Login_Visibility::VISIBILITY_MEMBER ){
152+ } else if ($ visibility == BCC_Login_Visibility::VISIBILITY_MEMBER ) {
180153 echo "<bcc:visibility>internal: " . $ this ->_settings ->member_organization_name . "</bcc:visibility> \n" ;
181154 }
182155 }
183-
184156
185- // Include group uid for each group that the post is visible for or targetted at (notification group)
186- // E.g.
187- // <bcc:visiblityGroup >d4c434a7-504a-4246-9a10-def7dbfa982c</bcc:visiblityGroup >
188- // <bcc:visiblityGroup>25f5bc4d-48e0-4a6e-bf05-6b2a15d70861 </bcc:visiblityGroup >
189- // <bcc:notificationGroup>d4c434a7-504a-4246-9a10-def7dbfa982c </bcc:notificationGroup >
157+ // Include group uid for each group that the post is targeted at or visible for
158+ // E.g.:
159+ // <bcc:targetGroup >d4c434a7-504a-4246-9a10-def7dbfa982c</bcc:targetGroup >
160+ // <bcc:visibilityGroup>d4c434a7-504a-4246-9a10-def7dbfa982c </bcc:visibilityGroup >
161+ // <bcc:visibilityGroup>25f5bc4d-48e0-4a6e-bf05-6b2a15d70861 </bcc:visibilityGroup >
190162 function add_groups_to_items ($ the_list , $ visibility ) {
191163 global $ post ;
192164 $ result = '' ;
165+
193166 if ( !empty ($ this ->_settings ->site_groups ) || !empty ($ this ->_settings ->full_content_access_groups ) ) {
194- // Get groups that are checked on post
195- $ post_groups = get_post_meta ($ post ->ID , 'bcc_groups ' , false );
167+ $ post_target_groups = get_post_meta ( $ post -> ID , ' bcc_groups ' , false );
168+ $ post_visibility_groups = get_post_meta ($ post ->ID , 'bcc_visibility_groups ' , false );
196169
197- // Visiblity Groups: Groups that are checked on post
198- // + groups with access to all posts (only if there are groups checked on post)
199- if ($ visibility != BCC_Login_Visibility::VISIBILITY_PUBLIC && is_array ($ post_groups ) && count ($ post_groups ))
200- {
201- $ visibility_post_groups = $ this ->array_union ($ post_groups , $ this ->_settings ->full_content_access_groups );
202- foreach ($ visibility_post_groups as $ group ){
203- $ result = $ result . "\t\t<bcc:visibilityGroup> " . $ group . "</bcc:visibilityGroup> \n" ;
204- }
170+ if ($ visibility == BCC_Login_Visibility::VISIBILITY_PUBLIC ) {
171+ return ; // No groups for public posts
205172 }
206173
207- if (in_array ($ post ->post_type , $ this ->_settings ->notification_post_types )){
208- // Notification Groups: Groups that are checked on posts + are eligable for notification
209- $ notification_groups = array_intersect ($ post_groups , $ this ->_settings ->notification_groups );
210- foreach ($ notification_groups as $ group ){
211- $ result = $ result . "\t\t<bcc:notificationGroup> " . $ group . "</bcc:notificationGroup> \n" ;
174+ // Target Groups: the primary groups that the KPIs are measured for
175+ if (is_array ($ post_target_groups )) {
176+ foreach ($ post_target_groups as $ group ) {
177+ $ result .= "\t\t<bcc:targetGroup> " . $ group . "</bcc:targetGroup> \n" ;
212178 }
213179 }
214180
181+ // Visibility Groups: the secondary groups which can view the post
182+ if (is_array ($ post_visibility_groups ) && count ($ post_visibility_groups )) {
183+ $ visibility_groups = $ this ->_settings ->array_union ($ post_visibility_groups , $ this ->_settings ->full_content_access_groups );
184+
185+ foreach ($ visibility_groups as $ group ) {
186+ $ result .= "\t\t<bcc:visibilityGroup> " . $ group . "</bcc:visibilityGroup> \n" ;
187+ }
188+ }
215189 }
190+
216191 echo $ result ;
217192 }
218193
0 commit comments