add support for articles (with HTML)
authorChristian Weiske <cweiske@cweiske.de>
Tue, 13 Sep 2016 15:16:48 +0000 (17:16 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 13 Sep 2016 15:16:48 +0000 (17:16 +0200)
src/shpub/Cli.php
src/shpub/Command/Article.php [new file with mode: 0644]

index 57ccee781a5856aedf4373afe97c027f2f681a99..eedbb10e37d916f4c68891bec497a4a3f4fddb29 100644 (file)
@@ -160,6 +160,7 @@ class Cli
             )
         );
 
             )
         );
 
+        Command_Article::opts($optParser);
         Command_Note::opts($optParser);
         Command_Reply::opts($optParser);
         Command_Like::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 (file)
index 0000000..b51740d
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+namespace shpub;
+
+class Command_Article extends Command_AbstractProps
+{
+    /**
+     * @var Config
+     */
+    protected $cfg;
+
+    public function __construct($cfg)
+    {
+        $this->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);
+    }
+}
+?>