| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) exit; |
| 4 |
if (!class_exists('WPRWPAdmin')) : |
| 5 |
|
| 6 |
class WPRWPAdmin { |
| 7 |
public $settings; |
| 8 |
public $siteinfo; |
| 9 |
public $bvinfo; |
| 10 |
public $bvapi; |
| 11 |
|
| 12 |
function __construct($settings, $siteinfo, $bvapi = null) { |
| 13 |
$this->settings = $settings; |
| 14 |
$this->siteinfo = $siteinfo; |
| 15 |
$this->bvapi = new WPRWPAPI($settings); |
| 16 |
$this->bvinfo = new WPRInfo($this->settings); |
| 17 |
} |
| 18 |
|
| 19 |
public function mainUrl($_params = '') { |
| 20 |
if (function_exists('network_admin_url')) { |
| 21 |
return network_admin_url('admin.php?page='.$this->bvinfo->plugname.$_params); |
| 22 |
} else { |
| 23 |
return admin_url('admin.php?page='.$this->bvinfo->plugname.$_params); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
function removeAdminNotices() { |
| 28 |
if (array_key_exists('page', $_REQUEST) && $_REQUEST['page'] == $this->bvinfo->plugname) { |
| 29 |
remove_all_actions('admin_notices'); |
| 30 |
remove_all_actions('all_admin_notices'); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
public function initHandler() { |
| 35 |
if (!current_user_can('activate_plugins')) |
| 36 |
return; |
| 37 |
|
| 38 |
if (array_key_exists('bvnonce', $_REQUEST) && |
| 39 |
wp_verify_nonce($_REQUEST['bvnonce'], "bvnonce") && |
| 40 |
array_key_exists('blogvaultkey', $_REQUEST) && |
| 41 |
(strlen(WPRAccount::sanitizeKey($_REQUEST['blogvaultkey'])) == 64) && |
| 42 |
(array_key_exists('page', $_REQUEST) && |
| 43 |
$_REQUEST['page'] == $this->bvinfo->plugname)) { |
| 44 |
$keys = str_split($_REQUEST['blogvaultkey'], 32); |
| 45 |
WPRAccount::addAccount($this->settings, $keys[0], $keys[1]); |
| 46 |
if (array_key_exists('redirect', $_REQUEST)) { |
| 47 |
$location = $_REQUEST['redirect']; |
| 48 |
wp_redirect($this->bvinfo->appUrl()."/dash/redir?q=".urlencode($location)); |
| 49 |
exit(); |
| 50 |
} |
| 51 |
} |
| 52 |
if ($this->bvinfo->isActivateRedirectSet()) { |
| 53 |
$this->settings->updateOption($this->bvinfo->plug_redirect, 'no'); |
| 54 |
##ACTIVATEREDIRECTCODE## |
| 55 |
if (!wp_doing_ajax()) { |
| 56 |
wp_redirect($this->mainUrl()); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
public function wprsecAdminMenu($hook) { |
| 62 |
if ($hook === 'toplevel_page_wpremote' || WPRHelper::safePregMatch("/wpr_add_account$/", $hook) || WPRHelper::safePregMatch("/wpr_account_details$/", $hook)) { |
| 63 |
wp_enqueue_style( 'bootstrap', plugins_url('css/bootstrap.min.css', __FILE__)); |
| 64 |
wp_enqueue_style( 'bvplugin', plugins_url('css/bvplugin.min.css', __FILE__)); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
public function menu() { |
| 69 |
$brand = $this->bvinfo->getPluginWhitelabelInfo(); |
| 70 |
if (!array_key_exists('hide', $brand) && !array_key_exists('hide_from_menu', $brand)) { |
| 71 |
$bname = $this->bvinfo->getBrandName(); |
| 72 |
$icon = $this->bvinfo->getBrandIcon(); |
| 73 |
add_menu_page($bname, $bname, 'manage_options', $this->bvinfo->plugname, |
| 74 |
array($this, 'adminPage'), plugins_url($icon, __FILE__ )); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
public function hidePluginUpdate($plugins) { |
| 79 |
if (!$this->bvinfo->canWhiteLabel()) { |
| 80 |
return $plugins; |
| 81 |
} |
| 82 |
$whitelabel_infos = $this->bvinfo->getPluginsWhitelabelInfos(); |
| 83 |
foreach ($whitelabel_infos as $slug => $brand) { |
| 84 |
if ($this->bvinfo->canWhiteLabel($slug) && isset($plugins->response[$slug]) && is_array($brand)) { |
| 85 |
if (array_key_exists('hide_from_menu', $brand) || array_key_exists('hide', $brand)) { |
| 86 |
unset($plugins->response[$slug]); |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
return $plugins; |
| 91 |
} |
| 92 |
|
| 93 |
public function hidePluginDetails($plugin_metas, $slug) { |
| 94 |
if (!is_array($plugin_metas) || !$this->bvinfo->canWhiteLabel($slug)) { |
| 95 |
return $plugin_metas; |
| 96 |
} |
| 97 |
$whitelabel_info = $this->bvinfo->getPluginWhitelabelInfo($slug); |
| 98 |
if (array_key_exists('hide_plugin_details', $whitelabel_info)) { |
| 99 |
foreach ($plugin_metas as $pluginKey => $pluginValue) { |
| 100 |
if (strpos($pluginValue, sprintf('>%s<', translate('View details')))) { |
| 101 |
unset($plugin_metas[$pluginKey]); |
| 102 |
break; |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
return $plugin_metas; |
| 107 |
} |
| 108 |
|
| 109 |
public function handlePluginHealthInfo($plugins) { |
| 110 |
if (!isset($plugins["wp-plugins-active"]) || |
| 111 |
!isset($plugins["wp-plugins-active"]["fields"]) || !$this->bvinfo->canWhiteLabel()) { |
| 112 |
return $plugins; |
| 113 |
} |
| 114 |
|
| 115 |
$whitelabel_infos_by_title = $this->bvinfo->getPluginsWhitelabelInfoByTitle(); |
| 116 |
|
| 117 |
foreach ($whitelabel_infos_by_title as $title => $brand) { |
| 118 |
if (is_array($brand) && array_key_exists('slug', $brand) && $this->bvinfo->canWhiteLabel($brand["slug"])) { |
| 119 |
if (array_key_exists('hide', $brand)) { |
| 120 |
unset($plugins["wp-plugins-active"]["fields"][$title]); |
| 121 |
} else { |
| 122 |
$plugin = $plugins["wp-plugins-active"]["fields"][$title]; |
| 123 |
$author = $brand['default_author']; |
| 124 |
if (array_key_exists('name', $brand)) { |
| 125 |
$plugin["label"] = $brand['name']; |
| 126 |
} |
| 127 |
if (array_key_exists('author', $brand)) { |
| 128 |
$plugin["value"] = str_replace($author, $brand['author'], $plugin["value"]); |
| 129 |
} |
| 130 |
if (array_key_exists('description', $brand)) { |
| 131 |
$plugin["debug"] = str_replace($author, $brand['author'], $plugin["debug"]); |
| 132 |
} |
| 133 |
$plugins["wp-plugins-active"]["fields"][$title] = $plugin; |
| 134 |
} |
| 135 |
} |
| 136 |
} |
| 137 |
return $plugins; |
| 138 |
} |
| 139 |
|
| 140 |
public function settingsLink($links, $file) { |
| 141 |
#XNOTE: Fix this |
| 142 |
if ( $file == plugin_basename( dirname(__FILE__).'/plugin.php' ) ) { |
| 143 |
$brand = $this->bvinfo->getPluginWhitelabelInfo(); |
| 144 |
if (!array_key_exists('hide_plugin_details', $brand)) { |
| 145 |
$links[] = '<a href="'.$this->mainUrl().'">'.__( 'Settings' ).'</a>'; |
| 146 |
} |
| 147 |
} |
| 148 |
return $links; |
| 149 |
} |
| 150 |
|
| 151 |
public function getPluginLogo() { |
| 152 |
$brand = $this->bvinfo->getPluginWhitelabelInfo(); |
| 153 |
if (array_key_exists('logo', $brand)) { |
| 154 |
return $brand['logo']; |
| 155 |
} |
| 156 |
return $this->bvinfo->logo; |
| 157 |
} |
| 158 |
|
| 159 |
public function getWebPage() { |
| 160 |
$brand = $this->bvinfo->getPluginWhitelabelInfo(); |
| 161 |
if (array_key_exists('webpage', $brand)) { |
| 162 |
return $brand['webpage']; |
| 163 |
} |
| 164 |
return $this->bvinfo->webpage; |
| 165 |
} |
| 166 |
|
| 167 |
public function siteInfoTags() { |
| 168 |
require_once dirname( __FILE__ ) . '/recover.php'; |
| 169 |
$bvnonce = wp_create_nonce("bvnonce"); |
| 170 |
$public = WPRAccount::getApiPublicKey($this->settings); |
| 171 |
$secret = WPRRecover::defaultSecret($this->settings); |
| 172 |
$tags = "<input type='hidden' name='url' value='".esc_attr($this->siteinfo->wpurl())."'/>\n". |
| 173 |
"<input type='hidden' name='homeurl' value='".esc_attr($this->siteinfo->homeurl())."'/>\n". |
| 174 |
"<input type='hidden' name='siteurl' value='".esc_attr($this->siteinfo->siteurl())."'/>\n". |
| 175 |
"<input type='hidden' name='dbsig' value='".esc_attr($this->siteinfo->dbsig(false))."'/>\n". |
| 176 |
"<input type='hidden' name='plug' value='".esc_attr($this->bvinfo->plugname)."'/>\n". |
| 177 |
"<input type='hidden' name='adminurl' value='".esc_attr($this->mainUrl())."'/>\n". |
| 178 |
"<input type='hidden' name='bvversion' value='".esc_attr($this->bvinfo->version)."'/>\n". |
| 179 |
"<input type='hidden' name='serverip' value='".esc_attr($_SERVER["SERVER_ADDR"])."'/>\n". |
| 180 |
"<input type='hidden' name='abspath' value='".esc_attr(ABSPATH)."'/>\n". |
| 181 |
"<input type='hidden' name='secret' value='".esc_attr($secret)."'/>\n". |
| 182 |
"<input type='hidden' name='public' value='".esc_attr($public)."'/>\n". |
| 183 |
"<input type='hidden' name='bvnonce' value='".esc_attr($bvnonce)."'/>\n"; |
| 184 |
return $tags; |
| 185 |
} |
| 186 |
|
| 187 |
public function activateWarning() { |
| 188 |
global $hook_suffix; |
| 189 |
if (!WPRAccount::isConfigured($this->settings) && $hook_suffix == 'index.php' ) { |
| 190 |
?> |
| 191 |
<div id="message" class="updated" style="padding: 8px; font-size: 16px; background-color: #dff0d8"> |
| 192 |
<a class="button-primary" href="<?php echo esc_url($this->mainUrl()); ?>">Activate WPRemote</a> |
| 193 |
<b>Almost Done:</b> Activate your WPRemote account to backup & secure your site. |
| 194 |
</div> |
| 195 |
<?php |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
public function showAddAccountPage() { |
| 200 |
require_once dirname( __FILE__ ) . "/admin/add_new_account.php"; |
| 201 |
} |
| 202 |
|
| 203 |
public function showAccountDetailsPage() { |
| 204 |
require_once dirname( __FILE__ ) . "/admin/account_details.php"; |
| 205 |
} |
| 206 |
|
| 207 |
public function adminPage() { |
| 208 |
if (isset($_REQUEST['bvnonce']) && wp_verify_nonce( $_REQUEST['bvnonce'], 'bvnonce' )) { |
| 209 |
$info = array(); |
| 210 |
$this->siteinfo->basic($info); |
| 211 |
$this->bvapi->pingbv('/bvapi/disconnect', $info, $_REQUEST['pubkey']); |
| 212 |
WPRAccount::remove($this->settings, $_REQUEST['pubkey']); |
| 213 |
} |
| 214 |
if (WPRAccount::isConfigured($this->settings)) { |
| 215 |
if (!isset($_REQUEST['add_account'])) { |
| 216 |
$this->showAccountDetailsPage(); |
| 217 |
} else { |
| 218 |
$this->showAddAccountPage(); |
| 219 |
} |
| 220 |
} else { |
| 221 |
$this->showAddAccountPage(); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
public function initWhitelabel($plugins) { |
| 226 |
if (!is_array($plugins) || !$this->bvinfo->canWhiteLabel()) { |
| 227 |
return $plugins; |
| 228 |
} |
| 229 |
$whitelabel_infos = $this->bvinfo->getPluginsWhitelabelInfos(); |
| 230 |
foreach ($whitelabel_infos as $slug => $brand) { |
| 231 |
if (!isset($slug) || !$this->bvinfo->canWhiteLabel($slug) || !array_key_exists($slug, $plugins) || !is_array($brand)) { |
| 232 |
continue; |
| 233 |
} |
| 234 |
if (array_key_exists('hide', $brand)) { |
| 235 |
unset($plugins[$slug]); |
| 236 |
} else { |
| 237 |
if (array_key_exists('name', $brand)) { |
| 238 |
$plugins[$slug]['Name'] = $brand['name']; |
| 239 |
} |
| 240 |
if (array_key_exists('title', $brand)) { |
| 241 |
$plugins[$slug]['Title'] = $brand['title']; |
| 242 |
} |
| 243 |
if (array_key_exists('description', $brand)) { |
| 244 |
$plugins[$slug]['Description'] = $brand['description']; |
| 245 |
} |
| 246 |
if (array_key_exists('authoruri', $brand)) { |
| 247 |
$plugins[$slug]['AuthorURI'] = $brand['authoruri']; |
| 248 |
} |
| 249 |
if (array_key_exists('author', $brand)) { |
| 250 |
$plugins[$slug]['Author'] = $brand['author']; |
| 251 |
} |
| 252 |
if (array_key_exists('authorname', $brand)) { |
| 253 |
$plugins[$slug]['AuthorName'] = $brand['authorname']; |
| 254 |
} |
| 255 |
if (array_key_exists('pluginuri', $brand)) { |
| 256 |
$plugins[$slug]['PluginURI'] = $brand['pluginuri']; |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
return $plugins; |
| 261 |
} |
| 262 |
} |
| 263 |
endif; |