From 3852b5ce7fe83cce93c0826a92c378a589bc8664 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 1 Sep 2015 17:06:58 -0700 Subject: separate objs/things from taxonomy --- mod/like.php | 13 ++++++------- mod/thing.php | 55 +++++++++++++++++++++++++++++-------------------------- 2 files changed, 35 insertions(+), 33 deletions(-) (limited to 'mod') diff --git a/mod/like.php b/mod/like.php index 0d0a1a8c2..42ff9bb8a 100755 --- a/mod/like.php +++ b/mod/like.php @@ -117,8 +117,7 @@ function like_content(&$a) { } elseif($obj_type == 'thing') { - $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' - and obj_type = %d and term_hash = '%s' limit 1", + $r = q("select * from obj where obj_type = %d and obj_obj = '%s' limit 1", intval(TERM_OBJ_THING), dbesc(argv(2)) ); @@ -146,18 +145,18 @@ function like_content(&$a) { $links = array(); $links[] = array('rel' => 'alternate', 'type' => 'text/html', - 'href' => z_root() . '/thing/' . $r[0]['term_hash']); + 'href' => z_root() . '/thing/' . $r[0]['obj_obj']); if($r[0]['imgurl']) - $links[] = array('rel' => 'photo', 'href' => $r[0]['imgurl']); + $links[] = array('rel' => 'photo', 'href' => $r[0]['obj_imgurl']); $target = json_encode(array( 'type' => $tgttype, - 'title' => $r[0]['term'], - 'id' => z_root() . '/thing/' . $r[0]['term_hash'], + 'title' => $r[0]['obj_term'], + 'id' => z_root() . '/thing/' . $r[0]['obj_obj'], 'link' => $links )); - $plink = '[zrl=' . z_root() . '/thing/' . $r[0]['term_hash'] . ']' . $r[0]['term'] . '[/zrl]'; + $plink = '[zrl=' . z_root() . '/thing/' . $r[0]['obj_obj'] . ']' . $r[0]['obj_term'] . '[/zrl]'; } diff --git a/mod/thing.php b/mod/thing.php index b4b8ad027..f673b8c43 100644 --- a/mod/thing.php +++ b/mod/thing.php @@ -66,16 +66,16 @@ function thing_init(&$a) { return; if($term_hash) { - $t = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", - intval(TERM_OBJ_THING), - dbesc($term_hash) + $t = q("select * from obj where obj_obj = '%s' and obj_channel = %d limit 1", + dbesc($term_hash), + intval(local_channel()) ); if(! $t) { notice( t('Item not found.') . EOL); return; } $orig_record = $t[0]; - if($photo != $orig_record['imgurl']) { + if($photo != $orig_record['obj_imgurl']) { $arr = import_profile_photo($photo,get_observer_hash(),true); $local_photo = $arr[0]; $local_photo_type = $arr[3]; @@ -83,10 +83,11 @@ function thing_init(&$a) { else $local_photo = $orig_record['imgurl']; - $r = q("update term set term = '%s', url = '%s', imgurl = '%s' where term_hash = '%s' and uid = %d", + $r = q("update obj set obj_term = '%s', obj_url = '%s', obj_imgurl = '%s', obj_edited = '%s' where obj_obj = '%s' and uid = %d", dbesc($name), dbesc(($url) ? $url : z_root() . '/thing/' . $term_hash), dbesc($local_photo), + dbesc(datetime_convert()), dbesc($term_hash), intval(local_channel()) ); @@ -113,10 +114,9 @@ function thing_init(&$a) { $local_photo_type = $arr[3]; } - $r = q("select * from term where uid = %d and otype = %d and type = %d and term = '%s' limit 1", + $r = q("select * from obj where obj_channel = %d and obj_type = %d and obj_term = '%s' limit 1", intval(local_channel()), intval(TERM_OBJ_THING), - intval(TERM_THING), dbesc($name) ); if(! $r) { @@ -139,14 +139,21 @@ function thing_init(&$a) { dbesc($name) ); } - $term = $r[0]; - $r = q("insert into obj ( obj_page, obj_verb, obj_type, obj_channel, obj_obj) values ('%s','%s', %d, %d, '%s') ", + $created = datetime_convert(); + $url = (($url) ? $url : z_root() . '/thing/' . $hash); + + $r = q("insert into obj ( obj_page, obj_verb, obj_type, obj_channel, obj_obj, obj_term, obj_url, obj_imgurl, obj_created, obj_edited ) values ('%s','%s', %d, %d, '%s','%s','%s','%s','%s','%s') ", dbesc($profile['profile_guid']), dbesc($verb), intval(TERM_OBJ_THING), intval(local_channel()), - dbesc($term['term_hash']) + dbesc($hash), + dbesc($name), + dbesc($url), + dbesc(($photo) ? $local_photo : ''), + dbesc($created), + dbesc($created) ); if(! $r) { @@ -155,10 +162,10 @@ function thing_init(&$a) { } info( t('Thing added')); - + if($activity) { $arr = array(); - $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $term['url'])); + $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $url)); if($local_photo) $links[] = array('rel' => 'photo', 'type' => $local_photo_type, 'href' => $local_photo); @@ -166,10 +173,10 @@ function thing_init(&$a) { $obj = json_encode(array( 'type' => $objtype, - 'id' => $term['url'], + 'id' => $url, 'link' => $links, - 'title' => $term['term'], - 'content' => $term['term'] + 'title' => $name, + 'content' => $name )); $bodyverb = str_replace('OBJ: ', '',t('OBJ: %1$s %2$s %3$s')); @@ -182,7 +189,7 @@ function thing_init(&$a) { $arr['item_thread_top'] = 1; $ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]'; - $plink = '[zrl=' . $term['url'] . ']' . $term['term'] . '[/zrl]'; + $plink = '[zrl=' . $url . ']' . $name . '[/zrl]'; $arr['body'] = sprintf( $bodyverb, $ulink, $translated_verb, $plink ); @@ -218,7 +225,7 @@ function thing_content(&$a) { if(argc() == 2) { - $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", + $r = q("select * from obj where obj_type = %d and obj_obj = '%s' limit 1", intval(TERM_OBJ_THING), dbesc(argv(1)) ); @@ -249,7 +256,7 @@ function thing_content(&$a) { if(argc() == 3 && argv(1) === 'edit') { $thing_hash = argv(2); - $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", + $r = q("select * from obj where obj_type = %d and obj_obj = '%s' limit 1", intval(TERM_OBJ_THING), dbesc($thing_hash) ); @@ -269,11 +276,11 @@ function thing_content(&$a) { '$activity' => array('activity',t('Post an activity'),true,t('Only sends to viewers of the applicable profile')), '$thing_hash' => $thing_hash, '$thing_lbl' => t('Name of thing e.g. something'), - '$thething' => $r[0]['term'], + '$thething' => $r[0]['obj_term'], '$url_lbl' => t('URL of thing (optional)'), - '$theurl' => $r[0]['url'], + '$theurl' => $r[0]['obj_url'], '$img_lbl' => t('URL for photo of thing (optional)'), - '$imgurl' => $r[0]['imgurl'], + '$imgurl' => $r[0]['obj_imgurl'], '$submit' => t('Submit') )); @@ -283,7 +290,7 @@ function thing_content(&$a) { if(argc() == 3 && argv(1) === 'drop') { $thing_hash = argv(2); - $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", + $r = q("select * from obj where obj_type = %d and obj_obj = '%s' limit 1", intval(TERM_OBJ_THING), dbesc($thing_hash) ); @@ -298,10 +305,6 @@ function thing_content(&$a) { intval(TERM_OBJ_THING), intval(local_channel()) ); - $x = q("delete from term where term_hash = '%s' and uid = %d", - dbesc($thing_hash), - intval(local_channel()) - ); return $o; } -- cgit v1.2.3 From 286be43963dd742ff8f87690df7546875f769701 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 1 Sep 2015 17:16:10 -0700 Subject: issue #31 --- mod/item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod') diff --git a/mod/item.php b/mod/item.php index ec5d1b3a1..c93560771 100644 --- a/mod/item.php +++ b/mod/item.php @@ -318,7 +318,7 @@ function item_post(&$a) { $private = 0; // webpages are allowed to change ACLs after the fact. Normal conversation items aren't. if($webpage) { - $acl->set_from_arry($_REQUEST); + $acl->set_from_array($_REQUEST); } else { $acl->set($orig_post); -- cgit v1.2.3 From 85daf26eb1f12a5fd7f2782b0cd4c9cd6f2c0cb5 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 1 Sep 2015 19:01:19 -0700 Subject: more work on objs/things --- mod/thing.php | 56 ++++++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) (limited to 'mod') diff --git a/mod/thing.php b/mod/thing.php index f673b8c43..ed0f97efa 100644 --- a/mod/thing.php +++ b/mod/thing.php @@ -61,10 +61,24 @@ function thing_init(&$a) { * Future work on this module might produce more complex activities with targets, e.g. Phillip likes Karen's moustache * and to describe other non-thing objects like channels, such as Karl wants Susan - where Susan represents a channel profile. */ + + /** @FIXME add and fix ACL support to the input forms */ + if((! $name) || (! $translated_verb)) return; + $acl = new AccessList($channel); + + if(array_key_exists('contact_allow',$_REQUEST) + || array_key_exists('group_allow',$_REQUEST) + || array_key_exists('contact_deny',$_REQUEST) + || array_key_exists('group_deny',$_REQUEST)) { + $acl->set_from_array($_REQUEST); + } + + $x = $acl->get(); + if($term_hash) { $t = q("select * from obj where obj_obj = '%s' and obj_channel = %d limit 1", dbesc($term_hash), @@ -81,13 +95,17 @@ function thing_init(&$a) { $local_photo_type = $arr[3]; } else - $local_photo = $orig_record['imgurl']; + $local_photo = $orig_record['obj_imgurl']; - $r = q("update obj set obj_term = '%s', obj_url = '%s', obj_imgurl = '%s', obj_edited = '%s' where obj_obj = '%s' and uid = %d", + $r = q("update obj set obj_term = '%s', obj_url = '%s', obj_imgurl = '%s', obj_edited = '%s', allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' where obj_obj = '%s' and obj_channel = %d ", dbesc($name), dbesc(($url) ? $url : z_root() . '/thing/' . $term_hash), dbesc($local_photo), dbesc(datetime_convert()), + dbesc($x['allow_cid']), + dbesc($x['allow_gid']), + dbesc($x['deny_cid']), + dbesc($x['deny_gid']), dbesc($term_hash), intval(local_channel()) ); @@ -114,36 +132,10 @@ function thing_init(&$a) { $local_photo_type = $arr[3]; } - $r = q("select * from obj where obj_channel = %d and obj_type = %d and obj_term = '%s' limit 1", - intval(local_channel()), - intval(TERM_OBJ_THING), - dbesc($name) - ); - if(! $r) { - $r = q("insert into term ( aid, uid, oid, otype, type, term, url, imgurl, term_hash ) - values( %d, %d, %d, %d, %d, '%s', '%s', '%s', '%s' ) ", - intval($account_id), - intval(local_channel()), - 0, - intval(TERM_OBJ_THING), - intval(TERM_THING), - dbesc($name), - dbesc(($url) ? $url : z_root() . '/thing/' . $hash), - dbesc(($photo) ? $local_photo : ''), - dbesc($hash) - ); - $r = q("select * from term where uid = %d and otype = %d and type = %d and term = '%s' limit 1", - intval(local_channel()), - intval(TERM_OBJ_THING), - intval(TERM_THING), - dbesc($name) - ); - } - $created = datetime_convert(); $url = (($url) ? $url : z_root() . '/thing/' . $hash); - $r = q("insert into obj ( obj_page, obj_verb, obj_type, obj_channel, obj_obj, obj_term, obj_url, obj_imgurl, obj_created, obj_edited ) values ('%s','%s', %d, %d, '%s','%s','%s','%s','%s','%s') ", + $r = q("insert into obj ( obj_page, obj_verb, obj_type, obj_channel, obj_obj, obj_term, obj_url, obj_imgurl, obj_created, obj_edited, allow_cid, allow_gid, deny_cid, deny_gid ) values ('%s','%s', %d, %d, '%s','%s','%s','%s','%s','%s','%s','%s','%s','%s') ", dbesc($profile['profile_guid']), dbesc($verb), intval(TERM_OBJ_THING), @@ -153,7 +145,11 @@ function thing_init(&$a) { dbesc($url), dbesc(($photo) ? $local_photo : ''), dbesc($created), - dbesc($created) + dbesc($created), + dbesc($x['allow_cid']), + dbesc($x['allow_gid']), + dbesc($x['deny_cid']), + dbesc($x['deny_gid']) ); if(! $r) { -- cgit v1.2.3 From 1ce8ce896b39e4131fdb67ce4505959638c523a5 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 1 Sep 2015 19:27:41 -0700 Subject: provide consistent ui for things --- mod/thing.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'mod') diff --git a/mod/thing.php b/mod/thing.php index ed0f97efa..78fbf396c 100644 --- a/mod/thing.php +++ b/mod/thing.php @@ -5,8 +5,9 @@ */ require_once('include/items.php'); +require_once('include/security.php'); require_once('include/contact_selectors.php'); - +require_once('include/acl_selectors.php'); function thing_init(&$a) { @@ -61,9 +62,6 @@ function thing_init(&$a) { * Future work on this module might produce more complex activities with targets, e.g. Phillip likes Karen's moustache * and to describe other non-thing objects like channels, such as Karl wants Susan - where Susan represents a channel profile. */ - - /** @FIXME add and fix ACL support to the input forms */ - if((! $name) || (! $translated_verb)) return; @@ -221,7 +219,9 @@ function thing_content(&$a) { if(argc() == 2) { - $r = q("select * from obj where obj_type = %d and obj_obj = '%s' limit 1", + $sql_extra = permissions_sql(); + + $r = q("select * from obj where obj_type = %d and obj_obj = '%s' $sql_extra limit 1", intval(TERM_OBJ_THING), dbesc(argv(1)) ); @@ -247,6 +247,11 @@ function thing_content(&$a) { return; } + $acl = new AccessList($channel); + $channel_acl = $acl->get(); + + $lockstate = (($acl->is_private()) ? 'lock' : 'unlock'); + $thing_hash = ''; if(argc() == 3 && argv(1) === 'edit') { @@ -277,6 +282,9 @@ function thing_content(&$a) { '$theurl' => $r[0]['obj_url'], '$img_lbl' => t('URL for photo of thing (optional)'), '$imgurl' => $r[0]['obj_imgurl'], + '$permissions' => t('Permissions'), + '$aclselect' => populate_acl($channel_acl,false), + '$lockstate' => $lockstate, '$submit' => t('Submit') )); @@ -316,6 +324,9 @@ function thing_content(&$a) { '$thing_lbl' => t('Name of thing e.g. something'), '$url_lbl' => t('URL of thing (optional)'), '$img_lbl' => t('URL for photo of thing (optional)'), + '$permissions' => t('Permissions'), + '$aclselect' => populate_acl($channel_acl,false), + '$lockstate' => $lockstate, '$submit' => t('Submit') )); -- cgit v1.2.3 From 6cc60ba477c1634b2ba6d78495d35cbf306988e1 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 1 Sep 2015 22:03:10 -0700 Subject: initial work on obj import, rename import_profile_photo to import_xchan_photo to more accurately state its purpose. --- mod/import.php | 45 +++++++++++++++++++++++++++++---------------- mod/openid.php | 2 +- mod/thing.php | 4 ++-- 3 files changed, 32 insertions(+), 19 deletions(-) (limited to 'mod') diff --git a/mod/import.php b/mod/import.php index 0c5ec2a4c..e8e4f7a3d 100644 --- a/mod/import.php +++ b/mod/import.php @@ -422,7 +422,7 @@ function import_post(&$a) { require_once('include/photo/photo_driver.php'); - $photos = import_profile_photo($xchan['xchan_photo_l'],$xchan['xchan_hash']); + $photos = import_xchan_photo($xchan['xchan_photo_l'],$xchan['xchan_hash']); if($photos[4]) $photodate = NULL_DATE; else @@ -556,22 +556,35 @@ function import_post(&$a) { ref_session_write(session_id(), serialize($_SESSION)); } + $objs = $data['obj']; + if($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'],get_observer_hash(),true); + $obj['obj_imgurl'] = $x[0]; + } -// This needs more work - we also need the term where otype = 6 to link with this, and the terms need to be relocated. -// $objs = $data['obj']; -// if($objs) { -// foreach($objs as $obj) { -// unset($obj['obj_id']); -// $obj['channel'] = $channel['channel_id']; - -// dbesc_array($obj); -// $r = dbq("INSERT INTO obj (`" -// . implode("`, `", array_keys($obj)) -// . "`) VALUES ('" -// . implode("', '", array_values($obj)) -// . "')" ); -// } -// } + dbesc_array($obj); + $r = dbq("INSERT INTO obj (`" + . implode("`, `", array_keys($obj)) + . "`) VALUES ('" + . implode("', '", array_values($obj)) + . "')" ); + } + } $saved_notification_flags = notifications_off($channel['channel_id']); diff --git a/mod/openid.php b/mod/openid.php index 70da2690a..b9ca672a9 100644 --- a/mod/openid.php +++ b/mod/openid.php @@ -155,7 +155,7 @@ function openid_content(&$a) { ); if($r) { - $photos = import_profile_photo($pphoto,$url); + $photos = import_xchan_photo($pphoto,$url); if($photos) { $z = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", diff --git a/mod/thing.php b/mod/thing.php index 78fbf396c..86712d9eb 100644 --- a/mod/thing.php +++ b/mod/thing.php @@ -88,7 +88,7 @@ function thing_init(&$a) { } $orig_record = $t[0]; if($photo != $orig_record['obj_imgurl']) { - $arr = import_profile_photo($photo,get_observer_hash(),true); + $arr = import_xchan_photo($photo,get_observer_hash(),true); $local_photo = $arr[0]; $local_photo_type = $arr[3]; } @@ -125,7 +125,7 @@ function thing_init(&$a) { $local_photo = null; if($photo) { - $arr = import_profile_photo($photo,get_observer_hash(),true); + $arr = import_xchan_photo($photo,get_observer_hash(),true); $local_photo = $arr[0]; $local_photo_type = $arr[3]; } -- cgit v1.2.3 From d105f324afefa138683094a05b056dd25122a76a Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 1 Sep 2015 22:27:09 -0700 Subject: import apps --- mod/import.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'mod') diff --git a/mod/import.php b/mod/import.php index e8e4f7a3d..0472abfcd 100644 --- a/mod/import.php +++ b/mod/import.php @@ -586,6 +586,29 @@ function import_post(&$a) { } } + $apps = $data['app']; + if($app) { + 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'],get_observer_hash(),true); + $app['app_photo'] = $x[0]; + } + + dbesc_array($app); + $r = dbq("INSERT INTO app (`" + . implode("`, `", array_keys($obj)) + . "`) VALUES ('" + . implode("', '", array_values($obj)) + . "')" ); + } + } + $saved_notification_flags = notifications_off($channel['channel_id']); -- cgit v1.2.3 From c22da3da1c5d3c5418cb9f142883adb838db9f76 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 2 Sep 2015 20:12:40 -0700 Subject: start to modularise the clone import and sync functions --- mod/import.php | 234 ++++++++------------------------------------------------- mod/thing.php | 21 ++++++ 2 files changed, 51 insertions(+), 204 deletions(-) (limited to 'mod') diff --git a/mod/import.php b/mod/import.php index 0472abfcd..c2ed82a0a 100644 --- a/mod/import.php +++ b/mod/import.php @@ -6,6 +6,8 @@ require_once('include/Contact.php'); require_once('include/zot.php'); require_once('include/identity.php'); +require_once('include/import.php'); + function import_post(&$a) { @@ -118,118 +120,41 @@ function import_post(&$a) { // import channel if(array_key_exists('channel',$data)) { - $channel = $data['channel']; if($completed < 1) { + $channel = import_channel($data['channel']); - if(! array_key_exists('channel_system',$channel)) { - $channel['channel_system'] = (($channel['channel_pageflags'] & 0x1000) ? 1 : 0); - $channel['channel_removed'] = (($channel['channel_pageflags'] & 0x8000) ? 1 : 0); - } - - $r = q("select * from channel where (channel_guid = '%s' or channel_hash = '%s' or channel_address = '%s' ) limit 1", - dbesc($channel['channel_guid']), - dbesc($channel['channel_hash']), - dbesc($channel['channel_address']) - ); - - // We should probably also verify the hash - - if($r) { - if($r[0]['channel_guid'] === $channel['channel_guid'] || $r[0]['channel_hash'] === $channel['channel_hash']) { - logger('mod_import: duplicate channel. ', print_r($channel,true)); - notice( t('Cannot create a duplicate channel identifier on this system. Import failed.') . EOL); - return; - } - else { - // try at most ten times to generate a unique address. - $x = 0; - $found_unique = false; - do { - $tmp = $channel['channel_address'] . mt_rand(1000,9999); - $r = q("select * from channel where channel_address = '%s' limit 1", - dbesc($tmp) - ); - if(! $r) { - $channel['channel_address'] = $tmp; - $found_unique = true; - break; - } - $x ++; - } while ($x < 10); - if(! $found_unique) { - logger('mod_import: duplicate channel. randomisation failed.', print_r($channel,true)); - notice( t('Unable to create a unique channel address. Import failed.') . EOL); - return; - } - } - } - - unset($channel['channel_id']); - $channel['channel_account_id'] = get_account_id(); - $channel['channel_primary'] = (($seize) ? 1 : 0); - - dbesc_array($channel); - - $r = dbq("INSERT INTO channel (`" - . implode("`, `", array_keys($channel)) - . "`) VALUES ('" - . implode("', '", array_values($channel)) - . "')" ); - - if(! $r) { - logger('mod_import: channel clone failed. ', print_r($channel,true)); - notice( t('Channel clone failed. Import failed.') . EOL); - return; - } - + } + else { $r = q("select * from channel where channel_account_id = %d and channel_guid = '%s' limit 1", intval(get_account_id()), - $channel['channel_guid'] // Already dbesc'd + dbesc($channel['channel_guid']) ); - if(! $r) { - logger('mod_import: channel not found. ', print_r($channel,true)); - notice( t('Cloned channel not found. Import failed.') . EOL); - return; - } - // reset - $channel = $r[0]; - - set_default_login_identity(get_account_id(),$channel['channel_id'],false); - logger('import step 1'); - $_SESSION['import_step'] = 1; - ref_session_write(session_id(), serialize($_SESSION)); + if($r) + $channel = $r[0]; } - } - else { - $r = q("select * from channel where channel_account_id = %d and channel_guid = '%s' limit 1", - intval(get_account_id()), - dbesc($channel['channel_guid']) - ); - if($r) - $channel = $r[0]; - else { + if(! $channel) { logger('mod_import: channel not found. ', print_r($channel,true)); notice( t('Cloned channel not found. Import failed.') . EOL); return; } } - if($completed < 2) { + if(! $channel) + $channel = $a->get_channel(); + + if(! $channel) { + logger('mod_import: channel not found. ', print_r($channel,true)); + notice( t('No channel. Import failed.') . EOL); + return; + } - $configs = $data['config']; - if($configs) { - foreach($configs as $config) { - unset($config['id']); - $config['uid'] = $channel['channel_id']; - dbesc_array($config); - $r = dbq("INSERT INTO pconfig (`" - . implode("`, `", array_keys($config)) - . "`) VALUES ('" - . implode("', '", array_values($config)) - . "')" ); - } + + if($completed < 2) { + if(is_array($data['config'])) { + import_config($channel,$data['config']); } + logger('import step 2'); $_SESSION['import_step'] = 2; ref_session_write(session_id(), serialize($_SESSION)); @@ -244,27 +169,9 @@ function import_post(&$a) { import_channel_photo(base64url_decode($data['photo']['data']),$data['photo']['type'],get_account_id(),$channel['channel_id']); } - $profiles = $data['profile']; - if($profiles) { - foreach($profiles as $profile) { - unset($profile['id']); - $profile['aid'] = get_account_id(); - $profile['uid'] = $channel['channel_id']; - - // we are going to reset all profile photos to the original - // somebody will have to fix this later and put all the applicable photos into the export - - $profile['photo'] = z_root() . '/photo/profile/l/' . $channel['channel_id']; - $profile['thumb'] = z_root() . '/photo/profile/m/' . $channel['channel_id']; + if(is_array($data['profiles'])) + import_profiles($channel,$data['profiles']); - dbesc_array($profile); - $r = dbq("INSERT INTO profile (`" - . implode("`, `", array_keys($profile)) - . "`) VALUES ('" - . implode("', '", array_values($profile)) - . "')" ); - } - } logger('import step 3'); $_SESSION['import_step'] = 3; ref_session_write(session_id(), serialize($_SESSION)); @@ -272,43 +179,10 @@ function import_post(&$a) { if($completed < 4) { - $hublocs = $data['hubloc']; - if($hublocs) { - foreach($hublocs as $hubloc) { - $hash = make_xchan_hash($hubloc['hubloc_guid'],$hubloc['hubloc_guid_sig']); - if($hubloc['hubloc_network'] === 'zot' && $hash !== $hubloc['hubloc_hash']) { - logger('forged hubloc: ' . print_r($hubloc,true)); - continue; - } + if(is_array($data['hubloc'])) { + import_hublocs($channel,$data['hubloc'],$seize); - if(! array_key_exists('hubloc_primary',$hubloc)) { - $hubloc['hubloc_primary'] = (($hubloc['hubloc_flags'] & 0x0001) ? 1 : 0); - $hubloc['hubloc_orphancheck'] = (($hubloc['hubloc_flags'] & 0x0004) ? 1 : 0); - $hubloc['hubloc_error'] = (($hubloc['hubloc_status'] & 0x0003) ? 1 : 0); - $hubloc['hubloc_deleted'] = (($hubloc['hubloc_flags'] & 0x1000) ? 1 : 0); - } - - $arr = array( - 'guid' => $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)) - . "')" ); - } - } } logger('import step 4'); $_SESSION['import_step'] = 4; @@ -556,59 +430,11 @@ function import_post(&$a) { ref_session_write(session_id(), serialize($_SESSION)); } - $objs = $data['obj']; - if($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'],get_observer_hash(),true); - $obj['obj_imgurl'] = $x[0]; - } - - dbesc_array($obj); - $r = dbq("INSERT INTO obj (`" - . implode("`, `", array_keys($obj)) - . "`) VALUES ('" - . implode("', '", array_values($obj)) - . "')" ); - } - } - - $apps = $data['app']; - if($app) { - 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'],get_observer_hash(),true); - $app['app_photo'] = $x[0]; - } - - dbesc_array($app); - $r = dbq("INSERT INTO app (`" - . implode("`, `", array_keys($obj)) - . "`) VALUES ('" - . implode("', '", array_values($obj)) - . "')" ); - } - } + if(is_array($data['obj'])) + import_objs($channel,$data['obj']); + if(is_array($data['app'])) + import_apps($channel,$data['app']); $saved_notification_flags = notifications_off($channel['channel_id']); diff --git a/mod/thing.php b/mod/thing.php index 86712d9eb..03dc7db5b 100644 --- a/mod/thing.php +++ b/mod/thing.php @@ -109,6 +109,15 @@ function thing_init(&$a) { ); info( t('Thing updated') . EOL); + + $r = q("select * from obj where obj_channel = %d and obj_obj = '%s' limit 1", + intval(local_channel()), + dbesc($term_hash) + ); + if($r) { + build_sync_packet(0, array('obj' => $r)); + } + return; } @@ -157,6 +166,14 @@ function thing_init(&$a) { info( t('Thing added')); + $r = q("select * from obj where obj_channel = %d and obj_obj = '%s' limit 1", + intval(local_channel()), + dbesc($hash) + ); + if($r) { + build_sync_packet(0, array('obj' => $r)); + } + if($activity) { $arr = array(); $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $url)); @@ -310,6 +327,10 @@ function thing_content(&$a) { intval(local_channel()) ); + $r[0]['obj_deleted'] = 1; + + build_sync_packet(0,array('obj' => $r)); + return $o; } -- cgit v1.2.3