aea5fa23 by Jeremy Groot

pantheon migrate plugin

1 parent 061534ff
Showing 29 changed files with 2784 additions and 0 deletions
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('PTNAccount')) :
class PTNAccount {
public $settings;
public $public;
public $secret;
public static $api_public_key = 'bvApiPublic';
public static $accounts_list = 'bvAccountsList';
public function __construct($settings, $public, $secret) {
$this->settings = $settings;
$this->public = $public;
$this->secret = $secret;
}
public static function find($settings, $public) {
$accounts = self::allAccounts($settings);
if (array_key_exists($public, $accounts) && isset($accounts[$public]['secret'])) {
$secret = $accounts[$public]['secret'];
}
if (empty($secret) || (strlen($secret) < 32)) {
return null;
}
return new self($settings, $public, $secret);
}
public static function update($settings, $allAccounts) {
$settings->updateOption(self::$accounts_list, $allAccounts);
}
public static function randString($length) {
$chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$str = "";
$size = strlen($chars);
for( $i = 0; $i < $length; $i++ ) {
$str .= $chars[rand(0, $size - 1)];
}
return $str;
}
public static function sanitizeKey($key) {
return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key);
}
public static function apiPublicAccount($settings) {
$pubkey = $settings->getOption(self::$api_public_key);
return self::find($settings, $pubkey);
}
public static function updateApiPublicKey($settings, $pubkey) {
$settings->updateOption(self::$api_public_key, $pubkey);
}
public static function getApiPublicKey($settings) {
return $settings->getOption(self::$api_public_key);
}
public static function getPlugName($settings) {
$bvinfo = new PTNInfo($settings);
return $bvinfo->plugname;
}
public static function allAccounts($settings) {
$accounts = $settings->getOption(self::$accounts_list);
if (!is_array($accounts)) {
$accounts = array();
}
return $accounts;
}
public static function accountsByPlugname($settings) {
$accounts = self::allAccounts($settings);
$accountsByPlugname = array();
$plugname = self::getPlugName($settings);
foreach ($accounts as $pubkey => $value) {
if (array_key_exists($plugname, $value) && $value[$plugname] == 1) {
$accountsByPlugname[$pubkey] = $value;
}
}
return $accountsByPlugname;
}
public static function accountsByType($settings, $account_type) {
$accounts = self::allAccounts($settings);
$accounts_by_type = array();
foreach ($accounts as $pubkey => $value) {
if (array_key_exists('account_type', $value) && $value['account_type'] === $account_type) {
$accounts_by_type[$pubkey] = $value;
}
}
return $accounts_by_type;
}
public static function accountsByGid($settings, $account_gid) {
$accounts = self::allAccounts($settings);
$accounts_by_gid = array();
foreach ($accounts as $pubkey => $value) {
if (array_key_exists('account_gid', $value) && $value['account_gid'] === $account_gid) {
$accounts_by_gid[$pubkey] = $value;
}
}
return $accounts_by_gid;
}
public static function accountsByPattern($settings, $search_key, $search_pattern) {
$accounts = self::allAccounts($settings);
$accounts_by_pattern = array();
foreach ($accounts as $pubkey => $value) {
if (array_key_exists($search_key, $value) &&
PTNHelper::safePregMatch($search_pattern, $value[$search_key]) == 1) {
$accounts_by_pattern[$pubkey] = $value;
}
}
return $accounts_by_pattern;
}
public static function isConfigured($settings) {
$accounts = self::accountsByPlugname($settings);
return (sizeof($accounts) >= 1);
}
public static function setup($settings) {
$bvinfo = new PTNInfo($settings);
$settings->updateOption($bvinfo->plug_redirect, 'yes');
$settings->updateOption('bvActivateTime', time());
}
public function authenticatedUrl($method) {
$bvinfo = new PTNInfo($this->settings);
$qstr = http_build_query($this->newAuthParams($bvinfo->version));
return $bvinfo->appUrl().$method."?".$qstr;
}
public function newAuthParams($version) {
$bvinfo = new PTNInfo($this->settings);
$args = array();
$time = time();
$sig = sha1($this->public.$this->secret.$time.$version);
$args['sig'] = $sig;
$args['bvTime'] = $time;
$args['bvPublic'] = $this->public;
$args['bvVersion'] = $version;
$args['sha1'] = '1';
$args['plugname'] = $bvinfo->plugname;
return $args;
}
public static function addAccount($settings, $public, $secret) {
$accounts = self::allAccounts($settings);
if (!isset($public, $accounts)) {
$accounts[$public] = array();
}
$accounts[$public]['secret'] = $secret;
self::update($settings, $accounts);
}
public function info() {
return array(
"public" => substr($this->public, 0, 6)
);
}
public function updateInfo($info) {
$accounts = self::allAccounts($this->settings);
$account_type = $info["account_type"];
$pubkey = $info['pubkey'];
if (!array_key_exists($pubkey, $accounts)) {
$accounts[$pubkey] = array();
}
if (array_key_exists('secret', $info)) {
$accounts[$pubkey]['secret'] = $info['secret'];
}
$accounts[$pubkey]['account_gid'] = $info['account_gid'];
$accounts[$pubkey]['lastbackuptime'] = time();
if (isset($info["speed_plugname"])) {
$speed_plugname = $info["speed_plugname"];
$accounts[$pubkey][$speed_plugname] = true;
}
if (isset($info["plugname"])) {
$plugname = $info["plugname"];
$accounts[$pubkey][$plugname] = true;
}
$accounts[$pubkey]['account_type'] = $account_type;
$accounts[$pubkey]['url'] = $info['url'];
$accounts[$pubkey]['email'] = $info['email'];
self::update($this->settings, $accounts);
}
public static function remove($settings, $pubkey) {
$accounts = self::allAccounts($settings);
if (array_key_exists($pubkey, $accounts)) {
unset($accounts[$pubkey]);
self::update($settings, $accounts);
return true;
}
return false;
}
public static function removeByAccountType($settings, $account_type) {
$accounts = PTNAccount::accountsByType($settings, $account_type);
if (sizeof($accounts) >= 1) {
foreach ($accounts as $pubkey => $value) {
PTNAccount::remove($settings, $pubkey);
}
return true;
}
return false;
}
public static function removeByAccountGid($settings, $account_gid) {
$accounts = PTNAccount::accountsByGid($settings, $account_gid);
if (sizeof($accounts) >= 1) {
foreach ($accounts as $pubkey => $value) {
PTNAccount::remove($settings, $pubkey);
}
return true;
}
return false;
}
public static function exists($settings, $pubkey) {
$accounts = self::allAccounts($settings);
return array_key_exists($pubkey, $accounts);
}
}
endif;
\ No newline at end of file
<div class="logo-container" style="padding: 50px 0px 10px 20px">
<a href="http://blogvault.net/" style="padding-right: 20px;"><img src="<?php echo esc_url(plugins_url($this->getPluginLogo(), __FILE__)); ?>" /></a>
</div>
<div id="wrapper toplevel_page_ptn-automated-migration">
<form id="ptn_migrate_form" dummy=">" action="<?php echo esc_url($this->bvinfo->appUrl()); ?>/home/migrate" onsubmit="document.getElementById('migratesubmit').disabled = true;" style="padding:0 2% 2em 1%;" method="post" name="signup">
<h1>Migrate Site to Pantheon</h1>
<p><font size="3">This plugin makes it very easy to migrate your site to Pantheon</font></p>
<input type="hidden" name="bvsrc" value="wpplugin" />
<input type="hidden" name="migrate" value="pantheon" />
<input type="hidden" name="type" value="sftp" />
<?php echo $this->siteInfoTags(); ?>
<p>No Pantheon site yet? Start by <a href="https://dashboard.pantheon.io/sites/migrate">migrating an existing site</a> on your Pantheon dashboard.</p>
<div class="row-fluid">
<div class="span5" style="border-right: 1px solid #EEE; padding-top:1%;">
<label class="control-label" for="input02">Pantheon Site Name</label>
<div class="control-group">
<div class="controls">
<input type="text" class="input-large" name="newurl">
</div>
</div>
<label class="control-label" for="input01">Machine Token</label>
<div class="control-group">
<div class="controls">
<input type="text" class="input-large" name="machine_token">
</div>
</div>
<?php if (array_key_exists('auth_required_source', $_REQUEST)) { ?>
<div id="source-auth">
<label class="control-label" for="input02" style="color:red">User <small>(for this site)</small></label>
<div class="control-group">
<div class="controls">
<input type="text" class="input-large" name="httpauth_src_user">
</div>
</div>
<label class="control-label" for="input02" style="color:red">Password <small>(for this site)</small></label>
<div class="control-group">
<div class="controls">
<input type="password" class="input-large" name="httpauth_src_password">
</div>
</div>
</div>
<?php } ?>
<?php if (array_key_exists('auth_required_dest', $_REQUEST)) { ?>
<label class="control-label" for="input02" style="color:red">Username <small>(for Pantheon Install)</small></label>
<div class="control-group">
<div class="controls">
<input type="text" class="input-large" name="httpauth_dest_user">
</div>
</div>
<label class="control-label" for="input02" style="color:red">Password <small>(for Pantheon Install)</small></label>
<div class="control-group">
<div class="controls">
<input type="password" class="input-large" name="httpauth_dest_password">
</div>
</div>
<?php } ?>
<div class="control-group">
<div class="controls">
<br><input type="checkbox" name="consent" onchange="document.getElementById('migratesubmit').disabled = !this.checked;" value="1"/>I agree to Blogvault <a href="https://blogvault.net/tos" target="_blank" rel="noopener noreferrer">Terms of Service</a> and <a href="https://blogvault.net/privacy" target="_blank" rel="noopener noreferrer">Privacy Policy</a>
</div>
</div>
</div>
</div>
</div>
<input type='submit' disabled id='migratesubmit' value='Migrate'>
</form>
</div> <!-- wrapper ends here -->
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('BVCallbackBase')) :
class BVCallbackBase {
public static $wing_infos = array("BRAND_WING_VERSION" => '1.0',
"DB_WING_VERSION" => '1.3',
"ACCOUNT_WING_VERSION" => '1.2',
"MISC_WING_VERSION" => '1.2',
"FS_WING_VERSION" => '1.2',
"INFO_WING_VERSION" => '1.8',
);
public function objectToArray($obj) {
return json_decode(json_encode($obj), true);
}
public function base64Encode($data, $chunk_size) {
if ($chunk_size) {
$out = "";
$len = strlen($data);
for ($i = 0; $i < $len; $i += $chunk_size) {
$out .= base64_encode(substr($data, $i, $chunk_size));
}
} else {
$out = base64_encode($data);
}
return $out;
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('BVCallbackHandler')) :
class BVCallbackHandler {
public $db;
public $settings;
public $siteinfo;
public $request;
public $account;
public $response;
public $bvinfo;
public function __construct($db, $settings, $siteinfo, $request, $account, $response) {
$this->db = $db;
$this->settings = $settings;
$this->siteinfo = $siteinfo;
$this->request = $request;
$this->account = $account;
$this->response = $response;
$this->bvinfo = new PTNInfo($this->settings);
}
public function bvAdmExecuteWithoutUser() {
$this->execute(array("bvadmwithoutuser" => true));
}
public function bvAdmExecuteWithUser() {
$this->execute(array("bvadmwithuser" => true));
}
public function execute($resp = array()) {
$params = $this->request->params;
if (array_key_exists('disable_global_cache', $params)) {
$GLOBALS['_wp_using_ext_object_cache'] = false;
}
$this->routeRequest();
$resp = array(
"request_info" => $this->request->info(),
"site_info" => $this->siteinfo->info(),
"account_info" => $this->account->info(),
"bvinfo" => $this->bvinfo->info(),
"api_pubkey" => substr(PTNAccount::getApiPublicKey($this->settings), 0, 8)
);
$this->response->terminate($resp);
}
public function routeRequest() {
switch ($this->request->wing) {
case 'manage':
require_once dirname( __FILE__ ) . '/wings/manage.php';
$module = new BVManageCallback($this);
break;
case 'fs':
require_once dirname( __FILE__ ) . '/wings/fs.php';
$module = new BVFSCallback($this);
break;
case 'db':
require_once dirname( __FILE__ ) . '/wings/db.php';
$module = new BVDBCallback($this);
break;
case 'info':
require_once dirname( __FILE__ ) . '/wings/info.php';
$module = new BVInfoCallback($this);
break;
case 'dynsync':
require_once dirname( __FILE__ ) . '/wings/dynsync.php';
$module = new BVDynSyncCallback($this);
break;
case 'ipstr':
require_once dirname( __FILE__ ) . '/wings/ipstore.php';
$module = new BVIPStoreCallback($this);
break;
case 'wtch':
require_once dirname( __FILE__ ) . '/wings/watch.php';
$module = new BVWatchCallback($this);
break;
case 'brand':
require_once dirname( __FILE__ ) . '/wings/brand.php';
$module = new BVBrandCallback($this);
break;
case 'pt':
require_once dirname( __FILE__ ) . '/wings/protect.php';
$module = new BVProtectCallback($this);
break;
case 'act':
require_once dirname( __FILE__ ) . '/wings/account.php';
$module = new BVAccountCallback($this);
break;
case 'fswrt':
require_once dirname( __FILE__ ) . '/wings/fs_write.php';
$module = new BVFSWriteCallback();
break;
case 'actlg':
require_once dirname( __FILE__ ) . '/wings/actlog.php';
$module = new BVActLogCallback($this);
break;
case 'speed':
require_once dirname( __FILE__ ) . '/wings/speed.php';
$module = new BVSpeedCallback($this);
break;
case 'scrty':
require_once dirname( __FILE__ ) . '/wings/security.php';
$module = new BVSecurityCallback($this);
break;
default:
require_once dirname( __FILE__ ) . '/wings/misc.php';
$module = new BVMiscCallback($this);
break;
}
$resp = $module->process($this->request);
if ($resp === false) {
$resp = array(
"statusmsg" => "Bad Command",
"status" => false);
}
$resp = array(
$this->request->wing => array(
$this->request->method => $resp
)
);
$this->response->addStatus("callbackresponse", $resp);
return 1;
}
}
endif;
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('BVCallbackRequest')) :
class BVCallbackRequest {
public $params;
public $method;
public $wing;
public $is_afterload;
public $is_admin_ajax;
public $is_debug;
public $account;
public $settings;
public $sig;
public $sighshalgo;
public $time;
public $version;
public $is_sha1;
public $bvb64stream;
public $bvb64cksize;
public $checksum;
public $error = array();
public $pubkey_name;
public $bvprmsmac;
public $bvboundry;
public function __construct($account, $in_params, $settings) {
$this->params = array();
$this->account = $account;
$this->settings = $settings;
$this->wing = $in_params['wing'];
$this->method = $in_params['bvMethod'];
$this->is_afterload = array_key_exists('afterload', $in_params);
$this->is_admin_ajax = array_key_exists('adajx', $in_params);
$this->is_debug = array_key_exists('bvdbg', $in_params);
$this->sig = $in_params['sig'];
$this->sighshalgo = !empty($in_params['sighshalgo']) ? $in_params['sighshalgo'] : null;
$this->time = intval($in_params['bvTime']);
$this->version = $in_params['bvVersion'];
$this->is_sha1 = array_key_exists('sha1', $in_params);
$this->bvb64stream = isset($in_params['bvb64stream']);
$this->bvb64cksize = array_key_exists('bvb64cksize', $in_params) ? intval($in_params['bvb64cksize']) : false;
$this->checksum = array_key_exists('checksum', $in_params) ? $in_params['checksum'] : false;
$this->pubkey_name = !empty($in_params['pubkeyname']) ?
PTNAccount::sanitizeKey($in_params['pubkeyname']) : 'm_public';
$this->bvprmsmac = !empty($in_params['bvprmsmac']) ? PTNAccount::sanitizeKey($in_params['bvprmsmac']) : "";
$this->bvboundry = !empty($in_params['bvboundry']) ? $in_params['bvboundry'] : "";
}
public function isAPICall() {
return array_key_exists('apicall', $this->params);
}
public function curlRequest($url, $body) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return curl_exec($ch);
}
public function fileGetContentRequest($url, $body) {
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($body)
)
);
$context = stream_context_create($options);
return file_get_contents($url, false, $context);
}
public function http_request($url, $body) {
if (in_array('curl', get_loaded_extensions())) {
return $this->curlRequest($url, $body);
} else {
return $this->fileGetContentRequest($url, $body);
}
}
public function get_params_via_api($params_key, $apiurl) {
$res = $this->http_request($apiurl, array('bvkey' => $params_key));
if ($res === FALSE) {
return false;
}
return $res;
}
public function info() {
$info = array(
"requestedsig" => $this->sig,
"requestedtime" => $this->time,
"requestedversion" => $this->version,
"error" => $this->error
);
if ($this->is_debug) {
$info["inreq"] = $this->params;
}
if ($this->is_admin_ajax) {
$info["adajx"] = true;
}
if ($this->is_afterload) {
$info["afterload"] = true;
}
return $info;
}
public function processParams($in_params) {
$params = array();
if (array_key_exists('obend', $in_params) && function_exists('ob_end_clean'))
@ob_end_clean();
if (array_key_exists('op_reset', $in_params) && function_exists('output_reset_rewrite_vars'))
@output_reset_rewrite_vars();
if (array_key_exists('concat', $in_params)) {
foreach ($in_params['concat'] as $key) {
$concated = '';
$count = intval($in_params[$key]);
for ($i = 1; $i <= $count; $i++) {
$concated .= $in_params[$key."_bv_".$i];
}
$in_params[$key] = $concated;
}
}
if (isset($in_params['bvpdataviaapi']) && isset($in_params['bvapiurl'])) {
$pdata = $this->get_params_via_api($in_params['bvpdataviaapi'], $in_params['bvapiurl']);
if ($pdata !== false) {
$in_params["bvprms"] = $pdata;
}
}
if (array_key_exists('bvprms', $in_params) && isset($in_params['bvprms'])) {
if (!empty($in_params['bvprmshshalgo']) && $in_params['bvprmshshalgo'] === 'sha256') {
$calculated_mac = hash_hmac('SHA256', $in_params['bvprms'], $this->account->secret);
} else {
$calculated_mac = hash_hmac('SHA1', $in_params['bvprms'], $this->account->secret);
}
if ($this->compare_mac($this->bvprmsmac, $calculated_mac) === true) {
if (array_key_exists('b64', $in_params)) {
foreach ($in_params['b64'] as $key) {
if (is_array($in_params[$key])) {
$in_params[$key] = array_map('base64_decode', $in_params[$key]);
} else {
$in_params[$key] = base64_decode($in_params[$key]);
}
}
}
if (array_key_exists('unser', $in_params)) {
foreach ($in_params['unser'] as $key) {
$in_params[$key] = json_decode($in_params[$key], TRUE);
}
}
if (array_key_exists('sersafe', $in_params)) {
$key = $in_params['sersafe'];
$in_params[$key] = BVCallbackRequest::serialization_safe_decode($in_params[$key]);
}
if (array_key_exists('bvprms', $in_params) && isset($in_params['bvprms'])) {
$params = $in_params['bvprms'];
}
if (array_key_exists('clacts', $in_params)) {
foreach ($in_params['clacts'] as $action) {
remove_all_actions($action);
}
}
if (array_key_exists('clallacts', $in_params)) {
global $wp_filter;
foreach ( $wp_filter as $filter => $val ){
remove_all_actions($filter);
}
}
if (array_key_exists('memset', $in_params)) {
$val = intval($in_params['memset']);
@ini_set('memory_limit', $val.'M');
}
return $params;
}
}
return false;
}
private function compare_mac($l_hash, $r_hash) {
if (!is_string($l_hash) || !is_string($r_hash)) {
return false;
}
if (strlen($l_hash) !== strlen($r_hash)) {
return false;
}
if (function_exists('hash_equals')) {
return hash_equals($l_hash, $r_hash);
} else {
return $l_hash === $r_hash;
}
}
public static function serialization_safe_decode($data) {
if (is_array($data)) {
$data = array_map(array('BVCallbackRequest', 'serialization_safe_decode'), $data);
} elseif (is_string($data)) {
$data = base64_decode($data);
}
return $data;
}
public function authenticate() {
if (!$this->account) {
$this->error["message"] = "ACCOUNT_NOT_FOUND";
return false;
}
$bv_last_recv_time = $this->settings->getOption('bvLastRecvTime');
if ($this->time < intval($bv_last_recv_time) - 300) {
return false;
}
$data = $this->method.$this->account->secret.$this->time.$this->version.$this->bvprmsmac;
if (!$this->verify($data, base64_decode($this->sig), $this->sighshalgo)) {
return false;
}
$this->settings->updateOption('bvLastRecvTime', $this->time);
return 1;
}
public function verify($data, $sig, $sighshalgo) {
if (!function_exists('openssl_verify') || !function_exists('openssl_pkey_get_public')) {
$this->error["message"] = "OPENSSL_FUNCS_NOT_FOUND";
return false;
}
$key_file = dirname( __FILE__ ) . '/../public_keys/' . $this->pubkey_name . '.pub';
if (!file_exists($key_file)) {
$this->error["message"] = "PUBLIC_KEY_NOT_FOUND";
return false;
}
$public_key_str = file_get_contents($key_file);
$public_key = openssl_pkey_get_public($public_key_str);
if (!$public_key) {
$this->error["message"] = "UNABLE_TO_LOAD_PUBLIC_KEY";
return false;
}
if ($sighshalgo === 'sha256') {
$verify = openssl_verify($data, $sig, $public_key, OPENSSL_ALGO_SHA256);
} else {
$verify = openssl_verify($data, $sig, $public_key);
}
if ($verify === 1) {
return true;
} elseif ($verify === 0) {
$this->error["message"] = "INCORRECT_SIGNATURE";
$this->error["pubkey_sig"] = substr(hash('md5', $public_key_str), 0, 8);
} else {
$this->error["message"] = "OPENSSL_VERIFY_FAILED";
}
return false;
}
public function corruptedParamsResp() {
$bvinfo = new PTNInfo($this->settings);
return array(
"account_info" => $this->account->info(),
"request_info" => $this->info(),
"bvinfo" => $bvinfo->info(),
"statusmsg" => "BVPRMS_CORRUPTED"
);
}
public function authFailedResp() {
$api_public_key = PTNAccount::getApiPublicKey($this->settings);
$default_secret = PTNRecover::getDefaultSecret($this->settings);
$bvinfo = new PTNInfo($this->settings);
$resp = array(
"request_info" => $this->info(),
"bvinfo" => $bvinfo->info(),
"statusmsg" => "FAILED_AUTH",
"api_pubkey" => substr($api_public_key, 0, 8),
"def_sigmatch" => substr(hash('sha1', $this->method.$default_secret.$this->time.$this->version), 0, 8)
);
if ($this->account) {
$resp["account_info"] = $this->account->info();
$resp["sigmatch"] = substr(hash('sha1', $this->method.$this->account->secret.$this->time.$this->version), 0, 6);
} else {
$resp["account_info"] = array("error" => "ACCOUNT_NOT_FOUND");
}
return $resp;
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('BVCallbackResponse')) :
class BVCallbackResponse extends BVCallbackBase {
public $status;
public $bvb64cksize;
public function __construct($bvb64cksize) {
$this->status = array("blogvault" => "response");
$this->bvb64cksize = $bvb64cksize;
}
public function addStatus($key, $value) {
$this->status[$key] = $value;
}
public function addArrayToStatus($key, $value) {
if (!isset($this->status[$key])) {
$this->status[$key] = array();
}
$this->status[$key][] = $value;
}
public function terminate($resp = array()) {
$resp = array_merge($this->status, $resp);
$resp["signature"] = "Blogvault API";
$response = "bvbvbvbvbv".serialize($resp)."bvbvbvbvbv";
$response = "bvb64bvb64".$this->base64Encode($response, $this->bvb64cksize)."bvb64bvb64";
die($response);
exit;
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('BVRespStream')) :
class BVStream extends BVCallbackBase {
public $bvb64stream;
public $bvb64cksize;
public $checksum;
function __construct($request) {
$this->bvb64stream = $request->bvb64stream;
$this->bvb64cksize = $request->bvb64cksize;
$this->checksum = $request->checksum;
}
public function writeChunk($chunk) {
}
public static function startStream($account, $request) {
$result = array();
$params = $request->params;
$stream = new BVRespStream($request);
if ($request->isAPICall()) {
$stream = new BVHttpStream($request);
if (!$stream->connect()) {
$apicallstatus = array(
"httperror" => "Cannot Open Connection to Host",
"streamerrno" => $stream->errno,
"streamerrstr" => $stream->errstr
);
return array("apicallstatus" => $apicallstatus);
}
if (array_key_exists('acbmthd', $params)) {
$qstr = http_build_query(array('bvapicheck' => $params['bvapicheck']));
$url = '/bvapi/'.$params['acbmthd']."?".$qstr;
if (array_key_exists('acbqry', $params)) {
$url .= "&".$params['acbqry'];
}
$stream->multipartChunkedPost($url);
} else {
return array("apicallstatus" => array("httperror" => "ApiCall method not present"));
}
}
return array('stream' => $stream);
}
public function writeStream($chunk) {
if (strlen($chunk) > 0) {
$bvb64_prefix = "";
if ($this->bvb64stream) {
$chunk_size = $this->bvb64cksize;
$chunk = $this->base64Encode($chunk, $chunk_size);
$bvb64_prefix .= "BVB64" . ":";
}
$hash_prefix = "";
if ($this->checksum == 'crc32') {
$hash_prefix .= "CRC32" . ":" . crc32($chunk) . ":";
} else if ($this->checksum == 'md5') {
$hash_prefix .= "MD5" . ":" . md5($chunk) . ":";
}
$chunk = $hash_prefix . $bvb64_prefix . strlen($chunk) . ":" . $chunk;
$this->writeChunk($chunk);
}
}
}
class BVRespStream extends BVStream {
public $bvboundry;
function __construct($request) {
parent::__construct($request);
$this->bvboundry = $request->bvboundry;
}
public function writeChunk($chunk) {
echo $this->bvboundry . "ckckckckck" . $chunk . $this->bvboundry . "ckckckckck";
}
public function endStream() {
echo $this->bvboundry . "rerererere";
return array();
}
}
class BVHttpStream extends BVStream {
var $user_agent = 'BVHttpStream';
var $host;
var $port;
var $timeout = 20;
var $conn;
var $errno;
var $errstr;
var $boundary;
var $apissl;
function __construct($request) {
parent::__construct($request);
$this->host = $request->params['apihost'];
$this->port = intval($request->params['apiport']);
$this->apissl = array_key_exists('apissl', $request->params);
}
public function connect() {
if ($this->apissl && function_exists('stream_socket_client')) {
$this->conn = stream_socket_client("ssl://".$this->host.":".$this->port, $errno, $errstr, $this->timeout);
} else {
$this->conn = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
}
if (!$this->conn) {
$this->errno = $errno;
$this->errstr = $errstr;
return false;
}
socket_set_timeout($this->conn, $this->timeout);
return true;
}
public function write($data) {
fwrite($this->conn, $data);
}
public function sendChunk($data) {
$this->write(sprintf("%x\r\n", strlen($data)));
$this->write($data);
$this->write("\r\n");
}
public function sendRequest($method, $url, $headers = array(), $body = null) {
$def_hdrs = array("Connection" => "keep-alive",
"Host" => $this->host);
$headers = array_merge($def_hdrs, $headers);
$request = strtoupper($method)." ".$url." HTTP/1.1\r\n";
if (null != $body) {
$headers["Content-length"] = strlen($body);
}
foreach($headers as $key=>$val) {
$request .= $key.":".$val."\r\n";
}
$request .= "\r\n";
if (null != $body) {
$request .= $body;
}
$this->write($request);
return $request;
}
public function post($url, $headers = array(), $body = "") {
if(is_array($body)) {
$b = "";
foreach($body as $key=>$val) {
$b .= $key."=".urlencode($val)."&";
}
$body = substr($b, 0, strlen($b) - 1);
}
$this->sendRequest("POST", $url, $headers, $body);
}
public function streamedPost($url, $headers = array()) {
$headers['Transfer-Encoding'] = "chunked";
$this->sendRequest("POST", $url, $headers);
}
public function multipartChunkedPost($url) {
$mph = array(
"Content-Disposition" => "form-data; name=bvinfile; filename=data",
"Content-Type" => "application/octet-stream"
);
$rnd = rand(100000, 999999);
$this->boundary = "----".$rnd;
$prologue = "--".$this->boundary."\r\n";
foreach($mph as $key=>$val) {
$prologue .= $key.":".$val."\r\n";
}
$prologue .= "\r\n";
$headers = array('Content-Type' => "multipart/form-data; boundary=".$this->boundary);
$this->streamedPost($url, $headers);
$this->sendChunk($prologue);
}
public function writeChunk($data) {
$this->sendChunk($data);
}
public function closeChunk() {
$this->sendChunk("");
}
public function endStream() {
$epilogue = "\r\n\r\n--".$this->boundary."--\r\n";
$this->sendChunk($epilogue);
$this->closeChunk();
$result = array();
$resp = $this->getResponse();
if (array_key_exists('httperror', $resp)) {
$result["httperror"] = $resp['httperror'];
} else {
$result["respstatus"] = $resp['status'];
$result["respstatus_string"] = $resp['status_string'];
}
return array("apicallstatus" => $result);
}
public function getResponse() {
$response = array();
$response['headers'] = array();
$state = 1;
$conlen = 0;
stream_set_timeout($this->conn, 300);
while (!feof($this->conn)) {
$line = fgets($this->conn, 4096);
if (1 == $state) {
if (!PTNHelper::safePregMatch('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
$response['httperror'] = "Status code line invalid: ".htmlentities($line);
return $response;
}
$response['http_version'] = $m[1];
$response['status'] = $m[2];
$response['status_string'] = $m[3];
$state = 2;
} else if (2 == $state) {
# End of headers
if (2 == strlen($line)) {
if ($conlen > 0)
$response['body'] = fread($this->conn, $conlen);
return $response;
}
if (!PTNHelper::safePregMatch('/([^:]+):\\s*(.*)/', $line, $m)) {
// Skip to the next header
continue;
}
$key = strtolower(trim($m[1]));
$val = trim($m[2]);
$response['headers'][$key] = $val;
if ($key == "content-length") {
$conlen = intval($val);
}
}
}
return $response;
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('BVAccountCallback')) :
class BVAccountCallback extends BVCallbackBase {
public $account;
public $settings;
const ACCOUNT_WING_VERSION = 1.2;
public function __construct($callback_handler) {
$this->account = $callback_handler->account;
$this->settings = $callback_handler->settings;
}
function updateInfo($args) {
$result = array();
if (array_key_exists('update_info', $args)) {
$this->account->updateInfo($args['update_info']);
$result['update_info'] = array(
"status" => PTNAccount::exists($this->settings, $args['update_info']['pubkey'])
);
}
if (array_key_exists('update_api_key', $args)) {
PTNAccount::updateApiPublicKey($this->settings, $args['update_api_key']['pubkey']);
$result['update_api_key'] = array(
"status" => $this->settings->getOption(PTNAccount::$api_public_key)
);
}
if (array_key_exists('update_options', $args))
$result['update_options'] = $this->settings->updateOptions($args['update_options']);
if (array_key_exists('delete_options', $args))
$result['delete_options'] = $this->settings->deleteOptions($args['delete_options']);
$result['status'] = true;
return $result;
}
function process($request) {
$params = $request->params;
$account = $this->account;
$settings = $this->settings;
switch ($request->method) {
case "addacc":
PTNAccount::addAccount($this->settings, $params['public'], $params['secret']);
$resp = array("status" => PTNAccount::exists($this->settings, $params['public']));
break;
case "rmacc":
$resp = array("status" => PTNAccount::remove($this->settings, $params['public']));
break;
case "updt":
$account->updateInfo($params);
$resp = array("status" => PTNAccount::exists($this->settings, $params['pubkey']));
break;
case "updtapikey":
PTNAccount::updateApiPublicKey($this->settings, $params['pubkey']);
$resp = array("status" => $this->settings->getOption(PTNAccount::$api_public_key));
break;
case "rmbvscrt":
$resp = array("status" => $settings->deleteOption('bvSecretKey'));
break;
case "rmbvkeys":
$resp = array("status" => $settings->deleteOption('bvKeys'));
break;
case "rmdefpub":
$resp = array("status" => $settings->deleteOption('bvDefaultPublic'));
break;
case "rmoldbvacc":
$resp = array("status" => $settings->deleteOption('bvAccounts'));
break;
case "fetch":
$accounts = PTNAccount::allAccounts($this->settings);
if (!isset($params['full'])) {
foreach ($accounts as &$account) {
if (isset($account['secret'])) {
unset($account['secret']);
}
}
}
$resp = array("status" => $accounts);
break;
case "updtinfo":
$resp = $this->updateInfo($params);
break;
default:
$resp = false;
}
return $resp;
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('BVBrandCallback')) :
class BVBrandCallback extends BVCallbackBase {
public $settings;
const BRAND_WING_VERSION = 1.0;
public function __construct($callback_handler) {
$this->settings = $callback_handler->settings;
}
public function process($request) {
$bvinfo = new PTNInfo($this->settings);
$option_name = $bvinfo->brand_option;
$params = $request->params;
switch($request->method) {
case 'setbrand':
$brandinfo = array();
if (array_key_exists('hide', $params)) {
$brandinfo['hide'] = $params['hide'];
} else {
$brandinfo['name'] = $params['name'];
$brandinfo['title'] = $params['title'];
$brandinfo['description'] = $params['description'];
$brandinfo['pluginuri'] = $params['pluginuri'];
$brandinfo['author'] = $params['author'];
$brandinfo['authorname'] = $params['authorname'];
$brandinfo['authoruri'] = $params['authoruri'];
$brandinfo['menuname'] = $params['menuname'];
$brandinfo['logo'] = $params['logo'];
$brandinfo['webpage'] = $params['webpage'];
$brandinfo['appurl'] = $params['appurl'];
if (array_key_exists('hide_plugin_details', $params)) {
$brandinfo['hide_plugin_details'] = $params['hide_plugin_details'];
}
if (array_key_exists('hide_from_menu', $params)) {
$brandinfo['hide_from_menu'] = $params['hide_from_menu'];
}
}
$this->settings->updateOption($option_name, $brandinfo);
$resp = array("setbrand" => $this->settings->getOption($option_name));
break;
case 'rmbrand':
$this->settings->deleteOption($option_name);
$resp = array("rmbrand" => !$this->settings->getOption($option_name));
break;
default:
$resp = false;
}
return $resp;
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('BVMiscCallback')) :
class BVMiscCallback extends BVCallbackBase {
public $settings;
public $bvinfo;
public $siteinfo;
public $account;
public $bvapi;
public $db;
const MISC_WING_VERSION = 1.2;
public function __construct($callback_handler) {
$this->settings = $callback_handler->settings;
$this->siteinfo = $callback_handler->siteinfo;
$this->account = $callback_handler->account;
$this->db = $callback_handler->db;
$this->bvinfo = new PTNInfo($callback_handler->settings);
$this->bvapi = new PTNWPAPI($callback_handler->settings);
}
public function refreshPluginUpdates() {
global $wp_current_filter;
$wp_current_filter[] = 'load-update-core.php';
wp_update_plugins();
array_pop($wp_current_filter);
wp_update_plugins();
return array("wpupdateplugins" => true);
}
public function refreshThemeUpdates() {
global $wp_current_filter;
$wp_current_filter[] = 'load-update-core.php';
wp_update_themes();
array_pop($wp_current_filter);
wp_update_themes();
return array("wpupdatethemes" => true);
}
public function getWingInfo() {
return array('wing_info' => self::$wing_infos);
}
public function post_types_data($post_params) {
$result = array();
$get_post_types_args = $post_params['get_post_types_args'];
$post_types = get_post_types($get_post_types_args);
$post_types = array_merge($post_types, $post_params['include_post_types']);
$post_types = array_diff( $post_types, $post_params['exclude_post_types']);
$result['post_types'] = $post_types;
$post_types = esc_sql($post_types);
$post_types = "'" . implode("','", $post_types) . "'";
$post_table = $post_params['table'];
$post_select_columns = implode(", ", $post_params['select_column']);
$post_query = "SELECT MAX(ID) as $post_select_columns FROM ( SELECT
$post_select_columns FROM $post_table WHERE post_type IN ( $post_types )
AND post_status='publish' ORDER BY post_date DESC ) AS posts GROUP BY post_type";
$posts = $this->db->getResult($post_query);
foreach ( $posts as $key => $post ) {
$posts[$key]['url'] = get_permalink($post['ID']);
}
$result['posts'] = $posts;
return $result;
}
public function taxonomy_data($taxonomy_params) {
$result = array();
$get_taxonomies_args = $taxonomy_params['get_taxonomies_args'];
$taxonomies = get_taxonomies($get_taxonomies_args);
$taxonomies = array_diff($taxonomies, $taxonomy_params['exclude_taxonomies']);
$result['taxonomies'] = $taxonomies;
$taxonomies = esc_sql( $taxonomies );
$taxonomies = "'" . implode( "','", $taxonomies ) . "'";
$taxonomy_table = $taxonomy_params['table'];
$taxonomy_select_columns = implode(", ", $taxonomy_params['select_column']);
$taxonomy_query = "SELECT MAX( term_id ) AS $taxonomy_select_columns FROM (
SELECT $taxonomy_select_columns FROM $taxonomy_table WHERE taxonomy IN (
$taxonomies ) AND count > 0) AS taxonomies GROUP BY taxonomy";
$taxonomies = $this->db->getResult($taxonomy_query);
foreach($taxonomies as $key => $taxonomy) {
$taxonomies[$key]['url'] = get_term_link((int)$taxonomy['term_id'], $taxonomy['taxonomy']);
}
$result['taxonomy_data'] = $taxonomies;
return $result;
}
public function process($request) {
$bvinfo = $this->bvinfo;
$settings = $this->settings;
$params = $request->params;
switch ($request->method) {
case "dummyping":
$resp = array();
$resp = array_merge($resp, $this->siteinfo->info());
$resp = array_merge($resp, $this->account->info());
$resp = array_merge($resp, $this->bvinfo->info());
$resp = array_merge($resp, $this->getWingInfo());
break;
case "pngbv":
$info = array();
$this->siteinfo->basic($info);
$this->bvapi->pingbv('/bvapi/pingbv', $info);
$resp = array("status" => true);
break;
case "enablebadge":
$option = $bvinfo->badgeinfo;
$badgeinfo = array();
$badgeinfo['badgeurl'] = $params['badgeurl'];
$badgeinfo['badgeimg'] = $params['badgeimg'];
$badgeinfo['badgealt'] = $params['badgealt'];
$settings->updateOption($option, $badgeinfo);
$resp = array("status" => $settings->getOption($option));
break;
case "disablebadge":
$option = $bvinfo->badgeinfo;
$settings->deleteOption($option);
$resp = array("status" => !$settings->getOption($option));
break;
case "getoption":
$resp = array('getoption' => $settings->getOption($params['opkey']));
break;
case "setdynplug":
$settings->updateOption('bvdynplug', $params['dynplug']);
$resp = array("setdynplug" => $settings->getOption('bvdynplug'));
break;
case "unsetdynplug":
$settings->deleteOption('bvdynplug');
$resp = array("unsetdynplug" => $settings->getOption('bvdynplug'));
break;
case "wpupplgs":
$resp = $this->refreshPluginUpdates();
break;
case "wpupthms":
$resp = $this->refreshThemeUpdates();
break;
case "wpupcre":
$resp = array("wpupdatecore" => wp_version_check());
break;
case "phpinfo":
phpinfo();
die();
break;
case "wpnonce":
$resp = array("wpnonce" => wp_create_nonce($params["wpnonce_action"]));
break;
case "dlttrsnt":
$resp = array("dlttrsnt" => $settings->deleteTransient($params['key']));
break;
case "optns":
$resp = array();
if (array_key_exists("get_options", $params))
$resp["get_options"] = $settings->getOptions($params["get_options"]);
if (array_key_exists("update_options", $params))
$resp["update_options"] = $settings->updateOptions($params["update_options"]);
if (array_key_exists("delete_options", $params))
$resp["delete_options"] = $settings->deleteOptions($params["delete_options"]);
break;
case "setbvss":
$resp = array("status" => $settings->updateOption('bv_site_settings', $params['bv_site_settings']));
break;
case "stsrvcs":
$resp = array();
$deleted_configs = array();
$updated_configs = array();
if (array_key_exists("configs_to_delete", $params)) {
foreach($params["configs_to_delete"] as $config_name) {
$deleted_configs[$config_name] = $settings->deleteOption($config_name);
}
}
if (array_key_exists("configs_to_update", $params)) {
foreach($params["configs_to_update"] as $config_name => $config_value) {
$settings->updateOption($config_name, $config_value);
$updated_configs[$config_name] = $settings->getOption($config_name);
}
}
$resp["updated_configs"] = $updated_configs;
$resp["deleted_configs"] = $deleted_configs;
break;
case "critical_css_data":
$resp = array();
if (array_key_exists('fetch_post_data', $params) && $params['fetch_post_data'] == true) {
$post_params = $params['post_params'];
$post_result = $this->post_types_data($post_params);
$resp['post_cp_results'] = $post_result['posts'];
$resp['post_types'] = $post_result['post_types'];
}
if (array_key_exists('fetch_taxonomy_data', $params) && $params['fetch_taxonomy_data'] == true) {
$taxonomy_params = $params['taxonomy_params'];
$taxonomy_result = $this->taxonomy_data($taxonomy_params);
$resp['taxonomy_cp_results'] = $taxonomy_result['taxonomy_data'];
$resp['taxonomies'] = $taxonomy_result['taxonomies'];
}
break;
case "get_post_ids":
if (array_key_exists('urls', $params)) {
$resp = array();
foreach ( $params['urls'] as $url ) {
$resp[$url] = url_to_postid($url);
}
}
break;
case "permalink":
if (array_key_exists('post_ids', $params)) {
$resp = array();
foreach ( $params['post_ids'] as $id ) {
$resp[$id]['url'] = get_permalink($id);
}
}
break;
default:
$resp = false;
}
return $resp;
}
}
endif;
\ No newline at end of file
.toplevel_page_ptn-automated-migration label{
float: left;
width: 220px;
font-weight: bold;
}
.toplevel_page_ptn-automated-migration input, .toplevel_page_ptn-automated-migration textarea{
width: 180px;
margin-bottom: 20px;
}
.toplevel_page_ptn-automated-migration textarea{
width: 250px;
height: 150px;
}
.boxes{
width: 1em;
}
#submitbutton{
margin-left: 300px;
margin-top: 5px;
width: 100px;
}
br{
clear: left;
}
#wrapper {
width:100%;
clear:both;
overflow: hidden;
position: relative;
width: 100%;
}
.logo-left {
max-width: 50%;
float: left;
}
.logo-right {
max-width: 50%;
float: right;
}
<?php
if (!class_exists('PTNHelper')) :
class PTNHelper {
public static function safePregMatch($pattern, $subject, &$matches = null, $flags = 0, $offset = 0) {
if (!is_string($pattern) || !is_string($subject)) {
return false;
}
return preg_match($pattern, $subject, $matches, $flags, $offset);
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('PTNInfo')) :
class PTNInfo {
public $settings;
public $config;
public $plugname = 'pantheon';
public $brandname = 'Pantheon Migrate';
public $badgeinfo = 'ptnbadge';
public $ip_header_option = 'ptnipheader';
public $brand_option = 'ptnbrand';
public $version = '5.25';
public $webpage = 'https://pantheon.io';
public $appurl = 'https://migrate.blogvault.net';
public $slug = 'bv-pantheon-migration/pantheon.php';
public $plug_redirect = 'ptnredirect';
public $logo = '../img/logo.png';
public $brand_icon = '/img/icon.png';
public $services_option_name = 'BVSERVICESOPTIONNAME';
public $author = 'Pantheon';
public $title = 'Pantheon Migration';
const DB_VERSION = '4';
public function __construct($settings) {
$this->settings = $settings;
$this->config = $this->settings->getOption($this->services_option_name);
}
public function getCurrentDBVersion() {
$bvconfig = $this->config;
if ($bvconfig && array_key_exists('db_version', $bvconfig)) {
return $bvconfig['db_version'];
}
return false;
}
public function hasValidDBVersion() {
return PTNInfo::DB_VERSION === $this->getCurrentDBVersion();
}
public static function getRequestID() {
if (!defined("BV_REQUEST_ID")) {
define("BV_REQUEST_ID", uniqid(mt_rand()));
}
return BV_REQUEST_ID;
}
public function canSetCWBranding() {
if (PTNWPSiteInfo::isCWServer()) {
$bot_protect_accounts = PTNAccount::accountsByType($this->settings, 'botprotect');
if (sizeof($bot_protect_accounts) >= 1)
return true;
$bot_protect_accounts = PTNAccount::accountsByPattern($this->settings, 'email', '/@cw_user\.com$/');
if (sizeof($bot_protect_accounts) >= 1)
return true;
}
return false;
}
public function getBrandInfo() {
return $this->settings->getOption($this->brand_option);
}
public function getBrandName() {
$brand = $this->getBrandInfo();
if (is_array($brand) && array_key_exists('menuname', $brand)) {
return $brand['menuname'];
}
return $this->brandname;
}
public function getBrandIcon() {
$brand = $this->getBrandInfo();
if (is_array($brand) && array_key_exists('brand_icon', $brand)) {
return $brand['brand_icon'];
}
return $this->brand_icon;
}
public function getWatchTime() {
$time = $this->settings->getOption('bvwatchtime');
return ($time ? $time : 0);
}
public function appUrl() {
if (defined('BV_APP_URL')) {
return BV_APP_URL;
} else {
$brand = $this->getBrandInfo();
if (is_array($brand) && array_key_exists('appurl', $brand)) {
return $brand['appurl'];
}
return $this->appurl;
}
}
public function isActivePlugin() {
$expiry_time = time() - (3 * 24 * 3600);
return ($this->getWatchTime() > $expiry_time);
}
public function isValidEnvironment(){
$bvsiteinfo = new PTNWPSiteInfo();
$bvconfig = $this->config;
if (is_multisite()) {
return true;
} elseif ($bvconfig && array_key_exists("siteurl_scheme", $bvconfig)) {
$siteurl = $bvsiteinfo->siteurl('', $bvconfig["siteurl_scheme"]);
if (array_key_exists("abspath", $bvconfig) &&
array_key_exists("siteurl", $bvconfig) && !empty($siteurl)) {
return ($bvconfig["abspath"] == ABSPATH && $bvconfig["siteurl"] == $siteurl);
}
}
return true;
}
public function isProtectModuleEnabled() {
return $this->isServiceActive("protect") && $this->isValidEnvironment();
}
public function isDynSyncModuleEnabled() {
if ($this->isServiceActive("dynsync")) {
$dynconfig = $this->config['dynsync'];
if (array_key_exists('dynplug', $dynconfig) && ($dynconfig['dynplug'] === $this->plugname)) {
return true;
}
}
return false;
}
public function isServiceActive($service) {
$bvconfig = $this->config;
if ($bvconfig && array_key_exists('services', $bvconfig)) {
return in_array($service, $bvconfig['services']) && $this->isActivePlugin();
}
return false;
}
public function isActivateRedirectSet() {
return ($this->settings->getOption($this->plug_redirect) === 'yes') ? true : false;
}
public function isMalcare() {
return $this->getBrandName() === 'MalCare';
}
public function isBlogvault() {
return $this->getBrandName() === 'BlogVault';
}
public function info() {
return array(
"bvversion" => $this->version,
"sha1" => "true",
"plugname" => $this->plugname
);
}
}
endif;
\ No newline at end of file
<?php
/*
Plugin Name: Pantheon Migration
Plugin URI: https://pantheon.io
Description: The easiest way to migrate your site to Pantheon
Author: Pantheon
Author URI: https://pantheon.io
Version: 5.25
Network: True
*/
/* Copyright 2017 Pantheon Migrate (email : support@blogvault.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Global response array */
if (!defined('ABSPATH')) exit;
##OLDWPR##
require_once dirname( __FILE__ ) . '/wp_settings.php';
require_once dirname( __FILE__ ) . '/wp_site_info.php';
require_once dirname( __FILE__ ) . '/wp_db.php';
require_once dirname( __FILE__ ) . '/wp_api.php';
require_once dirname( __FILE__ ) . '/wp_actions.php';
require_once dirname( __FILE__ ) . '/info.php';
require_once dirname( __FILE__ ) . '/account.php';
require_once dirname( __FILE__ ) . '/helper.php';
##WPCACHEMODULE##
$bvsettings = new PTNWPSettings();
$bvsiteinfo = new PTNWPSiteInfo();
$bvdb = new PTNWPDb();
$bvapi = new PTNWPAPI($bvsettings);
$bvinfo = new PTNInfo($bvsettings);
$wp_action = new PTNWPAction($bvsettings, $bvsiteinfo, $bvapi);
register_uninstall_hook(__FILE__, array('PTNWPAction', 'uninstall'));
register_activation_hook(__FILE__, array($wp_action, 'activate'));
register_deactivation_hook(__FILE__, array($wp_action, 'deactivate'));
add_action('wp_footer', array($wp_action, 'footerHandler'), 100);
add_action('clear_bv_services_config', array($wp_action, 'clear_bv_services_config'));
##SOADDUNINSTALLACTION##
##DISABLE_OTHER_OPTIMIZATION_PLUGINS##
##WPCLIMODULE##
if (is_admin()) {
require_once dirname( __FILE__ ) . '/wp_admin.php';
$wpadmin = new PTNWPAdmin($bvsettings, $bvsiteinfo);
add_action('admin_init', array($wpadmin, 'initHandler'));
add_filter('all_plugins', array($wpadmin, 'initBranding'));
add_filter('plugin_row_meta', array($wpadmin, 'hidePluginDetails'), 10, 2);
##HEALTH_INFO_HOOK##
if ($bvsiteinfo->isMultisite()) {
add_action('network_admin_menu', array($wpadmin, 'menu'));
} else {
add_action('admin_menu', array($wpadmin, 'menu'));
}
add_filter('plugin_action_links', array($wpadmin, 'settingsLink'), 10, 2);
add_action('admin_head', array($wpadmin, 'removeAdminNotices'), 3);
##ACTIVATEWARNING##
add_action('admin_enqueue_scripts', array($wpadmin, 'ptnsecAdminMenu'));
##ALPURGECACHEFUNCTION##
##ALADMINMENU##
}
if ((array_key_exists('bvreqmerge', $_POST)) || (array_key_exists('bvreqmerge', $_GET))) {
$_REQUEST = array_merge($_GET, $_POST);
}
if ($bvinfo->hasValidDBVersion()) {
##ACTLOGMODULE##
}
if ((array_key_exists('bvplugname', $_REQUEST)) && ($_REQUEST['bvplugname'] == "pantheon")) {
require_once dirname( __FILE__ ) . '/callback/base.php';
require_once dirname( __FILE__ ) . '/callback/response.php';
require_once dirname( __FILE__ ) . '/callback/request.php';
require_once dirname( __FILE__ ) . '/recover.php';
$pubkey = PTNAccount::sanitizeKey($_REQUEST['pubkey']);
if (array_key_exists('rcvracc', $_REQUEST)) {
$account = PTNRecover::find($bvsettings, $pubkey);
} else {
$account = PTNAccount::find($bvsettings, $pubkey);
}
$request = new BVCallbackRequest($account, $_REQUEST, $bvsettings);
$response = new BVCallbackResponse($request->bvb64cksize);
if ($request->authenticate() === 1) {
##BVBASEPATH##
require_once dirname( __FILE__ ) . '/callback/handler.php';
$params = $request->processParams($_REQUEST);
if ($params === false) {
$response->terminate($request->corruptedParamsResp());
}
$request->params = $params;
$callback_handler = new BVCallbackHandler($bvdb, $bvsettings, $bvsiteinfo, $request, $account, $response);
if ($request->is_afterload) {
add_action('wp_loaded', array($callback_handler, 'execute'));
} else if ($request->is_admin_ajax) {
add_action('wp_ajax_bvadm', array($callback_handler, 'bvAdmExecuteWithUser'));
add_action('wp_ajax_nopriv_bvadm', array($callback_handler, 'bvAdmExecuteWithoutUser'));
} else {
$callback_handler->execute();
}
} else {
$response->terminate($request->authFailedResp());
}
} else {
if ($bvinfo->hasValidDBVersion()) {
##PROTECTMODULE##
##DYNSYNCMODULE##
}
##WPAUTOUPDATEBLOCKMODULE##
##HIDEPLUGINUPDATEMODULE##
}
\ No newline at end of file
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzBFU9onxE3A+NpctmsLi
ZvPgj9QV2aBKDKEsRDJw7O0vyI2bpU/aScYJVOkuqlAkyrbZglJA0H+mSf+alvWp
pDFO4pyal04uxwwzji9xZ7kCSiA1wrzZFxG4SwZXpwr4qc+XtrnkSakxkyi2V4RX
ey42pOvSbSASBs6zcPq28R6LSBDhLNHho2T2qXBf7vKeuE4DR1nNcBlsLnge0x/Q
YBey+64b/8cJGyxcceAMV3F5jKI2XkkbyXtE8v+N2K5HjStyMwS3dUa4aoHl8ph4
buoEXCu6WFyUF2oMqKmkVAaE8qZQA8Q9Qni7rNHRRjVss5Z+tFOxbDBBSfsYjmvE
lQIDAQAB
-----END PUBLIC KEY-----
=== Pantheon Migrations ===
Contributors: akshatc, blogvault, getpantheon
Tags: pantheon, migration
Requires at least: 4.0
Tested up to: 6.4
Requires PHP: 5.4.0
Stable tag: 5.25
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
The easiest way to migrate your site to Pantheon
== Description ==
Pantheon is a website management platform that is the best place to run your WordPress site — hands down. And migrating your WordPress site doesn’t get any easier than with Pantheon Migrations.
With this plugin forget the headaches of manually migrating your site. All you need to activate the plugin is administrative access to your WordPress site. Just copy and paste your SFTP credentials from your new Pantheon site to the Pantheon Migrations tab in your WordPress Dashboard and click “migrate”. You can get back to work on other projects, and our migrations team will email you when everything is complete.
For full instructions please see our [docs page](https://pantheon.io/docs/migrate-wordpress/) on Pantheon Migrations.
Shout out to [BlogVault.net](https://blogvault.net/) for the development and hand in creating this plugin. By using this plugin you are agreeing to their [Terms of Service](https://blogvault.net/tos)
== Installation ==
= There are two methods =
1. Upload `bv-pantheon-migration` to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
Once the plugin is activated, click on Pantheon Migration in the left side navigation
Enter the required information:
`Destination URL:` (this will be your pantheon address you are migrating to, example: http://dev-sitename.pantheon.io)
`Machine Token:` (Machine tokens are used to uniquely identify your machine and securely authenticate via Terminus)
Click the `Migrate` button and you will be redirected to the migration landing page. The plugin will automatically verify your Machine Token and let you know if there are any issues.
After the migration is complete there will be a button you can click to see the results of your migration and automatically redirected to your Pantheon site URL.
== Frequently Asked Questions ==
= 1) I do not have a Pantheon account, can I still use this plugin? =
No, but signing up for a Pantheon account is free and so is migrating your site with Pantheon Migrations. [Sign up here!](https://pantheon.io/register)
= 2) What information will the plugin ask for? =
You will have to provide the plugin your destination url and Machine Token from your Pantheon account. Please read the [Installation section](https://wordpress.org/plugins/bv-pantheon-migration/installation/) for more information on where to find this.
= 3) Why do you need my email? =
We require an email address to send you updates on the migration process, notify you of any errors that occur during the migration.
= 4) Is Multisite supported with this plugin =
Not yet, Pantheon is currently working on testing the support of Multisite on our platform but it's still too soon. We will update this section when it's available.
= 5) How long does it take to migrate a website? =
This can range anywhere from 30 minutes to several hours depending on the size of the website. On average, migrations to Pantheon take about 1 hour.
= 6) Can I migrate a site from WordPress.com? =
Currently you can only migrate a self hosted WordPress installation, the plugin does not support migrating from WordPress.com.
= 7) What happens if I run into an error after the migration is complete? =
We are always wanting to assist and help out in any way that we can. If you encounter any type of issue please use the support section of our plugin. [Click here](https://wordpress.org/support/plugin/bv-pantheon-migration/) to file an issue. `This section is monitored daily.`
= 8) Do I need to leave the window open while the migration is processing? =
No, that's the beauty of this plugin. It runs on a SAAS based technology and a secure web address that runs everything in the background. Once you start the migration you can close the window at any time and come back to it later while it's still running, no need to wait for hours. You will also receive an email once the migration has completed.
== Screenshots ==
1. Accessing your SFTP credentials within Pantheon
2. Adding information to the Pantheon Migrations plugin
== Changelog ==
= 5.25 =
* Bug fix get_admin_url
= 5.24 =
* SHA256 Support
* Stream Improvements
= 5.22 =
* Code Improvements
* Reduced Memory Footprint
= 5.16 =
* Bug Fixes
= 5.15 =
* Upgraded Authentication
= 5.05 =
* Code Improvements for PHP 8.2 compatibility
* Site Health BugFix
= 4.97 =
* Code Improvements
* Sync Improvements
* Code Cleanup
* Bug Fixes
= 4.78 =
* Better handling for plugin, theme infos
* Sync Improvements
= 4.69 =
* Improved network call efficiency for site info callbacks.
= 4.68 =
* Removing use of constants for arrays for PHP 5.4 support.
* Post type fetch improvement.
= 4.65 =
* Robust handling of requests params.
* Callback wing versioning.
= 4.62 =
* MultiTable Sync in single callback functionality added.
* Improved host info
* Fixed services data fetch bug
* Fixed account listing bug in wp-admin
= 4.58 =
* Better Handling of error message from Server on signup
= 4.35 =
* Improved scanfiles and filelist api
= 4.31 =
* Fetching Mysql Version
* Robust data fetch APIs
* Core plugin changes
* Sanitizing incoming params
= 3.4 =
* Plugin branding fixes
= 3.2 =
* Updating account authentication struture
= 3.1 =
* Adding params validation
* Adding support for custom user tables
= 2.1 =
* Restructuring classes
= 1.88 =
* Callback improvements
= 1.86 =
* Updating tested upto 5.1
= 1.84 =
* Disable form on submit
= 1.82 =
* Updating tested upto 5.0
= 1.77 =
* Adding function_exists for getmyuid and get_current_user functions
= 1.76 =
* Removing create_funtion for PHP 7.2 compatibility
= 1.72 =
* Adding Misc Callback
= 1.71 =
* Adding logout functionality in the plugin
= 1.69 =
* Adding support for chunked base64 encoding
= 1.68 =
* Updating upload rows
= 1.66 =
* Updating TOS and privacy policies
= 1.64 =
* Bug fixes for lp and fw
= 1.62 =
* SSL support in plugin for API calls
* Adding support for plugin branding
= 1.44 =
* Removed bv_manage_site
* Updated asym_key
= 1.41 =
* Better integrity checking
* Woo Commerce Dynamic sync support
= 1.40 =
* Manage sites straight from BlogVault dashboard
= 1.31 =
* Changing dynamic backups to be pull-based
= 1.30 =
* Using dbsig based authenticatation
= 1.22 =
* Adding support for GLOB based directory listings
* Adding support for Machine Tokens instead of SFTP details
= 1.21 =
* Adding support for PHP 5 style constructors
= 1.20 =
* Adding DB Signature and Server Signature to uniquely identify a site
* Adding the stats api to the WordPress Backup plugin.
* Sending tablename/rcount as part of the callback
= 1.17 =
* Add support for repair table so that the backup plugin itself can be used to repair tables without needing PHPMyAdmin access
* Making the plugin to be available network wide.
* Adding support for 401 Auth checks on the source or destination
= 1.16 =
* Improving the Base64 Decode functionality so that it is extensible for any parameter in the future and backups can be completed for any site
* Separating out callbacks gettablecreate and getrowscount to make the backups more modular
* The plugin will now automatically ping the server once a day. This will ensure that we know if we are not doing the backup of a site where the plugin is activated.
* Use SHA1 for authentication instead of MD5
= 1.15 =
* First release of Pantheon Plugin
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('PTNRecover')) :
class PTNRecover {
public static $default_secret_key = 'bvSecretKey';
public static function defaultSecret($settings) {
$secret = self::getDefaultSecret($settings);
if (empty($secret)) {
$secret = PTNAccount::randString(32);
self::updateDefaultSecret($settings, $secret);
}
return $secret;
}
public static function deleteDefaultSecret($settings) {
$settings->deleteOption(self::$default_secret_key);
}
public static function getDefaultSecret($settings) {
return $settings->getOption(self::$default_secret_key);
}
public static function updateDefaultSecret($settings, $secret) {
$settings->updateOption(self::$default_secret_key, $secret);
}
public static function validate($pubkey) {
if ($pubkey && strlen($pubkey) >= 32) {
return true;
} else {
return false;
}
}
public static function find($settings, $pubkey) {
if (!self::validate($pubkey)) {
return null;
}
$secret = self::getDefaultSecret($settings);
if (!empty($secret) && (strlen($secret) >= 32)) {
$account = new PTNAccount($settings, $pubkey, $secret);
}
return $account;
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('PTNWPAction')) :
class PTNWPAction {
public $settings;
public $siteinfo;
public $bvinfo;
public $bvapi;
public function __construct($settings, $siteinfo, $bvapi) {
$this->settings = $settings;
$this->siteinfo = $siteinfo;
$this->bvapi = $bvapi;
$this->bvinfo = new PTNInfo($settings);
}
public function activate() {
if (!isset($_REQUEST['blogvaultkey'])) {
##BVKEYSLOCATE##
}
if (PTNAccount::isConfigured($this->settings)) {
/* This informs the server about the activation */
$info = array();
$this->siteinfo->basic($info);
$this->bvapi->pingbv('/bvapi/activate', $info);
} else {
PTNAccount::setup($this->settings);
}
}
public function deactivate() {
$info = array();
$this->siteinfo->basic($info);
##DISABLECACHE##
$this->bvapi->pingbv('/bvapi/deactivate', $info);
}
public static function uninstall() {
##CLEARPTCONFIG##
##CLEARIPSTORE##
##CLEARDYNSYNCCONFIG##
##CLEARCACHECONFIG##
do_action('clear_bv_services_config');
}
public function clear_bv_services_config() {
$this->settings->deleteOption($this->bvinfo->services_option_name);
}
##SOUNINSTALLFUNCTION##
public function footerHandler() {
$bvfooter = $this->settings->getOption($this->bvinfo->badgeinfo);
if ($bvfooter) {
echo '<div style="max-width:150px;min-height:70px;margin:0 auto;text-align:center;position:relative;">
<a href='.esc_url($bvfooter['badgeurl']).' target="_blank" ><img src="'.esc_url(plugins_url($bvfooter['badgeimg'], __FILE__)).'" alt="'.esc_attr($bvfooter['badgealt']).'" /></a></div>';
}
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('PTNWPAdmin')) :
class PTNWPAdmin {
public $settings;
public $siteinfo;
public $bvinfo;
public $bvapi;
function __construct($settings, $siteinfo, $bvapi = null) {
$this->settings = $settings;
$this->siteinfo = $siteinfo;
$this->bvapi = $bvapi;
$this->bvinfo = new PTNInfo($this->settings);
}
public function mainUrl($_params = '') {
if (function_exists('network_admin_url')) {
return network_admin_url('admin.php?page='.$this->bvinfo->plugname.$_params);
} else {
return admin_url('admin.php?page='.$this->bvinfo->plugname.$_params);
}
}
function removeAdminNotices() {
if (array_key_exists('page', $_REQUEST) && $_REQUEST['page'] == $this->bvinfo->plugname) {
remove_all_actions('admin_notices');
remove_all_actions('all_admin_notices');
}
}
public function initHandler() {
if (!current_user_can('activate_plugins'))
return;
if ($this->bvinfo->isActivateRedirectSet()) {
$this->settings->updateOption($this->bvinfo->plug_redirect, 'no');
wp_redirect($this->mainUrl());
}
}
public function menu() {
$brand = $this->bvinfo->getBrandInfo();
if (!is_array($brand) || (!array_key_exists('hide', $brand) && !array_key_exists('hide_from_menu', $brand))) {
$bname = $this->bvinfo->getBrandName();
$icon = $this->bvinfo->getBrandIcon();
add_menu_page($bname, $bname, 'manage_options', $this->bvinfo->plugname,
array($this, 'adminPage'), plugins_url($icon, __FILE__ ));
}
}
public function hidePluginDetails($plugin_metas, $slug) {
$brand = $this->bvinfo->getBrandInfo();
$bvslug = $this->bvinfo->slug;
if ($slug === $bvslug && is_array($brand) && array_key_exists('hide_plugin_details', $brand)) {
foreach ($plugin_metas as $pluginKey => $pluginValue) {
if (strpos($pluginValue, sprintf('>%s<', translate('View details')))) {
unset($plugin_metas[$pluginKey]);
break;
}
}
}
return $plugin_metas;
}
public function settingsLink($links, $file) {
if ( $file == plugin_basename( dirname(__FILE__).'/pantheon.php' ) ) {
$links[] = '<a href="'.$this->mainUrl().'">'.__( 'Settings' ).'</a>';
}
return $links;
}
public function ptnsecAdminMenu($hook) {
if ($hook === 'toplevel_page_pantheon') {
wp_enqueue_style( 'ptnsurface', plugins_url( 'css/style.css', __FILE__));
wp_enqueue_style('ptnsurface');
}
}
public function getPluginLogo() {
$brand = $this->bvinfo->getBrandInfo();
if ($brand && array_key_exists('logo', $brand)) {
return $brand['logo'];
}
return $this->bvinfo->logo;
}
public function getWebPage() {
$brand = $this->bvinfo->getBrandInfo();
if ($brand && array_key_exists('webpage', $brand)) {
return $brand['webpage'];
}
return $this->bvinfo->webpage;
}
public function siteInfoTags() {
require_once dirname( __FILE__ ) . '/recover.php';
$secret = PTNRecover::defaultSecret($this->settings);
$public = PTNAccount::getApiPublicKey($this->settings);
$tags = "<input type='hidden' name='url' value='".esc_attr($this->siteinfo->wpurl())."'/>\n".
"<input type='hidden' name='homeurl' value='".esc_attr($this->siteinfo->homeurl())."'/>\n".
"<input type='hidden' name='siteurl' value='".esc_attr($this->siteinfo->siteurl())."'/>\n".
"<input type='hidden' name='dbsig' value='".esc_attr($this->siteinfo->dbsig(false))."'/>\n".
"<input type='hidden' name='plug' value='".esc_attr($this->bvinfo->plugname)."'/>\n".
"<input type='hidden' name='adminurl' value='".esc_attr($this->mainUrl())."'/>\n".
"<input type='hidden' name='bvversion' value='".esc_attr($this->bvinfo->version)."'/>\n".
"<input type='hidden' name='serverip' value='".esc_attr($_SERVER["SERVER_ADDR"])."'/>\n".
"<input type='hidden' name='abspath' value='".esc_attr(ABSPATH)."'/>\n".
"<input type='hidden' name='secret' value='".esc_attr($secret)."'/>\n".
"<input type='hidden' name='public' value='".esc_attr($public)."'/>\n";
return $tags;
}
public function activateWarning() {
global $hook_suffix;
if (!PTNAccount::isConfigured($this->settings) && $hook_suffix == 'index.php' ) {
?>
<div id="message" class="updated" style="padding: 8px; font-size: 16px; background-color: #dff0d8">
<a class="button-primary" href="<?php echo esc_url($this->mainUrl()); ?>">Activate Pantheon</a>
&nbsp;&nbsp;&nbsp;<b>Almost Done:</b> Activate your Pantheon account to migrate your site.
</div>
<?php
}
}
public function adminPage() {
require_once dirname( __FILE__ ) . '/admin/main_page.php';
}
public function initBranding($plugins) {
$slug = $this->bvinfo->slug;
if (!is_array($plugins) || !isset($slug, $plugins)) {
return $plugins;
}
$brand = $this->bvinfo->getBrandInfo();
if (is_array($brand)) {
if (array_key_exists('hide', $brand)) {
unset($plugins[$slug]);
} else {
if (array_key_exists('name', $brand)) {
$plugins[$slug]['Name'] = $brand['name'];
}
if (array_key_exists('title', $brand)) {
$plugins[$slug]['Title'] = $brand['title'];
}
if (array_key_exists('description', $brand)) {
$plugins[$slug]['Description'] = $brand['description'];
}
if (array_key_exists('authoruri', $brand)) {
$plugins[$slug]['AuthorURI'] = $brand['authoruri'];
}
if (array_key_exists('author', $brand)) {
$plugins[$slug]['Author'] = $brand['author'];
}
if (array_key_exists('authorname', $brand)) {
$plugins[$slug]['AuthorName'] = $brand['authorname'];
}
if (array_key_exists('pluginuri', $brand)) {
$plugins[$slug]['PluginURI'] = $brand['pluginuri'];
}
}
}
return $plugins;
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('PTNWPAPI')) :
class PTNWPAPI {
public $settings;
public function __construct($settings) {
$this->settings = $settings;
}
public function pingbv($method, $body, $public = false) {
if ($public) {
return $this->do_request($method, $body, $public);
} else {
$api_public_key = $this->settings->getOption('bvApiPublic');
if (!empty($api_public_key) && (strlen($api_public_key) >= 32)) {
return $this->do_request($method, $body, $api_public_key);
}
}
}
public function do_request($method, $body, $pubkey) {
$account = PTNAccount::find($this->settings, $pubkey);
if (isset($account)) {
$url = $account->authenticatedUrl($method);
return $this->http_request($url, $body);
}
}
public function http_request($url, $body, $headers = array()) {
$_body = array(
'method' => 'POST',
'timeout' => 15,
'body' => $body
);
if (!empty($headers)) {
$_body['headers'] = $headers;
}
return wp_remote_post($url, $_body);
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('PTNWPDb')) :
class PTNWPDb {
public function dbprefix() {
global $wpdb;
$prefix = $wpdb->base_prefix ? $wpdb->base_prefix : $wpdb->prefix;
return $prefix;
}
public function prepare($query, $args) {
global $wpdb;
return $wpdb->prepare($query, $args);
}
public function getSiteId() {
global $wpdb;
return $wpdb->siteid;
}
public function getResult($query, $obj = ARRAY_A) {
global $wpdb;
return $wpdb->get_results($query, $obj);
}
public function query($query) {
global $wpdb;
return $wpdb->query($query);
}
public function getVar($query, $col = 0, $row = 0) {
global $wpdb;
return $wpdb->get_var($query, $col, $row);
}
public function getCol($query, $col = 0) {
global $wpdb;
return $wpdb->get_col($query, $col);
}
public function tableName($table) {
return $table[0];
}
public function showTables() {
$tables = $this->getResult("SHOW TABLES", ARRAY_N);
return array_map(array($this, 'tableName'), $tables);
}
public function showTableStatus() {
return $this->getResult("SHOW TABLE STATUS");
}
public function tableKeys($table) {
return $this->getResult("SHOW KEYS FROM $table;");
}
public function showDbVariables($variable) {
$variables = $this->getResult("Show variables like '%$variable%' ;");
$result = array();
foreach ($variables as $variable) {
$result[$variable["Variable_name"]] = $variable["Value"];
}
return $result;
}
public function describeTable($table) {
return $this->getResult("DESCRIBE $table;");
}
public function showTableIndex($table) {
return $this->getResult("SHOW INDEX FROM $table");
}
public function checkTable($table, $type) {
return $this->getResult("CHECK TABLE $table $type;");
}
public function repairTable($table) {
return $this->getResult("REPAIR TABLE $table;");
}
public function showTableCreate($table) {
return $this->getVar("SHOW CREATE TABLE $table;", 1);
}
public function rowsCount($table) {
$count = $this->getVar("SELECT COUNT(*) FROM $table;");
return intval($count);
}
public function createTable($query, $name, $usedbdelta = false) {
$table = $this->getBVTable($name);
if (!$this->isTablePresent($table)) {
if ($usedbdelta) {
if (!function_exists('dbDelta'))
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta($query);
} else {
$this->query($query);
}
}
return $this->isTablePresent($table);
}
public function createTables($tables, $usedbdelta = false) {
$result = array();
foreach ($tables as $table => $query) {
$result[$table] = $this->createTable($query, $table, $usedbdelta);
}
return $result;
}
public function alterBVTable($query, $name) {
$resp = false;
$table = $this->getBVTable($name);
if ($this->isTablePresent($table)) {
$resp = $this->query($query);
}
return $resp;
}
public function alterTables($tables) {
$result = array();
foreach ($tables as $table => $query) {
$result[$table] = $this->alterBVTable($query, $table);
}
return $result;
}
public function getTableContent($table, $fields = '*', $filter = '', $limit = 0, $offset = 0) {
$query = "SELECT $fields from $table $filter";
if ($limit > 0)
$query .= " LIMIT $limit";
if ($offset > 0)
$query .= " OFFSET $offset";
$rows = $this->getResult($query);
return $rows;
}
public function isTablePresent($table) {
return ($this->getVar("SHOW TABLES LIKE '$table'") === $table);
}
public function getCharsetCollate() {
global $wpdb;
return $wpdb->get_charset_collate();
}
public function getWPTable($name) {
return ($this->dbprefix() . $name);
}
public function getBVTable($name) {
return ($this->getWPTable("bv_" . $name));
}
public function truncateBVTable($name) {
$table = $this->getBVTable($name);
if ($this->isTablePresent($table)) {
return $this->query("TRUNCATE TABLE $table;");
} else {
return false;
}
}
public function deleteBVTableContent($name, $filter = "") {
$table = $this->getBVTable($name);
if ($this->isTablePresent($table)) {
return $this->query("DELETE FROM $table $filter;");
} else {
return false;
}
}
public function dropBVTable($name) {
$table = $this->getBVTable($name);
if ($this->isTablePresent($table)) {
$this->query("DROP TABLE IF EXISTS $table;");
}
return !$this->isTablePresent($table);
}
public function dropTables($tables) {
$result = array();
foreach ($tables as $table) {
$result[$table] = $this->dropBVTable($table);
}
return $result;
}
public function truncateTables($tables) {
$result = array();
foreach ($tables as $table) {
$result[$table] = $this->truncateBVTable($table);
}
return $result;
}
public function deleteRowsFromtable($name, $count = 1) {
$table = $this->getBVTable($name);
if ($this->isTablePresent($table)) {
return $this->getResult("DELETE FROM $table LIMIT $count;");
} else {
return false;
}
}
public function replaceIntoBVTable($name, $value) {
global $wpdb;
$table = $this->getBVTable($name);
return $wpdb->replace($table, $value);
}
public function tinfo($name) {
$result = array();
$table = $this->getBVTable($name);
$result['name'] = $table;
if ($this->isTablePresent($table)) {
$result['exists'] = true;
$result['createquery'] = $this->showTableCreate($table);
}
return $result;
}
public function getMysqlVersion() {
return $this->showDbVariables('version')['version'];
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('PTNWPSettings')) :
class PTNWPSettings {
public function getOption($key) {
$res = false;
if (function_exists('get_site_option')) {
$res = get_site_option($key, false);
}
if ($res === false) {
$res = get_option($key, false);
}
return $res;
}
public function deleteOption($key) {
if (function_exists('delete_site_option')) {
return delete_site_option($key);
} else {
return delete_option($key);
}
}
public function updateOption($key, $value) {
if (function_exists('update_site_option')) {
return update_site_option($key, $value);
} else {
return update_option($key, $value);
}
}
public function getOptions($options = array()) {
$result = array();
foreach ($options as $option)
$result[$option] = $this->getOption($option);
return $result;
}
public function updateOptions($args) {
$result = array();
foreach ($args as $option => $value) {
$this->updateOption($option, $value);
$result[$option] = $this->getOption($option);
}
return $result;
}
public function deleteOptions($options) {
$result = array();
foreach ($options as $option) {
$this->deleteOption($option);
$result[$option] = !$this->getOption($option);
}
return $result;
}
public function setTransient($name, $value, $time) {
if (function_exists('set_site_transient')) {
return set_site_transient($name, $value, $time);
}
return false;
}
public function deleteTransient($name) {
if (function_exists('delete_site_transient')) {
return delete_site_transient($name);
}
return false;
}
public function getTransient($name) {
if (function_exists('get_site_transient')) {
return get_site_transient($name);
}
return false;
}
}
endif;
\ No newline at end of file
<?php
if (!defined('ABSPATH')) exit;
if (!class_exists('PTNWPSiteInfo')) :
class PTNWPSiteInfo {
public function wpurl() {
if (function_exists('network_site_url'))
return network_site_url();
else
return get_bloginfo('wpurl');
}
public function siteurl($path = '', $scheme = null) {
if (function_exists('site_url')) {
return site_url($path, $scheme);
} else {
return get_bloginfo('wpurl');
}
}
public function homeurl() {
if (function_exists('home_url')) {
return home_url();
} else {
return get_bloginfo('url');
}
}
public function isMultisite() {
if (function_exists('is_multisite') && is_multisite())
return true;
return false;
}
public function isMainSite() {
if (!function_exists('is_main_site' ) || !$this->isMultisite())
return true;
return is_main_site();
}
public function getMainSiteId() {
if (!function_exists('get_main_site_id'))
return 0;
return get_main_site_id();
}
public function info() {
$info = array();
$this->basic($info);
$info['dbsig'] = $this->dbsig(false);
$info["serversig"] = $this->serversig(false);
return $info;
}
public function basic(&$info) {
$info['wpurl'] = $this->wpurl();
$info['siteurl'] = $this->siteurl();
$info['homeurl'] = $this->homeurl();
if (array_key_exists('SERVER_ADDR', $_SERVER)) {
$info['serverip'] = $_SERVER['SERVER_ADDR'];
}
$info['abspath'] = ABSPATH;
}
public function serversig($full = false) {
$sig_param = ABSPATH;
if (array_key_exists('SERVER_ADDR', $_SERVER)) {
$sig_param = $_SERVER['SERVER_ADDR'].ABSPATH;
}
$sig = sha1($sig_param);
if ($full)
return $sig;
else
return substr($sig, 0, 6);
}
public function dbsig($full = false) {
if (defined('DB_USER') && defined('DB_NAME') &&
defined('DB_PASSWORD') && defined('DB_HOST')) {
$sig = sha1(DB_USER.DB_NAME.DB_PASSWORD.DB_HOST);
} else {
$sig = "bvnone".PTNAccount::randString(34);
}
if ($full)
return $sig;
else
return substr($sig, 0, 6);
}
public static function isCWServer() {
return isset($_SERVER['cw_allowed_ip']);
}
}
endif;
\ No newline at end of file