dracoblue.net

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

htmlspecialchars_decode for Mootools

This is a short function for Mootools decoding a string containing html entities to text.

function htmlspecialchars_decode(text)
{
    var stub_object = new Element('span',{ 'html':text });
    var ret_val = stub_object.get('text');
    delete stub_object;
    return ret_val;
}

Remember that you usually have no use for that function, because every element of mootools has a .get('text') function, which does the same.

In javascript, mootools by DracoBlue @ 06 Feb 2009 | 62 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