forked from dengenxp/MediaGallery
/
functions.inc
1787 lines (1528 loc) · 60.3 KB
/
functions.inc
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
// +--------------------------------------------------------------------------+
// | Media Gallery Plugin - Geeklog |
// +--------------------------------------------------------------------------+
// | functions.inc |
// | |
// | This file does two things: 1) it implements the necessary glFusion Plugin|
// | API method and 2) implements all the common code needed by the Media |
// | Gallery PHP files. |
// +--------------------------------------------------------------------------+
// | Copyright (C) 2015 by the following authors: |
// | |
// | Yoshinori Tahara taharaxp AT gmail DOT com |
// | |
// | Based on the Media Gallery Plugin for glFusion CMS |
// | Copyright (C) 2002-2010 by the following authors: |
// | |
// | Mark R. Evans mark AT glfusion DOT org |
// +--------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +--------------------------------------------------------------------------+
if (strpos(strtolower($_SERVER['PHP_SELF']), strtolower(basename(__FILE__))) !== false) {
die('This file can not be used on its own!');
}
/**
* Include language file
*/
$plugin_path = $_CONF['path'] . 'plugins/mediagallery/';
$langfile = $plugin_path . 'language/' . $_CONF['language'] . '.php';
if (file_exists($langfile)) {
require_once $langfile;
} else {
require_once $plugin_path . 'language/english.php';
}
//global $_MG_CONF;
$_MG_CONF = array();
$_MG_CONF['pi_version'] = '1.7.0';
$_MG_CONF['installed_version'] = DB_getItem($_TABLES['plugins'], 'pi_version', "pi_name = 'mediagallery'");
$_MG_CONF['var_current_code'] = version_compare($_MG_CONF['installed_version'], $_MG_CONF['pi_version'], '>=');
/**
* Add to $_TABLES array the tables mediagallery plugin uses
*/
$_TABLES['mg_albums'] = $_DB_table_prefix . 'mg_albums';
$_TABLES['mg_media'] = $_DB_table_prefix . 'mg_media';
$_TABLES['mg_media_albums'] = $_DB_table_prefix . 'mg_media_albums';
$_TABLES['mg_usage_tracking'] = $_DB_table_prefix . 'mg_usage_tracking';
$_TABLES['mg_mediaqueue'] = $_DB_table_prefix . 'mg_mediaqueue'; // renamed from mg_media_queue to mg_mediaqueue
$_TABLES['mg_media_album_queue']= $_DB_table_prefix . 'mg_media_album_queue';
$_TABLES['mg_playback_options'] = $_DB_table_prefix . 'mg_playback_options';
$_TABLES['mg_userprefs'] = $_DB_table_prefix . 'mg_userprefs';
$_TABLES['mg_exif_tags'] = $_DB_table_prefix . 'mg_exif_tags';
$_TABLES['mg_watermarks'] = $_DB_table_prefix . 'mg_watermarks';
$_TABLES['mg_category'] = $_DB_table_prefix . 'mg_category';
$_TABLES['mg_sessions'] = $_DB_table_prefix . 'mg_sessions';
$_TABLES['mg_session_items'] = $_DB_table_prefix . 'mg_session_items';
$_TABLES['mg_session_log'] = $_DB_table_prefix . 'mg_session_log';
$_TABLES['mg_sort'] = $_DB_table_prefix . 'mg_sort';
$_TABLES['mg_rating'] = $_DB_table_prefix . 'mg_rating';
//$_TABLES['mg_mediasubmission'] = $_DB_table_prefix . 'mg_mediaqueue';
//$_TABLES['mg_mediasubmission'] = $_DB_table_prefix . 'mg_media_queue';
$_TABLES['mg_old_mediaqueue'] = $_DB_table_prefix . 'mg_media_queue';
$_TABLES['mg_config'] = $_DB_table_prefix . 'mg_config';
/**
* Media Gallery Global Configuration Options
*/
/*
* Media Gallery Path Configuration. If you want to move the directory where
* the Media Gallery programs are stored and accessed, change the
* $_MG_CONF['path_mg'] to the new directory name.
*
* You normally do not need to change any of the other paths.
*/
$_MG_CONF['path_html'] = $_CONF['path_html'] . 'mediagallery/';
$_MG_CONF['site_url'] = $_CONF['site_url'] . '/mediagallery';
$_MG_CONF['admin_url'] = $_CONF['site_admin_url'] . '/plugins/mediagallery/';
$_MG_CONF['path_admin'] = $_CONF['path_html'] . 'admin/plugins/mediagallery/';
$_MG_CONF['path_mediaobjects'] = $_CONF['path_html'] . 'mediagallery/mediaobjects/';
$_MG_CONF['mediaobjects_url'] = $_CONF['site_url'] . '/mediagallery/mediaobjects';
$_MG_CONF['template_path'] = $_CONF['path'] . 'plugins/mediagallery/templates';
$_MG_CONF['watermark_types'] = array('image/jpeg','image/jpg','image/png','image/bmp');
$_MG_CONF['link_to_member_album'] = 1;
/*
* By default, Media Gallery plays MP4 video files as QuickTime
* videos, using the QuickTime player.
*
* If you prefer to use the Flash Video Player for MP4 files,
* set this value to true.
*
*/
$_MG_CONF['play_mp4_flv'] = false;
//$_MG_CONF['play_mp4_flv'] = true;
/*
* Number of seconds to wait between ratings
*/
$_MG_CONF['rating_speedlimit'] = 45;
/*
* Set the maximum number of media items to display in the Media Manage Screen
*/
$_MG_CONF['mediamanage_items'] = 200;
/*
* If set to 1, MG will not automatically populate the video playback
* resolution, instead it will use the default settings
*/
$_MG_CONF['use_default_resolution'] = 0;
/*
* if set to 1, MG will use the larger stars in the album view for ratings
*/
$_MG_CONF['use_large_stars'] = 0;
/*
* By default, Media Gallery will play MPEG videos with Apple's QuickTime
* player. If you wish to use Microsoft's Windows Media Player instead,
* set this variable to 1.
*/
$_MG_CONF['use_wmp_mpeg'] = 0;
/*
* By default, Media Gallery will attempt to extract the actual image capture
* date from the meta data included by many digital cameras and graphics
* packages. If you prefer to always use the upload date (the date you added
* the image to your Media Gallery album) as the displayed date, set this
* variable to 1.
*/
$_MG_CONF['use_upload_time'] = 0;
/**
* FFMPEG Command line options
*
* There are lots of versions of ffmpeg out there, some work with one set of
* switches and some don't. You can easily modify the commands used to create
* thumbnails from videos by modifying the arguments below. The first %s is
* the source video and the second %s is the destination thumbnail, both %s
* need to be in the command.
*/
$_MG_CONF['ffmpeg_command_args'] = ' -i %s -f mjpeg -t 0.01 -y %s';
// $_MG_CONF['ffmpeg_command_args'] = ' -i %s -f mjpeg -an -r 1 -ss 00:00:03 -vframes 1 -y %s';
// $_MG_CONF['ffmpeg_command_args'] = ' -i %s -f singlejpeg -an -r 1 -ss 00:00:03 -vframes 1 -y %s';
// --- RIVA FLV Encoded / converter for Windows command line
// $_MG_CONF['ffmpeg_command_args'] = ' -an -y -i "%s" -t 0.001 -s 640x480 -deinterlace -hq -f image2 "%s"';
/*
* Default thumbnails for non-media type files
*
* This allows you to specify new default thumbnails for non-media file types.
* Place the thumbnail image in the mediaobjects/ directory.
*
*/
$_MG_CONF['dt']['pdf'] = 'pdf.png';
$_MG_CONF['dt']['zip'] = 'zip.png';
/*
* The JavaScript used by the lightbox slideshow can cause
* conflicts with other JS libraries. You can set this to true to disable
* the lightbox slideshow feature.
*/
$_MG_CONF['disable_lightbox'] = false;
/*
* If you want Media Gallery to update the 'last updated' time for all parent
* albums, set this to true.
*/
$_MG_CONF['update_parent_lastupdated'] = true; //false;
/*
* If you want to allow users who 'own' (uploaded) a media item to be able
* to also edit the media item, set this value to true.
*/
$_MG_CONF['allow_user_edit'] = false; // Do we need this?
/*
* Media Gallery provides limited support for including remotely hosted
* images in your albums. Your web host must support the CURL PHP extension
* or allow opening remote URLs to take full advantage of this features.
* To enable remote image support, set this value to true.
*/
$_MG_CONF['enable_remote_images'] = true;
/*
* Set whether or not click image and go next image
* true: display the next image
* false: change the display size (full size or normal size)
*/
$_MG_CONF['click_image_and_go_next'] = true;
/*
* Set whether or not hide the dialog select the destination album, on the media display page
*/
$_MG_CONF['hide_jumpbox_on_mediaview'] = true;
/*
* Set whether or not loop turning over the media display page at the top or the end
*/
$_MG_CONF['enable_loop_pagination'] = true;
/*
* Set the default of the shape (aspect ratio) of a random image on the side block area
* 0:original, 1:square
*/
$_MG_CONF['random_img_ratio'] = 0;
/* --------------------------------------------------------------------------------- */
define("MG_JPG",1);
define("MG_PNG",2);
define("MG_TIF",4);
define("MG_GIF",8);
define("MG_BMP",16);
define("MG_TGA",32);
define("MG_PSD",64);
define("MG_MP3",128);
define("MG_OGG",256);
define("MG_ASF",512);
define("MG_SWF",1024);
define("MG_MOV",2048);
define("MG_MP4",4096);
define("MG_MPG",8192);
define("MG_ZIP",16384);
define("MG_OTHER",32768);
define("MG_PDF",65536);
define("MG_FLV",131072);
define("MG_RFLV",262144);
define("MG_EMB",524288);
if (!defined ('UC_SELECTED')) define('UC_SELECTED', (XHTML == '') ? 'selected' : 'selected="selected"');
if (!defined ('UC_CHECKED')) define('UC_CHECKED', (XHTML == '') ? 'checked' : 'checked="checked"' );
if (!defined ('UC_READONLY')) define('UC_READONLY', (XHTML == '') ? 'readonly' : 'readonly="readonly"');
if (!defined ('UC_DISABLED')) define('UC_DISABLED', (XHTML == '') ? 'disabled' : 'disabled="disabled"');
// This is a list of valid extensions for image media thumbnails / display images
$_MG_CONF['validExtensions'] = array('.jpg','.png','.gif','.bmp');
// placeholder until implemented
$_MG_CONF['ad_shopping_cart'] = 0;
$swfjsinclude = 0;
$mgLightBox = 0;
$_MG_CONF['random_skin'] = 'default';
$_MG_CONF['tmp_path'] = $_CONF['path'] . 'plugins/mediagallery/tmp/';
$_MG_CONF['rater_units_num'] = 5;
/**
* Load the plugin configuration
*/
require_once $_CONF['path_system'] . 'classes/config.class.php';
$plg_config = config::get_instance();
$temp = $plg_config->get_config('mediagallery');
if (is_array($temp)) {
$_MG_CONF = array_merge($_MG_CONF, $temp);
}
if ($_CONF['loginrequired'] == 1) {
$_MG_CONF['loginrequired'] = 1;
}
/*
$_MG_CONF['up_mp3_player_enabled'] = 0;
if ($_MG_CONF['installed_version']) {
$_MG_CONF['dfid'] = '19';
$_MG_CONF['dateformat'] = DB_getItem($_TABLES['dateformats'], 'format', "dfid = {$_MG_CONF['dfid']}");
// safety checks....
if ($_MG_CONF['album_display_columns'] < 1) {
$_MG_CONF['album_display_columns'] = 1;
}
if ($_MG_CONF['album_display_rows'] < 1) {
$_MG_CONF['album_display_rows'] = 9;
}
}
*/
if (version_compare($_MG_CONF['installed_version'], '1.7.0', '>=')) {
$_MG_CONF['dateformat'] = DB_getItem($_TABLES['dateformats'], 'format', "dfid = {$_MG_CONF['dfid']}");
}
$_MG_CONF['path_to_imagemagick'] = '';
if ($_CONF['image_lib'] == 'imagemagick') {
$tmpstr = $_CONF['path_to_mogrify'];
if (strtolower(substr($tmpstr, -4)) == '.exe') {
$tmpstr = substr($tmpstr, 0, strlen($tmpstr) - 4);
}
if (strtolower(substr($tmpstr, -8)) == '/mogrify') {
$tmpstr = substr($tmpstr, 0, strlen($tmpstr) - 7); // Note that the path must end in a slash
}
$_MG_CONF['path_to_imagemagick'] = $tmpstr;
}
$_MG_CONF['ad_valid_formats'] =
$_MG_CONF['ad_valid_format_jpg'] * MG_JPG +
$_MG_CONF['ad_valid_format_png'] * MG_PNG +
$_MG_CONF['ad_valid_format_tif'] * MG_TIF +
$_MG_CONF['ad_valid_format_gif'] * MG_GIF +
$_MG_CONF['ad_valid_format_bmp'] * MG_BMP +
$_MG_CONF['ad_valid_format_tga'] * MG_TGA +
$_MG_CONF['ad_valid_format_psd'] * MG_PSD +
$_MG_CONF['ad_valid_format_mp3'] * MG_MP3 +
$_MG_CONF['ad_valid_format_ogg'] * MG_OGG +
$_MG_CONF['ad_valid_format_asf'] * MG_ASF +
$_MG_CONF['ad_valid_format_swf'] * MG_SWF +
$_MG_CONF['ad_valid_format_mov'] * MG_MOV +
$_MG_CONF['ad_valid_format_mp4'] * MG_MP4 +
$_MG_CONF['ad_valid_format_mpg'] * MG_MPG +
$_MG_CONF['ad_valid_format_flv'] * MG_FLV +
$_MG_CONF['ad_valid_format_rflv'] * MG_RFLV +
$_MG_CONF['ad_valid_format_emb'] * MG_EMB +
$_MG_CONF['ad_valid_format_zip'] * MG_ZIP +
$_MG_CONF['ad_valid_format_other'] * MG_OTHER;
$_MG_CONF['member_valid_formats'] =
$_MG_CONF['member_valid_format_jpg'] * MG_JPG +
$_MG_CONF['member_valid_format_png'] * MG_PNG +
$_MG_CONF['member_valid_format_tif'] * MG_TIF +
$_MG_CONF['member_valid_format_gif'] * MG_GIF +
$_MG_CONF['member_valid_format_bmp'] * MG_BMP +
$_MG_CONF['member_valid_format_tga'] * MG_TGA +
$_MG_CONF['member_valid_format_psd'] * MG_PSD +
$_MG_CONF['member_valid_format_mp3'] * MG_MP3 +
$_MG_CONF['member_valid_format_ogg'] * MG_OGG +
$_MG_CONF['member_valid_format_asf'] * MG_ASF +
$_MG_CONF['member_valid_format_swf'] * MG_SWF +
$_MG_CONF['member_valid_format_mov'] * MG_MOV +
$_MG_CONF['member_valid_format_mp4'] * MG_MP4 +
$_MG_CONF['member_valid_format_mpg'] * MG_MPG +
$_MG_CONF['member_valid_format_flv'] * MG_FLV +
$_MG_CONF['member_valid_format_rflv'] * MG_RFLV +
$_MG_CONF['member_valid_format_emb'] * MG_EMB +
$_MG_CONF['member_valid_format_zip'] * MG_ZIP +
$_MG_CONF['member_valid_format_other'] * MG_OTHER;
if ($_MG_CONF['usage_tracking']) {
$_MG_CONF['last_usage_purge'] = DB_getItem($_TABLES['vars'], 'value', "name = 'mg_last_usage_purge'");
}
$_MG_CONF['verbose'] = false;
/**
* Check to see if this Plugin uses comments
*
* @return boolean true or false
*
*/
function plugin_commentsupport_mediagallery()
{
return true;
}
/**
* Plugin function to save a comment
*
* @param string $title comment title
* @param string $comment comment text
* @param string $id Item id to which $cid belongs
* @param int $pid comment parent
* @param string $postmode 'html' or 'text'
* @return mixed false for failure, HTML string (redirect?) for success
*/
function plugin_savecomment_mediagallery($title, $comment, $id, $pid, $postmode)
{
global $_CONF, $_MG_CONF, $_TABLES, $LANG03;
$retval = '';
$sql = "SELECT a.enable_comments "
. "FROM {$_TABLES['mg_albums']} AS a "
. "LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON a.album_id = ma.album_id "
. "WHERE ma.media_id = '$id'";
$result = DB_query($sql);
$A = DB_fetchArray($result);
if ($A['enable_comments'] != 1) {
return COM_refresh($_CONF['site_url'] . '/index.php');
}
$ret = CMT_saveComment($title, $comment, $id, $pid, 'mediagallery', $postmode);
if ($ret > 0) { // failure //FIXME: some failures should not return to comment form
$retval .= CMT_commentForm($title, $comment, $id, $pid, 'mediagallery',
$LANG03[14], $postmode);
if (!defined('COMMENT_ON_SAME_PAGE') || !COMMENT_ON_SAME_PAGE) {
$retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG03[1]));
}
return $retval;
} else { // success
$comments = DB_count($_TABLES['comments'], array('sid', 'type'), array(addslashes($id), 'mediagallery'));
DB_change($_TABLES['mg_media'], 'media_comments', $comments, 'media_id', addslashes($id));
return COM_refresh($_MG_CONF['site_url'] . "/media.php?s=$id");
}
return false;
}
/**
* Plugin function to delete a comment
*
* @param int $cid Comment to be deleted
* @param string $id Item id to which $cid belongs
* @return mixed false for failure, HTML string (redirect?) for success
*/
function plugin_deletecomment_mediagallery($cid, $id)
{
global $_CONF, $_MG_CONF, $_TABLES;
// find the album that holds this peice of media
$sql = "SELECT album_id FROM {$_TABLES['mg_media_albums']} WHERE media_id='" . addslashes($id) . "'";
$result = DB_query($sql);
$nRows = DB_numRows($result);
$access = 0;
if ($nRows > 0) {
$row = DB_fetchArray($result);
require_once $_CONF['path'].'plugins/mediagallery/include/classAlbum.php';
$root_album = new mgAlbum(0); // root album
$album = new mgAlbum($row['album_id']); // current album
$access = 3;
if (!$root_album->owner_id) {
$access = $album->access;
}
}
if ($access == 3 && SEC_hasRights('mediagallery.admin')) {
if (CMT_deleteComment($cid, $id, 'mediagallery') == 0) {
$comments = DB_count($_TABLES['comments'], array('sid', 'type'), array(addslashes($id), 'mediagallery'));
DB_change($_TABLES['mg_media'], 'media_comments', $comments, 'media_id', addslashes($id));
return COM_refresh($_MG_CONF['site_url'] . "/media.php?s=$id");
}
}
return false;
}
function plugin_getcommenturlid_mediagallery()
{
global $_CONF, $_MG_CONF;
$retval = array();
$retval[] = $_MG_CONF['site_url'] . '/media.php';
$retval[] = 's';
$retval[] = 'page=';
return $retval;
}
/**
* Plugin should display [a] comment[s]
*
* @param string $id Unique idenifier for item comment belongs to
* @param int $cid Comment id to display (possibly including sub-comments)
* @param string $title Page/comment title
* @param string $order 'ASC' or 'DESC' or blank
* @param string $format 'threaded', 'nested', or 'flat'
* @param int $page Page number of comments to display
* @param boolean $view True to view comment (by cid), false to display (by $pid)
* @return mixed results of calling the plugin_displaycomment_ function
*/
function plugin_displaycomment_mediagallery($id, $cid, $title, $order, $format, $page, $view)
{
global $_TABLES, $LANG_ACCESS, $LANG_MG00;
$retval = '';
$sql = "SELECT COUNT(*) AS count, a.enable_comments, "
. "a.owner_id, a.group_id, a.perm_owner, "
. "a.perm_group, a.perm_members, a.perm_anon "
. "FROM {$_TABLES['mg_albums']} AS a "
. "LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON a.album_id = ma.album_id "
. "WHERE ma.media_id = '$id'" . COM_getPermSQL('AND')
. " GROUP BY ma.media_id";
$result = DB_query($sql);
$A = DB_fetchArray($result);
$allowed = $A['count'];
if ($allowed == 1 && $A['enable_comments'] == 1) {
$delete_option = (SEC_hasRights('mediagallery.admin') &&
(SEC_hasAccess($A['owner_id'], $A['group_id'],
$A['perm_owner'], $A['perm_group'], $A['perm_members'],
$A['perm_anon']) == 3));
$commentcode = 0;
$retval .= CMT_userComments($id, $title, 'mediagallery', $order, $format,
$cid, $page, $view, $delete_option, $commentcode);
} else {
$retval .= COM_startBlock($LANG_ACCESS['accessdenied'], '',
COM_getBlockTemplate('_msg_block', 'header'))
. $LANG_MG00['deny_msg']
. COM_endBlock(COM_getBlockTemplate ('_msg_block', 'footer'));
}
return $retval;
}
/**
* Returns the items for this plugin that should appear on the main menu
*
* NOTE: this MUST return the url/value pairs in the following format
* $<arrayname>[<label>] = <url>
*
* Universal Plugin: Uncomment and fill in variables;
*
* @return array Associative array of menu items to be added to menu
*
*/
function plugin_getmenuitems_mediagallery()
{
global $_CONF, $_USER, $_MG_CONF, $LANG_MG03;
if (COM_isAnonUser() && $_MG_CONF['loginrequired'] == 1) return '';
$menulabel = $LANG_MG03['menulabel'];
$menurul = $_MG_CONF['site_url'] . "/index.php"; // Menu url here
$menuitems = array();
$menuitems["$menulabel"] = $menurul;
return $menuitems;
}
function plugin_getheadercode_mediagallery()
{
global $_CONF, $_MG_CONF, $_SCRIPTS, $mgLightBox, $swfjsinclude;
$retval = '';
//
// Check to see if the template path is using the plugins/ directory, if yes,
// we must point to the stylesheet in public_html/mediagallery/
//
if ($_MG_CONF['template_path'] == $_CONF['path'] . 'plugins/mediagallery/templates') {
$styleFile = $_MG_CONF['site_url'] . '/style.css';
} else {
$styleFile = $_CONF['layout_url'] . '/mediagallery/style.css';
}
$retval .= LB . '<link rel="stylesheet" type="text/css" href="' . $styleFile . '"' . XHTML . '>' . LB;
$_SCRIPTS->setJavaScriptFile('swfobject', '/mediagallery/js/swfobject_2.1.js', false);
$_SCRIPTS->setJavaScriptFile('mediagallery', '/mediagallery/js/mediagallery.js');
$_SCRIPTS->setJavaScriptLibrary('jquery');
if (! $_MG_CONF['disable_lightbox']) {
$_SCRIPTS->setJavaScriptFile('jquery.slimbox2', '/mediagallery/js/slimbox2.js');
}
$_SCRIPTS->setJavaScriptFile('jquery.cyclelite', '/mediagallery/js/jquery.cycle.lite.min.js');
$swfjsinclude = 1;
$_SCRIPTS->setCSSFile('mg.framecss' . $_MG_CONF['random_skin'] , '/mediagallery/frames/' . $_MG_CONF['random_skin'] . '/style.css', false);
return $retval;
}
/**
* Whats New Block API Support
* Return the Headline and Byline for the new section in the Whatsnew Block
*/
function plugin_whatsnewsupported_mediagallery()
{
global $_CONF, $_MG_CONF, $LANG_MG00;
if ($_MG_CONF['whatsnew'] == 0) return '';
if ($_MG_CONF['installed_version'] != $_MG_CONF['pi_version']) return '';
if (COM_isAnonUser() && $_MG_CONF['loginrequired'] == 1) return '';
$label = sprintf($LANG_MG00['whatsnew_prompt'], $_MG_CONF['whatsnew_time']);
return array($LANG_MG00['whatsnew_title'], $label);
}
/**
* API function provides the content of our "What's New" feed
*/
function plugin_getwhatsnew_mediagallery()
{
global $_TABLES, $_CONF, $_MG_CONF, $_USER, $LANG_MG03;
require_once $_CONF['path'].'plugins/mediagallery/include/classAlbum.php';
$retval = '';
$newMediaCount = 0;
$newCommentCount = 0;
$items = array();
$newAge = time() - ($_MG_CONF['whatsnew_time'] * 86400);
$sql = "SELECT album_id FROM {$_TABLES['mg_albums']} WHERE last_update >= '" . $newAge . "' ORDER BY last_update DESC";
$result = DB_query($sql,1);
while ($row = DB_fetchArray($result)) {
$album = new mgAlbum($row['album_id']);
if ($album->access > 0 && $album->hidden != 1 && $album->getOffset() != -1) {
$title = $album->title;
if (strlen($title) > $_MG_CONF['title_length']) {
$dTitle = substr($title,0,$_MG_CONF['title_length'] - 3) . '...';
} else {
$dTitle = $title;
}
$items[] = COM_createLink($dTitle,
$_MG_CONF['site_url'] . '/album.php?aid=' . $row['album_id'],
array('title' => htmlspecialchars($title, ENT_COMPAT, COM_getCharset())));
$newMediaCount++;
}
}
if ($newMediaCount == 0) {
$retval .= $LANG_MG03['no_new_items'] . '<br' . XHTML . '>' . LB;
}
if ($_MG_CONF['disable_whatsnew_comments'] == 0) {
$sql = "SELECT * FROM {$_TABLES['comments']} AS c "
. "LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON c.sid=ma.media_id "
. "LEFT JOIN {$_TABLES['mg_albums']} AS a ON ma.album_id=a.album_id "
. "WHERE c.date >= DATE_SUB(NOW(), INTERVAL " . $_MG_CONF['whatsnew_time'] . " DAY ) "
. "AND c.type='mediagallery' GROUP BY c.sid ORDER BY c.date DESC LIMIT 15";
$result = DB_query($sql, 1);
$nrows2 = DB_numRows($result);
if ($nrows2 == 0) {
$retval .= '' . '<br' . XHTML . '>' . LB;
} else {
while ($A = DB_fetchArray($result)) {
$access = SEC_hasAccess($A['owner_id'],$A['group_id'],$A['perm_owner'],
$A['perm_group'],$A['perm_members'],$A['perm_anon']);
if ($access > 0) {
$titleLength = $_MG_CONF['title_length']; // Compensate for the added HTML
$title = "<strong>C:</strong> " . $A['title'];
$items[] = COM_createLink(substr($title, 0, $titleLength),
"{$_CONF['site_url']}/comment.php?mode=view&cid={$A['cid']}&sid={$A['sid']}&type=mediagallery");
$newCommentCount++;
}
}
}
if ($newCommentCount == 0) {
$retval .= $LANG_MG03['no_comments'] . '<br' . XHTML . '>' . LB;
}
}
if ($newMediaCount == 0 && $newCommentCount == 0) {
return $retval;
} else {
return $items;
}
}
/**
* Shows the statistics for the plugin on stats.php. If
* $showsitestats is 1 then we are to only print the overall stats in the 'site
* statistics' box otherwise we show the detailed stats for the plugin
*
* Universal Plugin: Modify/uncomment use it
*
* @param int showsitestate Flag to let us know which stats to get
* @return string returns formatted HTML to insert in stats page
*
*/
function plugin_showstats_mediagallery($showsitestats)
{
global $_CONF;
require_once $_CONF['path'] . 'plugins/mediagallery/include/statistics.php';
return MG_showstats($showsitestats);
}
function plugin_statssummary_mediagallery()
{
global $_CONF, $_MG_CONF, $_TABLES, $LANG_MG00, $_USER;
if (COM_isAnonUser() && $_MG_CONF['loginrequired'] == 1) return '';
// This shows in the summary box
$total_items=DB_count($_TABLES['mg_media']);
$summary_label = $LANG_MG00['items_in'] . ' ' . $LANG_MG00['plugin'];
$retval[] = $summary_label;
$retval[] = $total_items;
return $retval;
}
/**
* This will put an option for the plugin in the command and control block on moderation.php
*
* Add the plugin name, icon and link to the command and control block in moderation.php
*
* @return array Array containing (plugin name, admin url, url of plugin icon)
*
*/
function plugin_cclabel_mediagallery()
{
global $_CONF, $_MG_CONF, $LANG_MG00;
if (SEC_hasRights('mediagallery.config')) {
return array($LANG_MG00['plugin'],
$_MG_CONF['admin_url'] . 'index.php',
plugin_geticon_mediagallery());
}
return false;
}
/**
* Returns the URL of the plugin's icon
*
* @return string URL of the icon
*
*/
function plugin_geticon_mediagallery()
{
global $_CONF;
return $_CONF['site_url'] . '/mediagallery/images/mediagallery.png';
}
/**
* Returns the administrative option for this plugin
*
* Adds the plugin to the Admin menu
*
* Universal Plugin: Modify/Uncomment use it
*
* @return array Array containing (plugin name, plugin admin url, # of items in plugin or '')
*
*/
function plugin_getadminoption_mediagallery()
{
global $_CONF, $_TABLES, $LANG_MG00, $_MG_CONF;
if (SEC_hasRights('mediagallery.config')) {
return array($LANG_MG00['plugin'], $_MG_CONF['admin_url'] . 'index.php', DB_count($_TABLES['mg_albums']));
}
}
function plugin_autotags_mediagallery ($op, $content = '', $autotag = '')
{
global $_CONF, $_TABLES, $_MG_CONF;
if ($_MG_CONF['installed_version'] != $_MG_CONF['pi_version']) {
return $content;
}
if ($op == 'tagname') {
return array('album','media','img','slideshow','fslideshow','video','audio',
'download','image','oimage','mlink','alink','playall',
'gallery'
,'medialist','albumlist');//@@@@@
} else if ($op == 'parse') {
require_once $_CONF['path'] . 'plugins/mediagallery/include/autotags.php';
return MG_autotags($op, $content, $autotag);
}
}
/**
* returns list of moderation values
*
* The array returned contains (in order): the row 'id' label, main plugin
* table, moderation fields (comma seperated), and plugin submission table
*
* @return array Returns array of useful moderation values
*
*/
function plugin_moderationvalues_mediagallery()
{
global $_TABLES;
return array (
'media_id',
$_TABLES['mg_media'],
'media_id, media_filename, media_original_filename, media_mime_ext, media_exif, mime_type, '
. 'media_title, media_desc, media_keywords, media_time, media_views, media_comments, '
. 'media_votes, media_rating, media_resolution_x, media_resolution_y, remote_media, '
. 'remote_url, media_tn_attached, media_tn_image, include_ss, media_user_id, '
. 'media_user_ip, media_approval, media_type, media_upload_time, media_category, '
. 'media_watermarked, artist, album, genre, v100, maint',
$_TABLES['mg_mediaqueue']);
}
/**
* show files for moderation on submissions page
*
* Uses the Plugin class to return data required by moderation.php to list
* plugin objects that need to be moderated.
*
* @return Plugin return Plugin class containing submission data
*
*/
function plugin_itemlist_mediagallery()
{
global $_CONF, $_TABLES, $LANG_MG01;
if (plugin_ismoderator_mediagallery()) {
$plugin = new Plugin();
$plugin->submissionlabel = $LANG_MG01['media_submissions'];
if (file_exists($_CONF['path_html'] . 'help/ccmediagallerysubmission.html')) {
$plugin->submissionhelpfile = 'ccmediagallerysubmission.html';
}
$plugin->getsubmissionssql = "SELECT media_id AS id, media_title AS title, FROM_UNIXTIME(media_upload_time), mime_type "
. "FROM {$_TABLES['mg_mediaqueue']} ORDER BY media_title ASC";
$plugin->addSubmissionHeading($LANG_MG01['title']);
$plugin->addSubmissionHeading($LANG_MG01['date']);
$plugin->addSubmissionHeading($LANG_MG01['mime_type']);
return $plugin;
}
return;
}
/**
* Returns the plugins submission form
*
* Returns a string contain the HTML of the submission form for the plugin.
*
* @return string The HTML form
*
*/
function plugin_submit_mediagallery()
{
$retval = '<h1>submit file</h1>';
$retval .= '<p>This would be the input form for uploading files. ';
$retval .= 'But that functionality is already implemented elsewhere.</p>';
return($retval);
}
/**
*
* Checks that the current user has the rights to moderate the
* plugin, returns true if this is the case, false otherwise
*
* @return boolean Returns true if moderator
*
*/
function plugin_ismoderator_mediagallery()
{
return SEC_hasRights('mediagallery.admin');
}
/**
* Returns the number of submissions waiting moderation
*
* Calculates the number of submissions that are currently waiting
* to be moderated and returns that number.
*
* @return int number of submissions awaiting moderation
*/
function plugin_submissioncount_mediagallery()
{
global $_MG_CONF, $_TABLES;
$retval = 0;
$table = $_TABLES['mg_old_mediaqueue'];
if (version_compare($_MG_CONF['installed_version'], $_MG_CONF['pi_version']) >= 0) {
$table = $_TABLES['mg_mediaqueue'];
}
if (plugin_ismoderator_mediagallery()) {
$retval = DB_count($table);
}
return $retval;
}
/**
* Performs plugin exclusive work for items approved by moderation
*
* While moderation.php handles the actual move from mediagallery submission
* to mediagallery tables, within the function we handle all other approval
* relate tasks
*
* @param string $id Identifying string
* @return string Any wanted HTML output
*
*/
function plugin_moderationapprove_mediagallery($id)
{
global $_CONF;
require_once $_CONF['path'] . 'plugins/mediagallery/include/moderate.php';
MG_approveSubmission($id);
return '';
}
/**
* Performs plugin exclusive work for items deleted by moderation
*
* While moderation.php handles the actual removal from mediagallery submission
* table, within this function we handle all other deletion
* relate tasks
*
* @param string $id Identifying string
* @return string Any wanted HTML output
*
*/
function plugin_moderationdelete_mediagallery($id)
{
global $_CONF;
require_once $_CONF['path'] . 'plugins/mediagallery/include/moderate.php';
MG_deleteSubmission($id);
return '';
}
/**
* saves submission to mediagallery submission table
*
* takes data input by submission form and populates the mediagallery submission
* table.
*
* @param array $A array (key => value) of form items
* @return boolean returns true if successful
*
*/
function plugin_savesubmission_mediagallery($A)
{
return false;
}
function plugin_searchtypes_mediagallery()
{
global $_MG_CONF, $LANG_MG00;
if (COM_isAnonUser() && $_MG_CONF['loginrequired'] == 1) return '';
$tmp['mediagallery'] = $LANG_MG00['plugin'];
return $tmp;
}
/**
* this searches for pages matching the user query and returns an array of
* for the header and table rows back to search.php where it will be formated and
* printed
*
* @query string Keywords user is looking for
* @datestart date/time Start date to get results for
* @dateend date/time End date to get results for
* @topic string The topic they were searching in
* @type string Type of items they are searching
* @author string Get all results by this author
*
*/
function plugin_dopluginsearch_mediagallery($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage)
{
global $_TABLES, $_CONF, $_MG_CONF, $LANG_MG00, $LANG_MG01, $LANG09;
if (COM_isAnonUser() && $_MG_CONF['loginrequired'] == 1) return '';
$query = trim(addslashes(htmlspecialchars($query)));
$sql = "SELECT DISTINCT "
. "m.media_id AS id, "
. "m.media_user_id AS uid, "
. "m.media_desc AS description, "
. "m.media_title AS title, "
. "m.media_time AS date, "
. "m.media_views AS hits, "
. "CONCAT('/mediagallery/media.php?s=', m.media_id) AS url "
. "FROM {$_TABLES['mg_media']} AS m "