From e46ef107b205a7d38b83f38b71a3bb536274bb75 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 1 Nov 2017 20:46:33 +0100 Subject: [PATCH] Add command to create custom types --- README.rst | 17 +++++++++++++++++ src/shpub/Cli.php | 1 + src/shpub/Command/X.php | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/shpub/Command/X.php diff --git a/README.rst b/README.rst index 8a5c087..410cdcb 100644 --- a/README.rst +++ b/README.rst @@ -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 =============== diff --git a/src/shpub/Cli.php b/src/shpub/Cli.php index 04ef974..f1a6259 100644 --- a/src/shpub/Cli.php +++ b/src/shpub/Cli.php @@ -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 index 0000000..644a109 --- /dev/null +++ b/src/shpub/Command/X.php @@ -0,0 +1,41 @@ + + * @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); + } +} +?> -- 2.30.2