code cleanup

This commit is contained in:
Mike Macgirvin 2022-08-14 19:20:43 +10:00
parent 41055b60a7
commit 864e6f19fa
15 changed files with 90 additions and 192 deletions

View file

@ -3969,7 +3969,7 @@ class Activity
intval($x['item_id']) intval($x['item_id'])
); );
if ($r) { if ($r) {
send_status_notifications($x['item_id'], $r[0]); send_status_notifications($r[0]);
} }
sync_an_item($channel['channel_id'], $x['item_id']); sync_an_item($channel['channel_id'], $x['item_id']);
} }

View file

@ -272,13 +272,13 @@ class Libzotdir
$arr = []; $arr = [];
$arr['xprof_hash'] = $hash; $arr['xprof_hash'] = $hash;
$arr['xprof_dob'] = '0000-00-00'; $arr['xprof_dob'] = '0000-00-00';
if (isset($profile['birthday'])) { if (isset($profile['birthday'])) {
$arr['xprof_dob'] = (($profile['birthday'] === '0000-00-00') $arr['xprof_dob'] = (($profile['birthday'] === '0000-00-00')
? $profile['birthday'] ? $profile['birthday']
: datetime_convert('', '', $profile['birthday'], 'Y-m-d')); // !!!! check this for 0000 year : datetime_convert('', '', $profile['birthday'], 'Y-m-d')); // !!!! check this for 0000 year
} }
$arr['xprof_age'] = (isset($profile['age']) ? intval($profile['age']) : 0); $arr['xprof_age'] = (isset($profile['age']) ? intval($profile['age']) : 0);
$arr['xprof_desc'] = ((isset($profile['description']) && $profile['description']) ? htmlspecialchars($profile['description'], ENT_COMPAT, 'UTF-8', false) : ''); $arr['xprof_desc'] = ((isset($profile['description']) && $profile['description']) ? htmlspecialchars($profile['description'], ENT_COMPAT, 'UTF-8', false) : '');
$arr['xprof_gender'] = ((isset($profile['gender']) && $profile['gender']) ? htmlspecialchars($profile['gender'], ENT_COMPAT, 'UTF-8', false) : ''); $arr['xprof_gender'] = ((isset($profile['gender']) && $profile['gender']) ? htmlspecialchars($profile['gender'], ENT_COMPAT, 'UTF-8', false) : '');

View file

@ -53,7 +53,7 @@ class Ca extends Controller
} }
if ($_GET['url']) { if ($_GET['url']) {
goaway($url); goaway($_GET['url']);
} }
} }
http_status_exit(404, 'Not found'); http_status_exit(404, 'Not found');

View file

@ -189,6 +189,7 @@ class Channel extends Controller
{ {
$noscript_content = get_config('system', 'noscript_content', '1'); $noscript_content = get_config('system', 'noscript_content', '1');
$sql_extra2 = '';
$category = $datequery = $datequery2 = ''; $category = $datequery = $datequery2 = '';

View file

@ -5,6 +5,7 @@ namespace Code\Module;
use App; use App;
use Code\Web\Controller; use Code\Web\Controller;
use Code\Lib\Libzot; use Code\Lib\Libzot;
use Code\Lib\Zotfinger;
use Code\Lib\Webfinger; use Code\Lib\Webfinger;
use Code\Lib\ActivityStreams; use Code\Lib\ActivityStreams;
use Code\Lib\Activity; use Code\Lib\Activity;
@ -77,7 +78,7 @@ class Chanview extends Controller
$r = null; $r = null;
if ($_REQUEST['address']) { if ($_REQUEST['address']) {
$href = Webfinger::zot_url(punify($url)); $href = Webfinger::zot_url(punify($_REQUEST['address']));
if ($href) { if ($href) {
$zf = Zotfinger::exec($href, $channel); $zf = Zotfinger::exec($href, $channel);
} }

View file

@ -14,8 +14,8 @@ use Sabre\DAV as SDAV;
use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound; use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Exception\NotImplemented; use Sabre\DAV\Exception\NotImplemented;
use Code\Storage;
use Code\Lib\Libprofile; use Code\Lib\Libprofile;
use Code\Storage\Stdio;
use Code\Storage\Browser; use Code\Storage\Browser;
use Code\Web\Controller; use Code\Web\Controller;
use Code\Storage\BasicAuth; use Code\Storage\BasicAuth;
@ -40,7 +40,7 @@ class Cloud extends Controller
{ {
if (!is_dir('store')) { if (!is_dir('store')) {
os_mkdir('store', STORAGE_DEFAULT_PERMISSIONS, false); Stdio::mkdir('store', STORAGE_DEFAULT_PERMISSIONS, false);
} }
$which = null; $which = null;

View file

@ -3,7 +3,7 @@
namespace Code\Storage; namespace Code\Storage;
use App; use App;
use Sabre\; use Sabre;
use Sabre\DAV; use Sabre\DAV;
use Sabre\DAV\Browser\Plugin; use Sabre\DAV\Browser\Plugin;
use Sabre\HTTP\Auth\Basic; use Sabre\HTTP\Auth\Basic;
@ -16,7 +16,7 @@ use Sabre\HTTP\ResponseInterface;
* This class also contains some data which is not necessary for authentication * This class also contains some data which is not necessary for authentication
* like timezone settings. * like timezone settings.
* *
* @extends \DAV\\Auth\\Backend\\AbstractBasic * @extends Sabre\DAV\Auth\Backend\AbstractBasic
* *
* @link http://github.com/friendica/red * @link http://github.com/friendica/red
* @license http://opensource.org/unlicense.org * @license http://opensource.org/unlicense.org
@ -38,6 +38,12 @@ class BasicAuth extends DAV\Auth\Backend\AbstractBasic
* @var int $channel_id * @var int $channel_id
*/ */
public $channel_id = 0; public $channel_id = 0;
/**
* @brief channel_account_id of the current channel of the logged-in account.
*
* @var int $channel_account_id
*/
public $channel_account_id = 0;
/** /**
* @brief channel_hash of the current channel of the logged-in account. * @brief channel_hash of the current channel of the logged-in account.
* *
@ -53,7 +59,7 @@ class BasicAuth extends DAV\Auth\Backend\AbstractBasic
/** /**
* *
* @see Browser::set_writeable() * @see Browser::set_writeable()
* @var \DAV\\Browser\\Plugin $browser * @var Sabre\DAV\Browser\Plugin $browser
*/ */
public $browser; public $browser;
/** /**
@ -94,7 +100,7 @@ class BasicAuth extends DAV\Auth\Backend\AbstractBasic
*/ */
protected function validateUserPass($username, $password) protected function validateUserPass($username, $password)
{ {
$channel = false;
require_once('include/auth.php'); require_once('include/auth.php');
$record = account_verify_password($username, $password); $record = account_verify_password($username, $password);
if ($record && $record['account']) { if ($record && $record['account']) {
@ -135,6 +141,7 @@ class BasicAuth extends DAV\Auth\Backend\AbstractBasic
$this->channel_name = $channel['channel_address']; $this->channel_name = $channel['channel_address'];
$this->channel_id = $channel['channel_id']; $this->channel_id = $channel['channel_id'];
$this->channel_hash = $this->observer = $channel['channel_hash']; $this->channel_hash = $this->observer = $channel['channel_hash'];
$this->channel_account_id = $channel['channel_account_id'];
if ($this->observer) { if ($this->observer) {
$r = q("select * from xchan where xchan_hash = '%s' limit 1", $r = q("select * from xchan where xchan_hash = '%s' limit 1",

View file

@ -3,7 +3,6 @@ namespace Code\Storage;
use App; use App;
use Sabre\;
use Sabre\DAV; use Sabre\DAV;
use Sabre\DAV\INode; use Sabre\DAV\INode;
use Code\Lib\PermissionDescription; use Code\Lib\PermissionDescription;
@ -23,7 +22,7 @@ use function Sabre\HTTP\encodePath;
* Browser is a SabreDAV server-plugin to provide a view to the DAV storage * Browser is a SabreDAV server-plugin to provide a view to the DAV storage
* for the webbrowser. * for the webbrowser.
* *
* @extends \DAV\\Browser\\Plugin * @extends DAV\\Browser\\Plugin
* *
* @link http://framagit.org/hubzilla/core/ * @link http://framagit.org/hubzilla/core/
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT) * @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)

View file

@ -3,7 +3,6 @@
namespace Code\Storage; namespace Code\Storage;
use App; use App;
use Sabre\;
use Sabre\DAV; use Sabre\DAV;
use Code\Lib\Libsync; use Code\Lib\Libsync;
use Code\Daemon\Run; use Code\Daemon\Run;
@ -18,9 +17,9 @@ require_once('include/photos.php');
* *
* A class that represents a directory. * A class that represents a directory.
* *
* @extends \DAV\\Node * @extends DAV\\Node
* @implements \DAV\\ICollection * @implements DAV\\ICollection
* @implements \DAV\\IQuota * @implements DAV\\IQuota
* *
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT) * @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)
*/ */

View file

@ -3,7 +3,6 @@
namespace Code\Storage; namespace Code\Storage;
use App; use App;
use Code\;
use Sabre\DAV; use Sabre\DAV;
use Code\Lib\Libsync; use Code\Lib\Libsync;
use Code\Daemon\Run; use Code\Daemon\Run;
@ -38,8 +37,8 @@ class File extends DAV\Node implements DAV\IFile {
public $data; public $data;
/** /**
* @see \\Sabre\\DAV\\Auth\\Backend\\BackendInterface * @see \Sabre\DAV\Auth\Backend\BackendInterface
* @var \Storage\\BasicAuth $auth * @var \Code\Storage\BasicAuth $auth
*/ */
private $auth; private $auth;
@ -106,7 +105,7 @@ class File extends DAV\Node implements DAV\IFile {
intval($this->auth->owner_id) intval($this->auth->owner_id)
); );
if ($this->data->is_photo) { if ($this->data['is_photo']) {
$r = q("update photo set filename = '%s', display_path = '%s' where resource_id = '%s' and uid = %d", $r = q("update photo set filename = '%s', display_path = '%s' where resource_id = '%s' and uid = %d",
dbesc($newName), dbesc($newName),
dbesc($x['path']), dbesc($x['path']),

View file

@ -5,10 +5,6 @@
* *
* @brief File/attach API with the potential for revision control. * @brief File/attach API with the potential for revision control.
* *
* @TODO A filesystem storage abstraction which maintains security (and 'data'
* contains a system filename which is inaccessible from the web). This could
* get around PHP storage limits and store videos and larger items, using fread
* or OS methods or native code to read/write or chunk it through.
* @todo Also an 'append' option to the storage function might be a useful addition. * @todo Also an 'append' option to the storage function might be a useful addition.
*/ */
@ -1337,7 +1333,7 @@ function attach_mkdir($channel, $observer_hash, $arr = null)
$ret['data'] = $z[0]; $ret['data'] = $z[0];
} }
} else { } else {
logger('attach_mkdir: ' . mkdir . ' ' . $os_basepath . $os_path . ' failed.'); logger('attach_mkdir: ' . $os_basepath . $os_path . ' failed.');
$ret['message'] = t('mkdir failed.'); $ret['message'] = t('mkdir failed.');
} }
} else { } else {

View file

@ -4,7 +4,7 @@ require_once('boot.php');
// Everything we need to boot standalone 'background' processes // Everything we need to boot standalone 'background' processes
function cli_startup() function cli_startup(): void
{ {
sys_boot(); sys_boot();
App::set_baseurl(get_config('system', 'baseurl')); App::set_baseurl(get_config('system', 'baseurl'));

View file

@ -42,7 +42,7 @@ require_once('include/photo_factory.php');
function collect_recipients($item, &$private_envelope,$include_groups = true) { function collect_recipients($item, &$private_envelope,$include_groups = true) {
$private_envelope = ((intval($item['item_private'])) ? true : false); $private_envelope = (bool)intval($item['item_private']);
$recipients = []; $recipients = [];
if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) { if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) {
@ -324,7 +324,6 @@ function can_comment_on_post($observer_xchan, $item)
// Anonymous folks won't ever reach this point (as $observer_xchan will be empty). // Anonymous folks won't ever reach this point (as $observer_xchan will be empty).
// This means the viewer has an xchan and we can identify them. // This means the viewer has an xchan and we can identify them.
return true; return true;
break;
case 'any connections': case 'any connections':
case 'specific': case 'specific':
case 'contacts': case 'contacts':
@ -510,92 +509,6 @@ function validate_item_elements($message,$arr) {
} }
/**
* @brief Limit length on imported system messages.
*
* The purpose of this function is to apply system message length limits to
* imported messages without including any embedded photos in the length.
*
* @param string $body
* @return string
*/
function limit_body_size($body) {
$maxlen = get_max_import_size();
// If the length of the body, including the embedded images, is smaller
// than the maximum, then don't waste time looking for the images
if($maxlen && (strlen($body) > $maxlen)) {
$orig_body = $body;
$new_body = '';
$textlen = 0;
$img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
$img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
while(($img_st_close !== false) && ($img_end !== false)) {
$img_st_close++; // make it point to AFTER the closing bracket
$img_end += $img_start;
$img_end += strlen('[/img]');
if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
// This is an embedded image
if( ($textlen + $img_start) > $maxlen ) {
if($textlen < $maxlen) {
logger('The limit happens before an embedded image', LOGGER_DEBUG);
$new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
$textlen = $maxlen;
}
}
else {
$new_body = $new_body . substr($orig_body, 0, $img_start);
$textlen += $img_start;
}
$new_body = $new_body . substr($orig_body, $img_start, $img_end - $img_start);
}
else {
if( ($textlen + $img_end) > $maxlen ) {
if($textlen < $maxlen) {
$new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
$textlen = $maxlen;
}
}
else {
$new_body = $new_body . substr($orig_body, 0, $img_end);
$textlen += $img_end;
}
}
$orig_body = substr($orig_body, $img_end);
if($orig_body === false) // in case the body ends on a closing image tag
$orig_body = '';
$img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
$img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
}
if( ($textlen + strlen($orig_body)) > $maxlen) {
if($textlen < $maxlen) {
$new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
$textlen = $maxlen;
}
}
else {
$new_body = $new_body . $orig_body;
$textlen += strlen($orig_body);
}
return $new_body;
}
else
return $body;
}
function get_item_elements($x,$allow_code = false) { function get_item_elements($x,$allow_code = false) {
$arr = []; $arr = [];
@ -965,7 +878,7 @@ function import_author_unknown($x) {
'xchan_guid' => $x['url'], 'xchan_guid' => $x['url'],
'xchan_url' => $x['url'], 'xchan_url' => $x['url'],
'xchan_updated' => datetime_convert(), 'xchan_updated' => datetime_convert(),
'xchan_name' => (($name) ? $name : t('(Unknown)')), 'xchan_name' => (($name) ?: t('(Unknown)')),
'xchan_name_date' => datetime_convert(), 'xchan_name_date' => datetime_convert(),
'xchan_network' => 'unknown' 'xchan_network' => 'unknown'
] ]
@ -994,7 +907,7 @@ function import_author_unknown($x) {
} }
function empty_acl($item) { function empty_acl($item) {
return (($item['allow_cid'] === EMPTY_STR && $item['allow_gid'] === EMPTY_STR && $item['deny_cid'] === EMPTY_STR && $item['deny_gid'] === EMPTY_STR) ? true : false); return $item['allow_cid'] === EMPTY_STR && $item['allow_gid'] === EMPTY_STR && $item['deny_cid'] === EMPTY_STR && $item['deny_gid'] === EMPTY_STR;
} }
function encode_item($item,$mirror = false) { function encode_item($item,$mirror = false) {
@ -1002,8 +915,6 @@ function encode_item($item,$mirror = false) {
$x['type'] = 'activity'; $x['type'] = 'activity';
$x['encoding'] = 'zot'; $x['encoding'] = 'zot';
$key = get_config('system','prvkey');
// If we're trying to backup an item so that it's recoverable or for export/imprt, // If we're trying to backup an item so that it's recoverable or for export/imprt,
// add all the attributes we need to recover it // add all the attributes we need to recover it
@ -1153,6 +1064,7 @@ function translate_scope($scope) {
return t('Visible to approved connections.'); return t('Visible to approved connections.');
if(strpos($scope,'specific') === 0) if(strpos($scope,'specific') === 0)
return t('Visible to specific connections.'); return t('Visible to specific connections.');
return ''; // This shouldn't happen.
} }
/** /**
@ -1229,7 +1141,7 @@ function decode_item_meta($meta) {
function termtype($t) { function termtype($t) {
$types = array('unknown','hashtag','mention','category','personal_category','file','search','thing','bookmark', 'hierarchy', 'communitytag', 'forum'); $types = array('unknown','hashtag','mention','category','personal_category','file','search','thing','bookmark', 'hierarchy', 'communitytag', 'forum');
return(($types[$t]) ? $types[$t] : 'unknown'); return(($types[$t]) ?: 'unknown');
} }
/** /**
@ -1265,7 +1177,7 @@ function decode_tags($t) {
$tag['ttype'] = TERM_FILE; $tag['ttype'] = TERM_FILE;
break; break;
case 'search': case 'search':
$tag['ttype'] = TERM_SEARCH; $tag['ttype'] = TERM_SAVEDSEARCH;
break; break;
case 'thing': case 'thing':
$tag['ttype'] = TERM_THING; $tag['ttype'] = TERM_THING;
@ -1343,7 +1255,7 @@ function activity_sanitise($arr) {
} }
} }
if (in_array($k, [ 'content', 'summary', 'contentMap', 'summaryMap' ])) { if (in_array($k, [ 'content', 'summary', 'contentMap', 'summaryMap' ])) {
$ret[$k] = purify_imported_object($arr[$k]); $ret[$k] = purify_imported_object($x);
continue; continue;
} }
if(is_array($x)) if(is_array($x))
@ -1938,7 +1850,7 @@ function item_store($arr, $allow_exec = false, $deliver = true, $linkid = true)
$arr['id'] = $current_post; $arr['id'] = $current_post;
if(! intval($r[0]['parent'])) { if(! intval($r[0]['parent'])) {
$x = q("update item set parent = id where id = %d", q("update item set parent = id where id = %d",
intval($r[0]['id']) intval($r[0]['id'])
); );
$arr['parent'] = $r[0]['id']; $arr['parent'] = $r[0]['id'];
@ -1991,7 +1903,7 @@ function item_store($arr, $allow_exec = false, $deliver = true, $linkid = true)
// that isn't aware that we were already told to delete it. // that isn't aware that we were already told to delete it.
if(($deliver) && (! intval($arr['item_deleted']))) { if(($deliver) && (! intval($arr['item_deleted']))) {
send_status_notifications($current_post,$arr); send_status_notifications($arr);
tag_deliver($arr['uid'],$current_post); tag_deliver($arr['uid'],$current_post);
} }
@ -2388,7 +2300,7 @@ function item_update_parent_commented($item) {
} }
function send_status_notifications($post_id,$item) { function send_status_notifications($item) {
// only send notifications for comments // only send notifications for comments
@ -2483,7 +2395,7 @@ function send_status_notifications($post_id,$item) {
} }
Enotify::submit(array( Enotify::submit([
'type' => $notify_type, 'type' => $notify_type,
'from_xchan' => $item['author_xchan'], 'from_xchan' => $item['author_xchan'],
'to_xchan' => $r[0]['channel_hash'], 'to_xchan' => $r[0]['channel_hash'],
@ -2491,9 +2403,9 @@ function send_status_notifications($post_id,$item) {
'link' => $link, 'link' => $link,
'verb' => $item['verb'], 'verb' => $item['verb'],
'otype' => 'item', 'otype' => 'item',
'parent' => $thr_parent_id ? $thr_parent_id : $parent, 'parent' => $thr_parent_id ?: $parent,
'parent_mid' => $thr_parent_id ? $item['thr_parent'] : $item['parent_mid'] 'parent_mid' => $thr_parent_id ? $item['thr_parent'] : $item['parent_mid']
)); ]);
} }
/** /**
@ -2509,12 +2421,10 @@ function tag_deliver($uid, $item_id) {
$role = get_pconfig($uid,'system','permissions_role'); $role = get_pconfig($uid,'system','permissions_role');
$rolesettings = PermissionRoles::role_perms($role); $rolesettings = PermissionRoles::role_perms($role);
$channel_type = isset($rolesettings['channel_type']) ? $rolesettings['channel_type'] : 'normal'; $channel_type = $rolesettings['channel_type'] ?? 'normal';
$is_group = (($channel_type === 'group') ? true : false); $is_group = $channel_type === 'group';
$is_collection = (($channel_type === 'collection') ? true : false); $is_collection = $channel_type === 'collection';
$mention = false;
/* /*
* Fetch stuff we need - a channel and an item * Fetch stuff we need - a channel and an item
@ -2546,7 +2456,7 @@ function tag_deliver($uid, $item_id) {
// after resetting ownership and permission bits // after resetting ownership and permission bits
logger('updating edited tag_deliver post for ' . $u['channel_address']); logger('updating edited tag_deliver post for ' . $u['channel_address']);
start_delivery_chain($u, $item, $item_id, 0, false, true); start_delivery_chain($u, $item, $item_id, false, false, true);
return; return;
} }
@ -2574,7 +2484,7 @@ function tag_deliver($uid, $item_id) {
// and this will be turned into an embedded wall-to-wall post // and this will be turned into an embedded wall-to-wall post
if(perm_is_allowed($uid,$item['author_xchan'],'post_wall')) { if(perm_is_allowed($uid,$item['author_xchan'],'post_wall')) {
logger('group DM delivery for ' . $u['channel_address']); logger('group DM delivery for ' . $u['channel_address']);
start_delivery_chain($u, $item, $item_id, 0, true, (($item['edited'] != $item['created']) || $item['item_deleted'])); start_delivery_chain($u, $item, $item_id, false, true, (($item['edited'] != $item['created']) || $item['item_deleted']));
q("update item set item_blocked = %d where id = %d", q("update item set item_blocked = %d where id = %d",
intval(ITEM_HIDDEN), intval(ITEM_HIDDEN),
intval($item_id) intval($item_id)
@ -2603,7 +2513,7 @@ function tag_deliver($uid, $item_id) {
if ($id == z_root() . '/outbox/' . $u['channel_address']) { if ($id == z_root() . '/outbox/' . $u['channel_address']) {
if(perm_is_allowed($uid,$item['author_xchan'],'post_wall')) { if(perm_is_allowed($uid,$item['author_xchan'],'post_wall')) {
logger('group collection delivery for ' . $u['channel_address']); logger('group collection delivery for ' . $u['channel_address']);
start_delivery_chain($u, $item, $item_id, 0, true, (($item['edited'] != $item['created']) || $item['item_deleted'])); start_delivery_chain($u, $item, $item_id, false, true, (($item['edited'] != $item['created']) || $item['item_deleted']));
q("update item set item_blocked = %d where id = %d", q("update item set item_blocked = %d where id = %d",
intval(ITEM_HIDDEN), intval(ITEM_HIDDEN),
intval($item_id) intval($item_id)
@ -2621,7 +2531,7 @@ function tag_deliver($uid, $item_id) {
} }
// group delivery via W2W // group delivery via W2W
logger('rewriting W2W post for ' . $u['channel_address']); logger('rewriting W2W post for ' . $u['channel_address']);
start_delivery_chain($u, $item, $item_id, 0, true, (($item['edited'] != $item['created']) || $item['item_deleted'])); start_delivery_chain($u, $item, $item_id, false, true, (($item['edited'] != $item['created']) || $item['item_deleted']));
q("update item set item_wall = 0 where id = %d", q("update item set item_wall = 0 where id = %d",
intval($item_id) intval($item_id)
); );
@ -2705,12 +2615,9 @@ function tag_deliver($uid, $item_id) {
if (! link_compare($term['url'],$link)) { if (! link_compare($term['url'],$link)) {
continue; continue;
} }
$mention = true;
logger('Mention found for ' . $u['channel_name']); logger('Mention found for ' . $u['channel_name']);
$r = q("update item set item_mentionsme = 1 where id = %d", q("update item set item_mentionsme = 1 where id = %d",
intval($item_id) intval($item_id)
); );
@ -2761,7 +2668,7 @@ function tag_deliver($uid, $item_id) {
if ($is_group && intval($item['item_thread_top']) && (! intval($item['item_wall']))) { if ($is_group && intval($item['item_thread_top']) && (! intval($item['item_wall']))) {
if (get_pconfig($uid,'system','post_via_mentions',in_array($role,['forum','forum_moderated'])) && perm_is_allowed($uid,$item['author_xchan'],'post_wall')) { if (get_pconfig($uid,'system','post_via_mentions',in_array($role,['forum','forum_moderated'])) && perm_is_allowed($uid,$item['author_xchan'],'post_wall')) {
logger('group mention delivery for ' . $u['channel_address']); logger('group mention delivery for ' . $u['channel_address']);
start_delivery_chain($u, $item, $item_id, 0, true, (($item['edited'] != $item['created']) || $item['item_deleted'])); start_delivery_chain($u, $item, $item_id, false, true, (($item['edited'] != $item['created']) || $item['item_deleted']));
q("update item set item_blocked = %d where id = %d", q("update item set item_blocked = %d where id = %d",
intval(ITEM_HIDDEN), intval(ITEM_HIDDEN),
intval($item_id) intval($item_id)
@ -2821,7 +2728,7 @@ function tag_deliver($uid, $item_id) {
} }
logger('Creating second delivery chain.'); logger('Creating second delivery chain.');
start_delivery_chain($u,$item,$item_id,null); start_delivery_chain($u,$item,$item_id, false);
} }
} }
@ -2833,7 +2740,7 @@ function tag_deliver($uid, $item_id) {
} }
logger('Creating second delivery chain.'); logger('Creating second delivery chain.');
start_delivery_chain($u,$item,$item_id,null); start_delivery_chain($u,$item,$item_id,false);
} }
@ -2939,8 +2846,8 @@ function tgroup_check($uid, $item) {
} }
} }
} }
$unless = intval(get_pconfig($channel['channel_id'], 'system', 'unless_tag_count', $unless = intval(PConfig::Get($uid, 'system', 'unless_tag_count',
get_config('system', 'unless_tag_count', 20))); Config::Get('system', 'unless_tag_count', 20)));
if ($unless && count($terms) > $unless) { if ($unless && count($terms) > $unless) {
$tag_result= false; $tag_result= false;
} }
@ -2992,9 +2899,9 @@ function i_am_mentioned($channel,$item) {
* @param array $channel * @param array $channel
* @param array $item * @param array $item
* @param int $item_id * @param int $item_id
* @param boolean $parent * @param bool|array $parent
*/ */
function start_delivery_chain($channel, $item, $item_id, $parent, $group = false, $edit = false) { function start_delivery_chain($channel, $item, $item_id, bool|array $parent, $group = false, $edit = false) {
// btlogger('start_chain: ' . $channel['channel_id'] . ' item: ' . $item_id); // btlogger('start_chain: ' . $channel['channel_id'] . ' item: ' . $item_id);
@ -3305,15 +3212,10 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $group = false
$private = (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 1 : 0); $private = (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 1 : 0);
// Setting item_origin on a deleted item also seems to cause looping $item_origin = ($item['item_deleted']) ? 0 : 1;
if (! intval($arr['item_deleted'])) {
$arr['item_origin'] = 1;
}
$item_wall = 1; $item_wall = 1;
$item_uplink = 0; $item_uplink = 0;
$item_nocomment = 0; $item_nocomment = 0;
$flag_bits = $item['item_flags']; $flag_bits = $item['item_flags'];
// maintain the original source, which will be the original item owner and was stored in source_xchan // maintain the original source, which will be the original item owner and was stored in source_xchan
@ -3674,10 +3576,6 @@ function drop_items($items, $stage = DROPITEM_NORMAL, $force = false) {
$uid = 0; $uid = 0;
if (($interactive) && (! (local_channel() || remote_channel()))) {
return;
}
if (count($items)) { if (count($items)) {
foreach ($items as $item) { foreach ($items as $item) {
$owner = drop_item($item, $stage, $force); $owner = drop_item($item, $stage, $force);
@ -4240,7 +4138,7 @@ function zot_feed($uid, $observer_hash, $arr) {
foreach($items as $item) { foreach($items as $item) {
if($encoding === 'zot') if($encoding === 'zot')
$result[] = encode_item($item); $result[] = encode_item($item);
elseif(encoding === 'activitystreams') elseif($encoding === 'activitystreams')
$result[] = Activity::encode_activity($item); $result[] = Activity::encode_activity($item);
} }
@ -4296,15 +4194,15 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
$sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE item_thread_top = 1 $sql_options $item_normal ) "; $sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE item_thread_top = 1 $sql_options $item_normal ) ";
if(isset($arr['since_id']) && $arr['since_id']) { if (!empty($arr['since_id'])) {
$sql_extra .= " and item.id > " . $since_id . " "; $sql_extra .= " and item.id > " . $arr['since_id'] . " ";
} }
if (isset($arr['cat']) && $arr['cat']) { if (!empty($arr['cat'])) {
$sql_extra .= protect_sprintf(term_query('item', $arr['cat'], TERM_CATEGORY)); $sql_extra .= protect_sprintf(term_query('item', $arr['cat'], TERM_CATEGORY));
} }
if (isset($arr['gid']) && $arr['gid'] && $uid) { if ($uid && !empty($arr['gid'])) {
$r = q("SELECT * FROM pgrp WHERE id = %d AND uid = %d LIMIT 1", $r = q("SELECT * FROM pgrp WHERE id = %d AND uid = %d LIMIT 1",
intval($arr['group']), intval($arr['group']),
intval($uid) intval($uid)
@ -4587,8 +4485,9 @@ function update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remo
// sixteen bytes of the mid - which makes the link portable and not quite as daunting // sixteen bytes of the mid - which makes the link portable and not quite as daunting
// as the entire mid. If it were the post_id the link would be less portable. // as the entire mid. If it were the post_id the link would be less portable.
$post_id = intval($post_id);
IConfig::Set( IConfig::Set(
intval($post_id), $post_id,
'system', 'system',
$page_type, $page_type,
($pagetitle) ? $pagetitle : substr($mid,0,16), ($pagetitle) ? $pagetitle : substr($mid,0,16),
@ -4636,13 +4535,13 @@ function item_remove_cid($xchan_hash,$mid,$uid) {
} }
// Set item permissions based on results obtained from linkify_tags() // 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, $parent_item, &$private) {
$first_access_tag = true; $first_access_tag = true;
foreach($linkified as $x) { foreach($linkified as $x) {
$access_tag = $x['success']['access_tag']; $access_tag = $x['success']['access_tag'];
if(($access_tag) && (! $parent_item)) { if(($access_tag) && (! $parent_item)) {
logger('access_tag: ' . $tag . ' ' . print_r($access_tag,true), LOGGER_DATA); logger('access_tag: ' . print_r($access_tag,true), LOGGER_DATA);
if ($first_access_tag && (! get_pconfig($profile_uid,'system','no_private_mention_acl_override'))) { if ($first_access_tag && (! get_pconfig($profile_uid,'system','no_private_mention_acl_override'))) {
// This is a tough call, hence configurable. The issue is that one can type in a @!privacy mention // This is a tough call, hence configurable. The issue is that one can type in a @!privacy mention
@ -4834,10 +4733,8 @@ function fix_attached_permissions($uid,$body,$str_contact_allow,$str_group_allow
$attach = array_shift($attach_q); $attach = array_shift($attach_q);
$match = null; $new_public = !(($str_contact_allow || $str_group_allow || $str_contact_deny || $str_group_deny));
$existing_public = false; $existing_public = !(($attach['allow_cid'] || $attach['allow_gid'] || $attach['deny_cid'] || $attach['deny_gid']));
$new_public = (($str_contact_allow||$str_group_allow||$str_contact_deny||$str_group_deny) ? false : true);
$existing_public = (($attach['allow_cid']||$attach['allow_gid']||$attach['deny_cid']||$attach['deny_gid']) ? false : true);
if ($existing_public) { if ($existing_public) {
// permissions have already been fixed and they are public. There's nothing for us to do. // permissions have already been fixed and they are public. There's nothing for us to do.

View file

@ -201,7 +201,7 @@ function z_dns_check($h, $check_mx = 0)
// BSD variants have dns_get_record() but it only works reliably without any options // BSD variants have dns_get_record() but it only works reliably without any options
if (stripos(PHP_OS, 'bsd') !== false) { if (stripos(PHP_OS, 'bsd') !== false) {
return((@dns_get_record($h) || filter_var($h, FILTER_VALIDATE_IP)) ? true : false); return @dns_get_record($h) || filter_var($h, FILTER_VALIDATE_IP);
} }
// Otherwise we will assume dns_get_record() works as documented // Otherwise we will assume dns_get_record() works as documented
@ -211,7 +211,7 @@ function z_dns_check($h, $check_mx = 0)
$opts += DNS_MX; $opts += DNS_MX;
} }
return((@dns_get_record($h, $opts) || filter_var($h, FILTER_VALIDATE_IP)) ? true : false); return @dns_get_record($h, $opts) || filter_var($h, FILTER_VALIDATE_IP);
} }
/** /**
@ -458,7 +458,7 @@ function xml2array($contents, $namespaces = true, $get_attributes = 1, $priority
if ($priority == 'tag') { if ($priority == 'tag') {
$result = $value; $result = $value;
} else { } else {
$result['value'] = $value; // Put the value in a assoc array if we are in the 'Attribute' mode $result['value'] = $value; // Put the value in an assoc array if we are in the 'Attribute' mode
} }
} }
@ -468,7 +468,7 @@ function xml2array($contents, $namespaces = true, $get_attributes = 1, $priority
if ($priority == 'tag') { if ($priority == 'tag') {
$attributes_data[$attr] = $val; $attributes_data[$attr] = $val;
} else { } else {
$result['@attributes'][$attr] = $val; // Set all the attributes in a array called 'attr' $result['@attributes'][$attr] = $val; // Set all the attributes in an array called 'attr'
} }
} }
} }
@ -525,7 +525,7 @@ function xml2array($contents, $namespaces = true, $get_attributes = 1, $priority
} }
$repeated_tag_index[$tag . '_' . $level]++; $repeated_tag_index[$tag . '_' . $level]++;
} else { // If it is not an array... } else { // If it is not an array...
$current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value $current[$tag] = array($current[$tag],$result); //...Make it an array using the existing value and the new value
$repeated_tag_index[$tag . '_' . $level] = 1; $repeated_tag_index[$tag . '_' . $level] = 1;
if ($priority == 'tag' and $get_attributes) { if ($priority == 'tag' and $get_attributes) {
if (isset($current[$tag . '_attr'])) { // The attribute of the last(0th) tag must be moved as well if (isset($current[$tag . '_attr'])) { // The attribute of the last(0th) tag must be moved as well
@ -584,7 +584,7 @@ function email_header_encode($in_str, $charset = 'UTF-8', $header = 'Subject')
base64-encoding 3 8-bit-chars are represented base64-encoding 3 8-bit-chars are represented
by 4 6-bit-chars. These 4 chars must not be by 4 6-bit-chars. These 4 chars must not be
split between two encoded words, according split between two encoded words, according
to RFC-2047. to RFC-2047.]
*/ */
$length = $length - ($length % 4); $length = $length - ($length % 4);
@ -653,7 +653,7 @@ function discover_by_webbie($webbie, $protocol = '', $verify = true)
if ($verify) { if ($verify) {
$hsig = $record['signature']; $hsig = $record['signature'];
if($hsig && ($hsig['signer'] === $url || $hsig['signer'] === $link['href']) && $hsig['header_valid'] === true && $hsig['content_valid'] === true) { if($hsig && $hsig['signer'] === $link['href'] && $hsig['header_valid'] === true && $hsig['content_valid'] === true) {
$hsig_valid = true; $hsig_valid = true;
} }
@ -688,7 +688,7 @@ function discover_by_webbie($webbie, $protocol = '', $verify = true)
if ($verify) { if ($verify) {
$hsig = $record['signature']; $hsig = $record['signature'];
if ($hsig && ($hsig['signer'] === $url || $hsig['signer'] === $link['href']) && $hsig['header_valid'] === true && $hsig['content_valid'] === true) { if ($hsig && $hsig['signer'] === $link['href'] && $hsig['header_valid'] === true && $hsig['content_valid'] === true) {
$hsig_valid = true; $hsig_valid = true;
} }
@ -721,7 +721,7 @@ function discover_by_webbie($webbie, $protocol = '', $verify = true)
if ($record) { if ($record) {
if ($verify) { if ($verify) {
$hsig = $record['signature']; $hsig = $record['signature'];
if ($hsig && ($hsig['signer'] === $url || $hsig['signer'] === $webbie) && $hsig['header_valid'] === true && $hsig['content_valid'] === true) { if ($hsig && $hsig['signer'] === $webbie && $hsig['header_valid'] === true && $hsig['content_valid'] === true) {
$hsig_valid = true; $hsig_valid = true;
} }
@ -1139,7 +1139,7 @@ function check_channelallowed($hash)
if ($bl === '*') { if ($bl === '*') {
$retvalue = true; $retvalue = true;
} }
if ($bl && (strpos($url, $bl) !== false || wildmat($bl, $url))) { if ($bl && (strpos($hash, $bl) !== false || wildmat($bl, $hash))) {
return true; return true;
} }
} }
@ -1149,7 +1149,7 @@ function check_channelallowed($hash)
if ($bl === '*') { if ($bl === '*') {
$retvalue = false; $retvalue = false;
} }
if ($bl && (strpos($url, $bl) !== false || wildmat($bl, $url))) { if ($bl && (strpos($hash, $bl) !== false || wildmat($bl, $hash))) {
return false; return false;
} }
} }
@ -1194,7 +1194,7 @@ function check_pubstream_channelallowed($hash)
if ($bl === '*') { if ($bl === '*') {
$retvalue = true; $retvalue = true;
} }
if ($bl && (strpos($url, $bl) !== false || wildmat($bl, $url))) { if ($bl && (strpos($hash, $bl) !== false || wildmat($bl, $hash))) {
return true; return true;
} }
} }
@ -1204,7 +1204,7 @@ function check_pubstream_channelallowed($hash)
if ($bl === '*') { if ($bl === '*') {
$retvalue = false; $retvalue = false;
} }
if ($bl && (strpos($url, $bl) !== false || wildmat($bl, $url))) { if ($bl && (strpos($hash, $bl) !== false || wildmat($bl, $hash))) {
return false; return false;
} }
} }
@ -1293,7 +1293,7 @@ function network_to_name($s)
* @param array $params an associative array with: * @param array $params an associative array with:
* * \e string \b fromName name of the sender * * \e string \b fromName name of the sender
* * \e string \b fromEmail email of the sender * * \e string \b fromEmail email of the sender
* * \e string \b replyTo replyTo address to direct responses * * \e string \b replyTo address to direct responses
* * \e string \b toEmail destination email address * * \e string \b toEmail destination email address
* * \e string \b messageSubject subject of the message * * \e string \b messageSubject subject of the message
* * \e string \b htmlVersion html version of the message * * \e string \b htmlVersion html version of the message
@ -1429,7 +1429,7 @@ function getBestSupportedMimeType($mimeTypes = null, $acceptedTypes = false)
$acceptedTypes = ((isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : EMPTY_STR); $acceptedTypes = ((isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : EMPTY_STR);
} }
// Accept header is case insensitive, and whitespace isnt important // Accept header is case-insensitive, and whitespace isnt important
$accept = strtolower(str_replace(' ', '', $acceptedTypes)); $accept = strtolower(str_replace(' ', '', $acceptedTypes));
// divide it into parts in the place of a "," // divide it into parts in the place of a ","
$accept = explode(',', $accept); $accept = explode(',', $accept);

View file

@ -231,7 +231,6 @@ function get_all_perms($uid, $observer_xchan, $check_siteblock = true, $default_
// No permissions allowed. // No permissions allowed.
$ret[$perm_name] = false; $ret[$perm_name] = false;
continue;
} }
$arr = array( $arr = array(
@ -455,7 +454,7 @@ function get_all_api_perms($uid, $api)
$arr = array( $arr = array(
'channel_id' => $uid, 'channel_id' => $uid,
'observer_hash' => $observer_xchan, 'observer_hash' => get_observer_hash(),
'permissions' => $ret); 'permissions' => $ret);
Hook::call('get_all_api_perms', $arr); Hook::call('get_all_api_perms', $arr);
@ -469,7 +468,7 @@ function api_perm_is_allowed($uid, $api, $permission)
$arr = array( $arr = array(
'channel_id' => $uid, 'channel_id' => $uid,
'observer_hash' => $observer_xchan, 'observer_hash' => get_observer_hash(),
'permission' => $permission, 'permission' => $permission,
'result' => false 'result' => false
); );