Commit realizado el 12:13:52 08-04-2024
This commit is contained in:
157
wp-content/plugins/deployer-for-git/includes/Admin.php
Normal file
157
wp-content/plugins/deployer-for-git/includes/Admin.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
namespace DeployerForGit;
|
||||
|
||||
use DeployerForGit\Subpages\DashboardPage\Dashboard;
|
||||
use DeployerForGit\Subpages\InstallThemePage\InstallTheme;
|
||||
use DeployerForGit\Subpages\InstallPluginPage\InstallPlugin;
|
||||
use DeployerForGit\Subpages\LogsPage\Logs;
|
||||
use DeployerForGit\Subpages\MiscellaneousPage\Miscellaneous;
|
||||
|
||||
/**
|
||||
* Class Admin
|
||||
*
|
||||
* @package DeployerForGit
|
||||
*/
|
||||
class Admin {
|
||||
/**
|
||||
* Admin constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->init_dashboard_page();
|
||||
$this->init_install_theme_page();
|
||||
$this->init_install_plugin_page();
|
||||
$this->init_logs_page();
|
||||
$this->init_miscellaneous_page();
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
add_action( is_multisite() ? 'network_admin_notices' : 'admin_notices', array( $this, 'display_alert_notification_box' ) );
|
||||
add_filter( 'admin_footer_text', array( $this, 'admin_footer' ), 1, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize dashboard page
|
||||
*/
|
||||
private function init_dashboard_page() {
|
||||
new Dashboard();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize install theme page
|
||||
*/
|
||||
public function init_install_theme_page() {
|
||||
new InstallTheme();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize install plugin page
|
||||
*/
|
||||
private function init_install_plugin_page() {
|
||||
new InstallPlugin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize miscellaneous page
|
||||
*/
|
||||
private function init_miscellaneous_page() {
|
||||
new Miscellaneous();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize logs page
|
||||
*/
|
||||
private function init_logs_page() {
|
||||
new Logs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display alert notification box
|
||||
*/
|
||||
public function display_alert_notification_box() {
|
||||
$data_manager = new DataManager();
|
||||
$alert_notification_setting = $data_manager->get_alert_notification_setting();
|
||||
|
||||
if ( $alert_notification_setting ) {
|
||||
$menu_slug = Helper::menu_slug();
|
||||
$dashboard_url = is_multisite() ? network_admin_url( "admin.php?page={$menu_slug}" ) : menu_page_url( $menu_slug, false );
|
||||
|
||||
// translators: %s = dashboard url.
|
||||
$html = wp_kses_post( __( '<strong>Warning:</strong> Please do not make any changes to the theme or plugin code directly because some themes or plugins are connected with Git.<br>Click <a href="%s">here</a> to learn more.', 'deployer-for-git' ) );
|
||||
$html = sprintf( $html, esc_url( $dashboard_url ) );
|
||||
|
||||
$html = apply_filters( 'dfg_alert_notification_message', $html );
|
||||
|
||||
$html = "<div class='dfg_alert_box' >{$html}</div>";
|
||||
|
||||
echo wp_kses(
|
||||
$html,
|
||||
array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'title' => array(),
|
||||
),
|
||||
'br' => array(),
|
||||
'strong' => array(),
|
||||
'div' => array(
|
||||
'class' => array(),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
wp_enqueue_style( 'dfg-styles', DFG_URL . 'assets/css/deployer-for-git-main.css', array(), DFG_VERSION );
|
||||
|
||||
wp_enqueue_script( 'dfg-script', DFG_URL . 'assets/js/deployer-for-git-main.js', array(), DFG_VERSION, true );
|
||||
|
||||
wp_localize_script(
|
||||
'dfg-script',
|
||||
'dfg',
|
||||
array(
|
||||
'copy_url_label' => __( 'Copy URL', 'deployer-for-git' ),
|
||||
'copied_url_label' => __( 'Copied!', 'deployer-for-git' ),
|
||||
'updating_now_label' => __( 'Updating now...', 'deployer-for-git' ),
|
||||
'error_label' => __( 'Something went wrong', 'deployer-for-git' ),
|
||||
'update_completed_label' => __( 'Updated!', 'deployer-for-git' ),
|
||||
'update_theme_label' => __( 'Update Theme', 'deployer-for-git' ),
|
||||
'update_plugin_label' => __( 'Update Plugin', 'deployer-for-git' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* When user is on a plugin related admin page, display footer text.
|
||||
*
|
||||
* @param string $text Footer text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function admin_footer( $text ) {
|
||||
|
||||
global $current_screen;
|
||||
|
||||
if ( ! empty( $current_screen->id ) && strpos( $current_screen->id, 'deployer-for-git' ) !== false ) {
|
||||
$url = 'https://wordpress.org/support/plugin/deployer-for-git/reviews/?filter=5#new-post';
|
||||
$text = sprintf(
|
||||
wp_kses( /* translators: $1$s - Deployer for Git plugin name; $2$s - WP.org review link; $3$s - WP.org review link. */
|
||||
__( 'Please rate %1$s <a href="%2$s" target="_blank" rel="noopener noreferrer">★★★★★</a> on <a href="%3$s" target="_blank" rel="noopener">WordPress.org</a> to support and promote our solution. Thank you very much!', 'deployer-for-git' ),
|
||||
array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'target' => array(),
|
||||
'rel' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'<strong>Deployer for Git</strong>',
|
||||
$url,
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace DeployerForGit\ApiRequests;
|
||||
|
||||
use DeployerForGit\DataManager;
|
||||
use DeployerForGit\Helper;
|
||||
use DeployerForGit\Logger;
|
||||
use DeployerForGit\Subpages\InstallPackage;
|
||||
|
||||
/**
|
||||
* PackageUpdate class
|
||||
* Used to handle the package installation or update
|
||||
*/
|
||||
class PackageUpdate {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Register the REST API route
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action(
|
||||
'rest_api_init',
|
||||
function () {
|
||||
register_rest_route(
|
||||
'dfg/v1',
|
||||
'/package_update/',
|
||||
array(
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array( $this, 'update_package_callback' ),
|
||||
),
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array( $this, 'update_package_callback' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the package update URL
|
||||
*
|
||||
* @param string $package_slug slug of the package.
|
||||
* @param string $type (theme|plugin).
|
||||
* @return string $url
|
||||
*/
|
||||
public static function package_update_url( $package_slug = '', $type = 'theme' ) {
|
||||
$type = ( 'theme' === $type ) ? 'theme' : 'plugin';
|
||||
$url = sprintf( '%s/wp-json/dfg/v1/package_update?secret=%s&type=%s&package=%s', site_url(), Helper::get_api_secret(), $type, $package_slug );
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the package update request
|
||||
*
|
||||
* @param WP_REST_Request $request The request object.
|
||||
* @return array $response
|
||||
*/
|
||||
public function update_package_callback( $request ) {
|
||||
// Handle the request and return data as JSON.
|
||||
$secret = $request->get_param( 'secret' );
|
||||
$package_slug = $request->get_param( 'package' );
|
||||
$package_type = $request->get_param( 'type' ) === 'plugin' ? 'plugin' : 'theme';
|
||||
|
||||
do_action( 'dfg_before_api_package_update', $package_slug, $package_type );
|
||||
|
||||
if ( null === $secret || Helper::get_api_secret() !== $secret ) {
|
||||
// set status code to 401.
|
||||
status_header( 401 );
|
||||
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => 'Invalid secret',
|
||||
);
|
||||
}
|
||||
|
||||
$data_manager = new DataManager();
|
||||
|
||||
if ( 'theme' === $package_type ) {
|
||||
$package_details = $data_manager->get_theme( $package_slug );
|
||||
} else {
|
||||
$package_details = $data_manager->get_plugin( $package_slug );
|
||||
}
|
||||
|
||||
if ( false === $package_details ) {
|
||||
status_header( 401 );
|
||||
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => 'Invalid package',
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
$provider_class_name = Helper::get_provider_class( $package_details['provider'] );
|
||||
|
||||
$provider = new $provider_class_name( $package_details['repo_url'] );
|
||||
|
||||
$package_slug = $provider->get_package_slug();
|
||||
$package_zip_url = $provider->get_zip_repo_url( $package_details['branch'] );
|
||||
$package_install_options = array();
|
||||
|
||||
if ( array_key_exists( 'is_private_repository', $package_details ) && $package_details['is_private_repository'] === true ) {
|
||||
$package_install_options = array(
|
||||
'is_private_repository' => true,
|
||||
'username' => $package_details['options']['username'],
|
||||
'password' => $package_details['options']['password'],
|
||||
'access_token' => $package_details['options']['access_token'],
|
||||
);
|
||||
}
|
||||
|
||||
$package_install_options['wp_json_request'] = true;
|
||||
|
||||
$install_result = InstallPackage::install_package_from_zip_url( $package_zip_url, $package_slug, $package_type, $package_details['provider'], $package_install_options );
|
||||
} catch ( \Exception $e ) {
|
||||
$install_result = new \WP_Error( 'invalid', $e->getMessage() );
|
||||
}
|
||||
|
||||
$success = ( is_wp_error( $install_result ) ? false : true );
|
||||
$message = '';
|
||||
|
||||
$logger = new Logger();
|
||||
if ( $success ) {
|
||||
$logger->log( "Package ({$package_type}) \"{$package_slug}\" successfully updated via wp-json" );
|
||||
$message = esc_attr__( 'Package updated successfully.', 'deployer-for-git' );
|
||||
|
||||
$flush_cache_setting_enabled = $data_manager->get_flush_cache_setting();
|
||||
if ( $flush_cache_setting_enabled ) {
|
||||
$logger->log( "Flushing cache after package ({$package_type}) \"{$package_slug}\" update via wp-json" );
|
||||
$message .= ' ' . esc_attr__( 'Cache flushed.', 'deployer-for-git' );
|
||||
Helper::trigger_cache_flush();
|
||||
}
|
||||
} elseif ( is_wp_error( $install_result ) ) {
|
||||
$error_message = $install_result->get_error_message();
|
||||
|
||||
$logger->log(
|
||||
sprintf(
|
||||
'Error occurred while updating a package (%1$s) "%2$s" via wp-json "%3$s"',
|
||||
$package_type,
|
||||
$package_slug,
|
||||
$error_message
|
||||
)
|
||||
);
|
||||
|
||||
$message = $error_message;
|
||||
}
|
||||
|
||||
do_action( 'dfg_after_api_package_update', $success, $package_slug, $package_type );
|
||||
|
||||
return array(
|
||||
'success' => $success,
|
||||
'message' => $message,
|
||||
'package_type' => $package_type,
|
||||
'package_slug' => $package_slug,
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
// Silence is golden
|
360
wp-content/plugins/deployer-for-git/includes/DataManager.php
Normal file
360
wp-content/plugins/deployer-for-git/includes/DataManager.php
Normal file
@@ -0,0 +1,360 @@
|
||||
<?php
|
||||
namespace DeployerForGit;
|
||||
|
||||
/**
|
||||
* Data Manager class
|
||||
*/
|
||||
class DataManager {
|
||||
|
||||
/**
|
||||
* Update flush cache setting
|
||||
*
|
||||
* @param boolean $enabled true if need to enable, false otherwise.
|
||||
* @return boolean
|
||||
*/
|
||||
public function update_flush_cache_setting( $enabled = false ) {
|
||||
$option_name = $this->get_flush_cache_option_name();
|
||||
|
||||
$string_value = $enabled ? '1' : '0';
|
||||
|
||||
return update_option( $option_name, $string_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update alert notification setting
|
||||
*
|
||||
* @param boolean $enabled true if need to enable, false otherwise.
|
||||
* @return boolean
|
||||
*/
|
||||
public function update_alert_notification_setting( $enabled = false ) {
|
||||
$option_name = $this->get_alert_notification_option_name();
|
||||
|
||||
$string_value = $enabled ? '1' : '0';
|
||||
|
||||
return update_option( $option_name, $string_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get flush cache option name
|
||||
*
|
||||
* @return boolean, false if not enabled, true if enabled
|
||||
*/
|
||||
public function get_flush_cache_setting() {
|
||||
$option_name = $this->get_flush_cache_option_name();
|
||||
$option_value = get_option( $option_name, '0' );
|
||||
|
||||
$bool_result = ( $option_value === '0' ) ? false : true;
|
||||
|
||||
return $bool_result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get alert notification option name
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function get_alert_notification_setting() {
|
||||
$option_name = $this->get_alert_notification_option_name();
|
||||
$option_value = get_option( $option_name, '0' );
|
||||
|
||||
$bool_result = ( $option_value === '0' ) ? false : true;
|
||||
|
||||
return $bool_result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will reverify the theme saved in database and will remove if it's not exist.
|
||||
*/
|
||||
private function reverify_theme_lists() {
|
||||
return $this->reverify_package_lists( 'theme' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will reverify the plugin saved in database and will remove if it's not exist.
|
||||
*/
|
||||
private function reverify_plugin_lists() {
|
||||
return $this->reverify_package_lists( 'plugin' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will reverify the theme details.
|
||||
*
|
||||
* @param string $type Type of package (theme or plugin).
|
||||
* @return void
|
||||
*/
|
||||
private function reverify_package_lists( $type = 'theme' ) {
|
||||
$type = ( $type === 'theme' ) ? 'theme' : 'plugin';
|
||||
|
||||
if ( $type === 'theme' ) {
|
||||
$option_name = $this->get_themes_option_name();
|
||||
} else {
|
||||
$option_name = $this->get_plugins_option_name();
|
||||
}
|
||||
|
||||
$package_list = get_option( $option_name, array() );
|
||||
|
||||
foreach ( $package_list as $package_data ) {
|
||||
if ( $type === 'theme' ) {
|
||||
$theme = wp_get_theme( $package_data['slug'] );
|
||||
|
||||
if ( ! $theme->exists() ) {
|
||||
$this->remove_package_details( $package_data['slug'], 'theme' );
|
||||
}
|
||||
} else {
|
||||
$plugin_path = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $package_data['slug'];
|
||||
|
||||
if ( ! file_exists( $plugin_path ) ) {
|
||||
$this->remove_package_details( $package_data['slug'], 'plugin' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will return the theme details.
|
||||
*
|
||||
* @param string $slug Theme slug.
|
||||
* @param string $type Type of package (theme or plugin).
|
||||
* @return array|bool Array of theme details if found, false otherwise.
|
||||
*/
|
||||
private function get_package( $slug = '', $type = 'theme' ) {
|
||||
$type = ( $type === 'theme' ) ? 'theme' : 'plugin';
|
||||
|
||||
if ( $type === 'theme' ) {
|
||||
$package_list = $this->get_theme_list();
|
||||
} else {
|
||||
$package_list = $this->get_plugin_list();
|
||||
}
|
||||
|
||||
foreach ( $package_list as $package_details ) {
|
||||
// If the theme_stylesheet matches the one we're looking to update.
|
||||
if ( $package_details['slug'] === $slug ) {
|
||||
|
||||
return $package_details;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will return the theme details.
|
||||
*
|
||||
* @param string $theme_slug Theme slug.
|
||||
* @return array|bool Array of theme details if found, false otherwise.
|
||||
*/
|
||||
public function get_theme( $theme_slug = '' ) {
|
||||
return $this->get_package( $theme_slug, 'theme' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will return the plugin details.
|
||||
*
|
||||
* @param string $plugin_slug Plugin slug.
|
||||
* @return array|bool Array of plugin details if found, false otherwise.
|
||||
*/
|
||||
public function get_plugin( $plugin_slug = '' ) {
|
||||
return $this->get_package( $plugin_slug, 'plugin' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will return the list of all stored theme details.
|
||||
*
|
||||
* @return array Array of all stored theme details.
|
||||
*/
|
||||
public function get_theme_list() {
|
||||
// synchronize existing themes with plugin options.
|
||||
$this->reverify_theme_lists();
|
||||
|
||||
// Get all stored theme details.
|
||||
$option_name = $this->get_themes_option_name();
|
||||
return get_option( $option_name, array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will return the list of all stored plugin details.
|
||||
*
|
||||
* @return array Array of all stored plugin details.
|
||||
*/
|
||||
public function get_plugin_list() {
|
||||
// synchronize existing themes with plugin options.
|
||||
$this->reverify_plugin_lists();
|
||||
|
||||
// Get all stored theme details.
|
||||
$option_name = $this->get_plugins_option_name();
|
||||
return get_option( $option_name, array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will return the option name for storing alert notification setting.
|
||||
*
|
||||
* @return string Option name for storing alert notification setting.
|
||||
*/
|
||||
private function get_alert_notification_option_name() {
|
||||
return DFG_SLUG . '_alert_notification';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will return the option name for storing flush cache setting.
|
||||
*
|
||||
* @return string Option name for storing flush cache setting.
|
||||
*/
|
||||
private function get_flush_cache_option_name() {
|
||||
return DFG_SLUG . '_flush_cache';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will return the option name for storing theme details.
|
||||
*
|
||||
* @return string Option name for storing theme details.
|
||||
*/
|
||||
private function get_themes_option_name() {
|
||||
return DFG_SLUG . '_themes_list';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will return the option name for storing plugin details.
|
||||
*
|
||||
* @return string Option name for storing plugin details.
|
||||
*/
|
||||
private function get_plugins_option_name() {
|
||||
return DFG_SLUG . '_plugins_list';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will check if the data is correct.
|
||||
*
|
||||
* @param array $data Array of package data to save.
|
||||
* @return bool true if saved successfully, false otherwise.
|
||||
*/
|
||||
private function option_value_is_correct( $data ) {
|
||||
if ( ! is_array( $data ) ) {
|
||||
return false; }
|
||||
|
||||
foreach ( array( 'slug', 'repo_url', 'branch', 'provider', 'is_private_repository', 'options' ) as $name ) {
|
||||
if ( ! array_key_exists( $name, $data ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! is_bool( $data['is_private_repository'] ) ) {
|
||||
return false; }
|
||||
|
||||
if ( ! is_array( $data['options'] ) ) {
|
||||
return false; }
|
||||
|
||||
if ( $data['is_private_repository'] === true ) {
|
||||
|
||||
$access_token_exist = array_key_exists( 'access_token', $data['options'] );
|
||||
$user_pwd_exist = array_key_exists( 'username', $data['options'] ) && array_key_exists( 'password', $data['options'] );
|
||||
|
||||
if ( ! $access_token_exist && ! $user_pwd_exist ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $data['provider'] === 'github' && ! $access_token_exist ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $data['provider'] === 'gitea' && ! $access_token_exist ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $data['provider'] === 'bitbucket' && ! $user_pwd_exist ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will save theme data to the DB.
|
||||
*
|
||||
* @param array $new_data Array of package data to save.
|
||||
* @param string $type Type of package (theme or plugin).
|
||||
* @return bool true if saved successfully, false otherwise.
|
||||
*/
|
||||
public function store_package_details( $new_data, $type = 'theme' ) {
|
||||
$type = ( $type === 'theme' ) ? 'theme' : 'plugin';
|
||||
|
||||
if ( ! $this->option_value_is_correct( $new_data ) ) {
|
||||
return false; }
|
||||
|
||||
$data_updated = false;
|
||||
|
||||
if ( $type === 'theme' ) {
|
||||
// Get all stored theme details.
|
||||
$packages_list = $this->get_theme_list();
|
||||
} else {
|
||||
// Get all stored plugin details.
|
||||
$packages_list = $this->get_plugin_list();
|
||||
}
|
||||
|
||||
// Iterate over each packages details.
|
||||
foreach ( $packages_list as &$details ) {
|
||||
// If the theme_stylesheet matches the one we're looking to update.
|
||||
if ( $details['slug'] === $new_data['slug'] ) {
|
||||
// Update theme data URL for this theme.
|
||||
$details = $new_data;
|
||||
$data_updated = true;
|
||||
|
||||
// Since we've found and updated the theme we're interested in, we can break the loop.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// check if nothing was updated.
|
||||
if ( ! $data_updated ) {
|
||||
// append to existing data.
|
||||
$packages_list[] = $new_data;
|
||||
}
|
||||
|
||||
if ( $type === 'theme' ) {
|
||||
$option_name = $this->get_themes_option_name();
|
||||
} else {
|
||||
$option_name = $this->get_plugins_option_name();
|
||||
}
|
||||
// Save the updated package details back to the options.
|
||||
return update_option( $option_name, $packages_list );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which will remove theme data from the DB.
|
||||
*
|
||||
* @param string $slug Theme slug.
|
||||
* @param string $type Type of package (theme or plugin).
|
||||
* @return bool true if saved successfully, false otherwise.
|
||||
*/
|
||||
private function remove_package_details( $slug = '', $type = 'theme' ) {
|
||||
$type = ( $type === 'theme' ) ? 'theme' : 'plugin';
|
||||
|
||||
if ( empty( $slug ) ) {
|
||||
return false; }
|
||||
|
||||
if ( $type === 'theme' ) {
|
||||
// Get all stored theme details.
|
||||
$option_name = $this->get_themes_option_name();
|
||||
} else {
|
||||
// Get all stored plugin details.
|
||||
$option_name = $this->get_plugins_option_name();
|
||||
}
|
||||
|
||||
$packages_details = get_option( $option_name, array() );
|
||||
|
||||
// Iterate over each theme's details.
|
||||
foreach ( $packages_details as $key => $package_details ) {
|
||||
// If the theme_stylesheet matches the one we're looking to update.
|
||||
if ( $package_details['slug'] === $slug ) {
|
||||
// Update theme data URL for this theme.
|
||||
unset( $packages_details[ $key ] );
|
||||
|
||||
// Since we've found and removed the theme we're interested in, we can break the loop.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Save the updated theme details back to the options.
|
||||
return update_option( $option_name, $packages_details );
|
||||
}
|
||||
}
|
205
wp-content/plugins/deployer-for-git/includes/Helper.php
Normal file
205
wp-content/plugins/deployer-for-git/includes/Helper.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
namespace DeployerForGit;
|
||||
|
||||
/**
|
||||
* Helper class
|
||||
*/
|
||||
class Helper {
|
||||
|
||||
/**
|
||||
* Get the plugin name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function menu_slug() {
|
||||
return 'deployer-for-git';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the theme install page url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function install_theme_url() {
|
||||
$menu_slug = self::menu_slug();
|
||||
$path = "admin.php?page={$menu_slug}-install-theme";
|
||||
$theme_istall_page_url = is_multisite() ? network_admin_url( $path ) : admin_url( $path );
|
||||
|
||||
return $theme_istall_page_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin install page url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function install_plugin_url() {
|
||||
$menu_slug = self::menu_slug();
|
||||
$path = "admin.php?page={$menu_slug}-install-plugin";
|
||||
$plugin_istall_page_url = is_multisite() ? network_admin_url( $path ) : admin_url( $path );
|
||||
|
||||
return $plugin_istall_page_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the available providers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function available_providers() {
|
||||
return array(
|
||||
'bitbucket' => 'Bitbucket',
|
||||
'github' => 'GitHub',
|
||||
'gitea' => 'Gitea',
|
||||
'gitlab' => 'GitLab',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the provider class
|
||||
*
|
||||
* @param string $provider Provider name.
|
||||
* @return string
|
||||
*/
|
||||
public static function get_provider_class( $provider ) {
|
||||
// phpcs:disable Squiz.PHP.NonExecutableCode.Unreachable
|
||||
switch ( $provider ) {
|
||||
case 'bitbucket':
|
||||
return '\DeployerForGit\Providers\BitbucketProvider';
|
||||
break;
|
||||
case 'github':
|
||||
return '\DeployerForGit\Providers\GithubProvider';
|
||||
break;
|
||||
case 'gitea':
|
||||
return '\DeployerForGit\Providers\GiteaProvider';
|
||||
break;
|
||||
case 'gitlab':
|
||||
return '\DeployerForGit\Providers\GitlabProvider';
|
||||
break;
|
||||
|
||||
default:
|
||||
return '\DeployerForGit\Providers\BitbucketProvider';
|
||||
break;
|
||||
}
|
||||
// phpcs:enable Squiz.PHP.NonExecutableCode.Unreachable
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the api secret
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generate_api_secret() {
|
||||
$key = bin2hex( random_bytes( 32 ) );
|
||||
return update_option( 'deployer_for_git_api_secret', $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the api secret
|
||||
*
|
||||
* @return string|boolean false
|
||||
*/
|
||||
public static function get_api_secret() {
|
||||
return get_option( 'deployer_for_git_api_secret', false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if WpRocket plugin is activated.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function wp_rocket_activated() {
|
||||
return function_exists( 'rocket_clean_domain' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if WP Optimize plugin is activated.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function wp_optimize_activated() {
|
||||
return class_exists( 'WP_Optimize' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if W3 Total Cache plugin is activated.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function w3tc_activated() {
|
||||
return function_exists( 'w3tc_pgcache_flush' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if LiteSpeed Cache plugin is activated.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function litespeed_cache_activated() {
|
||||
return has_action( 'litespeed_purge_all' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if WP Super Cache plugin is activated.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function wp_super_cache_activated() {
|
||||
return function_exists( 'wp_cache_clear_cache' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if WP Fastest Cache plugin is activated.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function wp_fastest_cache_activated() {
|
||||
return ( isset( $GLOBALS['wp_fastest_cache'] ) && method_exists( $GLOBALS['wp_fastest_cache'], 'deleteCache' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Autoptimize plugin is activated.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function autoptimize_activated() {
|
||||
return method_exists( 'autoptimizeCache', 'clearall' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger cache flush
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function trigger_cache_flush() {
|
||||
if ( self::wp_rocket_activated() ) {
|
||||
\rocket_clean_domain();
|
||||
}
|
||||
|
||||
if ( self::wp_optimize_activated() ) {
|
||||
if ( method_exists( 'WP_Optimize', 'get_page_cache' ) && method_exists( \WP_Optimize()->get_page_cache(), 'purge' ) ) {
|
||||
\WP_Optimize()->get_page_cache()->purge();
|
||||
}
|
||||
}
|
||||
|
||||
if ( self::w3tc_activated() ) {
|
||||
\w3tc_pgcache_flush();
|
||||
}
|
||||
|
||||
if ( self::litespeed_cache_activated() ) {
|
||||
do_action( 'litespeed_purge_all' );
|
||||
}
|
||||
|
||||
if ( self::wp_super_cache_activated() ) {
|
||||
\wp_cache_clear_cache();
|
||||
}
|
||||
|
||||
if ( self::wp_fastest_cache_activated() ) {
|
||||
$GLOBALS['wp_fastest_cache']->deleteCache( true );
|
||||
}
|
||||
|
||||
if ( self::autoptimize_activated() ) {
|
||||
\autoptimizeCache::clearall();
|
||||
}
|
||||
}
|
||||
}
|
140
wp-content/plugins/deployer-for-git/includes/Logger.php
Normal file
140
wp-content/plugins/deployer-for-git/includes/Logger.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace DeployerForGit;
|
||||
|
||||
/**
|
||||
* Logger class
|
||||
*/
|
||||
class Logger {
|
||||
|
||||
/**
|
||||
* Log directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $log_directory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$upload_dir = wp_upload_dir();
|
||||
$logs_directory_name = DFG_SLUG . '-logs';
|
||||
$this->log_directory = $upload_dir['basedir'] . '/' . $logs_directory_name;
|
||||
|
||||
$this->create_log_directory();
|
||||
$this->create_htaccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log message to log file
|
||||
*
|
||||
* @param string $message Message to log.
|
||||
*/
|
||||
public function log( $message ) {
|
||||
// Load the WordPress filesystem API.
|
||||
global $wp_filesystem;
|
||||
|
||||
// Make sure the filesystem is loaded and ready for use.
|
||||
if ( ! is_object( $wp_filesystem ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
WP_Filesystem();
|
||||
}
|
||||
|
||||
// Check if the filesystem is ready for use.
|
||||
if ( ! is_object( $wp_filesystem ) ) {
|
||||
// Filesystem couldn't be loaded, handle the error or fallback to alternative methods.
|
||||
return;
|
||||
}
|
||||
|
||||
$log_file_path = $this->log_directory . DIRECTORY_SEPARATOR . 'plugin.log';
|
||||
$log_message_string = '[' . gmdate( 'Y-m-d H:i:s' ) . '] ' . $message . PHP_EOL;
|
||||
|
||||
// Read the existing content of the file.
|
||||
$existing_content = $wp_filesystem->get_contents( $log_file_path );
|
||||
|
||||
// Concatenate the new log message to the existing content.
|
||||
$updated_content = $existing_content . $log_message_string;
|
||||
|
||||
// Use WP_Filesystem method to write the updated content back to the file.
|
||||
$wp_filesystem->put_contents( $log_file_path, $updated_content );
|
||||
|
||||
do_action( 'dfg_after_log', $log_message_string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display log content
|
||||
*
|
||||
* @return string Log content
|
||||
*/
|
||||
public function display_log_content() {
|
||||
$log_file_path = $this->log_directory . DIRECTORY_SEPARATOR . 'plugin.log';
|
||||
if ( file_exists( $log_file_path ) ) {
|
||||
|
||||
if ( ! class_exists( 'WP_Filesystem_Direct' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
|
||||
}
|
||||
|
||||
$filesystem = new \WP_Filesystem_Direct( true );
|
||||
$log_content = $filesystem->get_contents( $log_file_path );
|
||||
|
||||
return $log_content;
|
||||
} else {
|
||||
return esc_attr__( 'Log file not found.', 'deployer-for-git' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create log file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function create_htaccess() {
|
||||
$htaccess_file_path = $this->log_directory . '/.htaccess';
|
||||
|
||||
if ( ! file_exists( $htaccess_file_path ) ) {
|
||||
$content = 'Deny from all';
|
||||
|
||||
if ( ! class_exists( 'WP_Filesystem_Direct' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
|
||||
}
|
||||
|
||||
$filesystem = new \WP_Filesystem_Direct( true );
|
||||
$filesystem->put_contents( $htaccess_file_path, $content );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create log directory
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function create_log_directory() {
|
||||
if ( ! is_dir( $this->log_directory ) ) {
|
||||
mkdir( $this->log_directory, 0755, true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear log file
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function clear_log_file() {
|
||||
$log_file_path = $this->log_directory . '/plugin.log';
|
||||
$result = false;
|
||||
if ( file_exists( $log_file_path ) ) {
|
||||
if ( ! class_exists( 'WP_Filesystem_Direct' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
|
||||
}
|
||||
|
||||
$filesystem = new \WP_Filesystem_Direct( true );
|
||||
$result = $filesystem->put_contents( $log_file_path, '' );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace DeployerForGit;
|
||||
|
||||
if ( ! class_exists( 'WP_Upgrader_Skin' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php';
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Plugin_Installer_Skin' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-plugin-installer-skin.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Class PluginInstallerSkin
|
||||
*
|
||||
* @package DeployerForGit
|
||||
*/
|
||||
class PluginInstallerSkin extends \Plugin_Installer_Skin {
|
||||
|
||||
/**
|
||||
* Override header method with empty function.
|
||||
*/
|
||||
public function header() {}
|
||||
|
||||
/**
|
||||
* Override footer method with empty function.
|
||||
*/
|
||||
public function footer() {}
|
||||
|
||||
/**
|
||||
* Override feedback method with empty function.
|
||||
*
|
||||
* @param string $feedback Message data.
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
*/
|
||||
public function feedback( $feedback, ...$args ) {}
|
||||
|
||||
/**
|
||||
* Override error method with empty function.
|
||||
*
|
||||
* @param string|WP_Error $errors Errors.
|
||||
*/
|
||||
public function error( $errors ) {}
|
||||
|
||||
/**
|
||||
* Override after method with empty function.
|
||||
*/
|
||||
public function after() {}
|
||||
}
|
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
namespace DeployerForGit\Providers;
|
||||
|
||||
/**
|
||||
* Base provider class
|
||||
*/
|
||||
class BaseProvider {
|
||||
|
||||
/**
|
||||
* Repository url
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $repo_url;
|
||||
|
||||
/**
|
||||
* Repository options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $repo_url Repository url.
|
||||
* @param array $options Repository options.
|
||||
*
|
||||
* @throws \InvalidArgumentException If repository url is invalid.
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $repo_url = null, $options = array() ) {
|
||||
$this->repo_url = $repo_url;
|
||||
$this->options = $options;
|
||||
if ( is_wp_error( $this->validate_repo_url() ) ) {
|
||||
throw new \InvalidArgumentException( esc_attr( $this->validate_repo_url()->get_error_message() ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get repository url
|
||||
*
|
||||
* @return string Repository url
|
||||
*/
|
||||
public function get_repo_url() {
|
||||
return $this->repo_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate repository url
|
||||
*
|
||||
* @return WP_Error|boolean
|
||||
*/
|
||||
protected function validate_repo_url() {
|
||||
// check if the repo url is empty.
|
||||
if ( empty( $this->repo_url ) ) {
|
||||
return new \WP_Error( 'empty', __( 'Repository url required', 'deployer-for-git' ) );
|
||||
}
|
||||
|
||||
// check if the repo url is a valid url.
|
||||
if ( ! filter_var( $this->repo_url, FILTER_VALIDATE_URL ) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Repository url must be a url', 'deployer-for-git' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get provider repository zip URL
|
||||
*
|
||||
* @param string $branch Branch name, default is master.
|
||||
* @return string Repository URL to download zip.
|
||||
*/
|
||||
public function get_zip_repo_url( $branch = 'master' ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get provider repository handle
|
||||
*
|
||||
* @return string Repository handle
|
||||
*/
|
||||
protected function get_handle() {
|
||||
$parsed_url = wp_parse_url( $this->repo_url );
|
||||
$parts = explode( '/', $parsed_url['path'] );
|
||||
$handle = '';
|
||||
foreach ( $parts as $index => $part ) {
|
||||
if ( $index === 0 ) {
|
||||
continue;
|
||||
}
|
||||
$handle .= $part . '/';
|
||||
|
||||
// if end of the path, remove the trailing slash.
|
||||
if ( $index === count( $parts ) - 1 ) {
|
||||
$handle = rtrim( $handle, '/' );
|
||||
}
|
||||
}
|
||||
|
||||
return $handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get domain name from repository url
|
||||
*/
|
||||
protected function get_domain() {
|
||||
$parsed_url = wp_parse_url( $this->repo_url );
|
||||
|
||||
return $parsed_url['host'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pretty provider name
|
||||
*
|
||||
* @return string Provider name
|
||||
*/
|
||||
public function get_pretty_name() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get package slug from handle
|
||||
*
|
||||
* @return string Package slug
|
||||
*/
|
||||
public function get_package_slug() {
|
||||
$handle = $this->get_handle();
|
||||
|
||||
// get the last part of the handle.
|
||||
$slug = basename( $handle );
|
||||
|
||||
return $slug;
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace DeployerForGit\Providers;
|
||||
|
||||
/**
|
||||
* Class BitbucketProvider
|
||||
*
|
||||
* @package DeployerForGit\Providers
|
||||
*/
|
||||
class BitbucketProvider extends BaseProvider {
|
||||
|
||||
/**
|
||||
* Get provider repository handle
|
||||
*
|
||||
* @return string Repository handle
|
||||
*/
|
||||
public function get_pretty_name() {
|
||||
return 'Bitbucket';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get provider repository zip URL
|
||||
*
|
||||
* @param string $branch Branch name, default is master.
|
||||
* @return string Repository URL to download zip
|
||||
*/
|
||||
public function get_zip_repo_url( $branch = 'master' ) {
|
||||
$handle = $this->get_handle();
|
||||
|
||||
return "https://bitbucket.org/{$handle}/get/{$branch}.zip";
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate repository url
|
||||
*
|
||||
* @return WP_Error|boolean
|
||||
*/
|
||||
protected function validate_repo_url() {
|
||||
parent::validate_repo_url();
|
||||
|
||||
// check if string has exact format in a URL like this: https://bitbucket.org/owner/reponame .
|
||||
if ( ! preg_match( '/^https:\/\/bitbucket.org\/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+$/', $this->get_repo_url() ) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Repository url must be a valid Bitbucket repository url', 'deployer-for-git' ) );
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace DeployerForGit\Providers;
|
||||
|
||||
/**
|
||||
* Class GiteaProvider
|
||||
*
|
||||
* @package Wp_Git_Deployer
|
||||
*/
|
||||
class GiteaProvider extends BaseProvider {
|
||||
|
||||
/**
|
||||
* Get provider repository handle
|
||||
*
|
||||
* @return string Repository handle
|
||||
*/
|
||||
public function get_pretty_name() {
|
||||
return 'Gitea';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get provider repository zip URL
|
||||
*
|
||||
* @param string $branch Branch name, default is master.
|
||||
* @return string Repository URL to download zip
|
||||
*/
|
||||
public function get_zip_repo_url( $branch = 'master' ) {
|
||||
$handle = $this->get_handle();
|
||||
|
||||
return "https://gitea.com/api/v1/repos/{$handle}/archive/{$branch}.zip";
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate repository url
|
||||
*
|
||||
* @return WP_Error|boolean
|
||||
*/
|
||||
protected function validate_repo_url() {
|
||||
parent::validate_repo_url();
|
||||
|
||||
// check if string has exact format in a URL like this: https://gitea.com/owner/reponame .
|
||||
if ( ! preg_match( '/^https:\/\/gitea.com\/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+$/', $this->get_repo_url() ) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Repository url must be a valid Gitea repository url', 'deployer-for-git' ) );
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace DeployerForGit\Providers;
|
||||
|
||||
/**
|
||||
* Class GithubProvider
|
||||
*
|
||||
* @package Wp_Git_Deployer
|
||||
*/
|
||||
class GithubProvider extends BaseProvider {
|
||||
|
||||
/**
|
||||
* Get provider repository handle
|
||||
*
|
||||
* @return string Repository handle
|
||||
*/
|
||||
public function get_pretty_name() {
|
||||
return 'GitHub';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get provider repository zip URL
|
||||
*
|
||||
* @param string $branch Branch name, default is master.
|
||||
* @return string Repository URL to download zip
|
||||
*/
|
||||
public function get_zip_repo_url( $branch = 'master' ) {
|
||||
$handle = $this->get_handle();
|
||||
|
||||
return "https://github.com/{$handle}/archive/refs/heads/{$branch}.zip";
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate repository url
|
||||
*
|
||||
* @return WP_Error|boolean
|
||||
*/
|
||||
protected function validate_repo_url() {
|
||||
parent::validate_repo_url();
|
||||
|
||||
// check if string has exact format in a URL like this: https://github.com/company/wordpress-theme .
|
||||
if ( ! preg_match( '/^https:\/\/github.com\/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+$/', $this->get_repo_url() ) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Repository url must be a valid GitHub repository url', 'deployer-for-git' ) );
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace DeployerForGit\Providers;
|
||||
|
||||
/**
|
||||
* Class GitlabProvider
|
||||
*
|
||||
* @package DeployerForGit\Providers
|
||||
*/
|
||||
class GitlabProvider extends BaseProvider {
|
||||
|
||||
/**
|
||||
* Get provider repository handle
|
||||
*
|
||||
* @return string Repository handle
|
||||
*/
|
||||
public function get_pretty_name() {
|
||||
return 'GitLab';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get provider repository zip URL
|
||||
*
|
||||
* @param string $branch Branch name, default is master.
|
||||
* @return string Repository URL to download zip
|
||||
*/
|
||||
public function get_zip_repo_url( $branch = 'master' ) {
|
||||
$handle = $this->get_handle();
|
||||
$domain = $this->get_domain();
|
||||
$handle = rawurlencode( $handle );
|
||||
|
||||
return "https://{$domain}/api/v4/projects/{$handle}/repository/archive.zip?sha={$branch}";
|
||||
}
|
||||
|
||||
// disable the custom validation because user may use custom gitlab instance or groups which adds portions like /group/subgroup/ etc..
|
||||
// protected function validate_repo_url() {
|
||||
// return parent::validate_repo_url();.
|
||||
|
||||
// check if string has exact format in a URL like this: https://gitlab.com/owner/reponame .
|
||||
// if ( ! preg_match( '/^https?:\/\/[^\/]+(\/[^\/]+)+$/', $this->get_repo_url() ) ) {
|
||||
// return new \WP_Error( 'invalid', __( 'Repository url must be a valid GitLab repository url', 'deployer-for-git' ) );
|
||||
// }
|
||||
// }.
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace DeployerForGit\Subpages\DashboardPage;
|
||||
|
||||
use DeployerForGit\DataManager;
|
||||
use DeployerForGit\Helper;
|
||||
|
||||
/**
|
||||
* Class Dashboard
|
||||
*
|
||||
* @package DeployerForGit\Subpages\DashboardPage
|
||||
*/
|
||||
class Dashboard {
|
||||
|
||||
/**
|
||||
* Dashboard constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'init_menu' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the menu.
|
||||
*/
|
||||
public function init_menu() {
|
||||
$menu_slug = Helper::menu_slug();
|
||||
$capability = is_multisite() ? 'manage_network_options' : 'manage_options';
|
||||
|
||||
add_menu_page(
|
||||
esc_attr__( 'Dashboard', 'deployer-for-git' ),
|
||||
esc_attr__( 'Deployer for Git', 'deployer-for-git' ),
|
||||
$capability,
|
||||
$menu_slug,
|
||||
array( $this, 'init_page' ),
|
||||
'dashicons-randomize'
|
||||
);
|
||||
|
||||
add_submenu_page(
|
||||
$menu_slug,
|
||||
esc_attr__( 'Dashboard', 'deployer-for-git' ),
|
||||
esc_attr__( 'Dashboard', 'deployer-for-git' ),
|
||||
$capability,
|
||||
$menu_slug,
|
||||
array( $this, 'init_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the page.
|
||||
*/
|
||||
public function init_page() {
|
||||
$data_manager = new DataManager();
|
||||
|
||||
include_once __DIR__ . '/template.php';
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
use DeployerForGit\ApiRequests\PackageUpdate;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<h3>
|
||||
<span class="dashicons dashicons-admin-plugins"></span>
|
||||
<?php echo esc_attr__( 'Installed Plugins', 'deployer-for-git' ); ?> (<?php echo count( $plugin_list ); ?>)
|
||||
</h3>
|
||||
|
||||
<?php if ( empty( $plugin_list ) ) : ?>
|
||||
<?php
|
||||
$plugin_istall_page_url = \DeployerForGit\Helper::install_plugin_url();
|
||||
?>
|
||||
<div><?php echo esc_attr__( 'No plugins installed yet... Go and install one.', 'deployer-for-git' ); ?></div>
|
||||
<div class="dfg_mt_10" >
|
||||
<a href="<?php echo esc_url( $plugin_istall_page_url ); ?>" class="button">
|
||||
<?php echo esc_attr__( 'Install Plugin', 'deployer-for-git' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="dfg_package_boxes">
|
||||
<?php foreach ( $plugin_list as $plugin_info ) : ?>
|
||||
<?php $endpoint_url = PackageUpdate::package_update_url( $plugin_info['slug'], 'plugin' ); ?>
|
||||
<div class="dfg_package_box">
|
||||
<div>
|
||||
<h3>
|
||||
<?php
|
||||
$provider_logo_url = plugin_dir_url( DFG_FILE ) . 'assets/img/' . $plugin_info['provider'] . '-logo.svg';
|
||||
?>
|
||||
<img src="<?php echo esc_url( $provider_logo_url ); ?>" alt="<?php echo esc_attr( DeployerForGit\Helper::available_providers()[ $plugin_info['provider'] ] ); ?>" >
|
||||
<?php echo esc_attr( $plugin_info['slug'] ); ?>
|
||||
<?php if ( $plugin_info['is_private_repository'] ) : ?>
|
||||
<i class="dashicons dashicons-lock" title="<?php echo esc_attr__( 'Private Repo', 'deployer-for-git' ); ?>"></i>
|
||||
<?php else : ?>
|
||||
<i class="dashicons dashicons-unlock" title="<?php echo esc_attr__( 'Public Repo', 'deployer-for-git' ); ?>"></i>
|
||||
<?php endif; ?>
|
||||
</h3>
|
||||
<ul>
|
||||
<li>
|
||||
<i class="dashicons dashicons-randomize" title="<?php echo esc_attr__( 'Branch', 'deployer-for-git' ); ?>"></i>
|
||||
<code><?php echo esc_attr( $plugin_info['branch'] ); ?></code>
|
||||
</li>
|
||||
<li>
|
||||
<pre style="white-space: normal;"><?php echo esc_attr( $plugin_info['repo_url'] ); ?></pre>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" data-show-ptd-btn >
|
||||
<?php echo esc_attr__( '» Show Push-to-Deploy URL', 'deployer-for-git' ); ?>
|
||||
</a>
|
||||
<div class="dfg_package_box_action">
|
||||
<input type="url" disabled value="<?php echo esc_url( $endpoint_url ); ?>">
|
||||
<a data-copy-url-btn="<?php echo esc_url( $endpoint_url ); ?>" class="button" href="#" aria-label="<?php echo esc_attr__( 'Copy URL', 'deployer-for-git' ); ?>">
|
||||
<span class="dashicons dashicons-admin-page"></span>
|
||||
<span class="text" ><?php echo esc_attr__( 'Copy URL', 'deployer-for-git' ); ?></span>
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="dfg_package_box_buttons" >
|
||||
<button data-package-type="plugin"
|
||||
data-trigger-ptd-btn="<?php echo esc_url( $endpoint_url ); ?>"
|
||||
title="<?php echo esc_attr__( 'Remove', 'deployer-for-git' ); ?>"
|
||||
class="button button-primary update-package-btn" >
|
||||
<span class="dashicons dashicons-update"></span>
|
||||
<span class="text" ><?php echo esc_attr__( 'Update Plugin', 'deployer-for-git' ); ?></span>
|
||||
</button>
|
||||
|
||||
<?php
|
||||
$plugins_url = is_multisite() ? network_admin_url( 'plugins.php' ) : admin_url( 'plugins.php' );
|
||||
?>
|
||||
<a href="<?php echo esc_url( $plugins_url ); ?>"
|
||||
title="<?php echo esc_attr__( 'Remove', 'deployer-for-git' ); ?>"
|
||||
class="delete-theme button" ><span class="dashicons dashicons-trash"></span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
use DeployerForGit\ApiRequests\PackageUpdate;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<h3>
|
||||
<span class="dashicons dashicons-admin-appearance"></span>
|
||||
<?php echo esc_attr__( 'Installed Themes', 'deployer-for-git' ); ?> (<?php echo count( $theme_list ); ?>)
|
||||
</h3>
|
||||
|
||||
<?php if ( empty( $theme_list ) ) : ?>
|
||||
<?php
|
||||
$theme_istall_page_url = \DeployerForGit\Helper::install_theme_url();
|
||||
?>
|
||||
<div><?php echo esc_attr__( 'No themes installed yet... Go and install one.', 'deployer-for-git' ); ?></div>
|
||||
<div class="dfg_mt_10" >
|
||||
<a href="<?php echo esc_url( $theme_istall_page_url ); ?>" class="button">
|
||||
<?php echo esc_attr__( 'Install Theme', 'deployer-for-git' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="dfg_package_boxes">
|
||||
<?php foreach ( $theme_list as $theme_info ) : ?>
|
||||
<?php $endpoint_url = PackageUpdate::package_update_url( $theme_info['slug'], 'theme' ); ?>
|
||||
<div class="dfg_package_box">
|
||||
<div>
|
||||
<h3>
|
||||
<?php
|
||||
$provider_logo_url = plugin_dir_url( DFG_FILE ) . 'assets/img/' . $theme_info['provider'] . '-logo.svg';
|
||||
?>
|
||||
<img src="<?php echo esc_url( $provider_logo_url ); ?>" alt="<?php echo esc_attr( DeployerForGit\Helper::available_providers()[ $theme_info['provider'] ] ); ?>" >
|
||||
<?php echo esc_attr( $theme_info['slug'] ); ?>
|
||||
<?php if ( $theme_info['is_private_repository'] ) : ?>
|
||||
<i class="dashicons dashicons-lock" title="<?php echo esc_attr__( 'Private Repo', 'deployer-for-git' ); ?>"></i>
|
||||
<?php else : ?>
|
||||
<i class="dashicons dashicons-unlock" title="<?php echo esc_attr__( 'Public Repo', 'deployer-for-git' ); ?>"></i>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
$current_theme = wp_get_theme();
|
||||
if ( $current_theme->get_template() === $theme_info['slug'] ) :
|
||||
?>
|
||||
| <span><?php echo esc_attr__( 'Active', 'deployer-for-git' ); ?></span>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</h3>
|
||||
<ul>
|
||||
<li>
|
||||
<?php echo esc_attr__( 'Branch', 'deployer-for-git' ); ?>
|
||||
<i class="dashicons dashicons-randomize" title="<?php echo esc_attr__( 'Branch', 'deployer-for-git' ); ?>"></i>:
|
||||
<code><?php echo esc_attr( $theme_info['branch'] ); ?></code>
|
||||
</li>
|
||||
<li>
|
||||
<pre style="white-space: normal;"><?php echo esc_attr( $theme_info['repo_url'] ); ?></pre>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" data-show-ptd-btn >
|
||||
<?php echo esc_attr__( '» Show Push-to-Deploy URL', 'deployer-for-git' ); ?>
|
||||
</a>
|
||||
<div class="dfg_package_box_action">
|
||||
<input type="url" disabled value="<?php echo esc_url( $endpoint_url ); ?>">
|
||||
<a data-copy-url-btn="<?php echo esc_url( $endpoint_url ); ?>" class="button" href="#" aria-label="<?php echo esc_attr__( 'Copy URL', 'deployer-for-git' ); ?>">
|
||||
<span class="dashicons dashicons-admin-page"></span>
|
||||
<span class="text" ><?php echo esc_attr__( 'Copy URL', 'deployer-for-git' ); ?></span>
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="dfg_package_box_buttons" >
|
||||
<button data-package-type="theme"
|
||||
data-trigger-ptd-btn="<?php echo esc_url( $endpoint_url ); ?>"
|
||||
title="<?php echo esc_attr__( 'Remove', 'deployer-for-git' ); ?>"
|
||||
class="button button-primary update-package-btn" >
|
||||
<span class="dashicons dashicons-update"></span>
|
||||
<span class="text" ><?php echo esc_attr__( 'Update Theme', 'deployer-for-git' ); ?></span>
|
||||
</button>
|
||||
|
||||
<?php
|
||||
$themes_url = is_multisite() ? network_admin_url( 'themes.php' ) : admin_url( 'themes.php' );
|
||||
$theme_url = add_query_arg( 'theme', $theme_info['slug'], $themes_url );
|
||||
?>
|
||||
<a href="<?php echo esc_url( $theme_url ); ?>"
|
||||
title="<?php echo esc_attr__( 'Remove', 'deployer-for-git' ); ?>"
|
||||
class="delete-theme button" ><span class="dashicons dashicons-trash"></span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$theme_list = $data_manager->get_theme_list();
|
||||
$plugin_list = $data_manager->get_plugin_list();
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_attr__( 'Dashboard', 'deployer-for-git' ); ?></h1>
|
||||
|
||||
<?php require_once 'partials/_themes.php'; ?>
|
||||
<hr>
|
||||
<?php require_once 'partials/_plugins.php'; ?>
|
||||
</div>
|
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
|
||||
namespace DeployerForGit\Subpages;
|
||||
|
||||
use DeployerForGit\DataManager ;
|
||||
use DeployerForGit\Logger ;
|
||||
use DeployerForGit\Helper ;
|
||||
/**
|
||||
* Class InstallPackage
|
||||
*
|
||||
* @package Wp_Git_Deployer
|
||||
*/
|
||||
class InstallPackage
|
||||
{
|
||||
/**
|
||||
* Init package menu hook.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
add_action( ( is_multisite() ? 'network_admin_menu' : 'admin_menu' ), array( $this, 'init_menu' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the menu.
|
||||
*/
|
||||
public function init_menu()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the package installation form.
|
||||
*/
|
||||
private function validate_install_package_form()
|
||||
{
|
||||
if ( !isset( $_POST[DFG_SLUG . '_install_package_submitted'] ) ) {
|
||||
return;
|
||||
}
|
||||
// Vefiry form nonce.
|
||||
$nonce = ( isset( $_POST[DFG_SLUG . '_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST[DFG_SLUG . '_nonce'] ) ) : '' );
|
||||
if ( !wp_verify_nonce( $nonce, DFG_SLUG . '_install_package_form' ) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Invalid nonce', 'deployer-for-git' ) );
|
||||
}
|
||||
$provider_type = ( isset( $_POST['provider_type'] ) ? sanitize_text_field( wp_unslash( $_POST['provider_type'] ) ) : '' );
|
||||
// Check if provider type is valid.
|
||||
if ( !in_array( $provider_type, array_keys( Helper::available_providers() ), true ) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Invalid provider type', 'deployer-for-git' ) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the package installation form.
|
||||
*
|
||||
* @return WP_Error|bool Returns WP_Error object for failure or true for success.
|
||||
*/
|
||||
public function handle_package_install_form()
|
||||
{
|
||||
// Validate form.
|
||||
$validation_result = $this->validate_install_package_form();
|
||||
if ( $validation_result !== true ) {
|
||||
return $validation_result;
|
||||
}
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
// Sanitize form data.
|
||||
$package_type = ( isset( $_POST['package_type'] ) ? sanitize_text_field( wp_unslash( $_POST['package_type'] ) ) : '' );
|
||||
$package_type = ( $package_type === 'plugin' ? 'plugin' : 'theme' );
|
||||
$provider_type = ( isset( $_POST['provider_type'] ) ? sanitize_text_field( wp_unslash( $_POST['provider_type'] ) ) : '' );
|
||||
$branch = ( isset( $_POST['repository_branch'] ) && !empty($_POST['repository_branch']) ? sanitize_text_field( wp_unslash( $_POST['repository_branch'] ) ) : 'master' );
|
||||
$repository_url = ( isset( $_POST['repository_url'] ) ? esc_url_raw( wp_unslash( $_POST['repository_url'] ) ) : '' );
|
||||
$is_private_repository = isset( $_POST['is_private_repository'] );
|
||||
$username = ( isset( $_POST['username'] ) ? sanitize_text_field( wp_unslash( $_POST['username'] ) ) : '' );
|
||||
$password = ( isset( $_POST['password'] ) ? sanitize_text_field( wp_unslash( $_POST['password'] ) ) : '' );
|
||||
$access_token = ( isset( $_POST['access_token'] ) ? sanitize_text_field( wp_unslash( $_POST['access_token'] ) ) : '' );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
$package_install_options = array();
|
||||
if ( $is_private_repository ) {
|
||||
$package_install_options = array(
|
||||
'is_private_repository' => true,
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'access_token' => $access_token,
|
||||
);
|
||||
}
|
||||
$provider_class_name = Helper::get_provider_class( $provider_type );
|
||||
$logger = new Logger();
|
||||
try {
|
||||
$provider = new $provider_class_name( $repository_url );
|
||||
$package_slug = $provider->get_package_slug();
|
||||
$package_zip_url = $provider->get_zip_repo_url( $branch );
|
||||
$install_result = self::install_package_from_zip_url(
|
||||
$package_zip_url,
|
||||
$package_slug,
|
||||
$package_type,
|
||||
$provider_type,
|
||||
$package_install_options
|
||||
);
|
||||
// TODO: maybe move this piece to a method?
|
||||
|
||||
if ( $install_result === true ) {
|
||||
$data_manager = new DataManager();
|
||||
$package_data = array(
|
||||
'slug' => $package_slug,
|
||||
'repo_url' => $repository_url,
|
||||
'branch' => $branch,
|
||||
'provider' => $provider_type,
|
||||
'is_private_repository' => $is_private_repository,
|
||||
'options' => array(
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'access_token' => $access_token,
|
||||
),
|
||||
);
|
||||
$data_manager->store_package_details( $package_data, $package_type );
|
||||
$logger->log( "Package ({$package_type}) \"{$package_slug}\" successfully updated or installed via wp-admin" );
|
||||
} else {
|
||||
$logger->log( "Error occured while installing a {$package_type} \"{$package_slug}\" via wp-admin \"{$install_result->get_error_message()}\"" );
|
||||
}
|
||||
|
||||
} catch ( \Exception $e ) {
|
||||
// Invalid repository URL.
|
||||
$install_result = new \WP_Error( 'invalid', $e->getMessage() );
|
||||
$logger->log( "Error occured while installing a package via wp-admin \"{$e->getMessage()}\"" );
|
||||
}
|
||||
$success = $install_result === true;
|
||||
do_action( 'dfg_after_package_install', $success );
|
||||
return $install_result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the page.
|
||||
*/
|
||||
public function init_page()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the request is a WP JSON request.
|
||||
*
|
||||
* @param array $options Additional options for the installation.
|
||||
*/
|
||||
private static function is_wp_json_request( $options = array() )
|
||||
{
|
||||
return array_key_exists( 'wp_json_request', $options ) && $options['wp_json_request'] === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current user can proceed with the installation.
|
||||
*
|
||||
* @param string $package_type Type of the package (theme|plugin).
|
||||
*/
|
||||
private static function current_user_can_proceed( $package_type )
|
||||
{
|
||||
$type_in_plural = "{$package_type}s";
|
||||
return current_user_can( "install_{$type_in_plural}" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a package from a zip file URL.
|
||||
*
|
||||
* @param string $package_zip_url The URL of the package zip file.
|
||||
* @param string $package_slug The slug of the package.
|
||||
* @param string $type Type of the package (theme|plugin).
|
||||
* @param string $provider_type Type of the provider (bitbucket|github|gitlab|gitea).
|
||||
* @param array $options Additional options for the installation.
|
||||
*
|
||||
* @return WP_Error|bool Returns WP_Error object for failure or true for success.
|
||||
*/
|
||||
public static function install_package_from_zip_url(
|
||||
$package_zip_url,
|
||||
$package_slug,
|
||||
$type,
|
||||
$provider_type,
|
||||
$options = array()
|
||||
)
|
||||
{
|
||||
if ( empty($provider_type) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Provider does not exist.', 'deployer-for-git' ) );
|
||||
}
|
||||
// Check if provider type is valid.
|
||||
if ( !in_array( $provider_type, array_keys( Helper::available_providers() ), true ) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Invalid provider type', 'deployer-for-git' ) );
|
||||
}
|
||||
$type = ( $type === 'theme' ? 'theme' : 'plugin' );
|
||||
// Check for empty URL and slug.
|
||||
if ( empty($package_zip_url) || empty($package_slug) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Package zip URL and package slug must exist', 'deployer-for-git' ) );
|
||||
}
|
||||
$is_wp_json_request = self::is_wp_json_request( $options );
|
||||
// Check user capabilities.
|
||||
if ( !self::current_user_can_proceed( $type ) && !$is_wp_json_request ) {
|
||||
return new \WP_Error( 'invalid', __( 'User should have enough permissions', 'deployer-for-git' ) );
|
||||
}
|
||||
// Initialize WordPress filesystem.
|
||||
if ( !function_exists( 'WP_Filesystem' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
}
|
||||
WP_Filesystem();
|
||||
// load file which loads most of the classes needed for package installation.
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
// Set up package installation parameters.
|
||||
|
||||
if ( $type === 'theme' ) {
|
||||
$package_destination_dir = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $package_slug;
|
||||
$skin = new \DeployerForGit\ThemeInstallerSkin();
|
||||
// Create a new instance of the Theme_Upgrader class.
|
||||
$package_upgrader = new \Theme_Upgrader( $skin );
|
||||
} else {
|
||||
$package_destination_dir = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $package_slug;
|
||||
$skin = new \DeployerForGit\PluginInstallerSkin();
|
||||
// Create a new instance of the Plugin_Upgrader class.
|
||||
$package_upgrader = new \Plugin_Upgrader( $skin );
|
||||
}
|
||||
|
||||
// Set upgrader arguments.
|
||||
$package_upgrader->generic_strings();
|
||||
// Run the package installation.
|
||||
$result = $package_upgrader->run( array(
|
||||
'package' => $package_zip_url,
|
||||
'destination' => $package_destination_dir,
|
||||
'clear_destination' => true,
|
||||
'clear_working' => true,
|
||||
'hook_extra' => array(
|
||||
'type' => $type,
|
||||
'action' => 'install',
|
||||
),
|
||||
) );
|
||||
$package_upgrader->maintenance_mode( false );
|
||||
|
||||
if ( $result === false ) {
|
||||
return new \WP_Error( 'invalid', __( 'Some error occurred', 'deployer-for-git' ) );
|
||||
} elseif ( is_wp_error( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace DeployerForGit\Subpages\InstallPluginPage;
|
||||
|
||||
use DeployerForGit\Subpages\InstallPackage;
|
||||
|
||||
/**
|
||||
* Class InstallPlugin
|
||||
*
|
||||
* @package DeployerForGit\Subpages\InstallPluginPage
|
||||
*/
|
||||
class InstallPlugin extends InstallPackage {
|
||||
|
||||
/**
|
||||
* Initializes the menu.
|
||||
*/
|
||||
public function init_menu() {
|
||||
$menu_slug = \DeployerForGit\Helper::menu_slug();
|
||||
$page_title = esc_attr__( 'Install Plugin', 'deployer-for-git' );
|
||||
$capability = is_multisite() ? 'manage_network_options' : 'manage_options';
|
||||
|
||||
add_submenu_page(
|
||||
$menu_slug,
|
||||
$page_title,
|
||||
$page_title,
|
||||
$capability,
|
||||
"{$menu_slug}-install-plugin",
|
||||
array( $this, 'init_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a plugin from a zip file.
|
||||
*
|
||||
* @param string $package_zip_url The URL of the zip file.
|
||||
* @param string $package_slug The slug of the package.
|
||||
* @param string $package_provider The provider of the package (github, bitbucket, gitlab, gitea).
|
||||
* @param array $options The options.
|
||||
* @return WP_Error|bool Returns WP_Error object for failure or true for success.
|
||||
*/
|
||||
public static function install_plugin_from_zip_url( $package_zip_url, $package_slug, $package_provider, $options = array() ) {
|
||||
return parent::install_package_from_zip_url( $package_zip_url, $package_slug, 'plugin', $package_provider, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the page.
|
||||
*/
|
||||
public function init_page() {
|
||||
// Handle package installation form.
|
||||
$install_result = parent::handle_package_install_form();
|
||||
|
||||
include_once __DIR__ . '/template.php';
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
if ( !defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
if ( isset( $install_result ) ) {
|
||||
?>
|
||||
<?php
|
||||
|
||||
if ( !is_wp_error( $install_result ) ) {
|
||||
?>
|
||||
<div class="updated">
|
||||
<p>
|
||||
<?php
|
||||
echo esc_attr__( 'Plugin was successfully installed', 'deployer-for-git' ) ;
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div class="error">
|
||||
<p>
|
||||
<!-- <strong><?php
|
||||
echo esc_attr( $install_result->get_error_code() ) ;
|
||||
?></strong> -->
|
||||
<?php
|
||||
echo esc_attr( $install_result->get_error_message() ) ;
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1><?php
|
||||
echo esc_attr__( 'Install Plugin', 'deployer-for-git' ) ;
|
||||
?></h1>
|
||||
<form class="dfg_install_package_form" method="post" action="">
|
||||
<input type="hidden" name="<?php
|
||||
echo esc_attr( DFG_SLUG . '_install_package_submitted' ) ;
|
||||
?>" value="1">
|
||||
<input type="hidden" name="package_type" value="plugin">
|
||||
|
||||
<?php
|
||||
wp_nonce_field( DFG_SLUG . '_install_package_form', DFG_SLUG . '_nonce' );
|
||||
?>
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<?php
|
||||
echo esc_attr__( 'Provider Type', 'deployer-for-git' ) ;
|
||||
?>
|
||||
</th>
|
||||
<td>
|
||||
<select name='provider_type'>
|
||||
<option value="" selected disabled><?php
|
||||
echo esc_attr__( 'Choose a provider', 'deployer-for-git' ) ;
|
||||
?></option>
|
||||
<?php
|
||||
foreach ( \DeployerForGit\Helper::available_providers() as $provider_id => $name ) {
|
||||
?>
|
||||
<option value="<?php
|
||||
echo esc_attr( $provider_id ) ;
|
||||
?>"><?php
|
||||
echo esc_attr( $name ) ;
|
||||
?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php
|
||||
echo esc_attr__( 'Repository URL', 'deployer-for-git' ) ;
|
||||
?></th>
|
||||
<td>
|
||||
<input type="url" class="regular-text code" name="repository_url" value="" />
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="bitbucket-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://bitbucket.org/owner/wordpress-plugin-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="github-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://github.com/owner/wordpress-plugin-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="gitea-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://gitea.com/owner/wordpress-plugin-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php
|
||||
echo esc_attr__( 'Branch', 'deployer-for-git' ) ;
|
||||
?> <span class="dashicons dashicons-randomize"></span></th>
|
||||
<td>
|
||||
<input type="text" class="" placeholder="master" name="repository_branch" value="" />
|
||||
<p class="description"><?php
|
||||
echo esc_attr__( 'default is "master"', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
$private_repository_row_class = 'free';
|
||||
?>
|
||||
|
||||
<tr valign="top" class="dfg_hidden dfg_is_private_repository_row <?php
|
||||
echo esc_attr( $private_repository_row_class ) ;
|
||||
?>">
|
||||
<th scope="row">
|
||||
<?php
|
||||
echo esc_attr__( 'Is Private Repository', 'deployer-for-git' ) ;
|
||||
?>
|
||||
|
||||
<?php
|
||||
?>
|
||||
<br>
|
||||
<small><?php
|
||||
echo esc_attr__( '[Available in PRO version]', 'deployer-for-git' ) ;
|
||||
?></small>
|
||||
<?php
|
||||
?>
|
||||
|
||||
<span class="dashicons dashicons-lock"></span>
|
||||
</th>
|
||||
<td><input type="checkbox" name="is_private_repository" value="1"></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
?>
|
||||
</table>
|
||||
<div class="submit">
|
||||
<input type="submit" class="button-primary" value="<?php
|
||||
echo esc_attr__( 'Install Plugin', 'deployer-for-git' ) ;
|
||||
?>" /><br><br>
|
||||
<p class="description"><i><?php
|
||||
echo esc_attr__( 'Note that if a plugin with specified slug is already installed, this action will overwrite the already existing plugin.', 'deployer-for-git' ) ;
|
||||
?><i></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace DeployerForGit\Subpages\InstallThemePage;
|
||||
|
||||
use DeployerForGit\DataManager;
|
||||
use DeployerForGit\Logger;
|
||||
use DeployerForGit\Subpages\InstallPackage;
|
||||
|
||||
/**
|
||||
* Class InstallTheme
|
||||
*
|
||||
* @package DeployerForGit\Subpages\InstallThemePage
|
||||
*/
|
||||
class InstallTheme extends InstallPackage {
|
||||
|
||||
/**
|
||||
* Initializes the menu.
|
||||
*/
|
||||
public function init_menu() {
|
||||
$menu_slug = \DeployerForGit\Helper::menu_slug();
|
||||
$page_title = esc_attr__( 'Install Theme', 'deployer-for-git' );
|
||||
$capability = is_multisite() ? 'manage_network_options' : 'manage_options';
|
||||
|
||||
add_submenu_page(
|
||||
$menu_slug,
|
||||
$page_title,
|
||||
$page_title,
|
||||
$capability,
|
||||
"{$menu_slug}-install-theme",
|
||||
array( $this, 'init_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a theme from a zip file.
|
||||
*
|
||||
* @param string $package_zip_url The URL of the zip file.
|
||||
* @param string $package_slug The slug of the package.
|
||||
* @param string $package_provider The provider of the package (github|bitbucket|gitlab|gitea).
|
||||
* @param array $options The options.
|
||||
* @return WP_Error|bool Returns WP_Error object for failure or true for success.
|
||||
*/
|
||||
public static function install_theme_from_zip_url( $package_zip_url, $package_slug, $package_provider, $options = array() ) {
|
||||
return parent::install_package_from_zip_url( $package_zip_url, $package_slug, 'theme', $package_provider, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the page.
|
||||
*/
|
||||
public function init_page() {
|
||||
// Handle package installation form.
|
||||
$install_result = parent::handle_package_install_form();
|
||||
|
||||
include_once __DIR__ . '/template.php';
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
use DeployerForGit\Helper ;
|
||||
if ( !defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( isset( $install_result ) ) {
|
||||
?>
|
||||
<?php
|
||||
|
||||
if ( !is_wp_error( $install_result ) ) {
|
||||
?>
|
||||
<div class="updated">
|
||||
<p>
|
||||
<?php
|
||||
echo esc_attr__( 'Theme was successfully installed', 'deployer-for-git' ) ;
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div class="error">
|
||||
<p>
|
||||
<!-- <strong><?php
|
||||
echo esc_attr( $install_result->get_error_code() ) ;
|
||||
?></strong> -->
|
||||
<?php
|
||||
echo esc_attr( $install_result->get_error_message() ) ;
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1><?php
|
||||
echo esc_attr__( 'Install Theme', 'deployer-for-git' ) ;
|
||||
?></h1>
|
||||
<form class="dfg_install_package_form" method="post" action="">
|
||||
<input type="hidden" name="<?php
|
||||
echo esc_attr( DFG_SLUG . '_install_package_submitted' ) ;
|
||||
?>" value="1">
|
||||
<input type="hidden" name="package_type" value="theme">
|
||||
|
||||
<?php
|
||||
wp_nonce_field( DFG_SLUG . '_install_package_form', DFG_SLUG . '_nonce' );
|
||||
?>
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php
|
||||
echo esc_attr__( 'Provider Type', 'deployer-for-git' ) ;
|
||||
?></th>
|
||||
<td>
|
||||
<select name='provider_type'>
|
||||
<option value="" selected disabled><?php
|
||||
echo esc_attr__( 'Choose a provider', 'deployer-for-git' ) ;
|
||||
?></option>
|
||||
<?php
|
||||
foreach ( Helper::available_providers() as $provider_id => $name ) {
|
||||
?>
|
||||
<option value="<?php
|
||||
echo esc_attr( $provider_id ) ;
|
||||
?>"><?php
|
||||
echo esc_attr( $name ) ;
|
||||
?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php
|
||||
echo esc_attr__( 'Repository URL', 'deployer-for-git' ) ;
|
||||
?></th>
|
||||
<td>
|
||||
<input type="url" class="regular-text code" name="repository_url" value="" />
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="bitbucket-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://bitbucket.org/owner/wordpress-theme-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="github-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://github.com/owner/wordpress-theme-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="gitea-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://gitea.com/owner/wordpress-theme-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="gitlab-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://gitlab.com/owner/wordpress-theme-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php
|
||||
echo esc_attr__( 'Branch', 'deployer-for-git' ) ;
|
||||
?> <span class="dashicons dashicons-randomize"></span></th>
|
||||
<td>
|
||||
<input type="text" class="" placeholder="master" name="repository_branch" value="" />
|
||||
<p class="description"><?php
|
||||
echo esc_attr__( 'default is "master"', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
$private_repository_row_class = 'free';
|
||||
?>
|
||||
|
||||
<tr valign="top" class="dfg_hidden dfg_is_private_repository_row <?php
|
||||
echo esc_attr( $private_repository_row_class ) ;
|
||||
?>" >
|
||||
<th scope="row">
|
||||
<?php
|
||||
echo esc_attr__( 'Is Private Repository', 'deployer-for-git' ) ;
|
||||
?>
|
||||
|
||||
<?php
|
||||
?>
|
||||
<br>
|
||||
<small><?php
|
||||
echo esc_attr__( '[Available in PRO version]', 'deployer-for-git' ) ;
|
||||
?></small>
|
||||
<?php
|
||||
?>
|
||||
|
||||
<span class="dashicons dashicons-lock"></span>
|
||||
</th>
|
||||
<td><input type="checkbox" name="is_private_repository" value="1"></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
?>
|
||||
</table>
|
||||
<div class="submit">
|
||||
<input type="submit" class="button-primary" value="<?php
|
||||
echo esc_attr__( 'Install Theme', 'deployer-for-git' ) ;
|
||||
?>" /><br><br>
|
||||
<p class="description"><i><?php
|
||||
echo esc_attr__( 'Note that if a theme with specified slug is already installed, this action will overwrite the already existing theme.', 'deployer-for-git' ) ;
|
||||
?><i></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace DeployerForGit\Subpages\LogsPage;
|
||||
|
||||
use DeployerForGit\DataManager;
|
||||
use DeployerForGit\Logger;
|
||||
|
||||
/**
|
||||
* Logs page
|
||||
*/
|
||||
class Logs {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'init_menu' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize menu
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init_menu() {
|
||||
$menu_slug = \DeployerForGit\Helper::menu_slug();
|
||||
$capability = is_multisite() ? 'manage_network_options' : 'manage_options';
|
||||
|
||||
add_submenu_page(
|
||||
$menu_slug,
|
||||
esc_attr__( 'Logs', 'deployer-for-git' ),
|
||||
esc_attr__( 'Logs', 'deployer-for-git' ),
|
||||
$capability,
|
||||
"{$menu_slug}-logs",
|
||||
array( $this, 'init_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init_page() {
|
||||
$data_manager = new DataManager();
|
||||
$this->handle_clear_log_form();
|
||||
|
||||
include_once __DIR__ . '/template.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle clear log form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle_clear_log_form() {
|
||||
$form_submitted = false;
|
||||
|
||||
if ( isset( $_POST[ DFG_SLUG . '_nonce' ] ) && wp_verify_nonce( ( sanitize_text_field( wp_unslash( $_POST[ DFG_SLUG . '_nonce' ] ) ) ), DFG_SLUG . '_clear_log_file' ) ) {
|
||||
$logger = new Logger();
|
||||
$clear_log_result = $logger->clear_log_file();
|
||||
$form_submitted = true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
use DeployerForGit\Logger;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>
|
||||
<?php echo esc_attr__( 'Logs', 'deployer-for-git' ); ?>
|
||||
</h1>
|
||||
|
||||
<?php if ( isset( $form_submitted ) && $form_submitted ) : ?>
|
||||
<?php if ( isset( $clear_log_result ) && $clear_log_result ) : ?>
|
||||
<div class="updated">
|
||||
<p><?php echo esc_attr__( 'Log file cleared', 'deployer-for-git' ); ?></p>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="error">
|
||||
<p><?php echo esc_attr__( 'Can\'t clear the log file.', 'deployer-for-git' ); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $logger = new Logger(); ?>
|
||||
<textarea class="large-text code dfg_log_textarea" readonly><?php echo esc_textarea( $logger->display_log_content() ); ?></textarea>
|
||||
|
||||
<form method="post" action="" onsubmit="return confirm('<?php echo esc_attr__( 'Are you sure?', 'deployer-for-git' ); ?>');">
|
||||
<input type="hidden" name="action" value="clear_log_file">
|
||||
<?php wp_nonce_field( DFG_SLUG . '_clear_log_file', DFG_SLUG . '_nonce' ); ?>
|
||||
<input type="submit" class="button button-primary" value="<?php echo esc_attr__( 'Clear log file', 'deployer-for-git' ); ?>">
|
||||
</form>
|
||||
</div>
|
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
namespace DeployerForGit\Subpages\MiscellaneousPage;
|
||||
|
||||
use DeployerForGit\DataManager;
|
||||
use DeployerForGit\Helper;
|
||||
|
||||
/**
|
||||
* Miscellaneous page
|
||||
*/
|
||||
class Miscellaneous {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'init_menu' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize menu
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init_menu() {
|
||||
$menu_slug = Helper::menu_slug();
|
||||
$capability = is_multisite() ? 'manage_network_options' : 'manage_options';
|
||||
|
||||
add_submenu_page(
|
||||
$menu_slug,
|
||||
esc_attr__( 'Miscellaneous', 'deployer-for-git' ),
|
||||
esc_attr__( 'Miscellaneous', 'deployer-for-git' ),
|
||||
$capability,
|
||||
"{$menu_slug}-miscellaneous",
|
||||
array( $this, 'init_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init_page() {
|
||||
$regenerate_secret_key_result = $this->handle_regenerate_secret_key_form();
|
||||
$flush_cache_result = $this->handle_flush_cache_form();
|
||||
$alert_notification_result = $this->handle_alert_notification_form();
|
||||
$data_manager = new DataManager();
|
||||
|
||||
include_once __DIR__ . '/template.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle regenerate secret key form
|
||||
*
|
||||
* @return boolean|null
|
||||
*/
|
||||
public function handle_regenerate_secret_key_form() {
|
||||
$result = null;
|
||||
|
||||
if ( isset( $_POST['action'] ) && $_POST['action'] === 'regenerate_secret_key' ) {
|
||||
$result = false;
|
||||
|
||||
if ( isset( $_POST[ DFG_SLUG . '_nonce' ] ) || wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST[ DFG_SLUG . '_nonce' ] ) ), DFG_SLUG . '_regenerate_secret_key' ) ) {
|
||||
$result = true;
|
||||
Helper::generate_api_secret();
|
||||
|
||||
do_action( 'dfg_after_secret_key_regenerate' );
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle flush cache form
|
||||
*
|
||||
* @return boolean|null
|
||||
*/
|
||||
public function handle_flush_cache_form() {
|
||||
$result = null;
|
||||
|
||||
if ( isset( $_POST['action'] ) && $_POST['action'] === 'flush_cache' ) {
|
||||
$result = false;
|
||||
|
||||
if ( isset( $_POST[ DFG_SLUG . '_nonce' ] ) || wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST[ DFG_SLUG . '_nonce' ] ) ), DFG_SLUG . '_flush_cache' ) ) {
|
||||
$data_manager = new DataManager();
|
||||
|
||||
$result = $data_manager->update_flush_cache_setting( isset( $_POST['flush_cache_setting'] ) );
|
||||
|
||||
do_action( 'dfg_after_flush_cache_setting_update' );
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle alert notification form
|
||||
*
|
||||
* @return boolean|null
|
||||
*/
|
||||
public function handle_alert_notification_form() {
|
||||
$result = null;
|
||||
|
||||
if ( isset( $_POST['action'] ) && $_POST['action'] === 'alert_notification' ) {
|
||||
$result = false;
|
||||
|
||||
if ( isset( $_POST[ DFG_SLUG . '_nonce' ] ) || wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST[ DFG_SLUG . '_nonce' ] ) ), DFG_SLUG . '_alert_notification' ) ) {
|
||||
$data_manager = new DataManager();
|
||||
|
||||
$result = $data_manager->update_alert_notification_setting( isset( $_POST['alert_notification_setting'] ) );
|
||||
|
||||
do_action( 'dfg_after_alert_notification_setting_update' );
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
use DeployerForGit\Helper;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1>
|
||||
<?php echo esc_attr__( 'Miscellaneous', 'deployer-for-git' ); ?>
|
||||
</h1>
|
||||
|
||||
<?php
|
||||
if ( isset( $regenerate_secret_key_result ) && $regenerate_secret_key_result !== null ) {
|
||||
if ( $regenerate_secret_key_result === false ) {
|
||||
echo '<div class="notice notice-error is-dismissible"><p>' . esc_attr__( 'Error while regenerating secret key.', 'deployer-for-git' ) . '</p></div>';
|
||||
} else {
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_attr__( 'Secret key has been successfully regenerated.', 'deployer-for-git' ) . '</p></div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
if ( isset( $flush_cache_result ) && $flush_cache_result !== null ) {
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_attr__( 'Cache setting has been updated.', 'deployer-for-git' ) . '</p></div>';
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
if ( isset( $alert_notification_result ) && $alert_notification_result !== null ) {
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_attr__( 'Alert notification setting has been updated.', 'deployer-for-git' ) . '</p></div>';
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="dfg_form_box">
|
||||
<h3><span class="dashicons dashicons-admin-network"></span> <?php echo esc_attr__( 'Secret Key management', 'deployer-for-git' ); ?></h3>
|
||||
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<?php echo esc_attr__( 'Current secret key:', 'deployer-for-git' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<span><?php echo esc_attr( Helper::get_api_secret() ); ?></span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<form method="post" action="" onsubmit="return confirm( '<?php echo esc_attr__( 'Are you sure?', 'deployer-for-git' ); ?>' );">
|
||||
<input type="hidden" name="action" value="regenerate_secret_key">
|
||||
<?php wp_nonce_field( DFG_SLUG . '_regenerate_secret_key', DFG_SLUG . '_nonce' ); ?>
|
||||
|
||||
<input type="submit" class="button button-primary" value="<?php echo esc_attr__( 'Regenerate Secret Key', 'deployer-for-git' ); ?>">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="dfg_form_box">
|
||||
<h3><span class="dashicons dashicons-database"></span> <?php echo esc_attr__( 'Flush cache', 'deployer-for-git' ); ?></h3>
|
||||
|
||||
<p class="description">
|
||||
<?php echo esc_attr__( 'Activate this option if you want the plugin to clear the cache every time the package update link is triggered. We support next list of plugins:', 'deployer-for-git' ); ?>
|
||||
<ul>
|
||||
<li>
|
||||
WP Rocket |
|
||||
<?php if ( Helper::wp_rocket_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<li>
|
||||
WP-Optimize |
|
||||
<?php if ( Helper::wp_optimize_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<li>W3 Total Cache |
|
||||
<?php if ( Helper::w3tc_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<li>
|
||||
LiteSpeed Cache |
|
||||
<?php if ( Helper::litespeed_cache_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<li>
|
||||
WP Super Cache |
|
||||
<?php if ( Helper::wp_super_cache_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<li>
|
||||
WP Fastest Cache |
|
||||
<?php if ( Helper::wp_fastest_cache_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<li>
|
||||
Autoptimize |
|
||||
<?php if ( Helper::autoptimize_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<form method="post" action="">
|
||||
<input type="hidden" name="action" value="flush_cache">
|
||||
<?php wp_nonce_field( DFG_SLUG . '_flush_cache', DFG_SLUG . '_nonce' ); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<?php echo esc_attr__( 'Enable', 'deployer-for-git' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<input type="checkbox" name="flush_cache_setting" <?php echo $data_manager->get_flush_cache_setting() === true ? 'checked' : ''; ?> value="1">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p class="submit">
|
||||
<input type="submit" class="button-primary" value="<?php echo esc_attr__( 'Save Caching Settings', 'deployer-for-git' ); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="dfg_form_box">
|
||||
<h3><span class="dashicons dashicons-feedback"></span> <?php echo esc_attr__( 'Alert notification', 'deployer-for-git' ); ?></h3>
|
||||
|
||||
<p class="description">
|
||||
<?php echo esc_attr__( 'Enable this option if you wish to display a notification message at the top of WordPress Admin interface (/wp-admin). The message is intended for developers, reminding them not to make any changes to the theme or plugin directly on this site, but rather use Git for such modifications.', 'deployer-for-git' ); ?>
|
||||
</p>
|
||||
|
||||
<form method="post" action="">
|
||||
<input type="hidden" name="action" value="alert_notification">
|
||||
<?php wp_nonce_field( DFG_SLUG . '_alert_notification', DFG_SLUG . '_nonce' ); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<?php echo esc_attr__( 'Enable', 'deployer-for-git' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<input type="checkbox" name="alert_notification_setting" <?php echo $data_manager->get_alert_notification_setting() === true ? 'checked' : ''; ?> value="1">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p class="submit">
|
||||
<input type="submit" class="button-primary" value="<?php echo esc_attr__( 'Save Alert Notification Settings', 'deployer-for-git' ); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace DeployerForGit;
|
||||
|
||||
if ( ! class_exists( 'WP_Upgrader_Skin' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php';
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Theme_Installer_Skin' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-theme-installer-skin.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Class ThemeInstallerSkin
|
||||
*
|
||||
* @package DeployerForGit
|
||||
*/
|
||||
class ThemeInstallerSkin extends \Theme_Installer_Skin {
|
||||
|
||||
/**
|
||||
* Override header method with empty function.
|
||||
*/
|
||||
public function header() {}
|
||||
|
||||
/**
|
||||
* Override footer method with empty function.
|
||||
*/
|
||||
public function footer() {}
|
||||
|
||||
/**
|
||||
* Override feedback method with empty function.
|
||||
*
|
||||
* @param string $feedback Message data.
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
*/
|
||||
public function feedback( $feedback, ...$args ) {}
|
||||
|
||||
/**
|
||||
* Override error method with empty function.
|
||||
*
|
||||
* @param string|WP_Error $errors Errors.
|
||||
*/
|
||||
public function error( $errors ) {}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace DeployerForGit;
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php';
|
||||
|
||||
/**
|
||||
* Class WPUpgraderSkin
|
||||
*
|
||||
* @package DeployerForGit
|
||||
*/
|
||||
class WPUpgraderSkin extends \WP_Upgrader_Skin {
|
||||
|
||||
/**
|
||||
* Override feedback method with empty function.
|
||||
*
|
||||
* @param string $feedback Message data.
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
*/
|
||||
public function feedback( $feedback, ...$args ) {}
|
||||
}
|
1
wp-content/plugins/deployer-for-git/includes/index.php
Normal file
1
wp-content/plugins/deployer-for-git/includes/index.php
Normal file
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
Reference in New Issue
Block a user