<?php
 
 /**
 * =============================================================================
 *
 * @package         Blue Raven (Free Version)
 * @Plugin URI      https://enterrahost.com/plugins/blue-raven
 * 
 * @Author          EnterraHost
 * @Author URI      https://enterrahost.com
 * @License         GPL-2.0-or-later
 *  
 * @Copyright       (c) 2025 EnterraHost
 * @Contents        Contents for the about page, includes news, updates and change log data
 *
 * =============================================================================
 * 
 * || INDEX:
 * ||   - BLUE RAVEN ABOUT PAGE
 * || 
 * =============================================================================
 */

if ( ! defined( 'ABSPATH' ) ) exit; 

/*
============================================================
    BLUE RAVEN ABOUT PAGE
============================================================
*/
class Blue_Raven_Admin_About {
    
    /**
     * The plugin URL.
     *
     * @since 1.0.0
     * @var string
     */
    private $plugin_url;
    
    /**
     * The plugin path.
     *
     * @since 1.0.0
     * @var string
     */
    private $plugin_path;
    
    /**
     * Class constructor.
     *
     * Initializes the plugin URL and path properties.
     *
     * @since 1.0.0
     */
    public function __construct() {
        $this->plugin_url = BLUERAVEN_PLUGIN_URL;
        $this->plugin_path = BLUERAVEN_PLUGIN_DIR;
    }
    
    /**
     * Render the about page.
     *
     * Static method to create an instance and display the about page content.
     *
     * @since 1.0.0
     * @static
     */
    public static function render() {
        $instance = new self();
        $instance->about();
    }
    
    /**
     * Display the about page content.
     *
     * Outputs the HTML for the Blue Raven about page including version information,
     * features, changelog, and support resources.
     *
     * @since 1.0.0
     * @access private
     */
    private function about() {


        define('BLUE_RAVEN_PLUGIN_URL', BLUERAVEN_PLUGIN_URL);
        wp_enqueue_style(
            'blue-raven-fontawesome',
            BLUE_RAVEN_PLUGIN_URL . 'assets/css/all.min.css',
            [],
            '7.0.0'
        );

        ?>
        <div style='margin: 2rem auto 2rem 6vw;'>
            <h1><?php esc_html_e('ABOUT BLUE RAVEN', 'blue-raven'); ?></h1>
        </div>
        
        <div class='parent-container'>
            <div id='tools-sub-container' style='width:90%; padding: 20px;'>
                <h2 class="spacing-right text-center">
                    <?php 
                        esc_html_e( 'Welcome to Blue Raven - ', 'blue-raven' );

                        if ( ! function_exists( 'get_plugin_data' ) ) require_once trailingslashit( ABSPATH ) . 'wp-admin/includes/plugin.php';

                        $plugin_root_path = plugin_dir_path( dirname( __FILE__ ) );
                        $main_plugin_file = $plugin_root_path . 'blue-raven.php';

                        if ( file_exists( $main_plugin_file ) ) {
                            $plugin_data = get_plugin_data( $main_plugin_file );
                            echo '<span style="font-size: 0.6em; vertical-align: middle; color: #9ad6ff;">'
							. sprintf(
								/* translators: %s: Plugin version number */
								esc_html__( 'Version %s', 'blue-raven' ),
								esc_html( $plugin_data['Version'] )
							)
							. '</span>';
                        }
                    ?>
                </h2>
                <p><?php esc_html_e('Thanks for installing Blue Raven! Our all-in-one assistant for optimising WooCommerce product content, metadata, SEO and much more. Blue Raven is built by the team at Enterrahost, and it\'s part of a growing suite of smart WordPress tools built to make your online store faster, better, and easier to manage.', 'blue-raven'); ?></p>
    
                <h3 class="spacing-right text-center" style='margin-top: 5rem; padding-top: 5rem ; margin-top: 5rem;border-top: white solid 11px;'><?php esc_html_e('About Enterrahost', 'blue-raven'); ?></h3>
                <p><?php esc_html_e('At Enterrahost, we build powerful yet approachable tools that empower WordPress site owners and eCommerce entrepreneurs. Whether you\'re running a side hustle or scaling a serious online store, our plugins are designed with clarity, performance, and results in mind.', 'blue-raven'); ?></p>
                <p><a class="enterra-href" href="<?php echo esc_url('https://enterrahost.com'); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e('Visit enterrahost.com', 'blue-raven'); ?></a></p>
    
                <h3 class="spacing-right text-center" style='margin-top: 5rem;'><?php esc_html_e('About Blue Raven', 'blue-raven'); ?></h3>
                <p><?php esc_html_e('Blue Raven helps you:', 'blue-raven'); ?></p>
                <ul>
                    <li><?php esc_html_e('Generate product titles, descriptions, meta tags, and pricing suggestions using AI.', 'blue-raven'); ?></li>
                    <li><?php esc_html_e('Refine and lock content for better SEO and conversion performance.', 'blue-raven'); ?></li>
                    <li><?php esc_html_e('Track content improvements over time.', 'blue-raven'); ?></li>
                    <li><?php esc_html_e('Optimise your entire store with smart automation and manual controls.', 'blue-raven'); ?></li>
                </ul>
                <p><?php esc_html_e('We\'re constantly improving Blue Raven, so if you have any suggestions or feature requests please let us know, Blue Raven is growing fast, and we want your voice to shape what comes next.', 'blue-raven'); ?></p>
                <ul>
                    <li><?php 
                        echo sprintf(
							/* translators: %s is replaced with the plugin version number */
                            esc_html__('We would love to hear from you! %s', 'blue-raven'),
                            '<a class="enterra-href" href="' . esc_url('https://portal.enterrahost.com/submitticket.php?step=2&deptid=9') . '" target="_blank" rel="noopener noreferrer">' . esc_html__('Submit a Feature Request', 'blue-raven') . '</a>'
                        );
                    ?></li>
                </ul>     
                
                <h3 class="spacing-right text-center" style='margin-top: 5rem;'><?php esc_html_e('What\'s Coming Next in Blue Raven', 'blue-raven'); ?></h3>
                <p><?php esc_html_e('We\'re working on a suite of new tools, including:', 'blue-raven'); ?></p>
                <br>
                <ul>
                    <li><?php esc_html_e('Merchant Feeds', 'blue-raven'); ?></li>
                    <li><?php esc_html_e('WooCommerce Mail customizer', 'blue-raven'); ?></li>
                    <li><?php esc_html_e('Abandoned Cart', 'blue-raven'); ?></li>
                    <li><?php esc_html_e('On Page SEO checks and scoring', 'blue-raven'); ?></li>
                </ul>
    
                <h3 class="spacing-right text-center" style='margin-top: 5rem;'><?php esc_html_e('Plugin & Feature Updates', 'blue-raven'); ?></h3>
                <p><?php esc_html_e('You can check out our latest News and Announcements regarding updates and feature rollouts from the News Feed below :', 'blue-raven'); ?></p>
                <div class="rss-feed-container">
                    <?php
                    
    ## =========== Include the required file for the feed functions =========== ##      
                        
                    include_once trailingslashit( ABSPATH . WPINC ) . 'feed.php';
                    
    ## =========== Get the RSS feed =========== ##    
                        
                    $rss = fetch_feed('https://portal.enterrahost.com/announcements/rss');
                    
                    if (!is_wp_error($rss)) {
                        
    ## =========== Figure out how many total items there are =========== ##
                        
                        $maxitems = $rss->get_item_quantity(5); 
                        
    ## =========== Build an array of all the items =========== ##   
    
                        $rss_items = $rss->get_items(0, $maxitems);
                        
                        if ($maxitems > 0) {
						echo '<ul>';
						foreach ($rss_items as $item) {
							$posted_title = sprintf(
								// translators: %s is replaced with the post date.
								esc_attr__('Posted %s', 'blue-raven'),
								esc_html($item->get_date('j F Y | g:i a'))
							);

							echo '<li>';
							echo '<strong><a class="enterra-href" href="' . esc_url($item->get_permalink()) . '" 
								  target="_blank" rel="noopener noreferrer" title="' . esc_attr($posted_title) . '">';
							echo ' - ' . esc_html($item->get_title());
							echo '</a> - </strong>';
							echo '</li>';
						}
                            echo '</ul> ';
                        } else {
                            echo '<p>' . esc_html__('No news items available at this time.', 'blue-raven') . '</p>';
                        }
                    } else {
                        echo '<p>' . esc_html__('Unable to fetch news feed. Please try again later.', 'blue-raven') . '</p>';
                    }
                    ?>
                </div>
    
                <h3 class="spacing-right text-center" style='margin-top: 5rem;'><?php esc_html_e('Support & Resources', 'blue-raven'); ?></h3>
                <p><strong><?php esc_html_e('Need help?', 'blue-raven'); ?></strong> <?php 
                    echo sprintf(
						/* translators: %s is replaced with the plugin version number */
                        esc_html__('Start with our %s — it\'s full of helpful guides and tips.', 'blue-raven'),
                        '<a class="enterra-href" href="' . esc_url('https://portal.enterrahost.com/knowledgebase') . '" target="_blank" rel="noopener noreferrer">' . esc_html__('Knowledge Base', 'blue-raven') . '</a>'
                    );
                ?></p>
                <p><strong><?php esc_html_e('Subscribers', 'blue-raven'); ?></strong>: <?php esc_html_e('You can open support tickets directly via your Enterrahost Portal.', 'blue-raven'); ?></p>
                <p><strong><?php esc_html_e('Free Users', 'blue-raven'); ?></strong>: <?php esc_html_e('Please check the KB first — but we\'d still love your feedback!', 'blue-raven'); ?></p>
                <br>
                <h3 class="changelog-heading" style='padding-top: 5rem;margin-top: 5rem;border-top: white solid 11px;'><?php esc_html_e('Blue Raven Change Log', 'blue-raven'); ?></h3>
                <div class="blue-raven-changelog-container">
                    <?php
                    include_once trailingslashit( ABSPATH . WPINC ) . 'feed.php';
                    
                    $rss = fetch_feed('https://portal.enterrahost.com/modules/addons/changelogmanager/rss.php?plugin=Blue+Raven');
                    
                    if (!is_wp_error($rss)) {
                        $rss->set_cache_duration(3600);
                        $rss_items = $rss->get_items(0, 5);
                    
                        if (!empty($rss_items)) {
                            echo '<div class="blue-raven-changelog">';
                            foreach ($rss_items as $item) {
                                $title = esc_html($item->get_title());
                                $content = $item->get_content();
                                $date = $item->get_date('F j, Y');
                    
                                $content = html_entity_decode($content, ENT_QUOTES | ENT_XML1, 'UTF-8');
                                $content = html_entity_decode($content, ENT_QUOTES | ENT_XML1, 'UTF-8');
                                $content = wp_kses_post($content);
                    
                                echo '<div class="changelog-entry">';
                                echo '<h4 class="version-title">' . esc_html($title) . '</h4>';
                                echo '<div class="version-date">' . esc_html($date) . '</div>';
                                echo '<div class="version-content">' . wp_kses_post($content) . '</div>';
                                echo '</div>';
                            }
                            echo '</div>';
                        } else {
                            echo '<p class="no-entries">' . esc_html__('No changelog entries found.', 'blue-raven') . '</p>';
                        }
                    } else {
                        echo '<p class="changelog-error">' . sprintf(
							/* translators: %s is replaced with the plugin version number */
                            esc_html__('Could not load changelog: %s', 'blue-raven'),
                            esc_html($rss->get_error_message())
                        ) . '</p>';
                    }
                    ?>
                </div>
                <br>
                <h4 class="spacing-right text-center"><strong><?php esc_html_e('Other Places to Find Us:', 'blue-raven'); ?></strong></h4>
                <ul>
                    <li class="social-list-item">
                        <div class="social-icons" style="display: inline-flex; gap: 12px; align-items: center; margin-left: 8px;">
                            <?php
                           	wp_enqueue_style(
								'font-awesome',
								BLUERAVEN_PLUGIN_URL . 'assets/css/font-awesome.min.css',
								array(),
								'6.5.0'
							);
                            ?>
                            <a href="<?php echo esc_url('https://youtube.com/@enterrahost'); ?>" target="_blank" rel="noopener noreferrer">
                              <i class="fa-brands fa-youtube" style="color: #ffffff;"></i>
                            </a>
                            <a href="<?php echo esc_url('https://tiktok.com/@enterrahost'); ?>" target="_blank" rel="noopener noreferrer">
                              <i class="fa-brands fa-tiktok" style="color: #ffffff;"></i>
                            </a>
                            <a href="<?php echo esc_url('https://facebook.com/enterrahost'); ?>" target="_blank" rel="noopener noreferrer">
                              <i class="fa-brands fa-facebook-f" style="color: #ffffff;"></i>
                            </a>
                            <a href="<?php echo esc_url('https://instagram.com/enterrahost'); ?>" target="_blank" rel="noopener noreferrer">
                              <i class="fa-brands fa-instagram" style="color: #ffffff;"></i>
                            </a>
                            <a href="<?php echo esc_url('https://x.com/enterrahost'); ?>" target="_blank" rel="noopener noreferrer">
                              <i class="fa-brands fa-x-twitter" style="color: #ffffff;"></i>
                            </a>
                            <a href="<?php echo esc_url('https://github.com/enterrahost'); ?>" target="_blank" rel="noopener noreferrer">
                              <i class="fa-brands fa-github" style="color: #ffffff;"></i>
                            </a>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
        <?php
    }
}