| | |
| | | Route::for('content') |
| | | ->get([$this, 'getContent']) |
| | | ->auth(PermissionHandler::combine(['user', 'nonce', ['actionNonce'=>'dash-']])) |
| | | ->args([ |
| | | 'content' => 'string|required', |
| | | 'status' => 'string|default:all', |
| | | 'page' => 'integer|default:1|min:1', |
| | | 'per_page' => 'integer|default:30|min:1|max:100', |
| | | 'orderby' => 'string|enum:date,alphabetical|default:date', |
| | | 'order' => 'string|enum:asc,desc|default:desc', |
| | | 'search' => 'string', |
| | | 'date-filter' => 'string', |
| | | 'dateFrom' => 'string', |
| | | 'dateTo' => 'string', |
| | | ]) |
| | | ->rateLimit(20) |
| | | ->post([$this, 'postContent']) |
| | | ->auth(PermissionHandler::combine(['user', 'nonce', ['actionNonce'=>'dash-']])) |
| | | ->rateLimit(30); |
| | | ->rateLimit(30) |
| | | ->args([ |
| | | 'user' => 'int|required', |
| | | 'posts' => 'required', |
| | | 'content' => 'string', |
| | | ]) |
| | | ->register(); |
| | | } |
| | | |
| | | protected function initTimelineFields(string $content): void |
| | |
| | | return Response::success(['message'=>'No posts found in request']); |
| | | } |
| | | |
| | | |
| | | $count = count($data['posts']); |
| | | $operationId = $data['id']; |
| | | unset($data['user']); |
| | |
| | | return $this->formatTimeline($post); |
| | | } |
| | | $this->meta = Meta::forPost($post->ID); |
| | | $fields = ($fields) ? $this->meta->getAll() : []; |
| | | $data = [ |
| | | 'id' => $post->ID, |
| | | 'title' => $post->post_title, |
| | |
| | | 'alt' => get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true), |
| | | 'icon' => $this->post_type, |
| | | 'taxonomies' => [], |
| | | 'fields' => ($fields) ? $this->meta->getAll() : [], |
| | | 'fields' => $fields, |
| | | 'images' => [], |
| | | ]; |
| | | |
| | |
| | | $images = []; |
| | | $get = []; |
| | | $fields = (empty($fields)) ? $this->fields : $fields; |
| | | foreach ($fields as $field => $config) { |
| | | if ($config['type'] === 'gallery' || $config['type'] === 'image' || $field === 'post_thumbnail') { |
| | | $get[] = $field; |
| | | } |
| | | } |
| | | $get = $this->getUploadFields($fields); |
| | | |
| | | |
| | | if (!empty($get)) { |
| | | $allImages = $this->meta->getAll($get); |
| | | $actualGet = array_map(function($fieldName) { |
| | | return (str_contains($fieldName, ':')) ? strtok($fieldName, ':') : $fieldName; |
| | | }, $get); |
| | | $complex = array_map(function($item) { |
| | | return explode(':', $item); |
| | | },array_filter($get, function($fieldName) { |
| | | return str_contains($fieldName, ':'); |
| | | })); |
| | | |
| | | $allImages = $this->meta->getAll($actualGet); |
| | | foreach ($allImages as $k => $imgs) { |
| | | $temp = explode(',', $imgs); |
| | | foreach ($temp as $img) { |
| | | if (is_numeric($img) && !array_key_exists($img, $images)) { |
| | | $images[$img] = jvbImageData((int)$img); |
| | | //It's a complex field |
| | | if (is_array($imgs)) { |
| | | foreach ($imgs as $row) { |
| | | foreach ($row as $fName => $fValue) { |
| | | foreach ($complex as $c) { |
| | | if (in_array($k, $c)) { |
| | | foreach ($c as $complexField) { |
| | | if ($complexField === $fName) { |
| | | $images = $this->addImages($fValue, $images); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | $images = $this->addImages($imgs, $images); |
| | | } |
| | | } |
| | | } |
| | | return $images; |
| | | } |
| | | public function addImages(string $imgs, array $images):array |
| | | { |
| | | $temp = explode(',', $imgs); |
| | | foreach ($temp as $img) { |
| | | if (is_numeric($img) && !array_key_exists($img, $images)) { |
| | | $images[$img] = jvbImageData((int)$img); |
| | | } |
| | | } |
| | | return $images; |
| | | } |
| | | public function getUploadFields($fields):array |
| | | { |
| | | $get = []; |
| | | foreach ($fields as $field => $config) { |
| | | if (in_array($config['type'], ['group', 'repeater'])) { |
| | | $nestedUploads = $this->getUploadFields($config['fields']); |
| | | foreach ($nestedUploads as $nested) { |
| | | $get[] = $field.':'.$nested; |
| | | } |
| | | } elseif ($config['type'] === 'upload' || $config['type'] === 'gallery' || $config['type'] === 'image' ) { |
| | | $get[] = $field; |
| | | } |
| | | } |
| | | |
| | | return $get; |
| | | } |
| | | |
| | | public function formatTimeline(WP_Post $post): array |
| | | { |