77elgg_register_event_handler ('init ' , 'system ' , __NAMESPACE__ . '\\init ' );
88
99/**
10- * Plugin Init
10+ * Plugin Init
1111 */
1212function init () {
1313 // set the river item to private if it's not an object
1414 elgg_register_plugin_hook_handler ('creating ' , 'river ' , __NAMESPACE__ . '\\creating_river_hook ' );
15- }
1615
16+ // filter river views if necessary
17+ elgg_register_plugin_hook_handler ('view_vars ' , 'page/components/list ' , __NAMESPACE__ . '\\filter_list_vars ' );
18+
19+ // add access check back into the river queries
20+ elgg_register_plugin_hook_handler ('get_sql ' , 'access ' , __NAMESPACE__ . '\\river_access_query ' );
21+ }
1722
18-
1923/**
2024 * hook called before river creation
2125 * return associative array of parameters to create the river entry
@@ -34,3 +38,80 @@ function creating_river_hook($hook, $type, $returnvalue, $params) {
3438
3539 return $ returnvalue ;
3640}
41+
42+ /**
43+ * filter the items sent to a list view
44+ *
45+ * @param type $hook
46+ * @param type $type
47+ * @param type $return
48+ * @param type $params
49+ * @return type
50+ */
51+ function filter_list_vars ($ hook , $ type , $ return , $ params ) {
52+ $ filter_river = elgg_get_plugin_setting ('hide_old_items ' , PLUGIN_ID );
53+ if ($ filter_river == 'no ' ) {
54+ // no need to filter
55+ return $ return ;
56+ }
57+
58+ if ($ return ['items ' ] && is_array ($ return ['items ' ])) {
59+ foreach ($ return ['items ' ] as $ key => $ item ) {
60+ if (!($ item instanceof \ElggRiverItem)) {
61+ continue ;
62+ }
63+
64+ if ($ item ->type == 'object ' ) {
65+ continue ;
66+ }
67+
68+ if ($ item ->subject_guid == elgg_get_logged_in_user_guid ()) {
69+ continue ;
70+ }
71+
72+ if (elgg_is_admin_logged_in ()) {
73+ continue ;
74+ }
75+
76+ if (elgg_get_ignore_access ()) {
77+ continue ;
78+ }
79+
80+ unset($ return ['items ' ][$ key ]);
81+ }
82+ }
83+
84+ return $ return ;
85+ }
86+
87+ /**
88+ * Add a custom access clause for river queries
89+ *
90+ * @param type $hook
91+ * @param type $type
92+ * @param array $return
93+ * @param type $params
94+ * @return type
95+ */
96+ function river_access_query ($ hook , $ type , $ return , $ params ) {
97+
98+ // anything else we can use to isolate river queries?
99+ // currently 'oe' is only used in core by river queries
100+ // but it's not really a great way to judge...
101+ if ($ params ['table_alias ' ] != 'oe ' ) {
102+ return $ return ;
103+ }
104+
105+ if ($ params ['ignore_access ' ]) {
106+ return $ return ;
107+ }
108+
109+ if (elgg_is_admin_logged_in ()) {
110+ return $ return ;
111+ }
112+
113+ $ guid = (int ) elgg_get_logged_in_user_guid ();
114+ $ return ['ands ' ][] = "((rv.type != 'object' AND rv.subject_guid = {$ guid }) OR rv.access_id != 0) " ;
115+
116+ return $ return ;
117+ }
0 commit comments