This repository has been archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
tiki-admin_content_templates.php
298 lines (281 loc) · 10.9 KB
/
tiki-admin_content_templates.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
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
<?php
/**
* @package tikiwiki
*/
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
$section = 'admin';
require_once('tiki-setup.php');
$access->check_feature(['feature_wiki_templates','feature_cms_templates','feature_file_galleries_templates'], '', 'features', true);
$templateslib = TikiLib::lib('template');
$auto_query_args = ['templateId'];
//get_strings tra('Content Templates')
if (! isset($_REQUEST["templateId"])) {
$_REQUEST["templateId"] = 0;
}
$smarty->assign('templateId', $_REQUEST["templateId"]);
if ($_REQUEST["templateId"]) {
$info = $templateslib->get_template($_REQUEST["templateId"]);
if ($templateslib->template_is_in_section($_REQUEST["templateId"], 'html')) {
$info["section_html"] = 'y';
} else {
$info["section_html"] = 'n';
}
if ($templateslib->template_is_in_section($_REQUEST["templateId"], 'wiki')) {
$info["section_wiki"] = 'y';
} else {
$info["section_wiki"] = 'n';
}
if ($templateslib->template_is_in_section($_REQUEST["templateId"], 'wiki_html')) {
$info["section_wiki_html"] = 'y';
} else {
$info["section_wiki_html"] = 'n';
}
if ($templateslib->template_is_in_section($_REQUEST["templateId"], 'file_galleries')) {
$info["section_file_galleries"] = 'y';
} else {
$info["section_file_galleries"] = 'n';
}
if ($templateslib->template_is_in_section($_REQUEST["templateId"], 'newsletters')) {
$info["section_newsletters"] = 'y';
} else {
$info["section_newsletters"] = 'n';
}
if ($templateslib->template_is_in_section($_REQUEST["templateId"], 'events')) {
$info["section_events"] = 'y';
} else {
$info["section_events"] = 'n';
}
if ($templateslib->template_is_in_section($_REQUEST["templateId"], 'admins')) {
$info["section_admins"] = 'y';
} else {
$info["section_admin"] = 'n';
}
if ($templateslib->template_is_in_section($_REQUEST["templateId"], 'cms')) {
$info["section_cms"] = 'y';
} else {
$info["section_cms"] = 'n';
}
} else {
$info = [];
$info["name"] = '';
$info['template_type'] = 'static';
$info["content"] = '';
$info["section_cms"] = 'n';
$info["section_html"] = 'n';
$info["section_wiki"] = 'n';
$info["section_wiki_html"] = 'n';
$info["section_file_galleries"] = 'n';
$info["section_newsletters"] = 'n';
$info["section_event"] = 'n';
}
$cat_type = 'template';
$cat_objid = $_REQUEST['templateId'];
include_once("categorize_list.php");
$smarty->assign_by_ref('info', $info);
if (isset($_REQUEST["remove"])) {
$access->check_authenticity();
$templateslib->remove_template($_REQUEST["remove"]);
}
if (isset($_REQUEST["removesection"])) {
$access->check_authenticity();
$templateslib->remove_template_from_section($_REQUEST["rtemplateId"], $_REQUEST["removesection"]);
}
$smarty->assign('preview', 'n');
if (isset($_REQUEST["preview"])) {
TikiLib::lib('access')->check_permission('edit_content_templates', 'Edit template', 'template', $_REQUEST['templateId']);
$smarty->assign('preview', 'y');
if (isset($_REQUEST["section_html"]) && $_REQUEST["section_html"] == 'on') {
$info["section_html"] = 'y';
$parsed = nl2br($_REQUEST["content"]);
} else {
$info["section_html"] = 'n';
$parsed = TikiLib::lib('parser')->parse_data($_REQUEST["content"], ['is_html' => $info['section_wiki_html'] === 'y']);
}
$smarty->assign('parsed', $parsed);
if (isset($_REQUEST["section_wiki"]) && $_REQUEST["section_wiki"] == 'on') {
$info["section_wiki"] = 'y';
} else {
$info["section_wiki"] = 'n';
}
if (isset($_REQUEST["section_file_galleries"]) && $_REQUEST["section_file_galleries"] == 'on') {
$info["section_file_galleries"] = 'y';
} else {
$info["section_file_galleries"] = 'n';
}
if (isset($_REQUEST["section_newsletters"]) && $_REQUEST["section_newsletters"] == 'on') {
$info["section_newsletters"] = 'y';
} else {
$info["section_newsletters"] = 'n';
}
if (isset($_REQUEST["section_events"]) && $_REQUEST["section_events"] == 'on') {
$info["section_events"] = 'y';
} else {
$info["section_events"] = 'n';
}
if (isset($_REQUEST["section_cms"]) && $_REQUEST["section_cms"] == 'on') {
$info["section_cms"] = 'y';
} else {
$info["section_cms"] = 'n';
}
$info["content"] = $_REQUEST["content"];
$info["name"] = $_REQUEST["name"];
$info['page_name'] = $_REQUEST['page_name'];
$info['template_type'] = $_REQUEST['template_type'];
$smarty->assign('info', $info);
$cookietab = 2;
}
if (isset($_REQUEST["save"])) {
check_ticket('admin-content-templates');
$type = $_REQUEST['template_type'];
if ($type == 'page') {
$content = 'page:' . $_REQUEST['page_name'];
} else {
$content = $_REQUEST["content"];
}
if (isset($_REQUEST["name"]) && $_REQUEST["name"] != "") {
$tid = $templateslib->replace_template($_REQUEST["templateId"], $_REQUEST["name"], $content, $type);
$smarty->assign("templateId", '0');
$info["name"] = '';
$info["content"] = '';
$info["section_cms"] = 'n';
$info["section_wiki"] = 'n';
$info["section_wiki_html"] = 'n';
$info["section_file_galleries"] = 'n';
$info["section_newsletters"] = 'n';
$info["section_events"] = 'n';
$info["section_html"] = 'n';
$smarty->assign('info', $info);
if (isset($_REQUEST["section_cms"]) && $_REQUEST["section_cms"] == 'on') {
$templateslib->add_template_to_section($tid, 'cms');
} else {
$templateslib->remove_template_from_section($tid, 'cms');
}
if (isset($_REQUEST["section_wiki"]) && $_REQUEST["section_wiki"] == 'on') {
$templateslib->add_template_to_section($tid, 'wiki');
} else {
$templateslib->remove_template_from_section($tid, 'wiki');
}
if (isset($_REQUEST["section_wiki_html"]) && $_REQUEST["section_wiki_html"] == 'on') {
$templateslib->add_template_to_section($tid, 'wiki_html');
} else {
$templateslib->remove_template_from_section($tid, 'wiki_html');
}
if (isset($_REQUEST["section_file_galleries"]) && $_REQUEST["section_file_galleries"] == 'on') {
$templateslib->add_template_to_section($tid, 'file_galleries');
} else {
$templateslib->remove_template_from_section($tid, 'file_galleries');
}
if (isset($_REQUEST["section_newsletters"]) && $_REQUEST["section_newsletters"] == 'on') {
$templateslib->add_template_to_section($tid, 'newsletters');
} else {
$templateslib->remove_template_from_section($tid, 'newsletters');
}
if (isset($_REQUEST["section_events"]) && $_REQUEST["section_events"] == 'on') {
$templateslib->add_template_to_section($tid, 'events');
} else {
$templateslib->remove_template_from_section($tid, 'events');
}
if (isset($_REQUEST["section_html"]) && $_REQUEST["section_html"] == 'on') {
$templateslib->add_template_to_section($tid, 'html');
} else {
$templateslib->remove_template_from_section($tid, 'html');
}
$cat_type = 'template';
$cat_objid = $tid;
$cat_desc = '';
$cat_name = $_REQUEST["name"];
$cat_href = "tiki-admin_content_templates.php?templateId=" . $cat_objid;
include_once("categorize.php");
// Locking: only needed on new templates, ajax locks existing ones
if ($prefs['lock_content_templates'] === 'y' && empty($_REQUEST['templateId'])) {
if (! empty($_REQUEST['locked'])) {
TikiLib::lib('attribute')->set_attribute('template', $tid, 'tiki.object.lock', $_REQUEST['locked']);
}
}
$cookietab = 1;
} else {
$smarty->assign("templateId", '0');
$info["name"] = '';
$info["content"] = (isset($_REQUEST["content"]) && $_REQUEST["content"] != '') ? $_REQUEST["content"] : '' ;
$info["section_cms"] = (isset($_REQUEST["section_cms"]) && $_REQUEST["section_cms"] == 'on') ? 'y' : 'n';
$info["section_wiki"] = (isset($_REQUEST["section_wiki"]) && $_REQUEST["section_wiki"] == 'on') ? 'y' : 'n';
$info["section_wiki_html"] = (isset($_REQUEST["section_wiki_html"]) && $_REQUEST["section_wiki_html"] == 'on') ? 'y' : 'n';
$info["section_file_galleries"] = (isset($_REQUEST["section_file_galleries"]) && $_REQUEST["section_file_galleries"] == 'on') ? 'y' : 'n';
$info["section_newsletters"] = (isset($_REQUEST["section_newsletters"]) && $_REQUEST["section_newsletters"] == 'on') ? 'y' : 'n' ;
$info["section_events"] = (isset($_REQUEST["section_events"]) && $_REQUEST["section_events"] == 'on') ? 'y' : 'n';
$info["section_html"] = (isset($_REQUEST["section_html"]) && $_REQUEST["section_html"] == 'on') ? 'y' : 'n';
$smarty->assign('info', $info);
$smarty->assign('emptyname', "true");
$cookietab = 2;
}
}
if (! isset($_REQUEST["sort_mode"])) {
$sort_mode = 'created_desc';
} else {
$sort_mode = $_REQUEST["sort_mode"];
}
if (! isset($_REQUEST["offset"])) {
$offset = 0;
} else {
$offset = $_REQUEST["offset"];
}
$smarty->assign_by_ref('offset', $offset);
if (isset($_REQUEST["find"])) {
$find = $_REQUEST["find"];
} else {
$find = '';
}
$smarty->assign('find', $find);
$smarty->assign_by_ref('sort_mode', $sort_mode);
$channels = $templateslib->list_all_templates($offset, $maxRecords, $sort_mode, $find);
$smarty->assign_by_ref('cant_pages', $channels["cant"]);
// wysiwyg decision
if ($_REQUEST['templateId']) {
$info['is_html'] = $info['section_wiki_html'] === 'y' ? 1 : 0;
$info['wysiwyg'] = $info['section_wiki_html'];
}
include 'lib/setup/editmode.php';
$info['section_wiki_html'] = $_SESSION['wysiwyg']; //$info['is_html'] ? 'y' : 'n';
// Handles switching editor modes
$editlib = TikiLib::lib('edit');
if (isset($_REQUEST['mode_normal']) && $_REQUEST['mode_normal'] == 'y') {
// Parsing page data as first time seeing html page in normal editor
$smarty->assign('msg', "Parsing html to wiki");
$info['content'] = $editlib->parseToWiki($_REQUEST["content"]);
$smarty->assign('parsed', $parsed);
} elseif (isset($_REQUEST['mode_wysiwyg']) && $_REQUEST['mode_wysiwyg'] == 'y') {
// Parsing page data as first time seeing wiki page in wysiwyg editor
$smarty->assign('msg', "Parsing wiki to html");
$info['content'] = $editlib->parseToWysiwyg($_REQUEST["content"]);
$smarty->assign('parsed', $parsed);
}
// check edit/create perms
if ($_REQUEST['templateId']) {
$perms = Perms::get(['type' => 'template', 'object' => $_REQUEST['templateId']]);
$canEdit = $perms->edit_content_templates;
if ($prefs['lock_content_templates'] === 'y' && $canEdit) { // check for locked
$lockedby = TikiLib::lib('attribute')->get_attribute('template', $_REQUEST['templateId'], 'tiki.object.lock');
if ($lockedby && $lockedby === $user && $perms->lock_content_templates || ! $lockedby || $perms->admin_content_templates) {
$canEdit = true;
} else {
$canEdit = false;
}
}
} else {
$canEdit = ($tiki_p_admin_content_templates === 'y') || ($tiki_p_admin === 'y'); // create
}
$smarty->assign('canEdit', $canEdit);
$smarty->assign_by_ref('channels', $channels["data"]);
ask_ticket('admin-content-templates');
$wikilib = TikiLib::lib('wiki');
$plugins = $wikilib->list_plugins(true, 'editwiki');
$smarty->assign_by_ref('plugins', $plugins);
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
// Display the template
$smarty->assign('mid', 'tiki-admin_content_templates.tpl');
$smarty->display("tiki.tpl");