[TASK] Separate ext:statictemplates code from core
[Packages/TYPO3.CMS.git] / typo3 / sysext / statictemplates / Classes / TypoScriptTemplateModuleControllerHook.php
1 <?php
2 namespace TYPO3\CMS\Statictemplates;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Statictemplates for typo script tstemplate menu
32 *
33 * Shows 'static template selector' and adds handling
34 *
35 * @author Christian Kuhn <lolli@schwarzbu.ch>
36 */
37 class TypoScriptTemplateModuleControllerHook {
38
39 /**
40 * Render a drop down of available static templates
41 *
42 * @param array $params Params array
43 * @param object $pObj Parent object
44 * @return void
45 */
46 public function render(array $params, $pObj) {
47 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('title,uid', 'static_template', '', '', 'title');
48 $opt = '';
49 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
50 if (substr(trim($row['title']), 0, 8) == 'template') {
51 $opt .= '<option value="' . $row['uid'] . '">' . htmlspecialchars($row['title']) . '</option>';
52 }
53 }
54 $GLOBALS['TYPO3_DB']->sql_free_result($res);
55 $params['selectorHtml'] = '<select name="createStandard"><option></option>' . $opt . '</select><br />';
56 $params['staticsText'] = ', optionally based on one of the standard templates';
57 }
58
59 /**
60 * Manipulate row data when creating new template
61 *
62 * @param array $params Params array
63 * @param object $pObj Parent object
64 * @return void
65 */
66 public function handle(array $params, $pObj) {
67 if (intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('createStandard'))) {
68 $staticT = intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('createStandard'));
69 $params['recData']['sys_template']['NEW'] = array(
70 'pid' => $params['id'],
71 'title' => $GLOBALS['LANG']->getLL('titleNewSiteStandard'),
72 'sorting' => 0,
73 'root' => 1,
74 'clear' => 3,
75 'include_static' => $staticT . ',57'
76 );
77 }
78 }
79 }
80
81 ?>