PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/server/localplay.ajax.php

https://gitlab.com/x33n/ampache
PHP | 201 lines | 139 code | 23 blank | 39 comment | 9 complexity | 028a9dc4e82190e4c37b145ef266a212 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 'set_instance':
  29. // Make sure they they are allowed to do this
  30. if (!Access::check('localplay','5')) {
  31. debug_event('DENIED','Error attempted to set instance without required level','1');
  32. exit;
  33. }
  34. $type = $_REQUEST['instance'] ? 'localplay' : 'stream';
  35. $localplay = new Localplay(AmpConfig::get('localplay_controller'));
  36. $localplay->set_active_instance($_REQUEST['instance']);
  37. Preference::update('play_type',$GLOBALS['user']->id,$type);
  38. // We should also refesh the sidebar
  39. ob_start();
  40. require_once AmpConfig::get('prefix') . '/templates/sidebar.inc.php';
  41. $results['sidebar-content'] = ob_get_contents();
  42. ob_end_clean();
  43. break;
  44. case 'command':
  45. // Make sure they are allowed to do this
  46. if (!Access::check('localplay','50')) {
  47. debug_event('DENIED','Attempted to control Localplay without sufficient access','1');
  48. exit;
  49. }
  50. $localplay = new Localplay(AmpConfig::get('localplay_controller'));
  51. $localplay->connect();
  52. // Switch on valid commands
  53. switch ($_REQUEST['command']) {
  54. case 'prev':
  55. case 'next':
  56. case 'stop':
  57. case 'play':
  58. case 'pause':
  59. $command = scrub_in($_REQUEST['command']);
  60. $localplay->$command();
  61. break;
  62. case 'volume_up':
  63. case 'volume_down':
  64. case 'volume_mute':
  65. $command = scrub_in($_REQUEST['command']);
  66. $localplay->$command();
  67. // We actually want to refresh something here
  68. ob_start();
  69. $objects = $localplay->get();
  70. require_once AmpConfig::get('prefix') . '/templates/show_localplay_status.inc.php';
  71. $results['localplay_status'] = ob_get_contents();
  72. ob_end_clean();
  73. break;
  74. case 'delete_all':
  75. $localplay->delete_all();
  76. ob_start();
  77. $browse = new Browse();
  78. $browse->set_type('playlist_localplay');
  79. $browse->set_static_content(true);
  80. $browse->save_objects(array());
  81. $browse->show_objects(array());
  82. $browse->store();
  83. $results[$browse->get_content_div()] = ob_get_contents();
  84. ob_end_clean();
  85. break;
  86. case 'skip':
  87. $localplay->skip(intval($_REQUEST['id']));
  88. $objects = $localplay->get();
  89. ob_start();
  90. $browse = new Browse();
  91. $browse->set_type('playlist_localplay');
  92. $browse->set_static_content(true);
  93. $browse->save_objects($objects);
  94. $browse->show_objects($objects);
  95. $browse->store();
  96. $results[$browse->get_content_div()] = ob_get_contents();
  97. ob_end_clean();
  98. break;
  99. default:
  100. // Nothing
  101. break;
  102. } // end whitelist
  103. break;
  104. case 'delete_track':
  105. // Load Connect... yada yada
  106. if (!Access::check('localplay','50')) {
  107. debug_event('DENIED','Attempted to delete track without access','1');
  108. exit;
  109. }
  110. $localplay = new Localplay(AmpConfig::get('localplay_controller'));
  111. $localplay->connect();
  112. // Scrub in the delete request
  113. $id = intval($_REQUEST['id']);
  114. $localplay->delete_track($id);
  115. // Wait in case we just deleted what we were playing
  116. sleep(3);
  117. $objects = $localplay->get();
  118. $status = $localplay->status();
  119. ob_start();
  120. $browse = new Browse();
  121. $browse->set_type('playlist_localplay');
  122. $browse->set_static_content(true);
  123. $browse->save_objects($objects);
  124. $browse->show_objects($objects);
  125. $browse->store();
  126. $results[$browse->get_content_div()] = ob_get_contents();
  127. ob_end_clean();
  128. break;
  129. case 'delete_instance':
  130. // Make sure that you have access to do this...
  131. if (!Access::check('localplay','75')) {
  132. debug_event('DENIED','Attempted to delete instance without access','1');
  133. exit;
  134. }
  135. // Scrub it in
  136. $localplay = new Localplay(AmpConfig::get('localplay_controller'));
  137. $localplay->delete_instance($_REQUEST['instance']);
  138. $key = 'localplay_instance_' . $_REQUEST['instance'];
  139. $results[$key] = '';
  140. break;
  141. case 'repeat':
  142. // Make sure that they have access to do this again no clue
  143. if (!Access::check('localplay','50')) {
  144. debug_event('DENIED','Attempted to set repeat without access','1');
  145. exit;
  146. }
  147. // Scrub her in
  148. $localplay = new Localplay(AmpConfig::get('localplay_controller'));
  149. $localplay->connect();
  150. $localplay->repeat(make_bool($_REQUEST['value']));
  151. ob_start();
  152. $objects = $localplay->get();
  153. require_once AmpConfig::get('prefix') . '/templates/show_localplay_status.inc.php';
  154. $results['localplay_status'] = ob_get_contents();
  155. ob_end_clean();
  156. break;
  157. case 'random':
  158. // Make sure that they have access to do this
  159. if (!Access::check('localplay','50')) {
  160. debug_event('DENIED','Attempted to set random without access','1');
  161. exit;
  162. }
  163. // Scrub her in
  164. $localplay = new Localplay(AmpConfig::get('localplay_controller'));
  165. $localplay->connect();
  166. $localplay->random(make_bool($_REQUEST['value']));
  167. ob_start();
  168. $objects = $localplay->get();
  169. require_once AmpConfig::get('prefix') . '/templates/show_localplay_status.inc.php';
  170. $results['localplay_status'] = ob_get_contents();
  171. ob_end_clean();
  172. break;
  173. default:
  174. $results['rfc3514'] = '0x1';
  175. break;
  176. } // switch on action;
  177. // We always do this
  178. echo xoutput_from_array($results);