Advanced search  

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

Pages: [1]   Go Down

Author Topic: Accentuated letters  (Read 13868 times)

0 Members and 1 Guest are viewing this topic.

clefranc

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Accentuated letters
« 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
Logged

vuud

  • Moderator
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1803
  • [cpmfetch.fistfullofcode.com]
    • Fist Full Of Code
Re: Accentuated letters
« Reply #1 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

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 )
Logged
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

  • Guest
Re: Accentuated letters
« Reply #2 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
Logged

clefranc

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Re: Accentuated letters
« Reply #3 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).

$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
Logged

Nibbler

  • Guest
Re: Accentuated letters
« Reply #4 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));
Logged

clefranc

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Re: Accentuated letters
« Reply #5 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
Logged

Nibbler

  • Guest
Re: Accentuated letters
« Reply #6 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.
Logged

clefranc

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Re: Accentuated letters
« Reply #7 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.
Logged

vuud

  • Moderator
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1803
  • [cpmfetch.fistfullofcode.com]
    • Fist Full Of Code
Re: Accentuated letters
« Reply #8 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.
Logged
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

  • Moderator
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1803
  • [cpmfetch.fistfullofcode.com]
    • Fist Full Of Code
Re: Accentuated letters
« Reply #9 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!
Logged
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

  • Moderator
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1803
  • [cpmfetch.fistfullofcode.com]
    • Fist Full Of Code
Re: Accentuated letters
« Reply #10 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.
Logged
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

  • Contributor
  • Coppermine newbie
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 17
    • blog
Re: Accentuated letters
« Reply #11 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  :(
Logged
¿do you like my comment?, gift me one bitcoin: 1266FWznbEW1uLNPsLU9ATBxGuM1U19thB
bitcoin pay forward project: 15pjRCNT2CpzVo7HQ6b6r4q18Vv4Da7y9K
Pages: [1]   Go Up
 

Page created in 0.024 seconds with 19 queries.