| 1 |
<?php |
| 2 |
namespace FileBird\Page; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
/** |
| 6 |
* Settings Page |
| 7 |
*/ |
| 8 |
class Settings { |
| 9 |
protected static $instance = null; |
| 10 |
private $pageId = null; |
| 11 |
public $settingPageSuffix = ''; |
| 12 |
|
| 13 |
public static function getInstance() { |
| 14 |
if ( null == self::$instance ) { |
| 15 |
self::$instance = new self(); |
| 16 |
self::$instance->doHooks(); |
| 17 |
} |
| 18 |
|
| 19 |
return self::$instance; |
| 20 |
} |
| 21 |
|
| 22 |
private function doHooks() { |
| 23 |
add_filter( 'plugin_action_links_' . NJFB_PLUGIN_BASE_NAME, array( $this, 'addActionLinks' ) ); |
| 24 |
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); |
| 25 |
|
| 26 |
add_action( 'admin_init', array( $this, 'registerSettings' ) ); |
| 27 |
add_action( 'admin_footer', array( $this, 'adminFooter' ) ); |
| 28 |
add_action( 'admin_menu', array( $this, 'settingsMenu' ) ); |
| 29 |
} |
| 30 |
|
| 31 |
public function settingsMenu() { |
| 32 |
$filebirdIcon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTEwLDRINEMyLjg5LDQgMiw0Ljg5IDIsNlYxOEEyLDIgMCAwLDAgNCwyMEgyMEEyLDIgMCAwLDAgMjIsMThWOEMyMiw2Ljg5IDIxLjEsNiAyMCw2SDEyTDEwLDRaIiBmaWxsPSIjYTdhYWFkIi8+PC9zdmc+'; |
| 33 |
|
| 34 |
add_menu_page( 'FileBird', 'FileBird', 'manage_options', 'filebird-settings', null, $filebirdIcon ); |
| 35 |
|
| 36 |
$this->settingPageSuffix = add_submenu_page( 'filebird-settings', __( 'FileBird Settings', 'filebird' ), __( 'FileBird Settings', 'filebird' ), 'manage_options', 'filebird-settings', array( $this, 'settingsPage' ), 0 ); |
| 37 |
add_submenu_page( |
| 38 |
'filebird-settings', |
| 39 |
'', |
| 40 |
'<span>' . __( 'Go Pro', 'filebird' ) . '</span>', |
| 41 |
'manage_options', |
| 42 |
'go_filebird_pro', |
| 43 |
array( $this, 'goProRedirects' ), |
| 44 |
100 |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
public function adminFooter() { |
| 49 |
?> |
| 50 |
<style> |
| 51 |
body.admin-color-fresh #adminmenu #toplevel_page_filebird-settings a[href="admin.php?page=go_filebird_pro"] { |
| 52 |
color: #00BC28; |
| 53 |
font-weight: bold; |
| 54 |
position: relative; |
| 55 |
} |
| 56 |
|
| 57 |
body.admin-color-fresh #adminmenu #toplevel_page_filebird-settings a[href="admin.php?page=go_filebird_pro"]::after { |
| 58 |
content: ''; |
| 59 |
position: absolute; |
| 60 |
width: 4px; |
| 61 |
top: 0; |
| 62 |
bottom: 0; |
| 63 |
left: 0; |
| 64 |
background: green; |
| 65 |
} |
| 66 |
</style> |
| 67 |
<script> |
| 68 |
jQuery(document).ready(function() { |
| 69 |
jQuery('#toplevel_page_filebird-settings a[href="admin.php?page=go_filebird_pro"]').click(function(event) { |
| 70 |
event.preventDefault() |
| 71 |
window.open('https://1.envato.market/GoPro-FileBird-Premium', '_blank') |
| 72 |
}) |
| 73 |
}) |
| 74 |
</script> |
| 75 |
<?php |
| 76 |
} |
| 77 |
|
| 78 |
public function goProRedirects() { |
| 79 |
if ( empty( $_GET['page'] ) ) { |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
if ( 'go_filebird_pro' === $_GET['page'] ) { |
| 84 |
// wp_redirect( 'https://1.envato.market/GoPro-FileBird-Premium' ); |
| 85 |
?> |
| 86 |
<script>window.location.href = "https://1.envato.market/GoPro-FileBird-Premium"</script> |
| 87 |
<?php |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
public function settingsPage() { |
| 92 |
include_once NJFB_PLUGIN_PATH . 'views/pages/html-settings.php'; |
| 93 |
} |
| 94 |
|
| 95 |
public function plugin_row_meta( $links, $file ) { |
| 96 |
if ( strpos( $file, 'filebird.php' ) !== false ) { |
| 97 |
$new_links = array( |
| 98 |
'doc' => '<a href="https://ninjateam.gitbook.io/filebird/" target="_blank">' . __( 'Documentation', 'filebird' ) . '</a>', |
| 99 |
); |
| 100 |
|
| 101 |
$links = array_merge( $links, $new_links ); |
| 102 |
} |
| 103 |
|
| 104 |
return $links; |
| 105 |
} |
| 106 |
|
| 107 |
public function addActionLinks( $links ) { |
| 108 |
$settingsLinks = array( |
| 109 |
'<a href="' . admin_url( 'admin.php?page=' . $this->getPageId() ) . '">' . esc_html__( 'Settings', 'filebird' ) . '</a>', |
| 110 |
); |
| 111 |
|
| 112 |
$links[] = '<a target="_blank" href="https://1.envato.market/FileBirdPro" style="color: #43B854; font-weight: bold">' . __( 'Go Pro', 'filebird' ) . '</a>'; |
| 113 |
return array_merge( $settingsLinks, $links ); |
| 114 |
} |
| 115 |
|
| 116 |
public function getPageId() { |
| 117 |
if ( null == $this->pageId ) { |
| 118 |
$this->pageId = NJFB_PREFIX . '-settings'; |
| 119 |
} |
| 120 |
|
| 121 |
return $this->pageId; |
| 122 |
} |
| 123 |
public function registerSettings() { |
| 124 |
$settings = array( |
| 125 |
'njt_fbv_folder_per_user', |
| 126 |
'njt_fbv_allow_svg_upload', |
| 127 |
'njt_fbv_default_folder', |
| 128 |
); |
| 129 |
foreach ( $settings as $k => $v ) { |
| 130 |
register_setting( 'njt_fbv', $v ); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|