I did a modification of one component for a contact, where the name of the file being sent as attachment is compared to the names in the database. Only if the name matches it is allowed to send. If it does not match, an error message should be displayed. The code I added is last 15 lines:
public function exec($upload_directory, $item)
{
if (!is_writable($upload_directory))
{
return array('error' => JText::_('COM_FOXCONTACT_ERR_DIR_NOT_WRITABLE'));
}
$size = $this->getFileSize();
if ($size == 0)
{
return array('error' => JText::_('COM_FOXCONTACT_ERR_FILE_EMPTY'));
}
if ($size > constant($item->get('file.size', 'MB100')))
{
return array('error' => JText::_('COM_FOXCONTACT_ERR_FILE_TOO_LARGE'));
}
$realname = $this->getFileName();
// My code
$realname = Normalizer::normalize($realname);
setlocale(LC_ALL,'bs_BA.UTF-8');
$onlyname = pathinfo($realname, PATHINFO_FILENAME);
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('eio3k_peaks.peak_name');
$query->from($db->quoteName('#__peaks'));
$db->setQuery($query);
$peaks_list = $db->loadColumn();
if (!in_array($onlyname, $peaks_list))
{
return array('error' => JText::_('Name of file <strong>' .$onlyname. ' <strong> is not correct. Pay attention to uppercase/lowercase, spaces, and special characters. More info at this link: https://planinarenje.ba'));
}
// End of my code
...
I'm trying to make variable $onlyname bold, and link clickable. I tried to make the message as a language constant and as a code, but it does not work.
This is updated code from @Robbie Jackson but with this code get empty message:
// My code
$realname = Normalizer::normalize($realname);
setlocale(LC_ALL,'bs_BA.UTF-8');
$onlyname = pathinfo($realname, PATHINFO_FILENAME);
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('eio3k_peaks.peak_name');
$query->from($db->quoteName('#__peaks'));
$db->setQuery($query);
$peaks_list = $db->loadColumn();
if (!in_array($onlyname, $peaks_list))
{
JFactory::getApplication()->enqueueMessage(JText::_('Name of file <strong>' .$onlyname. ' </strong> is not correct', 'error')); return array('error' => ' ');
}
// End of my code
...
On this link you can see printscreen with old and new code https://emreza.org/a.jpg
COUNT(1)
and useloadResult()
to only generate a single-value result set. Then you only need to check for zero or one (in other words a truthy|falsey result, noin_array()
call).