-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.php
265 lines (220 loc) · 8.33 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
261
262
263
264
265
<?php
/**
* Elgg tasks plugin
*
* @package Elggtasks
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Fx NION AND Anirup Dutta
* @link http://fxnion.free.fr/
*/
// tasks initialisation function
function tasks_init() {
// Grab the config file
global $CONFIG;
elgg_extend_view('metatags','tasks/js');
// for 1.7 use this instead
// elgg_extend_view('metatags','tasks/js');
//add a tools menu option
if (isloggedin())
add_menu(elgg_echo('tasks'), $CONFIG->wwwroot . "mod/tasks/tasks.php");
// Register a page handler, so we can have nice URLs
register_page_handler('tasks','tasks_page_handler');
// Add our CSS
elgg_extend_view('css','tasks/css');
// Add to groups context
elgg_extend_view('groups/left_column', 'tasks/groupprofile_tasks');
// Register granular notification for this type
if (is_callable('register_notification_object'))
register_notification_object('object', 'tasks', elgg_echo('tasks:new'));
// Listen to notification events and supply a more useful message
register_plugin_hook('notify:entity:message', 'object', 'tasks_notify_message');
// Register a URL handler for shared items
register_entity_url_handler('task_url','object','tasks');
// Shares widget
add_widget_type('tasks',elgg_echo("tasks:recent"),elgg_echo("tasks:widget:description"));
// Register entity type
register_entity_type('object','tasks');
// Add group menu option
add_group_tool_option('tasks',elgg_echo('tasks:enabletasks'),true);
}
function tasks_pagesetup() {
global $CONFIG;
// Set up menu for logged in users
//add submenu options
if (get_context() == "tasks") {
if (isloggedin()) {
if (page_owner()) {
$page_owner = page_owner_entity();
$user = $_SESSION['user'];
if (is_plugin_enabled('profile_manager')) {
$user_type = get_entity($user->custom_profile_type);
echo $user_type;
if ($user_type) {
$user_type = $user_type->getTitle();
}
}
if($user_type || isadminloggedin()){
add_submenu_item(sprintf(elgg_echo('tasks:read'), $page_owner->name),$CONFIG->wwwroot."pg/tasks/" . $page_owner->username . "/items");
}
}
}
if ((isloggedin()) && (page_owner()) && (can_write_to_container(0, page_owner()))) {
$page_owner = page_owner_entity();
// Ajout de Fx pour créer des tasks vierges
if($user_type || isadminloggedin()){
add_submenu_item(sprintf(elgg_echo("tasks:add"),$page_owner->name), $CONFIG->wwwroot . "pg/tasks/" . $page_owner->username . '/add'.'?container_guid='.$page_owner->getGUID());
}
}
if(!$page_owner instanceof ElggGroup){
add_submenu_item(elgg_echo('tasks:everyone'),$CONFIG->wwwroot."mod/tasks/everyone.php");
add_submenu_item(elgg_echo('Search based on Skill'),$CONFIG->wwwroot."mod/tasks/tasks.php");
}
}
$page_owner = page_owner_entity();
if ($page_owner instanceof ElggGroup && get_context() == 'groups') {
if($page_owner->tasks_enable != "no"){
if($user_type){
add_submenu_item(sprintf(elgg_echo("tasks:group"),$page_owner->name), $CONFIG->wwwroot . "pg/tasks/" . $page_owner->username . '/items');
}
}
}
}
/**
* tasks page handler; allows the use of fancy URLs
*
* @param array $page From the page_handler function
* @return true|false Depending on success
*/
function tasks_page_handler($page) {
// The first component of a tasks URL is the username
if (isset($page[0])) {
set_input('username',$page[0]);
}
// The second part dictates what we're doing
if (isset($page[1])) {
switch($page[1]) {
case "read": set_input('guid',$page[2]);
@include(dirname(dirname(dirname(__FILE__))) . "/entities/index.php"); return true;
break;
case "items": @include(dirname(__FILE__) . "/index.php"); return true;
break;
case "add": @include(dirname(__FILE__) . "/add.php"); return true;
break;
case "manage": @include(dirname(__FILE__) . "/manage.php"); return true;
break;
}
// If the URL is just 'tasks/username', or just 'tasks/', load the standard tasks index
} else {
@include(dirname(__FILE__) . "/index.php");
return true;
}
return false;
}
/**
* Populates the ->getUrl() method for tasked objects
*
* @param ElggEntity $entity The tasked object
* @return string tasked item URL
*/
function task_url($entity) {
global $CONFIG;
$title = $entity->title;
$title = friendly_title($title);
return $CONFIG->url . "pg/tasks/" . $entity->getOwnerEntity()->username . "/read/" . $entity->getGUID() . "/" . $title;
}
/**
* Returns a more meaningful message
*
* @param unknown_type $hook
* @param unknown_type $entity_type
* @param unknown_type $returnvalue
* @param unknown_type $params
*/
function tasks_notify_message($hook, $entity_type, $returnvalue, $params)
{
$entity = $params['entity'];
$to_entity = $params['to_entity'];
$method = $params['method'];
if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'tasks'))
{
$descr = $entity->description;
$title = $entity->title;
global $CONFIG;
$url = $CONFIG->wwwroot . "pg/view/" . $entity->guid;
if ($method == 'sms') {
$owner = $entity->getOwnerEntity();
return $owner->username . ' ' . elgg_echo("tasks:via") . ': ' . $url . ' (' . $title . ')';
}
if ($method == 'email') {
$owner = $entity->getOwnerEntity();
return $owner->username . ' ' . elgg_echo("tasks:via") . ': ' . $title . "\n\n" . $descr . "\n\n" . $entity->getURL();
}
if ($method == 'web') {
$owner = $entity->getOwnerEntity();
return $owner->username . ' ' . elgg_echo("tasks:via") . ': ' . $title . "\n\n" . $descr . "\n\n" . $entity->getURL();
}
}
return null;
}
/**
* Extend permissions checking to extend can-edit for write users.
*
* @param unknown_type $hook
* @param unknown_type $entity_type
* @param unknown_type $returnvalue
* @param unknown_type $params
*/
function tasks_write_permission_check($hook, $entity_type, $returnvalue, $params)
{
if ($params['entity']->getSubtype() == 'tasks') {
$write_permission = $params['entity']->write_access_id;
$user = $params['user'];
if (($write_permission) && ($user))
{
// $list = get_write_access_array($user->guid);
$list = get_access_array($user->guid); // get_access_list($user->guid);
if (($write_permission!=0) && (in_array($write_permission,$list)))
return true;
}
}
}
/**
* Extend container permissions checking to extend can_write_to_container for write users.
*
* @param unknown_type $hook
* @param unknown_type $entity_type
* @param unknown_type $returnvalue
* @param unknown_type $params
*/
function tasks_container_permission_check($hook, $entity_type, $returnvalue, $params) {
if (get_context() == "tasks") {
if (page_owner()) {
if (can_write_to_container($_SESSION['user']->guid, page_owner())) return true;
}
if ($page_guid = get_input('page_guid',0)) {
$entity = get_entity($page_guid);
} else if ($parent_guid = get_input('parent_guid',0)) {
$entity = get_entity($parent_guid);
}
if ($entity instanceof ElggObject) {
if (
can_write_to_container($_SESSION['user']->guid, $entity->container_guid)
|| in_array($entity->write_access_id,get_access_list())
) {
return true;
}
}
}
}
// write permission plugin hooks
register_plugin_hook('permissions_check', 'object', 'tasks_write_permission_check');
register_plugin_hook('container_permissions_check', 'object', 'tasks_container_permission_check');
// Make sure the initialisation function is called on initialisation
register_elgg_event_handler('init','system','tasks_init');
register_elgg_event_handler('pagesetup','system','tasks_pagesetup');
// Register actions
global $CONFIG;
register_action('tasks/add',false,$CONFIG->pluginspath . "tasks/actions/add.php");
register_action('tasks/manage',false,$CONFIG->pluginspath . "tasks/actions/manage.php");
register_action('tasks/delete',false,$CONFIG->pluginspath . "tasks/actions/delete.php");
?>