Pastebin Module for Phprojekt6

During the Mayflower barcamp 2009 we (Stephanie and Maria) decided to develop a pastebin module for Phprojekt6.
Pastebins are an easy way to share code among developers. Often instant messaging systems are used for that purpose which is not quite comfortable (formatting gets lost, searching in history is tedious, security issues). There are a view public pastebins but the problem is, that everyone can access your code snippets. This is not always allowed when developing software for customers. So we thought a pastebin module for P6 would be great, since the access is limited to the users of P6.

With the P6 Pastebin Module you can do the following things:

  • create, update and delete code snippets
  • simply share the code snippets by passing the link to other users
  • comment code snippets
  • apply syntax highlighting for the following languages (C++, CSS, Delphi, django, HTML, JavaScript, PHP, Python, SQL, XML)
  • apply automatic line numbering of the code
  • mark code lines
  • use themes to present the code snippets in different styles.

A default code snippet is shown in the following screenshot.

To implement the syntax highlighting we were using the dojox.highlighter and added functionalities
like code marking and line numbering. The themes are provided by dojox.highlight and allow you to color the code in different ways like Emacs or Borland style. More than ten themes are available at the moment.

The picture below shows the „native“ theme.

The P6 Pastebin module will be available with the next release of Phprojekt6. Use it for more effective collaboration with your fellow developers or for creating a valuable personal code snippet library that documents your evolving skills as a developer!

Have fun using the P6 Pastebin module! We look forward to receiving your comments!

All the best Stephanie & Maria

Using LDIF to simulate LDAP transactions with PHP

LDIF is the acronym for LDAP Data Interchange Format and a text format to represent LDAP information ( Respectively an LDIF file is a simple text file that can contain those LDAP information, which can be separated into two groups. On the one hand, it can hold exported LDAP data in a text format. The other purpose of LDIF is to use it for importing data into an LDAP based system. So it can contain data to be imported or just commands that shall be processed. This is an important fact, because that opens the door to an interesting workaround. Though LDAP does not support transactions, which can be a real problem, LDIF can do the job for you. Transactions are important whenever some instructions have to be performed atomically. That means that a set of instructions can not be disturbed by any other commands of another client. A good example would be a scenario where you first read a record and then perform actions (like update or delete) on that record. Without transactions it is not possible to make sure the record still exists after you read it.

Using LDIF requires ldap client binaries. You can chose between the following client programs.

  • ldapsearch
  • ldapcompare
  • ldapcmp
  • ldapdelete
  • ldapmodify

Those binaries can be found in the Open Ldap distribution or in the Sun ONE Directory SDK for C 5.08 (
To import data ldapmodify is the best choice. It is necessary to call that binary with the right connect parameters which are host name, user name, password and of course the file to import. The php code snippet would look like the following (the call itself is done by the PHP function proc_open):

        //  Using ldapmodify with pipes to ensure safe transactions
	$descriptorspec = array(
		0 => array("pipe", "r"),  	// stdin is a pipe that the child will read from
		1 => array("pipe", "w"),  	// stdout is a pipe that the child will write to
		2 => array("pipe", "w") 	// stderr is a pipe that the child will write to
	$pipes = array();
	//  build LDAP-Command								
	$comm = $ldapPath.'ldapmodify -h "'.$host.'" -D "'. $user.'" -w "'. $pwd .'"  -f '.$filename;
	// call ldapmodify
	$process = proc_open($comm, $descriptorspec, $pipes);

	if (is_resource($process)) {
		// $pipes now looks like this:
		// 0 => writeable handle connected to child stdin
		// 1 => readable handle connected to child stdout

		fwrite($pipes[0], '');

		// check for output
		$out = "";
		while (!feof($pipes[1])) {
			$out .= fgets($pipes[1], 1024);

		// check for errors
		$err = '';
		while (!feof($pipes[2])) {
			$err .= fgets($pipes[2], 1024);

		// It is important that you close any pipes before calling
		// proc_close in order to avoid a deadlock
		$return_value = proc_close($process);

		if ($err != '') {
			// TODO: Handle error
		} else {
			// TODO: Handle result

The Code creates a command string with the needed connection parameters and the filename. This string is used as a parameter of the proc_open function which executes the command. That has the effect that the LDIF file is imported and cannot be disturbed by any other client, in other words it is executed atomically which leads to the concept of transactions.

Accessing Nike+ data with PHP

Nike+ is a feature for the iPod nano which allows to measure time, distance and speed of runnings with a small sensor in running shoes that sends data to a transmitter on the iPod. Those data are sent to a users Nike+ account by iTunes whenever the iPod is synchronized. On the Nike+ website there is a report of runnings, the average speed, total kilometers run etc. The users can also compete with each other in virtual competitions and define goals to run more often, faster or a longer distance. The Nike+ website displays the data graphically with Adobe Flash.

There is no official API that allows you to use the raw data. Nevertheless the data are sent to the Flash via XML so there is a chance to use them. For PHP Rasmus Lerdorf himself has implemented a class to access these data. The class allows to authenticate a user and fetch the running data of a user in a XML-Format. This class can be found under Nike+ PHP API. To use that class you just have to create an object and pass the user credentials and optional caching parameters:

$mynike = new NikePlus("", "password");

After the instantiation the object contains a SimpleXML object with all running information of that user that can be processed by any PHP application. The variables $data, $run, $challenges and $goals hold the information of the user account, runnings, ongoing challenges with other users and the personal goals of a user.
A partial output of the $data variable is shown below and contains among other things the total statistics of a user and the last recent run. The other data are represented in a similar way.

object(SimpleXMLElement)#3 (5) {
  object(SimpleXMLElement)#7 (4) {
    string(8) "106.5635"
    string(8) "40500702"
    string(2) "21"
    string(4) "5195"
  object(SimpleXMLElement)#9 (4) {
    array(1) {
      string(10) "1155526254"
    string(25) "2008-04-20T10:40:54+02:00"
    string(6) "6.6107"
    string(7) "2303090"

The Nike+ data can be used to display them on a website or to use them for mash up applications. For example there is already a word press plugin to display the data on a Blog System. Also there is another community called Runner+ which displays the data in a way similar to the Nike website.