function errorNative() { $err = parent::errorNative(); error_log("PGSQL error: {$err}", 0); error_log("in query: " . substr($this->last_query, 0, 254), 0); global $debug; if ($debug) { raiseError("SQL error: {$err} in \n " . $this->last_query); } else { raiseError("SQL error!"); } /* echo "<p><b>SQL error: $err</b> in <br>"; echo $this->last_query . "</p>"; exit; */ /* global $sqlDebug; if($sqlDebug) { echo "<p><b>SQL error: $err</b> in <br>"; echo $this->last_query . "</p>"; } */ //return $err; }
function userDbSelect($fields) { if ($fields['username']) { $query = sprintf("SELECT * FROM sotf_users WHERE username='******'", $fields['username']); $raw = $this->userdb->getRow($query); if (count($raw) > 0) { $data['username'] = $raw['username']; $data['userid'] = $raw['id']; } return $data; } if ($fields['userid']) { $query = sprintf("SELECT * FROM sotf_users WHERE id='%s'", $fields['userid']); $raw = $this->userdb->getRow($query); if (count($raw) > 0) { $data['username'] = $raw['username']; $data['userid'] = $raw['id']; //$data['realname'] = $raw['realname']; $data['language'] = $raw['language']; $data['email'] = $raw['email']; } return $data; } raiseError("bad usage: userDbSelect"); }
/** static, this places the icon into the www/tmp, so that you can refer to it with <img src=, returns true if there is an icon for this object */ function cacheIcon($id) { global $cachedir; $cacheTimeout = 2 * 60; // 2 minutes if (!$id) { raiseError("missing id"); } $fname = "{$cachedir}/" . $id . '.png'; if (is_readable($fname)) { $stat = stat($fname); if (time() - $stat['mtime'] <= $cacheTimeout) { return true; } } $icon = sotf_Blob::findBlob($id, 'icon'); if (!$icon) { return false; } // TODO: cache cleanup! ////debug("cache: ". filesize($fname) ."==" . strlen($icon)); if (is_readable($fname) && filesize($fname) == strlen($icon)) { return true; } debug("cached icon for", $id); sotf_Utils::save($fname, $icon); return true; }
/** * Returns the indexth item in the collection. * * @param integer * @return object Node * @access public */ function &item($index) { if (!array_key_exists($index, $this->_list)) { raiseError('myDOM error: index is negative, or greater than the allowed value'); } return $this->_list[$index]; }
function getTableCode($tablename) { $tc = $this->tableCodes[$tablename]; if (!$tc) { raiseError("no table code for table {$tablename}"); } return $tc; }
function errorNative() { $err = parent::errorNative(); //error_log("PGSQL error: $err",0); //error_log("in query: " . substr($this->last_query,0,254) ,0); if (!$this->silent) { raiseError("SQL error!", "{$err} in \n " . $this->last_query); } return $err; }
function listProgrammes($start, $hitsPerPage) { $sql = "SELECT p.*, r.role_id FROM sotf_contacts c, sotf_object_roles r, sotf_programmes p WHERE c.id = '{$this->id}' AND c.id=r.contact_id AND r.object_id = p.id"; $res = $this->db->limitQuery($sql, $start, $hitsPerPage); if (DB::isError($res)) { raiseError($res); } while (DB_OK === $res->fetchInto($item)) { $list[] = $item; } return $list; }
/** returns a list of all such objects: can be slow!! * @method static listAll */ function listAll() { global $db; $sql = "SELECT * FROM sotf_nodes ORDER BY name"; $res = $db->getAll($sql); if (DB::isError($res)) { raiseError($res); } $slist = array(); foreach ($res as $st) { $slist[] = new sotf_Node($st['id'], $st); } return $slist; }
function get($variable_name) { if (isset($this->vars[$variable_name])) { return $this->vars[$variable_name]; } $query = "SELECT value FROM sotf_vars WHERE name='{$variable_name}'"; $result = $this->db->getOne($query); if (DB::isError($result)) { raiseError($result->getMessage()); } debug("getvar", "{$variable_name}={$result}"); $this->vars[$variable_name] = $result; return $result; }
/** Sets the value of a persistent variable. */ function set($name, $val) { $name = sotf_Utils::magicQuotes($name); $val = sotf_Utils::magicQuotes($val); if (isset($this->vars[$name])) { $update = 1; } $this->vars[$name] = $val; if ($update) { $result = $this->db->query("UPDATE {$this->table} SET value='{$val}' WHERE name='{$name}'"); } else { $result = $this->db->query("INSERT INTO {$this->table} (name,value) VALUES('{$name}', '{$val}')"); } if (DB::isError($result)) { raiseError($result); } debug("setvar", "{$name}={$val}"); }
function getFileInDir($dir, $filename) { if (empty($filename)) { raiseError("Filename is empty"); } if (!($path = realpath($dir . '/' . $filename))) { debug("no such file", $dir . '/' . $filename); raiseError("no_such_file"); } /* TODO: this does not work under WIndows, because of / and \ differences if(!strstr($path, $dir)) { debug("path", $path); debug("dir", $dir); raiseError("Attempt to break out directory"); } */ return $path; }
/** static */ function load($id) { global $db; if (empty($id)) { raiseError("empty id for user prefs"); } $data = $db->getOne("SELECT prefs FROM sotf_user_prefs WHERE id = '{$id}'"); if (empty($data)) { $prefs = new sotf_UserPrefs(); $prefs->id = $id; } else { $prefs = unserialize($data); if ($prefs === FALSE) { raiseError("Could not unserialize user preferences"); } } return $prefs; }
function getFileInDir($dir, $filename) { if (empty($filename)) { raiseError("Filename is empty"); } if (!($path = realpath($dir . '/' . $filename))) { debug("no such file", $dir . '/' . $filename); raiseError("no_such_file"); } /* TODO: this does not work under WIndows, because of / and \ differences */ $dirP = str_replace('\\', '/', $dir); $pathP = str_replace('\\', '/', $pathP); debug("DIRP", $dirP); if (!preg_match("|^{$dirP}|", $path)) { debug("path", $path); debug("dir", $dir); raiseError("Attempt to break out directory", $path); } return $path; }
/** list programmes */ function listProgrammes($start, $hitsPerPage, $onlyPublished = true) { $id = $this->id; $sql = "SELECT * FROM sotf_programmes WHERE series_id = '{$id}' "; if ($onlyPublished) { $sql .= " AND published='t' "; } $sql .= " ORDER BY entry_date DESC,track ASC"; if (!$start) { $start = 0; } $res = $this->db->limitQuery($sql, $start, $hitsPerPage); if (DB::isError($res)) { raiseError($res); } while (DB_OK === $res->fetchInto($item)) { $list[] = new sotf_Programme($item['id'], $item); } return $list; }
* 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("OKURL", $_SERVER['PHP_SELF'] . "?id=" . rawurlencode($id)); $id = sotf_Utils::getParameter('id'); if ($id) { $db->begin(); $smarty->assign('ID', $id); $prg =& $repository->getObject($id); if (!$prg) { raiseError("no_such_object", $id); } if (!$prg->getBool('published')) { if (!hasPerm($prg->id, 'change')) { raiseError("not_published_yet", $id); exit; } $smarty->assign("UNPUBLISHED", 1); } $page->setTitle($prg->get('title')); // general data $prgData = $prg->getAll(); $prgData['icon'] = sotf_Blob::cacheIcon($id); $smarty->assign('PRG_DATA', $prgData); // station data $station = $prg->getStation(); $smarty->assign('STATION_DATA', $station->getAllWithIcon()); // series data $series = $prg->getSeries(); if ($series) {
function listProgrammes($start, $hitsPerPage) { global $db; // TODO: make it distinct, but also list roles (if multiple) ... r.role_id is not collected $sql = "SELECT distinct(p.*) FROM sotf_contacts c, sotf_object_roles r, sotf_programmes p WHERE c.id = '{$this->id}' AND c.id=r.contact_id AND r.object_id = p.id"; $res = $db->limitQuery($sql, $start, $hitsPerPage); if (DB::isError($res)) { raiseError($res); } while (DB_OK === $res->fetchInto($item)) { $list[] = $item; } return $list; }
} $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 require "init.inc.php"; $page->forceLogin(); $context = sotf_Utils::getParameter('context'); $objectname = sotf_Utils::getParameter('objectname'); $objectid = sotf_Utils::getParameter('objectid'); $username = sotf_Utils::getParameter('username'); $save = sotf_Utils::getParameter('save'); $userid = $user->getUserid($username); if (!hasPerm($objectid, "change")) { raiseError("You have no permission to change user permissions!"); } if (empty($userid) || !is_numeric($userid)) { raiseError("Invalid username: {$username}"); } if ($save) { $userPerms = $permissions->getPermissions($objectid, $userid); debug("userPerms", $userPerms); if (sotf_Utils::getParameter('perm_admin')) { if (!in_array('admin', $userPerms)) { $permissions->addPermission($objectid, $userid, 'admin'); } } else { if (in_array('admin', $userPerms)) { $permissions->delPermission($objectid, $userid, 'admin'); } $perms['create'] = sotf_Utils::getParameter('perm_create'); $perms['change'] = sotf_Utils::getParameter('perm_change'); $perms['add_prog'] = sotf_Utils::getParameter('perm_add_prog'); $perms['delete'] = sotf_Utils::getParameter('perm_delete');
/** can be static */ function newNodeInNetwork($newId) { global $db; $db->begin(); $count = $db->getOne("SELECT count(*) FROM sotf_object_status WHERE node_id = '{$newId}'"); if ($count > 0) { raiseError("THis new node is not new at all: {$newId}"); } $db->query("INSERT INTO sotf_object_status SELECT id, '{$newId}' AS node_id FROM sotf_node_objects WHERE node_id != '{$newId}' OR node_id IS NULL"); $db->commit(); }
<?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"; $smarty->assign("PAGETITLE", $page->getlocalized("EditorPage")); $page->forceLogin(); $smarty->assign("OKURL", $_SERVER['PHP_SELF']); if (!$permissions->isEditor()) { raiseError("You have no permission to upload to any station"); exit; } // delete prog if (sotf_Utils::getParameter('delprog')) { $prgid = sotf_Utils::getParameter('prgid'); $prg = new sotf_Programme($prgid); $prg->delete(); $page->redirect("editor.php"); exit; } if (sotf_Utils::getParameter('addprog')) { $fname = sotf_Utils::getParameter('fname'); $station = sotf_Utils::getParameter('station'); checkPerm($station, 'add_prog'); $newPrg = new sotf_Programme(); $track = preg_replace('/\\.[^.]*$/', '', $fname);
/** THis will change the user interface into the desired language on the next request. */ function setUILanguage($lang) { if (!setcookie('uiLang', $lang)) { raiseError("could not set cookie for uilang"); } }
/** Search for users. */ function findUsers($pattern, $prefix = false) { global $userdb; $storage =& sotf_User::getStorageObject(); $fields['pattern'] = sotf_Utils::magicQuotes($pattern); if ($prefix) { $fields['prefix'] = 1; } $res = $storage->userDbFind($fields); if (DB::isError($res)) { raiseError($res); } return $res; }
<?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"; $filename = sotf_Utils::getParameter('filename'); $filename = sotf_Utils::getFileInDir($user->getUserDir(), $filename); $file =& new sotf_File($filename); if ($file->type != "none") { header("Content-type: " . $file->mimetype . "\n"); header("Content-transfer-encoding: binary\n"); header("Content-length: " . filesize($filename) . "\n"); // send file readfile($filename); } else { raiseError("download_problem"); } $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"; $id = sotf_Utils::getParameter('id'); $fileid = sotf_Utils::getParameter('fileid'); if (empty($id)) { raiseError("Missing parameters!"); } $prg = new sotf_Programme($id); $playlist = new sotf_Playlist(); $playlist->addProg($prg, $fileid); $playlist->startStreaming(); $playlist->sendRemotePlaylist(); $page->logRequest();
function linkAudio($filepath, $audioAttrs) { global $config; $tmpFileName = 'au_' . $audioAttrs['id'] . '_' . basename($filepath); $tmpFile = $config['tmpDir'] . "/{$tmpFileName}"; $file = @readlink($tmpFile); if ($file) { if (!is_readable($file)) { logError("Bad symlink: {$tmpFile} to {$file}"); unlink($tmpFile); $file = false; } } if (!$file) { if (!symlink($filepath, $tmpFile)) { raiseError("symlink failed in tmp dir"); } } return $tmpFile; }
function checkAdminAccess() { global $config; $host = getHostName(); debug('admin check', $config['adminDomain']); if (!preg_match('/' . $config['adminDomain'] . '/i', $host)) { raiseError("no access", "to admin page: " . myGetenv("REQUEST_URI")); } else { debug("admin access OK for", $host); } }
$neighbour = sotf_Neighbour::getById($nid); $neighbour->delete(); $page->redirect("admin.php#network"); $page->logRequest(); } // manage permissions $delperm = sotf_Utils::getParameter('delperm'); if (sotf_Utils::getParameter('delperm')) { checkPerm('node', 'authorize'); $userid = sotf_Utils::getParameter('userid'); if (empty($userid) || !is_numeric($userid)) { raiseError("Invalid userid: {$userid}"); } $username = $user->getUsername($userid); if (empty($username)) { raiseError("Invalid userid: {$userid}"); } $permissions->delPermission('node', $userid); $msg = $page->getlocalizedWithParams("deleted_permissions_for", $username); $page->addStatusMsg($msg, false); $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();
for ($i = 0; $i < count($config[$checker->prefix . 'Formats']); $i++) { if ($PRG_AUDIO[$i]['converting'] == true) { $converting = true; } } debug("mainAudio", $mainAudio); if (is_array($mainAudio)) { while (list($fn, $finfo) = each($mainAudio)) { $PRG_AUDIO[] = $finfo; } } // start converting required video formats if ($videoconv && $missing) { $obj = $repository->getObject($id); if (!$obj) { raiseError("object does not exist!"); } checkPerm($obj->id, 'change'); $checker->console = false; if ($convertall) { $checker->convertAll($obj->id); } elseif ($convertindex != "") { $checker->convert($obj->id, $convertindex); } $page->redirect("editFiles.php?id={$id}"); exit; } ////////////////////////////////////////////////////////// if (preg_match("/.ogg\$/", $audioFiles[0]['format'])) { $smarty->assign('IS_OGG', true); }
<?php require "init.inc.php"; $smarty->assign('PAGETITLE', $page->getlocalized('add_files')); $page->forceLogin(); $prgId = sotf_Utils::getParameter('prgid'); $main = sotf_Utils::getParameter('main'); $add = sotf_Utils::getParameter('add'); if (empty($prgId)) { raiseError("Missing programme id!"); } if (!hasPerm($prgId, "change")) { raiseError("You have no permission to add files here!"); } // upload file $upload = sotf_Utils::getParameter('upload'); if ($upload) { $fname = $_FILES['userfile']['name']; $file = sotf_Utils::getFileInDir($user->getUserDir(), $fname); move_uploaded_file($_FILES['userfile']['tmp_name'], $file); $prg = new sotf_Programme($prgId); if ($main) { $prg->setAudio($file); $page->redirect("closeAndRefresh.php"); } else { $prg->setOtherFile($fname); $page->redirect("closeAndRefresh.php#anchor=mfiles"); } exit; } // add files
$properties["link"] = $config['rootUrl'] . "/search.php?language=any_language&station={$stationName}"; $properties["title"] = "Search for:"; $properties["description"] = $page->getlocalizedWithParams('search_in_station', $stationName); $rss_writer_object->addtextinput($properties); } elseif ($userName) { // user's saved query $userid = sotf_User::getUserid($userName); if (!$userid) { raiseError("no such user: {$userName}"); } $user2 = new sotf_User($userid); $prefs2 = $user2->getPreferences(); debug('saved queries', $prefs2->savedQueries); $query = $prefs2->getQuery($queryName); if (!$query) { raiseError("no such user query: {$userName}/{$queryName}"); } // Define the properties of the channel. $properties = array(); $properties["description"] = "Results of the StreamOnTheFly query {$userName}/{$queryName}"; $properties["link"] = $config['rootUrl'] . ""; $properties["title"] = "StreamOnTheFly query results"; //$properties["language"]="en"; $properties["dc:date"] = getW3CDate(); $rss_writer_object->addchannel($properties); // If your channel has a logo, before adding any channel items, specify the logo details this way. $properties = array(); $properties["url"] = $config['rootUrl'] . "/static/sotflogosmall.gif"; $properties["link"] = $config['rootUrl'] . ""; $properties["title"] = "StreamOnTheFly logo"; $properties["description"] = "World wide network of radio archives";