Location: PHPKode > scripts > Joomla Site Monitor > com_sitemonitor16/site/models/extensions.php
<?php
defined('_JEXEC') or die( 'Restricted access' );

class smcModelExtensions extends JModel {
	function loadList() {
        ini_set('memory_limit', '128M');
		$result = array();

		$db = JFactory :: getDBO();
		jimport('joomla.filesystem.folder');
		/* load components */
		$db->setQuery('SELECT name, element AS `option` FROM #__extensions WHERE `type` = \'component\'');
		if ($etxs = $db->loadObjectList()) foreach ($etxs as $ext) {
			$row = new stdclass;
			$row->iscore = false;
			$row->name = $ext->name;
			$row->version = '';
			$row->url = '';
			$row->is_legacy = false;
			$row->legacy_cms = '';
			$row->type = 'component';

			if ($option = $ext->option) {
				$folder = JPATH_ADMINISTRATOR.'/components/'.$option.'/';
				if (file_exists($folder)) {
					$row->extension = $option;
					if ($xml_files = JFolder :: files($folder, '\.xml$')) foreach ($xml_files as $xml_file) {
						$file_conent = file_get_contents($folder.$xml_file);
						if (preg_match('#<(.*)(install|extension).*type="component"#msi', $file_conent, $m)) {
							if (preg_match('#<name>(.+)</name>#i', $file_conent, $m)) $row->name = $m[1];
							if (preg_match('#<version>(.+)</version>#i', $file_conent, $m)) $row->version = $m[1];
							if (preg_match('#<authorUrl>(.+)</authorUrl>#i', $file_conent, $m)) $row->url = $m[1];
							if ($row->url and preg_match('/www\.joomla\.org/i', $row->url)) $row->iscore = 1;
							$result[] = $row;
							break;
						}
					}
				}
			}
		}
		/* load modules */
		$db->setQuery('SELECT name AS module, client_id FROM #__extensions WHERE `type` = \'module\'');
		if ($etxs = $db->loadObjectList()) foreach ($etxs as $ext) {
			$row = new stdclass;
			$row->iscore = false;
			$row->name = $ext->module;
			$row->version = '';
			$row->url = '';
			$row->is_legacy = false;
			$row->legacy_cms = '';
			$row->type = $ext->client_id?'admin module':'frontend module';
			$row->extension = $ext->module;

			$folder = ($ext->client_id?JPATH_ADMINISTRATOR:JPATH_SITE).'/modules/'.$ext->module.'/';
			if (file_exists($folder)) {
				if ($xml_files = JFolder :: files($folder, '\.xml$')) foreach ($xml_files as $xml_file) {
					$file_conent = file_get_contents($folder.$xml_file);
					if (preg_match('#<(.*)(install|extension).*type="module"#msi', $file_conent, $m)) {
						if (preg_match('#<name>(.+)</name>#i', $file_conent, $m)) $row->name = $m[1];
						if (preg_match('#<version>(.+)</version>#i', $file_conent, $m)) $row->version = $m[1];
						if (preg_match('#<authorUrl>(.+)</authorUrl>#i', $file_conent, $m)) $row->url = $m[1];
						if ($row->url and preg_match('/www\.joomla\.org/i', $row->url)) $row->iscore = 1;
						$result[] = $row;
						break;
					}
				}
			}
		}
		/* load plugins */
		$db->setQuery('SELECT name, element, folder FROM #__extensions WHERE `type` = \'plugin\'');
		if ($etxs = $db->loadObjectList()) foreach ($etxs as $ext) {
			$row = new stdclass;
			$row->iscore = false;
			$row->name = $ext->name;
			$row->version = '';
			$row->url = '';
			$row->is_legacy = false;
			$row->legacy_cms = '';
			$row->type = $ext->folder.' plugin';
			$row->extension = $ext->folder.'/'.$ext->element;

			$path = JPATH_SITE.'/plugins/'.$ext->folder.'/'.$ext->element.'/'.$ext->element.'.xml';
			if (file_exists($path)) {
				$file_conent = file_get_contents($path);
				if (preg_match('#<(.*)(install|extension).*type="plugin"#msi', $file_conent, $m)) {
					if ($m[1] == 'mos') {
						$row->is_legacy = true;
						$row->legacy_cms = 'Joomla 1.0';
					}
					if (preg_match('#<name>(.+)</name>#i', $file_conent, $m)) $row->name = $m[1];
					if (preg_match('#<version>(.+)</version>#i', $file_conent, $m)) $row->version = $m[1];
					if (preg_match('#<authorUrl>(.+)</authorUrl>#i', $file_conent, $m)) $row->url = $m[1];
					if ($row->url and preg_match('/www\.joomla\.org/i', $row->url)) $row->iscore = 1;
					$result[] = $row;
				}
			}
		}
		/* load templates */
		$db->setQuery('SELECT DISTINCT template, client_id FROM #__template_styles');
		if ($etxs = $db->loadObjectList()) foreach ($etxs as $ext) {
			$row = new stdclass;
			$row->iscore = 0;
			$row->name = $ext->template;
			$row->version = '';
			$row->url = '';
			$row->is_legacy = false;
			$row->legacy_cms = '';
			$row->type = $ext->client_id?'admin template':'frontend template';
			$row->extension = $ext->template;

			$folder = ($ext->client_id?JPATH_ADMINISTRATOR:JPATH_SITE).'/templates/'.$ext->template.'/';
			if (file_exists($folder)) {
				if ($xml_files = JFolder :: files($folder, '\.xml$')) foreach ($xml_files as $xml_file) {
					$file_conent = file_get_contents($folder.$xml_file);
					if (preg_match('#<(.*)(install|extension).*type="template"#msi', $file_conent, $m)) {
						if ($m[1] == 'mos') {
							$row->is_legacy = true;
							$row->legacy_cms = 'Joomla 1.0';
						}
						if (preg_match('#<name>(.+)</name>#i', $file_conent, $m)) $row->name = $m[1];
						if (preg_match('#<version>(.+)</version>#i', $file_conent, $m)) $row->version = $m[1];
						if (preg_match('#<authorUrl>(.+)</authorUrl>#i', $file_conent, $m)) $row->url = $m[1];
						if ($row->url and preg_match('/www\.joomla\.org/i', $row->url)) $row->iscore = 1;
						$result[] = $row;
						break;
					}
				}
			}
		}

		return $result;
	}
}
?>
Return current item: Joomla Site Monitor