-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.php
executable file
·262 lines (228 loc) · 8.54 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
/* Notes
* General vocabulary is :
* poll => survey
* question => question
* vote => response (annotation "response", action "response", responded)
*/
elgg_register_event_handler('init','system','survey_init');
function survey_init() {
elgg_register_library('elgg:survey', elgg_get_plugins_path() . 'survey/lib/survey/functions.php');
// Set up menu
elgg_register_menu_item('site', array('name' => 'survey', 'href' => 'survey/all', 'text' => elgg_echo('survey')));
// Extend system CSS with our own styles, which are defined in the survey/css view
elgg_extend_view('css/elgg','survey/css');
// Extend hover-over menu
elgg_extend_view('profile/menu/links','survey/menu');
// Register a page handler, so we can have nice URLs
elgg_register_page_handler('survey','survey_page_handler');
// Register a URL handler for survey posts
elgg_register_plugin_hook_handler('entity:url', 'object', 'survey_url');
// notifications
$send_notification = elgg_get_plugin_setting('send_notification', 'survey');
if (!$send_notification || $send_notification != 'no') {
elgg_register_notification_event('object', 'survey', array('create'));
elgg_register_plugin_hook_handler('prepare', 'notification:publish:object:survey', 'survey_prepare_notification');
}
// add link to owner block
elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'survey_owner_block_menu');
// Register entity type
elgg_register_entity_type('object','survey');
// register the JavaScript (autoloaded in 1.10)
$js = elgg_get_simplecache_url('js', 'survey/survey');
elgg_register_simplecache_view('js/survey/survey');
elgg_register_js('elgg.survey.survey', $js);
$js = elgg_get_simplecache_url('js', 'survey/edit');
elgg_register_simplecache_view('js/survey/edit');
elgg_register_js('elgg.survey.edit', $js);
// add group widget
$group_survey = elgg_get_plugin_setting('group_survey', 'survey');
if (!$group_survey || $group_survey != 'no') {
elgg_extend_view('groups/tool_latest', 'survey/group_module');
}
if (!$group_survey || ($group_survey == 'yes_default')) {
add_group_tool_option('survey', elgg_echo('survey:enable_survey'), true);
} else if ($group_survey == 'yes_not_default') {
add_group_tool_option('survey', elgg_echo('survey:enable_survey'), false);
}
//add widgets
// @TODO
/*
elgg_register_widget_type('survey', elgg_echo('survey:my_widget_title'), elgg_echo('survey:my_widget_description'));
elgg_register_widget_type('latestsurvey', elgg_echo('survey:latest_widget_title'), elgg_echo('survey:latest_widget_description'), array("dashboard"));
$survey_front_page = elgg_get_plugin_setting('front_page','survey');
if ($survey_front_page == 'yes') {
elgg_register_widget_type('survey_individual', elgg_echo('survey:individual'), elgg_echo('survey_individual:widget:description'), array("dashboard"));
}
if (elgg_is_active_plugin('widget_manager')) {
elgg_register_widget_type('latestsurvey_index', elgg_echo('survey:latest_widget_title'), elgg_echo('survey:latest_widget_description'), array("index"));
if (!$group_survey || $group_survey != 'no') {
elgg_register_widget_type('latestgroupsurvey', elgg_echo('survey:latestgroup_widget_title'), elgg_echo('survey:latestgroup_widget_description'), array("groups"));
}
if ($survey_front_page == 'yes') {
elgg_register_widget_type('survey_individual_index', elgg_echo('survey:individual'), elgg_echo('survey_individual:widget:description'), array("index"));
}
//register title urls for widgets
elgg_register_plugin_hook_handler('widget_url', 'widget_manager', "survey_widget_urls", 499);
//elgg_register_plugin_hook_handler("entity:url", "object", "survey_widget_urls"); // Elgg 1.10
}
*/
// Register actions
$action_path = elgg_get_plugins_path() . 'survey/actions/survey';
elgg_register_action("survey/edit", "$action_path/edit.php");
elgg_register_action("survey/delete", "$action_path/delete.php");
elgg_register_action("survey/response", "$action_path/response.php");
}
/**
* survey page handler; allows the use of fancy URLs
*
* @param array $page From the page_handler function
* @return true|false Depending on success
*/
function survey_page_handler($page) {
elgg_load_library('elgg:survey');
elgg_push_breadcrumb(elgg_echo('item:object:survey'), "survey/all");
$page_type = $page[0];
if (empty($page_type)) { $page_type = 'all'; }
switch($page_type) {
case "view":
echo survey_get_page_view($page[1]);
break;
case "all":
echo survey_get_page_list($page_type);
break;
case "add":
case "edit":
$container = null;
if (isset($page[1])) { $container = $page[1]; }
echo survey_get_page_edit($page_type, $container);
break;
case "results":
$guid = $filter = $filter_guid = false;
if (isset($page[1])) { $guid = $page[1]; }
if (isset($page[2])) { $filter = $page[2]; }
if (isset($page[3])) { $filter_guid = $page[3]; }
echo survey_get_page_results($guid, $filter, $filter_guid);
break;
case "export":
$guid = false;
if (isset($page[1])) { $guid = $page[1]; }
echo survey_get_page_export($guid);
break;
case "friends":
case "owner":
$username = $page[1];
$user = get_user_by_username($username);
$user_guid = $user->guid;
echo survey_get_page_list($page_type, $user_guid);
break;
case "group":
echo survey_get_page_list($page_type, $page[1]);
break;
default:
$user = get_user_by_username($page_type);
if ($user instanceof ElggUser) {
if (isset($page[1])) {
switch($page[1]) {
case "read":
forward("/survey/view/{$page[2]}");
break;
case "friends":
forward("/survey/friends/{$user->username}");
break;
}
// If the URL is just 'survey/username' forward to surveys page of this user
} else {
forward("/survey/owner/{$user->username}");
break;
}
}
return false;
break;
}
return true;
}
/**
* Return the url for survey objects
*/
function survey_url($hook, $type, $url, $params) {
$entity = $params['entity'];
if (elgg_instanceof($entity, 'object', 'survey')) {
// default to a standard view if no owner.
if (!$entity->getOwnerEntity()) { return false; }
$title = elgg_get_friendly_title($entity->title);
return "survey/view/" . $entity->guid . "/" . $title;
}
}
/**
* Add a menu item to an owner block
*/
function survey_owner_block_menu($hook, $type, $return, $params) {
if (elgg_instanceof($params['entity'], 'user')) {
$url = "survey/owner/{$params['entity']->username}";
$item = new ElggMenuItem('survey', elgg_echo('survey'), $url);
$return[] = $item;
} else {
elgg_load_library('elgg:survey');
if (survey_activated_for_group($params['entity'])) {
$url = "survey/group/{$params['entity']->guid}/all";
$item = new ElggMenuItem('survey', elgg_echo('survey:group_survey'), $url);
$return[] = $item;
}
}
return $return;
}
/**
* Prepare a notification message about a created survey
*
* @param string $hook Hook name
* @param string $type Hook type
* @param Elgg_Notifications_Notification $notification The notification to prepare
* @param array $params Hook parameters
* @return Elgg_Notifications_Notification
*/
function survey_prepare_notification($hook, $type, $notification, $params) {
$entity = $params['event']->getObject();
$owner = $params['event']->getActor();
$recipient = $params['recipient'];
$language = $params['language'];
$method = $params['method'];
$notification->subject = elgg_echo('survey:notify:subject', array($entity->title), $language);
$notification->body = elgg_echo('survey:notify:body', array(
$owner->name,
$entity->title,
$entity->getURL()
), $language);
$notification->summary = elgg_echo('survey:notify:summary', array($entity->title), $language);
return $notification;
}
function survey_widget_urls($hook_name, $entity_type, $return_value, $params) {
$result = $return_value;
$widget = $params["entity"];
if (empty($result) && ($widget instanceof ElggWidget)) {
$owner = $widget->getOwnerEntity();
switch($widget->handler) {
case "survey":
if (elgg_instanceof($owner, 'user')) {
$result = "/survey/owner/{$owner->username}/all";
} else {
$result = "/survey/all";
}
break;
case "latestsurvey":
case "survey_individual":
case "latestsurvey_index":
case "survey_individual_index":
$result = "/survey/all";
break;
case "latestgroupsurvey":
if (elgg_instanceof($owner, 'group')) {
$result = "/survey/group/{$owner->guid}/all";
} else {
$result = "/survey/owner/{$owner->username}/all";
}
break;
}
}
return $result;
}