Merge branch 'MDL-24898_strip_and_trunc_subjects_wip' of git://github.com/stronk7...
authorPetr Skoda <commits@skodak.org>
Mon, 14 Feb 2011 19:57:13 +0000 (20:57 +0100)
committerPetr Skoda <commits@skodak.org>
Mon, 14 Feb 2011 19:57:13 +0000 (20:57 +0100)
blog/lib.php

index 781f4a0..a8bd8f7 100644 (file)
@@ -150,6 +150,8 @@ function blog_sync_external_entries($externalblog) {
     $rssfile = new moodle_simplepie_file($externalblog->url);
     $filetest = new SimplePie_Locator($rssfile);
 
+    $textlib = textlib_get_instance(); // Going to use textlib services
+
     if (!$filetest->is_feed($rssfile)) {
         $externalblog->failedlastsync = 1;
         $DB->update_record('blog_external', $externalblog);
@@ -197,7 +199,13 @@ function blog_sync_external_entries($externalblog) {
         $newentry->uniquehash = $entry->get_permalink();
         $newentry->publishstate = 'site';
         $newentry->format = FORMAT_HTML;
-        $newentry->subject = $entry->get_title();
+        // Clean subject of html, just in case
+        $newentry->subject = clean_param($entry->get_title(), PARAM_TEXT);
+        // Observe 128 max chars in DB
+        // TODO: +1 to raise this to 255
+        if ($textlib->strlen($newentry->subject) > 128) {
+            $newentry->subject = $textlib->substr($newentry->subject, 0, 125) . '...';
+        }
         $newentry->summary = $entry->get_description();
 
         //used to decide whether to insert or update