dracoblue.net

Unix timestamps in Talend Open Studio

Today (while migrating the userdata for dracoblue.net) I was facing the issue, that I needed to transform the unix timestmaps (used by SimpleMachinesForum) into date-objects.

After trying different things, I noticed that the easiest way is the java-function to create a new Date-Object.

Converting UnixTimestamp (int/long) to Date:

new java.sql.Timestamp(new Long(row1.registerDate)*1000)

Explanation: Since the Timestamp expects milliseconds since 01/01/1970, but I have seconds, I need to multiply be 1000. But since the initial Value may be a int, which can't be that big we need to convert it to Long first.

Converting Date String (e.g. dd.MM.yyyy) to UnixTimestamp:

(TalendDate.parseDate("dd.MM.yyyy",row1.registerDate)).getTime()

Converting Date Object to UnixTimestamp:

row1.registerDate.getTime()

In java, open source, talend by DracoBlue @ 15 Feb 2009 | 120 Words

How to install and run latest (stable) PHP for Eclipse (PDT)

If you want to run latest stable 2.1 version of PDT (the eclipse extension for PHP) you'll find a all-in-one version at the

eclipse pdt download page.

Just scroll down a bit, until you find 2.1.0 Stable Builds and download All-In-One (around 167MB).

Once downloaded the .zip file, copy the contents of that file to a directory.

Windows-Users: Copy it somewhere with a short path, e.g. [em]c:\eclipse[/em] ( good!) or [em]c:\apps\eclipse[/em] ( good!). Do not install it to [em]c:\program files\eclipse[/em] ( not!) or [em]c:\document and settings\jan\apps\eclipse[/em] ( not!). There are two reasons for this:
  • If you are running eclipse on e.g. VISTA or XP with insufficient rights to write the program files folder: it will tend to fail.
  • On Windows there is [x] a 260 characters for a path-name limit, you may exceed it if you put eclipse in a too extra ordinary root folder.

Launch the eclipse(.exe) in that folder.

Eclipse will launch and ask you where to put the workspace to. The workspace will be used as

cache and will store configuration files for each of your projects. You are still able to locate the projects outside of your workspace!

If you will have projects accessible only over network shares, put your workspace on your local disk and in [em]new project wizard[/em] select the network share. This will minimize load for cache/index.

In eclipse, open source, pdt for eclipse, php by DracoBlue @ 12 Feb 2009 | 240 Words

Agavi Age Validator

Hello,

a friend and I were wondering how would be best practice to implement an age validator in agavi. Since agavi already has the AgaviDateTimeValidator, my initial idea was, to extend that one and just re-interpret the min/max-parameters.

But a

minimum age of 18 would result into a max date of 1991-02-08. And a maximum age of 20 would result into a min date of 1989-02-08. So I had to swap the throwError's for max and min.

The resulting code:

class AgeValidator extends AgaviDateTimeValidator {
    protected function validate() {
        $min = $this->getParameter('min',null);
        $max = $this->getParameter('max',null);
        if (null !== $min) {
            $min_date = new DateTime(($min*(-1)).' years');
            $this->removeParameter('min');
            $this->setParameter('max',$min_date->format('Y-m-d'));
        }
        if (null !== $max) {
            $max_date = new DateTime(($max*(-1)).' years');
            if (null !== $min) $this->removeParameter('max'); // remove only, if _min_ was not set
            $this->setParameter('min',$max_date->format('Y-m-d'));
        }
        return parent::validate();
    }
    protected function throwError($index = null, $affectedArgument = null, $argumentsRelative = false, $setAffected = false)
    {
        if ($index == 'max' || $index == 'min') {
            // Swap those, since we faked them for the default behaviour
            $index = ($index == 'max' ? 'min' : 'max');
        }
        return parent::throwError($index, $affectedArgument, $argumentsRelative, $setAffected);
    }
}

Do you got any other ideas how to solve that in a gentle way?

  • Draco

In agavi, open source, php, validator by DracoBlue @ 08 Feb 2009 | 211 Words

Access HTTP_USER_AGENT/HTTP_* in Agavi

If you try to do retrive the users browsers by accessing $SERVER['HTTPUSER_AGENT'] in agavi, you'll have no luck.

It's common in agavi, that all user input must be validated. Thus for instance $SERVER['SERVERNAME'] can not be manipulated by the user and is therefor accessible by using the $_SERVER global.

But $_SERVER'HTTPUSERAGENT' are transfered by the browser and pretend to be valid and normalized. Therefor you need to validate them with a validator.

A sample validator, for retrieving the HTTPUSERAGENT of the accessing user:

<validator class="string" [strong]source="headers"[/strong]>
    <argument>USER_AGENT</argument>
</validator>

As you can see, I highlighted the [em]source="headers"[/em] part of the code. The reason is, that the AgaviWebRequest fills all received data (post with files and data, get parameters, cookies and headers) into different parts of the request data.

Since the user supplied data in the header all starts with a HTTP, it got stripped. So if you want to validate [em]HTTPUSERAGENT[/em] you have to validate [em]USERAGENT[/em].
As result a

$rd->getParameter('USER_AGENT')

will just fail, because the USER_AGENT is not send in the POST/GET-Parameters, but send as header. So correct access on that value is:

$rd->get('headers','USER_AGENT')

Since we are using AgaviWebRequestDataHolder ($rd), we may also use:

$rd->getHeader('User-Agent');

to access it. Thanks to

Wombert for pointing that out.

In agavi, open source, php, validator by DracoBlue @ 07 Feb 2009 | 231 Words

Registration closed

Hello,

while updating the site I have to switch of the registration. It will be available again in next days. Sorry for the inconvience!

  • Draco

In dracoblue.net by DracoBlue @ 07 Feb 2009 | 27 Words

Page 28 - Page 29 - Page 30

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About