Skip to content

Commit 9b8656d

Browse files
committed
upgrade for Elgg 1.10+
1 parent 9ee990d commit 9b8656d

File tree

4 files changed

+91
-114
lines changed

4 files changed

+91
-114
lines changed

CHANGES.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
x.x:
44

5-
2.0.0 (10/16/2-15):
5+
3.0.0 (10/16/2015):
6+
- Upgrade for Elgg 1.10+
7+
- use view vars hooks for page/components/list filtering
8+
9+
2.0.0 (10/16/2015):
610
- Upgrade for Elgg 1.9+
711

812
1.2 ():

manifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<id>river_privacy</id>
55
<author>Matt Beckett</author>
66
<email>matt@mattbeckett.me</email>
7-
<version>2.0.0</version>
7+
<version>3.0.0</version>
88
<description>Sets non-object oriented river items to private access (eg. friend relationships)</description>
99
<website>http://landing.athabascau.ca</website>
1010
<copyright>(C) Matt Beckett, 2012</copyright>
@@ -13,7 +13,7 @@
1313
<!-- All plugins must require either elgg_version or elgg_release. -->
1414
<requires>
1515
<type>elgg_release</type>
16-
<version>1.9</version>
16+
<version>1.10</version>
1717
</requires>
1818

1919
<category>Miscellaneous</category>

start.php

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77
elgg_register_event_handler('init', 'system', __NAMESPACE__ . '\\init');
88

99
/**
10-
* Plugin Init
10+
* Plugin Init
1111
*/
1212
function 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+
}

views/default/page/components/list.php

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)