fix previous patch for metadata_dir 

Hi,

In previous patch $phpdir and $regdir are compute too late and thus get corrupted values (in case of non standard channel).

Other changes are mainly optimization (but also fix channel alias retrieval which seems broken, I'm working on this pear issue)

As I'm the fedora maintainer of this package, fedora which is the main user of this, perhaps you can give me access to this git repo ?