-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
newsfeed.php
203 lines (170 loc) · 5.65 KB
/
newsfeed.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
195
196
197
198
199
200
201
202
203
<?php
/**
* @package Joomla.Administrator
* @subpackage com_newsfeeds
*
* @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 newsfeeds picker.
*
* @since 1.6
*/
class JFormFieldModal_Newsfeed extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'Modal_Newsfeed';
/**
* 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_newsfeeds', JPATH_ADMINISTRATOR);
// Load the javascript
JHtml::_('bootstrap.tooltip');
// Build the script.
$script = array();
// Select button script
$script[] = ' function jSelectNewsfeed_' . $this->id . '(id, name, object) {';
$script[] = ' document.getElementById("' . $this->id . '_id").value = id;';
$script[] = ' document.getElementById("' . $this->id . '_name").value = name;';
if ($allowEdit)
{
$script[] = ' jQuery("#' . $this->id . '_edit").removeClass("hidden");';
}
if ($allowClear)
{
$script[] = ' jQuery("#' . $this->id . '_clear").removeClass("hidden");';
}
$script[] = ' jQuery("#modalNewsfeed").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 jClearNewsfeed(id) {';
$script[] = ' document.getElementById(id + "_id").value = "";';
$script[] = ' document.getElementById(id + "_name").value = "' .
htmlspecialchars(JText::_('COM_NEWSFEEDS_SELECT_A_FEED', 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_newsfeeds&view=newsfeeds&layout=modal&tmpl=component&function=jSelectNewsfeed_' . $this->id;
if (isset($this->element['language']))
{
$link .= '&forcedLanguage=' . $this->element['language'];
}
// Get the title of the linked chart
if ((int) $this->value > 0)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('name'))
->from($db->quoteName('#__newsfeeds'))
->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_NEWSFEEDS_SELECT_A_FEED');
}
$title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
// The active newsfeed id field.
if (0 == (int) $this->value)
{
$value = '';
}
else
{
$value = (int) $this->value;
}
// The current newsfeed 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="#modalNewsfeed" class="btn hasTooltip" role="button" data-toggle="modal"'
. ' title="' . JHtml::tooltipText('COM_NEWSFEEDS_CHANGE_FEED_BUTTON') . '">'
. '<span class="icon-file"></span> ' . JText::_('JSELECT')
. '</a>';
$html[] = JHtmlBootstrap::renderModal(
'modalNewsfeed', array(
'url' => $link . '&' . JSession::getFormToken() . '=1"',
'title' => JText::_('COM_NEWSFEEDS_CHANGE_FEED_BUTTON'),
'width' => '800px',
'height' => '300px',
'footer' => '<button class="btn" data-dismiss="modal" aria-hidden="true">'
. JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '</button>'
)
);
// Edit newsfeed button
if ($allowEdit)
{
$html[] = '<a class="btn hasTooltip' . ($value ? '' : ' hidden') .
'" href="index.php?option=com_newsfeeds&layout=modal&tmpl=component&task=newsfeed.edit&id=' . $value .
'" target="_blank" title="' . JHtml::tooltipText('COM_NEWSFEEDS_EDIT_NEWSFEED') .
'" ><span class="icon-edit"></span>' . JText::_('JACTION_EDIT') . '</a>';
}
// Clear newsfeed button
if ($allowClear)
{
$html[] = '<button id="' . $this->id . '_clear" class="btn' . ($value ? '' : ' hidden') . '" onclick="return jClearNewsfeed(\'' .
$this->id . '\')"><span class="icon-remove"></span>' . JText::_('JCLEAR') . '</button>';
}
$html[] = '</span>';
// 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 . '" />';
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());
}
}