first commit

This commit is contained in:
2025-02-24 22:33:42 +01:00
commit 737c037e85
18358 changed files with 5392983 additions and 0 deletions

View File

@@ -0,0 +1,288 @@
<?php
defined("ABSPATH") or die("");
/**
* Used to generate a thick box inline dialog such as an alert or confirm pop-up
*
* Standard: PSR-2
*
* @link http://www.php-fig.org/psr/psr-2
*
* @package DUP_PRO
* @subpackage classes/ui
* @copyright (c) 2017, Snapcreek LLC
* @license https://opensource.org/licenses/GPL-3.0 GNU Public License
* @since 3.3.0
*/
class DUP_PRO_UI_Dialog
{
/** @var int */
protected static $uniqueIdCounter = 0;
/** @var string if not empty contains class of box */
public $boxClass = '';
/** @var bool if false don't disaply ok,confirm and cancel buttons */
public $showButtons = true;
/** @var bool if false don't disaply textarea */
public $showTextArea = false;
/** @var integer rows attribute of textarea */
public $textAreaRows = 15;
/** @var int cols attribute of textarea */
public $textAreaCols = 100;
/** @var string if not empty set class on wrapper buttons div */
public $wrapperClassButtons = null;
/** @var string The title that shows up in the dialog */
public $title = '';
/** @var string The message displayed in the body of the dialog */
public $message = '';
/** @var int The width of the dialog the default is used if not set */
public $width = 500;
/** @var int The height of the dialog the default is used if not set */
public $height = 225;
/** @var string When the progress meter is running show this text, Available only on confirm dialogs */
public $progressText;
/** @var bool When true a progress meter will run until page is reloaded, Available only on confirm dialogs */
public $progressOn = true;
/** @var ?string The javascript call back method to call when the 'Yes' or 'Ok' button is clicked */
public $jsCallback = null;
/** @var string */
public $okText = '';
/** @var string */
public $cancelText = '';
/** @var bool If true close dialog on confirm */
public $closeOnConfirm = false;
/** @var string The id given to the full dialog */
private $id = '';
/** @var int A unique id that is added to all id elements */
private $uniqid = 0;
/**
* Init this object when created
*/
public function __construct()
{
add_thickbox();
$this->progressText = __('Processing please wait...', 'duplicator-pro');
$this->uniqid = ++self::$uniqueIdCounter;
$this->id = 'dpro-dlg-' . $this->uniqid;
$this->okText = __('OK', 'duplicator-pro');
$this->cancelText = __('Cancel', 'duplicator-pro');
}
/**
*
* @return int
*/
public function getUniqueIdCounter()
{
return $this->uniqid;
}
/**
* Gets the unique id that is assigned to each instance of a dialog
*
* @return string The unique ID of this dialog
*/
public function getID()
{
return $this->id;
}
/**
* Gets the unique id that is assigned to each instance of a dialogs message text
*
* @return string The unique ID of the message
*/
public function getMessageID()
{
return "{$this->id}_message";
}
/**
* Display The html content used for the alert dialog
*
* @return void
*/
public function initAlert()
{
?>
<div id="<?php echo $this->id; ?>" style="display:none;" >
<?php if ($this->showTextArea) { ?>
<div class="dpro-dlg-textarea-caption">Status</div>
<textarea id="<?php echo $this->id; ?>_textarea" class="dpro-dlg-textarea" rows="<?php echo $this->textAreaRows; ?>" cols="<?php echo $this->textAreaCols; ?>"></textarea>
<?php } ?>
<div id="<?php echo $this->id; ?>-alert-txt" class="dpro-dlg-alert-txt <?php echo $this->boxClass; ?>" >
<span id="<?php echo $this->id; ?>_message">
<?php echo $this->message; ?>
</span>
</div>
<?php if ($this->showButtons) { ?>
<div class="dpro-dlg-alert-btns <?php echo $this->wrapperClassButtons; ?>" >
<input
id="<?php echo $this->id; ?>-confirm"
type="button"
class="button button-large dup-dialog-confirm"
value="<?php echo esc_attr($this->okText); ?>"
onclick="<?php echo esc_attr($this->closeAlert(false)); ?>"
>
</div>
<?php } ?>
</div>
<?php
}
/**
* Shows the alert base JS code used to display when needed
*
* @return void
*/
public function showAlert()
{
$title = esc_js($this->title);
$id = esc_js($this->id);
$html = "tb_show('" . $title . "', '#TB_inline?width=" . $this->width . "&height=" . $this->height . "&inlineId=" . $id . "');" .
"var styleData = jQuery('#TB_window').attr('style') + 'height: " . $this->height . "px !important';\n" .
"jQuery('#TB_window').attr('style', styleData);" .
"DuplicatorTooltip.reload();";
echo $html;
}
/**
* Close tick box
*
* @param boolean $echo if true echo javascript else return string
*
* @return string
*/
public function closeAlert($echo = true)
{
$onClickClose = '';
if (!is_null($this->jsCallback)) {
$onClickClose .= $this->jsCallback . ';';
}
$onClickClose .= 'tb_remove();';
if ($echo) {
echo $onClickClose;
return '';
} else {
return $onClickClose;
}
}
/**
* js code to update html message content from js var name
*
* @param string $jsVarName js var name
*
* @return void
*/
public function updateMessage($jsVarName)
{
$js = '$("#' . $this->getID() . '_message").html(' . $jsVarName . ');';
echo $js;
}
/**
* js code to update textarea content from js var name
*
* @param string $jsVarName js var name
*
* @return void
*/
public function updateTextareaMessage($jsVarName)
{
$js = '$("#' . $this->getID() . '_textarea").val(' . $jsVarName . ');';
echo $js;
}
/**
* Shows the confirm base JS code used to display when needed
*
* @return void
*/
public function initConfirm()
{
$progress_data = '';
$progress_func2 = '';
$onClickConfirm = '';
if (!is_null($this->jsCallback)) {
$onClickConfirm .= $this->jsCallback . ';';
}
//Enable the progress spinner
if ($this->progressOn) {
$progress_func1 = "__dpro_dialog_" . $this->uniqid;
$progress_func2 = ";{$progress_func1}(this)";
$progress_data = <<<HTML
<div class='dpro-dlg-confirm-progress' id="{$this->id}-progress">
<br/><br/>
<i class='fa fa-circle-notch fa-spin fa-lg fa-fw'></i> {$this->progressText}</div>
<script>
function {$progress_func1}(obj)
{
(function($,obj){
console.log($('#{$this->id}'));
// Set object for reuse
var e = $(obj);
// Check and set progress
if($('#{$this->id}-progress')) $('#{$this->id}-progress').show();
// Check and set confirm button
if($('#{$this->id}-confirm')) $('#{$this->id}-confirm').attr('disabled', 'true');
// Check and set cancel button
if($('#{$this->id}-cancel')) $('#{$this->id}-cancel').attr('disabled', 'true');
}(window.jQuery, obj));
}
</script>
HTML;
$onClickConfirm .= $progress_func2 . ';';
}
if ($this->closeOnConfirm) {
$onClickConfirm .= 'tb_remove();';
} ?>
<div id="<?php echo $this->id; ?>" style="display:none">
<div class="dpro-dlg-confirm-txt" id="<?php echo $this->id; ?>-confirm-txt">
<div id="<?php echo $this->id; ?>_message">
<?php echo $this->message; ?>
</div>
<?php echo $progress_data; ?>
</div>
<?php if ($this->showButtons) { ?>
<div class="dpro-dlg-confirm-btns <?php echo $this->wrapperClassButtons; ?>" >
<input
id="<?php echo $this->id; ?>-confirm"
type="button"
class="button button-large dup-dialog-confirm"
value="<?php echo esc_attr($this->okText); ?>"
onclick="<?php echo esc_attr($onClickConfirm); ?>"
>
<input
id="<?php echo $this->id; ?>-cancel"
type="button"
class="button button-large dup-dialog-cancel"
value="<?php echo esc_attr($this->cancelText); ?>"
onclick="tb_remove();"
>
</div>
<?php } ?>
</div>
<?php
}
/**
* Shows the confirm base JS code used to display when needed
*
* @return void
*/
public function showConfirm()
{
$html = "tb_show('" . esc_js($this->title) . "', '#TB_inline?width=" . $this->width . "&height=" . $this->height . "&inlineId=" . $this->id . "');\n" .
"var styleData = jQuery('#TB_window').attr('style') + 'height: " . $this->height . "px !important';\n" .
"jQuery('#TB_window').attr('style', styleData); DuplicatorTooltip.reload();";
echo $html;
}
}

View File

@@ -0,0 +1,180 @@
<?php
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
/**
* Used to generate a thick box inline dialog such as an alert or confirm pop-up
*
* Standard: PSR-2
*
* @link http://www.php-fig.org/psr/psr-2
*
* @package Duplicator
* @subpackage classes/ui
* @copyright (c) 2017, Snapcreek LLC
*/
use Duplicator\Libs\Snap\SnapJson;
class DUP_PRO_UI_Messages
{
const UNIQUE_ID_PREFIX = 'dup_ui_msg_';
const NOTICE = 'updated';
const WARNING = 'update-nag';
const ERROR = 'error';
/** @var int */
private static $unique_id = 0;
/** @var string */
private $id = '';
/** @var string */
public $type = self::NOTICE;
/** @var string */
public $content = '';
/** @var string */
public $wrap_tag = 'p';
/** @var string */
public $wrap_cont_tag = 'p';
/** @var bool */
public $hide_on_init = true;
/** @var bool */
public $is_dismissible = false;
/** @var int delay in milliseconds */
public $auto_hide_delay = 0;
/** @var string */
public $callback_on_show = '';
/** @var string */
public $callback_on_hide = '';
/**
* Class constructor
*
* @param string $content Content of the message
* @param string $type Type of the message (NOTICE, WARNING, ERROR)
*/
public function __construct($content = '', $type = self::NOTICE)
{
self::$unique_id++;
$this->id = self::UNIQUE_ID_PREFIX . self::$unique_id;
$this->content = (string) $content;
$this->type = $type;
}
/**
* Get the classes for the notice
*
* @param string[] $classes Additional classes
*
* @return string
*/
protected function get_notice_classes($classes = array())
{
if (is_string($classes)) {
$classes = explode(' ', $classes);
} elseif (is_array($classes)) {
} else {
$classes = array();
}
if ($this->is_dismissible) {
$classes[] = 'is-dismissible';
}
$result = array_merge(array('notice', $this->type), $classes);
return trim(implode(' ', $result));
}
/**
* Initialize the message
*
* @param bool $jsBodyAppend If true, the message will be appended to the body tag
*
* @return void
*/
public function initMessage($jsBodyAppend = false)
{
$classes = array();
if ($this->hide_on_init) {
$classes[] = 'no_display';
}
$this->wrap_tag = empty($this->wrap_tag) ? 'p' : $this->wrap_tag;
$result = '<div id="' . $this->id . '" class="' . $this->get_notice_classes($classes) . '">' .
'<' . $this->wrap_cont_tag . ' class="msg-content">' .
$this->content .
'</' . $this->wrap_cont_tag . '>' .
'</div>';
if ($jsBodyAppend) {
echo '$("body").append(' . SnapJson::jsonEncode($result) . ');';
} else {
echo $result;
}
}
/**
* Update the message content
*
* @param string $jsVarName Name of the variable containing the new content
* @param bool $echo If true, the result will be echoed
*
* @return string
*/
public function updateMessage($jsVarName, $echo = true)
{
$result = 'jQuery("#' . $this->id . ' > .msg-content").html(' . $jsVarName . ');';
if ($echo) {
echo $result;
return '';
} else {
return $result;
}
}
/**
* Show the message
*
* @param bool $echo If true, the result will be echoed
*
* @return string
*/
public function showMessage($echo = true)
{
$callStr = (strlen($this->callback_on_show) ? $this->callback_on_show . ';' : '');
$result = 'jQuery("body, html").animate({ scrollTop: 0 }, 500 );';
$result .= 'jQuery("#' . $this->id . '").fadeIn( "slow", function() { jQuery(this).removeClass("no_display");' . $callStr . ' });';
if ($this->auto_hide_delay > 0) {
$result .= 'setTimeout(function () { ' . $this->hideMessage(false) . ' }, ' . $this->auto_hide_delay . ');';
}
if ($echo) {
echo $result;
return '';
} else {
return $result;
}
}
/**
* Hide the message
*
* @param bool $echo If true, the result will be echoed
*
* @return string
*/
public function hideMessage($echo = true)
{
$callStr = (strlen($this->callback_on_hide) ? $this->callback_on_hide . ';' : '');
$result = 'jQuery("#' . $this->id . '").fadeOut( "slow", function() { jQuery(this).addClass("no_display");' . $callStr . ' });';
if ($echo) {
echo $result;
return '';
} else {
return $result;
}
}
}

View File

@@ -0,0 +1,166 @@
<?php
defined("ABSPATH") or die("");
/**
* Gets the view state of UI elements to remember its viewable state
*
* Standard: PSR-2
*
* @link http://www.php-fig.org/psr/psr-2
*
* @package DUP_PRO
* @subpackage classes/ui
* @copyright (c) 2017, Snapcreek LLC
* @license https://opensource.org/licenses/GPL-3.0 GNU Public License
* @since 3.3.0
*/
class DUP_PRO_UI_ViewState
{
/** @var string The key used in the wp_options table */
private static $optionsTableKey = 'duplicator_pro_ui_view_state';
/**
* Save the view state of UI elements
*
* @param string $key A unique key to define the UI element
* @param string $value A generic value to use for the view state
*
* @return bool Returns true if the value was successfully saved
*/
public static function save($key, $value)
{
$view_state = array();
$view_state = get_option(self::$optionsTableKey);
$view_state[$key] = $value;
$success = update_option(self::$optionsTableKey, $view_state);
return $success;
}
/**
* Saves the state of a UI element via post params
*
* @return void
*
* <code>
* //JavaScript Ajax Request
* DupPro.UI.SaveViewStateByPost('dup-pack-archive-panel', 1);
*
* //Call PHP Code
* $view_state = DUP_PRO_UI_ViewState::getValue('dup-pack-archive-panel');
* $ui_css_archive = ($view_state == 1) ? 'display:block' : 'display:none';
* </code>
*
* @todo: Move this method to a controller see dlite (ctrl)
*/
public static function saveByPost()
{
DUP_PRO_Handler::init_error_handler();
check_ajax_referer('DUP_PRO_UI_ViewState_SaveByPost', 'nonce');
$json = array(
'update-success' => false,
'error-message' => '',
'key' => '',
'value' => '',
);
$isValid = true;
$inputData = filter_input_array(INPUT_POST, array(
'states' => array(
'filter' => FILTER_UNSAFE_RAW,
'flags' => FILTER_FORCE_ARRAY,
'options' => array(
'default' => array(),
),
),
'key' => array(
'filter' => FILTER_SANITIZE_SPECIAL_CHARS,
'options' => array('default' => false),
),
'value' => array(
'filter' => FILTER_SANITIZE_SPECIAL_CHARS,
'options' => array('default' => false),
),
));
if (isset($inputData['states']) && !empty($inputData['states'])) {
foreach ($inputData['states'] as $index => $state) {
$filteredState = filter_var_array($state, array(
'key' => array(
'filter' => FILTER_SANITIZE_SPECIAL_CHARS,
'options' => array('default' => false),
),
'value' => array(
'filter' => FILTER_SANITIZE_SPECIAL_CHARS,
'options' => array('default' => false),
),
));
if ($filteredState['key'] === false && $filteredState['value']) {
$isValid = false;
break;
}
$inputData['states'][$index] = $filteredState;
}
}
if ($inputData['key'] === false || $inputData['value'] === false) {
$isValid = false;
}
// VALIDATIO END
if ($isValid) {
if (!empty($inputData['states'])) {
$view_state = self::getArray();
$last_key = '';
foreach ($inputData['states'] as $state) {
$view_state[$state['key']] = $state['value'];
$last_key = $state['key'];
}
$json['update-success'] = self::setArray($view_state);
$json['key'] = esc_html($last_key);
$json['value'] = esc_html($view_state[$last_key]);
} else {
$json['update-success'] = self::save($inputData['key'], $inputData['value']);
$json['key'] = esc_html($inputData['key']);
$json['value'] = esc_html($inputData['value']);
}
} else {
$json['update-success'] = false;
$json['error-message'] = "Sent data is not valid.";
}
die(json_encode($json));
}
/**
* Gets all the values from the settings array
*
* @return array<string, mixed> Returns and array of all the values stored in the settings array
*/
public static function getArray()
{
return get_option(self::$optionsTableKey);
}
/**
* Gwer view statue value or default if don't exists
*
* @param string $key key
* @param mixed $default default value
*
* @return mixed
*/
public static function getValue($key, $default = false)
{
$vals = self::getArray();
return (isset($vals[$key]) ? $vals[$key] : $default);
}
/**
* Sets all the values from the settings array
*
* @param array<string, mixed> $view_state states
*
* @return boolean Returns whether updated or not
*/
public static function setArray($view_state)
{
return update_option(self::$optionsTableKey, $view_state);
}
}

View File

@@ -0,0 +1,3 @@
<?php
//silent