]> git.mxchange.org Git - friendica.git/blobdiff - mod/wall_upload.php
Remove/replace killme() with *exit()
[friendica.git] / mod / wall_upload.php
index 8bf2966152957943c93655cde47df9eb42d9eac4..d1fb918bfe124bf69c2848e1f0e9c229227eaa69 100644 (file)
 
 use Friendica\App;
 use Friendica\Core\L10n;
+use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Core\Config;
-use Friendica\Database\DBM;
+use Friendica\Database\DBA;
+use Friendica\Model\Contact;
 use Friendica\Model\Photo;
 use Friendica\Object\Image;
+use Friendica\Util\Strings;
 
 function wall_upload_post(App $a, $desktopmode = true)
 {
-       logger("wall upload: starting new upload", LOGGER_DEBUG);
+       Logger::log("wall upload: starting new upload", Logger::DEBUG);
 
-       $r_json = (x($_GET, 'response') && $_GET['response'] == 'json');
-       $album = (x($_GET, 'album') ? notags(trim($_GET['album'])) : '');
+       $r_json = (!empty($_GET['response']) && $_GET['response'] == 'json');
+       $album = (!empty($_GET['album']) ? Strings::escapeTags(trim($_GET['album'])) : '');
 
        if ($a->argc > 1) {
-               if (!x($_FILES, 'media')) {
+               if (empty($_FILES['media'])) {
                        $nick = $a->argv[1];
                        $r = q("SELECT `user`.*, `contact`.`id` FROM `user`
                                INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
                                WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0
                                AND `contact`.`self` = 1 LIMIT 1",
-                               dbesc($nick)
+                               DBA::escape($nick)
                        );
 
-                       if (!DBM::is_result($r)) {
+                       if (!DBA::isResult($r)) {
                                if ($r_json) {
                                        echo json_encode(['error' => L10n::t('Invalid request.')]);
-                                       killme();
+                                       exit();
                                }
                                return;
                        }
@@ -46,13 +49,13 @@ function wall_upload_post(App $a, $desktopmode = true)
                                INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
                                WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0
                                AND `contact`.`self` = 1 LIMIT 1",
-                               dbesc($user_info['screen_name'])
+                               DBA::escape($user_info['screen_name'])
                        );
                }
        } else {
                if ($r_json) {
                        echo json_encode(['error' => L10n::t('Invalid request.')]);
-                       killme();
+                       exit();
                }
                return;
        }
@@ -66,7 +69,7 @@ function wall_upload_post(App $a, $desktopmode = true)
        $page_owner_uid   = $r[0]['uid'];
        $default_cid      = $r[0]['id'];
        $page_owner_nick  = $r[0]['nickname'];
-       $community_page   = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
+       $community_page   = (($r[0]['page-flags'] == Contact::PAGE_COMMUNITY) ? true : false);
 
        if ((local_user()) && (local_user() == $page_owner_uid)) {
                $can_post = true;
@@ -89,7 +92,7 @@ function wall_upload_post(App $a, $desktopmode = true)
                                        intval($contact_id),
                                        intval($page_owner_uid)
                                );
-                               if (DBM::is_result($r)) {
+                               if (DBA::isResult($r)) {
                                        $can_post = true;
                                        $visitor = $contact_id;
                                }
@@ -101,30 +104,30 @@ function wall_upload_post(App $a, $desktopmode = true)
        if (!$can_post) {
                if ($r_json) {
                        echo json_encode(['error' => L10n::t('Permission denied.')]);
-                       killme();
+                       exit();
                }
                notice(L10n::t('Permission denied.') . EOL);
-               killme();
+               exit();
        }
 
-       if (!x($_FILES, 'userfile') && !x($_FILES, 'media')) {
+       if (empty($_FILES['userfile']) && empty($_FILES['media'])) {
                if ($r_json) {
                        echo json_encode(['error' => L10n::t('Invalid request.')]);
                }
-               killme();
+               exit();
        }
 
        $src = '';
        $filename = '';
        $filesize = 0;
        $filetype = '';
-       if (x($_FILES, 'userfile')) {
+       if (!empty($_FILES['userfile'])) {
                $src      = $_FILES['userfile']['tmp_name'];
                $filename = basename($_FILES['userfile']['name']);
                $filesize = intval($_FILES['userfile']['size']);
                $filetype = $_FILES['userfile']['type'];
 
-       } elseif (x($_FILES, 'media')) {
+       } elseif (!empty($_FILES['media'])) {
                if (!empty($_FILES['media']['tmp_name'])) {
                        if (is_array($_FILES['media']['tmp_name'])) {
                                $src = $_FILES['media']['tmp_name'][0];
@@ -161,10 +164,10 @@ function wall_upload_post(App $a, $desktopmode = true)
        if ($src == "") {
                if ($r_json) {
                        echo json_encode(['error' => L10n::t('Invalid request.')]);
-                       killme();
+                       exit();
                }
                notice(L10n::t('Invalid request.').EOL);
-               killme();
+               exit();
        }
 
        // This is a special treatment for picture upload from Twidere
@@ -185,20 +188,20 @@ function wall_upload_post(App $a, $desktopmode = true)
                $filetype = $imagedata['mime'];
        }
 
-       logger("File upload src: " . $src . " - filename: " . $filename .
-               " - size: " . $filesize . " - type: " . $filetype, LOGGER_DEBUG);
+       Logger::log("File upload src: " . $src . " - filename: " . $filename .
+               " - size: " . $filesize . " - type: " . $filetype, Logger::DEBUG);
 
        $maximagesize = Config::get('system', 'maximagesize');
 
        if (($maximagesize) && ($filesize > $maximagesize)) {
-               $msg = L10n::t('Image exceeds size limit of %s', formatBytes($maximagesize));
+               $msg = L10n::t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize));
                if ($r_json) {
                        echo json_encode(['error' => $msg]);
                } else {
                        echo  $msg. EOL;
                }
                @unlink($src);
-               killme();
+               exit();
        }
 
        $imagedata = @file_get_contents($src);
@@ -212,7 +215,7 @@ function wall_upload_post(App $a, $desktopmode = true)
                        echo  $msg. EOL;
                }
                @unlink($src);
-               killme();
+               exit();
        }
 
        $Image->orient($src);
@@ -224,7 +227,7 @@ function wall_upload_post(App $a, $desktopmode = true)
        }
        if ($max_length > 0) {
                $Image->scaleDown($max_length);
-               logger("File upload: Scaling picture to new size " . $max_length, LOGGER_DEBUG);
+               Logger::log("File upload: Scaling picture to new size " . $max_length, Logger::DEBUG);
        }
 
        $width = $Image->getWidth();
@@ -250,7 +253,7 @@ function wall_upload_post(App $a, $desktopmode = true)
                } else {
                        echo  $msg. EOL;
                }
-               killme();
+               exit();
        }
 
        if ($width > 640 || $height > 640) {
@@ -280,7 +283,7 @@ function wall_upload_post(App $a, $desktopmode = true)
                if (!$r) {
                        if ($r_json) {
                                echo json_encode(['error' => '']);
-                               killme();
+                               exit();
                        }
                        return false;
                }
@@ -297,20 +300,20 @@ function wall_upload_post(App $a, $desktopmode = true)
 
                if ($r_json) {
                        echo json_encode(['picture' => $picture]);
-                       killme();
+                       exit();
                }
-               logger("upload done", LOGGER_DEBUG);
+               Logger::log("upload done", Logger::DEBUG);
                return $picture;
        }
 
-       logger("upload done", LOGGER_DEBUG);
+       Logger::log("upload done", Logger::DEBUG);
 
        if ($r_json) {
                echo json_encode(['ok' => true]);
-               killme();
+               exit();
        }
 
        echo  "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . System::baseUrl() . "/photo/{$hash}-{$smallest}.".$Image->getExt()."[/img][/url]\n\n";
-       killme();
+       exit();
        // NOTREACHED
 }