Question2answer: show excerpt in the RSS feed

There is a "Include full text in feeds:" option in the "RSS feeds" configuration panel but no options/method to only show excerpt instead of the "full text" or nothing for RSS feeds. This need to hack the question2answer source code. Details are in the answer.

asked May 16, 2013 by SA (14,760 points)

1 Answer

 
Best answer

The changes based on Question2asnwer 1.5.4:

diff --git a/qa-include/qa-index.php b/qa-include/qa-index.php
index 1a5845a..f49d83c 100644
--- a/qa-include/qa-index.php
+++ b/qa-include/qa-index.php
@@ -158,7 +158,7 @@
                                                ob_start('ob_gzhandler');
                                                
                        if (substr($requestlower, 0, 5)=='feed/')
-                               require QA_INCLUDE_DIR.'qa-feed.php';
+                               require QA_INCLUDE_DIR.'qa-feed-excerpt.php';
                        else
                                require QA_INCLUDE_DIR.'qa-page.php';
                }
@@ -169,4 +169,4 @@
 
 /*
        Omit PHP closing tag to help avoid accidental output
-*/
\ No newline at end of file
+*/


diff qa-feed.php qa-feed-excerpt.php 
40a41,74
> 	function qa_feed_excerpt($string, $length)
> /*
> 	Return no more than $length characters from $string after converting it to a single line, by
> 	removing words from the middle (and especially towards the end)
> */
> 	{
> 		$string=strtr($string, "\r\n\t", '  ');
> 		
> 		if (qa_strlen($string)>$length) {
> 			$remaining=$length-5;
> 			
> 			$words=qa_string_to_words($string, false, true);
> 			$countwords=count($words);
> 			
> 			$prefix='';
> 			
> 			for ($addword=0; $addword<$countwords; $addword++) {
> 				$word=array_shift($words);
> 				
> 				if (qa_strlen($word)>$remaining)
> 					break;
> 				
> 				$prefix.=$word;
> 				
> 				$remaining-=qa_strlen($word);
> 			}
> 			
> 			$string=$prefix.' ... ';
> 		}
> 		
> 		return $string;
> 	}
> 
> 
402c436,438
< 			$lines[]='<description>'.qa_html($htmlcontent).'</description>'; // qa_html() a second time to put HTML code inside XML wrapper
---
> 			$lines[]='<description>'.
> 			qa_html(qa_feed_excerpt($htmlcontent, 400)).
> 			'</description>'; // qa_html() a second time to put HTML code inside XML wrapper
432c468
< */
\ No newline at end of file
---
> */
answered May 16, 2013 by SA (14,760 points)
edited May 16, 2013 by SA

The patch for question2answer 1.6.3 can be downloaded here:

0001-qa-feed-excerpt-for-question2answer.patch.

Note that I copied the qa-feed.php to qa-feed-excerpt.php before this patch.

commented Apr 10, 2014 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Related questions

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...