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 c9ea8bb..b581f3c 100644 (file)
@@ -107,6 +107,20 @@ class Command_AbstractProps
         static::addOptJson($cmd);
     }
 
         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(
     protected static function addOptJson(\Console_CommandLine_Command $cmd)
     {
         $cmd->addOption(
index 8445af4..c657b2c 100644 (file)
@@ -6,16 +6,7 @@ class Command_Article extends Command_AbstractProps
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('article');
     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',
         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']);
         $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();
         $this->handleGenericOptions($cmdRes, $req);
 
         $res = $req->send();
index bdbe0f3..0116cb5 100644 (file)
@@ -6,6 +6,7 @@ class Command_Bookmark extends Command_AbstractProps
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('bookmark');
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('bookmark');
+        static::addOptHtml($cmd);
         static::optsGeneric($cmd);
         $cmd->addArgument(
             'url',
         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('bookmark-of', $url);
 
         if ($cmdRes->args['text']) {
-            $req->addProperty('content', $cmdRes->args['text']);
+            $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
         }
 
 
         }
 
 
index c7683f3..1694243 100644 (file)
@@ -6,6 +6,7 @@ class Command_Note extends Command_AbstractProps
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('note');
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('note');
+        static::addOptHtml($cmd);
         static::optsGeneric($cmd);
         $cmd->addArgument(
             'text',
         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 = 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();
         $this->handleGenericOptions($cmdRes, $req);
 
         $res = $req->send();
index 6b3bc94..aa193e0 100644 (file)
@@ -6,6 +6,7 @@ class Command_Reply extends Command_AbstractProps
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('reply');
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('reply');
+        static::addOptHtml($cmd);
         static::optsGeneric($cmd);
         $cmd->addArgument(
             'url',
         static::optsGeneric($cmd);
         $cmd->addArgument(
             'url',
@@ -18,7 +19,7 @@ class Command_Reply extends Command_AbstractProps
             'text',
             [
                 'optional'    => false,
             'text',
             [
                 'optional'    => false,
-                'multiple'    => true,
+                'multiple'    => false,
                 'description' => 'Reply text',
             ]
         );
                 '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 = new Request($this->cfg->host, $this->cfg);
         $req->setType('entry');
-        $req->addProperty('content', implode(' ', $cmdRes->args['text']));
         $req->addProperty('in-reply-to', $url);
         $req->addProperty('in-reply-to', $url);
+        $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
 
         $this->handleGenericOptions($cmdRes, $req);
         $res = $req->send();
 
         $this->handleGenericOptions($cmdRes, $req);
         $res = $req->send();
index 69602d9..4e67e9b 100644 (file)
@@ -9,6 +9,7 @@ class Command_Rsvp extends Command_AbstractProps
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('rsvp');
     public static function opts(\Console_CommandLine $optParser)
     {
         $cmd = $optParser->addCommand('rsvp');
+        static::addOptHtml($cmd);
         static::optsGeneric($cmd);
         $cmd->addArgument(
             'url',
         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);
         $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);
 
         }
         $this->handleGenericOptions($cmdRes, $req);
 
index 0cadc48..544962b 100644 (file)
@@ -122,6 +122,18 @@ class Request
         return $this->req->addUpload($fieldName, $filename);
     }
 
         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.
      *
     /**
      * Adds a micropub property to the request.
      *