-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
3453 lines (2427 loc) · 103 KB
/
index.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
error_reporting(0);
class SystemExit extends Exception {}
try {
require_once('./config.php');
//error_reporting(E_ERROR | E_PARSE);
//error_reporting(E_ALL);
//error_reporting(E_WARNING|E_NOTICE);
require_once('./crero-lib.php');
//error_reporting(E_WARNING|E_NOTICE|E_ERROR|E_PARSE);
error_reporting(0);
$myhtmlcache=null;
//Whoever you are, you deserve a cleaning
//LOCKING
//By the way, let's remove old locks on callbacks ping recently played
if (array_key_exists('recently_callback_id' , $_SESSION)){
foreach (array_keys($_SESSION['recently_callback_id']) as $stamped){
if (floatval($_SESSION['recently_callback_id'][$stamped]['stamp'])+300<microtime(true)){
unset($_SESSION['recently_callback_id'][$stamped]);
}
}
}
if (file_exists('./recently_ping.lock')&&(floatval(filectime('./recently_ping.lock'))+5.0)<microtime(true)){
unlink('./recently_ping.lock');
}
while (file_exists('./recently_ping.lock')){
if (file_exists('./recently_ping.lock')&&(floatval(filectime('./recently_ping.lock'))+5.0)>microtime(true)){
unlink('./recently_ping.lock');
session_reset();
}
sleep(1);
}
touch ('./recently_ping.lock');
//LOCKED
$recentsjailed=Array();
if (file_exists('./d/recent.dat')){
$recentsjailed=unserialize(file_get_contents('./d/recent.dat'));
}
$recentsfinal=Array();
if ($recentjailed){
foreach ($recentsjailed as $recent){
if($recent['jailed']==false||(($recent['jailed']===true)&&(floatval($recent['date'])+90.0)>floatval(time()))){
array_push($recentsfinal, $recent);
}//if jailed && jailtime < 90 secondes OR not jailed
}
file_put_contents('./d/recent.dat', serialize($recentsfinal));
}
unlink('./recently_ping.lock');
//UNLOCKED
if (array_key_exists('void', $_GET)){
echo '<!DOCTYPE html><html><body>Initializing...</body></html>';
throw new SystemExit();
}
function checkOverload ($apiResponse) {
if ($apiResponse===false){
echo '<br/>Oooops... We are currently over capacity. Please try again later<br/></body></html>';
throw new SystemExit();
}
}
if ((filectime('./ypservices.lock')+intval(60))>time()){
unlink ('./ypservices.lock');
}
if (array_key_exists('ypservices', $_GET)){
touch ('./ypservices.lock');
$ypindex=$_GET['ypservices'];
if (!is_numeric($ypindex)){
throw new SystemExit();
}
$ypindex=intval($ypindex);
$arryp=array();
if (file_exists('./ypservices.dat')){
$ypfile=file_get_contents('./ypservices.dat');
$ypdata=unserialize($ypfile);
$arryp=$ypdata;
//Note that in the case of the file was not readable,
//we will continue anyway,
//and ypdata will be an FALSE boolean no longer an//empty array
}
if (count($creroypservices)>0){
//let's do some cleanup in the .dat record
$barryp=array();
foreach ($creroypservices as $srv){
if (array_key_exists($srv, $arryp))
{
$barryp[$srv]=$arryp[$srv];
}
}
$arryp=$barryp;
$data=serialize($arryp);
file_put_contents('./ypservices.dat', $data);//note that it can return false on failure and we won't handle such a thing.
//Here comes the main stuff
if (isset($creroypservices[$ypindex])){
$ypservice=$creroypservices[$ypindex];
$ypre=null;
if (!is_array($arryp[$ypservice]))
{
$arryp[$ypservice]=array();
}
if (array_key_exists('ping', $_GET)){//We only ping YP when homepage is displayed, not upon every call to the AJAX
$ypre=file_get_contents(trim($ypservice).'?url='.urlencode('http://'.$server).'&name='.urlencode($sitename).'&description='.urlencode($description).'&forceHTTPS='.urlencode($YPForceHTTPS));
if (($ypre===false)){
$arryp[$ypservice]['hasFailed']=true;
$arryp[$ypservice]['repliedFailureTime']=time();
}
else {//we pinged since ypre is no longer null, and YP replied, since it is not false, so store the pong reply
$yppong=explode (' ', $ypre);
$arryp[$ypservice]['hasFailed']=false;
$arryp[$ypservice]['repliedSuccessTime']=time();
$arryp[$ypservice]['pong']=array();
$arryp[$ypservice]['pong']=$yppong;
}
//we didn't ping'ed, but can continue
//at this point is soon enough to save the .dat on disk, since we will only need read access from now
$data=serialize($arryp);
file_put_contents('./ypservices.dat', $data);//note that it can return false on failure and we won't handle such a thing.
}
//and now let's thing about our web browser waiting for data
$yp_server_addr_no_proto = $ypservice;
$yp_server_addr_no_proto = str_replace('https://', '', $yp_server_addr_no_proto);
$yp_server_addr_no_proto = str_replace('http://', '', $yp_server_addr_no_proto);
if (isset($arryp[$ypservice]['pong'])){//3 is enough for now and stricly necessary according to protocol RTFS specifications
$pong_saved_status=boolval ($arryp[$ypservice]['pong'][0]=='0');
$pong_force_https=boolval (strtoupper($arryp[$ypservice]['pong'][1])=='HTTPS');
$pong_public=boolval (strtolower($arryp[$ypservice]['pong'][2])=='public');
}
else {//lets use default value suitable in most cases
$pong_saved_status=true;//never got a failure, never, before pong replies introduction
$pong_force_https=false;
if (!(strpos($ypservice, 'https://')===false)&&strpos($ypservice, 'https://')==0){
$pong_force_https=true;//if nothing more indicated, let's trust what have been entered by CreRo admins
}
$pong_public=true;
}
$ourproto='http://';
if ($pong_force_https){
$ourproto='https://';
}
if($pong_public){
echo '[<a href="'.$ourproto.str_replace('"','', $yp_server_addr_no_proto).'">'.$ourproto.str_replace('"','', $yp_server_addr_no_proto).'</a>] (';
if (array_key_exists('hasFailed', $arryp[$ypservice])){
$yp_hasfailed=$arryp[$ypservice]['hasFailed'];
}
else $yp_hasfailed=null;
if (array_key_exists('repliedFailureTime', $arryp[$ypservice])){
$yp_failuretime=$arryp[$ypservice]['repliedFailureTime'];
}
else $yp_failuretime=null;
if (array_key_exists('repliedSuccessTime', $arryp[$ypservice])){
$yp_successtime=$arryp[$ypservice]['repliedSuccessTime'];
}
else $yp_successtime=null;
if (!isset($yp_hasfailed))
echo 'Last ping success is unknown';
else if ($yp_failuretime>$yp_successtime){
echo 'Last ping has failled ';
if (isset($yp_failuretime)){
echo ''.date(DATE_RSS, $yp_failuretime).' ';
}
else
echo 'an unkown time ago.';
}
if (isset($yp_successtime)){
echo 'Last ping success '.date(DATE_RSS, $yp_successtime).' ';
if (!$pong_saved_status){
echo 'but the YP replied that its record was not updated';
}
}
else
echo 'Last ping success is unknown ';
echo ') ';
}
}
else {//we finished, going bybye
unlink ('./ypservices.lock');
throw new SystemExit();
}
}
//and now we're done, now we can go home
unlink ('./ypservices.lock');
throw new SystemExit();
}//Ajax reply to ypservices get parameter
if (isset($_GET['embed'])){
$embed=$_GET['embed'];
//as a temporary measure, to comply with per-site cookies isolation introduced in modern mozilla
//we disable download_cart
//to allow download on embeding sites
//awaiting for further dev. enabling it
$enableDownloadCart=false;
}else{$embed=false;}
/**********************************************************************
* IMPORTANT NOTICE ABOUT $embed
* Embed can be of two types ! Either a String, or a Boolean
* So never write <?php if ($embed) ?> of <?php if (!$embed) ?> !!!!!!
* Instead, write <?php if (((true==$embed)||(false!==$embed)))
* or <?php if (!((true==$embed)||(false!==$embed))) ?>
*
* Otherwise, if the embed string contains the name of an artist who
* has for name "0", it will evaluate as false
* and will not embed properly
* so a strict double check is necessary
* firstly without strict type checking for normal name artists
* secondary with an OR (||) with strict type checking
* to be sure it's not strictly a boolean that has its value "false"
* ********************************************************************/
//$sessionstarted=session_start();
header("Content-Type: text/html; charset=utf-8");
if (!array_key_exists('crero_uid', $_SESSION)){
$_SESSION['crero_uid']=microtime(true).'-'.random_int(1, 1000000);
}
ob_start();
if (!isset($_SESSION['origin'])){
$_SESSION['origin']=$_SERVER['HTTP_REFERER'];
}
srand();
if (isset($_SESSION['random'])&&$_SESSION['random']){
$_GET['twist']='random';//necessary if cache enabled
}
if (array_key_exists('noscript', $_GET)&&$_GET['noscript']=='footer'){
?>
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="./<?php echo $favicon;?>" />
<link rel="stylesheet" href="//<?php echo $server; ?>/style.css" type="text/css" media="screen" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="charset" value="utf-8" />
<meta charset="UTF-8"/>
<title><?php echo htmlspecialchars($sitename).' - '.htmlspecialchars($footerReadableName); ?></title>
<meta name="description" content="<?php echo htmlspecialchars($title.' - '.$description); ?>" />
</head>
<body>
<a href="./"><?php echo htmlspecialchars($sitename); ?></a> > <?php echo htmlspecialchars($footerReadableName); ?><br/>
<?php echo $footerhtmlcode; ?>
</body>
</html>
<?php
throw new SystemExit();
}
$willhavetocache=false;
if ($activatehtmlcache){
$myhtmlcache=new creroHtmlCache($htmlcacheexpires);
}
$cachingkey='key:';
$get_keys=array_keys($_GET);
$whitelist= array ('artist', 'album', 'track', 'offset', 'autoplay', 'vid', 'twist', 'embed', 'body', 'target[]');
foreach ($get_keys as $get_key){
//EXPECT crazy behaviors if target[] count more than one single elements. For now this is not a problem, cause the the sole target[] is array ('radio') and has only one element
if (in_array($get_key, $whitelist)){
$cachingkey.=$get_key."\n".$_GET[$get_key];
}
}
if ($activatehtmlcache){
if (isset($_GET['purge'])){
$myhtmlcache->purgeCache();
echo '<html><body>Cache purged. <a href="./">Proceed</a></body></html>';
throw new SystemExit();
}
}
if (isset($_POST['page_purge'])&&$activatehtmlcache){
$pseudoget=json_decode(base64_decode($_POST['page_purge']),true);
$cachingkey='key:';
$get_keys=array_keys($pseudoget);
foreach ($get_keys as $get_key){
if (in_array($get_key, $whitelist)){
$cachingkey.=$get_key."\n".$pseudoget[$get_key];
}
}
$myhtmlcache->purgePage($cachingkey);
$redirect_proto='http';
if (isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']!==''){
$redirect_proto='https';
}
$querystring='?';
$get_keys=array_keys($pseudoget);
foreach ($get_keys as $get_key){
if (in_array($get_key, $whitelist)){
if ($get_key!='body'&&$get_key!='no-infinite-loop-please'){
$querystring=$querystring.$get_key.'='.urlencode($pseudoget[$get_key]).'&';
}
}
}
if ($querystring=='?'){
$querystring='';
}
header_remove(null);
header("Location: ".$redirect_proto.'://'.$_SERVER['SERVER_NAME'].str_replace ('index.php', '', $_SERVER['PHP_SELF']).$querystring, true, 302);
echo '<html><head><title>Cache page purging</title></head><body style="font-size:700%;">The page was purged from the cache.<br/>
<a onload="this.click();" href="./'.$querystring;
echo '">Continue...</a></body></html>';
throw new SystemExit();
}
if (isset($_GET['getinfo'])){
echo file_get_contents($clewnapiurl.'?getinfo='.urlencode($_GET['getinfo']));
throw new SystemExit();
}
//some last pre-caching thing
//***************PRE CACHING THINGS***************************
//We want to store in the recent.dat
//The album currenlty played (if any)
//If the RecentPlay option has been desired
//And the session started, just to keep many bots
//Out of the log
//And polite bots are not wished as well
//thanks to them for being polite
if (((array_key_exists('recently_callback', $_GET)&&
array_key_exists('recently_callback_id', $_GET))
&&isset($_GET['album'])
&&(((!array_key_exists('recently_callback_id', $_SESSION))||!array_key_exists($_GET['album'], $_SESSION['recently_callback_id']))&&$_SESSION['recently_callback_id'][$_GET['album']]['id']!=$_GET['recently_callback_id']))
&&!isset($_GET['listall'])&&$recentplay&&$sessionstarted
)
{
//LOCKING
if (file_exists('./recently_ping.lock')&&(floatval(filectime('./recently_ping.lock'))+5.0)<microtime(true)){
unlink('./recently_ping.lock');
}
while (file_exists('./recently_ping.lock')){
if (file_exists('./recently_ping.lock')&&(floatval(filectime('./recently_ping.lock'))+5.0)<microtime(true)){
unlink('./recently_ping.lock');
session_reset();
}
sleep(1);
}
touch ('./recently_ping.lock');
//LOCKED
$recent=Array();
$recent['album']=$_GET['album'];
$recent['date']=microtime(true);
$recent['who']['color']=$_SESSION['color'];
$recent['who']['nick']=$_SESSION['nick'];
$recent['uid']=$_SESSION['crero_uid'];
$recent['jailed']=true;
if (!file_exists('./d/recent.dat')){
$recents= Array();
}
else {
$recents=unserialize(file_get_contents('./d/recent.dat'));
}
$_SESSION['jailtime']=$recent['date'];
if (!array_key_exists('recently_callback_id', $_SESSION)){
$_SESSION['recently_callback_id']=array();
}
$_SESSION['recently_callback_id'][$recent['album']]=array( 'id' => $_GET['recently_callback_id'], 'stamp' => microtime(true));
if (true){
if (count($recents)>=10000){//hey guys, let's store 1000 times more than we need, just to keep the jailed ones, unjail the legitimates upon validation, and with a certain incertainyty get 0.1% of our list that is valid visitors.
$recents=array_slice($recents, 1, 9999);
}
array_push($recents, $recent);
$dat=serialize($recents);
if ($dat!==false){
file_put_contents('./d/recent.dat', $dat);
}
if ($activatechat&&array_key_exists('nick', $_SESSION)){
$data['long']=$_SESSION['long'];
$data['lat']=$_SESSION['lat'];
$data['nick']=$_SESSION['nick'];
$data['range']=$_SESSION['range'];
$data['message']=' is playing '.html_entity_decode($recent['album']).' *';
$data['color']=$_SESSION['color'];
$dat=serialize($data);
file_put_contents('./network/d/'.microtime(true).'.dat', $dat);
}
}
}
//by the way, it's time to delete jailed album in recently played
//that haven't been validated within a minute and a half
//just by keeping those jailed
//since less than this period
$recentsjailed=Array();
if (file_exists('./d/recent.dat')){
$recentsjailed=unserialize(file_get_contents('./d/recent.dat'));
}
$recentsfinal=Array();
foreach ($recentsjailed as $recent){
if($recent['jailed']==false||(($recent['jailed']===true)&&(floatval($recent['date'])+90.0)>floatval(time()))){
array_push($recentsfinal, $recent);
}//if jailed && jailtime < 90 secondes OR not jailed
}
file_put_contents('./d/recent.dat', serialize($recentsfinal));
unlink ('./recently_ping.lock');
//UNLOCKED
if (array_key_exists('recently_callback', $_GET)){
throw new SystemExit();
}
//*************PRE CACHING ENDS**************
//* caching of htmlpage ; here we are
if ($activatehtmlcache&&!isset($_POST['validateemail'])&&!isset($_GET['pingstat'])){
if ($_SERVER['HTTP_USER_AGENT']==''){
http_response_code(403);
exit(0);
}
if ($myhtmlcache->hasPageExpired($cachingkey)){
$willhavetocache=true;
}
else {
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
if (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) <= date(DATE_RFC822, $myhtmlcache->getCachedPageDate($cachingkey))){
header(null);
session_abort();
header('HTTP/1.0 304 Not Modified');
throw new SystemExit();
}
}
header('Last-Modified: '.date(DATE_RFC822, $myhtmlcache->getCachedPageDate($cachingkey)));
echo $myhtmlcache->getCachedPage($cachingkey);
throw new SystemExit();
}
}
//caching of html page ; almost done. Just cache the output buffer once the page is fully generated. See end of this file
$album_scores=Array();
if ($activatestats&&false)
{
//The scoring system for each album is no longer used due to refactoring of the stats module to make it usable with htmlcache
$raw_scores=Array();
$scoredats=array_diff(scandir ('./admin/d/stats/'), Array ('.', '..', '.htaccess'));
foreach ($scoredats as $score_dat){
$thisscoredat=unserialize(file_get_contents('./admin/d/stats/'.$score_dat));
if (strstr($thisscoredat['page'], '?')){
$scoretokens=explode('?', $thisscoredat['page']);
$scoreuri=$scoretokens[1];
$scoregets=explode('&', $scoreuri);
foreach ($scoregets as $scoreget){
$scorepair=explode('=', $scoreget);
for ($dex=0;$dex<count($scorepair);$dex++){
if ($scorepair[$dex]==='album'){
if (!isset($raw_scores[urldecode($scorepair[$dex+1])])){
$raw_scores[urldecode($scorepair[$dex+1])]=1;
}
else {
$raw_scores[urldecode($scorepair[$dex+1])]++;
}
}
$dex++;
}
}
}
}
arsort($raw_scores);
$albums_scored=array_keys($raw_scores);
$maxscore=$raw_scores[$albums_scored[0]];
$multiplicant=floatval($maxscore/155);
foreach ($albums_scored as $album_scored){
$album_scores[$album_scored]=floatval($raw_scores[$album_scored]*$multiplicant);
}
//var_dump($raw_scores);
//var_dump($album_scores);
}
if ($activatestats&&isset($_GET['pingstat'])){
//if audience figures are activated, let's store the hit details in the stats directory
if ($sessionstarted){
if (!isset($_SESSION['statid'])){
$_SESSION['statid']=microtime(true);
$_SESSION['css_color']='rgb('.rand(140, 255).','.rand(140, 255).','.rand(140, 255).')';
}
$page['data']['agent']=$_SERVER['HTTP_USER_AGENT'];
$variable='agent';
if (!(strstr($page['data'][$variable],'bot')||
strstr($page['data'][$variable],'Yahoo! Slurp')||
strstr($page['data'][$variable],'+http://')||
strstr($page['data'][$variable],'+https://')||
strstr($page['data'][$variable],'()'))) {
//may be an human, we store it
$figure['userid']=$_SESSION['statid'];
$figure['css_color']=$_SESSION['css_color'];
$figure['page']=$_SERVER['REQUEST_URI'];
$figure['referer']=$_SERVER['HTTP_REFERER'];
$figure['random']=$_SESSION['random'];
$figure['origin']=$_SESSION['origin'];
file_put_contents('./admin/d/stats/'.microtime(true).'.dat', serialize($figure));
}
}
throw new SystemExit();//die();
}
$mosaic=false;
if (count(array_intersect(array_keys($_GET),array ('offset', 'listall', 'autoplay', 'vid', 'twist', 'embed')))==0){
$mosaic=true;
if ($_GET['listall']!='material'){
$_GET['listall']='albums';
}
}
if (count(array_intersect(array_keys($_GET), array ('artist', 'album', 'track', 'offset')))>0){
if($_GET['listall']=='albums')
unset($_GET['listall']);
$mosaic=false;
}
if (array_key_exists('listall', $_GET)&&$_GET['listall']!='albums'&&$_GET['listall']!='material'&&$_GET['listall']!='bogus'){
$mosaic=false;
}
if (isset($_GET['random'])&&$_GET['random']=='true'&&!isset($_GET['artist'])){
$_SESSION['random']=true;
}
else if (isset($_GET['random'])&&$_GET['random']=='false'){
$_SESSION['random']=false;
}
else if (isset($_GET['artist'])||isset($_GET['listall'])){
$_SESSION['random']=false;
}
if (isset($_GET['artist'])) {
//$artist=$_GET['artist'];
//$favicon='//'.$server.'/favicon.png';
$arturl='&artist='.urlencode($_GET['artist']);
//$title=htmlspecialchars($_GET['artist']).' - A '.htmlspecialchars($sitename).' artist';
$artists_file=trim(file_get_contents('./d/artists.txt'));
$artists=explode("\n", $artists_file);
if (!in_array($_GET['artist'], $artists)&&(file_exists('./d/artists.txt')&&count($artists)>0)) {
echo 'ooops... Invalid artist ! <a href="./">Browse the site, maybe?</a>';
throw new SystemExit();
}
}
else {
//$favicon='/favicon.png';
$arturl='';
$artist='';
}
if (!isset($_GET['artist'])){
$artists_file=trim(file_get_contents('./d/artists.txt'));
$artists=explode("\n", $artists_file);
if (count($artists)==0)
{
$artists=explode("\n", trim(file_get_contents($clewnapiurl.'?listartists=true')));
}
}
else {
$artists=Array($_GET['artist']);
}
$material_artists_file=htmlentities(trim(file_get_contents('./d/material_artists.txt')), ENT_COMPAT);
$material_artists=explode("\n", $material_artists_file);
$material_blacklist_file=htmlentities(trim(file_get_contents('./d/material_blacklist.txt')), ENT_COMPAT);
$material_blacklist=explode("\n", $material_blacklist_file);
if (isset($_GET['listall'])&&($_GET['listall']==='material'||($_GET['listall']==='mixed'&&isset($_GET['album'])))) {
$artists=$material_artists;
$material_currency=trim(file_get_contents('./d/material_currency.txt'));
$material_paypal_address=trim(file_get_contents('./d/material_paypal_address.txt'));
$material_shipping_file=trim(file_get_contents('./d/material_shipping.txt'));
$material_shippings=explode("\n", $material_shipping_file);
$material_shipping=Array();
$count=count($material_shippings);
$i=0;
while ($i < $count){
$material_shipping[$material_shippings[$i]]=$material_shippings[$i+1];
$i++;
$i++;
}
$material_supports_file=trim(file_get_contents('./d/material_supports_and_prices.txt'));
$material_supports=explode("\n", $material_supports_file);
$material_support=Array();
$i=0;
$count=count($material_supports);
while ($i<$count){
$material_support[$material_supports[$i]]['description']=$material_supports[$i+1];
$material_support[$material_supports[$i]]['price']=$material_supports[$i+2];
$material_support[$material_supports[$i]]['options']=$material_supports[$i+3];
$i++;
$i++;
$i++;
$i++;
}
}
function featuredvids(){
}
function cacheTracklist($album_entitified, $myserverapi) {
if (!file_exists('./d/albums_track_counter.dat')){
file_put_contents('./d/albums_track_counter.dat', serialize(array()));
}
$data=unserialize(file_get_contents('./d/albums_track_counter.dat'));
if ($data!==false){
$localfreshness=filectime('./d/albums_track_counter.dat');
$remotefreshness=file_get_contents($myserverapi.'?freshness=1');
if ($remotefreshness!==false){
if (floatval($localfreshness)>=floatval(trim($remotefreshness))){
if (array_key_exists($album_entitified, $data)){
return $data[$album_entitified];
}
}
}
}
/////NOT IN CACHE, QUERYING
$remotedat=file_get_contents($myserverapi.'?gettracks='.urlencode($album_entitified));
if ($remotedat!==false){
$data=unserialize(file_get_contents('./d/albums_track_counter.dat'));
if ($data!==false){
if (array_key_exists($album_entitified, $data)&&(strlen($data[$album_entitified])<=strlen($remotedat))){
$data[$album_entitified]=$remotedat;
file_put_contents('./d/albums_track_counter.dat', serialize($data));
return $remotedat;
}
else if (array_key_exists($album_entitified, $data)){
return $data[$album_entitified];
}
else if (!array_key_exists($album_entitified, $data)){
$data[$album_entitified]=$remotedat;
file_put_contents('./d/albums_track_counter.dat', serialize($data));
return $remotedat;
}
else {
return false;
}
}
}
return false;
}
function loginpanel($activateaccountcreation){
if (!$activateaccountcreation) {
return;
}
/*
if (isset($_SESSION['logged'])&&$_SESSION['logged']) {
}
else if (!isset($_GET['login'])&&!isset($_GET['createaccount'])&&!isset($_POST['validateemail'])){
// echo '<a href="./?login=login">Login</a> or <a href="./?createaccount=createaccount">Create account</a>';
*/ else if (!isset ($_POST['validateemail'])){
echo '<form id="orderform" style="display:inline;" method="POST" action="./"><a href="javascript:void(0);" onclick="document.getElementById(\'friends\').style.display=\'inline\';">Let\'s make friends ! </a><span id="friends" style="display:none;"><input type="text" name="validateemail" value="your email address" onfocus="if (this.value==\'your email address\'){this.value=\'\';}"/><input type="submit"/></span></form>';
}
else if (isset($_GET['createaccount'])) {
echo 'ease enter a <em>valid</em> email adress. You will receive a link to set your password and activate your account. <br/>';
echo '<form id="orderform" style="display:inline;" method="POST" action="./">Your email address : <input type="text" name="validateemail"/><input type="submit"/></form>';
}
else if (isset ($_POST['validateemail'])&&file_exists('./d/mailing-list-owner.txt')) {
$_POST['validateemail']=explode("\n",$_POST['validateemail'])[0];
$_POST['validateemail']=trim($_POST['validateemail']);
$message ='<html><body>Hello<br/>';
$message.="\r\n".'Someone requested mailing list ';
$message.="\r\n".'subscription using the email address <br/>'.htmlentities($_POST['validateemail']);
$message.="\r\n".'</body></html>';
$message=chunk_split($message);
if (
mail(trim(file_get_contents('./d/mailing-list-owner.txt')), 'Mailing list subscription request', $message, 'Content-Type: text/html;charset=UTF-8')
){
echo 'A subscription request has been sent for the address '.htmlspecialchars($_POST['validateemail']).'. We will get in touch shortly to confirm. <a href="./">Close</a>';
}
else {
echo 'The system has not been able to subscribe '.htmlspecialchars($_POST['validateemail']).'. Please <a href="">try again</a> later';
}
}
}
function outputArtistSiteLink($artistHTML, $albumHTML, $ArtistSites){
$returnLink='';
if (is_array($ArtistSites)&&count($ArtistSites)>0&&array_key_exists(html_entity_decode($artistHTML), $ArtistSites)){
$returnlink='Also available on <a target="_blank" href="'.$ArtistSites[html_entity_decode($artistHTML)].'?album='.rawurlencode(html_entity_decode($albumHTML)).'">'.$artistHTML.'</a> site';
}
return $returnlink;
}
function generatevideo($track_name, $album, $track_artist, $videoapiurl, $videourl, $albumhasvid) {
//let's see if there is a video available
if ($videoapiurl===false||intval($albumhasvid)<=0){
return;
}
$videotarget=trim(file_get_contents($videoapiurl.'?artist='.urlencode($track_artist).'&album='.urlencode($album).'&title='.urlencode($track_name).'&gettarget=y'));
$hasvideo=false;
$haslyrics=false;
if ($videotarget!==''){
$hasvideo=true;
}
//if has video and GET vid not set, dislplay video display link
//if has lyrics display lyrics link
if (($hasvideo || $haslyrics)){
echo '<div style="background-color:#FAFAFA;text-align:center;">';
if ($hasvideo&&!isset($_GET['vid'])){
echo '<a href="./?vid=play&track='.urlencode($track_name).'&album='.urlencode($album).'&artist='.urlencode($track_artist).'">Video available</a>';
}
echo '</div>';
}
if ($hasvideo&&isset($_GET['vid'])&&isset($_GET['artist'])&&isset($_GET['album'])&&isset($_GET['track'])){
echo '<div style="background-color:#FAFAFA">';
$videoformatsfile=trim(file_get_contents($videoapiurl.'?listformats='.urlencode($videotarget)));
$videoformats=explode("\n",$videoformatsfile);
$videotargetfiles=Array();
foreach ($videoformats as $videoformat){
$downgradefile=trim(file_get_contents($videoapiurl.'?hasdowngrade='.$videotarget.'&format='.$videoformat));
$downgradelist=explode("\n", $downgradefile);
sort($downgradelist);
if (count($downgradelist)>0) {
$videotargetfiles[$videoformat]=$downgradelist[0].'.'.$videotarget.'.'.$videoformat;
}
else {
$videotargetfiles[$videoformat]=$videotarget.'.'.$videoformat;
}
}
echo '<video controls="controls" autoplay="autoplay" style="width:100%;">';
foreach($videoformats as $videoformat) {
echo '<source src="'.htmlspecialchars($videourl.rawurlencode($videotarget).'.'.rawurlencode($videoformat)).'" mime-type="'.htmlspecialchars(mime_content_type($videotarget.'.'.$videoformat)).'"></source>';
}
echo 'Your browser is very old and does not support HTML5 video, sorry</video>';
echo '<br/>';
echo 'Download : ';
foreach ($videoformats as $videoformat) {
echo '<a download href="'.$videourl.rawurlencode($videotarget).'.'.rawurlencode($videoformat).'">'.htmlspecialchars($videoformat).'</a> ';
}
echo '<br/>';
echo htmlspecialchars(trim(file_get_contents($videourl.$videotarget.'.description.txt')));
echo '</div>';
}
}
function showsongsheet($track) {
if (file_exists('./songbook/'.$track.'.txt')){
echo '<div style="background-color:#A8A8A8;"><a href="#'.htmlspecialchars($track.'.txt').'" onclick="cr_document_menu_getElementById(\''.htmlspecialchars($track.'.txt').'\').style=\'display:block;\'">Lyrics/chords</a></div>';
echo '<a name="'.htmlspecialchars($track.'.txt').'"><div style="font-family:monospace;display:none;background-color:#DFDFDF;" id="'.htmlspecialchars($track.'.txt').'">'.str_replace("\n", '<br/>', htmlspecialchars(file_get_contents('./songbook/'.$track.'.txt'))).'</div></a>';
}
}
function displaycover($album, $ratio, $param='cover', $AlbumsToBeHighlighted = 0, $highlightcounter = 0){
if (file_exists('./d/covers.txt')){
if ($highlightcounter<$AlbumsToBeHighlighted){
$ratio=$ratio*2;
}
$coversfile=trim(file_get_contents('./d/covers.txt'));
$coverslines=explode("\n", $coversfile);
$i=0;
$url=null;
while ($i<count($coverslines)){
if ($coverslines[$i]==html_entity_decode($album)){
if (array_key_exists($i+1, $coverslines)){
$url=$coverslines[$i+1];
}
}
$i++;
$i++;
}
if (isset($url)){
$output='';
$output.='<table style="border:solid red 4px;border-radius:3px;"><tr><td><div style="display:inline;align:center;text-align:center;border:solid black 3px;border-radius:2px;"><img style="margin:auto;" class="lineTranslate" alt=" ['.$album.'] " id="'.$param.'_'.htmlspecialchars($album).'" onload="increment_overload_track_counter();if (!get_page_init()){init_page()};if (this.src==\'favicon.png\'){increment_thumbnail_max();};if (album_displayed<=album_counter){chckImg(this, \''.str_replace("'", "\\'", urlencode($url)).'\', '.floatval($ratio).');album_displayed++;}" src="favicon.png" />';
/*$output.='<script>
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL Version 3 or later
//var onload="if(!get_page_init()){;
/*if (document.documentElement.clientWidth>=document.documentElement.clientHeight){
onload="if(!get_page_init()){=document.documentElement.clientHeight;
}
else
{
onload="if(!get_page_init()){=document.documentElement.clientWidth;
}// ';
$output.='document.getElementById('."'".$param.'_'.str_replace("'","\\'",$album)."'".').src='."'".'./thumbnailer.php?target='."'".'+encodeURI('."'".str_replace("'","\\'",'./covers/'.$url)."'".')+'."'".'&viewportwidth='."'".'+encodeURI(onload="if(!get_page_init()){)+'."'".'&ratio='."'".'+encodeURI('."'".str_replace("'","\\'",$ratio)."'".');';
$output.='
// @license-end
</script>';