-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.php
More file actions
328 lines (293 loc) · 11.4 KB
/
Copy pathstart.php
File metadata and controls
328 lines (293 loc) · 11.4 KB
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<?php
// Make sure the vacancy initialisation function is called on initialisation
elgg_register_event_handler('init', 'system', 'vacancy_init');
class ApplicationsVacancyPluginFile extends ElggFile
{
protected function initialiseAttributes()
{
parent::initialise_attributes();
$this->attributes['subtype'] = "vacancy_application_file";
$this->attributes['class'] = "ElggFile";
}
public function __construct($guid = null)
{
if ($guid && !is_object($guid)) {
// Loading entities via __construct(GUID) is deprecated, so we give it the entity row and the
// attribute loader will finish the job. This is necessary due to not using a custom
// subtype (see above).
$guid = get_entity_as_row($guid);
}
parent::__construct($guid);
}
}
class ZipsVacancyPluginFile extends ElggFile
{
protected function initialiseAttributes()
{
parent::initialise_attributes();
$this->attributes['subtype'] = "vacancy_zips_file";
$this->attributes['class'] = "ElggFile";
}
public function __construct($guid = null)
{
if ($guid && !is_object($guid)) {
// Loading entities via __construct(GUID) is deprecated, so we give it the entity row and the
// attribute loader will finish the job. This is necessary due to not using a custom
// subtype (see above).
$guid = get_entity_as_row($guid);
}
parent::__construct($guid);
}
}
/**
* Vacancy initialization
*/
function vacancy_init() {
// Set up menu for logged in users
$item = new ElggMenuItem('vacancy', elgg_echo('vacancies'), 'vacancy/all');
elgg_register_menu_item('site', $item);
// Add a menu item to the user ownerblock
elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'vacancy_owner_block_menu');
// Extend system CSS with our own styles, which are defined in the vacancy/css view
elgg_extend_view('css/elgg', 'vacancy/css');
// Register a page handler, so we can have nice URLs
elgg_register_page_handler('vacancy', 'vacancy_page_handler');
// Register a URL handler for vacancies posts
elgg_register_plugin_hook_handler('entity:url', 'object', 'vacancy_url');
// Register entity types
elgg_register_entity_type('object', 'company');
elgg_register_entity_type('object', 'vacancy');
elgg_register_entity_type('object', 'vacancy_applications');
elgg_register_entity_type('object', 'vacancy_application_file');
elgg_register_entity_type('object', 'vacancy_zips_file');
// Add group menu option
add_group_tool_option('vacancy', elgg_echo('vacancy:enable_group_vacancies'), true);
elgg_extend_view('groups/tool_latest', 'vacancy/group_module');
// Advanced permissions
elgg_register_plugin_hook_handler('permissions_check', 'object', 'vacancy_permissions_check');
// Add items to menu filter
elgg_register_plugin_hook_handler('register', 'menu:filter', 'vacancy_add_groups');
elgg_register_plugin_hook_handler('register', 'menu:filter', 'vacancy_add_opens');
// Remove items from menu filter
elgg_register_plugin_hook_handler('register', 'menu:filter', 'vacancy_delete_friends');
// Register a plugin hook handler for the entity menu
elgg_register_plugin_hook_handler('register', 'menu:entity', 'register_my_entity_menu_handler');
// Add a widget
elgg_register_widget_type('vacancy', elgg_echo('vacancies'), elgg_echo('vacancy:widget:description'));
// Register library
elgg_register_library('vacancy', elgg_get_plugins_path() . 'vacancy/lib/vacancy_lib.php');
run_function_once("vacancy_application_file_add_subtype_run_once");
run_function_once("vacancy_zips_file_add_subtype_run_once");
}
function vacancy_application_file_add_subtype_run_once()
{
add_subtype("object", "vacancy_application_file", "ApplicationsVacancyPluginFile");
}
function vacancy_zips_file_add_subtype_run_once()
{
add_subtype("object", "vacancy_zips_file", "ZipsVacancyPluginFile");
}
/**
* Advanced permissions
*/
function vacancy_permissions_check($hook, $type, $return, $params) {
if (($params['entity']->getSubtype() == 'vacancy')||($params['entity']->getSubtype() == 'vacancy_application')||($params['entity']->getSubtype() == 'vacancy_application_file')||($params['entity']->getSubtype() == 'form_answer')||($params['entity']->getSubtype() == 'form_response_file')) {
$user_guid = elgg_get_logged_in_user_guid();
$container_guid = $params['entity']->container_guid;
$container = get_entity($container_guid);
if ($container instanceof ElggGroup) {
$group_owner_guid = $container->owner_guid;
$operator=false;
if (($group_owner_guid==$user_guid)||(check_entity_relationship($user_guid,'group_admin',$container_guid))){
$operator=true;
}
if ($operator){
return true;
}
} else {
if (($params['entity']->getSubtype() == 'vacancy_application')||($params['entity']->getSubtype() == 'vacancy_application_file')) {
$vacancy_guid = $params['entity']->vacancy_guid;
$vacancy = get_entity($vacancy_guid);
if ($vacancy->owner_guid == $user_guid)
return true;
}
}
}
}
/**
* Add a menu item to the user ownerblock
*/
function vacancy_owner_block_menu($hook, $type, $return, $params) {
if (elgg_instanceof($params['entity'], 'user')) {
$url = "vacancy/owner/{$params['entity']->username}";
$item = new ElggMenuItem('vacancy', elgg_echo('vacancies'), $url);
$return[] = $item;
} else {
if ($params['entity']->vacancy_enable != "no") {
$url = "vacancy/group/{$params['entity']->guid}/all";
$item = new ElggMenuItem('vacancy', elgg_echo('vacancy:group'), $url);
$return[] = $item;
}
}
return $return;
}
/**
* Add items to menu filter
*/
function vacancy_add_groups($hook, $type, $return, $params) {
if ((elgg_get_context() === 'vacancy')) {
$return[] = ElggMenuItem::factory(array(
'name' => 'groups',
'href' => "vacancy/groups",
'text' => elgg_echo('vacancy:my_groups'),
'priority' => 1000,
));
}
return $return;
}
function vacancy_add_opens($hook, $type, $return, $params) {
if ((elgg_get_context() === 'vacancy')) {
$return[] = ElggMenuItem::factory(array(
'name' => 'open',
'href' => "vacancy/open",
'text' => elgg_echo("vacancy:opened_vacancies"),
'priority' => 1050,
));
}
return $return;
}
/**
* Remove items from menu filter
*/
function vacancy_delete_friends($hook, $type, $return, $params) {
if ((elgg_get_context() === 'vacancy')) {
$remove = array('friend');
foreach($return as $key => $item) {
if (in_array($item->getName(), $remove)) {
unset($return[$key]);
}
}
}
return $return;
}
/**
* Vacancy page handler; allows the use of fancy URLs
*
* @param array $page From the page_handler function
* @return true|false Depending on success
*/
function vacancy_page_handler($page) {
if (isset($page[0])) {
elgg_push_breadcrumb(elgg_echo('vacancies'));
$base_dir = elgg_get_plugins_path() . 'vacancy/pages/vacancy';
switch ($page[0]) {
case "view":
set_input('guid', $page[1]);
include "$base_dir/read.php";
break;
case "owner":
set_input('username', $page[1]);
include "$base_dir/owner.php";
break;
case "group":
set_input('container_guid', $page[1]);
include "$base_dir/owner.php";
break;
case "all":
include "$base_dir/everyone.php";
break;
case "add":
set_input('container_guid', $page[1]);
include "$base_dir/add.php";
break;
case "edit":
set_input('guid', $page[1]);
include "$base_dir/edit.php";
break;
case "filter":
set_input('container_guid', $page[1]);
include "$base_dir/filter.php";
break;
case "show_filter":
set_input('container_guid', $page[1]);
include "$base_dir/show_filter.php";
break;
case "groups":
include "$base_dir/groups.php";
break;
case "open":
include "$base_dir/open.php";
break;
case 'add_company':
set_input('container_guid',$page[1]);
include "$base_dir/add_company.php";
break;
case 'edit_company':
set_input('container_guid',$page[1]);
include "$base_dir/edit_company.php";
break;
case 'accept_reject':
set_input('guid', $page[1]);
set_input('member_guid', $page[2]);
set_input('offset', $page[3]);
include "$base_dir/accept_reject.php";
break;
default:
return false;
}
} else {
forward();
}
return true;
}
/**
* Populates the ->getUrl() method for vacancy objects
*
* @param ElggEntity $vacancy Vacancy entity
* @return string Vacancy URL
*/
function vacancy_url($hook, $type, $url, $params) {
$entity = $params['entity'];
// Check that the entity is a vacancy object
if ($entity->getSubtype() !== 'vacancy') {
return;
}
$title = elgg_get_friendly_title($entity->title);
$url = elgg_get_config('url');
return $url . "vacancy/view/" . $entity->getGUID() . "/" . $title;
}
// Vacancy opened or closed?
function vacancy_check_status($vacancy)
{
if ((strcmp($vacancy->option_close_value, 'vacancy_close_date') == 0)) {
$now = time();
if (($now >= $vacancy->activate_time) && ($now < $vacancy->close_time)) {
return true;
} else {
if ($vacancy->action == true) {
$vacancy->option_close_value = '';
$vacancy->action = false;
$vacancy->opened = true;
return true;
}
return false;
}
} else {
$vacancy->action = false;
return $vacancy->opened;
}
}
// Register actions
$action_base = elgg_get_plugins_path() . 'vacancy/actions/vacancy';
elgg_register_action("vacancy/edit", "$action_base/edit.php", 'logged_in');
elgg_register_action("vacancy/delete", "$action_base/delete.php", 'logged_in');
elgg_register_action("vacancy/add_company", "$action_base/add_company.php", 'logged_in');
elgg_register_action("vacancy/edit_company", "$action_base/edit_company.php", 'logged_in');
elgg_register_action("vacancy/open", "$action_base/open.php");
elgg_register_action("vacancy/close", "$action_base/close.php");
elgg_register_action("vacancy/apply", "$action_base/apply.php");
elgg_register_action("vacancy/delete_application", "$action_base/delete_application.php");
elgg_register_action("vacancy/get_zips", "$action_base/get_zips.php");
elgg_register_action("vacancy/zip_all", "$action_base/zip_all.php");
elgg_register_action("vacancy/filter", "$action_base/filter.php");
elgg_register_action("vacancy/accept_reject", "$action_base/accept_reject.php");