forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 cpmFetch by vuud => Topic started by: clefranc on February 10, 2007, 03:27:11 am

Title: Accentuated letters
Post by: clefranc on February 10, 2007, 03:27:11 am
Hi all,
I use the rss_lastadded.php routine, but can't get accentuated letters.

When displaying RSS feed, instead of returning this : L'été à Schefferville :: Vivi_286-W.jpg
I get this : L'été à Schefferville :: Vivi_286-W.jpg

On my site, the letters are good, only cpmfetch can't display them correctly. Any clue???

http://www.photocaniapiscau.net/galeries/cpmfetch/rss_lastadded.php (http://www.photocaniapiscau.net/galeries/cpmfetch/rss_lastadded.php)

Thanks
Title: Re: Accentuated letters
Post by: vuud on February 10, 2007, 04:35:33 am
Hi all,
I use the rss_lastadded.php routine, but can't get accentuated letters.

When displaying RSS feed, instead of returning this : L'été à Schefferville :: Vivi_286-W.jpg
I get this : L'été à Schefferville :: Vivi_286-W.jpg

On my site, the letters are good, only cpmfetch can't display them correctly. Any clue???

http://www.photocaniapiscau.net/galeries/cpmfetch/rss_lastadded.php (http://www.photocaniapiscau.net/galeries/cpmfetch/rss_lastadded.php)

Thanks

Ah crap.  I have little experience with foriegn character sets.  If anyone has an idea why this would happen, please speak up and point me in the right direction!

If no one does, I will try to figure it out.

Is your settings for UTF-8?  Is that even an option?  I am so clueless on this one...

(It could also be the library I use to generate the rss feed and not my fault at all :D )
Title: Re: Accentuated letters
Post by: Nibbler on February 10, 2007, 11:34:27 am
Modify cfrssget.php, and specify the encoding after you create the object

Code: [Select]
$this->rss = new UniversalFeedCreator();
$this->rss->encoding = $CONFIG['charset']; // set rss encoding to match gallery encoding
Title: Re: Accentuated letters
Post by: clefranc on February 10, 2007, 07:03:12 pm
Is your settings for UTF-8?  Is that even an option?  I am so clueless on this one...

I was clueless too and new to PHP, but I think I found a way. In feedcreator.class.php, I've replaced

var $encoding = "ISO-8859-1";
by
var $encoding = "UTF-8";

Also in feedcreator.class.php, I've removed a htmlspecialchars in class 'RSSCreator10 extends FeedCreator' because it expand the html code ' by ' (' is the code for ' so in the title L'été à Schefferville I get L'été à Schefferville). This is an known issue for RSS feed generator, I saw it can be bypassed by using a custom function, but it's beyong my skill (look at http://ca3.php.net/htmlspecialchars (http://ca3.php.net/htmlspecialchars)).

$feed.= "        <title>".strip_tags(strtr($this->items[$i]->title,"\n\r","  "))."</title>\n";

Seems to work, not an elegant solution because the encoding is hardcoded and I don't know how to solve the ampersand problem.

I forgot to tell it's for copperminefetch-1.9.8-dev.zip
Title: Re: Accentuated letters
Post by: Nibbler on February 10, 2007, 07:13:07 pm
The code I posted is the correct way to implement your first change. For the second, the data in the db is already converted to special chars. It should be reversed before sending it to the feed generator. Best way is:

Code: [Select]
// transformations taken from init.inc.php
$HTML_SUBST = array('&' => '&amp;', '"' => '&quot;', '<' => '&lt;', '>' => '&gt;', '%26' => '&amp;', '%22' => '&quot;', '%3C' => '&lt;', '%3E' => '&gt;','%27' => '&#39;', "'" => '&#39;');

// apply them in reverse
$string = strtr($string, array_flip($HTML_SUBST));
Title: Re: Accentuated letters
Post by: clefranc on February 10, 2007, 07:48:13 pm
The code I posted is the correct way to implement your first change.

Ok, when I add your code to cfrssget.php like this:

Code: [Select]
function cfrss ($config_file = "") {
$this->cpm = new cpm($config_file);
$this->cpm->cpm_setReturnType("resultset");
$this->rss = new UniversalFeedCreator();
$this->rss->encoding = $CONFIG['charset']; // set rss encoding to match gallery encoding

}

and set debug "on" for cfrssget.php, this the IE7 browser result:

Notice: Undefined variable: CONFIG in C:\Inetpub\ftproot\cpc\galeries\cpmfetch\cfrssget.php on line 118

Like I said, I'm not a PHP coder, can you tell me if I've added your modification at the right place, if not, can you be more specific.

Thanks
Title: Re: Accentuated letters
Post by: Nibbler on February 10, 2007, 07:58:54 pm
It's not as easy as I thought. I can't see a quick way to do it so, just hardcode it there for now.

Code: [Select]
$this->rss->encoding = 'UTF-8';
Most galleries should be UTF-8 anyway.
Title: Re: Accentuated letters
Post by: clefranc on February 10, 2007, 08:34:00 pm
For the second, the data in the db is already converted to special chars. It should be reversed before sending it to the feed generator. Best way is:

Code: [Select]
// transformations taken from init.inc.php
$HTML_SUBST = array('&' => '&amp;', '"' => '&quot;', '<' => '&lt;', '>' => '&gt;', '%26' => '&amp;', '%22' => '&quot;', '%3C' => '&lt;', '%3E' => '&gt;','%27' => '&#39;', "'" => '&#39;');

// apply them in reverse
$string = strtr($string, array_flip($HTML_SUBST));

This work great, here is my modification to cfrssget.php:

Code: [Select]
function generateFeedFromResults($results) {
    foreach ($results as $data) {

$item = new FeedItem();

  $item->link =  $this->cpm->createLink($data['pFilepath'], rawurlencode($data['pFilename']), $data['pAid'], $data['pPid']);

$titleToUse = "";
$descriptionToUse="";

if (($titleToUse = $this->cpm->createDescription($this->itemTitle,$data,true)) === false) {
$titleToUse = $this->cpm->createDescription($this->itemAltTitle,$data);
}

if (($descriptionToUse = $this->cpm->createDescription($this->itemDescription,$data,true)) === false) {
$descriptionToUse = $this->cpm->createDescription($this->itemAltDescription,$data);
}

$imagetag = '<a href="' . $item->link . '"><img src="'.
$this->cpm->urlEncodeImagePath($this->cpm->getImageToUse($data['pFilepath'],$data['pFilename'], $this->cpm->cfg['thumb_pfx'])) . '" align="right" /></a>';

$descriptionToUse = $imagetag . $descriptionToUse;

$HTML_SUBST = array('&' => '&amp;', '"' => '&quot;', '<' => '&lt;', '>' => '&gt;', '%26' => '&amp;', '%22' => '&quot;', '%3C' => '&lt;', '%3E' => '&gt;','%27' => '&#39;', "'" => '&#39;'); //Code added
$item->title = strtr($titleToUse, array_flip($HTML_SUBST)); // Code modified

$item->description = $descriptionToUse;

$item->date = date("r",$data['pCtime']);
$item->source = $this->cpm->cfg['cpg_url'];
$item->author = $data['pOwner_name'];

$this->rss->addItem($item);
}

}

Hope this is the right way. BTW, my galery was UTF-8 right at the begining, I'm using a French version of Micro$oft Window$ $erver 2003, Coppermine 1.4.9, PHP 5.1.6, mySQL 1.2.4 rc

Thank you very much for your support.
Title: Re: Accentuated letters
Post by: vuud on February 11, 2007, 03:15:01 pm
The code I posted is the correct way to implement your first change. For the second, the data in the db is already converted to special chars. It should be reversed before sending it to the feed generator. Best way is:

Code: [Select]
// transformations taken from init.inc.php
$HTML_SUBST = array('&' => '&amp;', '"' => '&quot;', '<' => '&lt;', '>' => '&gt;', '%26' => '&amp;', '%22' => '&quot;', '%3C' => '&lt;', '%3E' => '&gt;','%27' => '&#39;', "'" => '&#39;');

// apply them in reverse
$string = strtr($string, array_flip($HTML_SUBST));

I've got an easy way to get the char set...  I'll implement it somehow.
Title: Re: Accentuated letters
Post by: vuud on February 11, 2007, 05:33:58 pm
It's not as easy as I thought. I can't see a quick way to do it so, just hardcode it there for now.

Code: [Select]
$this->rss->encoding = 'UTF-8';
Most galleries should be UTF-8 anyway.


In cpmfetch, this could be done like so:

$this->rss->encoding = $this->cpm->cpm_getConfigEntry('charset');

Beware the syntax, I did not test it and I am kinda rushing though

The cpm_getConfigEntry can be used to get most anything from the config table.

Thanks for responsing nibbler!
Title: Re: Accentuated letters
Post by: vuud on February 21, 2007, 07:10:49 am
This work great, here is my modification to cfrssget.php:

Code: [Select]
function generateFeedFromResults($results) {
    foreach ($results as $data) {

$item = new FeedItem();

  $item->link =  $this->cpm->createLink($data['pFilepath'], rawurlencode($data['pFilename']), $data['pAid'], $data['pPid']);

$titleToUse = "";
$descriptionToUse="";

if (($titleToUse = $this->cpm->createDescription($this->itemTitle,$data,true)) === false) {
$titleToUse = $this->cpm->createDescription($this->itemAltTitle,$data);
}

if (($descriptionToUse = $this->cpm->createDescription($this->itemDescription,$data,true)) === false) {
$descriptionToUse = $this->cpm->createDescription($this->itemAltDescription,$data);
}

$imagetag = '<a href="' . $item->link . '"><img src="'.
$this->cpm->urlEncodeImagePath($this->cpm->getImageToUse($data['pFilepath'],$data['pFilename'], $this->cpm->cfg['thumb_pfx'])) . '" align="right" /></a>';

$descriptionToUse = $imagetag . $descriptionToUse;

$HTML_SUBST = array('&' => '&amp;', '"' => '&quot;', '<' => '&lt;', '>' => '&gt;', '%26' => '&amp;', '%22' => '&quot;', '%3C' => '&lt;', '%3E' => '&gt;','%27' => '&#39;', "'" => '&#39;'); //Code added
$item->title = strtr($titleToUse, array_flip($HTML_SUBST)); // Code modified

$item->description = $descriptionToUse;

$item->date = date("r",$data['pCtime']);
$item->source = $this->cpm->cfg['cpg_url'];
$item->author = $data['pOwner_name'];

$this->rss->addItem($item);
}

}

Hope this is the right way. BTW, my galery was UTF-8 right at the begining, I'm using a French version of Micro$oft Window$ $erver 2003, Coppermine 1.4.9, PHP 5.1.6, mySQL 1.2.4 rc

Thank you very much for your support.


I just uploaded 1.9.10 which autosets the character set in the feed.  If you upgrade, can you let me know if this fixes your problem.
Title: Re: Accentuated letters
Post by: tuxsoul on July 20, 2007, 06:07:55 pm
In cpmfetch, this could be done like so:
$this->rss->encoding = $this->cpm->cpm_getConfigEntry('charset');

Hi, i testing the last version of cpmfetch, the stable version today, and checking my feed with cfrssget.php, have wrong encoding, checking this thread, i see the stable version have this line that you comment for get encoding of db, but i use utf-8 encoding and the encoding is wrong  ???

Checking the "feedcreator.class.php", i can see the line that protect encoding variable value:

Code: [Select]
line: 393
                        // prevent overwriting of properties "contentType", "encoding"; do not copy "_feed" itself
                        if (!in_array($key, array("_feed", "contentType", "encoding"))) {
                                $this->_feed->{$key} = $this->{$key};
                        }

I have change for that:

Code: [Select]
line: 393
                        // prevent overwriting of properties "contentType", "encoding"; do not copy "_feed" itself
                        if (!in_array($key, array("_feed", "contentType"))) {
                                $this->_feed->{$key} = $this->{$key};
                        }

And the encoding change how $this->rss->encoding variable change of value. Maybe this help somebody in this encoding trouble.  ;D

Greetings, sorry my english is bad  :(