diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/channel.php | 14 | ||||
-rw-r--r-- | include/conversation.php | 20 | ||||
-rw-r--r-- | include/items.php | 52 | ||||
-rw-r--r-- | include/network.php | 2 | ||||
-rw-r--r-- | include/photo/photo_driver.php | 17 | ||||
-rw-r--r-- | include/text.php | 6 |
6 files changed, 57 insertions, 54 deletions
diff --git a/include/channel.php b/include/channel.php index 68e7fdf31..a309fa5c8 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1376,19 +1376,19 @@ function profile_load($nickname, $profile = '') { } // get the current observer - $observer = App::get_observer(); + $observer_hash = get_observer_hash(); $can_view_profile = true; // Can the observer see our profile? require_once('include/permissions.php'); - if(! perm_is_allowed($user[0]['channel_id'],$observer['xchan_hash'],'view_profile')) { + if(! perm_is_allowed($user[0]['channel_id'], $observer_hash, 'view_profile')) { $can_view_profile = false; } - if(! $profile) { + if($observer_hash && !$profile) { $r = q("SELECT abook_profile FROM abook WHERE abook_xchan = '%s' and abook_channel = '%d' limit 1", - dbesc($observer['xchan_hash']), + dbesc($observer_hash), intval($user[0]['channel_id']) ); if($r) @@ -1575,14 +1575,14 @@ function profile_edit_menu($uid) { */ function profile_sidebar($profile, $block = 0, $show_connect = true, $details = false) { - $observer = App::get_observer(); + $observer_hash = get_observer_hash(); $o = ''; $location = false; $pdesc = true; $reddress = true; - if(! perm_is_allowed($profile['uid'],((is_array($observer)) ? $observer['xchan_hash'] : ''),'view_profile')) { + if(! perm_is_allowed($profile['uid'], $observer_hash, 'view_profile')) { $block = true; } @@ -1654,7 +1654,7 @@ function profile_sidebar($profile, $block = 0, $show_connect = true, $details = $menu = get_pconfig($profile['uid'],'system','channel_menu'); if($menu && ! $block) { require_once('include/menu.php'); - $m = menu_fetch($menu,$profile['uid'],$observer['xchan_hash']); + $m = menu_fetch($menu,$profile['uid'], $observer_hash); if($m) $channel_menu = menu_render($m); } diff --git a/include/conversation.php b/include/conversation.php index 7df7b62c2..5f6bc1654 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -106,7 +106,7 @@ function localize_item(&$item){ $author_link = get_rel_link($obj['author']['link'],'alternate'); elseif(isset($obj['actor']) && isset($obj['actor']['url'])) $author_link = ((is_array($obj['actor']['url'])) ? $obj['actor']['url'][0]['href'] : $obj['actor']['url']); - elseif (is_string($obj['actor'])) + elseif (isset($obj['actor']) && is_string($obj['actor'])) $author_link = $obj['actor']; else $author_link = ''; @@ -116,7 +116,7 @@ function localize_item(&$item){ if(!$author_name) $author_name = $obj['actor']['name'] ?? ''; - if(!$author_name && is_string($obj['actor'])) { + if(!$author_name && isset($obj['actor']) && is_string($obj['actor'])) { $cached_actor = Activity::get_cached_actor($obj['actor']); if (is_array($cached_actor)) { $author_name = $cached_actor['name'] ?? $cached_actor['preferredUsername']; @@ -691,7 +691,7 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa ]; call_hooks('stream_item',$x); - if($x['item']['blocked']) + if(isset($x['item']['blocked']) && $x['item']['blocked']) continue; $item = $x['item']; @@ -964,14 +964,12 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa function best_link_url($item) { - - $best_url = ''; + $best_url = $item['author-link'] ?? $item['url'] ?? ''; $sparkle = false; - $clean_url = isset($item['author-link']) ? normalise_link($item['author-link']) : ''; - if((local_channel()) && (local_channel() == $item['uid'])) { - if(isset(App::$contacts) && x(App::$contacts,$clean_url)) { + if($clean_url && local_channel() && (local_channel() == $item['uid'])) { + if(isset(App::$contacts) && x(App::$contacts, $clean_url)) { if(App::$contacts[$clean_url]['network'] === NETWORK_DFRN) { $best_url = z_root() . '/redir/' . App::$contacts[$clean_url]['id']; $sparkle = true; @@ -980,12 +978,6 @@ function best_link_url($item) { $best_url = App::$contacts[$clean_url]['url']; } } - if(! $best_url) { - if($item['author-link']) - $best_url = $item['author-link']; - else - $best_url = $item['url']; - } return $best_url; } diff --git a/include/items.php b/include/items.php index c8b032806..be3c83f7d 100644 --- a/include/items.php +++ b/include/items.php @@ -974,10 +974,10 @@ function import_author_rss($x) { $r = xchan_store_lowlevel( [ - 'xchan_hash' => $x['guid'], - 'xchan_guid' => $x['guid'], - 'xchan_url' => $x['url'], - 'xchan_name' => (($name) ? $name : t('(Unknown)')), + 'xchan_hash' => $x['guid'] ?? '', + 'xchan_guid' => $x['guid'] ?? '', + 'xchan_url' => $x['url'] ?? '', + 'xchan_name' => $name ?? '(Unknown)', 'xchan_name_date' => datetime_convert(), 'xchan_network' => 'rss' ] @@ -3424,7 +3424,7 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $group = false function check_item_source($uid, $item) { logger('source: uid: ' . $uid, LOGGER_DEBUG); - $xchan = (($item['source_xchan'] && intval($item['item_uplink'])) ? $item['source_xchan'] : $item['owner_xchan']); + $xchan = ((isset($item['source_xchan']) && $item['source_xchan'] && isset($item['item_uplink']) && $item['item_uplink']) ? $item['source_xchan'] : $item['owner_xchan']); $r = q("select * from source where src_channel_id = %d and ( src_xchan = '%s' or src_xchan = '*' ) limit 1", intval($uid), @@ -4352,7 +4352,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C ); } - if($arr['uid']) { + if(isset($arr['uid'])) { $uid = $arr['uid']; } @@ -4362,30 +4362,30 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C $item_uids = " item.uid = " . intval($uid) . " "; } - if($arr['top']) + if(isset($arr['top'])) $sql_options .= " and item_thread_top = 1 "; - if($arr['star']) + if(isset($arr['star'])) $sql_options .= " and item_starred = 1 "; - if($arr['wall']) + if(isset($arr['wall'])) $sql_options .= " and item_wall = 1 "; - if($arr['item_id']) + if(isset($arr['item_id'])) $sql_options .= " and parent = " . intval($arr['item_id']) . " "; - if($arr['mid']) + if(isset($arr['mid'])) $sql_options .= " and parent_mid = '" . dbesc($arr['mid']) . "' "; $sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE $item_uids and item_thread_top = 1 $sql_options $item_normal ) "; - if($arr['since_id']) + if(isset($arr['since_id'])) $sql_extra .= " and item.id > " . intval($arr['since_id']) . " "; - if($arr['cat']) + if(isset($arr['cat'])) $sql_extra .= protect_sprintf(term_query('item', $arr['cat'], TERM_CATEGORY)); - if($arr['gid'] && $uid) { + if(isset($arr['gid']) && $uid) { $r = q("SELECT * FROM pgrp WHERE id = %d AND uid = %d LIMIT 1", intval($arr['group']), intval($uid) @@ -4416,7 +4416,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C $x = AccessList::by_hash($uid, $r[0]['hash']); $result['headline'] = sprintf( t('Privacy group: %s'),$x['gname']); } - elseif($arr['cid'] && $uid) { + elseif(isset($arr['cid']) && $uid) { $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_channel = %d and abook_blocked = 0 limit 1", intval($arr['cid']), @@ -4435,14 +4435,14 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C $sql_extra = " AND author_xchan = '" . $channel['channel_hash'] . "' and item_private = 0 $item_normal "; } - if ($arr['datequery']) { + if (isset($arr['datequery'])) { $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert('UTC','UTC',$arr['datequery'])))); } - if ($arr['datequery2']) { + if (isset($arr['datequery2'])) { $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert('UTC','UTC',$arr['datequery2'])))); } - if($arr['search']) { + if(isset($arr['search'])) { if(strpos($arr['search'],'#') === 0) $sql_extra .= term_query('item',substr($arr['search'],1),TERM_HASHTAG,TERM_COMMUNITYTAG); else @@ -4451,11 +4451,11 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C ); } - if($arr['file']) { + if(isset($arr['file'])) { $sql_extra .= term_query('item',$arr['files'],TERM_FILE); } - if($arr['conv'] && $channel) { + if(isset($arr['conv']) && $channel) { $sql_extra .= sprintf(" AND parent IN (SELECT distinct parent from item where ( author_xchan like '%s' or item_mentionsme = 1 )) ", dbesc(protect_sprintf($uidhash)) ); @@ -4465,7 +4465,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C // only setup pagination on initial page view $pager_sql = ''; } else { - if(! $arr['total']) { + if(!isset($arr['total'])) { $itemspage = (($channel) ? get_pconfig($uid,'system','itemspage') : 10); App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 10)); $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start'])); @@ -4505,19 +4505,19 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C require_once('include/security.php'); $sql_extra .= item_permissions_sql($channel['channel_id'],$observer_hash); - if($arr['pages']) + if(isset($arr['pages'])) $item_restrict = " AND item_type = " . ITEM_TYPE_WEBPAGE . " "; else $item_restrict = " AND item_type = 0 "; - if($arr['item_type'] === '*') + if(isset($arr['item_type']) && $arr['item_type'] === '*') $item_restrict = ''; - if ((($arr['compat']) || ($arr['nouveau'] && ($client_mode & CLIENT_MODE_LOAD))) && $channel) { + if (((isset($arr['compat'])) || (isset($arr['nouveau']) && ($client_mode & CLIENT_MODE_LOAD))) && $channel) { // "New Item View" - show all items unthreaded in reverse created date order - if ($arr['total']) { + if (isset($arr['total'])) { $items = dbq("SELECT count(item.id) AS total FROM item WHERE $item_uids $item_restrict $simple_update $sql_options @@ -4544,7 +4544,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C // Normal conversation view - if($arr['order'] === 'post') + if(isset($arr['order']) && $arr['order'] === 'post') $ordering = "created"; else $ordering = "commented"; diff --git a/include/network.php b/include/network.php index a236a6f8e..36859bc2f 100644 --- a/include/network.php +++ b/include/network.php @@ -1997,7 +1997,7 @@ function getBestSupportedMimeType($mimeTypes = null, $acceptedTypes = false) { $AcceptTypes = []; if($acceptedTypes === false) - $acceptedTypes = $_SERVER['HTTP_ACCEPT']; + $acceptedTypes = $_SERVER['HTTP_ACCEPT'] ?? ''; if (!$acceptedTypes) { return null; diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 3fced76f2..14408ea50 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -263,16 +263,23 @@ function import_xchan_photo($photo, $xchan, $thing = false, $force = false) { $hdrs[strtolower($t)] = $v; } + $expires = time() + 86400; + if(array_key_exists('expires', $hdrs)) $expires = strtotime($hdrs['expires']); - if($expires - 60 < time()) - $expires = time() + 60; + + if($expires - 60 < time()) { + $expires = time() + 60; + } else { $cc = ''; - if(array_key_exists('cache-control', $hdrs)) + if(array_key_exists('cache-control', $hdrs)) { $cc = $hdrs['cache-control']; - if(strpos($cc, 'no-cache')) + } + + if(strpos($cc, 'no-cache')) { $expires = time() + 60; + } else { $ttl = (preg_match('/max-age=(\d+)/i', $cc, $o) ? intval($o[1]) : 86400); $expires = time() + $ttl; @@ -297,7 +304,7 @@ function import_xchan_photo($photo, $xchan, $thing = false, $force = false) { $micro = z_root() . '/photo/' . $hash . '-6'; if(isset($result)) q("UPDATE photo SET expires = '%s' WHERE xchan = '%s' and photo_usage = %d and imgscale IN (4, 5, 6)", - dbescdate(gmdate('Y-m-d H:i:s', (isset($expires) ? $expires : time() + 86400))), + dbescdate(gmdate('Y-m-d H:i:s', $expires)), dbesc($xchan), intval(PHOTO_XCHAN) ); diff --git a/include/text.php b/include/text.php index 63b472bbd..dde810e17 100644 --- a/include/text.php +++ b/include/text.php @@ -1544,8 +1544,10 @@ function link_compare($a, $b) { function theme_attachments(&$item) { + $s = ''; $arr = json_decode($item['attach'],true); + if(is_array($arr) && count($arr)) { $attaches = []; @@ -1568,13 +1570,15 @@ function theme_attachments(&$item) { $title = t('Size') . ' ' . (isset($r['length']) ? userReadableSize($r['length']) : t('unknown')); + $revision = $r['revision'] ?? ''; + require_once('include/channel.php'); 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']); + $url = z_root() . '/magic?f=&owa=1&hash=' . $item['author_xchan'] . '&bdest=' . bin2hex($r['href'] . '/' . $revision); } //$s .= '<a href="' . $url . '" title="' . $title . '" class="attachlink" >' . $icon . '</a>'; |