| | |
| | | <?php |
| | | namespace JVBase\rest\routes; |
| | | |
| | | use JVBase\Instance; |
| | | use JVBase\managers\queue\Queue; |
| | | use JVBase\rest\PermissionHandler; |
| | | use JVBase\rest\Rest; |
| | | use JVBase\meta\Meta; |
| | |
| | | |
| | | class NewsRoutes extends Rest |
| | | { |
| | | use Instance; |
| | | protected int $per_page; |
| | | protected bool|object $manager = false; |
| | | public function __construct() |
| | |
| | | ->rateLimit(20) |
| | | ->post([$this, 'handleNewsOperation']) |
| | | ->args([ |
| | | 'user' => 'integer|required', |
| | | 'id' => 'string|required', |
| | | 'post_title' => 'string|required', |
| | | 'post_excerpt' => 'string', |
| | |
| | | */ |
| | | public function handleNewsOperation(WP_REST_Request $request):WP_REST_Response |
| | | { |
| | | $queue = JVB()->queue(); |
| | | $queue = Queue::getInstance(); |
| | | $data = $request->get_params(); |
| | | $user = absint($data['user']); |
| | | $user = get_current_user_id(); |
| | | $operationID = sanitize_text_field($data['id']); |
| | | |
| | | unset($data['user']); |
| | |
| | | public function getNews(WP_REST_Request $request):WP_REST_Response |
| | | { |
| | | $args = $this->buildQueryArgs($request); |
| | | $key = $this->cache->generateKey($args); |
| | | $cache = $this->cache->get($key); |
| | | |
| | | $cache = $this->cache->get($args); |
| | | if ($cache) { |
| | | return $this->success($cache); |
| | | } |
| | |
| | | 'total_pages' => $query->max_num_pages |
| | | ]; |
| | | |
| | | $this->cache->set($key, $results); |
| | | $this->cache->set($args, $results); |
| | | |
| | | return $this->success($results); |
| | | } |
| | |
| | | { |
| | | if (array_key_exists('orderby', $data) && $data['orderby'] === 'random') { |
| | | // Handle random ordering |
| | | $current_seed = jvbGetRandomSeed(); |
| | | $current_seed = floor(time() / 1800); |
| | | $args['orderby'] = 'RAND(' . $current_seed . ')'; |
| | | unset($args['order']); |
| | | } else { |
| | |
| | | $artist = jvbContentFromUser($post->post_author); |
| | | $upvotes = (int) get_post_meta($post->ID, BASE.'upvotes', true); |
| | | $downvotes = (int) get_post_meta($post->ID, BASE.'downvotes', true); |
| | | $comments = JVB()->routes('comments')->getItemResponse($post->ID, BASE.'news'); |
| | | $comments = ResponseRoutes::getInstance()->getItemResponse($post->ID, ['post_type' => BASE.'news']); |
| | | |
| | | return [ |
| | | 'id' => $post->ID, |
| | |
| | | $m = $meta->set($key, $value); |
| | | $result[$key] = $m; |
| | | } |
| | | $meta->save(); |
| | | } |
| | | |
| | | $this->cache->flush(); |