mirror of
https://gh.llkk.cc/https://github.com/CaptainCore/captaincore-manager.git
synced 2025-10-03 14:04:44 +08:00
📦 NEW: Composer autoload
This commit is contained in:
parent
4ce9cdd7db
commit
48424b9b79
27 changed files with 2405 additions and 1795 deletions
328
app/Account.php
Normal file
328
app/Account.php
Normal file
|
@ -0,0 +1,328 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class Account {
|
||||
|
||||
protected $account_id = "";
|
||||
|
||||
public function __construct( $account_id = "", $admin = false ) {
|
||||
|
||||
if ( captaincore_verify_permissions_account( $account_id ) ) {
|
||||
$this->account_id = $account_id;
|
||||
}
|
||||
|
||||
if ( $admin ) {
|
||||
$this->account_id = $account_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function invite( $email ) {
|
||||
if ( email_exists( $email ) ) {
|
||||
$user = get_user_by( 'email', $email );
|
||||
// Add account ID to current user
|
||||
$accounts = get_field( 'partner', "user_{$user->ID}" );
|
||||
$accounts[] = $this->account_id;
|
||||
update_field( 'partner', array_unique( $accounts ), "user_{$user->ID}" );
|
||||
$this->calculate_totals();
|
||||
|
||||
return [ "message" => "Account already exists. Adding permissions for existing user." ];
|
||||
}
|
||||
|
||||
$time_now = date("Y-m-d H:i:s");
|
||||
$token = bin2hex( openssl_random_pseudo_bytes( 24 ) );
|
||||
$new_invite = array(
|
||||
'email' => $email,
|
||||
'account_id' => $this->account_id,
|
||||
'created_at' => $time_now,
|
||||
'updated_at' => $time_now,
|
||||
'token' => $token
|
||||
);
|
||||
$invite = new invites();
|
||||
$invite_id = $invite->insert( $new_invite );
|
||||
|
||||
// Send out invite email
|
||||
$invite_url = home_url() . "/account/?account={$this->account_id}&token={$token}";
|
||||
$account_name = get_the_title( $this->account_id );
|
||||
$subject = "Hosting account invite";
|
||||
$body = "You've been granted access to account '$account_name'. Click here to accept:<br /><br /><a href=\"{$invite_url}\">$invite_url</a>";
|
||||
$headers = [ 'Content-Type: text/html; charset=UTF-8' ];
|
||||
|
||||
wp_mail( $email, $subject, $body, $headers );
|
||||
|
||||
return [ "message" => "Invite has been sent." ];
|
||||
}
|
||||
|
||||
public function account() {
|
||||
|
||||
return [
|
||||
"id" => $this->account_id,
|
||||
"name" => get_the_title( $this->account_id ),
|
||||
'website_count' => get_field( "website_count", $this->account_id ),
|
||||
'user_count' => get_field( "user_count", $this->account_id ),
|
||||
'domain_count' => count( get_field( "domains", $this->account_id ) ),
|
||||
];
|
||||
}
|
||||
|
||||
public function invites() {
|
||||
$invites = new invites();
|
||||
return $invites->where( [ "account_id" => $this->account_id, "accepted_at" => "0000-00-00 00:00:00" ] );
|
||||
}
|
||||
|
||||
public function domains() {
|
||||
|
||||
$all_domains = [];
|
||||
$customers = [];
|
||||
$partner = [ $this->account_id ];
|
||||
|
||||
$websites_for_partner = get_posts(
|
||||
array(
|
||||
'post_type' => 'captcore_website',
|
||||
'posts_per_page' => '-1',
|
||||
'order' => 'asc',
|
||||
'orderby' => 'title',
|
||||
'fields' => 'ids',
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => 'partner', // name of custom field
|
||||
'value' => '"' . $this->account_id . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $websites_for_partner as $website ) {
|
||||
$customers[] = get_field( 'customer', $website );
|
||||
}
|
||||
|
||||
if ( count( $customers ) == 0 and is_array( $partner ) ) {
|
||||
foreach ( $partner as $partner_id ) {
|
||||
$websites_for_partner = get_posts(
|
||||
array(
|
||||
'post_type' => 'captcore_website',
|
||||
'posts_per_page' => '-1',
|
||||
'order' => 'asc',
|
||||
'orderby' => 'title',
|
||||
'fields' => 'ids',
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => 'customer', // name of custom field
|
||||
'value' => '"' . $partner_id . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
foreach ( $websites_for_partner as $website ) {
|
||||
$customers[] = get_field( 'customer', $website );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $customers as $customer ) :
|
||||
|
||||
if ( is_array( $customer ) ) {
|
||||
$customer = $customer[0];
|
||||
}
|
||||
|
||||
$domains = get_field( 'domains', $customer );
|
||||
if ( $domains ) {
|
||||
foreach ( $domains as $domain ) :
|
||||
$domain_name = get_the_title( $domain );
|
||||
$domain_id = get_field( "domain_id", $domain );
|
||||
if ( $domain_name ) {
|
||||
$all_domains[ $domain_name ] = array( "name" => $domain_name, "id" => $domain_id );
|
||||
}
|
||||
endforeach;
|
||||
}
|
||||
|
||||
endforeach;
|
||||
|
||||
foreach ( $partner as $customer ) :
|
||||
$domains = get_field( 'domains', $customer );
|
||||
if ( $domains ) {
|
||||
foreach ( $domains as $domain ) :
|
||||
$domain_name = get_the_title( $domain );
|
||||
$domain_id = get_field( "domain_id", $domain );
|
||||
if ( $domain_name ) {
|
||||
$all_domains[ $domain_name ] = array( "name" => $domain_name, "id" => $domain_id );
|
||||
}
|
||||
endforeach;
|
||||
}
|
||||
endforeach;
|
||||
|
||||
usort( $all_domains, "sort_by_name" );
|
||||
return $all_domains;
|
||||
|
||||
}
|
||||
|
||||
public function sites() {
|
||||
|
||||
$results = [];
|
||||
$websites = get_posts(
|
||||
array(
|
||||
'post_type' => 'captcore_website',
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'customer', // name of custom field
|
||||
'value' => '"' . $this->account_id . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
if ( $websites ) {
|
||||
foreach ( $websites as $website ) {
|
||||
if ( get_field( 'status', $website->ID ) == 'active' ) {
|
||||
$results[] = array(
|
||||
"name" => get_the_title( $website->ID ),
|
||||
"site_id" => $website->ID,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$websites = get_posts(
|
||||
array(
|
||||
'post_type' => 'captcore_website',
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'partner', // name of custom field
|
||||
'value' => '"' . $this->account_id . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
if ( $websites ) {
|
||||
foreach ( $websites as $website ) {
|
||||
if ( get_field( 'status', $website->ID ) == 'active' ) {
|
||||
if ( in_array( $website->ID, array_column( $results, "site_id" ) ) ) {
|
||||
continue;
|
||||
}
|
||||
$results[] = array(
|
||||
"name" => get_the_title( $website->ID ),
|
||||
"site_id" => $website->ID,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
usort( $results, "sort_by_name" );
|
||||
|
||||
return $results;
|
||||
|
||||
}
|
||||
|
||||
public function users() {
|
||||
|
||||
$args = array (
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'display_name',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'partner',
|
||||
'value' => '"' . $this->account_id . '"',
|
||||
'compare' => 'LIKE'
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Create the WP_User_Query object
|
||||
$wp_user_query = new \WP_User_Query($args);
|
||||
$users = $wp_user_query->get_results();
|
||||
$results = [];
|
||||
|
||||
foreach( $users as $user ) {
|
||||
$results[] = array(
|
||||
"user_id" => $user->ID,
|
||||
"name" => $user->display_name,
|
||||
"email" => $user->user_email,
|
||||
"level" => ""
|
||||
);
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
||||
}
|
||||
|
||||
public function calculate_totals() {
|
||||
|
||||
// Calculate active website count
|
||||
$websites_by_customer = get_posts(
|
||||
array(
|
||||
'post_type' => 'captcore_website',
|
||||
'fields' => 'ids',
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => 'customer', // name of custom field
|
||||
'value' => '"' . $this->account_id . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
array(
|
||||
'key' => 'status',
|
||||
'value' => 'active',
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$websites_by_partners = get_posts(
|
||||
array(
|
||||
'post_type' => 'captcore_website',
|
||||
'fields' => 'ids',
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => 'partner', // name of custom field
|
||||
'value' => '"' . $this->account_id . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
array(
|
||||
'key' => 'status',
|
||||
'value' => 'active',
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$websites = array_unique(array_merge($websites_by_customer, $websites_by_partners));
|
||||
$args = array (
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'display_name',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'partner',
|
||||
'value' => '"' . $this->account_id . '"',
|
||||
'compare' => 'LIKE'
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Create the WP_User_Query object
|
||||
$wp_user_query = new \WP_User_Query($args);
|
||||
$users = $wp_user_query->get_results();
|
||||
update_field( 'website_count', count( $websites ), $this->account_id );
|
||||
update_field( 'user_count', count( $users ), $this->account_id );
|
||||
}
|
||||
|
||||
public function fetch() {
|
||||
$record = array (
|
||||
"users" => $this->users(),
|
||||
"invites" => $this->invites(),
|
||||
"domains" => $this->domains(),
|
||||
"sites" => $this->sites(),
|
||||
"account" => $this->account(),
|
||||
);
|
||||
return $record;
|
||||
}
|
||||
|
||||
}
|
58
app/Accounts.php
Normal file
58
app/Accounts.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class Accounts {
|
||||
|
||||
protected $accounts = [];
|
||||
|
||||
public function __construct( $accounts = [] ) {
|
||||
|
||||
$user = wp_get_current_user();
|
||||
$role_check = in_array( 'subscriber', $user->roles ) + in_array( 'customer', $user->roles ) + in_array( 'administrator', $user->roles ) + in_array( 'editor', $user->roles );
|
||||
|
||||
// Bail if not assigned a role
|
||||
if ( ! $role_check ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$account_ids = get_field( 'partner', 'user_' . get_current_user_id() );
|
||||
if ( in_array( 'administrator', $user->roles ) ) {
|
||||
$account_ids = get_posts([
|
||||
'post_type' => 'captcore_customer',
|
||||
'fields' => 'ids',
|
||||
'numberposts' => '-1'
|
||||
]);
|
||||
}
|
||||
|
||||
$accounts = [];
|
||||
|
||||
if ( $account_ids ) {
|
||||
foreach ( $account_ids as $account_id ) {
|
||||
if ( get_field( 'partner', $account_id ) ) {
|
||||
$developer = true;
|
||||
} else {
|
||||
$developer = false;
|
||||
}
|
||||
$accounts[] = (object) [
|
||||
'id' => $account_id,
|
||||
'name' => get_the_title( $account_id ),
|
||||
'website_count' => get_field( "website_count", $account_id ),
|
||||
'user_count' => get_field( "user_count", $account_id ),
|
||||
'domain_count' => count( get_field( "domains", $account_id ) ),
|
||||
'developer' => $developer
|
||||
];
|
||||
}
|
||||
}
|
||||
usort($accounts, function($a, $b) {
|
||||
return strcmp( ucfirst($a->name), ucfirst($b->name));
|
||||
});
|
||||
|
||||
$this->accounts = $accounts;
|
||||
|
||||
}
|
||||
|
||||
public function all() {
|
||||
return $this->accounts;
|
||||
}
|
||||
}
|
381
app/DB.php
Normal file
381
app/DB.php
Normal file
|
@ -0,0 +1,381 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class DB {
|
||||
|
||||
private static function _table() {
|
||||
global $wpdb;
|
||||
$tablename = str_replace( '\\', '_', strtolower( get_called_class() ) );
|
||||
return $wpdb->prefix . $tablename;
|
||||
}
|
||||
|
||||
private static function _fetch_sql( $value ) {
|
||||
global $wpdb;
|
||||
$sql = sprintf( 'SELECT * FROM %s WHERE %s = %%s', self::_table(), static::$primary_key );
|
||||
return $wpdb->prepare( $sql, $value );
|
||||
}
|
||||
|
||||
static function valid_check( $data ) {
|
||||
global $wpdb;
|
||||
|
||||
$sql_where = '';
|
||||
$sql_where_count = count( $data );
|
||||
$i = 1;
|
||||
foreach ( $data as $key => $row ) {
|
||||
if ( $i < $sql_where_count ) {
|
||||
$sql_where .= "`$key` = '$row' and ";
|
||||
} else {
|
||||
$sql_where .= "`$key` = '$row'";
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$sql = 'SELECT * FROM ' . self::_table() . " WHERE $sql_where";
|
||||
$results = $wpdb->get_results( $sql );
|
||||
if ( count( $results ) != 0 ) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static function get( $value ) {
|
||||
global $wpdb;
|
||||
return $wpdb->get_row( self::_fetch_sql( $value ) );
|
||||
}
|
||||
|
||||
static function insert( $data ) {
|
||||
global $wpdb;
|
||||
$wpdb->insert( self::_table(), $data );
|
||||
return $wpdb->insert_id;
|
||||
}
|
||||
|
||||
static function update( $data, $where ) {
|
||||
global $wpdb;
|
||||
$wpdb->update( self::_table(), $data, $where );
|
||||
}
|
||||
|
||||
static function delete( $value ) {
|
||||
global $wpdb;
|
||||
$sql = sprintf( 'DELETE FROM %s WHERE %s = %%s', self::_table(), static::$primary_key );
|
||||
return $wpdb->query( $wpdb->prepare( $sql, $value ) );
|
||||
}
|
||||
|
||||
static function fetch_logs( $value, $environment_id ) {
|
||||
global $wpdb;
|
||||
$value = intval( $value );
|
||||
$environment_id = intval( $environment_id );
|
||||
$sql = 'SELECT * FROM ' . self::_table() . " WHERE `site_id` = '$value' and `environment_id` = '$environment_id'";
|
||||
$results = $wpdb->get_results( $sql );
|
||||
$response = [];
|
||||
foreach ( $results as $result ) {
|
||||
|
||||
$update_log = json_decode( $result->update_log );
|
||||
|
||||
foreach ( $update_log as $log ) {
|
||||
$log->type = $result->update_type;
|
||||
$log->date = $result->created_at;
|
||||
$response[] = $log;
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
static function where( $conditions ) {
|
||||
global $wpdb;
|
||||
$where_statements = [];
|
||||
foreach ( $conditions as $row => $value ) {
|
||||
$where_statements[] = "`{$row}` = '{$value}'";
|
||||
}
|
||||
$where_statements = implode( " AND ", $where_statements );
|
||||
$sql = 'SELECT * FROM ' . self::_table() . " WHERE $where_statements order by `created_at` DESC";
|
||||
return $wpdb->get_results( $sql );
|
||||
}
|
||||
|
||||
static function fetch( $value ) {
|
||||
global $wpdb;
|
||||
$value = intval( $value );
|
||||
$sql = 'SELECT * FROM ' . self::_table() . " WHERE `site_id` = '$value' order by `created_at` DESC";
|
||||
return $wpdb->get_results( $sql );
|
||||
}
|
||||
|
||||
static function fetch_environment( $value, $environment_id ) {
|
||||
global $wpdb;
|
||||
$value = intval( $value );
|
||||
$environment_id = intval( $environment_id );
|
||||
$sql = 'SELECT * FROM ' . self::_table() . " WHERE `site_id` = '$value' and `environment_id` = '$environment_id' order by `created_at` DESC";
|
||||
return $wpdb->get_results( $sql );
|
||||
}
|
||||
|
||||
static function all( $sort = "created_at", $sort_order = "DESC" ) {
|
||||
global $wpdb;
|
||||
$sql = 'SELECT * FROM ' . self::_table() . ' order by `' . $sort . '` '. $sort_order;
|
||||
return $wpdb->get_results( $sql );
|
||||
}
|
||||
|
||||
static function mine( $sort = "created_at", $sort_order = "DESC" ) {
|
||||
global $wpdb;
|
||||
$user_id = get_current_user_id();
|
||||
$sql = 'SELECT * FROM ' . self::_table() . " WHERE user_id = '{$user_id}' order by `{$sort}` {$sort_order}";
|
||||
return $wpdb->get_results( $sql );
|
||||
}
|
||||
|
||||
static function fetch_recipes( $sort = "created_at", $sort_order = "DESC" ) {
|
||||
global $wpdb;
|
||||
$user_id = get_current_user_id();
|
||||
$sql = 'SELECT * FROM ' . self::_table() . " WHERE user_id = '{$user_id}' or `public` = '1' order by `{$sort}` {$sort_order}";
|
||||
return $wpdb->get_results( $sql );
|
||||
}
|
||||
|
||||
static function fetch_environments( $value ) {
|
||||
global $wpdb;
|
||||
$value = intval( $value );
|
||||
$sql = 'SELECT * FROM ' . self::_table() . " WHERE `site_id` = '$value' order by `environment` ASC";
|
||||
return $wpdb->get_results( $sql );
|
||||
}
|
||||
|
||||
static function fetch_field( $value, $environment, $field ) {
|
||||
global $wpdb;
|
||||
$value = intval( $value );
|
||||
$sql = "SELECT $field FROM " . self::_table() . " WHERE `site_id` = '$value' and `environment` = '$environment' order by `created_at` DESC";
|
||||
return $wpdb->get_results( $sql );
|
||||
}
|
||||
|
||||
static function fetch_by_environments( $site_id ) {
|
||||
|
||||
$results = [];
|
||||
|
||||
$environment_id = get_field( 'environment_production_id', $site_id );
|
||||
if ( $environment_id != "" ) {
|
||||
$results["Production"] = self::fetch_environment( $site_id, $environment_id );
|
||||
}
|
||||
|
||||
$environment_id = get_field( 'environment_staging_id', $site_id );
|
||||
if ( $environment_id != "" ) {
|
||||
$results["Staging"] = self::fetch_environment( $site_id, $environment_id );
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
// Perform CaptainCore database upgrades by running `CaptainCore\DB::upgrade();`
|
||||
public static function upgrade() {
|
||||
$required_version = 17;
|
||||
$version = (int) get_site_option( 'captcorecore_db_version' );
|
||||
|
||||
if ( $version >= $required_version ) {
|
||||
return "Not needed `captcorecore_db_version` is v{$version} and required v{$required_version}.";
|
||||
}
|
||||
|
||||
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
||||
global $wpdb;
|
||||
$charset_collate = $wpdb->get_charset_collate();
|
||||
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_update_logs` (
|
||||
log_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
site_id bigint(20) UNSIGNED NOT NULL,
|
||||
environment_id bigint(20) UNSIGNED NOT NULL,
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
update_type varchar(255),
|
||||
update_log longtext,
|
||||
PRIMARY KEY (log_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_quicksaves` (
|
||||
quicksave_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
site_id bigint(20) UNSIGNED NOT NULL,
|
||||
environment_id bigint(20) UNSIGNED NOT NULL,
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
git_status varchar(255),
|
||||
git_commit varchar(100),
|
||||
core varchar(10),
|
||||
themes longtext,
|
||||
plugins longtext,
|
||||
PRIMARY KEY (quicksave_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_snapshots` (
|
||||
snapshot_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
user_id bigint(20) UNSIGNED NOT NULL,
|
||||
site_id bigint(20) UNSIGNED NOT NULL,
|
||||
environment_id bigint(20) UNSIGNED NOT NULL,
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
snapshot_name varchar(255),
|
||||
storage varchar(20),
|
||||
email varchar(100),
|
||||
notes longtext,
|
||||
expires_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
token varchar(32),
|
||||
PRIMARY KEY (snapshot_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_environments` (
|
||||
environment_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
site_id bigint(20) UNSIGNED NOT NULL,
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
environment varchar(255),
|
||||
address varchar(255),
|
||||
username varchar(255),
|
||||
password varchar(255),
|
||||
protocol varchar(255),
|
||||
port varchar(255),
|
||||
fathom varchar(255),
|
||||
home_directory varchar(255),
|
||||
database_username varchar(255),
|
||||
database_password varchar(255),
|
||||
offload_enabled boolean,
|
||||
offload_provider varchar(255),
|
||||
offload_access_key varchar(255),
|
||||
offload_secret_key varchar(255),
|
||||
offload_bucket varchar(255),
|
||||
offload_path varchar(255),
|
||||
storage varchar(20),
|
||||
visits varchar(20),
|
||||
core varchar(10),
|
||||
subsite_count varchar(10),
|
||||
home_url varchar(255),
|
||||
themes longtext,
|
||||
plugins longtext,
|
||||
users longtext,
|
||||
screenshot boolean,
|
||||
updates_enabled boolean,
|
||||
updates_exclude_themes longtext,
|
||||
updates_exclude_plugins longtext,
|
||||
PRIMARY KEY (environment_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_recipes` (
|
||||
recipe_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
user_id bigint(20) UNSIGNED NOT NULL,
|
||||
title varchar(255),
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
content longtext,
|
||||
public boolean,
|
||||
PRIMARY KEY (recipe_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_keys` (
|
||||
key_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
user_id bigint(20) UNSIGNED NOT NULL,
|
||||
title varchar(255),
|
||||
fingerprint varchar(47),
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (key_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_invites` (
|
||||
invite_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
account_id bigint(20) UNSIGNED NOT NULL,
|
||||
email varchar(255),
|
||||
token varchar(255),
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
accepted_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (invite_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
// Permission/relationships data stucture for CaptainCore: https://dbdiagram.io/d/5d7d409283427516dc0ba8b3
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_accounts` (
|
||||
account_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
name varchar(255),
|
||||
defaults longtext,
|
||||
plan longtext,
|
||||
account_usage longtext,
|
||||
status varchar(255),
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (account_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_sites` (
|
||||
site_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
account_id bigint(20) UNSIGNED NOT NULL,
|
||||
environment_production_id bigint(20),
|
||||
environment_staging_id bigint(20),
|
||||
name varchar(255),
|
||||
site varchar(255),
|
||||
provider varchar(255),
|
||||
mailgun varchar(255),
|
||||
token varchar(255),
|
||||
status varchar(255),
|
||||
site_usage longtext,
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (site_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_domains` (
|
||||
domain_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
name varchar(255),
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (domain_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_permissions` (
|
||||
user_permission_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
user_id bigint(20) UNSIGNED NOT NULL,
|
||||
account_id bigint(20) UNSIGNED NOT NULL,
|
||||
level varchar(255),
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (user_permission_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_account_domain` (
|
||||
account_domain_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
account_id bigint(20) UNSIGNED NOT NULL,
|
||||
domain_id bigint(20) UNSIGNED NOT NULL,
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (account_domain_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
$sql = "CREATE TABLE `{$wpdb->base_prefix}captaincore_account_site` (
|
||||
account_site_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
account_id bigint(20) UNSIGNED NOT NULL,
|
||||
site_id bigint(20) UNSIGNED NOT NULL,
|
||||
owner boolean,
|
||||
created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
PRIMARY KEY (account_site_id)
|
||||
) $charset_collate;";
|
||||
|
||||
dbDelta($sql);
|
||||
|
||||
if ( ! empty( $wpdb->last_error ) ) {
|
||||
return $wpdb->last_error;
|
||||
}
|
||||
|
||||
update_site_option( 'captcorecore_db_version', $required_version );
|
||||
return "Updated `captcorecore_db_version` to v$required_version";
|
||||
}
|
||||
|
||||
}
|
139
app/Domains.php
Normal file
139
app/Domains.php
Normal file
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class Domains {
|
||||
|
||||
protected $domains = [];
|
||||
|
||||
public function __construct( $domains = [] ) {
|
||||
|
||||
$user = wp_get_current_user();
|
||||
$role_check = in_array( 'subscriber', $user->roles ) + in_array( 'customer', $user->roles ) + in_array( 'administrator', $user->roles ) + in_array( 'editor', $user->roles );
|
||||
$partner = get_field( 'partner', 'user_' . get_current_user_id() );
|
||||
$all_domains = [];
|
||||
|
||||
// Bail if not assigned a role
|
||||
if ( ! $role_check ) {
|
||||
return 'Error: Please log in.';
|
||||
}
|
||||
|
||||
// Administrators return all sites
|
||||
if ( in_array( 'administrator', $user->roles ) ) {
|
||||
|
||||
$domains = get_posts(
|
||||
array(
|
||||
'post_type' => 'captcore_domain',
|
||||
'posts_per_page' => '-1',
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $domains as $domain ) :
|
||||
$domain_name = get_the_title( $domain );
|
||||
$domain_id = get_field( "domain_id", $domain );
|
||||
if ( $domain_name ) {
|
||||
$all_domains[ $domain_name ] = array( "name" => $domain_name, "id" => $domain_id, "post_id" => $domain->ID );
|
||||
}
|
||||
endforeach;
|
||||
|
||||
usort( $all_domains, "sort_by_name" );
|
||||
|
||||
$this->domains = $all_domains;
|
||||
}
|
||||
|
||||
if ( in_array( 'subscriber', $user->roles ) or in_array( 'customer', $user->roles ) or in_array( 'editor', $user->roles ) ) {
|
||||
|
||||
$customers = [];
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$partner = get_field( 'partner', 'user_' . get_current_user_id() );
|
||||
if ( $partner ) {
|
||||
foreach ( $partner as $partner_id ) {
|
||||
$websites_for_partner = get_posts(
|
||||
array(
|
||||
'post_type' => 'captcore_website',
|
||||
'posts_per_page' => '-1',
|
||||
'order' => 'asc',
|
||||
'orderby' => 'title',
|
||||
'fields' => 'ids',
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => 'partner', // name of custom field
|
||||
'value' => '"' . $partner_id . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
foreach ( $websites_for_partner as $website ) :
|
||||
$customers[] = get_field( 'customer', $website );
|
||||
endforeach;
|
||||
}
|
||||
}
|
||||
if ( count( $customers ) == 0 and is_array( $partner ) ) {
|
||||
foreach ( $partner as $partner_id ) {
|
||||
$websites_for_partner = get_posts(
|
||||
array(
|
||||
'post_type' => 'captcore_website',
|
||||
'posts_per_page' => '-1',
|
||||
'order' => 'asc',
|
||||
'orderby' => 'title',
|
||||
'fields' => 'ids',
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => 'customer', // name of custom field
|
||||
'value' => '"' . $partner_id . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
foreach ( $websites_for_partner as $website ) :
|
||||
$customers[] = get_field( 'customer', $website );
|
||||
endforeach;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $customers as $customer ) :
|
||||
|
||||
if ( is_array( $customer ) ) {
|
||||
$customer = $customer[0];
|
||||
}
|
||||
|
||||
$domains = get_field( 'domains', $customer );
|
||||
if ( $domains ) {
|
||||
foreach ( $domains as $domain ) :
|
||||
$domain_name = get_the_title( $domain );
|
||||
$domain_id = get_field( "domain_id", $domain );
|
||||
if ( $domain_name ) {
|
||||
$all_domains[ $domain_name ] = array( "name" => $domain_name, "id" => $domain_id );
|
||||
}
|
||||
endforeach;
|
||||
}
|
||||
|
||||
endforeach;
|
||||
|
||||
foreach ( $partner as $customer ) :
|
||||
$domains = get_field( 'domains', $customer );
|
||||
if ( $domains ) {
|
||||
foreach ( $domains as $domain ) :
|
||||
$domain_name = get_the_title( $domain );
|
||||
$domain_id = get_field( "domain_id", $domain );
|
||||
if ( $domain_name ) {
|
||||
$all_domains[ $domain_name ] = array( "name" => $domain_name, "id" => $domain_id );
|
||||
}
|
||||
endforeach;
|
||||
}
|
||||
endforeach;
|
||||
usort( $all_domains, "sort_by_name" );
|
||||
$this->domains = $all_domains;
|
||||
}
|
||||
}
|
||||
|
||||
public function all() {
|
||||
return $this->domains;
|
||||
}
|
||||
|
||||
}
|
9
app/Environments.php
Normal file
9
app/Environments.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class Environments extends DB {
|
||||
|
||||
static $primary_key = 'environment_id';
|
||||
|
||||
}
|
28
app/Invite.php
Normal file
28
app/Invite.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class Invite {
|
||||
|
||||
protected $invite_id = "";
|
||||
|
||||
public function __construct( $invite_id = "" ) {
|
||||
$this->invite_id = $invite_id;
|
||||
}
|
||||
|
||||
public function get() {
|
||||
$invite = (new invites)->get( $this->invite_id );
|
||||
return $invite;
|
||||
}
|
||||
|
||||
public function mark_accepted() {
|
||||
$db = new invites;
|
||||
$time_now = date("Y-m-d H:i:s");
|
||||
$db->update(
|
||||
[ 'accepted_at' => $time_now ],
|
||||
[ 'invite_id' => $this->invite_id ]
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
9
app/Invites.php
Normal file
9
app/Invites.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class Invites extends DB {
|
||||
|
||||
static $primary_key = 'invite_id';
|
||||
|
||||
}
|
9
app/Keys.php
Normal file
9
app/Keys.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class Keys extends DB {
|
||||
|
||||
static $primary_key = 'key_id';
|
||||
|
||||
}
|
9
app/Quicksaves.php
Normal file
9
app/Quicksaves.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class Quicksaves extends DB {
|
||||
|
||||
static $primary_key = 'quicksave_id';
|
||||
|
||||
}
|
9
app/Recipes.php
Normal file
9
app/Recipes.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class Recipes extends DB {
|
||||
|
||||
static $primary_key = 'recipe_id';
|
||||
|
||||
}
|
615
app/Site.php
Normal file
615
app/Site.php
Normal file
|
@ -0,0 +1,615 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class Site {
|
||||
|
||||
public function get( $site_id ) {
|
||||
|
||||
if ( is_object( $site_id ) ) {
|
||||
$site = $site_id;
|
||||
}
|
||||
|
||||
if ( ! isset( $site ) ) {
|
||||
$site = get_post( $site_id );
|
||||
}
|
||||
|
||||
$upload_dir = wp_upload_dir();
|
||||
|
||||
// Fetch relating environments
|
||||
$db_environments = new Environments();
|
||||
$environments = $db_environments->fetch_environments( $site->ID );
|
||||
|
||||
$domain = get_the_title( $site->ID );
|
||||
$customer = get_field( 'customer', $site->ID );
|
||||
$shared_with = get_field( 'partner', $site->ID );
|
||||
$mailgun = get_field( 'mailgun', $site->ID );
|
||||
$storage = $environments[0]->storage;
|
||||
if ( $storage ) {
|
||||
$storage_gbs = round( $storage / 1024 / 1024 / 1024, 1 );
|
||||
$storage_gbs = $storage_gbs . 'GB';
|
||||
} else {
|
||||
$storage_gbs = '';
|
||||
}
|
||||
$visits = $environments[0]->visits;
|
||||
$subsite_count = $environments[0]->subsite_count;
|
||||
$production_address = $environments[0]->address;
|
||||
$production_username = $environments[0]->username;
|
||||
$production_port = $environments[0]->port;
|
||||
$database_username = $environments[0]->database_username;
|
||||
$staging_address = ( isset( $environments[1] ) ? $environments[1]->address : '' );
|
||||
$staging_username = ( isset( $environments[1] ) ? $environments[1]->username : '' );
|
||||
$staging_port = ( isset( $environments[1] ) ? $environments[1]->port : '' );
|
||||
$home_url = $environments[0]->home_url;
|
||||
|
||||
// Prepare site details to be returned
|
||||
$site_details = new \stdClass();
|
||||
$site_details->id = $site->ID;
|
||||
$site_details->name = $domain;
|
||||
$site_details->site = get_field( 'site', $site->ID );
|
||||
$site_details->provider = get_field( 'provider', $site->ID );
|
||||
$site_details->key = get_field( 'key', $site->ID );
|
||||
$site_details->filtered = true;
|
||||
$site_details->usage_breakdown = [];
|
||||
$site_details->timeline = [];
|
||||
$site_details->selected = false;
|
||||
$site_details->loading_plugins = false;
|
||||
$site_details->loading_themes = false;
|
||||
$site_details->environment_selected = 'Production';
|
||||
$site_details->mailgun = $mailgun;
|
||||
$site_details->subsite_count = $subsite_count;
|
||||
$site_details->tabs = 'tab-Site-Management';
|
||||
$site_details->tabs_management = 'tab-Info';
|
||||
$site_details->storage_raw = $environments[0]->storage;
|
||||
$site_details->storage = $storage_gbs;
|
||||
$site_details->outdated = false;
|
||||
if ( is_string( $visits ) ) {
|
||||
$site_details->visits = number_format( intval( $visits ) );
|
||||
}
|
||||
$site_details->update_logs = [];
|
||||
$site_details->update_logs_pagination = array(
|
||||
'descending' => true,
|
||||
'sortBy' => 'date',
|
||||
);
|
||||
$site_details->pagination = array( 'sortBy' => 'roles' );
|
||||
|
||||
// Mark site as outdated if sync older then 48 hours
|
||||
if ( strtotime( $environments[0]->updated_at ) <= strtotime( "-48 hours" ) ) {
|
||||
$site_details->outdated = true;
|
||||
}
|
||||
|
||||
if ( ! isset( $site_details->visits ) ) {
|
||||
$site_details->visits = '';
|
||||
}
|
||||
|
||||
if ( $site_details->visits == 0 ) {
|
||||
$site_details->visits = '';
|
||||
}
|
||||
|
||||
if ( $customer ) {
|
||||
foreach ( $customer as $customer_id ) {
|
||||
$customer_name = get_post_field( 'post_title', $customer_id, 'raw' );
|
||||
$addons = get_field( 'addons', $customer_id );
|
||||
if ( $addons == '' ) {
|
||||
$addons = [];
|
||||
}
|
||||
$site_details->customer = array(
|
||||
'customer_id' => $customer_id,
|
||||
'name' => $customer_name,
|
||||
'hosting_addons' => $addons,
|
||||
'hosting_plan' => array(
|
||||
'name' => get_field( 'hosting_plan', $customer_id ),
|
||||
'visits_limit' => get_field( 'visits_limit', $customer_id ),
|
||||
'storage_limit' => get_field( 'storage_limit', $customer_id ),
|
||||
'sites_limit' => get_field( 'sites_limit', $customer_id ),
|
||||
'price' => get_field( 'price', $customer_id ),
|
||||
),
|
||||
'usage' => array(
|
||||
'storage' => get_field( 'storage', $customer_id ),
|
||||
'visits' => get_field( 'visits', $customer_id ),
|
||||
'sites' => get_field( 'sites', $customer_id ),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $site_details->customer ) == 0 ) {
|
||||
$site_details->customer = array(
|
||||
'customer_id' => '',
|
||||
'name' => '',
|
||||
'hosting_plan' => '',
|
||||
'visits_limit' => '',
|
||||
'storage_limit' => '',
|
||||
'sites_limit' => '',
|
||||
);
|
||||
}
|
||||
|
||||
$site_details->users = [];
|
||||
$site_details->update_logs = [];
|
||||
|
||||
if ( $shared_with ) {
|
||||
foreach ( $shared_with as $customer_id ) {
|
||||
$site_details->shared_with[] = array(
|
||||
'customer_id' => "$customer_id",
|
||||
'name' => get_post_field( 'post_title', $customer_id, 'raw' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$site_details->environments[0] = array(
|
||||
'id' => $environments[0]->environment_id,
|
||||
'link' => "http://$domain",
|
||||
'environment' => 'Production',
|
||||
'updated_at' => $environments[0]->updated_at,
|
||||
'address' => $environments[0]->address,
|
||||
'username' => $environments[0]->username,
|
||||
'password' => $environments[0]->password,
|
||||
'protocol' => $environments[0]->protocol,
|
||||
'port' => $environments[0]->port,
|
||||
'home_directory' => $environments[0]->home_directory,
|
||||
'fathom' => json_decode( $environments[0]->fathom ),
|
||||
'plugins' => json_decode( $environments[0]->plugins ),
|
||||
'themes' => json_decode( $environments[0]->themes ),
|
||||
'users' => 'Loading',
|
||||
'quicksaves' => 'Loading',
|
||||
'snapshots' => 'Loading',
|
||||
'update_logs' => 'Loading',
|
||||
'quicksave_panel' => [],
|
||||
'quicksave_search' => '',
|
||||
'core' => $environments[0]->core,
|
||||
'home_url' => $environments[0]->home_url,
|
||||
'updates_enabled' => intval( $environments[0]->updates_enabled ),
|
||||
'updates_exclude_plugins' => $environments[0]->updates_exclude_plugins,
|
||||
'updates_exclude_themes' => $environments[0]->updates_exclude_themes,
|
||||
'offload_enabled' => $environments[0]->offload_enabled,
|
||||
'offload_provider' => $environments[0]->offload_provider,
|
||||
'offload_access_key' => $environments[0]->offload_access_key,
|
||||
'offload_secret_key' => $environments[0]->offload_secret_key,
|
||||
'offload_bucket' => $environments[0]->offload_bucket,
|
||||
'offload_path' => $environments[0]->offload_path,
|
||||
'screenshot' => intval( $environments[0]->screenshot ),
|
||||
'screenshot_small' => '',
|
||||
'screenshot_large' => '',
|
||||
'stats' => 'Loading',
|
||||
'themes_selected' => [],
|
||||
'plugins_selected' => [],
|
||||
'users_selected' => [],
|
||||
);
|
||||
|
||||
if ( $site_details->environments[0]['fathom'] == '' ) {
|
||||
$site_details->environments[0]['fathom'] = array(
|
||||
array(
|
||||
'code' => '',
|
||||
'domain' => '',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if ( intval( $environments[0]->screenshot ) ) {
|
||||
$site_details->environments[0]['screenshot_small'] = $upload_dir['baseurl'] . "/screenshots/{$site_details->site}_{$site_details->id}/production/screenshot-100.png";
|
||||
$site_details->environments[0]['screenshot_large'] = $upload_dir['baseurl'] . "/screenshots/{$site_details->site}_{$site_details->id}/production/screenshot-800.png";
|
||||
}
|
||||
|
||||
if ( $site_details->environments[0]['updates_exclude_themes'] ) {
|
||||
$site_details->environments[0]['updates_exclude_themes'] = explode( ',', $site_details->environments[0]['updates_exclude_themes'] );
|
||||
} else {
|
||||
$site_details->environments[0]['updates_exclude_themes'] = [];
|
||||
}
|
||||
if ( $site_details->environments[0]['updates_exclude_plugins'] ) {
|
||||
$site_details->environments[0]['updates_exclude_plugins'] = explode( ',', $site_details->environments[0]['updates_exclude_plugins'] );
|
||||
} else {
|
||||
$site_details->environments[0]['updates_exclude_plugins'] = [];
|
||||
}
|
||||
|
||||
if ( $site_details->environments[0]['themes'] == '' ) {
|
||||
$site_details->environments[0]['themes'] = [];
|
||||
}
|
||||
if ( $site_details->environments[0]['plugins'] == '' ) {
|
||||
$site_details->environments[0]['plugins'] = [];
|
||||
}
|
||||
|
||||
if ( $site_details->provider == 'kinsta' ) {
|
||||
$site_details->environments[0]['ssh'] = "ssh ${production_username}@${production_address} -p ${production_port}";
|
||||
}
|
||||
if ( $site_details->provider == 'kinsta' and $environments[0]->database_username ) {
|
||||
$kinsta_ending = array_pop( explode(".", $site_details->environments[0]['address']) );
|
||||
if ( $kinsta_ending != "com" && $$kinsta_ending != "cloud" ) {
|
||||
$kinsta_ending = "cloud";
|
||||
}
|
||||
$site_details->environments[0]['database'] = "https://mysqleditor-${database_username}.kinsta.{$kinsta_ending}";
|
||||
$site_details->environments[0]['database_username'] = $environments[0]->database_username;
|
||||
$site_details->environments[0]['database_password'] = $environments[0]->database_password;
|
||||
}
|
||||
|
||||
if ( $site_details->provider == 'kinsta' ) {
|
||||
$link_staging = $environments[1]->home_url;
|
||||
}
|
||||
|
||||
if ( $site_details->provider == 'wpengine' ) {
|
||||
$link_staging = 'https://' . get_field( 'site', $site->ID ) . '.staging.wpengine.com';
|
||||
}
|
||||
|
||||
$site_details->environments[1] = array(
|
||||
'key_id' => 2,
|
||||
'link' => $link_staging,
|
||||
'environment' => 'Staging',
|
||||
'updated_at' => $environments[1]->updated_at,
|
||||
'address' => $environments[1]->address,
|
||||
'username' => $environments[1]->username,
|
||||
'password' => $environments[1]->password,
|
||||
'protocol' => $environments[1]->protocol,
|
||||
'port' => $environments[1]->port,
|
||||
'home_directory' => $environments[1]->home_directory,
|
||||
'fathom' => json_decode( $environments[1]->fathom ),
|
||||
'plugins' => json_decode( $environments[1]->plugins ),
|
||||
'themes' => json_decode( $environments[1]->themes ),
|
||||
'users' => 'Loading',
|
||||
'quicksaves' => 'Loading',
|
||||
'snapshots' => 'Loading',
|
||||
'update_logs' => 'Loading',
|
||||
'quicksave_panel' => [],
|
||||
'quicksave_search' => '',
|
||||
'core' => $environments[1]->core,
|
||||
'home_url' => $environments[1]->home_url,
|
||||
'updates_enabled' => intval( $environments[1]->updates_enabled ),
|
||||
'updates_exclude_plugins' => $environments[1]->updates_exclude_plugins,
|
||||
'updates_exclude_themes' => $environments[1]->updates_exclude_themes,
|
||||
'offload_enabled' => $environments[1]->offload_enabled,
|
||||
'offload_provider' => $environments[1]->offload_provider,
|
||||
'offload_access_key' => $environments[1]->offload_access_key,
|
||||
'offload_secret_key' => $environments[1]->offload_secret_key,
|
||||
'offload_bucket' => $environments[1]->offload_bucket,
|
||||
'offload_path' => $environments[1]->offload_path,
|
||||
'screenshot' => intval( $environments[1]->screenshot ),
|
||||
'screenshot_small' => '',
|
||||
'screenshot_large' => '',
|
||||
'stats' => 'Loading',
|
||||
'themes_selected' => [],
|
||||
'plugins_selected' => [],
|
||||
'users_selected' => [],
|
||||
);
|
||||
|
||||
if ( $site_details->environments[1]['fathom'] == '' ) {
|
||||
$site_details->environments[1]['fathom'] = array(
|
||||
array(
|
||||
'code' => '',
|
||||
'domain' => '',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if ( intval( $environments[1]->screenshot ) == 1 ) {
|
||||
$site_details->environments[1]['screenshot_small'] = $upload_dir['baseurl'] . "/screenshots/{$site_details->site}_{$site_details->id}/staging/screenshot-100.png";
|
||||
$site_details->environments[1]['screenshot_large'] = $upload_dir['baseurl'] . "/screenshots/{$site_details->site}_{$site_details->id}/production/screenshot-800.png";
|
||||
}
|
||||
|
||||
if ( $site_details->environments[1]['updates_exclude_themes'] ) {
|
||||
$site_details->environments[1]['updates_exclude_themes'] = explode( ',', $site_details->environments[1]['updates_exclude_themes'] );
|
||||
} else {
|
||||
$site_details->environments[1]['updates_exclude_themes'] = [];
|
||||
}
|
||||
if ( $site_details->environments[1]['updates_exclude_plugins'] ) {
|
||||
$site_details->environments[1]['updates_exclude_plugins'] = explode( ',', $site_details->environments[1]['updates_exclude_plugins'] );
|
||||
} else {
|
||||
$site_details->environments[1]['updates_exclude_plugins'] = [];
|
||||
}
|
||||
|
||||
if ( $site_details->environments[1]['themes'] == '' ) {
|
||||
$site_details->environments[1]['themes'] = [];
|
||||
}
|
||||
if ( $site_details->environments[1]['plugins'] == '' ) {
|
||||
$site_details->environments[1]['plugins'] = [];
|
||||
}
|
||||
|
||||
if ( $site_details->provider == 'kinsta' ) {
|
||||
$site_details->environments[1]['ssh'] = "ssh ${staging_username}@${staging_address} -p ${staging_port}";
|
||||
}
|
||||
if ( $site_details->provider == 'kinsta' and $environments[1]->database_username ) {
|
||||
$kinsta_ending = array_pop( explode(".", $site_details->environments[1]['address']) );
|
||||
if ( $kinsta_ending != "com" && $$kinsta_ending != "cloud" ) {
|
||||
$kinsta_ending = "cloud";
|
||||
}
|
||||
$site_details->environments[1]['database'] = "https://mysqleditor-staging-${database_username}.kinsta.{$kinsta_ending}";
|
||||
$site_details->environments[1]['database_username'] = $environments[1]->database_username;
|
||||
$site_details->environments[1]['database_password'] = $environments[1]->database_password;
|
||||
}
|
||||
|
||||
return $site_details;
|
||||
|
||||
}
|
||||
|
||||
public function create( $site ) {
|
||||
|
||||
// Work with array as PHP object
|
||||
$site = (object) $site;
|
||||
|
||||
// Prep for response to return
|
||||
$response = array( "errors" => [] );
|
||||
|
||||
// Pull in current user
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
// Validate
|
||||
if ( $site->domain == '' ) {
|
||||
$response['errors'][] = "Error: Domain can't be empty.";
|
||||
}
|
||||
if ( $site->site == '' ) {
|
||||
$response['errors'][] = "Error: Site can't be empty.";
|
||||
}
|
||||
if ( ! ctype_alnum ( $site->site ) ) {
|
||||
$response['errors'][] = "Error: Site does not consist of all letters or digits.";
|
||||
}
|
||||
if ( strlen($site->site) < 3 ) {
|
||||
$response['errors'][] = "Error: Site length less then 3 characters.";
|
||||
}
|
||||
if ( $site->environments[0]['address'] == "" ) {
|
||||
$response['errors'][] = "Error: Production environment address can't be empty.";
|
||||
}
|
||||
if ( $site->environments[0]['username'] == "" ) {
|
||||
$response['errors'][] = "Error: Production environment username can't be empty.";
|
||||
}
|
||||
if ( $site->environments[0]['protocol'] == "" ) {
|
||||
$response['errors'][] = "Error: Production environment protocol can't be empty.";
|
||||
}
|
||||
if ( $site->environments[0]['port'] == "" ) {
|
||||
$response['errors'][] = "Error: Production environment port can't be empty.";
|
||||
}
|
||||
if ( $site->environments[0]['port'] != "" and ! ctype_digit( $site->environments[0]['port'] ) ) {
|
||||
$response['errors'][] = "Error: Production environment port can only be numbers.";
|
||||
}
|
||||
|
||||
if ( $site->environments[1]['port'] and ! ctype_digit( $site->environments[1]['port'] ) ) {
|
||||
$response['errors'][] = "Error: Staging environment port can only be numbers.";
|
||||
}
|
||||
|
||||
|
||||
// Hunt for conflicting site names
|
||||
$arguments = array(
|
||||
'fields' => 'ids',
|
||||
'post_type' => 'captcore_website',
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => 'site',
|
||||
'value' => $site->site,
|
||||
'compare' => '=',
|
||||
),
|
||||
array(
|
||||
'key' => 'status',
|
||||
'value' => 'closed',
|
||||
'compare' => '!=',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$site_check = get_posts( $arguments );
|
||||
|
||||
if ( count( $site_check ) > 0 ) {
|
||||
$response['errors'][] = "Error: Site name needs to be unique.";
|
||||
}
|
||||
|
||||
if ( count($response['errors']) > 0 ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Create post object
|
||||
$new_site = array(
|
||||
'post_title' => $site->domain,
|
||||
'post_author' => $current_user->ID,
|
||||
'post_type' => 'captcore_website',
|
||||
'post_status' => 'publish',
|
||||
);
|
||||
|
||||
// Insert the post into the database
|
||||
$site_id = wp_insert_post( $new_site );
|
||||
|
||||
if ( $site_id ) {
|
||||
|
||||
$response['response'] = 'Successfully added new site';
|
||||
$response['site_id'] = $site_id;
|
||||
|
||||
// add in ACF fields
|
||||
update_field( 'site', $site->site, $site_id );
|
||||
update_field( 'provider', $site->provider, $site_id );
|
||||
update_field( 'customer', $site->customers, $site_id );
|
||||
update_field( 'key', $site->key, $site_id );
|
||||
update_field( 'partner', array_column( $site->shared_with, 'customer_id' ), $site_id );
|
||||
update_field( 'updates_enabled', $site->updates_enabled, $site_id );
|
||||
update_field( 'status', 'active', $site_id );
|
||||
|
||||
if ( get_field( 'launch_date', $site_id ) == '' ) {
|
||||
|
||||
// No date was entered for Launch Date, assign to today.
|
||||
update_field( 'launch_date', date( 'Ymd' ), $site_id );
|
||||
|
||||
}
|
||||
|
||||
$db_environments = new Environments();
|
||||
|
||||
$environment = array(
|
||||
'site_id' => $site_id,
|
||||
'environment' => 'Production',
|
||||
'address' => $site->environments[0]['address'],
|
||||
'username' => $site->environments[0]['username'],
|
||||
'password' => $site->environments[0]['password'],
|
||||
'protocol' => $site->environments[0]['protocol'],
|
||||
'port' => $site->environments[0]['port'],
|
||||
'home_directory' => $site->environments[0]['home_directory'],
|
||||
'database_username' => $site->environments[0]['database_username'],
|
||||
'database_password' => $site->environments[0]['database_password'],
|
||||
'updates_enabled' => $site->environments[0]['updates_enabled'],
|
||||
'updates_exclude_plugins' => $site->environments[0]['updates_exclude_plugins'],
|
||||
'updates_exclude_themes' => $site->environments[0]['updates_exclude_themes'],
|
||||
'offload_enabled' => $site->environments[0]['offload_enabled'],
|
||||
'offload_provider' => $site->environments[0]['offload_provider'],
|
||||
'offload_access_key' => $site->environments[0]['offload_access_key'],
|
||||
'offload_secret_key' => $site->environments[0]['offload_secret_key'],
|
||||
'offload_bucket' => $site->environments[0]['offload_bucket'],
|
||||
'offload_path' => $site->environments[0]['offload_path'],
|
||||
);
|
||||
|
||||
$time_now = date( 'Y-m-d H:i:s' );
|
||||
$environment['created_at'] = $time_now;
|
||||
$environment['updated_at'] = $time_now;
|
||||
$environment_id = $db_environments->insert( $environment );
|
||||
update_field( 'environment_production_id', $environment_id, $site_id );
|
||||
|
||||
$environment = array(
|
||||
'site_id' => $site_id,
|
||||
'environment' => 'Staging',
|
||||
'address' => $site->environments[1]['address'],
|
||||
'username' => $site->environments[1]['username'],
|
||||
'password' => $site->environments[1]['password'],
|
||||
'protocol' => $site->environments[1]['protocol'],
|
||||
'port' => $site->environments[1]['port'],
|
||||
'home_directory' => $site->environments[1]['home_directory'],
|
||||
'database_username' => $site->environments[1]['database_username'],
|
||||
'database_password' => $site->environments[1]['database_password'],
|
||||
'updates_enabled' => $site->environments[1]['updates_enabled'],
|
||||
'updates_exclude_plugins' => $site->environments[1]['updates_exclude_plugins'],
|
||||
'updates_exclude_themes' => $site->environments[1]['updates_exclude_themes'],
|
||||
'offload_enabled' => $site->environments[1]['offload_enabled'],
|
||||
'offload_provider' => $site->environments[1]['offload_provider'],
|
||||
'offload_access_key' => $site->environments[1]['offload_access_key'],
|
||||
'offload_secret_key' => $site->environments[1]['offload_secret_key'],
|
||||
'offload_bucket' => $site->environments[1]['offload_bucket'],
|
||||
'offload_path' => $site->environments[1]['offload_path'],
|
||||
);
|
||||
|
||||
$time_now = date( 'Y-m-d H:i:s' );
|
||||
$environment['created_at'] = $time_now;
|
||||
$environment['updated_at'] = $time_now;
|
||||
$environment_id = $db_environments->insert( $environment );
|
||||
update_field( 'environment_staging_id', $environment_id, $site_id );
|
||||
|
||||
// Run ACF custom tasks afterward.
|
||||
captaincore_acf_save_post_after( $site_id );
|
||||
}
|
||||
if ( ! $site_id ) {
|
||||
$response['response'] = 'Failed to add new site';
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function update( $site ) {
|
||||
|
||||
// Work with array as PHP object
|
||||
$site = (object) $site;
|
||||
|
||||
// Prep for response to return
|
||||
$response = [];
|
||||
|
||||
// Pull in current user
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
$site_id = $site->id;
|
||||
|
||||
// Validate site exists
|
||||
if ( get_post_type( $site_id ) != 'captcore_website' ) {
|
||||
$response['response'] = 'Error: Site ID not found.';
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Updates post
|
||||
$update_site = array(
|
||||
'ID' => $site_id,
|
||||
'post_title' => $site->name,
|
||||
'post_author' => $current_user->ID,
|
||||
'post_type' => 'captcore_website',
|
||||
'post_status' => 'publish',
|
||||
);
|
||||
|
||||
wp_update_post( $update_site, true );
|
||||
|
||||
if ( is_wp_error( $site_id ) ) {
|
||||
$errors = $site_id->get_error_messages();
|
||||
return $response['response'] = implode( ' ', $errors );
|
||||
}
|
||||
|
||||
if ( $site_id ) {
|
||||
|
||||
$response['response'] = 'Successfully updated site';
|
||||
$response['site_id'] = $site_id;
|
||||
|
||||
// add in ACF fields
|
||||
update_field( 'customer', $site->customer["customer_id"], $site_id );
|
||||
update_field( 'partner', array_column( $site->shared_with, 'customer_id' ), $site_id );
|
||||
update_field( 'provider', $site->provider, $site_id );
|
||||
update_field( 'key', $site->key, $site_id );
|
||||
|
||||
// update_field( 'status', 'active', $site_id );
|
||||
if ( get_field( 'launch_date', $site_id ) == '' ) {
|
||||
// No date was entered for Launch Date, assign to today.
|
||||
update_field( 'launch_date', date( 'Ymd' ), $site_id );
|
||||
}
|
||||
|
||||
// Fetch relating environments
|
||||
$db_environments = new Environments();
|
||||
|
||||
$environment = array(
|
||||
'address' => $site->environments[0]['address'],
|
||||
'username' => $site->environments[0]['username'],
|
||||
'password' => $site->environments[0]['password'],
|
||||
'protocol' => $site->environments[0]['protocol'],
|
||||
'port' => $site->environments[0]['port'],
|
||||
'home_directory' => $site->environments[0]['home_directory'],
|
||||
'database_username' => $site->environments[0]['database_username'],
|
||||
'database_password' => $site->environments[0]['database_password'],
|
||||
'offload_enabled' => $site->environments[0]['offload_enabled'],
|
||||
'offload_access_key' => $site->environments[0]['offload_access_key'],
|
||||
'offload_secret_key' => $site->environments[0]['offload_secret_key'],
|
||||
'offload_bucket' => $site->environments[0]['offload_bucket'],
|
||||
'offload_path' => $site->environments[0]['offload_path'],
|
||||
'updates_enabled' => $site->environments[0]['updates_enabled'],
|
||||
'updates_exclude_plugins' => $site->environments[0]['updates_exclude_plugins'],
|
||||
'updates_exclude_themes' => $site->environments[0]['updates_exclude_themes'],
|
||||
);
|
||||
|
||||
$environment_id = get_field( 'environment_production_id', $site_id );
|
||||
$db_environments->update( $environment, array( 'environment_id' => $environment_id ) );
|
||||
|
||||
$environment = array(
|
||||
'address' => $site->environments[1]['address'],
|
||||
'username' => $site->environments[1]['username'],
|
||||
'password' => $site->environments[1]['password'],
|
||||
'protocol' => $site->environments[1]['protocol'],
|
||||
'port' => $site->environments[1]['port'],
|
||||
'home_directory' => $site->environments[1]['home_directory'],
|
||||
'database_username' => $site->environments[1]['database_username'],
|
||||
'database_password' => $site->environments[1]['database_password'],
|
||||
'offload_enabled' => $site->environments[1]['offload_enabled'],
|
||||
'offload_access_key' => $site->environments[1]['offload_access_key'],
|
||||
'offload_secret_key' => $site->environments[1]['offload_secret_key'],
|
||||
'offload_bucket' => $site->environments[1]['offload_bucket'],
|
||||
'offload_path' => $site->environments[1]['offload_path'],
|
||||
'updates_enabled' => $site->environments[1]['updates_enabled'],
|
||||
'updates_exclude_plugins' => $site->environments[1]['updates_exclude_plugins'],
|
||||
'updates_exclude_themes' => $site->environments[1]['updates_exclude_themes'],
|
||||
);
|
||||
|
||||
$environment_id = get_field( 'environment_staging_id', $site_id );
|
||||
$db_environments->update( $environment, array( 'environment_id' => $environment_id ) );
|
||||
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function delete( $site_id ) {
|
||||
|
||||
// Remove environments attached to site
|
||||
// $db_environments = new Environments();
|
||||
// $environment_id = get_field( 'environment_production_id', $site_id );
|
||||
// $db_environments->delete( $environment_id );
|
||||
// $environment_id = get_field( 'environment_staging_id', $site_id );
|
||||
// $db_environments->delete( $environment_id );
|
||||
|
||||
// Mark site removed
|
||||
update_field( 'closed_date', date( 'Ymd' ), $site_id );
|
||||
update_field( 'status', 'closed', $site_id );
|
||||
|
||||
}
|
||||
|
||||
}
|
141
app/Sites.php
Normal file
141
app/Sites.php
Normal file
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class Sites {
|
||||
|
||||
protected $sites = [];
|
||||
|
||||
public function __construct( $sites = [] ) {
|
||||
$user = wp_get_current_user();
|
||||
$role_check = in_array( 'subscriber', $user->roles ) + in_array( 'customer', $user->roles ) + in_array( 'administrator', $user->roles ) + in_array( 'editor', $user->roles );
|
||||
$partner = get_field( 'partner', 'user_' . get_current_user_id() );
|
||||
|
||||
// New array to collect IDs
|
||||
$site_ids = [];
|
||||
|
||||
// Bail if not assigned a role
|
||||
if ( ! $role_check ) {
|
||||
return 'Error: Please log in.';
|
||||
}
|
||||
|
||||
// Administrators return all sites
|
||||
if ( $partner && $role_check && in_array( 'administrator', $user->roles ) ) {
|
||||
$sites = get_posts(
|
||||
array(
|
||||
'order' => 'asc',
|
||||
'orderby' => 'title',
|
||||
'posts_per_page' => '-1',
|
||||
'post_type' => 'captcore_website',
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => 'status',
|
||||
'value' => 'closed',
|
||||
'compare' => '!=',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->sites = $sites;
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if no partner set.
|
||||
if ( ! is_array( $partner ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through each partner assigned to current user
|
||||
foreach ( $partner as $partner_id ) {
|
||||
|
||||
// Load websites assigned to partner
|
||||
$arguments = array(
|
||||
'fields' => 'ids',
|
||||
'post_type' => 'captcore_website',
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => 'partner',
|
||||
'value' => '"' . $partner_id . '"',
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
array(
|
||||
'key' => 'status',
|
||||
'value' => 'closed',
|
||||
'compare' => '!=',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$sites = new \WP_Query( $arguments );
|
||||
|
||||
foreach ( $sites->posts as $site_id ) {
|
||||
if ( ! in_array( $site_id, $site_ids ) ) {
|
||||
$site_ids[] = $site_id;
|
||||
}
|
||||
}
|
||||
|
||||
// Load websites assigned to partner
|
||||
$arguments = array(
|
||||
'fields' => 'ids',
|
||||
'post_type' => 'captcore_website',
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => 'customer',
|
||||
'value' => '"' . $partner_id . '"',
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
array(
|
||||
'key' => 'status',
|
||||
'value' => 'closed',
|
||||
'compare' => '!=',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$sites = new \WP_Query( $arguments );
|
||||
|
||||
foreach ( $sites->posts as $site_id ) {
|
||||
if ( ! in_array( $site_id, $site_ids ) ) {
|
||||
$site_ids[] = $site_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bail if no site ids found
|
||||
if ( count( $site_ids ) == 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sites = get_posts(
|
||||
array(
|
||||
'order' => 'asc',
|
||||
'orderby' => 'title',
|
||||
'posts_per_page' => '-1',
|
||||
'post_type' => 'captcore_website',
|
||||
'include' => $site_ids,
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => 'status',
|
||||
'value' => 'closed',
|
||||
'compare' => '!=',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->sites = $sites;
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
public function all() {
|
||||
return $this->sites;
|
||||
}
|
||||
|
||||
}
|
9
app/Snapshots.php
Normal file
9
app/Snapshots.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class Snapshots extends DB {
|
||||
|
||||
static $primary_key = 'snapshot_id';
|
||||
|
||||
}
|
9
app/UpdateLogs.php
Normal file
9
app/UpdateLogs.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore;
|
||||
|
||||
class UpdateLogs extends DB {
|
||||
|
||||
static $primary_key = 'log_id';
|
||||
|
||||
}
|
|
@ -62,8 +62,8 @@ register_deactivation_hook( __FILE__, 'deactivate_captaincore' );
|
|||
* The core plugin class that is used to define internationalization,
|
||||
* admin-specific hooks, and public-facing site hooks.
|
||||
*/
|
||||
|
||||
require plugin_dir_path( __FILE__ ) . 'includes/class-captaincore.php';
|
||||
require plugin_dir_path( __FILE__ ) . 'includes/class-captaincore-db.php';
|
||||
|
||||
/**
|
||||
* Begins execution of the plugin.
|
||||
|
@ -82,6 +82,7 @@ function run_captaincore() {
|
|||
}
|
||||
run_captaincore();
|
||||
|
||||
require plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
|
||||
require 'includes/register-custom-fields.php';
|
||||
require 'includes/constellix-api/constellix-api.php';
|
||||
require 'includes/woocommerce-custom-password-fields.php';
|
||||
|
@ -1498,7 +1499,7 @@ function captaincore_api_func( WP_REST_Request $request ) {
|
|||
'token' => $token
|
||||
);
|
||||
|
||||
$db = new CaptainCore\snapshots();
|
||||
$db = new CaptainCore\Snapshots();
|
||||
$snapshot_id = $db->insert( $snapshot );
|
||||
|
||||
// Send out snapshot email
|
||||
|
@ -1579,7 +1580,7 @@ function captaincore_api_func( WP_REST_Request $request ) {
|
|||
'created_at' => $date_formatted,
|
||||
);
|
||||
|
||||
$db_update_logs = new CaptainCore\update_logs();
|
||||
$db_update_logs = new CaptainCore\UpdateLogs();
|
||||
|
||||
$valid_check = $db_update_logs->valid_check( $new_update_log_check );
|
||||
|
||||
|
@ -1635,7 +1636,7 @@ function captaincore_api_func( WP_REST_Request $request ) {
|
|||
'created_at' => $date_formatted,
|
||||
);
|
||||
|
||||
$db_quicksaves = new CaptainCore\quicksaves();
|
||||
$db_quicksaves = new CaptainCore\Quicksaves();
|
||||
|
||||
$valid_check = $db_quicksaves->valid_check( $new_quicksave_check );
|
||||
|
||||
|
@ -1776,7 +1777,7 @@ function captaincore_keys_func( $request ) {
|
|||
|
||||
// Checks for a current user. If admin found pass
|
||||
if ( $current_user && $role_check ) {
|
||||
return (new CaptainCore\keys())->all( "title", "ASC" );
|
||||
return (new CaptainCore\Keys())->all( "title", "ASC" );
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
@ -1790,7 +1791,7 @@ function captaincore_site_snapshots_func( $request ) {
|
|||
return new WP_Error( 'token_invalid', 'Invalid Token', array( 'status' => 403 ) );
|
||||
}
|
||||
|
||||
$db = new CaptainCore\snapshots;
|
||||
$db = new CaptainCore\Snapshots;
|
||||
$snapshots = $db->fetch_by_environments( $site_id );
|
||||
foreach( $snapshots as $environment ) {
|
||||
|
||||
|
@ -1818,7 +1819,7 @@ function captaincore_site_snapshot_download_func( $request ) {
|
|||
$snapshot_name = $request['snapshot_name'] . ".zip";
|
||||
|
||||
// Verify Snapshot link is valid
|
||||
$db = new CaptainCore\snapshots();
|
||||
$db = new CaptainCore\Snapshots();
|
||||
$snapshot = $db->get( $snapshot_id );
|
||||
|
||||
if ( $snapshot->snapshot_name != $snapshot_name || $snapshot->site_id != $site_id || $snapshot->token != $token ) {
|
||||
|
@ -1838,7 +1839,7 @@ function captaincore_site_quicksaves_func( $request ) {
|
|||
}
|
||||
|
||||
$results = [];
|
||||
$db_quicksaves = new CaptainCore\quicksaves;
|
||||
$db_quicksaves = new CaptainCore\Quicksaves;
|
||||
|
||||
$environment_id = get_field( 'environment_production_id', $site_id );
|
||||
$quicksaves = $db_quicksaves->fetch_environment( $site_id, $environment_id );
|
||||
|
@ -2502,7 +2503,7 @@ function captaincore_login_func( WP_REST_Request $request ) {
|
|||
|
||||
$errors = [];
|
||||
$password = $post->login->password;
|
||||
$invites = new CaptainCore\invites();
|
||||
$invites = new CaptainCore\Invites();
|
||||
$results = $invites->where( array(
|
||||
"account_id" => $post->invite->account,
|
||||
"token" => $post->invite->token,
|
||||
|
@ -3672,7 +3673,7 @@ function captaincore_local_action_callback() {
|
|||
}
|
||||
if ( $cmd == 'fetchInvite' ) {
|
||||
$invite = (object) $value;
|
||||
$invites = new CaptainCore\invites();
|
||||
$invites = new CaptainCore\Invites();
|
||||
$results = $invites->where( array(
|
||||
"account_id" => $invite->account,
|
||||
"token" => $invite->token,
|
||||
|
@ -3697,13 +3698,13 @@ function captaincore_local_action_callback() {
|
|||
$account->calculate_totals();
|
||||
}
|
||||
if ( $cmd == 'deleteInvite' ) {
|
||||
$invites = new CaptainCore\invites();
|
||||
$invites = new CaptainCore\Invites();
|
||||
$invites->delete( $value );
|
||||
echo "Invite deleted.";
|
||||
}
|
||||
if ( $cmd == 'acceptInvite' ) {
|
||||
$invite = (object) $value;
|
||||
$invites = new CaptainCore\invites();
|
||||
$invites = new CaptainCore\Invites();
|
||||
$results = $invites->where( array(
|
||||
"account_id" => $invite->account,
|
||||
"token" => $invite->token,
|
||||
|
@ -4051,7 +4052,7 @@ function captaincore_ajax_action_callback() {
|
|||
|
||||
if ( $cmd == 'fetchLink' ) {
|
||||
// Fetch snapshot details
|
||||
$db = new CaptainCore\snapshots;
|
||||
$db = new CaptainCore\Snapshots;
|
||||
$in_24hrs = date("Y-m-d H:i:s", strtotime ( date("Y-m-d H:i:s")."+24 hours" ) );
|
||||
|
||||
// Generate new token
|
||||
|
@ -4225,7 +4226,7 @@ function captaincore_ajax_action_callback() {
|
|||
'created_at' => $time_now,
|
||||
);
|
||||
|
||||
$db = new CaptainCore\keys();
|
||||
$db = new CaptainCore\Keys();
|
||||
$key_id = $db->insert( $new_key );
|
||||
|
||||
$remote_command = true;
|
||||
|
@ -4245,7 +4246,7 @@ function captaincore_ajax_action_callback() {
|
|||
'updated_at' => $time_now,
|
||||
);
|
||||
|
||||
$db = new CaptainCore\keys();
|
||||
$db = new CaptainCore\Keys();
|
||||
$db->update( $key_update, array( "key_id" => $key_id ) );
|
||||
|
||||
$remote_command = true;
|
||||
|
@ -4260,7 +4261,7 @@ function captaincore_ajax_action_callback() {
|
|||
$key_id = $value;
|
||||
$time_now = date("Y-m-d H:i:s");
|
||||
|
||||
$db = new CaptainCore\keys();
|
||||
$db = new CaptainCore\Keys();
|
||||
$db->delete( $key_id );
|
||||
|
||||
$remote_command = true;
|
||||
|
@ -4684,7 +4685,7 @@ function captaincore_ajax_action_callback() {
|
|||
'public' => $recipe->public,
|
||||
);
|
||||
|
||||
$db_recipes = new CaptainCore\recipes();
|
||||
$db_recipes = new CaptainCore\Recipes();
|
||||
$recipe_id = $db_recipes->insert( $new_recipe );
|
||||
echo json_encode( $db_recipes->fetch_recipes("title","ASC") );
|
||||
|
||||
|
@ -4707,7 +4708,7 @@ function captaincore_ajax_action_callback() {
|
|||
'public' => $recipe->public,
|
||||
);
|
||||
|
||||
$db_recipes = new CaptainCore\recipes();
|
||||
$db_recipes = new CaptainCore\Recipes();
|
||||
$db_recipes->update( $recipe_update, array( "recipe_id" => $recipe->recipe_id ) );
|
||||
|
||||
echo json_encode( $db_recipes->fetch_recipes( "title", "ASC" ) );
|
||||
|
@ -4937,7 +4938,7 @@ function captaincore_ajax_action_callback() {
|
|||
|
||||
if ( $cmd == 'fetch-update-logs' ) {
|
||||
|
||||
$db = new CaptainCore\update_logs;
|
||||
$db = new CaptainCore\UpdateLogs;
|
||||
|
||||
$environment_production_id = get_field( 'environment_production_id', $post_id );
|
||||
$environment_staging_id = get_field( 'environment_staging_id', $post_id );
|
||||
|
@ -5029,7 +5030,7 @@ function captaincore_ajax_action_callback() {
|
|||
'fingerprint' => $response,
|
||||
);
|
||||
|
||||
$db = new CaptainCore\keys();
|
||||
$db = new CaptainCore\Keys();
|
||||
$db->update( $key_update, array( "key_id" => $key_id ) );
|
||||
echo json_encode( $db->get( $key_id ) );
|
||||
}
|
||||
|
@ -5305,7 +5306,7 @@ function captaincore_install_action_callback() {
|
|||
}
|
||||
|
||||
if ( $cmd == 'quicksave_file_diff' ) {
|
||||
$db_quicksaves = new CaptainCore\quicksaves;
|
||||
$db_quicksaves = new CaptainCore\Quicksaves;
|
||||
$quicksaves = $db_quicksaves->get( $quicksave_id );
|
||||
$git_commit = $quicksaves->git_commit;
|
||||
$command = "quicksave-file-diff $site --hash=$commit --file=$value --html";
|
||||
|
@ -5313,7 +5314,7 @@ function captaincore_install_action_callback() {
|
|||
|
||||
if ( $cmd == 'rollback' ) {
|
||||
$run_in_background = true;
|
||||
$db_quicksaves = new CaptainCore\quicksaves;
|
||||
$db_quicksaves = new CaptainCore\Quicksaves;
|
||||
$quicksaves = $db_quicksaves->get( $quicksave_id );
|
||||
$git_commit = $quicksaves->git_commit;
|
||||
$command = "rollback $site $git_commit --$addon_type=$value";
|
||||
|
@ -5321,7 +5322,7 @@ function captaincore_install_action_callback() {
|
|||
|
||||
if ( $cmd == 'quicksave_rollback' ) {
|
||||
$run_in_background = true;
|
||||
$db_quicksaves = new CaptainCore\quicksaves;
|
||||
$db_quicksaves = new CaptainCore\Quicksaves;
|
||||
$quicksaves = $db_quicksaves->get( $quicksave_id );
|
||||
$git_commit = $quicksaves->git_commit;
|
||||
$command = "rollback $site $git_commit --all";
|
||||
|
@ -5329,7 +5330,7 @@ function captaincore_install_action_callback() {
|
|||
|
||||
if ( $cmd == 'quicksave_file_restore' ) {
|
||||
$run_in_background = true;
|
||||
$db_quicksaves = new CaptainCore\quicksaves;
|
||||
$db_quicksaves = new CaptainCore\Quicksaves;
|
||||
$quicksaves = $db_quicksaves->get( $quicksave_id );
|
||||
$git_commit = $quicksaves->git_commit;
|
||||
$command = "rollback $site $git_commit --file=$value";
|
||||
|
@ -6111,7 +6112,7 @@ function log_process_completed_callback() {
|
|||
function captaincore_download_snapshot_email( $snapshot_id ) {
|
||||
|
||||
// Fetch snapshot details
|
||||
$db = new CaptainCore\snapshots;
|
||||
$db = new CaptainCore\Snapshots;
|
||||
$snapshot = $db->get( $snapshot_id );
|
||||
$name = $snapshot->snapshot_name;
|
||||
$domain = get_the_title( $snapshot->site_id );
|
||||
|
@ -6136,7 +6137,7 @@ function captaincore_download_snapshot_email( $snapshot_id ) {
|
|||
|
||||
function captaincore_snapshot_download_link( $snapshot_id ) {
|
||||
|
||||
$db = new CaptainCore\snapshots;
|
||||
$db = new CaptainCore\Snapshots;
|
||||
$snapshot = $db->get( $snapshot_id );
|
||||
$name = $snapshot->snapshot_name;
|
||||
$domain = get_the_title( $snapshot->site_id );
|
||||
|
|
7
composer.json
Normal file
7
composer.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"CaptainCore\\": "app/"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -3842,7 +3842,7 @@ new Vue({
|
|||
custom_script: "",
|
||||
recipes:
|
||||
<?php
|
||||
$db_recipes = new CaptainCore\recipes();
|
||||
$db_recipes = new CaptainCore\Recipes();
|
||||
$recipes = $db_recipes->fetch_recipes("title","ASC");
|
||||
echo json_encode( $recipes );
|
||||
?>,
|
||||
|
|
7
vendor/autoload.php
vendored
Normal file
7
vendor/autoload.php
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
// autoload.php @generated by Composer
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit9f7509cc1c55bc410ccf6f05510f2050::getLoader();
|
445
vendor/composer/ClassLoader.php
vendored
Normal file
445
vendor/composer/ClassLoader.php
vendored
Normal file
|
@ -0,0 +1,445 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
/**
|
||||
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
|
||||
*
|
||||
* $loader = new \Composer\Autoload\ClassLoader();
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
* // activate the autoloader
|
||||
* $loader->register();
|
||||
*
|
||||
* // to enable searching the include path (eg. for PEAR packages)
|
||||
* $loader->setUseIncludePath(true);
|
||||
*
|
||||
* In this example, if you try to use a class in the Symfony\Component
|
||||
* namespace or one of its children (Symfony\Component\Console for instance),
|
||||
* the autoloader will first look for the class under the component/
|
||||
* directory, and it will then fallback to the framework/ directory if not
|
||||
* found before giving up.
|
||||
*
|
||||
* This class is loosely based on the Symfony UniversalClassLoader.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @see http://www.php-fig.org/psr/psr-0/
|
||||
* @see http://www.php-fig.org/psr/psr-4/
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
// PSR-4
|
||||
private $prefixLengthsPsr4 = array();
|
||||
private $prefixDirsPsr4 = array();
|
||||
private $fallbackDirsPsr4 = array();
|
||||
|
||||
// PSR-0
|
||||
private $prefixesPsr0 = array();
|
||||
private $fallbackDirsPsr0 = array();
|
||||
|
||||
private $useIncludePath = false;
|
||||
private $classMap = array();
|
||||
private $classMapAuthoritative = false;
|
||||
private $missingClasses = array();
|
||||
private $apcuPrefix;
|
||||
|
||||
public function getPrefixes()
|
||||
{
|
||||
if (!empty($this->prefixesPsr0)) {
|
||||
return call_user_func_array('array_merge', $this->prefixesPsr0);
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getPrefixesPsr4()
|
||||
{
|
||||
return $this->prefixDirsPsr4;
|
||||
}
|
||||
|
||||
public function getFallbackDirs()
|
||||
{
|
||||
return $this->fallbackDirsPsr0;
|
||||
}
|
||||
|
||||
public function getFallbackDirsPsr4()
|
||||
{
|
||||
return $this->fallbackDirsPsr4;
|
||||
}
|
||||
|
||||
public function getClassMap()
|
||||
{
|
||||
return $this->classMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $classMap Class to filename map
|
||||
*/
|
||||
public function addClassMap(array $classMap)
|
||||
{
|
||||
if ($this->classMap) {
|
||||
$this->classMap = array_merge($this->classMap, $classMap);
|
||||
} else {
|
||||
$this->classMap = $classMap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix, either
|
||||
* appending or prepending to the ones previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param array|string $paths The PSR-0 root directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*/
|
||||
public function add($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr0
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$this->fallbackDirsPsr0,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$first = $prefix[0];
|
||||
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
||||
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($prepend) {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixesPsr0[$first][$prefix]
|
||||
);
|
||||
} else {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$this->prefixesPsr0[$first][$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace, either
|
||||
* appending or prepending to the ones previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param array|string $paths The PSR-4 base directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function addPsr4($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
// Register directories for the root namespace.
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr4
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$this->fallbackDirsPsr4,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
||||
// Register directories for a new namespace.
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
} elseif ($prepend) {
|
||||
// Prepend directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixDirsPsr4[$prefix]
|
||||
);
|
||||
} else {
|
||||
// Append directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$this->prefixDirsPsr4[$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix,
|
||||
* replacing any others previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param array|string $paths The PSR-0 base directories
|
||||
*/
|
||||
public function set($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr0 = (array) $paths;
|
||||
} else {
|
||||
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace,
|
||||
* replacing any others previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param array|string $paths The PSR-4 base directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setPsr4($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr4 = (array) $paths;
|
||||
} else {
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on searching the include path for class files.
|
||||
*
|
||||
* @param bool $useIncludePath
|
||||
*/
|
||||
public function setUseIncludePath($useIncludePath)
|
||||
{
|
||||
$this->useIncludePath = $useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to check if the autoloader uses the include path to check
|
||||
* for classes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseIncludePath()
|
||||
{
|
||||
return $this->useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off searching the prefix and fallback directories for classes
|
||||
* that have not been registered with the class map.
|
||||
*
|
||||
* @param bool $classMapAuthoritative
|
||||
*/
|
||||
public function setClassMapAuthoritative($classMapAuthoritative)
|
||||
{
|
||||
$this->classMapAuthoritative = $classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should class lookup fail if not found in the current class map?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isClassMapAuthoritative()
|
||||
{
|
||||
return $this->classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
|
||||
*
|
||||
* @param string|null $apcuPrefix
|
||||
*/
|
||||
public function setApcuPrefix($apcuPrefix)
|
||||
{
|
||||
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The APCu prefix in use, or null if APCu caching is not enabled.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getApcuPrefix()
|
||||
{
|
||||
return $this->apcuPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters this instance as an autoloader.
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
* @return bool|null True if loaded, null otherwise
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
if ($file = $this->findFile($class)) {
|
||||
includeFile($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the path to the file where the class is defined.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return string|false The path if found, false otherwise
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
// class map lookup
|
||||
if (isset($this->classMap[$class])) {
|
||||
return $this->classMap[$class];
|
||||
}
|
||||
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
|
||||
return false;
|
||||
}
|
||||
if (null !== $this->apcuPrefix) {
|
||||
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
|
||||
if ($hit) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
$file = $this->findFileWithExtension($class, '.php');
|
||||
|
||||
// Search for Hack files if we are running on HHVM
|
||||
if (false === $file && defined('HHVM_VERSION')) {
|
||||
$file = $this->findFileWithExtension($class, '.hh');
|
||||
}
|
||||
|
||||
if (null !== $this->apcuPrefix) {
|
||||
apcu_add($this->apcuPrefix.$class, $file);
|
||||
}
|
||||
|
||||
if (false === $file) {
|
||||
// Remember that this class does not exist.
|
||||
$this->missingClasses[$class] = true;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
private function findFileWithExtension($class, $ext)
|
||||
{
|
||||
// PSR-4 lookup
|
||||
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
|
||||
|
||||
$first = $class[0];
|
||||
if (isset($this->prefixLengthsPsr4[$first])) {
|
||||
$subPath = $class;
|
||||
while (false !== $lastPos = strrpos($subPath, '\\')) {
|
||||
$subPath = substr($subPath, 0, $lastPos);
|
||||
$search = $subPath . '\\';
|
||||
if (isset($this->prefixDirsPsr4[$search])) {
|
||||
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
|
||||
foreach ($this->prefixDirsPsr4[$search] as $dir) {
|
||||
if (file_exists($file = $dir . $pathEnd)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-4 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr4 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 lookup
|
||||
if (false !== $pos = strrpos($class, '\\')) {
|
||||
// namespaced class name
|
||||
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
|
||||
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
|
||||
}
|
||||
|
||||
if (isset($this->prefixesPsr0[$first])) {
|
||||
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr0 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 include paths.
|
||||
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope isolated include.
|
||||
*
|
||||
* Prevents access to $this/self from included files.
|
||||
*/
|
||||
function includeFile($file)
|
||||
{
|
||||
include $file;
|
||||
}
|
21
vendor/composer/LICENSE
vendored
Normal file
21
vendor/composer/LICENSE
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
Copyright (c) Nils Adermann, Jordi Boggiano
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
23
vendor/composer/autoload_classmap.php
vendored
Normal file
23
vendor/composer/autoload_classmap.php
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
// autoload_classmap.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'CaptainCore\\Account' => $baseDir . '/app/Account.php',
|
||||
'CaptainCore\\Accounts' => $baseDir . '/app/Accounts.php',
|
||||
'CaptainCore\\DB' => $baseDir . '/app/DB.php',
|
||||
'CaptainCore\\Domains' => $baseDir . '/app/Domains.php',
|
||||
'CaptainCore\\Environments' => $baseDir . '/app/Environments.php',
|
||||
'CaptainCore\\Invite' => $baseDir . '/app/Invite.php',
|
||||
'CaptainCore\\Invites' => $baseDir . '/app/Invites.php',
|
||||
'CaptainCore\\Keys' => $baseDir . '/app/Keys.php',
|
||||
'CaptainCore\\Quicksaves' => $baseDir . '/app/Quicksaves.php',
|
||||
'CaptainCore\\Recipes' => $baseDir . '/app/Recipes.php',
|
||||
'CaptainCore\\Site' => $baseDir . '/app/Site.php',
|
||||
'CaptainCore\\Sites' => $baseDir . '/app/Sites.php',
|
||||
'CaptainCore\\Snapshots' => $baseDir . '/app/Snapshots.php',
|
||||
'CaptainCore\\UpdateLogs' => $baseDir . '/app/UpdateLogs.php',
|
||||
);
|
9
vendor/composer/autoload_namespaces.php
vendored
Normal file
9
vendor/composer/autoload_namespaces.php
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
// autoload_namespaces.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
10
vendor/composer/autoload_psr4.php
vendored
Normal file
10
vendor/composer/autoload_psr4.php
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
// autoload_psr4.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'CaptainCore\\' => array($baseDir . '/app'),
|
||||
);
|
52
vendor/composer/autoload_real.php
vendored
Normal file
52
vendor/composer/autoload_real.php
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit9f7509cc1c55bc410ccf6f05510f2050
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
public static function loadClassLoader($class)
|
||||
{
|
||||
if ('Composer\Autoload\ClassLoader' === $class) {
|
||||
require __DIR__ . '/ClassLoader.php';
|
||||
}
|
||||
}
|
||||
|
||||
public static function getLoader()
|
||||
{
|
||||
if (null !== self::$loader) {
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit9f7509cc1c55bc410ccf6f05510f2050', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit9f7509cc1c55bc410ccf6f05510f2050', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require_once __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit9f7509cc1c55bc410ccf6f05510f2050::getInitializer($loader));
|
||||
} else {
|
||||
$map = require __DIR__ . '/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->set($namespace, $path);
|
||||
}
|
||||
|
||||
$map = require __DIR__ . '/autoload_psr4.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->setPsr4($namespace, $path);
|
||||
}
|
||||
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
$loader->addClassMap($classMap);
|
||||
}
|
||||
}
|
||||
|
||||
$loader->register(true);
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
49
vendor/composer/autoload_static.php
vendored
Normal file
49
vendor/composer/autoload_static.php
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
// autoload_static.php @generated by Composer
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit9f7509cc1c55bc410ccf6f05510f2050
|
||||
{
|
||||
public static $prefixLengthsPsr4 = array (
|
||||
'C' =>
|
||||
array (
|
||||
'CaptainCore\\' => 12,
|
||||
),
|
||||
);
|
||||
|
||||
public static $prefixDirsPsr4 = array (
|
||||
'CaptainCore\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/../..' . '/app',
|
||||
),
|
||||
);
|
||||
|
||||
public static $classMap = array (
|
||||
'CaptainCore\\Account' => __DIR__ . '/../..' . '/app/Account.php',
|
||||
'CaptainCore\\Accounts' => __DIR__ . '/../..' . '/app/Accounts.php',
|
||||
'CaptainCore\\DB' => __DIR__ . '/../..' . '/app/DB.php',
|
||||
'CaptainCore\\Domains' => __DIR__ . '/../..' . '/app/Domains.php',
|
||||
'CaptainCore\\Environments' => __DIR__ . '/../..' . '/app/Environments.php',
|
||||
'CaptainCore\\Invite' => __DIR__ . '/../..' . '/app/Invite.php',
|
||||
'CaptainCore\\Invites' => __DIR__ . '/../..' . '/app/Invites.php',
|
||||
'CaptainCore\\Keys' => __DIR__ . '/../..' . '/app/Keys.php',
|
||||
'CaptainCore\\Quicksaves' => __DIR__ . '/../..' . '/app/Quicksaves.php',
|
||||
'CaptainCore\\Recipes' => __DIR__ . '/../..' . '/app/Recipes.php',
|
||||
'CaptainCore\\Site' => __DIR__ . '/../..' . '/app/Site.php',
|
||||
'CaptainCore\\Sites' => __DIR__ . '/../..' . '/app/Sites.php',
|
||||
'CaptainCore\\Snapshots' => __DIR__ . '/../..' . '/app/Snapshots.php',
|
||||
'CaptainCore\\UpdateLogs' => __DIR__ . '/../..' . '/app/UpdateLogs.php',
|
||||
);
|
||||
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit9f7509cc1c55bc410ccf6f05510f2050::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit9f7509cc1c55bc410ccf6f05510f2050::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit9f7509cc1c55bc410ccf6f05510f2050::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
}
|
1
vendor/composer/installed.json
vendored
Normal file
1
vendor/composer/installed.json
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
[]
|
Loading…
Add table
Add a link
Reference in a new issue