From: Christian Weiske Date: Thu, 8 Sep 2016 19:35:52 +0000 (+0200) Subject: support image urls X-Git-Tag: v0.0.3~1 X-Git-Url: https://git.cweiske.de/shpub.git/commitdiff_plain/8b4c17e2e9a292682f83d6c23c7793e700b09bcf support image urls --- 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) {