TYPO3 API  SVNRelease
class.tx_lowlevel_cleaner.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * Web > Functions module plugin for cleaning up.
00029  *
00030  * $Id: class.tx_lowlevel_cleaner.php 10120 2011-01-18 20:03:36Z ohader $
00031  *
00032  * XHTML compliant
00033  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00034  */
00035 /**
00036  * [CLASS/FUNCTION INDEX of SCRIPT]
00037  *
00038  *
00039  *
00040  *   65: class tx_lowlevel_cleaner extends t3lib_extobjbase
00041  *   74:     function modMenu()
00042  *  109:     function main()
00043  *  130:     function createMenu()
00044  *  145:     function moduleContent()
00045  *
00046  * TOTAL FUNCTIONS: 4
00047  * (This index is automatically created/updated by the extension "extdeveval")
00048  *
00049  */
00050 
00051 require_once(t3lib_extMgm::extPath('lowlevel').'class.tx_lowlevel_cleaner_core.php');
00052 
00053 die('Not developed...');
00054 
00055 
00056 
00057 
00058 
00059 /**
00060  * Web > Functions module plugin for cleaning up.
00061  *
00062  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00063  * @package TYPO3
00064  * @subpackage tx_lowlevel
00065  */
00066 class tx_lowlevel_cleaner extends t3lib_extobjbase {
00067 
00068 
00069     /**
00070      * Modifies parent objects internal MOD_MENU array, adding items this module needs.
00071      *
00072      * @return  array       Items merged with the parent objects.
00073      * @see t3lib_extobjbase::init()
00074      */
00075     function modMenu()  {
00076         global $LANG;
00077 
00078         $modMenuAdd = array(
00079             'tx_lowlevel_cleaner' => array(
00080 #               'delete_flush' => 'Flush "deleted" records',        // ID/depth related
00081 #               'delete_restore' => 'Restore "deleted" records',    // ID/depth related
00082 #               'versions_flush' => 'Flush published versions', // ID/depth related
00083 
00084 #               'clean_flexform_xml' => 'Clean up FlexForm XML',    // ID/depth related
00085             # tt_content element removal: templavoila plugin!       // ID/depth related
00086             # Check for various: uid>0, pid>-1  , lost swapping operations,
00087 #               'l10n_duplicates' => 'Localization errors',
00088 # Find TCA/FlexForm fields which should probably have a soft reference parser attached!
00089 
00090             # TemplaVoila plugs in to display mapping issues.
00091             # Overview of http://  and emails                       // UPDATE index!
00092 
00093                 'missing_files' => 'Missing files',             // UPDATE index!
00094                 'missing_relations' => 'Missing relations',     // UPDATE index!
00095 #               'lost_records' => 'Orphan records',
00096                 'lost_files' => 'Orphan files (from uploads/)', // UPDATE index!
00097                 'RTEmagic_files' => 'RTE Magic Images',         // UPDATE index!
00098                 'double_files' => 'Double file references',         // UPDATE index!
00099             )
00100         );
00101 
00102         return $modMenuAdd;
00103     }
00104 
00105     /**
00106      * Creation of the main content.
00107      *
00108      * @return  string      The content
00109      */
00110     function main() {
00111         global $BE_USER;
00112 
00113         $content = '';
00114 
00115         if ($BE_USER->isAdmin())    {
00116             $content.= $this->pObj->doc->spacer(5);
00117             $content.= $this->createMenu().'<hr/>';
00118             $content.= $this->moduleContent();
00119             $content.= $this->quickDBlookUp();
00120         } else {
00121             $content.= $this->pObj->doc->spacer(5);
00122             $content.= 'Only access for admin users, sorry.';
00123         }
00124         return $content;
00125     }
00126 
00127     /**
00128      * Creates HTML menu for the module.
00129      *
00130      * @return  string      HTML code for menu
00131      */
00132     function createMenu()   {
00133         if (is_array($this->pObj->MOD_MENU['tx_lowlevel_cleaner'])) {
00134             $menu = '';
00135             foreach($this->pObj->MOD_MENU['tx_lowlevel_cleaner'] as $key => $value) {
00136                 $menu .= '<a href="index.php?id=' . intval(t3lib_div::_GP('id')) . '&tx_lowlevel_cleaner=' . $key . '">' . htmlspecialchars($value) . '</a><br />';
00137             }
00138             return $menu;
00139         }
00140     }
00141 
00142     /**
00143      * Branching out to the specified module functionality.
00144      *
00145      * @return  string      HTML
00146      */
00147     function moduleContent()    {
00148         $cleanerObj = t3lib_div::makeInstance('tx_lowlevel_cleaner_core');
00149         $silent = FALSE;
00150         $filter = 0;
00151 
00152         switch(t3lib_div::_GP('tx_lowlevel_cleaner'))   {
00153             case 'lost_files':
00154                 $res = $cleanerObj->clean_lost_files_analyze();
00155                 $output = $cleanerObj->html_printInfo('clean_lost_files_analyze()',$res,$silent,$filter);
00156             break;
00157             case 'RTEmagic_files':
00158                 $res = $cleanerObj->RTEmagic_files_analyze();
00159                 $output = $cleanerObj->html_printInfo('RTEmagic_files_analyze()',$res,$silent,$filter);
00160             break;
00161             case 'double_files':
00162                 $res = $cleanerObj->double_files_analyze();
00163                 $output = $cleanerObj->html_printInfo('double_files_analyze()',$res,$silent,$filter);
00164             break;
00165             case 'missing_files':
00166                 $res = $cleanerObj->missing_files_analyze();
00167                 $output = $cleanerObj->html_printInfo('missing_files_analyze()',$res,$silent,$filter);
00168             break;
00169             case 'missing_relations':
00170                 $res = $cleanerObj->missing_relations_analyze();
00171                 $output = $cleanerObj->html_printInfo('missing_relations_analyze()',$res,$silent,$filter);
00172             break;
00173         }
00174 
00175 /*
00176 // TEST of how we can get the used Content Elements on a TemplaVoila page:
00177 require_once(t3lib_extMgm::extPath('templavoila').'class.tx_templavoila_api.php');
00178 $apiObj = t3lib_div::makeInstance('tx_templavoila_api', 'pages');
00179 $contentTreeData = $apiObj->getContentTree('pages', t3lib_BEfunc::getRecordWSOL('pages',33),FALSE);
00180 debug($contentTreeData);
00181 */
00182         return $output;
00183     }
00184 
00185     function quickDBlookUp()    {
00186         $output = 'Enter [table]:[uid]:[fieldlist (optional)] <input name="table_uid" value="'.htmlspecialchars(t3lib_div::_POST('table_uid')).'" />';
00187         $output .= '<input type="submit" name="_" value="REFRESH" /><br />';
00188 
00189             // Show record:
00190         if (t3lib_div::_POST('table_uid'))  {
00191             list($table,$uid,$fieldName) = t3lib_div::trimExplode(':',t3lib_div::_POST('table_uid'),1);
00192             if ($GLOBALS['TCA'][$table])    {
00193                 $rec = t3lib_BEfunc::getRecordRaw($table,'uid='.intval($uid),$fieldName?$fieldName:'*');
00194 
00195                 if (count($rec))    {
00196                     if (t3lib_div::_POST('_EDIT'))  {
00197                         $output .= '<hr />Edit:<br /><br />';
00198                         foreach($rec as $field => $value)   {
00199                             $output .= htmlspecialchars($field) . '<br /><input name="record[' . $table . '][' . $uid . '][' . $field . ']" value="' . htmlspecialchars($value) . '" /><br />';
00200                         }
00201                         $output.='<input type="submit" name="_SAVE" value="SAVE" />';
00202                     } elseif (t3lib_div::_POST('_SAVE'))    {
00203                         $incomingData = t3lib_div::_POST('record');
00204                         $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,'uid='.intval($uid),$incomingData[$table][$uid]);
00205                         $output .= '<br />Updated ' . $table . ':' . $uid . '...';
00206                         $this->updateRefIndex($table,$uid);
00207                     } else if (t3lib_div::_POST('_DELETE')) {
00208                         $GLOBALS['TYPO3_DB']->exec_DELETEquery($table,'uid='.intval($uid));
00209                         $output .= '<br />Deleted ' . $table . ':' . $uid . '...';
00210                         $this->updateRefIndex($table,$uid);
00211                     } else {
00212                         $output.='<input type="submit" name="_EDIT" value="EDIT" />';
00213                         $output.='<input type="submit" name="_DELETE" value="DELETE" onclick="return confirm(\'Are you sure you wish to delete?\');" />';
00214                         $output.= t3lib_utility_Debug::viewArray($rec);
00215                         $output.=md5(implode($rec));
00216                     }
00217                 } else {
00218                     $output.='No record existed!';
00219                 }
00220             }
00221         }
00222 
00223         return $output;
00224     }
00225 
00226 
00227     /**
00228      * Update Reference Index (sys_refindex) for a record
00229      *
00230      * @param   string      Table name
00231      * @param   integer     Record UID
00232      * @return  void
00233      */
00234     function updateRefIndex($table,$id) {
00235         $refIndexObj = t3lib_div::makeInstance('t3lib_refindex');
00236         $result = $refIndexObj->updateRefIndexTable($table,$id);
00237     }
00238 }
00239 
00240 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_cleaner.php'])) {
00241     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_cleaner.php']);
00242 }
00243 ?>