| 1 |
<?php |
| 2 |
|
| 3 |
namespace Tableberg\Admin; |
| 4 |
|
| 5 |
use Tableberg; |
| 6 |
|
| 7 |
class Tableberg_Admin { |
| 8 |
private $plugin_url; |
| 9 |
|
| 10 |
public function __construct() { |
| 11 |
|
| 12 |
$this->plugin_name = 'tableberg'; |
| 13 |
$this->plugin_url = TABLEBERG_URL; |
| 14 |
|
| 15 |
add_action('wp_ajax_tableberg_toggle_control', [$this, 'update_toggle_control']); |
| 16 |
add_action('wp_ajax_tableberg_block_properties', [$this, 'update_block_properties']); |
| 17 |
|
| 18 |
add_action('admin_menu', [$this, 'register_admin_menus']); |
| 19 |
add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_script']); |
| 20 |
add_action('admin_notices', [$this, 'tableberg_review_notice']); |
| 21 |
add_action('wp_ajax_TablebergReviewNoticeHide', [$this, 'tableberg_hide_review_notify']); |
| 22 |
add_filter('tableberg/filter/admin_settings_menu_data', [$this, 'add_settings_menu_data'], 1, 1); |
| 23 |
} |
| 24 |
|
| 25 |
private function update_block_properties() { |
| 26 |
if ( |
| 27 |
check_ajax_referer('block_properties') && |
| 28 |
isset($_POST['value']) && |
| 29 |
isset($_POST['property_name']) && |
| 30 |
current_user_can('manage_options') |
| 31 |
) { |
| 32 |
$value = sanitize_text_field(wp_unslash($_POST['value'])); |
| 33 |
$property_name = sanitize_text_field(wp_unslash($_POST['property_name'])); |
| 34 |
$saved_properties = get_option('tableberg_block_properties', false); |
| 35 |
if ($saved_properties) { |
| 36 |
foreach ($saved_properties as $key => $property) { |
| 37 |
if ($property['name'] === $property_name) { |
| 38 |
$saved_properties[$key]['value'] = (int) $value; |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
update_option('tableberg_block_properties', $saved_properties); |
| 44 |
} |
| 45 |
|
| 46 |
die(); |
| 47 |
} |
| 48 |
|
| 49 |
private function update_toggle_control() { |
| 50 |
|
| 51 |
if ( |
| 52 |
check_ajax_referer('toggle_control') && |
| 53 |
isset($_POST['enable']) && |
| 54 |
isset($_POST['toggle_name']) && |
| 55 |
current_user_can('manage_options') |
| 56 |
) { |
| 57 |
$enable = sanitize_text_field(wp_unslash($_POST['enable'])); |
| 58 |
$toggle_name = sanitize_text_field(wp_unslash($_POST['toggle_name'])); |
| 59 |
update_option($toggle_name, $enable); |
| 60 |
} |
| 61 |
die(); |
| 62 |
} |
| 63 |
|
| 64 |
public function add_settings_menu_data($data) { |
| 65 |
$data['assets'] = [ |
| 66 |
'logo' => trailingslashit($this->plugin_url) . 'includes/Admin/images/logos/menu-icon-colored.svg', |
| 67 |
'logoTransparent' => trailingslashit($this->plugin_url) . 'includes/Admin/images/logos/menu-icon-colored-transparent.svg', |
| 68 |
]; |
| 69 |
|
| 70 |
$data['individual_control'] = [ |
| 71 |
'data' => get_option('tableberg_individual_control', false), |
| 72 |
'ajax' => [ |
| 73 |
'toggleControl' => [ |
| 74 |
'url' => admin_url('admin-ajax.php'), |
| 75 |
'action' => 'tableberg_toggle_control', |
| 76 |
'nonce' => wp_create_nonce('toggle_control'), |
| 77 |
], |
| 78 |
], |
| 79 |
]; |
| 80 |
$data['global_control'] = [ |
| 81 |
'data' => get_option('tableberg_global_control', false), |
| 82 |
'ajax' => [ |
| 83 |
'toggleControl' => [ |
| 84 |
'url' => admin_url('admin-ajax.php'), |
| 85 |
'action' => 'tableberg_toggle_control', |
| 86 |
'nonce' => wp_create_nonce('toggle_control'), |
| 87 |
], |
| 88 |
], |
| 89 |
]; |
| 90 |
$data['block_properties'] = [ |
| 91 |
'data' => get_option('tableberg_block_properties', false), |
| 92 |
'ajax' => [ |
| 93 |
'blockProperties' => [ |
| 94 |
'url' => admin_url('admin-ajax.php'), |
| 95 |
'action' => 'tableberg_block_properties', |
| 96 |
'nonce' => wp_create_nonce('block_properties'), |
| 97 |
], |
| 98 |
], |
| 99 |
]; |
| 100 |
|
| 101 |
global $tp_fs; |
| 102 |
if (isset($tp_fs)) { |
| 103 |
$data['misc'] = [ |
| 104 |
'pro_status' => $tp_fs->is__premium_only() |
| 105 |
&& $tp_fs->can_use_premium_code(), |
| 106 |
]; |
| 107 |
} else { |
| 108 |
$data['misc'] = [ |
| 109 |
'pro_status' => false, |
| 110 |
]; |
| 111 |
} |
| 112 |
|
| 113 |
$data = array_merge($data, $this->welcome_page()); |
| 114 |
return $data; |
| 115 |
} |
| 116 |
|
| 117 |
public function enqueue_admin_script() { |
| 118 |
$tableberg_assets = new Tableberg\Assets(); |
| 119 |
$tableberg_assets->register_admin_assets(); |
| 120 |
} |
| 121 |
|
| 122 |
public static function welcome_page() { |
| 123 |
return [ |
| 124 |
'welcome' => [ |
| 125 |
'title' => 'Welcome to Tableberg!', |
| 126 |
'content' => 'Elevate Your Content with Seamless Tables - The Ultimate WordPress Block Editor Plugin for Effortless Table Creation!', |
| 127 |
], |
| 128 |
'documentation' => [ |
| 129 |
'title' => 'Documentation', |
| 130 |
'content' => 'Elevate your space with Tableberg: a sleek, modern table block for style and functionality. Crafted for timeless elegance and versatility.', |
| 131 |
], |
| 132 |
'support' => [ |
| 133 |
'title' => 'Support', |
| 134 |
'content' => "Visit our Tableberg Support Page for quick solutions and assistance. We're here to ensure your Tableberg experience is seamless and satisfying.", |
| 135 |
], |
| 136 |
'community' => [ |
| 137 |
'title' => 'Join Community', |
| 138 |
'content' => 'Join the vibrant Tableberg community. Connect, share, and discover endless possibilities together. Elevate your experience with like-minded enthusiasts now!', |
| 139 |
], |
| 140 |
'upgrade' => [ |
| 141 |
'title' => 'Upgrade to Tableberg PRO!', |
| 142 |
'content' => 'Elevate Your Content with Seamless Tables - The Ultimate WordPress Block Editor Plugin for Effortless Table Creation!', |
| 143 |
], |
| 144 |
]; |
| 145 |
} |
| 146 |
|
| 147 |
public function main_menu_template_cb() { |
| 148 |
?> |
| 149 |
<div id="tableberg-admin-menu"></div> |
| 150 |
<?php |
| 151 |
} |
| 152 |
|
| 153 |
public function register_admin_menus() { |
| 154 |
global $menu_page; |
| 155 |
global $menu_page_slug; |
| 156 |
|
| 157 |
$menu_page_slug = 'tableberg-settings'; |
| 158 |
$menu_page = add_menu_page( |
| 159 |
__('Tableberg Settings', 'tableberg'), |
| 160 |
__('Tableberg', 'tableberg'), |
| 161 |
'manage_options', |
| 162 |
$menu_page_slug, |
| 163 |
[$this, 'main_menu_template_cb'], |
| 164 |
plugin_dir_url(__FILE__) . 'images/logos/menu-icon.svg' |
| 165 |
); |
| 166 |
} |
| 167 |
|
| 168 |
public static function tableberg_review_notice() { |
| 169 |
$install_date = get_option('tableberg_installDate'); |
| 170 |
$display_date = date('Y-m-d h:i:s'); |
| 171 |
$datetime1 = new \DateTime($install_date); |
| 172 |
$datetime2 = new \DateTime($display_date); |
| 173 |
$diff_interval = round(($datetime2->format('U') - $datetime1->format('U')) / (60 * 60 * 24)); |
| 174 |
|
| 175 |
if ($diff_interval >= 21 && get_option('tableberg_review_notify') == 'no') { |
| 176 |
?> |
| 177 |
<div class="tableberg-review-notice notice notice-info" style="display: inline-block; position: relative; padding:0.5rem 1.5rem"> |
| 178 |
<button type="button" class="notice-dismiss Tableberg_HideReview_Notice" style="position: absolute; top: 2px; right: 2px;"> |
| 179 |
<span class="screen-reader-text"><?php esc_html_e('Dismiss this notice.', 'tableberg'); ?></span> |
| 180 |
</button> |
| 181 |
<p style="font-size: 14px; line-height: 2;padding-right:2rem"> |
| 182 |
<?php |
| 183 |
echo wp_kses_post(__( |
| 184 |
'Hello! Seems like you\'ve been using <strong>Tableberg</strong> for a while on your website. That\'s awesome!<br>If you can spare a few moments to rate it on wordpress.org, it would help us a lot (and boost my motivation).<br>Imtiaz Rayhan, developer of Tableberg', |
| 185 |
'tableberg' |
| 186 |
)); |
| 187 |
?> |
| 188 |
</p> |
| 189 |
<ul style="list-style-type: none; padding: 0;"> |
| 190 |
<li> |
| 191 |
<a style="margin-right: 5px; margin-bottom: 5px;" class="button-primary" href="https://wordpress.org/support/plugin/tableberg/reviews/" target="_blank"><?php esc_html_e('Ok, I will gladly help!', 'tableberg'); ?></a> |
| 192 |
<a class="Tableberg_HideReview_Notice button" href="javascript:void(0);"><?php esc_html_e('No, thanks', 'tableberg'); ?></a> |
| 193 |
</li> |
| 194 |
</ul> |
| 195 |
</div> |
| 196 |
<script> |
| 197 |
jQuery(document).ready(function($) { |
| 198 |
$('.Tableberg_HideReview_Notice').click(function() { |
| 199 |
var data = { |
| 200 |
'action': 'TablebergReviewNoticeHide' |
| 201 |
}; |
| 202 |
$.ajax({ |
| 203 |
url: "<?php echo esc_url(admin_url('admin-ajax.php')); ?>", |
| 204 |
type: "post", |
| 205 |
data: data, |
| 206 |
dataType: "json", |
| 207 |
async: true, |
| 208 |
success: function(notice_hide) { |
| 209 |
if (notice_hide == "success") { |
| 210 |
$('.tableberg-review-notice').slideUp('fast'); |
| 211 |
} |
| 212 |
} |
| 213 |
}); |
| 214 |
}); |
| 215 |
}); |
| 216 |
</script> |
| 217 |
<?php |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
public function tableberg_hide_review_notify() { |
| 223 |
update_option('tableberg_review_notify', 'yes'); |
| 224 |
echo wp_json_encode(['success']); |
| 225 |
exit; |
| 226 |
} |
| 227 |
} |
| 228 |
|