From ba1e1ccf869b818f7a7a897264dfea05563a7796 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 07 Jun 2026 20:10:20 +0000
Subject: [PATCH] =Major overhaul of Integrations. Playing around with adding fields to post types through Registrar from an integrations' class file.
---
inc/rest/routes/FeedRoutes.php | 110 ++++++++++++++++++++++++------------------------------
1 files changed, 49 insertions(+), 61 deletions(-)
diff --git a/inc/rest/routes/FeedRoutes.php b/inc/rest/routes/FeedRoutes.php
index f1b6bb2..f4e0ab1 100644
--- a/inc/rest/routes/FeedRoutes.php
+++ b/inc/rest/routes/FeedRoutes.php
@@ -6,7 +6,7 @@
use JVBase\rest\Rest;
use JVBase\integrations\Umami;
use JVBase\rest\Route;
-use JVBase\utility\Features;
+use JVBase\base\Site;
use WP_Query;
use WP_Post;
use WP_Term;
@@ -44,7 +44,7 @@
public function init():void
{
- if (Features::hasIntegration('umami')) {
+ if (Site::hasIntegration('umami')) {
$this->tracker = JVB()->connect('umami');
}
}
@@ -68,7 +68,7 @@
'dateFrom' => 'string',
'dateTo' => 'string',
'context' => 'string',
- 'source' => 'string',
+ 'contextId' => 'string',
'favourites' => 'boolean',
'user' => 'integer',
'highlight' => 'string',
@@ -87,7 +87,7 @@
'dateFrom' => 'string',
'dateTo' => 'string',
'context' => 'string',
- 'source' => 'string',
+ 'contextId' => 'string',
'favourites' => 'boolean',
'user' => 'integer',
'highlight' => 'string',
@@ -149,21 +149,16 @@
$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,
];
@@ -173,23 +168,18 @@
//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();
}
@@ -212,8 +202,6 @@
$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);
@@ -253,37 +241,30 @@
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;
}
@@ -338,7 +319,7 @@
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) {
@@ -410,7 +391,7 @@
$args = $this->applyContextFilters(
$args,
[
- 'id' => $data['source']??'0',
+ 'id' => $data['contextId']??'0',
'type' => $data['context']
]
);
@@ -520,7 +501,7 @@
: 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 ?? [];
@@ -528,7 +509,7 @@
$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)
@@ -537,8 +518,15 @@
// 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;
@@ -622,7 +610,7 @@
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;
@@ -1159,7 +1147,7 @@
$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);
@@ -1175,7 +1163,7 @@
}
// 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)) {
--
Gitblit v1.10.0