| | |
| | | use JVBase\managers\queue\executors\ContentExecutor; |
| | | use JVBase\managers\queue\TypeConfig; |
| | | use JVBase\meta\Meta; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\rest\PermissionHandler; |
| | | use JVBase\rest\Response; |
| | | use JVBase\rest\Rest; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\rest\Route; |
| | | use JVBase\utility\Features; |
| | | use WP_Post; |
| | | use WP_Query; |
| | | use WP_Error; |
| | | use WP_REST_Request; |
| | | use WP_REST_Response; |
| | | use Exception; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; // Exit if accessed directly |
| | |
| | | protected function initTimelineFields(string $content): void |
| | | { |
| | | $content = jvbNoBase($content); |
| | | if (!Features::forContent($content)->has('is_timeline')) { |
| | | |
| | | $config = Registrar::getInstance($content); |
| | | if (!$config || !$config->hasFeature('is_timeline')) { |
| | | return; |
| | | } |
| | | $config = Features::getConfig($content); |
| | | $this->fields = $config['fields']; |
| | | $this->fields = $config->getFields(); |
| | | |
| | | $this->timelineSharedFields = $this->getTimelineSharedFields($content); |
| | | array_unshift($this->timelineSharedFields, 'post_thumbnail'); |
| | |
| | | public function getTimelineUniqueFields(string $content): array |
| | | { |
| | | $content = jvbNoBase($content); |
| | | if (!Features::forContent($content)->has('is_timeline')) { |
| | | $registrar = Registrar::getInstance($content); |
| | | if (!$registrar || !$registrar->hasFeature('is_timeline')) { |
| | | return []; |
| | | } |
| | | $config = Features::getConfig($content); |
| | | $allFields = $config['fields']; |
| | | |
| | | $allFields = $registrar->getFields(); |
| | | |
| | | return array_keys(array_filter($allFields, function ($field) { |
| | | if (array_key_exists('for_all', $field) && $field['for_all'] === true) { |
| | |
| | | public function getTimelineSharedFields(string $content): array |
| | | { |
| | | $content = jvbNoBase($content); |
| | | if (!Features::forContent($content)->has('is_timeline')) { |
| | | $registrar = Registrar::getInstance($content); |
| | | if (!$registrar || !$registrar->hasFeature('is_timeline')) { |
| | | return []; |
| | | } |
| | | $config = Features::getConfig($content); |
| | | if (!$config || empty($config)) { |
| | | return []; |
| | | } |
| | | $allFields = $config['fields'] ?? []; |
| | | |
| | | $allFields = $registrar->getFields()??[]; |
| | | |
| | | return array_keys(array_filter($allFields, function ($field) { |
| | | if (!array_key_exists('for_all', $field) || $field['for_all'] === false) { |
| | |
| | | public function getContent(WP_REST_Request $request): WP_REST_Response |
| | | { |
| | | $params = $request->get_params(); |
| | | error_log('getContent params: '.print_r($params, true)); |
| | | $user_id = $params['user']; |
| | | |
| | | $post_status = $params['status']; |
| | |
| | | 'post_status' => $post_status |
| | | ]; |
| | | //Only top level posts for timeline types |
| | | if (Features::forContent($post_type)->has('is_timeline')) { |
| | | $registrar = Registrar::getInstance($post_type); |
| | | |
| | | if ($registrar && $registrar->hasFeature('is_timeline')) { |
| | | $args['post_parent'] = 0; |
| | | } |
| | | |
| | | //Calendar filters |
| | | if (Features::forContent($post_type)->has('is_calendar')) { |
| | | if ($registrar && $registrar->hasFeature('is_calendar')) { |
| | | $args = $this->applyCalendarFilters($args, $params); |
| | | } |
| | | $taxonomies = array_filter($params, function ($param) { |
| | |
| | | $query = new WP_Query($args); |
| | | |
| | | |
| | | $this->fields = jvbGetFields(str_replace('-', '_', $this->post_type)); |
| | | $this->fields = Registrar::getFieldsFor(str_replace('-', '_', $this->post_type)); |
| | | $this->taxonomies = $this->getTaxonomies($this->post_type); |
| | | $posts = array_map([$this, 'prepareItem'], $query->posts); |
| | | |
| | |
| | | */ |
| | | protected function getTaxonomies(string $content): array |
| | | { |
| | | $taxonomy_for = jvbGlobalTaxonomyFor(); |
| | | $out = []; |
| | | foreach ($taxonomy_for as $tax => $postTypes) { |
| | | if (in_array($content, $postTypes)) { |
| | | $out[BASE . $tax] = [ |
| | | 'label' => JVB_CONTENT[$content]['plural'], |
| | | 'icon' => $tax, |
| | | ]; |
| | | } |
| | | $registrar = Registrar::getInstance($content); |
| | | if (!$registrar) { |
| | | return []; |
| | | } |
| | | $out = []; |
| | | foreach ($registrar->registrar->taxonomies as $tax) { |
| | | $taxReg = Registrar::getInstance($tax); |
| | | $out[jvbCheckBase($tax)] = [ |
| | | 'label' => $taxReg->getPlural(), |
| | | 'icon' => $taxReg->getIcon()??jvbDefaultIcon() |
| | | ]; |
| | | } |
| | | |
| | | return $out; |
| | | } |
| | | |
| | |
| | | */ |
| | | protected function prepareItem(WP_Post $post, bool $skip = false, bool $fields = true): array |
| | | { |
| | | if (!$skip && Features::forContent($post->post_type)->has('is_timeline')) { |
| | | $registrar = Registrar::getInstance($post->post_type); |
| | | if (!$skip && $registrar && $registrar->hasFeature('is_timeline')) { |
| | | $this->initTimelineFields($post->post_type); |
| | | return $this->formatTimeline($post); |
| | | } |