function create()
 {
     global $nodeId;
     if (!$this->nodeId) {
         $this->nodeId = $nodeId;
     }
     if (!$this->lastChange) {
         $this->lastChange = $this->db->getTimestampTz();
     }
     if (empty($this->id)) {
         $this->id = $this->generateID();
     }
     $this->db->query("INSERT INTO sotf_node_objects (id, node_id, last_change, arrived) VALUES('{$this->id}','{$this->nodeId}', '{$this->lastChange}', CURRENT_TIMESTAMP)");
     $success = parent::create();
     if (!$success) {
         $this->db->query("DELETE FROM sotf_node_objects WHERE id='{$this->id}'");
     }
     return $success;
 }
 /** may be static, if all paramters filled -- When you have to send forward stats data to the home node */
 function createForwardObject($type, $data, $objId = 0, $nodeId = 0)
 {
     global $db;
     if (!$objId) {
         $objId = $this->id;
     }
     // the id of the target object
     if (!$nodeId) {
         $nodeId = $this->getNodeId();
     }
     // the id of the node to send this to
     $obj = new sotf_Object("sotf_to_forward");
     $obj->setAll(array('prog_id' => $objId, 'node_id' => $nodeId, 'type' => $type, 'entered' => $db->getTimestampTz(), 'data' => serialize($data)));
     $obj->create();
 }
 function startStreaming()
 {
     global $config, $page, $db;
     if ($config['httpStreaming']) {
         $this->makeLocalPlaylist();
         $this->url = $config['tmpUrl'] . '/pl_' . $this->getTmpId() . '.m3u';
         return;
     }
     // check if the stream has started already (Win+IE+Media player)
     $urls = $db->getCol("SELECT url FROM sotf_streams WHERE host='" . getHostName() . "' AND started < CURRENT_TIMESTAMP AND started > CURRENT_TIMESTAMP - interval '15 seconds'");
     if (count($urls) == 1) {
         debug("found url for Win Explorer", $urls[0]);
         $this->url = $urls[0];
         // found stream so we can return
         return;
     }
     $this->stopMyStream();
     if ($config['tamburineURL']) {
         // streaming with tamburine + XML-RPC
         // playlist
         reset($this->audioFiles);
         while (list(, $audioFile) = each($this->audioFiles)) {
             $songs[] = $audioFile['path'];
         }
         $rpc = new rpc_Utils();
         //$rpc->debug = true;
         $response = $rpc->callTamburine('setpls', $songs);
         if (is_null($response)) {
             raiseError("no reply from tamburine server");
         } else {
             $this->url = $response[2];
             $this->streamId = $response[1];
         }
         if (!$this->url) {
             raiseError("Could not find mount point for stream!");
         }
     } elseif ($config['tamburineCMD']) {
         // streaming with tbrcmd
         if (!$this->localPlaylist) {
             $this->makeLocalPlaylist();
         }
         $cmd = $config['tamburineCMD'] . " setpls " . $this->localPlaylist . " 2>&1";
         exec($cmd, $output, $retval);
         debug("cmd", $cmd);
         //debug("output", $output);
         //debug("retval", $retval);
         $lines = array_values(preg_grep('/Fatal Error:/', $output));
         if (count($lines) > 0) {
             raiseError(join(", ", $lines));
             // TODO: restart tamburine (??)
         }
         //$lines = preg_grep('/Stream\[(\d+)\]\s+spawned on (\S+)/', $output);
         foreach ($output as $line) {
             if (preg_match('/Stream\\[(\\d+)\\]\\s+spawned on (\\S+)/', $line, $mm)) {
                 $this->streamId = $mm[1];
                 $this->url = $mm[2];
                 break;
             }
         }
         if (!$this->url) {
             raiseError("Could not find mount point for stream!");
         }
     } else {
         // command-line streaming
         if (!$this->localPlaylist) {
             $this->makeLocalPlaylist();
         }
         $this->url = 'http://' . $config['iceServer'] . ':' . $config['icePort'] . '/' . $this->getMountPoint() . "\n";
         //$url = preg_replace('/^.*\/repository/', 'http://sotf2.dsd.sztaki.hu/node/repository', $filepath);
         // TODO: calculate bitrate from all files...
         $bitrate = $this->audioFiles[0]['bitrate'];
         if (!$bitrate) {
             $bitrate = 24;
         }
         $this->cmdStart($this->localPlaylist, $this->getMountPoint(), $bitrate);
         //$this->cmdStart2($bitrate);
     }
     if ($this->url) {
         $streamData = array('pid' => $this->streamId, 'url' => $this->url, 'started' => $db->getTimestamp(), 'length' => round($this->totalLength), 'will_end_at' => $db->getTimestamp(time() + round($this->totalLength)), 'host' => getHostName());
         debug("streamData", $streamData);
         $_SESSION['stream'] = $streamData;
         $obj = new sotf_Object('sotf_streams');
         $obj->setAll($streamData);
         $obj->create();
         // TODO wait until stream really starts
         sleep(3);
     }
 }
 function setGroup($uid, $gid, $member, $rid = '')
 {
     if ($rid) {
         if (!$member) {
             $o = new sotf_Object('sotf_user_groups', $rid);
             $o->delete();
         }
         return;
     }
     $o = new sotf_Object('sotf_user_groups');
     $o->set('user_id', $uid);
     $o->set('group_id', $gid);
     $o->find();
     debug("EXISTS", $o->exists());
     debug("MEM", $member);
     if ($member) {
         if (!$o->exists()) {
             $o->create();
         }
     } else {
         if ($o->exists()) {
             $o->delete();
         }
     }
 }
Esempio n. 5
0
    $id = $x->getID();
}
if ($topic_name != "") {
    $x = new sotf_NodeObject("sotf_topics");
    $x->set('topic_id', $topic_id);
    $x->set('language', "en");
    $x->set('topic_name', $topic_name);
    $x->create();
    $id = $x->getID();
    print $id;
}
if ($topic_counter != "") {
    $x = new sotf_Object("sotf_topics_counter");
    $x->set('topic_id', $topic_id);
    $x->set('number', $topic_counter);
    $x->create();
    $id = $x->getID();
    print $id;
}
$query = "SELECT sotf_topic_tree_defs.*, sotf_topics.topic_name, sotf_topics_counter.number from sotf_topic_tree_defs" . " LEFT JOIN sotf_topics ON sotf_topics.topic_id = sotf_topic_tree_defs.id" . " LEFT JOIN sotf_topics_counter ON sotf_topics_counter.topic_id = sotf_topic_tree_defs.id";
$result = $db->getAll($query);
usort($result, "SORTIT");
$parentid;
$counter = 0;
$max = count($result);
for ($i = 0; $i < $max; $i++) {
    if ($result[$i]["supertopic"] == 0) {
        if ($i != 0) {
            $result[$parentid]["numberall"] = $counter;
        }
        $parentid = $i;
 function addStat($fileId, $type)
 {
     global $db, $user;
     sotf_Statistics::addStat($this, $fileId, $type);
     if ($user) {
         $hist = new sotf_Object('sotf_user_history');
         $hist->set('user_id', $user->id);
         $hist->set('object_id', $this->id);
         $hist->set('action', $type);
         $hist->set('action_date', $db->getTimestampTz());
         $hist->create();
     }
 }
 function processPortalEvent($event)
 {
     debug("processing event", $event);
     $progId = $event['prog_id'];
     if ($progId) {
         if ($this->looksLikeId($progId)) {
             $prg =& $this->getObject($progId);
         }
         if (!$prg) {
             debug("Invalid prog_id arrived in portal event", $progId);
             return -1;
         }
     }
     switch ($event['name']) {
         case 'programme_added':
             $obj = new sotf_NodeObject('sotf_prog_refs');
             $obj->set('prog_id', $event['value']);
             $obj->set('url', $event['url']);
             $obj->find();
             $obj->set('station_id', $prg->get('station_id'));
             $obj->set('start_date', $event['timestamp']);
             $obj->set('portal_name', $event['portal_name']);
             $obj->save();
             break;
         case 'programme_deleted':
             $obj = new sotf_NodeObject('sotf_prog_refs');
             $obj->set('prog_id', $event['value']);
             $obj->set('url', $event['url']);
             $obj->find();
             if (!$obj->exists()) {
                 debug("unknown prog ref arrives: " . $event['value'] . ' - ' . $event['url']);
                 $obj->set('portal_name', $event['portal_name']);
             }
             $obj->set('station_id', $prg->get('station_id'));
             $obj->set('end_date', $event['timestamp']);
             //$obj->set('portal_name', $event['portal_name']);
             $obj->save();
             break;
         case 'visit':
             $obj = new sotf_NodeObject('sotf_prog_refs');
             $obj->set('prog_id', $event['value']['prog_id']);
             $obj->set('url', $event['url']);
             $obj->find();
             if (!$obj->exists()) {
                 // TODO: how can this happen? It happens too many times!
                 debug("unknown prog ref arrives: " . $event['value']['prog_id'] . ' - ' . $event['url']);
                 $obj->set('start_date', $event['timestamp']);
                 $obj->set('portal_name', $event['portal_name']);
             }
             $obj->set('station_id', $prg->get('station_id'));
             $obj->set('visits', (int) $obj->get('visits') + 1);
             // TODO: count unique accesses
             $obj->save();
             break;
         case 'page_impression':
             $obj = new sotf_NodeObject('sotf_portals');
             $obj->set('url', $event['url']);
             $obj->find();
             $obj->set('name', $event['portal_name']);
             $obj->set('page_impression', $event['value']);
             $obj->set('last_access', $event['timestamp']);
             $obj->save();
             break;
         case 'portal_updated':
             $obj = new sotf_NodeObject('sotf_portals');
             $obj->set('url', $event['url']);
             $obj->find();
             $obj->set('name', $event['portal_name']);
             $obj->set('last_update', $event['timestamp']);
             $obj->save();
             break;
         case 'users':
             $obj = new sotf_NodeObject('sotf_portals');
             $obj->set('url', $event['url']);
             $obj->find();
             if (!$obj->exists()) {
                 $obj->set('name', $event['portal_name']);
             }
             $obj->set('last_update', $event['timestamp']);
             $obj->set('reg_users', $event['value']);
             if (!$obj->get('name') || !$obj->get('url')) {
                 logError("Bad portal even teceived", implode(" | ", $event));
             } else {
                 $obj->save();
             }
             break;
         case 'rating':
             // first save in prog_refs
             $obj = new sotf_NodeObject('sotf_prog_refs');
             $obj->set('prog_id', $event['value']['prog_id']);
             $obj->set('url', $event['url']);
             $obj->find();
             if (!$obj->exists()) {
                 debug("unknown prog ref arrives: " . $event['url']);
                 $obj->set('start_date', $event['timestamp']);
                 $obj->set('portal_name', $event['portal_name']);
             }
             $obj->set('station_id', $prg->get('station_id'));
             $obj->set('rating', $event['value']['RATING_VALUE']);
             $obj->set('raters', $event['value']['RATING_COUNT']);
             $obj->save();
             // TODO second, put into global rating database
             /*
             $rating = new sotf_Rating();
             $id = $event['value']['prog_id'];
             $obj = & $this->getObject($id);
             if($obj->isLocal()) {
               $data = $event['value'];
               $rating->setRemoteRating($data);
             } else {
               logError("received rating for non-local object!");
             }
             */
             break;
         case 'comment':
             // first save in prog_refs
             $obj = new sotf_NodeObject('sotf_prog_refs');
             $obj->set('prog_id', $event['value']['prog_id']);
             $obj->set('url', $event['url']);
             $obj->find();
             if (!$obj->exists()) {
                 logError("unknown prog ref arrives: " . $event['value']['prog_id'] . ' - ' . $event['url']);
                 $obj->set('start_date', $event['timestamp']);
                 $obj->set('portal_name', $event['portal_name']);
             }
             $obj->set('station_id', $prg->get('station_id'));
             $obj->set('comments', (int) $obj->get('comments') + 1);
             $obj->save();
             // save comment
             $obj = new sotf_Object('sotf_comments');
             $obj->set('prog_id', $event['value']['prog_id']);
             $obj->set('portal', $event['url']);
             $obj->set('entered', $event['timestamp']);
             $obj->set('comment_title', $event['value']['title']);
             $obj->set('comment_text', $event['value']['comment']);
             $obj->set('from_name', $event['value']['user_name']);
             $obj->set('from_email', $event['value']['email']);
             $obj->create();
             // TODO forward to authors
             break;
         case 'query_added':
             //debug("query from portal", $event);
         //debug("query from portal", $event);
         case 'query_deleted':
         case 'file_uploaded':
             // silently ignored
             break;
         default:
             logError("unknown portal event: " . $event['name']);
     }
 }
 /** Private! Compares a replicated object to the local one and saves it if it's newer than the local. */
 function saveReplica()
 {
     global $sotfVars;
     $oldData = $this->db->getRow("SELECT * FROM sotf_node_objects WHERE id='{$this->id}' ");
     //debug("changed", $changed);
     //debug("lch", $this->lastChange);
     if (count($oldData) > 0) {
         if ($this->internalData['change_stamp'] && $this->internalData['change_stamp'] > $oldData['change_stamp']) {
             // this is newer, save it
             sotf_Object::update();
             // save internal data
             $this->internalData['arrived_stamp'] = $sotfVars->get('sync_stamp', 0);
             $this->internalData['arrived'] = $this->db->getTimestampTz();
             $internalObj = new sotf_Object('sotf_node_objects', $this->internalData['id'], $this->internalData);
             $internalObj->update();
             // save binary fields
             /*
             reset($this->binaryFields);
             while(list(,$field)=each($this->binaryFields)) {
             			 sotf_Object::setBlob($field, $this->db->unescape_bytea($this->data[$field]));
             }
             */
             debug("updated ", $this->id);
             return true;
         } elseif ($this->internalData['change_stamp'] && $this->internalData['change_stamp'] == $oldData['change_stamp']) {
             debug("arrived same version of", $this->id);
             return true;
         } else {
             debug("arrived older version of", $this->id);
             return false;
         }
     } else {
         $this->internalData['arrived_stamp'] = $sotfVars->get('sync_stamp', 0);
         $this->internalData['arrived'] = $this->db->getTimestampTz();
         $internalObj = new sotf_Object('sotf_node_objects', $this->id, $this->internalData);
         $internalObj->create();
         $success = sotf_Object::create();
         if (!$success) {
             $internalObj->delete();
         }
         debug("created ", $this->id);
         return $success;
     }
 }