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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
|
<?php
/**
* Elgg tidypics
*
* @license GPL2
*/
// set some simple defines
define('TP_OLD_ALBUM', 0);
define('TP_NEW_ALBUM', 1);
// include core libraries
require dirname(__FILE__) . "/lib/tidypics.php";
require dirname(__FILE__) . "/classes/TidypicsImage.php";
require dirname(__FILE__) . "/classes/TidypicsAlbum.php";
// Make sure tidypics_init is called on initialization
register_elgg_event_handler('init', 'system', 'tidypics_init');
/**
* Tidypics plugin initialization
*/
function tidypics_init() {
global $CONFIG;
// Set up menu for logged in users
if (isloggedin()) {
add_menu(elgg_echo('photos'), $CONFIG->wwwroot . "pg/photos/owned/" . $_SESSION['user']->username);
}
// Extend CSS
elgg_extend_view('css', 'tidypics/css');
// Extend hover-over and profile menu
elgg_extend_view('profile/menu/links','tidypics/hover_menu');
//group view ** psuedo widget view for group pages**
elgg_extend_view('groups/right_column','tidypics/groupprofile_albums');
// rss extensions
elgg_extend_view('extensions/xmlns', 'extensions/tidypics/xmlns');
elgg_extend_view('extensions/channel', 'extensions/tidypics/channel');
// Register a page handler, so we can have nice URLs
register_page_handler('photos','tidypics_page_handler');
// register for menus
register_elgg_event_handler('pagesetup', 'system', 'tidypics_submenus');
register_elgg_event_handler('pagesetup', 'system', 'tidypics_adminmenu');
// Add a new tidypics widget
add_widget_type('album_view', elgg_echo("tidypics:widget:albums"), elgg_echo("tidypics:widget:album_descr"), 'profile');
add_widget_type('latest_photos', elgg_echo("tidypics:widget:latest"), elgg_echo("tidypics:widget:latest_descr"), 'profile');
// Register a URL handler for files
register_entity_url_handler('tidypics_image_url', 'object', 'image');
register_entity_url_handler('tidypics_album_url', 'object', 'album');
// add the class files for image and album
add_subtype("object", "image", "TidypicsImage");
add_subtype("object", "album", "TidypicsAlbum");
// Register entity type
register_entity_type('object','image');
register_entity_type('object','album');
add_group_tool_option('photos', elgg_echo('tidypics:enablephotos'), true);
if (get_plugin_setting('grp_perm_override', 'tidypics') != "disabled") {
register_plugin_hook('permissions_check', 'object', 'tidypics_permission_override');
}
// Register for notifications
register_notification_object('object', 'album', elgg_echo('tidypics:newalbum'));
register_plugin_hook('notify:entity:message', 'object', 'tidypics_notify_message');
// slideshow plugin hook
register_plugin_hook('tp_slideshow', 'album', 'tidypics_slideshow');
// ajax handler for uploads when use_only_cookies is set
register_plugin_hook('forward', 'system', 'tidypics_ajax_session_handler');
// Register actions
$base_dir = $CONFIG->pluginspath . "tidypics/actions";
register_action("tidypics/upload", false, "$base_dir/upload.php");
register_action("tidypics/ajax_upload", true, "$base_dir/ajax_upload.php");
register_action("tidypics/ajax_upload_complete", true, "$base_dir/ajax_upload_complete.php");
register_action("tidypics/addalbum", false, "$base_dir/addalbum.php");
register_action("tidypics/sortalbum", false, "$base_dir/sortalbum.php");
register_action("tidypics/edit", false, "$base_dir/edit.php");
register_action("tidypics/delete", false, "$base_dir/delete.php");
register_action("tidypics/edit_multi", false, "$base_dir/edit_multi.php");
register_action("tidypics/addtag", false, "$base_dir/addtag.php");
register_action("tidypics/deletetag", false, "$base_dir/deletetag.php");
register_action("tidypics/admin/settings", false, "$base_dir/admin/settings.php", true);
register_action("tidypics/admin/upgrade", false, "$base_dir/admin/upgrade.php", true);
}
/**
* Sets up sidebar menus for tidypics. Triggered on pagesetup.
*/
function tidypics_submenus() {
global $CONFIG;
$page_owner = page_owner_entity();
if ($page_owner instanceof ElggGroup) {
if (get_context() == "groups") {
if ($page_owner->photos_enable != "no") {
add_submenu_item( sprintf(elgg_echo('album:group'),$page_owner->name),
$CONFIG->wwwroot . "pg/photos/owned/" . $page_owner->username);
}
}
}
// context is only set to photos on individual pages, not on group pages
else if (get_context() == "photos") {
$view_count = get_plugin_setting('view_count', 'tidypics');
// owner gets "your albumn", "your friends albums", "your most recent", "your most viewed"
if (get_loggedin_userid() && get_loggedin_userid() == $page_owner->guid) {
add_submenu_item( elgg_echo('album:create'),
$CONFIG->wwwroot . "pg/photos/new/{$page_owner->username}/",
'tidypics-a' );
add_submenu_item( elgg_echo("album:yours"),
$CONFIG->wwwroot . "pg/photos/owned/{$page_owner->username}/",
'tidypics-a' );
add_submenu_item( elgg_echo('album:yours:friends'),
$CONFIG->wwwroot . "pg/photos/friends/{$page_owner->username}/",
'tidypics-a');
add_submenu_item( elgg_echo('tidypics:yourmostrecent'),
$CONFIG->wwwroot . "pg/photos/mostrecent/{$page_owner->username}/",
'tidypics-a');
if ($view_count != 'disabled') {
add_submenu_item( elgg_echo('tidypics:yourmostviewed'),
$CONFIG->wwwroot . "pg/photos/mostviewed/{$page_owner->username}/",
'tidypics-a');
}
} else if (isloggedin()) {
$user = get_loggedin_user();
// logged in not owner gets "page owners albums", "page owner's friends albums", "page owner's most viewed", "page owner's most recent"
// and then "your albums", "your most recent", "your most viewed"
add_submenu_item( elgg_echo("album:yours"),
$CONFIG->wwwroot . "pg/photos/owned/{$user->username}/",
'tidypics-b' );
add_submenu_item( elgg_echo('tidypics:yourmostrecent'),
$CONFIG->wwwroot . "pg/photos/mostrecent/{$user->username}/",
'tidypics-b');
if ($view_count != 'disabled') {
add_submenu_item( elgg_echo('tidypics:yourmostviewed'),
$CONFIG->wwwroot . "pg/photos/mostviewed/{$user->username}/",
'tidypics-b');
}
if ($page_owner->name) { // check to make sure the owner set their display name
add_submenu_item( sprintf(elgg_echo("album:user"), $page_owner->name),
$CONFIG->wwwroot . "pg/photos/owned/{$page_owner->username}/",
'tidypics-a' );
add_submenu_item( sprintf(elgg_echo('album:friends'),$page_owner->name),
$CONFIG->wwwroot . "pg/photos/friends/{$page_owner->username}/",
'tidypics-a');
if ($view_count != 'disabled') {
add_submenu_item( sprintf(elgg_echo('tidypics:friendmostviewed'),$page_owner->name),
$CONFIG->wwwroot . "pg/photos/mostviewed/{$page_owner->username}/",
'tidypics-a');
}
add_submenu_item( sprintf(elgg_echo('tidypics:friendmostrecent'),$page_owner->name),
$CONFIG->wwwroot . "pg/photos/mostrecent/{$page_owner->username}/",
'tidypics-a');
}
} else if ($page_owner->guid) {
// non logged in user gets "page owners albums", "page owner's friends albums"
add_submenu_item( sprintf(elgg_echo("album:user"), $page_owner->name),
$CONFIG->wwwroot . "pg/photos/owned/{$page_owner->username}/",
'tidypics-a' );
add_submenu_item( sprintf(elgg_echo('album:friends'),$page_owner->name),
$CONFIG->wwwroot . "pg/photos/friends/{$page_owner->username}/",
'tidypics-a');
}
// everyone gets world albums, most recent, most viewed, most recently viewed, recently commented
add_submenu_item( elgg_echo('album:all'),
$CONFIG->wwwroot . "pg/photos/world/",
'tidypics-z');
add_submenu_item( elgg_echo('tidypics:mostrecent'),
$CONFIG->wwwroot . 'pg/photos/mostrecent/',
'tidypics-z');
if ($view_count != 'disabled') {
add_submenu_item( elgg_echo('tidypics:mostviewed'),
$CONFIG->wwwroot . 'pg/photos/mostviewed/',
'tidypics-z');
add_submenu_item( elgg_echo('tidypics:recentlyviewed'),
$CONFIG->wwwroot . 'pg/photos/recentlyviewed/',
'tidypics-z');
}
add_submenu_item( elgg_echo('tidypics:recentlycommented'),
$CONFIG->wwwroot . 'pg/photos/recentlycommented/',
'tidypics-z');
}
}
/**
* Sets up tidypics admin menu. Triggered on pagesetup.
*/
function tidypics_adminmenu() {
global $CONFIG;
if (get_context() == 'admin' && isadminloggedin()) {
add_submenu_item(elgg_echo('tidypics:administration'), $CONFIG->url . "pg/photos/admin/");
}
}
/**
* Sets up submenus for tidypics most viewed pages
*/
function tidypics_mostviewed_submenus() {
global $CONFIG;
add_submenu_item(elgg_echo('tidypics:mostvieweddashboard'), $CONFIG->url . "mod/tidypics/mostvieweddashboard.php");
add_submenu_item(elgg_echo('tidypics:mostviewedthisyear'), $CONFIG->url . "mod/tidypics/pages/lists/mostviewedimagesthisyear.php");
add_submenu_item(elgg_echo('tidypics:mostviewedthismonth'), $CONFIG->url . "mod/tidypics/pages/lists/mostviewedimagesthismonth.php");
add_submenu_item(elgg_echo('tidypics:mostviewedlastmonth'), $CONFIG->url . "mod/tidypics/pages/lists/mostviewedimageslastmonth.php");
add_submenu_item(elgg_echo('tidypics:mostviewedtoday'), $CONFIG->url . "mod/tidypics/pages/lists/mostviewedimagestoday.php");
add_submenu_item(elgg_echo('tidypics:mostcommented'), $CONFIG->url . "mod/tidypics/pages/lists/mostcommentedimages.php");
add_submenu_item(elgg_echo('tidypics:mostcommentedthismonth'), $CONFIG->url . "mod/tidypics/pages/lists/mostcommentedimagesthismonth.php");
add_submenu_item(elgg_echo('tidypics:mostcommentedtoday'), $CONFIG->url . "mod/tidypics/pages/lists/mostcommentedimagestoday.php");
add_submenu_item(elgg_echo('tidypics:recentlycommented'), $CONFIG->wwwroot . 'pg/photos/recentlycommented/');
}
/**
* tidypics page handler
*
* @param array $page Array of page elements, forwarded by the page handling mechanism
*/
function tidypics_page_handler($page) {
global $CONFIG;
if (isset($page[0])) {
switch($page[0]) {
case "owned": //view list of albums owned by container
if (isset($page[1])) {
set_input('username', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/ownedalbums.php");
break;
case "view": //view an image individually
if (isset($page[1])) {
set_input('guid', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/viewimage.php");
break;
case "album": //view an album individually
if (isset($page[1])) {
set_input('guid', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/viewalbum.php");
break;
case "sort": //sort a photo album
if (isset($page[1])) {
set_input('guid', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/sortalbum.php");
break;
case "new": //create new album
if (isset($page[1])) {
set_input('username', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/newalbum.php");
break;
case "upload": //upload images to album
if (isset($page[1])) {
set_input('album_guid', $page[1]);
}
if (isset($page[2])) {
set_input('uploader', 'basic');
}
include($CONFIG->pluginspath . "tidypics/pages/upload.php");
break;
case "edit": //edit image or album
if (isset($page[1])) {
set_input('guid', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/edit.php");
break;
case "batch": //update titles and descriptions
if (isset($page[1])) {
set_input('batch', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/edit_multiple.php");
break;
case "friends": // albums of friends
if (isset($page[1])) {
set_input('username', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/friends.php");
break;
case "world": // all site albums
include($CONFIG->pluginspath . "tidypics/pages/world.php");
break;
case "download": // download an image
if (isset($page[1])) {
set_input('file_guid', $page[1]);
}
if (isset($page[2])) {
set_input('type', $page[2]);
}
include($CONFIG->pluginspath . "tidypics/pages/download.php");
break;
case "thumbnail": // tidypics thumbnail
if (isset($page[1])) {
set_input('file_guid', $page[1]);
}
if (isset($page[2])) {
set_input('size', $page[2]);
}
include($CONFIG->pluginspath . "tidypics/pages/thumbnail.php");
break;
case "tagged": // all photos tagged with user
if (isset($page[1])) {
set_input('guid', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/tagged.php");
break;
case "mostviewed": // images with the most views
if (isset($page[1])) {
set_input('username', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/lists/mostviewedimages.php");
break;
case "mostrecent": // images uploaded most recently
if (isset($page[1])) {
set_input('username', $page[1]);
}
include($CONFIG->pluginspath . "tidypics/pages/lists/mostrecentimages.php");
break;
case "recentlyviewed": // images most recently viewed
include($CONFIG->pluginspath . "tidypics/pages/lists/recentlyviewed.php");
break;
case "recentlycommented": // images with the most recent comments
include($CONFIG->pluginspath . "tidypics/pages/lists/recentlycommented.php");
break;
case "highestrated": // images with the highest average rating
include($CONFIG->pluginspath . "tidypics/pages/lists/highestrated.php");
break;
case "admin":
include ($CONFIG->pluginspath . "tidypics/pages/admin.php");
break;
}
}
else {
// going to all site albums if something goes wrong with the page handler
include($CONFIG->pluginspath . "tidypics/pages/world.php");
}
return true;
}
/**
* Override permissions for group albums and images
*
* @param string $hook
* @param string $type
* @param bool $result
* @param array $params
* @return mixed
*/
function tidypics_permission_override($hook, $type, $result, $params) {
$entity = $params['entity'];
$user = $params['user'];
if ($entity->subtype == get_subtype_id('object', 'album')) {
// test that the user can edit the container
return can_write_to_container(0, $entity->container_guid);
}
if ($entity->subtype == get_subtype_id('object', 'image')) {
// test that the user can edit the container
return can_write_to_container(0, $entity->container_guid);
}
}
/**
* Notification message handler
* @param string $hook
* @param string $type
* @param bool $result
* @param array $params
* @return mixed
*/
function tidypics_notify_message($hook, $type, $result, $params) {
$entity = $params['entity'];
$to_entity = $params['to_entity'];
$method = $params['method'];
if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'album')) {
// block notification message when the album doesn't have any photos
if ($entity->new_album == TP_NEW_ALBUM) {
return false;
}
$descr = $entity->description;
$title = $entity->title;
$owner = $entity->getOwnerEntity();
return sprintf(elgg_echo('album:river:created'), $owner->name) . ': ' . $title . "\n\n" . $descr . "\n\n" . $entity->getURL();
}
return null;
}
/**
* Populates the ->getUrl() method for file objects
* Registered in the init function
*
* @param ElggEntity $entity album/image entity
* @return string File URL
*/
function tidypics_image_url($entity) {
global $CONFIG;
$title = $entity->title;
$title = friendly_title($title);
return $CONFIG->url . "pg/photos/view/" . $entity->getGUID() . "/" . $title;
}
function tidypics_album_url($entity) {
global $CONFIG;
$title = $entity->title;
$title = friendly_title($title);
return $CONFIG->url . "pg/photos/album/" . $entity->getGUID() . "/" . $title;
}
/**
* Catch the plugin hook and add the default album slideshow
*
* @param $hook - 'tidypics:slideshow'
* @param $entity_type - 'album'
* @param $returnvalue - if set, return because another plugin has used the hook
* @param $params - arry containing album entity
* @return unknown_type
*/
function tidypics_slideshow($hook, $entity_type, $returnvalue, $params) {
if ($returnvalue !== null) {
// someone has already added a slideshow or requested that the slideshow is not used
return $returnvalue;
}
$url = current_page_url();
if (strpos($url, '?')) {
$url = substr($url, 0, strpos($url, '?'));
}
$url = "$url?limit=50&view=rss";
$slideshow_link = "javascript:PicLensLite.start({maxScale:0,feedUrl:'$url'})";
// add the slideshow javascript to the header
elgg_extend_view('metatags', 'tidypics/js/slideshow');
return $slideshow_link;
}
/**
* Convenience function for listing recent images
*
* @param int $max
* @param bool $pagination
* @return string
*/
function tp_mostrecentimages($max = 8, $pagination = true) {
return list_entities("object", "image", 0, $max, false, false, $pagination);
}
/**
* Work around for Flash/session issues
*
* @param string $hook
* @param string $entity_type
* @param string $returnvalue
* @param array $params
*/
function tidypics_ajax_session_handler($hook, $entity_type, $returnvalue, $params) {
global $CONFIG;
$url = current_page_url();
if ($url !== "{$CONFIG->wwwroot}action/tidypics/ajax_upload/") {
return;
}
if (get_loggedin_userid() != 0) {
return;
}
// action_gatekeeper rejected ajax call from Flash due to session issue
// Validate token
$token = get_input('__elgg_token');
$ts = get_input('__elgg_ts');
$session_id = get_input('Elgg');
$tidypics_token = get_input('tidypics_token');
$user_guid = get_input('user_guid');
$user = get_user($user_guid);
if (!$user) {
return;
}
if (!$token || !$ts || !$session_id || !$tidypics_token) {
return;
}
$hour = 60*60;
$now = time();
if ($ts < $now-$hour || $ts > $now+$hour) {
return;
}
$generated_token = md5($session_id . get_site_secret() . $ts . $user->salt);
if ($tidypics_token !== $generated_token) {
return;
}
// passed token test, so login and process action
login($user);
include $CONFIG->actions['tidypics/ajax_upload']['file'];
exit;
}
|