| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.13 Free | |
| 4 | + * @version 2.1.39 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <info@fireplugins.com> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2022 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2025 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; |
| @@ -36,8 +36,25 @@ | ||
| 36 | 36 | * Admin constructor |
| 37 | 37 | */ |
| 38 | 38 | public function __construct() |
| 39 | 39 | { |
| 40 | + new \FireBox\Core\Notices\Ajax(); | |
| 41 | + | |
| 42 | + $this->maybeExportSubmsissions(); | |
| 43 | + | |
| 44 | + add_action('wp_trash_post', [$this, 'on_campaign_trash'], 10, 2); | |
| 45 | + add_action('untrash_post', [$this, 'on_campaign_untrash'], 10, 2); | |
| 46 | + | |
| 47 | + | |
| 48 | + add_action('admin_enqueue_scripts', [$this, 'global_backend_assets'], 20); | |
| 49 | + | |
| 50 | + | |
| 51 | + add_action('enqueue_block_editor_assets', [$this, 'block_editor_assets'], -100); | |
| 52 | + | |
| 53 | + add_action('current_screen', [$this, 'current_screen']); | |
| 54 | + | |
| 55 | + add_action('firebox/admin/content', [$this, 'showNotices'], -5); | |
| 56 | + | |
| 40 | 57 | // init dependencies |
| 41 | 58 | $this->initDependencies(); |
| 42 | 59 | |
| 43 | 60 | // Admin Page Settings |
| @@ -48,45 +65,303 @@ | ||
| 48 | 65 | |
| 49 | 66 | // run filters |
| 50 | 67 | $this->handleFilters(); |
| 51 | 68 | } |
| 52 | - | |
| 69 | + | |
| 70 | + private function maybeExportSubmsissions() | |
| 71 | + { | |
| 72 | + if (!isset($_GET['task']) || $_GET['task'] !== 'export') //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 73 | + { | |
| 74 | + return; | |
| 75 | + } | |
| 76 | + | |
| 77 | + if (!isset($_GET['form_id'])) //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 78 | + { | |
| 79 | + return; | |
| 80 | + } | |
| 81 | + | |
| 82 | + if (!isset($_GET['page']) || $_GET['page'] !== 'firebox-submissions') //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 83 | + { | |
| 84 | + return; | |
| 85 | + } | |
| 86 | + | |
| 87 | + $form_id = sanitize_text_field(wp_unslash($_GET['form_id'])); //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 88 | + | |
| 89 | + $payload = [ | |
| 90 | + 'where' => [ | |
| 91 | + 'form_id' => " = '" . esc_sql($form_id) . "'", | |
| 92 | + 'state' => ' = 1' | |
| 93 | + ], | |
| 94 | + 'offset' => 0, | |
| 95 | + 'limit' => 99999, | |
| 96 | + 'orderby' => 'created_at ASC' | |
| 97 | + ]; | |
| 98 | + | |
| 99 | + if (!$submissions = firebox()->tables->submission->getResults($payload)) | |
| 100 | + { | |
| 101 | + return; | |
| 102 | + } | |
| 103 | + | |
| 104 | + if (!$form = \FireBox\Core\Helpers\Form\Form::getFormByID($form_id, true)) | |
| 105 | + { | |
| 106 | + return; | |
| 107 | + } | |
| 108 | + | |
| 109 | + $prepared = []; | |
| 110 | + | |
| 111 | + // Set submission fields values | |
| 112 | + foreach ($submissions as $item) | |
| 113 | + { | |
| 114 | + $prepared_payload = [ | |
| 115 | + 'id' => $item->id, | |
| 116 | + 'created' => get_date_from_gmt($item->created_at), | |
| 117 | + 'state' => $item->state === '1' ? 'Published' : 'Unpublished' | |
| 118 | + ]; | |
| 119 | + | |
| 120 | + // Find field values | |
| 121 | + $meta = firebox()->tables->submissionmeta->getResults([ | |
| 122 | + 'where' => [ | |
| 123 | + 'submission_id' => " = " . esc_sql($item->id) | |
| 124 | + ] | |
| 125 | + ]); | |
| 126 | + | |
| 127 | + if ($meta && $form['fields']) | |
| 128 | + { | |
| 129 | + foreach ($form['fields'] as $field) | |
| 130 | + { | |
| 131 | + foreach ($meta as $meta_item) | |
| 132 | + { | |
| 133 | + if ($field->getOptionValue('id') === $meta_item->meta_key) | |
| 134 | + { | |
| 135 | + $prepared_payload[$field->getOptionValue('name')] = $field->prepareValue($meta_item->meta_value); | |
| 136 | + } | |
| 137 | + } | |
| 138 | + } | |
| 139 | + } | |
| 140 | + | |
| 141 | + $prepared[] = $prepared_payload; | |
| 142 | + } | |
| 143 | + | |
| 144 | + | |
| 145 | + $filename = get_temp_dir() . 'submissions_' . $form['name'] . '_' . date('Y-m-d_H-i-s') . '.csv'; | |
| 146 | + self::toCSV($prepared, $filename); | |
| 147 | + | |
| 148 | + // Prompt to download the file | |
| 149 | + error_reporting(0); | |
| 150 | + | |
| 151 | + // Send the appropriate headers to force the download in the browser | |
| 152 | + header('Content-Description: File Transfer'); | |
| 153 | + header('Content-Type: application/octet-stream'); | |
| 154 | + header('Content-Disposition: attachment; filename="' . basename($filename) . '"'); | |
| 155 | + header('Expires: 0'); | |
| 156 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); | |
| 157 | + header('Cache-Control: public', false); | |
| 158 | + header('Pragma: public'); | |
| 159 | + header('Content-Length: ' . @filesize($filename)); | |
| 160 | + | |
| 161 | + // Clear the output buffer and disable output buffering | |
| 162 | + ob_clean(); | |
| 163 | + flush(); | |
| 164 | + | |
| 165 | + readfile($filename); | |
| 166 | + | |
| 167 | + unlink($filename); | |
| 168 | + | |
| 169 | + exit; | |
| 170 | + } | |
| 171 | + | |
| 53 | 172 | /** |
| 54 | - * Load admin dependencies. | |
| 173 | + * Create a CSV file with given data | |
| 174 | + * | |
| 175 | + * @param array $data The data to populate the file | |
| 176 | + * @param string $destination The path where the store the CSV file | |
| 177 | + * @param bool $append If true, given data will be appended to the end of the file. | |
| 178 | + * @param boolean $excel_security If enabled, certain row values will be prefixed by a tab to avoid any CSV injection. | |
| 179 | + * | |
| 180 | + * @return void | |
| 181 | + */ | |
| 182 | + private static function toCSV($data, $destination, $append = false, $excel_security = true, $check_for_duplicates = true) | |
| 183 | + { | |
| 184 | + $resource = fopen($destination, $append ? 'a+' : 'w'); | |
| 185 | + | |
| 186 | + if (!$append) | |
| 187 | + { | |
| 188 | + // Support UTF-8 on Microsoft Excel | |
| 189 | + fputs($resource, "\xEF\xBB\xBF"); | |
| 190 | + | |
| 191 | + // Add column names in the first line | |
| 192 | + fputcsv($resource, array_keys($data[0])); | |
| 193 | + } | |
| 194 | + | |
| 195 | + // Get CSV content | |
| 196 | + $existingRows = []; | |
| 197 | + if ($append && $check_for_duplicates) | |
| 198 | + { | |
| 199 | + while (($existingData = fgetcsv($resource)) !== false) | |
| 200 | + { | |
| 201 | + $existingRows[(int) $existingData[0]] = $existingData; | |
| 202 | + } | |
| 203 | + } | |
| 204 | + | |
| 205 | + foreach ($data as $row) | |
| 206 | + { | |
| 207 | + if (!empty($existingRows) && isset($row['id']) && array_key_exists($row['id'], $existingRows)) | |
| 208 | + { | |
| 209 | + continue; | |
| 210 | + } | |
| 211 | + | |
| 212 | + // Prevent CSV Injection: https://vel.joomla.org/articles/2140-introducing-csv-injection | |
| 213 | + if ($excel_security) | |
| 214 | + { | |
| 215 | + foreach ($row as &$value) | |
| 216 | + { | |
| 217 | + $value = is_array($value) ? implode(', ', $value) : $value; | |
| 218 | + | |
| 219 | + $firstChar = substr($value, 0, 1); | |
| 220 | + | |
| 221 | + // Prefixe values starting with a =, +, - or @ by a tab character | |
| 222 | + if (in_array($firstChar, array('=', '+', '-', '@'))) | |
| 223 | + { | |
| 224 | + $value = ' ' . $value; | |
| 225 | + } | |
| 226 | + } | |
| 227 | + } | |
| 228 | + | |
| 229 | + fputcsv($resource, $row); | |
| 230 | + } | |
| 231 | + | |
| 232 | + fclose($resource); | |
| 233 | + } | |
| 234 | + | |
| 235 | + /** | |
| 236 | + * Fires when a campaign is trashed. | |
| 55 | 237 | * |
| 238 | + * @param int $post_id | |
| 239 | + * @param string $previous_status | |
| 240 | + * | |
| 56 | 241 | * @return void |
| 57 | 242 | */ |
| 58 | - private function initDependencies() | |
| 243 | + public function on_campaign_trash($post_id, $previous_status) | |
| 59 | 244 | { |
| 60 | - $this->library = firebox()->library; | |
| 245 | + $post_type = get_post_type($post_id); | |
| 246 | + $post_status = get_post_status($post_id); | |
| 61 | 247 | |
| 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, | |
| 248 | + if ($post_type === 'firebox' && $post_status === 'draft') | |
| 249 | + { | |
| 250 | + \FPFramework\Libs\AdminNotice::displaySuccess(firebox()->_('FB_CAMPAIGN_HAS_BEEN_TRASHED')); | |
| 251 | + } | |
| 252 | + } | |
| 253 | + | |
| 254 | + /** | |
| 255 | + * Fires when a campaign is untrashed. | |
| 256 | + * | |
| 257 | + * @param int $post_id | |
| 258 | + * @param string $previous_status | |
| 259 | + * | |
| 260 | + * @return void | |
| 261 | + */ | |
| 262 | + public function on_campaign_untrash($post_id, $previous_status) | |
| 263 | + { | |
| 264 | + $post_type = get_post_type($post_id); | |
| 265 | + $post_status = get_post_status($post_id); | |
| 266 | + | |
| 267 | + if ($post_type === 'firebox' && $post_status === 'trash') | |
| 268 | + { | |
| 269 | + \FPFramework\Libs\AdminNotice::displaySuccess(firebox()->_('FB_CAMPAIGN_HAS_BEEN_RESTORED')); | |
| 270 | + } | |
| 271 | + } | |
| 272 | + | |
| 273 | + public function showNotices() | |
| 274 | + { | |
| 275 | + \FireBox\Core\Notices\Notices::getInstance()->show(); | |
| 276 | + } | |
| 277 | + | |
| 278 | + public function block_editor_assets() | |
| 279 | + { | |
| 280 | + wp_enqueue_style( | |
| 281 | + 'firebox-blocks', | |
| 282 | + FBOX_MEDIA_PUBLIC_URL . 'css/blocks.css', | |
| 283 | + [], | |
| 284 | + FBOX_VERSION | |
| 285 | + ); | |
| 286 | + | |
| 287 | + wp_enqueue_script( | |
| 288 | + 'firebox-store', | |
| 289 | + FBOX_MEDIA_ADMIN_URL . 'js/blocks/store.js', | |
| 290 | + ['wp-data'], | |
| 72 | 291 | FBOX_VERSION, |
| 73 | - $valid_pages | |
| 292 | + false | |
| 74 | 293 | ); |
| 75 | - $updateNotice->init(); | |
| 294 | + } | |
| 76 | 295 | |
| 77 | - // Top Bar Navigation | |
| 78 | - new Includes\TopBarNavigation(); | |
| 296 | + | |
| 297 | + public function global_backend_assets() | |
| 298 | + { | |
| 299 | + wp_register_style( | |
| 300 | + 'firebox-admin-lite', | |
| 301 | + FBOX_MEDIA_ADMIN_URL . 'css/lite.css', | |
| 302 | + [], | |
| 303 | + FBOX_VERSION, | |
| 304 | + false | |
| 305 | + ); | |
| 306 | + wp_enqueue_style('firebox-admin-lite'); | |
| 307 | + } | |
| 308 | + | |
| 79 | 309 | |
| 80 | - // Review Reminder | |
| 81 | - new \FPFramework\Admin\Includes\ReviewReminder( | |
| 82 | - firebox()->plugin_slug, | |
| 83 | - firebox()->plugin_name, | |
| 84 | - FBOX_MEDIA_ADMIN_URL | |
| 85 | - ); | |
| 310 | + public function current_screen($screen) | |
| 311 | + { | |
| 312 | + add_action('admin_enqueue_scripts', [$this, 'registerEditorMedia'], 11); | |
| 313 | + | |
| 314 | + $allowed_pages = [ | |
| 315 | + 'toplevel_page_firebox', | |
| 316 | + 'firebox_page_firebox-campaigns', | |
| 317 | + 'firebox_page_firebox-analytics', | |
| 318 | + 'firebox_page_firebox-submissions', | |
| 319 | + 'firebox_page_firebox-settings', | |
| 320 | + 'firebox_page_firebox-import' | |
| 321 | + ]; | |
| 322 | + | |
| 323 | + if (isset($screen->id) && in_array($screen->id, $allowed_pages)) | |
| 324 | + { | |
| 325 | + add_action('admin_enqueue_scripts', [$this, 'registerMediaAdminPages'], 20); | |
| 326 | + | |
| 327 | + add_filter('admin_footer_text', [$this, 'admin_footer_text']); | |
| 328 | + } | |
| 86 | 329 | } |
| 87 | 330 | |
| 331 | + public function registerEditorMedia() | |
| 332 | + { | |
| 333 | + wp_register_script('firebox-admin-editor', false); | |
| 334 | + wp_enqueue_script('firebox-admin-editor'); | |
| 335 | + | |
| 336 | + $data = [ | |
| 337 | + 'media_url' => FBOX_MEDIA_URL, | |
| 338 | + 'timezone' => $this->getTimezone(), | |
| 339 | + 'license_type' => FBOX_LICENSE_TYPE | |
| 340 | + ]; | |
| 341 | + | |
| 342 | + wp_localize_script('firebox-admin-editor', 'fbox_admin_editor_js_object', $data); | |
| 343 | + | |
| 344 | + } | |
| 345 | + | |
| 346 | + public function admin_footer_text() | |
| 347 | + { | |
| 348 | + return; | |
| 349 | + } | |
| 350 | + | |
| 88 | 351 | /** |
| 352 | + * Load admin dependencies. | |
| 353 | + * | |
| 354 | + * @return void | |
| 355 | + */ | |
| 356 | + private function initDependencies() | |
| 357 | + { | |
| 358 | + new Media(); | |
| 359 | + | |
| 360 | + $this->library = firebox()->library; | |
| 361 | + } | |
| 362 | + | |
| 363 | + /** | |
| 89 | 364 | * Runs all Admin Actions |
| 90 | 365 | * |
| 91 | 366 | * @return void |
| 92 | 367 | */ |
| @@ -91,15 +366,30 @@ | ||
| 91 | 366 | * @return void |
| 92 | 367 | */ |
| 93 | 368 | private function handleActions() |
| 94 | 369 | { |
| 95 | - add_action('admin_enqueue_scripts', [$this, 'registerMedia'], 20); | |
| 370 | + add_action('admin_enqueue_scripts', [$this, 'registerGlobalMedia'], 20); | |
| 96 | 371 | |
| 97 | 372 | |
| 98 | 373 | add_action('plugin_action_links_' . plugin_basename(FBOX_PLUGIN_BASE_FILE), [$this, 'plugin_action_links']); |
| 374 | + | |
| 375 | + } | |
| 99 | 376 | |
| 100 | - add_action('fpframework/admin/template/footer/nav_links', [$this, 'add_admin_page_template_footer_nav_links']); | |
| 101 | - | |
| 377 | + public function registerGlobalMedia() | |
| 378 | + { | |
| 379 | + wp_register_style('firebox-global-admin', false); | |
| 380 | + wp_enqueue_style('firebox-global-admin'); | |
| 381 | + $css = ' | |
| 382 | + #adminmenu li.toplevel_page_firebox .wp-menu-image { | |
| 383 | + padding: 6px 0 0 3px; | |
| 384 | + height: auto; | |
| 385 | + } | |
| 386 | + #adminmenu li.toplevel_page_firebox img { | |
| 387 | + width: 22px; | |
| 388 | + padding: 0; | |
| 389 | + } | |
| 390 | + '; | |
| 391 | + wp_add_inline_style('firebox-global-admin', $css); | |
| 102 | 392 | } |
| 103 | 393 | |
| 104 | 394 | |
| 105 | 395 | /** |
| @@ -112,35 +402,45 @@ | ||
| 112 | 402 | */ |
| 113 | 403 | public function plugin_action_links($links) |
| 114 | 404 | { |
| 115 | 405 | $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>' | |
| 406 | + '<a href="' . FBOX_GO_PRO_URL . '" class="firebox-go-pro-link" title="' . fpframework()->_('FPF_UNLOCK_MORE_FEATURES_WITH_PRO_READ_MORE') . '">' . firebox()->_('FB_UPGRADE_20_OFF') . '</a>' | |
| 117 | 407 | ) ); |
| 118 | 408 | |
| 119 | 409 | return $links; |
| 120 | 410 | } |
| 411 | + | |
| 121 | 412 | |
| 122 | 413 | /** |
| 123 | - * Adds links to the admin template footer nav links | |
| 414 | + * Runs all Admin Filters | |
| 124 | 415 | * |
| 125 | 416 | * @return void |
| 126 | 417 | */ |
| 127 | - public function add_admin_page_template_footer_nav_links() | |
| 418 | + private function handleFilters() | |
| 128 | 419 | { |
| 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 | |
| 420 | + add_filter('admin_body_class', [$this, 'setPluginPageBodyClass']); | |
| 421 | + add_filter('plugin_row_meta' , [$this, 'addPluginMetaLinks'], 10, 4); | |
| 132 | 422 | } |
| 133 | - | |
| 134 | 423 | |
| 135 | 424 | /** |
| 136 | - * Runs all Admin Filters | |
| 425 | + * Adds extra links to the plugins page. | |
| 137 | 426 | * |
| 138 | - * @return void | |
| 427 | + * @param array $links | |
| 428 | + * @param string $file | |
| 429 | + * @param array $plugin_data | |
| 430 | + * @param string $status | |
| 431 | + * | |
| 432 | + * @return array | |
| 139 | 433 | */ |
| 140 | - private function handleFilters() | |
| 434 | + public function addPluginMetaLinks($links, $file, $plugin_data, $status) | |
| 141 | 435 | { |
| 142 | - add_filter('admin_body_class', [$this, 'setPluginPageBodyClass']); | |
| 436 | + if ($file === FBOX_PLUGIN_BASENAME) | |
| 437 | + { | |
| 438 | + $links['rate'] = '<a href="https://wordpress.org/support/plugin/firebox/reviews/?filter=5#new-post" aria-label="' . esc_attr(firebox()->_('FB_RATE_FIREBOX')) . '" target="_blank">' . esc_html(firebox()->_('FB_RATE_FIREBOX')) . '</a>'; | |
| 439 | + $links['support'] = '<a href="' . \FPFramework\Base\Functions::getUTMURL('https://www.fireplugins.com/contact/', '', 'misc', 'support') . '" aria-label="' . esc_attr(fpframework()->_('FPF_SUPPORT')) . '" target="_blank">' . esc_html(fpframework()->_('FPF_SUPPORT')) . '</a>'; | |
| 440 | + } | |
| 441 | + | |
| 442 | + return $links; | |
| 143 | 443 | } |
| 144 | 444 | |
| 145 | 445 | /** |
| 146 | 446 | * Sets a class to the body of the FireBox Admin Pages |
| @@ -160,8 +460,16 @@ | ||
| 160 | 460 | { |
| 161 | 461 | $classes .= ' fpf-controller-page'; |
| 162 | 462 | } |
| 163 | 463 | |
| 464 | + // Set admin template theme class | |
| 465 | + $fireplugins_theme = isset($_COOKIE['fireplugins_theme']) ? sanitize_key($_COOKIE['fireplugins_theme']) : 'light'; | |
| 466 | + $classes .= ' ' . $fireplugins_theme; | |
| 467 | + | |
| 468 | + // Set admin template sidebar toggle class | |
| 469 | + $sidebar_state = isset($_COOKIE['fireplugins_sidebar_state']) ? sanitize_key($_COOKIE['fireplugins_sidebar_state']) : 'expand'; | |
| 470 | + $classes .= ' ' . ($sidebar_state === 'expand' ? 'fpf-admin-sidebar-expand' : 'fpf-admin-sidebar-shrink'); | |
| 471 | + | |
| 164 | 472 | return $classes; |
| 165 | 473 | } |
| 166 | 474 | |
| 167 | 475 | /** |
| @@ -170,9 +478,9 @@ | ||
| 170 | 478 | * @return boolean |
| 171 | 479 | */ |
| 172 | 480 | private function isPluginPage() |
| 173 | 481 | { |
| 174 | - if ($this->getPageNow() == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'firebox') | |
| 482 | + if (in_array($this->getPageNow(), ['edit.php', 'post-new.php']) && isset($_GET['post_type']) && $_GET['post_type'] == 'firebox') //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 175 | 483 | { |
| 176 | 484 | return true; |
| 177 | 485 | } |
| 178 | 486 | |
| @@ -185,13 +493,8 @@ | ||
| 185 | 493 | { |
| 186 | 494 | return true; |
| 187 | 495 | } |
| 188 | 496 | |
| 189 | - if (current_user_can('manage_options')) | |
| 190 | - { | |
| 191 | - return true; | |
| 192 | - } | |
| 193 | - | |
| 194 | 497 | return false; |
| 195 | 498 | } |
| 196 | 499 | |
| 197 | 500 | /** |
| @@ -228,9 +531,9 @@ | ||
| 228 | 531 | * Registers CSS and JS files |
| 229 | 532 | * |
| 230 | 533 | * @return void |
| 231 | 534 | */ |
| 232 | - public function registerMedia() | |
| 535 | + public function registerMediaAdminPages() | |
| 233 | 536 | { |
| 234 | 537 | $this->registerStyles(); |
| 235 | 538 | $this->registerScripts(); |
| 236 | 539 | } |
| @@ -253,8 +556,25 @@ | ||
| 253 | 556 | FBOX_VERSION, |
| 254 | 557 | false |
| 255 | 558 | ); |
| 256 | 559 | wp_enqueue_style('firebox-admin'); |
| 560 | + | |
| 561 | + // firebox admin design | |
| 562 | + wp_register_style( | |
| 563 | + 'firebox-design-admin', | |
| 564 | + FBOX_MEDIA_ADMIN_URL . 'css/firebox_design.css', | |
| 565 | + [], | |
| 566 | + FBOX_VERSION, | |
| 567 | + false | |
| 568 | + ); | |
| 569 | + wp_enqueue_style('firebox-design-admin'); | |
| 570 | + | |
| 571 | + $css = ' | |
| 572 | + :root { | |
| 573 | + --fpf-templates-library-header-logo: url(' . FBOX_MEDIA_ADMIN_URL . 'images/logo.svg); | |
| 574 | + } | |
| 575 | + '; | |
| 576 | + wp_add_inline_style('firebox-admin', $css); | |
| 257 | 577 | } |
| 258 | 578 | |
| 259 | 579 | /** |
| 260 | 580 | * Registers admin scripts. |
| @@ -262,18 +582,120 @@ | ||
| 262 | 582 | * @return void |
| 263 | 583 | */ |
| 264 | 584 | public function registerScripts() |
| 265 | 585 | { |
| 266 | - wp_register_script( | |
| 267 | - 'firebox-admin', | |
| 268 | - false | |
| 269 | - ); | |
| 586 | + wp_register_script('firebox-admin', false); | |
| 270 | 587 | wp_enqueue_script('firebox-admin'); |
| 271 | 588 | |
| 272 | 589 | $data = array( |
| 273 | - 'media_url' => FBOX_MEDIA_URL, | |
| 274 | - 'admin_url' => get_admin_url() | |
| 590 | + 'campaigns_item_new_url' => admin_url('post-new.php?post_type=firebox'), | |
| 591 | + 'campaigns_list_url' => admin_url('admin.php?page=firebox-campaigns'), | |
| 592 | + 'campaigns_item_edit_url' => admin_url('post.php?post={{ID}}&action=edit'), | |
| 593 | + 'campaigns_item_analytics_url' => admin_url('admin.php?page=firebox-analytics&campaign={{ID}}'), | |
| 594 | + 'campaigns_analytics_url' => admin_url('admin.php?page=firebox-analytics'), | |
| 595 | + 'submissions_page' => admin_url('admin.php?page=firebox-submissions'), | |
| 596 | + 'flags_url' => FBOX_PLUGIN_URL . 'Inc/Framework/media/admin/images/flags/{{FLAG}}.png', | |
| 597 | + 'license_type' => FBOX_LICENSE_TYPE, | |
| 598 | + 'langs' => [ | |
| 599 | + 'CAMPAIGN_INFO' => firebox()->_('FB_CAMPAIGN_INFO'), | |
| 600 | + 'EDIT_CAMPAIGN' => firebox()->_('FB_EDIT_CAMPAIGN'), | |
| 601 | + 'STATUS' => fpframework()->_('FPF_STATUS'), | |
| 602 | + 'CREATED' => fpframework()->_('FPF_CREATED'), | |
| 603 | + 'LAST_VIEWED' => firebox()->_('FB_LAST_VIEWED'), | |
| 604 | + 'ACTIVE' => firebox()->_('FB_ACTIVE'), | |
| 605 | + 'DISABLED' => fpframework()->_('FPF_DISABLED'), | |
| 606 | + 'ID' => fpframework()->_('FPF_ID'), | |
| 607 | + 'CAMPAIGN' => firebox()->_('FB_CAMPAIGN'), | |
| 608 | + 'VIEWS' => firebox()->_('FB_VIEWS'), | |
| 609 | + 'ACTIONS' => firebox()->_('FB_ACTIONS'), | |
| 610 | + 'CONVERSIONS' => firebox()->_('FB_CONVERSIONS'), | |
| 611 | + 'CONVERSION_RATE' => firebox()->_('FB_CONVERSION_RATE'), | |
| 612 | + 'NO_DATA_AVAILABLE' => firebox()->_('FB_NO_DATA_AVAILABLE'), | |
| 613 | + 'COUNTRIES' => fpframework()->_('FPF_COUNTRIES'), | |
| 614 | + 'FLAG' => fpframework()->_('FPF_FLAG'), | |
| 615 | + 'DEVICES' => fpframework()->_('FPF_DEVICES'), | |
| 616 | + 'EVENTS' => fpframework()->_('FPF_EVENTS'), | |
| 617 | + 'PERCENTAGE_DIFFERENCE_AGAINST_PREVIOUS_PERIOD' => firebox()->_('FB_PERCENTAGE_DIFFERENCE_AGAINST_PREVIOUS_PERIOD'), | |
| 618 | + 'NO_CAMPAIGN_DATA_FOUND' => firebox()->_('FB_NO_CAMPAIGN_DATA_FOUND'), | |
| 619 | + 'MOST_POPULAR_CAMPAIGNS' => firebox()->_('FB_MOST_POPULAR_CAMPAIGNS'), | |
| 620 | + 'TOP_CAMPAIGNS' => firebox()->_('FB_TOP_CAMPAIGNS'), | |
| 621 | + 'N/A' => fpframework()->_('FPF_N/A'), | |
| 622 | + 'ALL_DAYS' => firebox()->_('FB_ALL_DAYS'), | |
| 623 | + 'MONDAY' => firebox()->_('FB_MONDAY'), | |
| 624 | + 'TUESDAY' => firebox()->_('FB_TUESDAY'), | |
| 625 | + 'WEDNESDAY' => firebox()->_('FB_WEDNESDAY'), | |
| 626 | + 'THURSDAY' => firebox()->_('FB_THURSDAY'), | |
| 627 | + 'FRIDAY' => firebox()->_('FB_FRIDAY'), | |
| 628 | + 'SATURDAY' => firebox()->_('FB_SATURDAY'), | |
| 629 | + 'SUNDAY' => firebox()->_('FB_SUNDAY'), | |
| 630 | + 'VIEW_HOURS' => firebox()->_('FB_VIEW_HOURS'), | |
| 631 | + 'PATHS' => fpframework()->_('FPF_PATHS'), | |
| 632 | + 'REFERRERS' => fpframework()->_('FPF_REFERRERS'), | |
| 633 | + 'S' => fpframework()->_('FPF_S'), | |
| 634 | + 'VIEW_CAMPAIGN_ANALYTICS' => firebox()->_('FB_VIEW_CAMPAIGN_ANALYTICS'), | |
| 635 | + 'ACTIVATE' => fpframework()->_('FPF_ACTIVATE'), | |
| 636 | + 'DEACTIVATE' => fpframework()->_('FPF_DEACTIVATE'), | |
| 637 | + 'EDIT' => fpframework()->_('FPF_EDIT'), | |
| 638 | + 'DELETE' => fpframework()->_('FPF_DELETE'), | |
| 639 | + 'DUPLICATE' => fpframework()->_('FPF_DUPLICATE'), | |
| 640 | + 'ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_CAMPAIGN' => firebox()->_('FB_ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_CAMPAIGN'), | |
| 641 | + 'RECENT_CAMPAIGNS' => firebox()->_('FB_RECENT_CAMPAIGNS'), | |
| 642 | + 'VIEW_ALL' => firebox()->_('FB_VIEW_ALL'), | |
| 643 | + 'YOU_HAVENT_CREATED_ANY_CAMPAIGNS_YET' => firebox()->_('FB_YOU_HAVENT_CREATED_ANY_CAMPAIGNS_YET'), | |
| 644 | + 'NEW_CAMPAIGN' => firebox()->_('FB_NEW_CAMPAIGN'), | |
| 645 | + 'NUMBER_OF_VIEWS_IN_THE_LAST_30_DAYS' => firebox()->_('FB_NUMBER_OF_VIEWS_IN_THE_LAST_30_DAYS'), | |
| 646 | + 'NUMBER_OF_CONVERSIONS_IN_THE_LAST_30_DAYS' => firebox()->_('FB_NUMBER_OF_CONVERSIONS_IN_THE_LAST_30_DAYS'), | |
| 647 | + 'CONVERSION_RATE_IN_THE_LAST_30_DAYS' => firebox()->_('FB_CONVERSION_RATE_IN_THE_LAST_30_DAYS'), | |
| 648 | + 'LOADING_CAMPAIGNS' => firebox()->_('FB_LOADING_CAMPAIGNS'), | |
| 649 | + 'NO_CAMPAIGNS_FOUND' => firebox()->_('FB_NO_CAMPAIGNS_FOUND'), | |
| 650 | + 'SEARCH_DOTS' => firebox()->_('FB_SEARCH_DOTS'), | |
| 651 | + 'TODAY' => firebox()->_('FB_TODAY'), | |
| 652 | + 'YESTERDAY' => firebox()->_('FB_YESTERDAY'), | |
| 653 | + 'LAST_7_DAYS' => firebox()->_('FB_LAST_7_DAYS'), | |
| 654 | + 'LAST_30_DAYS' => firebox()->_('FB_LAST_30_DAYS'), | |
| 655 | + 'LAST_WEEK' => firebox()->_('FB_LAST_WEEK'), | |
| 656 | + 'LAST_MONTH' => firebox()->_('FB_LAST_MONTH'), | |
| 657 | + 'CUSTOM' => firebox()->_('FB_CUSTOM'), | |
| 658 | + 'AVG_TIME_OPEN_TOOLTIP_DESC' => firebox()->_('FB_AVG_TIME_OPEN_TOOLTIP_DESC'), | |
| 659 | + 'READ_MORE' => firebox()->_('FB_READ_MORE'), | |
| 660 | + 'AVG_TIME_OPEN' => firebox()->_('FB_AVG_TIME_OPEN'), | |
| 661 | + 'CONVERSION_RATE_TOOLTIP_DESC' => firebox()->_('FB_CONVERSION_RATE_TOOLTIP_DESC'), | |
| 662 | + 'CONVERSIONS_TOOLTIP_DESC' => firebox()->_('FB_CONVERSIONS_TOOLTIP_DESC'), | |
| 663 | + 'VS_PREVIOUS_PERIOD' => firebox()->_('FB_VS_PREVIOUS_PERIOD'), | |
| 664 | + 'VIEWS_TOOLTIP_DESC' => firebox()->_('FB_VIEWS_TOOLTIP_DESC'), | |
| 665 | + 'NO' => firebox()->_('FB_NO'), | |
| 666 | + 'DATA_AVAILABLE' => firebox()->_('FB_DATA_AVAILABLE'), | |
| 667 | + 'PERFORMANCE' => firebox()->_('FB_PERFORMANCE'), | |
| 668 | + 'TRENDING_TEMPLATES' => firebox()->_('FB_TRENDING_TEMPLATES'), | |
| 669 | + 'THERE_ARE_NO_TRENDING_TEMPLATES_TO_SHOW' => firebox()->_('FB_THERE_ARE_NO_TRENDING_TEMPLATES_TO_SHOW'), | |
| 670 | + 'INSERT_TEMPLATE' => firebox()->_('FB_INSERT_TEMPLATE'), | |
| 671 | + 'INSERT' => firebox()->_('FB_INSERT'), | |
| 672 | + 'VIEW_ALL_ANALYTICS' => firebox()->_('FB_VIEW_ALL_ANALYTICS'), | |
| 673 | + 'DAILY' => firebox()->_('FB_DAILY'), | |
| 674 | + 'WEEKLY' => firebox()->_('FB_WEEKLY'), | |
| 675 | + 'MONTHLY' => firebox()->_('FB_MONTHLY'), | |
| 676 | + 'UPGRADE_TO_PRO' => fpframework()->_('FPF_UPGRADE_TO_PRO'), | |
| 677 | + 'ALL_CAMPAIGNS' => firebox()->_('FB_ALL_CAMPAIGNS'), | |
| 678 | + 'OVERVIEW' => fpframework()->_('FPF_OVERVIEW'), | |
| 679 | + 'TO' => fpframework()->_('FPF_TO'), | |
| 680 | + 'SHOWING_TOP_30_RESULTS' => firebox()->_('FB_SHOWING_TOP_30_RESULTS'), | |
| 681 | + 'DAY_OF_THE_WEEK' => firebox()->_('FB_DAY_OF_THE_WEEK'), | |
| 682 | + 'ANALYTICS' => fpframework()->_('FPF_ANALYTICS') | |
| 683 | + ] | |
| 275 | 684 | ); |
| 276 | 685 | |
| 277 | 686 | wp_localize_script('firebox-admin', 'fbox_admin_js_object', $data); |
| 687 | + } | |
| 688 | + | |
| 689 | + /** | |
| 690 | + * Returns the timezone in format: +-XX:XX | |
| 691 | + * | |
| 692 | + * @return string | |
| 693 | + */ | |
| 694 | + private function getTimezone() | |
| 695 | + { | |
| 696 | + $offset = get_option('gmt_offset'); | |
| 697 | + $hours = (int) $offset; | |
| 698 | + $minutes = abs(($offset - (int) $offset) * 60); | |
| 699 | + return sprintf('%+03d:%02d', $hours, $minutes); | |
| 278 | 700 | } |
| 279 | 701 | } |