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;
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;
}
$called_api = explode("/", $p);
- //unset($_SERVER['PHP_AUTH_USER']);
- /// @TODO should be "true ==[=] $info['auth']", if you miss only one = character, you assign a variable (only with ==). Let's make all this even.
if (!empty($info['auth']) && api_user() === false) {
api_login($a);
}
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);
}
}
- $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);
}
}
- $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);
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 = [];
*/
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' => '',
// 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);
}
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']);
}
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)");
@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;
}
// retrieve item element for getting activities (like, dislike etc.) related to photo
$condition = ['uid' => local_user(), 'resource-id' => $photo_id, 'type' => 'photo'];
$item = Item::selectFirstForUser(local_user(), ['id'], $condition);
+ if (!DBA::isResult($item)) {
+ throw new NotFoundException('Photo-related item not found.');
+ }
$data['photo']['friendica_activities'] = api_format_items_activities($item, $type);
if ($a->argc!==3) {
throw new BadRequestException("Invalid argument count");
}
- $notes = DI::notify()->getAll([], ['seen' => 'ASC', 'date' => 'DESC'], 50);
+
+ $notifications = DI::notify()->select(['uid' => api_user()], ['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]);
}
/**
*/
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::notify()->getByID($id);
+ $notification->setSeen();
+
+ if ($notification->otype === Notify::OTYPE_ITEM) {
+ $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
// 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) {