aboutsummaryrefslogtreecommitdiffstats
path: root/mod
diff options
context:
space:
mode:
authorHaakon Meland Eriksen <haakon.eriksen@far.no>2015-09-03 18:12:02 +0200
committerHaakon Meland Eriksen <haakon.eriksen@far.no>2015-09-03 18:12:02 +0200
commitadfc748bfa724ad8cc9d4ebf6f9d095fc56fb936 (patch)
tree2d5e256b6bb001397939debad609789367745fc9 /mod
parent2ce1e3678acd59409f1013433db99df6624c2895 (diff)
parentf3cb17ac3b007afd2dc5bf7cdad8a054b4d7fcd8 (diff)
downloadvolse-hubzilla-adfc748bfa724ad8cc9d4ebf6f9d095fc56fb936.tar.gz
volse-hubzilla-adfc748bfa724ad8cc9d4ebf6f9d095fc56fb936.tar.bz2
volse-hubzilla-adfc748bfa724ad8cc9d4ebf6f9d095fc56fb936.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'mod')
-rw-r--r--mod/import.php200
-rw-r--r--mod/item.php2
-rwxr-xr-xmod/like.php13
-rw-r--r--mod/openid.php2
-rw-r--r--mod/thing.php137
5 files changed, 123 insertions, 231 deletions
diff --git a/mod/import.php b/mod/import.php
index 0c5ec2a4c..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;
@@ -422,7 +296,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,23 +430,11 @@ function import_post(&$a) {
ref_session_write(session_id(), serialize($_SESSION));
}
+ if(is_array($data['obj']))
+ import_objs($channel,$data['obj']);
-// 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))
-// . "')" );
-// }
-// }
-
+ if(is_array($data['app']))
+ import_apps($channel,$data['app']);
$saved_notification_flags = notifications_off($channel['channel_id']);
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);
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/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 b4b8ad027..03dc7db5b 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) {
@@ -65,33 +66,58 @@ function thing_init(&$a) {
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 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']) {
- $arr = import_profile_photo($photo,get_observer_hash(),true);
+ if($photo != $orig_record['obj_imgurl']) {
+ $arr = import_xchan_photo($photo,get_observer_hash(),true);
$local_photo = $arr[0];
$local_photo_type = $arr[3];
}
else
- $local_photo = $orig_record['imgurl'];
+ $local_photo = $orig_record['obj_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', 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())
);
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;
}
@@ -108,45 +134,29 @@ 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];
}
- $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)
- );
- 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)
- );
- }
- $term = $r[0];
+ $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) values ('%s','%s', %d, %d, '%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),
intval(local_channel()),
- dbesc($term['term_hash'])
+ dbesc($hash),
+ dbesc($name),
+ dbesc($url),
+ dbesc(($photo) ? $local_photo : ''),
+ dbesc($created),
+ dbesc($created),
+ dbesc($x['allow_cid']),
+ dbesc($x['allow_gid']),
+ dbesc($x['deny_cid']),
+ dbesc($x['deny_gid'])
);
if(! $r) {
@@ -155,10 +165,18 @@ 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' => $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 +184,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 +200,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 +236,9 @@ 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",
+ $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))
);
@@ -244,12 +264,17 @@ 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') {
$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 +294,14 @@ 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'],
+ '$permissions' => t('Permissions'),
+ '$aclselect' => populate_acl($channel_acl,false),
+ '$lockstate' => $lockstate,
'$submit' => t('Submit')
));
@@ -283,7 +311,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 +326,10 @@ 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())
- );
+
+ $r[0]['obj_deleted'] = 1;
+
+ build_sync_packet(0,array('obj' => $r));
return $o;
}
@@ -317,6 +345,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')
));