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' => '--files',
37 'description' => 'Files or URLs to upload',
38 'help_name' => 'PATH',
39 'action' => 'StoreArray',
46 'long_name' => '--published',
47 'description' => 'Publish date',
48 'help_name' => 'DATE',
49 'action' => 'StoreString',
57 'long_name' => '--slug',
58 'description' => 'URL path',
59 'help_name' => 'PATH',
60 'action' => 'StoreString',
68 'long_name' => '--syndication',
69 'description' => 'Syndication URL(s)',
71 'action' => 'StoreArray',
79 'long_name' => '--xprop',
80 'description' => 'Additional property',
81 'help_name' => 'key=value',
82 'action' => 'StoreArray',
88 protected function handleGenericOptions(
89 \Console_CommandLine_Result $cmdRes, Request $req
91 if ($cmdRes->options['published'] !== null) {
92 $req->req->addPostParameter(
93 'published', $cmdRes->options['published']
96 if (count($cmdRes->options['categories'])) {
97 $req->addPostParameter(
98 'category', $cmdRes->options['categories']
101 if ($cmdRes->options['slug'] !== null) {
102 $req->req->addPostParameter(
103 'slug', $cmdRes->options['slug']
106 if (count($cmdRes->options['syndication'])) {
107 $req->addPostParameter(
108 'syndication', $cmdRes->options['syndication']
112 $this->handleFiles($cmdRes, $req);
114 if (count($cmdRes->options['x'])) {
116 foreach ($cmdRes->options['x'] as $xproperty) {
117 list($propkey, $propval) = explode('=', $xproperty, 2);
118 if (!isset($postParams[$propkey] )) {
119 $postParams[$propkey] = [];
121 $postParams[$propkey][] = $propval;
123 foreach ($postParams as $propkey => $propvals) {
124 $req->addPostParameter($propkey, $propvals);
129 protected function handleFiles(
130 \Console_CommandLine_Result $cmdRes, Request $req
132 $files = $cmdRes->options['files'];
133 $fileList = $urlList = [
139 foreach ($files as $filePath) {
140 if (strpos($filePath, '://') !== false) {
142 $mte = new \MIME_Type_Extension();
143 $mimetype = $mte->getMIMEType($filePath);
144 $media = \MIME_Type::getMedia($mimetype);
145 if (!isset($urlList[$media])) {
146 Log::err('File type not allowed: ' . $mimetype);
149 $urlList[$media][] = $filePath;
150 } else if (file_exists($filePath)) {
152 $mimetype = \MIME_Type::autoDetect($filePath);
153 $media = \MIME_Type::getMedia($mimetype);
154 if (!isset($urlList[$media])) {
155 Log::err('File type not allowed: ' . $mimetype);
158 $fileList[$media][] = $filePath;
160 Log::err('File does not exist: ' . $filePath);
164 foreach ($urlList as $type => $urls) {
165 if ($type == 'image') {
168 if (count($urls) == 1) {
169 $req->req->addPostParameter($type, reset($urls));
170 } else if (count($urls) > 1) {
172 foreach ($urls as $url) {
173 $req->req->addPostParameter(
174 $type . '[' . $n++ . ']', $url
179 foreach ($fileList as $type => $filePaths) {
180 if ($type == 'image') {
183 if (count($filePaths) == 1) {
184 $req->addUpload($type, reset($filePaths));
185 } else if (count($filePaths) > 0) {
186 $req->addUpload($type, $filePaths);