11 public function __construct($cfg)
16 public static function opts(\Console_CommandLine $optParser)
18 $cmd = $optParser->addCommand('note');
23 'long_name' => '--files',
24 'description' => 'Files to upload',
25 'help_name' => 'PATH',
26 'action' => 'StoreArray',
33 'long_name' => '--published',
34 'description' => 'Publish date',
35 'help_name' => 'DATE',
36 'action' => 'StoreString',
45 'description' => 'Post text',
50 public function run($command)
52 $req = new Request($this->cfg->host, $this->cfg);
53 $req->req->addPostParameter('h', 'entry');
54 $req->req->addPostParameter('content', $command->args['text']);
55 if ($command->options['published'] !== null) {
56 $req->req->addPostParameter(
57 'published', $command->options['published']
61 $files = $command->options['files'];
68 foreach ($files as $filePath) {
69 if (file_exists($filePath)) {
71 $fileList[$type][] = $filePath;
72 } else if (strpos($filePath, '://') !== false) {
76 Log::err('File does not exist: ' . $filePath);
81 if (count($urls) == 1) {
82 $req->req->addPostParameter('photo', reset($urls));
85 foreach ($urls as $url) {
86 $req->req->addPostParameter(
87 'photo[' . $n++ . ']', reset($urls)
92 foreach ($fileList as $type => $filePaths) {
93 if (count($filePaths) == 1) {
94 $req->addUpload($type, reset($filePaths));
95 } else if (count($filePaths) > 0) {
96 $req->addUpload($type, $filePaths);
101 $postUrl = $res->getHeader('Location');
102 echo "Post created at server\n";
103 echo $postUrl . "\n";