// must be an admin make a change to use EXTERNAL code (we may add a custom access switch - use ADMIN for now)
if ($hash !== $live_hash && $this->user->authorise(
'core.admin', 'com_componentbuilder'
))
{
// update the hash since it changed
$object = new \stdClass();
$object->target = $target_key;
$object->hash = $live_hash;
// update local hash
$this->db->updateObject(
'#__componentbuilder_external_code', $object,
'target'
);
// give notice of the change
$this->app->enqueueMessage(
Text::_('<hr /><h3>External Code Warning</h3>'),
'Warning'
);
$this->app->enqueueMessage(
Text::sprintf('The code/string from <b>%s</b> has been <b>changed</b> since the last compilation. Please investigate to ensure the changes are safe! <b>Should you not expect this change to the external code/string being added, then this is a serious issue! and requires immediate attention!</b> Do not ignore this warning as it will only show <b>once</b>.',
$key
), 'Warning'
);
}
elseif ($hash !== $live_hash)
{
// set the notice
$this->app->enqueueMessage(
Text::_('<hr /><h3>External Code Error</h3>'),
'Error'
);
$this->app->enqueueMessage(
Text::sprintf('%s, we detected a change in <b>EXTERNALCODE</b>, but you do not have permission to allow this change so <b>%s</b> was removed from the compilation. Please contact your system administrator for more info!<br /><small>(admin access required)</small>',
$this->user->get('name'), $key
), 'Error'
);
// remove the code/string
$this->code[$target_key] = '';
}
}
// only an admin can add new EXTERNAL code (we may add a custom access switch - use ADMIN for now)
elseif ($this->user->authorise(
'core.admin', 'com_componentbuilder'
))
{
// add the hash to track changes
$object = new \stdClass();
$object->target = $target_key;
$object->hash = $live_hash;
// insert local hash
$this->db->insertObject(
'#__componentbuilder_external_code', $object
);
// give notice the first time this is added
$this->app->enqueueMessage(
Text::_('<hr /><h3>External Code Notice</h3>'),
'Warning'
);
$this->app->enqueueMessage(
Text::sprintf('The code/string from <b>%s</b> has been added for the <b>first time</b>. Please <i>investigate</i> to ensure the correct code/string was used! <b>Should you not know about this NEW external code/string being added, then this is a serious danger! and requires immediate attention!</b> Do not ignore this warning as it will only show <b>once</b>.',
$key
), 'Warning'
);
}
else
{
// set the notice
$this->app->enqueueMessage(
Text::_('<hr /><h3>External Code Error</h3>'),
'Error'
);
$this->app->enqueueMessage(
Text::sprintf('%s, we detected <b>NEW EXTERNALCODE</b>, but you do not have permission to allow this new code/string so <b>%s</b> was removed from the compilation. Please contact you system administrator for more info!<br /><small>(admin access required)</small>',
$this->user->get('name'), $key
), 'Error'
);
// remove the code/string
$this->code[$target_key] = '';
}
}
else
{
// set notice that we could not get a valid string from the target
Text::sprintf('The <b>%s</b> returned an invalid string!', $key
), 'Error'
);
}
}
// add to local bucket
$bucket[$key] = $this->code[$target_key] ?? '';
}
/**
* Cut the External Code/String
*
* @param string $string The content to cut
* @param string $sequence The cutting sequence
* @param string $key The content key
*
* @return string
* @since 3.2.0
*/
protected function cut(string $string, string $sequence, string $key): string
{
// we first break the string up in rows
$rows = (array) explode(PHP_EOL, $string);
// get the cutting sequence
$cutter = (array) explode('|', $sequence);
// we only continue if we have more rows than we have to cut
if (array_sum($cutter) < ArrayHelper::check($rows))
{
// remove the rows at the bottom if needed
if (isset($cutter[1]) && $cutter[1] > 0)
{
array_splice($rows, "-$cutter[1]");
}
// remove the rows at the top if needed
if ($cutter[0] > 0)
{
$rows = array_splice($rows, $cutter[0]);
}
// return the remaining rows
return implode(PHP_EOL, $rows);
}
// we set an error message about too few lines to cut
$this->app->enqueueMessage(
Text::_('<hr /><h3>External Code Notice</h3>'),
'Error'
);
$this->app->enqueueMessage(
Text::sprintf('The <b>%s</b> cut sequence failed on the returned external code/string as more lines has to be cut then was found in the code/string. We have completely removed the code. Please check this code/string!',