From: stronk7 Date: Tue, 28 Mar 2006 18:46:07 +0000 (+0000) Subject: Some changes to make proper UTF-8 encoding only if necesary. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1d5a7c4b0adc9c069b306cac9e94916fce73b2fa;p=moodle.git Some changes to make proper UTF-8 encoding only if necesary. We need to move all the **_tag functions to a central place ASAP (backup are better to be used as central) Also, I don't know why the author is now out from the feeds... --- diff --git a/lib/rsslib.php b/lib/rsslib.php index 81d482cbb8..2fb8176c72 100644 --- a/lib/rsslib.php +++ b/lib/rsslib.php @@ -227,10 +227,10 @@ function rss_add_items($items) { //We put it in the description instead because it's more important //for moodle than most other feeds, and most rss software seems to ignore //the author field ... - $item->description = get_string('byname','',$item->author).'.  

'.$item->description.'

'; + $item->description = get_string('byname','',$item->author).'.  

'.$item->description.'

'; } $result .= rss_full_tag('description',3,false,$item->description); - $result .= " " . utf8_encode(htmlspecialchars($item->link)) . "\n"; + $result .= rss_full_tag('guid',3,false,$item->link,array('isPermaLink' => 'true')); $result .= rss_end_tag('item',2,true); } @@ -291,13 +291,19 @@ function rss_geterrorxmlfile() { // diferences. Someday all they should go to a common place. //Return the xml start tag -function rss_start_tag($tag,$level=0,$endline=false) { +function rss_start_tag($tag,$level=0,$endline=false,$attributes=null) { if ($endline) { $endchar = "\n"; } else { $endchar = ""; } - return str_repeat(" ",$level*2)."<".$tag.">".$endchar; + $attrstring = ''; + if (!empty($attributes) && is_array($attributes)) { + foreach ($attributes as $key => $value) { + $attrstring .= " ".$key."=\"".$value."\""; + } + } + return str_repeat(" ",$level*2)."<".$tag.$attrstring.">".$endchar; } //Return the xml end tag @@ -311,16 +317,19 @@ function rss_end_tag($tag,$level=0,$endline=true) { } //Return the start tag, the contents and the end tag -function rss_full_tag($tag,$level=0,$endline=true,$content,$to_utf=true) { - //Here we encode absolute links - $st = rss_start_tag($tag,$level,$endline); +function rss_full_tag($tag,$level=0,$endline=true,$content,$attributes=null) { + global $CFG; + $st = rss_start_tag($tag,$level,$endline,$attributes); $co=""; - if ($to_utf) { - $co = preg_replace("/\r\n|\r/", "\n", utf8_encode(htmlspecialchars($content))); - } else { + if (!empty($CFG->unicodedb)) { + // Don't perform the conversion. Contents are Unicode. $co = preg_replace("/\r\n|\r/", "\n", htmlspecialchars($content)); + } else { + // Perform the conversion. Contents aren't Unicode. + $co = preg_replace("/\r\n|\r/", "\n", utf8_encode(htmlspecialchars($content))); } $et = rss_end_tag($tag,0,true); + return $st.$co.$et; }