<?php

/********************************************************************
 * Copyright (C) 2025 Hassine RIANI (https://upvimeo.com)
 *
 * This file is part of Upvimeo
 *
 * Upvimeo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * Upvimeo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Upvimeo. If not, see <https://www.gnu.org/licenses/>.
 **********************************************************************/

/**
 * Class UpVimeo_Post_Types
 *
 * Responsible for registering the post types used by the pluyin.
 *
 * @license GPLv2
 * @copyright Hassine RIANI (https://upvimeo.com)
 * @since 1.0.0
 */
class UpVimeo_Post_Types
{
    /**
     * Register the required post types
     */
    public function init()
    {
        $this->register_vimeo_uplaods();
    }

    /**
     * Register the Vimeo Uploads post type
     */
    public function register_vimeo_uplaods()
    {

        $settings = new UpVimeo_Settings_Helper();

        $labels = array(
            'name' => _x('Vimeo Uploads', 'Post Type General Name', 'upvimeo-direct-uploads'),
            'singular_name' => _x('Vimeo Uploads', 'Post Type Singular Name', 'upvimeo-direct-uploads'),
            'menu_name' => __('Vimeo Uploads', 'upvimeo-direct-uploads'),
            'name_admin_bar' => __('Vimeo Upload', 'upvimeo-direct-uploads'),
            'archives' => __('Item Archives', 'upvimeo-direct-uploads'),
            'attributes' => __('Item Attributes', 'upvimeo-direct-uploads'),
            'parent_item_colon' => __('Parent Item:', 'upvimeo-direct-uploads'),
            'all_items' => __('All Items', 'upvimeo-direct-uploads'),
            'add_new_item' => __('Add New Item', 'upvimeo-direct-uploads'),
            'add_new' => __('Add New', 'upvimeo-direct-uploads'),
            'new_item' => __('New Item', 'upvimeo-direct-uploads'),
            'edit_item' => __('Edit Item', 'upvimeo-direct-uploads'),
            'update_item' => __('Update Item', 'upvimeo-direct-uploads'),
            'view_item' => __('View Item', 'upvimeo-direct-uploads'),
            'view_items' => __('View Items', 'upvimeo-direct-uploads'),
            'search_items' => __('Search Item', 'upvimeo-direct-uploads'),
            'not_found' => __('Not found', 'upvimeo-direct-uploads'),
            'not_found_in_trash' => __('Not found in Trash', 'upvimeo-direct-uploads'),
            'featured_image' => __('Featured Image', 'upvimeo-direct-uploads'),
            'set_featured_image' => __('Set featured image', 'upvimeo-direct-uploads'),
            'remove_featured_image' => __('Remove featured image', 'upvimeo-direct-uploads'),
            'use_featured_image' => __('Use as featured image', 'upvimeo-direct-uploads'),
            'insert_into_item' => __('Insert into item', 'upvimeo-direct-uploads'),
            'uploaded_to_this_item' => __('Uploaded to this item', 'upvimeo-direct-uploads'),
            'items_list' => __('Items list', 'upvimeo-direct-uploads'),
            'items_list_navigation' => __('Items list navigation', 'upvimeo-direct-uploads'),
            'filter_items_list' => __('Filter items list', 'upvimeo-direct-uploads'),
        );
        $args = array(
            'label' => __('Vimeo Uploads', 'upvimeo-direct-uploads'),
            'description' => __('WP Vimeo Uploads', 'upvimeo-direct-uploads'),
            'labels' => $labels,
            'supports' => array('title', 'editor', 'thumbnail'),
            'hierarchical' => false,
            'public' => true,
            'show_ui' => false,
            'show_in_menu' => false,
            'menu_position' => 5,
            'show_in_admin_bar' => false,
            'show_in_nav_menus' => true,
            'can_export' => true,
            'has_archive' => false,
            'exclude_from_search' => false,
            'publicly_queryable' => ((bool) $settings->get('UPVIMEO_enable_single_pages')) ? true : false,
            'rewrite' => true,
            'capability_type' => 'page',
        );

        $post_slug = apply_filters('UPVIMEO_post_type_slug', 'vimeo-upload');
        if (!empty($post_slug)) {
            $args['rewrite'] = array(
                'slug' => $post_slug,
                'with_front' => true,
                'pages' => true,
                'feeds' => false,
            );
        }

        $args = apply_filters('UPVIMEO_post_type_args', $args);

        register_post_type(UpVimeo_Db_Helper::POST_TYPE_UPLOADS, $args);
    }
}
