diff options
author | redmatrix <redmatrix@redmatrix.me> | 2015-09-03 18:44:40 -0700 |
---|---|---|
committer | redmatrix <redmatrix@redmatrix.me> | 2015-09-03 18:44:40 -0700 |
commit | d79e81a0697617b5552917c2fe169b30433c54f6 (patch) | |
tree | 77fb93e47bd18d8fab477aa5f5abe3ee79a3a452 /include/import.php | |
parent | d93e1c84acd07188e8cba06249b11840d562d011 (diff) | |
download | volse-hubzilla-d79e81a0697617b5552917c2fe169b30433c54f6.tar.gz volse-hubzilla-d79e81a0697617b5552917c2fe169b30433c54f6.tar.bz2 volse-hubzilla-d79e81a0697617b5552917c2fe169b30433c54f6.zip |
import and sync chatrooms
Diffstat (limited to 'include/import.php')
-rw-r--r-- | include/import.php | 99 |
1 files changed, 97 insertions, 2 deletions
diff --git a/include/import.php b/include/import.php index 6ce572ea2..261219ce0 100644 --- a/include/import.php +++ b/include/import.php @@ -349,7 +349,7 @@ function sync_apps($channel,$apps) { intval($channel['channel_id']) ); if($x) { - if($x[0]['app_edited'] >= $obj['app_edited']) + if($x[0]['app_edited'] >= $app['app_edited']) continue; $exists = true; } @@ -377,4 +377,99 @@ function sync_apps($channel,$apps) { } } } -}
\ No newline at end of file +} + + + +function import_chatrooms($channel,$chatrooms) { + + if($channel && $chatrooms) { + foreach($chatrooms as $chatroom) { + + if(! $chatroom['cr_name']) + continue; + + unset($chatroom['cr_id']); + unset($chatroom['cr_aid']); + unset($chatroom['cr_uid']); + + $chatroom['cr_aid'] = $channel['channel_account_id']; + $chatroom['cr_uid'] = $channel['channel_id']; + + dbesc_array($chatroom); + $r = dbq("INSERT INTO chatroom (`" + . implode("`, `", array_keys($chatroom)) + . "`) VALUES ('" + . implode("', '", array_values($chatroom)) + . "')" + ); + } + } +} + + + +function sync_chatrooms($channel,$chatrooms) { + + if($channel && $chatrooms) { + foreach($chatrooms as $chatroom) { + + if(! $chatroom['cr_name']) + continue; + + if(array_key_exists('cr_deleted',$chatroom) && $chatroom['cr_deleted']) { + q("delete from chatroom where cr_name = '%s' and cr_uid = %d limit 1", + dbesc($chatroom['cr_name']), + intval($channel['channel_id']) + ); + continue; + } + + + unset($chatroom['cr_id']); + unset($chatroom['cr_aid']); + unset($chatroom['cr_uid']); + + if(! $chatroom['cr_created'] || $chatroom['cr_created'] === NULL_DATE) + $chatroom['cr_created'] = datetime_convert(); + if(! $chatroom['cr_edited'] || $chatroom['cr_edited'] === NULL_DATE) + $chatroom['cr_edited'] = datetime_convert(); + + $chatroom['cr_aid'] = $channel['channel_account_id']; + $chatroom['cr_uid'] = $channel['channel_id']; + + $exists = false; + + $x = q("select * from chatroom where cr_name = '%s' and cr_uid = %d limit 1", + dbesc($chatroom['cr_name']), + intval($channel['channel_id']) + ); + if($x) { + if($x[0]['cr_edited'] >= $chatroom['cr_edited']) + continue; + $exists = true; + } + $name = $chatroom['cr_name']; + + if($exists) { + foreach($chatroom as $k => $v) { + $r = q("UPDATE chatroom SET `%s` = '%s' WHERE cr_name = '%s' AND cr_uid = %d", + dbesc($k), + dbesc($v), + dbesc($name), + intval($channel['channel_id']) + ); + } + } + else { + dbesc_array($chatroom); + $r = dbq("INSERT INTO chatroom (`" + . implode("`, `", array_keys($chatroom)) + . "`) VALUES ('" + . implode("', '", array_values($chatroom)) + . "')" + ); + } + } + } +} |