PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/server/playlist.ajax.php

https://gitlab.com/x33n/ampache
PHP | 148 lines | 102 code | 14 blank | 32 comment | 14 complexity | 73c7d7b56558b877d4169c2075abdd7c MD5 | raw file
  1. <?php
  2. /* vim:set softtabstop=4 shiftwidth=4 expandtab: */
  3. /**
  4. *
  5. * LICENSE: GNU General Public License, version 2 (GPLv2)
  6. * Copyright 2001 - 2015 Ampache.org
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License v2
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. *
  21. */
  22. /**
  23. * Sub-Ajax page, requires AJAX_INCLUDE
  24. */
  25. if (!defined('AJAX_INCLUDE')) { exit; }
  26. $results = array();
  27. switch ($_REQUEST['action']) {
  28. case 'delete_track':
  29. // Create the object and remove the track
  30. $playlist = new Playlist($_REQUEST['playlist_id']);
  31. $playlist->format();
  32. if ($playlist->has_access()) {
  33. $playlist->delete_track($_REQUEST['track_id']);
  34. // This could have performance issues
  35. $playlist->regenerate_track_numbers();
  36. }
  37. $object_ids = $playlist->get_items();
  38. ob_start();
  39. $browse = new Browse();
  40. $browse->set_type('playlist_song');
  41. $browse->add_supplemental_object('playlist',$playlist->id);
  42. $browse->save_objects($object_ids);
  43. $browse->show_objects($object_ids);
  44. $browse->store();
  45. $results[$browse->get_content_div()] = ob_get_clean();
  46. break;
  47. case 'append_item':
  48. // Only song item are supported with playlists
  49. debug_event('playlist', 'Appending items to playlist {'.$_REQUEST['playlist_id'].'}...', '5');
  50. if (!isset($_REQUEST['playlist_id']) || empty($_REQUEST['playlist_id'])) {
  51. if (!Access::check('interface','25')) {
  52. debug_event('DENIED','Error:' . $GLOBALS['user']->username . ' does not have user access, unable to create playlist','1');
  53. break;
  54. }
  55. $name = $GLOBALS['user']->username . ' - ' . date("Y-m-d H:i:s",time());
  56. $playlist_id = Playlist::create($name,'public');
  57. if (!$playlist_id) {
  58. break;
  59. }
  60. $playlist = new Playlist($playlist_id);
  61. } else {
  62. $playlist = new Playlist($_REQUEST['playlist_id']);
  63. }
  64. if (!$playlist->has_access()) {
  65. break;
  66. }
  67. $songs = array();
  68. $item_id = $_REQUEST['item_id'];
  69. switch ($_REQUEST['item_type']) {
  70. case 'smartplaylist':
  71. $smartplaylist = new Search($item_id, 'song');
  72. $items = $playlist->get_items();
  73. foreach ($items as $item) {
  74. $songs[] = $item['object_id'];
  75. }
  76. break;
  77. case 'album':
  78. debug_event('playlist', 'Adding all songs of album(s) {'.$item_id.'}...', '5');
  79. $albums_array = explode(',', $item_id);
  80. foreach ($albums_array as $a) {
  81. $album = new Album($a);
  82. $asongs = $album->get_songs();
  83. foreach ($asongs as $song_id) {
  84. $songs[] = $song_id;
  85. }
  86. }
  87. break;
  88. case 'artist':
  89. debug_event('playlist', 'Adding all songs of artist {'.$item_id.'}...', '5');
  90. $artist = new Artist($item_id);
  91. $songs[] = $artist->get_songs();
  92. break;
  93. case 'song_preview':
  94. case 'song':
  95. debug_event('playlist', 'Adding song {'.$item_id.'}...', '5');
  96. $songs = explode(',', $item_id);
  97. break;
  98. case 'playlist':
  99. $pl = new Playlist($item_id);
  100. $songs = $pl->get_songs();
  101. break;
  102. default:
  103. debug_event('playlist', 'Adding all songs of current playlist...', '5');
  104. $objects = $GLOBALS['user']->playlist->get_items();
  105. foreach ($objects as $object_data) {
  106. $type = array_shift($object_data);
  107. if ($type == 'song') {
  108. $songs[] = array_shift($object_data);
  109. }
  110. }
  111. break;
  112. }
  113. if (count($songs) > 0) {
  114. Ajax::set_include_override(true);
  115. $playlist->add_songs($songs, true);
  116. /*$playlist->format();
  117. $object_ids = $playlist->get_items();
  118. ob_start();
  119. require_once AmpConfig::get('prefix') . '/templates/show_playlist.inc.php';
  120. $results['content'] = ob_get_contents();
  121. ob_end_clean();*/
  122. debug_event('playlist', 'Items added successfully!', '5');
  123. ob_start();
  124. display_notification(T_('Added to playlist'));
  125. $results['rfc3514'] = ob_get_clean();
  126. } else {
  127. debug_event('playlist', 'No item to add. Aborting...', '5');
  128. }
  129. break;
  130. default:
  131. $results['rfc3514'] = '0x1';
  132. break;
  133. }
  134. echo xoutput_from_array($results);