english/administrator/components/com_templates/models/source.php
/**
	 * Method to store the source file contents.
	 *
	 * @param	array	The souce data to save.
	 *
	 * @return	boolean	True on success, false otherwise and internal error set.
	 * @since	1.6
	 */
Method to store the source file contents.
@param       array   The souce data to save.

@return      boolean True on success, false otherwise and internal error set.
Method to store the source file contents . @param array The souce data to save . @return boolean True on success false otherwise and internal error set .
public function save($data)
	{
		jimport('joomla.filesystem.file');
		jimport('joomla.client.helper');
		$template = $this->getTemplate();
		if (empty($template)) {
			return false;
		}
		$dispatcher = JDispatcher::getInstance();
		$fileName	= $this->getState('filename');
		$client		= JApplicationHelper::getClientInfo($template->client_id);
		$filePath	= JPath::clean($client->path.'/templates/'.$template->element.'/'.$fileName);
		JPluginHelper::importPlugin('extension');
		JClientHelper::setCredentialsFromRequest('ftp');
		$ftp = JClientHelper::getCredentials('ftp');
		if (!$ftp['enabled'] && JPath::isOwner($filePath) && !JPath::setPermissions($filePath, '0644')) {
			$this->setError(JText::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_WRITABLE'));
			return false;
		}
		$result = $dispatcher->trigger('onExtensionBeforeSave', array('com_templates.source', &$data, false));
		if (in_array(false, $result, true)) {
			$this->setError($table->getError());
			return false;
		}
		$return = JFile::write($filePath, $data['source']);
		if (!$ftp['enabled'] && JPath::isOwner($filePath) && !JPath::setPermissions($filePath, '0444')) {
			$this->setError(JText::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_UNWRITABLE'));
			return false;
		} else if (!$return) {
			$this->setError(JText::sprintf('COM_TEMPLATES_ERROR_FAILED_TO_SAVE_FILENAME', $fileName));
			return false;
		}
		$dispatcher->trigger('onExtensionAfterSave', array('com_templates.source', &$table, false));
		return true;
	}
public function save ( $ data ) { jimport ( 'joomla.filesystem.file' ) ; jimport ( 'joomla.client.helper' ) ; $ template = $ this -> getTemplate ( ) ; if ( empty ( $ template ) ) { return false ; } $ dispatcher = JDispatcher :: getInstance ( ) ; $ fileName = $ this -> getState ( 'filename' ) ; $ client = JApplicationHelper :: getClientInfo ( $ template -> client_id ) ; $ filePath = JPath :: clean ( $ client -> path . '/templates/' . $ template -> element . '/' . $ fileName ) ; JPluginHelper :: importPlugin ( 'extension' ) ; JClientHelper :: setCredentialsFromRequest ( 'ftp' ) ; $ ftp = JClientHelper :: getCredentials ( 'ftp' ) ; if ( ! $ ftp [ 'enabled' ] && JPath :: isOwner ( $ filePath ) && ! JPath :: setPermissions ( $ filePath , '0644' ) ) { $ this -> setError ( JText :: _ ( 'COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_WRITABLE' ) ) ; return false ; } $ result = $ dispatcher -> trigger ( 'onExtensionBeforeSave' , array ( 'com_templates.source' , & $ data , false ) ) ; if ( in_array ( false , $ result , true ) ) { $ this -> setError ( $ table -> getError ( ) ) ; return false ; } $ return = JFile :: write ( $ filePath , $ data [ 'source' ] ) ; if ( ! $ ftp [ 'enabled' ] && JPath :: isOwner ( $ filePath ) && ! JPath :: setPermissions ( $ filePath , '0444' ) ) { $ this -> setError ( JText :: _ ( 'COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_UNWRITABLE' ) ) ; return false ; } else if ( ! $ return ) { $ this -> setError ( JText :: sprintf ( 'COM_TEMPLATES_ERROR_FAILED_TO_SAVE_FILENAME' , $ fileName ) ) ; return false ; } $ dispatcher -> trigger ( 'onExtensionAfterSave' , array ( 'com_templates.source' , & $ table , false ) ) ; return true ; }
Method to store the source file contents.
Method to store the source file contents .
// Get the template. // Include the extension plugins for the save events. // Set FTP credentials, if given. // Try to make the template file writeable. // Trigger the onExtensionBeforeSave event. // Try to make the template file unwriteable. // Trigger the onExtensionAfterSave event.