|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2004-2009 Kasper Skårhøj (kasper@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 * Contains an example DBAL handler class 00029 * 00030 * $Id: class.tx_dbal_handler_openoffice.php 40828 2010-12-05 14:55:53Z xperseguers $ 00031 * 00032 * @author Kasper Skårhøj <kasper@typo3.com> 00033 */ 00034 /** 00035 * [CLASS/FUNCTION INDEX of SCRIPT] 00036 * 00037 * 00038 * 00039 * 74: class tx_dbal_handler_xmldb extends tx_dbal_sqlengine 00040 * 91: function init($config, &$pObj) 00041 * 128: function readDataSource($table) 00042 * 157: function saveDataSource($table) 00043 * 184: function xmlDB_writeStructure() 00044 * 193: function xmlDB_readStructure() 00045 * 00046 * SECTION: SQL admin functions 00047 * 217: function admin_get_tables() 00048 * 242: function admin_get_fields($tableName) 00049 * 276: function admin_get_keys($tableName) 00050 * 314: function admin_query($query) 00051 * 00052 * TOTAL FUNCTIONS: 9 00053 * (This index is automatically created/updated by the extension "extdeveval") 00054 * 00055 */ 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 /** 00067 * Example DBAL handler class 00068 * Stores data in an Open Office Calc Spreadsheet 00069 * 00070 * @author Kasper Skårhøj <kasper@typo3.com> 00071 * @package TYPO3 00072 * @subpackage tx_dbal 00073 */ 00074 class tx_dbal_handler_openoffice extends tx_dbal_sqlengine { 00075 00076 var $config = array(); 00077 var $pObj; // Set from DBAL class. 00078 00079 var $spreadSheetFiles = ''; 00080 var $unzip; // Object 00081 00082 /** 00083 * Initialize handler 00084 * 00085 * @param array Configuration from DBAL 00086 * @param object Parent object 00087 * @return boolean True on success. 00088 */ 00089 function init($config, $pObj) { 00090 $this->config = $config['config']; 00091 00092 if (t3lib_extMgm::isLoaded('libunzipped')) { 00093 00094 // Include Unzip library: 00095 require_once(t3lib_extMgm::extPath('libunzipped').'class.tx_libunzipped.php'); 00096 00097 // Find database file: 00098 $sxc_file = t3lib_div::getFileAbsFileName($this->config['sxc_file']); 00099 if (@is_file($sxc_file)) { 00100 00101 // Initialize Unzip object: 00102 $this->unzip = t3lib_div::makeInstance('tx_libunzipped'); 00103 $this->spreadSheetFiles = $this->unzip->init($sxc_file); 00104 00105 if (is_array($this->spreadSheetFiles)) { 00106 return TRUE; 00107 } else $this->errorStatus = 'Spreadsheet could not be unzipped...?'; 00108 } else $this->errorStatus = 'The Spreadsheet file "'.$sxc_file.'" was not found!'; 00109 } else $this->errorStatus = 'This data handler needs the extension "tx_libunzipped" to be installed!'; 00110 00111 return FALSE; 00112 } 00113 00114 /** 00115 * Setting table data (overriding function) 00116 * 00117 * @param string Table name 00118 * @return void 00119 */ 00120 function readDataSource($table) { 00121 if (!is_array($this->spreadSheetFiles)) { 00122 die('Spreadsheet Data Source FATAL ERROR: No spreadsheet file loaded. Init() must have failed!'); 00123 } 00124 00125 $this->data[$table] = array(); 00126 00127 // Read content.xml: 00128 $content_xml = $this->unzip->getFileFromArchive('content.xml'); 00129 00130 // Testing for writing back: 00131 $content_xml = str_replace('Felt A1','FELT A1',$content_xml); 00132 00133 // Writing file back (to database) 00134 $this->unzip->putFileToArchive('content.xml', $content_xml['content']); 00135 00136 // Writing ZIP content back to zip-archive file: 00137 $result = $this->unzip->compileZipFile($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'dbtest_output.sxc'); 00138 00139 debug($result); 00140 00141 exit; 00142 } 00143 00144 /** 00145 * Saving data source 00146 * 00147 * @param string Table name 00148 * @return boolean True on success 00149 */ 00150 function saveDataSource($table) { 00151 } 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 /************************************** 00162 * 00163 * SQL admin functions 00164 * (For use in the Install Tool and Extension Manager) 00165 * 00166 **************************************/ 00167 00168 /** 00169 * Returns the list of tables from the database 00170 * 00171 * @return array Tables in an array with tablename as key and an array with status information as value 00172 */ 00173 function admin_get_tables() { 00174 00175 $whichTables = array(); 00176 return $whichTables; 00177 } 00178 00179 /** 00180 * Returns information about each field in the $table 00181 * 00182 * @param string Table name 00183 * @return array Field information in an associative array with fieldname => field row 00184 */ 00185 function admin_get_fields($tableName) { 00186 return array(); 00187 } 00188 00189 /** 00190 * Returns information about each index key in the $table 00191 * 00192 * @param string Table name 00193 * @return array Key information in a numeric array 00194 */ 00195 function admin_get_keys($tableName) { 00196 return array(); 00197 } 00198 00199 /** 00200 * mysql() wrapper function, used by the Install Tool and EM for all queries regarding management of the database! 00201 * 00202 * @param string Query to execute 00203 * @return pointer Result pointer 00204 */ 00205 function admin_query($query) { 00206 00207 $parsedQuery = $this->parseSQL($query); 00208 $table = $parsedQuery['TABLE']; 00209 00210 if (is_array($parsedQuery)) { 00211 // Process query based on type: 00212 switch($parsedQuery['type']) { 00213 case 'CREATETABLE': 00214 break; 00215 case 'ALTERTABLE': 00216 break; 00217 case 'DROPTABLE': 00218 break; 00219 default: 00220 $this->errorStatus = 'Query type "'.$parsedQuery['type'].'" was not supported!'; 00221 break; 00222 } 00223 00224 } else $this->errorStatus = 'SQL parse error: '.$parsedQuery; 00225 00226 return FALSE; 00227 } 00228 } 00229 00230 00231 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/handlers/class.tx_dbal_handler_openoffice.php'])) { 00232 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/handlers/class.tx_dbal_handler_openoffice.php']); 00233 } 00234 00235 ?>
1.8.0