Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / class.tx_lowlevel_cleaner.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Web > Functions module plugin for cleaning up.
29 *
30 * $Id$
31 *
32 * XHTML compliant
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 65: class tx_lowlevel_cleaner extends t3lib_extobjbase
41 * 74: function modMenu()
42 * 109: function main()
43 * 130: function createMenu()
44 * 145: function moduleContent()
45 *
46 * TOTAL FUNCTIONS: 4
47 * (This index is automatically created/updated by the extension "extdeveval")
48 *
49 */
50
51 require_once(t3lib_extMgm::extPath('lowlevel').'class.tx_lowlevel_cleaner_core.php');
52
53 die('Not developed...');
54
55
56
57
58
59 /**
60 * Web > Functions module plugin for cleaning up.
61 *
62 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
63 * @package TYPO3
64 * @subpackage tx_lowlevel
65 */
66 class tx_lowlevel_cleaner extends t3lib_extobjbase {
67
68
69 /**
70 * Modifies parent objects internal MOD_MENU array, adding items this module needs.
71 *
72 * @return array Items merged with the parent objects.
73 * @see t3lib_extobjbase::init()
74 */
75 function modMenu() {
76 global $LANG;
77
78 $modMenuAdd = array(
79 'tx_lowlevel_cleaner' => array(
80 # 'delete_flush' => 'Flush "deleted" records', // ID/depth related
81 # 'delete_restore' => 'Restore "deleted" records', // ID/depth related
82 # 'versions_flush' => 'Flush published versions', // ID/depth related
83
84 # 'clean_flexform_xml' => 'Clean up FlexForm XML', // ID/depth related
85 # tt_content element removal: templavoila plugin! // ID/depth related
86 # Check for various: uid>0, pid>-1 , lost swapping operations,
87 # 'l10n_duplicates' => 'Localization errors',
88 # Find TCA/FlexForm fields which should probably have a soft reference parser attached!
89
90 # TemplaVoila plugs in to display mapping issues.
91 # Overview of http:// and emails // UPDATE index!
92
93 'missing_files' => 'Missing files', // UPDATE index!
94 'missing_relations' => 'Missing relations', // UPDATE index!
95 # 'lost_records' => 'Orphan records',
96 'lost_files' => 'Orphan files (from uploads/)', // UPDATE index!
97 'RTEmagic_files' => 'RTE Magic Images', // UPDATE index!
98 'double_files' => 'Double file references', // UPDATE index!
99 )
100 );
101
102 return $modMenuAdd;
103 }
104
105 /**
106 * Creation of the main content.
107 *
108 * @return string The content
109 */
110 function main() {
111 global $BE_USER;
112
113 $content = '';
114
115 if ($BE_USER->isAdmin()) {
116 $content.= $this->pObj->doc->spacer(5);
117 $content.= $this->createMenu().'<hr/>';
118 $content.= $this->moduleContent();
119 $content.= $this->quickDBlookUp();
120 } else {
121 $content.= $this->pObj->doc->spacer(5);
122 $content.= 'Only access for admin users, sorry.';
123 }
124 return $content;
125 }
126
127 /**
128 * Creates HTML menu for the module.
129 *
130 * @return string HTML code for menu
131 */
132 function createMenu() {
133 if (is_array($this->pObj->MOD_MENU['tx_lowlevel_cleaner'])) {
134 $menu = '';
135 foreach($this->pObj->MOD_MENU['tx_lowlevel_cleaner'] as $key => $value) {
136 $menu .= '<a href="index.php?id=' . intval(t3lib_div::_GP('id')) . '&tx_lowlevel_cleaner=' . $key . '">' . htmlspecialchars($value) . '</a><br />';
137 }
138 return $menu;
139 }
140 }
141
142 /**
143 * Branching out to the specified module functionality.
144 *
145 * @return string HTML
146 */
147 function moduleContent() {
148 $cleanerObj = t3lib_div::makeInstance('tx_lowlevel_cleaner_core');
149 $silent = FALSE;
150 $filter = 0;
151
152 switch(t3lib_div::_GP('tx_lowlevel_cleaner')) {
153 case 'lost_files':
154 $res = $cleanerObj->clean_lost_files_analyze();
155 $output = $cleanerObj->html_printInfo('clean_lost_files_analyze()',$res,$silent,$filter);
156 break;
157 case 'RTEmagic_files':
158 $res = $cleanerObj->RTEmagic_files_analyze();
159 $output = $cleanerObj->html_printInfo('RTEmagic_files_analyze()',$res,$silent,$filter);
160 break;
161 case 'double_files':
162 $res = $cleanerObj->double_files_analyze();
163 $output = $cleanerObj->html_printInfo('double_files_analyze()',$res,$silent,$filter);
164 break;
165 case 'missing_files':
166 $res = $cleanerObj->missing_files_analyze();
167 $output = $cleanerObj->html_printInfo('missing_files_analyze()',$res,$silent,$filter);
168 break;
169 case 'missing_relations':
170 $res = $cleanerObj->missing_relations_analyze();
171 $output = $cleanerObj->html_printInfo('missing_relations_analyze()',$res,$silent,$filter);
172 break;
173 }
174
175 /*
176 // TEST of how we can get the used Content Elements on a TemplaVoila page:
177 require_once(t3lib_extMgm::extPath('templavoila').'class.tx_templavoila_api.php');
178 $apiObj = t3lib_div::makeInstance('tx_templavoila_api', 'pages');
179 $contentTreeData = $apiObj->getContentTree('pages', t3lib_BEfunc::getRecordWSOL('pages',33),FALSE);
180 debug($contentTreeData);
181 */
182 return $output;
183 }
184
185 function quickDBlookUp() {
186 $output = 'Enter [table]:[uid]:[fieldlist (optional)] <input name="table_uid" value="'.htmlspecialchars(t3lib_div::_POST('table_uid')).'" />';
187 $output .= '<input type="submit" name="_" value="REFRESH" /><br />';
188
189 // Show record:
190 if (t3lib_div::_POST('table_uid')) {
191 list($table,$uid,$fieldName) = t3lib_div::trimExplode(':',t3lib_div::_POST('table_uid'),1);
192 if ($GLOBALS['TCA'][$table]) {
193 $rec = t3lib_BEfunc::getRecordRaw($table,'uid='.intval($uid),$fieldName?$fieldName:'*');
194
195 if (count($rec)) {
196 if (t3lib_div::_POST('_EDIT')) {
197 $output .= '<hr />Edit:<br /><br />';
198 foreach($rec as $field => $value) {
199 $output .= htmlspecialchars($field) . '<br /><input name="record[' . $table . '][' . $uid . '][' . $field . ']" value="' . htmlspecialchars($value) . '" /><br />';
200 }
201 $output.='<input type="submit" name="_SAVE" value="SAVE" />';
202 } elseif (t3lib_div::_POST('_SAVE')) {
203 $incomingData = t3lib_div::_POST('record');
204 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,'uid='.intval($uid),$incomingData[$table][$uid]);
205 $output .= '<br />Updated ' . $table . ':' . $uid . '...';
206 $this->updateRefIndex($table,$uid);
207 } else if (t3lib_div::_POST('_DELETE')) {
208 $GLOBALS['TYPO3_DB']->exec_DELETEquery($table,'uid='.intval($uid));
209 $output .= '<br />Deleted ' . $table . ':' . $uid . '...';
210 $this->updateRefIndex($table,$uid);
211 } else {
212 $output.='<input type="submit" name="_EDIT" value="EDIT" />';
213 $output.='<input type="submit" name="_DELETE" value="DELETE" onclick="return confirm(\'Are you sure you wish to delete?\');" />';
214 $output.= t3lib_utility_Debug::viewArray($rec);
215 $output.=md5(implode($rec));
216 }
217 } else {
218 $output.='No record existed!';
219 }
220 }
221 }
222
223 return $output;
224 }
225
226
227 /**
228 * Update Reference Index (sys_refindex) for a record
229 *
230 * @param string Table name
231 * @param integer Record UID
232 * @return void
233 */
234 function updateRefIndex($table,$id) {
235 $refIndexObj = t3lib_div::makeInstance('t3lib_refindex');
236 $result = $refIndexObj->updateRefIndexTable($table,$id);
237 }
238 }
239
240 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_cleaner.php'])) {
241 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_cleaner.php']);
242 }
243 ?>