-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
article.php
194 lines (164 loc) · 5.49 KB
/
article.php
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/**
* @package Joomla.Administrator
* @subpackage com_content
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_BASE') or die;
/**
* Supports a modal article picker.
*
* @since 1.6
*/
class JFormFieldModal_Article extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'Modal_Article';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 1.6
*/
protected function getInput()
{
$allowEdit = ((string) $this->element['edit'] == 'true') ? true : false;
$allowClear = ((string) $this->element['clear'] != 'false') ? true : false;
// Load language
JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR);
// Build the script.
$script = array();
// Select button script
$script[] = ' function jSelectArticle_' . $this->id . '(id, title, catid, object) {';
$script[] = ' document.getElementById("' . $this->id . '_id").value = id;';
$script[] = ' document.getElementById("' . $this->id . '_name").value = title;';
if ($allowEdit)
{
$script[] = ' jQuery("#' . $this->id . '_edit").removeClass("hidden");';
}
if ($allowClear)
{
$script[] = ' jQuery("#' . $this->id . '_clear").removeClass("hidden");';
}
$script[] = ' jQuery("#modalArticle").modal("hide");';
if ($this->required)
{
$script[] = ' document.formvalidator.validate(document.getElementById("' . $this->id . '_id"));';
$script[] = ' document.formvalidator.validate(document.getElementById("' . $this->id . '_name"));';
}
$script[] = ' }';
// Clear button script
static $scriptClear;
if ($allowClear && !$scriptClear)
{
$scriptClear = true;
$script[] = ' function jClearArticle(id) {';
$script[] = ' document.getElementById(id + "_id").value = "";';
$script[] = ' document.getElementById(id + "_name").value = "' .
htmlspecialchars(JText::_('COM_CONTENT_SELECT_AN_ARTICLE', true), ENT_COMPAT, 'UTF-8') . '";';
$script[] = ' jQuery("#"+id + "_clear").addClass("hidden");';
$script[] = ' if (document.getElementById(id + "_edit")) {';
$script[] = ' jQuery("#"+id + "_edit").addClass("hidden");';
$script[] = ' }';
$script[] = ' return false;';
$script[] = ' }';
}
// Add the script to the document head.
JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
// Setup variables for display.
$html = array();
$link = 'index.php?option=com_content&view=articles&layout=modal&tmpl=component&function=jSelectArticle_' . $this->id;
if (isset($this->element['language']))
{
$link .= '&forcedLanguage=' . $this->element['language'];
}
if ((int) $this->value > 0)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__content'))
->where($db->quoteName('id') . ' = ' . (int) $this->value);
$db->setQuery($query);
try
{
$title = $db->loadResult();
}
catch (RuntimeException $e)
{
JError::raiseWarning(500, $e->getMessage());
}
}
if (empty($title))
{
$title = JText::_('COM_CONTENT_SELECT_AN_ARTICLE');
}
$title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
// The active article id field.
if (0 == (int) $this->value)
{
$value = '';
}
else
{
$value = (int) $this->value;
}
$url = $link . '&' . JSession::getFormToken() . '=1';
// The current article display field.
$html[] = '<span class="input-append">';
$html[] = '<input type="text" class="input-medium" id="' . $this->id . '_name" value="' . $title . '" disabled="disabled" size="35" />';
$html[] = '<a href="#modalArticle" class="btn hasTooltip" role="button" data-toggle="modal" title="'
. JHtml::tooltipText('COM_CONTENT_CHANGE_ARTICLE') . '">'
. '<span class="icon-file"></span> '
. JText::_('JSELECT') . '</a>';
// Edit article button
if ($allowEdit)
{
$html[] = '<a class="btn hasTooltip' . ($value ? '' : ' hidden') . '" href="index.php?option=com_content&layout=modal&tmpl=component&task=article.edit&id=' . $value . '" target="_blank" title="' . JHtml::tooltipText('COM_CONTENT_EDIT_ARTICLE') . '" ><span class="icon-edit"></span>' . JText::_('JACTION_EDIT') . '</a>';
}
// Clear article button
if ($allowClear)
{
$html[] = '<button id="' . $this->id . '_clear" class="btn' . ($value ? '' : ' hidden') . '" onclick="return jClearArticle(\'' .
$this->id . '\')"><span class="icon-remove"></span>' . JText::_('JCLEAR') . '</button>';
}
$html[] = '</span>';
// The class='required' for client side validation
$class = '';
if ($this->required)
{
$class = ' class="required modal-value"';
}
$html[] = '<input type="hidden" id="' . $this->id . '_id"' . $class . ' name="' . $this->name . '" value="' . $value . '" />';
$html[] = JHtmlBootstrap::renderModal(
'modalArticle', array(
'url' => $url,
'title' => JText::_('COM_CONTENT_CHANGE_ARTICLE'),
'width' => '800px',
'height' => '300px',
'footer' => '<button class="btn" data-dismiss="modal" aria-hidden="true">'
. JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '</button>'
)
);
return implode("\n", $html);
}
/**
* Method to get the field label markup.
*
* @return string The field label markup.
*
* @since 3.4
*/
protected function getLabel()
{
return str_replace($this->id, $this->id . '_id', parent::getLabel());
}
}