Merge remote-tracking branch 'upstream/develop' into item-notification

This commit is contained in:
Michael 2020-01-04 22:53:06 +00:00
commit 30a4b0eafb
37 changed files with 219 additions and 216 deletions

View file

@ -234,29 +234,6 @@ if (!defined('CURLE_OPERATION_TIMEDOUT')) {
define('CURLE_OPERATION_TIMEDOUT', CURLE_OPERATION_TIMEOUTED); define('CURLE_OPERATION_TIMEDOUT', CURLE_OPERATION_TIMEOUTED);
} }
/**
* @brief Retrieve the App structure
*
* Useful in functions which require it but don't get it passed to them
*
* @deprecated since version 2018.09
* @see DI::app()
* @return App
*/
function get_app()
{
return DI::app();
}
/**
* @brief Used to end the current process, after saving session state.
* @deprecated
*/
function killme()
{
exit();
}
/** /**
* @brief Returns the user id of locally logged in user or false. * @brief Returns the user id of locally logged in user or false.
* *
@ -325,7 +302,7 @@ function notice($s)
return; return;
} }
$a = \get_app(); $a = DI::app();
if (empty($_SESSION['sysmsg'])) { if (empty($_SESSION['sysmsg'])) {
$_SESSION['sysmsg'] = []; $_SESSION['sysmsg'] = [];
} }
@ -343,7 +320,7 @@ function notice($s)
*/ */
function info($s) function info($s)
{ {
$a = \get_app(); $a = DI::app();
if (local_user() && PConfig::get(local_user(), 'system', 'ignore_info')) { if (local_user() && PConfig::get(local_user(), 'system', 'ignore_info')) {
return; return;
@ -406,7 +383,7 @@ function feed_birthday($uid, $tz)
*/ */
function is_site_admin() function is_site_admin()
{ {
$a = \get_app(); $a = DI::app();
$admin_email = Config::get('config', 'admin_email'); $admin_email = Config::get('config', 'admin_email');
@ -683,22 +660,3 @@ function validate_include(&$file)
// Simply return flag // Simply return flag
return $valid; return $valid;
} }
/**
* PHP 5 compatible dirname() with count parameter
*
* @see http://php.net/manual/en/function.dirname.php#113193
*
* @deprecated with PHP 7
* @param string $path
* @param int $levels
* @return string
*/
function rdirname($path, $levels = 1)
{
if ($levels > 1) {
return dirname(rdirname($path, --$levels));
} else {
return dirname($path);
}
}

View file

@ -930,7 +930,7 @@ function api_format_data($root_element, $type, $data)
*/ */
function api_account_verify_credentials($type) function api_account_verify_credentials($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -998,7 +998,7 @@ function requestdata($k)
*/ */
function api_statuses_mediap($type) function api_statuses_mediap($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
Logger::log('api_statuses_update: no user'); Logger::log('api_statuses_update: no user');
@ -1052,7 +1052,7 @@ api_register_func('api/statuses/mediap', 'api_statuses_mediap', true, API_METHOD
*/ */
function api_statuses_update($type) function api_statuses_update($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
Logger::log('api_statuses_update: no user'); Logger::log('api_statuses_update: no user');
@ -1202,7 +1202,7 @@ api_register_func('api/statuses/update_with_media', 'api_statuses_update', true,
*/ */
function api_media_upload() function api_media_upload()
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
Logger::log('no user'); Logger::log('no user');
@ -1257,7 +1257,7 @@ api_register_func('api/media/upload', 'api_media_upload', true, API_METHOD_POST)
*/ */
function api_media_metadata_create($type) function api_media_metadata_create($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
Logger::info('no user'); Logger::info('no user');
@ -1404,7 +1404,7 @@ api_register_func('api/externalprofile/show', 'api_users_show');
*/ */
function api_users_search($type) function api_users_search($type)
{ {
$a = \get_app(); $a = DI::app();
$userlist = []; $userlist = [];
@ -1466,7 +1466,7 @@ function api_users_lookup($type)
if (!empty($_REQUEST['user_id'])) { if (!empty($_REQUEST['user_id'])) {
foreach (explode(',', $_REQUEST['user_id']) as $id) { foreach (explode(',', $_REQUEST['user_id']) as $id) {
if (!empty($id)) { if (!empty($id)) {
$users[] = api_get_user(get_app(), $id); $users[] = api_get_user(DI::app(), $id);
} }
} }
} }
@ -1497,7 +1497,7 @@ api_register_func('api/users/lookup', 'api_users_lookup', true);
*/ */
function api_search($type) function api_search($type)
{ {
$a = \get_app(); $a = DI::app();
$user_info = api_get_user($a); $user_info = api_get_user($a);
if (api_user() === false || $user_info === false) { if (api_user() === false || $user_info === false) {
@ -1611,7 +1611,7 @@ api_register_func('api/search', 'api_search', true);
*/ */
function api_statuses_home_timeline($type) function api_statuses_home_timeline($type)
{ {
$a = \get_app(); $a = DI::app();
$user_info = api_get_user($a); $user_info = api_get_user($a);
if (api_user() === false || $user_info === false) { if (api_user() === false || $user_info === false) {
@ -1704,7 +1704,7 @@ api_register_func('api/statuses/friends_timeline', 'api_statuses_home_timeline',
*/ */
function api_statuses_public_timeline($type) function api_statuses_public_timeline($type)
{ {
$a = \get_app(); $a = DI::app();
$user_info = api_get_user($a); $user_info = api_get_user($a);
if (api_user() === false || $user_info === false) { if (api_user() === false || $user_info === false) {
@ -1789,7 +1789,7 @@ api_register_func('api/statuses/public_timeline', 'api_statuses_public_timeline'
*/ */
function api_statuses_networkpublic_timeline($type) function api_statuses_networkpublic_timeline($type)
{ {
$a = \get_app(); $a = DI::app();
$user_info = api_get_user($a); $user_info = api_get_user($a);
if (api_user() === false || $user_info === false) { if (api_user() === false || $user_info === false) {
@ -1850,7 +1850,7 @@ api_register_func('api/statuses/networkpublic_timeline', 'api_statuses_networkpu
*/ */
function api_statuses_show($type) function api_statuses_show($type)
{ {
$a = \get_app(); $a = DI::app();
$user_info = api_get_user($a); $user_info = api_get_user($a);
if (api_user() === false || $user_info === false) { if (api_user() === false || $user_info === false) {
@ -1929,7 +1929,7 @@ api_register_func('api/statuses/show', 'api_statuses_show', true);
*/ */
function api_conversation_show($type) function api_conversation_show($type)
{ {
$a = \get_app(); $a = DI::app();
$user_info = api_get_user($a); $user_info = api_get_user($a);
if (api_user() === false || $user_info === false) { if (api_user() === false || $user_info === false) {
@ -2011,7 +2011,7 @@ function api_statuses_repeat($type)
{ {
global $called_api; global $called_api;
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -2088,7 +2088,7 @@ api_register_func('api/statuses/retweet', 'api_statuses_repeat', true, API_METHO
*/ */
function api_statuses_destroy($type) function api_statuses_destroy($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -2135,7 +2135,7 @@ api_register_func('api/statuses/destroy', 'api_statuses_destroy', true, API_METH
*/ */
function api_statuses_mentions($type) function api_statuses_mentions($type)
{ {
$a = \get_app(); $a = DI::app();
$user_info = api_get_user($a); $user_info = api_get_user($a);
if (api_user() === false || $user_info === false) { if (api_user() === false || $user_info === false) {
@ -2204,7 +2204,7 @@ api_register_func('api/statuses/replies', 'api_statuses_mentions', true);
*/ */
function api_statuses_user_timeline($type) function api_statuses_user_timeline($type)
{ {
$a = \get_app(); $a = DI::app();
$user_info = api_get_user($a); $user_info = api_get_user($a);
if (api_user() === false || $user_info === false) { if (api_user() === false || $user_info === false) {
@ -2288,7 +2288,7 @@ api_register_func('api/statuses/user_timeline', 'api_statuses_user_timeline', tr
*/ */
function api_favorites_create_destroy($type) function api_favorites_create_destroy($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -2371,7 +2371,7 @@ function api_favorites($type)
{ {
global $called_api; global $called_api;
$a = \get_app(); $a = DI::app();
$user_info = api_get_user($a); $user_info = api_get_user($a);
if (api_user() === false || $user_info === false) { if (api_user() === false || $user_info === false) {
@ -2836,7 +2836,7 @@ function api_contactlink_to_array($txt)
*/ */
function api_format_items_activities($item, $type = "json") function api_format_items_activities($item, $type = "json")
{ {
$a = \get_app(); $a = DI::app();
$activities = [ $activities = [
'like' => [], 'like' => [],
@ -3257,7 +3257,7 @@ api_register_func('api/lists/subscriptions', 'api_lists_list', true);
*/ */
function api_lists_ownerships($type) function api_lists_ownerships($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -3306,7 +3306,7 @@ api_register_func('api/lists/ownerships', 'api_lists_ownerships', true);
*/ */
function api_lists_statuses($type) function api_lists_statuses($type)
{ {
$a = \get_app(); $a = DI::app();
$user_info = api_get_user($a); $user_info = api_get_user($a);
if (api_user() === false || $user_info === false) { if (api_user() === false || $user_info === false) {
@ -3384,7 +3384,7 @@ api_register_func('api/lists/statuses', 'api_lists_statuses', true);
*/ */
function api_statuses_f($qtype) function api_statuses_f($qtype)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -3636,7 +3636,7 @@ function api_ff_ids($type, int $rel)
throw new ForbiddenException(); throw new ForbiddenException();
} }
$a = \get_app(); $a = DI::app();
api_get_user($a); api_get_user($a);
@ -3723,7 +3723,7 @@ api_register_func('api/followers/ids', 'api_followers_ids', true);
*/ */
function api_direct_messages_new($type) function api_direct_messages_new($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -3815,7 +3815,7 @@ api_register_func('api/direct_messages/new', 'api_direct_messages_new', true, AP
*/ */
function api_direct_messages_destroy($type) function api_direct_messages_destroy($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -3983,7 +3983,7 @@ api_register_func('api/friendships/destroy', 'api_friendships_destroy', true, AP
*/ */
function api_direct_messages_box($type, $box, $verbose) function api_direct_messages_box($type, $box, $verbose)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
} }
@ -4627,7 +4627,7 @@ function api_account_update_profile_image($type)
Contact::updateSelfFromUserID(api_user(), true); Contact::updateSelfFromUserID(api_user(), true);
// Update global directory in background // Update global directory in background
$url = DI::baseUrl() . '/profile/' . \get_app()->user['nickname']; $url = DI::baseUrl() . '/profile/' . DI::app()->user['nickname'];
if ($url && strlen(Config::get('system', 'directory'))) { if ($url && strlen(Config::get('system', 'directory'))) {
Worker::add(PRIORITY_LOW, "Directory", $url); Worker::add(PRIORITY_LOW, "Directory", $url);
} }
@ -4668,7 +4668,7 @@ api_register_func('api/account/update_profile_image', 'api_account_update_profil
function api_account_update_profile($type) function api_account_update_profile($type)
{ {
$local_user = api_user(); $local_user = api_user();
$api_user = api_get_user(get_app()); $api_user = api_get_user(DI::app());
if (!empty($_POST['name'])) { if (!empty($_POST['name'])) {
DBA::update('profile', ['name' => $_POST['name']], ['uid' => $local_user]); DBA::update('profile', ['name' => $_POST['name']], ['uid' => $local_user]);
@ -4963,7 +4963,7 @@ function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $f
*/ */
function prepare_photo_data($type, $scale, $photo_id) function prepare_photo_data($type, $scale, $photo_id)
{ {
$a = \get_app(); $a = DI::app();
$user_info = api_get_user($a); $user_info = api_get_user($a);
if ($user_info === false) { if ($user_info === false) {
@ -5391,7 +5391,7 @@ function api_best_nickname(&$contacts)
*/ */
function api_friendica_group_show($type) function api_friendica_group_show($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -5461,7 +5461,7 @@ api_register_func('api/friendica/group_show', 'api_friendica_group_show', true);
*/ */
function api_friendica_group_delete($type) function api_friendica_group_delete($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -5528,7 +5528,7 @@ api_register_func('api/friendica/group_delete', 'api_friendica_group_delete', tr
*/ */
function api_lists_destroy($type) function api_lists_destroy($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -5650,7 +5650,7 @@ function group_create($name, $uid, $users = [])
*/ */
function api_friendica_group_create($type) function api_friendica_group_create($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -5684,7 +5684,7 @@ api_register_func('api/friendica/group_create', 'api_friendica_group_create', tr
*/ */
function api_lists_create($type) function api_lists_create($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -5723,7 +5723,7 @@ api_register_func('api/lists/create', 'api_lists_create', true, API_METHOD_POST)
*/ */
function api_friendica_group_update($type) function api_friendica_group_update($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -5802,7 +5802,7 @@ api_register_func('api/friendica/group_update', 'api_friendica_group_update', tr
*/ */
function api_lists_update($type) function api_lists_update($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -5852,7 +5852,7 @@ api_register_func('api/lists/update', 'api_lists_update', true, API_METHOD_POST)
*/ */
function api_friendica_activity($type) function api_friendica_activity($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -5899,7 +5899,7 @@ api_register_func('api/friendica/activity/unattendmaybe', 'api_friendica_activit
*/ */
function api_friendica_notification($type) function api_friendica_notification($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -5937,7 +5937,7 @@ function api_friendica_notification($type)
*/ */
function api_friendica_notification_seen($type) function api_friendica_notification_seen($type)
{ {
$a = \get_app(); $a = DI::app();
$user_info = api_get_user($a); $user_info = api_get_user($a);
if (api_user() === false || $user_info === false) { if (api_user() === false || $user_info === false) {
@ -5987,7 +5987,7 @@ api_register_func('api/friendica/notification', 'api_friendica_notification', tr
*/ */
function api_friendica_direct_messages_setseen($type) function api_friendica_direct_messages_setseen($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
} }
@ -6041,7 +6041,7 @@ api_register_func('api/friendica/direct_messages_setseen', 'api_friendica_direct
*/ */
function api_friendica_direct_messages_search($type, $box = "") function api_friendica_direct_messages_search($type, $box = "")
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();
@ -6109,7 +6109,7 @@ api_register_func('api/friendica/direct_messages_search', 'api_friendica_direct_
*/ */
function api_friendica_profile_show($type) function api_friendica_profile_show($type)
{ {
$a = \get_app(); $a = DI::app();
if (api_user() === false) { if (api_user() === false) {
throw new ForbiddenException(); throw new ForbiddenException();

View file

@ -33,7 +33,7 @@ use Friendica\Util\Strings;
*/ */
function notification($params) function notification($params)
{ {
$a = \get_app(); $a = DI::app();
// Temporary logging for finding the origin // Temporary logging for finding the origin
if (!isset($params['uid'])) { if (!isset($params['uid'])) {

View file

@ -258,7 +258,7 @@ function consume_feed($xml, array $importer, array $contact, &$hub)
if ($contact['network'] === Protocol::FEED) { if ($contact['network'] === Protocol::FEED) {
Logger::log("Consume feeds", Logger::DEBUG); Logger::log("Consume feeds", Logger::DEBUG);
Feed::import($xml, $importer, $contact, $hub); Feed::import($xml, $importer, $contact);
return; return;
} }

View file

@ -78,7 +78,7 @@ function fbrowser_content(App $a)
function _map_files1($rr) function _map_files1($rr)
{ {
$a = \get_app(); $a = DI::app();
$types = Images::supportedTypes(); $types = Images::supportedTypes();
$ext = $types[$rr['type']]; $ext = $types[$rr['type']];
$filename_e = $rr['filename']; $filename_e = $rr['filename'];

View file

@ -246,7 +246,7 @@ function item_post(App $a) {
$app = $orig_post['app']; $app = $orig_post['app'];
$categories = $orig_post['file']; $categories = $orig_post['file'];
$title = Strings::escapeTags(trim($_REQUEST['title'])); $title = Strings::escapeTags(trim($_REQUEST['title']));
$body = Strings::escapeHtml(trim($body)); $body = trim($body);
$private = $orig_post['private']; $private = $orig_post['private'];
$pubmail_enabled = $orig_post['pubmail']; $pubmail_enabled = $orig_post['pubmail'];
$network = $orig_post['network']; $network = $orig_post['network'];
@ -285,7 +285,7 @@ function item_post(App $a) {
$coord = Strings::escapeTags(trim($_REQUEST['coord'] ?? '')); $coord = Strings::escapeTags(trim($_REQUEST['coord'] ?? ''));
$verb = Strings::escapeTags(trim($_REQUEST['verb'] ?? '')); $verb = Strings::escapeTags(trim($_REQUEST['verb'] ?? ''));
$emailcc = Strings::escapeTags(trim($_REQUEST['emailcc'] ?? '')); $emailcc = Strings::escapeTags(trim($_REQUEST['emailcc'] ?? ''));
$body = Strings::escapeHtml(trim($body)); $body = trim($body);
$network = Strings::escapeTags(trim(($_REQUEST['network'] ?? '') ?: Protocol::DFRN)); $network = Strings::escapeTags(trim(($_REQUEST['network'] ?? '') ?: Protocol::DFRN));
$guid = System::createUUID(); $guid = System::createUUID();
@ -509,7 +509,7 @@ function item_post(App $a) {
// Fold multi-line [code] sequences // Fold multi-line [code] sequences
$body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body); $body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body);
$body = BBCode::scaleExternalImages($body, false); $body = BBCode::scaleExternalImages($body);
// Setting the object type if not defined before // Setting the object type if not defined before
if (!$objecttype) { if (!$objecttype) {
@ -848,7 +848,7 @@ function item_post(App $a) {
function item_post_return($baseurl, $api_source, $return_path) function item_post_return($baseurl, $api_source, $return_path)
{ {
// figure out how to return, depending on from whence we came // figure out how to return, depending on from whence we came
$a = \get_app(); $a = DI::app();
if ($api_source) { if ($api_source) {
return; return;

View file

@ -499,7 +499,7 @@ function get_messages($uid, $start, $limit)
function render_messages(array $msg, $t) function render_messages(array $msg, $t)
{ {
$a = \get_app(); $a = DI::app();
$tpl = Renderer::getMarkupTemplate($t); $tpl = Renderer::getMarkupTemplate($t);
$rslt = ''; $rslt = '';

View file

@ -814,7 +814,7 @@ function photos_post(App $a)
Hook::callAll('photo_post_end', $item_id); Hook::callAll('photo_post_end', $item_id);
// addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook // addon uploaders should call "exit()" within the photo_post_end hook
// if they do not wish to be redirected // if they do not wish to be redirected
DI::baseUrl()->redirect($_SESSION['photo_return']); DI::baseUrl()->redirect($_SESSION['photo_return']);

View file

@ -33,7 +33,7 @@ function get_theme_config_file($theme)
{ {
$theme = Strings::sanitizeFilePathItem($theme); $theme = Strings::sanitizeFilePathItem($theme);
$a = \get_app(); $a = DI::app();
$base_theme = $a->theme_info['extends'] ?? ''; $base_theme = $a->theme_info['extends'] ?? '';
if (file_exists("view/theme/$theme/config.php")) { if (file_exists("view/theme/$theme/config.php")) {

View file

@ -355,7 +355,7 @@ class BaseURL
if (!empty($relative_script_path)) { if (!empty($relative_script_path)) {
// Module // Module
if (!empty($this->server['QUERY_STRING'])) { if (!empty($this->server['QUERY_STRING'])) {
$this->urlPath = trim(rdirname($relative_script_path, substr_count(trim($this->server['QUERY_STRING'], '/'), '/') + 1), '/'); $this->urlPath = trim(dirname($relative_script_path, substr_count(trim($this->server['QUERY_STRING'], '/'), '/') + 1), '/');
} else { } else {
// Root page // Root page
$this->urlPath = trim($relative_script_path, '/'); $this->urlPath = trim($relative_script_path, '/');

View file

@ -88,7 +88,7 @@ abstract class BaseModule
*/ */
public static function getFormSecurityToken($typename = '') public static function getFormSecurityToken($typename = '')
{ {
$a = \get_app(); $a = DI::app();
$timestamp = time(); $timestamp = time();
$sec_hash = hash('whirlpool', $a->user['guid'] . $a->user['prvkey'] . session_id() . $timestamp . $typename); $sec_hash = hash('whirlpool', $a->user['guid'] . $a->user['prvkey'] . session_id() . $timestamp . $typename);
@ -116,7 +116,7 @@ abstract class BaseModule
$max_livetime = 10800; // 3 hours $max_livetime = 10800; // 3 hours
$a = \get_app(); $a = DI::app();
$x = explode('.', $hash); $x = explode('.', $hash);
if (time() > (intval($x[0]) + $max_livetime)) { if (time() > (intval($x[0]) + $max_livetime)) {
@ -136,7 +136,7 @@ abstract class BaseModule
public static function checkFormSecurityTokenRedirectOnError($err_redirect, $typename = '', $formname = 'form_security_token') public static function checkFormSecurityTokenRedirectOnError($err_redirect, $typename = '', $formname = 'form_security_token')
{ {
if (!self::checkFormSecurityToken($typename, $formname)) { if (!self::checkFormSecurityToken($typename, $formname)) {
$a = \get_app(); $a = DI::app();
Logger::log('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename); Logger::log('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
Logger::log('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), Logger::DATA); Logger::log('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), Logger::DATA);
notice(self::getFormSecurityStandardErrorMessage()); notice(self::getFormSecurityStandardErrorMessage());
@ -147,7 +147,7 @@ abstract class BaseModule
public static function checkFormSecurityTokenForbiddenOnError($typename = '', $formname = 'form_security_token') public static function checkFormSecurityTokenForbiddenOnError($typename = '', $formname = 'form_security_token')
{ {
if (!self::checkFormSecurityToken($typename, $formname)) { if (!self::checkFormSecurityToken($typename, $formname)) {
$a = \get_app(); $a = DI::app();
Logger::log('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename); Logger::log('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
Logger::log('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), Logger::DATA); Logger::log('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), Logger::DATA);

View file

@ -2,6 +2,8 @@
namespace Friendica\Console; namespace Friendica\Console;
use Friendica\App;
/** /**
* When I installed docblox, I had the experience that it does not generate any output at all. * When I installed docblox, I had the experience that it does not generate any output at all.
* This script may be used to find that kind of problems with the documentation build process. * This script may be used to find that kind of problems with the documentation build process.
@ -29,6 +31,16 @@ class DocBloxErrorChecker extends \Asika\SimpleConsole\Console
protected $helpOptions = ['h', 'help', '?']; protected $helpOptions = ['h', 'help', '?'];
/** @var App */
private $app;
public function __construct(App $app, array $argv = null)
{
parent::__construct($argv);
$this->app = $app;
}
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -59,7 +71,7 @@ HELP;
throw new \RuntimeException('DocBlox isn\'t available.'); throw new \RuntimeException('DocBlox isn\'t available.');
} }
$dir = \get_app()->getBasePath(); $dir = $this->app->getBasePath();
//stack for dirs to search //stack for dirs to search
$dirstack = []; $dirstack = [];

View file

@ -2,6 +2,8 @@
namespace Friendica\Console; namespace Friendica\Console;
use Friendica\App;
/** /**
* Read a strings.php file and create messages.po in the same directory * Read a strings.php file and create messages.po in the same directory
* *
@ -15,6 +17,16 @@ class PhpToPo extends \Asika\SimpleConsole\Console
private $normBaseMsgIds = []; private $normBaseMsgIds = [];
const NORM_REGEXP = "|[\\\]|"; const NORM_REGEXP = "|[\\\]|";
/** @var App */
private $app;
public function __construct(App $app, array $argv = null)
{
parent::__construct($argv);
$this->app = $app;
}
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -51,7 +63,7 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
} }
$a = \get_app(); $a = $this->app;
$phpfile = realpath($this->getArgument(0)); $phpfile = realpath($this->getArgument(0));

View file

@ -57,7 +57,7 @@ class OEmbed
{ {
$embedurl = trim($embedurl, '\'"'); $embedurl = trim($embedurl, '\'"');
$a = \get_app(); $a = DI::app();
$cache_key = 'oembed:' . $a->videowidth . ':' . $embedurl; $cache_key = 'oembed:' . $a->videowidth . ':' . $embedurl;

View file

@ -436,15 +436,9 @@ class BBCode
} }
} }
public static function scaleExternalImages($srctext, $include_link = true, $scale_replace = false) public static function scaleExternalImages($srctext)
{ {
// Suppress "view full size" $s = $srctext;
if (intval(Config::get('system', 'no_view_full_size'))) {
$include_link = false;
}
// Picture addresses can contain special characters
$s = htmlspecialchars_decode($srctext);
$matches = null; $matches = null;
$c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER); $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER);
@ -457,17 +451,7 @@ class BBCode
continue; continue;
} }
// $scale_replace, if passed, is an array of two elements. The $i = Network::fetchUrl($mtch[1]);
// first is the name of the full-size image. The second is the
// name of a remote, scaled-down version of the full size image.
// This allows Friendica to display the smaller remote image if
// one exists, while still linking to the full-size image
if ($scale_replace) {
$scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[1]);
} else {
$scaled = $mtch[1];
}
$i = Network::fetchUrl($scaled);
if (!$i) { if (!$i) {
return $srctext; return $srctext;
} }
@ -488,10 +472,8 @@ class BBCode
Logger::log('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], Logger::DEBUG); Logger::log('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], Logger::DEBUG);
$s = str_replace( $s = str_replace(
$mtch[0], $mtch[0],
'[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]' '[img=' . $new_width . 'x' . $new_height. ']' . $mtch[1] . '[/img]'
. "\n" . (($include_link) . "\n",
? '[url=' . $mtch[1] . ']' . L10n::t('view full size') . '[/url]' . "\n"
: ''),
$s $s
); );
Logger::log('scale_external_images: new string: ' . $s, Logger::DEBUG); Logger::log('scale_external_images: new string: ' . $s, Logger::DEBUG);
@ -501,8 +483,6 @@ class BBCode
} }
} }
// replace the special char encoding
$s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8');
return $s; return $s;
} }

View file

@ -12,6 +12,7 @@ use Friendica\Core\Hook;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Proxy as ProxyUtils;
@ -815,7 +816,7 @@ class HTML
*/ */
public static function contactBlock() public static function contactBlock()
{ {
$a = \get_app(); $a = DI::app();
return ContactBlock::getHTML($a->profile); return ContactBlock::getHTML($a->profile);
} }

View file

@ -119,7 +119,7 @@ class Markdown
$s = preg_replace('/(\[code\])+(.*?)(\[\/code\])+/ism', '[code]$2[/code]', $s); $s = preg_replace('/(\[code\])+(.*?)(\[\/code\])+/ism', '[code]$2[/code]', $s);
// Don't show link to full picture (until it is fixed) // Don't show link to full picture (until it is fixed)
$s = BBCode::scaleExternalImages($s, false); $s = BBCode::scaleExternalImages($s);
return $s; return $s;
} }

View file

@ -302,7 +302,7 @@ class Widget
*/ */
public static function categories($baseurl, $selected = '') public static function categories($baseurl, $selected = '')
{ {
$a = \get_app(); $a = DI::app();
$uid = intval($a->profile['profile_uid']); $uid = intval($a->profile['profile_uid']);
@ -420,7 +420,7 @@ class Widget
*/ */
public static function tagCloud($limit = 50) public static function tagCloud($limit = 50)
{ {
$a = \get_app(); $a = DI::app();
$uid = intval($a->profile['profile_uid']); $uid = intval($a->profile['profile_uid']);

View file

@ -9,6 +9,7 @@ namespace Friendica\Content\Widget;
use Friendica\Content\Feature; use Friendica\Content\Feature;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\DI;
/** /**
* TagCloud widget * TagCloud widget
@ -24,7 +25,7 @@ class CalendarExport
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function getHTML() { public static function getHTML() {
$a = \get_app(); $a = DI::app();
if (empty($a->data['user'])) { if (empty($a->data['user'])) {
return; return;

View file

@ -283,7 +283,6 @@ class System
/// @todo Move the following functions from boot.php /// @todo Move the following functions from boot.php
/* /*
function killme()
function local_user() function local_user()
function public_contact() function public_contact()
function remote_user() function remote_user()

View file

@ -48,8 +48,6 @@ class Worker
*/ */
public static function processQueue($run_cron = true) public static function processQueue($run_cron = true)
{ {
$a = \get_app();
// Ensure that all "strtotime" operations do run timezone independent // Ensure that all "strtotime" operations do run timezone independent
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
@ -372,7 +370,7 @@ class Worker
*/ */
private static function execFunction($queue, $funcname, $argv, $method_call) private static function execFunction($queue, $funcname, $argv, $method_call)
{ {
$a = \get_app(); $a = DI::app();
$argc = count($argv); $argc = count($argv);
@ -1083,7 +1081,7 @@ class Worker
$args = ['no_cron' => !$do_cron]; $args = ['no_cron' => !$do_cron];
$a = get_app(); $a = DI::app();
$process = new Core\Process(DI::logger(), DI::mode(), DI::config(), $a->getBasePath()); $process = new Core\Process(DI::logger(), DI::mode(), DI::config(), $a->getBasePath());
$process->run($command, $args); $process->run($command, $args);

View file

@ -2220,7 +2220,7 @@ class Contact
{ {
$result = ['cid' => -1, 'success' => false, 'message' => '']; $result = ['cid' => -1, 'success' => false, 'message' => ''];
$a = \get_app(); $a = DI::app();
// remove ajax junk, e.g. Twitter // remove ajax junk, e.g. Twitter
$url = str_replace('/#!/', '/', $url); $url = str_replace('/#!/', '/', $url);

View file

@ -105,7 +105,7 @@ class Mail
*/ */
public static function send($recipient = 0, $body = '', $subject = '', $replyto = '') public static function send($recipient = 0, $body = '', $subject = '', $replyto = '')
{ {
$a = \get_app(); $a = DI::app();
if (!$recipient) { if (!$recipient) {
return -1; return -1;

View file

@ -461,7 +461,7 @@ class Photo
$micro = DI::baseUrl() . "/photo/" . $resource_id . "-6." . $Image->getExt() . $suffix; $micro = DI::baseUrl() . "/photo/" . $resource_id . "-6." . $Image->getExt() . $suffix;
// Remove the cached photo // Remove the cached photo
$a = \get_app(); $a = DI::app();
$basepath = $a->getBasePath(); $basepath = $a->getBasePath();
if (is_dir($basepath . "/photo")) { if (is_dir($basepath . "/photo")) {

View file

@ -568,7 +568,7 @@ class Profile
public static function getBirthdays() public static function getBirthdays()
{ {
$a = \get_app(); $a = DI::app();
$o = ''; $o = '';
if (!local_user() || DI::mode()->isMobile() || DI::mode()->isMobile()) { if (!local_user() || DI::mode()->isMobile() || DI::mode()->isMobile()) {
@ -665,7 +665,7 @@ class Profile
public static function getEventsReminderHTML() public static function getEventsReminderHTML()
{ {
$a = \get_app(); $a = DI::app();
$o = ''; $o = '';
if (!local_user() || DI::mode()->isMobile() || DI::mode()->isMobile()) { if (!local_user() || DI::mode()->isMobile() || DI::mode()->isMobile()) {
@ -1106,7 +1106,7 @@ class Profile
*/ */
public static function addVisitorCookieForHandle($handle) public static function addVisitorCookieForHandle($handle)
{ {
$a = \get_app(); $a = DI::app();
// Try to find the public contact entry of the visitor. // Try to find the public contact entry of the visitor.
$cid = Contact::getIdForURL($handle); $cid = Contact::getIdForURL($handle);
@ -1144,7 +1144,7 @@ class Profile
*/ */
public static function openWebAuthInit($token) public static function openWebAuthInit($token)
{ {
$a = \get_app(); $a = DI::app();
// Clean old OpenWebAuthToken entries. // Clean old OpenWebAuthToken entries.
OpenWebAuthToken::purge('owt', '3 MINUTE'); OpenWebAuthToken::purge('owt', '3 MINUTE');

View file

@ -29,15 +29,12 @@ class Feed extends BaseModule
if (!empty($_REQUEST['url'])) { if (!empty($_REQUEST['url'])) {
$url = $_REQUEST['url']; $url = $_REQUEST['url'];
$importer = Model\User::getById(local_user());
$contact_id = Model\Contact::getIdForURL($url, local_user(), true); $contact_id = Model\Contact::getIdForURL($url, local_user(), true);
$contact = Model\Contact::getById($contact_id); $contact = Model\Contact::getById($contact_id);
$xml = Network::fetchUrl($contact['poll']); $xml = Network::fetchUrl($contact['poll']);
$dummy = null; $import_result = Protocol\Feed::import($xml);
$import_result = Protocol\Feed::import($xml, $importer, $contact, $dummy, true);
$result = [ $result = [
'input' => $xml, 'input' => $xml,

View file

@ -1480,10 +1480,7 @@ class Probe
return false; return false;
} }
$feed = $curlResult->getBody(); $feed = $curlResult->getBody();
$dummy1 = null; $feed_data = Feed::import($feed);
$dummy2 = null;
$dummy2 = null;
$feed_data = Feed::import($feed, $dummy1, $dummy2, $dummy3, true);
if (!$feed_data) { if (!$feed_data) {
return false; return false;
} }
@ -1763,8 +1760,7 @@ class Probe
return false; return false;
} }
$feed = $curlResult->getBody(); $feed = $curlResult->getBody();
$dummy1 = $dummy2 = $dummy3 = null; $feed_data = Feed::import($feed);
$feed_data = Feed::import($feed, $dummy1, $dummy2, $dummy3, true);
if (!$feed_data) { if (!$feed_data) {
if (!$probe) { if (!$probe) {

View file

@ -1304,12 +1304,17 @@ class Transmitter
$data['content'] = BBCode::convert($body, false, 9); $data['content'] = BBCode::convert($body, false, 9);
} }
// The regular "content" field does contain a minimized HTML. This is done since systems like
// Mastodon has got problems with - for example - embedded pictures.
// The contentMap does contain the unmodified HTML.
$language = self::getLanguage($item);
if (!empty($language)) {
$regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism"; $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
$richbody = preg_replace_callback($regexp, ['self', 'mentionCallback'], $item['body']); $richbody = preg_replace_callback($regexp, ['self', 'mentionCallback'], $item['body']);
$richbody = BBCode::removeAttachment($richbody); $richbody = BBCode::removeAttachment($richbody);
$data['contentMap']['text/html'] = BBCode::convert($richbody, false); $data['contentMap'][$language] = BBCode::convert($richbody, false);
$data['contentMap']['text/markdown'] = BBCode::toMarkdown($item["body"]); }
$data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"]; $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"];
@ -1333,6 +1338,35 @@ class Transmitter
return $data; return $data;
} }
/**
* Fetches the language from the post, the user or the system.
*
* @param array $item
*
* @return string language string
*/
private static function getLanguage(array $item)
{
// Try to fetch the language from the post itself
if (!empty($item['language'])) {
$languages = array_keys(json_decode($item['language'], true));
if (!empty($languages[0])) {
return $languages[0];
}
}
// Otherwise use the user's language
if (!empty($item['uid'])) {
$user = DBA::selectFirst('user', ['language'], ['uid' => $item['uid']]);
if (!empty($user['language'])) {
return $user['language'];
}
}
// And finally just use the system language
return Config::get('system', 'language');
}
/** /**
* Creates an an "add tag" entry * Creates an an "add tag" entry
* *

View file

@ -146,7 +146,7 @@ class DFRN
*/ */
public static function feed($dfrn_id, $owner_nick, $last_update, $direction = 0, $onlyheader = false) public static function feed($dfrn_id, $owner_nick, $last_update, $direction = 0, $onlyheader = false)
{ {
$a = \get_app(); $a = DI::app();
$sitefeed = ((strlen($owner_nick)) ? false : true); // not yet implemented, need to rewrite huge chunks of following logic $sitefeed = ((strlen($owner_nick)) ? false : true); // not yet implemented, need to rewrite huge chunks of following logic
$public_feed = (($dfrn_id) ? false : true); $public_feed = (($dfrn_id) ? false : true);

View file

@ -14,8 +14,8 @@ use Friendica\Core\Protocol;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Util\ParseUrl;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
use Friendica\Util\XML; use Friendica\Util\XML;
/** /**
@ -29,24 +29,23 @@ class Feed {
* @param string $xml The feed data * @param string $xml The feed data
* @param array $importer The user record of the importer * @param array $importer The user record of the importer
* @param array $contact The contact record of the feed * @param array $contact The contact record of the feed
* @param string $hub Unused dummy value for compatibility reasons
* @param bool $simulate If enabled, no data is imported
* *
* @return array In simulation mode it returns the header and the first item * @return array Returns the header and the first item in dry run mode
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function import($xml, $importer, &$contact, &$hub, $simulate = false) { public static function import($xml, array $importer = [], array $contact = [])
{
$dryRun = empty($importer) && empty($contact);
$a = \get_app(); if ($dryRun) {
Logger::info("Test Atom/RSS feed");
if (!$simulate) {
Logger::log("Import Atom/RSS feed '".$contact["name"]."' (Contact ".$contact["id"].") for user ".$importer["uid"], Logger::DEBUG);
} else { } else {
Logger::log("Test Atom/RSS feed", Logger::DEBUG); Logger::info("Import Atom/RSS feed '" . $contact["name"] . "' (Contact " . $contact["id"] . ") for user " . $importer["uid"]);
} }
if (empty($xml)) { if (empty($xml)) {
Logger::log('XML is empty.', Logger::DEBUG); Logger::info('XML is empty.');
return; return [];
} }
if (!empty($contact['poll'])) { if (!empty($contact['poll'])) {
@ -114,14 +113,17 @@ class Feed {
if (empty($author["author-name"])) { if (empty($author["author-name"])) {
$author["author-name"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:subtitle/text()'); $author["author-name"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:subtitle/text()');
} }
if (empty($author["author-name"])) { if (empty($author["author-name"])) {
$author["author-name"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:author/atom:name/text()'); $author["author-name"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:author/atom:name/text()');
} }
$value = XML::getFirstNodeValue($xpath, 'atom:author/poco:displayName/text()'); $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:displayName/text()');
if ($value != "") { if ($value != "") {
$author["author-name"] = $value; $author["author-name"] = $value;
} }
if ($simulate) {
if ($dryRun) {
$author["author-id"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:author/atom:id/text()'); $author["author-id"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:author/atom:id/text()');
// See https://tools.ietf.org/html/rfc4287#section-3.2.2 // See https://tools.ietf.org/html/rfc4287#section-3.2.2
@ -134,14 +136,17 @@ class Feed {
if ($value != "") { if ($value != "") {
$author["author-nick"] = $value; $author["author-nick"] = $value;
} }
$value = XML::getFirstNodeValue($xpath, 'atom:author/poco:address/poco:formatted/text()'); $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:address/poco:formatted/text()');
if ($value != "") { if ($value != "") {
$author["author-location"] = $value; $author["author-location"] = $value;
} }
$value = XML::getFirstNodeValue($xpath, 'atom:author/poco:note/text()'); $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:note/text()');
if ($value != "") { if ($value != "") {
$author["author-about"] = $value; $author["author-about"] = $value;
} }
$avatar = XML::getFirstAttributes($xpath, "atom:author/atom:link[@rel='avatar']"); $avatar = XML::getFirstAttributes($xpath, "atom:author/atom:link[@rel='avatar']");
if (is_object($avatar)) { if (is_object($avatar)) {
foreach ($avatar AS $attribute) { foreach ($avatar AS $attribute) {
@ -169,9 +174,11 @@ class Feed {
if (empty($author["author-name"])) { if (empty($author["author-name"])) {
$author["author-name"] = XML::getFirstNodeValue($xpath, '/rss/channel/copyright/text()'); $author["author-name"] = XML::getFirstNodeValue($xpath, '/rss/channel/copyright/text()');
} }
if (empty($author["author-name"])) { if (empty($author["author-name"])) {
$author["author-name"] = XML::getFirstNodeValue($xpath, '/rss/channel/description/text()'); $author["author-name"] = XML::getFirstNodeValue($xpath, '/rss/channel/description/text()');
} }
$author["edited"] = $author["created"] = XML::getFirstNodeValue($xpath, '/rss/channel/pubDate/text()'); $author["edited"] = $author["created"] = XML::getFirstNodeValue($xpath, '/rss/channel/pubDate/text()');
$author["app"] = XML::getFirstNodeValue($xpath, '/rss/channel/generator/text()'); $author["app"] = XML::getFirstNodeValue($xpath, '/rss/channel/generator/text()');
@ -179,12 +186,13 @@ class Feed {
$entries = $xpath->query('/rss/channel/item'); $entries = $xpath->query('/rss/channel/item');
} }
if (!$simulate) { if (!$dryRun) {
$author["author-link"] = $contact["url"]; $author["author-link"] = $contact["url"];
if (empty($author["author-name"])) { if (empty($author["author-name"])) {
$author["author-name"] = $contact["name"]; $author["author-name"] = $contact["name"];
} }
$author["author-avatar"] = $contact["thumb"]; $author["author-avatar"] = $contact["thumb"];
$author["owner-link"] = $contact["url"]; $author["owner-link"] = $contact["url"];
@ -193,7 +201,7 @@ class Feed {
} }
$header = []; $header = [];
$header["uid"] = $importer["uid"]; $header["uid"] = $importer["uid"] ?? 0;
$header["network"] = Protocol::FEED; $header["network"] = Protocol::FEED;
$header["wall"] = 0; $header["wall"] = 0;
$header["origin"] = 0; $header["origin"] = 0;
@ -202,16 +210,16 @@ class Feed {
$header["verb"] = Activity::POST; $header["verb"] = Activity::POST;
$header["object-type"] = Activity\ObjectType::NOTE; $header["object-type"] = Activity\ObjectType::NOTE;
$header["contact-id"] = $contact["id"]; $header["contact-id"] = $contact["id"] ?? 0;
if (!is_object($entries)) { if (!is_object($entries)) {
Logger::log("There are no entries in this feed.", Logger::DEBUG); Logger::info("There are no entries in this feed.");
return; return [];
} }
$items = []; $items = [];
// Importing older entries first // Importing older entries first
for($i = $entries->length - 1; $i >= 0;--$i) { for ($i = $entries->length - 1; $i >= 0; --$i) {
$entry = $entries->item($i); $entry = $entries->item($i);
$item = array_merge($header, $author); $item = array_merge($header, $author);
@ -227,9 +235,11 @@ class Feed {
} }
} }
} }
if (empty($item["plink"])) { if (empty($item["plink"])) {
$item["plink"] = XML::getFirstNodeValue($xpath, 'link/text()', $entry); $item["plink"] = XML::getFirstNodeValue($xpath, 'link/text()', $entry);
} }
if (empty($item["plink"])) { if (empty($item["plink"])) {
$item["plink"] = XML::getFirstNodeValue($xpath, 'rss:link/text()', $entry); $item["plink"] = XML::getFirstNodeValue($xpath, 'rss:link/text()', $entry);
} }
@ -239,6 +249,7 @@ class Feed {
if (empty($item["uri"])) { if (empty($item["uri"])) {
$item["uri"] = XML::getFirstNodeValue($xpath, 'guid/text()', $entry); $item["uri"] = XML::getFirstNodeValue($xpath, 'guid/text()', $entry);
} }
if (empty($item["uri"])) { if (empty($item["uri"])) {
$item["uri"] = $item["plink"]; $item["uri"] = $item["plink"];
} }
@ -249,12 +260,12 @@ class Feed {
$item["parent-uri"] = $item["uri"]; $item["parent-uri"] = $item["uri"];
if (!$simulate) { if (!$dryRun) {
$condition = ["`uid` = ? AND `uri` = ? AND `network` IN (?, ?)", $condition = ["`uid` = ? AND `uri` = ? AND `network` IN (?, ?)",
$importer["uid"], $item["uri"], Protocol::FEED, Protocol::DFRN]; $importer["uid"], $item["uri"], Protocol::FEED, Protocol::DFRN];
$previous = Item::selectFirst(['id'], $condition); $previous = Item::selectFirst(['id'], $condition);
if (DBA::isResult($previous)) { if (DBA::isResult($previous)) {
Logger::log("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$previous["id"], Logger::DEBUG); Logger::info("Item with uri " . $item["uri"] . " for user " . $importer["uid"] . " already existed under id " . $previous["id"]);
continue; continue;
} }
} }
@ -275,9 +286,11 @@ class Feed {
if (empty($published)) { if (empty($published)) {
$published = XML::getFirstNodeValue($xpath, 'pubDate/text()', $entry); $published = XML::getFirstNodeValue($xpath, 'pubDate/text()', $entry);
} }
if (empty($published)) { if (empty($published)) {
$published = XML::getFirstNodeValue($xpath, 'dc:date/text()', $entry); $published = XML::getFirstNodeValue($xpath, 'dc:date/text()', $entry);
} }
$updated = XML::getFirstNodeValue($xpath, 'atom:updated/text()', $entry); $updated = XML::getFirstNodeValue($xpath, 'atom:updated/text()', $entry);
if (empty($updated) && !empty($published)) { if (empty($updated) && !empty($published)) {
@ -291,20 +304,25 @@ class Feed {
if ($published != "") { if ($published != "") {
$item["created"] = $published; $item["created"] = $published;
} }
if ($updated != "") { if ($updated != "") {
$item["edited"] = $updated; $item["edited"] = $updated;
} }
$creator = XML::getFirstNodeValue($xpath, 'author/text()', $entry); $creator = XML::getFirstNodeValue($xpath, 'author/text()', $entry);
if (empty($creator)) { if (empty($creator)) {
$creator = XML::getFirstNodeValue($xpath, 'atom:author/atom:name/text()', $entry); $creator = XML::getFirstNodeValue($xpath, 'atom:author/atom:name/text()', $entry);
} }
if (empty($creator)) { if (empty($creator)) {
$creator = XML::getFirstNodeValue($xpath, 'dc:creator/text()', $entry); $creator = XML::getFirstNodeValue($xpath, 'dc:creator/text()', $entry);
} }
if ($creator != "") { if ($creator != "") {
$item["author-name"] = $creator; $item["author-name"] = $creator;
} }
$creator = XML::getFirstNodeValue($xpath, 'dc:creator/text()', $entry); $creator = XML::getFirstNodeValue($xpath, 'dc:creator/text()', $entry);
if ($creator != "") { if ($creator != "") {
@ -332,6 +350,7 @@ class Feed {
$type = $attribute->textContent; $type = $attribute->textContent;
} }
} }
if (!empty($item["attach"])) { if (!empty($item["attach"])) {
$item["attach"] .= ','; $item["attach"] .= ',';
} else { } else {
@ -340,7 +359,7 @@ class Feed {
$attachments[] = ["link" => $href, "type" => $type, "length" => $length]; $attachments[] = ["link" => $href, "type" => $type, "length" => $length];
$item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'"[/attach]'; $item["attach"] .= '[attach]href="' . $href . '" length="' . $length . '" type="' . $type . '"[/attach]';
} }
$tags = ''; $tags = '';
@ -432,7 +451,7 @@ class Feed {
// We always strip the title since it will be added in the page information // We always strip the title since it will be added in the page information
$item["title"] = ""; $item["title"] = "";
$item["body"] = $item["body"].add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]); $item["body"] = $item["body"] . add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
$item["tag"] = add_page_keywords($item["plink"], $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]); $item["tag"] = add_page_keywords($item["plink"], $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
$item["object-type"] = Activity\ObjectType::BOOKMARK; $item["object-type"] = Activity\ObjectType::BOOKMARK;
unset($item["attach"]); unset($item["attach"]);
@ -448,16 +467,20 @@ class Feed {
// @todo $preview is never set in this case, is it intended? - @MrPetovan 2018-02-13 // @todo $preview is never set in this case, is it intended? - @MrPetovan 2018-02-13
$item["tag"] = add_page_keywords($item["plink"], $preview, true, $contact["ffi_keyword_blacklist"]); $item["tag"] = add_page_keywords($item["plink"], $preview, true, $contact["ffi_keyword_blacklist"]);
} }
$item["body"] .= "\n".$item['tag']; $item["body"] .= "\n" . $item['tag'];
} }
// Add the link to the original feed entry if not present in feed // Add the link to the original feed entry if not present in feed
if (($item['plink'] != '') && !strstr($item["body"], $item['plink'])) { if (($item['plink'] != '') && !strstr($item["body"], $item['plink'])) {
$item["body"] .= "[hr][url]".$item['plink']."[/url]"; $item["body"] .= "[hr][url]" . $item['plink'] . "[/url]";
} }
} }
if (!$simulate) { if ($dryRun) {
Logger::log("Stored feed: ".print_r($item, true), Logger::DEBUG); $items[] = $item;
break;
} else {
Logger::info("Stored feed: " . print_r($item, true));
$notify = Item::isRemoteSelf($contact, $item); $notify = Item::isRemoteSelf($contact, $item);
@ -474,19 +497,12 @@ class Feed {
$id = Item::insert($item, false, $notify); $id = Item::insert($item, false, $notify);
Logger::log("Feed for contact ".$contact["url"]." stored under id ".$id); Logger::info("Feed for contact " . $contact["url"] . " stored under id " . $id);
} else {
$items[] = $item;
}
if ($simulate) {
break;
} }
} }
if ($simulate) {
return ["header" => $author, "items" => $items]; return ["header" => $author, "items" => $items];
} }
}
private static function titleIsBody($title, $body) private static function titleIsBody($title, $body)
{ {

View file

@ -4,6 +4,7 @@
*/ */
namespace Friendica\Render; namespace Friendica\Render;
use Friendica\DI;
use Smarty; use Smarty;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
@ -22,7 +23,7 @@ class FriendicaSmarty extends Smarty
{ {
parent::__construct(); parent::__construct();
$a = \get_app(); $a = DI::app();
$theme = $a->getCurrentTheme(); $theme = $a->getCurrentTheme();
// setTemplateDir can be set to an array, which Smarty will parse in order. // setTemplateDir can be set to an array, which Smarty will parse in order.

View file

@ -5,6 +5,7 @@
namespace Friendica\Render; namespace Friendica\Render;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\DI;
/** /**
* Smarty implementation of the Friendica template engine interface * Smarty implementation of the Friendica template engine interface
@ -32,7 +33,7 @@ class FriendicaSmartyEngine implements ITemplateEngine
$s = new FriendicaSmarty(); $s = new FriendicaSmarty();
} }
$r['$APP'] = \get_app(); $r['$APP'] = DI::app();
// "middleware": inject variables into templates // "middleware": inject variables into templates
$arr = [ $arr = [
@ -54,7 +55,7 @@ class FriendicaSmartyEngine implements ITemplateEngine
public function getTemplateFile($file, $root = '') public function getTemplateFile($file, $root = '')
{ {
$a = \get_app(); $a = DI::app();
$template = new FriendicaSmarty(); $template = new FriendicaSmarty();
// Make sure $root ends with a slash / // Make sure $root ends with a slash /

View file

@ -96,7 +96,7 @@ class Network
{ {
$stamp1 = microtime(true); $stamp1 = microtime(true);
$a = \get_app(); $a = DI::app();
if (strlen($url) > 1000) { if (strlen($url) > 1000) {
Logger::log('URL is longer than 1000 characters. Callstack: ' . System::callstack(20), Logger::DEBUG); Logger::log('URL is longer than 1000 characters. Callstack: ' . System::callstack(20), Logger::DEBUG);
@ -260,7 +260,7 @@ class Network
return CurlResult::createErrorCurl($url); return CurlResult::createErrorCurl($url);
} }
$a = \get_app(); $a = DI::app();
$ch = curl_init($url); $ch = curl_init($url);
if (($redirects > 8) || (!$ch)) { if (($redirects > 8) || (!$ch)) {
@ -630,7 +630,7 @@ class Network
*/ */
public static function finalUrl(string $url, int $depth = 1, bool $fetchbody = false) public static function finalUrl(string $url, int $depth = 1, bool $fetchbody = false)
{ {
$a = \get_app(); $a = DI::app();
$url = self::stripTrackingQueryParams($url); $url = self::stripTrackingQueryParams($url);

View file

@ -297,10 +297,6 @@ return [
// Don't show smilies. // Don't show smilies.
'no_smilies' => false, 'no_smilies' => false,
// no_view_full_size (Boolean)
// Don't add the link "View full size" under a resized image.
'no_view_full_size' => false,
// optimize_items (Boolean) // optimize_items (Boolean)
// Triggers an SQL command to optimize the item table before expiring items. // Triggers an SQL command to optimize the item table before expiring items.
'optimize_items' => false, 'optimize_items' => false,

View file

@ -1383,7 +1383,7 @@ class ApiTest extends DatabaseTest
'type' => 'image/png' 'type' => 'image/png'
] ]
]; ];
$app = \get_app(); $app = DI::app();
$app->argc = 2; $app->argc = 2;
$result = api_media_upload(); $result = api_media_upload();
@ -3305,7 +3305,7 @@ class ApiTest extends DatabaseTest
*/ */
public function testApiOauthRequestToken() public function testApiOauthRequestToken()
{ {
$this->markTestIncomplete('killme() kills phpunit as well'); $this->markTestIncomplete('exit() kills phpunit as well');
} }
/** /**
@ -3315,7 +3315,7 @@ class ApiTest extends DatabaseTest
*/ */
public function testApiOauthAccessToken() public function testApiOauthAccessToken()
{ {
$this->markTestIncomplete('killme() kills phpunit as well'); $this->markTestIncomplete('exit() kills phpunit as well');
} }
/** /**

View file

@ -19,11 +19,12 @@
*/ */
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\DI;
use Friendica\Util\Strings; use Friendica\Util\Strings;
function get_scheme_info($scheme) function get_scheme_info($scheme)
{ {
$theme = \get_app()->getCurrentTheme(); $theme = DI::app()->getCurrentTheme();
$themepath = 'view/theme/' . $theme . '/'; $themepath = 'view/theme/' . $theme . '/';
if (empty($scheme)) { if (empty($scheme)) {
$scheme = PConfig::get(local_user(), 'frio', 'scheme', PConfig::get(local_user(), 'frio', 'schema')); $scheme = PConfig::get(local_user(), 'frio', 'scheme', PConfig::get(local_user(), 'frio', 'schema'));

View file

@ -106,7 +106,7 @@ function get_vier_config($key, $default = false, $admin = false)
function vier_community_info() function vier_community_info()
{ {
$a = \get_app(); $a = DI::app();
$show_pages = get_vier_config("show_pages", 1); $show_pages = get_vier_config("show_pages", 1);
$show_profiles = get_vier_config("show_profiles", 1); $show_profiles = get_vier_config("show_profiles", 1);