Core API

3.8.5. A few examples of extending the backend classes

The concept of extending classes in the backend can come in handy in many cases. First of all it's a brilliant way to make your own project specific extensions to TYPO3 without spoiling the compatibility with the distribution! This is a very important point! Stated another way: By making an "XCLASS extension" you can change one method in a TYPO3 class and next time you update TYPO3, your method is still there - but all the other TYPO3 code has been updated! Great!

Also for development and experimental situations is great. Generally the concept offers you quite a lot of freedom, because you are seriously able to take action if you need something solved here and now which cannot be fixed in the main distribution at the moment.

Anyway, here's a few simple examples:

1) Say you wish to have the backend user time out after 30 seconds instead of the default 6000.

  1. In localconf.php, insert:
    $TYPO3_CONF_VARS["BE"]["XCLASS"]["t3lib/class.t3lib_beuserauth.php"]
    =PATH_typo3conf."class.ux_myBackendUserExtension.php";

  2. Create the file "class.ux_myBackendUserExtension.php" in typo3conf/ folder and put this content in:

  
<?php


class
ux_t3lib_beUserAuth
extends
t3lib_beUserAuth
{
var

$auth_timeout_field
=
30
;
}


?>

 

Of course you need to know why it's the variable

auth_timeout_field

which must be set, but you are a bright person, so of course you go directly to the file t3lib/class.t3lib_beuserauth.php, open it and find that

var 

$auth_timeout_field 

= 6000;

there!

You could also easily insert an IP-filter (which is already present though...). Here you have to take a little adventure a bit further. As you see in "class.t3lib_beuserauth.php" extends "t3lib_userAuthGroup" which extends "t3lib_userAuth" the method start() is the place where the users are authenticated. This could quickly be exploited to make this IP filter for the backend:

  
<?php


class
ux_t3lib_beUserAuth
extends
t3lib_beUserAuth
{
var

$auth_timeout_field
=
30
;

function

start
() {
if (!

t3lib_div
::
cmpIP
(
getenv
(
"REMOTE_ADDR"
),
"192.168.*.*"
)) {
die(

"Wrong IP, you cannot be authenticated!"
);
} else {
return

parent
::
start
();
}
}
}


?>

 

So now only users with client IP numbers in the 192.168.*.* series will gain access to the backend. If that is the case, notice how the parent start() method is called and any result is returned. Thus your overriding method is a wrapped for the original. Brilliant, right!

Here's another one:

  
<?php


class
ux_t3lib_TCEforms
extends
t3lib_TCEforms
{
function

formWidth
(
$size
=
48
,
$textarea
=
0
) {

$size
=
round
(
$size
*
1.5
);
return

parent
::
formWidth
(
$size
,
$textarea
);
}
function

printPalette
(
$palArr
) {

reset
(
$palArr
);
while(list(

$k
)=
each
(
$palArr
)) {

$palArr
[
$k
][
"NAME"
] =
strtoupper
(
$palArr
[
$k
][
"NAME"
]);
}
return

parent
::
printPalette
(
$palArr
);
}
}


?>

 

... and configured in localconf.php as this:

  $TYPO3_CONF_VARS["BE"]["XCLASS"]["t3lib/class.t3lib_tceforms.php"]
=PATH_typo3conf."class.ux_myTCEformsExtension.php";

 

The result is this; Normally the "General options" palette of the forms in the backend looks like this:


 

But the extensions does two things: 1) All formfields have their width multiplied with 1.5 so they are wider, 2) the titles of the palette-fields are converted for uppercase. Looks like this:

 


So as you see you can do really stupid details - in fact almost any extension.

To top


Valid XHTML 1.0!