qa-widget-activity-count.php 2.05 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-activity-count.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.

	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_activity_count
{
	public function allow_template($template)
	{
		return true;
	}
Scott committed
29

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

Scott committed
35 36 37
	public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
	{
		$themeobject->output('<div class="qa-activity-count">');
Scott committed
38

Scott committed
39 40
		$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 committed
41

Scott committed
42 43
		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 committed
44

Scott committed
45
		$this->output_count($themeobject, qa_opt('cache_userpointscount'), 'main/1_user', 'main/x_users');
Scott committed
46

Scott committed
47 48
		$themeobject->output('</div>');
	}
Scott committed
49

Scott committed
50 51
	public function output_count($themeobject, $value, $langsingular, $langplural)
	{
52 53
		require_once QA_INCLUDE_DIR . 'app/format.php';

Scott committed
54
		$themeobject->output('<p class="qa-activity-count-item">');
Scott committed
55

Scott committed
56 57 58
		if ($value==1)
			$themeobject->output(qa_lang_html_sub($langsingular, '<span class="qa-activity-count-data">1</span>', '1'));
		else
Scott committed
59
			$themeobject->output(qa_lang_html_sub($langplural, '<span class="qa-activity-count-data">'.qa_format_number((int) $value, 0, true).'</span>'));
Scott committed
60

Scott committed
61
		$themeobject->output('</p>');
Scott committed
62
	}
Scott committed
63
}