Project

General

Profile

Feature #13579 ยป 13579.diff

Xavier Perseguers, 2011-03-03 15:08

View differences:

t3lib/class.t3lib_db.php
// Default character set, applies unless character set or collation are explicitely set
var $default_charset = 'utf8';
/**
* @var t3lib_DB_preProcessQueryHook[]
*/
protected $preProcessHookObjects;
/**
* @var t3lib_DB_postProcessQueryHook[]
*/
protected $postProcessHookObjects;
/************************************
*
......
if ($this->debugOutput) {
$this->debug('exec_INSERTquery');
}
foreach ($this->postProcessHookObjects as $hookObject) {
$hookObject->exec_INSERTquery_postProcessAction($table, $fields_values, $no_quote_fields, $this);
}
return $res;
}
......
if ($this->debugOutput) {
$this->debug('exec_INSERTmultipleRows');
}
foreach ($this->postProcessHookObjects as $hookObject) {
$hookObject->exec_INSERTmultipleRows_postProcessAction($table, $fields, $rows, $no_quote_fields, $this);
}
return $res;
}
......
if ($this->debugOutput) {
$this->debug('exec_UPDATEquery');
}
foreach ($this->postProcessHookObjects as $hookObject) {
$hookObject->exec_UPDATEquery_postProcessAction($table, $where, $fields_values, $no_quote_fields, $this);
}
return $res;
}
......
if ($this->debugOutput) {
$this->debug('exec_DELETEquery');
}
foreach ($this->postProcessHookObjects as $hookObject) {
$hookObject->exec_DELETEquery_postProcessAction($table, $where, $this);
}
return $res;
}
......
if ($this->debugOutput) {
$this->debug('exec_TRUNCATEquery');
}
foreach ($this->postProcessHookObjects as $hookObject) {
$hookObject->exec_TRUNCATEquery_postProcessAction($table, $this);
}
return $res;
}
......
// Table and fieldnames should be "SQL-injection-safe" when supplied to this
// function (contrary to values in the arrays which may be insecure).
if (is_array($fields_values) && count($fields_values)) {
foreach ($this->preProcessHookObjects as $hookObject) {
$hookObject->INSERTquery_preProcessAction($table, $fields_values, $no_quote_fields, $this);
}
// quote and escape values
$fields_values = $this->fullQuoteArray($fields_values, $table, $no_quote_fields);
......
// Table and fieldnames should be "SQL-injection-safe" when supplied to this
// function (contrary to values in the arrays which may be insecure).
if (count($rows)) {
foreach ($this->preProcessHookObjects as $hookObject) {
$hookObject->INSERTmultipleRows_preProcessAction($table, $fields, $rows, $no_quote_fields, $this);
}
// Build query:
$query = 'INSERT INTO ' . $table .
' (' . implode(', ', $fields) . ') VALUES ';
......
// Table and fieldnames should be "SQL-injection-safe" when supplied to this
// function (contrary to values in the arrays which may be insecure).
if (is_string($where)) {
foreach ($this->preProcessHookObjects as $hookObject) {
$hookObject->UPDATEquery_preProcessAction($table, $where, $fields_values, $no_quote_fields, $this);
}
$fields = array();
if (is_array($fields_values) && count($fields_values)) {
......
*/
function DELETEquery($table, $where) {
if (is_string($where)) {
foreach ($this->preProcessHookObjects as $hookObject) {
$hookObject->DELETEquery_preProcessAction($table, $where, $this);
}
// Table and fieldnames should be "SQL-injection-safe" when supplied to this function
$query = 'DELETE FROM ' . $table .
......
* @return string Full SQL query for TRUNCATE TABLE
*/
public function TRUNCATEquery($table) {
foreach ($this->preProcessHookObjects as $hookObject) {
$hookObject->TRUNCATEquery_preProcessAction($table, $this);
}
// Table should be "SQL-injection-safe" when supplied to this function
// Build basic query:
$query = 'TRUNCATE TABLE ' . $table;
......
1270853884
);
}
// Prepare user defined objects (if any) for hooks which extend query methods
$this->preProcessHookObjects = array();
$this->postProcessHookObjects = array();
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_db.php']['queryProcessors'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_db.php']['queryProcessors'] as $classRef) {
$hookObject = t3lib_div::getUserObj($classRef);
if (!($hookObject instanceof t3lib_DB_preProcessQueryHook || $hookObject instanceof t3lib_DB_postProcessQueryHook)) {
throw new UnexpectedValueException('$hookObject must either implement interface t3lib_DB_preProcessQueryHook or interface t3lib_DB_postProcessQueryHook', 1299158548);
}
if ($hookObject instanceof t3lib_DB_preProcessQueryHook) {
$this->preProcessHookObjects[] = $hookObject;
}
if ($hookObject instanceof t3lib_DB_postProcessQueryHook) {
$this->postProcessHookObjects[] = $hookObject;
}
}
}
}
/**
t3lib/core_autoload.php
't3lib_cache_frontend_stringfrontend' => PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_stringfrontend.php',
't3lib_cache_frontend_variablefrontend' => PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_variablefrontend.php',
't3lib_cache_frontend_frontend' => PATH_t3lib . 'cache/frontend/interfaces/interface.t3lib_cache_frontend_frontend.php',
't3lib_db_preprocessqueryhook' => PATH_t3lib . 'interfaces/interface.t3lib_db_preprocessqueryhook.php',
't3lib_db_postprocessqueryhook' => PATH_t3lib . 'interfaces/interface.t3lib_db_postprocessqueryhook.php',
't3lib_error_abstractexceptionhandler' => PATH_t3lib . 'error/class.t3lib_error_abstractexceptionhandler.php',
't3lib_error_debugexceptionhandler' => PATH_t3lib . 'error/class.t3lib_error_debugexceptionhandler.php',
't3lib_error_errorhandler' => PATH_t3lib . 'error/class.t3lib_error_errorhandler.php',
t3lib/interfaces/interface.t3lib_db_postprocessqueryhook.php
<?php
/***************************************************************
* Copyright notice
*
* (c) 2011 Xavier Perseguers <typo3@perseguers.ch>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Created by JetBrains PhpStorm.
* User: xavier
* Date: 03.03.11
* Time: 14:20
* To change this template use File | Settings | File Templates.
* Interface for classes which hook into t3lib_DB and do additional processing
* after a query has been executed.
*
* @author Xavier Perseguers <typo3@perseguers.ch>
* @package TYPO3
* @subpackage t3lib
*/
interface t3lib_DB_postProcessQueryHook {
/**
* Post-processor for the exec_INSERTquery method.
*
* @param string $table Database table name
* @param array $fieldsValues Field values as key => value pairs
* @param string/array $noQuoteFields List/array of keys NOT to quote
* @param t3lib_DB $parentObject
* @return void
*/
public function exec_INSERTquery_postProcessAction($table, array $fieldsValues, $noQuoteFields, t3lib_DB $parentObject);
/**
* Post-processor for the exec_INSERTmultipleRows method.
*
* @param string $table Database table name
* @param array $fields Field names
* @param array $rows Table rows
* @param string/array $noQuoteFields List/array of keys NOT to quote
* @param t3lib_DB $parentObject
* @return void
*/
public function exec_INSERTmultipleRows_postProcessAction($table, array $fields, array $rows, $noQuoteFields, t3lib_DB $parentObject);
interface t3lib_DB_postprocessQueryHook {
/**
* Post-processor for the exec_UPDATEquery method.
*
* @param string $table Database table name
* @param string $where WHERE clause
* @param array $fieldsValues Field values as key => value pairs
* @param string/array $noQuoteFields List/array of keys NOT to quote
* @param t3lib_DB $parentObject
* @return void
*/
public function exec_UPDATEquery_postProcessAction($table, $where, array $fieldsValues, $noQuoteFields, t3lib_DB $parentObject);
/**
* Post-processor for the exec_DELETEquery method.
*
* @param string $table Database table name
* @param string $where WHERE clause
* @param t3lib_DB $parentObject
* @return void
*/
public function exec_DELETEquery_postProcessAction($table, $where, t3lib_DB $parentObject);
/**
* Post-processor for the exec_TRUNCATEquery method.
*
* @param string $table Database table name
* @param t3lib_DB $parentObject
* @return void
*/
public function exec_TRUNCATEquery_postProcessAction($table, t3lib_DB $parentObject);
}
?>
t3lib/interfaces/interface.t3lib_db_preprocessqueryhook.php
/**
* Interface for classes which hook into t3lib_DB and do additional processing
* after a query has been executed.
* before a query has been executed.
*
* @author Xavier Perseguers <typo3@perseguers.ch>
* @package TYPO3
* @subpackage t3lib
*/
interface t3lib_DB_postprocessQueryHook {
interface t3lib_DB_preProcessQueryHook {
/**
* Post-processor for the exec_INSERTquery method.
* Pre-processor for the INSERTquery method.
*
* @param string $table Database table name
* @param array $fieldsValues Field values as key => value pairs
......
* @param t3lib_DB $parentObject
* @return void
*/
public function exec_INSERTquery_postProcessAction($table, array $fieldsValues, $noQuoteFields, t3lib_DB $parentObject);
public function INSERTquery_preProcessAction($table, array $fieldsValues, $noQuoteFields, t3lib_DB $parentObject);
/**
* Post-processor for the exec_INSERTmultipleRows method.
* Pre-processor for the INSERTmultipleRows method.
*
* @param string $table Database table name
* @param array $fields Field names
......
* @param t3lib_DB $parentObject
* @return void
*/
public function exec_INSERTmultipleRows_postProcessAction($table, array $fields, array $rows, $noQuoteFields, t3lib_DB $parentObject);
public function INSERTmultipleRows_preProcessAction($table, array $fields, array $rows, $noQuoteFields, t3lib_DB $parentObject);
/**
* Post-processor for the exec_UPDATEquery method.
* Pre-processor for the UPDATEquery method.
*
* @param string $table Database table name
* @param string $where WHERE clause
......
* @param t3lib_DB $parentObject
* @return void
*/
public function exec_UPDATEquery_postProcessAction($table, $where, array $fieldsValues, $noQuoteFields, t3lib_DB $parentObject);
public function UPDATEquery_preProcessAction($table, $where, array $fieldsValues, $noQuoteFields, t3lib_DB $parentObject);
/**
* Post-processor for the exec_DELETEquery method.
* Pre-processor for the DELETEquery method.
*
* @param string $table Database table name
* @param string $where WHERE clause
* @param t3lib_DB $parentObject
* @return void
*/
public function exec_DELETEquery_postProcessAction($table, $where, t3lib_DB $parentObject);
public function DELETEquery_preProcessAction($table, $where, t3lib_DB $parentObject);
/**
* Post-processor for the exec_TRUNCATEquery method.
* Pre-processor for the TRUNCATEquery method.
*
* @param string $table Database table name
* @param t3lib_DB $parentObject
* @return void
*/
public function exec_TRUNCATEquery_postProcessAction($table, t3lib_DB $parentObject);
public function TRUNCATEquery_preProcessAction($table, t3lib_DB $parentObject);
}
    (1-1/1)