]> git.mxchange.org Git - friendica.git/commitdiff
API: New picture upload function (Enhanced Twidere support)
authorMichael Vogel <icarus@dabo.de>
Mon, 6 Apr 2015 01:19:12 +0000 (03:19 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 6 Apr 2015 01:19:12 +0000 (03:19 +0200)
include/api.php
mod/wall_upload.php

index d2592afc676716cbf22f7efd3831f7781bde3e11..e5ee36fdf120191d3001a949c28467aafc5a6f0e 100644 (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
         *
                                $_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;
        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);
 
                if (!$ret)
                        return false;
 
-               require_once("include/Photo.php");
-
                $attachments = array();
 
                foreach ($images[1] AS $image) {
 
                        $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:
index f1fde2e33c3b364b44f14852d4a314b7c3f65f12..291307b8ec3d22efcf14e2b6295c1fb686f9aa00 100644 (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 */