| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) exit; |
| 4 |
if (!class_exists('WPCOMWPAdmin')) : |
| 5 |
class WPCOMWPAdmin { |
| 6 |
public $settings; |
| 7 |
public $siteinfo; |
| 8 |
public $bvinfo; |
| 9 |
public $bvapi; |
| 10 |
|
| 11 |
function __construct($settings, $siteinfo, $bvapi = null) { |
| 12 |
$this->settings = $settings; |
| 13 |
$this->siteinfo = $siteinfo; |
| 14 |
$this->bvapi = $bvapi; |
| 15 |
$this->bvinfo = new WPCOMInfo($this->settings); |
| 16 |
} |
| 17 |
|
| 18 |
public function mainUrl($_params = '') { |
| 19 |
if (function_exists('network_admin_url')) { |
| 20 |
return network_admin_url('admin.php?page='.$this->bvinfo->plugname.$_params); |
| 21 |
} else { |
| 22 |
return admin_url('admin.php?page='.$this->bvinfo->plugname.$_params); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
function removeAdminNotices() { |
| 27 |
if (WPCOMHelper::getRawParam('REQUEST', 'page') === $this->bvinfo->plugname) { |
| 28 |
remove_all_actions('admin_notices'); |
| 29 |
remove_all_actions('all_admin_notices'); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
public function initHandler() { |
| 34 |
if (!current_user_can('activate_plugins')) |
| 35 |
return; |
| 36 |
|
| 37 |
if ($this->bvinfo->isActivateRedirectSet()) { |
| 38 |
$this->settings->updateOption($this->bvinfo->plug_redirect, 'no'); |
| 39 |
if (!wp_doing_ajax()) { |
| 40 |
wp_redirect($this->mainUrl()); |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
public function menu() { |
| 46 |
$brand = $this->bvinfo->getBrandInfo(); |
| 47 |
if (!is_array($brand) || (!array_key_exists('hide', $brand) && !array_key_exists('hide_from_menu', $brand))) { |
| 48 |
$bname = $this->bvinfo->getBrandName(); |
| 49 |
$icon = $this->bvinfo->getBrandIcon(); |
| 50 |
add_menu_page($bname, $bname, 'manage_options', $this->bvinfo->plugname, |
| 51 |
array($this, 'adminPage'), $icon); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
public function hidePluginDetails($plugin_metas, $slug) { |
| 56 |
$brand = $this->bvinfo->getBrandInfo(); |
| 57 |
$bvslug = $this->bvinfo->slug; |
| 58 |
|
| 59 |
if ($slug === $bvslug && is_array($brand) && array_key_exists('hide_plugin_details', $brand)) { |
| 60 |
foreach ($plugin_metas as $pluginKey => $pluginValue) { |
| 61 |
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain |
| 62 |
if (strpos($pluginValue, sprintf('>%s<', __('View details')))) { |
| 63 |
unset($plugin_metas[$pluginKey]); |
| 64 |
break; |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
return $plugin_metas; |
| 69 |
} |
| 70 |
|
| 71 |
public function settingsLink($links, $file) { |
| 72 |
if ( $file == plugin_basename( dirname(__FILE__).'/wpcom_migration.php' ) ) { |
| 73 |
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain |
| 74 |
$links[] = '<a href="'.$this->mainUrl().'">'.__( 'Settings' ).'</a>'; |
| 75 |
} |
| 76 |
return $links; |
| 77 |
} |
| 78 |
|
| 79 |
public function wpcomsecAdminMenu($hook) { |
| 80 |
if ($hook === 'toplevel_page_wpcom-migration') { |
| 81 |
wp_enqueue_style('wpcom-variables', plugins_url('assets/css/variables.css', __FILE__), array(), $this->bvinfo->version); |
| 82 |
wp_enqueue_style('wpcom-styles', plugins_url('assets/css/style.css', __FILE__), array(), $this->bvinfo->version); |
| 83 |
wp_enqueue_style('wpcom-fonts', plugins_url('assets/css/fonts.css', __FILE__), array(), $this->bvinfo->version); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
public function getPluginLogo() { |
| 88 |
$brand = $this->bvinfo->getBrandInfo(); |
| 89 |
if ($brand && array_key_exists('logo', $brand)) { |
| 90 |
return $brand['logo']; |
| 91 |
} |
| 92 |
return $this->bvinfo->logo; |
| 93 |
} |
| 94 |
|
| 95 |
public function getWebPage() { |
| 96 |
$brand = $this->bvinfo->getBrandInfo(); |
| 97 |
if ($brand && array_key_exists('webpage', $brand)) { |
| 98 |
return $brand['webpage']; |
| 99 |
} |
| 100 |
return $this->bvinfo->webpage; |
| 101 |
} |
| 102 |
|
| 103 |
public function siteInfoTags() { |
| 104 |
require_once dirname( __FILE__ ) . '/recover.php'; |
| 105 |
$secret = WPCOMRecover::defaultSecret($this->settings); |
| 106 |
$ctag = WPCOMRecover::connectionTag($this->settings); |
| 107 |
$public = WPCOMAccount::getApiPublicKey($this->settings); |
| 108 |
$server_ip = WPCOMHelper::getStringParamEscaped('SERVER', 'SERVER_ADDR', 'attr'); |
| 109 |
$tags = "<input type='hidden' name='url' value='".esc_attr($this->siteinfo->wpurl())."'/>\n". |
| 110 |
"<input type='hidden' name='homeurl' value='".esc_attr($this->siteinfo->homeurl())."'/>\n". |
| 111 |
"<input type='hidden' name='siteurl' value='".esc_attr($this->siteinfo->siteurl())."'/>\n". |
| 112 |
"<input type='hidden' name='dbsig' value='".esc_attr($this->siteinfo->dbsig(false))."'/>\n". |
| 113 |
"<input type='hidden' name='plug' value='".esc_attr($this->bvinfo->plugname)."'/>\n". |
| 114 |
"<input type='hidden' name='adminurl' value='".esc_attr($this->mainUrl())."'/>\n". |
| 115 |
"<input type='hidden' name='bvversion' value='".esc_attr($this->bvinfo->version)."'/>\n". |
| 116 |
"<input type='hidden' name='serverip' value='".$server_ip."'/>\n". |
| 117 |
"<input type='hidden' name='abspath' value='".esc_attr(ABSPATH)."'/>\n". |
| 118 |
"<input type='hidden' name='secret' value='".esc_attr($secret)."'/>\n". |
| 119 |
"<input type='hidden' name='bvctag' value='".esc_attr($ctag)."'/>\n". |
| 120 |
"<input type='hidden' name='public' value='".esc_attr($public)."'/>\n"; |
| 121 |
return $tags; |
| 122 |
} |
| 123 |
|
| 124 |
public function activateWarning() { |
| 125 |
global $hook_suffix; |
| 126 |
if (!WPCOMAccount::isConfigured($this->settings) && $hook_suffix == 'index.php' ) { |
| 127 |
?> |
| 128 |
<div id="message" class="updated" style="padding: 8px; font-size: 16px; background-color: #dff0d8"> |
| 129 |
<a class="button-primary" href="<?php echo esc_url($this->mainUrl()); ?>">Activate DreamHost Automated Migration</a> |
| 130 |
<b>Almost Done:</b> Activate your DreamHost account to migrate your site. |
| 131 |
</div> |
| 132 |
<?php |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
public function adminPage() { |
| 137 |
require_once dirname( __FILE__ ) . '/admin/main_page.php'; |
| 138 |
} |
| 139 |
|
| 140 |
public function initWhitelabel($plugins) { |
| 141 |
$slug = $this->bvinfo->slug; |
| 142 |
|
| 143 |
if (!is_array($plugins) || !isset($slug, $plugins)) { |
| 144 |
return $plugins; |
| 145 |
} |
| 146 |
|
| 147 |
$brand = $this->bvinfo->getBrandInfo(); |
| 148 |
if (is_array($brand)) { |
| 149 |
if (array_key_exists('hide', $brand)) { |
| 150 |
unset($plugins[$slug]); |
| 151 |
} else { |
| 152 |
if (array_key_exists('name', $brand)) { |
| 153 |
$plugins[$slug]['Name'] = $brand['name']; |
| 154 |
} |
| 155 |
if (array_key_exists('title', $brand)) { |
| 156 |
$plugins[$slug]['Title'] = $brand['title']; |
| 157 |
} |
| 158 |
if (array_key_exists('description', $brand)) { |
| 159 |
$plugins[$slug]['Description'] = $brand['description']; |
| 160 |
} |
| 161 |
if (array_key_exists('authoruri', $brand)) { |
| 162 |
$plugins[$slug]['AuthorURI'] = $brand['authoruri']; |
| 163 |
} |
| 164 |
if (array_key_exists('author', $brand)) { |
| 165 |
$plugins[$slug]['Author'] = $brand['author']; |
| 166 |
} |
| 167 |
if (array_key_exists('authorname', $brand)) { |
| 168 |
$plugins[$slug]['AuthorName'] = $brand['authorname']; |
| 169 |
} |
| 170 |
if (array_key_exists('pluginuri', $brand)) { |
| 171 |
$plugins[$slug]['PluginURI'] = $brand['pluginuri']; |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
return $plugins; |
| 176 |
} |
| 177 |
} |
| 178 |
endif; |