Accentuated letters Accentuated letters
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Accentuated letters

Started by clefranc, February 10, 2007, 03:27:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

clefranc

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

Thanks

vuud

Quote from: 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

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 )
Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

Nibbler

Modify cfrssget.php, and specify the encoding after you create the object


$this->rss = new UniversalFeedCreator();
$this->rss->encoding = $CONFIG['charset']; // set rss encoding to match gallery encoding

clefranc

Quote from: vuud on February 10, 2007, 04:35:33 AM
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).

$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

Nibbler

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:


// 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));

clefranc

Quote from: Nibbler on February 10, 2007, 07:13:07 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:

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

Nibbler

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.

$this->rss->encoding = 'UTF-8';

Most galleries should be UTF-8 anyway.

clefranc

Quote from: Nibbler on February 10, 2007, 07:13:07 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:


// 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:

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.

vuud

Quote from: 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:


// 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.
Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

vuud

Quote from: 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.

$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!
Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

vuud

Quote from: clefranc on February 10, 2007, 08:34:00 PM
This work great, here is my modification to cfrssget.php:

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.
Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

tuxsoul

Quote from: vuud on February 11, 2007, 05:33:58 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:

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:

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  :(
¿do you like my comment?, gift me one bitcoin: 1266FWznbEW1uLNPsLU9ATBxGuM1U19thB
bitcoin pay forward project: 15pjRCNT2CpzVo7HQ6b6r4q18Vv4Da7y9K