mediajce.php
2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* @package JCE
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @copyright Copyright (C) 2017 Ryan Demmer All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_PLATFORM') or die;
/**
* Provides a modal media selector field for the JCE File Browser
*
* @since 2.6.17
*/
class JFormFieldMediaJce extends JFormFieldMedia
{
/**
* The form field type.
*
* @var string
*/
protected $type = 'MediaJce';
/**
* Method to attach a JForm object to the field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see JFormField::setup()
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result === true) {
$this->mediatype = isset($this->element['mediatype']) ? (string) $this->element['mediatype'] : 'images';
}
return $result;
}
/**
* Get the data that is going to be passed to the layout
*
* @return array
*/
public function getLayoutData()
{
// Include jQuery
JHtml::_('jquery.framework');
$document = JFactory::getDocument();
$document->addScript(JURI::root(true) . '/plugins/system/jce/js/media.js', array('version' => 'auto'));
$document->addStyleSheet(JURI::root(true) . '/plugins/system/jce/css/media.css', array('version' => 'auto'));
require_once JPATH_ADMINISTRATOR . '/components/com_jce/helpers/browser.php';
$options = WFBrowserHelper::getMediaFieldOptions(array(
'element' => $this->id,
'filter' => $this->mediatype,
'converted' => (int) $this->element['converted'] ? true : false
));
$this->link = $options['url'];
// Get the basic field data
$data = parent::getLayoutData();
// not a valid file browser link
if (!$this->link) {
return $data;
}
$extraData = array(
'link' => $this->link,
'class' => $this->element['class'] . ' input-medium wf-media-input'
);
if ($options['upload'] === 1) {
$extraData['class'] .= ' wf-media-input-upload';
}
return array_merge($data, $extraData);
}
}