5 * Abstract command class that handles generic properties
7 class Command_AbstractProps
9 public static function optsGeneric(\Console_CommandLine_Command $cmd)
15 'long_name' => '--category',
16 'description' => 'Category names',
18 'action' => 'StoreArray',
26 'long_name' => '--files',
27 'description' => 'Files or URLs to upload',
28 'help_name' => 'PATH',
29 'action' => 'StoreArray',
36 'long_name' => '--published',
37 'description' => 'Publish date',
38 'help_name' => 'DATE',
39 'action' => 'StoreString',
47 'long_name' => '--syndication',
48 'description' => 'Syndication URL(s)',
50 'action' => 'StoreArray',
58 'long_name' => '--xprop',
59 'description' => 'Additional property',
60 'help_name' => 'key=value',
61 'action' => 'StoreArray',
67 protected function handleGenericOptions(
68 \Console_CommandLine_Result $cmdRes, Request $req
70 if ($cmdRes->options['published'] !== null) {
71 $req->req->addPostParameter(
72 'published', $cmdRes->options['published']
75 if (count($cmdRes->options['categories'])) {
76 $req->addPostParameter(
77 'category', $cmdRes->options['categories']
80 if (count($cmdRes->options['syndication'])) {
81 $req->addPostParameter(
82 'syndication', $cmdRes->options['syndication']
86 $this->handleFiles($cmdRes, $req);
88 if (count($cmdRes->options['x'])) {
90 foreach ($cmdRes->options['x'] as $xproperty) {
91 list($propkey, $propval) = explode('=', $xproperty, 2);
92 if (!isset($postParams[$propkey] )) {
93 $postParams[$propkey] = [];
95 $postParams[$propkey][] = $propval;
97 foreach ($postParams as $propkey => $propvals) {
98 $req->addPostParameter($propkey, $propvals);
103 protected function handleFiles(
104 \Console_CommandLine_Result $cmdRes, Request $req
106 $files = $cmdRes->options['files'];
107 $fileList = $urlList = [
113 foreach ($files as $filePath) {
114 if (strpos($filePath, '://') !== false) {
116 $mte = new \MIME_Type_Extension();
117 $mimetype = $mte->getMIMEType($filePath);
118 $media = \MIME_Type::getMedia($mimetype);
119 if (!isset($urlList[$media])) {
120 Log::err('File type not allowed: ' . $mimetype);
123 $urlList[$media][] = $filePath;
124 } else if (file_exists($filePath)) {
126 $mimetype = \MIME_Type::autoDetect($filePath);
127 $media = \MIME_Type::getMedia($mimetype);
128 if (!isset($urlList[$media])) {
129 Log::err('File type not allowed: ' . $mimetype);
132 $fileList[$media][] = $filePath;
134 Log::err('File does not exist: ' . $filePath);
138 foreach ($urlList as $type => $urls) {
139 if ($type == 'image') {
142 if (count($urls) == 1) {
143 $req->req->addPostParameter($type, reset($urls));
144 } else if (count($urls) > 1) {
146 foreach ($urls as $url) {
147 $req->req->addPostParameter(
148 $type . '[' . $n++ . ']', $url
153 foreach ($fileList as $type => $filePaths) {
154 if ($type == 'image') {
157 if (count($filePaths) == 1) {
158 $req->addUpload($type, reset($filePaths));
159 } else if (count($filePaths) > 0) {
160 $req->addUpload($type, $filePaths);