From 18a77a1b456b4df7d46112cbaf5323d8d17f9790 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 5 Jun 2018 05:42:26 +0000 Subject: [PATCH 1/2] Removed some quick and dirty hack to upload pictures --- include/api.php | 17 ++++++-------- mod/wall_upload.php | 57 ++++++++++++++++++++------------------------- 2 files changed, 32 insertions(+), 42 deletions(-) diff --git a/include/api.php b/include/api.php index de5c5689f1..881cb3309b 100644 --- a/include/api.php +++ b/include/api.php @@ -1066,7 +1066,7 @@ function requestdata($k) } /** - * Waitman Gobble Mod + * Deprecated function to upload media. * * @param string $type Return type (atom, rss, xml, json) * @@ -1098,14 +1098,12 @@ function api_statuses_mediap($type) } $txt = HTML::toBBCode($txt); - $a->argv[1]=$user_info['screen_name']; //should be set to username? + $a->argv[1] = $user_info['screen_name']; //should be set to username? - // tell wall_upload function to return img info instead of echo - $_REQUEST['hush'] = 'yeah'; - $bebop = wall_upload_post($a); + $picture = wall_upload_post($a, false); // now that we have the img url in bbcode we can add it to the status and insert the wall item. - $_REQUEST['body'] = $txt . "\n\n" . $bebop; + $_REQUEST['body'] = $txt . "\n\n" . '[url=' . $picture["albumpage"] . '][img]' . $picture["preview"] . "[/img][/url]"; item_post($a); // this should output the last post (the one we just posted). @@ -1254,10 +1252,9 @@ function api_statuses_update($type) if (x($_FILES, 'media')) { // upload the image if we have one - $_REQUEST['hush'] = 'yeah'; //tell wall_upload function to return img info instead of echo - $media = wall_upload_post($a); - if (strlen($media) > 0) { - $_REQUEST['body'] .= "\n\n" . $media; + $picture = wall_upload_post($a, false); + if (is_array($media)) { + $_REQUEST['body'] .= "\n\n" . '[url=' . $picture["albumpage"] . '][img]' . $picture["preview"] . "[/img][/url]"; } } diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 61578ca5c8..7067077eb7 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -16,15 +16,15 @@ use Friendica\Database\DBM; use Friendica\Model\Photo; use Friendica\Object\Image; -function wall_upload_post(App $a, $desktopmode = true) { - +function wall_upload_post(App $a, $desktopmode = true) +{ logger("wall upload: starting new upload", LOGGER_DEBUG); $r_json = (x($_GET, 'response') && $_GET['response'] == 'json'); $album = (x($_GET, 'album') ? notags(trim($_GET['album'])) : ''); if ($a->argc > 1) { - if (! x($_FILES, 'media')) { + if (!x($_FILES, 'media')) { $nick = $a->argv[1]; $r = q("SELECT `user`.*, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid` @@ -33,9 +33,9 @@ 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(['error'=>L10n::t('Invalid request.')]); + echo json_encode(['error' => L10n::t('Invalid request.')]); killme(); } return; @@ -51,7 +51,7 @@ function wall_upload_post(App $a, $desktopmode = true) { } } else { if ($r_json) { - echo json_encode(['error'=>L10n::t('Invalid request.')]); + echo json_encode(['error' => L10n::t('Invalid request.')]); killme(); } return; @@ -98,18 +98,18 @@ function wall_upload_post(App $a, $desktopmode = true) { } - if (! $can_post) { + if (!$can_post) { if ($r_json) { - echo json_encode(['error'=>L10n::t('Permission denied.')]); + echo json_encode(['error' => L10n::t('Permission denied.')]); killme(); } notice(L10n::t('Permission denied.') . EOL); killme(); } - if (! x($_FILES, 'userfile') && ! x($_FILES, 'media')) { + if (!x($_FILES, 'userfile') && !x($_FILES, 'media')) { if ($r_json) { - echo json_encode(['error'=>L10n::t('Invalid request.')]); + echo json_encode(['error' => L10n::t('Invalid request.')]); } killme(); } @@ -150,9 +150,9 @@ function wall_upload_post(App $a, $desktopmode = true) { } } - if ($src=="") { + if ($src == "") { if ($r_json) { - echo json_encode(['error'=>L10n::t('Invalid request.')]); + echo json_encode(['error' => L10n::t('Invalid request.')]); killme(); } notice(L10n::t('Invalid request.').EOL); @@ -185,7 +185,7 @@ function wall_upload_post(App $a, $desktopmode = true) { if (($maximagesize) && ($filesize > $maximagesize)) { $msg = L10n::t('Image exceeds size limit of %s', formatBytes($maximagesize)); if ($r_json) { - echo json_encode(['error'=>$msg]); + echo json_encode(['error' => $msg]); } else { echo $msg. EOL; } @@ -196,10 +196,10 @@ function wall_upload_post(App $a, $desktopmode = true) { $imagedata = @file_get_contents($src); $Image = new Image($imagedata, $filetype); - if (! $Image->isValid()) { + if (!$Image->isValid()) { $msg = L10n::t('Unable to process image.'); if ($r_json) { - echo json_encode(['error'=>$msg]); + echo json_encode(['error' => $msg]); } else { echo $msg. EOL; } @@ -211,7 +211,7 @@ function wall_upload_post(App $a, $desktopmode = true) { @unlink($src); $max_length = Config::get('system', 'max_image_length'); - if (! $max_length) { + if (!$max_length) { $max_length = MAX_IMAGE_LENGTH; } if ($max_length > 0) { @@ -227,7 +227,7 @@ function wall_upload_post(App $a, $desktopmode = true) { $smallest = 0; // If we don't have an album name use the Wall Photos album - if (! strlen($album)) { + if (!strlen($album)) { $album = L10n::t('Wall Photos'); } @@ -235,10 +235,10 @@ function wall_upload_post(App $a, $desktopmode = true) { $r = Photo::store($Image, $page_owner_uid, $visitor, $hash, $filename, $album, 0, 0, $defperm); - if (! $r) { + if (!$r) { $msg = L10n::t('Image upload failed.'); if ($r_json) { - echo json_encode(['error'=>$msg]); + echo json_encode(['error' => $msg]); } else { echo $msg. EOL; } @@ -271,7 +271,7 @@ function wall_upload_post(App $a, $desktopmode = true) { ); if (!$r) { if ($r_json) { - echo json_encode(['error'=>'']); + echo json_encode(['error' => '']); killme(); } return false; @@ -288,28 +288,21 @@ function wall_upload_post(App $a, $desktopmode = true) { $picture["preview"] = System::baseUrl() . "/photo/{$hash}-{$smallest}." . $Image->getExt(); if ($r_json) { - echo json_encode(['picture'=>$picture]); + echo json_encode(['picture' => $picture]); killme(); } + logger("upload done", LOGGER_DEBUG); return $picture; } + logger("upload done", LOGGER_DEBUG); if ($r_json) { - echo json_encode(['ok'=>true]); + echo json_encode(['ok' => true]); killme(); } -/* 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=' . System::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . System::baseUrl() . "/photo/{$hash}-{$smallest}.".$Image->getExt()."[/img][/url]\n\n"; - } else { - $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 */ - + 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(); // NOTREACHED } From e632be763ca06f3c634bff50bcf42bf7d571d0b2 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 5 Jun 2018 05:44:04 +0000 Subject: [PATCH 2/2] Corrected variable --- include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index 881cb3309b..91a8d42c46 100644 --- a/include/api.php +++ b/include/api.php @@ -1253,7 +1253,7 @@ function api_statuses_update($type) if (x($_FILES, 'media')) { // upload the image if we have one $picture = wall_upload_post($a, false); - if (is_array($media)) { + if (is_array($picture)) { $_REQUEST['body'] .= "\n\n" . '[url=' . $picture["albumpage"] . '][img]' . $picture["preview"] . "[/img][/url]"; } }