-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.php
167 lines (131 loc) · 4.07 KB
/
start.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/**
* Elgg Consents factory plugin
*
* @package Elgg-consents_factory
*/
elgg_register_event_handler('init', 'system', 'consents_factory');
/**
* elgg-consents_factory init
*/
function consents_factory() {
$root = dirname(__FILE__);
elgg_register_library('elgg:consents_factory', "$root/lib/consents_factory.php");
// actions
$action_path = "$root/actions/consents_factory";
elgg_register_action('consents_factory/save', "$action_path/save.php");
elgg_register_action('consents_factory/delete', "$action_path/delete.php");
elgg_register_action('consents_factory/vote_clarification', "$action_path/vote_clarification.php");
// menus
elgg_register_menu_item('site', array(
'name' => 'consents_factory',
'text' => elgg_echo('decision'),
'href' => 'decision/all'
));
elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'consents_factory_owner_block_menu');
elgg_register_page_handler('decision', 'consents_factory_page_handler');
elgg_extend_view('css/elgg', 'consents_factory/css');
elgg_extend_view('js/elgg', 'consents_factory/js');
elgg_register_widget_type('consents_factory', elgg_echo('decision'), elgg_echo('decision:widget:description'));
// Register granular notification for this type
register_notification_object('object', 'decision', elgg_echo('decision:new'));
// Register a URL handler for decision
elgg_register_entity_url_handler('object', 'decision', 'decision_url');
// Register entity type for search
elgg_register_entity_type('object', 'decision');
// Groups
add_group_tool_option('consents_factory', elgg_echo('decision:enableconsents_factory'), false);
elgg_extend_view('groups/tool_latest', 'consents_factory/group_module');
}
/**
* Dispatcher for decision.
*
* URLs take the form of
* All decision: decision/all
* User's decision: decision/owner/<username>
* Friends' decision: decision/friends/<username>
* View decision: decision/view/<guid>/<title>
* New decision: decision/add/<guid> (container: user, group, parent)
* Edit decision: decision/edit/<guid>
* Group decision: decision/group/<guid>/all
*
* Title is ignored
*
* @param array $page
* @return bool
*/
function consents_factory_page_handler($page) {
if (!isset($page[0])) {
$page[0] = 'all';
}
elgg_load_library('elgg:consents_factory');
elgg_push_breadcrumb(elgg_echo('decision'), 'decision/all');
elgg_push_context('consents_factory');
$pages = dirname(__FILE__) . '/pages/consents_factory';
switch ($page[0]) {
case "all":
include "$pages/all.php";
break;
case "owner":
include "$pages/owner.php";
break;
case "friends":
include "$pages/friends.php";
break;
case "view":
set_input('guid', $page[1]);
include "$pages/view.php";
break;
case "add":
gatekeeper();
include "$pages/add.php";
break;
case "edit":
gatekeeper();
set_input('guid', $page[1]);
include "$pages/edit.php";
break;
case 'group':
group_gatekeeper();
include "$pages/owner.php";
break;
default:
return false;
}
elgg_pop_context();
return true;
}
/**
* Populates the ->getUrl() method for decision objects
*
* @param ElggEntity $entity The decision object
* @return string decision item URL
*/
function decision_url($entity) {
global $CONFIG;
$title = $entity->title;
$title = elgg_get_friendly_title($title);
return $CONFIG->url . "decision/view/" . $entity->getGUID() . "/" . $title;
}
/**
* Add a menu item to an ownerblock
*
* @param string $hook
* @param string $type
* @param array $return
* @param array $params
*/
function consents_factory_owner_block_menu($hook, $type, $return, $params) {
if (elgg_instanceof($params['entity'], 'user')) {
$url = "decision/owner/{$params['entity']->username}";
$item = new ElggMenuItem('decision', elgg_echo('decision'), $url);
$return[] = $item;
} else {
if ($params['entity']->consents_factory_enable != 'no') {
$url = "decision/group/{$params['entity']->guid}/all";
$item = new ElggMenuItem('decision', elgg_echo('decision:group'), $url);
$return[] = $item;
}
}
return $return;
}