forked from jinzora/jinzora3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
1487 lines (1302 loc) · 46.3 KB
/
api.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
define('JZ_SECURE_ACCESS','true');
/**
* - JINZORA | Web-based Media Streamer -
*
* Jinzora is a Web-based media streamer, primarily desgined to stream MP3s
* (but can be used for any media file that can stream from HTTP).
* Jinzora can be integrated into a CMS site, run as a standalone application,
* or integrated into any PHP website. It is released under the GNU GPL.
*
* - Resources -
* - Jinzora Author: Ross Carlson <ross@jasbone.com>
* - Web: http://www.jinzora.org
* - Documentation: http://www.jinzora.org/docs
* - Support: http://www.jinzora.org/forum
* - Downloads: http://www.jinzora.org/downloads
* - License: GNU GPL <http://www.gnu.org/copyleft/gpl.html>
*
* - Contributors -
* Please see http://www.jinzora.org/team.html
*
* - Code Purpose -
* - This page handles all API requests for add-on services
*
* @since 04.14.05
* @author Ross Carlson <ross@jinzora.org>
* @author Ben Dodson <ben@jinzora.org>
*/
// Let's set the error reporting level
//@error_reporting(E_ERROR);
// Let's include ALL the functions we'll need
// Now we'll need to figure out the path stuff for our includes
// This is critical for CMS modes
$include_path = ""; $link_root = ""; $cms_type = ""; $cms_mode = "false";
$backend = ""; $jz_lang_file = ""; $skin = ""; $my_frontend = "";
define('NO_AJAX_LINKS','true');
include_once('system.php');
include_once('settings.php');
include_once('backend/backend.php');
include_once('playlists/playlists.php');
include_once('lib/general.lib.php');
include_once('lib/jzcomp.lib.php');
include_once('services/class.php');
$skin = "slick";
$image_dir = $root_dir. "/style/$skin/";
include_once('frontend/display.php');
include_once('frontend/blocks.php');
include_once('frontend/icons.lib.php');
include_once('frontend/frontends/slick/blocks.php');
include_once('frontend/frontends/slick/settings.php');
$this_page = setThisPage();
$enable_page_caching = "false";
url_alias();
// see this method for persistent vars
$api_page = get_base_url();
// Clean up input variables
$_REQUEST = unurlize($_REQUEST);
// Let's create our user object for later
$jzUSER = new jzUser();
// Let's create our services object
// This object lets us do things like get metadata, resize images, get lyrics, etc
$jzSERVICES = new jzServices();
$jzSERVICES->loadStandardServices();
$blocks = new jzBlocks();
$display = new jzDisplay();
$jz_path = $_REQUEST['jz_path'];
$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 0;
$params = array();
$params['limit'] = $limit;
if (empty($_REQUEST['request']) && (isset($_REQUEST['query']) || isset($_REQUEST['search']))) {
$_REQUEST['request'] = 'search';
}
// Non authenticated API requests.
switch($_REQUEST['request']){
case "trackinfo":
return trackInfo();
break;
case "gettrackart":
return getTrackArt();
break;
}
// Let's make sure this user has the right permissions
if ($jzUSER->getSetting("view") === false || isset($_REQUEST['user'])) {
if (isset($_REQUEST['user'])) {
$store_cookie = true;
// Are they ok?
$prehashed = (isset($_REQUEST['pw_hashed']) && $_REQUEST['pw_hashed']=='true');
if ($jzUSER->login($_REQUEST['user'],$_REQUEST['pass'],$store_cookie, $prehashed) === false) {
echoXMLHeader();
echo "<login>false</login>";
echoXMLFooter();
exit();
}
} else {
// Nope, error...
echoXMLHeader();
echo "<login>false</login>";
echoXMLFooter();
exit();
}
}
// Now let's see what they want
switch($_REQUEST['request']){
case "genres":
//return listAllGenres($limit); // why??? :(
return listAllSubNode("genre",$params);
break;
case "artists":
return listAllSubNode("artist",$params);
break;
case "albums":
return listAllSubNode("album",$params);
break;
case "playlists":
return playlists();
break;
case "playlist":
return playlist();
break;
case "saveplaylist":
return savePlaylist();
break;
case "deleteplaylist":
return deletePlaylist();
break;
case "curtrack":
return getCurrentTrack();
break;
case "search":
return search();
case "browse":
return browse();
break;
case "home":
return home();
break;
case "chart":
return chart();
break;
case "userhistories":
return userHistories();
break;
case "jukebox":
return jukebox();
break;
case "adduser":
return adduser();
break;
case "removeuser":
return removeuser();
break;
case "listusers":
return listusers();
break;
case "setpassword":
return setpassword();
break;
case "stylesheet":
echo '<link rel="stylesheet" title="slick" type="text/css" media="screen" href="'. $root_dir. '/style/'. $skin. '/default.php">';
break;
case "javascript":
$display->handleAJAX();
break;
case "artistAlbumsBlock":
case "artistProfileBlock":
case "displaySlickSampler":
case "displaySlickAllTracks":
case "artistAlbumArtBlock":
case "albumAlbumBlock":
case "albumTracksBlock":
case "albumOtherAlbumBlock":
case "blockUser":
case "blockNowStreaming":
case "blockWhoIsWhere":
case "blockSearch":
case "blockPlaylists":
case "blockBrowsing":
case "blockOptions":
case "slickHeaderBlock":
case "blockLogo":
$node = new jzMediaNode($_REQUEST['jz_path']);
$blocks->$_REQUEST['request']($node);
break;
default:
echoXMLHeader();
echo "<login>true</login>";
echoXMLFooter();
exit();
break;
}
/**
* Gets the output format requested
*
* @author Ben Dodson
* @since 6/21/08
*/
function getFormatFromRequest() {
if (isset($_REQUEST['type'])){
$type = $_REQUEST['type'];
} else if (isset($_REQUEST['output'])) {
$type = $_REQUEST['output'];
} else {
$type = "xml";
}
return $type;
}
// These are the functions for the API
/**
* User management API
*/
function adduser() {
global $jzUSER;
if ($jzUSER->getSetting('admin') === false){
echoXMLHeader();
echo " <error>Insufficient permissions.</error>\n";
echoXMLFooter();
return;
}
if (!isset($_REQUEST['add_user']) || !isset($_REQUEST['add_password'])) {
echoXMLHeader();
echo " <error>Please specify a username/password (add_user/add_password).</error>\n";
echoXMLFooter();
return;
}
$user = $_REQUEST['add_user'];
$password = $_REQUEST['add_password'];
$uid = $jzUSER->addUser($user,$password);
if ($uid === false) {
echoXMLHeader();
echo " <error>Failed to add username/password.</error>\n";
echoXMLFooter();
return;
}
// todo: probably read settings from a template.
echoXMLHeader();
echo " <userid>${uid}</userid>\n";
echoXMLFooter();
}
function listusers() {
global $jzUSER;
if ($jzUSER->getSetting('admin') === false){
echoXMLHeader();
echo " <error>Insufficient permissions.</error>\n";
echoXMLFooter();
return;
}
$list = $jzUSER->listUsers();
echoXMLHeader();
echo '<users>';
foreach ($list as $id=>$user) {
echo " <user>\n";
echo ' <id>'.$id."</id>\n";
echo ' <username>'.$user."</username>\n";
echo " </user>\n";
}
echo "</users>\n";
echoXMLFooter();
}
function removeuser() {
global $jzUSER;
if ($jzUSER->getSetting('admin') === false){
echoXMLHeader();
echo " <error>Insufficient permissions.</error>\n";
echoXMLFooter();
return;
}
if (!isset($_REQUEST['remove_id']) && !isset($_REQUEST['remove_user'])) {
echoXMLHeader();
echo " <error>Must specify a userto remove (remove_id or remove_user).</error>\n";
echoXMLFooter();
return;
}
if (isset($_REQUEST['remove_user'])) {
$id = $jzUSER->lookupUID($_REQUEST['remove_user']);
} else {
$id=$_REQUEST['remove_id'];
}
if ($id === false) {
echoXMLHeader();
echo " <error>Bad user specified.</error>\n";
echoXMLFooter();
return;
}
$jzUSER->removeUser($id);
echoXMLHeader();
echo " <status>User removed.</status>";
echoXMLFooter();
}
function setpassword() {
global $jzUSER;
if (!isset($_REQUEST['set_password'])) {
echoXMLHeader();
echo " <error>Must specify a password to set.</error>\n";
echoXMLFooter();
return;
}
$pw = $_REQUEST['set_password'];
if (isset($_REQUEST['modify_user'])) {
if ($jzUSER->getSetting('admin') === false){
echoXMLHeader();
echo " <error>Insufficient permissions.</error>\n";
echoXMLFooter();
return;
}
$user = $_REQUEST['modify_user'];
} else {
$user = false;
}
if (!$jzUSER->changePassword($pw,$user)) {
echoXMLHeader();
echo " <error>Failed to set password.</error>\n";
echoXMLFooter();
} else {
echoXMLHeader();
echo " <status>Changed password.</status>";
echoXMLFooter();
}
}
/**
*
* Searches the API and returns the results
*
* @author Ross Carlson
* @since 4/21/05
*
**/
function search(){
global $jzUSER, $this_site, $root_dir;
// What kind of output?
$type = getFormatFromRequest();
// Let's setup our objects
// The display object is just a set of functions related to display
// Like returning images and links
$display = new jzDisplay();
// Let's search
// This will search the API and return an array of objects
$st = isset($_REQUEST['search_type']) ? $_REQUEST['search_type'] : 'best';
$query = '';
if (!empty($_REQUEST['search'])) {
$query = $_REQUEST['search'];
}
$results = handleSearch($query, $st);
/*
// Now let's make sure we had results
if (count($results) == 0){
// Now let's output
switch ($type){
case "xml":
echoXMLHeader();
echo " <search>false</search>\n";
echoXMLFooter();
return;
break;
}
}
*/
print_results($results,$type);
}
/**
*
* Browses Jinzora given the path to a node.
*
* @author Ben Dodson
* @since 4/21/05
* @version 6/21/08
*
**/
function browse(){
global $jzUSER, $this_site, $root_dir;
$ntype = 'both';
if (!isset($_REQUEST['jz_path'])) {
return home(); // or browse root?
}
$type = getFormatFromRequest();
$root = new JzMediaNode($_REQUEST['jz_path']);
$trackfields = (isset($_REQUEST['track_fields'])) ? explode(',', $_REQUEST['track_fields']) : false;
$nodefields = (isset($_REQUEST['node_fields'])) ? explode(',', $_REQUEST['node_fields']) : false;
$distance = false;
if (isset($_REQUEST['resulttype'])) {
$rt = $_REQUEST['resulttype'];
if ($rt == 'artist') {
$distance = distanceTo('artist',$root);
}
if ($rt == 'album') {
$distance = distanceTo('album',$root);
}
if ($rt == 'track' || $rt == 'tracks') {
$distance = -1;
$ntype = 'tracks';
}
}
if (isset($_REQUEST['offset']) || isset($_REQUEST['limit'])){
//$results = array_slice($results,$_REQUEST['offset'],$_REQUEST['limit']);
}
$lim = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 0;
$off = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : false;
$results = $root->getSubNodes($ntype,$distance,false,$lim,false,$off);
$total = $root->getSubNodeCount($ntype,$distance);
$meta = array('totalMatches' => $total);
print_results($results, $type, $trackfields, $nodefields, $meta);
}
function getTrackArt(){
$display = new jzDisplay();
$track = &new jzMediaTrack($_GET['jz_path'],"id");
$album = $track->getAncestor("album");
$art = $album->getMainArt(false, true, "audio", true);
if($_GET['type'] == 'xml'){
echoXMLHeader();
echo " <track>\n";
echo " <name>". xmlentities($track->getName()). "</name>\n";
echo " <image>";
if ($art){
echo xmlentities($display->returnImage($art,false,false, false, "limit", false, false, false, false, false, "0", false, true, true));
}
echo " </image>\n";
echo " <thumbnail>";
$art = $album->getMainArt('75x75', true, "audio", true);
if ($art){
echo xmlentities($display->returnImage($art,false,75,75, "limit", false, false, false, false, false, "0", false, true, true));
}
echo " </thumbnail>\n";
echo " </track>\n";
echoXMLFooter();
} else {
showImage($art);
}
}
function trackInfo(){
global $this_site;
$display = new jzDisplay();
$track = &new jzMediaTrack($_GET['jz_path'],"id");
$meta = $track->getMeta();
$album = $track->getAncestor("album");
$art = $album->getMainArt(false, true, "audio", true);
$artist = $album->getAncestor("artist");
$genre = $artist->getParent();
$results = array();
$results[] = $track;
$trackfields = (isset($_REQUEST['track_fields'])) ? explode(',', $_REQUEST['track_fields']) : false;
$nodefields = (isset($_REQUEST['node_fields'])) ? explode(',', $_REQUEST['node']) : false;
$type = getFormatFromRequest();
print_results($results,$type, $trackfields, $nodefields);
}
function playlists() {
global $api_page, $this_site, $jzUSER;
$lists = $jzUSER->listPlaylists('all');
$type = getFormatFromRequest();
switch ($type){
case "xml":
echoXMLHeader();
echo " <search>\n";
echo " <tracks>\n";
echo " </tracks>\n";
echo " <nodes>\n";
foreach($lists as $id => $pname){
$plist = $jzUSER->loadPlaylist($id);
echo " <node>\n";
echo " <name>" . xmlentities($pname) . "</name>\n";
echo " <type>". xmlentities(ucwords("Playlist")) . "</type>\n";
echo " <playlink>". xmlentities($this_site .$plist->getPlayHREF()). "</playlink>\n";
echo " <image>";
echo " </image>\n";
echo " <playlistid>". xmlentities($id) . "</playlistid>\n";
echo " <thumbnail>";
echo " </thumbnail>\n";
//echo " <path>". xmlentities($pname). "</path>\n";
echo " <browse>". xmlentities($api_page.'&request=playlist&jz_playlist_id='. urlencode($id)). "</browse>\n";
echo " </node>\n";
}
echo " </nodes>\n";
echo " </search>\n";
echoXMLFooter();
break;
case "json":
$jt = array(); $jn = array();
foreach($lists as $id => $pname){
$a = array();
$plist = $jzUSER->loadPlaylist($id);
$a['name'] = $pname;
$a['type'] = ucwords("Playlist");
$a['playlink'] = $this_site . $plist->getPlayHREF();
$a['image'] = "";
$a['playlistid'] = $id;
$a['thumbnail'] = "";
$a['browse'] = $api_page.'&request=playlist&jz_playlist_id='. urlencode($id);
$jn[] = $a;
}
echo json_encode(array('tracks'=>$jt,'nodes'=>$jn));
break;
}
}
function playlist() {
global $jzUSER, $this_site, $root_dir;
$plist = $jzUSER->loadPlaylist($_REQUEST['jz_playlist_id']);
$plist->flatten();
$results = $plist->getList();
$type = getFormatFromRequest();
$trackfields = (isset($_REQUEST['track_fields'])) ? explode(',', $_REQUEST['track_fields']) : false;
$nodefields = (isset($_REQUEST['node_fields'])) ? explode(',', $_REQUEST['node']) : false;
print_results($results,$type, $trackfields, $nodefields);
}
function savePlaylist() {
global $jzUSER;
$songarr = $_REQUEST["songs"];
$tracks = array();
foreach($songarr as $song){
$track = &new jzMediaTrack($song,"id");
$tracks[] = $track;
}
$pl = new jzPlaylist($tracks, $_REQUEST['name'], "static");
$jzUSER->storePlaylist($pl);
echo $pl->getID();
}
function deletePlayList() {
global $jzUSER;
$jzUSER->removePlaylist($_REQUEST["jz_playlist_id"]);
}
/**
* Get an api-centric 'homepage' for Jinzora
*
* @author Ben Dodson
* @since 6/21/08
*/
function home() {
global $api_page;
$entries = array();
if (false !== distanceTo('genre')) {
$entries[] = array('name' => 'Browse Genres',
'description' => 'See music by genre.',
'browse' => $api_page.'&request=browse&jz_path='.urlencode('/')
);
}
$entries[] = array('name' => 'Browse Artists',
'description' => 'Browse all artists.',
'browse' => $api_page.'&request=browse&resulttype=artist&jz_path='.urlencode('/')
);
/*
$entries[] = array('name' => 'Browse Albums',
'description' => 'Browse all albums.',
'browse' => $api_page.'&request=browse&resulttype=album&jz_path='.urlencode('/')
);
*/
/*
$entries[] = array('name' => 'Browse Tracks',
'description' => 'Browse all tracks.',
'browse' => $api_page.'&request=browse&resulttype=track&jz_path='.urlencode('/')
);
*/
$entries[] = array('name' => 'Browse Playlists',
'description' => 'Browse all playlists.',
'browse' => $api_page.'&request=playlists'
);
$entries[] = array('name' => 'Recently Added Albums',
'description' => 'Albums recently added to Jinzora.',
'browse' => $api_page.'&request=chart&chart=newalbums'
);
$entries[] = array('name' => 'Recently Played Albums',
'description' => 'Albums recently listened to.',
'browse' => $api_page.'&request=chart&chart=recentlyplayedalbums'
);
$entries[] = array('name' => 'Recently Played by Friends',
'description' => 'Albums recently listened to.',
'browse' => $api_page.'&request=userhistories'
);
$entries[] = array('name' => 'Random Albums',
'description' => 'A list of randomly selected albums.',
'browse' => $api_page.'&request=chart&chart=randomalbums'
);
$type = getFormatFromRequest();
print_lists($entries,$type);
}
/**
* Play histories for users
*/
function userHistories() {
global $api_page;
$be = new jzBackend();
if (!isset($_REQUEST['forUser'])) {
$users = $be->getUsersWithHistories();
$type = getFormatFromRequest();
switch ($type){
case "xml":
echoXMLHeader();
echo " <search>\n";
echo " <tracks>\n";
echo " </tracks>\n";
echo " <nodes>\n";
foreach($users as $u){
$playlink = xmlentities($api_page.'&request=userhistories&doplaylist=true&forUser='.$u.'&ext=pl.m3u');
echo " <node>\n";
echo " <name>" . xmlentities("Played By " . $u) . "</name>\n";
echo " <type>". xmlentities(ucwords("User-History")) . "</type>\n";
echo " <playlink>" . $playlink . "</playlink>\n";
echo " <image>";
echo " </image>\n";
//echo " <playlistid>";
//echo " </playlistid>\n";
echo " <thumbnail>";
echo " </thumbnail>\n";
//echo " <path>". xmlentities($pname). "</path>\n";
echo " <browse>". xmlentities($api_page.'&request=userhistories&forUser='.$u). "</browse>\n";
echo " </node>\n";
}
echo " </nodes>\n";
echo " </search>\n";
echoXMLFooter();
break;
case "json":
case "jsonp":
if ($type == "jsonp"){
echo $_GET['jsoncallback'] . '(';
}
$jt = array(); $jn = array();
foreach($users as $u){
// hack for now. TODO: merge play histories into core.
$playlink = $api_page.'&request=userhistories&doplaylist=true&forUser='.$u.'&ext=pl.m3u';
$a = array();
$a['name'] = "Played By " . $u;
$a['type'] = ucwords("User-History");
$a['playlink'] = $playlink;
$a['image'] = "";
//$a['playlistid'] = $id;
$a['thumbnail'] = "";
$a['browse'] = $api_page.'&request=userhistories&forUser='.$u;
$jn[] = $a;
}
echo json_encode(array('tracks'=>$jt,'nodes'=>$jn));
if ($type == "jsonp"){
echo ')';
}
break;
}
return;
} else {
$for = $_REQUEST['forUser'];
$h = $be->getPlayHistory($for);
if ($_REQUEST['doplaylist']) {
$pl = new jzPlaylist();
$pl->add($h);
$pl->stream();
} else {
$trackfields = (isset($_REQUEST['track_fields'])) ? explode(',', $_REQUEST['track_fields']) : false;
$nodefields = (isset($_REQUEST['node_fields'])) ? explode(',', $_REQUEST['node']) : false;
print_results($h,getFormatFromRequest(), $trackfields, $nodefields);
}
}
}
/**
* Gets the requested chart.
* @author Ben Dodson
* @since 6/21/08
*/
function chart() {
// todo: use common code for charts in blocks.php and here.
$chart = $_REQUEST['chart'];
$limit = 25;
$results = array();
if (isset($_REQUEST['jz_path'])) {
$root = new jzMediaNode($_REQUEST['jz_path']);
} else {
$root = new jzMediaNode();
}
switch ($chart) {
case 'newalbums':
$results = $root->getRecentlyAdded('nodes',distanceTo('album',$root),$limit);
break;
case 'recentlyplayedalbums':
$results = $root->getRecentlyPlayed('nodes',distanceTo('album',$root),$limit);
break;
case 'randomalbums':
$results = $root->getSubnodes('nodes',distanceTo('album',$root),true,$limit);
break;
}
print_results($results,getFormatFromRequest());
}
function jukebox() {
global $jzUSER;
if (!isset($_REQUEST['jb_id']) && $_REQUEST['action'] != 'list') {
return;
}
$_SESSION['jb_id'] = $_REQUEST['jb_id'];
if (isset($_REQUEST['action'])) {
if ($_REQUEST['action']=='list') {
if ($jzUSER->getSetting('jukebox_admin') === false && $jzUSER->getSetting('jukebox_queue') === false) {
echo "";
return;
}
@include_once('jukebox/class.php');
$jbArr = jzJukebox::getJbArr();
foreach ($jbArr as $key => $val) {
echo $key.':'.$val['description']."\n";
}
}
}
// Do we need to use the standard jukebox or not?
// Now did they have a subcommand?
if ($jzUSER->getSetting('jukebox_admin') === false && $jzUSER->getSetting('jukebox_queue') === false) {
echo 'insufficient permissions.';
exit();
}
if (isset($_REQUEST['external_playlist'])) {
require_once('playlists/class.php');
$pl = new JzPlaylist();
$pl->addFromExternal($_REQUEST['external_player']);
$pl->jukebox();
// Questions: how to handle addwhere param;
// how to bring in media as JzObject (without breaking built-in calls)
return;
}
// Jukebox commands:
if (isset($_REQUEST['command'])){
$command = $_REQUEST['command'];
// Let's include the Jukebox classes
writeLogData("messages","API: Passing command: ". $command. " to the jukebox");
include_once("jukebox/class.php");
$jb = new jzJukebox();
$jb->passCommand($command);
}
}
/**
*
* Echos out the XML header information
*
* @author Ross Carlson
* @since 3/31/05
*
**/
function getCurrentTrack(){
global $jzUSER, $this_site, $root_dir;
// What kind of output?
if (isset($_REQUEST['type'])){
$type = $_REQUEST['type'];
} else {
$type = "xml";
}
// Now let's set the width
if (isset($_REQUEST['imagesize'])){
$imagesize = $_REQUEST['imagesize']. "x". $_REQUEST['imagesize'];
} else {
$imagesize = "150x150";
}
// Now let's see when to stop
if (isset($_REQUEST['count'])){
$total = $_REQUEST['count'];
} else {
$total = 1;
}
// Let's start the page
if ($type == "xml"){
echoXMLHeader();
}
// Now let's get the data
$be = new jzBackend();
$ar = $be->getPlaying();
$display = new jzDisplay();
$fullList = "";
$found=false;
foreach($ar as $user=>$tracks) {
$name = $jzUSER->getSetting("full_name");
if ($name == ""){
$name = $jzUSER->lookupName($user); // that's the user name
}
$i=0;
foreach($tracks as $time=>$song) {
// Now let's make sure this is the right user
if ($name == $jzUSER->getName()){
// Now let's make sure we don't list this twice
if (stristr($fullList,$song['path']. "-". $name. "\n")){continue;}
$fullList .= $song['path']. "-". $name. "\n";
// Now let's create the objects we need
$node = new jzMediaNode($song['path']);
$track = new jzMediaTrack($song['path']);
$album = $node->getParent();
$artist = $album->getParent();
$meta = $track->getMeta();
// Now, now let's echo out the data
switch ($type){
case "xml":
echo " <item>\n";
echo " <title>". $this_site. xmlUrlClean($meta['title']). "</title>\n";
echo " <album>\n";
echo " <name>". $this_site. xmlUrlClean($album->getName()). "</name>\n";
echo " <image>". $this_site. xmlUrlClean($display->returnImage($album->getMainArt(false, true, "audio", true),$album->getName(),false, false, "limit", false, false, false, false, false, "0", false, true, true)). "</image>\n";
echo " </album>\n";
echo " <artist>\n";
echo " <name>". $this_site. xmlUrlClean($artist->getName()). "</name>\n";
echo " <image>". $this_site. xmlUrlClean($display->returnImage($artist->getMainArt(false, true, "audio", true),$artist->getName(),false, false, "limit", false, false, false, false, false, "0", false, true, true)). "</image>\n";
echo " </artist>\n";
echo " </item>\n";
break;
case "html":
if (isset($_REQUEST['align'])){
if ($_REQUEST['align'] == "center"){
echo "<center>";
}
}
echo $meta['title']. "<br>";
echo $album->getName(). "<br>";
echo $this_site. $display->returnImage($album->getMainArt(false, true, "audio", true),$album->getName(),false, false, "limit", false, false, false, false, false, "0", false, true, true). "<br>";
echo $artist->getName(). "<br>";
echo $display->returnImage($artist->getMainArt(false, true, "audio", true),$artist->getName(),false, false, "limit", false, false, false, false, false, "0", false, true, true). "<br>";
break;
case "mt":
$art = $album->getMainArt($imagesize, true, "audio", true);
if ($art){
// Now let's try to get the link from the amazon meta data service
if ($_REQUEST['amazon_id'] <> ""){
$jzService = new jzServices();
$jzService->loadService("metadata", "amazon");
$id = $jzService->getAlbumMetadata($album, false, "id");
echo '<a target="_blank" href="http://www.amazon.com/exec/obidos/tg/detail/-/'. $id. '/'. $_REQUEST['amazon_id']. '/">';
}
$display->image($art,$album->getName(),150,false,"limit");
if ($_REQUEST['amazon_id'] <> ""){
echo '</a>';
}
echo "<br>";
}
echo $meta['title']. "<br>";
if ($_REQUEST['amazon_id'] <> ""){
$jzService = new jzServices();
$jzService->loadService("metadata", "amazon");
$id = $jzService->getAlbumMetadata($album, false, "id");
echo '<a target="_blank" href="http://www.amazon.com/exec/obidos/tg/detail/-/'. $id. '/'. $_REQUEST['amazon_id']. '/">'. $album->getName(). "</a><br>";
} else {
echo $album->getName(). "<br>";
}
echo $artist->getName(). "<br>";
break;
}
$found=true;
// Now should we stop?
$i++;
if ($i >= $total){ break; }
}
}
}
if (!$found){
// Ok, we didn't find anything so let's get the last thing they played...
$be = new jzBackend();
$history = explode("\n",$be->loadData("playhistory-". $jzUSER->getID()));
$track = new jzMediatrack($history[count($history)-1]);
$album = $track->getParent();
$artist = $album->getParent();
$meta = $track->getMeta();
// Now, now let's echo out the data
switch ($type){
case "xml":
echo " <item>\n";
echo " <title>". $this_site. xmlUrlClean($meta['title']). "</title>\n";
echo " <album>\n";
echo " <name>". $this_site. xmlUrlClean($album->getName()). "</name>\n";
echo " <image>". $this_site. xmlUrlClean($display->returnImage($album->getMainArt(false, true, "audio", true),$album->getName(),false, false, "limit", false, false, false, false, false, "0", false, true, true)). "</image>\n";
echo " </album>\n";
echo " <artist>\n";
echo " <name>". $this_site. xmlUrlClean($artist->getName()). "</name>\n";
echo " <image>". $this_site. xmlUrlClean($display->returnImage($artist->getMainArt(false, true, "audio", true),$artist->getName(),false, false, "limit", false, false, false, false, false, "0", false, true, true)). "</image>\n";
echo " </artist>\n";
echo " </item>\n";
break;
case "html":
if (isset($_REQUEST['align'])){
if ($_REQUEST['align'] == "center"){
echo "<center>";
}
}
echo $meta['title']. "<br>";
echo $album->getName(). "<br>";
echo $this_site. $display->returnImage($album->getMainArt(false, true, "audio", true),$album->getName(),false, false, "limit", false, false, false, false, false, "0", false, true, true). "<br>";
echo $artist->getName(). "<br>";