| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 1.0.0 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2021 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 |
use \FPFramework\Admin\Library\Library as FrameworkLibrary; |
| 20 |
|
| 21 |
class Library extends FrameworkLibrary |
| 22 |
{ |
| 23 |
/** |
| 24 |
* The Modal ID. |
| 25 |
* |
| 26 |
* @var String |
| 27 |
*/ |
| 28 |
protected $modal_id = 'fbSelectTemplate'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Library categories. |
| 32 |
* |
| 33 |
* @var array |
| 34 |
*/ |
| 35 |
protected $categories = [ |
| 36 |
'all' => 'FPF_ALL', |
| 37 |
'popup' => 'FB_POPUP', |
| 38 |
'fullscreen' => 'FB_FULLSCREEN', |
| 39 |
'slidein' => 'FB_SLIDEIN', |
| 40 |
'floatingbar' => 'FB_FLOATING_BAR', |
| 41 |
'sidebar' => 'FB_SIDEBAR', |
| 42 |
'specials' => 'FB_SPECIALS' |
| 43 |
]; |
| 44 |
|
| 45 |
/** |
| 46 |
* The library settings |
| 47 |
* |
| 48 |
* @var array |
| 49 |
*/ |
| 50 |
protected $library_settings; |
| 51 |
|
| 52 |
public function __construct() |
| 53 |
{ |
| 54 |
$this->setup(); |
| 55 |
|
| 56 |
add_action('current_screen', [$this, 'validate']); |
| 57 |
|
| 58 |
// set default post title |
| 59 |
add_filter('default_title', [$this, 'presetPostTitle'], 10, 2); |
| 60 |
|
| 61 |
// set default post content |
| 62 |
add_filter('default_content', [$this, 'presetPostContent']); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Plugin library settings |
| 67 |
* |
| 68 |
* @return void |
| 69 |
*/ |
| 70 |
private function setup() |
| 71 |
{ |
| 72 |
$this->library_settings = [ |
| 73 |
'id' => $this->modal_id, |
| 74 |
'title' => 'FB_LIBRARY', |
| 75 |
'support_request_label' => 'FB_REQUEST_POPUP', |
| 76 |
'categories' => $this->categories, |
| 77 |
'plugin_dir' => FBOX_PLUGIN_DIR, |
| 78 |
'plugin' => 'firebox', |
| 79 |
'plugin_name' => firebox()->_('PLUGIN_NAME'), |
| 80 |
'blank_template_label' => 'FB_BLANK_POPUP', |
| 81 |
'blank_template_desc' => 'FPF_START_FROM_SCRATCH', |
| 82 |
'noresults_create_from_scratch_label' => 'FB_CREATE_FROM_SCRATCH', |
| 83 |
'template_use_url' => 'post-new.php?post_type=firebox&template=', |
| 84 |
'license_type' => FBOX_LICENSE_TYPE |
| 85 |
]; |
| 86 |
|
| 87 |
$this->setupAjax(); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Set the default post title if we have selected a template via the Library |
| 92 |
* |
| 93 |
* @param string $post_title |
| 94 |
* @param object $post |
| 95 |
* |
| 96 |
* @return string |
| 97 |
*/ |
| 98 |
public function presetPostTitle($post_title, $post) |
| 99 |
{ |
| 100 |
$template = isset($_GET['template']) ? sanitize_text_field($_GET['template']) : ''; |
| 101 |
|
| 102 |
if ($template == 'blank') |
| 103 |
{ |
| 104 |
return; |
| 105 |
} |
| 106 |
|
| 107 |
$box = \FireBox\Core\Helpers\BoxHelper::getBoxFromTemplate(); |
| 108 |
|
| 109 |
if (empty($box)) |
| 110 |
{ |
| 111 |
return $post_title; |
| 112 |
} |
| 113 |
|
| 114 |
return $box->post_title; |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Sets the default post content if we have selected a template via the Library |
| 119 |
* |
| 120 |
* @param string |
| 121 |
* |
| 122 |
* @return string |
| 123 |
*/ |
| 124 |
public function presetPostContent($content) |
| 125 |
{ |
| 126 |
$template = isset($_GET['template']) ? sanitize_text_field($_GET['template']) : ''; |
| 127 |
|
| 128 |
if ($template == 'blank') |
| 129 |
{ |
| 130 |
return; |
| 131 |
} |
| 132 |
|
| 133 |
$box = \FireBox\Core\Helpers\BoxHelper::getBoxFromTemplate(); |
| 134 |
|
| 135 |
if (empty($box)) |
| 136 |
{ |
| 137 |
return $content; |
| 138 |
} |
| 139 |
|
| 140 |
return $box->post_content; |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Runs only on specific FireBox pages |
| 145 |
* |
| 146 |
* @return void |
| 147 |
*/ |
| 148 |
public function validate() |
| 149 |
{ |
| 150 |
$current_screen = get_current_screen(); |
| 151 |
|
| 152 |
$allowed_pages = [ |
| 153 |
'toplevel_page_firebox', |
| 154 |
'edit-firebox' |
| 155 |
]; |
| 156 |
|
| 157 |
if (!in_array($current_screen->id, $allowed_pages)) |
| 158 |
{ |
| 159 |
return false; |
| 160 |
} |
| 161 |
|
| 162 |
$this->run(); |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Runs the module |
| 167 |
* |
| 168 |
* @return void |
| 169 |
*/ |
| 170 |
private function run() |
| 171 |
{ |
| 172 |
// render custom actions |
| 173 |
add_action('fpframework/modal/' . $this->modal_id . '/header/prepend_actions', [$this, 'set_modal_actions']); |
| 174 |
|
| 175 |
// add custom footer links |
| 176 |
add_action('fpframework/library/' . $this->modal_id . '/footer/prepend_links', [$this, 'set_modal_footer_links']); |
| 177 |
|
| 178 |
$this->init(); |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Renders any other actions in the modal header |
| 183 |
* |
| 184 |
* @return void |
| 185 |
*/ |
| 186 |
public function set_modal_actions() |
| 187 |
{ |
| 188 |
?> |
| 189 |
<li> |
| 190 |
<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> |
| 191 |
</li> |
| 192 |
<li> |
| 193 |
<a href="#" class="dashicons dashicons-update fpf-templates-refresh-btn" title="<?php echo fpframework()->_('FPF_REFRESH_TEMPLATES'); ?>"></a> |
| 194 |
</li> |
| 195 |
<li> |
| 196 |
<a href="<?php echo admin_url('admin.php?page=firebox-import'); ?>" class="dashicons dashicons-upload" title="<?php echo firebox()->_('FB_IMPORT_POPUP'); ?>"></a> |
| 197 |
</li> |
| 198 |
<li> |
| 199 |
<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> |
| 200 |
</li> |
| 201 |
<?php |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* Renders any other actions in the modal header |
| 206 |
* |
| 207 |
* @return void |
| 208 |
*/ |
| 209 |
public function set_modal_footer_links() |
| 210 |
{ |
| 211 |
?> |
| 212 |
<li> |
| 213 |
<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> |
| 214 |
</li> |
| 215 |
<?php |
| 216 |
} |
| 217 |
} |