public function addTemplateEntry($element, $name=null, $client=1, $enabled=1, $home=0, $styles=null, $protected=0)
	{
		if ($this->baseDb->tableExists('#__extensions'))
		{
			if (!isset($name))
			{
				if (substr($element, 0, 4) == 'tpl_')
				{
					$name    = substr($element, 4);
					$element = $name;
				}
				else
				{
					$name = $element;
				}

				$name = ucwords($name);
			}

			// First, see if it already exists
			$query = "SELECT `extension_id` FROM `#__extensions` WHERE `type` = 'template' AND (`element` = '{$element}' OR `element` LIKE '{$name}') AND `client_id` = '{$client}'";
			$this->baseDb->setQuery($query);

			if (!$this->baseDb->loadResult())
			{
				$query  = "INSERT INTO `#__extensions` (`name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `ordering`, `state`)";
				$query .= " VALUES ('{$name}', 'template', '{$element}', '', '{$client}', '{$enabled}', '1', '{$protected}', '{}', '{}', '', '', '0', '0', '0')";
				$this->baseDb->setQuery($query);
				$this->baseDb->query();

				$this->log(sprintf('Added extension entry for template "%s"', $element));

				if ($this->baseDb->tableExists('#__template_styles'))
				{
					// If we're setting this template to be default, disable others first
					if ($home)
					{
						$query = "UPDATE `#__template_styles` SET `home` = 0 WHERE `client_id` = '{$client}'";
						$this->baseDb->setQuery($query);
						$this->baseDb->query();

						$this->log(sprintf('Disabling "home" for all other templates (client "%s")', $client));
					}

					$query  = "INSERT INTO `#__template_styles` (`template`, `client_id`, `home`, `title`, `params`)";
					$query .= " VALUES ('{$element}', '{$client}', '{$home}', '{$name}', " . ((isset($styles)) ? $this->baseDb->quote(json_encode($styles)) : "'{}'") . ")";
					$this->baseDb->setQuery($query);
					$this->baseDb->query();

					$this->log(sprintf('Added style entry for template "%s"', $element));
				}
			}
			else
			{
				$this->log(sprintf('Extension entry already exists for template "%s"', $element));
			}

			return true;
		}

		$this->log(sprintf('Required table not found for adding template "%s"', $element), 'warning');

		return false;
	}
public function addTemplateEntry($element, $name=null, $client=1, $enabled=1, $home=0, $styles=null, $protected=0)
	{
		if ($this->baseDb->tableExists('#__extensions'))
		{
			if (!isset($name))
			{
				if (substr($element, 0, 4) == 'tpl_')
				{
					$name    = substr($element, 4);
					$element = $name;
				}
				else
				{
					$name = $element;
				}

				$name = ucwords($name);
			}

			// First, see if it already exists
			$query = "SELECT `extension_id` FROM `#__extensions` WHERE `type` = 'template' AND (`element` = '{$element}' OR `element` LIKE '{$name}') AND `client_id` = '{$client}'";
			$this->baseDb->setQuery($query);

			if (!$this->baseDb->loadResult())
			{
				$query  = "INSERT INTO `#__extensions` (`name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `ordering`, `state`)";
				$query .= " VALUES ('{$name}', 'template', '{$element}', '', '{$client}', '{$enabled}', '1', '{$protected}', '{}', '{}', '', '', '0', '0', '0')";
				$this->baseDb->setQuery($query);
				$this->baseDb->query();

				$this->log(sprintf('Added extension entry for template "%s"', $element));

				if ($this->baseDb->tableExists('#__template_styles'))
				{
					// If we're setting this template to be default, disable others first
					if ($home)
					{
						$query = "UPDATE `#__template_styles` SET `home` = 0 WHERE `client_id` = '{$client}'";
						$this->baseDb->setQuery($query);
						$this->baseDb->query();

						$this->log(sprintf('Disabling "home" for all other templates (client "%s")', $client));
					}

					$query  = "INSERT INTO `#__template_styles` (`template`, `client_id`, `home`, `title`, `params`)";
					$query .= " VALUES ('{$element}', '{$client}', '{$home}', '{$name}', " . ((isset($styles)) ? $this->baseDb->quote(json_encode($styles)) : "'{}'") . ")";
					$this->baseDb->setQuery($query);
					$this->baseDb->query();

					$this->log(sprintf('Added style entry for template "%s"', $element));
				}
			}
			else
			{
				$this->log(sprintf('Extension entry already exists for template "%s"', $element));
			}

			return true;
		}

		$this->log(sprintf('Required table not found for adding template "%s"', $element), 'warning');

		return false;
	}
public function addTemplateEntry ( $ element , $ name = null , $ client = 1 , $ enabled = 1 , $ home = 0 , $ styles = null , $ protected = 0 ) { if ( $ this -> baseDb -> tableExists ( '#__extensions' ) ) { if ( ! isset ( $ name ) ) { if ( substr ( $ element , 0 , 4 ) == 'tpl_' ) { $ name = substr ( $ element , 4 ) ; $ element = $ name ; } else { $ name = $ element ; } $ name = ucwords ( $ name ) ; } // First, see if it already exists $ query = "SELECT `extension_id` FROM `#__extensions` WHERE `type` = 'template' AND (`element` = '{$element}' OR `element` LIKE '{$name}') AND `client_id` = '{$client}'" ; $ this -> baseDb -> setQuery ( $ query ) ; if ( ! $ this -> baseDb -> loadResult ( ) ) { $ query = "INSERT INTO `#__extensions` (`name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `ordering`, `state`)" ; $ query .= " VALUES ('{$name}', 'template', '{$element}', '', '{$client}', '{$enabled}', '1', '{$protected}', '{}', '{}', '', '', '0', '0', '0')" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Added extension entry for template "%s"' , $ element ) ) ; if ( $ this -> baseDb -> tableExists ( '#__template_styles' ) ) { // If we're setting this template to be default, disable others first if ( $ home ) { $ query = "UPDATE `#__template_styles` SET `home` = 0 WHERE `client_id` = '{$client}'" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Disabling "home" for all other templates (client "%s")' , $ client ) ) ; } $ query = "INSERT INTO `#__template_styles` (`template`, `client_id`, `home`, `title`, `params`)" ; $ query .= " VALUES ('{$element}', '{$client}', '{$home}', '{$name}', " . ( ( isset ( $ styles ) ) ? $ this -> baseDb -> quote ( json_encode ( $ styles ) ) : "'{}'" ) . ")" ; $ this -> baseDb -> setQuery ( $ query ) ; $ this -> baseDb -> query ( ) ; $ this -> log ( sprintf ( 'Added style entry for template "%s"' , $ element ) ) ; } } else { $ this -> log ( sprintf ( 'Extension entry already exists for template "%s"' , $ element ) ) ; } return true ; } $ this -> log ( sprintf ( 'Required table not found for adding template "%s"' , $ element ) , 'warning' ) ; return false ; }
Add, as needed, templates to the CMS

@param   string  $element    Template element
@param   string  $name       Template name
@param   int     $client     Admin or site client
@param   int     $enabled    Whether or not the template should be enabled
@param   int     $home       Whether or not this should become the enabled template
@param   array   $styles     Template styles
@param   int     $protected  Whether or not the template is a core one or not
@return  bool
Add as needed templates to the CMS