$hubloc['hubloc_guid'], 'guid_sig' => $hubloc['hubloc_guid_sig'], 'url' => $hubloc['hubloc_url'], 'url_sig' => $hubloc['hubloc_url_sig'] ); if(($hubloc['hubloc_hash'] === $channel['channel_hash']) && intval($hubloc['hubloc_primary']) && ($seize)) $hubloc['hubloc_primary'] = 0; if(! zot_gethub($arr)) { unset($hubloc['hubloc_id']); dbesc_array($hubloc); $r = dbq("INSERT INTO hubloc (`" . implode("`, `", array_keys($hubloc)) . "`) VALUES ('" . implode("', '", array_values($hubloc)) . "')" ); } } } } function import_objs($channel,$objs) { if($channel && $objs) { foreach($objs as $obj) { // if it's the old term format - too hard to support if(! $obj['obj_created']) continue; $baseurl = $obj['obj_baseurl']; unset($obj['obj_id']); unset($obj['obj_baseurl']); $obj['obj_channel'] = $channel['channel_id']; if($baseurl && (strpos($obj['obj_url'],$baseurl . '/thing/') !== false)) { $obj['obj_url'] = str_replace($baseurl,z_root(),$obj['obj_url']); } if($obj['obj_imgurl']) { $x = import_xchan_photo($obj['obj_imgurl'],$channel['channel_hash'],true); $obj['obj_imgurl'] = $x[0]; } dbesc_array($obj); $r = dbq("INSERT INTO obj (`" . implode("`, `", array_keys($obj)) . "`) VALUES ('" . implode("', '", array_values($obj)) . "')" ); } } } function sync_objs($channel,$objs) { if($channel && $objs) { foreach($objs as $obj) { if(array_key_exists('obj_deleted',$obj) && $obj['obj_deleted'] && $obj['obj_obj']) { q("delete from obj where obj_obj = '%s' and obj_channel = %d limit 1", dbesc($obj['obj_obj']), intval($channel['channel_id']) ); continue; } // if it's the old term format - too hard to support if(! $obj['obj_created']) continue; $baseurl = $obj['obj_baseurl']; unset($obj['obj_id']); unset($obj['obj_baseurl']); $obj['obj_channel'] = $channel['channel_id']; if($baseurl && (strpos($obj['obj_url'],$baseurl . '/thing/') !== false)) { $obj['obj_url'] = str_replace($baseurl,z_root(),$obj['obj_url']); } $exists = false; $x = q("select * from obj where obj_obj = '%s' and obj_channel = %d limit 1", dbesc($obj['obj_obj']), intval($channel['channel_id']) ); if($x) { if($x[0]['obj_edited'] >= $obj['obj_edited']) continue; $exists = true; } if($obj['obj_imgurl']) { $x = import_xchan_photo($obj['obj_imgurl'],$channel['channel_hash'],true); $obj['obj_imgurl'] = $x[0]; } $hash = $obj['obj_obj']; if($exists) { unset($obj['obj_obj']); foreach($obj as $k => $v) { $r = q("UPDATE obj SET `%s` = '%s' WHERE obj_obj = '%s' AND obj_channel = %d", dbesc($k), dbesc($v), dbesc($hash), intval($channel['channel_id']) ); } } else { dbesc_array($obj); $r = dbq("INSERT INTO obj (`" . implode("`, `", array_keys($obj)) . "`) VALUES ('" . implode("', '", array_values($obj)) . "')" ); } } } } function import_apps($channel,$apps) { if($channel && $apps) { foreach($apps as $app) { unset($app['id']); unset($app['app_channel']); $app['app_channel'] = $channel['channel_id']; if($app['app_photo']) { $x = import_xchan_photo($app['app_photo'],$channel['channel_hash'],true); $app['app_photo'] = $x[0]; } dbesc_array($app); $r = dbq("INSERT INTO app (`" . implode("`, `", array_keys($app)) . "`) VALUES ('" . implode("', '", array_values($app)) . "')" ); } } } function sync_apps($channel,$apps) { if($channel && $apps) { foreach($apps as $app) { if(array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) { q("delete from app where app_id = '%s' and app_channel = %d limit 1", dbesc($app['app_id']), intval($channel['channel_id']) ); continue; } unset($app['id']); unset($app['app_channel']); if(! $app['app_created'] || $app['app_created'] === NULL_DATE) $app['app_created'] = datetime_convert(); if(! $app['app_edited'] || $app['app_edited'] === NULL_DATE) $app['app_edited'] = datetime_convert(); $app['app_channel'] = $channel['channel_id']; if($app['app_photo']) { $x = import_xchan_photo($app['app_photo'],$channel['channel_hash'],true); $app['app_photo'] = $x[0]; } $exists = false; $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1", dbesc($app['app_id']), intval($channel['channel_id']) ); if($x) { if($x[0]['app_edited'] >= $app['app_edited']) continue; $exists = true; } $hash = $app['app_id']; if($exists) { unset($app['app_id']); foreach($app as $k => $v) { $r = q("UPDATE app SET `%s` = '%s' WHERE app_id = '%s' AND app_channel = %d", dbesc($k), dbesc($v), dbesc($hash), intval($channel['channel_id']) ); } } else { dbesc_array($app); $r = dbq("INSERT INTO app (`" . implode("`, `", array_keys($app)) . "`) VALUES ('" . implode("', '", array_values($app)) . "')" ); } } } } 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)) . "')" ); } } } } function import_items($channel,$items) { if($channel && $items) { foreach($items as $i) { $item = get_item_elements($i); if(! $item) continue; $r = q("select id, edited from item where mid = '%s' and uid = %d limit 1", dbesc($item['mid']), intval($channel['channel_id']) ); if($r) { if($item['edited'] > $r[0]['edited']) { $item['id'] = $r[0]['id']; $item['uid'] = $channel['channel_id']; item_store_update($item); continue; } } else { $item['aid'] = $channel['channel_account_id']; $item['uid'] = $channel['channel_id']; $item_result = item_store($item); } } } } function sync_items($channel,$items) { import_items($channel,$items); } function import_item_ids($channel,$itemids) { if($channel && $itemids) { foreach($itemids as $i) { $r = q("select id from item where mid = '%s' and uid = %d limit 1", dbesc($i['mid']), intval($channel['channel_id']) ); if(! $r) continue; $z = q("select * from item_id where service = '%s' and sid = '%s' and iid = %d and uid = %d limit 1", dbesc($i['service']), dbesc($i['sid']), intval($r[0]['id']), intval($channel['channel_id']) ); if(! $z) { q("insert into item_id (iid,uid,sid,service) values(%d,%d,'%s','%s')", intval($r[0]['id']), intval($channel['channel_id']), dbesc($i['sid']), dbesc($i['service']) ); } } } } function import_events($channel,$events) { if($channel && $events) { foreach($events as $event) { unset($event['id']); $event['aid'] = $channel['channel_account_id']; $event['uid'] = $channel['channel_id']; dbesc_array($event); $r = dbq("INSERT INTO event (`" . implode("`, `", array_keys($event)) . "`) VALUES ('" . implode("', '", array_values($event)) . "')" ); } } } function sync_events($channel,$events) { if($channel && $events) { foreach($events as $event) { if((! $event['event_hash']) || (! $event['start'])) continue; if($event['event_deleted']) { $r = q("delete from event where event_hash = '%s' and uid = %d limit 1", dbesc($event['event_hash']), intval($channel['channel_id']) ); continue; } unset($event['id']); $event['aid'] = $channel['channel_account_id']; $event['uid'] = $channel['channel_id']; $exists = false; $x = q("select * from event where event_hash = '%s' and uid = %d limit 1", dbesc($event['event_hash']), intval($channel['channel_id']) ); if($x) { if($x[0]['edited'] >= $event['edited']) continue; $exists = true; } if($exists) { foreach($event as $k => $v) { $r = q("UPDATE event SET `%s` = '%s' WHERE event_hash = '%s' AND uid = %d", dbesc($k), dbesc($v), dbesc($event['event_hash']), intval($channel['channel_id']) ); } } else { dbesc_array($event); $r = dbq("INSERT INTO event (`" . implode("`, `", array_keys($event)) . "`) VALUES ('" . implode("', '", array_values($event)) . "')" ); } } } }