view.html.php
7 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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
/**
* @package Joomla.Administrator
* @subpackage com_templates
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* View to edit a template style.
*
* @since 1.6
*/
class TemplatesViewTemplate extends JViewLegacy
{
/**
* For loading extension state
*/
protected $state;
/**
* For loading template details
*/
protected $template;
/**
* For loading the source form
*/
protected $form;
/**
* For loading source file contents
*/
protected $source;
/**
* Extension id
*/
protected $id;
/**
* Encrypted file path
*/
protected $file;
/**
* List of available overrides
*/
protected $overridesList;
/**
* Name of the present file
*/
protected $fileName;
/**
* Type of the file - image, source, font
*/
protected $type;
/**
* For loading image information
*/
protected $image;
/**
* Template id for showing preview button
*/
protected $preview;
/**
* For loading font information
*/
protected $font;
/**
* A nested array containing lst of files and folders
*/
protected $files;
/**
* An array containing a list of compressed files
*/
protected $archive;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
$app = JFactory::getApplication();
$this->file = $app->input->get('file');
$this->fileName = JFilterInput::getInstance()->clean(base64_decode($this->file), 'string');
$explodeArray = explode('.', $this->fileName);
$ext = end($explodeArray);
$this->files = $this->get('Files');
$this->state = $this->get('State');
$this->template = $this->get('Template');
$this->preview = $this->get('Preview');
$params = JComponentHelper::getParams('com_templates');
$imageTypes = explode(',', $params->get('image_formats'));
$sourceTypes = explode(',', $params->get('source_formats'));
$fontTypes = explode(',', $params->get('font_formats'));
$archiveTypes = explode(',', $params->get('compressed_formats'));
if (in_array($ext, $sourceTypes))
{
$this->form = $this->get('Form');
$this->form->setFieldAttribute('source', 'syntax', $ext);
$this->source = $this->get('Source');
$this->type = 'file';
}
elseif (in_array($ext, $imageTypes))
{
$this->image = $this->get('Image');
$this->type = 'image';
}
elseif (in_array($ext, $fontTypes))
{
$this->font = $this->get('Font');
$this->type = 'font';
}
elseif (in_array($ext, $archiveTypes))
{
$this->archive = $this->get('Archive');
$this->type = 'archive';
}
else
{
$this->type = 'home';
}
$this->overridesList = $this->get('OverridesList');
$this->id = $this->state->get('extension.id');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
$app->enqueueMessage(implode("\n", $errors));
return false;
}
$this->addToolbar();
if (!JFactory::getUser()->authorise('core.admin'))
{
$this->setLayout('readonly');
}
return parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @since 1.6
*
* @return void
*/
protected function addToolbar()
{
$app = JFactory::getApplication();
$user = JFactory::getUser();
$app->input->set('hidemainmenu', true);
// User is global SuperUser
$isSuperUser = $user->authorise('core.admin');
// Get the toolbar object instance
$bar = JToolbar::getInstance('toolbar');
$explodeArray = explode('.', $this->fileName);
$ext = end($explodeArray);
JToolbarHelper::title(JText::sprintf('COM_TEMPLATES_MANAGER_VIEW_TEMPLATE', ucfirst($this->template->name)), 'eye thememanager');
// Only show file edit buttons for global SuperUser
if ($isSuperUser)
{
// Add an Apply and save button
if ($this->type == 'file')
{
JToolbarHelper::apply('template.apply');
JToolbarHelper::save('template.save');
}
// Add a Crop and Resize button
elseif ($this->type == 'image')
{
JToolbarHelper::custom('template.cropImage', 'move', 'move', 'COM_TEMPLATES_BUTTON_CROP', false);
JToolbarHelper::modal('resizeModal', 'icon-refresh', 'COM_TEMPLATES_BUTTON_RESIZE');
}
// Add an extract button
elseif ($this->type == 'archive')
{
JToolbarHelper::custom('template.extractArchive', 'arrow-down', 'arrow-down', 'COM_TEMPLATES_BUTTON_EXTRACT_ARCHIVE', false);
}
// Add a copy template button (Hathor override doesn't need the button)
if ($app->getTemplate() != 'hathor')
{
JToolbarHelper::modal('copyModal', 'icon-copy', 'COM_TEMPLATES_BUTTON_COPY_TEMPLATE');
}
}
// Add a Template preview button
if ($this->preview->client_id == 0)
{
$bar->appendButton('Popup', 'picture', 'COM_TEMPLATES_BUTTON_PREVIEW', JUri::root() . 'index.php?tp=1&templateStyle=' . $this->preview->id, 800, 520);
}
// Only show file manage buttons for global SuperUser
if ($isSuperUser)
{
// Add Manage folders button
JToolbarHelper::modal('folderModal', 'icon-folder icon white', 'COM_TEMPLATES_BUTTON_FOLDERS');
// Add a new file button
JToolbarHelper::modal('fileModal', 'icon-file', 'COM_TEMPLATES_BUTTON_FILE');
// Add a Rename file Button (Hathor override doesn't need the button)
if ($app->getTemplate() != 'hathor' && $this->type != 'home')
{
JToolbarHelper::modal('renameModal', 'icon-refresh', 'COM_TEMPLATES_BUTTON_RENAME_FILE');
}
// Add a Delete file Button
if ($this->type != 'home')
{
JToolbarHelper::modal('deleteModal', 'icon-remove', 'COM_TEMPLATES_BUTTON_DELETE_FILE');
}
// Add a Compile Button
if ($ext == 'less')
{
JToolbarHelper::custom('template.less', 'play', 'play', 'COM_TEMPLATES_BUTTON_LESS', false);
}
}
if ($this->type == 'home')
{
JToolbarHelper::cancel('template.cancel', 'JTOOLBAR_CLOSE');
}
else
{
JToolbarHelper::cancel('template.close', 'COM_TEMPLATES_BUTTON_CLOSE_FILE');
}
JToolbarHelper::divider();
JToolbarHelper::help('JHELP_EXTENSIONS_TEMPLATE_MANAGER_TEMPLATES_EDIT');
}
/**
* Method for creating the collapsible tree.
*
* @param array $array The value of the present node for recursion
*
* @return string
*
* @note Uses recursion
* @since 3.2
*/
protected function directoryTree($array)
{
$temp = $this->files;
$this->files = $array;
$txt = $this->loadTemplate('tree');
$this->files = $temp;
return $txt;
}
/**
* Method for listing the folder tree in modals.
*
* @param array $array The value of the present node for recursion
*
* @return string
*
* @note Uses recursion
* @since 3.2
*/
protected function folderTree($array)
{
$temp = $this->files;
$this->files = $array;
$txt = $this->loadTemplate('folders');
$this->files = $temp;
return $txt;
}
}