$status_user["protected"] = defaults($item, 'private', 0);
if (defaults($item, 'thr-parent', '') == defaults($item, 'uri', '')) {
- $owner_user = api_get_user($a, defaults($item, 'author-id', null));
+ $owner_user = api_get_user($a, defaults($item, 'owner-id', null));
} else {
$owner_user = $status_user;
}
// standard meta information
$ret = [
'id' => $item['id'],
- 'sender_id' => $sender['id'] ,
+ 'sender_id' => $sender['id'],
'text' => "",
'recipient_id' => $recipient['id'],
'created_at' => api_date(defaults($item, 'created', DateTimeFormat::utcNow())),
* likes => int count,
* dislikes => int count
*/
-function api_format_items_activities(&$item, $type = "json")
+function api_format_items_activities($item, $type = "json")
{
$a = get_app();
$condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri']];
$ret = Item::selectForUser($item['uid'], ['author-id', 'verb'], $condition);
- while ($item = Item::fetch($ret)) {
+ while ($parent_item = Item::fetch($ret)) {
// not used as result should be structured like other user data
//builtin_activity_puller($i, $activities);
// get user data and add it to the array of the activity
- $user = api_get_user($a, $item['author-id']);
- switch ($item['verb']) {
+ $user = api_get_user($a, $parent_item['author-id']);
+ switch ($parent_item['verb']) {
case ACTIVITY_LIKE:
$activities['like'][] = $user;
break;
'in_reply_to_screen_name' => $in_reply_to['screen_name'],
$geo => null,
'favorited' => $item['starred'] ? true : false,
- 'user' => $status_user ,
+ 'user' => $status_user,
'friendica_owner' => $owner_user,
'friendica_private' => $item['private'] == 1,
//'entities' => NULL,
*/
function api_ff_ids($type)
{
- if (! api_user()) {
+ if (!api_user()) {
throw new ForbiddenException();
}
/// @TODO move to top of file or somewhere better
api_register_func('api/direct_messages/destroy', 'api_direct_messages_destroy', true, API_METHOD_DELETE);
+/**
+ * Unfollow Contact
+ *
+ * @brief unfollow contact
+ *
+ * @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
+ * @return string|array
+ * @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/post-friendships-destroy.html
+ */
+function api_friendships_destroy($type)
+{
+ $uid = api_user();
+
+ if ($uid === false) {
+ throw new ForbiddenException();
+ }
+
+ $contact_id = defaults($_REQUEST, 'user_id');
+
+ if (empty($contact_id)) {
+ logger("No user_id specified", LOGGER_DEBUG);
+ throw new BadRequestException("no user_id specified");
+ }
+
+ // Get Contact by given id
+ $contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => 0, 'self' => false]);
+
+ if(!DBA::isResult($contact)) {
+ logger("No contact found for ID" . $contact_id, LOGGER_DEBUG);
+ throw new NotFoundException("no contact found to given ID");
+ }
+
+ $url = $contact["url"];
+
+ $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
+ $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url),
+ normalise_link($url), $url];
+ $contact = DBA::selectFirst('contact', [], $condition);
+
+ if (!DBA::isResult($contact)) {
+ logger("Not following Contact", LOGGER_DEBUG);
+ throw new NotFoundException("Not following Contact");
+ }
+
+ if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
+ logger("Not supported", LOGGER_DEBUG);
+ throw new ExpectationFailedException("Not supported");
+ }
+
+ $dissolve = ($contact['rel'] == Contact::SHARING);
+
+ $owner = User::getOwnerDataById($uid);
+ if ($owner) {
+ Contact::terminateFriendship($owner, $contact, $dissolve);
+ }
+ else {
+ logger("No owner found", LOGGER_DEBUG);
+ throw new NotFoundException("Error Processing Request");
+ }
+
+ // Sharing-only contacts get deleted as there no relationship any more
+ if ($dissolve) {
+ Contact::remove($contact['id']);
+ } else {
+ DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
+ }
+
+ // "uid" and "self" are only needed for some internal stuff, so remove it from here
+ unset($contact["uid"]);
+ unset($contact["self"]);
+
+ // Set screen_name since Twidere requests it
+ $contact["screen_name"] = $contact["nick"];
+
+ return api_format_data("friendships-destroy", $type, ['user' => $contact]);
+}
+api_register_func('api/friendships/destroy', 'api_friendships_destroy', true, API_METHOD_POST);
+
/**
*
* @param string $type Return type (atom, rss, xml, json)
// create Photo instance with the data of the image
$imagedata = @file_get_contents($src);
$Image = new Image($imagedata, $filetype);
- if (! $Image->isValid()) {
+ if (!$Image->isValid()) {
throw new InternalServerErrorException("unable to process image data");
}
// check max length of images on server
$max_length = Config::get('system', 'max_image_length');
- if (! $max_length) {
+ if (!$max_length) {
$max_length = MAX_IMAGE_LENGTH;
}
if ($max_length > 0) {
logger("photo upload: starting new photo upload", LOGGER_DEBUG);
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 0, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
- if (! $r) {
+ if (!$r) {
logger("photo upload: image upload with scale 0 (original size) failed");
}
if ($width > 640 || $height > 640) {
$Image->scaleDown(640);
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 1, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
- if (! $r) {
+ if (!$r) {
logger("photo upload: image upload with scale 1 (640x640) failed");
}
}
if ($width > 320 || $height > 320) {
$Image->scaleDown(320);
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 2, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
- if (! $r) {
+ if (!$r) {
logger("photo upload: image upload with scale 2 (320x320) failed");
}
}
if ($width > 175 || $height > 175) {
$Image->scaleDown(175);
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 4, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
- if (! $r) {
+ if (!$r) {
logger("photo upload: profile image upload with scale 4 (175x175) failed");
}
}
if ($width > 80 || $height > 80) {
$Image->scaleDown(80);
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 5, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
- if (! $r) {
+ if (!$r) {
logger("photo upload: profile image upload with scale 5 (80x80) failed");
}
}
if ($width > 48 || $height > 48) {
$Image->scaleDown(48);
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 6, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
- if (! $r) {
+ if (!$r) {
logger("photo upload: profile image upload with scale 6 (48x48) failed");
}
}
$owner_record = DBA::selectFirst('contact', [], ['uid' => api_user(), 'self' => true]);
$arr = [];
- $arr['guid'] = System::createGUID(32);
+ $arr['guid'] = System::createUUID();
$arr['uid'] = intval(api_user());
$arr['uri'] = $uri;
$arr['parent-uri'] = $uri;
{
$body = trim($item["body"]);
- if (Diaspora::isReshare($body, false)===false) {
- return false;
+ if (Diaspora::isReshare($body, false) === false) {
+ if ($item['author-id'] == $item['owner-id']) {
+ return false;
+ } else {
+ // Reshares from OStatus, ActivityPub and Twitter
+ $reshared_item = $item;
+ $reshared_item['owner-id'] = $reshared_item['author-id'];
+ $reshared_item['owner-link'] = $reshared_item['author-link'];
+ $reshared_item['owner-name'] = $reshared_item['author-name'];
+ $reshared_item['owner-avatar'] = $reshared_item['author-avatar'];
+ return $reshared_item;
+ }
}
/// @TODO "$1" should maybe mean '$1' ?
if (in_array($mode, ['community', 'contacts'])) {
$writable = true;
} else {
- $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]);
+ $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]);
}
if (!local_user()) {
foreach ($items as $index => $item) {
if ($item['uid'] == 0) {
- $items[$index]['writable'] = in_array($item['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]);
+ $items[$index]['writable'] = in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]);
}
}
}
if ((($cid == 0) || ($rel == Contact::FOLLOWER)) &&
- in_array($item['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
+ in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
$menu[L10n::t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
}
} else {
'$delitems' => L10n::t("Delete item\x28s\x29?")
]);
- $tpl = get_markup_template('jot-end.tpl');
- $a->page['end'] .= replace_macros($tpl, [
- '$newpost' => 'true',
- '$baseurl' => System::baseUrl(true),
- '$geotag' => $geotag,
- '$nickname' => $x['nickname'],
- '$ispublic' => L10n::t('Visible to <strong>everybody</strong>'),
- '$linkurl' => L10n::t('Please enter a link URL:'),
- '$vidurl' => L10n::t("Please enter a video link/URL:"),
- '$audurl' => L10n::t("Please enter an audio link/URL:"),
- '$term' => L10n::t('Tag term:'),
- '$fileas' => L10n::t('Save to Folder:'),
- '$whereareu' => L10n::t('Where are you right now?')
- ]);
-
$jotplugins = '';
Addon::callHooks('jot_tool', $jotplugins);
* Language was set earlier, but we can over-ride it in the session.
* We have to do it here because the session was just now opened.
*/
-if (x($_SESSION, 'authenticated') && !x($_SESSION, 'language')) {
+if (!empty($_SESSION['authenticated']) && empty($_SESSION['language'])) {
$_SESSION['language'] = $lang;
// we haven't loaded user data yet, but we need user language
if (!empty($_SESSION['uid'])) {
}
}
-if (x($_SESSION, 'language') && ($_SESSION['language'] !== $lang)) {
+if (!empty($_SESSION['language']) && $_SESSION['language'] !== $lang) {
$lang = $_SESSION['language'];
L10n::loadTranslationTable($lang);
}
logger("Invalid ZRL parameter " . $_GET['zrl'], LOGGER_DEBUG);
header('HTTP/1.1 403 Forbidden');
echo "<h1>403 Forbidden</h1>";
- killme();
+ exit();
}
}
}
-if ((x($_GET,'owt')) && $a->mode == App::MODE_NORMAL) {
+if (!empty($_GET['owt']) && $a->mode == App::MODE_NORMAL) {
$token = $_GET['owt'];
$a->query_string = Profile::stripQueryParam($a->query_string, 'owt');
Profile::openWebAuthInit($token);
Login::sessionAuth();
-if (! x($_SESSION, 'authenticated')) {
+if (empty($_SESSION['authenticated'])) {
header('X-Account-Management-Status: none');
}
-/* set up page['htmlhead'] and page['end'] for the modules to use */
-$a->page['htmlhead'] = '';
-$a->page['end'] = '';
-
$_SESSION['sysmsg'] = defaults($_SESSION, 'sysmsg' , []);
$_SESSION['sysmsg_info'] = defaults($_SESSION, 'sysmsg_info' , []);
$_SESSION['last_updated'] = defaults($_SESSION, 'last_updated', []);
if (! $a->module_loaded) {
// Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit.
- if ((x($_SERVER, 'QUERY_STRING')) && preg_match('/{[0-9]}/', $_SERVER['QUERY_STRING']) !== 0) {
+ if (!empty($_SERVER['QUERY_STRING']) && preg_match('/{[0-9]}/', $_SERVER['QUERY_STRING']) !== 0) {
killme();
}
- if ((x($_SERVER, 'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
+ if (!empty($_SERVER['QUERY_STRING']) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']);
goaway(System::baseUrl() . $_SERVER['REQUEST_URI']);
}
logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG);
header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . L10n::t('Not Found'));
$tpl = get_markup_template("404.tpl");
- $a->page['content'] = replace_macros(
- $tpl,
- [
- '$message' => L10n::t('Page not found.')]
- );
+ $a->page['content'] = replace_macros($tpl, [
+ '$message' => L10n::t('Page not found.')
+ ]);
}
}
/* initialise content region */
-if (! x($a->page, 'content')) {
- $a->page['content'] = '';
-}
-
if ($a->mode == App::MODE_NORMAL) {
Addon::callHooks('page_content_top', $a->page['content']);
}
$a->page['page_title'] = $a->module;
$placeholder = '';
+ Addon::callHooks($a->module . '_mod_init', $placeholder);
+
if ($a->module_class) {
- Addon::callHooks($a->module . '_mod_init', $placeholder);
call_user_func([$a->module_class, 'init']);
} else if (function_exists($a->module . '_init')) {
- Addon::callHooks($a->module . '_mod_init', $placeholder);
$func = $a->module . '_init';
$func($a);
}
+ // "rawContent" is especially meant for technical endpoints.
+ // This endpoint doesn't need any theme initialization or other comparable stuff.
+ if (!$a->error && $a->module_class) {
+ call_user_func([$a->module_class, 'rawContent']);
+ }
+
if (function_exists(str_replace('-', '_', $a->getCurrentTheme()) . '_init')) {
$func = str_replace('-', '_', $a->getCurrentTheme()) . '_init';
$func($a);
* theme choices made by the modules can take effect.
*/
-$a->init_pagehead();
+$a->initHead();
/*
* Build the page ending -- this is stuff that goes right before
* the closing </body> tag
*/
-$a->init_page_end();
-
-// If you're just visiting, let javascript take you home
-if (x($_SESSION, 'visitor_home')) {
- $homebase = $_SESSION['visitor_home'];
-} elseif (local_user()) {
- $homebase = 'profile/' . $a->user['nickname'];
-}
-
-if (isset($homebase)) {
- $a->page['content'] .= '<script>var homebase="' . $homebase . '" ; </script>';
-}
+$a->initFooter();
/*
* now that we've been through the module content, see if the page reported
Nav::build($a);
}
-/*
- * Add a "toggle mobile" link if we're using a mobile device
- */
-if ($a->is_mobile || $a->is_tablet) {
- if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
- $link = 'toggle_mobile?address=' . curPageURL();
- } else {
- $link = 'toggle_mobile?off=1&address=' . curPageURL();
- }
- $a->page['footer'] = replace_macros(
- get_markup_template("toggle_mobile_footer.tpl"),
- [
- '$toggle_link' => $link,
- '$toggle_text' => L10n::t('toggle mobile')]
- );
-}
-
/**
* Build the page - now that we have all the components
*/
-
-if (!$a->theme['stylesheet']) {
- $stylesheet = $a->getCurrentThemeStylesheetPath();
-} else {
- $stylesheet = $a->theme['stylesheet'];
-}
-
-$a->page['htmlhead'] = str_replace('{{$stylesheet}}', $stylesheet, $a->page['htmlhead']);
-//$a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => $stylesheet));
-
if (isset($_GET["mode"]) && (($_GET["mode"] == "raw") || ($_GET["mode"] == "minimal"))) {
$doc = new DOMDocument();
echo substr($target->saveHTML(), 6, -8);
- killme();
+ exit();
}
$page = $a->page;
/// @TODO Looks unsafe (remote-inclusion), is maybe not but Theme::getPathForFile() uses file_exists() but does not escape anything
require_once $template;
-
-killme();
$queues = ['label' => L10n::t('Message queues'), 'queue' => $queue, 'workerq' => $workerqueue];
+ $r = q("SHOW variables LIKE 'max_allowed_packet'");
+ $max_allowed_packet = (($r) ? $r[0]['Value'] : 0);
+
+ $server_settings = ['label' => L10n::t('Server Settings'),
+ 'php' => ['upload_max_filesize' => ini_get('upload_max_filesize'),
+ 'post_max_size' => ini_get('post_max_size'),
+ 'memory_limit' => ini_get('memory_limit')],
+ 'mysql' => ['max_allowed_packet' => $max_allowed_packet]];
+
$t = get_markup_template('admin/summary.tpl');
return replace_macros($t, [
'$title' => L10n::t('Administration'),
'$codename' => FRIENDICA_CODENAME,
'$build' => Config::get('system', 'build'),
'$addons' => [L10n::t('Active addons'), $a->addons],
+ '$serversettings' => $server_settings,
'$showwarning' => $showwarning,
'$warningtext' => $warningtext
]);
'$community_page_style' => ['community_page_style', L10n::t("Community pages for visitors"), Config::get('system','community_page_style'), L10n::t("Which community pages should be available for visitors. Local users always see both pages."), $community_page_style_choices],
'$max_author_posts_community_page' => ['max_author_posts_community_page', L10n::t("Posts per user on community page"), Config::get('system','max_author_posts_community_page'), L10n::t("The maximum number of posts per user on the community page. \x28Not valid for 'Global Community'\x29")],
'$ostatus_disabled' => ['ostatus_disabled', L10n::t("Enable OStatus support"), !Config::get('system','ostatus_disabled'), L10n::t("Provide built-in OStatus \x28StatusNet, GNU Social etc.\x29 compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.")],
- '$ostatus_full_threads' => ['ostatus_full_threads', L10n::t("Only import OStatus threads from our contacts"), Config::get('system','ostatus_full_threads'), L10n::t("Normally we import every content from our OStatus contacts. With this option we only store threads that are started by a contact that is known on our system.")],
+ '$ostatus_full_threads' => ['ostatus_full_threads', L10n::t("Only import OStatus/ActivityPub threads from our contacts"), Config::get('system','ostatus_full_threads'), L10n::t("Normally we import every content from our OStatus and ActivityPub contacts. With this option we only store threads that are started by a contact that is known on our system.")],
'$ostatus_not_able' => L10n::t("OStatus support can only be enabled if threading is enabled."),
'$diaspora_able' => $diaspora_able,
'$diaspora_not_able' => L10n::t("Diaspora support can't be enabled because Friendica was installed into a sub directory."),
'$baseurl' => System::baseUrl(true),
'$base' => $base
]);
-
- $tpl = get_markup_template("contacts-end.tpl");
- $a->page['end'] .= replace_macros($tpl, [
- '$baseurl' => System::baseUrl(true),
- '$base' => $base
- ]);
}
function contacts_batch_actions(App $a)
$a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), [
'$baseurl' => System::baseUrl(true),
]);
- $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), [
- '$baseurl' => System::baseUrl(true),
- ]);
$contact['blocked'] = Contact::isBlockedByUser($contact['id'], local_user());
$contact['readonly'] = Contact::isIgnoredByUser($contact['id'], local_user());
$relation_text = '';
}
- if (!in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
+ if (!in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
$relation_text = "";
}
}
$lblsuggest = (($contact['network'] === Protocol::DFRN) ? L10n::t('Suggest friends') : '');
- $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
+ $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
$nettype = L10n::t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact["url"]));
$profiledata = Contact::getDetailsByURL($contact["url"]);
if (local_user()) {
- if (in_array($profiledata["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
+ if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
$profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
}
}
$profiledata = Contact::getDetailsByURL($contact["url"]);
if (local_user()) {
- if (in_array($profiledata["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
+ if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
$profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
}
}
*/
function contact_actions($contact)
{
- $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
+ $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
$contact_actions = [];
// Provide friend suggestion only for Friendica contacts