255 lines
7.2 KiB
Plaintext
255 lines
7.2 KiB
Plaintext
|
/**
|
||
|
* The Owner details template
|
||
|
*
|
||
|
* @var array
|
||
|
* @since 3.2.0
|
||
|
*/
|
||
|
private array $owner = [
|
||
|
'company' => JustTEXT::_('<dt>Company</dt><dd>%s</dd>'),
|
||
|
'owner' => JustTEXT::_('<dt>Owner</dt><dd>%s</dd>'),
|
||
|
'email' => JustTEXT::_('<dt>Email</dt><dd>%s</dd>'),
|
||
|
'website' => JustTEXT::_('<dt>Website</dt><dd>%s</dd>'),
|
||
|
'license' => JustTEXT::_('<dt>License</dt><dd>%s</dd>'),
|
||
|
'copyright' => JustTEXT::_('<dt>Copyright</dt><dd>%s</dd>')
|
||
|
];
|
||
|
|
||
|
/**
|
||
|
* The Component details template
|
||
|
*
|
||
|
* @var array
|
||
|
* @since 3.2.0
|
||
|
*/
|
||
|
private array $component = [
|
||
|
'ul' => [
|
||
|
'companyname' => JustTEXT::_('<i>Company:</i> <b>%s</b>'),
|
||
|
'author' => JustTEXT::_('<i>Author:</i> <b>%s</b>'),
|
||
|
'email' => JustTEXT::_('<i>Email:</i> <b>%s</b>'),
|
||
|
'website' => JustTEXT::_('<i>Website:</i> <b>%s</b>'),
|
||
|
],
|
||
|
'other' => [
|
||
|
'license' => JustTEXT::_('<h4 class="nav-header">License</h4><p>%s</p>'),
|
||
|
'copyright' => JustTEXT::_('<h4 class="nav-header">Copyright</h4><p>%s</p>')
|
||
|
]
|
||
|
];
|
||
|
|
||
|
/**
|
||
|
* 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 = '<h2 class="module-title nav-header">' . Text::_('Package Owner Details') . '</h2>';
|
||
|
$ownerDetails .= '<dl class="uk-description-list-horizontal">';
|
||
|
|
||
|
// 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 .= '</dl>';
|
||
|
|
||
|
// 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 .= '<hr />';
|
||
|
$ownerDetails .= Text::sprintf('<b>Get the key from</b> <a %s>%s</a>', '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('<b>Get the key from %s</b> for <a %s>%s</a>', $owner, 'class="btn btn-primary" href="' . $link . '" target="_blank" title="get a key from ' . $owner . '"', $keyName);
|
||
|
}
|
||
|
$ownerDetails .= '<hr />';
|
||
|
$ownerDetails .= implode('<br />', $buttons);
|
||
|
}
|
||
|
|
||
|
// return the owner details
|
||
|
if (!$hasOwner)
|
||
|
{
|
||
|
$ownerDetails = '<h2>' . Text::_('Package owner details not found!') . '</h2>';
|
||
|
|
||
|
if (!$trust)
|
||
|
{
|
||
|
$ownerDetails .= '<p style="color: #922924;">' . Text::_('Be cautious! Do not continue unless you trust the origin of this package!') . '</p>';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return '<div>'.$ownerDetails.'</div>';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 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[] = '</div>';
|
||
|
$counter = 1;
|
||
|
}
|
||
|
if ($cAmount > 1 && $counter == 1)
|
||
|
{
|
||
|
$display[] = '<div>';
|
||
|
}
|
||
|
$display[] = '<div class="well well-small ' . $class2 . '">';
|
||
|
$display[] = '<h3>';
|
||
|
$display[] = $name;
|
||
|
if ($needKey)
|
||
|
{
|
||
|
$display[] = ' - <em>' . Text::sprintf('Paid/Locked') . '</em>';
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$display[] = ' - <em>' . Text::sprintf('Free/Open') . '</em>';
|
||
|
}
|
||
|
$display[] = '</h3><h4>';
|
||
|
$display[] = $info['short_description'][$key];
|
||
|
$display[] = '</h4>';
|
||
|
$display[] = '<ul class="uk-list uk-list-striped">';
|
||
|
|
||
|
// load the list items
|
||
|
foreach ($this->component['ul'] as $li => $value)
|
||
|
{
|
||
|
if (isset($info[$li]) && isset($info[$li][$key]))
|
||
|
{
|
||
|
$display[] = '<li>'.Text::sprintf($value, $info[$li][$key]).'</li>';
|
||
|
}
|
||
|
}
|
||
|
$display[] = '</ul>';
|
||
|
|
||
|
// 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[] = '<a class="uk-button uk-button-mini uk-width-1-1 uk-margin-small-bottom" href="' .
|
||
|
$info['joomla_source_link'][$key] . '" target="_blank" title="' . Text::_('Source Code for Joomla Component') . ' ('. $name . ')">' . Text::_('source code') . '</a>';
|
||
|
}
|
||
|
|
||
|
// 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[] = '</div>';
|
||
|
|
||
|
$counter++;
|
||
|
}
|
||
|
|
||
|
// close the div if needed
|
||
|
if ($cAmount > 1)
|
||
|
{
|
||
|
$display[] = '</div>';
|
||
|
}
|
||
|
|
||
|
return implode(PHP_EOL, $display);
|
||
|
}
|
||
|
|
||
|
return '<div>' . Text::_('No component details found, so it is not safe to continue!') . '</div>';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 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'];
|
||
|
}
|