Add command to create custom types
authorChristian Weiske <cweiske@cweiske.de>
Wed, 1 Nov 2017 19:46:33 +0000 (20:46 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 1 Nov 2017 20:04:53 +0000 (21:04 +0100)
README.rst
src/shpub/Cli.php
src/shpub/Command/X.php [new file with mode: 0644]

index 8a5c087c83052616741e4446ec7db175cb04432f..410cdcbdb7a39dee2ac1bfbf064aa88898122bf0 100644 (file)
@@ -115,6 +115,23 @@ URL image upload::
     http://known.bogo/2016/img-url
 
 
+Custom post types
+=================
+You may create custom post types with the ``x`` command.
+This is useful if your micropub endpoint supports additional types,
+like known's ``annotation`` type (comments and likes for posts).
+
+Create a comment to a known post::
+
+    $ ./bin/shpub.php x annotation\
+        -x url=http://known.bogo/2016/example-domain-1\
+        -x type=reply\
+        -x username=barryf\
+        -x userurl=http://example.org/~barryf\
+        -x userphoto=http://example.org/~barryf/avatar.jpg\
+        -x content="There is a typo in paragraph 1. 'Fou' should be 'Foo'"
+
+
 ===============
 Delete/Undelete
 ===============
index 04ef97495ef98dcf59b0513e52ccf9ea279366f7..f1a625986eb1800e2456b47f009d507ae863bb11 100644 (file)
@@ -131,6 +131,7 @@ class Cli
         Command_Repost::opts($optParser);
         Command_Rsvp::opts($optParser);
         Command_Bookmark::opts($optParser);
+        Command_X::opts($optParser);
 
         Command_Delete::opts($optParser);
         Command_Undelete::opts($optParser);
diff --git a/src/shpub/Command/X.php b/src/shpub/Command/X.php
new file mode 100644 (file)
index 0000000..644a109
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+namespace shpub;
+
+/**
+ * Create a object with a custom type
+ *
+ * @author  Christian Weiske <cweiske@cweiske.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link    http://cweiske.de/shpub.htm
+ */
+class Command_X extends Command_AbstractProps
+{
+    public static function opts(\Console_CommandLine $optParser)
+    {
+        $cmd = $optParser->addCommand('x');
+        $cmd->description = 'Create a custom type';
+        static::addOptHtml($cmd);
+        static::optsGeneric($cmd);
+        $cmd->addArgument(
+            'type',
+            [
+                'optional'    => false,
+                'multiple'    => false,
+                'description' => 'Microformat object type',
+            ]
+        );
+    }
+
+    public function run(\Console_CommandLine_Result $cmdRes)
+    {
+        $req = new Request($this->cfg->host, $this->cfg);
+        $req->setType($cmdRes->args['type']);
+        $this->handleGenericOptions($cmdRes, $req);
+
+        $res = $req->send();
+        $postUrl = $res->getHeader('Location');
+        Log::info('Object created at server');
+        Log::msg($postUrl);
+    }
+}
+?>