Support --html everywhere
authorChristian Weiske <cweiske@cweiske.de>
Thu, 15 Sep 2016 20:44:52 +0000 (22:44 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 15 Sep 2016 20:44:52 +0000 (22:44 +0200)
src/shpub/Command/AbstractProps.php
src/shpub/Command/Article.php
src/shpub/Command/Bookmark.php
src/shpub/Command/Note.php
src/shpub/Command/Reply.php
src/shpub/Command/Rsvp.php
src/shpub/Request.php

index c9ea8bb1a5c323876da182ebe2c1f455afdd2ff7..b581f3c33e64378e8eeb9b5483c0e1122f08c3af 100644 (file)
@@ -107,6 +107,20 @@ class Command_AbstractProps
         static::addOptJson($cmd);
     }
 
+    protected static function addOptHtml(\Console_CommandLine_Command $cmd)
+    {
+        $cmd->addOption(
+            'html',
+            array(
+                'short_name'  => '-h',
+                'long_name'   => '--html',
+                'description' => 'Text content is HTML',
+                'action'      => 'StoreTrue',
+                'default'     => false,
+            )
+        );
+    }
+
     protected static function addOptJson(\Console_CommandLine_Command $cmd)
     {
         $cmd->addOption(
index 8445af49e7471eab0d803ad81c7fc03e41a37f07..c657b2c74c3279d66b749b3c0a3621f97e3145a8 100644 (file)
@@ -6,16 +6,7 @@ class Command_Article extends Command_AbstractProps
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('article');
-        $cmd->addOption(
-            'html',
-            array(
-                'short_name'  => '-h',
-                'long_name'   => '--html',
-                'description' => 'Text content is HTML',
-                'action'      => 'StoreTrue',
-                'default'     => false,
-            )
-        );
+        static::addOptHtml($cmd);
         static::optsGeneric($cmd);
         $cmd->addArgument(
             'title',
@@ -40,13 +31,7 @@ class Command_Article extends Command_AbstractProps
         $req = new Request($this->cfg->host, $this->cfg);
         $req->setType('entry');
         $req->addProperty('name', $cmdRes->args['title']);
-        if ($cmdRes->options['html']) {
-            $req->addProperty(
-                'content', ['html' => $cmdRes->args['text']]
-            );
-        } else {
-            $req->addProperty('content', $cmdRes->args['text']);
-        }
+        $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
         $this->handleGenericOptions($cmdRes, $req);
 
         $res = $req->send();
index bdbe0f3fffc5a92c2a46dafc4f60b2623c18e458..0116cb51068c752c5e926140410ddc34e890d190 100644 (file)
@@ -6,6 +6,7 @@ class Command_Bookmark extends Command_AbstractProps
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('bookmark');
+        static::addOptHtml($cmd);
         static::optsGeneric($cmd);
         $cmd->addArgument(
             'url',
@@ -36,7 +37,7 @@ class Command_Bookmark extends Command_AbstractProps
         $req->addProperty('bookmark-of', $url);
 
         if ($cmdRes->args['text']) {
-            $req->addProperty('content', $cmdRes->args['text']);
+            $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
         }
 
 
index c7683f3b7a289f5052e571b2e3754b0ba6e77db7..1694243ef9cb3fa534900bffadb4b713d20c77c6 100644 (file)
@@ -6,6 +6,7 @@ class Command_Note extends Command_AbstractProps
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('note');
+        static::addOptHtml($cmd);
         static::optsGeneric($cmd);
         $cmd->addArgument(
             'text',
@@ -21,7 +22,7 @@ class Command_Note extends Command_AbstractProps
     {
         $req = new Request($this->cfg->host, $this->cfg);
         $req->setType('entry');
-        $req->addProperty('content', $cmdRes->args['text']);
+        $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
         $this->handleGenericOptions($cmdRes, $req);
 
         $res = $req->send();
index 6b3bc94cd336238cd2479af242b304b847804103..aa193e037c864de544e866097e2b6a4993e06194 100644 (file)
@@ -6,6 +6,7 @@ class Command_Reply extends Command_AbstractProps
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('reply');
+        static::addOptHtml($cmd);
         static::optsGeneric($cmd);
         $cmd->addArgument(
             'url',
@@ -18,7 +19,7 @@ class Command_Reply extends Command_AbstractProps
             'text',
             [
                 'optional'    => false,
-                'multiple'    => true,
+                'multiple'    => false,
                 'description' => 'Reply text',
             ]
         );
@@ -33,8 +34,8 @@ class Command_Reply extends Command_AbstractProps
 
         $req = new Request($this->cfg->host, $this->cfg);
         $req->setType('entry');
-        $req->addProperty('content', implode(' ', $cmdRes->args['text']));
         $req->addProperty('in-reply-to', $url);
+        $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
 
         $this->handleGenericOptions($cmdRes, $req);
         $res = $req->send();
index 69602d93ad3fd4affafbe09fdbf0140f8e5c0da0..4e67e9b1dbc3f8858adea5f1e7426f23ab78ed57 100644 (file)
@@ -9,6 +9,7 @@ class Command_Rsvp extends Command_AbstractProps
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('rsvp');
+        static::addOptHtml($cmd);
         static::optsGeneric($cmd);
         $cmd->addArgument(
             'url',
@@ -50,8 +51,8 @@ class Command_Rsvp extends Command_AbstractProps
         $req->setType('h', 'entry');
         $req->addProperty('in-reply-to', $url);
         $req->addProperty('rsvp', $rsvp);
-        if ($cmdRes->args['text'] != '') {
-            $req->addProperty('content', $cmdRes->args['text']);
+        if ($cmdRes->args['text']) {
+            $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
         }
         $this->handleGenericOptions($cmdRes, $req);
 
index 0cadc484c6d5391ddde586c107033ec3411e1562..544962b8e061c133467e4bd3312cf247559eefda 100644 (file)
@@ -122,6 +122,18 @@ class Request
         return $this->req->addUpload($fieldName, $filename);
     }
 
+    public function addContent($text, $isHtml)
+    {
+        if ($isHtml) {
+            $this->addProperty(
+                'content', ['html' => $text]
+            );
+        } else {
+            $this->addProperty('content', $text);
+        }
+
+    }
+
     /**
      * Adds a micropub property to the request.
      *