Determine URL file type from path, strip query parameters first
[shpub.git] / src / shpub / Command / Reply.php
1 <?php
2 namespace shpub;
3
4 class Command_Reply extends Command_AbstractProps
5 {
6     public static function opts(\Console_CommandLine $optParser)
7     {
8         $cmd = $optParser->addCommand('reply');
9         $cmd->description = 'Create a reply';
10         static::addOptHtml($cmd);
11         static::optsGeneric($cmd);
12         $cmd->addArgument(
13             'url',
14             [
15                 'optional'    => false,
16                 'description' => 'URL that is replied to',
17             ]
18         );
19         $cmd->addArgument(
20             'text',
21             [
22                 'optional'    => false,
23                 'multiple'    => false,
24                 'description' => 'Reply text',
25             ]
26         );
27     }
28
29     public function run(\Console_CommandLine_Result $cmdRes)
30     {
31         $url = Validator::url($cmdRes->args['url'], 'url');
32         if ($url === false) {
33             exit(10);
34         }
35
36         $req = new Request($this->cfg->host, $this->cfg);
37         $req->setType('entry');
38         $req->addProperty('in-reply-to', $url);
39         $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
40
41         $this->handleGenericOptions($cmdRes, $req);
42         $res = $req->send();
43
44         $postUrl = $res->getHeader('Location');
45         Log::info('Reply created at server');
46         Log::msg($postUrl);
47     }
48 }
49 ?>