| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.0 Free | |
| 4 | + * @version 2.1.14 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <info@fireplugins.com> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2021 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2024 FirePlugins All Rights Reserved | |
| 9 | 9 | * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | namespace FireBox\Core\Admin\Includes; |
| @@ -15,130 +15,63 @@ | ||
| 15 | 15 | { |
| 16 | 16 | exit; // Exit if accessed directly. |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -use \FPFramework\Admin\Library\Library as FrameworkLibrary; | |
| 20 | - | |
| 21 | -class Library extends FrameworkLibrary | |
| 19 | +class Library extends \FPFramework\Admin\Library\Library | |
| 22 | 20 | { |
| 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 | 21 | public function __construct() |
| 53 | 22 | { |
| 54 | - $this->setup(); | |
| 23 | + parent::__construct($this->getLibrarySettings()); | |
| 55 | 24 | |
| 56 | 25 | add_action('current_screen', [$this, 'validate']); |
| 57 | 26 | |
| 58 | 27 | // set default post title |
| 59 | - add_filter('default_title', [$this, 'presetPostTitle'], 10, 2); | |
| 28 | + add_filter('default_title', [$this, 'presetPostTitle'], 100, 2); | |
| 60 | 29 | |
| 61 | 30 | // set default post content |
| 62 | - add_filter('default_content', [$this, 'presetPostContent']); | |
| 31 | + add_filter('default_content', [$this, 'presetPostContent'], 200, 2); | |
| 63 | 32 | } |
| 64 | 33 | |
| 65 | 34 | /** |
| 66 | - * Plugin library settings | |
| 35 | + * Returns the library settings. | |
| 67 | 36 | * |
| 68 | - * @return void | |
| 37 | + * @return array | |
| 69 | 38 | */ |
| 70 | - private function setup() | |
| 39 | + private function getLibrarySettings() | |
| 71 | 40 | { |
| 72 | - $this->library_settings = [ | |
| 73 | - 'id' => $this->modal_id, | |
| 74 | - 'title' => 'FB_LIBRARY', | |
| 75 | - 'support_request_label' => 'FB_REQUEST_POPUP', | |
| 76 | - 'categories' => $this->categories, | |
| 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'), | |
| 77 | 47 | 'plugin_dir' => FBOX_PLUGIN_DIR, |
| 78 | 48 | '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 | |
| 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=' | |
| 85 | 59 | ]; |
| 86 | - | |
| 87 | - $this->setupAjax(); | |
| 88 | 60 | } |
| 89 | 61 | |
| 90 | 62 | /** |
| 91 | - * Set the default post title if we have selected a template via the Library | |
| 63 | + * Old function used to find templates. | |
| 92 | 64 | * |
| 93 | - * @param string $post_title | |
| 94 | - * @param object $post | |
| 65 | + * @param string $template | |
| 95 | 66 | * |
| 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 | |
| 67 | + * @deprecated 1.1.0 | |
| 119 | 68 | * |
| 120 | - * @param string | |
| 121 | - * | |
| 122 | - * @return string | |
| 69 | + * @return null | |
| 123 | 70 | */ |
| 124 | - public function presetPostContent($content) | |
| 71 | + public function find($template = '') | |
| 125 | 72 | { |
| 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; | |
| 73 | + return; | |
| 141 | 74 | } |
| 142 | 75 | |
| 143 | 76 | /** |
| 144 | 77 | * Runs only on specific FireBox pages |
| @@ -150,8 +83,12 @@ | ||
| 150 | 83 | $current_screen = get_current_screen(); |
| 151 | 84 | |
| 152 | 85 | $allowed_pages = [ |
| 153 | 86 | 'toplevel_page_firebox', |
| 87 | + 'firebox_page_firebox-analytics', | |
| 88 | + 'firebox_page_firebox-campaigns', | |
| 89 | + 'firebox_page_firebox-submissions', | |
| 90 | + 'firebox_page_firebox-settings', | |
| 154 | 91 | 'edit-firebox' |
| 155 | 92 | ]; |
| 156 | 93 | |
| 157 | 94 | if (!in_array($current_screen->id, $allowed_pages)) |
| @@ -158,60 +95,42 @@ | ||
| 158 | 95 | { |
| 159 | 96 | return false; |
| 160 | 97 | } |
| 161 | 98 | |
| 162 | - $this->run(); | |
| 99 | + $this->init(); | |
| 163 | 100 | } |
| 164 | 101 | |
| 165 | 102 | /** |
| 166 | - * Runs the module | |
| 103 | + * Set the default post title if we have selected a template via the Library | |
| 167 | 104 | * |
| 168 | - * @return void | |
| 105 | + * @param string $post_title | |
| 106 | + * @param object $post | |
| 107 | + * | |
| 108 | + * @return string | |
| 169 | 109 | */ |
| 170 | - private function run() | |
| 110 | + public function presetPostTitle($post_title, $post) | |
| 171 | 111 | { |
| 172 | - // render custom actions | |
| 173 | - add_action('fpframework/modal/' . $this->modal_id . '/header/prepend_actions', [$this, 'set_modal_actions']); | |
| 112 | + if (!$template = \FireBox\Core\Helpers\BoxHelper::getBoxFromTemplateURL()) | |
| 113 | + { | |
| 114 | + return $post_title; | |
| 115 | + } | |
| 174 | 116 | |
| 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(); | |
| 117 | + return $template['template']['post_title']; | |
| 179 | 118 | } |
| 180 | 119 | |
| 181 | 120 | /** |
| 182 | - * Renders any other actions in the modal header | |
| 121 | + * Sets the default post content if we have selected a template via the Library | |
| 183 | 122 | * |
| 184 | - * @return void | |
| 123 | + * @param string | |
| 124 | + * | |
| 125 | + * @return string | |
| 185 | 126 | */ |
| 186 | - public function set_modal_actions() | |
| 127 | + public function presetPostContent($content) | |
| 187 | 128 | { |
| 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 | - } | |
| 129 | + if (!$template = \FireBox\Core\Helpers\BoxHelper::getBoxFromTemplateURL()) | |
| 130 | + { | |
| 131 | + return $content; | |
| 132 | + } | |
| 203 | 133 | |
| 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 | |
| 134 | + return $template['template']['post_content']; | |
| 216 | 135 | } |
| 217 | 136 | } |