| | |
| | | 'dateFrom' => 'string', |
| | | 'dateTo' => 'string', |
| | | 'context' => 'string', |
| | | 'source' => 'string', |
| | | 'contextId' => 'string', |
| | | 'favourites' => 'boolean', |
| | | 'user' => 'integer', |
| | | 'highlight' => 'string', |
| | |
| | | 'dateFrom' => 'string', |
| | | 'dateTo' => 'string', |
| | | 'context' => 'string', |
| | | 'source' => 'string', |
| | | 'contextId' => 'string', |
| | | 'favourites' => 'boolean', |
| | | 'user' => 'integer', |
| | | 'highlight' => 'string', |
| | |
| | | $meta = Meta::forUser($postID); |
| | | $registrar = Registrar::getInstance($type); |
| | | break; |
| | | default: |
| | | $meta = false; |
| | | } |
| | | if (!$registrar) { |
| | | if (!$registrar || !$meta) { |
| | | return []; |
| | | } |
| | | $fields = $registrar->getFields(); |
| | | [$images, $fields] = $registrar->getFeedFields(); |
| | | |
| | | //Allow custom filtering for public fields |
| | | if (!empty($registrar->getConfig('feed')['fields'])) { |
| | | $fields = array_filter($fields, function($field) use ($registrar) { |
| | | return in_array($field, $registrar->getConfig('feed')['fields']); |
| | | }, ARRAY_FILTER_USE_KEY); |
| | | } |
| | | |
| | | $values = $meta->getAll(array_keys($fields)); |
| | | |
| | | $all = array_merge($images, $fields); |
| | | $values = $meta->getAll(array_map(function($f) { return $f['name']; }, $all)); |
| | | $out = [ |
| | | 'fields' => $values, |
| | | ]; |
| | |
| | | |
| | | //Add images |
| | | $imgIDs = []; |
| | | $temp = array_filter($fields, function($field) { |
| | | return in_array($field['type'], [ 'upload', 'image', 'gallery']); |
| | | }); |
| | | |
| | | foreach ($temp as $key => $config) { |
| | | if (array_key_exists($key, $out['fields']) && $out['fields'][$key] !== '') { |
| | | $IDs = array_map('absint', explode(',',$out['fields'][$key])); |
| | | foreach ($IDs as $ID) { |
| | | $imgIDs[$ID] = jvbImageData($ID); |
| | | } |
| | | $imgs = $meta->getAll(array_map(function($f) {return $f['name'];}, $images)); |
| | | foreach ($imgs as $img) { |
| | | $IDs = array_map('absint', explode(',',$img)); |
| | | foreach ($IDs as $ID) { |
| | | $imgIDs[$ID] = jvbImageData($ID); |
| | | } |
| | | } |
| | | $out['images'] = $imgIDs; |
| | | |
| | | $out['id'] = $postID; |
| | | $out['content'] = $type; |
| | | $out['icon'] = $registrar->getIcon()??jvbDefaultIcon(); |
| | | $out['icon'] = $registrar->getIcon(); |
| | | if ($out['icon'] === '') { |
| | | $out['icon'] = jvbDefaultIcon(); |
| | | } |
| | |
| | | $out['title'] = html_entity_decode($post->name); |
| | | break; |
| | | case 'post': |
| | | $out['date'] = $post->post_date; |
| | | $out['modified'] = $post->post_modified; |
| | | $out['user_id'] = (int)$post->post_author; |
| | | $out['url'] = get_the_permalink($postID); |
| | | $out['title']= get_the_title($postID); |
| | |
| | | |
| | | protected function formatTimeline(int $postID, WP_Post $post):array |
| | | { |
| | | if (!$this->timelineSharedFields || !$this->timelineUniqueFields){ |
| | | $this->initTimelineFields($post->post_type); |
| | | } |
| | | $item = $this->formatItem($postID, 'post', true); |
| | | //Step 1: Get the fields that apply to all posts |
| | | $mainMeta = Meta::forPost($post->ID); |
| | | $item['fields'] = $mainMeta->getAll($this->timelineSharedFields); |
| | | $item = $this->formatItem($postID, 'post', true); |
| | | |
| | | //Step 2: Get the fields for each individual posts |
| | | $children = get_children(['post_parent' => $post->ID, 'orderby' => 'date', 'order' => 'ASC', 'post_status' => ['publish'], 'fields'=> 'ids']); |
| | | array_unshift($children, $post->ID); |
| | | $children = jvbTimelinePoints($postID, $post->post_type); |
| | | $last = $children[array_key_last($children)]; |
| | | $lastMeta = Meta::forPost($last); |
| | | $lastImg = $lastMeta->get('post_thumbnail'); |
| | | |
| | | $item['taxonomies'] = $this->extractTaxonomies($item['fields'], $postID, jvbNoBase($post->post_type)); |
| | | $item['fields']['after'] = $lastImg; |
| | | $item['images'][$lastImg] = jvbImageData((int) $lastImg); |
| | | $item['fields']['post_modified'] = $lastMeta->get('post_date'); |
| | | |
| | | $subFields = []; |
| | | $images = []; |
| | | foreach ($children as $child) { |
| | | $meta = Meta::forPost($child); |
| | | $f = $meta->getAll($this->timelineUniqueFields); |
| | | $f = ['id' => $child] + $f; |
| | | $subFields[] = $f; |
| | | $item['taxonomies'] = array_merge($item['taxonomies'], $this->extractTaxonomies($f, $postID, jvbNoBase($post->post_type))); |
| | | $images[$f['post_thumbnail']] = jvbImageData((int) $f['post_thumbnail']); |
| | | $count = count(array_filter($children, function ($child) { |
| | | $tmp = Meta::forPost($child); |
| | | return empty($tmp->get('is_update')) || $tmp->get('is_update') !==1; |
| | | })); |
| | | |
| | | foreach($item['taxonomies'] as $tax => $items) { |
| | | $item[$tax] = array_keys($items); |
| | | } |
| | | $item['number'] = (int)get_post_meta($post->ID,BASE.'number', true); |
| | | $item['fields']['before'] = get_post_thumbnail_id($children[0]); |
| | | $item['fields']['after'] = get_post_thumbnail_id($children[array_key_last($children)]); |
| | | |
| | | $item['fields']['timeline'] = $subFields; |
| | | $item['images'] = $item['images'] + $images; |
| | | |
| | | $item['number'] = $count; |
| | | $item['fields']['before'] = $item['fields']['post_thumbnail']; |
| | | |
| | | return $item; |
| | | } |
| | |
| | | protected function getAuthorData(WP_Post $post) |
| | | { |
| | | $author = $post->post_author; |
| | | $userLink = get_user_meta($author, BASE.'link', true); |
| | | $userLink = get_user_meta($author, BASE.'profile_link', true); |
| | | return $this->cache->remember( |
| | | $userLink, |
| | | function () use ($userLink, $author) { |
| | |
| | | $args = $this->applyContextFilters( |
| | | $args, |
| | | [ |
| | | 'id' => $data['source']??'0', |
| | | 'id' => $data['contextId']??'0', |
| | | 'type' => $data['context'] |
| | | ] |
| | | ); |
| | |
| | | : explode(',', $args['post_type']); |
| | | |
| | | // Check if filtering global feed content |
| | | if (in_array(jvbNoBase($context['type']), Registrar::getFeatured('is_content', 'term'))) { |
| | | if (in_array(jvbNoBase($context['type']), Registrar::withFeature('is_content', 'term'))) { |
| | | // Global: show posts from any content type with this taxonomy |
| | | $for_content = Registrar::getInstance($context['type'])->registrar->for ?? []; |
| | | |
| | |
| | | $post_types = array_map(fn($type) => jvbCheckBase($type), $for_content); |
| | | |
| | | // Filter to only show_feed content types |
| | | $show_feed_types = Registrar::getFeatured('show_feed', 'post'); |
| | | $show_feed_types = Registrar::withFeature('show_feed', 'post'); |
| | | $args['post_type'] = array_intersect( |
| | | $post_types, |
| | | array_map(fn($type) => jvbCheckBase($type), $show_feed_types) |
| | |
| | | |
| | | // Add term to tax query |
| | | $args['tax_query'][] = [ |
| | | 'taxonomy' => jvbCheckBase($context['type']), |
| | | 'field' => 'term_id', |
| | | 'taxonomy' => $registrar->getBased(), |
| | | // 'field' => 'term_id', |
| | | 'terms' => [(int)$context['id']], |
| | | ]; |
| | | break; |
| | | case $registrar->getType() === 'term': |
| | | // Add term to tax query |
| | | $args['tax_query'][] = [ |
| | | 'taxonomy' => $registrar->getBased(), |
| | | 'terms' => [(int)$context['id']], |
| | | ]; |
| | | break; |
| | |
| | | |
| | | protected function handleContentTaxonomies(array $args): array |
| | | { |
| | | |
| | | //TODO: This needs to be better. We have CustomTable now, maybe pass it along to that? |
| | | $taxonomy = jvbNoBase($args['post_type']); |
| | | global $wpdb; |
| | | $table = $wpdb->prefix . BASE . 'content_' . $taxonomy; |
| | |
| | | $config = []; |
| | | |
| | | // Get content types with show_feed |
| | | $contentTypes = Registrar::getFeatured('show_feed', 'post'); |
| | | $contentTypes = Registrar::withFeature('show_feed', 'post'); |
| | | foreach ($contentTypes as $slug) { |
| | | $this->cache->tag('content:'.$slug); |
| | | $registrar = Registrar::getInstance($slug); |
| | |
| | | } |
| | | |
| | | // Get taxonomies with show_feed (content taxonomies) |
| | | $taxonomies = Registrar::getFeatured('show_feed', 'term'); |
| | | $taxonomies = Registrar::withFeature('show_feed', 'term'); |
| | | foreach ($taxonomies as $slug) { |
| | | $registrar = Registrar::getInstance($slug); |
| | | if (!$registrar || !($registrar->hasFeature('is_content') ?? false)) { |