ext_tables.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2006 - 2008 Stefan Galinski (stefan.galinski@gmail.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 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 
00025 if (!defined('TYPO3_MODE'))
00026         die('Access denied.');
00027 
00028 if (!class_exists('tx_date2cal_extTables'))
00029 {
00030 
00031 require_once(t3lib_extMgm::extPath('date2cal') . 'src/class.tx_date2cal_shared.php');
00032 
00038 class tx_date2cal_extTables
00039 {
00041         var $extConf = array();
00042 
00044         var $cache = '';
00045 
00047         var $tcaTables = array();
00048 
00056         function tx_date2cal_extTables()
00057         {
00058                 // init variables and configuration
00059                 $this->extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['date2cal']);
00060                 $this->extConf['extCache'] = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache'];
00061 
00062                 // convert end/start fields to evaluate also times
00063                 if ($this->extConf['datetime'])
00064                         $this->tx_date2cal_toDatetime();
00065 
00066                 // add wizards to all date and datetime fields
00067                 $this->tx_date2cal_setWizard();
00068 
00069                 // write cache file (only if the cache file was loaded already and caching is enabled)
00070                 if ($this->extConf['extCache'] && $this->extConf['doCache'])
00071                         $this->tx_date2cal_writeCacheFile();
00072         }
00073 
00079         function tx_date2cal_writeCacheFile() {
00080                 $tca = '';
00081                 foreach($this->tcaTables as $tcaTable)
00082                         $tca .= 't3lib_div::loadTCA(\'' . $tcaTable . '\');' . "\n";
00083 
00084                 $this->cache = "&lt;?php\n" . $tca . $this->cache . "?&gt;\n";
00085                 t3lib_div::writeFile(PATH_site . 'typo3temp/date2cal_cache.php',
00086                         html_entity_decode($this->cache));
00087         }
00088 
00094         function tx_date2cal_setWizard()
00095         {
00096                 // iterate tca tables
00097                 foreach($GLOBALS['TCA'] as $tcaTable => $tConf)
00098                 {
00099                         $changed = false;
00100                         t3lib_div::loadTCA($tcaTable);
00101 
00102                         // iterate table columns
00103                         foreach($GLOBALS['TCA'][$tcaTable]['columns'] as $field => $fConf)
00104                         {
00105                                 // type check
00106                                 $type = tx_date2cal_shared::isDateOrDateTime($fConf['config']);
00107                                 if ($type === false)
00108                                         continue;
00109 
00110                                 // add calendar wizard
00111                                 tx_date2cal_shared::addWizard($GLOBALS['TCA'][$tcaTable]['columns'][$field], $type);
00112                                 $changed = true;
00113 
00114                                 // write into the cache file
00115                                 $this->cache .=
00116                                         '$TCA[\'' . $tcaTable . '\'][\'columns\'][\'' . $field . '\']' .
00117                                         '[\'config\'][\'wizards\'][\'calendar\'][\'type\'] = \'userFunc\';
00118                                         $TCA[\'' . $tcaTable . '\'][\'columns\'][\'' . $field . '\']' .
00119                                         '[\'config\'][\'wizards\'][\'calendar\'][\'userFunc\'] = ' .
00120                                         '\'EXT:date2cal/src/class.tx_date2cal_wizard.php:tx_date2cal_wizard->renderWizard\';
00121                                         $TCA[\'' . $tcaTable . '\'][\'columns\'][\'' . $field . '\']' .
00122                                         '[\'config\'][\'wizards\'][\'calendar\'][\'evalValue\'] = ' .
00123                                         '\'' . $type . '\';' . "\n";
00124                         }
00125 
00126                         if ($changed)
00127                                 $this->tcaTables[] = $tcaTable;
00128                 }
00129         }
00130 
00137         function tx_date2cal_toDatetime()
00138         {
00139                 t3lib_div::loadTCA('tt_content');
00140                 $GLOBALS['TCA']['tt_content']['columns']['starttime']['config']['eval'] = 'datetime';
00141                 $GLOBALS['TCA']['tt_content']['columns']['starttime']['config']['size'] = 12;
00142                 $GLOBALS['TCA']['tt_content']['columns']['endtime']['config']['eval'] = 'datetime';
00143                 $GLOBALS['TCA']['tt_content']['columns']['endtime']['config']['size'] = 12;
00144 
00145                 t3lib_div::loadTCA('pages');
00146                 $GLOBALS['TCA']['pages']['columns']['starttime']['config']['eval'] = 'datetime';
00147                 $GLOBALS['TCA']['pages']['columns']['starttime']['config']['size'] = 12;
00148                 $GLOBALS['TCA']['pages']['columns']['endtime']['config']['eval'] = 'datetime';
00149                 $GLOBALS['TCA']['pages']['columns']['endtime']['config']['size'] = 12;
00150 
00151                 $this->cache =
00152                         '$TCA[\'tt_content\'][\'columns\'][\'starttime\'][\'config\'][\'eval\'] = \'datetime\';
00153                         $TCA[\'tt_content\'][\'columns\'][\'starttime\'][\'config\'][\'size\'] = 12;
00154                         $TCA[\'tt_content\'][\'columns\'][\'endtime\'][\'config\'][\'eval\'] = \'datetime\';
00155                         $TCA[\'tt_content\'][\'columns\'][\'endtime\'][\'config\'][\'size\'] = 12;
00156                         $TCA[\'pages\'][\'columns\'][\'starttime\'][\'config\'][\'eval\'] = \'datetime\';
00157                         $TCA[\'pages\'][\'columns\'][\'starttime\'][\'config\'][\'size\'] = 12;
00158                         $TCA[\'pages\'][\'columns\'][\'endtime\'][\'config\'][\'eval\'] = \'datetime\';
00159                         $TCA[\'pages\'][\'columns\'][\'endtime\'][\'config\'][\'size\'] = 12;' . "\n";
00160         }
00161 }
00162 
00163 // check if a call is needed
00164 $call = true;
00165 if ($TYPO3_LOADED_EXT['_CACHEFILE'] != '' &&
00166         is_file(PATH_site . 'typo3temp/date2cal_cache.php')) {
00167         $t1 = filemtime(PATH_typo3conf . $TYPO3_LOADED_EXT['_CACHEFILE'] . '_ext_tables.php');
00168         $t2 = @filemtime(PATH_site . 'typo3temp/date2cal_cache.php');
00169         if (($t2 + 30) > $t1)
00170                 $call = false;
00171 }
00172 
00173 // exec class
00174 if ($call) {
00175         $date2cal = new tx_date2cal_extTables();
00176         unset($date2cal);
00177 } else {
00178         include_once(PATH_site . 'typo3temp/date2cal_cache.php');
00179 }
00180 
00181 }
00182 ?>

Generated on Thu Mar 20 21:55:20 2008 for date2cal by  doxygen 1.5.3