Fix CS
[shpub.git] / src / shpub / Command / AbstractProps.php
index c9ea8bb1a5c323876da182ebe2c1f455afdd2ff7..e186819f49b26a907660a50854f87c028f9ee06f 100644 (file)
@@ -3,6 +3,10 @@ namespace shpub;
 
 /**
  * Abstract command class that handles generic properties
+ *
+ * @author  Christian Weiske <cweiske@cweiske.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link    http://cweiske.de/shpub.htm
  */
 class Command_AbstractProps
 {
@@ -40,6 +44,15 @@ class Command_AbstractProps
                 'default'     => [],
             )
         );
+        $cmd->addOption(
+            'direct_upload',
+            array(
+                'long_name'   => '--direct-upload',
+                'description' => 'Ignore media endpoint at file upload',
+                'action'      => 'StoreTrue',
+                'default'     => false,
+            )
+        );
         $cmd->addOption(
             'name',
             array(
@@ -85,7 +98,7 @@ class Command_AbstractProps
         $cmd->addOption(
             'syndication',
             array(
-                'short_name'  => '-s',
+                'short_name'  => '-u',
                 'long_name'   => '--syndication',
                 'description' => 'Syndication URL(s)',
                 'help_name'   => 'URL',
@@ -107,6 +120,19 @@ class Command_AbstractProps
         static::addOptJson($cmd);
     }
 
+    protected static function addOptHtml(\Console_CommandLine_Command $cmd)
+    {
+        $cmd->addOption(
+            'html',
+            array(
+                'long_name'   => '--html',
+                'description' => 'Text content is HTML',
+                'action'      => 'StoreTrue',
+                'default'     => false,
+            )
+        );
+    }
+
     protected static function addOptJson(\Console_CommandLine_Command $cmd)
     {
         $cmd->addOption(
@@ -126,36 +152,37 @@ class Command_AbstractProps
         $this->handleOptJson($cmdRes, $req);
 
         if ($cmdRes->options['published'] !== null) {
-            $req->req->addPostParameter(
+            $req->addProperty(
                 'published', $cmdRes->options['published']
             );
         }
         if ($cmdRes->options['updated'] !== null) {
-            $req->req->addPostParameter(
+            $req->addProperty(
                 'updated', $cmdRes->options['updated']
             );
         }
         if (count($cmdRes->options['categories'])) {
-            $req->addPostParameter(
+            $req->addProperty(
                 'category', $cmdRes->options['categories']
             );
         }
         if ($cmdRes->options['name'] !== null) {
-            $req->req->addPostParameter(
+            $req->addProperty(
                 'name', $cmdRes->options['name']
             );
         }
         if ($cmdRes->options['slug'] !== null) {
-            $req->req->addPostParameter(
+            $req->addProperty(
                 'slug', $cmdRes->options['slug']
             );
         }
         if (count($cmdRes->options['syndication'])) {
-            $req->addPostParameter(
+            $req->addProperty(
                 'syndication', $cmdRes->options['syndication']
             );
         }
 
+        $req->setDirectUpload($cmdRes->options['direct_upload']);
         $this->handleFiles($cmdRes, $req);
 
         if (count($cmdRes->options['x'])) {
@@ -168,7 +195,7 @@ class Command_AbstractProps
                 $postParams[$propkey][] = $propval;
             }
             foreach ($postParams as $propkey => $propvals) {
-                $req->addPostParameter($propkey, $propvals);
+                $req->addProperty($propkey, $propvals);
             }
         }
     }
@@ -192,8 +219,9 @@ class Command_AbstractProps
         foreach ($files as $filePath) {
             if (strpos($filePath, '://') !== false) {
                 //url
+                $urlPath  = parse_url($filePath, PHP_URL_PATH);
                 $mte      = new \MIME_Type_Extension();
-                $mimetype = $mte->getMIMEType($filePath);
+                $mimetype = $mte->getMIMEType($urlPath);
                 $media    = \MIME_Type::getMedia($mimetype);
                 if (!isset($urlList[$media])) {
                     Log::err('File type not allowed: ' . $mimetype);
@@ -218,24 +246,15 @@ class Command_AbstractProps
             if ($type == 'image') {
                 $type = 'photo';
             }
-            if (count($urls) == 1) {
-                $req->req->addPostParameter($type, reset($urls));
-            } else if (count($urls) > 1) {
-                $n = 0;
-                foreach ($urls as $url) {
-                    $req->req->addPostParameter(
-                        $type . '[' . $n++ . ']', $url
-                    );
-                }
+            if (count($urls) > 0) {
+                $req->addProperty($type, $urls);
             }
         }
         foreach ($fileList as $type => $filePaths) {
             if ($type == 'image') {
                 $type = 'photo';
             }
-            if (count($filePaths) == 1) {
-                $req->addUpload($type, reset($filePaths));
-            } else if (count($filePaths) > 0) {
+            if (count($filePaths) > 0) {
                 $req->addUpload($type, $filePaths);
             }
         }