support image urls
authorChristian Weiske <cweiske@cweiske.de>
Thu, 8 Sep 2016 19:35:52 +0000 (21:35 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 8 Sep 2016 19:35:52 +0000 (21:35 +0200)
src/shpub/Command/Note.php

index d7a709ed164c51be8306e2d80ef8dce8d7c36a2a..4a09b5afce5cd70a084267f9681384666da664bd 100644 (file)
@@ -49,13 +49,30 @@ class Command_Note
             'photo' => [],
             'video' => [],
         ];
+        $urls = [];
         foreach ($files as $filePath) {
-            if (!file_exists($filePath)) {
+            if (file_exists($filePath)) {
+                $type = 'photo';
+                $fileList[$type][] = $filePath;
+            } else if (strpos($filePath, '://') !== false) {
+                //url
+                $urls[] = $filePath;
+            } else {
                 Log::err('File does not exist: ' . $filePath);
                 exit(20);
             }
-            $type = 'photo';
-            $fileList[$type][] = $filePath;
+        }
+        if (count($urls)) {
+            if (count($urls) == 1) {
+                $req->req->addPostParameter('photo', reset($urls));
+            } else {
+                $n = 0;
+                foreach ($urls as $url) {
+                    $req->req->addPostParameter(
+                        'photo[' . $n++ . ']', reset($urls)
+                    );
+                }
+            }
         }
         foreach ($fileList as $type => $filePaths) {
             if (count($filePaths) == 1) {