Estou usando o módulo NF Scroller XT, ele faz um scroller de RSS através do component News Feeds.
O problema é que a codificação está com problemas, os acentos estão saindo errado.
Nas opções do modulo da pra escolher os tipos de codificação, mas todos ficam errados, e não tem utf-8, a opção padrão é ISO8859-1.
Este é o arquivo PHP do módulo:
Código: Selecionar todos
<?php
/**
* Nf_scroller_XT Scroller Module
* @for Joomla Open Source
* @Copyright (C) 2005 Sebastien Massiaux ( Wene )
* @ All rights reserved
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version $Revision: 1.3.5$
This module is used to display newsfeeds inside a hml marquee.
**/
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
$cacheDir = $mosConfig_absolute_path . "/cache/";
$LitePath = $mosConfig_absolute_path . "/includes/Cache/Lite.php";
require_once( $mosConfig_absolute_path . "/includes/domit/xml_domit_rss_lite.php");
//----------------------------------------- gets the chars replacers ------------------------------------------------------------
global $repl_list;
$repl_list = "&(apos|#39);,'-â,â-ù,u-¬Â¦,..-é,é-è,è-û,ù-àª,ê-à®,i-à§,ç-Ã,à-’,'-°,°";
if ($params->get( 'repl_list' )!=""){
$repl_list = $repl_list."-".$params->get( 'repl_list' );
}
//----------------------------------- define a function to ameliorate visualisation inspired from a fonction by francesco Orlando -------------
if (!defined( '_NFSXT_MODULE' )) {
/** ensure that functions are declared only once */
define( '_NFSXT_MODULE', 1 );
global $charset;
$charset = $params->get( 'charset' );
function remove_aposXT($text) {
global $charset,$repl_list;
$text= html_entity_decode($text,ENT_QUOTES,$charset); #NOTE: UTF-8 does not work!
$text= preg_replace("'€'i","€",$text);
$replacers = explode("-",$repl_list);
if (count($replacers)==1){
$repl_args = explode(",",$repl_list);
$mixed_pattern = "'".$repl_args[0]."'i";
$mixed_replacement = $repl_args[1];
$text= preg_replace($mixed_pattern,$mixed_replacement,$text);
}else{
foreach ($replacers as $replacer) {
$repl_args = explode(",",$replacer);
$mixed_pattern = "'".$repl_args[0]."'i";
$mixed_replacement = $repl_args[1];
$text= preg_replace($mixed_pattern,$mixed_replacement,$text);
}
}
return $text;
}
//------------------------------ function to draw spacers -----------------------------------------
function nfsxt_spacer ( $target ){
global $params_spacers, $hr, $space;
if ($params_spacers[$target . "_hr"] == "yes"){
echo $hr;
}
if ($params_spacers[$target . "_break_sw"] == "yes"){
if ($params_spacers[$target . "_break"] != ""){
echo $params_spacers[$target . "_break"] ;
}else{
echo $space;
}
}
}
}
//----------------------------------- defines the horizontal bar and spacer -------------------------------------------
global $hr, $space;
switch ($params->get( 'direction' )) {
case "up":
case "down":
$hr = "<hr/>";
if ($params->get( 'break' )!=""){
$space = $params->get( 'break' );
}else{
$space = "<br/>";
}
break;
default:
$hr ="";
if ($params->get( 'break' )!=""){
$space = $params->get( 'break' );
}else{
$space = " | ";
}
break;
}
//----------------------------------- retrieves params ----------------------------------------------
global $params_spacers;
$params_spacers['cat_hr'] =$params->get('cat_hr');
$params_spacers['cat_break'] =$params->get('cat_break');
$params_spacers['cat_break_sw'] =$params->get('cat_break_sw');
$params_spacers['feed_hr'] =$params->get('feed_break');
$params_spacers['feed_break'] =$params->get('feed_break');
$params_spacers['feed_break_sw'] =$params->get('feed_break_sw');
$params_spacers['feed_desc_hr'] =$params->get('feed_desc_hr');
$params_spacers['feed_desc_break'] =$params->get('feed_desc_break');
$params_spacers['feed_desc_break_sw'] =$params->get('feed_desc_break_sw');
$params_spacers['item_title_hr'] =$params->get('item_title_hr');
$params_spacers['item_title_break'] =$params->get('item_title_break');
$params_spacers['item_title_break_sw'] =$params->get('item_title_break_sw');
$params_spacers['item_cont_hr'] =$params->get('item_cont_hr');
$params_spacers['item_cont_break'] =$params->get('item_cont_break');
$params_spacers['item_cont_break_sw'] =$params->get('item_cont_break_sw');
//---------------------------------gets the feeds from the database---------------------------
switch ($params->get( 'nf_src' )) {
case "cat":
$cat_name = $params->get( 'cat_name' );
$cat_names = explode(",",$cat_name);
if (count($cat_names)==1){
$sel_cats = "name='$cat_name'";
}else{
$sel_cats = "name='";
foreach ($cat_names as $cat_name) {
$sel_cats = $sel_cats.$cat_name."' OR name='";
}
$sel_cats = $sel_cats."'";
}
$get_id = "SELECT id"
. "\nFROM #__categories"
. "\nWHERE published='1' AND section='com_newsfeeds' AND ($sel_cats)"
. "\nORDER BY ordering";
$database->setQuery($get_id);
$cat_id = $database->loadResult();
$get_nf = "SELECT name, link, numarticles, cache_time, id"
. "\nFROM #__newsfeeds"
. "\nWHERE published='1' AND checked_out='0' AND catid='$cat_id'"
. "\nORDER BY ordering";
break;
case "single":
$feed_name = $params->get( 'feed_name' );
$feed_names = explode(",",$feed_name);
if (count($feed_names)==1){
$sel_feeds = "name='$feed_name'";
}else{
$sel_feeds = "name='";
foreach ($feed_names as $feed_name) {
$sel_feeds = $sel_feeds.$feed_name."' OR name='";
}
$sel_feeds = $sel_feeds."'";
}
$get_nf = "SELECT name, link, numarticles, cache_time, id"
. "\nFROM #__newsfeeds"
. "\nWHERE published='1' AND checked_out='0' AND ($sel_feeds)"
. "\nORDER BY ordering" ;
break;
default:
$get_nf = "SELECT name, link, numarticles, cache_time, id"
. "\nFROM #__newsfeeds"
. "\nWHERE published='1' AND checked_out='0'"
. "\nORDER BY ordering";
break;
}
$database->setQuery($get_nf);
$newsfeeds = $database->loadObjectList();
if ($newsfeeds) {
//------------------------------------displays the scroller-------------------------------------
?>
<table width="<?php echo $params->get('width'); ?>" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<marquee
behavior="<?php echo $params->get('behavior'); ?>"
direction="<?php echo $params->get('direction'); ?>"
scrollamount="<?php echo $params->get('scrollamount'); ?>"
scrolldelay="<?php echo $params->get('scrolldelay'); ?>"
height="<?php echo $params->get('height'); ?>"
align="<?php echo $params->get('align'); ?>"
truespeed
<?php echo $params->get('options'); ?>
onmouseover=this.stop() onmouseout=this.start() >
<?php
echo $params->get('lead_in');
foreach ($newsfeeds as $newsfeed) {
$rssDoc =& new xml_domit_rss_document_lite();
$rssDoc->useCacheLite(true, $LitePath, $cacheDir, $newsfeed->cache_time);
//--------------------------------- Patch to Test the server connection -----------------------------------------
list($prefix,$addr)= explode('http://',"$newsfeed->link");
if(strstr($addr,"/"))
{$addr = substr($addr, 0, strpos($addr,"/"));
}
$churl = @fsockopen($addr, 80, $errno, $errstr, 10);
if (!$churl){
continue;
}
//--------------------------------- Patch end -----------------------------------------
$rssDoc->loadRSS($newsfeed->link);
$totalChannels = $rssDoc->getChannelCount();
//------------------------------------- CATEGORY NAME ---------------------------------------
if ($params->get( 'disp_cat_name' )=="yes" && $newsfeed->name) {
nfsxt_spacer ("cat");
if ($params->get( 'cat_name_link' )=="yes") {
?>
<a href ="<?php echo $mosConfig_live_site."/index.php?option=com_newsfeeds&task=view&feedid=".$newsfeed->id."&Itemid=".$params->get('cat_target') ?>" style="text-transform: uppercase;">
<?php echo $newsfeed->name; ?>
</a>
<?php
}else{
?>
<?php echo $newsfeed->name; ?>
<?php
}
}
//-------------------------------------- FEED NAME ---------------------------------------------------------
for ($i = 0; $i < $totalChannels; $i++) {
$currChannel =& $rssDoc->getChannel($i);
//----------------------------------------------------------------------------------------------
if ($params->get('disp_feed_name')=="yes" && $currChannel->getTitle()){
nfsxt_spacer ("feed");
if ($params->get( 'feed_name_link' )=="yes") {
?>
<a name="<?php echo $newsfeed->name; ?>"></a>
<a href="<?php echo $currChannel->getLink(); ?>" target="_child" style="text-transform: uppercase;">
<?php echo remove_aposXT($currChannel->getTitle()); ?></a>
<?php
}else{
?>
<?php echo remove_aposXT($currChannel->getTitle()); ?>
<?php
}
}
//------------------------------------- FEED DESC -----------------------------------------------------------
if ($params->get('disp_feed_desc')=="yes" && $currChannel->getDescription()){
nfsxt_spacer ("feed_desc");
if ($params->get( 'feed_desc_link' )=="yes") {
?>
<a href="<?php echo $currChannel->getLink(); ?>" target="_child" style="text-transform: uppercase;">
<?php echo remove_aposXT($currChannel->getDescription()); ?></a>
<?php
}else{
?>
<?php echo remove_aposXT($currChannel->getDescription()); ?>
<?php
}
?>
<?php
}
//------------------------------------ count feed items ------------------------------------------------------------
$actualItems = $currChannel->getItemCount();
$setItems = $newsfeed->numarticles;
if ($setItems > $actualItems) {
$totalItems = $actualItems;
} else {
$totalItems = $setItems;
}
for ($j = 0; $j < $totalItems; $j++) {
$currItem =& $currChannel->getItem($j);
//----------------------------------- ITEM TITLE -------------------------------------------------------------
if ($params->get('disp_item_title')=="yes" && $currItem->getTitle()){
nfsxt_spacer ("item_title");
if ($params->get( 'feed_item_title_link' )=="yes") {
?>
<a href="<?php echo $currItem->getLink(); ?>" target="_child">
<?php echo remove_aposXT($currItem->getTitle()); ?></a>
<?php
}else{
?>
<?php echo remove_aposXT($currItem->getTitle()); ?>
<?php
}
}
//-------------------------------------- ITEM CONTENT -----------------------------------------------------------
if ($params->get('disp_item_cont') == "yes" && $currItem->getDescription()){
nfsxt_spacer ("item_cont");
if ($params->get( 'feed_item_link' )=="yes") {
?>
<a href="<?php echo $currItem->getLink(); ?>" target="_child">
<?php echo remove_aposXT($currItem->getDescription()); ?></a>
<?php
}else{
?>
<?php echo remove_aposXT($currItem->getDescription()); ?>
<?php
}
}
//-------------------------------------------------------------------------------------------------
}
}
}
echo $params->get('lead_out');
?>
</marquee>
</td>
</tr>
</table>
<?php
}else{
echo "This category or feed does not exists. Please, check the names you entered";
}
?>
O estranho é que no meu server local (JSAS) apenas o "é" ficou errado, e foi facil de corrigir porque tem um campo de substituição de caractere, mas no site ficou tudo errado.
O JSAS usa o MySQL 4.1.14, PHPMyAdmin 2.8.2.4, em Conjunto de Caracters ta utf8, eCollation utf8_unicode_ci, mas na DB do meu site o Collation ta latin1_swedish_ci
No Host online o MySql é 4.1.21, PHPMy Admin 2.6.3, O Conjunto de caracteres e o Collation são os mesmo, e o Collation no DB do site tb é latin1_swedish_ci
Quando botei "Universal" em "Selecionar Automaticamente" no FireFox os acentos ficaram corretos no RRS, mas no resto do site ficaram com um losango com "?" dentro.
Há alguma maneira de arrumar isso??
Muito obrigado!
Luis Pacheco