* Update version numbers of all system extension that have been changed since TYPO3 4.1
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / class.tx_lowlevel_cleaner.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2008 Kasper Skaarhoj (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(PATH_t3lib.'class.t3lib_extobjbase.php');
52 require_once(t3lib_extMgm::extPath('lowlevel').'class.tx_lowlevel_cleaner_core.php');
53 require_once (PATH_t3lib.'class.t3lib_refindex.php');
54
55 die('Not developed...');
56
57
58
59
60
61 /**
62 * Web > Functions module plugin for cleaning up.
63 *
64 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
65 * @package TYPO3
66 * @subpackage tx_lowlevel
67 */
68 class tx_lowlevel_cleaner extends t3lib_extobjbase {
69
70
71 /**
72 * Modifies parent objects internal MOD_MENU array, adding items this module needs.
73 *
74 * @return array Items merged with the parent objects.
75 * @see t3lib_extobjbase::init()
76 */
77 function modMenu() {
78 global $LANG;
79
80 $modMenuAdd = array(
81 'tx_lowlevel_cleaner' => array(
82 # 'delete_flush' => 'Flush "deleted" records', // ID/depth related
83 # 'delete_restore' => 'Restore "deleted" records', // ID/depth related
84 # 'versions_flush' => 'Flush published versions', // ID/depth related
85
86 # 'clean_flexform_xml' => 'Clean up FlexForm XML', // ID/depth related
87 # tt_content element removal: templavoila plugin! // ID/depth related
88 # Check for various: uid>0, pid>-1 , lost swapping operations,
89 # 'l10n_duplicates' => 'Localization errors',
90 # Find TCA/FlexForm fields which should probably have a soft reference parser attached!
91
92 # TemplaVoila plugs in to display mapping issues.
93 # Overview of http:// and emails // UPDATE index!
94
95 'missing_files' => 'Missing files', // UPDATE index!
96 'missing_relations' => 'Missing relations', // UPDATE index!
97 # 'lost_records' => 'Orphan records',
98 'lost_files' => 'Orphan files (from uploads/)', // UPDATE index!
99 'RTEmagic_files' => 'RTE Magic Images', // UPDATE index!
100 'double_files' => 'Double file references', // UPDATE index!
101 )
102 );
103
104 return $modMenuAdd;
105 }
106
107 /**
108 * Creation of the main content.
109 *
110 * @return string The content
111 */
112 function main() {
113 global $BE_USER;
114
115 $content = '';
116
117 if ($BE_USER->isAdmin()) {
118 $content.= $this->pObj->doc->spacer(5);
119 $content.= $this->createMenu().'<hr/>';
120 $content.= $this->moduleContent();
121 $content.= $this->quickDBlookUp();
122 } else {
123 $content.= $this->pObj->doc->spacer(5);
124 $content.= 'Only access for admin users, sorry.';
125 }
126 return $content;
127 }
128
129 /**
130 * Creates HTML menu for the module.
131 *
132 * @return string HTML code for menu
133 */
134 function createMenu() {
135 if (is_array($this->pObj->MOD_MENU['tx_lowlevel_cleaner'])) {
136 $menu = '';
137 foreach($this->pObj->MOD_MENU['tx_lowlevel_cleaner'] as $key => $value) {
138 $menu.='<a href="index.php?id='.intval(t3lib_div::_GP('id')).'&tx_lowlevel_cleaner='.$key.'">'.htmlspecialchars($value).'</a><br/>';
139 }
140 return $menu;
141 }
142 }
143
144 /**
145 * Branching out to the specified module functionality.
146 *
147 * @return string HTML
148 */
149 function moduleContent() {
150 $cleanerObj = t3lib_div::makeInstance('tx_lowlevel_cleaner_core');
151 $silent = FALSE;
152 $filter = 0;
153
154 switch(t3lib_div::_GP('tx_lowlevel_cleaner')) {
155 case 'lost_files':
156 $res = $cleanerObj->clean_lost_files_analyze();
157 $output = $cleanerObj->html_printInfo('clean_lost_files_analyze()',$res,$silent,$filter);
158 break;
159 case 'RTEmagic_files':
160 $res = $cleanerObj->RTEmagic_files_analyze();
161 $output = $cleanerObj->html_printInfo('RTEmagic_files_analyze()',$res,$silent,$filter);
162 break;
163 case 'double_files':
164 $res = $cleanerObj->double_files_analyze();
165 $output = $cleanerObj->html_printInfo('double_files_analyze()',$res,$silent,$filter);
166 break;
167 case 'missing_files':
168 $res = $cleanerObj->missing_files_analyze();
169 $output = $cleanerObj->html_printInfo('missing_files_analyze()',$res,$silent,$filter);
170 break;
171 case 'missing_relations':
172 $res = $cleanerObj->missing_relations_analyze();
173 $output = $cleanerObj->html_printInfo('missing_relations_analyze()',$res,$silent,$filter);
174 break;
175 }
176
177 /*
178 // TEST of how we can get the used Content Elements on a TemplaVoila page:
179 require_once(t3lib_extMgm::extPath('templavoila').'class.tx_templavoila_api.php');
180 $apiClassName = t3lib_div::makeInstanceClassName('tx_templavoila_api');
181 $apiObj = new $apiClassName('pages');
182 $contentTreeData = $apiObj->getContentTree('pages', t3lib_BEfunc::getRecordWSOL('pages',33),FALSE);
183 debug($contentTreeData);
184 */
185 return $output;
186 }
187
188 function quickDBlookUp() {
189 $output = 'Enter [table]:[uid]:[fieldlist (optional)] <input name="table_uid" value="'.htmlspecialchars(t3lib_div::_POST('table_uid')).'" />';
190 $output.='<input type="submit" name="_" value="REFRESH" /><br/>';
191
192 // Show record:
193 if (t3lib_div::_POST('table_uid')) {
194 list($table,$uid,$fieldName) = t3lib_div::trimExplode(':',t3lib_div::_POST('table_uid'),1);
195 if ($GLOBALS['TCA'][$table]) {
196 $rec = t3lib_BEfunc::getRecordRaw($table,'uid='.intval($uid),$fieldName?$fieldName:'*');
197
198 if (count($rec)) {
199 if (t3lib_div::_POST('_EDIT')) {
200 $output.='<hr/>Edit:<br/><br/>';
201 foreach($rec as $field => $value) {
202 $output.= htmlspecialchars($field).'<br/><input name="record['.$table.']['.$uid.']['.$field.']" value="'.htmlspecialchars($value).'" /><br/>';
203 }
204 $output.='<input type="submit" name="_SAVE" value="SAVE" />';
205 } elseif (t3lib_div::_POST('_SAVE')) {
206 $incomingData = t3lib_div::_POST('record');
207 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,'uid='.intval($uid),$incomingData[$table][$uid]);
208 $output.='<br/>Updated '.$table.':'.$uid.'...';
209 $this->updateRefIndex($table,$uid);
210 } else if (t3lib_div::_POST('_DELETE')) {
211 $GLOBALS['TYPO3_DB']->exec_DELETEquery($table,'uid='.intval($uid));
212 $output.='<br/>Deleted '.$table.':'.$uid.'...';
213 $this->updateRefIndex($table,$uid);
214 } else {
215 $output.='<input type="submit" name="_EDIT" value="EDIT" />';
216 $output.='<input type="submit" name="_DELETE" value="DELETE" onclick="return confirm(\'Are you sure you wish to delete?\');" />';
217 $output.=t3lib_div::view_array($rec);
218 $output.=md5(implode($rec));
219 }
220 } else {
221 $output.='No record existed!';
222 }
223 }
224 }
225
226 return $output;
227 }
228
229
230 /**
231 * Update Reference Index (sys_refindex) for a record
232 *
233 * @param string Table name
234 * @param integer Record UID
235 * @return void
236 */
237 function updateRefIndex($table,$id) {
238 $refIndexObj = t3lib_div::makeInstance('t3lib_refindex');
239 $result = $refIndexObj->updateRefIndexTable($table,$id);
240 }
241 }
242
243 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_cleaner.php']) {
244 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_cleaner.php']);
245 }
246 ?>