Browse Source

API: New picture upload function (Enhanced Twidere support)

pull/1483/head
Michael Vogel 5 years ago
parent
commit
3cbd72d907
2 changed files with 69 additions and 4 deletions
  1. +49
    -3
      include/api.php
  2. +20
    -1
      mod/wall_upload.php

+ 49
- 3
include/api.php View File

@ -8,6 +8,8 @@
require_once("include/oauth.php");
require_once("include/html2plain.php");
require_once("mod/share.php");
require_once("include/Photo.php");
/*
* Twitter-Like API
*
@ -822,6 +824,18 @@
$_REQUEST['body'] .= "\n\n".$media;
}
// To-Do: Multiple IDs
if (requestdata('media_ids')) {
$r = q("SELECT `resource-id`, `scale`, `nickname`, `type` FROM `photo` INNER JOIN `user` ON `user`.`uid` = `photo`.`uid` WHERE `resource-id` IN (SELECT `resource-id` FROM `photo` WHERE `id` = %d) AND `scale` > 0 AND `photo`.`uid` = %d ORDER BY `photo`.`width` DESC LIMIT 1",
intval(requestdata('media_ids')), api_user());
if ($r) {
$phototypes = Photo::supportedTypes();
$ext = $phototypes[$r[0]['type']];
$_REQUEST['body'] .= "\n\n".'[url='.$a->get_baseurl().'/photos/'.$r[0]['nickname'].'/image/'.$r[0]['resource-id'].']';
$_REQUEST['body'] .= '[img]'.$a->get_baseurl()."/photo/".$r[0]['resource-id']."-".$r[0]['scale'].".".$ext."[/img][/url]";
}
}
// set this so that the item_post() function is quiet and doesn't redirect or emit json
$_REQUEST['api_source'] = true;
@ -841,6 +855,41 @@
api_register_func('api/statuses/update_with_media','api_statuses_update', true);
function api_media_upload(&$a, $type) {
if (api_user()===false) {
logger('no user');
return false;
}
$user_info = api_get_user($a);
if(!x($_FILES,'media')) {
// Output error
return false;
}
require_once('mod/wall_upload.php');
$media = wall_upload_post($a, false);
if(!$media) {
// Output error
return false;
}
$returndata = array();
$returndata["media_id"] = $media["id"];
$returndata["media_id_string"] = (string)$media["id"];
$returndata["size"] = $media["size"];
$returndata["image"] = array("w" => $media["width"],
"h" => $media["height"],
"image_type" => $media["type"]);
logger("Media uploaded: ".print_r($returndata, true), LOGGER_DEBUG);
return array("media" => $returndata);
}
api_register_func('api/media/upload','api_media_upload', true);
function api_status_show(&$a, $type){
$user_info = api_get_user($a);
@ -1875,8 +1924,6 @@
if (!$ret)
return false;
require_once("include/Photo.php");
$attachments = array();
foreach ($images[1] AS $image) {
@ -2002,7 +2049,6 @@
$start = iconv_strpos($text, $url, $offset, "UTF-8");
if (!($start === false)) {
require_once("include/Photo.php");
$image = get_photo_info($url);
if ($image) {
// If image cache is activated, then use the following sizes:


+ 20
- 1
mod/wall_upload.php View File

@ -2,7 +2,7 @@
require_once('include/Photo.php');
function wall_upload_post(&$a) {
function wall_upload_post(&$a, $desktopmode = true) {
logger("wall upload: starting new upload", LOGGER_DEBUG);
@ -189,6 +189,25 @@ function wall_upload_post(&$a) {
$basename = basename($filename);
if (!$desktopmode) {
$r = q("SELECT `id`, `datasize`, `width`, `height`, `type` FROM `photo` WHERE `resource-id` = '%s' ORDER BY `width` DESC LIMIT 1", $hash);
if (!$r)
return false;
$picture = array();
$picture["id"] = $r[0]["id"];
$picture["size"] = $r[0]["datasize"];
$picture["width"] = $r[0]["width"];
$picture["height"] = $r[0]["height"];
$picture["type"] = $r[0]["type"];
$picture["albumpage"] = $a->get_baseurl().'/photos/'.$page_owner_nick.'/image/'.$hash;
$picture["picture"] = $a->get_baseurl()."/photo/{$hash}-0.".$ph->getExt();
$picture["preview"] = $a->get_baseurl()."/photo/{$hash}-{$smallest}.".$ph->getExt();
return $picture;
}
/* mod Waitman Gobble NO WARRANTY */


Loading…
Cancel
Save