# firebox/1.0.4/Inc/Core/Previewer.php

FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin &amp; Cart Abandonment, version 1.0.4. 195 lines.

- Page: https://pluginprobe.com/plugins/firebox/1.0.4/code/Inc/Core/Previewer.php
- Raw: https://pluginprobe.com/plugins/firebox/1.0.4/raw/Inc/Core/Previewer.php
- Modified: 2021-07-19T14:57:48+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/firebox/1.0.4/code/Inc/Core/Previewer.php#L10-L20`.

```php
<?php
/**
 * @package         FireBox
 * @version         1.0.4 Free
 * 
 * @author          FirePlugins <info@fireplugins.com>
 * @link            https://www.fireplugins.com
 * @copyright       Copyright © 2021 FirePlugins All Rights Reserved
 * @license         GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/

namespace FireBox\Core;

if (!defined('ABSPATH'))
{
	exit; // Exit if accessed directly.
}

use \FPFramework\Libs\Registry;

class Previewer {
	/**
	 * FireBox data.
	 *
	 * @var  array
	 */
	public $box_data;

    /**
     * Inits Previewer
     * 
     * @return  void
     */
    public function init()
    {
        if (!$this->is_preview_page())
        {
			return false;
		}

		$this->hooks();
		return true;
    }

	/**
	 * Check if current page request meets requirements for firebox preview page.
	 *
	 * @return  boolean
	 */
    public function is_preview_page()
    {
		// Only proceed if we have a item to preview
        if (empty($_GET['post_type']))
        {
			return false;
		}

        if ($_GET['post_type'] != 'firebox')
        {
			return false;
		}

        if (empty($_GET['p']))
        {
			return false;
		}

        if (empty($_GET['preview']))
        {
			return false;
		}

        if (!$_GET['preview'])
        {
			return false;
		}

		// Check for logged in user.
        if (!\is_user_logged_in())
        {
			return false;
		}

        if (!\current_user_can('manage_options'))
        {
			return false;
		}

		$box_id = \absint($_GET['p']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended

		if (!$this->box_data = firebox()->box->get($box_id))
		{
			return false;
		}

		return true;
	}

	/**
	 * Hooks
	 *
     * @return  void
	 */
	public function hooks()
	{
		firebox()->box->render($this->box_data);
		
		\add_filter('the_title', [$this, 'the_title'], 100, 1);

		\add_filter('the_content', [$this, 'the_content'], 999);

		\add_filter('get_the_excerpt', [$this, 'the_content'], 999);
	}

	public function the_content()
	{
		if (!isset($this->box_data->ID))
		{
			return '';
		}

		if (!current_user_can('manage_options'))
		{
			return '';
		}
		
		$links = [];

		$links[] = [
			'url'  => esc_url(
				add_query_arg(
					[
						'post'	 => absint($this->box_data->ID),
						'action' => 'edit',
					],
					admin_url('post.php')
				)
			),
			'text' => esc_html(firebox()->_('FB_EDIT_FIREBOX')),
		];

		$links[] = [
			'url'  => esc_url(
				add_query_arg(
					[
						'post_type' => 'firebox',
					],
					admin_url('edit.php')
				)
			),
			'text' => esc_html(firebox()->_('FB_VIEW_FIREBOX_ITEMS')),
		];

		$content  = '<div style="padding: 15px; background: #ededed;">';
		$content .= '<p>';
		$content .= esc_html(firebox()->_('FB_FIREBOX_PREVIEW_DESC'));
        if (!empty($links))
        {
			$content .= '<br>';
            foreach ($links as $key => $link)
            {
				$content .= '<a href="' . $link['url'] . '">' . $link['text'] . '</a>';
				$l        = array_keys($links);
                if (end($l) !== $key)
                {
					$content .= ' <span style="display:inline-block;margin:0 6px;opacity: 0.5">|</span> ';
				}
			}
		}
		$content .= '</p>';
		$content .= '</div>';
		
		return $content;
	}

	/**
	 * Customize firebox popup preview page title.
	 *
	 * @param   string  $title
	 *
	 * @return  string
	 */
    public function the_title($title)
    {
        if (in_the_loop())
        {
			$title = sprintf(
				esc_html('%s'),
				! empty($this->box_data->post_title) ? sanitize_text_field($this->box_data->post_title) . ' ' . firebox()->_('FB_PREVIEW') : esc_html(firebox()->_('FB_FIREBOX_POPUP_PREVIEW'))
			);
		}
		
		return $title;
	}
}
```
