| 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; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class Admin |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Admin Page Settings |
| 23 |
* |
| 24 |
* @var AdminPageSettings |
| 25 |
*/ |
| 26 |
private $pageSettings; |
| 27 |
|
| 28 |
/** |
| 29 |
* Library |
| 30 |
* |
| 31 |
* @var Library |
| 32 |
*/ |
| 33 |
public $library; |
| 34 |
|
| 35 |
/** |
| 36 |
* Admin constructor |
| 37 |
*/ |
| 38 |
public function __construct() |
| 39 |
{ |
| 40 |
// init dependencies |
| 41 |
$this->initDependencies(); |
| 42 |
|
| 43 |
// Admin Page Settings |
| 44 |
$this->pageSettings = new AdminPageSettings(); |
| 45 |
|
| 46 |
// run actions |
| 47 |
$this->handleActions(); |
| 48 |
|
| 49 |
// run filters |
| 50 |
$this->handleFilters(); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Load admin dependencies. |
| 55 |
* |
| 56 |
* @return void |
| 57 |
*/ |
| 58 |
private function initDependencies() |
| 59 |
{ |
| 60 |
$this->library = firebox()->library; |
| 61 |
|
| 62 |
// Update Notice |
| 63 |
$valid_pages = [ |
| 64 |
'firebox', |
| 65 |
'firebox-analytics', |
| 66 |
'firebox-import', |
| 67 |
'firebox-settings' |
| 68 |
]; |
| 69 |
$updateNotice = new \FPFramework\Admin\Includes\UpdateNotice( |
| 70 |
firebox()->plugin_slug, |
| 71 |
firebox()->plugin_name, |
| 72 |
FBOX_VERSION, |
| 73 |
$valid_pages |
| 74 |
); |
| 75 |
$updateNotice->init(); |
| 76 |
|
| 77 |
// Top Bar Navigation |
| 78 |
new Includes\TopBarNavigation(); |
| 79 |
|
| 80 |
// Review Reminder |
| 81 |
new \FPFramework\Admin\Includes\ReviewReminder( |
| 82 |
firebox()->plugin_slug, |
| 83 |
firebox()->plugin_name, |
| 84 |
FBOX_MEDIA_ADMIN_URL |
| 85 |
); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Runs all Admin Actions |
| 90 |
* |
| 91 |
* @return void |
| 92 |
*/ |
| 93 |
private function handleActions() |
| 94 |
{ |
| 95 |
add_action('admin_enqueue_scripts', [$this, 'registerMedia'], 20); |
| 96 |
|
| 97 |
|
| 98 |
add_action('plugin_action_links_' . plugin_basename(FBOX_PLUGIN_BASE_FILE), [$this, 'plugin_action_links']); |
| 99 |
|
| 100 |
add_action('fpframework/admin/template/footer/nav_links', [$this, 'add_admin_page_template_footer_nav_links']); |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
/** |
| 106 |
* Adds extra links to the Plugins page in the free version. |
| 107 |
* - Upgrade to Pro button |
| 108 |
* |
| 109 |
* @param array $links |
| 110 |
* |
| 111 |
* @return array |
| 112 |
*/ |
| 113 |
public function plugin_action_links($links) |
| 114 |
{ |
| 115 |
$links = array_merge( $links, array( |
| 116 |
'<a href="' . FBOX_GO_PRO_URL . '" class="firebox-go-pro-link" title="' . fpframework()->_('FPF_UNLOCK_MORE_FEATURES_WITH_PRO_READ_MORE') . '">' . fpframework()->_('FPF_GO_PRO') . '</a>' |
| 117 |
) ); |
| 118 |
|
| 119 |
return $links; |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Adds links to the admin template footer nav links |
| 124 |
* |
| 125 |
* @return void |
| 126 |
*/ |
| 127 |
public function add_admin_page_template_footer_nav_links() |
| 128 |
{ |
| 129 |
?> |
| 130 |
<li><a href="https://www.fireplugins.com/<?php echo esc_attr(firebox()->plugin_slug); ?>" target="_blank"><?php echo esc_html(fpframework()->_('FPF_GET_PRO_FEATURES')); ?></a></li> |
| 131 |
<?php |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
/** |
| 136 |
* Runs all Admin Filters |
| 137 |
* |
| 138 |
* @return void |
| 139 |
*/ |
| 140 |
private function handleFilters() |
| 141 |
{ |
| 142 |
add_filter('admin_body_class', [$this, 'setPluginPageBodyClass']); |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Sets a class to the body of the FireBox Admin Pages |
| 147 |
* |
| 148 |
* @return string |
| 149 |
*/ |
| 150 |
public function setPluginPageBodyClass($classes) |
| 151 |
{ |
| 152 |
if (!$this->isPluginPage()) |
| 153 |
{ |
| 154 |
return $classes; |
| 155 |
} |
| 156 |
|
| 157 |
$classes .= ' fpf-admin-page fpf-firebox-page'; |
| 158 |
|
| 159 |
if ($this->isControllerPage()) |
| 160 |
{ |
| 161 |
$classes .= ' fpf-controller-page'; |
| 162 |
} |
| 163 |
|
| 164 |
return $classes; |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* Checks if we are in a plugin page |
| 169 |
* |
| 170 |
* @return boolean |
| 171 |
*/ |
| 172 |
private function isPluginPage() |
| 173 |
{ |
| 174 |
if ($this->getPageNow() == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'firebox') |
| 175 |
{ |
| 176 |
return true; |
| 177 |
} |
| 178 |
|
| 179 |
if ($this->getPageNow() == 'post.php') |
| 180 |
{ |
| 181 |
return true; |
| 182 |
} |
| 183 |
|
| 184 |
if ($this->isControllerPage()) |
| 185 |
{ |
| 186 |
return true; |
| 187 |
} |
| 188 |
|
| 189 |
if (current_user_can('manage_options')) |
| 190 |
{ |
| 191 |
return true; |
| 192 |
} |
| 193 |
|
| 194 |
return false; |
| 195 |
} |
| 196 |
|
| 197 |
/** |
| 198 |
* Whether we are browsing a plugin page from the plugin's menu |
| 199 |
* |
| 200 |
* @return boolean |
| 201 |
*/ |
| 202 |
private function isControllerPage() |
| 203 |
{ |
| 204 |
if (!firebox()->menu) |
| 205 |
{ |
| 206 |
return false; |
| 207 |
} |
| 208 |
|
| 209 |
$current_plugin_page = fpframework()->getPluginPage(); |
| 210 |
$plugin_menu_items = firebox()->menu->getPluginMenuItems(); |
| 211 |
|
| 212 |
// Only set the class to the plugin pages |
| 213 |
return $this->getPageNow() == 'admin.php' && in_array($current_plugin_page, $plugin_menu_items); |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* Returns page now |
| 218 |
* |
| 219 |
* @return string |
| 220 |
*/ |
| 221 |
protected function getPageNow() |
| 222 |
{ |
| 223 |
global $pagenow; |
| 224 |
return $pagenow; |
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* Registers CSS and JS files |
| 229 |
* |
| 230 |
* @return void |
| 231 |
*/ |
| 232 |
public function registerMedia() |
| 233 |
{ |
| 234 |
$this->registerStyles(); |
| 235 |
$this->registerScripts(); |
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* Register admin styles. |
| 240 |
* |
| 241 |
* @return void |
| 242 |
*/ |
| 243 |
public function registerStyles() |
| 244 |
{ |
| 245 |
// firebox main admin css |
| 246 |
wp_register_style( |
| 247 |
'firebox-admin', |
| 248 |
FBOX_MEDIA_ADMIN_URL . 'css/firebox.css', |
| 249 |
[], |
| 250 |
FBOX_VERSION, |
| 251 |
false |
| 252 |
); |
| 253 |
wp_enqueue_style('firebox-admin'); |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Registers admin scripts. |
| 258 |
* |
| 259 |
* @return void |
| 260 |
*/ |
| 261 |
public function registerScripts() |
| 262 |
{ |
| 263 |
$data = array( |
| 264 |
'media_url' => FBOX_MEDIA_URL |
| 265 |
); |
| 266 |
|
| 267 |
wp_localize_script('fpframework-admin', 'fbox_admin_js_object', $data); |
| 268 |
} |
| 269 |
} |