Browsing Category "Programming"
1 Nov
2008

Lightbox Clones Matrix

  • english
  • german

As I'm currently validating different lightbox clones I'll advert to the brilliant "The Lightbox Clones Matrix" of PlanetOzh. It lists nearly all lightbox clones and gives the possibility to filter by features and used javascript framework. File size is displayed, too.

The Lightbox Clones Matrix

6 Aug
2008

Eclipse 3.4 Ganymede und PDT

  • english
  • german

Unfortunatly there is no working and official version of the PDT release for the current Eclipse release, Eclipse 3.4 Ganymede. However it is possible to use both. I found the solution within the Digital Base blog: Simply download the nightly build of PDT and integrate it as local site in the Eclipse update manager and then install. Quite easy.

24 Jul
2008

Javascript und Sonderzeichen.

  • english
  • german

I just found a website providing tools and information about javascript and special characters. My current problem was that I lost the special characters in an ajax call. Some trying later and it finally worked - check it out:

http://www.the-art-of-web.com/javascript/escape/

30 May
2008

TypoScript auslesen (eID und BE-Modul)

Manchmal muss man beim Entwickeln für Typo3 TypoScript an den unterschiedlichsten Stellen auslesen. Im folgenden zwei Beispiele, die mich gerade ein wenig auf die Probe gestellt haben.

TypoScript bei Nutzung von eID

Das Skript, welches mit eID angesprochen wird, ist ja lightweight und lädt erstmal nahezu nix vom Typo3-Kern. Nutzer und Datenbank sind schnell initialisiert, aber wenn man z.B. Werte aus dem TypoScript Setup des Plugins auslesen will geht das nicht nur mit einer Zeile Code. Dem eID-Skript muss auf irgendeine Weise die PageID übergeben werden (ich mache das mit einer Get-Variable), die braucht man nämlich, um das TSFE (das ja nicht da ist), ordentlich zu initialisieren. Man instanziiert sich eine tslib_fe Klasse, verbindet zur Datenbank, initialisiert den Nutzer, das Template und die Config und schon ist man fertig:

// eID specific initialization of user and database
tslib_eidtools::connectDB();
tslib_eidtools::initFeUser();
 
// initialize TSFE
require_once(PATH_tslib.'class.tslib_fe.php');
require_once(PATH_t3lib.'class.t3lib_page.php');
$temp_TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
$GLOBALS['TSFE'] = new $temp_TSFEclassName($TYPO3_CONF_VARS, $pid, 0, true);
$GLOBALS['TSFE']->connectToDB();
$GLOBALS['TSFE']->initFEuser();
$GLOBALS['TSFE']->determineId();
$GLOBALS['TSFE']->getCompressedTCarray();
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->getConfigArray();

Nun kann man altbekannt via

$GLOBALS['TSFE']->tmpl->setup['plugin.']['extensionkey.']['your_value']

auf die Daten zugreifen. Mit der letzten Codezeile kann man übrigens auch in nicht vollständig initialisierten Plugins das TypoScript beliebig auslesen.

TypoScript in Backend-Modulen

In Backend-Modulen ist es auch manchmal notwendig, auf das TypoScript Setup zuzugreifen, zum Beispiel beim Senden einer Email, um den Absender auszulesen etc. Der Ablauf ist ähnlich wie bei eID, jedoch ermitteln wir selber die RootPageID und nutzen die t3lib_pageSelect und t3lib_tsparser_ext Klassen. Ich habe das ganze in eine Funktion gepackt, da man das ja nicht unbedingt immer braucht:

/**
 * Loads the TypoScript for the given extension prefix, e.g. tx_cspuppyfunctions_pi1, for use in a backend module.
 *
 * @param string $extKey
 * @return array
 */
function loadTypoScriptForBEModule($extKey) {
	require_once(PATH_t3lib . 'class.t3lib_page.php');
	require_once(PATH_t3lib . 'class.t3lib_tstemplate.php');
	require_once(PATH_t3lib . 'class.t3lib_tsparser_ext.php');
	list($page) = t3lib_BEfunc::getRecordsByField('pages', 'pid', 0);
	$pageUid = intval($page['uid']);
	$sysPageObj = t3lib_div::makeInstance('t3lib_pageSelect');
	$rootLine = $sysPageObj->getRootLine($pageUid);
	$TSObj = t3lib_div::makeInstance('t3lib_tsparser_ext');
	$TSObj->tt_track = 0;
	$TSObj->init();
	$TSObj->runThroughTemplates($rootLine);
	$TSObj->generateConfig();
	return $TSObj->setup['plugin.'][$extKey . '.'];
}

Und damit hätte man wieder ein paar Typo3-Probleme weniger...

12 Apr
2008

Function/Class ‘…’ was not prepended with ‘user_’

  • english
  • german

I'm currently configuring one of my extension for "realurl" within Typo3. My aim is to have the categories and subcategories of an article center within the url. But the functionality of "lookUpTable" does not suffice as I have to observe the nesting of the categories. So I choose "userFunc" and enter the values as given in the realurl documentation:

'fixedPostVars' => array(
	'articlecenter' => array(
		'userFunc' => 'EXT:extkey/class.tx_userxyz.php:
			&tx_realurl_userfunctest->main',
	),
),

then I clear the cache and it happens... nothing. Only a nice error message is presented:

|Function/Class 'E' was not prepended with 'user_'|

Seems that my configured values do not really reach the code they should. And of course that's the way it is. After some searching I detect that my configuration is wrong, because realurl is putting all configured values into a nested array wherein every key-value pair is put in as an array that has a numeric indice in the big array. (I hope you can follow my poor english). But my "userFunc" is not set up this way, its numeric indice is "userFunc" and the array with the key-value pairs is the string "EXT:realurl/class.tx_realurl_userfunctest.php:&tx_realurl_userfunctest->main". As realurl runs through this array using foreach it has only "E" as value (that comes from the "EXT") and furthermore the error is thrown in t3lib_div:callUserFunction.
Now the solution is quite easy, simply nest the userFunc within an additional array:

'fixedPostVars' => array(
	'articlecenter' => array(
		array(
			'userFunc' => 'EXT:extkey/class.tx_userxyz.php:
				&tx_realurl_userfunctest->main',
		),
	),
),

Now everything is working again. You only need to find it out...

24 Mar
2008

eSteak – hot MooTools-slices

  • english
  • german

By now there are many javascript frameworks available that make programming easy and encapsulate new and cool functionalities. Surely every framework has its advantages and disadvantages but in my opinion you can't switch between all of them - you have to deceide in favour of one. In my case I have chosen Mootools, as you may have already seen here...
A friend of mine and also a co-worker, Grundi, has created a site that answers to the beautiful name of "eSteak" that unites the different scripts for Mootools on a central place, with rating, Mootools dependency listing and so on. The whole thing is user generated content, so its up to all the Mootools developers and even to you to upload scripts and support it! Because the problem with Mootools is that there are really cool scripts out there, but you first have to find them. I hope that eSteak will be filled with a lot of scripts and that it will develop to the central place for Mootools friends and enthusiasts.

16 Feb
2008

Typo3: erstellbare Elemente auf Seite limitieren.

[german]In Typo3 ist es des öfteren sinnvoll, die erstellbaren Elemente auf einer Seite zu limitieren. Vor allem bei SysFoldern in denen man jeweils nur bestimmte Elemente speichern will macht das Sinn, denn im SysFolder "Nutzer" möchte ich eher keine anderen Elemente haben. Außerdem erhöht das die Übersichtlichkeit und bringt Redakteure nicht dazu, neue Elemente "einfach irgendwohin" zu speichern.

In der TSConfig der entsprechenden Seite muss man einfach nur:

mod.web_list.allowedNewTables = db_tablename,db_tablename_2

angeben, wobei db_tablename entsprechend die Namen der Datenbanktabellen der Elemente sind.

[/german]

5 Jan
2008

Configure Mercury mail transport system for external mail

  • english
  • german

Usually I develope my projects locally on my pc. Needless to say that you sometimes have to send an email from your script to external mail to check if everything is fine. So you need to configure your system in a way that your local apache webserver is able to send mail to external addresses.
I always use XAMPP for Windows because it contains everything you need for developing PHP applications as well as all the stuff for sending mails: fake sendmail und Mercury Mail Transport System. I reference to XAMPP 1.6.5 (for Windows) and Mercury 4.5 here. Mercury is already pre-configured in XAMPP - all settings that I don't explicitly address stay as they are :)

I'm writing this because I'm not a mail professional and read a lot of tutorials and none of them really worked. So I extracted what I needed and put it all together. An important assumption for this tutorial is that you have your own SMTP server, for example the one that your webspace hoster provides.

So let's get started:

  1. start Mercury (using the XAMPP Controlpanel) and then open the admin panel.
  2. first of all we disable the HTTP server of Mercury so that it doesn't conflict with the apache:
    1. "Configuration" -> "Protocol modules"
    2. disable the check "MercuryB HTTP web server"
    3. I also disabled "Mercury IMAP4rev1 server" because I won't need that one
    4. leave the window opened, we'll need it immediatly
  3. to be able to send external mail we have to disable "MercuryE SMTP end-to-end delivery client" in the same dialog and enable "MercuryC SMTP relaying client". Click "OK" and restart Mercury!
  4. now let's configure Mercury in general:
    1. "Configuration" -> "Mercury core module", tab "General"
    2. we want to send from localhost, therefore we check if "localhost" is the value of "internet name for this system" and adjust that if not
    3. all other settings stay the same as they are already configured, but we'll have a look to the checkboxes beneath:
    4. disable all but "Send copies of all errors to postmaster"
    5. check under the tab "Local domains" if the entry "localhost (local host or server) localhost (internet name)" is there, if not, add it
    6. click "OK" and leave the dialog
  5. next we focus on the MercuryS SMTP Server for outgoing emails:
    1. "Configuration" -> "MercuryS SMTP Server"
    2. choose the tab "General" and add a wonderful name for your SMTP server under "Announce myself as", simply fill in any name, I've chosen "CS SMTP".
    3. under "Listen on TCP/IP port" fill in "25", that's the SMTP port
    4. add "127.0.0.1" to "IP interface to use", that's the local IP of your pc. With the IP of the pc within the network (192.168.0.X) it doesn't work (at least for me)
    5. now we limit the access to the server so that only our local machine can access it:
      1. under "Connection Control" click on "Add restriction" and add the IP range from "127.0.0.1" till "127.0.0.1" (it's that simple, isn't it?)...
      2. and select "Allow connections"...
      3. and leave all checkboxes deselected
    6. with a click on "OK" we quit the dialog and we're looking forward to the next one :)
  6. now let's configure the MercuryP POP3 Server:
    1. "Configuration"-> "MercuryP POP3 Server", select the tab "General"
    2. "Listen on TCP port" -> "110" and "IP interface to use" -> "127.0.0.1"
    3. choose the tab "Connection control" and proceed as already written under 5.5 (see above)
    4. that's it already, leave the dialog by clicking "OK"
  7. now we have the important one "MercuryC SMTP Client"
    1. "Configuration" -> "MercuryC SMTP Client"
    2. to send mail to external addresses we need to have an external SMTP server. If you're renting webspace somewhere and have mail included then you normally have access to a SMTP server. My webspace is hosted at HostEurope and I'll use the SMTP of my domain. Without such an external server the whole thing won't work because domain names won't be resolved among other things. I've chosen this path because I didn't feel like configuring around the whole day.
    3. enter the address of your SMTP under "Smart host name", for example "mail.meinedomain.com"
    4. depending on the way you access the server fill the values under "Connection port/type":
      1. for a "normal" SMTP that would probably be port 25 and "Normal (no SSL encryption)"
      2. I access my SMTP via SSL, that would be port 465 and "SSL encryption using direct connection"
      3. if you have other parameters simply try around a little :-)
    5. we finally fill in the "Login username" and the "Password" that normally is supplied by your webhost and we've nearly finished...
  8. let's check the Mercury users that are normally pre-configured:
    1. "Configuration"-> "Manage local users"
    2. there should be at least the users "Admin" and "postmaster", both with administrative rights. If not you have to add them.
  9. now we finished with Mercury, but we still need to configure PHP for sending mail with our scripts:
    1. we search and open the appropriate php.ini, using XAMPP you find it under "xampp/php/php.ini" in newer version and under  "xampp/apache/bin/php.ini" in older versions
    2. we search for "[mail function]"...
    3. and we add/adjust the following:
      1. "SMTP = localhost"
      2. "smtp_port = 25"
      3. "sendmail_from = postmaster@localhost"
    4. save the php.ini and restart the Apache
  10. now everything should work! But we'll test it first:
    1. within Mercury choose "File" -> "Send mail message" and send an email for testing purposes, I've chosen to send it to my googlemail account
    2. if the windows in Mercury are at sixes and sevens, choose "Window" -> "Tile" enjoy the view
    3. within the window "Mercury Core Prozess" we'll see our test mail at first:
      1. "13:38:41 JOB XXXXXX: from postmaster@localhost (local) To: XXX@googlemail.com (non-local) (JOB XXXXXX) -OK"
    4. the mail was received in Mercury and processed, after some seconds the window "Mercury SMTP client (relay version)" should show some actions:
      1. "05 Jan 2008 13:39, Servicing job XXXXXX ...OK"
      2. if you see this message, everything went fine and the mail was sent!
      3. if you don't get the message you have to find out why, possible reasons could be:
        1. wrong connection values for the SMTP server
        2. SMTP server doesn't allow relaying (from your host)
    5. now we'll test the whole thing from a PHP script and we'll write a wonderful one-liner into a PHP file:
      1. "mail('xxx@googlemail.com', 'Mercury test mail', 'If you can read this, everything was fine!');"
      2. call the PHP file within your browser, a command window should pop up shortly (or maybe not), it's from the fake sendmail of XAMPP, and focus back on Mercury:
        1. the produre is the same as above only that the SMTP server receives the mail from php before everything else happens
        2. you can watch this in the window "Mercury SMTP Server" and should see something like this: Mercury SMTP

I hope that worked for you, if not, feel free to leave a comment but as I already said, I'm not a professional but I'll help you as far as I can!

EDIT:
If you get the error message "SMTP server response: 553 We do not relay non-local mail, sorry." while sending from PHP go to Mercury under MercuryS -> Connection Control -> "Uncheck Do not Permit SMTP relaying to non-local mail" an check this option. Should fix the problem. Thanks to ron!

19 Nov
2007

WebService mit PHP Server und Java Client

  • english
  • german

For my current private project that answers to the nice name "Telrunya" I'm trying to access a PHP web service through a Java client. I once heard in a .NET codecamp that WebServices are super cool and that it doesn't matter in which language they are implemented. But that doesn't apply if you're communication between 2 different technologies. In the Guxx blog I found the reversed case, how to access a java server through a PHP client. There is also a Java bridge developed by Zend that manages the conversion of the objects. But that seems to be an independent server or at least a server modul but that isn't considered by me. (furthermore it costs money)

Anyway, I tried the whole thing withion NetBeans IDE with JAX-WS. My WSDL file (document) written in Eclipse was successfully parsed and the Java files for client etc. were created. The client was also able to access the service but it failed to convert the values. Monitoring the HTTP traffic I can see that the right values are returned, but the Java client returns "null". I already read a lot of documentations and tutorials but I didn't find out anything about converting the received data.
Maybe someone has an advide for me?

Well, the old school alternative works but it is lond winded. Therefore I simply create an URL in Java, set my SOAP function as "RequestProperty" and send an handmade (or even by soapUI created) SOAP envelope. The result is the corresponding envelope returned that now has to be stripped and the relevant data has to be extracted. It could be so simply with JAX-WS but isn't....

17 Nov
2007

WebServices testen mit soapUI

Seit einiger Zeit beschäftige ich mich WebServices im Rahmen eines Projektes mit ein paar Freunden. Aktuell arbeite ich auch gerade wieder an einem privaten Projekt, welches WebServices nutzt.
Geschrieben ist ein Service ja relativ schnell, wobei "schreiben" da eher nicht ganz passt. Ich nutze hauptsächlich Eclipse mit WST, wobei der Editor da einige Bugs hat, Refactoring funktioniert meistens nicht und die normale Generation einer WSDL ist auch nicht ganz sauber.
Um also zu testen, ob meine WSDL und der entsprechende SoapServer (habe ich bisher nur in PHP gemacht) richtig definiert und implementiert sind, verwende ich soapUI. Das ist eine sehr coole Java-Applikation, mit der man WebServices eben testen kann: einfach in der Bedienung und übersichtlich. Ich nutze das meist wirklich nur, um zu prüfen, ob die gewünschten Daten bei entsprechender Eingabe zurückgesendet werden.
soapUI erstellt auch automatisch anhand der WSDL Beispielanfragen mit den benötigten Parametern, aber es kann noch viel mehr: es ist eine ganze Testumgebung für WebServices inklusive Validierung, LoadTests und WebService Simulation. Da ich bisher noch nicht so weit gekommen bin, mal Tests für Serviceanfragen zu erstellen, kann ich zum Rest nicht wirklich viel sagen. Aber wer sich dafür interessiert, sollte sich das Programm mal anschauen.

http://www.soapui.org