Example #1
0
 private function on_get()
 {
     $response = [];
     foreach (['langs', 'options', 'types'] as $name) {
         if ($this->request->query_boolean($name, false)) {
             $methodname = 'get_' . $name;
             $response[$name] = $this->context->{$methodname}();
         }
     }
     if ($this->request->query_boolean('setup', false)) {
         $response['setup'] = $this->setup->to_jsono($this->context->is_admin());
     }
     if ($this->request->query_boolean('theme', false)) {
         $theme = new Theme($this->context);
         $response['theme'] = $theme->get_icons();
     }
     if ($this->request->query('items', false)) {
         $href = $this->request->query('items.href');
         $what = $this->request->query_numeric('items.what');
         $response['items'] = $this->context->get_items($href, $what);
     }
     if ($this->request->query('custom', false)) {
         Util::json_fail(Util::ERR_DISABLED, 'custom disabled', !$this->context->query_option('custom.enabled', false));
         $href = $this->request->query('custom');
         $custom = new Custom($this->context);
         $response['custom'] = $custom->get_customizations($href);
     }
     if ($this->request->query('l10n', false)) {
         Util::json_fail(Util::ERR_DISABLED, 'l10n disabled', !$this->context->query_option('l10n.enabled', false));
         $iso_codes = $this->request->query_array('l10n');
         $iso_codes = array_filter($iso_codes);
         $response['l10n'] = $this->context->get_l10n($iso_codes);
     }
     if ($this->request->query('search', false)) {
         Util::json_fail(Util::ERR_DISABLED, 'search disabled', !$this->context->query_option('search.enabled', false));
         $href = $this->request->query('search.href');
         $pattern = $this->request->query('search.pattern');
         $search = new Search($this->context);
         $response['search'] = $search->get_items($href, $pattern);
     }
     if ($this->request->query('thumbs', false)) {
         Util::json_fail(Util::ERR_DISABLED, 'thumbnails disabled', !$this->context->query_option('thumbnails.enabled', false));
         Util::json_fail(Util::ERR_UNSUPPORTED, 'thumbnails not supported', !$this->setup->get('HAS_PHP_JPEG'));
         $thumbs = $this->request->query_array('thumbs');
         $response['thumbs'] = $this->context->get_thumbs($thumbs);
     }
     Util::json_exit($response);
 }
Example #2
0
         $songs = $album->get_songs();
         foreach ($songs as $song) {
             $media_ids[] = array('object_type' => 'song', 'object_id' => $song);
         }
     }
     break;
 case 'playlist':
     $playlist = new Playlist($_REQUEST['playlist_id']);
     $songs = $playlist->get_songs();
     foreach ($songs as $song) {
         $media_ids[] = array('object_type' => 'song', 'object_id' => $song);
     }
     break;
 case 'smartplaylist':
     $playlist = new Search('song', $_REQUEST['playlist_id']);
     $items = $playlist->get_items();
     foreach ($items as $item) {
         $media_ids[] = array('object_type' => $item['object_type'], 'object_id' => $item['object_id']);
     }
     break;
 case 'playlist_random':
     $playlist = new Playlist($_REQUEST['playlist_id']);
     $media_ids = $playlist->get_random_items();
     break;
 case 'random':
     $matchlist = array();
     if ($_REQUEST['genre'][0] != '-1') {
         $matchlist['genre'] = $_REQUEST['genre'];
     }
     if ($_REQUEST['catalog'] != '-1') {
         $matchlist['catalog'] = $_REQUEST['catalog'];
Example #3
0
        break;
    case 'delete_playlist':
        // If we made it here, we didn't have sufficient rights.
        UI::access_denied();
        break;
    case 'show_playlist':
        $playlist = new Search($_REQUEST['playlist_id'], 'song');
        $playlist->format();
        $object_ids = $playlist->get_items();
        require_once AmpConfig::get('prefix') . UI::find_template('show_search.inc.php');
        break;
    case 'update_playlist':
        $playlist = new Search($_REQUEST['playlist_id'], 'song');
        if ($playlist->has_access()) {
            $playlist->parse_rules(Search::clean_request($_REQUEST));
            $playlist->update();
            $playlist->format();
        } else {
            UI::access_denied();
            break;
        }
        $object_ids = $playlist->get_items();
        require_once AmpConfig::get('prefix') . UI::find_template('show_search.inc.php');
        break;
    default:
        $object_ids = $playlist->get_items();
        require_once AmpConfig::get('prefix') . UI::find_template('show_search.inc.php');
        break;
}
// switch on the action
UI::show_footer();
Example #4
0
 public static function _musicChilds($prmPath, $prmQuery, $start, $count)
 {
     $mediaItems = array();
     $maxCount = 0;
     $queryData = array();
     parse_str($prmQuery, $queryData);
     $parent = 'amp://music' . $prmPath;
     $pathreq = explode('/', $prmPath);
     if ($pathreq[0] == '' && count($pathreq) > 0) {
         array_shift($pathreq);
     }
     switch ($pathreq[0]) {
         case 'artists':
             switch (count($pathreq)) {
                 case 1:
                     // Get artists list
                     //$artists = Catalog::get_artists();
                     //list($maxCount, $artists) = self::_slice($artists, $start, $count);
                     $artists = Catalog::get_artists(null, $count, $start);
                     list($maxCount, $artists) = array(999999, $artists);
                     foreach ($artists as $artist) {
                         $artist->format();
                         $mediaItems[] = self::_itemArtist($artist, $parent);
                     }
                     break;
                 case 2:
                     // Get artist's albums list
                     $artist = new Artist($pathreq[1]);
                     if ($artist->id) {
                         $album_ids = $artist->get_albums();
                         list($maxCount, $album_ids) = self::_slice($album_ids, $start, $count);
                         foreach ($album_ids as $album_id) {
                             $album = new Album($album_id);
                             $album->format();
                             $mediaItems[] = self::_itemAlbum($album, $parent);
                         }
                     }
                     break;
             }
             break;
         case 'albums':
             switch (count($pathreq)) {
                 case 1:
                     // Get albums list
                     //!!$album_ids = Catalog::get_albums();
                     //!!list($maxCount, $album_ids) = self::_slice($album_ids, $start, $count);
                     $album_ids = Catalog::get_albums($count, $start);
                     list($maxCount, $album_ids) = array(999999, $album_ids);
                     foreach ($album_ids as $album_id) {
                         $album = new Album($album_id);
                         $album->format();
                         $mediaItems[] = self::_itemAlbum($album, $parent);
                     }
                     break;
                 case 2:
                     // Get album's songs list
                     $album = new Album($pathreq[1]);
                     if ($album->id) {
                         $song_ids = $album->get_songs();
                         list($maxCount, $song_ids) = self::_slice($song_ids, $start, $count);
                         foreach ($song_ids as $song_id) {
                             $song = new Song($song_id);
                             $song->format();
                             $mediaItems[] = self::_itemSong($song, $parent);
                         }
                     }
                     break;
             }
             break;
         case 'songs':
             switch (count($pathreq)) {
                 case 1:
                     // Get songs list
                     $catalogs = Catalog::get_catalogs();
                     foreach ($catalogs as $catalog_id) {
                         $catalog = Catalog::create_from_id($catalog_id);
                         $songs = $catalog->get_songs();
                         list($maxCount, $songs) = self::_slice($songs, $start, $count);
                         foreach ($songs as $song) {
                             $song->format();
                             $mediaItems[] = self::_itemSong($song, $parent);
                         }
                     }
                     break;
             }
             break;
         case 'playlists':
             switch (count($pathreq)) {
                 case 1:
                     // Get playlists list
                     $pl_ids = Playlist::get_playlists();
                     list($maxCount, $pl_ids) = self::_slice($pl_ids, $start, $count);
                     foreach ($pl_ids as $pl_id) {
                         $playlist = new Playlist($pl_id);
                         $playlist->format();
                         $mediaItems[] = self::_itemPlaylist($playlist, $parent);
                     }
                     break;
                 case 2:
                     // Get playlist's songs list
                     $playlist = new Playlist($pathreq[1]);
                     if ($playlist->id) {
                         $items = $playlist->get_items();
                         list($maxCount, $items) = self::_slice($items, $start, $count);
                         foreach ($items as $item) {
                             if ($item['object_type'] == 'song') {
                                 $song = new Song($item['object_id']);
                                 $song->format();
                                 $mediaItems[] = self::_itemSong($song, $parent);
                             }
                         }
                     }
                     break;
             }
             break;
         case 'smartplaylists':
             switch (count($pathreq)) {
                 case 1:
                     // Get playlists list
                     $pl_ids = Search::get_searches();
                     list($maxCount, $pl_ids) = self::_slice($pl_ids, $start, $count);
                     foreach ($pl_ids as $pl_id) {
                         $playlist = new Search($pl_id, 'song');
                         $playlist->format();
                         $mediaItems[] = self::_itemPlaylist($playlist, $parent);
                     }
                     break;
                 case 2:
                     // Get playlist's songs list
                     $playlist = new Search($pathreq[1], 'song');
                     if ($playlist->id) {
                         $items = $playlist->get_items();
                         list($maxCount, $items) = self::_slice($items, $start, $count);
                         foreach ($items as $item) {
                             if ($item['object_type'] == 'song') {
                                 $song = new Song($item['object_id']);
                                 $song->format();
                                 $mediaItems[] = self::_itemSong($song, $parent);
                             }
                         }
                     }
                     break;
             }
             break;
         default:
             $mediaItems[] = self::_musicMetadata('artists');
             $mediaItems[] = self::_musicMetadata('albums');
             $mediaItems[] = self::_musicMetadata('songs');
             $mediaItems[] = self::_musicMetadata('playlists');
             $mediaItems[] = self::_musicMetadata('smartplaylists');
             break;
     }
     if ($maxCount == 0) {
         $maxCount = count($mediaItems);
     }
     return array($maxCount, $mediaItems);
 }