From 8b4c17e2e9a292682f83d6c23c7793e700b09bcf Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 8 Sep 2016 21:35:52 +0200 Subject: [PATCH] support image urls --- src/shpub/Command/Note.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/shpub/Command/Note.php b/src/shpub/Command/Note.php index d7a709e..4a09b5a 100644 --- a/src/shpub/Command/Note.php +++ b/src/shpub/Command/Note.php @@ -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) { -- 2.30.2