From: Christian Weiske Date: Thu, 15 Sep 2016 20:44:52 +0000 (+0200) Subject: Support --html everywhere X-Git-Tag: v0.1.0~1 X-Git-Url: https://git.cweiske.de/shpub.git/commitdiff_plain/d5dbb7068eeeee3ae5e92cee77763c1e70e28c97?ds=sidebyside Support --html everywhere --- diff --git a/src/shpub/Command/AbstractProps.php b/src/shpub/Command/AbstractProps.php index c9ea8bb..b581f3c 100644 --- a/src/shpub/Command/AbstractProps.php +++ b/src/shpub/Command/AbstractProps.php @@ -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( diff --git a/src/shpub/Command/Article.php b/src/shpub/Command/Article.php index 8445af4..c657b2c 100644 --- a/src/shpub/Command/Article.php +++ b/src/shpub/Command/Article.php @@ -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(); diff --git a/src/shpub/Command/Bookmark.php b/src/shpub/Command/Bookmark.php index bdbe0f3..0116cb5 100644 --- a/src/shpub/Command/Bookmark.php +++ b/src/shpub/Command/Bookmark.php @@ -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']); } diff --git a/src/shpub/Command/Note.php b/src/shpub/Command/Note.php index c7683f3..1694243 100644 --- a/src/shpub/Command/Note.php +++ b/src/shpub/Command/Note.php @@ -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(); diff --git a/src/shpub/Command/Reply.php b/src/shpub/Command/Reply.php index 6b3bc94..aa193e0 100644 --- a/src/shpub/Command/Reply.php +++ b/src/shpub/Command/Reply.php @@ -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(); diff --git a/src/shpub/Command/Rsvp.php b/src/shpub/Command/Rsvp.php index 69602d9..4e67e9b 100644 --- a/src/shpub/Command/Rsvp.php +++ b/src/shpub/Command/Rsvp.php @@ -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); diff --git a/src/shpub/Request.php b/src/shpub/Request.php index 0cadc48..544962b 100644 --- a/src/shpub/Request.php +++ b/src/shpub/Request.php @@ -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. *