qa-widget-activity-count.php 2.2 KB
Newer Older
Gideon Greenspan committed
1 2 3 4 5 6 7
<?php

/*
	Question2Answer (c) Gideon Greenspan

	http://www.question2answer.org/

Scott Vivian committed
8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-include/qa-widget-activity-count.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Widget module class for activity count 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.
Scott Vivian committed
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_activity_count {
Scott Vivian committed
28

29
		public function allow_template($template)
Gideon Greenspan committed
30 31 32 33
		{
			return true;
		}

Scott Vivian committed
34

35
		public function allow_region($region)
Gideon Greenspan committed
36 37 38 39
		{
			return ($region=='side');
		}

Scott Vivian committed
40

41
		public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
Gideon Greenspan committed
42
		{
Gideon Greenspan committed
43
			$themeobject->output('<div class="qa-activity-count">');
Scott Vivian committed
44

Gideon Greenspan committed
45 46
			$this->output_count($themeobject, qa_opt('cache_qcount'), 'main/1_question', 'main/x_questions');
			$this->output_count($themeobject, qa_opt('cache_acount'), 'main/1_answer', 'main/x_answers');
Scott Vivian committed
47

Gideon Greenspan committed
48 49
			if (qa_opt('comment_on_qs') || qa_opt('comment_on_as'))
				$this->output_count($themeobject, qa_opt('cache_ccount'), 'main/1_comment', 'main/x_comments');
Scott Vivian committed
50

Gideon Greenspan committed
51
			$this->output_count($themeobject, qa_opt('cache_userpointscount'), 'main/1_user', 'main/x_users');
Scott Vivian committed
52

Gideon Greenspan committed
53
			$themeobject->output('</div>');
Gideon Greenspan committed
54
		}
Scott Vivian committed
55

Gideon Greenspan committed
56

57
		public function output_count($themeobject, $value, $langsingular, $langplural)
Gideon Greenspan committed
58
		{
Gideon Greenspan committed
59
			$themeobject->output('<p class="qa-activity-count-item">');
Scott Vivian committed
60

Gideon Greenspan committed
61
			if ($value==1)
Gideon Greenspan committed
62
				$themeobject->output(qa_lang_html_sub($langsingular, '<span class="qa-activity-count-data">1</span>', '1'));
Gideon Greenspan committed
63
			else
Gideon Greenspan committed
64
				$themeobject->output(qa_lang_html_sub($langplural, '<span class="qa-activity-count-data">'.number_format((int)$value).'</span>'));
Gideon Greenspan committed
65

Gideon Greenspan committed
66
			$themeobject->output('</p>');
Gideon Greenspan committed
67
		}
Scott Vivian committed
68

Gideon Greenspan committed
69
	}
Scott Vivian committed
70

Gideon Greenspan committed
71 72 73 74

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