From 4eb8921635add33215bffc4820f95c34b902f819 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 21 Sep 2021 11:07:23 +0200 Subject: improve item_url_replace() - fixes #1507 --- include/text.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index 2d863c5ae..7e1dd13c4 100644 --- a/include/text.php +++ b/include/text.php @@ -3216,38 +3216,46 @@ function item_url_replace($channel,&$item,$old,$new,$oldnick = '') { if($item['attach']) { json_url_replace($old,$new,$item['attach']); - if($oldnick) + if($oldnick && ($oldnick !== $channel['channel_address'])) json_url_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['attach']); } if($item['object']) { json_url_replace($old,$new,$item['object']); - if($oldnick) + if($oldnick && ($oldnick !== $channel['channel_address'])) json_url_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['object']); } if($item['target']) { json_url_replace($old,$new,$item['target']); - if($oldnick) + if($oldnick && ($oldnick !== $channel['channel_address'])) json_url_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['target']); } - $item['body'] = preg_replace("/(\[zrl=".preg_quote($old,'/')."\/(photo|photos|gallery)\/".$channel['channel_address'].".+\]\[zmg=\d+x\d+\])".preg_quote($old,'/')."\/(.+\[\/zmg\])/", '${1}'.$new.'/${3}', $item['body']); - $item['body'] = preg_replace("/".preg_quote($old,'/')."\/(search|\w+\/".$channel['channel_address'].")/", $new.'/${1}', $item['body']); + $root_replaced = null; + $nick_replaced = null; - $item['sig'] = base64url_encode(Crypto::sign($item['body'],$channel['channel_prvkey'])); - $item['item_verified'] = 1; + $item['body'] = str_replace($old, $new, $item['body'], $root_replaced); + + if($oldnick && ($oldnick !== $channel['channel_address'])) { + $item['body'] = str_replace('/' . $oldnick . '/', '/' . $channel['channel_address'] . '/', $item['body'], $nick_replaced); + } + + if ($root_replaced || $nick_replaced) { + $item['sig'] = Libzot::sign($item['body'], $channel['channel_prvkey']); + $item['item_verified'] = 1; + } $item['plink'] = str_replace($old,$new,$item['plink']); - if($oldnick) + if($oldnick && ($oldnick !== $channel['channel_address'])) $item['plink'] = str_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['plink']); $item['llink'] = str_replace($old,$new,$item['llink']); - if($oldnick) + if($oldnick && ($oldnick !== $channel['channel_address'])) $item['llink'] = str_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['llink']); if($item['term']) { for($x = 0; $x < count($item['term']); $x ++) { $item['term'][$x]['url'] = str_replace($old,$new,$item['term'][$x]['url']); - if ($oldnick) { + if ($oldnick && ($oldnick !== $channel['channel_address'])) { $item['term'][$x]['url'] = str_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['term'][$x]['url']); } } -- cgit v1.2.3 From e0600b241a8a1bd5f1296bb0dcd5ae12b6cff701 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 23 Sep 2021 12:45:55 +0000 Subject: make sure we do not mix up likes on direct messages and commments on direct messages in notices --- include/items.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index f451358f8..5e162738c 100644 --- a/include/items.php +++ b/include/items.php @@ -2423,9 +2423,14 @@ function send_status_notifications($post_id,$item) { $unfollowed = false; $parent = 0; + $is_reaction = false; + + $type = ((intval($item['item_private']) === 2) ? NOTIFY_MAIL : NOTIFY_COMMENT); if(array_key_exists('verb',$item) && (activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE))) { + $type = NOTIFY_LIKE; + $r = q("select id from item where mid = '%s' and uid = %d limit 1", dbesc($item['thr_parent']), intval($item['uid']) @@ -2494,7 +2499,7 @@ function send_status_notifications($post_id,$item) { Enotify::submit(array( - 'type' => ((intval($item['item_private']) === 2) ? NOTIFY_MAIL : NOTIFY_COMMENT), + 'type' => $type, 'from_xchan' => $item['author_xchan'], 'to_xchan' => $r[0]['channel_hash'], 'item' => $item, -- cgit v1.2.3 From dff8ef91a6e2e2b2fddb816218e15750061c4c2b Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 23 Sep 2021 21:52:27 +0200 Subject: implement the top option in items_fetch --- include/items.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index f451358f8..933d94f3c 100644 --- a/include/items.php +++ b/include/items.php @@ -4212,6 +4212,9 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C $item_uids = " item.uid = " . intval($uid) . " "; } + if($arr['top']) + $sql_options .= " and item_thread_top = 1 "; + if($arr['star']) $sql_options .= " and item_starred = 1 "; @@ -4367,7 +4370,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C if ($arr['total']) { $items = dbq("SELECT count(item.id) AS total FROM item WHERE $item_uids $item_restrict - $simple_update + $simple_update $sql_options $sql_extra $sql_nets $sql_extra3" ); if ($items) { @@ -4378,7 +4381,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C $items = dbq("SELECT item.*, item.id AS item_id FROM item WHERE $item_uids $item_restrict - $simple_update + $simple_update $sql_options $sql_extra $sql_nets $sql_extra3 ORDER BY item.received DESC $pager_sql" ); -- cgit v1.2.3 From 2688abf25a0bfc2a9e3b7537afc08a8d44f49e0c Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 29 Sep 2021 19:43:22 +0000 Subject: revise content import/export part 1 --- include/api_zot.php | 57 +++++++++++++++++++++++++++++++++++++---------------- include/channel.php | 22 +++++++++++++++------ 2 files changed, 56 insertions(+), 23 deletions(-) (limited to 'include') diff --git a/include/api_zot.php b/include/api_zot.php index 9beaaa19c..93b99c0c8 100644 --- a/include/api_zot.php +++ b/include/api_zot.php @@ -22,6 +22,8 @@ api_register_func('api/z/1.0/filedata', 'api_file_data', true); api_register_func('api/red/file/export', 'api_file_export', true); api_register_func('api/z/1.0/file/export', 'api_file_export', true); + api_register_func('api/red/file/export_page', 'api_file_export_page', true); + api_register_func('api/z/1.0/file/export_page', 'api_file_export_page', true); api_register_func('api/red/file', 'api_file_detail', true); api_register_func('api/z/1.0/file', 'api_file_detail', true); api_register_func('api/red/albums','api_albums', true); @@ -88,10 +90,6 @@ } $sections = (($_REQUEST['sections']) ? explode(',',$_REQUEST['sections']) : ''); $codebase = ((isset($_REQUEST['zap_compat']) && $_REQUEST['zap_compat']) ? true : false); - if($_REQUEST['posts']) { - $sections = get_default_export_sections(); - $sections[] = 'items'; - } json_return_and_die(identity_basic_export(api_user(),$sections,$codebase)); } @@ -104,7 +102,7 @@ $page = intval($_REQUEST['page']); $records = intval($_REQUEST['records']); if(! $records) { - $records = 50; + $records = 10; } if(! $_REQUEST['since']) $start = NULL_DATE; @@ -139,7 +137,7 @@ $_REQUEST['datequery'] = $_REQUEST['dend']; $arr = $_REQUEST; - $ret = []; + $ret = []; $i = items_fetch($arr,App::get_channel(),get_observer_hash()); if($i) { foreach($i as $iv) { @@ -202,7 +200,7 @@ } function api_attach_list($type) { - if(api_user() === false) + if(api_user() === false) return false; logger('api_user: ' . api_user()); @@ -235,7 +233,7 @@ dbesc($_REQUEST['file_id']) ); if($r) { - unset($r[0]['content']); + unset($r[0]['content']); $ret = array('attach' => $r[0]); json_return_and_die($ret); } @@ -278,7 +276,7 @@ $ptr['content'] = base64_encode($x); } } - + $ret = array('attach' => $ptr); json_return_and_die($ret); } @@ -303,6 +301,31 @@ killme(); } + function api_file_export_page($type) { + if(api_user() === false) + return false; + + $ret = []; + $codebase = ((isset($_REQUEST['zap_compat']) && $_REQUEST['zap_compat']) ? true : false); + $channel = channelx_by_n(api_user()); + $page = ((array_key_exists('page',$_REQUEST)) ? intval($_REQUEST['page']) : 0); + + $files = attach_list_files($channel['channel_id'], get_observer_hash(), '', '', '', 'created asc' ,$page, 1); + + if (!$files['success']) { + return false; + } + + foreach($files['results'] as $file) { + $ret[] = attach_export_data($channel, $file['hash'], false, $codebase); + } + + if($ret) { + json_return_and_die($ret); + } + killme(); + } + function api_file_detail($type) { if(api_user() === false) @@ -315,11 +338,11 @@ if($r) { if($r[0]['is_dir']) $r[0]['content'] = ''; - elseif(intval($r[0]['os_storage'])) + elseif(intval($r[0]['os_storage'])) $r[0]['content'] = base64_encode(file_get_contents(dbunescbin($r[0]['content']))); else $r[0]['content'] = base64_encode(dbunescbin($r[0]['content'])); - + $ret = array('attach' => $r[0]); json_return_and_die($ret); } @@ -401,7 +424,7 @@ } if($r) { - $x = q("select * from pgrp_member left join abook on abook_xchan = xchan and abook_channel = pgrp_member.uid left join xchan on pgrp_member.xchan = xchan.xchan_hash + $x = q("select * from pgrp_member left join abook on abook_xchan = xchan and abook_channel = pgrp_member.uid left join xchan on pgrp_member.xchan = xchan.xchan_hash where gid = %d", intval($r[0]['id']) ); @@ -426,7 +449,7 @@ return false; logger('api_xchan'); - if($_SERVER['REQUEST_METHOD'] === 'POST') { + if($_SERVER['REQUEST_METHOD'] === 'POST') { $r = xchan_store($_REQUEST); } $r = xchan_fetch($_REQUEST); @@ -497,7 +520,7 @@ } } } - + json_return_and_die($x); } @@ -528,7 +551,7 @@ } $mod = new Zotlabs\Module\Item(); - $x = $mod->post(); + $x = $mod->post(); json_return_and_die($x); } @@ -564,8 +587,8 @@ foreach($i as $ii) { $tmp[] = encode_item($ii,true); } - $ret['item'] = $tmp; - + $ret['item'] = $tmp; + json_return_and_die($ret); } diff --git a/include/channel.php b/include/channel.php index ed46904e7..53b781eb6 100644 --- a/include/channel.php +++ b/include/channel.php @@ -802,7 +802,6 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals /* * basic channel export */ - if(! $sections) { $sections = get_default_export_sections(); } @@ -1117,7 +1116,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals and created > %s - INTERVAL %s and resource_type = '' order by created", intval($channel_id), db_utcnow(), - db_quoteinterval('3 MONTH') + db_quoteinterval('1 MONTH') ); if($r) { $ret['item'] = array(); @@ -1239,11 +1238,11 @@ function channel_export_items_date($channel_id, $start, $finish, $zap_compat = f * * @param int $channel_id The channel ID * @param int $page - * @param int $limit (default 50) + * @param int $limit (default 10) * @return array */ -function channel_export_items_page($channel_id, $start, $finish, $page = 0, $limit = 50, $zap_compat = false) { +function channel_export_items_page($channel_id, $start, $finish, $page = 0, $limit = 10, $zap_compat = false) { if(intval($page) < 1) { $page = 0; @@ -1253,8 +1252,8 @@ function channel_export_items_page($channel_id, $start, $finish, $page = 0, $lim $limit = 1; } - if(intval($limit) > 5000) { - $limit = 5000; + if(intval($limit) > 1000) { + $limit = 1000; } if(! $start) @@ -1279,6 +1278,17 @@ function channel_export_items_page($channel_id, $start, $finish, $page = 0, $lim $ret['compatibility']['codebase'] = 'zap'; } + $r = q("select count(id) as total from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and resource_type != 'photo' and created >= '%s' and created <= '%s'", + intval(ITEM_TYPE_POST), + intval($channel_id), + dbesc($start), + dbesc($finish) + ); + + if ($r) { + $ret['items_total']= $r[0]['total']; + $ret['items_page']= $limit; + } $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and resource_type != 'photo' and created >= '%s' and created <= '%s' order by created limit %d offset %d", intval(ITEM_TYPE_POST), -- cgit v1.2.3 From 4ba47698d7d0ef6c799bd0a28045c1d1e49c76f3 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 29 Sep 2021 21:47:12 +0200 Subject: revise content import/export part 2 --- include/attach.php | 1 - include/import.php | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index ef3d6e242..067da21ae 100644 --- a/include/attach.php +++ b/include/attach.php @@ -2442,7 +2442,6 @@ function attach_export_data($channel, $resource_id, $deleted = false, $zap_compa return $ret; } - /** * @brief Strip off 'store/nickname/' from the provided path * diff --git a/include/import.php b/include/import.php index ae7b2787a..f635f3705 100644 --- a/include/import.php +++ b/include/import.php @@ -1265,6 +1265,7 @@ function sync_files($channel, $files) { $store_path = $newfname; + $fp = fopen($newfname,'w'); if(! $fp) { logger('failed to open storage file.',LOGGER_NORMAL,LOG_ERR); -- cgit v1.2.3 From 5cb5ecdb545d699eb0cbbed33797d0b4c234aadf Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 30 Sep 2021 12:09:50 +0200 Subject: implement channel purge daemon and send a notifier purge_all message if the xchan was deleted --- include/channel.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 53b781eb6..ca6d01498 100644 --- a/include/channel.php +++ b/include/channel.php @@ -2825,13 +2825,6 @@ function channel_remove($channel_id, $local = true, $unset_session = false) { } } - $r = q("select id from item where uid = %d", intval($channel_id)); - if($r) { - foreach($r as $rv) { - drop_item($rv['id'],false); - } - } - q("delete from abook where abook_xchan = '%s' and abook_self = 1 ", dbesc($channel['channel_hash']) ); @@ -2841,6 +2834,9 @@ function channel_remove($channel_id, $local = true, $unset_session = false) { intval($channel_id) ); + // remove items + Master::Summon([ 'Channel_purge', $channel_id ]); + // if this was the default channel, set another one as default if(App::$account['account_default_channel'] == $channel_id) { $r = q("select channel_id from channel where channel_account_id = %d and channel_removed = 0 limit 1", @@ -2881,6 +2877,8 @@ function channel_remove($channel_id, $local = true, $unset_session = false) { $r = q("UPDATE xchan SET xchan_deleted = 1 WHERE xchan_hash = '%s'", dbesc($channel['channel_hash']) ); + // send a cleanup message to other servers + Master::Summon([ 'Notifier', 'purge_all', $channel_id ]); } //remove from file system -- cgit v1.2.3 From 2c7c9ae2d7f3549a5ec9f7f00373fe5572c2c25d Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 30 Sep 2021 15:33:10 +0000 Subject: provide files total --- include/api_zot.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/api_zot.php b/include/api_zot.php index 93b99c0c8..7a217854f 100644 --- a/include/api_zot.php +++ b/include/api_zot.php @@ -305,24 +305,38 @@ if(api_user() === false) return false; - $ret = []; $codebase = ((isset($_REQUEST['zap_compat']) && $_REQUEST['zap_compat']) ? true : false); $channel = channelx_by_n(api_user()); $page = ((array_key_exists('page',$_REQUEST)) ? intval($_REQUEST['page']) : 0); + $ret['success'] = false; + $ret['total'] = 0; + $ret['results'] = []; + + $count = attach_count_files($channel['channel_id'], get_observer_hash()); + if($count['success']) { + $ret['total'] = $count['results']; + } + + if (!$ret['total']) { + json_return_and_die($ret); + } + $files = attach_list_files($channel['channel_id'], get_observer_hash(), '', '', '', 'created asc' ,$page, 1); if (!$files['success']) { - return false; + json_return_and_die($ret); } foreach($files['results'] as $file) { - $ret[] = attach_export_data($channel, $file['hash'], false, $codebase); + $ret['results'][] = attach_export_data($channel, $file['hash'], false, $codebase); } - if($ret) { + if($ret['results']) { + $ret['success'] = true; json_return_and_die($ret); } + killme(); } -- cgit v1.2.3 From b5cea3301d22185e7278a87176901e82419dafbb Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 2 Oct 2021 12:28:13 +0000 Subject: cleanup api_auth and make it fetch the identity if we do not have it cached yet --- include/api_auth.php | 99 +++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 43 deletions(-) (limited to 'include') diff --git a/include/api_auth.php b/include/api_auth.php index 4928e6a85..0395dae7a 100644 --- a/include/api_auth.php +++ b/include/api_auth.php @@ -1,19 +1,24 @@ db); - $server = new \Zotlabs\Identity\OAuth2Server($storage); - $request = \OAuth2\Request::createFromGlobals(); + $storage = new OAuth2Storage(DBA::$dba->db); + $server = new OAuth2Server($storage); + $request = Request::createFromGlobals(); if ($server->verifyResourceRequest($request)) { $token = $server->getAccessTokenData($request); - $uid = $token['user_id']; - $r = q("SELECT * FROM channel WHERE channel_id = %d LIMIT 1", + $uid = $token['user_id']; + $r = q("SELECT * FROM channel WHERE channel_id = %d LIMIT 1", intval($uid) ); if (count($r)) { $record = $r[0]; - } else { + } + else { header('HTTP/1.0 401 Unauthorized'); echo('This api requires login'); killme(); } - $_SESSION['uid'] = $record['channel_id']; + $_SESSION['uid'] = $record['channel_id']; $_SESSION['addr'] = $_SERVER['REMOTE_ADDR']; $x = q("select * from account where account_id = %d LIMIT 1", @@ -51,12 +57,13 @@ function api_login(&$a){ call_hooks('logged_in', App::$user); return; } - } else { + } + else { // OAuth 1.0 $oauth = new ZotOAuth1(); - $req = OAuth1Request::from_request(); + $req = OAuth1Request::from_request(); - list($consumer, $token) = $oauth->verify_request($req); + [$consumer, $token] = $oauth->verify_request($req); if (!is_null($token)) { $oauth->loginUser($token->uid); @@ -72,15 +79,14 @@ function api_login(&$a){ logger($e->getMessage()); } - - if(array_key_exists('HTTP_AUTHORIZATION',$_SERVER)) { + if (array_key_exists('HTTP_AUTHORIZATION', $_SERVER)) { /* Basic authentication */ - if (substr(trim($_SERVER['HTTP_AUTHORIZATION']),0,5) === 'Basic') { - $userpass = @base64_decode(substr(trim($_SERVER['HTTP_AUTHORIZATION']),6)) ; - if(strlen($userpass)) { - list($name, $password) = explode(':', $userpass); + if (substr(trim($_SERVER['HTTP_AUTHORIZATION']), 0, 5) === 'Basic') { + $userpass = @base64_decode(substr(trim($_SERVER['HTTP_AUTHORIZATION']), 6)); + if (strlen($userpass)) { + [$name, $password] = explode(':', $userpass); $_SERVER['PHP_AUTH_USER'] = $name; $_SERVER['PHP_AUTH_PW'] = $password; } @@ -88,34 +94,42 @@ function api_login(&$a){ /* OpenWebAuth */ - if(substr(trim($_SERVER['HTTP_AUTHORIZATION']),0,9) === 'Signature') { + if (substr(trim($_SERVER['HTTP_AUTHORIZATION']), 0, 9) === 'Signature') { $record = null; - $sigblock = \Zotlabs\Web\HTTPSig::parse_sigheader($_SERVER['HTTP_AUTHORIZATION']); - if($sigblock) { - $keyId = str_replace('acct:','',$sigblock['keyId']); - if($keyId) { - $r = q("select * from hubloc where ( hubloc_addr = '%s' or hubloc_id_url = '%s' ) limit 1", + $sigblock = HTTPSig::parse_sigheader($_SERVER['HTTP_AUTHORIZATION']); + if ($sigblock) { + $keyId = str_replace('acct:', '', $sigblock['keyId']); + if ($keyId) { + $r = q("select * from hubloc where hubloc_addr = '%s' or hubloc_id_url = '%s'", dbesc($keyId), dbesc($keyId) ); - if($r) { - $c = channelx_by_hash($r[0]['hubloc_hash']); - if($c) { + if (!$r) { + HTTPSig::get_zotfinger_key($keyId); + $r = q("select * from hubloc where hubloc_addr = '%s' or hubloc_id_url = '%s'", + dbesc($keyId), + dbesc($keyId) + ); + } + if ($r) { + $r = Libzot::zot_record_preferred($r); + $c = channelx_by_hash($r['hubloc_hash']); + if ($c) { $a = q("select * from account where account_id = %d limit 1", intval($c['channel_account_id']) ); - if($a) { - $record = [ 'channel' => $c, 'account' => $a[0] ]; + if ($a) { + $record = ['channel' => $c, 'account' => $a[0]]; $channel_login = $c['channel_id']; } } } - if($record) { - $verified = \Zotlabs\Web\HTTPSig::verify('',$record['channel']['channel_pubkey']); - if(! ($verified && $verified['header_signed'] && $verified['header_valid'])) { + if ($record) { + $verified = HTTPSig::verify('', $record['channel']['channel_pubkey']); + if (!($verified && $verified['header_signed'] && $verified['header_valid'])) { $record = null; } } @@ -129,18 +143,18 @@ function api_login(&$a){ // process normal login request - if(isset($_SERVER['PHP_AUTH_USER']) && (! $record)) { + if (isset($_SERVER['PHP_AUTH_USER']) && (!$record)) { $channel_login = 0; - $record = account_verify_password($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']); - if($record && $record['channel']) { + $record = account_verify_password($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); + if ($record && $record['channel']) { $channel_login = $record['channel']['channel_id']; } } - if($record['account']) { + if ($record['account']) { authenticate_success($record['account']); - if($channel_login) + if ($channel_login) change_channel($channel_login); $_SESSION['allow_api'] = true; @@ -148,16 +162,15 @@ function api_login(&$a){ } else { $_SERVER['PHP_AUTH_PW'] = '*****'; - logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG); + logger('API_login failure: ' . print_r($_SERVER, true), LOGGER_DEBUG); log_failed_login('API login failure'); retry_basic_auth(); } } - function retry_basic_auth($method = 'Basic') { - header('WWW-Authenticate: ' . $method . ' realm="Hubzilla"'); + header('WWW-Authenticate: ' . $method . ' realm="' . System::get_platform_name() . '"'); header('HTTP/1.0 401 Unauthorized'); echo('This api requires login'); killme(); -- cgit v1.2.3 From 4afd1ac705b7e0b8db7bbfacc5f46e0e42c9d4f1 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 3 Oct 2021 09:05:32 +0200 Subject: add optional $removed argument to channelx_by functions to allow inclusion of removed channels which is required (mod channel, daemon notifier -> refresh_all) if a channel got removed also remove caching to App so we always get a fresh copy. In import_hublocs() add site_id to the array passed to Libzot::gethubs() because it is expected there. --- include/channel.php | 48 +++++++++++++++++++++++++++--------------------- include/import.php | 3 ++- 2 files changed, 29 insertions(+), 22 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index ca6d01498..ca0c474a3 100644 --- a/include/channel.php +++ b/include/channel.php @@ -2455,23 +2455,23 @@ function get_zcard_embed($channel, $observer_hash = '', $args = array()) { * - array with channel entry * - false if no channel with $nick was found */ -function channelx_by_nick($nick) { +function channelx_by_nick($nick, $removed = false) { // If we are provided a Unicode nickname convert to IDN $nick = punify($nick); - // return a cached copy if there is a cached copy and it's a match + $sql_extra = ' AND channel_removed = 0 '; - if (App::$channel && is_array(App::$channel) && array_key_exists('channel_address',App::$channel) && App::$channel['channel_address'] === $nick) { - return App::$channel; + if ($removed) { + $sql_extra = ''; } - $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_address = '%s' and channel_removed = 0 LIMIT 1", + $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_address = '%s' $sql_extra LIMIT 1", dbesc($nick) ); - return(($r) ? $r[0] : false); + return (($r) ? $r[0] : false); } /** @@ -2480,17 +2480,19 @@ function channelx_by_nick($nick) { * @param string $hash * @return array|boolean false if channel ID not found, otherwise the channel array */ -function channelx_by_hash($hash) { +function channelx_by_hash($hash, $removed = false) { - if (App::$channel && is_array(App::$channel) && array_key_exists('channel_hash',App::$channel) && App::$channel['channel_hash'] === $hash) { - return App::$channel; + $sql_extra = ' AND channel_removed = 0 '; + + if ($removed) { + $sql_extra = ''; } - $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_hash = '%s' and channel_removed = 0 LIMIT 1", + $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_hash = '%s' $sql_extra LIMIT 1", dbesc($hash) ); - return(($r) ? $r[0] : false); + return (($r) ? $r[0] : false); } @@ -2500,17 +2502,19 @@ function channelx_by_hash($hash) { * @param string $hash * @return array|boolean false if channel ID not found, otherwise the channel array */ -function channelx_by_portid($hash) { +function channelx_by_portid($hash, $removed = false) { + + $sql_extra = ' AND channel_removed = 0 '; - if (App::$channel && is_array(App::$channel) && array_key_exists('channel_portable_id',App::$channel) && intval(App::$channel['channel_portable_id']) === intval($hash)) { - return App::$channel; + if ($removed) { + $sql_extra = ''; } - $r = q("SELECT * FROM channel left join xchan on channel_portable_id = xchan_hash WHERE channel_portable_id = '%s' and channel_removed = 0 LIMIT 1", + $r = q("SELECT * FROM channel left join xchan on channel_portable_id = xchan_hash WHERE channel_portable_id = '%s' $sql_extra LIMIT 1", dbesc($hash) ); - return(($r) ? $r[0] : false); + return (($r) ? $r[0] : false); } /** @@ -2519,17 +2523,19 @@ function channelx_by_portid($hash) { * @param int $id A channel ID * @return array|boolean false if channel ID not found, otherwise the channel array */ -function channelx_by_n($id) { +function channelx_by_n($id, $removed = false) { + + $sql_extra = ' AND channel_removed = 0 '; - if (App::$channel && is_array(App::$channel) && array_key_exists('channel_id',App::$channel) && intval(App::$channel['channel_id']) === intval($id)) { - return App::$channel; + if ($removed) { + $sql_extra = ''; } - $r = q("SELECT * FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE channel_id = %d AND channel_removed = 0 LIMIT 1", + $r = q("SELECT * FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE channel_id = %d $sql_extra = 0 LIMIT 1", intval($id) ); - return(($r) ? $r[0] : false); + return (($r) ? $r[0] : false); } /** diff --git a/include/import.php b/include/import.php index f635f3705..6e25f4154 100644 --- a/include/import.php +++ b/include/import.php @@ -238,7 +238,8 @@ function import_hublocs($channel, $hublocs, $seize, $moving = false) { 'id' => $hubloc['hubloc_guid'], 'id_sig' => $hubloc['hubloc_guid_sig'], 'location' => $hubloc['hubloc_url'], - 'location_sig' => $hubloc['hubloc_url_sig'] + 'location_sig' => $hubloc['hubloc_url_sig'], + 'site_id' => $hubloc['hubloc_site_id'] ]; if (($hubloc['hubloc_hash'] === $channel['channel_hash']) && intval($hubloc['hubloc_primary']) && ($seize)) { -- cgit v1.2.3 From 58ee147653a759d1a4e41d5978e29a66cb58384e Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 3 Oct 2021 08:20:16 +0000 Subject: fix typo --- include/channel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index ca0c474a3..2db0434ca 100644 --- a/include/channel.php +++ b/include/channel.php @@ -2531,7 +2531,7 @@ function channelx_by_n($id, $removed = false) { $sql_extra = ''; } - $r = q("SELECT * FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE channel_id = %d $sql_extra = 0 LIMIT 1", + $r = q("SELECT * FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE channel_id = %d $sql_extra LIMIT 1", intval($id) ); -- cgit v1.2.3 From d6f81e139aeb52e3068959c41d2ef6ce77e97232 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 3 Oct 2021 12:22:33 +0000 Subject: make sure to return if we have no xchan here --- include/connections.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index 59020051c..6dba06189 100644 --- a/include/connections.php +++ b/include/connections.php @@ -272,6 +272,9 @@ function mark_orphan_hubsxchans() { function remove_all_xchan_resources($xchan, $channel_id = 0) { + if(!$xchan) + return; + if(intval($channel_id)) { -- cgit v1.2.3 From 6da7fe7d27b30f691c07e5fb767afc904c3063c0 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 4 Oct 2021 09:24:13 +0000 Subject: provide system app sync --- include/import.php | 74 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 6e25f4154..3bd2af4ce 100644 --- a/include/import.php +++ b/include/import.php @@ -1,5 +1,6 @@ Date: Mon, 4 Oct 2021 13:31:26 +0200 Subject: app sync fixes - part 2 --- include/import.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 3bd2af4ce..c986eeaef 100644 --- a/include/import.php +++ b/include/import.php @@ -590,7 +590,7 @@ function import_sysapps($channel, $apps) { */ function sync_sysapps($channel, $apps) { - $sysapps = Apps::get_system_apps(false); + $sysapps = Apps::get_system_apps(false, true); if ($channel && $apps) { @@ -606,7 +606,8 @@ function sync_sysapps($channel, $apps) { } foreach ($sysapps as $sysapp) { - if ($app['app_id'] === hash('whirlpool',$sysapp['app_name'])) { + + if ($app['app_id'] === hash('whirlpool', $sysapp['name'])) { if (array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) { q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", dbesc($app['app_id']), @@ -617,13 +618,12 @@ function sync_sysapps($channel, $apps) { // install this app on this server $newapp = $sysapp; $newapp['uid'] = $channel['channel_id']; - $newapp['guid'] = hash('whirlpool',$newapp['name']); - + $newapp['guid'] = hash('whirlpool', $newapp['name']); $newapp['system'] = 1; if ($term) { - $newapp['categories'] = array_elm_to_str($term,'term'); + $newapp['categories'] = array_elm_to_str($term, 'term'); } - Apps::app_install($channel['channel_id'],$newapp); + Apps::app_install($channel['channel_id'], $newapp); } } } -- cgit v1.2.3 From 743098921220364341e5e3b194fbe0b442a4c28c Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 4 Oct 2021 13:41:54 +0200 Subject: more app sync fixes --- include/import.php | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index c986eeaef..ab44a6012 100644 --- a/include/import.php +++ b/include/import.php @@ -541,7 +541,7 @@ function import_sysapps($channel, $apps) { if ($channel && $apps) { - $sysapps = Apps::get_system_apps(false); + $sysapps = Apps::get_system_apps(false, true); foreach ($apps as $app) { @@ -549,32 +549,34 @@ function import_sysapps($channel, $apps) { continue; } - if (array_key_exists('app_deleted',$app) && (intval($app['app_deleted']))) { - continue; - } - $term = ((array_key_exists('term',$app) && is_array($app['term'])) ? $app['term'] : null); foreach ($sysapps as $sysapp) { - if ($app['app_id'] === hash('whirlpool',$sysapp['app_name'])) { + if (array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) { + q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", + dbesc($app['app_id']), + intval($channel['channel_id']) + ); + } + else { // install this app on this server $newapp = $sysapp; $newapp['uid'] = $channel['channel_id']; - $newapp['guid'] = hash('whirlpool',$newapp['name']); + $newapp['guid'] = hash('whirlpool', $newapp['name']); $installed = q("select id from app where app_id = '%s' and app_channel = %d limit 1", dbesc($newapp['guid']), intval($channel['channel_id']) ); if ($installed) { - break; + continue; } $newapp['system'] = 1; if ($term) { - $newapp['categories'] = array_elm_to_str($term,'term'); + $newapp['categories'] = array_elm_to_str($term, 'term'); } - Apps::app_install($channel['channel_id'],$newapp); + Apps::app_install($channel['channel_id'], $newapp); } } } @@ -606,7 +608,6 @@ function sync_sysapps($channel, $apps) { } foreach ($sysapps as $sysapp) { - if ($app['app_id'] === hash('whirlpool', $sysapp['name'])) { if (array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) { q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", @@ -619,6 +620,15 @@ function sync_sysapps($channel, $apps) { $newapp = $sysapp; $newapp['uid'] = $channel['channel_id']; $newapp['guid'] = hash('whirlpool', $newapp['name']); + + $installed = q("select id from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($newapp['guid']), + intval($channel['channel_id']) + ); + if ($installed) { + continue; + } + $newapp['system'] = 1; if ($term) { $newapp['categories'] = array_elm_to_str($term, 'term'); @@ -632,8 +642,6 @@ function sync_sysapps($channel, $apps) { } - - /** * @brief Import chatrooms. * -- cgit v1.2.3 From 21a6dffd5f24b0468e17e9e22fb795dff1020472 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 4 Oct 2021 13:54:45 +0200 Subject: Revert "more app sync fixes" This reverts commit 743098921220364341e5e3b194fbe0b442a4c28c. --- include/import.php | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index ab44a6012..c986eeaef 100644 --- a/include/import.php +++ b/include/import.php @@ -541,7 +541,7 @@ function import_sysapps($channel, $apps) { if ($channel && $apps) { - $sysapps = Apps::get_system_apps(false, true); + $sysapps = Apps::get_system_apps(false); foreach ($apps as $app) { @@ -549,34 +549,32 @@ function import_sysapps($channel, $apps) { continue; } + if (array_key_exists('app_deleted',$app) && (intval($app['app_deleted']))) { + continue; + } + $term = ((array_key_exists('term',$app) && is_array($app['term'])) ? $app['term'] : null); foreach ($sysapps as $sysapp) { - if (array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) { - q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", - dbesc($app['app_id']), - intval($channel['channel_id']) - ); - } - else { + if ($app['app_id'] === hash('whirlpool',$sysapp['app_name'])) { // install this app on this server $newapp = $sysapp; $newapp['uid'] = $channel['channel_id']; - $newapp['guid'] = hash('whirlpool', $newapp['name']); + $newapp['guid'] = hash('whirlpool',$newapp['name']); $installed = q("select id from app where app_id = '%s' and app_channel = %d limit 1", dbesc($newapp['guid']), intval($channel['channel_id']) ); if ($installed) { - continue; + break; } $newapp['system'] = 1; if ($term) { - $newapp['categories'] = array_elm_to_str($term, 'term'); + $newapp['categories'] = array_elm_to_str($term,'term'); } - Apps::app_install($channel['channel_id'], $newapp); + Apps::app_install($channel['channel_id'],$newapp); } } } @@ -608,6 +606,7 @@ function sync_sysapps($channel, $apps) { } foreach ($sysapps as $sysapp) { + if ($app['app_id'] === hash('whirlpool', $sysapp['name'])) { if (array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) { q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", @@ -620,15 +619,6 @@ function sync_sysapps($channel, $apps) { $newapp = $sysapp; $newapp['uid'] = $channel['channel_id']; $newapp['guid'] = hash('whirlpool', $newapp['name']); - - $installed = q("select id from app where app_id = '%s' and app_channel = %d limit 1", - dbesc($newapp['guid']), - intval($channel['channel_id']) - ); - if ($installed) { - continue; - } - $newapp['system'] = 1; if ($term) { $newapp['categories'] = array_elm_to_str($term, 'term'); @@ -642,6 +632,8 @@ function sync_sysapps($channel, $apps) { } + + /** * @brief Import chatrooms. * -- cgit v1.2.3 From c2c5730d00927a2e246a8c7e55450ea81d25a1a0 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 4 Oct 2021 14:08:39 +0200 Subject: more app sync fixes --- include/import.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index c986eeaef..88d29a46d 100644 --- a/include/import.php +++ b/include/import.php @@ -556,11 +556,11 @@ function import_sysapps($channel, $apps) { $term = ((array_key_exists('term',$app) && is_array($app['term'])) ? $app['term'] : null); foreach ($sysapps as $sysapp) { - if ($app['app_id'] === hash('whirlpool',$sysapp['app_name'])) { + if ($app['app_id'] === hash('whirlpool', $sysapp['name'])) { // install this app on this server $newapp = $sysapp; $newapp['uid'] = $channel['channel_id']; - $newapp['guid'] = hash('whirlpool',$newapp['name']); + $newapp['guid'] = hash('whirlpool', $newapp['name']); $installed = q("select id from app where app_id = '%s' and app_channel = %d limit 1", dbesc($newapp['guid']), @@ -572,9 +572,9 @@ function import_sysapps($channel, $apps) { $newapp['system'] = 1; if ($term) { - $newapp['categories'] = array_elm_to_str($term,'term'); + $newapp['categories'] = array_elm_to_str($term, 'term'); } - Apps::app_install($channel['channel_id'],$newapp); + Apps::app_install($channel['channel_id'], $newapp); } } } -- cgit v1.2.3 From 04c6d77d2cced4f2228be77107bbb85ee2f77562 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 4 Oct 2021 14:14:30 +0200 Subject: set the sync flag to true --- include/import.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 88d29a46d..b11d01511 100644 --- a/include/import.php +++ b/include/import.php @@ -541,7 +541,7 @@ function import_sysapps($channel, $apps) { if ($channel && $apps) { - $sysapps = Apps::get_system_apps(false); + $sysapps = Apps::get_system_apps(false, true); foreach ($apps as $app) { -- cgit v1.2.3 From 3a38946f8a9e08fec5406fedac2577a890c8773d Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 4 Oct 2021 20:19:16 +0200 Subject: more app sync --- include/import.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index b11d01511..6186fd6ed 100644 --- a/include/import.php +++ b/include/import.php @@ -609,10 +609,29 @@ function sync_sysapps($channel, $apps) { if ($app['app_id'] === hash('whirlpool', $sysapp['name'])) { if (array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) { - q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", - dbesc($app['app_id']), - intval($channel['channel_id']) - ); + if(Apps::can_delete($channel['channel_id'], ['guid' => $app['app_id']])) { + $local_app = q("select id from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($app['app_id']), + intval($channel['channel_id']) + ); + if ($local_app) { + q("delete from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($local_app[0]['id']) + ); + + q("delete from app where app_id = '%s' and app_channel = %d", + dbesc($app['app_id']), + intval($channel['channel_id']) + ); + } + } + else { + q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", + dbesc($app['app_id']), + intval($channel['channel_id']) + ); + } } else { // install this app on this server -- cgit v1.2.3 From c33660a015ff4a2ed387caa4064fc8c4d8655419 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 6 Oct 2021 09:36:14 +0200 Subject: move sync logic for apps to mod appman. this way we can re-use the functions without creating sync loops. --- include/import.php | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 6186fd6ed..c6d89b5f3 100644 --- a/include/import.php +++ b/include/import.php @@ -591,7 +591,6 @@ function import_sysapps($channel, $apps) { function sync_sysapps($channel, $apps) { $sysapps = Apps::get_system_apps(false, true); - if ($channel && $apps) { $columns = db_columns('app'); @@ -608,30 +607,8 @@ function sync_sysapps($channel, $apps) { foreach ($sysapps as $sysapp) { if ($app['app_id'] === hash('whirlpool', $sysapp['name'])) { - if (array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) { - if(Apps::can_delete($channel['channel_id'], ['guid' => $app['app_id']])) { - $local_app = q("select id from app where app_id = '%s' and app_channel = %d limit 1", - dbesc($app['app_id']), - intval($channel['channel_id']) - ); - if ($local_app) { - q("delete from term where otype = %d and oid = %d", - intval(TERM_OBJ_APP), - intval($local_app[0]['id']) - ); - - q("delete from app where app_id = '%s' and app_channel = %d", - dbesc($app['app_id']), - intval($channel['channel_id']) - ); - } - } - else { - q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", - dbesc($app['app_id']), - intval($channel['channel_id']) - ); - } + if (array_key_exists('app_deleted',$app) && $app['app_deleted'] == 1 && $app['app_id']) { + Apps::app_destroy($channel['channel_id'], ['guid' => $app['app_id']]); } else { // install this app on this server -- cgit v1.2.3 From 98eea41865b3488d5adf0cfa68d0d32973ca1cb5 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 6 Oct 2021 14:32:25 +0000 Subject: fix drop_query_params() if no query params are left --- include/zid.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/zid.php b/include/zid.php index 422683c95..e462f8357 100644 --- a/include/zid.php +++ b/include/zid.php @@ -142,9 +142,9 @@ function clean_query_string($s = '') { function drop_query_params($s, $p) { $parsed = parse_url($s); - $query = ''; $query_args = null; + if(isset($parsed['query'])) { parse_str($parsed['query'], $query_args); } @@ -157,8 +157,11 @@ function drop_query_params($s, $p) { } } - if($query) + unset($parsed['query']); + + if($query) { $parsed['query'] = $query; + } return unparse_url($parsed); } -- cgit v1.2.3 From f5f357060bf0ebcb0b8352519375953d993437e7 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 6 Oct 2021 14:32:49 +0000 Subject: fix alt_pager() --- include/text.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index 7e1dd13c4..1b3a77dba 100644 --- a/include/text.php +++ b/include/text.php @@ -577,11 +577,7 @@ function alt_pager($i, $more = '', $less = '') { if(! $less) $less = t('newer'); - $stripped = preg_replace('/(&page=[0-9]*)/','',App::$query_string); - $stripped = str_replace('q=','',$stripped); - $stripped = trim($stripped,'/'); - //$pagenum = App::$pager['page']; - $url = z_root() . '/' . $stripped; + $url = z_root() . '/' . drop_query_params(App::$query_string, ['page', 'q']); return replace_macros(get_markup_template('alt_pager.tpl'), array( '$has_less' => ((App::$pager['page'] > 1) ? true : false), -- cgit v1.2.3 From f19acd9f50ec9b8c78f77af64d523d2295b46052 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 Oct 2021 07:56:42 +0000 Subject: remove redundant variable and provide missing phpdoc --- include/import.php | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index c6d89b5f3..b0a1a77e5 100644 --- a/include/import.php +++ b/include/import.php @@ -597,7 +597,6 @@ function sync_sysapps($channel, $apps) { foreach ($apps as $app) { - $exists = false; $term = ((array_key_exists('term',$app)) ? $app['term'] : null); if (array_key_exists('app_system',$app) && (! intval($app['app_system']))) { -- cgit v1.2.3 From ad2c165f26625614086283d1efffcc411bc1c108 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 Oct 2021 08:10:49 +0000 Subject: bbcode: deal with codeblocks before we escape other tags --- include/bbcode.php | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 42790aaca..6a1a5a01e 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1120,26 +1120,7 @@ function bbcode($Text, $options = []) { } } - // Hide all [noparse] contained bbtags by spacefying them - if (strpos($Text,'[noparse]') !== false) { - $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text); - } - if (strpos($Text,'[nobb]') !== false) { - $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_spacefy',$Text); - } - if (strpos($Text,'[pre]') !== false) { - $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text); - } - if (strpos($Text,'[summary]') !== false) { - $Text = preg_replace_callback("/\[summary\](.*?)\[\/summary\]/ism", 'bb_spacefy',$Text); - } - if (strpos($Text,'[/img]') !== false) { - $Text = preg_replace_callback('/\[img(.*?)\[\/(img)\]/ism','\red_escape_codeblock',$Text); - } - if (strpos($Text,'[/zmg]') !== false) { - $Text = preg_replace_callback('/\[zmg(.*?)\[\/(zmg)\]/ism','\red_escape_codeblock',$Text); - } $Text = bb_format_attachdata($Text); @@ -1199,13 +1180,13 @@ function bbcode($Text, $options = []) { $Text = str_replace(array('[baseurl]','[sitename]'),array(z_root(),get_config('system','sitename')),$Text); - // Replace any html brackets with HTML Entities to prevent executing HTML or script // Don't use strip_tags here because it breaks [url] search by replacing & with amp $Text = str_replace("<", "<", $Text); $Text = str_replace(">", ">", $Text); - + $Text = preg_replace_callback("/\[table\](.*?)\[\/table\]/ism",'bb_fixtable_lf',$Text); + $Text = str_replace(array("\t", " "), array("    ", "  "), $Text); // Check for [code] text here, before the linefeeds are messed with. // The highlighter will unescape and re-escape the content. @@ -1214,10 +1195,6 @@ function bbcode($Text, $options = []) { $Text = preg_replace_callback("/\[code=(.*?)\](.*?)\[\/code\]/ism", 'bb_highlight', $Text); } - $Text = preg_replace_callback("/\[table\](.*?)\[\/table\]/ism",'bb_fixtable_lf',$Text); - - $Text = str_replace(array("\t", " "), array("    ", "  "), $Text); - // Check for [code] text if (strpos($Text,'[code]') !== false) { $Text = preg_replace_callback("/\[code\](.*?)\[\/code\]/ism", 'bb_code', $Text); @@ -1228,6 +1205,26 @@ function bbcode($Text, $options = []) { $Text = preg_replace_callback("/\[code(.*?)\](.*?)\[\/code\]/ism", 'bb_code_options', $Text); } + // Hide all [noparse] contained bbtags by spacefying them + if (strpos($Text,'[noparse]') !== false) { + $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text); + } + if (strpos($Text,'[nobb]') !== false) { + $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_spacefy',$Text); + } + if (strpos($Text,'[pre]') !== false) { + $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text); + } + if (strpos($Text,'[summary]') !== false) { + $Text = preg_replace_callback("/\[summary\](.*?)\[\/summary\]/ism", 'bb_spacefy',$Text); + } + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace_callback('/\[img(.*?)\[\/(img)\]/ism','\red_escape_codeblock',$Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace_callback('/\[zmg(.*?)\[\/(zmg)\]/ism','\red_escape_codeblock',$Text); + } + // Set up the parameters for a URL search string $URLSearchString = "^\[\]"; // Set up the parameters for a MAIL search string -- cgit v1.2.3 From ca32850a32986f0bb7ecbd2168119d4961e900c9 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 12 Oct 2021 20:06:11 +0000 Subject: fix image object as per AS2 --- include/photos.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index 967acf955..6ee57ba39 100644 --- a/include/photos.php +++ b/include/photos.php @@ -263,8 +263,8 @@ function photo_upload($channel, $observer, $args) { $r0 = $ph->save($p); $url[0] = array( - 'rel' => 'alternate', - 'type' => $type, + 'type' => 'Link', + 'mediaType' => $type, 'href' => z_root() . '/photo/' . $photo_hash . '-0.' . $ph->getExt(), 'width' => $width, 'height' => $height @@ -282,8 +282,8 @@ function photo_upload($channel, $observer, $args) { $r1 = $ph->storeThumbnail($p, PHOTO_RES_1024); $url[1] = array( - 'rel' => 'alternate', - 'type' => $type, + 'type' => 'Link', + 'mediaType' => $type, 'href' => z_root() . '/photo/' . $photo_hash . '-1.' . $ph->getExt(), 'width' => $ph->getWidth(), 'height' => $ph->getHeight() @@ -296,8 +296,8 @@ function photo_upload($channel, $observer, $args) { $r2 = $ph->storeThumbnail($p, PHOTO_RES_640); $url[2] = array( - 'rel' => 'alternate', - 'type' => $type, + 'type' => 'Link', + 'mediaType' => $type, 'href' => z_root() . '/photo/' . $photo_hash . '-2.' . $ph->getExt(), 'width' => $ph->getWidth(), 'height' => $ph->getHeight() @@ -310,8 +310,8 @@ function photo_upload($channel, $observer, $args) { $r3 = $ph->storeThumbnail($p, PHOTO_RES_320); $url[3] = array( - 'rel' => 'alternate', - 'type' => $type, + 'type' => 'Link', + 'mediaType' => $type, 'href' => z_root() . '/photo/' . $photo_hash . '-3.' . $ph->getExt(), 'width' => $ph->getWidth(), 'height' => $ph->getHeight() -- cgit v1.2.3 From aca1551e8608a6df6dbe666372b5941a212457bd Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 13 Oct 2021 09:23:59 +0000 Subject: implement AS representation of photos and albums, cleanup and minor fixes --- include/photos.php | 517 +++++++++++++++++++++++++++-------------------------- 1 file changed, 261 insertions(+), 256 deletions(-) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index 6ee57ba39..5bceb516d 100644 --- a/include/photos.php +++ b/include/photos.php @@ -4,9 +4,9 @@ * @brief Functions related to photo handling. */ +use Zotlabs\Access\PermissionLimits; use Zotlabs\Lib\Activity; - require_once('include/permissions.php'); require_once('include/items.php'); require_once('include/photo/photo_driver.php'); @@ -22,11 +22,11 @@ require_once('include/text.php'); */ function photo_upload($channel, $observer, $args) { - $ret = array('success' => false); + $ret = ['success' => false]; $channel_id = $channel['channel_id']; $account_id = $channel['channel_account_id']; - if(! perm_is_allowed($channel_id, $observer['xchan_hash'], 'write_storage')) { + if (!perm_is_allowed($channel_id, $observer['xchan_hash'], 'write_storage')) { $ret['message'] = t('Permission denied.'); return $ret; } @@ -35,15 +35,15 @@ function photo_upload($channel, $observer, $args) { * Determine the album to use */ - $album = $args['album']; + $album = $args['album']; - if(intval($args['visible']) || $args['visible'] === 'true') + if (intval($args['visible']) || $args['visible'] === 'true') $visible = 1; else $visible = 0; $deliver = true; - if(array_key_exists('deliver',$args)) + if (array_key_exists('deliver', $args)) $deliver = intval($args['deliver']); // Set to default channel permissions. If the parent directory (album) has permissions set, @@ -52,14 +52,14 @@ function photo_upload($channel, $observer, $args) { // ...messy... needs re-factoring once the photos/files integration stabilises $acl = new Zotlabs\Access\AccessList($channel); - if(array_key_exists('directory',$args) && $args['directory']) + if (array_key_exists('directory', $args) && $args['directory']) $acl->set($args['directory']); - if(array_key_exists('allow_cid',$args)) + if (array_key_exists('allow_cid', $args)) $acl->set($args); - if( (array_key_exists('group_allow',$args)) - || (array_key_exists('contact_allow',$args)) - || (array_key_exists('group_deny',$args)) - || (array_key_exists('contact_deny',$args))) { + if ((array_key_exists('group_allow', $args)) + || (array_key_exists('contact_allow', $args)) + || (array_key_exists('group_deny', $args)) + || (array_key_exists('contact_deny', $args))) { $acl->set_from_array($args); } @@ -67,54 +67,51 @@ function photo_upload($channel, $observer, $args) { $width = $height = 0; - if($args['getimagesize']) { - $width = $args['getimagesize'][0]; + if ($args['getimagesize']) { + $width = $args['getimagesize'][0]; $height = $args['getimagesize'][1]; } $os_storage = 0; - $max_thumb = get_config('system','max_thumbnail',1600); + $max_thumb = get_config('system', 'max_thumbnail', 1600); - if($args['os_syspath'] && $args['getimagesize']) { - if($args['getimagesize'][0] > $max_thumb || $args['getimagesize'][1] > $max_thumb) { - $imagick_path = get_config('system','imagick_convert_path'); - if($imagick_path && @file_exists($imagick_path)) { + if ($args['os_syspath'] && $args['getimagesize']) { + if ($args['getimagesize'][0] > $max_thumb || $args['getimagesize'][1] > $max_thumb) { + $imagick_path = get_config('system', 'imagick_convert_path'); + if ($imagick_path && @file_exists($imagick_path)) { $tmp_name = $args['os_syspath'] . '-001'; - $newsize = photo_calculate_scale(array_merge($args['getimagesize'],['max' => $max_thumb])); - $cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $args['os_syspath']) . ' -resize ' . $newsize . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmp_name); - logger('imagick thumbnail command: ' . $cmd); - for($x = 0; $x < 4; $x ++) { + $newsize = photo_calculate_scale(array_merge($args['getimagesize'], ['max' => $max_thumb])); + $cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $args['os_syspath']) . ' -resize ' . $newsize . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmp_name); + logger('imagick thumbnail command: ' . $cmd); + for ($x = 0; $x < 4; $x++) { exec($cmd); - if(file_exists($tmp_name)) { + if (file_exists($tmp_name)) { break; } logger('imagick scale failed. Retrying.'); continue; } - if(! file_exists($tmp_name)) { + if (!file_exists($tmp_name)) { logger('imagick scale failed. Abort.'); return $ret; } $imagedata = @file_get_contents($tmp_name); - $filesize = @filesize($args['os_syspath']); // @unlink($tmp_name); } else { $imagedata = @file_get_contents($args['os_syspath']); - $filesize = strlen($imagedata); } } else { $imagedata = @file_get_contents($args['os_syspath']); - $filesize = strlen($imagedata); } $filename = $args['filename']; // this is going to be deleted if it exists - $src = '/tmp/deletemenow'; - $type = $args['getimagesize']['mime']; + $src = '/tmp/deletemenow'; + $type = $args['getimagesize']['mime']; $os_storage = 1; } elseif ($args['data'] || $args['content']) { @@ -123,35 +120,37 @@ function photo_upload($channel, $observer, $args) { // This bypasses the upload step and max size limit checking $imagedata = (($args['content']) ? $args['content'] : $args['data']); - $filename = $args['filename']; - $filesize = strlen($imagedata); + $filename = $args['filename']; + // this is going to be deleted if it exists - $src = '/tmp/deletemenow'; + $src = '/tmp/deletemenow'; $type = (($args['mimetype']) ? $args['mimetype'] : $args['type']); - } else { - $f = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''); + } + else { + $f = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => '']; - if (x($f,'src') && x($f,'filesize')) { + if (x($f, 'src') && x($f, 'filesize')) { $src = $f['src']; $filename = $f['filename']; $filesize = $f['filesize']; $type = $f['type']; - } else { + } + else { $src = $_FILES['userfile']['tmp_name']; $filename = basename($_FILES['userfile']['name']); $filesize = intval($_FILES['userfile']['size']); $type = $_FILES['userfile']['type']; } - if (! $type) - $type=guess_image_type($filename); + if (!$type) + $type = guess_image_type($filename); - logger('Received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG); + logger('Received file: ' . $filename . ' as ' . $src . ' (' . $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG); - $maximagesize = get_config('system','maximagesize'); + $maximagesize = get_config('system', 'maximagesize'); if (($maximagesize) && ($filesize > $maximagesize)) { - $ret['message'] = sprintf ( t('Image exceeds website size limit of %lu bytes'), $maximagesize); + $ret['message'] = sprintf(t('Image exceeds website size limit of %lu bytes'), $maximagesize); @unlink($src); /** * @hooks photo_upload_end @@ -161,7 +160,7 @@ function photo_upload($channel, $observer, $args) { return $ret; } - if (! $filesize) { + if (!$filesize) { $ret['message'] = t('Image file is empty.'); @unlink($src); /** @@ -172,7 +171,7 @@ function photo_upload($channel, $observer, $args) { return $ret; } - logger('Loading the contents of ' . $src , LOGGER_DEBUG); + logger('Loading the contents of ' . $src, LOGGER_DEBUG); $imagedata = @file_get_contents($src); } @@ -180,7 +179,7 @@ function photo_upload($channel, $observer, $args) { intval($account_id) ); - $limit = engr_units_to_bytes(service_class_fetch($channel_id,'photo_upload_limit')); + $limit = engr_units_to_bytes(service_class_fetch($channel_id, 'photo_upload_limit')); if (($r) && ($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) { $ret['message'] = upgrade_message(); @@ -195,7 +194,7 @@ function photo_upload($channel, $observer, $args) { $ph = photo_factory($imagedata, $type); - if (! $ph->is_valid()) { + if (!$ph->is_valid()) { $ret['message'] = t('Unable to process image'); logger('unable to process image'); @unlink($src); @@ -211,7 +210,7 @@ function photo_upload($channel, $observer, $args) { $exif = $ph->exif(($args['os_syspath']) ? $args['os_syspath'] : $src); - if($exif) { + if ($exif) { $ph->orient($exif); } @@ -221,19 +220,17 @@ function photo_upload($channel, $observer, $args) { @unlink($src); - $max_length = get_config('system','max_image_length'); - if (! $max_length) + $max_length = get_config('system', 'max_image_length'); + if (!$max_length) $max_length = MAX_IMAGE_LENGTH; if ($max_length > 0) $ph->scaleImage($max_length); - if(! $width) - $width = $ph->getWidth(); - if(! $height) + if (!$width) + $width = $ph->getWidth(); + if (!$height) $height = $ph->getHeight(); - $smallest = 0; - $photo_hash = (($args['resource_id']) ? $args['resource_id'] : photo_new_resource()); $visitor = ''; @@ -242,34 +239,34 @@ function photo_upload($channel, $observer, $args) { $errors = false; - $p = array('aid' => $account_id, 'uid' => $channel_id, 'xchan' => $visitor, 'resource_id' => $photo_hash, - 'filename' => $filename, 'album' => $album, 'imgscale' => 0, 'photo_usage' => PHOTO_NORMAL, - 'width' => $width, 'height' => $height, - 'allow_cid' => $ac['allow_cid'], 'allow_gid' => $ac['allow_gid'], - 'deny_cid' => $ac['deny_cid'], 'deny_gid' => $ac['deny_gid'], - 'os_storage' => $os_storage, 'os_syspath' => $args['os_syspath'], - 'os_path' => $args['os_path'], 'display_path' => $args['display_path'] - ); - if($args['created']) + $p = ['aid' => $account_id, 'uid' => $channel_id, 'xchan' => $visitor, 'resource_id' => $photo_hash, + 'filename' => $filename, 'album' => $album, 'imgscale' => 0, 'photo_usage' => PHOTO_NORMAL, + 'width' => $width, 'height' => $height, + 'allow_cid' => $ac['allow_cid'], 'allow_gid' => $ac['allow_gid'], + 'deny_cid' => $ac['deny_cid'], 'deny_gid' => $ac['deny_gid'], + 'os_storage' => $os_storage, 'os_syspath' => $args['os_syspath'], + 'os_path' => $args['os_path'], 'display_path' => $args['display_path'] + ]; + if ($args['created']) $p['created'] = $args['created']; - if($args['edited']) + if ($args['edited']) $p['edited'] = $args['edited']; - if($args['title']) + if ($args['title']) $p['title'] = $args['title']; - if($args['description']) + if ($args['description']) $p['description'] = $args['description']; $url = []; - $r0 = $ph->save($p); - $url[0] = array( - 'type' => 'Link', + $r0 = $ph->save($p); + $url[0] = [ + 'type' => 'Link', 'mediaType' => $type, - 'href' => z_root() . '/photo/' . $photo_hash . '-0.' . $ph->getExt(), - 'width' => $width, - 'height' => $height - ); - if(! $r0) + 'href' => z_root() . '/photo/' . $photo_hash . '-0.' . $ph->getExt(), + 'width' => $width, + 'height' => $height + ]; + if (!$r0) $errors = true; unset($p['os_storage']); @@ -277,49 +274,49 @@ function photo_upload($channel, $observer, $args) { unset($p['width']); unset($p['height']); - if(($width > 1024 || $height > 1024) && (! $errors)) + if (($width > 1024 || $height > 1024) && (!$errors)) $ph->scaleImage(1024); - $r1 = $ph->storeThumbnail($p, PHOTO_RES_1024); - $url[1] = array( - 'type' => 'Link', + $r1 = $ph->storeThumbnail($p, PHOTO_RES_1024); + $url[1] = [ + 'type' => 'Link', 'mediaType' => $type, - 'href' => z_root() . '/photo/' . $photo_hash . '-1.' . $ph->getExt(), - 'width' => $ph->getWidth(), - 'height' => $ph->getHeight() - ); - if(! $r1) + 'href' => z_root() . '/photo/' . $photo_hash . '-1.' . $ph->getExt(), + 'width' => $ph->getWidth(), + 'height' => $ph->getHeight() + ]; + if (!$r1) $errors = true; - if(($width > 640 || $height > 640) && (! $errors)) + if (($width > 640 || $height > 640) && (!$errors)) $ph->scaleImage(640); - $r2 = $ph->storeThumbnail($p, PHOTO_RES_640); - $url[2] = array( - 'type' => 'Link', + $r2 = $ph->storeThumbnail($p, PHOTO_RES_640); + $url[2] = [ + 'type' => 'Link', 'mediaType' => $type, - 'href' => z_root() . '/photo/' . $photo_hash . '-2.' . $ph->getExt(), - 'width' => $ph->getWidth(), - 'height' => $ph->getHeight() - ); - if(! $r2) + 'href' => z_root() . '/photo/' . $photo_hash . '-2.' . $ph->getExt(), + 'width' => $ph->getWidth(), + 'height' => $ph->getHeight() + ]; + if (!$r2) $errors = true; - if(($width > 320 || $height > 320) && (! $errors)) + if (($width > 320 || $height > 320) && (!$errors)) $ph->scaleImage(320); - $r3 = $ph->storeThumbnail($p, PHOTO_RES_320); - $url[3] = array( - 'type' => 'Link', + $r3 = $ph->storeThumbnail($p, PHOTO_RES_320); + $url[3] = [ + 'type' => 'Link', 'mediaType' => $type, - 'href' => z_root() . '/photo/' . $photo_hash . '-3.' . $ph->getExt(), - 'width' => $ph->getWidth(), - 'height' => $ph->getHeight() - ); - if(! $r3) + 'href' => z_root() . '/photo/' . $photo_hash . '-3.' . $ph->getExt(), + 'width' => $ph->getWidth(), + 'height' => $ph->getHeight() + ]; + if (!$r3) $errors = true; - if($errors) { + if ($errors) { q("delete from photo where resource_id = '%s' and uid = %d", dbesc($photo_hash), intval($channel_id) @@ -334,19 +331,19 @@ function photo_upload($channel, $observer, $args) { return $ret; } - $item_hidden = (($visible) ? 0 : 1 ); + $item_hidden = (($visible) ? 0 : 1); $lat = $lon = null; - if($exif && feature_enabled($channel_id,'photo_location')) { + if ($exif && feature_enabled($channel_id, 'photo_location')) { $gps = null; - if(array_key_exists('GPS',$exif)) { + if (array_key_exists('GPS', $exif)) { $gps = $exif['GPS']; } - elseif(array_key_exists('GPSLatitude',$exif)) { + elseif (array_key_exists('GPSLatitude', $exif)) { $gps = $exif; } - if($gps) { + if ($gps) { $lat = getGps($gps['GPSLatitude'], $gps['GPSLatitudeRef']); $lon = getGps($gps['GPSLongitude'], $gps['GPSLongitudeRef']); } @@ -358,17 +355,17 @@ function photo_upload($channel, $observer, $args) { $found_tags = linkify_tags($args['body'], $channel_id); - if($large_photos) { - $scale = 1; - $width = $url[1]['width']; + if ($large_photos) { + $scale = 1; + $width = $url[1]['width']; $height = $url[1]['height']; - $tag = (($r1) ? '[zmg=' . $width . 'x' . $height . ']' : '[zmg]'); + $tag = (($r1) ? '[zmg=' . $width . 'x' . $height . ']' : '[zmg]'); } else { - $scale = 2; - $width = $url[2]['width']; + $scale = 2; + $width = $url[2]['width']; $height = $url[2]['height']; - $tag = (($r2) ? '[zmg=' . $width . 'x' . $height . ']' : '[zmg]'); + $tag = (($r2) ? '[zmg=' . $width . 'x' . $height . ']' : '[zmg]'); } $author_link = '[zrl=' . z_root() . '/channel/' . $channel['channel_address'] . ']' . $channel['channel_name'] . '[/zrl]'; @@ -377,11 +374,11 @@ function photo_upload($channel, $observer, $args) { $album_link = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $args['directory']['hash'] . ']' . ((strlen($album)) ? $album : '/') . '[/zrl]'; - $activity_format = sprintf(t('%1$s posted %2$s to %3$s','photo_upload'), $author_link, $photo_link, $album_link); + $activity_format = sprintf(t('%1$s posted %2$s to %3$s', 'photo_upload'), $author_link, $photo_link, $album_link); $summary = (($args['body']) ? $args['body'] : '') . '[footer]' . $activity_format . '[/footer]'; - $obj_body = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' + $obj_body = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' . $tag . z_root() . "/photo/{$photo_hash}-{$scale}." . $ph->getExt() . '[/zmg]' . '[/zrl]'; @@ -393,32 +390,39 @@ function photo_upload($channel, $observer, $args) { $post_tags = []; - if($found_tags) { - foreach($found_tags as $result) { + if ($found_tags) { + foreach ($found_tags as $result) { $success = $result['success']; - if($success['replaced']) { - $post_tags[] = array( + if ($success['replaced']) { + $post_tags[] = [ 'uid' => $channel['channel_id'], 'ttype' => $success['termtype'], 'otype' => TERM_OBJ_POST, 'term' => $success['term'], 'url' => $success['url'] - ); + ]; } } } + $attribution = (($visitor) ? $visitor['xchan_url'] : $channel['xchan_url']); + //// Create item object $object = [ - 'type' => 'Image', - 'name' => $title, - 'published' => datetime_convert('UTC','UTC',$p['created'],ATOM_TIME), - 'updated' => datetime_convert('UTC','UTC',$p['edited'],ATOM_TIME), - // This is a placeholder and will get over-ridden by the item mid, which is critical for sharing as a conversational item over activitypub - 'id' => z_root() . '/photo/' . $photo_hash, - 'url' => $url, - 'source' => [ 'content' => $summary, 'mediaType' => 'text/bbcode' ], - 'content' => bbcode($summary) + 'type' => 'Image', + 'name' => $title, + 'published' => datetime_convert('UTC', 'UTC', $p['created'], ATOM_TIME), + 'updated' => datetime_convert('UTC', 'UTC', $p['edited'], ATOM_TIME), + 'attributedTo' => $attribution, + + // id and diaspora:guid are placeholders and will get over-ridden by the item mid. + // This is critical for sharing as a conversational item over activitypub. + 'id' => z_root() . '/photo/' . $photo_hash, + 'diaspora:guid' => $photo_hash, + + 'url' => $url, + 'source' => ['content' => $summary, 'mediaType' => 'text/bbcode'], + 'content' => bbcode($summary) ]; if ($post_tags) { @@ -428,35 +432,38 @@ function photo_upload($channel, $observer, $args) { $public = (($ac['allow_cid'] || $ac['allow_gid'] || $ac['deny_cid'] || $ac['deny_gid']) ? false : true); if ($public) { - $object['to'] = [ ACTIVITY_PUBLIC_INBOX ]; - $object['cc'] = [ z_root() . '/followers/' . $channel['channel_address'] ]; + $object['to'] = [ACTIVITY_PUBLIC_INBOX]; + $object['cc'] = [z_root() . '/followers/' . $channel['channel_address']]; } else { - $object['to'] = Activity::map_acl(array_merge($ac, ['item_private' => 1 - intval($public) ])); + $object['to'] = Activity::map_acl(array_merge($ac, ['item_private' => 1 - intval($public)])); } $target = [ - 'type' => 'orderedCollection', - 'name' => ((strlen($album)) ? $album : '/'), - 'id' => z_root() . '/album/' . $channel['channel_address'] . ((isset($args['folder'])) ? '/' . $args['folder'] : EMPTY_STR) + 'type' => 'orderedCollection', + 'name' => ((strlen($album)) ? $album : '/'), + 'id' => z_root() . '/album/' . $channel['channel_address'] . ((isset($args['directory']['hash'])) ? '/' . $args['directory']['hash'] : EMPTY_STR) ]; // Create item container - if($args['item']) { - foreach($args['item'] as $i) { + if ($args['item']) { + foreach ($args['item'] as $i) { - $item = get_item_elements($i); + $item = get_item_elements($i); $force = false; - if($item['mid'] === $item['parent_mid']) { + if ($item['mid'] === $item['parent_mid']) { - $item['body'] = $summary; + $item['body'] = $summary; $item['mimetype'] = 'text/bbcode'; $item['obj_type'] = ACTIVITY_OBJ_PHOTO; - $item['obj'] = json_encode($object); - $item['tgt_type'] = ACTIVITY_OBJ_ALBUM; - $item['target'] = json_encode($target); + $object['id'] = $item['mid']; + $object['diaspora:guid'] = $item['uuid']; + $item['obj'] = json_encode($object); + + $item['tgt_type'] = 'orderedCollection'; + $item['target'] = json_encode($target); if ($post_tags) { $arr['term'] = $post_tags; } @@ -466,29 +473,33 @@ function photo_upload($channel, $observer, $args) { dbesc($item['mid']), intval($channel['channel_id']) ); - if($r) { - if(($item['edited'] > $r[0]['edited']) || $force) { - $item['id'] = $r[0]['id']; + if ($r) { + if (($item['edited'] > $r[0]['edited']) || $force) { + $item['id'] = $r[0]['id']; $item['uid'] = $channel['channel_id']; - item_store_update($item,false,$deliver); + item_store_update($item, false, $deliver); continue; } } else { $item['aid'] = $channel['channel_account_id']; $item['uid'] = $channel['channel_id']; - $item_result = item_store($item,false,$deliver); + item_store($item, false, $deliver); } } } else { - // $uuid = item_message_id(); - $mid = z_root() . '/item/' . $photo_hash; + + $uuid = new_uuid(); + $mid = z_root() . '/item/' . $uuid; + + $object['id'] = $mid; + $object['diaspora:guid'] = $uuid; $arr = [ 'aid' => $account_id, 'uid' => $channel_id, - 'uuid' => $photo_hash, + 'uuid' => $uuid, 'mid' => $mid, 'parent_mid' => $mid, 'item_hidden' => $item_hidden, @@ -504,23 +515,23 @@ function photo_upload($channel, $observer, $args) { 'verb' => ACTIVITY_POST, 'obj_type' => ACTIVITY_OBJ_PHOTO, 'obj' => json_encode($object), - 'tgt_type' => ACTIVITY_OBJ_ALBUM, - 'target' => json_encode($target), + 'tgt_type' => 'orderedCollection', + 'target' => json_encode($target), 'item_wall' => $visible, 'item_origin' => 1, 'item_thread_top' => 1, 'item_private' => intval($acl->is_private()), - 'body' => $summary + 'body' => $summary, + 'plink' => $mid ]; if ($post_tags) { $arr['term'] = $post_tags; } - $arr['plink'] = $mid; - - if($lat && $lon) + if ($lat && $lon) { $arr['coord'] = $lat . ' ' . $lon; + } // this one is tricky because the item and the photo have the same permissions, those of the photo. // Use the channel read_stream permissions to get the correct public_policy for the item and recalculate the @@ -529,22 +540,21 @@ function photo_upload($channel, $observer, $args) { // in the photos pages - using the photos permissions instead. We need the public policy to keep the photo // linked item from leaking into the feed when somebody has a channel with read_stream restrictions. - $arr['public_policy'] = map_scope(\Zotlabs\Access\PermissionLimits::Get($channel['channel_id'],'view_stream'),true); - if($arr['public_policy']) + $arr['public_policy'] = map_scope(PermissionLimits::Get($channel['channel_id'], 'view_stream'), true); + if ($arr['public_policy']) $arr['item_private'] = 1; - - $result = item_store($arr,false,$deliver); + $result = item_store($arr, false, $deliver); $item_id = $result['item_id']; - if($visible && $deliver) - Zotlabs\Daemon\Master::Summon(array('Notifier', 'wall-new', $item_id)); + if ($visible && $deliver) + Zotlabs\Daemon\Master::Summon(['Notifier', 'wall-new', $item_id]); } - $ret['success'] = true; - $ret['item'] = $arr; - $ret['body'] = $obj_body; - $ret['resource_id'] = $photo_hash; + $ret['success'] = true; + $ret['item'] = $arr; + $ret['body'] = $obj_body; + $ret['resource_id'] = $photo_hash; $ret['photoitem_id'] = $item_id; /** @@ -559,57 +569,55 @@ function photo_upload($channel, $observer, $args) { function photo_calculate_scale($arr) { - $max = $arr['max']; - $width = $arr[0]; + $max = $arr['max']; + $width = $arr[0]; $height = $arr[1]; - $dest_width = $dest_height = 0; - - if((! $width)|| (! $height)) + if ((!$width) || (!$height)) return FALSE; - if($width > $max && $height > $max) { + if ($width > $max && $height > $max) { // very tall image (greater than 16:9) // constrain the width - let the height float. - if((($height * 9) / 16) > $width) { - $dest_width = $max; - $dest_height = intval(( $height * $max ) / $width); + if ((($height * 9) / 16) > $width) { + $dest_width = $max; + $dest_height = intval(($height * $max) / $width); } // else constrain both dimensions - elseif($width > $height) { - $dest_width = $max; - $dest_height = intval(( $height * $max ) / $width); + elseif ($width > $height) { + $dest_width = $max; + $dest_height = intval(($height * $max) / $width); } else { - $dest_width = intval(( $width * $max ) / $height); + $dest_width = intval(($width * $max) / $height); $dest_height = $max; } } else { - if( $width > $max ) { - $dest_width = $max; - $dest_height = intval(( $height * $max ) / $width); + if ($width > $max) { + $dest_width = $max; + $dest_height = intval(($height * $max) / $width); } else { - if( $height > $max ) { + if ($height > $max) { // very tall image (greater than 16:9) // but width is OK - don't do anything - if((($height * 9) / 16) > $width) { - $dest_width = $width; - $dest_height = $height; + if ((($height * 9) / 16) > $width) { + $dest_width = $width; + $dest_height = $height; } else { - $dest_width = intval(( $width * $max ) / $height); + $dest_width = intval(($width * $max) / $height); $dest_height = $max; } } else { - $dest_width = $width; + $dest_width = $width; $dest_height = $height; } } @@ -637,34 +645,34 @@ function photos_albums_list($channel, $observer, $sort_key = 'display_path', $di $channel_id = $channel['channel_id']; $observer_xchan = (($observer) ? $observer['xchan_hash'] : ''); - if(! perm_is_allowed($channel_id, $observer_xchan, 'view_storage')) + if (!perm_is_allowed($channel_id, $observer_xchan, 'view_storage')) return false; - $sql_extra = permissions_sql($channel_id,$observer_xchan); + $sql_extra = permissions_sql($channel_id, $observer_xchan); - $sort_key = dbesc($sort_key); + $sort_key = dbesc($sort_key); $direction = dbesc($direction); $r = q("select display_path, hash from attach where is_dir = 1 and uid = %d $sql_extra order by $sort_key $direction", intval($channel_id) ); - array_unshift($r,[ 'display_path' => '/', 'hash' => '' ]); - $str = ids_to_querystr($r,'hash',true); + array_unshift($r, ['display_path' => '/', 'hash' => '']); + $str = ids_to_querystr($r, 'hash', true); $albums = []; - if($str) { + if ($str) { $x = q("select count( distinct hash ) as total, folder from attach where is_photo = 1 and uid = %d and folder in ( $str ) $sql_extra group by folder ", intval($channel_id) ); - if($x) { + if ($x) { require_once('include/attach.php'); - foreach($r as $rv) { - foreach($x as $xv) { - if($xv['folder'] === $rv['hash']) { - if($xv['total'] != 0 && attach_can_view_folder($channel_id,$observer_xchan,$xv['folder'])) { - $albums[] = [ 'album' => $rv['display_path'], 'folder' => $xv['folder'], 'total' => $xv['total'] ]; + foreach ($r as $rv) { + foreach ($x as $xv) { + if ($xv['folder'] === $rv['hash']) { + if ($xv['total'] != 0 && attach_can_view_folder($channel_id, $observer_xchan, $xv['folder'])) { + $albums[] = ['album' => $rv['display_path'], 'folder' => $xv['folder'], 'total' => $xv['total']]; } continue; } @@ -675,15 +683,15 @@ function photos_albums_list($channel, $observer, $sort_key = 'display_path', $di // add various encodings to the array so we can just loop through and pick them out in a template - $ret = array('success' => false); + $ret = ['success' => false]; - if($albums) { + if ($albums) { $ret['success'] = true; - $ret['albums'] = array(); - foreach($albums as $k => $album) { - $entry = [ + $ret['albums'] = []; + foreach ($albums as $k => $album) { + $entry = [ 'text' => (($album['album']) ? $album['album'] : '/'), - 'shorttext' => (($album['album']) ? ellipsify($album['album'],28) : '/'), + 'shorttext' => (($album['album']) ? ellipsify($album['album'], 28) : '/'), 'jstext' => (($album['album']) ? addslashes($album['album']) : '/'), 'total' => $album['total'], 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $album['folder'], @@ -699,25 +707,25 @@ function photos_albums_list($channel, $observer, $sort_key = 'display_path', $di return $ret; } -function photos_album_widget($channelx,$observer,$sortkey = 'display_path',$direction = 'asc') { +function photos_album_widget($channelx, $observer, $sortkey = 'display_path', $direction = 'asc') { $o = ''; - if(array_key_exists('albums', App::$data)) + if (array_key_exists('albums', App::$data)) $albums = App::$data['albums']; else - $albums = photos_albums_list($channelx,$observer,$sortkey,$direction); + $albums = photos_albums_list($channelx, $observer, $sortkey, $direction); - if($albums['success']) { - $o = replace_macros(get_markup_template('photo_albums.tpl'),array( + if ($albums['success']) { + $o = replace_macros(get_markup_template('photo_albums.tpl'), [ '$nick' => $channelx['channel_address'], '$title' => t('Photo Albums'), '$recent' => t('Recent Photos'), '$albums' => $albums['albums'], '$baseurl' => z_root(), - '$upload' => ((perm_is_allowed($channelx['channel_id'],(($observer) ? $observer['xchan_hash'] : ''),'write_storage')) + '$upload' => ((perm_is_allowed($channelx['channel_id'], (($observer) ? $observer['xchan_hash'] : ''), 'write_storage')) ? t('Upload New Photos') : '') - )); + ]); } return $o; @@ -736,15 +744,15 @@ function photos_list_photos($channel, $observer, $album = '') { $channel_id = $channel['channel_id']; $observer_xchan = (($observer) ? $observer['xchan_hash'] : ''); - if(! perm_is_allowed($channel_id,$observer_xchan,'view_storage')) + if (!perm_is_allowed($channel_id, $observer_xchan, 'view_storage')) return false; $sql_extra = permissions_sql($channel_id); - if($album) + if ($album) $sql_extra .= " and album = '" . protect_sprintf(dbesc($album)) . "' "; - $ret = array('success' => false); + $ret = ['success' => false]; $r = q("select resource_id, created, edited, title, description, album, filename, mimetype, height, width, filesize, imgscale, photo_usage, allow_cid, allow_gid, deny_cid, deny_gid from photo where uid = %d and photo_usage in ( %d, %d ) $sql_extra ", intval($channel_id), @@ -752,12 +760,12 @@ function photos_list_photos($channel, $observer, $album = '') { intval(PHOTO_PROFILE) ); - if($r) { - for($x = 0; $x < count($r); $x ++) { + if ($r) { + for ($x = 0; $x < count($r); $x++) { $r[$x]['src'] = z_root() . '/photo/' . $r[$x]['resource_id'] . '-' . $r[$x]['imgscale']; } $ret['success'] = true; - $ret['photos'] = $r; + $ret['photos'] = $r; } return $ret; @@ -782,7 +790,7 @@ function photos_album_exists($channel_id, $observer_hash, $album) { // partial backward compatibility with Hubzilla < 2.4 when we used the filename only // (ambiguous which would get chosen if you had two albums of the same name in different directories) - if(!$r && ctype_xdigit($album)) { + if (!$r && ctype_xdigit($album)) { $r = q("SELECT folder, hash, is_dir, filename, os_path, display_path FROM attach WHERE filename = '%s' AND is_dir = 1 AND uid = %d $sql_extra limit 1", dbesc(hex2bin($album)), intval($channel_id) @@ -795,12 +803,12 @@ function photos_album_exists($channel_id, $observer_hash, $album) { /** * @brief Renames a photo album in a channel. * - * @todo Do we need to check if new album name already exists? - * * @param int $channel_id id of the channel * @param string $oldname The name of the album to rename * @param string $newname The new name of the album * @return bool|array + * @todo Do we need to check if new album name already exists? + * */ function photos_album_rename($channel_id, $oldname, $newname) { return q("UPDATE photo SET album = '%s' WHERE album = '%s' AND uid = %d", @@ -820,7 +828,7 @@ function photos_album_rename($channel_id, $oldname, $newname) { */ function photos_album_get_db_idstr($channel_id, $album, $remote_xchan = '') { - if($remote_xchan) { + if ($remote_xchan) { $r = q("SELECT hash from attach where creator = '%s' and uid = %d and folder = '%s' ", dbesc($remote_xchan), intval($channel_id), @@ -834,7 +842,7 @@ function photos_album_get_db_idstr($channel_id, $album, $remote_xchan = '') { ); } if ($r) { - return ids_to_querystr($r,'hash',true); + return ids_to_querystr($r, 'hash', true); } return false; @@ -842,7 +850,7 @@ function photos_album_get_db_idstr($channel_id, $album, $remote_xchan = '') { function photos_album_get_db_idstr_admin($channel_id, $album) { - if(! is_site_admin()) + if (!is_site_admin()) return false; $r = q("SELECT hash from attach where uid = %d and folder = '%s' ", @@ -851,14 +859,13 @@ function photos_album_get_db_idstr_admin($channel_id, $album) { ); if ($r) { - return ids_to_querystr($r,'hash',true); + return ids_to_querystr($r, 'hash', true); } return false; } - /** * @brief Creates a new photo item. * @@ -872,12 +879,12 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) { // Create item container - $item_hidden = (($visible) ? 0 : 1 ); + $item_hidden = (($visible) ? 0 : 1); $uuid = item_message_id(); - $mid = z_root() . '/item/' . $uuid; + $mid = z_root() . '/item/' . $uuid; - $arr = array(); + $arr = []; $arr['aid'] = $channel['channel_account_id']; $arr['uid'] = $channel['channel_id']; @@ -893,18 +900,18 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) { $arr['owner_xchan'] = $channel['channel_hash']; $arr['author_xchan'] = $creator_hash; - $arr['allow_cid'] = $photo['allow_cid']; - $arr['allow_gid'] = $photo['allow_gid']; - $arr['deny_cid'] = $photo['deny_cid']; - $arr['deny_gid'] = $photo['deny_gid']; + $arr['allow_cid'] = $photo['allow_cid']; + $arr['allow_gid'] = $photo['allow_gid']; + $arr['deny_cid'] = $photo['deny_cid']; + $arr['deny_gid'] = $photo['deny_gid']; - $arr['plink'] = $mid; + $arr['plink'] = $mid; - $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']' + $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']' . '[zmg]' . z_root() . '/photo/' . $photo['resource_id'] . '-' . $photo['imgscale'] . '[/zmg]' . '[/zrl]'; - $result = item_store($arr); + $result = item_store($arr); $item_id = $result['item_id']; return $item_id; @@ -946,9 +953,9 @@ function gps2Num($coordPart) { } -function photo_profile_setperms($channel_id,$resource_id,$profile_id) { +function photo_profile_setperms($channel_id, $resource_id, $profile_id) { - if(! $profile_id) + if (!$profile_id) return; $r = q("select profile_guid, is_default from profile where id = %d and uid = %d limit 1", @@ -956,33 +963,33 @@ function photo_profile_setperms($channel_id,$resource_id,$profile_id) { intval($channel_id) ); - if(! $r) + if (!$r) return; $is_default = $r[0]['is_default']; $profile_guid = $r[0]['profile_guid']; - if($is_default) { - $r = q("update photo set allow_cid = '', allow_gid = '', deny_cid = '', deny_gid = '' + if ($is_default) { + q("update photo set allow_cid = '', allow_gid = '', deny_cid = '', deny_gid = '' where resource_id = '%s' and uid = %d", dbesc($resource_id), intval($channel_id) ); - $r = q("update attach set allow_cid = '', allow_gid = '', deny_cid = '', deny_gid = '' + q("update attach set allow_cid = '', allow_gid = '', deny_cid = '', deny_gid = '' where hash = '%s' and uid = %d", dbesc($resource_id), intval($channel_id) ); } else { - $r = q("update photo set allow_cid = '', allow_gid = '%s', deny_cid = '', deny_gid = '' + q("update photo set allow_cid = '', allow_gid = '%s', deny_cid = '', deny_gid = '' where resource_id = '%s' and uid = %d", dbesc(''), dbesc($resource_id), intval($channel_id) ); - $r = q("update attach set allow_cid = '', allow_gid = '%s', deny_cid = '', deny_gid = '' + q("update attach set allow_cid = '', allow_gid = '%s', deny_cid = '', deny_gid = '' where hash = '%s' and uid = %d", dbesc(''), dbesc($resource_id), @@ -999,9 +1006,7 @@ function photo_profile_setperms($channel_id,$resource_id,$profile_id) { */ function profile_photo_set_profile_perms($uid, $profileid = 0) { - $allowcid = ''; - - if($profileid) { + if ($profileid) { $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE uid = %d and ( profile.id = %d OR profile.profile_guid = '%s') LIMIT 1", intval($uid), @@ -1010,31 +1015,31 @@ function profile_photo_set_profile_perms($uid, $profileid = 0) { ); } else { - logger('Resetting permissions on default-profile-photo for user'.local_channel()); + logger('Resetting permissions on default-profile-photo for user' . local_channel()); $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE profile.uid = %d AND is_default = 1 LIMIT 1", intval($uid) ); //If no profile is given, we update the default profile } - if(! $r) + if (!$r) return; $profile = $r[0]; - if($profile['id'] && $profile['photo']) { + if ($profile['id'] && $profile['photo']) { preg_match("@\w*(?=-\d*$)@i", $profile['photo'], $resource_id); $resource_id = $resource_id[0]; - if (! intval($profile['is_default'])) { + if (!intval($profile['is_default'])) { $r0 = q("SELECT channel_hash FROM channel WHERE channel_id = %d LIMIT 1", intval($uid) ); //Should not be needed in future. Catches old int-profile-ids. - $r1 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%d' ", + $r1 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%d' ", intval($profile['id']) ); - $r2 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%s'", + $r2 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%s'", dbesc($profile['profile_guid']) ); $allowcid = "<" . $r0[0]['channel_hash'] . ">"; -- cgit v1.2.3 From 532b479f96eea701080d5533e5f28acab9af76ba Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 14 Oct 2021 18:15:38 +0000 Subject: provide local copies of the w3.org jsonld documents - addresses issue #1637 --- include/network.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index 194b50885..1b8f0e663 100644 --- a/include/network.php +++ b/include/network.php @@ -2014,6 +2014,21 @@ function getBestSupportedMimeType($mimeTypes = null, $acceptedTypes = false) { */ function jsonld_document_loader($url) { + switch ($url) { + case 'https://www.w3.org/ns/activitystreams': + $url = z_root() . '/library/w3org/activitystreams.jsonld'; + break; + case 'https://w3id.org/identity/v1': + $url = z_root() . '/library/w3org/identity-v1.jsonld'; + break; + case 'https://w3id.org/security/v1': + $url = z_root() . '/library/w3org/security-v1.jsonld'; + break; + default: + logger('URL: ' . $url, LOGGER_DEBUG); + break; + } + require_once('library/jsonld/jsonld.php'); $recursion = 0; @@ -2026,12 +2041,12 @@ function jsonld_document_loader($url) { } } } + if($recursion > 5) { logger('jsonld bomb detected at: ' . $url); killme(); } - $cachepath = 'store/[data]/ldcache'; if(! is_dir($cachepath)) os_mkdir($cachepath, STORAGE_DEFAULT_PERMISSIONS, true); -- cgit v1.2.3 From a622f533ad2f5890a782b6477406ce1d1d774d34 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 15 Oct 2021 19:17:06 +0000 Subject: some heavylifting on manual item export --- include/channel.php | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 2db0434ca..7188d76f8 100644 --- a/include/channel.php +++ b/include/channel.php @@ -767,10 +767,10 @@ function get_default_export_sections() { 'connections', 'config', 'apps', - 'chatrooms', - 'events', - 'webpages', - 'wikis' +// 'chatrooms', +// 'events', +// 'webpages', +// 'wikis' ]; $cb = [ 'sections' => $sections ]; @@ -1179,7 +1179,7 @@ function identity_export_year($channel_id, $year, $month = 0, $zap_compat = fals } /** - * @brief Export items within an arbitrary date range. + * @brief Export conv items within an arbitrary date range. * * Date/time is in UTC. * @@ -1212,19 +1212,39 @@ function channel_export_items_date($channel_id, $start, $finish, $zap_compat = f } - $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and created >= '%s' and created <= '%s' and resource_type != 'photo' order by created", - intval(ITEM_TYPE_POST), + // Fetch parent items for the timeframe + $r = q("SELECT parent AS item_id FROM item + WHERE uid = %d AND (item_wall = 1 OR item_private = 2) AND item_thread_top = 1 + AND resource_type IN ('group_item', '') AND item_deleted = 0 + AND created >= '%s' AND created <= '%s' + ORDER BY created", intval($channel_id), dbesc($start), dbesc($finish) ); - if($r) { - $ret['item'] = array(); - xchan_query($r); - $r = fetch_post_tags($r, true); - foreach($r as $rr) - $ret['item'][] = encode_item($rr, true, $zap_compat); + $parents_str = ids_to_querystr($r, 'item_id'); + + $items = q("SELECT * FROM item + WHERE uid = %d + AND parent IN ( $parents_str ) + ORDER BY created", + intval($channel_id) + ); + + //$items = q("select * from item where (item_wall = 1 or item_type != %d ) and resource_type = '' and item_deleted = 0 and uid = %d and created >= '%s' and created <= '%s' order by created", + //intval(ITEM_TYPE_POST), + //intval($channel_id), + //dbesc($start), + //dbesc($finish) + //); + + if($items) { + $ret['item'] = []; + xchan_query($items); + $r = fetch_post_tags($items, true); + foreach ($items as $item) + $ret['item'][] = encode_item($item, true, $zap_compat); } return $ret; -- cgit v1.2.3 From 27401794e113351f5f9a781bf7fdcca276c9a94d Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 16 Oct 2021 18:10:23 +0000 Subject: rename functions after heavy lifting and expand custom sections to all possible sections --- include/channel.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 7188d76f8..d438d0aa7 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1147,7 +1147,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals /** - * @brief Export items for a year, or a month of a year. + * @brief Export conv items for a year, or a month of a year. * * @param int $channel_id The channel ID * @param number $year YYYY @@ -1156,7 +1156,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals * * \e array \b relocate - (optional) * * \e array \b item - array with items encoded_item() */ -function identity_export_year($channel_id, $year, $month = 0, $zap_compat = false) { +function conv_item_export_year($channel_id, $year, $month = 0, $zap_compat = false) { if(! $year) return array(); @@ -1174,13 +1174,16 @@ function identity_export_year($channel_id, $year, $month = 0, $zap_compat = fals else $maxdate = datetime_convert('UTC', 'UTC', $year+1 . '-01-01 00:00:00'); - return channel_export_items_date($channel_id,$mindate,$maxdate, $zap_compat); + return channel_export_conv_items_date($channel_id,$mindate,$maxdate, $zap_compat); } /** * @brief Export conv items within an arbitrary date range. * + * In opposit to channel_export_items_page() which is used for bulk export via network, + * this function will only select conversational items (channel, cards, articles, direct messages). + * * Date/time is in UTC. * * @param int $channel_id The channel ID @@ -1189,7 +1192,7 @@ function identity_export_year($channel_id, $year, $month = 0, $zap_compat = fals * @return array */ -function channel_export_items_date($channel_id, $start, $finish, $zap_compat = false) { +function channel_export_conv_items_date($channel_id, $start, $finish, $zap_compat = false) { if(! $start) return array(); -- cgit v1.2.3 From 8bae40449f2a5bfcc6ef86f82be1e15bdb9b9acd Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 22 Oct 2021 08:07:19 +0000 Subject: remove library/urlify and use vendor/jbroadway/urlify instead --- include/import.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index b0a1a77e5..8707a9430 100644 --- a/include/import.php +++ b/include/import.php @@ -1719,8 +1719,7 @@ function import_webpage_element($element, $channel, $type) { $namespace = 'WEBPAGE'; $name = $element['pagelink']; if($name) { - require_once('library/urlify/URLify.php'); - $name = strtolower(\URLify::transliterate($name)); + $name = strtolower(URLify::transliterate($name)); } $arr['title'] = $element['title']; $arr['term'] = $element['term']; -- cgit v1.2.3 From 65acdd7b1587b0537cfe4084bbfd18436cc754b1 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 25 Oct 2021 08:03:12 +0000 Subject: mod regate: auto-connect the invitee with the inviter if auto channel create is enabled (default). fix issue where the default group was not set in the return array of create_identity() --- include/channel.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index d438d0aa7..927da3dcd 100644 --- a/include/channel.php +++ b/include/channel.php @@ -470,6 +470,10 @@ function create_identity($arr) { dbesc($default_collection_str), intval($newuid) ); + + // also update the current channel array, otherwise the auto-follow contacts will not be added to the default group + $ret['channel']['channel_default_group'] = dbesc($group_hash); + $ret['channel']['channel_allow_gid'] = dbesc($default_collection_str); } if(! $system) { -- cgit v1.2.3 From acfa527e3e3a4cfa44a8f5148c3409a284b7f253 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 30 Oct 2021 09:04:50 +0000 Subject: css fixes --- include/permissions.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/permissions.php b/include/permissions.php index 33b385490..9e432ce51 100644 --- a/include/permissions.php +++ b/include/permissions.php @@ -50,6 +50,7 @@ function get_all_perms($uid, $observer_xchan, $check_siteblock = true, $default_ // First find out what the channel owner declared permissions to be. $channel_perm = intval(\Zotlabs\Access\PermissionLimits::Get($uid,$perm_name)); +hz_syslog(print_r($channel_perm,true)); if(! $channel_checked) { $r = q("select * from channel where channel_id = %d limit 1", @@ -242,6 +243,7 @@ function get_all_perms($uid, $observer_xchan, $check_siteblock = true, $default_ call_hooks('get_all_perms',$arr); + return $arr['permissions']; } -- cgit v1.2.3 From 17bd36461425b48c168d122543d30264646ba8b6 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 30 Oct 2021 09:07:56 +0000 Subject: remove logging --- include/permissions.php | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/permissions.php b/include/permissions.php index 9e432ce51..d94b70da6 100644 --- a/include/permissions.php +++ b/include/permissions.php @@ -50,7 +50,6 @@ function get_all_perms($uid, $observer_xchan, $check_siteblock = true, $default_ // First find out what the channel owner declared permissions to be. $channel_perm = intval(\Zotlabs\Access\PermissionLimits::Get($uid,$perm_name)); -hz_syslog(print_r($channel_perm,true)); if(! $channel_checked) { $r = q("select * from channel where channel_id = %d limit 1", -- cgit v1.2.3