... | ... |
@@ -200,7 +200,7 @@ $GLOBALS['TL_DCA']['tl_article_layouts'] = array |
200 | 200 |
'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['bgStyle'], |
201 | 201 |
'exclude' => true, |
202 | 202 |
'inputType' => 'text', |
203 |
- 'eval' => array('tl_class'=>'long','maxlength'=>255), |
|
203 |
+ 'eval' => array('tl_class'=>'long','maxlength'=>255,'decodeEntities'=>true), |
|
204 | 204 |
'sql' => "varchar(255) NOT NULL default ''" |
205 | 205 |
), |
206 | 206 |
'restrictContentElements' => array |
... | ... |
@@ -230,7 +230,7 @@ $GLOBALS['TL_DCA']['tl_article_layouts'] = array |
230 | 230 |
* |
231 | 231 |
* @author Benjamin Roth <http://www.esales-media.de> |
232 | 232 |
*/ |
233 |
-class tl_article_layouts extends Backend |
|
233 |
+class tl_article_layouts extends \Backend |
|
234 | 234 |
{ |
235 | 235 |
|
236 | 236 |
/** |
... | ... |
@@ -270,7 +270,7 @@ class tl_article_layouts extends Backend |
270 | 270 |
* |
271 | 271 |
* @throws Exception |
272 | 272 |
*/ |
273 |
- public function generateAlias($varValue, DataContainer $dc) |
|
273 |
+ public function generateAlias($varValue, \DataContainer $dc) |
|
274 | 274 |
{ |
275 | 275 |
$autoAlias = false; |
276 | 276 |
|
... | ... |
@@ -99,14 +99,15 @@ $GLOBALS['TL_DCA']['tl_article_layouts'] = array |
99 | 99 |
// Palettes |
100 | 100 |
'palettes' => array |
101 | 101 |
( |
102 |
- '__selector__' => array('showBackgroundImage'), |
|
103 |
- 'default' => '{title_legend},title,alias;{content_legend},maxWidth,center,useHelper;{image_legend},showBackgroundImage' |
|
102 |
+ '__selector__' => array('showBackgroundImage','restrictContentElements'), |
|
103 |
+ 'default' => '{title_legend},title,alias;{content_legend},maxWidth,center,useHelper;{image_legend},showBackgroundImage;{expert_legend:hide},restrictContentElements' |
|
104 | 104 |
), |
105 | 105 |
|
106 | 106 |
// Subpalettes |
107 | 107 |
'subpalettes' => array |
108 | 108 |
( |
109 |
- 'showBackgroundImage' => 'bgImageSize,bgStyle' |
|
109 |
+ 'showBackgroundImage' => 'bgImageSize,bgStyle', |
|
110 |
+ 'restrictContentElements' => 'allowedElements' |
|
110 | 111 |
), |
111 | 112 |
|
112 | 113 |
// Fields |
... | ... |
@@ -202,6 +203,24 @@ $GLOBALS['TL_DCA']['tl_article_layouts'] = array |
202 | 203 |
'eval' => array('tl_class'=>'long','maxlength'=>255), |
203 | 204 |
'sql' => "varchar(255) NOT NULL default ''" |
204 | 205 |
), |
206 |
+ 'restrictContentElements' => array |
|
207 |
+ ( |
|
208 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['restrictContentElements'], |
|
209 |
+ 'exclude' => true, |
|
210 |
+ 'inputType' => 'checkbox', |
|
211 |
+ 'eval' => array('submitOnChange'=>true), |
|
212 |
+ 'sql' => "char(1) NOT NULL default ''" |
|
213 |
+ ), |
|
214 |
+ 'allowedElements' => array |
|
215 |
+ ( |
|
216 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['allowedElements'], |
|
217 |
+ 'exclude' => true, |
|
218 |
+ 'inputType' => 'checkbox', |
|
219 |
+ 'options_callback' => array('tl_article_layouts','getContentElements'), |
|
220 |
+ 'reference' => &$GLOBALS['TL_LANG']['CTE'], |
|
221 |
+ 'eval' => array('multiple'=>true,'mandatory'=>true), |
|
222 |
+ 'sql' => "blob NULL" |
|
223 |
+ ), |
|
205 | 224 |
) |
206 | 225 |
); |
207 | 226 |
|
... | ... |
@@ -292,4 +311,24 @@ class tl_article_layouts extends Backend |
292 | 311 |
return '<div style="float:left">'. $row['title'] .' <span style="color:#b3b3b3;">['.$row['alias']."]</span></div>\n"; |
293 | 312 |
} |
294 | 313 |
|
314 |
+ /** |
|
315 |
+ * Return all content elements as array |
|
316 |
+ * |
|
317 |
+ * @return array |
|
318 |
+ */ |
|
319 |
+ public function getContentElements() |
|
320 |
+ { |
|
321 |
+ $groups = array(); |
|
322 |
+ |
|
323 |
+ foreach ($GLOBALS['TL_CTE'] as $k=>$v) |
|
324 |
+ { |
|
325 |
+ foreach (array_keys($v) as $kk) |
|
326 |
+ { |
|
327 |
+ $groups[$k][] = $kk; |
|
328 |
+ } |
|
329 |
+ } |
|
330 |
+ |
|
331 |
+ return $groups; |
|
332 |
+ } |
|
333 |
+ |
|
295 | 334 |
} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,295 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/** |
|
4 |
+ * ArtLayout for Contao |
|
5 |
+ * |
|
6 |
+ * Copyright (c) 2016 Benjamin Roth |
|
7 |
+ * |
|
8 |
+ * @link http://www.esales-media.de |
|
9 |
+ * @license commercial |
|
10 |
+ */ |
|
11 |
+ |
|
12 |
+ |
|
13 |
+/** |
|
14 |
+ * Table tl_article_layouts |
|
15 |
+ */ |
|
16 |
+$GLOBALS['TL_DCA']['tl_article_layouts'] = array |
|
17 |
+( |
|
18 |
+ |
|
19 |
+ // Config |
|
20 |
+ 'config' => array |
|
21 |
+ ( |
|
22 |
+ 'dataContainer' => 'Table', |
|
23 |
+ 'ptable' => 'tl_theme', |
|
24 |
+ 'switchToEdit' => true, |
|
25 |
+ 'onload_callback' => array |
|
26 |
+ ( |
|
27 |
+ array('tl_article_layouts', 'checkPermission'), |
|
28 |
+ ), |
|
29 |
+ 'enableVersioning' => true, |
|
30 |
+ 'sql' => array |
|
31 |
+ ( |
|
32 |
+ 'keys' => array |
|
33 |
+ ( |
|
34 |
+ 'id' => 'primary' |
|
35 |
+ ) |
|
36 |
+ ) |
|
37 |
+ ), |
|
38 |
+ |
|
39 |
+ // List |
|
40 |
+ 'list' => array |
|
41 |
+ ( |
|
42 |
+ 'sorting' => array |
|
43 |
+ ( |
|
44 |
+ 'mode' => 4, |
|
45 |
+ 'flag' => 11, |
|
46 |
+ 'fields' => array('sorting'), |
|
47 |
+ 'panelLayout' => 'filter;search,limit', |
|
48 |
+ 'headerFields' => array('name', 'author', 'tstamp'), |
|
49 |
+ 'child_record_callback' => array('tl_article_layouts', 'listLayout'), |
|
50 |
+ 'disableGrouping' => true |
|
51 |
+ ), |
|
52 |
+ 'global_operations' => array |
|
53 |
+ ( |
|
54 |
+ 'all' => array |
|
55 |
+ ( |
|
56 |
+ 'label' => &$GLOBALS['TL_LANG']['MSC']['all'], |
|
57 |
+ 'href' => 'act=select', |
|
58 |
+ 'class' => 'header_edit_all', |
|
59 |
+ 'attributes' => 'onclick="Backend.getScrollOffset()" accesskey="e"' |
|
60 |
+ ) |
|
61 |
+ ), |
|
62 |
+ 'operations' => array |
|
63 |
+ ( |
|
64 |
+ 'edit' => array |
|
65 |
+ ( |
|
66 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['edit'], |
|
67 |
+ 'href' => 'table=tl_article_layouts&act=edit', |
|
68 |
+ 'icon' => 'edit.gif' |
|
69 |
+ ), |
|
70 |
+ 'copy' => array |
|
71 |
+ ( |
|
72 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['copy'], |
|
73 |
+ 'href' => 'act=paste&mode=copy', |
|
74 |
+ 'icon' => 'copy.gif' |
|
75 |
+ ), |
|
76 |
+ 'cut' => array |
|
77 |
+ ( |
|
78 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['cut'], |
|
79 |
+ 'href' => 'act=paste&mode=cut', |
|
80 |
+ 'icon' => 'cut.gif', |
|
81 |
+ 'attributes' => 'onclick="Backend.getScrollOffset()"' |
|
82 |
+ ), |
|
83 |
+ 'delete' => array |
|
84 |
+ ( |
|
85 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['delete'], |
|
86 |
+ 'href' => 'act=delete', |
|
87 |
+ 'icon' => 'delete.gif', |
|
88 |
+ 'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"' |
|
89 |
+ ), |
|
90 |
+ 'show' => array |
|
91 |
+ ( |
|
92 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['show'], |
|
93 |
+ 'href' => 'act=show', |
|
94 |
+ 'icon' => 'show.gif' |
|
95 |
+ ) |
|
96 |
+ ) |
|
97 |
+ ), |
|
98 |
+ |
|
99 |
+ // Palettes |
|
100 |
+ 'palettes' => array |
|
101 |
+ ( |
|
102 |
+ '__selector__' => array('showBackgroundImage'), |
|
103 |
+ 'default' => '{title_legend},title,alias;{content_legend},maxWidth,center,useHelper;{image_legend},showBackgroundImage' |
|
104 |
+ ), |
|
105 |
+ |
|
106 |
+ // Subpalettes |
|
107 |
+ 'subpalettes' => array |
|
108 |
+ ( |
|
109 |
+ 'showBackgroundImage' => 'bgImageSize,bgStyle' |
|
110 |
+ ), |
|
111 |
+ |
|
112 |
+ // Fields |
|
113 |
+ 'fields' => array |
|
114 |
+ ( |
|
115 |
+ 'id' => array |
|
116 |
+ ( |
|
117 |
+ 'sql' => "int(10) unsigned NOT NULL auto_increment" |
|
118 |
+ ), |
|
119 |
+ 'pid' => array |
|
120 |
+ ( |
|
121 |
+ 'foreignKey' => 'tl_theme.name', |
|
122 |
+ 'sql' => "int(10) unsigned NOT NULL default '0'", |
|
123 |
+ 'relation' => array('type'=>'belongsTo', 'load'=>'lazy') |
|
124 |
+ ), |
|
125 |
+ 'sorting' => array |
|
126 |
+ ( |
|
127 |
+ 'sql' => "int(10) unsigned NOT NULL default '0'" |
|
128 |
+ ), |
|
129 |
+ 'tstamp' => array |
|
130 |
+ ( |
|
131 |
+ 'sql' => "int(10) unsigned NOT NULL default '0'" |
|
132 |
+ ), |
|
133 |
+ 'title' => array |
|
134 |
+ ( |
|
135 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['title'], |
|
136 |
+ 'inputType' => 'text', |
|
137 |
+ 'exclude' => true, |
|
138 |
+ 'search' => true, |
|
139 |
+ 'eval' => array('mandatory'=>true, 'rgxp'=>'extnd', 'maxlength'=>64, 'tl_class'=>'w50'), |
|
140 |
+ 'sql' => "varchar(64) NULL" |
|
141 |
+ ), |
|
142 |
+ 'alias' => array |
|
143 |
+ ( |
|
144 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['alias'], |
|
145 |
+ 'exclude' => true, |
|
146 |
+ 'inputType' => 'text', |
|
147 |
+ 'search' => true, |
|
148 |
+ 'eval' => array('rgxp'=>'alias', 'doNotCopy'=>true, 'maxlength'=>128, 'tl_class'=>'w50'), |
|
149 |
+ 'save_callback' => array |
|
150 |
+ ( |
|
151 |
+ array('tl_article_layouts', 'generateAlias') |
|
152 |
+ ), |
|
153 |
+ 'sql' => "varchar(128) COLLATE utf8_bin NOT NULL default ''" |
|
154 |
+ ), |
|
155 |
+ 'showBackgroundImage' => array |
|
156 |
+ ( |
|
157 |
+ 'exclude' => true, |
|
158 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['showBackgroundImage'], |
|
159 |
+ 'inputType' => 'checkbox', |
|
160 |
+ 'eval' => array('tl_class'=>'w50 m12','submitOnChange'=>true), |
|
161 |
+ 'sql' => "char(1) NOT NULL default ''" |
|
162 |
+ ), |
|
163 |
+ 'bgImageSize' => array |
|
164 |
+ ( |
|
165 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['bgImageSize'], |
|
166 |
+ 'exclude' => true, |
|
167 |
+ 'inputType' => 'imageSize', |
|
168 |
+ 'options' => System::getImageSizes(), |
|
169 |
+ 'reference' => &$GLOBALS['TL_LANG']['MSC'], |
|
170 |
+ 'eval' => array('rgxp'=>'natural', 'includeBlankOption'=>true, 'nospace'=>true, 'helpwizard'=>true, 'tl_class'=>'w50'), |
|
171 |
+ 'sql' => "varchar(64) NOT NULL default ''" |
|
172 |
+ ), |
|
173 |
+ 'center' => array |
|
174 |
+ ( |
|
175 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['center'], |
|
176 |
+ 'exclude' => true, |
|
177 |
+ 'inputType' => 'checkbox', |
|
178 |
+ 'eval' => array('tl_class'=>'w50 m12'), |
|
179 |
+ 'sql' => "char(1) NOT NULL default ''" |
|
180 |
+ ), |
|
181 |
+ 'maxWidth' => array |
|
182 |
+ ( |
|
183 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['maxWidth'], |
|
184 |
+ 'exclude' => true, |
|
185 |
+ 'inputType' => 'checkbox', |
|
186 |
+ 'eval' => array('tl_class'=>'w50 m12'), |
|
187 |
+ 'sql' => "char(1) NOT NULL default ''" |
|
188 |
+ ), |
|
189 |
+ 'useHelper' => array |
|
190 |
+ ( |
|
191 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['useHelper'], |
|
192 |
+ 'exclude' => true, |
|
193 |
+ 'inputType' => 'checkbox', |
|
194 |
+ 'eval' => array('tl_class'=>'w50 m12'), |
|
195 |
+ 'sql' => "char(1) NOT NULL default ''" |
|
196 |
+ ), |
|
197 |
+ 'bgStyle' => array |
|
198 |
+ ( |
|
199 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_article_layouts']['bgStyle'], |
|
200 |
+ 'exclude' => true, |
|
201 |
+ 'inputType' => 'text', |
|
202 |
+ 'eval' => array('tl_class'=>'long','maxlength'=>255), |
|
203 |
+ 'sql' => "varchar(255) NOT NULL default ''" |
|
204 |
+ ), |
|
205 |
+ ) |
|
206 |
+); |
|
207 |
+ |
|
208 |
+ |
|
209 |
+/** |
|
210 |
+ * Provide miscellaneous methods that are used by the data configuration array. |
|
211 |
+ * |
|
212 |
+ * @author Benjamin Roth <http://www.esales-media.de> |
|
213 |
+ */ |
|
214 |
+class tl_article_layouts extends Backend |
|
215 |
+{ |
|
216 |
+ |
|
217 |
+ /** |
|
218 |
+ * Import the back end user object |
|
219 |
+ */ |
|
220 |
+ public function __construct() |
|
221 |
+ { |
|
222 |
+ parent::__construct(); |
|
223 |
+ $this->import('BackendUser', 'User'); |
|
224 |
+ } |
|
225 |
+ |
|
226 |
+ |
|
227 |
+ /** |
|
228 |
+ * Check permissions to edit the table |
|
229 |
+ */ |
|
230 |
+ public function checkPermission() |
|
231 |
+ { |
|
232 |
+ if ($this->User->isAdmin) |
|
233 |
+ { |
|
234 |
+ return; |
|
235 |
+ } |
|
236 |
+ |
|
237 |
+ if (!$this->User->hasAccess('artLayout', 'themes')) |
|
238 |
+ { |
|
239 |
+ $this->log('Not enough permissions to access the article layouts module', __METHOD__, TL_ERROR); |
|
240 |
+ $this->redirect('contao/main.php?act=error'); |
|
241 |
+ } |
|
242 |
+ } |
|
243 |
+ |
|
244 |
+ /** |
|
245 |
+ * Auto-generate an article layout alias if it has not been set yet |
|
246 |
+ * |
|
247 |
+ * @param mixed $varValue |
|
248 |
+ * @param DataContainer $dc |
|
249 |
+ * |
|
250 |
+ * @return string |
|
251 |
+ * |
|
252 |
+ * @throws Exception |
|
253 |
+ */ |
|
254 |
+ public function generateAlias($varValue, DataContainer $dc) |
|
255 |
+ { |
|
256 |
+ $autoAlias = false; |
|
257 |
+ |
|
258 |
+ // Generate an alias if there is none |
|
259 |
+ if ($varValue == '') |
|
260 |
+ { |
|
261 |
+ $autoAlias = true; |
|
262 |
+ $varValue = StringUtil::generateAlias($dc->activeRecord->title); |
|
263 |
+ } |
|
264 |
+ |
|
265 |
+ |
|
266 |
+ $objAlias = $this->Database->prepare("SELECT id FROM tl_article_layouts WHERE id=? OR alias=?") |
|
267 |
+ ->execute($dc->id, $varValue); |
|
268 |
+ |
|
269 |
+ // Check whether the page alias exists |
|
270 |
+ if ($objAlias->numRows > 1) |
|
271 |
+ { |
|
272 |
+ if (!$autoAlias) |
|
273 |
+ { |
|
274 |
+ throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); |
|
275 |
+ } |
|
276 |
+ |
|
277 |
+ $varValue .= '-' . $dc->id; |
|
278 |
+ } |
|
279 |
+ |
|
280 |
+ return $varValue; |
|
281 |
+ } |
|
282 |
+ |
|
283 |
+ /** |
|
284 |
+ * List an article layout |
|
285 |
+ * |
|
286 |
+ * @param array $row |
|
287 |
+ * |
|
288 |
+ * @return string |
|
289 |
+ */ |
|
290 |
+ public function listLayout($row) |
|
291 |
+ { |
|
292 |
+ return '<div style="float:left">'. $row['title'] .' <span style="color:#b3b3b3;">['.$row['alias']."]</span></div>\n"; |
|
293 |
+ } |
|
294 |
+ |
|
295 |
+} |