first commit

This commit is contained in:
2026-04-27 23:13:18 +02:00
commit 8cc95300c7
10702 changed files with 3223926 additions and 0 deletions

View File

@@ -0,0 +1,112 @@
<?php
/**
* Custom exceptions
*
* Standard: PSR-2
*
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
*
* @package SC\DUPX\U
*/
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
/**
* Dup installer custom exception
*/
class DupxException extends Exception
{
/** @var string formatted html string */
protected $longMsg = '';
/** @var false|array{url: string, label: string} */
protected $faqLink = false;
/**
* Class constructor
*
* @param string $shortMsg Short message
* @param string $longMsg Long message
* @param string $faqLinkUrl FAQ link URL
* @param string $faqLinkLabel FAQ link label
* @param int $code Exception code
* @param Exception $previous Previous exception
*/
public function __construct($shortMsg, $longMsg = '', $faqLinkUrl = '', $faqLinkLabel = '', $code = 0, Exception $previous = null)
{
parent::__construct($shortMsg, $code, $previous);
$this->longMsg = (string) $longMsg;
if (strlen($faqLinkUrl) > 0) {
$this->faqLink = array(
'url' => $faqLinkUrl,
'label' => $faqLinkLabel,
);
}
}
/**
* Get the long message
*
* @return string
*/
public function getLongMsg()
{
return $this->longMsg;
}
/**
* Check is have faq link
*
* @return bool
*/
public function haveFaqLink()
{
return $this->faqLink !== false;
}
/**
* Get FAQ URL
*
* @return string
*/
public function getFaqLinkUrl()
{
if ($this->haveFaqLink()) {
return $this->faqLink['url'];
} else {
return '';
}
}
/**
* Get FAQ label
*
* @return string
*/
public function getFaqLinkLabel()
{
if ($this->haveFaqLink()) {
return $this->faqLink['label'];
} else {
return '';
}
}
/**
* Custom string representation of object
*
* @return string
*/
public function __toString()
{
$result = __CLASS__ . ": [{$this->code}]: {$this->message}";
if ($this->haveFaqLink()) {
$result .= "\n\tSee FAQ " . $this->faqLink['label'] . ': ' . $this->faqLink['url'];
}
if (!empty($this->longMsg)) {
$result .= "\n\t" . strip_tags($this->longMsg);
}
$result .= "\n";
return $result;
}
}

View File

@@ -0,0 +1,108 @@
<?php
/**
* Search and reaplace manager
*
* Standard: PSR-2
*
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
*
* @package SC\DUPX\U
*/
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
use Duplicator\Libs\Snap\SnapIO;
class DUPX_TemplateItem
{
/** @var string */
protected $name = null;
/** @var string */
protected $mainFolder = null;
/** @var null|DUPX_TemplateItem */
protected $parent = null;
/**
* Class contructor
*
* @param string $name Template name
* @param string $mainFolder Main folder
* @param ?DUPX_TemplateItem $parent Parent template
*/
public function __construct($name, $mainFolder, $parent = null)
{
if (empty($name)) {
throw new Exception('The name of template can\'t be empty');
}
if (!is_dir($mainFolder) || !is_readable($mainFolder)) {
throw new Exception('The main main folder doesn\'t exist');
}
if (!is_null($parent) && !$parent instanceof self) {
throw new Exception('the parent must be a instance of ' . __CLASS__);
}
$this->name = $name;
$this->mainFolder = SnapIO::safePathUntrailingslashit($mainFolder);
$this->parent = $parent;
}
/**
* Render template
*
* @param string $fileTpl Template file is a relative path from root template folder
* @param array<string, mixed> $args Array key / val where key is the var name in template
* @param bool $echo If false return template in string
*
* @return string
*/
public function render($fileTpl, $args = array(), $echo = true)
{
ob_start();
if (($renderFile = $this->getFileTemplate($fileTpl)) !== false) {
foreach ($args as $var => $value) {
${$var} = $value;
}
require($renderFile);
} else {
echo '<p>FILE TPL NOT FOUND: ' . $fileTpl . '</p>';
}
if ($echo) {
ob_end_flush();
return '';
} else {
return ob_get_clean();
}
}
/**
* Acctept html of php extensions. if the file have unknown extension automatic add the php extension
*
* @param string $fileTpl File template
*
* @return boolean|string return false if don\'t find the template file
*/
protected function getFileTemplate($fileTpl)
{
$fileExtension = strtolower(pathinfo($fileTpl, PATHINFO_EXTENSION));
switch ($fileExtension) {
case 'php':
case 'html':
$fileName = $fileTpl;
break;
default:
$fileName = $fileTpl . '.php';
}
$fullPath = $this->mainFolder . '/' . $fileName;
if (file_exists($fullPath)) {
return $fullPath;
} elseif (!is_null($this->parent)) {
return $this->parent->getFileTemplate($fileName);
} else {
return false;
}
}
}

View File

@@ -0,0 +1,133 @@
<?php
/**
* Search and reaplace manager
*
* Standard: PSR-2
*
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
*
* @package SC\DUPX\U
*/
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
require_once(DUPX_INIT . '/classes/utilities/template/class.u.template.item.php');
/**
* DUPX_Template
*/
final class DUPX_Template
{
const TEMPLATE_ADVANCED = 'default';
const TEMPLATE_BASE = 'base';
const TEMPLATE_IMPORT_BASE = 'import-base';
const TEMPLATE_IMPORT_ADVANCED = 'import-advanced';
const TEMPLATE_RECOVERY = 'recovery';
/** @var ?self */
private static $instance = null;
/** @var DUPX_TemplateItem[] */
private $templates = array();
/** @var string */
private $currentTemplate = null;
/**
* Get instance
*
* @return DUPX_Template
*/
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Class constructor
*/
private function __construct()
{
// ADD DEFAULT TEMPLATE
$this->addTemplate(DUPX_Template::TEMPLATE_ADVANCED, DUPX_INIT . '/templates/default');
$this->setTemplate(DUPX_Template::TEMPLATE_ADVANCED);
}
/**
* Set template
*
* @param string $name Template name
*
* @return boolean
*/
public function setTemplate($name)
{
if (!isset($this->templates[$name])) {
throw new Exception('The template ' . $name . ' doesn\'t exist');
}
$this->currentTemplate = $name;
return true;
}
/**
* Add template
*
* @param string $name Template name
* @param string $mainFolder Main folder
* @param ?string $parentName Parent template name
*
* @return boolean
*/
public function addTemplate($name, $mainFolder, $parentName = null)
{
if (isset($this->templates[$name])) {
throw new Exception('The template "' . $name . '" already exists');
}
if (is_null($parentName)) {
$parent = null;
} elseif (isset($this->templates[$parentName])) {
$parent = $this->templates[$parentName];
} else {
throw new Exception('The parent template "' . $parentName . '" doesn\'t exist');
}
$this->templates[$name] = new DUPX_TemplateItem($name, $mainFolder, $parent);
return true;
}
/**
* Render template
*
* @param string $fileTpl Template file is a relative path from root template folder
* @param array<string, mixed> $args Array key / val where key is the var name in template
* @param bool $echo If false return template in string
*
* @return string
*/
public function render($fileTpl, $args = array(), $echo = true)
{
return $this->templates[$this->currentTemplate]->render($fileTpl, $args, $echo);
}
}
/**
* Render template
*
* @param string $fileTpl Template file is a relative path from root template folder
* @param array<string, mixed> $args Array key / val where key is the var name in template
* @param bool $echo If false return template in string
*
* @return string
*/
function dupxTplRender($fileTpl, $args = array(), $echo = true)
{
static $tplMng = null;
if (is_null($tplMng)) {
$tplMng = DUPX_Template::getInstance();
}
return $tplMng->render($fileTpl, $args, $echo);
}