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',
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',
68 'long_name' => '--slug',
69 'description' => 'URL path',
70 'help_name' => 'PATH',
71 'action' => 'StoreString',
79 'long_name' => '--syndication',
80 'description' => 'Syndication URL(s)',
82 'action' => 'StoreArray',
90 'long_name' => '--xprop',
91 'description' => 'Additional property',
92 'help_name' => 'key=value',
93 'action' => 'StoreArray',
99 protected function handleGenericOptions(
100 \Console_CommandLine_Result $cmdRes, Request $req
102 if ($cmdRes->options['published'] !== null) {
103 $req->req->addPostParameter(
104 'published', $cmdRes->options['published']
107 if (count($cmdRes->options['categories'])) {
108 $req->addPostParameter(
109 'category', $cmdRes->options['categories']
112 if ($cmdRes->options['name'] !== null) {
113 $req->req->addPostParameter(
114 'name', $cmdRes->options['name']
117 if ($cmdRes->options['slug'] !== null) {
118 $req->req->addPostParameter(
119 'slug', $cmdRes->options['slug']
122 if (count($cmdRes->options['syndication'])) {
123 $req->addPostParameter(
124 'syndication', $cmdRes->options['syndication']
128 $this->handleFiles($cmdRes, $req);
130 if (count($cmdRes->options['x'])) {
132 foreach ($cmdRes->options['x'] as $xproperty) {
133 list($propkey, $propval) = explode('=', $xproperty, 2);
134 if (!isset($postParams[$propkey] )) {
135 $postParams[$propkey] = [];
137 $postParams[$propkey][] = $propval;
139 foreach ($postParams as $propkey => $propvals) {
140 $req->addPostParameter($propkey, $propvals);
145 protected function handleFiles(
146 \Console_CommandLine_Result $cmdRes, Request $req
148 $files = $cmdRes->options['files'];
149 $fileList = $urlList = [
155 foreach ($files as $filePath) {
156 if (strpos($filePath, '://') !== false) {
158 $mte = new \MIME_Type_Extension();
159 $mimetype = $mte->getMIMEType($filePath);
160 $media = \MIME_Type::getMedia($mimetype);
161 if (!isset($urlList[$media])) {
162 Log::err('File type not allowed: ' . $mimetype);
165 $urlList[$media][] = $filePath;
166 } else if (file_exists($filePath)) {
168 $mimetype = \MIME_Type::autoDetect($filePath);
169 $media = \MIME_Type::getMedia($mimetype);
170 if (!isset($urlList[$media])) {
171 Log::err('File type not allowed: ' . $mimetype);
174 $fileList[$media][] = $filePath;
176 Log::err('File does not exist: ' . $filePath);
180 foreach ($urlList as $type => $urls) {
181 if ($type == 'image') {
184 if (count($urls) == 1) {
185 $req->req->addPostParameter($type, reset($urls));
186 } else if (count($urls) > 1) {
188 foreach ($urls as $url) {
189 $req->req->addPostParameter(
190 $type . '[' . $n++ . ']', $url
195 foreach ($fileList as $type => $filePaths) {
196 if ($type == 'image') {
199 if (count($filePaths) == 1) {
200 $req->addUpload($type, reset($filePaths));
201 } else if (count($filePaths) > 0) {
202 $req->addUpload($type, $filePaths);