X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fapi.php;h=8325e39b71442f6518054ac1293ea3657ae666ab;hb=1b5fa55bdcc6d0d62bc5ee2a6182027b9d552318;hp=e986a5173490791e432b28ada142971c5fa4e4d1;hpb=fed486bfc50f9c78bf84cd57108b558c82b38af7;p=friendica.git diff --git a/include/api.php b/include/api.php index e986a51734..8325e39b71 100644 --- a/include/api.php +++ b/include/api.php @@ -7,6 +7,7 @@ */ use Friendica\App; +use Friendica\BaseObject; use Friendica\Content\ContactSelector; use Friendica\Content\Feature; use Friendica\Content\Text\BBCode; @@ -15,7 +16,6 @@ use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Logger; -use Friendica\Core\NotificationsManager; use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Core\Session; @@ -26,6 +26,7 @@ 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; @@ -41,8 +42,10 @@ use Friendica\Network\HTTPException\NotImplementedException; use Friendica\Network\HTTPException\TooManyRequestsException; use Friendica\Network\HTTPException\UnauthorizedException; use Friendica\Object\Image; +use Friendica\Protocol\Activity; use Friendica\Protocol\Diaspora; use Friendica\Util\DateTimeFormat; +use Friendica\Util\Images; use Friendica\Util\Network; use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Strings; @@ -322,7 +325,7 @@ function api_call(App $a) $stamp = microtime(true); $return = call_user_func($info['func'], $type); - $duration = (float) (microtime(true) - $stamp); + $duration = floatval(microtime(true) - $stamp); Logger::info(API_LOG_PREFIX . 'username {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username'], 'duration' => round($duration, 2)]); @@ -1165,7 +1168,7 @@ function api_statuses_update($type) api_user() ); if (DBA::isResult($r)) { - $phototypes = Image::supportedTypes(); + $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'] . ']'; @@ -1374,7 +1377,7 @@ function api_get_item(array $condition) */ function api_users_show($type) { - $a = \Friendica\BaseObject::getApp(); + $a = BaseObject::getApp(); $user_info = api_get_user($a); @@ -2551,6 +2554,7 @@ function api_get_attachments(&$body) { $text = $body; $text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $text); + $text = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $text); $URLSearchString = "^\[\]"; $ret = preg_match_all("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $text, $images); @@ -2562,7 +2566,7 @@ function api_get_attachments(&$body) $attachments = []; foreach ($images[1] as $image) { - $imagedata = Image::getInfoFromURL($image); + $imagedata = Images::getInfoFromURLCached($image); if ($imagedata) { $attachments[] = ["url" => $image, "mimetype" => $imagedata["mime"], "size" => $imagedata["size"]]; @@ -2709,7 +2713,7 @@ function api_get_entitities(&$text, $bbcode) $start = iconv_strpos($text, $url, $offset, "UTF-8"); if (!($start === false)) { - $image = Image::getInfoFromURL($url); + $image = Images::getInfoFromURLCached($url); if ($image) { // If image cache is activated, then use the following sizes: // thumb (150), small (340), medium (600) and large (1024) @@ -2717,19 +2721,19 @@ function api_get_entitities(&$text, $bbcode) $media_url = ProxyUtils::proxifyUrl($url); $sizes = []; - $scale = Image::getScalingDimensions($image[0], $image[1], 150); + $scale = Images::getScalingDimensions($image[0], $image[1], 150); $sizes["thumb"] = ["w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"]; if (($image[0] > 150) || ($image[1] > 150)) { - $scale = Image::getScalingDimensions($image[0], $image[1], 340); + $scale = Images::getScalingDimensions($image[0], $image[1], 340); $sizes["small"] = ["w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"]; } - $scale = Image::getScalingDimensions($image[0], $image[1], 600); + $scale = Images::getScalingDimensions($image[0], $image[1], 600); $sizes["medium"] = ["w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"]; if (($image[0] > 600) || ($image[1] > 600)) { - $scale = Image::getScalingDimensions($image[0], $image[1], 1024); + $scale = Images::getScalingDimensions($image[0], $image[1], 1024); $sizes["large"] = ["w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"]; } } else { @@ -2839,19 +2843,19 @@ function api_format_items_activities($item, $type = "json") // get user data and add it to the array of the activity $user = api_get_user($a, $parent_item['author-id']); switch ($parent_item['verb']) { - case ACTIVITY_LIKE: + case Activity::LIKE: $activities['like'][] = $user; break; - case ACTIVITY_DISLIKE: + case Activity::DISLIKE: $activities['dislike'][] = $user; break; - case ACTIVITY_ATTEND: + case Activity::ATTEND: $activities['attendyes'][] = $user; break; - case ACTIVITY_ATTENDNO: + case Activity::ATTENDNO: $activities['attendno'][] = $user; break; - case ACTIVITY_ATTENDMAYBE: + case Activity::ATTENDMAYBE: $activities['attendmaybe'][] = $user; break; default: @@ -2947,7 +2951,7 @@ function api_format_items_profiles($profile_row) */ function api_format_items($items, $user_info, $filter_user = false, $type = "json") { - $a = \Friendica\BaseObject::getApp(); + $a = BaseObject::getApp(); $ret = []; @@ -2981,7 +2985,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 = \Friendica\BaseObject::getApp(); + $a = BaseObject::getApp(); if (empty($status_user) || empty($author_user) || empty($owner_user)) { list($status_user, $author_user, $owner_user) = api_item_get_user($a, $item); @@ -4738,7 +4742,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ } if ($filetype == "") { - $filetype=Image::guessType($filename); + $filetype = Images::guessType($filename); } $imagedata = @getimagesize($src); if ($imagedata) { @@ -4785,19 +4789,19 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ $height = $Image->getHeight(); // create a new resource-id if not already provided - $hash = ($photo_id == null) ? Photo::newResource() : $photo_id; + $resource_id = ($photo_id == null) ? Photo::newResource() : $photo_id; if ($mediatype == "photo") { // upload normal image (scales 0, 1, 2) Logger::log("photo upload: starting new photo upload", Logger::DEBUG); - $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 0, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); + $r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 0, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); if (!$r) { Logger::log("photo upload: image upload with scale 0 (original size) failed"); } if ($width > 640 || $height > 640) { $Image->scaleDown(640); - $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 1, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); + $r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 1, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); if (!$r) { Logger::log("photo upload: image upload with scale 1 (640x640) failed"); } @@ -4805,7 +4809,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ if ($width > 320 || $height > 320) { $Image->scaleDown(320); - $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 2, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); + $r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 2, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); if (!$r) { Logger::log("photo upload: image upload with scale 2 (320x320) failed"); } @@ -4817,7 +4821,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ if ($width > 300 || $height > 300) { $Image->scaleDown(300); - $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 4, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); + $r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 4, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); if (!$r) { Logger::log("photo upload: profile image upload with scale 4 (300x300) failed"); } @@ -4825,7 +4829,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ if ($width > 80 || $height > 80) { $Image->scaleDown(80); - $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 5, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); + $r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 5, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); if (!$r) { Logger::log("photo upload: profile image upload with scale 5 (80x80) failed"); } @@ -4833,7 +4837,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ if ($width > 48 || $height > 48) { $Image->scaleDown(48); - $r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 6, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); + $r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 6, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); if (!$r) { Logger::log("photo upload: profile image upload with scale 6 (48x48) failed"); } @@ -4845,10 +4849,10 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ if (isset($r) && $r) { // create entry in 'item'-table on new uploads to enable users to comment/like/dislike the photo if ($photo_id == null && $mediatype == "photo") { - post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility); + post_photo_item($resource_id, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility); } // on success return image data in json/xml format (like /api/friendica/photo does when no scale is given) - return prepare_photo_data($type, false, $hash); + return prepare_photo_data($type, false, $resource_id); } else { throw new InternalServerErrorException("image upload failed"); } @@ -5110,7 +5114,7 @@ function api_get_announce($item) } $fields = ['author-id', 'author-name', 'author-link', 'author-avatar']; - $activity = Item::activityToIndex(ACTIVITY2_ANNOUNCE); + $activity = Item::activityToIndex(Activity::ANNOUNCE); $condition = ['parent-uri' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY, 'uid' => [0, $item['uid']], 'activity' => $activity]; $announce = Item::selectFirstForUser($item['uid'], $fields, $condition, ['order' => ['received' => true]]); if (!DBA::isResult($announce)) { @@ -6039,7 +6043,8 @@ function api_friendica_notification($type) if ($a->argc!==3) { throw new BadRequestException("Invalid argument count"); } - $nm = new NotificationsManager(); + /** @var Notify $nm */ + $nm = BaseObject::getClass(Notify::class); $notes = $nm->getAll([], ['seen' => 'ASC', 'date' => 'DESC'], 50); @@ -6083,7 +6088,8 @@ function api_friendica_notification_seen($type) $id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0); - $nm = new NotificationsManager(); + /** @var Notify $nm */ + $nm = BaseObject::getClass(Notify::class); $note = $nm->getByID($id); if (is_null($note)) { throw new BadRequestException("Invalid argument");