Beispiel #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());
 }
Beispiel #2
0
 /**
  * Method for to create a wpl playlist into a array
  *
  * @param array $items
  */
 public function CreateWPLList($items, $archiv = null)
 {
     $PJContent = null;
     $session = JFactory::getSession();
     $dispatcher = JDispatcher::getInstance();
     $Entriecounter = count($items);
     $filecounter = 0;
     $PJContent = null;
     $PJContent .= '<?wpl version="1.0"?>' . "\r\n";
     $PJContent .= '<smil>' . "\r\n";
     $PJContent .= '<head>' . "\r\n";
     $PJContent .= '<meta name="Generator" content="PlayJoom Audio Server"/>' . "\r\n";
     $PJContent .= '<meta name="ItemCount" content="' . $Entriecounter . '"/>' . "\r\n";
     $PJContent .= '<title>Playlist</title>' . "\r\n";
     $PJContent .= '</head>' . "\r\n";
     $PJContent .= '<body>' . "\r\n";
     $PJContent .= '<seq>' . "\r\n";
     foreach ($items as $i => $item) {
         if (JFile::exists($item->pathatlocal . DIRECTORY_SEPARATOR . $item->file)) {
             $filecounter = $filecounter + 1;
             if ($archiv == true) {
                 if (JRequest::getVar('source') == 'album') {
                     $PJContent .= '<media src="' . $item->tracknumber . ' - ' . JApplication::stringURLSafe($item->title) . '.' . PlayJoomHelper::getFileExtension($item->mediatype) . '"/>' . "\r\n";
                 } else {
                     $PJContent .= '<media src="' . $i + 1 . '-' . JApplication::stringURLSafe($item->artist) . '-' . JApplication::stringURLSafe($item->title) . '.' . PlayJoomHelper::getFileExtension($item->mediatype) . '"/>' . "\r\n";
                 }
             } else {
                 $PJContent .= '<media src="' . SERVER_REF . "?option=com_playjoom&view=broadcast&format=raw&tlk=" . hash('sha256', $session->getId() . "+" . PlayJoomHelper::getUserIP() . "+" . $item->id) . "&id=" . $item->id . '"/>' . "\r\n";
             }
         } else {
             $dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__ . ":" . __LINE__, 'message' => 'Track ' . $item->title . ' isn´t available!', 'priority' => JLog::WARNING, 'section' => 'site')));
         }
     }
     $PJContent .= '</seq>' . "\r\n";
     $PJContent .= '</body>' . "\r\n";
     $PJContent .= '</smil>' . "\r\n";
     $dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__ . ":" . __LINE__, 'message' => 'Done to write playlist file.', 'priority' => JLog::INFO, 'section' => 'site')));
     $this->data[] = $PJContent;
 }