public function copyfileAction()
 {
     $upload_dir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
     $filename = $this->_getParam('name');
     StoredFile::copyFileToStor($upload_dir, $filename);
     die('{"jsonrpc" : "2.0"}');
 }
 function setup()
 {
     global $CC_CONFIG, $CC_DBC;
     // Clear the files table
     $sql = "DELETE FROM " . $CC_CONFIG["filesTable"];
     $CC_DBC->query($sql);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10001.mp3");
     $this->storedFile = StoredFile::Insert($values, false);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10002.mp3");
     $this->storedFile2 = StoredFile::Insert($values, false);
     // Clear the schedule table
     $sql = "DELETE FROM " . $CC_CONFIG["scheduleTable"];
     $CC_DBC->query($sql);
     // Create a playlist
     $playlist = new Playlist();
     $playlist->create("Scheduler Unit Test");
     $result = $playlist->addAudioClip($this->storedFile->getId());
     $result = $playlist->addAudioClip($this->storedFile2->getId());
     $result = $playlist->addAudioClip($this->storedFile2->getId());
     // Schedule it
     $i = new ScheduleGroup();
     $this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId());
 }
 function testDeleteAndPutFile()
 {
     $STORAGE_SERVER_PATH = dirname(__FILE__) . "/../../";
     $filePath = dirname(__FILE__) . "/ex1.mp3";
     // Delete any old data from previous tests
     $md5 = md5_file($filePath);
     $duplicate = StoredFile::RecallByMd5($md5);
     if ($duplicate) {
         $duplicate->delete();
     }
     // Test inserting a file by linking
     $values = array("filepath" => $filePath, "dc:description" => "Unit test " . time());
     $storedFile = StoredFile::Insert($values, false);
     if (PEAR::isError($storedFile)) {
         $this->fail("Failed to create StoredFile: " . $storedFile->getMessage());
         return;
     }
     //var_dump($storedFile);
     $id = $storedFile->getId();
     if (!is_numeric($id)) {
         $this->fail("StoredFile not created correctly. id = " . $id);
         return;
     }
     // Test loading metadata
     $f = new StoredFile();
     $f->__setGunid($storedFile->getGunid());
     $f->loadMetadata();
     if (!is_array($md = $f->getMetadata())) {
         $this->fail("Unable to load metadata.");
         return;
     }
     //var_dump($md);
     // Check if the length field has been set.
     $f2 = StoredFile::RecallByGunid($storedFile->getGunid());
     $m2 = $f2->getMetadata();
     if (!isset($m2["length"]) || $m2["length"] == "00:00:00.000000") {
         $this->fail("Length not reporting correctly in metadata.");
         return;
     }
 }
Example #4
0
 function setup()
 {
     global $CC_CONFIG, $CC_DBC;
     // Clear the files table
     //$sql = "DELETE FROM ".$CC_CONFIG["filesTable"];
     //$CC_DBC->query($sql);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10001.mp3");
     $this->storedFile = StoredFile::Insert($values, false);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10002.mp3");
     $this->storedFile2 = StoredFile::Insert($values, false);
     // Clear the schedule table
     //$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"];
     //$CC_DBC->query($sql);
 }
Example #5
0
 public static function OutputToM3u(&$pl, $plac, $ind = '')
 {
     $gunid = $plac['attrs']['id'];
     $ac = StoredFile::RecallByGunid($gunid);
     if (is_null($ac) || PEAR::isError($ac)) {
         return $ac;
     }
     $RADext = $ac->getFileExtension();
     if (PEAR::isError($RADext)) {
         return $RADext;
     }
     return array('playlength' => $plac['attrs']['playlength'], 'title' => $plac['attrs']['title'], 'uri' => AC_URL_RELPATH . "{$gunid}.{$RADext}");
 }
 public function contentContextMenuAction()
 {
     global $CC_CONFIG;
     $id = $this->_getParam('id');
     $params = '/format/json/id/#id#/';
     $paramsPop = str_replace('#id#', $id, $params);
     // added for downlaod
     $id = $this->_getParam('id');
     $file_id = $this->_getParam('id', null);
     $file = StoredFile::Recall($file_id);
     $url = $file->getFileURL() . '/api_key/' . $CC_CONFIG["apiKey"][0] . '/download/true';
     $menu[] = array('action' => array('type' => 'gourl', 'url' => $url), 'title' => 'Download');
     //returns format jjmenu is looking for.
     die(json_encode($menu));
 }
$img_src = $_GET['src'];
$new_img_width = $_GET['width'];
$new_img_height = $_GET['height'];
$img = null;
$img_remote = null;
if (function_exists("gd_info") && function_exists("imagecreatefromjpeg") && function_exists("imagecreatefromgif")) {
    $img_path = parse_url($img_src);
    $img_ext = pathinfo($img_path['path'], PATHINFO_EXTENSION);
    if (empty($img_ext)) {
        // dynamic image URL
        if (preg_match("|http://(.*?)/(.*)|", $img_src, $m)) {
            try {
                list(, $uf_server, $uf_path) = $m;
                $image_file = Storage::save($img_src, basename($uf_path), "critical", "image");
                if (!empty($image_file)) {
                    $stored_img = new StoredFile($image_file);
                    $img_src = $stored_img->getURL();
                    $img_path = parse_url($img_src);
                    $img_ext = pathinfo($img_path['path'], PATHINFO_EXTENSION);
                } else {
                    echo "invalid IMG url";
                    exit;
                }
            } catch (Exception $e) {
                $img = null;
            }
        }
    }
    if ($img_path['host'] == $_SERVER['SERVER_NAME']) {
        // image from local server
        $img_src = PA::resolveRelativePath('web' . $img_path['path']);
Example #8
0
 /**
  * Export the schedule in json formatted for pypo (the liquidsoap scheduler)
  *
  * @param string $p_fromDateTime
  *      In the format "YYYY-MM-DD-HH-mm-SS"
  * @param string $p_toDateTime
  *      In the format "YYYY-MM-DD-HH-mm-SS"
  */
 public static function GetScheduledPlaylists($p_fromDateTime = null, $p_toDateTime = null)
 {
     global $CC_CONFIG, $CC_DBC;
     if (is_null($p_fromDateTime)) {
         $t1 = new DateTime();
         $range_start = $t1->format("Y-m-d H:i:s");
     } else {
         $range_start = Schedule::PypoTimeToAirtimeTime($p_fromDateTime);
     }
     if (is_null($p_fromDateTime)) {
         $t2 = new DateTime();
         $t2->add(new DateInterval("PT24H"));
         $range_end = $t2->format("Y-m-d H:i:s");
     } else {
         $range_end = Schedule::PypoTimeToAirtimeTime($p_toDateTime);
     }
     // Scheduler wants everything in a playlist
     $data = Schedule::GetItems($range_start, $range_end, true);
     $playlists = array();
     if (is_array($data)) {
         foreach ($data as $dx) {
             $start = $dx['start'];
             //chop off subseconds
             $start = substr($start, 0, 19);
             //Start time is the array key, needs to be in the format "YYYY-MM-DD-HH-mm-ss"
             $pkey = Schedule::AirtimeTimeToPypoTime($start);
             $timestamp = strtotime($start);
             $playlists[$pkey]['source'] = "PLAYLIST";
             $playlists[$pkey]['x_ident'] = $dx['group_id'];
             //$playlists[$pkey]['subtype'] = '1'; // Just needs to be between 1 and 4 inclusive
             $playlists[$pkey]['timestamp'] = $timestamp;
             $playlists[$pkey]['duration'] = $dx['clip_length'];
             $playlists[$pkey]['played'] = '0';
             $playlists[$pkey]['schedule_id'] = $dx['group_id'];
             $playlists[$pkey]['show_name'] = $dx['show_name'];
             $playlists[$pkey]['show_start'] = Schedule::AirtimeTimeToPypoTime($dx['show_start']);
             $playlists[$pkey]['show_end'] = Schedule::AirtimeTimeToPypoTime($dx['show_end']);
             $playlists[$pkey]['user_id'] = 0;
             $playlists[$pkey]['id'] = $dx['group_id'];
             $playlists[$pkey]['start'] = Schedule::AirtimeTimeToPypoTime($dx["start"]);
             $playlists[$pkey]['end'] = Schedule::AirtimeTimeToPypoTime($dx["end"]);
         }
     }
     foreach ($playlists as &$playlist) {
         $scheduleGroup = new ScheduleGroup($playlist["schedule_id"]);
         $items = $scheduleGroup->getItems();
         $medias = array();
         foreach ($items as $item) {
             $storedFile = StoredFile::Recall($item["file_id"]);
             $uri = $storedFile->getFileUrl();
             $starts = Schedule::AirtimeTimeToPypoTime($item["starts"]);
             $medias[$starts] = array('row_id' => $item["id"], 'id' => $storedFile->getGunid(), 'uri' => $uri, 'fade_in' => Schedule::WallTimeToMillisecs($item["fade_in"]), 'fade_out' => Schedule::WallTimeToMillisecs($item["fade_out"]), 'fade_cross' => 0, 'cue_in' => DateHelper::CalculateLengthInSeconds($item["cue_in"]), 'cue_out' => DateHelper::CalculateLengthInSeconds($item["cue_out"]), 'export_source' => 'scheduler', 'start' => $starts, 'end' => Schedule::AirtimeTimeToPypoTime($item["ends"]));
         }
         $playlist['medias'] = $medias;
     }
     $result = array();
     $result['status'] = array('range' => array('start' => $range_start, 'end' => $range_end), 'version' => AIRTIME_REST_VERSION);
     $result['playlists'] = $playlists;
     $result['check'] = 1;
     $result['stream_metadata'] = array();
     $result['stream_metadata']['format'] = Application_Model_Preference::GetStreamLabelFormat();
     $result['stream_metadata']['station_name'] = Application_Model_Preference::GetStationName();
     $result['server_timezone'] = date('O');
     return $result;
 }
Example #9
0
 public static function copyFileToStor($p_targetDir, $fileName)
 {
     $audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $fileName;
     $md5 = md5_file($audio_file);
     $duplicate = StoredFile::RecallByMd5($md5);
     if ($duplicate) {
         if (PEAR::isError($duplicate)) {
             die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() . '}}');
         }
         if (file_exists($duplicate->getFilePath())) {
             $duplicateName = $duplicate->getMetadataValue('MDATA_KEY_TITLE');
             die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "An identical audioclip named ' . $duplicateName . ' already exists in the storage server."}}');
         }
     }
     $storDir = MusicDir::getStorDir();
     $stor = $storDir->getDirectory();
     $stor .= "/organize";
     $audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
     $r = @copy($audio_file, $audio_stor);
 }
// Delete any old playlists
$pl2 = Playlist::findPlaylistByName($playlistName);
foreach ($pl2 as $playlist) {
    //var_dump($playlist);
    $playlist->delete();
}
echo "done.\n";
// Create a new playlist
echo "Creating new playlist '{$playlistName}'...";
$pl = new Playlist();
$pl->create($playlistName);
$mediaFile = StoredFile::findByOriginalName("Peter_Rudenko_-_Opening.mp3");
if (is_null($mediaFile)) {
    echo "Adding test audio clip to the database.\n";
    $v = array("filepath" => __DIR__ . "/../../../audio_samples/vorbis.com/Hydrate-Kenny_Beltrey.ogg");
    $mediaFile = StoredFile::Insert($v);
    if (PEAR::isError($mediaFile)) {
        var_dump($mediaFile);
        exit;
    }
}
$pl->addAudioClip($mediaFile->getId());
echo "done.\n";
//$pl2 = Playlist::findPlaylistByName("pypo_playlist_test");
//var_dump($pl2);
// Get current time
// In the format YYYY-MM-DD HH:MM:SS.nnnnnn
$startTime = date("Y-m-d H:i:s");
$endTime = date("Y-m-d H:i:s", time() + 60 * 60);
echo "Removing everything from the scheduler between {$startTime} and {$endTime}...";
// Check for succces
Example #11
0
 public function searchPlaylistsForShow($datatables)
 {
     return StoredFile::searchPlaylistsForSchedule($datatables);
 }
Example #12
0
 public static function getUsersDataTablesInfo($datatables_post)
 {
     $fromTable = "cc_subjs";
     // get current user
     $username = "";
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $username = $auth->getIdentity()->login;
     }
     $res = StoredFile::searchFiles($fromTable, $datatables_post);
     // mark record which is for the current user
     foreach ($res['aaData'] as &$record) {
         if ($record[1] == $username) {
             $record[5] = "self";
         }
     }
     return $res;
 }
Example #13
0
 public static function convert2lspl(&$gb, &$tree, &$gunids, $parr, $ind = '')
 {
     extract($parr);
     $uri = $tree->attrs['src']->val;
     $gunid = isset($gunids[basename($uri)]) ? $gunids[basename($uri)] : NULL;
     $ind2 = $ind . INDCH;
     if ($tree->name != 'audio') {
         return PEAR::raiseError("SmilPlaylist::parse: audio tag expected");
     }
     if (isset($tree->children[2])) {
         return PEAR::raiseError(sprintf("SmilPlaylist::parse: unexpected tag %s in tag audio", $tree->children[2]->name));
     }
     $res = '';
     $fadeIn = 0;
     $fadeOut = 0;
     foreach ($tree->children as $i => $ch) {
         $ch =& $tree->children[$i];
         $r = SmilPlaylistAnimateElement::convert2lspl($gb, $ch, &$gunids, $parr, $ind2);
         if (PEAR::isError($r)) {
             return $r;
         }
         switch ($r['type']) {
             case "fadeIn":
                 $fadeIn = $r['val'];
                 break;
             case "fadeOut":
                 $fadeOut = $r['val'];
                 break;
         }
     }
     if ($fadeIn > 0 || $fadeOut > 0) {
         $fiGunid = StoredFile::CreateGunid();
         $fadeIn = Playlist::secondsToPlaylistTime($fadeIn);
         $fadeOut = Playlist::secondsToPlaylistTime($fadeOut);
         $fInfo = "{$ind2}<fadeInfo id=\"{$fiGunid}\" fadeIn=\"{$fadeIn}\" fadeOut=\"{$fadeOut}\"/>\n";
     } else {
         $fInfo = '';
     }
     $plElGunid = StoredFile::CreateGunid();
     $acGunid = $gunid;
     $type = 'audioClip';
     if (preg_match("|\\.([a-zA-Z0-9]+)\$|", $uri, $va)) {
         switch (strtolower($ext = $va[1])) {
             case "lspl":
             case "xml":
             case "smil":
             case "m3u":
                 $type = 'playlist';
                 $acId = $gb->bsImportPlaylistRaw($gunid, $aPath, $uri, $ext, $gunids, $subjid);
                 if (PEAR::isError($acId)) {
                     return $r;
                 }
                 //break;
             //break;
             default:
                 $ac = StoredFile::RecallByGunid($gunid);
                 if (is_null($ac) || PEAR::isError($ac)) {
                     return $ac;
                 }
                 $r = $ac->md->getMetadataElement('dcterms:extent');
                 if (PEAR::isError($r)) {
                     return $r;
                 }
                 $playlength = $r[0]['value'];
         }
     }
     $title = basename($tree->attrs['src']->val);
     $offset = Playlist::secondsToPlaylistTime($tree->attrs['begin']->val);
     $clipStart = Playlist::secondsToPlaylistTime($tree->attrs['clipStart']->val);
     $clipEnd = Playlist::secondsToPlaylistTime($tree->attrs['clipEnd']->val);
     $clipLength = Playlist::secondsToPlaylistTime($tree->attrs['clipLength']->val);
     $res = "{$ind}<playlistElement id=\"{$plElGunid}\" relativeOffset=\"{$offset}\" clipStart=\"{$clipStart}\" clipEnd=\"{$clipEnd}\" clipLength=\"{$clipLength}\">\n" . "{$ind2}<{$type} id=\"{$acGunid}\" playlength=\"{$playlength}\" title=\"{$title}\"/>\n" . $fInfo . "{$ind}</playlistElement>\n";
     return $res;
 }
Example #14
0
 public function listAllFilesAction()
 {
     global $CC_CONFIG;
     $request = $this->getRequest();
     $api_key = $request->getParam('api_key');
     if (!in_array($api_key, $CC_CONFIG["apiKey"])) {
         header('HTTP/1.0 401 Unauthorized');
         print 'You are not allowed to access this resource.';
         exit;
     }
     $dir_id = $request->getParam('dir_id');
     $this->view->files = StoredFile::listAllFiles($dir_id);
 }
 public function getFileMetaDataAction()
 {
     $id = $this->_getParam('id');
     $type = $this->_getParam('type');
     if ($type == "au") {
         $file = StoredFile::Recall($id);
         $this->view->type = $type;
         $this->view->md = $file->getMetadata();
     } else {
         if ($type == "pl") {
             $file = Playlist::Recall($id);
             $this->view->type = $type;
             $this->view->md = $file->getAllPLMetaData();
             $this->view->contents = $file->getContents();
         }
     }
 }
Example #16
0
 public static function GetSystemInfo($returnArray = false)
 {
     exec('/usr/bin/airtime-check-system', $output);
     $output = preg_replace('/\\s+/', ' ', $output);
     $systemInfoArray = array();
     foreach ($output as $key => &$out) {
         $info = explode('=', $out);
         if (isset($info[1])) {
             $key = str_replace(' ', '_', trim($info[0]));
             $key = strtoupper($key);
             $systemInfoArray[$key] = $info[1];
         }
     }
     $outputArray = array();
     $outputArray['STATION_NAME'] = Application_Model_Preference::GetStationName();
     $outputArray['PHONE'] = Application_Model_Preference::GetPhone();
     $outputArray['EMAIL'] = Application_Model_Preference::GetEmail();
     $outputArray['STATION_WEB_SITE'] = Application_Model_Preference::GetStationWebSite();
     $outputArray['STATION_COUNTRY'] = Application_Model_Preference::GetStationCountry();
     $outputArray['STATION_CITY'] = Application_Model_Preference::GetStationCity();
     $outputArray['STATION_DESCRIPTION'] = Application_Model_Preference::GetStationDescription();
     // get web server info
     if (isset($systemInfoArray["AIRTIME_VERSION_URL"])) {
         $url = $systemInfoArray["AIRTIME_VERSION_URL"];
         $index = strpos($url, '/api/');
         $url = substr($url, 0, $index);
         $headerInfo = get_headers(trim($url), 1);
         $outputArray['WEB_SERVER'] = $headerInfo['Server'][0];
     }
     $outputArray['NUM_OF_USERS'] = User::getUserCount();
     $outputArray['NUM_OF_SONGS'] = StoredFile::getFileCount();
     $outputArray['NUM_OF_PLAYLISTS'] = Playlist::getPlaylistCount();
     $outputArray['NUM_OF_SCHEDULED_PLAYLISTS'] = Schedule::getSchduledPlaylistCount();
     $outputArray['NUM_OF_PAST_SHOWS'] = ShowInstance::GetShowInstanceCount(date("Y-m-d H:i:s"));
     $outputArray['UNIQUE_ID'] = Application_Model_Preference::GetUniqueId();
     $outputArray = array_merge($systemInfoArray, $outputArray);
     $outputString = "\n";
     foreach ($outputArray as $key => $out) {
         if ($out != '') {
             $outputString .= $key . ' : ' . $out . "\n";
         }
     }
     if ($returnArray) {
         $outputArray['PROMOTE'] = Application_Model_Preference::GetPublicise();
         $outputArray['LOGOIMG'] = Application_Model_Preference::GetStationLogo();
         return $outputArray;
     } else {
         return $outputString;
     }
 }