qa-widget-related-qs.php 2.79 KB
Newer Older
Scott committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	File: qa-include/qa-widget-related-qs.php
	Description: Widget module class for related questions


	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.

	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
*/

Scott committed
23 24 25 26 27 28
class qa_related_qs
{
	public function allow_template($template)
	{
		return ($template=='question');
	}
Scott committed
29

Scott committed
30 31 32 33
	public function allow_region($region)
	{
		return ($region=='side') || ($region=='main') || ($region=='full');
	}
Scott committed
34

Scott committed
35 36 37
	public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
	{
		require_once QA_INCLUDE_DIR.'db/selects.php';
Scott committed
38

Scott committed
39 40
		if (@$qa_content['q_view']['raw']['type']!='Q') // question might not be visible, etc...
			return;
Scott committed
41

Scott committed
42
		$questionid=$qa_content['q_view']['raw']['postid'];
Scott committed
43

Scott committed
44 45
		$userid=qa_get_logged_in_userid();
		$cookieid=qa_cookie_get();
Scott committed
46

Scott committed
47
		$questions=qa_db_single_select(qa_db_related_qs_selectspec($userid, $questionid, qa_opt('page_size_related_qs')));
Scott committed
48

Scott committed
49
		$minscore=qa_match_to_min_score(qa_opt('match_related_qs'));
Scott committed
50

Scott committed
51 52 53
		foreach ($questions as $key => $question)
			if ($question['score']<$minscore)
				unset($questions[$key]);
Scott committed
54

Scott committed
55
		$titlehtml=qa_lang_html(count($questions) ? 'main/related_qs_title' : 'main/no_related_qs_title');
Scott committed
56

Scott committed
57 58 59 60 61 62 63
		if ($region=='side') {
			$themeobject->output(
				'<div class="qa-related-qs">',
				'<h2 style="margin-top:0; padding-top:0;">',
				$titlehtml,
				'</h2>'
			);
Scott committed
64

Scott committed
65
			$themeobject->output('<ul class="qa-related-q-list">');
Scott committed
66

Scott committed
67 68
			foreach ($questions as $question)
				$themeobject->output('<li class="qa-related-q-item"><a href="'.qa_q_path_html($question['postid'], $question['title']).'">'.qa_html($question['title']).'</a></li>');
Scott committed
69

Scott committed
70 71 72 73
			$themeobject->output(
				'</ul>',
				'</div>'
			);
Scott committed
74

Scott committed
75 76 77 78 79 80
		} else {
			$themeobject->output(
				'<h2>',
				$titlehtml,
				'</h2>'
			);
Scott committed
81

Scott committed
82 83 84
			$q_list=array(
				'form' => array(
					'tags' => 'method="post" action="'.qa_self_html().'"',
Scott committed
85

Scott committed
86 87
					'hidden' => array(
						'code' => qa_get_form_security_code('vote'),
Scott committed
88
					),
Scott committed
89
				),
Scott committed
90

Scott committed
91 92
				'qs' => array(),
			);
Scott committed
93

Scott committed
94 95
			$defaults=qa_post_html_defaults('Q');
			$usershtml=qa_userids_handles_html($questions);
Scott committed
96

Scott committed
97 98
			foreach ($questions as $question)
				$q_list['qs'][]=qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, qa_post_html_options($question, $defaults));
Scott committed
99

Scott committed
100
			$themeobject->q_list_and_form($q_list);
Scott committed
101 102
		}
	}
Scott committed
103
}