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/items.php') 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