/**
* The Owner details template
*
* @var array
* @since 3.2.0
*/
private array $owner = [
'company' => JustTEXT::_('
Company%s'),
'owner' => JustTEXT::_('Owner%s'),
'email' => JustTEXT::_('Email%s'),
'website' => JustTEXT::_('Website%s'),
'license' => JustTEXT::_('License%s'),
'copyright' => JustTEXT::_('Copyright%s')
];
/**
* The Component details template
*
* @var array
* @since 3.2.0
*/
private array $component = [
'ul' => [
'companyname' => JustTEXT::_('Company: %s'),
'author' => JustTEXT::_('Author: %s'),
'email' => JustTEXT::_('Email: %s'),
'website' => JustTEXT::_('Website: %s'),
],
'other' => [
'license' => JustTEXT::_('%s
'),
'copyright' => JustTEXT::_('%s
')
]
];
/**
* get the JCB package owner details display
*
* @param array $info The package info object
* @param bool $trust The trust switch
*
* @return string
* @since 3.2.0
**/
public function owner(array $info, $trust = false): string
{
$hasOwner = false;
$ownerDetails = '';
$ownerDetails .= '';
// load the list items
foreach ($this->owner as $key => $dd)
{
if ($value = $this->getInfoValue($key, $info))
{
$ownerDetails .= Text::sprintf($dd, $value);
// check if we have a owner/source name
if (('owner' === $key || 'company' === $key) && !$hasOwner)
{
$hasOwner = true;
$owner = $value;
}
}
}
$ownerDetails .= '
';
// provide some details to how the user can get a key
if ($hasOwner && isset($info['getKeyFrom']['buy_link']) && StringHelper::check($info['getKeyFrom']['buy_link']))
{
$ownerDetails .= '
';
$ownerDetails .= Text::sprintf('Get the key from %s', 'class="btn btn-primary" href="' . $info['getKeyFrom']['buy_link'] . '" target="_blank" title="get a key from ' . $owner . '"', $owner);
}
// add more custom links
elseif ($hasOwner && isset($info['getKeyFrom']['buy_links']) && ArrayHelper::check($info['getKeyFrom']['buy_links']))
{
$buttons = array();
foreach ($info['getKeyFrom']['buy_links'] as $keyName => $link)
{
$buttons[] = Text::sprintf('Get the key from %s for %s', $owner, 'class="btn btn-primary" href="' . $link . '" target="_blank" title="get a key from ' . $owner . '"', $keyName);
}
$ownerDetails .= '
';
$ownerDetails .= implode('
', $buttons);
}
// return the owner details
if (!$hasOwner)
{
$ownerDetails = '' . Text::_('Package owner details not found!') . '
';
if (!$trust)
{
$ownerDetails .= '' . Text::_('Be cautious! Do not continue unless you trust the origin of this package!') . '
';
}
}
return ''.$ownerDetails.'
';
}
/**
* Check if info details has owner values set
*
* @param array $info The package info object
*
* @return bool
* @since 3.2.0
**/
public function hasOwner(array &$info): bool
{
if ($this->getInfoValue('owner', $info) || $this->getInfoValue('company', $info))
{
return true;
}
return false;
}
/**
* get the JCB package components details display
*
* @param array $info The package info object
*
* @return string
* @since 3.2.0
**/
public function components(array &$info): string
{
// check if these components need a key
$needKey = $this->hasKey($info);
if (isset($info['name']) && ArrayHelper::check($info['name']))
{
$cAmount = count((array) $info['name']);
$class2 = ($cAmount == 1) ? 'span12' : 'span6';
$counter = 1;
$display = array();
foreach ($info['name'] as $key => $value)
{
// set the name
$name = $value . ' v' . $info['component_version'][$key];
if ($cAmount > 1 && $counter == 3)
{
$display[] = '';
$counter = 1;
}
if ($cAmount > 1 && $counter == 1)
{
$display[] = '';
}
$display[] = '
';
$display[] = '
';
$display[] = $name;
if ($needKey)
{
$display[] = ' - ' . Text::sprintf('Paid/Locked') . '';
}
else
{
$display[] = ' - ' . Text::sprintf('Free/Open') . '';
}
$display[] = '
';
$display[] = $info['short_description'][$key];
$display[] = '
';
$display[] = '
';
// load the list items
foreach ($this->component['ul'] as $li => $value)
{
if (isset($info[$li]) && isset($info[$li][$key]))
{
$display[] = '- '.Text::sprintf($value, $info[$li][$key]).'
';
}
}
$display[] = '
';
// if we have a source link we add it
if (isset($info['joomla_source_link']) && ArrayHelper::check($info['joomla_source_link']) && isset($info['joomla_source_link'][$key]) && StringHelper::check($info['joomla_source_link'][$key]))
{
$display[] = '
' . Text::_('source code') . '';
}
// load other
foreach ($this->component['other'] as $other => $value)
{
if (isset($info[$other]) && isset($info[$other][$key]))
{
$display[] = Text::sprintf($value, $info[$other][$key]);
}
}
$display[] = '
';
$counter++;
}
// close the div if needed
if ($cAmount > 1)
{
$display[] = '
';
}
return implode(PHP_EOL, $display);
}
return '' . Text::_('No component details found, so it is not safe to continue!') . '
';
}
/**
* get the value from INFO array
*
* @param string $key The value key
* @param array $info The package info object
*
* @return string|null
* @since 3.2.0
**/
private function getInfoValue(string $key, array &$info): ?string
{
$source = (isset($info['source']) && isset($info['source'][$key])) ? 'source' : ((isset($info['getKeyFrom']) && isset($info['getKeyFrom'][$key])) ? 'getKeyFrom' : null);
if ($source && StringHelper::check($info[$source][$key]))
{
return $info[$source][$key];
}
return null;
}
/**
* Check if the JCB package has a key
*
* @param array $info The package info object
*
* @return bool
* @since 3.2.0
**/
private function hasKey(array &$info): bool
{
// check the package key status
if (!isset($info['key']))
{
if (isset($info['getKeyFrom']) && isset($info['getKeyFrom']['owner']))
{
// has a key
$info['key'] = true;
}
else
{
// does not have a key
$info['key'] = false;
}
}
return (bool) $info['key'];
}