]> git.mxchange.org Git - friendica.git/blobdiff - mod/wall_upload.php
forgotten templates
[friendica.git] / mod / wall_upload.php
index 36d4db53d9395ebdf0d41fe5de08c8adbd3d88ce..a608743d07ff6292799f3c50fe8484b27591093d 100644 (file)
@@ -12,8 +12,9 @@
 use Friendica\App;
 use Friendica\Core\System;
 use Friendica\Core\Config;
-
-require_once 'include/Photo.php';
+use Friendica\Database\DBM;
+use Friendica\Model\Photo;
+use Friendica\Object\Image;
 
 function wall_upload_post(App $a, $desktopmode = true) {
 
@@ -32,7 +33,7 @@ function wall_upload_post(App $a, $desktopmode = true) {
                                dbesc($nick)
                        );
 
-                       if (! dbm::is_result($r)) {
+                       if (! DBM::is_result($r)) {
                                if ($r_json) {
                                        echo json_encode(array('error'=>t('Invalid request.')));
                                        killme();
@@ -88,7 +89,7 @@ function wall_upload_post(App $a, $desktopmode = true) {
                                        intval($contact_id),
                                        intval($page_owner_uid)
                                );
-                               if (dbm::is_result($r)) {
+                               if (DBM::is_result($r)) {
                                        $can_post = true;
                                        $visitor = $contact_id;
                                }
@@ -161,8 +162,8 @@ function wall_upload_post(App $a, $desktopmode = true) {
                $filetype = "";
        }
 
-       if ($filetype=="") {
-               $filetype=guess_image_type($filename);
+       if ($filetype == "") {
+               $filetype = Image::guessType($filename);
        }
 
        // If there is a temp name, then do a manual check
@@ -189,33 +190,10 @@ function wall_upload_post(App $a, $desktopmode = true) {
                killme();
        }
 
-
-       $limit = service_class_fetch($page_owner_uid, 'photo_upload_limit');
-
-       if ($limit) {
-               $r = q("SELECT SUM(OCTET_LENGTH(`data`)) AS `total` FROM `photo`
-                       WHERE `uid` = %d AND `scale` = 0
-                       AND `album` != 'Contact Photos' ",
-                       intval($page_owner_uid)
-               );
-               $size = $r[0]['total'];
-
-               if (($size + strlen($imagedata)) > $limit) {
-                       $msg = upgrade_message(true);
-                       if ($r_json) {
-                               echo json_encode(array('error'=>$msg));
-                       } else {
-                               echo  $msg. EOL;
-                       }
-                       @unlink($src);
-                       killme();
-               }
-       }
-
        $imagedata = @file_get_contents($src);
-       $ph = new Photo($imagedata, $filetype);
+       $Image = new Image($imagedata, $filetype);
 
-       if (! $ph->is_valid()) {
+       if (! $Image->isValid()) {
                $msg = t('Unable to process image.');
                if ($r_json) {
                        echo json_encode(array('error'=>$msg));
@@ -226,7 +204,7 @@ function wall_upload_post(App $a, $desktopmode = true) {
                killme();
        }
 
-       $ph->orient($src);
+       $Image->orient($src);
        @unlink($src);
 
        $max_length = Config::get('system', 'max_image_length');
@@ -234,12 +212,12 @@ function wall_upload_post(App $a, $desktopmode = true) {
                $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();
 
        $hash = photo_new_resource();
 
@@ -252,7 +230,7 @@ function wall_upload_post(App $a, $desktopmode = true) {
 
        $defperm = '<' . $default_cid . '>';
 
-       $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, $album, 0, 0, $defperm);
+       $r = Photo::store($Image, $page_owner_uid, $visitor, $hash, $filename, $album, 0, 0, $defperm);
 
        if (! $r) {
                $msg = t('Image upload failed.');
@@ -265,16 +243,16 @@ function wall_upload_post(App $a, $desktopmode = true) {
        }
 
        if ($width > 640 || $height > 640) {
-               $ph->scaleImage(640);
-               $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, $album, 1, 0, $defperm);
+               $Image->scaleDown(640);
+               $r = Photo::store($Image, $page_owner_uid, $visitor, $hash, $filename, $album, 1, 0, $defperm);
                if ($r) {
                        $smallest = 1;
                }
        }
 
        if ($width > 320 || $height > 320) {
-               $ph->scaleImage(320);
-               $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, $album, 2, 0, $defperm);
+               $Image->scaleDown(320);
+               $r = Photo::store($Image, $page_owner_uid, $visitor, $hash, $filename, $album, 2, 0, $defperm);
                if ($r && ($smallest == 0)) {
                        $smallest = 2;
                }
@@ -302,9 +280,9 @@ function wall_upload_post(App $a, $desktopmode = true) {
                $picture["width"]     = $r[0]["width"];
                $picture["height"]    = $r[0]["height"];
                $picture["type"]      = $r[0]["type"];
-               $picture["albumpage"] = App::get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash;
-               $picture["picture"]   = App::get_baseurl() . "/photo/{$hash}-0." . $ph->getExt();
-               $picture["preview"]   = App::get_baseurl() . "/photo/{$hash}-{$smallest}." . $ph->getExt();
+               $picture["albumpage"] = System::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $hash;
+               $picture["picture"]   = System::baseUrl() . "/photo/{$hash}-0." . $Image->getExt();
+               $picture["preview"]   = System::baseUrl() . "/photo/{$hash}-{$smallest}." . $Image->getExt();
 
                if ($r_json) {
                        echo json_encode(array('picture'=>$picture));
@@ -322,9 +300,9 @@ function wall_upload_post(App $a, $desktopmode = true) {
 /* mod Waitman Gobble NO WARRANTY */
        // if we get the signal then return the image url info in BBCODE
        if ($_REQUEST['hush']!='yeah') {
-               echo  "\n\n" . '[url=' . App::get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . App::get_baseurl() . "/photo/{$hash}-{$smallest}.".$ph->getExt()."[/img][/url]\n\n";
+               echo  "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . System::baseUrl() . "/photo/{$hash}-{$smallest}.".$Image->getExt()."[/img][/url]\n\n";
        } else {
-               $m = '[url='.App::get_baseurl().'/photos/'.$page_owner_nick.'/image/'.$hash.'][img]'.App::get_baseurl()."/photo/{$hash}-{$smallest}.".$ph->getExt()."[/img][/url]";
+               $m = '[url='.System::baseUrl().'/photos/'.$page_owner_nick.'/image/'.$hash.'][img]'.System::baseUrl()."/photo/{$hash}-{$smallest}.".$Image->getExt()."[/img][/url]";
                return($m);
        }
 /* mod Waitman Gobble NO WARRANTY */