Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
in Q2A Core by

I found bug of mouseover-layer plugin. Contents will be cut twice.

  1. Contents will be cut with SELECT query.
  2. Contents will be cut with qa_shorten_string_line function.
Also, if there is HTML code to the top of content, there is a further problem. This plugin might need to be modified.
Q2A version: 1.7.1

3 Answers

+2 votes
edited by

This issue is only related Q2A V1.7 OR V1.7.1. Probably, V1.6.x is safe.

My solution:

// Replaced by ASKIVE [start]
//$result = qa_db_query_sub('SELECT postid, LEFT(content, #) content, format FROM ^posts WHERE postid IN (#)', $maxlength + 1, $postids);
$result = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
// Replaced by ASKIVE [end]

$postinfo = qa_db_read_all_assoc($result, 'postid');

// Get the regular expression fragment to use for blocked words and the maximum length of content to show

$blockwordspreg = qa_get_block_words_preg();

// Now add the popup to the title for each question

foreach ($q_list['qs'] as $index => $question) {
    if (isset($postinfo[$question['raw']['postid']])) {
        $thispost = $postinfo[$question['raw']['postid']];
        $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));

        // Added by ASKIVE [start]
        $text = strip_tags($text);
        // Added by ASKIVE [end]

        $text = qa_shorten_string_line($text, $maxlength);

+3 votes

It seems the qa_shorten_string_line() function actually removes words at position ~66% of the string. Then it adds the ellipsis right there. Sadly, in order for this to make sense the whole text is needed, so cutting using the LEFT function is not a good idea. That would only work for the case in which the ellipsis is at the end of the text.

So the solution you suggest in your other answer about fetching the whole text of the question is correct.

The issue you're facing with HTML I think it has nothing to do with the plugin. The reason for this is that qa_viewer_text() should actually return a non-HTML string. So stripping HTML from it should be unnecessary. I bet you are using a viewer module that is not respecting this expected behavior. The fix should be simple, as you just need to strip the tags in that function.

I created a PR that should fix the double cut in the text bug and added some minor improvements too here: https://github.com/q2a/question2answer/pull/250

edited by
Nice solution.
If you omit strip_tags(), HTML5 tag may remain (<audio>, etc?). This may be caused qa_viewer_text() ...?
Remove line for debug (L41).
print_r($q_list['qs']); exit;
Whoops, good catch :)
Thanks pupi. Re-check my comment (point1).
strip_tags strips everything around < and >. Now, it is always called as you can see here: https://github.com/q2a/question2answer/blob/49f054ce905c34e30a602527b3d70544a526f61b/qa-include/plugins/qa-viewer-basic.php#L139

So there is no way for a post with 'html' format to avoid getting their HTML tags stripped. You might have edited a plain text post directly from the DB, added an <audio> tag and then forgot to update the format from '' to 'html'.

Did I hit the nail? :)
Matter of strip_tags might be only my problem. The htmLawed bundled in Q2A core do not permit HTML5. Therefore, I was replaced htmLawed with a new version that supports HTML5.

0 votes

what does this plugin benefit?

 Is it useful in archiving?

It helps in reading the question body without opening question page