Skip to content

Commit

Permalink
bug fix of nicolive (official) support
Browse files Browse the repository at this point in the history
* clear temporary only not live
* add to temporary only not already added
  • Loading branch information
kazy111 committed Mar 24, 2012
1 parent 450560e commit 0b824c7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
7 changes: 6 additions & 1 deletion check.php
Expand Up @@ -635,7 +635,12 @@ function check_nicolive_official()
$items = $xml->channel->item;
if ($items) {
for ($i = 0; $i < count($items); $i++) {
//set online
// if already added, then skip
if ($manager->check_already_registered(3, $items[$i]->guid, NULL)) {
continue;
}

// now add streamer as templrary
$check = $items[$i]->title;
$desc = addslashes(strip_tags($items[$i]->description));
if (preg_match('/'.$GLOBALS['limit_keywords'].'/', $check) > 0){
Expand Down
1 change: 1 addition & 0 deletions classes/database/IDataManager.php
Expand Up @@ -42,6 +42,7 @@ function set_tag($data);
function initialize_db();
function delete_db();
function register_onece($name, $room, $chat_type, $ust_id, $jus_id, $ust_no, $desc);
function check_already_registered($pg_type, $pg_id, $opt_no);
function register($name, $desc, $chat_type, $room, $pg_type, $pg_id, $opt_no, $temporary = 0);
function clear_temporary();
function truncate_increment_counter();
Expand Down
23 changes: 19 additions & 4 deletions classes/database/MySQLDataManager.php
Expand Up @@ -364,7 +364,7 @@ function initialize_db() {
.'optional_id VARCHAR(255),'
.'title VARCHAR(255) DEFAULT \'\','
.'thumbnail TEXT,'
.'live BOOL,'
.'live BOOL DEFAULT FALSE,'
.'start_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,'
.'end_time TIMESTAMP DEFAULT 0,'
.'viewer INT,'
Expand Down Expand Up @@ -446,6 +446,20 @@ function register_onece($name, $room, $chat_type, $ust_id, $jus_id, $ust_no, $de

}

function check_already_registered($pg_type, $pg_id, $opt_no) {
try{
$tmp = $this->db->query_ex('select id from program_table where type='
.$pg_type.' and ch_name=\''.$pg_id.'\' and optional_id=\''.$opt_no.'\'');
if (is_null($tmp) || !is_numeric($tmp['id'])) {
return FALSE;
} else {
return TRUE;
}
} catch (Exception $e) {
print $e->getMessage();
return FALSE;
}
}

function register($name, $desc, $chat_type, $room, $pg_type, $pg_id, $opt_no, $temporary = 0){
$this->db->begin();
Expand All @@ -464,8 +478,8 @@ function register($name, $desc, $chat_type, $room, $pg_type, $pg_id, $opt_no, $t
}else
$cid = $tmp['id'];

$this->db->query('insert into program_table (streamer_id, chat_id, type, ch_name, optional_id)'
.' values ('.$sid.', '.$cid.', '.$pg_type.', \''.$pg_id.'\',\''.$opt_no.'\')');
$this->db->query('insert into program_table (streamer_id, chat_id, type, ch_name, optional_id, live)'
.' values ('.$sid.', '.$cid.', '.$pg_type.', \''.$pg_id.'\',\''.$opt_no.'\', false)');

$this->db->commit();
}catch(Exception $e){
Expand All @@ -477,7 +491,8 @@ function register($name, $desc, $chat_type, $room, $pg_type, $pg_id, $opt_no, $t

function clear_temporary() {
try{
$sql = 'select id from streamer_table where temporary = 1';
// clear temporary (and not live) streaming
$sql = 'SELECT DISTINCT s.id FROM streamer_table s LEFT JOIN program_table p ON s.id = p.streamer_id AND p.live WHERE p.id IS NULL AND temporary = 1';
$result = $this->db->query($sql);

while($arr = $this->db->fetch($result)){
Expand Down
23 changes: 19 additions & 4 deletions classes/database/PostgreSQLDataManager.php
Expand Up @@ -364,7 +364,7 @@ function initialize_db() {
.'optional_id VARCHAR(255),'
.'title VARCHAR(255) DEFAULT \'\','
.'thumbnail TEXT,'
.'live BOOLEAN,'
.'live BOOLEAN DEFAULT FALSE,'
.'start_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,'
.'end_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,'
.'viewer INT,'
Expand Down Expand Up @@ -454,6 +454,20 @@ function register_onece($name, $room, $chat_type, $ust_id, $jus_id, $ust_no, $de

}

function check_already_registered($pg_type, $pg_id, $opt_no) {
try{
$tmp = $this->db->query_ex('select id from program_table where type='
.$pg_type.' and ch_name=\''.$pg_id.'\' and optional_id=\''.$opt_no.'\'');
if (is_null($tmp) || !is_numeric($tmp['id'])) {
return FALSE;
} else {
return TRUE;
}
} catch (Exception $e) {
print $e->getMessage();
return FALSE;
}
}

function register($name, $desc, $chat_type, $room, $pg_type, $pg_id, $opt_no, $temporary = 0){
$this->db->begin();
Expand All @@ -480,8 +494,8 @@ function register($name, $desc, $chat_type, $room, $pg_type, $pg_id, $opt_no, $t
$cid = $tmp['id'];
}

$this->db->query('insert into program_table (streamer_id, chat_id, type, ch_name, optional_id)'
.' values ('.$sid.', '.$cid.', '.$pg_type.', \''.$pg_id.'\',\''.$opt_no.'\')');
$this->db->query('insert into program_table (streamer_id, chat_id, type, ch_name, optional_id, live)'
.' values ('.$sid.', '.$cid.', '.$pg_type.', \''.$pg_id.'\',\''.$opt_no.'\', false)');

$this->db->commit();
}catch(Exception $e){
Expand All @@ -493,7 +507,8 @@ function register($name, $desc, $chat_type, $room, $pg_type, $pg_id, $opt_no, $t

function clear_temporary() {
try{
$sql = 'select id from streamer_table where temporary = 1';
// clear temporary (and not live) streaming
$sql = 'SELECT DISTINCT s.id FROM streamer_table s LEFT JOIN program_table p ON s.id = p.streamer_id AND p.live WHERE p.id IS NULL AND temporary = 1';
$result = $this->db->query($sql);

while($arr = $this->db->fetch($result)){
Expand Down

0 comments on commit 0b824c7

Please sign in to comment.