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',
46 'long_name' => '--direct-upload',
47 'description' => 'Ignore media endpoint at file upload',
48 'action' => 'StoreTrue',
56 'long_name' => '--name',
57 'description' => 'Post title',
58 'help_name' => 'TITLE',
59 'action' => 'StoreString',
66 'long_name' => '--published',
67 'description' => 'Publish date',
68 'help_name' => 'DATE',
69 'action' => 'StoreString',
76 'long_name' => '--updated',
77 'description' => 'Update date',
78 'help_name' => 'DATE',
79 'action' => 'StoreString',
87 'long_name' => '--slug',
88 'description' => 'URL path',
89 'help_name' => 'PATH',
90 'action' => 'StoreString',
98 'long_name' => '--syndication',
99 'description' => 'Syndication URL(s)',
100 'help_name' => 'URL',
101 'action' => 'StoreArray',
108 'short_name' => '-x',
109 'long_name' => '--xprop',
110 'description' => 'Additional property',
111 'help_name' => 'key=value',
112 'action' => 'StoreArray',
116 static::addOptJson($cmd);
119 protected static function addOptHtml(\Console_CommandLine_Command $cmd)
124 'long_name' => '--html',
125 'description' => 'Text content is HTML',
126 'action' => 'StoreTrue',
132 protected static function addOptJson(\Console_CommandLine_Command $cmd)
137 'long_name' => '--json',
138 'description' => 'Send request data as JSON',
139 'action' => 'StoreTrue',
145 protected function handleGenericOptions(
146 \Console_CommandLine_Result $cmdRes, Request $req
148 $this->handleOptJson($cmdRes, $req);
150 if ($cmdRes->options['published'] !== null) {
152 'published', $cmdRes->options['published']
155 if ($cmdRes->options['updated'] !== null) {
157 'updated', $cmdRes->options['updated']
160 if (count($cmdRes->options['categories'])) {
162 'category', $cmdRes->options['categories']
165 if ($cmdRes->options['name'] !== null) {
167 'name', $cmdRes->options['name']
170 if ($cmdRes->options['slug'] !== null) {
172 'slug', $cmdRes->options['slug']
175 if (count($cmdRes->options['syndication'])) {
177 'syndication', $cmdRes->options['syndication']
181 $req->setDirectUpload($cmdRes->options['direct_upload']);
182 $this->handleFiles($cmdRes, $req);
184 if (count($cmdRes->options['x'])) {
186 foreach ($cmdRes->options['x'] as $xproperty) {
187 list($propkey, $propval) = explode('=', $xproperty, 2);
188 if (!isset($postParams[$propkey])) {
189 $postParams[$propkey] = [];
191 $postParams[$propkey][] = $propval;
193 foreach ($postParams as $propkey => $propvals) {
194 $req->addProperty($propkey, $propvals);
199 protected function handleOptJson(
200 \Console_CommandLine_Result $cmdRes, Request $req
202 $req->setSendAsJson($cmdRes->options['json']);
205 protected function handleFiles(
206 \Console_CommandLine_Result $cmdRes, Request $req
208 $files = $cmdRes->options['files'];
209 $fileList = $urlList = [
215 foreach ($files as $filePath) {
216 if (strpos($filePath, '://') !== false) {
218 $urlPath = parse_url($filePath, PHP_URL_PATH);
219 $mte = new \MIME_Type_Extension();
220 $mimetype = $mte->getMIMEType($urlPath);
221 $media = \MIME_Type::getMedia($mimetype);
222 if (!isset($urlList[$media])) {
223 Log::err('File type not allowed: ' . $mimetype);
226 $urlList[$media][] = $filePath;
227 } else if (file_exists($filePath)) {
229 $mimetype = \MIME_Type::autoDetect($filePath);
230 $media = \MIME_Type::getMedia($mimetype);
231 if (!isset($urlList[$media])) {
232 Log::err('File type not allowed: ' . $mimetype);
235 $fileList[$media][] = $filePath;
237 Log::err('File does not exist: ' . $filePath);
241 foreach ($urlList as $type => $urls) {
242 if ($type == 'image') {
245 if (count($urls) > 0) {
246 $req->addProperty($type, $urls);
249 foreach ($fileList as $type => $filePaths) {
250 if ($type == 'image') {
253 if (count($filePaths) > 0) {
254 $req->addUpload($type, $filePaths);