X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fapi.php;h=4a55c2b919ffd89e5517a4e0fd0a385581cc7f8e;hb=74f3a2f90c6b92aafdaa7be6dcfb672fa7757586;hp=ab12d42bf3c75ee7c0b8617afa50174ee701997d;hpb=5dfee31108fc92a7abca5f99b8fdf1b34aec5dd5;p=friendica.git diff --git a/include/api.php b/include/api.php index ab12d42bf3..4a55c2b919 100644 --- a/include/api.php +++ b/include/api.php @@ -11,9 +11,7 @@ use Friendica\Content\ContactSelector; use Friendica\Content\Feature; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; -use Friendica\Core\Config; use Friendica\Core\Hook; -use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Session; @@ -1097,7 +1095,7 @@ function api_statuses_update($type) if (!$parent) { // Check for throttling (maximum posts per day, week and month) - $throttle_day = Config::get('system', 'throttle_limit_day'); + $throttle_day = DI::config()->get('system', 'throttle_limit_day'); if ($throttle_day > 0) { $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60); @@ -1107,11 +1105,11 @@ function api_statuses_update($type) if ($posts_day > $throttle_day) { Logger::log('Daily posting limit reached for user '.api_user(), Logger::DEBUG); // die(api_error($type, DI::l10n()->t("Daily posting limit of %d posts reached. The post was rejected.", $throttle_day)); - throw new TooManyRequestsException(L10n::tt("Daily posting limit of %d post reached. The post was rejected.", "Daily posting limit of %d posts reached. The post was rejected.", $throttle_day)); + throw new TooManyRequestsException(DI::l10n()->tt("Daily posting limit of %d post reached. The post was rejected.", "Daily posting limit of %d posts reached. The post was rejected.", $throttle_day)); } } - $throttle_week = Config::get('system', 'throttle_limit_week'); + $throttle_week = DI::config()->get('system', 'throttle_limit_week'); if ($throttle_week > 0) { $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7); @@ -1121,11 +1119,11 @@ function api_statuses_update($type) if ($posts_week > $throttle_week) { Logger::log('Weekly posting limit reached for user '.api_user(), Logger::DEBUG); // die(api_error($type, DI::l10n()->t("Weekly posting limit of %d posts reached. The post was rejected.", $throttle_week))); - throw new TooManyRequestsException(L10n::tt("Weekly posting limit of %d post reached. The post was rejected.", "Weekly posting limit of %d posts reached. The post was rejected.", $throttle_week)); + throw new TooManyRequestsException(DI::l10n()->tt("Weekly posting limit of %d post reached. The post was rejected.", "Weekly posting limit of %d posts reached. The post was rejected.", $throttle_week)); } } - $throttle_month = Config::get('system', 'throttle_limit_month'); + $throttle_month = DI::config()->get('system', 'throttle_limit_month'); if ($throttle_month > 0) { $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30); @@ -2740,7 +2738,7 @@ function api_get_entitities(&$text, $bbcode) if ($image) { // If image cache is activated, then use the following sizes: // thumb (150), small (340), medium (600) and large (1024) - if (!Config::get("system", "proxy_disabled")) { + if (!DI::config()->get("system", "proxy_disabled")) { $media_url = ProxyUtils::proxifyUrl($url); $sizes = []; @@ -3573,15 +3571,15 @@ api_register_func('api/friendships/incoming', 'api_friendships_incoming', true); */ function api_statusnet_config($type) { - $name = Config::get('config', 'sitename'); + $name = DI::config()->get('config', 'sitename'); $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:', DI::baseUrl()) : ''; + $email = DI::config()->get('config', 'admin_email'); + $closed = intval(DI::config()->get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 'true' : 'false'; + $private = DI::config()->get('system', 'block_public') ? 'true' : 'false'; + $textlimit = (string) DI::config()->get('config', 'api_import_size', DI::config()->get('config', 'max_import_size', 200000)); + $ssl = DI::config()->get('system', 'have_ssl') ? 'true' : 'false'; + $sslserver = DI::config()->get('system', 'have_ssl') ? str_replace('http:', 'https:', DI::baseUrl()) : ''; $config = [ 'site' => ['name' => $name,'server' => $server, 'theme' => 'default', 'path' => '', @@ -4628,7 +4626,7 @@ function api_account_update_profile_image($type) // Update global directory in background $url = DI::baseUrl() . '/profile/' . DI::app()->user['nickname']; - if ($url && strlen(Config::get('system', 'directory'))) { + if ($url && strlen(DI::config()->get('system', 'directory'))) { Worker::add(PRIORITY_LOW, "Directory", $url); } @@ -4685,7 +4683,7 @@ function api_account_update_profile($type) Worker::add(PRIORITY_LOW, 'ProfileUpdate', $local_user); // Update global directory in background - if ($api_user['url'] && strlen(Config::get('system', 'directory'))) { + if ($api_user['url'] && strlen(DI::config()->get('system', 'directory'))) { Worker::add(PRIORITY_LOW, "Directory", $api_user['url']); } @@ -4793,7 +4791,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ throw new InternalServerErrorException("image size exceeds PHP config settings, file was rejected by server"); } // check against max upload size within Friendica instance - $maximagesize = Config::get('system', 'maximagesize'); + $maximagesize = DI::config()->get('system', 'maximagesize'); if ($maximagesize && ($filesize > $maximagesize)) { $formattedBytes = Strings::formatBytes($maximagesize); throw new InternalServerErrorException("image size exceeds Friendica config setting (uploaded size: $formattedBytes)"); @@ -4811,7 +4809,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ @unlink($src); // check max length of images on server - $max_length = Config::get('system', 'max_image_length'); + $max_length = DI::config()->get('system', 'max_image_length'); if (!$max_length) { $max_length = MAX_IMAGE_LENGTH; } @@ -5907,19 +5905,25 @@ function api_friendica_notification($type) if ($a->argc!==3) { throw new BadRequestException("Invalid argument count"); } - $notes = DI::notify()->getAll([], ['seen' => 'ASC', 'date' => 'DESC'], 50); + + $notifications = DI::notification()->select([], ['order' => ['seen' => 'ASC', 'date' => 'DESC'], 'limit' => 50]); if ($type == "xml") { - $xmlnotes = []; - if (!empty($notes)) { - foreach ($notes as $note) { - $xmlnotes[] = ["@attributes" => $note]; + $xmlnotes = false; + if (!empty($notifications)) { + foreach ($notifications as $notification) { + $xmlnotes[] = ["@attributes" => $notification->toArray()]; } } - $notes = $xmlnotes; + $result = $xmlnotes; + } elseif (count($notifications) > 0) { + $result = $notifications->getArrayCopy(); + } else { + $result = false; } - return api_format_data("notes", $type, ['note' => $notes]); + + return api_format_data("notes", $type, ['note' => $result]); } /** @@ -5937,37 +5941,37 @@ function api_friendica_notification($type) */ function api_friendica_notification_seen($type) { - $a = DI::app(); + $a = DI::app(); $user_info = api_get_user($a); if (api_user() === false || $user_info === false) { throw new ForbiddenException(); } - if ($a->argc!==4) { + if ($a->argc !== 4) { throw new BadRequestException("Invalid argument count"); } $id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0); - $nm = DI::notify(); - $note = $nm->getByID($id); - if (is_null($note)) { - throw new BadRequestException("Invalid argument"); - } - - $nm->setSeen($note); - if ($note['otype']=='item') { - // would be really better with an ItemsManager and $im->getByID() :-P - $item = Item::selectFirstForUser(api_user(), [], ['id' => $note['iid'], 'uid' => api_user()]); - if (DBA::isResult($item)) { - // we found the item, return it to the user - $ret = api_format_items([$item], $user_info, false, $type); - $data = ['status' => $ret]; - return api_format_data("status", $type, $data); + try { + $notification = DI::notification()->getByID($id); + $notification->setSeen(); + + if ($notification->otype == 'item') { + // would be really better with an ItemsManager and $im->getByID() :-P + $item = Item::selectFirstForUser(api_user(), [], ['id' => $notification->iid, 'uid' => api_user()]); + if (DBA::isResult($item)) { + // we found the item, return it to the user + $ret = api_format_items([$item], $user_info, false, $type); + $data = ['status' => $ret]; + return api_format_data("status", $type, $data); + } + // the item can't be found, but we set the notification as seen, so we count this as a success } - // the item can't be found, but we set the note as seen, so we count this as a success + return api_format_data('result', $type, ['result' => "success"]); + } catch (NotFoundException $e) { + throw new BadRequestException('Invalid argument'); } - return api_format_data('result', $type, ['result' => "success"]); } /// @TODO move to top of file or somewhere better @@ -6120,7 +6124,7 @@ function api_friendica_profile_show($type) // retrieve general information about profiles for user $multi_profiles = Feature::isEnabled(api_user(), 'multi_profiles'); - $directory = Config::get('system', 'directory'); + $directory = DI::config()->get('system', 'directory'); // get data of the specified profile id or all profiles of the user if not specified if ($profile_id != 0) {