Created
July 2, 2012 09:27
-
-
Save digitaldisseny/3032271 to your computer and use it in GitHub Desktop.
Function to check Joomla! components. Easily extendable with more custom checks & transformable to check any joomla extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* @author Roberto Segura - Digital Disseny, S.L. | |
* @version 02/07/2012 | |
* | |
* @param string $comString | |
* @param string $validationType:<br> | |
* 100 => 1st char = validate db?<br> | |
* 010 => 2nd char = validate backend folder?<br> | |
* 001 => 3rd char = validate frontend folder?<br> | |
* 111 => validate all example<br> | |
*/ | |
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('element='.$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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment