Easy and precise JComponentHelper::isEnabled replacement
When I had to check if RSgallery2 is installed in Joomla CMS, I've found that the standard JOOMLA methods to check if component is enabled in the system, can give some unexpected results.
jimport('joomla.application.component.helper');
if(!JComponentHelper::isEnabled('com_toto', true))
{
JError::raiseWarning( 100, JText::_('Component toto is not enabled'));
}
1. If the component is not installed you will get a system warning message:
Error loading component: com_toto, 1
2. While having good results in site's interface and even using the strict verification in administration interface, you will get a positive answer if the target component is installed, but disabled.
So, the easiest way to check if component is enabled would be:
$db = JFactory::getDbo();
$db->setQuery("SELECT enabled FROM #__extensions WHERE name = 'com_toto'");
$toto_enabled = ($db->loadResult() == 1);
if(!$toto_enabled){
JError::raiseWarning( 100, JText::_('Component toto is not enabled'));
}
