$res->command->options['force']
);
break;
+
+ case 'server':
+ $cmd = new Command_Server($this->cfg);
+ $cmd->run($res->command->options['verbose']);
+ break;
+
case 'like':
$this->requireValidHost();
$cmd = new Command_Like($this->cfg->host);
$cmd->run($res->command->args['url']);
break;
- case 'server':
- $cmd = new Command_Server($this->cfg);
- $cmd->run($res->command->options['verbose']);
+
+ case 'reply':
+ $this->requireValidHost();
+ $cmd = new Command_Reply($this->cfg->host);
+ $cmd->run(
+ $res->command->args['url'],
+ implode(' ', $res->command->args['text'])
+ );
break;
+
default:
var_dump($this->cfg->host, $res);
Log::err('FIXME');
'text',
[
'optional' => false,
+ 'multiple' => true,
'description' => 'Reply text',
]
);
]
);
- $req = new \HTTP_Request2($this->host->endpoints->micropub, 'POST');
- if (version_compare(PHP_VERSION, '5.6.0', '<')) {
- //correct ssl validation on php 5.5 is a pain, so disable
- $req->setConfig('ssl_verify_host', false);
- $req->setConfig('ssl_verify_peer', false);
- }
- $req->setHeader('Content-type', 'application/x-www-form-urlencoded');
- $req->setHeader('Authorization', 'Bearer ' . $this->host->token);
- $req->setBody($body);
- $res = $req->send();
- if (intval($res->getStatus() / 100) != 2) {
- Log::err(
- 'Server returned an error status code ' . $res->getStatus()
- );
- Log::err($res->getBody());
- exit(11);
- }
+ $req = new Request($this->host);
+ $res = $req->send($body);
$postUrl = $res->getHeader('Location');
echo "Like created at server\n";
echo $postUrl . "\n";
--- /dev/null
+<?php
+namespace shpub;
+
+class Command_Reply
+{
+ /**
+ * @var Config_Host
+ */
+ protected $host;
+
+ public function __construct($host)
+ {
+ $this->host = $host;
+ }
+
+ public function run($url, $text)
+ {
+ $url = Validator::url($url, 'url');
+ if ($url === false) {
+ exit(10);
+ }
+
+ $body = http_build_query(
+ [
+ 'h' => 'entry',
+ 'content' => $text,
+ 'in-reply-to' => $url,
+ ]
+ );
+
+ $req = new Request($this->host);
+ $res = $req->send($body);
+ $postUrl = $res->getHeader('Location');
+ echo "Reply created at server\n";
+ echo $postUrl . "\n";
+ }
+}
+?>
--- /dev/null
+<?php
+namespace shpub;
+
+class Request
+{
+ public $req;
+
+ public function __construct($host)
+ {
+ $this->req = new \HTTP_Request2($host->endpoints->micropub, 'POST');
+ if (version_compare(PHP_VERSION, '5.6.0', '<')) {
+ //correct ssl validation on php 5.5 is a pain, so disable
+ $this->req->setConfig('ssl_verify_host', false);
+ $this->req->setConfig('ssl_verify_peer', false);
+ }
+ $this->req->setHeader('Content-type', 'application/x-www-form-urlencoded');
+ $this->req->setHeader('Authorization', 'Bearer ' . $host->token);
+ }
+
+ public function send($body)
+ {
+ $this->req->setBody($body);
+ $res = $this->req->send();
+ if (intval($res->getStatus() / 100) != 2) {
+ Log::err(
+ 'Server returned an error status code ' . $res->getStatus()
+ );
+ Log::err($res->getBody());
+ exit(11);
+ }
+ return $res;
+ }
+}
\ No newline at end of file