| Server IP : 89.39.208.18 / Your IP : 216.73.217.74 Web Server : LiteSpeed System : User : ( ) PHP Version : 7.4.33 Disable Function : eval,./,ln,passthru,dl,system,exec,popen,shell_exec,posix_getpwuid,posix_uname,ftp_exec,posix_uname,posix_getpwuid,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,get_current_user,getmyuid,getmygid,listen,chgrp,apache_note,apache_setenv,apache_child_terminate,closelog,debugger_off,debugge_on,ini_restore,netscript,escapeshellarg,cmd,backtick,virtual,show_sourc,show_source,pclose,pcntl_exec,datasec,old_offset,ctrl_dir,ini_alter,leak,listen,chgrp,apache_setenv,define_syslog_variables,root,diskfreespace,disk_free_space,disk_total_space,posix_kill,getmyuid,getmygid,apache_child_terminate,php_ini_scanned_files,ls,ps_aux,chown,getrusage,posixc,posame,chgrp,posix_setuid,posix_setsid,posix_setgid,apache_note,apache_setenv,x_getuid,e_ini_file,nfo,SQL,mysql_li,t_dbs,filegroup,highlight_file,ilegetcontents,get_dir,popen,popens,pfsockopen,dos_conv,apache_get_modules,crack_check,crack_closedict,rar_open,bzopen,bzread,bzwrite,shellcode,posix_isatty,posix_getservbyname,escapeshellarg,hypot,pg_host,pos,posix_access,inurl,posix_times,posix_mknod,pclose,ps_fill,symlink,id,escapeshellcmd,php_uname,phpinfo MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home3/mahyarcake/./public_html/wp-content/plugins/duplicator-pro/src/Models/ |
Upload File : |
<?php
/**
*
* @package Duplicator
* @copyright (c) 2022, Snap Creek LLC
*/
namespace Duplicator\Models;
use DUP_PRO_Log;
use Duplicator\Addons\ProBase\License\License;
use Duplicator\Core\Models\AbstractEntityList;
use Duplicator\Libs\Snap\SnapIO;
use ReflectionObject;
/**
* Brand entity
* DUP_PRO_Brand_Entity
*/
class BrandEntity extends AbstractEntityList
{
const MODE_KEEP_PLUGIN = 0;
const MODE_REMOVE_PLUGIN = 1;
/** @var string */
public $name = '';
/** @var string */
public $notes = '';
/** @var bool */
public $editable = true;
/** @var string */
public $logo = '<i class="fa fa-bolt fa-sm"></i> Duplicator Pro';
/** @var string[] */
public $attachments = array();
/** @var bool */
protected $default = false;
/** @var int */
protected $brandMode = self::MODE_REMOVE_PLUGIN;
/** @var bool */
public $active = false;
/** @var array<string, mixed> */
public $style = array();
/**
* Return entity type identifier
*
* @return string
*/
public static function getType()
{
return 'DUP_PRO_Brand_Entity';
}
/**
* Get the value of default
*
* @return bool true if is default brand
*/
public function isDefault()
{
return $this->default;
}
/**
* Return all list of brand with default brand included
*
* @return self[]|false false on failure
*/
public static function getAllWithDefault()
{
if (License::can(License::CAPABILITY_BRAND)) {
$brands = self::getAll();
} else {
$brands = [];
}
if ($brands === false) {
return false;
}
array_unshift($brands, self::getDefaultBrand());
return $brands;
}
/**
* Get entity by id
* For legacy reason $id can be -2 and thar case the brand is default
*
* @param int $id entity id
*
* @return self Return entity brand istance or default if son't exists
*/
public static function getByIdOrDefault($id)
{
if ($id < 0 || !License::can(License::CAPABILITY_BRAND)) {
return self::getDefaultBrand();
} elseif (($result = parent::getById($id)) == false) {
return self::getDefaultBrand();
} else {
return $result;
}
}
/**
* Get mode text
*
* @return string
*/
public function getModeText()
{
$txt = __('Unknown', 'duplicator-pro');
switch ($this->brandMode) {
case self::MODE_KEEP_PLUGIN:
$txt = __('Keep Plugin', 'duplicator-pro');
break;
case self::MODE_REMOVE_PLUGIN:
$txt = __('Remove Plugin', 'duplicator-pro');
break;
}
return $txt;
}
/**
* Save entity
*
* @return bool True on success, or false on error.
*/
public function save()
{
if (!License::can(License::CAPABILITY_BRAND)) {
return false;
}
if ($this->default) {
return false;
}
return parent::save();
}
/**
* Collect all attachments into `$this->attachments`
*
* @param string|string[] $attachments image paths inside /wp-content/uploads folder, Accept array or comma delimited array
*
* @return void
*/
public function setAttachments($attachments)
{
if (!is_array($attachments)) {
$attachments = array_map("trim", preg_split('/(;|,)/', $attachments));
}
$upload_dir = wp_upload_dir();
$dir = $upload_dir['basedir'];
// Uploads folder
$dir = str_replace(array('\\', '//'), array('/', '/'), $dir);
foreach ($attachments as $attachment) {
if (file_exists("{$dir}{$attachment}")) {
$this->attachments[] = $attachment;
}
}
}
/**
* Return default brand object
*
* @return self
*/
public static function getDefaultBrand()
{
$brand = new self();
$brand->name = __('Default', 'duplicator-pro');
$brand->notes = __('The default content used when a brand is not defined', 'duplicator-pro');
$brand->logo = sprintf(__('%s Duplicator Pro', 'duplicator-pro'), '<i class="fa fa-bolt fa-sm"></i>');
$brand->editable = false;
$brand->attachments = [];
$refObject = new ReflectionObject($brand);
$refProperty = $refObject->getProperty('default');
$refProperty->setAccessible(true);
$refProperty->setValue($brand, true);
return $brand;
}
/**
* Prepare attahcment to installer
*
* @return bool true on success, fail on failure
*/
public function prepareAttachmentsInstaller()
{
$this->emptyAttachmentFolder();
if (empty($this->attachments)) {
return true;
}
$brandAttFolder = self::getAttachmentFolder();
if (wp_mkdir_p($brandAttFolder) === false) {
return false;
}
$uploadInfo = wp_upload_dir();
$uploadDir = SnapIO::safePathUntrailingslashit($uploadInfo['basedir']);
$copied = false;
foreach ($this->attachments as $attachment) {
$sourceFile = $uploadDir . $attachment;
$targetFile = $brandAttFolder . $attachment;
if (!file_exists($sourceFile)) {
continue;
}
if (wp_mkdir_p(dirname($targetFile)) === false) {
return false;
}
if (copy($sourceFile, $targetFile) === false) {
DUP_PRO_Log::error("Error copying {$sourceFile} to {$targetFile}", '', false);
} else {
$copied = true;
}
}
return $copied;
}
/**
* Empty brand attachment folder
*
* @return bool true on success, fail on failure
*/
protected function emptyAttachmentFolder()
{
$dir = self::getAttachmentFolder();
if (file_exists($dir)) {
return SnapIO::rrmdir($dir);
}
return true;
}
/**
* Return attahcment folder
*
* @todo move this folder outsite pligin installation. (add attachmetn directly ad packag.
*
* @return string
*/
protected static function getAttachmentFolder()
{
return DUPLICATOR____PATH . "/installer/dup-installer/assets/images/brand";
}
}