Page 1 of 1

BUG in getAliasName? - Strange aliases

Posted: 19 Dec 2008, 15:36
by zocha
Hello,

I've done a quick research of "alias" word in forum and do not found result connected with my problem.

I've found that aliases of images names generated by Phocagallery are very strange.

Examples:

Code: Select all

filename | name -> alias
news/1/ALPA_Dreamworlds_Holzherr.jpg | ALPA_Dreamworlds_Holzherr -> l-_-_
news/1/ALPA_Dreamworlds_Holzherr.jpg | ALPA_Dreamworlds -> _-_
news/1/ALPA_Dreamworlds_Holzherr.jpg | Mlotek -> l-_-_
news/1/ALPA_Dreamworlds_Holzherr.jpg | Ala ma kota i psa -> _-_
news/1/ALPA_Dreamworlds_Holzherr.jpg | Ala ma kota -> l-_-_
news/2/photokina.jpg | photokina -> p
all like that. Currently I cannot find the shema, but I've found that generated value depends on Name I've put and Filename. Additionaly when I clear the Alias field of "Phoca Gallery Image: [ Edit ]" -> Details I've got "l-_-_", but after entering again into image details and pressing Save (without changes) I've got "_-_". Generated value is independent (as far as I've tested) from Joomla backend language (originally I've worked with Polish, then I've selected English).

I've spend some time for research after writing above text and I've found function getAliasName in helpers/phocagallery.php. I've changed it to see whats happening:

Code: Select all

        function getAliasName($name) {
                if (function_exists('iconv')) {
                    $test = $name;
                    $name = preg_replace('~[^\\pL0-9_.]+~u', '-', $name);
                    $test .= "|$name";
                    $name = trim($name, "-");
                    $test .= "|$name";
                    $name = iconv("utf-8", "us-ascii//TRANSLIT", $name);
                    $test .= "|$name";
                    $name = strtolower($name);
                    $test .= "|$name";
                    $name = preg_replace('~[^-a-z0-9_.]+~', '', $name);
                    $test .= "|$name";
                } else {
                        $name = JFilterOutput::stringURLSafe($name);
                        if(trim(str_replace('-','',$name)) == '') {
                                $datenow =& JFactory::getDate();
                                $name = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
                        }
                }
                return $test;
        }
Now:

Code: Select all

Alias (initial value): ''
Filename:              news/1/ALPA_Dreamworlds_Holzherr.jpg
Alias ($test value):   ALPA_Dreamworlds_Holzherr|-L-_-_-|L-_-_|L-_-_|l-_-_|l-_-_

Alias (initial value): 'l-_-_'
Filename:              news/1/ALPA_Dreamworlds_Holzherr.jpg
Alias ($test value):   l-_-_|-_-_|_-_|_-_|_-_|_-_

Alias (initial value): ''
Filename:              news/2/photokina.jpg
Alias ($test value):   photokina|p-|p|p|p|p
So it looks like first preg_replace() do all that mess.

My PHP version is 5.2.3

I have also another server with PHP 5.2.6 and there everything was ok. I'm not sure if the problem is with PHP version or something else.

Re: BUG in getAliasName? - Strange aliases

Posted: 22 Dec 2008, 20:52
by Jan
Hi, if your server support iconv library then the aliases will be done by this library, ... iconv can produce from some diacritics correct characters, e.g. in czech language:

ř -> r
ž -> z
š -> s ... these characters will be correct translated (there are not in e.g. articles, so aliases are wrong translated for some languages in Joomla!)

If your server doesn't support iconv then the standard Joomla! alias creating is used and these can do problems for some diacritics names...

Jan

Re: BUG in getAliasName? - Strange aliases

Posted: 05 Jan 2009, 12:30
by zocha
Hi,

I'm back after long Christmas break. Sorry for long time without answer.

As you can see from the code of function I've changed, my server do support iconv library. The problem appears in

Code: Select all

$name = preg_replace('~[^\\pL0-9_.]+~u', '-', $name);
because after that line everything gets spoiled (try to look at the function and examples bellow, not that on the top of post).

Best regards,
Łukasz Indeka

Re: BUG in getAliasName? - Strange aliases

Posted: 05 Jan 2009, 23:50
by Jan
hi, I am testing it on all czech strings and there is no problem :(

this functions are specifed for langages as czech or polish, I use this function for article aliases and get no problems there :(

maybe some problem with encoding ???

Jan

Re: BUG in getAliasName? - Strange aliases

Posted: 08 Jan 2009, 22:11
by zocha
Jan wrote:maybe some problem with encoding ???
Hi,

I have no idea. It's strange as it works well with the same page (Joomlapack copy) and the same files on another server. If I figure out something, I would give information here.

Łukasz

Re: BUG in getAliasName? - Strange aliases

Posted: 10 Jan 2009, 00:12
by Jan
ok

Re: BUG in getAliasName? - Strange aliases

Posted: 26 Mar 2009, 23:29
by willson
To revive this thread...
some environmental info: Phoca Gallery 2.2.3 (latest), Joomla 1.5.9, Registered stream: convert.iconv.*

Code: Select all

iconv settings: 
iconv support 	        enabled
iconv implementation 	 glibc
iconv library version 	2.5

Directive	            Local Value  Master Value
iconv.input_encoding	 ISO-8859-1	ISO-8859-1
iconv.internal_encoding ISO-8859-1	ISO-8859-1
iconv.output_encoding	ISO-8859-1	ISO-8859-1
My image file: glacier_seen_from_hoenegg_640
The alias: _-_-_-_640
and many others similar or worse or sometimes with the occasional letter in there somewhere.

I'm guessing that the encoding values might be the problem since they're showing as ISO-8859-1 and we're of course on uft-8.

I've not resolved it any further than that and am just living with odd aliases at the moment and will get back to this when something seriously breaks.
Haven't looked

Re: BUG in getAliasName? - Strange aliases

Posted: 27 Mar 2009, 12:21
by zocha
My configurations and results:

1'st server:
PHP Version 5.2.1 (CGI), dbinterface mysqli, Joomla 1.5.9, Phoca Gallery 2.1.0 RC

Code: Select all

iconviconv support 	enabled 
iconv implementation 	glibc 
iconv library version 	2.3.2 

Directive	Local Value	Master Value
iconv.input_encoding	ISO-8859-1	ISO-8859-1
iconv.internal_encoding	ISO-8859-1	ISO-8859-1
iconv.output_encoding	ISO-8859-1	ISO-8859-1
Results:

Code: Select all

ai_123.jpeg -> ai_123
ALPA_Dreamworlds_Holzherr.gif -> alpa_dreamworlds_holzherr
nara-adi.jpg -> nara-adi
star1250.gif -> star1250
star 2500.gif -> star-2500
znaki drogowe.jpg -> znaki-drogowe
pierścionek.jpg -> empty alias, pier in name
(everything cut from ś character (ś in iso-8859-2), wrong value in filename field, thumbnail not created)
The same problem with bułka.gif and gęba.jpg

The same server, changed to PHP Version 4.4.6 (Apache module) without iconv

Code: Select all

ai_123.jpeg -> ai123
ALPA_Dreamworlds_Holzherr.gif -> alpadreamworldsholzherr
rest as above.

I have currently no access to the server with original problem, to check it's configuration details.

The server with PHP Version 5.2.6, where everythings was ok has iconv installed & configured like bellow:

Code: Select all

iconv support 	enabled 
iconv implementation 	glibc 
iconv library version 	2.2.5 

Directive	Local Value	Master Value
iconv.input_encoding	ISO-8859-1	ISO-8859-1
iconv.internal_encoding	ISO-8859-1	ISO-8859-1
iconv.output_encoding	ISO-8859-1	ISO-8859-1
Łukasz

Re: BUG in getAliasName? - Strange aliases

Posted: 27 Mar 2009, 15:52
by Jan
Hi, try to see (edit, remove, change) this function:

Code: Select all

function getAliasName($name) {
  if (function_exists('iconv')) {
    $name = preg_replace('~[^\\pL0-9_.]+~u', '-', $name);
    $name = trim($name, "-");
    $name = iconv("utf-8", "us-ascii//TRANSLIT", $name);
    $name = strtolower($name);
    $name = preg_replace('~[^-a-z0-9_.]+~', '', $name);
  } else {
    $name = JFilterOutput::stringURLSafe($name);
    if(trim(str_replace('-','',$name)) == '') {
    $datenow =& JFactory::getDate();
    $name = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
  }
}
   return $name;
} 
in administrator\components\com_phocagallery\helpers\phocagallery.php

Jan