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',
35 'description' => 'Post text',
40 public function run($command)
42 $req = new Request($this->cfg->host, $this->cfg);
43 $req->req->addPostParameter('h', 'entry');
44 $req->req->addPostParameter('content', $command->args['text']);
46 $files = $command->options['files'];
53 foreach ($files as $filePath) {
54 if (file_exists($filePath)) {
56 $fileList[$type][] = $filePath;
57 } else if (strpos($filePath, '://') !== false) {
61 Log::err('File does not exist: ' . $filePath);
66 if (count($urls) == 1) {
67 $req->req->addPostParameter('photo', reset($urls));
70 foreach ($urls as $url) {
71 $req->req->addPostParameter(
72 'photo[' . $n++ . ']', reset($urls)
77 foreach ($fileList as $type => $filePaths) {
78 if (count($filePaths) == 1) {
79 $req->addUpload($type, reset($filePaths));
80 } else if (count($filePaths) > 0) {
81 $req->addUpload($type, $filePaths);
86 $postUrl = $res->getHeader('Location');
87 echo "Post created at server\n";