| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 2.1.14 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2024 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FireBox\Core\Admin\Includes; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class Library extends \FPFramework\Admin\Library\Library |
| 20 |
{ |
| 21 |
public function __construct() |
| 22 |
{ |
| 23 |
parent::__construct($this->getLibrarySettings()); |
| 24 |
|
| 25 |
add_action('current_screen', [$this, 'validate']); |
| 26 |
|
| 27 |
// set default post title |
| 28 |
add_filter('default_title', [$this, 'presetPostTitle'], 100, 2); |
| 29 |
|
| 30 |
// set default post content |
| 31 |
add_filter('default_content', [$this, 'presetPostContent'], 200, 2); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Returns the library settings. |
| 36 |
* |
| 37 |
* @return array |
| 38 |
*/ |
| 39 |
private function getLibrarySettings() |
| 40 |
{ |
| 41 |
return [ |
| 42 |
'id' => 'fbSelectTemplate', |
| 43 |
'title' => firebox()->_('FB_CAMPAIGN_LIBRARY'), |
| 44 |
'create_new_template_link' => admin_url('post-new.php?post_type=firebox'), |
| 45 |
'main_category_label' => firebox()->_('FB_CAMPAIGN_TYPE'), |
| 46 |
'plugin_license_settings_url' => admin_url('admin.php?page=firebox-settings#license_key'), |
| 47 |
'plugin_dir' => FBOX_PLUGIN_DIR, |
| 48 |
'plugin' => 'firebox', |
| 49 |
'plugin_version' => FBOX_VERSION, |
| 50 |
'plugin_license_type' => FBOX_LICENSE_TYPE, |
| 51 |
'plugin_name' => firebox()->_('FB_PLUGIN_NAME'), |
| 52 |
|
| 53 |
'license_key' => false, |
| 54 |
'license_key_status' => false, |
| 55 |
|
| 56 |
|
| 57 |
'blank_template_label' => fpframework()->_('FPF_BLANK_TEMPLATE'), |
| 58 |
'template_use_url' => 'post-new.php?post_type=firebox&fpf_use_template=true&template=' |
| 59 |
]; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Old function used to find templates. |
| 64 |
* |
| 65 |
* @param string $template |
| 66 |
* |
| 67 |
* @deprecated 1.1.0 |
| 68 |
* |
| 69 |
* @return null |
| 70 |
*/ |
| 71 |
public function find($template = '') |
| 72 |
{ |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Runs only on specific FireBox pages |
| 78 |
* |
| 79 |
* @return void |
| 80 |
*/ |
| 81 |
public function validate() |
| 82 |
{ |
| 83 |
$current_screen = get_current_screen(); |
| 84 |
|
| 85 |
$allowed_pages = [ |
| 86 |
'toplevel_page_firebox', |
| 87 |
'firebox_page_firebox-analytics', |
| 88 |
'firebox_page_firebox-campaigns', |
| 89 |
'firebox_page_firebox-submissions', |
| 90 |
'firebox_page_firebox-settings', |
| 91 |
'edit-firebox' |
| 92 |
]; |
| 93 |
|
| 94 |
if (!in_array($current_screen->id, $allowed_pages)) |
| 95 |
{ |
| 96 |
return false; |
| 97 |
} |
| 98 |
|
| 99 |
$this->init(); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Set the default post title if we have selected a template via the Library |
| 104 |
* |
| 105 |
* @param string $post_title |
| 106 |
* @param object $post |
| 107 |
* |
| 108 |
* @return string |
| 109 |
*/ |
| 110 |
public function presetPostTitle($post_title, $post) |
| 111 |
{ |
| 112 |
if (!$template = \FireBox\Core\Helpers\BoxHelper::getBoxFromTemplateURL()) |
| 113 |
{ |
| 114 |
return $post_title; |
| 115 |
} |
| 116 |
|
| 117 |
return $template['template']['post_title']; |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Sets the default post content if we have selected a template via the Library |
| 122 |
* |
| 123 |
* @param string |
| 124 |
* |
| 125 |
* @return string |
| 126 |
*/ |
| 127 |
public function presetPostContent($content) |
| 128 |
{ |
| 129 |
if (!$template = \FireBox\Core\Helpers\BoxHelper::getBoxFromTemplateURL()) |
| 130 |
{ |
| 131 |
return $content; |
| 132 |
} |
| 133 |
|
| 134 |
return $template['template']['post_content']; |
| 135 |
} |
| 136 |
} |