-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.php
405 lines (325 loc) · 12 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
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<?php
/**
* CloudIntegration Plugin
*/
// TODO
// Si desactivas Cloud en un grupo con ficheros vinculados aparece en la lista All (no deberia de ser así)
// Cuando borras un archivo desde su view devuelve que no existe (por que ya no existe una entidad asociada a esa url)
// ¿Que hacer si el enlace no funciona?
// Multivinculo de un mismo archivo (compartir el mismo archivo en diferentes grupos...)
// Añadir Multicuenta (Diferentes credenciales)
namespace HLV;
const PLUGIN_ID = 'cloudintegration';
const PLUGIN_URI = 'cloud';
// Class Handlers
Cloud\Encrypt\EncryptHandler::SET_HANDLER('\HLV\Cloud\Encrypt\OpenSSL');
Cloud\User\CredentialsHandler::SET_HANDLER('\HLV\Cloud\User\Credentials');
// Encrypt Seed
Cloud\Encrypt\EncryptHandler::SET_SEED('?2Yr:SZ-B:gUPLwz=~`#B_!VJZ;[a!4&GA72}^^P]YDnz#_{}Q4774Jh"Y>gd4]<');
//register the plugin hook handler
elgg_register_event_handler('init', 'system', __NAMESPACE__.'\\init');
/**
* plugin init function
*/
function init() {
// extend css && js
elgg_extend_view('css/elgg', PLUGIN_ID.'/style.css');
elgg_extend_view('js/elgg', PLUGIN_ID.'/script.js');
// site menu
if(Functions::SETTING_BOOL('enable_users')){
elgg_register_menu_item('site', array(
'name' => PLUGIN_ID,
'text' => elgg_echo('cloudintegration'),
'href' => PLUGIN_URI.'/all',
));
}
// routing of urls
elgg_register_page_handler(PLUGIN_URI, __NAMESPACE__.'\\page_handler');
// add CloudIntegration link to
elgg_register_plugin_hook_handler('register', 'menu:owner_block', __NAMESPACE__.'\\owner_block_menu');
// override the default url to view a blog object
elgg_register_plugin_hook_handler('entity:url', 'object', __NAMESPACE__.'\\set_url');
// Register a plugin hook handler for the entity menu
elgg_register_plugin_hook_handler('register', 'menu:entity', __NAMESPACE__.'\\menu_handler');
// Register for notifications
elgg_register_notification_event('object', PLUGIN_ID, array('create'));
elgg_register_plugin_hook_handler('prepare', 'notification:create:object:'.PLUGIN_ID , __NAMESPACE__.'\\prepare_notification');
// Register for search.
elgg_register_entity_type('object', PLUGIN_ID);
// Add group option
add_group_tool_option(PLUGIN_ID, elgg_echo('cloudintegration:group:tool:option:enable'), true);
// Extend group main page
elgg_extend_view('groups/tool_latest', PLUGIN_ID.'/group_module');
// Add Shares widget
elgg_register_widget_type( 'shares',
elgg_echo('cloudintegration:widgets:shares:name'),
elgg_echo('cloudintegration:widgets:shares:description'),
array('dashboard'), // Context
true); // Multiple
elgg_register_widget_type( 'metaShare',
elgg_echo('cloudintegration:widgets:metashares:name'),
elgg_echo('cloudintegration:widgets:metashares:description'),
array('all'), // Context
true); // Multiple
// Actions
elgg_register_action(PLUGIN_ID."/share", __DIR__ . "/actions/".PLUGIN_ID."/share.php");
elgg_register_action(PLUGIN_ID."/unshare", __DIR__ . "/actions/".PLUGIN_ID."/unshare.php");
elgg_register_action(PLUGIN_ID."/edit", __DIR__ . "/actions/".PLUGIN_ID."/edit.php");
elgg_register_action(PLUGIN_ID."/visibility", __DIR__ . "/actions/".PLUGIN_ID."/visibility.php");
// Ajax View
elgg_register_ajax_view('forms/'.PLUGIN_ID.'/share');
elgg_register_ajax_view('forms/'.PLUGIN_ID.'/unshare');
// ecml
elgg_register_plugin_hook_handler('get_views', 'ecml', __NAMESPACE__.'\\ecml_views_hook');
// allow to be liked
elgg_register_plugin_hook_handler('likes:is_likable', 'object:'.PLUGIN_ID , 'Elgg\Values::getTrue');
}
/*
* Dispatches plugin pages.
* URLs take the form of
* All cloudintegration: cloud/all
* User's cloudintegration: cloud/owner/<username>
* Friends' cloudintegration: cloud/friends/<username>
* view file cloudintegration: cloud/view/<guid>/<title>
* New file cloudintegration: cloud/add/<guid>
* Edit file cloudintegration: cloud/edit/<guid>
* Group cloudintegration: cloud/group/<guid>/all
*
* Title is ignored
*
* @param array $page
* @return bool
*/
function page_handler($page) {
$page_type = elgg_extract(0, $page, 'all');
$resource_vars = [
'page_type' => $page_type,
];
switch ($page_type) {
case 'owner':
if(Functions::SETTING_BOOL('enable_users')){
$resource_vars['username'] = elgg_extract(1, $page);
$resource_vars['webdavpath'] = elgg_extract(2, $page);
elgg_push_breadcrumb(elgg_echo('cloudintegration'), PLUGIN_URI.'/all');
echo elgg_view_resource(PLUGIN_ID.'/owner', $resource_vars);
}else{
return false;
}
break;
case 'friends':
if(Functions::SETTING_BOOL('enable_users') && elgg_is_logged_in()){
$resource_vars['username'] = elgg_extract(1, $page);
elgg_push_breadcrumb(elgg_echo('cloudintegration'), PLUGIN_URI.'/all');
echo elgg_view_resource(PLUGIN_ID.'/friends', $resource_vars);
}else{
return false;
}
break;
case 'view':
$resource_vars['guid'] = elgg_extract(1, $page);
elgg_push_breadcrumb(elgg_echo('cloudintegration'), PLUGIN_URI.'/all');
echo elgg_view_resource(PLUGIN_ID.'/view', $resource_vars);
break;
case 'add':
if(elgg_is_logged_in()){
$resource_vars['guid'] = elgg_extract(1, $page);
$resource_vars['webdavpath'] = elgg_extract(2, $page);
elgg_push_breadcrumb(elgg_echo('cloudintegration'), PLUGIN_URI.'/all');
echo elgg_view_resource(PLUGIN_ID.'/add', $resource_vars);
}else{
return false;
}
break;
case 'edit':
if(elgg_is_logged_in()){
$resource_vars['guid'] = elgg_extract(1, $page);
elgg_push_breadcrumb(elgg_echo('cloudintegration'), PLUGIN_URI.'/all');
echo elgg_view_resource(PLUGIN_ID.'/edit', $resource_vars);
}else{
return false;
}
break;
case 'group':
$resource_vars['page_type'] = elgg_extract(0, $page);
$resource_vars['group_guid'] = elgg_extract(1, $page);
$resource_vars['subpage'] = elgg_extract(2, $page);
$resource_vars['lower'] = elgg_extract(3, $page);
$resource_vars['upper'] = elgg_extract(4, $page);
// Breadcrumb for groups
$g_entity = get_entity($resource_vars['group_guid']);
elgg_push_breadcrumb(elgg_echo('cloudintegration:group').' '.$g_entity->name, PLUGIN_URI.'/group/'.$resource_vars['group_guid'].'/all');
echo elgg_view_resource(PLUGIN_ID.'/group', $resource_vars);
break;
case 'all':
if(Functions::SETTING_BOOL('enable_users')){
elgg_push_breadcrumb(elgg_echo('cloudintegration'), PLUGIN_URI.'/all');
echo elgg_view_resource(PLUGIN_ID.'/all', $resource_vars);
}else{
return false;
}
break;
default:
return false;
}
return true;
}
/**
* Add a menu item to an ownerblock
*/
function owner_block_menu($hook, $type, $return, $params) {
if (elgg_instanceof($params['entity'], 'user')) {
if(Functions::SETTING_BOOL('enable_users')){
$url = PLUGIN_URI."/owner/{$params['entity']->username}";
$item = new \ElggMenuItem(PLUGIN_ID, elgg_echo('cloudintegration'), $url);
$return[] = $item;
}
} else {
if ($params['entity']->{PLUGIN_ID.'_enable'} != "no") {
$url = PLUGIN_URI."/group/{$params['entity']->guid}/all";
$item = new \ElggMenuItem(PLUGIN_ID, elgg_echo('cloudintegration:group'), $url);
$return[] = $item;
}
}
return $return;
}
/**
* Format and return the URL for CloudIntegration.
*
* @param string $hook
* @param string $type
* @param string $url
* @param array $params
* @return string URL of Ownlcoud.
*/
function set_url($hook, $type, $url, $params) {
$entity = $params['entity'];
if (elgg_instanceof($entity, 'object', PLUGIN_ID)) {
$friendly_title = elgg_get_friendly_title($entity->title);
return PLUGIN_URI."/view/{$entity->guid}/$friendly_title";
}
}
/**
* Customize the entity menu for CloudIntegration objects
*/
function menu_handler($hook, $type, $menu, $params) {
// The entity can be found from the $params parameter
$entity = $params['entity'];
// We want to modify only the ElggOW objects, so we
// return immediately if the entity is something else
$handler = elgg_extract('handler', $params, false);
if ($handler != PLUGIN_URI) {
return $return;
}
$context = null;
foreach ($menu as $key => $item) {
switch ($item->getName()) {
case 'edit':
// Change the "Edit" text into a custom icon
$item->setText(elgg_view_icon('pencil'));
$context = $item->getContext();
//unset($menu[$key]);
break;
case 'delete':
// Remove the "Delete" menu item
unset($menu[$key]);
break;
}
}
// Get options data
$container = get_entity($entity->container_guid);
$canEdit = $container->canEdit();
$visible = filter_var($entity->visible, FILTER_VALIDATE_BOOLEAN);
$displayV = 'display:block;';
$displayI = 'display:none;';
if(!$visible){
$displayV = 'display:none;';
$displayI = 'display:block;';
}
if($canEdit){
// Visibility button
$optionsVisible = array(
'id' => 'civisible'.$entity->guid,
'name' => 'visible',
'title' => elgg_echo('cloudintegration:visible:true'),
'text' => elgg_view_icon('eye'),
'style' => $displayV,
'link_class' => 'ciiconvisiblefix',
'onclick' => 'CloudIntegration.visibility('.$entity->guid.',false);return false;',
'priority' => 100,
);
$Visible = \ElggMenuItem::factory($optionsVisible);
$Visible->addItemClass("cilivisiblefix");
$Visible->setContext($context);
// Invisibility button
$optionsInvisible = array(
'id' => 'ciinvisible'.$entity->guid,
'name' => 'invisible',
'title' => elgg_echo('cloudintegration:visible:false'),
'text' => elgg_view_icon('eye-slash'),
'style' => $displayI,
'link_class' => 'ciiconvisiblefix',
'onclick' => 'CloudIntegration.visibility('.$entity->guid.',true);return false;',
'priority' => 100,
);
$Invisible = \ElggMenuItem::factory($optionsInvisible);
$Invisible->addItemClass("cilivisiblefix");
$Invisible->setContext($context);
// Sort icons
$menu[] = $Invisible;
$menu[] = $Visible;
// Unshare
$optionsUnshare = array(
'id' => 'ciunshare'.$entity->guid,
'name' => 'unshare',
'title' => elgg_echo('cloudintegration:unshare'),
'text' => elgg_view_icon('share-alt-square'),
'href' => 'ajax/form/'.PLUGIN_ID.'/unshare?guid='.$entity->guid,
'priority' => 1010,
'link_class' => 'elgg-lightbox owlink',
'data-colorbox-opts' => json_encode([
'title' => elgg_echo('cloudintegration:unshare'),
'min-width' => '300px',
'max-width' => '600px',
]),
);
$Unshare = \ElggMenuItem::factory($optionsUnshare);
$Unshare->setContext($context);
$menu[] = $Unshare;
}
return $menu;
}
/**
* Prepare a notification message about a new owncloud metadata
*
* @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 prepare_notification($hook, $type, $notification, $params) {
$entity = $params['event']->getObject();
$owner = $params['event']->getActor();
$recipient = $params['recipient'];
$language = $params['language'];
$method = $params['method'];
// Title for the notification
$notification->subject = elgg_echo('cloudintegration:notify:subject', array($entity->title), $language);
// Message body for the notification
$notification->body = elgg_echo('cloudintegration:notify:body', array(
$owner->name,
$entity->title,
$entity->getExcerpt(),
$entity->getURL()
), $language);
// Short summary about the notification
$notification->summary = elgg_echo('cloudintegration:notify:summary', array($entity->title), $language);
return $notification;
}
/**
* Register CloudIntegration with ECML.
*/
function ecml_views_hook($hook, $entity_type, $return_value, $params) {
$return_value['object/'.PLUGIN_ID] = elgg_echo('cloudintegration:cloudintegrations');
return $return_value;
}