function selectAudio(&$prg) { global $config; $files = $prg->listAudioFiles('TRUE', 'kbps DESC'); foreach ($files as $f) { if ($f['download_access'] == 't') { //$f['url'] = $config['rootUrl'] . '/getFile.php/' . $f['filename'] . '?audio=1&id=' . $prg->id . '&filename=' . $f['filename']; //$f['url'] = $config['rootUrl'] . '/getFile.php?audio=1&id=' . $prg->id . '&filename=' . $f['filename']; $baseUrl = sotf_Node::getHomeNodeRootUrl($prg); $f['url'] = $baseUrl . '/getFile.php/fid__' . $f['id']; return $f; } } /* if(!$retval) { foreach($files as $f) { if($f['stream_access']=='t') { $f['url'] = $config['rootUrl'] . '/listen.php?id=' . $prg->id . '&fileid=' . $f['id']; return $f; } } } */ return NULL; }
/** static */ function getHomeNodeRootUrl($obj) { if ($obj->isLocal()) { global $config; return $config['rootUrl']; } else { $node = sotf_Node::getNodeById($obj->getNodeId()); if (!$node) { raiseError("Could not find home node for programme: " . $obj->id); } return $node->get('url'); } }
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'); }
if ($delperm) { $username = sotf_Utils::getParameter('username'); $userid = $user->getUserid($username); if (empty($userid) || !is_numeric($userid)) { raiseError("Invalid username: {$username}"); } $permissions->delPermission('node', $userid); $msg = $page->getlocalizedWithParams("deleted_permissions_for", $username); $page->addStatusMsg($msg, false); $page->redirect("admin.php"); exit; } // generate output $localNode = sotf_Node::getLocalNode(); if (!$localNode) { $localNode = new sotf_Node(); $localNode->set('node_id', $nodeId); $localNode->set('name', $nodeName); $localNode->set('url', $rootdir); $localNode->create(); } $smarty->assign("LOCAL_NODE", $localNode->getAll()); // nodes //$nodes = sotf_Node::countAll(); //$smarty->assign('NODES',$nodeData); // neighbours $neighbours = sotf_Neighbour::listAll(); while (list(, $nei) = each($neighbours)) { $node = sotf_Node::getNodeById($nei->get('node_id')); $data = $nei->getAll(); if ($node) {
$createNew = sotf_Utils::getParameter('create_new_node'); if ($createNew) { if (!$url) { $page->addStatusMsg('no_url_given'); } elseif (sotf_Node::getNodeById($nid)) { $page->addStatusMsg('node_id_occupied'); } else { $neighbor = new sotf_Neighbour(); $neighbor->set('node_id', $nid); $neighbor->set('use_for_outgoing', 'f'); $neighbor->set('accept_incoming', 't'); $neighbor->set('pending_url', $url); $neighbor->create(); $page->redirect("closeAndRefresh.php?anchor=network"); exit; } $page->redirect("createNeighbour.php?node_id={$nid}&url=" . urlencode($url) . "#network"); exit; } // generate output $nodes = sotf_Node::listAll(); $nodeData = array(); while (list(, $node) = each($nodes)) { if (!sotf_Neighbour::isNeighbour($node->get('node_id')) && $nodeId != $node->get('node_id')) { $nodeData[] = $node->getAll(); } } $smarty->assign('NODES', $nodeData); $smarty->assign('NID', $nid); $smarty->assign('URL', $url); $page->sendPopup();
$fobj =& $repository->getObject($fid); if (!$fobj) { raiseError("no_such_object", $fid); } $prg = $repository->getObject($fobj->get('prog_id')); $mainAudio = $fobj->get('main_content') == 't'; $filename = $fobj->get('filename'); } else { $prg = $repository->getObject($id); } if (!$prg) { raiseError("no_such_object", $id); } if (!$prg->isLocal()) { // have to send user to home node of this programme sotf_Node::redirectToHomeNode($prg, 'getFile.php'); exit; } if (!$prg->isPublished()) { raiseError("not_published_yet"); } if ($fobj and !$fobj->getBool('download_access')) { raiseError("no access"); } if (!$prg->canListen()) { $page->redirect($config['localPrefix'] . '/protected.php'); exit; } if ($mainAudio) { $filename = sotf_Utils::getFileInDir($prg->getAudioDir(), $filename); } else {
function forwardResp($params) { debug("incoming FORWARD request"); $chunkInfo = xmlrpc_decoder($params->getParam(0)); $fromNode = $chunkInfo['from_node']; $objects = xmlrpc_decoder($params->getParam(1)); $node = sotf_Node::getNodeById($fromNode); if (!$node) { logError("No access: you are not in my node list!"); return new xmlrpcresp(0, XMLRPC_ERR_NO_ACCESS, "No access: you are not in my node list!"); } $msg = checkAccess($node->get('url'), $fromNode); if ($msg) { logError($msg); return new xmlrpcresp(0, XMLRPC_ERR_NO_ACCESS, "No access: {$msg}!"); } $retval = $node->forwardResponse($chunkInfo, $objects); // send response $retval = xmlrpc_encoder($retval); return new xmlrpcresp($retval); }
//ADDED BY Martin Schmidt for ($i = 0; $i < $to; $i++) { if ($prg->isLocal()) { // if local, we check if file disappeared in the meantime $path = $prg->getFilePath($mainContentFiles[$i]); if (!is_readable($path)) { debug("DISAPPEARED FILE", $path); unset($mainContentFiles[$i]); continue; } } $mainContentFiles[$i] = array_merge($mainContentFiles[$i], sotf_AudioFile::decodeFormatFilename($mainContentFiles[$i]['format'])); //ADDED BY Martin Schmidt //print_r($mainContentFiles[$i]); if ($prg->isVideoPrg() && $mainContentFiles[$i]['format'] == "flv" && $mainContentFiles[$i]['download_access'] == 't') { $flv_path = sotf_Node::getHomeNodeRootUrl($prg) . '/getFile.php/' . 'fid__' . $mainContentFiles[$i]['id'] . '__' . $fname . ".flv"; $flv_found = true; //$_SESSION['flv_path'] = $flv_path; } $smarty->assign('FLV_PATH', $flv_path); ///////////////////// $d = getdate($mainContentFiles[$i]['play_length']); $d['hours']--; $mainContentFiles[$i]['playtime_string'] = ($d['hours'] ? $d['hours'] . ':' : '') . sprintf('%02d', $d['minutes']) . ':' . sprintf('%02d', $d['seconds']); } $smarty->assign('FLV_FOUND', $flv_found); $smarty->assign('AUDIO_FILES', $mainContentFiles); if ($prg->isVideoPrg()) { $smarty->assign('VIDEO_PRG', 'true'); } // other files
function selectAudioVideo(&$prg) { global $config; $files = $prg->listAudioFiles('TRUE', 'kbps DESC'); if (is_array($files)) { foreach ($files as $f) { if ($f['download_access'] == 't') { /* sun 8.2.06 added to format properly the enclosure url --rama */ $station = sotf_Utils::makeValidName($prg->get('station'), 23); $series = sotf_Utils::makeValidName($prg->get('series'), 23); $title = sotf_Utils::makeValidName($prg->get('title'), 30); if ($station != "" && $series != "" && $title != "") { $fname = "{$station}-{$series}-{$title}"; } elseif ($station != "" && $title != "") { $fname = "{$station}-{$title}"; } elseif ($title != "") { $fname = $title; } /* end properly format enclosure url */ //$f['url'] = $config['rootUrl'] . '/getFile.php/' . $f['filename'] . '?audio=1&id=' . $prg->id . '&filename=' . $f['filename']; //$f['url'] = $config['rootUrl'] . '/getFile.php?audio=1&id=' . $prg->id . '&filename=' . $f['filename']; $baseUrl = sotf_Node::getHomeNodeRootUrl($prg); //$f['url'] = $baseUrl . '/getFile.php/fid__' . $f['id'].".mp3"; // wreutz: very dirty hack for ipooder to work on os x //MODIFIED BY Martin Schmidt $f = array_merge($f, sotf_AudioFile::decodeFormatFilename($f['format'])); if ($prg->isVideoPrg() && $f['format'] == "mp4") { //echo "drinnen"; $f['url'] = $baseUrl . '/getFile.php/' . 'fid__' . $f['id'] . '__' . $fname . ".mp4"; return $f; } else { if ($prg->isAudioPrg()) { $f['url'] = $baseUrl . '/getFile.php/' . 'fid__' . $f['id'] . '__' . $fname . ".mp3"; //rjankowski changed order to get parsed by getFile.php return $f; } } ////////////////////////// // rama: included $fname as formatted name $station-$series-$title } } } /* if(!$retval and is_array($files)) { foreach($files as $f) { if($f['stream_access']=='t') { $f['url'] = $config['rootUrl'] . '/listen.php?id=' . $prg->id . '&fileid=' . $f['id']; return $f; } } } */ return NULL; }
function syncResponse($chunkInfo, $objects) { global $db; if ($this->get('accept_incoming') != 't') { debug("node {$remoteId} is not allowed for incoming sync!"); return NULL; } $timestamp = $db->getTimestampTz(); $remoteId = $this->get('node_id'); // save modified objects $db->begin(true); // TODO: itt gaz van! ha nem sikerul egy objektumot elmenteni, akkor soha tobbe nem lesz neki elkuldve!!! $updatedObjects = sotf_NodeObject::saveModifiedObjects($objects, $remoteId); // if db error: don't commit! if (is_null($updatedObjects)) { return array(array('error' => "store object failed, sync aborted")); } $db->commit(); debug("number of updated objects", $updatedObjects); $replyInfo = array('received' => count($objects), 'updated' => $updatedObjects); if ($chunkInfo['objects_remaining'] == 0) { // last chunk, save node and neighbour stats $node = sotf_Node::getLocalNode(); $this->set('last_sync_in', $timestamp); $node->set('last_sync_in', $timestamp); // take out from pending nodes, update neighbour list if ($this->get('pending_url')) { $this->set('pending_url', ''); $node->set('neighbours', $this->getNeighbourString()); } $this->update(); $node->update(); //$replyInfo['node'] = $node->getAll(); } return array($replyInfo); }
* $Id: editNeighbour.php 339 2003-12-03 08:39:25Z andras $ * Created for the StreamOnTheFly project (IST-2001-32226) * Authors: András Micsik, Máté Pataki, Tamás Déri * at MTA SZTAKI DSD, http://dsd.sztaki.hu */ require "init.inc.php"; $smarty->assign('PAGETITLE', $page->getlocalized('AdminPage')); $page->forceLogin(); $page->popup = true; $page->errorURL = "editNeighbour.php"; checkPerm('node', "change"); $nid = sotf_Utils::getParameter('nodeid'); $nei = sotf_Neighbour::getById($nid); if (!$nei) { raiseError("No such node: {$nid}"); } // save changes if (sotf_Utils::getParameter('save')) { $nei->set('use_for_outgoing', sotf_Utils::getParameter('use_out') ? 't' : 'f'); $nei->set('accept_incoming', sotf_Utils::getParameter('use_in') ? 't' : 'f'); $nei->update(); $page->redirect("closeAndRefresh.php?anchor=network"); exit; } // generate output $node = sotf_Node::getNodeById($nid); if ($node) { $smarty->assign('NODE', $node->getAll()); } $smarty->assign('NEI', $nei->getAll()); $page->sendPopup();
exit; } // delete prog $delprog = sotf_Utils::getParameter('delprog'); $prgid = sotf_Utils::getParameter('prgid'); if ($delprog) { $prg =& $repository->getObject($prgid); $prg->delete(); $page->redirect(mygetenv('PHP_SELF') . "#progs"); exit; } // generate output $smarty->assign('STATION_ID', $stationid); $smarty->assign('STATION', $st->get('name')); $smarty->assign('STATION_DATA', $st->getAllWithIcon()); $smarty->assign('HOME_URL', sotf_Node::getHomeNodeRootUrl($st)); if ($st->isLocal()) { $smarty->assign('IS_LOCAL', 1); } $smarty->assign('ROLES', $st->getRoles()); if ($st->getJingle()) { $smarty->assign('JINGLE', 1); } if ($entered) { $smarty->assign('ENTERED', $entered); } if (!$start) { $start = 0; } $seriesList = $st->listSeries(); if (!empty($seriesList)) {
/** * @method static getLocalNode */ function getLocalNode() { global $db, $nodeId; return sotf_Node::getNodeById($nodeId); }
<?php require "init.inc.php"; if ($_REQUEST['select_station']) { $page->redirect("listStation.php?station=" . $_POST['station']); } /* defaults for main "index" page */ define("MAX_ITEMS_IN_INDEX", 10); $data['numNodes'] = sotf_Node::numNodes(); if ($data['numNodes'] == 0) { $data['numNodes'] = 1; } $data['numStations'] = sotf_Station::numStations(); $data['numProgs'] = sotf_Programme::numProgrammes(); $smarty->assign($data); $smarty->assign('STATIONS', sotf_Station::listStationNames()); $searchLangs = $languages; array_unshift($searchLangs, "any_language"); for ($i = 0; $i < count($searchLangs); $i++) { $langNames[$i] = $page->getlocalized($searchLangs[$i]); } $smarty->assign('searchLangs', $searchLangs); $smarty->assign('langNames', $langNames); $now = getDate(); $yesterday = mktime(0, 0, 0, $now['mon'], $now['mday'] - 2, $now['year']); $fromDay = date('Y-m-d', $yesterday); $smarty->assign(array('LOCAL_NEWS' => sotf_Programme::getNewProgrammes(true, $fromDay, MAX_ITEMS_IN_INDEX), 'OTHER_NEWS' => sotf_Programme::getNewProgrammes(false, $fromDay, MAX_ITEMS_IN_INDEX))); $page->send();
function sync($console = false) { global $sotfVars; // tunable things $objectsPerRPCRequest = 100; global $page; if (!$console && $this->getBool('use_for_outgoing')) { debug("node {$this->id} is not used for outgoing sync"); return; } debug("SYNCing with ", $this->get("node_id")); $rpc = new rpc_Utils(); if ($config['debug']) { $rpc->debug = true; } $timestamp = $this->db->getTimestampTz(); $remoteId = $this->get('node_id'); $url = $this->getUrl(); // remove trailing '/' while (substr($url, -1) == '/') { $url = substr($url, 0, -1); } // collect local data to send $localNode = sotf_Node::getLocalNode(); //debug("localNode", $localNode); debug("neighbour", $this); $localNodeData = $localNode->getAll(); // check if url is correct... $localNodeData['url'] = $config['rootUrl']; // calculate chunking $currentStamp = $sotfVars->get('sync_stamp', 0); $lastSyncStamp = $this->lastSyncStamp(); $count = sotf_NodeObject::countModifiedObjects($remoteId, $lastSyncStamp); $numChunks = ceil($count / $objectsPerRPCRequest); if ($numChunks == 0) { $numChunks = 1; } $thisChunk = 1; $chunkInfo = array("old_stamp" => $lastSyncStamp, "current_stamp" => $currentStamp, "num_chunks" => $numChunks, 'this_chunk' => $thisChunk); debug("1st chunk info", $chunkInfo); // do XML-RPC conversation $objectsSent = 0; $objectsReceived = 0; while ($thisChunk <= $numChunks) { if ($thisChunk == $numChunks) { // last chunk: no limits $objectsPerRPCRequest = 100 * $objectsPerRPCRequest; } $modifiedObjects = sotf_NodeObject::getModifiedObjects($remoteId, $lastSyncStamp, $objectsSent + 1, $objectsPerRPCRequest); $chunkInfo['this_chunk'] = $thisChunk; debug("chunk info", $chunkInfo); //debug("number of sent objects", count($modifiedObjects)); $objectsSent = $objectsSent + count($modifiedObjects); $objs = array($chunkInfo, $localNodeData, $modifiedObjects); $response = $rpc->call($url . '/xmlrpcServer.php', 'sotf.sync', $objs); // error handling if (is_null($response)) { $this->set('errors', $this->get('errors') + 1); $this->update(); return; } // save received data $chunkInfo = $response[0]; $newObjects = $response[1]; $objectsReceived = $objectsReceived + count($newObjects); debug("number of received objects", count($newObjects)); if (count($newObjects) > 0) { $updatedObjects = sotf_NodeObject::saveModifiedObjects($newObjects); } $thisChunk++; } debug("total number of objects sent", $objectsSent); debug("total number of objects received", $objectsReceived); //$this->log($console, "number of updated objects: " .count($updatedObjects)); // save last_sync $this->set('success', $this->get('success') + 1); $this->set('last_sync_out', $timestamp); $this->saveSyncStatus($timestamp, $currentStamp); // send receipt of successful sync?? }
} } $mainContentFiles[$i] = array_merge($mainContentFiles[$i], sotf_AudioFile::decodeFormatFilename($mainContentFiles[$i]['format'])); //ADDED BY Martin Schmidt //print_r($mainContentFiles[$i]); if ($prg->isVideoPrg() && $mainContentFiles[$i]['format'] == "flv" && $mainContentFiles[$i]['download_access'] == 't') { $flv_path = sotf_Node::getHomeNodeRootUrl($prg) . '/getFile.php/' . 'fid__' . $mainContentFiles[$i]['id'] . '__' . $fname . ".flv"; $flv_found = true; //$_SESSION['flv_path'] = $flv_path; } $smarty->assign('FLV_PATH', $flv_path); ///////////////////// //ADDED BY Klaus Temper //print_r($mainContentFiles[$i]); if ($mainContentFiles[$i]['format'] == "mp3" && $mainContentFiles[$i]['download_access'] == 't') { $mp3_path = sotf_Node::getHomeNodeRootUrl($prg) . '/getFile.php/' . $mainContentFiles[$i]['filename'] . '?audio=1&id=' . $mainContentFiles[$i]['prog_id'] . '&filename=' . $mainContentFiles[$i]['filename']; $mp3_found = true; } $smarty->assign('mp3_PATH', $mp3_path); ///////////////////// $d = getdate($mainContentFiles[$i]['play_length']); $d['hours']--; $mainContentFiles[$i]['playtime_string'] = ($d['hours'] ? $d['hours'] . ':' : '') . sprintf('%02d', $d['minutes']) . ':' . sprintf('%02d', $d['seconds']); } $smarty->assign('FLV_FOUND', $flv_found); $smarty->assign('AUDIO_FILES', $mainContentFiles); if ($prg->isVideoPrg()) { $smarty->assign('VIDEO_PRG', 'true'); } // other files $otherFiles = $prg->getAssociatedObjects('sotf_other_files', 'filename');
} $playlist = new sotf_Playlist(); if ($jingle) { // play the jingle of station/series $obj = $repository->getObject($id); if (!$obj) { raiseError("no_such_object", $id); } if (!$obj->isLocal()) { // have to send user to home node of this programme sotf_Node::redirectToHomeNode($obj, 'listen.php'); exit; } $playlist->addJingle($obj); } else { // add normal programme $prg = $repository->getObject($id); if (!$prg) { raiseError("no_such_object", $id); } if (!$prg->isLocal()) { // have to send user to home node of this programme sotf_Node::redirectToHomeNode($prg, 'listen.php'); exit; } $playlist->addProg($prg, $fileid); } $playlist->startStreaming(); // must start stream before! otherwise we don't know stream url $playlist->sendRemotePlaylist(); $page->logRequest();
<?php // -*- tab-width: 3; indent-tabs-mode: 1; -*- /* * $Id$ * Created for the StreamOnTheFly project (IST-2001-32226) * Authors: András Micsik, Máté Pataki, Tamás Déri * at MTA SZTAKI DSD, http://dsd.sztaki.hu */ require "init.inc.php"; require $config['classdir'] . "/sotf_AdvSearch.class.php"; if ($_REQUEST['select_station']) { $page->redirect($config['localPrefix'] . "/showStation.php/" . $_POST['station']); } $db->begin(); $data['numNodes'] = sotf_Node::countAll(); if ($data['numNodes'] == 0) { $data['numNodes'] = 1; } $data['numStations'] = sotf_Station::countAll(); $data['numProgs'] = sotf_Programme::countAll(); $data['numProgs'] = sotf_Programme::countAll(); $allStats = sotf_Statistics::networkStats(); $allStats['l_and_d'] = $allStats['listens'] + $allStats['downloads']; $data['access'] = $allStats; $fileStats = sotf_Programme::getFileStats(); $fileStats['size_mb'] = sprintf('%d', $fileStats['filesize'] / 1024 / 1024); $fileStats['length_hour'] = sprintf('%d', $fileStats['play_length'] / 60 / 60); $data['files'] = $fileStats; $data['numUsers'] = sotf_User::countUsers(); $smarty->assign($data);
$page->redirect("admin.php"); $page->logRequest(); exit; } // generate output $localNode = sotf_Node::getLocalNode(); if (!$localNode) { // clear old entry $localNode = new sotf_Node(); $localNode->set('name', $config['nodeName']); $localNode->find(); if ($localNode->exists()) { $localNode->delete(); } // create local node entry if does not exist $localNode = new sotf_Node(); $localNode->set('node_id', $config['nodeId']); $localNode->set('name', $config['nodeName']); $localNode->set('url', $config['rootUrl']); $localNode->create(); } $smarty->assign("LOCAL_NODE", $localNode->getAll()); // nodes //$nodes = sotf_Node::countAll(); //$smarty->assign('NODES',$nodeData); // neighbours //$neighbours = sotf_Neighbour::listAll(); $nodes = sotf_Node::listAll(); print_r($neighbours); while (list(, $node) = each($nodes)) { $nodeId = $node->get('node_id');
/** * @method static getLocalNode */ function getLocalNode() { global $db, $config; return sotf_Node::getNodeById($config['nodeId']); }