Ok so this is what I was writing yesterday.
For Joomla 2.5 and 3.x only
- Check if the
http://
prefix is missing from the URL. If it is, then it adds it. Note that In this case I have not taken https://
into consideration.
- It then tries to get the Joomla manifest file and checks whether is exists/is readable.
- If it exists then it gets the value from the
<version>
tag.
- If the XML file is not readable, then I have written a fallback to get the TinyMCE version. Again, it will try to read the value from the
<version>
tag.
- From here on, I spent quite a long time going through the release notes for each Joomla version to see which versions has a TinyMCE update. Those that did, I added to the
switch
block further own in the code. This approach will not give the exact version apart from 2 of them, but it will give an average. I was thinking about detecting the jQuery version but then realised that a lot of people update the core version to the latest which would then make the results inaccurate.
- If the TinyMCE version cannot be found (so basically a non-Joomla site), then the function will return
Unknown
.
Note: This script uses CURL
so make sure it's enabled on your server.
class JoomlaVersions
{
public function getJoomlaVersion($site)
{
// Add http prefix if missing
if (strpos($site,'http://') === false)
{
$site = 'http://'.$site;
}
// Get the number value from the <version> tag in the XML file
$dom = new DOMDocument;
$url = $site . '/administrator/manifests/files/joomla.xml';
libxml_use_internal_errors(true);
$exists = $this->XMLexists($url);
if( $exists )
{
$dom->load($url);
$versions = $dom->getElementsByTagName('version');
foreach ($versions as $version)
{
return $version->nodeValue;
}
}
else
{
$mce = $this->getTinyMCEversion($site);
if($mce)
{
// Base Joomla version on the TinyMCE version
switch ($mce)
{
case '3.5.6':
$joomla = '3.0.0 - 3.1.6';
break;
case '4.0.10':
$joomla = '3.2.0 - 3.2.1';
break;
case '4.0.12':
$joomla = '3.2.2';
break;
case '4.0.18':
$joomla = '3.2.3 - 3.2.4';
break;
case '4.0.22':
$joomla = '3.3.0';
break;
case '4.0.28':
$joomla = '3.3.1 - 3.3.6';
break;
case '4.1.7':
$joomla = '3.4.0';
break;
default:
$joomla = '3.x';
}
return $joomla;
}
else
{
return 'Unknown';
}
}
}
// Get TinyMCE Version
private function getTinyMCEversion($site)
{
$tinymce = $site . '/plugins/editors/tinymce/tinymce.xml';
libxml_use_internal_errors(true);
$exists = $this->XMLexists($tinymce);
if( $exists )
{
$dom->load($tinymce);
$vTag = $dom->getElementsByTagName('version');
foreach ($vTag as $tag)
{
return $tag->nodeValue;
}
}
}
// Check file exists using CURL
private function XMLexists($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$getinfo = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $getinfo;
}
}
Then call the function like so:
$version = new JoomlaVersions;
echo $version->getJoomlaVersion('http://joomla.org');
I've created a module on my website as a Tool for other users:
Joomla Version Detection Tool
I've also created a Github repository if you wish to fork it or submit pull requests:
Joomla Version Detect Github Repo
Anyway, as some of you know, I'm not a backend developer so there are probably a lot of improvements which can be made to the code. If you have another solution or can update what I currently have, be sure to post it as a new answer.