Example #1
0
 function display($tpl = null)
 {
     $dispatcher = JDispatcher::getInstance();
     // Get data from the model
     $items = $this->get('Items');
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         $dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__ . ":" . __LINE__, 'message' => 'Problem with datadase request: ' . implode("\r\n", $errors), 'priority' => JLog::ERROR, 'section' => 'site')));
         return false;
     }
     //Load helper files
     JLoader::import('helpers.download', JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_playjoom');
     JLoader::import('helpers.playlist', JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_playjoom');
     // Create folder name
     if (JRequest::getVar('source') == 'album') {
         $foldername = JApplication::stringURLSafe(base64_decode(JRequest::getVar('artist'))) . ' - ' . JApplication::stringURLSafe(base64_decode(JRequest::getVar('name')));
     } else {
         $foldername = JApplication::stringURLSafe(base64_decode(JRequest::getVar('name')));
     }
     $CreateArchivFile = new PlayJoomHelperDownload();
     // Add the info file into the archive
     $CreateInfoFile = new PlayJoomHelperPlaylist();
     $CreateInfoFile->createInfoFile($items);
     $CreateArchivFile->addFile($CreateInfoFile->file(), $foldername . DIRECTORY_SEPARATOR . 'readme.txt');
     // Add the playlist files into the archive
     $CreateM3UPlaylistFile = new PlayJoomHelperPlaylist();
     $CreateM3UPlaylistFile->CreateM3UList($items, true);
     $CreateArchivFile->addFile($CreateM3UPlaylistFile->file(), $foldername . DIRECTORY_SEPARATOR . 'playlist.m3u');
     $CreatePLSPlaylistFile = new PlayJoomHelperPlaylist();
     $CreatePLSPlaylistFile->CreatePLSList($items, true);
     $CreateArchivFile->addFile($CreatePLSPlaylistFile->file(), $foldername . DIRECTORY_SEPARATOR . 'playlist.pls');
     $CreateXSPFPlaylistFile = new PlayJoomHelperPlaylist();
     $CreateXSPFPlaylistFile->CreateXSPFList($items, true);
     $CreateArchivFile->addFile($CreateXSPFPlaylistFile->file(), $foldername . DIRECTORY_SEPARATOR . 'playlist.xspf');
     $CreateWPLPlaylistFile = new PlayJoomHelperPlaylist();
     $CreateWPLPlaylistFile->CreateWPLList($items, true);
     $CreateArchivFile->addFile($CreateWPLPlaylistFile->file(), $foldername . DIRECTORY_SEPARATOR . 'playlist.wpl');
     $dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__ . ":" . __LINE__, 'message' => 'Ready for to create a download archiv file: ' . JApplication::stringURLSafe(JRequest::getVar('name')) . '.zip', 'priority' => JLog::INFO, 'section' => 'site')));
     // Add the audio files into the archive
     foreach ($items as $i => $item) {
         if (JRequest::getVar('source') == 'album') {
             $filename = $item->tracknumber . ' - ' . JApplication::stringURLSafe($item->title) . '.' . PlayJoomHelper::getFileExtension($item->mediatype);
         } else {
             $filename = $i + 1 . ' - ' . JApplication::stringURLSafe($item->artist) . ' - ' . JApplication::stringURLSafe($item->title) . '.' . PlayJoomHelper::getFileExtension($item->mediatype);
         }
         $CreateArchivFile->addFile(file_get_contents($item->pathatlocal . DIRECTORY_SEPARATOR . $item->file), $foldername . DIRECTORY_SEPARATOR . $filename);
     }
     // Add cover file into archive, if once existing.
     $covercontent = PlayJoomHelper::getAlbumCover(base64_decode(JRequest::getVar('name')), base64_decode(JRequest::getVar('artist')));
     if ($covercontent) {
         $CreateArchivFile->addFile($covercontent->data, $foldername . DIRECTORY_SEPARATOR . 'cover.' . PlayJoomHelper::getFileExtension($covercontent->mime));
     }
     $CreateArchivFile->setHeader(JApplication::stringURLSafe($foldername) . '.zip', 'application/zip', mb_strlen($CreateArchivFile->file(), '8bit'));
     // Send the archiv
     $CreateArchivFile->send($CreateArchivFile->file());
 }
Example #2
0
 function display($tpl = null)
 {
     $dispatcher = JDispatcher::getInstance();
     // Get data from the model
     $items = $this->get('Items');
     //Get setting values from xml file
     $app = JFactory::getApplication();
     $params = $app->getParams();
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         $dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__ . ":" . __LINE__, 'message' => 'Problem with datadase request: ' . implode("\r\n", $errors), 'priority' => JLog::ERROR, 'section' => 'site')));
         return false;
     }
     //Load playlist helper
     JLoader::import('helpers.playlist', JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_playjoom');
     $PlaylistFile = new PlayJoomHelperPlaylist();
     if (JRequest::getVar('attachment_playlist') != '') {
         $listtype = JRequest::getVar('attachment_playlist');
     } else {
         $listtype = $params->get('playlist_type', 'm3u');
     }
     $filename = base64_decode(JRequest::getVar('name'));
     if ($filename != '' && JRequest::getVar('disposition') == 'attachment') {
         $playlistFileName = JApplication::stringURLSafe($filename) . '.' . $listtype;
     } else {
         $playlistFileName = 'playlist.' . $listtype;
     }
     switch ($listtype) {
         case 'pls':
             $PlaylistFile->CreatePLSList($items, false);
             $PlaylistFile->setHeader($playlistFileName, 'application/pls+xml', mb_strlen($PlaylistFile->file(), '8bit'));
             break;
         case 'm3u':
             $PlaylistFile->CreateM3UList($items, false);
             $PlaylistFile->setHeader($playlistFileName, 'audio/x-mpegurl', mb_strlen($PlaylistFile->file(), '8bit'));
             break;
         case 'xspf':
             $PlaylistFile->CreateXSPFList($items, false);
             $PlaylistFile->setHeader($playlistFileName, 'application/xspf+xml', mb_strlen($PlaylistFile->file(), '8bit'));
             break;
         case 'wpl':
             $PlaylistFile->CreateWPLList($items, false);
             $PlaylistFile->setHeader($playlistFileName, 'application/vnd.ms-wpl', mb_strlen($PlaylistFile->file(), '8bit'));
             break;
         case 'plist':
             // Placeholder for Apples plist
             break;
         default:
             $PlaylistFile->CreateM3UList($items, false);
             $PlaylistFile->setHeader($playlistFileName, 'audio/x-mpegurl', mb_strlen($PlaylistFile->file(), '8bit'));
             break;
     }
     $PlaylistFile->send($PlaylistFile->file());
 }