aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-06-21 18:18:06 -0700
committerredmatrix <git@macgirvin.com>2016-06-21 18:18:06 -0700
commit8fa26db1b32fd9ff8b61c46194439a02ccc550c8 (patch)
tree3e6d54e3e23b17709c4f5d1c94abccd106cb95ed
parent63423c8ee1f750d855c75ed67205076d21eda4f1 (diff)
downloadvolse-hubzilla-8fa26db1b32fd9ff8b61c46194439a02ccc550c8.tar.gz
volse-hubzilla-8fa26db1b32fd9ff8b61c46194439a02ccc550c8.tar.bz2
volse-hubzilla-8fa26db1b32fd9ff8b61c46194439a02ccc550c8.zip
1. provide automatic relocation of important links in items that are imported or synced to clones
2. provide framework for custom curl request bodies using custom/non-standard request methods. This was a real nightmare because curl doesn't actually let you specify a string to send as the request body (except when doing POST). You have to treat it as a file upload using a custom file handler function which provides the actual content in chunks as if it were buffered I/O.
-rw-r--r--Zotlabs/Module/Import.php6
-rw-r--r--Zotlabs/Module/Import_items.php4
-rw-r--r--Zotlabs/Module/Item.php4
-rw-r--r--Zotlabs/Module/Uexport.php2
-rw-r--r--include/channel.php8
-rw-r--r--include/import.php59
-rwxr-xr-xinclude/items.php12
-rw-r--r--include/network.php10
-rw-r--r--include/zot.php17
9 files changed, 69 insertions, 53 deletions
diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php
index 122e27e90..4a559fe95 100644
--- a/Zotlabs/Module/Import.php
+++ b/Zotlabs/Module/Import.php
@@ -131,6 +131,8 @@ class Import extends \Zotlabs\Web\Controller {
// import channel
+ $relocate = ((array_key_exists('relocate',$data)) ? $data['relocate'] : null);
+
if(array_key_exists('channel',$data)) {
if($completed < 1) {
@@ -475,7 +477,7 @@ class Import extends \Zotlabs\Web\Controller {
import_events($channel,$data['event']);
if(is_array($data['event_item']))
- import_items($channel,$data['event_item']);
+ import_items($channel,$data['event_item'],false,$relocate);
if(is_array($data['menu']))
import_menus($channel,$data['menu']);
@@ -486,7 +488,7 @@ class Import extends \Zotlabs\Web\Controller {
$saved_notification_flags = notifications_off($channel['channel_id']);
if($import_posts && array_key_exists('item',$data) && $data['item'])
- import_items($channel,$data['item']);
+ import_items($channel,$data['item'],false,$relocate);
notifications_on($channel['channel_id'],$saved_notification_flags);
diff --git a/Zotlabs/Module/Import_items.php b/Zotlabs/Module/Import_items.php
index a862836c5..07b1c620c 100644
--- a/Zotlabs/Module/Import_items.php
+++ b/Zotlabs/Module/Import_items.php
@@ -92,7 +92,7 @@ class Import_items extends \Zotlabs\Web\Controller {
if(array_key_exists('item',$data) && $data['item']) {
- import_items($channel,$data['item']);
+ import_items($channel,$data['item'],false,((array_key_exists('relocate',$data)) ? $data['relocate'] : null));
}
if(array_key_exists('item_id',$data) && $data['item_id']) {
@@ -106,7 +106,7 @@ class Import_items extends \Zotlabs\Web\Controller {
- function get() {
+ function get() {
if(! local_channel()) {
notice( t('Permission denied') . EOL);
diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php
index 272da7971..369dd3948 100644
--- a/Zotlabs/Module/Item.php
+++ b/Zotlabs/Module/Item.php
@@ -894,8 +894,8 @@ class Item extends \Zotlabs\Web\Controller {
if($orig_post) {
$datarray['id'] = $post_id;
- item_store_update($datarray,$execflag);
-
+ $x = item_store_update($datarray,$execflag);
+
if(! $parent) {
$r = q("select * from item where id = %d",
intval($post_id)
diff --git a/Zotlabs/Module/Uexport.php b/Zotlabs/Module/Uexport.php
index d48f96d76..f36d77174 100644
--- a/Zotlabs/Module/Uexport.php
+++ b/Zotlabs/Module/Uexport.php
@@ -44,7 +44,7 @@ class Uexport extends \Zotlabs\Web\Controller {
}
}
- function get() {
+ function get() {
$y = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
diff --git a/include/channel.php b/include/channel.php
index 90dfb2bf6..fdb6788be 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -496,8 +496,10 @@ function identity_basic_export($channel_id, $items = false) {
$r = q("select * from channel where channel_id = %d limit 1",
intval($channel_id)
);
- if($r)
+ if($r) {
$ret['channel'] = $r[0];
+ $ret['relocate'] = [ 'channel_address' => $r[0]['channel_address'], 'url' => z_root()];
+ }
$r = q("select * from profile where uid = %d",
intval($channel_id)
@@ -717,6 +719,10 @@ function identity_export_year($channel_id,$year,$month = 0) {
$ret = array();
+ $ch = channelx_by_n($channel_id);
+ if($ch) {
+ $ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()];
+ }
$mindate = datetime_convert('UTC','UTC',$year . '-' . $target_month . '-01 00:00:00');
if($month && $month < 12)
$maxdate = datetime_convert('UTC','UTC',$year . '-' . $target_month_plus . '-01 00:00:00');
diff --git a/include/import.php b/include/import.php
index 0f52f3ff8..982eeb138 100644
--- a/include/import.php
+++ b/include/import.php
@@ -553,7 +553,7 @@ function sync_chatrooms($channel,$chatrooms) {
-function import_items($channel,$items,$sync = false) {
+function import_items($channel,$items,$sync = false,$relocate = null) {
if($channel && $items) {
$allow_code = false;
@@ -584,13 +584,6 @@ function import_items($channel,$items,$sync = false) {
$item['id'] = $r[0]['id'];
$item['uid'] = $channel['channel_id'];
$item_result = item_store_update($item,$allow_code,$deliver);
- if($sync && $item['item_wall']) {
- // deliver singletons if we have any
- if($item_result && $item_result['success']) {
- Zotlabs\Daemon\Master::Summon(array('Notifier','single_activity',$item_result['item_id']));
- }
- }
- continue;
}
}
else {
@@ -598,19 +591,37 @@ function import_items($channel,$items,$sync = false) {
$item['uid'] = $channel['channel_id'];
$item_result = item_store($item,$allow_code,$deliver);
}
+
if($sync && $item['item_wall']) {
// deliver singletons if we have any
if($item_result && $item_result['success']) {
Zotlabs\Daemon\Master::Summon(array('Notifier','single_activity',$item_result['item_id']));
}
}
+ if($relocate && $item_result['item_id']) {
+ $item = $item_result['item'];
+ if($item['mid'] === $item['parent_mid']) {
+ item_url_replace($channel,$item,$relocate['url'],z_root(),$relocate['channel_address']);
+ dbesc_array($item);
+ $item_id = $item_result['item_id'];
+ unset($item['id']);
+ $str = '';
+ foreach($item as $k => $v) {
+ if($str)
+ $str .= ",";
+ $str .= " `" . $k . "` = '" . $v . "' ";
+ }
+
+ $r = dbq("update `item` set " . $str . " where id = " . $item_id );
+ }
+ }
}
}
}
-function sync_items($channel,$items) {
- import_items($channel,$items,true);
+function sync_items($channel,$items,$relocate = null) {
+ import_items($channel,$items,true,$relocate);
}
@@ -1200,31 +1211,9 @@ function sync_files($channel,$files) {
}
}
if($f['item']) {
- sync_items($channel,$f['item']);
- foreach($f['item'] as $i) {
- if($i['message_id'] !== $i['message_parent'])
- continue;
- $r = q("select * from item where mid = '%s' and uid = %d limit 1",
- dbesc($i['message_id']),
- intval($channel['channel_id'])
- );
- if($r) {
- $item = $r[0];
- item_url_replace($channel,$item,$oldbase,z_root(),$original_channel);
-
- dbesc_array($item);
- $item_id = $item['id'];
- unset($item['id']);
- $str = '';
- foreach($item as $k => $v) {
- if($str)
- $str .= ",";
- $str .= " `" . $k . "` = '" . $v . "' ";
- }
-
- $r = dbq("update `item` set " . $str . " where id = " . $item_id );
- }
- }
+ sync_items($channel,$f['item'],
+ ['channel_address' => $original_channel,'url' => $oldbase]
+ );
}
}
}
diff --git a/include/items.php b/include/items.php
index a844cd1f6..84683273d 100755
--- a/include/items.php
+++ b/include/items.php
@@ -1889,6 +1889,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
}
+ $ret['item'] = $arr;
call_hooks('post_remote_end',$arr);
@@ -2139,6 +2140,15 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) {
return $ret;
}
+ // fetch an unescaped complete copy of the stored item
+
+ $r = q("select * from item where id = %d",
+ intval($orig_post_id)
+ );
+ if($r)
+ $arr = $r[0];
+
+
$r = q("delete from term where oid = %d and otype = %d",
intval($orig_post_id),
intval(TERM_OBJ_POST)
@@ -2170,6 +2180,8 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) {
$arr['iconfig'] = $meta;
}
+ $ret['item'] = $arr;
+
call_hooks('post_remote_update_end',$arr);
if($deliver) {
diff --git a/include/network.php b/include/network.php
index 41d13a40e..91dac936e 100644
--- a/include/network.php
+++ b/include/network.php
@@ -62,7 +62,17 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) {
@curl_setopt($ch, CURLOPT_HEADER, $false);
}
+ if(x($opts,'upload'))
+ @curl_setopt($ch, CURLOPT_UPLOAD, $opts['upload']);
+
+ if(x($opts,'infile'))
+ @curl_setopt($ch, CURLOPT_INFILE, $opts['infile']);
+
+ if(x($opts,'infilesize'))
+ @curl_setopt($ch, CURLOPT_INFILESIZE, $opts['infilesize']);
+ if(x($opts,'readfunc'))
+ @curl_setopt($ch, CURLOPT_READFUNCTION, $opts['readfunc']);
if(x($opts,'headers'))
@curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']);
diff --git a/include/zot.php b/include/zot.php
index 043139e2f..2530e55bb 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -3031,7 +3031,8 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) {
$info = (($packet) ? $packet : array());
$info['type'] = 'channel_sync';
- $info['encoding'] = 'red'; // note: not zot, this packet is very red specific
+ $info['encoding'] = 'red'; // note: not zot, this packet is very platform specific
+ $info['relocate'] = ['channel_address' => $channel['channel_address'], 'url' => z_root() ];
if(array_key_exists($uid,App::$config) && array_key_exists('transient',App::$config[$uid])) {
$settings = App::$config[$uid]['transient'];
@@ -3169,10 +3170,13 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
sync_events($channel,$arr['event']);
if(array_key_exists('event_item',$arr) && $arr['event_item'])
- sync_items($channel,$arr['event_item']);
+ sync_items($channel,$arr['event_item'],((array_key_exists('relocate',$arr)) ? $arr['relocate'] : null));
if(array_key_exists('item',$arr) && $arr['item'])
- sync_items($channel,$arr['item']);
+ sync_items($channel,$arr['item'],((array_key_exists('relocate',$arr)) ? $arr['relocate'] : null));
+
+ // deprecated, maintaining for a few months for upward compatibility
+ // this should sync webpages, but the logic is a bit subtle
if(array_key_exists('item_id',$arr) && $arr['item_id'])
sync_items($channel,$arr['item_id']);
@@ -3529,13 +3533,6 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
}
}
-
- if(array_key_exists('item',$arr) && $arr['item'])
- sync_items($channel,$arr['item']);
-
- if(array_key_exists('item_id',$arr) && $arr['item_id'])
- sync_items($channel,$arr['item_id']);
-
$addon = array('channel' => $channel,'data' => $arr);
call_hooks('process_channel_sync_delivery',$addon);