~ubuntu-branches/debian/sid/ampache/sid

« back to all changes in this revision

Viewing changes to server/playlist.ajax.php

  • Committer: Package Import Robot
  • Author(s): Charlie Smotherman
  • Date: 2013-08-27 13:19:48 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20130827131948-1czew0zxn6u70dtv
Tags: 3.6-rzb2752+dfsg-1
* New upsteam snapshot.  Contains important bug fixes to the installer.
* Correct typo in ampache-common.postrm.
* Remove courtousy copy of php-getid3, during repack.  Closes: #701526
* Update package to use dh_linktree to make the needed sym links to the
  needed system libs that were removed during repack.
* Update debian/rules to reflect upstreams removing/moving of modules.
* Update debian/ampache-common.install to reflect upstreams removal of files.
* Updated to use new apache2.4 API. Closes: #669756
* Updated /debian/po/de.po thx David Prévot for the patch.  Closes:  #691963
* M3U import is now ordered, fixed upstream.  Closes: #684984
* Text input area has been resized so IPv6 addresses will now fit, fixed
  upstream.  Closes:  #716230
* Added ampache-common.preinst to make sure that the courtousy copies of code
  dirs are empty so dh_linktree can do it's magic on upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
 
2
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
3
3
/**
4
 
 * Playlist Ajax
5
 
 *
6
4
 *
7
5
 * LICENSE: GNU General Public License, version 2 (GPLv2)
8
 
 * Copyright (c) 2001 - 2011 Ampache.org All Rights Reserved
 
6
 * Copyright 2001 - 2013 Ampache.org
9
7
 *
10
8
 * This program is free software; you can redistribute it and/or
11
9
 * modify it under the terms of the GNU General Public License v2
20
18
 * along with this program; if not, write to the Free Software
21
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
20
 *
23
 
 * @package     Ampache
24
 
 * @copyright   2001 - 2011 Ampache.org
25
 
 * @license     http://opensource.org/licenses/gpl-2.0 GPLv2
26
 
 * @link        http://www.ampache.org/
27
21
 */
28
22
 
29
23
/**
32
26
if (!defined('AJAX_INCLUDE')) { exit; }
33
27
 
34
28
switch ($_REQUEST['action']) {
35
 
        case 'delete_track':
36
 
                // Create the object and remove the track
37
 
                $playlist = new Playlist($_REQUEST['playlist_id']);
38
 
                $playlist->format();
39
 
                if ($playlist->has_access()) {
40
 
                        $playlist->delete_track($_REQUEST['track_id']);
41
 
                }
42
 
 
43
 
                $object_ids = $playlist->get_items();
44
 
                ob_start();
45
 
                $browse = new Browse();
46
 
                $browse->set_type('playlist_song');
47
 
                $browse->add_supplemental_object('playlist',$playlist->id);
48
 
                $browse->save_objects($object_ids);
49
 
                $browse->show_objects($object_ids);
50
 
                $browse->store();
51
 
                $results['browse_content'] = ob_get_clean();
52
 
        break;
53
 
        case 'edit_track':
54
 
                $playlist = new Playlist($_REQUEST['playlist_id']);
55
 
                if (!$playlist->has_access()) {
56
 
                        $results['rfc3514'] = '0x1';
57
 
                        break;
58
 
                }
59
 
 
60
 
                // They've got access, show the edit page
61
 
                $track = $playlist->get_track($_REQUEST['track_id']);
62
 
                $song = new Song($track['object_id']);
63
 
                $song->format();
64
 
                require_once Config::get('prefix') . '/templates/show_edit_playlist_song_row.inc.php';
65
 
                $results['track_' . $track['id']] = ob_get_clean();
66
 
        break;
67
 
        case 'save_track':
68
 
                $playlist = new Playlist($_REQUEST['playlist_id']);
69
 
                if (!$playlist->has_access()) {
70
 
                        $results['rfc3514'] = '0x1';
71
 
                        break;
72
 
                }
73
 
                $playlist->format();
74
 
 
75
 
                // They've got access, save this guy and re-display row
76
 
                $playlist->update_track_number($_GET['track_id'],$_POST['track']);
77
 
                $track = $playlist->get_track($_GET['track_id']);
78
 
                $song = new Song($track['object_id']);
79
 
                $song->format();
80
 
                $playlist_track = $track['track'];
81
 
                require Config::get('prefix') . '/templates/show_playlist_song_row.inc.php';
82
 
                $results['track_' . $track['id']] = ob_get_clean();
83
 
        break;
84
 
        case 'create':
85
 
                if (!Access::check('interface','25')) {
86
 
                        debug_event('DENIED','Error:' . $GLOBALS['user']->username . ' does not have user access, unable to create playlist','1');
87
 
                        break;
88
 
                }
89
 
 
90
 
                // Pull the current active playlist items
91
 
                $objects = $GLOBALS['user']->playlist->get_items();
92
 
 
93
 
                $name = $GLOBALS['user']->username . ' - ' . date("Y-m-d H:i:s",time());
94
 
 
95
 
                // generate the new playlist
96
 
                $playlist_id = Playlist::create($name,'public');
97
 
                if (!$playlist_id) { break; }
98
 
                $playlist = new Playlist($playlist_id);
99
 
 
100
 
                // Itterate through and add them to our new playlist
101
 
                foreach ($objects as $object_data) {
102
 
                        // For now only allow songs on here, we'll change this later
103
 
                        $type = array_shift($object_data);
104
 
                        if ($type == 'song') {
105
 
                                $songs[] = array_shift($object_data);
106
 
                        }
107
 
                } // object_data
108
 
 
109
 
                // Add our new songs
110
 
                $playlist->add_songs($songs,'ORDERED');
111
 
                $playlist->format();
112
 
                $object_ids = $playlist->get_items();
113
 
                ob_start();
114
 
                require_once Config::get('prefix') . '/templates/show_playlist.inc.php';
115
 
                $results['content'] = ob_get_clean();
116
 
        break;
117
 
        case 'append':
118
 
                // Pull the current active playlist items
119
 
                $objects = $GLOBALS['user']->playlist->get_items();
120
 
 
121
 
                // Create the playlist object
122
 
                $playlist = new Playlist($_REQUEST['playlist_id']);
123
 
 
124
 
                // We need to make sure that they have access
125
 
                if (!$playlist->has_access()) {
126
 
                        break;
127
 
                }
128
 
 
129
 
                $songs = array();
130
 
 
131
 
                // Itterate through and add them to our new playlist
132
 
                foreach ($objects as $element) {
133
 
                        $type = array_shift($element);
134
 
                        switch ($type) {
135
 
                                case 'song':
136
 
                                        $songs[] = array_shift($element);
137
 
                                break;
138
 
                        } // end switch
139
 
                } // foreach
140
 
 
141
 
                // Override normal include procedure
142
 
                Ajax::set_include_override(true);
143
 
 
144
 
                // Add our new songs
145
 
                $playlist->add_songs($songs,'ORDERED');
146
 
                $playlist->format();
147
 
                $object_ids = $playlist->get_items();
148
 
                ob_start();
149
 
                require_once Config::get('prefix') . '/templates/show_playlist.inc.php';
150
 
                $results['content'] = ob_get_contents();
151
 
                ob_end_clean();
152
 
        break;
153
 
        default:
154
 
                $results['rfc3514'] = '0x1';
155
 
        break;
 
29
    case 'delete_track':
 
30
        // Create the object and remove the track
 
31
        $playlist = new Playlist($_REQUEST['playlist_id']);
 
32
        $playlist->format();
 
33
        if ($playlist->has_access()) {
 
34
            $playlist->delete_track($_REQUEST['track_id']);
 
35
        }
 
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_content'] = ob_get_clean();
 
46
    break;
 
47
    case 'edit_track':
 
48
        $playlist = new Playlist($_REQUEST['playlist_id']);
 
49
        if (!$playlist->has_access()) {
 
50
            $results['rfc3514'] = '0x1';
 
51
            break;
 
52
        }
 
53
 
 
54
        // They've got access, show the edit page
 
55
        $track = $playlist->get_track($_REQUEST['track_id']);
 
56
        $song = new Song($track['object_id']);
 
57
        $song->format();
 
58
        require_once Config::get('prefix') . '/templates/show_edit_playlist_song_row.inc.php';
 
59
        $results['track_' . $track['id']] = ob_get_clean();
 
60
    break;
 
61
    case 'save_track':
 
62
        $playlist = new Playlist($_REQUEST['playlist_id']);
 
63
        if (!$playlist->has_access()) {
 
64
            $results['rfc3514'] = '0x1';
 
65
            break;
 
66
        }
 
67
        $playlist->format();
 
68
 
 
69
        // They've got access, save this guy and re-display row
 
70
        $playlist->update_track_number($_GET['track_id'],$_POST['track']);
 
71
        $track = $playlist->get_track($_GET['track_id']);
 
72
        $song = new Song($track['object_id']);
 
73
        $song->format();
 
74
        $playlist_track = $track['track'];
 
75
        require Config::get('prefix') . '/templates/show_playlist_song_row.inc.php';
 
76
        $results['track_' . $track['id']] = ob_get_clean();
 
77
    break;
 
78
    case 'create':
 
79
        if (!Access::check('interface','25')) {
 
80
            debug_event('DENIED','Error:' . $GLOBALS['user']->username . ' does not have user access, unable to create playlist','1');
 
81
            break;
 
82
        }
 
83
 
 
84
        // Pull the current active playlist items
 
85
        $objects = $GLOBALS['user']->playlist->get_items();
 
86
 
 
87
        $name = $GLOBALS['user']->username . ' - ' . date("Y-m-d H:i:s",time());
 
88
 
 
89
        // generate the new playlist
 
90
        $playlist_id = Playlist::create($name,'public');
 
91
        if (!$playlist_id) { break; }
 
92
        $playlist = new Playlist($playlist_id);
 
93
 
 
94
        // Iterate through and add them to our new playlist
 
95
        foreach ($objects as $object_data) {
 
96
            // For now only allow songs on here, we'll change this later
 
97
            $type = array_shift($object_data);
 
98
            if ($type == 'song') {
 
99
                $songs[] = array_shift($object_data);
 
100
            }
 
101
        } // object_data
 
102
 
 
103
        // Add our new songs
 
104
        $playlist->add_songs($songs,'ORDERED');
 
105
        $playlist->format();
 
106
        $object_ids = $playlist->get_items();
 
107
        ob_start();
 
108
        require_once Config::get('prefix') . '/templates/show_playlist.inc.php';
 
109
        $results['content'] = ob_get_clean();
 
110
    break;
 
111
    case 'append':
 
112
        // Pull the current active playlist items
 
113
        $objects = $GLOBALS['user']->playlist->get_items();
 
114
 
 
115
        // Create the playlist object
 
116
        $playlist = new Playlist($_REQUEST['playlist_id']);
 
117
 
 
118
        // We need to make sure that they have access
 
119
        if (!$playlist->has_access()) {
 
120
            break;
 
121
        }
 
122
 
 
123
        $songs = array();
 
124
 
 
125
        // Iterate through and add them to our new playlist
 
126
        foreach ($objects as $element) {
 
127
            $type = array_shift($element);
 
128
            switch ($type) {
 
129
                case 'song':
 
130
                    $songs[] = array_shift($element);
 
131
                break;
 
132
            } // end switch
 
133
        } // foreach
 
134
 
 
135
        // Override normal include procedure
 
136
        Ajax::set_include_override(true);
 
137
 
 
138
        // Add our new songs
 
139
        $playlist->add_songs($songs,'ORDERED');
 
140
        $playlist->format();
 
141
        $object_ids = $playlist->get_items();
 
142
        ob_start();
 
143
        require_once Config::get('prefix') . '/templates/show_playlist.inc.php';
 
144
        $results['content'] = ob_get_contents();
 
145
        ob_end_clean();
 
146
    break;
 
147
    default:
 
148
        $results['rfc3514'] = '0x1';
 
149
    break;
156
150
} // switch on action;
157
151
 
158
152
// We always do this