X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fapi.php;h=e19c89524140d17cd3b0681f50720bc344f9a312;hb=b8f85f0484fbb1f37e9cae2f4cf98f9349fda099;hp=80abb750f7d666b7f9c256d1b7da005d9b2c91f4;hpb=30dfbb95d9f764738fcaa9cf69e9c4059c38678c;p=friendica.git diff --git a/include/api.php b/include/api.php index 80abb750f7..e19c895241 100644 --- a/include/api.php +++ b/include/api.php @@ -7,7 +7,6 @@ */ use Friendica\App; -use Friendica\BaseObject; use Friendica\Content\ContactSelector; use Friendica\Content\Feature; use Friendica\Content\Text\BBCode; @@ -22,14 +21,15 @@ use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\Mail; -use Friendica\Model\Notify; use Friendica\Model\Photo; use Friendica\Model\Profile; use Friendica\Model\User; +use Friendica\Model\UserItem; use Friendica\Network\FKOAuth1; use Friendica\Network\HTTPException; use Friendica\Network\HTTPException\BadRequestException; @@ -131,7 +131,7 @@ function api_date($str) * * @brief Register API endpoint * - * @param string $path API URL path, relative to System::baseUrl() + * @param string $path API URL path, relative to DI::baseUrl() * @param string $func Function name to call on path request * @param bool $auth API need logged user * @param string $method HTTP method reqiured to call this endpoint. @@ -253,7 +253,7 @@ function api_login(App $a) throw new UnauthorizedException("This API requires login"); } - Session::setAuthenticatedForUser($a, $record); + DI::auth()->setForUser($a, $record); $_SESSION["allow_api"] = true; @@ -284,30 +284,35 @@ function api_check_method($method) * @brief Main API entry point * * @param App $a App + * @param App\Arguments $args The app arguments (optional, will retrieved by the DI-Container in case of missing) * @return string|array API call result * @throws Exception */ -function api_call(App $a) +function api_call(App $a, App\Arguments $args = null) { global $API, $called_api; + if ($args == null) { + $args = DI::args(); + } + $type = "json"; - if (strpos($a->query_string, ".xml") > 0) { + if (strpos($args->getQueryString(), ".xml") > 0) { $type = "xml"; } - if (strpos($a->query_string, ".json") > 0) { + if (strpos($args->getQueryString(), ".json") > 0) { $type = "json"; } - if (strpos($a->query_string, ".rss") > 0) { + if (strpos($args->getQueryString(), ".rss") > 0) { $type = "rss"; } - if (strpos($a->query_string, ".atom") > 0) { + if (strpos($args->getQueryString(), ".atom") > 0) { $type = "atom"; } try { foreach ($API as $p => $info) { - if (strpos($a->query_string, $p) === 0) { + if (strpos($args->getQueryString(), $p) === 0) { if (!api_check_method($info['method'])) { throw new MethodNotAllowedException(); } @@ -329,7 +334,7 @@ function api_call(App $a) Logger::info(API_LOG_PREFIX . 'username {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username'], 'duration' => round($duration, 2)]); - $a->getProfiler()->saveLog($a->getLogger(), API_LOG_PREFIX . 'performance'); + DI::profiler()->saveLog(DI::logger(), API_LOG_PREFIX . 'performance'); if (false === $return) { /* @@ -366,11 +371,11 @@ function api_call(App $a) } } - Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => $a->query_string]); + Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString()]); throw new NotImplementedException(); } catch (HTTPException $e) { header("HTTP/1.1 {$e->getCode()} {$e->httpdesc}"); - return api_error($type, $e); + return api_error($type, $e, $args); } } @@ -379,18 +384,17 @@ function api_call(App $a) * * @param string $type Return type (xml, json, rss, as) * @param object $e HTTPException Error object + * @param App\Arguments $args The App arguments * @return string|array error message formatted as $type */ -function api_error($type, $e) +function api_error($type, $e, App\Arguments $args) { - $a = \get_app(); - $error = ($e->getMessage() !== "" ? $e->getMessage() : $e->httpdesc); /// @TODO: https://dev.twitter.com/overview/api/response-codes $error = ["error" => $error, "code" => $e->getCode() . " " . $e->httpdesc, - "request" => $a->query_string]; + "request" => $args->getQueryString()]; $return = api_format_data('status', $type, ['status' => $error]); @@ -435,12 +439,12 @@ function api_rss_extra(App $a, $arr, $user_info) $arr['$user'] = $user_info; $arr['$rss'] = [ 'alternate' => $user_info['url'], - 'self' => System::baseUrl() . "/" . $a->query_string, - 'base' => System::baseUrl(), + 'self' => DI::baseUrl() . "/" . DI::args()->getQueryString(), + 'base' => DI::baseUrl(), 'updated' => api_date(null), 'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), 'language' => $user_info['lang'], - 'logo' => System::baseUrl() . "/images/friendica-32.png", + 'logo' => DI::baseUrl() . "/images/friendica-32.png", ]; return $arr; @@ -610,7 +614,7 @@ function api_get_user(App $a, $contact_id = null) 'id_str' => (string) $contact["id"], 'name' => $contact["name"], 'screen_name' => (($contact['nick']) ? $contact['nick'] : $contact['name']), - 'location' => ($contact["location"] != "") ? $contact["location"] : ContactSelector::networkToName($contact['network'], $contact['url']), + 'location' => ($contact["location"] != "") ? $contact["location"] : ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol']), 'description' => BBCode::toPlaintext($contact["about"]), 'profile_image_url' => $contact["micro"], 'profile_image_url_https' => $contact["micro"], @@ -676,7 +680,7 @@ function api_get_user(App $a, $contact_id = null) } elseif (!empty($uinfo[0]["location"])) { $location = $uinfo[0]["location"]; } else { - $location = ContactSelector::networkToName($uinfo[0]['network'], $uinfo[0]['url']); + $location = ContactSelector::networkToName($uinfo[0]['network'], $uinfo[0]['url'], $uinfo[0]['protocol']); } $ret = [ @@ -711,7 +715,7 @@ function api_get_user(App $a, $contact_id = null) 'statusnet_blocking' => false, 'notifications' => false, /// @TODO old way? - //'statusnet_profile_url' => System::baseUrl()."/contact/".$uinfo[0]['cid'], + //'statusnet_profile_url' => DI::baseUrl()."/contact/".$uinfo[0]['cid'], 'statusnet_profile_url' => $uinfo[0]['url'], 'uid' => intval($uinfo[0]['uid']), 'cid' => intval($uinfo[0]['cid']), @@ -927,7 +931,7 @@ function api_format_data($root_element, $type, $data) */ function api_account_verify_credentials($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -995,7 +999,7 @@ function requestdata($k) */ function api_statuses_mediap($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { Logger::log('api_statuses_update: no user'); @@ -1049,7 +1053,7 @@ api_register_func('api/statuses/mediap', 'api_statuses_mediap', true, API_METHOD */ function api_statuses_update($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { Logger::log('api_statuses_update: no user'); @@ -1161,8 +1165,8 @@ function api_statuses_update($type) $phototypes = Images::supportedTypes(); $ext = $phototypes[$r[0]['type']]; $description = $r[0]['desc'] ?? ''; - $_REQUEST['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $r[0]['nickname'] . '/image/' . $r[0]['resource-id'] . ']'; - $_REQUEST['body'] .= '[img=' . System::baseUrl() . '/photo/' . $r[0]['resource-id'] . '-' . $r[0]['scale'] . '.' . $ext . ']' . $description . '[/img][/url]'; + $_REQUEST['body'] .= "\n\n" . '[url=' . DI::baseUrl() . '/photos/' . $r[0]['nickname'] . '/image/' . $r[0]['resource-id'] . ']'; + $_REQUEST['body'] .= '[img=' . DI::baseUrl() . '/photo/' . $r[0]['resource-id'] . '-' . $r[0]['scale'] . '.' . $ext . ']' . $description . '[/img][/url]'; } } } @@ -1199,7 +1203,7 @@ api_register_func('api/statuses/update_with_media', 'api_statuses_update', true, */ function api_media_upload() { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { Logger::log('no user'); @@ -1254,7 +1258,7 @@ api_register_func('api/media/upload', 'api_media_upload', true, API_METHOD_POST) */ function api_media_metadata_create($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { Logger::info('no user'); @@ -1367,7 +1371,7 @@ function api_get_item(array $condition) */ function api_users_show($type) { - $a = BaseObject::getApp(); + $a = Friendica\DI::app(); $user_info = api_get_user($a); @@ -1401,7 +1405,7 @@ api_register_func('api/externalprofile/show', 'api_users_show'); */ function api_users_search($type) { - $a = \get_app(); + $a = DI::app(); $userlist = []; @@ -1463,7 +1467,7 @@ function api_users_lookup($type) if (!empty($_REQUEST['user_id'])) { foreach (explode(',', $_REQUEST['user_id']) as $id) { if (!empty($id)) { - $users[] = api_get_user(get_app(), $id); + $users[] = api_get_user(DI::app(), $id); } } } @@ -1494,7 +1498,7 @@ api_register_func('api/users/lookup', 'api_users_lookup', true); */ function api_search($type) { - $a = \get_app(); + $a = DI::app(); $user_info = api_get_user($a); if (api_user() === false || $user_info === false) { @@ -1516,7 +1520,7 @@ function api_search($type) } elseif (!empty($_REQUEST['count'])) { $count = $_REQUEST['count']; } - + $since_id = $_REQUEST['since_id'] ?? 0; $max_id = $_REQUEST['max_id'] ?? 0; $page = $_REQUEST['page'] ?? 1; @@ -1552,7 +1556,7 @@ function api_search($type) $condition = [implode(' AND ', $preCondition)]; } else { - $condition = ["`id` > ? + $condition = ["`id` > ? " . ($exclude_replies ? " AND `id` = `parent` " : ' ') . " AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `body` LIKE CONCAT('%',?,'%')", @@ -1608,7 +1612,7 @@ api_register_func('api/search', 'api_search', true); */ function api_statuses_home_timeline($type) { - $a = \get_app(); + $a = DI::app(); $user_info = api_get_user($a); if (api_user() === false || $user_info === false) { @@ -1701,7 +1705,7 @@ api_register_func('api/statuses/friends_timeline', 'api_statuses_home_timeline', */ function api_statuses_public_timeline($type) { - $a = \get_app(); + $a = DI::app(); $user_info = api_get_user($a); if (api_user() === false || $user_info === false) { @@ -1786,7 +1790,7 @@ api_register_func('api/statuses/public_timeline', 'api_statuses_public_timeline' */ function api_statuses_networkpublic_timeline($type) { - $a = \get_app(); + $a = DI::app(); $user_info = api_get_user($a); if (api_user() === false || $user_info === false) { @@ -1847,7 +1851,7 @@ api_register_func('api/statuses/networkpublic_timeline', 'api_statuses_networkpu */ function api_statuses_show($type) { - $a = \get_app(); + $a = DI::app(); $user_info = api_get_user($a); if (api_user() === false || $user_info === false) { @@ -1926,7 +1930,7 @@ api_register_func('api/statuses/show', 'api_statuses_show', true); */ function api_conversation_show($type) { - $a = \get_app(); + $a = DI::app(); $user_info = api_get_user($a); if (api_user() === false || $user_info === false) { @@ -2008,7 +2012,7 @@ function api_statuses_repeat($type) { global $called_api; - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -2085,7 +2089,7 @@ api_register_func('api/statuses/retweet', 'api_statuses_repeat', true, API_METHO */ function api_statuses_destroy($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -2132,7 +2136,7 @@ api_register_func('api/statuses/destroy', 'api_statuses_destroy', true, API_METH */ function api_statuses_mentions($type) { - $a = \get_app(); + $a = DI::app(); $user_info = api_get_user($a); if (api_user() === false || $user_info === false) { @@ -2155,17 +2159,34 @@ function api_statuses_mentions($type) $start = max(0, ($page - 1) * $count); - $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ? AND `author-id` != ? AND `mention` - AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `thread`.`uid` = ? AND NOT `thread`.`ignored`)", - api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $user_info['pid'], api_user()]; + $query = "SELECT `item`.`id` FROM `user-item` + INNER JOIN `item` ON `item`.`id` = `user-item`.`iid` AND `item`.`gravity` IN (?, ?) + WHERE (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) AND + `user-item`.`uid` = ? AND `user-item`.`notification-type` & ? != 0 + AND `user-item`.`iid` > ?"; + $condition = [GRAVITY_PARENT, GRAVITY_COMMENT, api_user(), + UserItem::NOTIF_EXPLICIT_TAGGED | UserItem::NOTIF_IMPLICIT_TAGGED | + UserItem::NOTIF_THREAD_COMMENT | UserItem::NOTIF_DIRECT_COMMENT, + $since_id]; if ($max_id > 0) { - $condition[0] .= " AND `item`.`id` <= ?"; + $query .= " AND `item`.`id` <= ?"; $condition[] = $max_id; } + $query .= " ORDER BY `user-item`.`iid` DESC LIMIT ?, ?"; + $condition[] = $start; + $condition[] = $count; + + $useritems = DBA::p($query, $condition); + $itemids = []; + while ($useritem = DBA::fetch($useritems)) { + $itemids[] = $useritem['id']; + } + DBA::close($useritems); + $params = ['order' => ['id' => true], 'limit' => [$start, $count]]; - $statuses = Item::selectForUser(api_user(), [], $condition, $params); + $statuses = Item::selectForUser(api_user(), [], ['id' => $itemids], $params); $ret = api_format_items(Item::inArray($statuses), $user_info, false, $type); @@ -2201,7 +2222,7 @@ api_register_func('api/statuses/replies', 'api_statuses_mentions', true); */ function api_statuses_user_timeline($type) { - $a = \get_app(); + $a = DI::app(); $user_info = api_get_user($a); if (api_user() === false || $user_info === false) { @@ -2285,7 +2306,7 @@ api_register_func('api/statuses/user_timeline', 'api_statuses_user_timeline', tr */ function api_favorites_create_destroy($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -2368,7 +2389,7 @@ function api_favorites($type) { global $called_api; - $a = \get_app(); + $a = DI::app(); $user_info = api_get_user($a); if (api_user() === false || $user_info === false) { @@ -2783,7 +2804,7 @@ function api_format_items_embeded_images($item, $text) $text = preg_replace_callback( '|data:image/([^;]+)[^=]+=*|m', function () use ($item) { - return System::baseUrl() . '/display/' . $item['guid']; + return DI::baseUrl() . '/display/' . $item['guid']; }, $text ); @@ -2833,7 +2854,7 @@ function api_contactlink_to_array($txt) */ function api_format_items_activities($item, $type = "json") { - $a = \get_app(); + $a = DI::app(); $activities = [ 'like' => [], @@ -2965,7 +2986,7 @@ function api_format_items_profiles($profile_row) */ function api_format_items($items, $user_info, $filter_user = false, $type = "json") { - $a = BaseObject::getApp(); + $a = Friendica\DI::app(); $ret = []; @@ -2999,7 +3020,7 @@ function api_format_items($items, $user_info, $filter_user = false, $type = "jso */ function api_format_item($item, $type = "json", $status_user = null, $author_user = null, $owner_user = null) { - $a = BaseObject::getApp(); + $a = Friendica\DI::app(); if (empty($status_user) || empty($author_user) || empty($owner_user)) { list($status_user, $author_user, $owner_user) = api_item_get_user($a, $item); @@ -3038,7 +3059,7 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use //'entities' => NULL, 'statusnet_html' => $converted["html"], 'statusnet_conversation_id' => $item['parent'], - 'external_url' => System::baseUrl() . "/display/" . $item['guid'], + 'external_url' => DI::baseUrl() . "/display/" . $item['guid'], 'friendica_activities' => api_format_items_activities($item, $type), 'friendica_title' => $item['title'], 'friendica_html' => BBCode::convert($item['body'], false) @@ -3053,9 +3074,9 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use } if ($status["source"] == 'web') { - $status["source"] = ContactSelector::networkToName($item['network'], $item['author-link']); - } elseif (ContactSelector::networkToName($item['network'], $item['author-link']) != $status["source"]) { - $status["source"] = trim($status["source"].' ('.ContactSelector::networkToName($item['network'], $item['author-link']).')'); + $status["source"] = ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']); + } elseif (ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']) != $status["source"]) { + $status["source"] = trim($status["source"].' ('.ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']).')'); } $retweeted_item = []; @@ -3254,7 +3275,7 @@ api_register_func('api/lists/subscriptions', 'api_lists_list', true); */ function api_lists_ownerships($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -3303,7 +3324,7 @@ api_register_func('api/lists/ownerships', 'api_lists_ownerships', true); */ function api_lists_statuses($type) { - $a = \get_app(); + $a = DI::app(); $user_info = api_get_user($a); if (api_user() === false || $user_info === false) { @@ -3381,7 +3402,7 @@ api_register_func('api/lists/statuses', 'api_lists_statuses', true); */ function api_statuses_f($qtype) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -3564,17 +3585,15 @@ api_register_func('api/friendships/incoming', 'api_friendships_incoming', true); */ function api_statusnet_config($type) { - $a = \get_app(); - $name = Config::get('config', 'sitename'); - $server = $a->getHostName(); - $logo = System::baseUrl() . '/images/friendica-64.png'; + $server = DI::baseUrl()->getHostname(); + $logo = DI::baseUrl() . '/images/friendica-64.png'; $email = Config::get('config', 'admin_email'); $closed = intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 'true' : 'false'; $private = Config::get('system', 'block_public') ? 'true' : 'false'; $textlimit = (string) Config::get('config', 'api_import_size', Config::get('config', 'max_import_size', 200000)); $ssl = Config::get('system', 'have_ssl') ? 'true' : 'false'; - $sslserver = Config::get('system', 'have_ssl') ? str_replace('http:', 'https:', System::baseUrl()) : ''; + $sslserver = Config::get('system', 'have_ssl') ? str_replace('http:', 'https:', DI::baseUrl()) : ''; $config = [ 'site' => ['name' => $name,'server' => $server, 'theme' => 'default', 'path' => '', @@ -3635,7 +3654,7 @@ function api_ff_ids($type, int $rel) throw new ForbiddenException(); } - $a = \get_app(); + $a = DI::app(); api_get_user($a); @@ -3722,7 +3741,7 @@ api_register_func('api/followers/ids', 'api_followers_ids', true); */ function api_direct_messages_new($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -3814,7 +3833,7 @@ api_register_func('api/direct_messages/new', 'api_direct_messages_new', true, AP */ function api_direct_messages_destroy($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -3982,7 +4001,7 @@ api_register_func('api/friendships/destroy', 'api_friendships_destroy', true, AP */ function api_direct_messages_box($type, $box, $verbose) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); } @@ -4312,7 +4331,7 @@ function api_fr_photos_list($type) $photo['album'] = $rr['album']; $photo['filename'] = $rr['filename']; $photo['type'] = $rr['type']; - $thumb = System::baseUrl() . "/photo/" . $rr['resource-id'] . "-" . $rr['scale'] . "." . $typetoext[$rr['type']]; + $thumb = DI::baseUrl() . "/photo/" . $rr['resource-id'] . "-" . $rr['scale'] . "." . $typetoext[$rr['type']]; $photo['created'] = $rr['created']; $photo['edited'] = $rr['edited']; $photo['desc'] = $rr['desc']; @@ -4618,15 +4637,15 @@ function api_account_update_profile_image($type) $condition = ["`profile` AND `resource-id` != ? AND `uid` = ?", $data['photo']['id'], api_user()]; Photo::update(['profile' => false], $condition); } else { - $fields = ['photo' => System::baseUrl() . '/photo/' . $data['photo']['id'] . '-4.' . $fileext, - 'thumb' => System::baseUrl() . '/photo/' . $data['photo']['id'] . '-5.' . $fileext]; + $fields = ['photo' => DI::baseUrl() . '/photo/' . $data['photo']['id'] . '-4.' . $fileext, + 'thumb' => DI::baseUrl() . '/photo/' . $data['photo']['id'] . '-5.' . $fileext]; DBA::update('profile', $fields, ['id' => $_REQUEST['profile'], 'uid' => api_user()]); } Contact::updateSelfFromUserID(api_user(), true); // Update global directory in background - $url = System::baseUrl() . '/profile/' . \get_app()->user['nickname']; + $url = DI::baseUrl() . '/profile/' . DI::app()->user['nickname']; if ($url && strlen(Config::get('system', 'directory'))) { Worker::add(PRIORITY_LOW, "Directory", $url); } @@ -4667,7 +4686,7 @@ api_register_func('api/account/update_profile_image', 'api_account_update_profil function api_account_update_profile($type) { $local_user = api_user(); - $api_user = api_get_user(get_app()); + $api_user = api_get_user(DI::app()); if (!empty($_POST['name'])) { DBA::update('profile', ['name' => $_POST['name']], ['uid' => $local_user]); @@ -4938,8 +4957,8 @@ function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $f ]; // adds link to the thumbnail scale photo - $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nick'] . '/image/' . $hash . ']' - . '[img]' . System::baseUrl() . '/photo/' . $hash . '-' . "2" . '.'. $typetoext[$filetype] . '[/img]' + $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nick'] . '/image/' . $hash . ']' + . '[img]' . DI::baseUrl() . '/photo/' . $hash . '-' . "2" . '.'. $typetoext[$filetype] . '[/img]' . '[/url]'; // do the magic for storing the item in the database and trigger the federation to other contacts @@ -4962,7 +4981,7 @@ function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $f */ function prepare_photo_data($type, $scale, $photo_id) { - $a = \get_app(); + $a = DI::app(); $user_info = api_get_user($a); if ($user_info === false) { @@ -5007,14 +5026,14 @@ function prepare_photo_data($type, $scale, $photo_id) for ($k = intval($data['photo']['minscale']); $k <= intval($data['photo']['maxscale']); $k++) { $data['photo']['links'][$k . ":link"]["@attributes"] = ["type" => $data['photo']['type'], "scale" => $k, - "href" => System::baseUrl() . "/photo/" . $data['photo']['resource-id'] . "-" . $k . "." . $typetoext[$data['photo']['type']]]; + "href" => DI::baseUrl() . "/photo/" . $data['photo']['resource-id'] . "-" . $k . "." . $typetoext[$data['photo']['type']]]; } } else { $data['photo']['link'] = []; // when we have profile images we could have only scales from 4 to 6, but index of array always needs to start with 0 $i = 0; for ($k = intval($data['photo']['minscale']); $k <= intval($data['photo']['maxscale']); $k++) { - $data['photo']['link'][$i] = System::baseUrl() . "/photo/" . $data['photo']['resource-id'] . "-" . $k . "." . $typetoext[$data['photo']['type']]; + $data['photo']['link'][$i] = DI::baseUrl() . "/photo/" . $data['photo']['resource-id'] . "-" . $k . "." . $typetoext[$data['photo']['type']]; $i++; } } @@ -5390,7 +5409,7 @@ function api_best_nickname(&$contacts) */ function api_friendica_group_show($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -5460,7 +5479,7 @@ api_register_func('api/friendica/group_show', 'api_friendica_group_show', true); */ function api_friendica_group_delete($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -5527,7 +5546,7 @@ api_register_func('api/friendica/group_delete', 'api_friendica_group_delete', tr */ function api_lists_destroy($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -5649,7 +5668,7 @@ function group_create($name, $uid, $users = []) */ function api_friendica_group_create($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -5683,7 +5702,7 @@ api_register_func('api/friendica/group_create', 'api_friendica_group_create', tr */ function api_lists_create($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -5722,7 +5741,7 @@ api_register_func('api/lists/create', 'api_lists_create', true, API_METHOD_POST) */ function api_friendica_group_update($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -5801,7 +5820,7 @@ api_register_func('api/friendica/group_update', 'api_friendica_group_update', tr */ function api_lists_update($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -5851,7 +5870,7 @@ api_register_func('api/lists/update', 'api_lists_update', true, API_METHOD_POST) */ function api_friendica_activity($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -5898,7 +5917,7 @@ api_register_func('api/friendica/activity/unattendmaybe', 'api_friendica_activit */ function api_friendica_notification($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -5906,10 +5925,7 @@ function api_friendica_notification($type) if ($a->argc!==3) { throw new BadRequestException("Invalid argument count"); } - /** @var Notify $nm */ - $nm = BaseObject::getClass(Notify::class); - - $notes = $nm->getAll([], ['seen' => 'ASC', 'date' => 'DESC'], 50); + $notes = DI::notify()->getAll([], ['seen' => 'ASC', 'date' => 'DESC'], 50); if ($type == "xml") { $xmlnotes = []; @@ -5939,7 +5955,7 @@ function api_friendica_notification($type) */ function api_friendica_notification_seen($type) { - $a = \get_app(); + $a = DI::app(); $user_info = api_get_user($a); if (api_user() === false || $user_info === false) { @@ -5951,8 +5967,7 @@ function api_friendica_notification_seen($type) $id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0); - /** @var Notify $nm */ - $nm = BaseObject::getClass(Notify::class); + $nm = DI::notify(); $note = $nm->getByID($id); if (is_null($note)) { throw new BadRequestException("Invalid argument"); @@ -5990,7 +6005,7 @@ api_register_func('api/friendica/notification', 'api_friendica_notification', tr */ function api_friendica_direct_messages_setseen($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); } @@ -6044,7 +6059,7 @@ api_register_func('api/friendica/direct_messages_setseen', 'api_friendica_direct */ function api_friendica_direct_messages_search($type, $box = "") { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException(); @@ -6112,7 +6127,7 @@ api_register_func('api/friendica/direct_messages_search', 'api_friendica_direct_ */ function api_friendica_profile_show($type) { - $a = \get_app(); + $a = DI::app(); if (api_user() === false) { throw new ForbiddenException();