/
Aeva-Gallery2.php
2793 lines (2457 loc) · 92.7 KB
/
Aeva-Gallery2.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
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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* More gallery-related actions.
* Uses portions written by Shitiz Garg.
*
* @package Wedge
* @copyright 2010 René-Gilles Deberdt, wedge.org
* @license http://wedge.org/license/
* @author see contributors.txt
*/
if (!defined('WEDGE'))
die('Hacking attempt...');
/*
This holds the secondary sub-actions in Aeva Media
void aeva_moveItems()
- Moves one or several items
void aeva_unseen()
- Shows the unseen items page
- Also handles Mark as Seen
void aeva_mgSearch()
- Handles the search/search results pages
void aeva_listAlbums()
- Shows all the albums, sorted by owner
void aeva_mgStats()
- Shows the statistics page
void aeva_albumCP()
- Shows the control panel for one's albums
- Allows users to add/edit/view their albums
void aeva_editAlbum()
- Edits an album...
void aeva_addAlbum(bool is_admin, bool is_add)
- A universal function to add/edit albums
- Used by all the album add/edit functions out there
- Use featured to specify whether the album is featured or not
- Use is_add to specify whether we are adding or editing the album
void aeva_moveAlbum()
- Oh, come on...
void aeva_deleteAlbum(int id, bool from_approval)
- Delete an album, its items and comments. Be careful!
- If called from the approval area (from_approval = true), an album ID is provided
void aeva_massUpload()
- Shows the mass upload page
- Also handles adding of items sent via the page as well as giving a return
void aeva_massUploadFinish()
- Updates titles sent after a mass upload
void aeva_profileSummary(int memID)
- Prepares the summary page for gallery user profiles
void aeva_profileItems(int memID)
- Retrieves all items for gallery user profiles
void aeva_profileComments(int memID)
- Retrieves all comments for gallery user profiles
void aeva_profileVotes(int memID)
- Handles viewing the rates for the specific member
void aeva_whoRatedWhat()
- Handles the Who Rated What page
void aeva_tagHelper()
- Shows the complete popup help page for the [media] BBCode tag
void aeva_massDownload()
- Handles the initialisation of multiple downloads, asks for user inputs
void aeva_massDownloadCreate()
- Creates the zip file for the supplied items
void aeva_massDownloadSend()
- Sends the file to the user once created
*/
function aeva_moveItems()
{
// Handles moving of items from one album to another
global $context, $galurl, $txt, $amSettings;
// Load the item's data
$ids = !empty($_POST['ids']) ? $_POST['ids'] : (array) (!empty($_GET['in']) ? (int) $_GET['in'] : 0);
$request = wesql::query('
SELECT
m.id_media, m.title, m.id_member, IFNULL(mem.real_name, m.member_name) AS member_name, a.name, a.id_album, m.id_file, m.type,
m.id_thumb, a.directory AS album_dir, f.filename, f.directory AS file_dir, t.filename AS thumb_file,
t.directory AS thumb_dir, m.id_preview, p.filename AS preview_file, p.directory AS preview_dir,
(a.icon = m.id_thumb) AS is_album_icon, (a.bigicon = m.id_preview) AS is_album_bigicon, a.master
FROM {db_prefix}media_items AS m
INNER JOIN {db_prefix}media_albums AS a ON (a.id_album = m.album_id)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}media_files AS f ON (f.id_file = m.id_file)
LEFT JOIN {db_prefix}media_files AS t ON (t.id_file = m.id_thumb)
LEFT JOIN {db_prefix}media_files AS p ON (p.id_file = m.id_preview)
WHERE m.id_media ' . (is_array($ids) ? 'IN ({array_int:media})' : '= {int:media}'),
array('media' => array_values($ids))
);
if (wesql::num_rows($request) == 0)
fatal_lang_error('media_item_not_found', !empty($amSettings['log_access_errors']));
$items = array();
$can_moderate = aeva_allowedTo('moderate');
$can_edit_own = aeva_allowedTo('edit_own_item');
while ($row = wesql::fetch_assoc($request))
if ($can_moderate || ($can_edit_own && $row['id_member'] == MID))
$items[] = $row;
wesql::free_result($request);
if (empty($items))
fatal_lang_error('media_edit_denied');
// Let's see what albums they can move to
$types = $ids = array();
$moving_link = '';
foreach ($items as $item)
{
$ids[] = $item['id_media'];
$types[$item['type']] = 'add_' . $item['type'] . 's';
$moving_link .= '<a href="' . $galurl . 'sa=item;in=' . $item['id_media'] . '">' . $item['title'] . '</a>, ';
}
$moving_link = substr($moving_link, 0, -2);
$allowed_albums = albumsAllowedTo($types, true);
aeva_getAlbums(aeva_allowedTo('moderate') ? '' : (empty($allowed_albums) ? '1=0' : 'a.id_album IN (' . implode(',', array_keys($allowed_albums)) . ')'), 1, false, 'a.album_of, a.child_level, a.a_order');
$albums = array();
$sep = $prev_owner = -1;
foreach ($context['aeva_album_list'] as $k => $list)
{
$new_owner = $context['aeva_albums'][$list]['owner']['id'];
if ($prev_owner != $new_owner)
{
if ($prev_owner > -1)
$albums['sep' . ++$sep] = array('', false, '');
$albums['sep' . ++$sep] = array($context['aeva_albums'][$list]['owner']['name'], false, 'begin');
$prev_owner = $new_owner;
}
$albums[$list] = array(str_repeat('-', $context['aeva_albums'][$list]['child_level']) . ' ' . $context['aeva_albums'][$list]['name'], false, $list == $items[0]['id_album'] ? ' disabled' : null);
}
$albums['sep' . ++$sep] = array('', false, '');
// Load up the form
$context['aeva_form_headers'] = array(
array($txt['media_moving_item'] . ': ' . $moving_link),
array(sprintf($txt['media_album_is'], '<a href="' . $galurl . 'sa=album;in=' . $items[0]['id_album'] . '">' . $items[0]['name'] . '</a>')),
);
$context['aeva_form_url'] = $galurl . 'sa=move';
$context['aeva_form'] = array(
'album_to_move' => array(
'type' => 'select',
'fieldname' => 'album',
'label' => $txt['media_album_to_move'],
'options' => $albums,
),
);
foreach ($items as $item)
$context['aeva_form']['ids_' . $item['id_media']] = array(
'fieldname' => 'ids[' . $item['id_media'] . ']',
'value' => $item['id_media'],
'skip' => true,
);
// Moving?
if (isset($_POST['submit_aeva']))
{
// Let's make sure it is in a correct album
$album_id = (int) $_POST['album'];
if (!isset($albums[$album_id]))
fatal_lang_error('media_invalid_album');
$perm = @$allowed_albums[$album_id];
// Everything verified, let's move them! First we will move the files, then the comments,
// then we'll update the album's stats and then we'll move the actual items... Phew!
foreach ($items as $i)
{
$main_file = $amSettings['data_dir_path'] . '/' . $i['file_dir'] . '/' . aeva_getEncryptedFilename($i['filename'], $i['id_file']);
// If file type is not supported by target album, or it's larger than the allowed quota, skip it!
// If user is a moderator, they probably know what they're doing -- allow them anything.
if (!$can_moderate && !isset($perm['perms']['add_' . $i['type'] . 's']))
continue;
if (!$can_moderate && isset($perm['quotas'][$i['type']]) && file_exists($main_file) && (filesize($main_file) / 1024) > $perm['quotas'][$i['type']])
continue;
// Files
if ($i['id_thumb'] > 4 && file_exists($amSettings['data_dir_path'] . '/' . $i['thumb_dir'] . '/' . aeva_getEncryptedFilename($i['thumb_file'], $i['id_thumb'], true)))
{
$new_dir = aeva_getSuitableDir($album_id);
$_new_dir = substr($new_dir, strlen($amSettings['data_dir_path']) + 1);
$success = rename(
$amSettings['data_dir_path'] . '/' . $i['thumb_dir'] . '/' . aeva_getEncryptedFilename($i['thumb_file'], $i['id_thumb'], true),
$new_dir . '/' . aeva_getEncryptedFilename($i['thumb_file'], $i['id_thumb'], true)
);
if (!$success)
fatal_lang_error('media_filemove_failed');
wesql::query('
UPDATE {db_prefix}media_files
SET id_album = {int:album}, directory = {string:dir}
WHERE id_file = {int:file}',
array(
'file' => $i['id_thumb'],
'dir' => $_new_dir,
'album' => $album_id,
)
);
}
if ($i['id_preview'] > 4 && file_exists($amSettings['data_dir_path'] . '/' . $i['preview_dir'] . '/' . aeva_getEncryptedFilename($i['preview_file'], $i['id_preview'])))
{
$new_dir = aeva_getSuitableDir($album_id);
$_new_dir = substr($new_dir, strlen($amSettings['data_dir_path']) + 1);
$success = rename(
$amSettings['data_dir_path'] . '/' . $i['preview_dir'] . '/' . aeva_getEncryptedFilename($i['preview_file'],
$i['id_preview']), $new_dir . '/' . aeva_getEncryptedFilename($i['preview_file'], $i['id_preview'])
);
if (!$success)
fatal_lang_error('media_filemove_failed');
wesql::query('
UPDATE {db_prefix}media_files
SET id_album = {int:album}, directory = {string:dir}
WHERE id_file = {int:file}',
array(
'file' => $i['id_preview'],
'dir' => $_new_dir,
'album' => $album_id,
)
);
}
if ($i['id_file'] != 0 && file_exists($main_file))
{
$new_dir = aeva_getSuitableDir($album_id);
$_new_dir = substr($new_dir, strlen($amSettings['data_dir_path']) + 1);
$success = rename(
$amSettings['data_dir_path'] . '/' . $i['file_dir'] . '/' . aeva_getEncryptedFilename($i['filename'],
$i['id_file']), $new_dir . '/' . aeva_getEncryptedFilename($i['filename'], $i['id_file'])
);
if (!$success)
fatal_lang_error('media_filemove_failed');
wesql::query('
UPDATE {db_prefix}media_files
SET id_album = {int:album}, directory = {string:dir}
WHERE id_file = {int:file}',
array(
'file' => $i['id_file'],
'dir' => $_new_dir,
'album' => $album_id,
)
);
}
// Update the comments!
wesql::query('
UPDATE {db_prefix}media_comments
SET id_album = {int:album}
WHERE id_media = {int:media}',
array('album' => $album_id, 'media' => $i['id_media'])
);
// Update the album stats!
wesql::query('
UPDATE {db_prefix}media_albums
SET num_items = num_items - 1' . (!empty($i['is_album_icon']) ? ', icon = 4' : '') . (!empty($i['is_album_bigicon']) ? ', bigicon = 0' : '') . '
WHERE id_album = {int:album}',
array('album' => $i['id_album'])
);
wesql::query('
UPDATE {db_prefix}media_albums
SET num_items = num_items + 1
WHERE id_album = {int:album}',
array('album' => $album_id)
);
// OK, done with everything, move the actual item!
wesql::query('
UPDATE {db_prefix}media_items
SET album_id = {int:album}
WHERE id_media = {int:media}',
array('album' => $album_id, 'media' => $i['id_media'])
);
}
// Log it -- we don't need to log more than ONE item being moved... Do we? :-/
$opts = array(
'type' => 'move',
'action_on' => array(
'id' => $items[0]['id_media'],
'name' => $items[0]['name'],
),
'action_by' => array(
'id' => MID,
'name' => we::$user['name'],
),
'extra_info' => array(
'val8' => $album_id . ',' . $context['aeva_albums'][$album_id]['name'],
'val9' => $items[0]['id_album'] . ',' . $items[0]['name'],
),
);
aeva_logModAction($opts);
// Redirect back to previous album
redirectexit($galurl . 'sa=album;in=' . $items[0]['id_album']);
}
// Linktree
$albums = array_reverse(aeva_getAlbumParents($items[0]['id_album'], $items[0]['master']));
foreach ($albums as $a)
add_linktree($a['name'], $galurl . 'sa=album;in=' . $a['id']);
add_linktree($items[0]['title'], $galurl . 'sa=item;in=' . $items[0]['id_media']);
add_linktree($txt['media_moving'], $galurl . 'sa=move;in=' . $items[0]['id_media']);
wetem::load('aeva_form');
}
function aeva_unseen()
{
// Handles the viewing of unseen files
global $galurl, $amSettings, $txt, $context;
is_not_guest();
$start = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
$album = isset($_REQUEST['album']) ? 'AND a.id_album = ' . (int) $_REQUEST['album'] : '';
$per_page = max(1, min(200, (int) $amSettings['num_items_per_page']));
if (isset($_REQUEST['markseen']))
{
checkSession('get');
aeva_markAllSeen();
redirectexit($galurl . 'sa=unseen');
}
if (!empty($_REQUEST['pageseen']))
{
checkSession('get');
$pageseen = explode(',', $_REQUEST['pageseen']);
foreach ($pageseen as $item)
if ((int) $item > 0)
media_markSeen((int) $item, 'force_insert');
media_resetUnseen(MID);
}
// Get the total items to show
$request = wesql::query('
SELECT COUNT(m.id_media)
FROM {db_prefix}media_items AS m
INNER JOIN {db_prefix}media_albums AS a ON (m.album_id = a.id_album)
LEFT JOIN {db_prefix}media_log_media AS lm ON (lm.id_media = m.id_media AND lm.id_member = {int:user})
LEFT JOIN {db_prefix}media_log_media AS lm_all ON (lm_all.id_media = 0 AND lm_all.id_member = {int:user})
WHERE {query_see_album}
AND IFNULL(lm.time, IFNULL(lm_all.time, 0)) < m.log_last_access_time
{raw:album}' . (!aeva_allowedTo('moderate') ? '
AND m.approved = 1' : '') . '
LIMIT 1', array('album' => $album, 'user' => MID)
);
list ($total_items) = wesql::fetch_row($request);
wesql::free_result($request);
if (empty($total_items) && we::$is_member)
{
// Quick test to see if we should optimize the log_media table...
$request = wesql::query('
SELECT id_media FROM {db_prefix}media_log_media WHERE id_media > 0 AND id_member = {int:user} LIMIT 1',
array('user' => MID)
);
list ($remaining) = wesql::fetch_row($request);
wesql::free_result($request);
if (empty($remaining))
aeva_markAllSeen();
}
// If we're asking for a page that doesn't exist, show the last one.
if ($total_items <= $start)
$start = floor(max(0, $total_items - 1) / $per_page) * $per_page;
// Now get the items!
$context['aeva_items'] = aeva_fillMediaArray(wesql::query('
SELECT
m.id_media, m.title, m.views, m.num_comments, m.id_member, m.time_added, m.approved, m.views, m.type, m.embed_url,
IFNULL(mem.real_name, m.member_name) AS member_name, a.id_album, a.name, f.width, f.height, m.voters, m.weighted AS rating,
m.id_thumb, f.directory AS thumb_dir, f.filename AS thumb_file, f.height AS thumb_height, f.transparency, (pt.width && pt.height) AS has_preview
FROM {db_prefix}media_items AS m
INNER JOIN {db_prefix}media_albums AS a ON (m.album_id = a.id_album)
LEFT JOIN {db_prefix}media_files AS f ON (f.id_file = m.id_thumb)
LEFT JOIN {db_prefix}media_files AS pt ON (pt.id_file = m.id_preview)
LEFT JOIN {db_prefix}media_log_media AS lm ON (lm.id_media = m.id_media AND lm.id_member = {int:user})
LEFT JOIN {db_prefix}media_log_media AS lm_all ON (lm_all.id_media = 0 AND lm_all.id_member = {int:user})
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE {query_see_album}
AND IFNULL(lm.time, IFNULL(lm_all.time, 0)) < m.log_last_access_time
{raw:album}' . (!aeva_allowedTo('moderate') ? '
AND m.approved = 1' : '') . '
ORDER BY m.log_last_access_time DESC
LIMIT {int:start}, {int:per_page}',
array('start' => $start, 'per_page' => $per_page, 'album' => $album, 'user' => MID)
));
$comment_list = array();
foreach ($context['aeva_items'] as $id => $dummy)
{
$context['aeva_items'][$id]['is_new'] = true;
$comment_list[] = $id;
}
if (!empty($comment_list))
{
// Get new comments per item
$request = wesql::query('
SELECT COUNT(c.id_comment) AS co, c.id_media
FROM {db_prefix}media_comments AS c
LEFT JOIN {db_prefix}media_log_media AS lm ON (lm.id_media = c.id_media AND lm.id_member = {int:user})
LEFT JOIN {db_prefix}media_log_media AS lm_all ON (lm_all.id_media = 0 AND lm_all.id_member = {int:user})
WHERE c.id_media IN (' . implode(',', $comment_list) . ')
AND IFNULL(lm.time, IFNULL(lm_all.time, 0)) < c.posted_on
GROUP BY c.id_media',
array('user' => MID)
);
while ($row = wesql::fetch_assoc($request))
$context['aeva_items'][$row['id_media']]['new_comments'] = $row['co'];
wesql::free_result($request);
}
$context['aeva_page_index'] = template_page_index($galurl . 'sa=unseen' . (isset($_REQUEST['album']) ? ';album=' . (int) $_REQUEST['album'] : ''), $start, $total_items, $per_page);
$context['page_title'] = $txt['media_viewing_unseen'];
wetem::load('aeva_unseen');
add_linktree($txt['media_viewing_unseen'], $galurl . 'sa=unseen');
}
// Handles searching of items
function aeva_mgSearch()
{
global $galurl, $txt, $amSettings, $context;
// Let's see what all albums they can search in
aeva_getAlbums();
$albums = array();
foreach ($context['aeva_album_list'] as $album)
$albums[$album] = str_repeat('-', $context['aeva_albums'][$album]['child_level']) . ' ' . $context['aeva_albums'][$album]['name'];
// Fields
$context['custom_fields'] = aeva_loadCustomFields(null, array(), 'cf.searchable = 1');
// Searching?
if (isset($_REQUEST['search']))
{
if (trim($_REQUEST['search']) == '')
fatal_lang_error('media_search_left_empty', false);
$joins = array();
if (isset($_REQUEST['sch_mem']) && empty($_REQUEST['sch_mem_list']))
$_REQUEST['sch_mem_list'] = explode(',', $_REQUEST['sch_mem']);
$filters = array(
'title' => isset($_REQUEST['sch_title']),
'desc' => isset($_REQUEST['sch_desc']),
'keywords' => isset($_REQUEST['sch_kw']),
'alname' => isset($_REQUEST['sch_an']),
'member' => isset($_REQUEST['sch_mem_list']) && is_array($_REQUEST['sch_mem_list']) ? $_REQUEST['sch_mem_list'] : false,
'album' => !empty($_REQUEST['sch_album']) ? (int) $_REQUEST['sch_album'] : false,
'custom_fields' => !empty($_REQUEST['fields']) && is_array($_REQUEST['fields']) ? $_REQUEST['fields'] : array(),
);
$search_query = array();
$searching_for = '%' . un_htmlspecialchars($_REQUEST['search']) . '%';
$test = false;
foreach ($filters as $f)
if (!empty($f))
$test = true;
// Some special stuff for query search via address
if (isset($_GET['search']) && !isset($_POST['search']) && $test === false)
{
$filters['title'] = true;
$filters['desc'] = true;
$test = true;
}
if ($test === false)
fatal_lang_error('media_no_search_option_selected', false);
$enclose = false;
if ($filters['keywords'])
$search_query[] = 'm.keywords LIKE {string:search}';
if ($filters['title'])
$search_query[] = 'm.title LIKE {string:search}';
if ($filters['desc'])
$search_query[] = 'm.description LIKE {string:search}';
if ($filters['alname'])
$search_query[] = 'a.name LIKE {string:search}';
if ($filters['member'])
{
$members_to_filter = array();
foreach ($filters['member'] as $mem)
$members_to_filter[(int) $mem] = (int) $mem;
if (!empty($members_to_filter))
{
$enclose = true;
$search_query_and[] = "m.id_member = {int:mem}";
}
else
fatal_lang_error('media_search_mem_not_found',false);
}
if ($filters['album'])
{
foreach ($albums as $k => $v)
if ($k == $filters['album'])
$found = true;
if (!isset($found))
fatal_lang_error('media_invalid_album');
$enclose = true;
$search_query_and[] = "m.album_id = {int:album}";
}
// Custom fields
$field_query = array();
if (!empty($filters['custom_fields']))
{
foreach ($filters['custom_fields'] as $k => $v)
{
$v = (int) $v;
if (!in_array($v, array_keys($context['custom_fields'])))
continue;
$key = 'cfd' . $v;
$joins[] = 'LEFT JOIN {db_prefix}media_field_data AS ' . $key . ' ON (' . $key . '.id_field = ' . $v . ' AND ' . $key . '.id_media = m.id_media)';
$field_query[] = 'fields[]=' . $v;
$search_query[] = $key . '.value LIKE {string:search}';
}
}
if (empty($search_query))
fatal_lang_error('media_item_not_found', !empty($amSettings['log_access_errors']));
// Make the real query
$query = '';
if ($enclose)
$query .= '(';
$query .= implode(' OR ', $search_query);
if ($enclose)
$query .= ') AND ' . implode(' AND ', $search_query_and);
// Perform the query now
$context['aeva_items'] = aeva_fillMediaArray(wesql::query('
SELECT
m.id_media, m.title, m.id_member, m.views, m.num_comments, m.approved, a.hidden,
IFNULL(mem.real_name, m.member_name) AS member_name, a.name, a.id_album, m.time_added,
IFNULL(lm.time, IFNULL(lm_all.time, 0)) < m.log_last_access_time AS is_new, f.width, f.height,
m.id_thumb, f.directory AS thumb_dir, f.filename AS thumb_file, f.transparency
FROM {db_prefix}media_items AS m
INNER JOIN {db_prefix}media_albums AS a ON (m.album_id = a.id_album)
LEFT JOIN {db_prefix}media_files AS f ON (f.id_file = m.id_thumb)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}media_log_media AS lm ON (lm.id_media = m.id_media AND lm.id_member = {int:user})
LEFT JOIN {db_prefix}media_log_media AS lm_all ON (lm_all.id_media = 0 AND lm_all.id_member = {int:user})' . (!empty($joins) ? '
' . implode('
', $joins) : '') . '
WHERE {query_see_album_hidden} AND (' . $query . ')' . (!aeva_allowedTo('moderate') ? '
AND m.approved = 1' : '') . '
ORDER BY m.id_media DESC
LIMIT {int:start}, {int:per_page}',
array('user' => MID, 'mem' => !empty($members_to_filter) ? implode(' OR m.id_member = ',$members_to_filter) : '', 'album' => $filters['album'],
'search' => $searching_for, 'start' => isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0, 'per_page' => empty($context['current_board']) ? 15 : 30)
));
// Pagination query
$request = wesql::query('
SELECT COUNT(m.id_media)
FROM {db_prefix}media_items AS m
INNER JOIN {db_prefix}media_albums AS a ON (m.album_id = a.id_album)' . (!empty($joins) ? implode('
', $joins) : '') . '
WHERE {query_see_album_hidden} AND (' . $query . ')' . (!aeva_allowedTo('moderate') ? '
AND m.approved = 1' : ''),
array(
'user' => MID,
'mem' => !empty($members_to_filter) ? implode(' OR m.id_member = ', $members_to_filter) : '',
'album' => $filters['album'],
'search' => $searching_for
)
);
list ($total_items) = wesql::fetch_row($request);
$pageindexURL = '<URL>' . (!empty($context['current_board']) ? '?board=' . $context['current_board'] . '.0;' : '?') . 'action=media;sa=search;search=' . urlencode($_REQUEST['search']);
if ($filters['album'])
$pageindexURL .= ';sch_album=' . $filters['album'];
if ($filters['title'])
$pageindexURL .= ';sch_title';
if ($filters['desc'])
$pageindexURL .= ';sch_desc';
if ($filters['keywords'])
$pageindexURL .= ';sch_kw';
if ($filters['alname'])
$pageindexURL .= ';sch_an';
if (!empty($members_to_filter))
$pageindexURL .= ';sch_mem=' . implode(',', $members_to_filter);
$pageindexURL .= ';' . implode(';', $field_query);
$start = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
$context['aeva_page_index'] = template_page_index($pageindexURL, $start, $total_items, empty($context['current_board']) ? 15 : 30);
wesql::free_result($request);
wetem::load('aeva_search_results');
$context['aeva_searching_for'] = westr::htmlspecialchars($_REQUEST['search']);
$context['aeva_total_results'] = $total_items;
// If we're in a board, means we're viewing a playlist... Then return a playlist.
if (!empty($context['current_board']))
{
$id_list = '';
foreach ($context['aeva_items'] as $i)
$id_list .= $i['id'] . ',';
$context['aeva_foxy_rendered_search'] = aeva_foxy_album(substr($id_list, 0, -1), 'ids');
if (!empty($context['aeva_page_index']) && strpos($context['aeva_page_index'], '<a') !== false)
$context['aeva_foxy_rendered_search'] = str_replace('<!-- aeva_page_index -->', '
<div class="pagesection">
<nav>' . $txt['pages'] . ': ' . $context['aeva_page_index'] . '</nav>
</div>', $context['aeva_foxy_rendered_search']);
}
}
else
{
wetem::load('aeva_search_searching');
$context['aeva_albums'] = $albums;
}
// Page title
$context['page_title'] = $txt['media_search'];
// Search linktree
add_linktree($txt['media_search'], $galurl . 'sa=search');
}
function aeva_listAlbums()
{
// Handles viewing of all the albums out there
global $txt, $galurl, $context;
// Just load it!
$start = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
// We support sorting, but it's not even mentioned on the page... Ain't we smart?
$sort_by = isset($_REQUEST['name']) ? 'a.name' : 'a.id_album';
$sort_order = isset($_REQUEST['asc']) ? 'ASC' : 'DESC';
$per_page = 15;
// Load all the albums..
aeva_getAlbums('', 1, true, 'a.album_of ASC, ' . $sort_by . ' ' . $sort_order, $start . ', ' . $per_page, true, true, true);
$context['aeva_user_albums'] = array();
foreach ($context['aeva_albums'] as $list)
$context['aeva_user_albums'][$list['owner']['id']][] = $list;
// Do another query for pagination
$request = wesql::query('
SELECT a.id_album
FROM {db_prefix}media_albums AS a
WHERE {query_see_album_nocheck}
AND a.child_level = 0' . (!aeva_allowedTo('moderate') ? '
AND ((a.approved = 1 AND a.hidden = 0) OR a.album_of = ' . MID . ')' : ''),
array()
);
$total_items = wesql::num_rows($request);
wesql::free_result($request);
// Construct the page index
$pageindexURL = $galurl . 'sa=vua';
if (isset($_REQUEST['name']))
$pageindexURL .= ';name';
if (isset($_REQUEST['asc']))
$pageindexURL .= ';asc';
$context['aeva_page_index'] = template_page_index($pageindexURL, $start, $total_items, $per_page);
// End this
wetem::load('aeva_viewUserAlbums');
add_linktree($txt['media_albums'], $galurl . 'sa=vua');
$context['page_title'] = $txt['media_albums'];
}
function aeva_mgStats()
{
// Handles the stat pages
global $amSettings, $context, $txt, $galurl;
/*******************************************************
Let's see what all we got at the stats page:
Normal stats like total comments, total items, total albums, total featured albums, avg items per day, avg comments per day, total item contributors, total comment contributors
Top 5 uploaders
Top 5 commentators
Top 5 albums by num items
Top 5 albums by num comments
Top 5 items by views
Top 5 items by comments
Top 5 items by rating
********************************************************/
// Get the stats
$days_started = round((time() - $amSettings['installed_on'])/ 86400);
$context['aeva_stats'] = array();
$context['aeva_stats'] = array(
'total_comments' => $amSettings['total_comments'],
'total_items' => $amSettings['total_items'],
'total_albums' => $amSettings['total_albums'],
'avg_items' => $days_started > 0 ? round($amSettings['total_items'] / $days_started, 2) : 0,
'avg_comments' => $days_started > 0 ? round($amSettings['total_comments'] / $days_started, 2) : 0,
);
// Total item contributors
$request = wesql::query('
SELECT id_member
FROM {db_prefix}media_items
WHERE approved = 1
GROUP BY id_member',
array()
);
$total_item_contributors = wesql::num_rows($request);
wesql::free_result($request);
// Total comment contributors
$request = wesql::query('
SELECT id_member
FROM {db_prefix}media_comments
WHERE approved = 1
GROUP BY id_member',
array()
);
$total_comment_contributors = wesql::num_rows($request);
wesql::free_result($request);
// Total featured albums
$request = wesql::query('
SELECT COUNT(id_album)
FROM {db_prefix}media_albums
WHERE approved = 1
AND featured = 1',
array()
);
list ($total_featured_albums) = wesql::fetch_row($request);
wesql::free_result($request);
// Some more stats eh?
$context['aeva_stats'] += array(
'total_commentators' => (int) $total_comment_contributors,
'total_item_posters' => (int) $total_item_contributors,
'total_featured_albums' => (int) $total_featured_albums,
'top_uploaders' => aeva_getTopMembers(5),
'top_commentators' => aeva_getTopMembers(5, 'comments'),
'top_albums_items' => aeva_getTopAlbumsByItems(5),
'top_albums_comments' => aeva_getTopAlbumsByComments(5),
'top_items_views' => aeva_getTopItems(5),
'top_items_com' => aeva_getTopItems(5, 'num_com'),
'top_items_rating' => aeva_getTopItems(5, 'rating'),
'top_items_voters' => aeva_getTopItems(5, 'voters'),
);
wetem::load('aeva_stats');
$context['page_title'] = $txt['media_stats'];
add_linktree($txt['media_stats'], $galurl . 'sa=stats');
}
// Manages your albums' control panel
function aeva_albumCP($is_admin = false)
{
global $context, $txt, $galurl, $alburl;
$alburl = $is_admin ? '<URL>?action=admin;area=aeva_albums;' . $context['session_query'] . ';' : $galurl . 'area=mya;';
if (!$is_admin)
{
// This is needed for the toggle
add_js_file('mediadmin.js');
$context['page_title'] = $txt['media_my_user_albums'];
add_linktree($txt['media_my_user_albums'], $galurl . 'area=mya');
}
$sa = array(
'add' => array($is_admin ? 'aeva_admin_albums_add' : 'aeva_addAlbum', true),
'edit' => array($is_admin ? 'aeva_admin_albums_edit' : 'aeva_editAlbum', true),
'delete' => array($is_admin ? 'aeva_admin_albums_delete' : 'aeva_deleteAlbum', false),
'move' => array($is_admin ? 'aeva_admin_albums_move' : 'aeva_moveAlbum', false),
);
if (isset($_REQUEST['sa'], $sa[$_REQUEST['sa']]))
if ($sa[$_REQUEST['sa']][1] === true)
return $sa[$_REQUEST['sa']][0]();
else
$sa[$_REQUEST['sa']][0]();
wetem::load('aeva_album_cp');
loadLanguage('ManageMedia');
// Load the albums
if (!$is_admin)
{
$quicklist = aeva_getQuickAlbums('a.album_of = ' . MID, 'master');
aeva_getAlbums(empty($quicklist) ? '1=0' : 'a.master IN (' . implode(',', $quicklist) . ')', 1, false, 'a.album_of, a.child_level, a.a_order', '', false, 100);
}
else
aeva_getAlbums(isset($_REQUEST['sa']) ? ($_REQUEST['sa'] == 'normal' ? 'a.featured = 0' : ($_REQUEST['sa'] == 'featured' ? 'a.featured = 1' : '')) : '', 0, false, 'a.album_of, a.child_level, a.a_order', '', false, 100);
// Are we moving by any chance?
$context['aeva_moving'] = $moving = isset($_REQUEST['move'], $context['aeva_albums'][$_REQUEST['move']]) ? $_REQUEST['move'] : false;
$context['aeva_my_albums'] = array();
foreach ($context['aeva_album_list'] as $list)
{
if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'normal' && $context['aeva_albums'][$list]['featured'])
continue;
if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'featured' && !$context['aeva_albums'][$list]['featured'])
continue;
$context['aeva_my_albums'][$list] = $context['aeva_albums'][$list];
if ($moving !== false && $moving != $list)
{
$move_url = '<a href="' . $alburl . ';sa=move;target=' . $context['aeva_albums'][$list]['id'] . ';src=' . $moving . ';pos=%s"><img src="' . ASSETS . '/aeva/arrow_%s.png" title="%s" style="vertical-align: bottom"></a>';
$context['aeva_my_albums'][$list]['move_links'] = array(
'before' => sprintf($move_url, 'before', 'up', $txt['media_admin_before']),
'after' => sprintf($move_url, 'after', 'down', $txt['media_admin_after']),
'child_of' => sprintf($move_url, 'child', 'in', $txt['media_admin_child_of']),
);
$context['aeva_my_albums'][$list]['is_getting_moved'] = false;
}
else
{
$context['aeva_my_albums'][$list]['move_links'] = array();
$context['aeva_my_albums'][$list]['is_getting_moved'] = true;
}
}
}
// We could do all lists at the same time instead of separately, but who cares...
function aeva_getFromMemberlist($lis, $owner = 1)
{
$lis = aeva_getTags($lis);
$request = wesql::query('
SELECT
id_member, ' . ($owner ? 'member' : 'real') . '_name
FROM {db_prefix}members' . (is_numeric($lis[0]) ? '
WHERE id_member IN ({array_int:names})' : '
WHERE real_name IN ({array_string:names}) OR member_name IN ({array_string:names})') . '
AND id_member != {int:owner}',
array(
'names' => $lis,
'owner' => $owner
)
);
$lis = array();
while ($row = wesql::fetch_row($request))
$lis[$row[0]] = $row[1];
wesql::free_result($request);
return $lis;
}
function aeva_editAlbum()
{
aeva_addAlbum(false, false);
}
function aeva_addAlbum($is_admin = false, $is_add = true)
{
global $context, $galurl, $amSettings, $txt;
$is_edit = !$is_add;
wetem::load('aeva_form');
$albums = array();
$primary_groups = array(0 => 0);
// Retrieve all non-admin primary groups used by members...
$request = wesql::query('SELECT id_group FROM {db_prefix}members GROUP BY id_group ORDER BY id_group', array());
while ($row = wesql::fetch_row($request))
$primary_groups[(int) $row[0]] = (int) $row[0];
wesql::free_result($request);
unset($primary_groups[1]);
if ($is_add)
{
// Access
if (!aeva_allowedTo('add_user_album'))
fatal_lang_error('media_accessDenied', !empty($amSettings['log_access_errors']));
if ($is_admin)
aeva_getAlbums('', 1, false, 'a.album_of, a.child_level, a.a_order');
else
{
// Get our album tree
$quicklist = aeva_getQuickAlbums('a.album_of = ' . MID . ' AND a.master = a.id_album');
// Add all albums in our tree
aeva_getAlbums('a.album_of = ' . MID . (empty($quicklist) ? '' : ' OR a.master IN (' . implode(',', $quicklist) . ')'), 1, false, 'a.album_of, a.child_level, a.a_order');
}
$_albums = array();
foreach ($context['aeva_album_list'] as $list)
{
$albums[$list] = str_repeat('-', $context['aeva_albums'][$list]['child_level']) . ($context['aeva_albums'][$list]['owner']['id'] == MID && !$is_admin ? ' '
: ' [' . $context['aeva_albums'][$list]['owner']['name'] . '] ') . $context['aeva_albums'][$list]['name'] . ' ';
$_albums[$list] = $context['aeva_albums'][$list];
}
$access = array_merge((array) -1, array_keys($primary_groups));
$access_write = array();
$still_unapproved = true;
$description = '';
$passwd = '';
$profile = 0;
$quotaProfile = 0;
$hidden = 0;
$allowed_members = '';
$allowed_write = '';
$denied_members = '';
$denied_write = '';
$owner = MID;
$owner_display_name = we::$user['name'];
$id_topic = 0;
$id_album = 0;
$big_icon = 0;
$topic_subject = '';
$title = '';
$featured = $is_admin;
}
else
{
// Get the album's data
$request = wesql::query('
SELECT
a.id_album, a.name, a.description, a.passwd, a.icon, a.bigicon, f.filename, bf.filename AS big_filename, a.options, NOT a.approved,
a.id_perm_profile, a.id_quota_profile, a.featured, a.hidden, a.album_of, a.id_topic, t.id_topic AS id_topic2, m.subject,
a.access, a.access_write, a.allowed_members, a.allowed_write, a.denied_members, a.denied_write, mem.member_name, mem.real_name
FROM {db_prefix}media_albums AS a
LEFT JOIN {db_prefix}media_files AS f ON (f.id_file = a.icon)
LEFT JOIN {db_prefix}media_files AS bf ON (bf.id_file = a.bigicon)
LEFT JOIN {db_prefix}topics AS t ON (a.id_topic = t.id_topic)
LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (a.album_of = mem.id_member)
WHERE a.id_album = {int:album}
LIMIT 1',
array('album' => (int) $_GET['in'])
);
if (wesql::num_rows($request) == 0)
fatal_lang_error('media_album_not_found');
list (
$id_album, $title, $description, $passwd, $icon, $big_icon, $filename, $big_filename, $peralbum_options, $still_unapproved,
$profile, $quotaProfile, $featured, $hidden, $owner, $id_topic, $id_topic2, $topic_subject, $access,
$access_write, $allowed_members, $allowed_write, $denied_members, $denied_write, $owner_name, $owner_display_name
) = wesql::fetch_row($request);
wesql::free_result($request);
$access = $access === '' ? array() : explode(',', $access);
$access_write = $access_write === '' ? array() : explode(',', $access_write);
// If user removed the linked topic manually, we should reset the topic ID.
if ($id_topic != $id_topic2)
{
$id_topic = 0;
wesql::query('UPDATE {db_prefix}media_albums SET id_topic = 0 WHERE id_album = {int:album}', array('album' => (int) $_GET['in']));
}
}
loadSource('Class-Editor');
$title = wedit::un_preparsecode($title);
$description = wedit::un_preparsecode($description);
$members_allowed = !empty($allowed_members) ? aeva_getFromMemberlist($allowed_members, $owner) : array();
$members_denied = !empty($denied_members) ? aeva_getFromMemberlist($denied_members, $owner) : array();
$members_allowed_write = !empty($allowed_write) ? aeva_getFromMemberlist($allowed_write, $owner) : array();
$members_denied_write = !empty($denied_write) ? aeva_getFromMemberlist($denied_write, $owner) : array();
$can_auto_approve = aeva_allowedTo('auto_approve_albums') || aeva_allowedTo('moderate');
$will_be_unapproved = !$is_admin && !$can_auto_approve && ($is_edit ? !empty($amSettings['album_edit_unapprove']) || $still_unapproved : true);
$peralbum = $is_add ? array() : unserialize($peralbum_options);
$peralbum['zoom'] = isset($peralbum['zoom']) && $peralbum['zoom'] == 'no' ? 'no' : 'yes';
$peralbum['outline'] = isset($peralbum['outline']) && in_array($peralbum['outline'], array('drop-shadow', 'white', 'black', 'glass')) ? $peralbum['outline'] : 'glass';
$peralbum['autosize'] = isset($peralbum['autosize']) && $peralbum['autosize'] == 'no' ? 'no' : 'yes';
$peralbum['fadeinout'] = empty($peralbum['fadeinout']) ? 0 : 1;
$peralbum['sort'] = empty($peralbum['sort']) ? 'm.id_media DESC' : $peralbum['sort'];
// Load the member groups
$simple_groups = !aeva_allowedTo('moderate');
$groups = array();
$groups[-1] = array($txt['media_membergroups_guests'], in_array(-1, $access));
$groups[0] = array('<span' . (isset($primary_groups[0]) && !$simple_groups ? ' style="font-weight: bold" title="' . $txt['media_admin_membergroups_primary'] . '"' : '') . '>' . $txt['media_membergroups_members'] . '</span>', in_array(0, $access), in_array(0, $access_write));
$groups['sep1'] = 'sep';
if ($simple_groups)
{
$first_group = reset($primary_groups);
$last_group = end($primary_groups);
if ($last_group)