CoreFiles by mySites.guru
media.php67 lines, 1,649 bytes, from Joomla_3.7.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 3.7.0-alpha1
md5
2a75de3de0b94d51778d5585cb83b52a
sha1
0a5e73315b3603e628a35c2f2dba757da6698d8f
sha256
18afed535ccf24f618dea3d7d1d638e143531964948f0ab5b2b5065aadcb3a0a
<?php
/**
 * @package     Joomla.Plugin
 * @subpackage  Fields.Media
 *
 * @copyright   Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR);

/**
 * Fields Media Plugin
 *
 * @since  3.7.0
 */
class PlgFieldsMedia extends FieldsPlugin
{
	/**
	 * Transforms the field into an XML element and appends it as child on the given parent. This
	 * is the default implementation of a field. Form fields which do support to be transformed into
	 * an XML Element mut implemet the JFormDomfieldinterface.
	 *
	 * @param   stdClass    $field   The field.
	 * @param   DOMElement  $parent  The field node parent.
	 * @param   JForm       $form    The form.
	 *
	 * @return  DOMElement
	 *
	 * @since   3.7.0
	 */
	public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form)
	{
		$fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form);

		if (!$fieldNode)
		{
			return $fieldNode;
		}

		$fieldNode->setAttribute('hide_default', 'true');

		if ($field->fieldparams->get('home'))
		{
			$userName = JFactory::getUser()->username;
			$root     = $field->fieldparams->get('directory');

			if (!$root)
			{
				$root = 'images';
			}

			$directory = JPATH_ROOT . '/images/' . $root . '/' . $userName;

			if (!JFolder::exists($directory))
			{
				JFolder::create($directory);
			}

			$fieldNode->setAttribute('directory', str_replace(JPATH_ROOT . '/images', '', $directory));
		}

		return $fieldNode;
	}
}

The same content is in 4 releases, Joomla 3.7.0-alpha2 to 3.7.0-beta3. See them all, or every version of this file.