This function can check:

  • Component is present and enabled in #__extensions table
  • Component folder is present in backend
  • Component folder is present in frontend

You can extend the validation methods just adding chars to the validationType, receiving the validation status and adding the validation to the end of the script.

	/**
	 *
	 * @author Roberto Segura - Digital Disseny, S.L.
	 * @version 02/07/2012
	 *
	 * @param string $comString
	 * @param string $validationType:
* 100 => 1st char = validate db?
* 010 => 2nd char = validate backend folder?
* 001 => 3rd char = validate frontend folder?
* 111 => validate all example
*/ public function validateComponent($comString, $validationType = 100){ jimport('joomla.filesystem.folder'); // default result $validComponent = false; $validationsDone = 0; // use allways as string $validationType = (string)$validationType; // get required validations $validateDb = (isset($validationType[0]) && $validationType[0] == '1'); $validateBackend = (isset($validationType[1]) && $validationType[1] == '1'); $validateFrontend = (isset($validationType[2]) && $validationType[2] == '1'); // validate: extension is present and enabled on db if (($validationsDone == 0 || ($validComponent)) && $validateDb) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('extension_id, name'); $query->from('#__extensions'); $query->where('name='.$db->quote($comString)); $db->setQuery($query); if($db->loadObject()) { $validComponent = true; } else { $validComponent = false; } $validationsDone++; } // validate: backend folder exist if (($validationsDone == 0 || ($validComponent)) && $validateBackend) { $backendPath = JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR .'components' . DIRECTORY_SEPARATOR . $comString ; if (JFolder::exists($backendPath)) { $validComponent = true; } else { $validComponent = false; } $validationsDone++; } // validate: frontend folder exist if (($validationsDone == 0 || ($validComponent)) && $validateFrontend) { $frontendPath = JPATH_SITE . DIRECTORY_SEPARATOR .'components' . DIRECTORY_SEPARATOR . $comString; if (JFolder::exists($frontendPath)) { $validComponent = true; } else { $validComponent = false; } $validationsDone++; } return $validComponent; }

The function will be called as:

$validComponent = validateComponent('com_phocagallery',101);

As the validation type is 101 the function will perform the first (database) and the third (frontend folder) checks.

To demonstrate the customization we will add an extra validation. In this example we just added a validation to check if the component is phocagallery.If we want to perfom this validation we will call it this way:

$validComponent = validateComponent('com_phocagallery',1001);

Note that we just added a fourth digit to the validation type.

	/**
	 *
	 * @author Roberto Segura - Digital Disseny, S.L.
	 * @version 02/07/2012
	 *
	 * @param string $comString
	 * @param string $validationType:
* 100 => 1st char = validate db?
* 010 => 2nd char = validate backend folder?
* 001 => 3rd char = validate frontend folder?
* 111 => validate all example
*/ public function validateComponent($comString, $validationType = 1000){ jimport('joomla.filesystem.folder'); // default result $validComponent = false; $validationsDone = 0; // use allways as string $validationType = (string)$validationType; // get required validations $validateDb = (isset($validationType[0]) && $validationType[0] == '1'); $validateBackend = (isset($validationType[1]) && $validationType[1] == '1'); $validateFrontend = (isset($validationType[2]) && $validationType[2] == '1'); // check if my validation is required $myValidation = (isset($validationType[3]) && $validationType[3] == '1'); // validate: extension is present and enabled on db if (($validationsDone == 0 || ($validComponent)) && $validateDb) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('extension_id, name'); $query->from('#__extensions'); $query->where('name='.$db->quote($comString)); $db->setQuery($query); if($db->loadObject()) { $validComponent = true; } else { $validComponent = false; } $validationsDone++; } // validate: backend folder exist if (($validationsDone == 0 || ($validComponent)) && $validateBackend) { $backendPath = JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR .'components' . DIRECTORY_SEPARATOR . $comString ; if (JFolder::exists($backendPath)) { $validComponent = true; } else { $validComponent = false; } $validationsDone++; } // validate: frontend folder exist if (($validationsDone == 0 || ($validComponent)) && $validateFrontend) { $frontendPath = JPATH_SITE . DIRECTORY_SEPARATOR .'components' . DIRECTORY_SEPARATOR . $comString; if (JFolder::exists($frontendPath)) { $validComponent = true; } else { $validComponent = false; } $validationsDone++; } // validate: do myValidation if (($validationsDone == 0 || ($validComponent)) && $myValidation) { if ($comString == 'com_phocagallery') { $validComponent = true; } else { $validComponent = false; } $validationsDone++; } return $validComponent; }