5 * Abstract command class that handles generic properties
7 class Command_AbstractProps
14 public function __construct($cfg)
19 public static function optsGeneric(\Console_CommandLine_Command $cmd)
25 'long_name' => '--category',
26 'description' => 'Category names',
28 'action' => 'StoreArray',
36 'long_name' => '--file',
37 'description' => 'Files or URLs to upload',
38 'help_name' => 'PATH',
39 'action' => 'StoreArray',
47 'long_name' => '--name',
48 'description' => 'Post title',
49 'help_name' => 'TITLE',
50 'action' => 'StoreString',
57 'long_name' => '--published',
58 'description' => 'Publish date',
59 'help_name' => 'DATE',
60 'action' => 'StoreString',
67 'long_name' => '--updated',
68 'description' => 'Update date',
69 'help_name' => 'DATE',
70 'action' => 'StoreString',
78 'long_name' => '--slug',
79 'description' => 'URL path',
80 'help_name' => 'PATH',
81 'action' => 'StoreString',
89 'long_name' => '--syndication',
90 'description' => 'Syndication URL(s)',
92 'action' => 'StoreArray',
100 'long_name' => '--xprop',
101 'description' => 'Additional property',
102 'help_name' => 'key=value',
103 'action' => 'StoreArray',
109 protected function handleGenericOptions(
110 \Console_CommandLine_Result $cmdRes, Request $req
112 if ($cmdRes->options['published'] !== null) {
113 $req->req->addPostParameter(
114 'published', $cmdRes->options['published']
117 if ($cmdRes->options['updated'] !== null) {
118 $req->req->addPostParameter(
119 'updated', $cmdRes->options['updated']
122 if (count($cmdRes->options['categories'])) {
123 $req->addPostParameter(
124 'category', $cmdRes->options['categories']
127 if ($cmdRes->options['name'] !== null) {
128 $req->req->addPostParameter(
129 'name', $cmdRes->options['name']
132 if ($cmdRes->options['slug'] !== null) {
133 $req->req->addPostParameter(
134 'slug', $cmdRes->options['slug']
137 if (count($cmdRes->options['syndication'])) {
138 $req->addPostParameter(
139 'syndication', $cmdRes->options['syndication']
143 $this->handleFiles($cmdRes, $req);
145 if (count($cmdRes->options['x'])) {
147 foreach ($cmdRes->options['x'] as $xproperty) {
148 list($propkey, $propval) = explode('=', $xproperty, 2);
149 if (!isset($postParams[$propkey] )) {
150 $postParams[$propkey] = [];
152 $postParams[$propkey][] = $propval;
154 foreach ($postParams as $propkey => $propvals) {
155 $req->addPostParameter($propkey, $propvals);
160 protected function handleFiles(
161 \Console_CommandLine_Result $cmdRes, Request $req
163 $files = $cmdRes->options['files'];
164 $fileList = $urlList = [
170 foreach ($files as $filePath) {
171 if (strpos($filePath, '://') !== false) {
173 $mte = new \MIME_Type_Extension();
174 $mimetype = $mte->getMIMEType($filePath);
175 $media = \MIME_Type::getMedia($mimetype);
176 if (!isset($urlList[$media])) {
177 Log::err('File type not allowed: ' . $mimetype);
180 $urlList[$media][] = $filePath;
181 } else if (file_exists($filePath)) {
183 $mimetype = \MIME_Type::autoDetect($filePath);
184 $media = \MIME_Type::getMedia($mimetype);
185 if (!isset($urlList[$media])) {
186 Log::err('File type not allowed: ' . $mimetype);
189 $fileList[$media][] = $filePath;
191 Log::err('File does not exist: ' . $filePath);
195 foreach ($urlList as $type => $urls) {
196 if ($type == 'image') {
199 if (count($urls) == 1) {
200 $req->req->addPostParameter($type, reset($urls));
201 } else if (count($urls) > 1) {
203 foreach ($urls as $url) {
204 $req->req->addPostParameter(
205 $type . '[' . $n++ . ']', $url
210 foreach ($fileList as $type => $filePaths) {
211 if ($type == 'image') {
214 if (count($filePaths) == 1) {
215 $req->addUpload($type, reset($filePaths));
216 } else if (count($filePaths) > 0) {
217 $req->addUpload($type, $filePaths);