| | |
| | | $this->cache_name = 'feed'; |
| | | $this->cache_ttl = 86400; |
| | | parent::__construct(); |
| | | $this->cache->clear(); |
| | | } |
| | | |
| | | public function init():void |
| | | { |
| | | $this->cache->clear(); |
| | | $this->checker = Checker::getInstance(); |
| | | |
| | | if (jvbSiteUsesUmami()) { |
| | | $this->tracker = JVB()->connect('umami'); |
| | | } |
| | | |
| | | $this->cache->clear(); |
| | | $this->setupCacheConnections(); |
| | | } |
| | | |
| | |
| | | if (!$post || is_wp_error($post)) { |
| | | return []; |
| | | } |
| | | |
| | | return $cache->remember($postID, |
| | | function() use ($postID, $type, $metaType, $post, $skip) { |
| | | // |
| | | // return $cache->remember($postID, |
| | | // function() use ($postID, $type, $metaType, $post, $skip) { |
| | | $config = null; |
| | | switch ($metaType) { |
| | | case 'post': |
| | |
| | | return $field['type'] === 'taxonomy'; |
| | | }); |
| | | foreach ($temp as $key => $config) { |
| | | if (array_key_exists($key, $out) && $out[$key] !== '') { |
| | | $IDs = array_map('absint', explode(',', $out[$key])); |
| | | if (array_key_exists($key, $out['fields']) && $out['fields'][$key] !== '') { |
| | | $IDs = array_map('absint', explode(',', $out['fields'][$key])); |
| | | $data = []; |
| | | $icon = JVB_TAXONOMY[$config['taxonomy']]['icon']??'triangle'; |
| | | $icon = JVB_TAXONOMY[$config['taxonomy']]['icon']??jvbDefaultIcon(); |
| | | foreach ($IDs as $ID) { |
| | | $term = get_term($ID, jvbCheckBase($config['taxonomy'])); |
| | | if ($term && !is_wp_error($term)) { |
| | |
| | | $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) && $out[$key] !== '') { |
| | | $IDs = array_map('absint', explode(',',$out[$key])); |
| | | 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); |
| | | } |
| | |
| | | |
| | | $out['id'] = $postID; |
| | | $out['content'] = $type; |
| | | $out['icon'] = $config['icon']??'triangle'; |
| | | $out['icon'] = $config['icon']??jvbDefaultIcon(); |
| | | |
| | | if ($this->tracker) { |
| | | $args = ($metaType === 'post') ? ['owner_id' => $post->post_author] : []; |
| | |
| | | $out['url'] = get_the_permalink($postID); |
| | | break; |
| | | } |
| | | return $out; |
| | | } |
| | | ); |
| | | |
| | | // return $out; |
| | | // } |
| | | // ); |
| | | return $out; |
| | | } |
| | | |
| | | |
| | | |
| | | protected function initTimelineFields(string $content):void |
| | | { |
| | | $content = jvbNoBase($content); |
| | |
| | | |
| | | $images[$f['post_thumbnail']] = jvbImageData((int) $f['post_thumbnail']); |
| | | } |
| | | $item['fields']['order'] = $subFields; |
| | | $item['fields']['timeline'] = $subFields; |
| | | $item['images'] = $item['images'] + $images; |
| | | |
| | | return $item; |
| | |
| | | protected function buildRequestArgs(WP_REST_Request $request): array |
| | | { |
| | | $data = $request->get_params(); |
| | | error_log('Feed Request: ' . print_r($data, true)); |
| | | $args = [ |
| | | 'post_type' => (array_key_exists($data['content'], $this->buildFeedTypesConfig())) ? |
| | | BASE . $data['content'] : |
| | |
| | | $args = $this->applyDateFilters($args, $data); |
| | | |
| | | $args = $this->applyFavouritesFilter($args, $data); |
| | | error_log('Final Args: '.print_r($args, true)); |
| | | return $args; |
| | | } |
| | | |
| | |
| | | // Fetch and format items |
| | | $items = $this->fetchFeedItems($args); |
| | | |
| | | error_log('Feed Got items: ' .print_r($items, true)); |
| | | |
| | | |
| | | $ttl = (str_contains($args['orderby'], 'RAND')) ? 1800 : $this->cache_ttl; |
| | | $this->cache->set($key, $items, $ttl); |
| | | |
| | |
| | | */ |
| | | protected function processHighlightedItem(array $items, array $data): array |
| | | { |
| | | error_log('Data passed to processHighlightedItem:' . print_r($data, true)); |
| | | if (empty($data['highlight'] ?? null)) { |
| | | return $items; |
| | | } |
| | |
| | | if (!array_key_exists('favourites', $filters)) { |
| | | return $args; |
| | | } |
| | | error_log('Proceeding to check for favourites:'); |
| | | global $wpdb; |
| | | |
| | | // Get post types for the current filter |
| | |
| | | |
| | | $favourites_table = $wpdb->prefix . BASE . 'favourites'; |
| | | $placeholders = implode(',', array_fill(0, count($post_types), '%s')); |
| | | error_log('CurrentUser ID: ' . print_r(get_current_user_id(), true)); |
| | | $favourited_ids = $wpdb->get_col($wpdb->prepare( |
| | | "SELECT target_id FROM {$favourites_table} |
| | | WHERE user_id = %d AND type IN ($placeholders)", |