<?php
/*
 * Plugin Name:       Xpose Content
 * Plugin URI:        https://xposecontent.com/
 * Description:       Xpose Content is a tool for managers who want to view and manage all the content of a site, blog or ecommerce project. Check the main metrics related to published content and export them to spreadsheets.
 * Version:           0.9.10
 * Author:            Leonardo de Souza
 * Author URI:        https://grunge.com.br/
 * License:           GPL v2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       xpose-content
 * Domain Path:       /languages
 */
 
/*
Xpose Content 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
any later version.

Xpose Content 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 Xpose Content. If not, see {URI to Plugin License}.
 */

// Admin Menu
add_action( 'admin_menu', 'xpose_content_menu_pages' );
function xpose_content_menu_pages(){
    add_menu_page(
	'Xpose Content', 
	'Xpose Content', 
	'manage_options', 
	'xc-dashboard', 
	'xpco_dashboard', 
	plugin_dir_url(__FILE__) . 'assets/images/xpose-content-icon.png', 
	2
	);
    add_submenu_page(
	'xc-dashboard', 
	'Dashboard', 
	'XC Dash', 
	'manage_options', 
	'xc-dashboard', 
	'xpco_dashboard'
	);
    add_submenu_page(
	'xc-dashboard', 
	'Posts', 
	'XC Posts', 
	'manage_options', 
	'xc-posts', 
	'xpco_posts'
	);
    add_submenu_page(
	'xc-dashboard', 
	'Pages', 
	'XC Pages', 
	'manage_options', 
	'xc-pages', 
	'xpco_pages'
	);
    add_submenu_page(
	'xc-dashboard', 
	'Products', 
	'XC Products', 
	'manage_options', 
	'xc-products', 
	'xpco_products'
	);
    add_submenu_page(
	'xc-dashboard', 
	'Custom', 
	'XC Custom', 
	'manage_options', 
	'xc-custom', 
	'xpco_custom'
	);
    add_submenu_page(
	null, 
	'Posts OnPage', 
	'XC Posts OnPage', 
	'manage_options', 
	'xc-posts-onpage', 
	'xpco_posts_onpage'
	);
    add_submenu_page(
	null, 
	'Pages OnPage', 
	'XC Pages OnPage', 
	'manage_options', 
	'xc-pages-onpage', 
	'xpco_pages_onpage'
	);
    add_submenu_page(
	null, 
	'Products OnPage', 
	'XC Products OnPage', 
	'manage_options', 
	'xc-products-onpage', 
	'xpco_products_onpage'
	);
    add_submenu_page(
	null, 
	'Custom OnPage', 
	'XC Custom OnPage', 
	'manage_options', 
	'xc-custom-posts-onpage', 
	'xpco_custom_posts_onpage'
	);
}

// Admin Submenu
add_action( 'admin_head', 'xpco_force_open_menu' );
function xpco_force_open_menu() {
    global $plugin_page, $submenu_file;
    $onpage_list = array(
        'xc-posts-onpage'        => 'xc-posts',
        'xc-pages-onpage'        => 'xc-pages',
        'xc-products-onpage'     => 'xc-products',
        'xc-custom-posts-onpage' => 'xc-custom',
    );
    if ( isset($_GET['page']) ) {
        $page = sanitize_key( wp_unslash( $_GET['page'] ) );
        if ( isset($onpage_list[$page]) ) {
            $plugin_page  = 'xc-dashboard';
            $submenu_file = $onpage_list[$page];
        }
    }
}

function xpco_dashboard(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-dash.php' );
}

function xpco_posts(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-posts.php' );
}

function xpco_posts_export(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-posts-export.php' );
}
add_action( 'init', 'xpco_posts_export' );

function xpco_posts_onpage(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-posts-onpage.php' );
}

function xpco_pages(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-pages.php' );
}

function xpco_pages_export(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-pages-export.php' );
}
add_action( 'init', 'xpco_pages_export' );

function xpco_pages_onpage(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-pages-onpage.php' );
}

function xpco_products(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-products.php' );
}

function xpco_products_export(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-products-export.php' );
}
add_action( 'init', 'xpco_products_export' );

function xpco_products_onpage(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-products-onpage.php' );
}

function xpco_custom(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-custom.php' );
}

function xpco_custom_export(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-custom-export.php' );
}
add_action( 'init', 'xpco_custom_export' );

function xpco_custom_posts_onpage(){
	require_once( plugin_dir_path( __FILE__ ) . 'views/xc-custom-posts-onpage.php' );
}

// Used Styles
function xpose_content_stylesheets(){
    $version = '0.9.10';
    wp_enqueue_style( 'xc-styles', plugins_url( '/assets/css/xc-styles.css', __FILE__ ), array(), $version );
    wp_enqueue_style( 'xc-all', plugins_url( '/assets/css/xc-all.css', __FILE__ ), array(), $version );
}
add_action( 'admin_print_styles', 'xpose_content_stylesheets' );

// Text Domain For Translations
function xpose_content_load_textdomain(){
	load_plugin_textdomain( 'xpose-content', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); 
}
add_action( 'init', 'xpose_content_load_textdomain' );

// Description Links
add_filter( 'plugin_row_meta', 'xpose_content_meta_links', 10, 2 );
function xpose_content_meta_links( $xc_links, $file ) {
    if ( plugin_basename(__FILE__) == $file ) {
        $xc_links[] = '<a href="' . esc_url( 'https://www.amazon.com.br/dp/B0FGFGL13X' ) . '" target="_blank">' . esc_html( 'Check my Book' ) . '</a>';
    }
    return $xc_links;
}
?>