qa-mouseover-layer.php 2.73 KB
Newer Older
Gideon Greenspan committed
1 2 3 4 5 6 7
<?php

/*
	Question2Answer (c) Gideon Greenspan

	http://www.question2answer.org/

8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-plugin/mouseover-layer/qa-mouseover-layer.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Theme layer class for mouseover layer plugin


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

	class qa_html_theme_layer extends qa_html_theme_base {
28

29
		public function q_list($q_list)
Gideon Greenspan committed
30
		{
31
			if (!empty($q_list['qs']) && qa_opt('mouseover_content_on')) { // first check it is not an empty list and the feature is turned on
Gideon Greenspan committed
32

33
				// Collect the question ids of all items in the question list (so we can do this in one DB query)
34

35
				$postids = array();
36 37 38 39
				foreach ($q_list['qs'] as $question) {
					if (isset($question['raw']['postid']))
							$postids[] = $question['raw']['postid'];
				}
40

41
				if (!empty($postids)) {
Gideon Greenspan committed
42

43 44
					// Retrieve the content for these questions from the database and put into an array fetching
					// the minimal amount of characters needed to determine the string should be shortened or not
45

46 47 48
					$maxlength = qa_opt('mouseover_content_max_len');
					$result = qa_db_query_sub('SELECT postid, LEFT(content, #) content, format FROM ^posts WHERE postid IN (#)', $maxlength + 1, $postids);
					$postinfo = qa_db_read_all_assoc($result, 'postid');
49

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

52
					$blockwordspreg = qa_get_block_words_preg();
53

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

56
					foreach ($q_list['qs'] as $index => $question) {
57 58 59 60 61 62
						if (isset($postinfo[$question['raw']['postid']])) {
							$thispost = $postinfo[$question['raw']['postid']];
							$text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
							$text = qa_shorten_string_line($text, $maxlength);
							$title = isset($question['title']) ? $question['title'] : '';
							$q_list['qs'][$index]['title'] = sprintf('<span title="%s">%s</span>', qa_html($text), $title);
Gideon Greenspan committed
63
						}
64
					}
Gideon Greenspan committed
65 66
				}
			}
67

Gideon Greenspan committed
68 69 70 71
			qa_html_theme_base::q_list($q_list); // call back through to the default function
		}

	}
72

Gideon Greenspan committed
73 74 75 76

/*
	Omit PHP closing tag to help avoid accidental output
*/