function addProg($prg, $fileid = '') { if (empty($fileid)) { // find a file to listen $fileid = $prg->selectFileToListen(); if (!$fileid) { raiseError("no_file_to_listen"); } } $file = new sotf_NodeObject("sotf_media_files", $fileid); if (!$prg->isLocal()) { $node = sotf_Node::getNodeById($file->getNodeId()); $path = $node->get('url') . "/listen.php?id=" . $prg->id . "&fileid=" . $file->id; $this->add(array('path' => $path, 'url' => $path)); return; } if ($prg->get('published') != 't' || $file->get('stream_access') != 't') { raiseError("no_listen_access"); } $filepath = $prg->getFilePath($file); $index = sotf_AudioCheck::getRequestIndex(new sotf_AudioFile($filepath)); debug("audio index", $index); if (!$index) { $index = '0'; } // add jingle for station (if exists) $station = $prg->getStation(); $jfile = $station->getJingle($index); if ($jfile) { $this->add(array('id' => $station->id, 'path' => $jfile, 'jingle' => 1, 'name' => 'station_jingle')); } // add jingle for series (if exists) $series = $prg->getSeries(); if ($series) { $jfile = $series->getJingle($index); if ($jfile) { $this->add(array('id' => $series->id, 'path' => $jfile, 'jingle' => 1, 'name' => 'series_jingle')); } } // add program file $filepath = $prg->getFilePath($file); $this->add(array('id' => $prg->id, 'path' => $filepath, 'name' => urlencode($prg->get('title')))); // temp: set title $title = $prg->get("title"); $title = preg_replace('/\\s+/', '_', $title); $this->name = urlencode($title); // save stats $prg->addStat($file->get('id'), 'listens'); }
/** * Sets jingle of the station. * * @param object $audiofile sotf_AudioFile object represents the jingle * @return boolean True if the function succeeded, else false * @todo Look for the old existing jingle. If the old one doesn't follow the current naming procedure, it will remain in the directory, and makes troubles * @use $audioFormats */ function setJingle($audiofile) { global $audioFormats; $index = sotf_AudioCheck::getRequestIndex($audiofile); if (false === $index) { return false; } $dir = $this->getStationDir(); $targetFile = $dir . '/' . 'jingle_' . $audiofile->getFormatFilename(); $retval = copy($audiofile->getPath(), $targetFile); if (!$retval) { return false; } //return new PEAR_Error("Could not move file $fromFile to its location"); //chmod($targetFile, 0770); return true; }