From c40d4e6c6349b98c90e8bbb79b361e08e60c0dba Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 13 Sep 2016 17:16:48 +0200 Subject: [PATCH 1/1] add support for articles (with HTML) --- src/shpub/Cli.php | 1 + src/shpub/Command/Article.php | 68 +++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/shpub/Command/Article.php diff --git a/src/shpub/Cli.php b/src/shpub/Cli.php index 57ccee7..eedbb10 100644 --- a/src/shpub/Cli.php +++ b/src/shpub/Cli.php @@ -160,6 +160,7 @@ class Cli ) ); + Command_Article::opts($optParser); Command_Note::opts($optParser); Command_Reply::opts($optParser); Command_Like::opts($optParser); diff --git a/src/shpub/Command/Article.php b/src/shpub/Command/Article.php new file mode 100644 index 0000000..b51740d --- /dev/null +++ b/src/shpub/Command/Article.php @@ -0,0 +1,68 @@ +cfg = $cfg; + } + + 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::optsGeneric($cmd); + $cmd->addArgument( + 'title', + [ + 'optional' => false, + 'multiple' => false, + 'description' => 'Title/Name', + ] + ); + $cmd->addArgument( + 'text', + [ + 'optional' => false, + 'multiple' => false, + 'description' => 'Text content', + ] + ); + } + + public function run(\Console_CommandLine_Result $cmdRes) + { + $req = new Request($this->cfg->host, $this->cfg); + $req->req->addPostParameter('h', 'entry'); + $req->req->addPostParameter('name', $cmdRes->args['title']); + if ($cmdRes->options['html']) { + $req->req->addPostParameter( + 'content[html]', $cmdRes->args['text'] + ); + } else { + $req->req->addPostParameter('content', $cmdRes->args['text']); + } + $this->handleGenericOptions($cmdRes, $req); + + $res = $req->send(); + $postUrl = $res->getHeader('Location'); + Log::info('Article created at server'); + Log::msg($postUrl); + } +} +?> -- 2.30.2