Separate Object\Photo into Model\Photo and Object\Image
- Renamed a bunch of functions to shorter or clearer names
This commit is contained in:
parent
7499824381
commit
3fc3e67b70
22 changed files with 464 additions and 408 deletions
|
@ -12,6 +12,7 @@ use Friendica\Core\Config;
|
|||
use Friendica\Core\NotificationsManager;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\FKOAuth1;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
@ -24,7 +25,7 @@ use Friendica\Network\HTTPException\NotImplementedException;
|
|||
use Friendica\Network\HTTPException\UnauthorizedException;
|
||||
use Friendica\Network\HTTPException\TooManyRequestsException;
|
||||
use Friendica\Object\Contact;
|
||||
use Friendica\Object\Photo;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
|
@ -1192,7 +1193,7 @@ function api_statuses_update($type)
|
|||
api_user()
|
||||
);
|
||||
if (DBM::is_result($r)) {
|
||||
$phototypes = Photo::supportedTypes();
|
||||
$phototypes = Image::supportedTypes();
|
||||
$ext = $phototypes[$r[0]['type']];
|
||||
$_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 . '[/img][/url]';
|
||||
|
@ -2377,7 +2378,7 @@ function api_get_attachments(&$body)
|
|||
$attachments = array();
|
||||
|
||||
foreach ($images[1] as $image) {
|
||||
$imagedata = Photo::getInfoFromURL($image);
|
||||
$imagedata = Image::getInfoFromURL($image);
|
||||
|
||||
if ($imagedata) {
|
||||
$attachments[] = array("url" => $image, "mimetype" => $imagedata["mime"], "size" => $imagedata["size"]);
|
||||
|
@ -2509,7 +2510,7 @@ function api_get_entitities(&$text, $bbcode)
|
|||
|
||||
$start = iconv_strpos($text, $url, $offset, "UTF-8");
|
||||
if (!($start === false)) {
|
||||
$image = Photo::getInfoFromURL($url);
|
||||
$image = Image::getInfoFromURL($url);
|
||||
if ($image) {
|
||||
// If image cache is activated, then use the following sizes:
|
||||
// thumb (150), small (340), medium (600) and large (1024)
|
||||
|
@ -2517,19 +2518,19 @@ function api_get_entitities(&$text, $bbcode)
|
|||
$media_url = proxy_url($url);
|
||||
|
||||
$sizes = array();
|
||||
$scale = Photo::scaleImageTo($image[0], $image[1], 150);
|
||||
$scale = Image::getScalingDimensions($image[0], $image[1], 150);
|
||||
$sizes["thumb"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
|
||||
|
||||
if (($image[0] > 150) || ($image[1] > 150)) {
|
||||
$scale = Photo::scaleImageTo($image[0], $image[1], 340);
|
||||
$scale = Image::getScalingDimensions($image[0], $image[1], 340);
|
||||
$sizes["small"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
|
||||
}
|
||||
|
||||
$scale = Photo::scaleImageTo($image[0], $image[1], 600);
|
||||
$scale = Image::getScalingDimensions($image[0], $image[1], 600);
|
||||
$sizes["medium"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
|
||||
|
||||
if (($image[0] > 600) || ($image[1] > 600)) {
|
||||
$scale = Photo::scaleImageTo($image[0], $image[1], 1024);
|
||||
$scale = Image::getScalingDimensions($image[0], $image[1], 1024);
|
||||
$sizes["large"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
|
||||
}
|
||||
} else {
|
||||
|
@ -3946,7 +3947,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
|
|||
}
|
||||
|
||||
if ($filetype == "") {
|
||||
$filetype=Photo::guessImageType($filename);
|
||||
$filetype=Image::guessType($filename);
|
||||
}
|
||||
$imagedata = getimagesize($src);
|
||||
if ($imagedata) {
|
||||
|
@ -3970,13 +3971,13 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
|
|||
|
||||
// create Photo instance with the data of the image
|
||||
$imagedata = @file_get_contents($src);
|
||||
$ph = new Photo($imagedata, $filetype);
|
||||
if (! $ph->isValid()) {
|
||||
$Image = new Image($imagedata, $filetype);
|
||||
if (! $Image->isValid()) {
|
||||
throw new InternalServerErrorException("unable to process image data");
|
||||
}
|
||||
|
||||
// check orientation of image
|
||||
$ph->orient($src);
|
||||
$Image->orient($src);
|
||||
@unlink($src);
|
||||
|
||||
// check max length of images on server
|
||||
|
@ -3985,11 +3986,11 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
|
|||
$max_length = MAX_IMAGE_LENGTH;
|
||||
}
|
||||
if ($max_length > 0) {
|
||||
$ph->scaleImage($max_length);
|
||||
$Image->scaleDown($max_length);
|
||||
logger("File upload: Scaling picture to new size " . $max_length, LOGGER_DEBUG);
|
||||
}
|
||||
$width = $ph->getWidth();
|
||||
$height = $ph->getHeight();
|
||||
$width = $Image->getWidth();
|
||||
$height = $Image->getHeight();
|
||||
|
||||
// create a new resource-id if not already provided
|
||||
$hash = ($photo_id == null) ? photo_new_resource() : $photo_id;
|
||||
|
@ -3998,21 +3999,21 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
|
|||
// upload normal image (scales 0, 1, 2)
|
||||
logger("photo upload: starting new photo upload", LOGGER_DEBUG);
|
||||
|
||||
$r =$ph->store(local_user(), $visitor, $hash, $filename, $album, 0, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 0, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (! $r) {
|
||||
logger("photo upload: image upload with scale 0 (original size) failed");
|
||||
}
|
||||
if ($width > 640 || $height > 640) {
|
||||
$ph->scaleImage(640);
|
||||
$r = $ph->store(local_user(), $visitor, $hash, $filename, $album, 1, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$Image->scaleDown(640);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 1, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (! $r) {
|
||||
logger("photo upload: image upload with scale 1 (640x640) failed");
|
||||
}
|
||||
}
|
||||
|
||||
if ($width > 320 || $height > 320) {
|
||||
$ph->scaleImage(320);
|
||||
$r = $ph->store(local_user(), $visitor, $hash, $filename, $album, 2, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$Image->scaleDown(320);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 2, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (! $r) {
|
||||
logger("photo upload: image upload with scale 2 (320x320) failed");
|
||||
}
|
||||
|
@ -4023,29 +4024,29 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
|
|||
logger("photo upload: starting new profile image upload", LOGGER_DEBUG);
|
||||
|
||||
if ($width > 175 || $height > 175) {
|
||||
$ph->scaleImage(175);
|
||||
$r = $ph->store(local_user(), $visitor, $hash, $filename, $album, 4, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$Image->scaleDown(175);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 4, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (! $r) {
|
||||
logger("photo upload: profile image upload with scale 4 (175x175) failed");
|
||||
}
|
||||
}
|
||||
|
||||
if ($width > 80 || $height > 80) {
|
||||
$ph->scaleImage(80);
|
||||
$r = $ph->store(local_user(), $visitor, $hash, $filename, $album, 5, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$Image->scaleDown(80);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 5, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (! $r) {
|
||||
logger("photo upload: profile image upload with scale 5 (80x80) failed");
|
||||
}
|
||||
}
|
||||
|
||||
if ($width > 48 || $height > 48) {
|
||||
$ph->scaleImage(48);
|
||||
$r = $ph->store(local_user(), $visitor, $hash, $filename, $album, 6, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$Image->scaleDown(48);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 6, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (! $r) {
|
||||
logger("photo upload: profile image upload with scale 6 (48x48) failed");
|
||||
}
|
||||
}
|
||||
$ph->__destruct();
|
||||
$Image->__destruct();
|
||||
logger("photo upload: new profile image upload ended", LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ use Friendica\Core\System;
|
|||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\GlobalContact;
|
||||
use Friendica\Object\Contact;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Protocol\DFRN;
|
||||
use Friendica\Protocol\OStatus;
|
||||
use Friendica\Util\Lock;
|
||||
|
||||
require_once 'include/bbcode.php';
|
||||
require_once 'include/oembed.php';
|
||||
|
@ -1887,11 +1887,11 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) {
|
|||
$width = intval($match[1]);
|
||||
$height = intval($match[2]);
|
||||
|
||||
$ph = new Photo($data, $type);
|
||||
if ($ph->isValid()) {
|
||||
$ph->scaleImage(max($width, $height));
|
||||
$data = $ph->imageString();
|
||||
$type = $ph->getType();
|
||||
$Image = new Image($data, $type);
|
||||
if ($Image->isValid()) {
|
||||
$Image->scaleDown(max($width, $height));
|
||||
$data = $Image->asString();
|
||||
$type = $Image->getType();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use Friendica\App;
|
|||
use Friendica\Core\System;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Object\Photo;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
/**
|
||||
|
@ -710,18 +710,18 @@ function scale_external_images($srctext, $include_link = true, $scale_replace =
|
|||
}
|
||||
|
||||
// guess mimetype from headers or filename
|
||||
$type = Photo::guessImageType($mtch[1], true);
|
||||
$type = Image::guessType($mtch[1], true);
|
||||
|
||||
if ($i) {
|
||||
$ph = new Photo($i, $type);
|
||||
if ($ph->isValid()) {
|
||||
$orig_width = $ph->getWidth();
|
||||
$orig_height = $ph->getHeight();
|
||||
$Image = new Image($i, $type);
|
||||
if ($Image->isValid()) {
|
||||
$orig_width = $Image->getWidth();
|
||||
$orig_height = $Image->getHeight();
|
||||
|
||||
if ($orig_width > 640 || $orig_height > 640) {
|
||||
$ph->scaleImage(640);
|
||||
$new_width = $ph->getWidth();
|
||||
$new_height = $ph->getHeight();
|
||||
$Image->scaleDown(640);
|
||||
$new_width = $Image->getWidth();
|
||||
$new_height = $Image->getHeight();
|
||||
logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG);
|
||||
$s = str_replace(
|
||||
$mtch[0],
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use Friendica\App;
|
||||
use Friendica\ParseUrl;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Object\Photo;
|
||||
use Friendica\Object\Image;
|
||||
|
||||
require_once "include/bbcode.php";
|
||||
require_once "include/html2plain.php";
|
||||
|
@ -51,7 +51,7 @@ function get_old_attachment_data($body) {
|
|||
|
||||
if (preg_match("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $attacheddata, $matches)) {
|
||||
|
||||
$picturedata = Photo::getInfoFromURL($matches[1]);
|
||||
$picturedata = Image::getInfoFromURL($matches[1]);
|
||||
|
||||
if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1]))
|
||||
$post["image"] = $matches[1];
|
||||
|
@ -221,7 +221,7 @@ function get_attached_data($body, $item = array()) {
|
|||
$post["preview"] = $pictures[0][2];
|
||||
$post["text"] = str_replace($pictures[0][0], "", $body);
|
||||
} else {
|
||||
$imgdata = Photo::getInfoFromURL($pictures[0][1]);
|
||||
$imgdata = Image::getInfoFromURL($pictures[0][1]);
|
||||
if (substr($imgdata["mime"], 0, 6) == "image/") {
|
||||
$post["type"] = "photo";
|
||||
$post["image"] = $pictures[0][1];
|
||||
|
|
|
@ -7,7 +7,8 @@ use Friendica\Core\System;
|
|||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Object\Photo;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Object\Image;
|
||||
|
||||
define("IMPORT_DEBUG", False);
|
||||
|
||||
|
@ -260,8 +261,9 @@ function import_account(App $a, $file) {
|
|||
$photo['uid'] = $newuid;
|
||||
$photo['data'] = hex2bin($photo['data']);
|
||||
|
||||
$p = new Photo($photo['data'], $photo['type']);
|
||||
$r = $p->store(
|
||||
$Image = new Image($photo['data'], $photo['type']);
|
||||
$r = Photo::store(
|
||||
$Image,
|
||||
$photo['uid'], $photo['contact-id'], //0
|
||||
$photo['resource-id'], $photo['filename'], $photo['album'], $photo['scale'], $photo['profile'], //1
|
||||
$photo['allow_cid'], $photo['allow_gid'], $photo['deny_cid'], $photo['deny_gid']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue