Montag, 28. Februar 2011

Call user functions with USER_INT

Custom PHP in Typoscript

These two listing just shall show you a working example of calling custom PHP functions from Typoscript. I just publish this because in all the existing examples I found some details were missing.

The following listing shows usage of USER_INT which causes no caching of this content element. Please note that your class needs to have a prefix "user_" to be excuted via userFunc. Use admin panel to get according feedback.

includeLibs.hashTools = fileadmin/hashTools.php
page.200 = USER_INT
page.200 {
  userFunc = user_MyTools->testFunction
 }

Following PHP listing shows a simple function to be called via Typoscript.
<?php

class user_MyTools {

  function testFunction($content,$conf) {
     return "Hallo Welt!";
  }

}

?>

Typoscript link with parameters

How to create an external link with parameters with Typoscript

Have you ever had the need to add to an external link some dynamic parameters? Well before you grab your PHP editor and start developing have a look into the following Typoscript listing:

[loginUser = *]

page.201 = COA_INT
page.201 {
10 = TEXT
10.value = My fancy link
10.typolink.parameter {
  dataWrap = http://www.mysite.de/index.php?param=value&id={TSFE:fe_user|user|uid}&name={TSFE:fe_user|user|username}_{TSFE:fe_user|user|city}
 }
}
[global]
What this script does is it creates a link using typolink function and you can add some parameters to it. Good thing here is, that can add some dynamic parameters such as user name of current logged in user.

With accessing TSFE which is the central array that Typo3 uses to store almost everything you can add many more interesting parameters.

Please note that content object used here is COA_INT and that means this is generated every time a page is displayed. This way for every user this example creates a proper parameter.

Dienstag, 22. Februar 2011

Powershell test Web Service

For all of you who haven't touched it yet - Microsoft has put an interesting shell to Windows operating systems called Powershell. Following code creates a web service stub (proxy in dot.net speak) and calls a method. If you call a web service that is running on a IIS you often need some kind of authentication.
#  build credential object 
$Pass = ConvertTo-SecureString " xxxx " –AsPlaintext –Force
$Cred = New-Object System.Management.Automation.PsCredential "domain\User",$Pass

# just a simple web service tester
$wsProxy = New-WebServiceProxy -Credential $Cred -URI http://yourserver.com/path?WSDL
$result = $wsProxy.WebServiceMethod('Parameter') 
$result


To use this example you need to replace WebServiceMethod with the web service method you want to use. It is up to you to provide proper parameters. Having a look into service's WSDL file will help here.

General note, execution of unsigend srcripts needs to be activated. Please see
http://www.windowsecurity.com/articles/PowerShell-Security.html for more information.