# firebox/1.0.4/Inc/Core/Admin/Includes/Library.php

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

- Page: https://pluginprobe.com/plugins/firebox/1.0.4/code/Inc/Core/Admin/Includes/Library.php
- Raw: https://pluginprobe.com/plugins/firebox/1.0.4/raw/Inc/Core/Admin/Includes/Library.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/Admin/Includes/Library.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\Admin\Includes;

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

use \FPFramework\Admin\Library\Library as FrameworkLibrary;

class Library extends FrameworkLibrary
{
	/**
	 * The Modal ID.
	 * 
	 * @var  String
	 */
	protected $modal_id = 'fbSelectTemplate';

	/**
	 * Library categories.
	 * 
	 * @var  array
	 */
	protected $categories = [
		'all' => 'FPF_ALL',
		'popup' => 'FB_POPUP',
		'fullscreen' => 'FB_FULLSCREEN',
		'slidein' => 'FB_SLIDEIN',
		'floatingbar' => 'FB_FLOATING_BAR',
		'sidebar' => 'FB_SIDEBAR',
		'specials' => 'FB_SPECIALS'
	];

	/**
	 * The library settings
	 * 
	 * @var   array
	 */
	protected $library_settings;

	public function __construct()
	{
		$this->setup();

		add_action('current_screen', [$this, 'validate']);

		// set default post title
		add_filter('default_title', [$this, 'presetPostTitle'], 10, 2);

		// set default post content
		add_filter('default_content', [$this, 'presetPostContent']);
	}

	/**
	 * Plugin library settings
	 * 
	 * @return  void
	 */
	private function setup()
	{
		$this->library_settings = [
			'id' => $this->modal_id,
			'title' => 'FB_LIBRARY',
			'support_request_label' => 'FB_REQUEST_POPUP',
			'categories' => $this->categories,
			'plugin_dir' => FBOX_PLUGIN_DIR,
			'plugin' => 'firebox',
			'plugin_name' => firebox()->_('PLUGIN_NAME'),
			'blank_template_label' => 'FB_BLANK_POPUP',
			'blank_template_desc' => 'FPF_START_FROM_SCRATCH',
			'noresults_create_from_scratch_label' => 'FB_CREATE_FROM_SCRATCH',
			'template_use_url' => 'post-new.php?post_type=firebox&template=',
			'license_type' => FBOX_LICENSE_TYPE == 'pro' ? 'pro' : 'free'
		];

		$this->setupAjax();
	}

	/**
	 * Set the default post title if we have selected a template via the Library
	 * 
	 * @param   string  $post_title
	 * @param   object  $post
	 * 
	 * @return  string
	 */
	public function presetPostTitle($post_title, $post)
	{
		$template = isset($_GET['template']) ? sanitize_text_field($_GET['template']) : '';

		if ($template == 'blank')
		{
			return;
		}

		$box = \FireBox\Core\Helpers\BoxHelper::getBoxFromTemplate();

		if (empty($box))
		{
			return $post_title;
		}

		return $box->post_title;
	}

	/**
	 * Sets the default post content if we have selected a template via the Library
	 * 
	 * @param   string
	 * 
	 * @return  string
	 */
	public function presetPostContent($content)
	{
		$template = isset($_GET['template']) ? sanitize_text_field($_GET['template']) : '';

		if ($template == 'blank')
		{
			return;
		}
		
		$box = \FireBox\Core\Helpers\BoxHelper::getBoxFromTemplate();

		if (empty($box))
		{
			return $content;
		}

		return $box->post_content;
	}

	/**
	 * Runs only on specific FireBox pages
	 * 
	 * @return  void
	 */
	public function validate()
	{
		$current_screen = get_current_screen();

		$allowed_pages = [
			'toplevel_page_firebox',
			'edit-firebox'
		];

		if (!in_array($current_screen->id, $allowed_pages))
		{
			return false;
		}

		$this->run();
	}

	/**
	 * Runs the module
	 * 
	 * @return  void
	 */
	private function run()
	{
		// render custom actions
		add_action('fpframework/modal/' . $this->modal_id . '/header/prepend_actions', [$this, 'set_modal_actions']);

		// add custom footer links
		add_action('fpframework/library/' . $this->modal_id . '/footer/prepend_links', [$this, 'set_modal_footer_links']);

		$this->init();
	}

	/**
	 * Renders any other actions in the modal header
	 * 
	 * @return  void
	 */
	public function set_modal_actions()
	{
		?>
		<li>
			<a href="<?PHP echo admin_url('post-new.php?post_type=firebox&template=blank'); ?>" class="dashicons dashicons-plus-alt" title="<?php echo firebox()->_('FB_BLANK_POPUP'); ?>"></a>
		</li>
		<li>
			<a href="#" class="dashicons dashicons-update fpf-templates-refresh-btn" title="<?php echo fpframework()->_('FPF_REFRESH_TEMPLATES'); ?>"></a>
		</li>
		<li>
			<a href="<?php echo admin_url('admin.php?page=firebox-import'); ?>" class="dashicons dashicons-upload" title="<?php echo firebox()->_('FB_IMPORT_POPUP'); ?>"></a>
		</li>
		<li>
			<a href="<?php echo esc_url(FPF_SUPPORT_URL . '?topic=Custom%20Development&plugin=FireBox'); ?>" class="dashicons dashicons-email-alt" title="<?php echo firebox()->_('FB_REQUEST_POPUP'); ?>"></a>
		</li>
		<?php
	}

	/**
	 * Renders any other actions in the modal header
	 * 
	 * @return  void
	 */
	public function set_modal_footer_links()
	{
		?>
        <li>
            <a class="parent" href="<?php echo admin_url('post-new.php?post_type=firebox&template=blank'); ?>"><?php echo esc_html(firebox()->_('FB_BLANK_POPUP')); ?></a>
        </li>
		<?php
	}
}
```
