<?php
// no direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.form.formfield');

class JFormFieldUpdate extends JFormField {
	protected $type = 'Update';

	protected function getInput() {

		if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
		$base_path = str_replace('admin'.DS.'elements', '', dirname(__FILE__)).'\templateDetails.xml';
		$file_handle = fopen($base_path, "r");
		
		if (FALSE === $file_handle) {
			$version = '1.0.4';
			return '<div id="template_updates" data-version="'.$version.'"></div>';
		}

		$data = fread($file_handle, 2048);
		preg_match('/<version>.*<\/version>/i', $data, $version);
		$version[0] = str_replace('<version>', '', $version[0]);
		$version[0] = str_replace('</version>', '', $version[0]);

		return '<div id="template_updates" data-version="'.$version[0].'"></div>';
	}
}