]> git.mxchange.org Git - friendica.git/commitdiff
api: add support for StatusNet-style media param to API
authorMichael Johnston <michaelgeorgejohnston@gmail.com>
Sun, 22 Apr 2012 17:37:25 +0000 (13:37 -0400)
committerMichael Johnston <michaelgeorgejohnston@gmail.com>
Sun, 22 Apr 2012 17:37:25 +0000 (13:37 -0400)
include/api.php
mod/wall_upload.php

index 0885a1434b19b773284f9b7d85b1a3d582e6c25f..f9be68c3df3a4961c3d9e6a98b6c7fe1337c9f80 100644 (file)
                $_REQUEST['profile_uid'] = local_user();
                if(requestdata('parent'))
                        $_REQUEST['type'] = 'net-comment';
-               else
+               else {
                        $_REQUEST['type'] = 'wall';
+                        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
+                               require_once('mod/wall_upload.php');
+                               $media = wall_upload_post($a);
+                               if(strlen($media)>0)
+                                       $_REQUEST['body'] .= "\n\n".$media;
+                               }
+               }
 
                // set this so that the item_post() function is quiet and doesn't redirect or emit json
 
index f341cc9cdaa837186d2b10d4efad4964f10f6fe5..fa66561e8ec3ab9c1fcd726f1080fa2878aa4e6b 100644 (file)
@@ -5,19 +5,26 @@ require_once('Photo.php');
 function wall_upload_post(&$a) {
 
        if($a->argc > 1) {
-               $nick = $a->argv[1];
-               $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid`  WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1",
-                       dbesc($nick)
-               );
-               if(! count($r))
-                       return;
-
+               if(! x($_FILES,'media')) {
+                       $nick = $a->argv[1];
+                       $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid`  WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1",
+                               dbesc($nick)
+                       );
+
+                       if(! count($r))
+                                return;
+               }
+                else {
+                       $user_info = api_get_user($a);
+                       $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT 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'])
+                       );
+                }
        }
        else
                return;
 
 
-
        $can_post  = false;
        $visitor   = 0;
 
@@ -47,12 +54,19 @@ function wall_upload_post(&$a) {
                killme();
        }
 
-       if(! x($_FILES,'userfile'))
+       if(! x($_FILES,'userfile') && ! x($_FILES,'media'))
                killme();
 
-       $src      = $_FILES['userfile']['tmp_name'];
-       $filename = basename($_FILES['userfile']['name']);
-       $filesize = intval($_FILES['userfile']['size']);
+        if(x($_FILES,'userfile')) {
+               $src      = $_FILES['userfile']['tmp_name'];
+               $filename = basename($_FILES['userfile']['name']);
+               $filesize = intval($_FILES['userfile']['size']);
+        }
+        elseif(x($_FILES,'media')) {
+               $src = $_FILES['media']['tmp_name'];
+                $filename = basename($_FILES['media']['name']);
+               $filesize = intval($_FILES['media']['size']);
+        }
 
        $maximagesize = get_config('system','maximagesize');