2 /***************************************************************
5 * (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Web > Functions module plugin for cleaning up.
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 * [CLASS/FUNCTION INDEX of SCRIPT]
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()
47 * (This index is automatically created/updated by the extension "extdeveval")
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');
55 die('Not developed...');
62 * Web > Functions module plugin for cleaning up.
64 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
66 * @subpackage tx_lowlevel
68 class tx_lowlevel_cleaner
extends t3lib_extobjbase
{
72 * Modifies parent objects internal MOD_MENU array, adding items this module needs.
74 * @return array Items merged with the parent objects.
75 * @see t3lib_extobjbase::init()
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
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!
92 # TemplaVoila plugs in to display mapping issues.
93 # Overview of http:// and emails // UPDATE index!
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!
108 * Creation of the main content.
110 * @return string The content
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();
123 $content.= $this->pObj
->doc
->spacer(5);
124 $content.= 'Only access for admin users, sorry.';
130 * Creates HTML menu for the module.
132 * @return string HTML code for menu
134 function createMenu() {
135 if (is_array($this->pObj
->MOD_MENU
['tx_lowlevel_cleaner'])) {
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/>';
145 * Branching out to the specified module functionality.
147 * @return string HTML
149 function moduleContent() {
150 $cleanerObj = t3lib_div
::makeInstance('tx_lowlevel_cleaner_core');
154 switch(t3lib_div
::_GP('tx_lowlevel_cleaner')) {
156 $res = $cleanerObj->clean_lost_files_analyze();
157 $output = $cleanerObj->html_printInfo('clean_lost_files_analyze()',$res,$silent,$filter);
159 case 'RTEmagic_files':
160 $res = $cleanerObj->RTEmagic_files_analyze();
161 $output = $cleanerObj->html_printInfo('RTEmagic_files_analyze()',$res,$silent,$filter);
164 $res = $cleanerObj->double_files_analyze();
165 $output = $cleanerObj->html_printInfo('double_files_analyze()',$res,$silent,$filter);
167 case 'missing_files':
168 $res = $cleanerObj->missing_files_analyze();
169 $output = $cleanerObj->html_printInfo('missing_files_analyze()',$res,$silent,$filter);
171 case 'missing_relations':
172 $res = $cleanerObj->missing_relations_analyze();
173 $output = $cleanerObj->html_printInfo('missing_relations_analyze()',$res,$silent,$filter);
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);
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/>';
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:'*');
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/>';
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);
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));
221 $output.='No record existed!';
231 * Update Reference Index (sys_refindex) for a record
233 * @param string Table name
234 * @param integer Record UID
237 function updateRefIndex($table,$id) {
238 $refIndexObj = t3lib_div
::makeInstance('t3lib_refindex');
239 $result = $refIndexObj->updateRefIndexTable($table,$id);
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']);