From 3d264f5a55f340e3c20c1181c8b4578abecf3f1c Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 3 Mar 2021 12:39:41 +0000 Subject: php8: fix warnings during install procedure (cherry picked from commit 48bae9d4219735bc44f4ee72228d19d3e6b9efc9) --- include/account.php | 12 +++++++----- include/channel.php | 10 +++++----- include/environment.php | 9 +++++---- include/language.php | 14 +++++++++----- include/permissions.php | 25 +++++++++++++------------ 5 files changed, 39 insertions(+), 31 deletions(-) (limited to 'include') diff --git a/include/account.php b/include/account.php index 34936c33f..fefe61d15 100644 --- a/include/account.php +++ b/include/account.php @@ -605,8 +605,8 @@ function account_approve($hash) { */ function downgrade_accounts() { - $r = q("select * from account where not ( account_flags & %d ) > 0 - and account_expires > '%s' + $r = q("select * from account where not ( account_flags & %d ) > 0 + and account_expires > '%s' and account_expires < %s ", intval(ACCOUNT_EXPIRED), dbesc(NULL_DATE), @@ -746,8 +746,8 @@ function service_class_fetch($uid, $property) { $service_class = App::$account['account_service_class']; } else { - $r = q("select account_service_class as service_class - from channel c, account a + $r = q("select account_service_class as service_class + from channel c, account a where c.channel_account_id=a.account_id and c.channel_id= %d limit 1", intval($uid) ); @@ -780,6 +780,8 @@ function service_class_fetch($uid, $property) { */ function account_service_class_fetch($aid, $property) { + $service_class = null; + $r = q("select account_service_class as service_class from account where account_id = %d limit 1", intval($aid) ); @@ -787,7 +789,7 @@ function account_service_class_fetch($aid, $property) { $service_class = $r[0]['service_class']; } - if(! x($service_class)) + if(! isset($service_class)) return false; // everything is allowed $arr = get_config('service_class', $service_class); diff --git a/include/channel.php b/include/channel.php index c6ca673eb..d1095115d 100644 --- a/include/channel.php +++ b/include/channel.php @@ -303,8 +303,8 @@ function create_identity($arr) { $photo_type = null; $z = [ - 'account' => $a[0], - 'channel' => $r[0], + 'account' => $a[0] ?? [], + 'channel' => $r[0] ?? [], 'photo_url' => '' ]; /** @@ -1098,11 +1098,11 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals // @fixme - Not totally certain how to handle $zot_compat for the event timezone which exists // in Hubzilla but is stored with the item and not the event. In Zap, stored information is - // always UTC and localised on access as per standard conventions for working with global time data. + // always UTC and localised on access as per standard conventions for working with global time data. // Older Zot (pre-Zot6) records aren't translated correctly w/r/t AS2 so only include events for the last year or so if - // migrating to Zap. - + // migrating to Zap. + $sqle = (($zap_compat) ? " and created > '2020-01-01 00:00:00' " : ''); $r = q("select * from event where uid = %d $sqle", diff --git a/include/environment.php b/include/environment.php index 96a614821..274eca214 100644 --- a/include/environment.php +++ b/include/environment.php @@ -52,17 +52,18 @@ function getPhpiniUploadLimits() { */ function phpiniSizeToBytes($val) { $val = trim($val); + $num = (double)$val; $unit = strtolower($val[strlen($val)-1]); switch($unit) { case 'g': - $val *= 1024; + $num *= 1024; case 'm': - $val *= 1024; + $num *= 1024; case 'k': - $val *= 1024; + $num *= 1024; default: break; } - return (int)$val; + return (int)$num; } diff --git a/include/language.php b/include/language.php index 622b9614d..d291deb63 100644 --- a/include/language.php +++ b/include/language.php @@ -77,7 +77,7 @@ function get_best_language() { if(! isset($preferred)) { /* - * We could find no perfect match for any of the preferred languages. + * We could find no perfect match for any of the preferred languages. * For cases where the preference is fr-fr and we have fr but *not* fr-fr * run the test again and only look for the language base * which should provide an interface they can sort of understand @@ -262,11 +262,15 @@ function tt($singular, $plural, $count, $ctx = ''){ * @return string */ function ta($k){ + $t = null; - $t = App::$strings[$k]; - if (is_array($t)) - $t = implode("/", $t); - return ($t == "" ? $k : $t); + if(isset(App::$strings[$k])) + $t = App::$strings[$k]; + + if (is_array($t)) + $t = implode("/", $t); + + return ($t == "" ? $k : $t); } /** diff --git a/include/permissions.php b/include/permissions.php index c7eee11f4..9dd503132 100644 --- a/include/permissions.php +++ b/include/permissions.php @@ -6,7 +6,7 @@ require_once('include/security.php'); * @file include/permissions.php * * This file conntains functions to check and work with permissions. - * + * */ @@ -27,7 +27,7 @@ function get_all_perms($uid, $observer_xchan, $check_siteblock = true, $default_ $api = App::get_oauth_key(); if($api) - return get_all_api_perms($uid,$api); + return get_all_api_perms($uid,$api); $global_perms = \Zotlabs\Access\Permissions::Perms(); @@ -210,7 +210,7 @@ function get_all_perms($uid, $observer_xchan, $check_siteblock = true, $default_ $ret[$perm_name] = false; continue; } - + $ret[$perm_name] = true; continue; } @@ -294,14 +294,14 @@ function perm_is_allowed($uid, $observer_xchan, $permission, $check_siteblock = if($channel_perm & PERMS_AUTHED) return true; - $x = q("select abook_my_perms, abook_blocked, abook_ignored, abook_pending, xchan_network from abook left join xchan on abook_xchan = xchan_hash + $x = q("select abook_my_perms, abook_blocked, abook_ignored, abook_pending, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_xchan = '%s' and abook_self = 0 limit 1", intval($uid), dbesc($observer_xchan) ); // If they're blocked - they can't read or write - + if(($x) && intval($x[0]['abook_blocked'])) return false; @@ -324,9 +324,9 @@ function perm_is_allowed($uid, $observer_xchan, $permission, $check_siteblock = // This requires an explanation and the effects are subtle. // The following line creates a fake connection, and this allows - // access tokens to have specific permissions even though they are + // access tokens to have specific permissions even though they are // not actual connections. - // The existence of this fake entry must be checked when dealing + // The existence of this fake entry must be checked when dealing // with connection related permissions. $x = array(pseudo_abook($y[0])); @@ -343,7 +343,7 @@ function perm_is_allowed($uid, $observer_xchan, $permission, $check_siteblock = return false; // Check if this $uid is actually the $observer_xchan - // you will have full access unless the channel was moved - + // you will have full access unless the channel was moved - // in which case you will have read_only access if($r[0]['channel_hash'] === $observer_xchan) { @@ -366,7 +366,7 @@ function perm_is_allowed($uid, $observer_xchan, $permission, $check_siteblock = // If we're still here, we have an observer, check the network. if($channel_perm & PERMS_NETWORK) { - if ($x && in_array($x[0]['xchan_network'], ['zot','zot6'])) + if ($x && in_array($x[0]['xchan_network'], ['zot','zot6'])) return true; } @@ -382,7 +382,7 @@ function perm_is_allowed($uid, $observer_xchan, $permission, $check_siteblock = return false; } - // From here on we require that the observer be a connection or pseudo connection + // From here on we require that the observer be a connection or pseudo connection if(! $x) { return false; @@ -425,7 +425,7 @@ function perm_is_allowed($uid, $observer_xchan, $permission, $check_siteblock = return false; } -function get_all_api_perms($uid,$api) { +function get_all_api_perms($uid,$api) { $global_perms = \Zotlabs\Access\Permissions::Perms(); @@ -541,7 +541,8 @@ function site_default_perms() { 'write_pages' => PERMS_SPECIFIC, 'write_wiki' => PERMS_SPECIFIC, 'delegate' => PERMS_SPECIFIC, - 'post_like' => PERMS_NETWORK + 'republish' => PERMS_SPECIFIC, + 'post_like' => PERMS_NETWORK, ); $global_perms = \Zotlabs\Access\Permissions::Perms(); -- cgit v1.2.3 From 7d1599f9b0bd8ead7a0652ceca494fc38a28fd82 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 3 Mar 2021 12:44:38 +0000 Subject: group_add(): return hash if success (cherry picked from commit f8f15f526f68073baa1e4e846ab87a66c2d5b291) --- include/group.php | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'include') diff --git a/include/group.php b/include/group.php index efda389d6..bb1ed5ed8 100644 --- a/include/group.php +++ b/include/group.php @@ -4,23 +4,23 @@ use Zotlabs\Lib\Libsync; function group_add($uid,$name,$public = 0) { - $ret = false; + $success = false; if(x($uid) && x($name)) { $r = group_byname($uid,$name); // check for dups if($r !== false) { - // This could be a problem. + // This could be a problem. // Let's assume we've just created a group which we once deleted // all the old members are gone, but the group remains so we don't break any security // access lists. What we're doing here is reviving the dead group, but old content which - // was restricted to this group may now be seen by the new group members. + // was restricted to this group may now be seen by the new group members. $z = q("SELECT * FROM pgrp WHERE id = %d LIMIT 1", intval($r) ); if(($z) && $z[0]['deleted']) { q('UPDATE pgrp SET deleted = 0 WHERE id = %d', intval($z[0]['id'])); - notice( t('A deleted group with this name was revived. Existing item permissions may apply to this group and any future members. If this is not what you intended, please create another group with a different name.') . EOL); + notice( t('A deleted group with this name was revived. Existing item permissions may apply to this group and any future members. If this is not what you intended, please create another group with a different name.') . EOL); } return true; } @@ -42,12 +42,18 @@ function group_add($uid,$name,$public = 0) { intval($public), dbesc($name) ); - $ret = $r; - } - Libsync::build_sync_packet($uid,null,true); + if($r) + $success = true; + } - return $ret; + + if($success) { + Libsync::build_sync_packet($uid,null,true); + return $hash; + } + + return false; } @@ -88,7 +94,7 @@ function group_rmv($uid,$name) { } if($change) { - q("UPDATE channel SET channel_default_group = '%s', channel_allow_gid = '%s', channel_deny_gid = '%s' + q("UPDATE channel SET channel_default_group = '%s', channel_allow_gid = '%s', channel_deny_gid = '%s' WHERE channel_id = %d", intval($user_info['channel_default_group']), dbesc($user_info['channel_allow_gid']), @@ -159,7 +165,7 @@ function group_rmv_member($uid,$name,$member) { Libsync::build_sync_packet($uid,null,true); return $r; - + } @@ -170,13 +176,13 @@ function group_add_member($uid,$name,$member,$gid = 0) { if((! $gid) || (! $uid) || (! $member)) return false; - $r = q("SELECT * FROM pgrp_member WHERE uid = %d AND gid = %d AND xchan = '%s' LIMIT 1", + $r = q("SELECT * FROM pgrp_member WHERE uid = %d AND gid = %d AND xchan = '%s' LIMIT 1", intval($uid), intval($gid), dbesc($member) ); if($r) - return true; // You might question this, but + return true; // You might question this, but // we indicate success because the group member was in fact created // -- It was just created at another time if(! $r) @@ -195,7 +201,7 @@ function group_add_member($uid,$name,$member,$gid = 0) { function group_get_members($gid) { $ret = array(); if(intval($gid)) { - $r = q("SELECT * FROM pgrp_member + $r = q("SELECT * FROM pgrp_member LEFT JOIN abook ON abook_xchan = pgrp_member.xchan left join xchan on xchan_hash = abook_xchan WHERE gid = %d AND abook_channel = %d and pgrp_member.uid = %d and xchan_deleted = 0 and abook_self = 0 and abook_blocked = 0 and abook_pending = 0 ORDER BY xchan_name ASC ", intval($gid), @@ -245,7 +251,7 @@ function group_get_profile_members_xchan($uid,$gid) { function mini_group_select($uid,$group = '') { - + $grps = array(); $o = ''; @@ -263,7 +269,7 @@ function mini_group_select($uid,$group = '') { $o = replace_macros(get_markup_template('group_selection.tpl'), array( '$label' => t('Add new connections to this privacy group'), - '$groups' => $grps + '$groups' => $grps )); return $o; } @@ -287,12 +293,12 @@ function group_side($every="connections",$each="group",$edit = false, $group_id $member_of = array(); if($cid) { $member_of = groups_containing(local_channel(),$cid); - } + } if($r) { foreach($r as $rr) { $selected = (($group_id == $rr['id']) ? ' group-selected' : ''); - + if ($edit) { $groupedit = array( 'href' => "group/".$rr['id'], @@ -301,7 +307,7 @@ function group_side($every="connections",$each="group",$edit = false, $group_id } else { $groupedit = null; } - + $groups[] = array( 'id' => $rr['id'], 'enc_cid' => base64url_encode($cid), @@ -314,8 +320,8 @@ function group_side($every="connections",$each="group",$edit = false, $group_id ); } } - - + + $tpl = get_markup_template("group_side.tpl"); $o = replace_macros($tpl, array( '$title' => t('Privacy Groups'), @@ -325,8 +331,8 @@ function group_side($every="connections",$each="group",$edit = false, $group_id '$groups' => $groups, '$add' => t('add'), )); - - + + return $o; } @@ -356,7 +362,7 @@ function expand_groups($g) { else { $x[] = $gv; } - } + } if($x) { stringify_array_elms($x,true); -- cgit v1.2.3 From c2dc3e8dec7acf1f1750f7379e641ae8c7a2ed81 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 3 Mar 2021 13:09:17 +0000 Subject: set the default collection acl if indicated so by the role permissions but always set the created friends group as channel_default_group when creating a new channel (cherry picked from commit 9389abdb757d5cb5b4b4322260e86c47d11ff043) --- include/channel.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index d1095115d..4f48402d2 100644 --- a/include/channel.php +++ b/include/channel.php @@ -503,23 +503,22 @@ function create_identity($arr) { // right away as a default group for new contacts. require_once('include/group.php'); - group_add($newuid, t('Friends')); - group_add_member($newuid,t('Friends'),$ret['channel']['channel_hash']); + $group_hash = group_add($newuid, t('Friends')); - // if our role_permissions indicate that we're using a default collection ACL, add it. + if($group_hash) { + group_add_member($newuid,t('Friends'),$ret['channel']['channel_hash']); - if(is_array($role_permissions) && $role_permissions['default_collection']) { - $r = q("select hash from pgrp where uid = %d and gname = '%s' limit 1", - intval($newuid), - dbesc( t('Friends') ) - ); - if($r) { - q("update channel set channel_default_group = '%s', channel_allow_gid = '%s' where channel_id = %d", - dbesc($r[0]['hash']), - dbesc('<' . $r[0]['hash'] . '>'), - intval($newuid) - ); + $default_collection = ''; + // if our role_permissions indicate that we're using a default collection ACL, add it. + if(is_array($role_permissions) && $role_permissions['default_collection']) { + $default_collection_str = '<' . $group_hash . '>'; } + + q("update channel set channel_default_group = '%s', channel_allow_gid = '%s' where channel_id = %d", + dbesc($group_hash), + dbesc($default_collection_str), + intval($newuid) + ); } if(! $system) { -- cgit v1.2.3 From 7460b1eecbb1d4eb7937ab551f7d4b333eba5a38 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 6 Mar 2021 08:50:36 +0000 Subject: fix varable name and more changelog --- 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 4f48402d2..ecb7c24f7 100644 --- a/include/channel.php +++ b/include/channel.php @@ -508,7 +508,7 @@ function create_identity($arr) { if($group_hash) { group_add_member($newuid,t('Friends'),$ret['channel']['channel_hash']); - $default_collection = ''; + $default_collection_str = ''; // if our role_permissions indicate that we're using a default collection ACL, add it. if(is_array($role_permissions) && $role_permissions['default_collection']) { $default_collection_str = '<' . $group_hash . '>'; -- cgit v1.2.3 From 0c5a7ab19b9ccb76aebe006626bacb35b1e1c66b Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 8 Mar 2021 19:16:41 +0000 Subject: Define $sql_extra2 variable before concatenation --- include/taxonomy.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/taxonomy.php b/include/taxonomy.php index 5fa4fde3f..19a843cc4 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -331,11 +331,12 @@ function pubtagblock($net,$site,$limit,$recent = 0,$safemode = 1, $type = TERM_H } -function pub_tagadelic($net,$site,$limit,$recent,$safemode,$type) { +function pub_tagadelic($net, $site, $limit, $recent, $safemode, $type) { $item_normal = item_normal(); $count = intval($limit); + $sql_extra = ""; if($site) $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; else { -- cgit v1.2.3 From c9ec5043b9d1638da9ea1d66b55a84c961920ec1 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 8 Mar 2021 19:22:17 +0000 Subject: Check if HTTP port is defined --- include/queue_fn.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/queue_fn.php b/include/queue_fn.php index b72730d2f..b505a5b22 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -132,7 +132,7 @@ function queue_deliver($outq, $immediate = false) { $base = null; $h = parse_url($outq['outq_posturl']); if($h !== false) - $base = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : ''); + $base = $h['scheme'] . '://' . $h['host'] . (array_key_exists('port', $h) ? ':' . $h['port'] : ''); if(($base) && ($base !== z_root()) && ($immediate)) { $y = q("select site_update, site_dead from site where site_url = '%s' ", -- cgit v1.2.3 From 1ad6308f979572343cffdce83638273a6e210f28 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 8 Mar 2021 20:43:29 +0000 Subject: Formatting --- include/taxonomy.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/taxonomy.php b/include/taxonomy.php index 19a843cc4..f765a9f0e 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -332,11 +332,10 @@ function pubtagblock($net,$site,$limit,$recent = 0,$safemode = 1, $type = TERM_H function pub_tagadelic($net, $site, $limit, $recent, $safemode, $type) { - - $item_normal = item_normal(); - $count = intval($limit); - - $sql_extra = ""; + + $item_normal = item_normal(); + $count = intval($limit); + $sql_extra = ""; if($site) $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; else { -- cgit v1.2.3 From 975d8ef0c7fba8fdc26f29dae9cd47c7f6079e67 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 9 Mar 2021 09:06:16 +0000 Subject: Fix deprecated function arguments order --- include/items.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 88f100e60..a1198bb4d 100644 --- a/include/items.php +++ b/include/items.php @@ -4853,7 +4853,7 @@ function item_remove_cid($xchan_hash,$mid,$uid) { } // Set item permissions based on results obtained from linkify_tags() -function set_linkified_perms($linkified, &$str_contact_allow, &$str_group_allow, $profile_uid, $parent_item = false, &$private) { +function set_linkified_perms($linkified, &$str_contact_allow, &$str_group_allow, $profile_uid, &$private, $parent_item = false) { $first_access_tag = true; foreach($linkified as $x) { -- cgit v1.2.3 From bdae290ec4477d9894aca65c59bbebe32fbe7e4e Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 9 Mar 2021 11:05:43 +0000 Subject: Revert "More checks on note decoding" This reverts commit 20199f7aee34dbc7a8aebcd459ef6cb84cdb5bd7 --- include/text.php | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index ca3453b64..1cfee4c87 100644 --- a/include/text.php +++ b/include/text.php @@ -1542,39 +1542,46 @@ function unobscure_mail(&$item) { function theme_attachments(&$item) { + $s = ''; $arr = json_decode($item['attach'],true); - if(is_array($arr) && count($arr)) { - $attaches = array(); + + $attaches = []; foreach($arr as $r) { - $icon = getIconFromType($r['type']); + if(isset($r['type'])) + $icon = getIconFromType($r['type']); - if($r['title']) + if(isset($r['title'])) $label = urldecode(htmlspecialchars($r['title'], ENT_COMPAT, 'UTF-8')); - if(! $label && $r['href']) + if(! $label && isset($r['href'])) $label = basename($r['href']); //some feeds provide an attachment where title an empty space if(! $label || $label == ' ') $label = t('Unknown Attachment'); - $title = t('Size') . ' ' . (($r['length']) ? userReadableSize($r['length']) : t('unknown')); + $title = t('Size') . ' ' . (isset($r['length']) ? userReadableSize($r['length']) : t('unknown')); require_once('include/channel.php'); - if(is_foreigner($item['author_xchan'])) - $url = $r['href']; - else - $url = z_root() . '/magic?f=&owa=1&hash=' . $item['author_xchan'] . '&bdest=' . bin2hex($r['href'] . '/' . $r['revision']); + + if (isset($r['href'])) { + if(is_foreigner($item['author_xchan'])) + $url = $r['href']; + else + $url = z_root() . '/magic?f=&owa=1&hash=' . $item['author_xchan'] . '&bdest=' . bin2hex($r['href'] . '/' . $r['revision']); + } //$s .= '' . $icon . ''; - $attaches[] = array('label' => $label, 'url' => $url, 'icon' => $icon, 'title' => $title); + if (isset($label) && isset($url) && isset($icon) && isset($title)) + $attaches[] = array('label' => $label, 'url' => $url, 'icon' => $icon, 'title' => $title); } - $s = replace_macros(get_markup_template('item_attach.tpl'), array( - '$attaches' => $attaches - )); + if (count($attaches) > 0) + $s = replace_macros(get_markup_template('item_attach.tpl'), [ + '$attaches' => $attaches + ]); } return $s; @@ -1612,8 +1619,8 @@ function format_categories(&$item,$writeable) { */ function format_hashtags(&$item) { - $s = ''; + $s = ''; $terms = get_terms_oftype($item['term'], array(TERM_HASHTAG,TERM_COMMUNITYTAG)); if($terms) { foreach($terms as $t) { @@ -1635,13 +1642,14 @@ function format_hashtags(&$item) { } - function format_mentions(&$item) { - $s = ''; + $s = ''; $terms = get_terms_oftype($item['term'],TERM_MENTION); if($terms) { foreach($terms as $t) { + if(! isset($t['term'])) + continue; $term = htmlspecialchars($t['term'],ENT_COMPAT,'UTF-8',false) ; if(! trim($term)) continue; -- cgit v1.2.3 From 15faf01ec960fff88a1f9c83fb6d251319cecea7 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 10 Mar 2021 11:09:49 +0000 Subject: do not parse bbcode in summary - issue #1532 --- include/bbcode.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index a5ef6760b..388a828c4 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -151,6 +151,18 @@ function bb_spacefy($st) { return $new_str; } +// The previously spacefied [noparse][ i ]italic[ /i ][/noparse], +// now turns back returning [noparse][i]italic[/i][/noparse] +function bb_unspacefy($st) { + $whole_match = $st[0]; + $captured = $st[1]; + $spacefied = preg_replace("/\[ (.*?) \]/", "[$1]", $captured); + $new_str = str_replace($captured, $spacefied, $whole_match); + + return $new_str; +} + + // The previously spacefied [noparse][ i ]italic[ /i ][/noparse], // now turns back and the [noparse] tags are trimmed // returning [i]italic[/i] @@ -1097,6 +1109,9 @@ function bbcode($Text, $options = []) { 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); + } $Text = bb_format_attachdata($Text); @@ -1438,11 +1453,6 @@ function bbcode($Text, $options = []) { $Text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/sm", "$2", $Text); } - - if(strpos($Text,'[/summary]') !== false) { - $Text = preg_replace_callback("/^(.*?)\[summary\](.*?)\[\/summary\](.*?)$/is", 'bb_summary', $Text); - } - // Check for [spoiler] text $endlessloop = 0; while ((strpos($Text, "[/spoiler]")!== false) and (strpos($Text, "[spoiler]") !== false) and (++$endlessloop < 20)) { @@ -1611,6 +1621,13 @@ function bbcode($Text, $options = []) { } + if (strpos($Text,'[summary]') !== false) { + $Text = preg_replace_callback("/\[summary\](.*?)\[\/summary\]/ism", 'bb_unspacefy',$Text); + } + if(strpos($Text,'[/summary]') !== false) { + $Text = preg_replace_callback("/^(.*?)\[summary\](.*?)\[\/summary\](.*?)$/is", 'bb_summary', $Text); + } + // Unhide all [noparse] contained bbtags unspacefying them // and triming the [noparse] tag. if (strpos($Text,'[noparse]') !== false) { -- cgit v1.2.3 From 11d831e4d7bd4163ea518892f541252ce1acea2e Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Wed, 10 Mar 2021 11:14:02 +0000 Subject: More PHP 8 fixes --- include/html2plain.php | 47 +++++++++++++++++++++++++++++++++-------------- include/network.php | 12 ++++++++---- 2 files changed, 41 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/include/html2plain.php b/include/html2plain.php index 91a1f14cb..bf8581bdb 100644 --- a/include/html2plain.php +++ b/include/html2plain.php @@ -76,28 +76,47 @@ function quotelevel($message, $wraplength = 75) return(implode("\n", $newlines)); } + function collecturls($message) { + $pattern = '/(.*?)<\/a>/is'; preg_match_all($pattern, $message, $result, PREG_SET_ORDER); - - $urls = array(); - foreach ($result as $treffer) { - // A list of some links that should be ignored - $list = array("/user/", "/tag/", "/group/", "/profile/", "/channel/", "/search?search=", "/search?tag=", "mailto:", "/u/", "/node/", - "//facebook.com/profile.php?id=", "//plus.google.com/"); - foreach ($list as $listitem) - if (strpos($treffer[1], $listitem) !== false) - $ignore = true; - - if ((strpos($treffer[1], "//plus.google.com/") !== false) and (strpos($treffer[1], "/posts") !== false)) + + $urls = []; + if ($result) { + $ignore = false; + foreach ($result as $treffer) { + // A list of some links that should be ignored + $list = [ + "/user/", + "/tag/", + "/group/", + "/profile/", + "/channel/", + "/search?search=", + "/search?tag=", + "mailto:", + "/u/", + "/node/", + "//facebook.com/profile.php?id=", + "//plus.google.com/" + ]; + foreach ($list as $listitem) + if (strpos($treffer[1], $listitem) !== false) + $ignore = true; + + if ((strpos($treffer[1], "//plus.google.com/") !== false) and (strpos($treffer[1], "/posts") !== false)) $ignore = false; - - if (!$ignore) - $urls[$treffer[1]] = $treffer[1]; + + if (! $ignore) + $urls[$treffer[1]] = $treffer[1]; + } } + return($urls); } + function html2plain($html, $wraplength = 75, $compact = false) { diff --git a/include/network.php b/include/network.php index f5ff48fce..fcc7b4289 100644 --- a/include/network.php +++ b/include/network.php @@ -1134,11 +1134,15 @@ function discover_by_webbie($webbie, $protocol = '') { foreach($x['links'] as $link) { if(array_key_exists('rel',$link)) { if($link['rel'] === PROTOCOL_ZOT6 && ((! $protocol) || (strtolower($protocol) === 'zot6'))) { + logger('zot6 found for ' . $webbie, LOGGER_DEBUG); $record = Zotfinger::exec($link['href']); + if (! $record) { + logger('Record not found for ' . $link['href']); + continue; + } // Check the HTTP signature - $hsig = $record['signature']; if($hsig && $hsig['signer'] === $link['href'] && $hsig['header_valid'] === true && $hsig['content_valid'] === true) $hsig_valid = true; @@ -1226,7 +1230,7 @@ function webfinger_rfc7033($webbie, $zot = false) { if($m['scheme'] !== 'https') return false; - $rhs = $m['host'] . (($m['port']) ? ':' . $m['port'] : ''); + $rhs = $m['host'] . (array_key_exists('port', $m) ? ':' . $m['port'] : ''); $resource = urlencode($webbie); } } @@ -1957,10 +1961,10 @@ function service_plink($contact, $guid) { $m = parse_url($contact['xchan_url']); if($m) { - $url = $m['scheme'] . '://' . $m['host'] . (($m['port']) ? ':' . $m['port'] : ''); + $url = $m['scheme'] . '://' . $m['host'] . (array_key_exists('port', $m) ? ':' . $m['port'] : ''); } else { - $url = 'https://' . substr($contact['xchan_addr'],strpos($contact['xchan_addr'],'@')+1); + $url = 'https://' . substr($contact['xchan_addr'], strpos($contact['xchan_addr'], '@') + 1); } $handle = substr($contact['xchan_addr'], 0, strpos($contact['xchan_addr'],'@')); -- cgit v1.2.3 From f8447521a84c0eb30c08da212e8156256558617b Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 10 Mar 2021 13:16:08 +0000 Subject: php8: random fixes deriving from mod network --- include/conversation.php | 6 +++--- include/items.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index ae69b7a01..f3e5fafa7 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -865,7 +865,7 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa $x = [ 'mode' => $mode, 'item' => $item ]; call_hooks('stream_item',$x); - if($x['item']['blocked']) + if(isset($x['item']['blocked'])) continue; $item = $x['item']; @@ -1563,7 +1563,7 @@ function sort_item_children($items) { $result = $items; usort($result,'sort_thr_created_rev'); foreach($result as $k => $i) { - if($result[$k]['children']) { + if(isset($result[$k]['children'])) { $result[$k]['children'] = sort_item_children($result[$k]['children']); } } @@ -1573,7 +1573,7 @@ function sort_item_children($items) { function add_children_to_list($children, &$arr) { foreach($children as $y) { $arr[] = $y; - if($y['children']) + if(isset($y['children'])) add_children_to_list($y['children'], $arr); } } diff --git a/include/items.php b/include/items.php index a1198bb4d..c6a5f40a6 100644 --- a/include/items.php +++ b/include/items.php @@ -1432,7 +1432,7 @@ function purify_imported_object($obj) { elseif (is_string($obj)) { $ret = purify_html($obj); } - + return $ret; } @@ -4334,8 +4334,8 @@ function fetch_post_tags($items, $link = false) { foreach($imeta as $i) { if(array_key_exists('item_id',$items[$x])) { if($i['iid'] == $items[$x]['item_id']) { - if(! is_array($items[$x]['iconfig'])) - $items[$x]['iconfig'] = array(); + if(! isset($items[$x]['iconfig'])) + $items[$x]['iconfig'] = []; $i['v'] = ((preg_match('|^a:[0-9]+:{.*}$|s',$i['v'])) ? unserialize($i['v']) : $i['v']); $items[$x]['iconfig'][] = $i; } -- cgit v1.2.3 From 9098bb431cefa0a865938d866a7f34396e21a154 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Wed, 10 Mar 2021 19:44:17 +0000 Subject: Check for HTTP port use --- include/bookmarks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bookmarks.php b/include/bookmarks.php index 145119347..207cf5a33 100644 --- a/include/bookmarks.php +++ b/include/bookmarks.php @@ -73,6 +73,6 @@ function get_bookmark_link($observer) { $h = @parse_url($observer['xchan_url']); if($h) - return $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : '') . '/rbmark?f='; + return $h['scheme'] . '://' . $h['host'] . (isset($h['port']) ? ':' . $h['port'] : '') . '/rbmark?f='; return ''; } -- cgit v1.2.3 From f8467845d208c0efde81d00d51cd0eb10637f6d5 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Wed, 10 Mar 2021 19:44:54 +0000 Subject: Check for HTTP port use --- include/queue_fn.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/queue_fn.php b/include/queue_fn.php index b505a5b22..1e8171b1d 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -132,7 +132,7 @@ function queue_deliver($outq, $immediate = false) { $base = null; $h = parse_url($outq['outq_posturl']); if($h !== false) - $base = $h['scheme'] . '://' . $h['host'] . (array_key_exists('port', $h) ? ':' . $h['port'] : ''); + $base = $h['scheme'] . '://' . $h['host'] . (isset($h['port']) ? ':' . $h['port'] : ''); if(($base) && ($base !== z_root()) && ($immediate)) { $y = q("select site_update, site_dead from site where site_url = '%s' ", -- cgit v1.2.3 From 260c518562f6402fea563cbd6988efbd05abd10a Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 10 Mar 2021 20:44:20 +0000 Subject: if rewriting the mid also rewrite the llink --- include/items.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index c6a5f40a6..d781ff8b8 100644 --- a/include/items.php +++ b/include/items.php @@ -3253,6 +3253,7 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $group = false $item['mid'] = z_root() . '/item/' . $item['uuid']; $item['parent_mid'] = $item['mid']; $item['thr_parent'] = $item['mid']; + $item['llink'] = z_root() . '/display/' . gen_link_id($item['mid']); } $r = q("UPDATE item SET author_xchan = '%s', mid = '%s', parent_mid = '%s', thr_parent = '%s' WHERE id = %d", -- cgit v1.2.3 From db0e1c9f31022453d44e68183673c55c8f880b3e Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 11 Mar 2021 08:25:26 +0000 Subject: save the rewritten llink --- include/items.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index d781ff8b8..a4b026e2e 100644 --- a/include/items.php +++ b/include/items.php @@ -3256,11 +3256,12 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $group = false $item['llink'] = z_root() . '/display/' . gen_link_id($item['mid']); } - $r = q("UPDATE item SET author_xchan = '%s', mid = '%s', parent_mid = '%s', thr_parent = '%s' WHERE id = %d", + $r = q("UPDATE item SET author_xchan = '%s', mid = '%s', parent_mid = '%s', thr_parent = '%s', llink = '%s' WHERE id = %d", dbesc($item['author_xchan']), dbesc($item['mid']), dbesc($item['parent_mid']), dbesc($item['thr_parent']), + dbesc($item['llink']), intval($item_id) ); } -- cgit v1.2.3 From f980c2e3de0339536d58c9ba91799106074b239e Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 11 Mar 2021 13:03:54 +0000 Subject: php8: daily warning fixes (deriving from mod network) --- include/acl_selectors.php | 9 +++++---- include/text.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 8da46649c..f158a439b 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -63,6 +63,7 @@ function populate_acl($defaults = null,$show_jotnets = true, $emptyACL_descripti $single_group = false; $just_me = false; $custom = false; + $groups = ''; if($allow_cid || $allow_gid || $deny_gid || $deny_cid) { $has_acl = true; @@ -112,11 +113,11 @@ function populate_acl($defaults = null,$show_jotnets = true, $emptyACL_descripti $forums_count = 0; $forum_otions = ''; foreach($forums as $f) { - if($f['no_post_perms']) + if(isset($f['no_post_perms'])) continue; - $private = (($f['private_forum']) ? ' (' . t('Private Forum') . ')' : ''); - $selected = (($single_group && $f['hash'] === $allow_cid[0]) ? ' selected = "selected" ' : ''); + $private = ((isset($f['private_forum'])) ? ' (' . t('Private Forum') . ')' : ''); + $selected = (($single_group && isset($f['hash'], $allow_cid[0]) && $f['hash'] === $allow_cid[0]) ? ' selected = "selected" ' : ''); $forum_otions .= '' . "\r\n"; $forums_count++; } @@ -133,7 +134,7 @@ function populate_acl($defaults = null,$show_jotnets = true, $emptyACL_descripti $o = replace_macros($tpl, array( '$showall' => $showall_caption, '$onlyme' => t('Only me'), - '$groups' => $groups, + '$groups' => $groups, '$public_selected' => (($has_acl) ? false : true), '$justme_selected' => $just_me, '$custom_selected' => $custom, diff --git a/include/text.php b/include/text.php index 1cfee4c87..85950c58b 100644 --- a/include/text.php +++ b/include/text.php @@ -3691,7 +3691,7 @@ function get_forum_channels($uid) { if(! $uid) return; - if(App::$data['forum_channels']) + if(isset(App::$data['forum_channels'])) return App::$data['forum_channels']; $xf = ''; -- cgit v1.2.3 From 024b489af9b5fadc776aa51b135cd6ed306b07b6 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 11 Mar 2021 17:51:13 +0000 Subject: Stricter item array checks --- include/items.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index a4b026e2e..26d009b55 100644 --- a/include/items.php +++ b/include/items.php @@ -1206,10 +1206,10 @@ function encode_item($item,$mirror = false,$zap_compat = false) { else $x['comment_scope'] = $c_scope; - if($item['term']) - $x['tags'] = encode_item_terms($item['term'],$mirror); + if(! empty($item['term'])) + $x['tags'] = encode_item_terms($item['term'],$mirror); - if($item['iconfig']) { + if(! empty($item['iconfig'])) { if ($zap_compat) { for ($y = 0; $y < count($item['iconfig']); $y ++) { if (preg_match('|^a:[0-9]+:{.*}$|s', $item['iconfig'][$y]['v'])) { @@ -1217,7 +1217,7 @@ function encode_item($item,$mirror = false,$zap_compat = false) { } } } - $x['meta'] = encode_item_meta($item['iconfig'],$mirror); + $x['meta'] = encode_item_meta($item['iconfig'],$mirror); } logger('encode_item: ' . print_r($x,true), LOGGER_DATA); @@ -2832,11 +2832,11 @@ function tag_deliver($uid, $item_id) { * Now we've got those out of the way. Let's see if this is a post that's tagged for re-delivery */ - $terms = array_merge(get_terms_oftype($item['term'],TERM_MENTION),get_terms_oftype($item['term'],TERM_FORUM)); - - if($terms) + $terms = []; + if (array_key_exists('term', $item)) { + $terms = array_merge(get_terms_oftype($item['term'],TERM_MENTION),get_terms_oftype($item['term'],TERM_FORUM)); logger('Post mentions: ' . print_r($terms,true), LOGGER_DATA); - + } $max_forums = get_config('system','max_tagged_forums',2); $matched_forums = 0; @@ -2845,7 +2845,7 @@ function tag_deliver($uid, $item_id) { $link = normalise_link($u[0]['xchan_url']); - if($terms) { + if(count($terms) > 0) { foreach($terms as $term) { if(! link_compare($term['url'],$link)) { continue; @@ -4235,9 +4235,9 @@ function list_post_dates($uid, $wall, $mindate) { $start_month = datetime_convert('','',$dstart,'Y-m-d'); $end_month = datetime_convert('','',$dend,'Y-m-d'); $str = day_translate(datetime_convert('','',$dnow,'F')); - if(! $ret[$dyear]) - $ret[$dyear] = array(); - $ret[$dyear][] = array($str,$end_month,$start_month); + if(! isset($ret[$dyear])) + $ret[$dyear] = []; + $ret[$dyear][] = [ $str, $end_month, $start_month ]; $dnow = datetime_convert('','',$dnow . ' -1 month', 'Y-m-d'); } @@ -4316,17 +4316,17 @@ function fetch_post_tags($items, $link = false) { foreach($tags as $t) { if(($link) && ($t['ttype'] == TERM_MENTION)) $t['url'] = chanlink_url($t['url']); - if(array_key_exists('item_id',$items[$x])) { + if(array_key_exists('item_id', $items[$x])) { if($t['oid'] == $items[$x]['item_id']) { - if(! is_array($items[$x]['term'])) - $items[$x]['term'] = array(); + if(array_key_exists('term', $items[$x]) && ! is_array($items[$x]['term'])) + $items[$x]['term'] = []; $items[$x]['term'][] = $t; } } else { if($t['oid'] == $items[$x]['id']) { - if(! is_array($items[$x]['term'])) - $items[$x]['term'] = array(); + if(array_key_exists('term', $items[$x]) && ! is_array($items[$x]['term'])) + $items[$x]['term'] = []; $items[$x]['term'][] = $t; } } @@ -4344,8 +4344,8 @@ function fetch_post_tags($items, $link = false) { } else { if($i['iid'] == $items[$x]['id']) { - if(! is_array($items[$x]['iconfig'])) - $items[$x]['iconfig'] = array(); + if(array_key_exists('iconfig', $items[$x]) && ! is_array($items[$x]['iconfig'])) + $items[$x]['iconfig'] = []; $i['v'] = ((preg_match('|^a:[0-9]+:{.*}$|s',$i['v'])) ? unserialize($i['v']) : $i['v']); $items[$x]['iconfig'][] = $i; } -- cgit v1.2.3