qa-theme-base.php 59.8 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-theme-base.php
	Description: Default theme class, broken into lots of little functions for easy overriding


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

23 24 25 26
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
	header('Location: ../');
	exit;
}
Scott committed
27 28 29 30 31 32 33 34 35 36 37 38 39


/*
	How do I make a theme which goes beyond CSS to actually modify the HTML output?

	Create a file named qa-theme.php in your new theme directory which defines a class qa_html_theme
	that extends this base class qa_html_theme_base. You can then override any of the methods below,
	referring back to the default method using double colon (qa_html_theme_base::) notation.

	Plugins can also do something similar by using a layer. For more information and to see some example
	code, please consult the online Q2A documentation.
*/

40 41
class qa_html_theme_base
{
42 43 44 45 46 47
	public $template;
	public $content;
	public $rooturl;
	public $request;
	public $isRTL; // (boolean) whether text direction is Right-To-Left

48 49 50
	protected $indent = 0;
	protected $lines = 0;
	protected $context = array();
Scott committed
51

52 53
	// whether to use new block layout in rankings (true) or fall back to tables (false)
	protected $ranking_block_layout = false;
Scott committed
54 55


56 57 58 59 60 61 62 63 64
	public function __construct($template, $content, $rooturl, $request)
/*
	Initialize the object and assign local variables
*/
	{
		$this->template = $template;
		$this->content = $content;
		$this->rooturl = $rooturl;
		$this->request = $request;
Scott committed
65

66 67
		$this->isRTL = isset($content['direction']) && $content['direction'] === 'rtl';
	}
68

69 70 71 72 73 74 75 76
	/**
	 * @deprecated PHP4-style constructor deprecated from 1.7; please use proper `__construct`
	 * function instead.
	 */
	public function qa_html_theme_base($template, $content, $rooturl, $request)
	{
		self::__construct($template, $content, $rooturl, $request);
	}
Scott committed
77

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

	public function output_array($elements)
/*
	Output each element in $elements on a separate line, with automatic HTML indenting.
	This should be passed markup which uses the <tag/> form for unpaired tags, to help keep
	track of indenting, although its actual output converts these to <tag> for W3C validation
*/
	{
		foreach ($elements as $element) {
			$delta = substr_count($element, '<') - substr_count($element, '<!') - 2*substr_count($element, '</') - substr_count($element, '/>');

			if ($delta < 0)
				$this->indent += $delta;

			echo str_repeat("\t", max(0, $this->indent)).str_replace('/>', '>', $element)."\n";

			if ($delta > 0)
				$this->indent += $delta;

			$this->lines++;
Scott committed
98
		}
99
	}
Scott committed
100 101


102 103 104 105 106 107 108 109
	public function output() // other parameters picked up via func_get_args()
/*
	Output each passed parameter on a separate line - see output_array() comments
*/
	{
		$args = func_get_args();
		$this->output_array($args);
	}
Scott committed
110 111


112 113 114 115 116 117 118 119 120
	public function output_raw($html)
/*
	Output $html at the current indent level, but don't change indent level based on the markup within.
	Useful for user-entered HTML which is unlikely to follow the rules we need to track indenting
*/
	{
		if (strlen($html))
			echo str_repeat("\t", max(0, $this->indent)).$html."\n";
	}
Scott committed
121 122


123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
	public function output_split($parts, $class, $outertag='span', $innertag='span', $extraclass=null)
/*
	Output the three elements ['prefix'], ['data'] and ['suffix'] of $parts (if they're defined),
	with appropriate CSS classes based on $class, using $outertag and $innertag in the markup.
*/
	{
		if (empty($parts) && strtolower($outertag) != 'td')
			return;

		$this->output(
			'<'.$outertag.' class="'.$class.(isset($extraclass) ? (' '.$extraclass) : '').'">',
			(strlen(@$parts['prefix']) ? ('<'.$innertag.' class="'.$class.'-pad">'.$parts['prefix'].'</'.$innertag.'>') : '').
			(strlen(@$parts['data']) ? ('<'.$innertag.' class="'.$class.'-data">'.$parts['data'].'</'.$innertag.'>') : '').
			(strlen(@$parts['suffix']) ? ('<'.$innertag.' class="'.$class.'-pad">'.$parts['suffix'].'</'.$innertag.'>') : ''),
			'</'.$outertag.'>'
		);
	}
Scott committed
140 141


142 143 144 145 146 147 148
	public function set_context($key, $value)
/*
	Set some context, which be accessed via $this->context for a function to know where it's being used on the page
*/
	{
		$this->context[$key] = $value;
	}
Scott committed
149 150


151 152 153 154 155 156 157
	public function clear_context($key)
/*
	Clear some context (used at the end of the appropriate loop)
*/
	{
		unset($this->context[$key]);
	}
Scott committed
158 159


160 161 162
	public function reorder_parts($parts, $beforekey=null, $reorderrelative=true)
/*
	Reorder the parts of the page according to the $parts array which contains part keys in their new order. Call this
Scott committed
163
	before main_parts(). See the docs for qa_array_reorder() in util/sort.php for the other parameters.
164 165
*/
	{
Scott committed
166
		require_once QA_INCLUDE_DIR.'util/sort.php';
Scott committed
167

168 169
		qa_array_reorder($this->content, $parts, $beforekey, $reorderrelative);
	}
Scott committed
170 171


172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
	public function widgets($region, $place)
/*
	Output the widgets (as provided in $this->content['widgets']) for $region and $place
*/
	{
		if (count(@$this->content['widgets'][$region][$place])) {
			$this->output('<div class="qa-widgets-'.$region.' qa-widgets-'.$region.'-'.$place.'">');

			foreach ($this->content['widgets'][$region][$place] as $module) {
				$this->output('<div class="qa-widget-'.$region.' qa-widget-'.$region.'-'.$place.'">');
				$module->output_widget($region, $place, $this, $this->template, $this->request, $this->content);
				$this->output('</div>');
			}

			$this->output('</div>', '');
Scott committed
187
		}
188
	}
Scott committed
189

190 191 192 193 194
	/**
	 * Pre-output initialization. Immediately called after loading of the module. Content and template variables are
	 * already setup at this point. Useful to perform layer initialization in the earliest and safest stage possible
	 */
	public function initialize() { }
Scott committed
195

196 197 198 199 200 201 202 203 204 205 206
	public function finish()
/*
	Post-output cleanup. For now, check that the indenting ended right, and if not, output a warning in an HTML comment
*/
	{
		if ($this->indent) {
			echo "<!--\nIt's no big deal, but your HTML could not be indented properly. To fix, please:\n".
				"1. Use this->output() to output all HTML.\n".
				"2. Balance all paired tags like <td>...</td> or <div>...</div>.\n".
				"3. Use a slash at the end of unpaired tags like <img/> or <input/>.\n".
				"Thanks!\n-->\n";
Scott committed
207
		}
208
	}
Scott committed
209 210


211 212 213 214
//	From here on, we have a large number of class methods which output particular pieces of HTML markup
//	The calling chain is initiated from qa-page.php, or qa-ajax-*.php for refreshing parts of a page,
//	For most HTML elements, the name of the function is similar to the element's CSS class, for example:
//	search() outputs <div class="qa-search">, q_list() outputs <div class="qa-q-list">, etc...
Scott committed
215

216 217 218 219
	public function doctype()
	{
		$this->output('<!DOCTYPE html>');
	}
Scott committed
220

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
	public function html()
	{
		$attribution = '<!-- Powered by Question2Answer - http://www.question2answer.org/ -->';
		$this->output(
			'<html>',
			$attribution
		);

		$this->head();
		$this->body();

		$this->output(
			$attribution,
			'</html>'
		);
	}
Scott committed
237

238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
	public function head()
	{
		$this->output(
			'<head>',
			'<meta charset="'.$this->content['charset'].'"/>'
		);

		$this->head_title();
		$this->head_metas();
		$this->head_css();
		$this->head_links();
		$this->head_lines();
		$this->head_script();
		$this->head_custom();

		$this->output('</head>');
	}
Scott committed
255

256 257 258 259
	public function head_title()
	{
		$pagetitle = strlen($this->request) ? strip_tags(@$this->content['title']) : '';
		$headtitle = (strlen($pagetitle) ? ($pagetitle.' - ') : '').$this->content['site_title'];
Scott committed
260

261 262
		$this->output('<title>'.$headtitle.'</title>');
	}
Scott committed
263

264 265 266 267
	public function head_metas()
	{
		if (strlen(@$this->content['description']))
			$this->output('<meta name="description" content="'.$this->content['description'].'"/>');
Scott committed
268

269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
		if (strlen(@$this->content['keywords'])) // as far as I know, meta keywords have zero effect on search rankings or listings
			$this->output('<meta name="keywords" content="'.$this->content['keywords'].'"/>');
	}

	public function head_links()
	{
		if (isset($this->content['canonical']))
			$this->output('<link rel="canonical" href="'.$this->content['canonical'].'"/>');

		if (isset($this->content['feed']['url']))
			$this->output('<link rel="alternate" type="application/rss+xml" href="'.$this->content['feed']['url'].'" title="'.@$this->content['feed']['label'].'"/>');

		// convert page links to rel=prev and rel=next tags
		if (isset($this->content['page_links']['items'])) {
			foreach ($this->content['page_links']['items'] as $page_link) {
				if (in_array($page_link['type'], array('prev', 'next')))
					$this->output('<link rel="' . $page_link['type'] . '" href="' . $page_link['url'] . '" />');
Scott committed
286 287
			}
		}
288
	}
Scott committed
289

290 291 292 293 294 295 296
	public function head_script()
	{
		if (isset($this->content['script'])) {
			foreach ($this->content['script'] as $scriptline)
				$this->output_raw($scriptline);
		}
	}
Scott committed
297

298 299 300
	public function head_css()
	{
		$this->output('<link rel="stylesheet" href="'.$this->rooturl.$this->css_name().'"/>');
Scott committed
301

302 303 304
		if (isset($this->content['css_src'])) {
			foreach ($this->content['css_src'] as $css_src)
				$this->output('<link rel="stylesheet" href="'.$css_src.'"/>');
Scott committed
305 306
		}

307
		if (!empty($this->content['notices'])) {
Scott committed
308
			$this->output(
309 310 311
				'<style>',
				'.qa-body-js-on .qa-notice {display:none;}',
				'</style>'
Scott committed
312
			);
313 314
		}
	}
Scott committed
315

316 317 318 319
	public function css_name()
	{
		return 'qa-styles.css?'.QA_VERSION;
	}
Scott committed
320

321 322 323 324 325
	public function head_lines()
	{
		if (isset($this->content['head_lines'])) {
			foreach ($this->content['head_lines'] as $line)
				$this->output_raw($line);
Scott committed
326
		}
327
	}
Scott committed
328

329 330 331 332
	public function head_custom()
	{
		// abstract method
	}
Scott committed
333

334 335 336 337 338
	public function body()
	{
		$this->output('<body');
		$this->body_tags();
		$this->output('>');
Scott committed
339

340 341 342 343 344
		$this->body_script();
		$this->body_header();
		$this->body_content();
		$this->body_footer();
		$this->body_hidden();
Scott committed
345

346 347
		$this->output('</body>');
	}
Scott committed
348

349 350 351 352 353 354 355
	public function body_hidden()
	{
		$indent = $this->isRTL ? '9999px' : '-9999px';
		$this->output('<div style="position:absolute; left:'.$indent.'; top:-9999px;">');
		$this->waiting_template();
		$this->output('</div>');
	}
Scott committed
356

357 358 359 360
	public function waiting_template()
	{
		$this->output('<span id="qa-waiting-template" class="qa-waiting">...</span>');
	}
Scott committed
361

362 363 364 365 366 367 368 369 370
	public function body_script()
	{
		$this->output(
			'<script>',
			"var b=document.getElementsByTagName('body')[0];",
			"b.className=b.className.replace('qa-body-js-off', 'qa-body-js-on');",
			'</script>'
		);
	}
Scott committed
371

372 373 374 375 376
	public function body_header()
	{
		if (isset($this->content['body_header']))
			$this->output_raw($this->content['body_header']);
	}
Scott committed
377

378 379 380 381 382
	public function body_footer()
	{
		if (isset($this->content['body_footer']))
			$this->output_raw($this->content['body_footer']);
	}
Scott committed
383

384 385 386 387
	public function body_content()
	{
		$this->body_prefix();
		$this->notices();
Scott committed
388

389
		$this->output('<div class="qa-body-wrapper">', '');
Scott committed
390

391 392 393 394 395 396 397 398
		$this->widgets('full', 'top');
		$this->header();
		$this->widgets('full', 'high');
		$this->sidepanel();
		$this->main();
		$this->widgets('full', 'low');
		$this->footer();
		$this->widgets('full', 'bottom');
Scott committed
399

400
		$this->output('</div> <!-- END body-wrapper -->');
Scott committed
401

402 403
		$this->body_suffix();
	}
Scott committed
404

405 406 407
	public function body_tags()
	{
		$class = 'qa-template-'.qa_html($this->template);
Scott committed
408

409 410 411
		if (isset($this->content['categoryids'])) {
			foreach ($this->content['categoryids'] as $categoryid)
				$class .= ' qa-category-'.qa_html($categoryid);
Scott committed
412 413
		}

414 415
		$this->output('class="'.$class.' qa-body-js-off"');
	}
Scott committed
416

417 418 419 420
	public function body_prefix()
	{
		// abstract method
	}
Scott committed
421

422 423 424 425
	public function body_suffix()
	{
		// abstract method
	}
Scott committed
426

427 428 429 430 431
	public function notices()
	{
		if (!empty($this->content['notices'])) {
			foreach ($this->content['notices'] as $notice)
				$this->notice($notice);
Scott committed
432
		}
433
	}
Scott committed
434

435 436 437
	public function notice($notice)
	{
		$this->output('<div class="qa-notice" id="'.$notice['id'].'">');
Scott committed
438

439 440
		if (isset($notice['form_tags']))
			$this->output('<form '.$notice['form_tags'].'>');
Scott committed
441

442
		$this->output_raw($notice['content']);
Scott committed
443

444
		$this->output('<input '.$notice['close_tags'].' type="submit" value="X" class="qa-notice-close-button"/> ');
Scott committed
445

446 447 448
		if (isset($notice['form_tags'])) {
			$this->form_hidden_elements(@$notice['form_hidden']);
			$this->output('</form>');
Scott committed
449 450
		}

451 452
		$this->output('</div>');
	}
Scott committed
453

454 455 456
	public function header()
	{
		$this->output('<div class="qa-header">');
Scott committed
457

458 459 460 461
		$this->logo();
		$this->nav_user_search();
		$this->nav_main_sub();
		$this->header_clear();
Scott committed
462

463 464
		$this->output('</div> <!-- END qa-header -->', '');
	}
Scott committed
465

466 467 468 469 470
	public function nav_user_search()
	{
		$this->nav('user');
		$this->search();
	}
Scott committed
471

472 473 474 475 476
	public function nav_main_sub()
	{
		$this->nav('main');
		$this->nav('sub');
	}
Scott committed
477

478 479 480 481 482 483 484 485
	public function logo()
	{
		$this->output(
			'<div class="qa-logo">',
			$this->content['logo'],
			'</div>'
		);
	}
Scott committed
486

487 488 489
	public function search()
	{
		$search = $this->content['search'];
Scott committed
490

491 492 493 494 495
		$this->output(
			'<div class="qa-search">',
			'<form '.$search['form_tags'].'>',
			@$search['form_extra']
		);
Scott committed
496

497 498
		$this->search_field($search);
		$this->search_button($search);
Scott committed
499

500 501 502 503 504
		$this->output(
			'</form>',
			'</div>'
		);
	}
Scott committed
505

506 507 508 509
	public function search_field($search)
	{
		$this->output('<input type="text" '.$search['field_tags'].' value="'.@$search['value'].'" class="qa-search-field"/>');
	}
Scott committed
510

511 512 513 514
	public function search_button($search)
	{
		$this->output('<input type="submit" value="'.$search['button_label'].'" class="qa-search-button"/>');
	}
Scott committed
515

516 517 518
	public function nav($navtype, $level=null)
	{
		$navigation = @$this->content['navigation'][$navtype];
Scott committed
519

520 521
		if ($navtype == 'user' || isset($navigation)) {
			$this->output('<div class="qa-nav-'.$navtype.'">');
Scott committed
522

523 524 525 526 527 528 529 530 531
			if ($navtype == 'user')
				$this->logged_in();

			// reverse order of 'opposite' items since they float right
			foreach (array_reverse($navigation, true) as $key => $navlink) {
				if (@$navlink['opposite']) {
					unset($navigation[$key]);
					$navigation[$key] = $navlink;
				}
Scott committed
532 533
			}

534 535 536 537 538
			$this->set_context('nav_type', $navtype);
			$this->nav_list($navigation, 'nav-'.$navtype, $level);
			$this->nav_clear($navtype);
			$this->clear_context('nav_type');

Scott committed
539 540
			$this->output('</div>');
		}
541
	}
Scott committed
542

543 544 545
	public function nav_list($navigation, $class, $level=null)
	{
		$this->output('<ul class="qa-'.$class.'-list'.(isset($level) ? (' qa-'.$class.'-list-'.$level) : '').'">');
Scott committed
546

547
		$index = 0;
Scott committed
548

549 550 551 552
		foreach ($navigation as $key => $navlink) {
			$this->set_context('nav_key', $key);
			$this->set_context('nav_index', $index++);
			$this->nav_item($key, $navlink, $class, $level);
Scott committed
553 554
		}

555 556
		$this->clear_context('nav_key');
		$this->clear_context('nav_index');
Scott committed
557

558 559
		$this->output('</ul>');
	}
Scott committed
560

561 562 563 564 565 566 567
	public function nav_clear($navtype)
	{
		$this->output(
			'<div class="qa-nav-'.$navtype.'-clear">',
			'</div>'
		);
	}
Scott committed
568

569 570 571 572 573 574
	public function nav_item($key, $navlink, $class, $level=null)
	{
		$suffix = strtr($key, array( // map special character in navigation key
			'$' => '',
			'/' => '-',
		));
Scott committed
575

576 577 578 579 580 581
		$this->output('<li class="qa-'.$class.'-item'.(@$navlink['opposite'] ? '-opp' : '').
			(@$navlink['state'] ? (' qa-'.$class.'-'.$navlink['state']) : '').' qa-'.$class.'-'.$suffix.'">');
		$this->nav_link($navlink, $class);

		if (count(@$navlink['subnav']))
			$this->nav_list($navlink['subnav'], $class, 1+$level);
Scott committed
582

583 584
		$this->output('</li>');
	}
Scott committed
585

586 587 588
	public function nav_link($navlink, $class)
	{
		if (isset($navlink['url'])) {
Scott committed
589
			$this->output(
590 591 592 593 594 595
				'<a href="'.$navlink['url'].'" class="qa-'.$class.'-link'.
				(@$navlink['selected'] ? (' qa-'.$class.'-selected') : '').
				(@$navlink['favorited'] ? (' qa-'.$class.'-favorited') : '').
				'"'.(strlen(@$navlink['popup']) ? (' title="'.$navlink['popup'].'"') : '').
				(isset($navlink['target']) ? (' target="'.$navlink['target'].'"') : '').'>'.$navlink['label'].
				'</a>'
Scott committed
596 597
			);
		}
598 599 600 601 602 603 604
		else {
			$this->output(
				'<span class="qa-'.$class.'-nolink'.(@$navlink['selected'] ? (' qa-'.$class.'-selected') : '').
				(@$navlink['favorited'] ? (' qa-'.$class.'-favorited') : '').'"'.
				(strlen(@$navlink['popup']) ? (' title="'.$navlink['popup'].'"') : '').
				'>'.$navlink['label'].'</span>'
			);
Scott committed
605 606
		}

607 608 609
		if (strlen(@$navlink['note']))
			$this->output('<span class="qa-'.$class.'-note">'.$navlink['note'].'</span>');
	}
Scott committed
610

611 612 613 614
	public function logged_in()
	{
		$this->output_split(@$this->content['loggedin'], 'qa-logged-in', 'div');
	}
Scott committed
615

616 617 618 619 620 621 622
	public function header_clear()
	{
		$this->output(
			'<div class="qa-header-clear">',
			'</div>'
		);
	}
Scott committed
623

624 625 626 627 628 629 630 631 632 633 634 635 636
	public function sidepanel()
	{
		$this->output('<div class="qa-sidepanel">');
		$this->widgets('side', 'top');
		$this->sidebar();
		$this->widgets('side', 'high');
		$this->nav('cat', 1);
		$this->widgets('side', 'low');
		$this->output_raw(@$this->content['sidepanel']);
		$this->feed();
		$this->widgets('side', 'bottom');
		$this->output('</div>', '');
	}
Scott committed
637

638 639 640
	public function sidebar()
	{
		$sidebar = @$this->content['sidebar'];
Scott committed
641

642 643 644 645 646 647
		if (!empty($sidebar)) {
			$this->output('<div class="qa-sidebar">');
			$this->output_raw($sidebar);
			$this->output('</div>', '');
		}
	}
Scott committed
648

649 650 651 652 653 654 655 656
	public function feed()
	{
		$feed = @$this->content['feed'];

		if (!empty($feed)) {
			$this->output('<div class="qa-feed">');
			$this->output('<a href="'.$feed['url'].'" class="qa-feed-link">'.@$feed['label'].'</a>');
			$this->output('</div>');
Scott committed
657
		}
658
	}
Scott committed
659

660 661 662
	public function main()
	{
		$content = $this->content;
Scott committed
663

664
		$this->output('<div class="qa-main'.(@$this->content['hidden'] ? ' qa-main-hidden' : '').'">');
Scott committed
665

666
		$this->widgets('main', 'top');
Scott committed
667

668
		$this->page_title_error();
Scott committed
669

670
		$this->widgets('main', 'high');
Scott committed
671

672
		$this->main_parts($content);
Scott committed
673

674
		$this->widgets('main', 'low');
Scott committed
675

676 677
		$this->page_links();
		$this->suggest_next();
Scott committed
678

679
		$this->widgets('main', 'bottom');
Scott committed
680

681 682
		$this->output('</div> <!-- END qa-main -->', '');
	}
Scott committed
683

684 685 686 687 688 689 690
	public function page_title_error()
	{
		if (isset($this->content['title'])) {
			$favorite = isset($this->content['favorite']) ? $this->content['favorite'] : null;

			if (isset($favorite))
				$this->output('<form ' . $favorite['form_tags'] . '>');
Scott committed
691

692 693 694 695 696 697 698 699 700 701
			$this->output('<h1>');
			$this->favorite();
			$this->title();
			$this->output('</h1>');

			if (isset($favorite)) {
				$formhidden = isset($favorite['form_hidden']) ? $favorite['form_hidden'] : null;
				$this->form_hidden_elements($formhidden);
				$this->output('</form>');
			}
Scott committed
702
		}
703 704 705
		if (isset($this->content['error']))
			$this->error($this->content['error']);
	}
Scott committed
706

707 708 709 710 711 712 713 714
	public function favorite()
	{
		$favorite = isset($this->content['favorite']) ? $this->content['favorite'] : null;
		if (isset($favorite)) {
			$favoritetags = isset($favorite['favorite_tags']) ? $favorite['favorite_tags'] : '';
			$this->output('<span class="qa-favoriting" ' . $favoritetags . '>');
			$this->favorite_inner_html($favorite);
			$this->output('</span>');
Scott committed
715
		}
716
	}
Scott committed
717

718 719 720 721 722 723 724 725
	public function title()
	{
		$q_view = @$this->content['q_view'];

		// link title where appropriate
		$url = isset($q_view['url']) ? $q_view['url'] : false;

		if (isset($this->content['title'])) {
Scott committed
726
			$this->output(
727 728 729
				$url ? '<a href="'.$url.'">' : '',
				$this->content['title'],
				$url ? '</a>' : ''
Scott committed
730 731 732
			);
		}

733
		// add closed note in title
734
		if (!empty($q_view['closed']['state']))
735 736
			$this->output(' ['.$q_view['closed']['state'].']');
	}
Scott committed
737

738 739 740 741 742
	public function favorite_inner_html($favorite)
	{
		$this->favorite_button(@$favorite['favorite_add_tags'], 'qa-favorite');
		$this->favorite_button(@$favorite['favorite_remove_tags'], 'qa-unfavorite');
	}
Scott committed
743

744 745 746 747 748
	public function favorite_button($tags, $class)
	{
		if (isset($tags))
			$this->output('<input '.$tags.' type="submit" value="" class="'.$class.'-button"/> ');
	}
Scott committed
749

750 751 752 753 754 755 756 757 758 759
	public function error($error)
	{
		if (strlen($error)) {
			$this->output(
				'<div class="qa-error">',
				$error,
				'</div>'
			);
		}
	}
Scott committed
760

761 762 763 764 765
	public function main_parts($content)
	{
		foreach ($content as $key => $part) {
			$this->set_context('part', $key);
			$this->main_part($key, $part);
Scott committed
766 767
		}

768 769
		$this->clear_context('part');
	}
Scott committed
770

771 772 773 774 775 776
	public function main_part($key, $part)
	{
		$partdiv = (
			strpos($key, 'custom') === 0 ||
			strpos($key, 'form') === 0 ||
			strpos($key, 'q_list') === 0 ||
Scott committed
777
			(strpos($key, 'q_view') === 0 && !isset($this->content['form_q_edit'])) ||
778 779 780 781 782 783
			strpos($key, 'a_form') === 0 ||
			strpos($key, 'a_list') === 0 ||
			strpos($key, 'ranking') === 0 ||
			strpos($key, 'message_list') === 0 ||
			strpos($key, 'nav_list') === 0
		);
Scott committed
784

785 786
		if ($partdiv)
			$this->output('<div class="qa-part-'.strtr($key, '_', '-').'">'); // to help target CSS to page parts
Scott committed
787

788 789
		if (strpos($key, 'custom') === 0)
			$this->output_raw($part);
Scott committed
790

791 792
		elseif (strpos($key, 'form') === 0)
			$this->form($part);
Scott committed
793

794 795
		elseif (strpos($key, 'q_list') === 0)
			$this->q_list_and_form($part);
Scott committed
796

797 798
		elseif (strpos($key, 'q_view') === 0)
			$this->q_view($part);
Scott committed
799

800 801
		elseif (strpos($key, 'a_form') === 0)
			$this->a_form($part);
Scott committed
802

803 804
		elseif (strpos($key, 'a_list') === 0)
			$this->a_list($part);
Scott committed
805

806 807
		elseif (strpos($key, 'ranking') === 0)
			$this->ranking($part);
Scott committed
808

809 810
		elseif (strpos($key, 'message_list') === 0)
			$this->message_list_and_form($part);
Scott committed
811

812 813 814 815
		elseif (strpos($key, 'nav_list') === 0) {
			$this->part_title($part);
			$this->nav_list($part['nav'], $part['type'], 1);
		}
Scott committed
816

817 818 819
		if ($partdiv)
			$this->output('</div>');
	}
Scott committed
820

821 822 823
	public function footer()
	{
		$this->output('<div class="qa-footer">');
Scott committed
824

825 826 827
		$this->nav('footer');
		$this->attribution();
		$this->footer_clear();
Scott committed
828

829 830
		$this->output('</div> <!-- END qa-footer -->', '');
	}
Scott committed
831

832 833 834
	public function attribution()
	{
		// Hi there. I'd really appreciate you displaying this link on your Q2A site. Thank you - Gideon
Scott committed
835

836 837 838 839 840 841
		$this->output(
			'<div class="qa-attribution">',
			'Powered by <a href="http://www.question2answer.org/">Question2Answer</a>',
			'</div>'
		);
	}
Scott committed
842

843 844 845 846 847 848 849
	public function footer_clear()
	{
		$this->output(
			'<div class="qa-footer-clear">',
			'</div>'
		);
	}
Scott committed
850

851 852 853 854
	public function section($title)
	{
		$this->part_title(array('title' => $title));
	}
Scott committed
855

856 857 858 859 860
	public function part_title($part)
	{
		if (strlen(@$part['title']) || strlen(@$part['title_tags']))
			$this->output('<h2'.rtrim(' '.@$part['title_tags']).'>'.@$part['title'].'</h2>');
	}
Scott committed
861

862 863 864 865 866
	public function part_footer($part)
	{
		if (isset($part['footer']))
			$this->output($part['footer']);
	}
Scott committed
867

868 869 870 871
	public function form($form)
	{
		if (!empty($form)) {
			$this->part_title($form);
Scott committed
872

873 874
			if (isset($form['tags']))
				$this->output('<form '.$form['tags'].'>');
Scott committed
875

876
			$this->form_body($form);
Scott committed
877

878 879
			if (isset($form['tags']))
				$this->output('</form>');
Scott committed
880
		}
881
	}
Scott committed
882

883 884 885 886 887 888
	public function form_columns($form)
	{
		if (isset($form['ok']) || !empty($form['fields']) )
			$columns = ($form['style'] == 'wide') ? 3 : 1;
		else
			$columns = 0;
Scott committed
889

890 891
		return $columns;
	}
Scott committed
892

893 894 895 896 897 898 899 900 901 902
	public function form_spacer($form, $columns)
	{
		$this->output(
			'<tr>',
			'<td colspan="'.$columns.'" class="qa-form-'.$form['style'].'-spacer">',
			'&nbsp;',
			'</td>',
			'</tr>'
		);
	}
Scott committed
903

904 905 906 907
	public function form_body($form)
	{
		if (@$form['boxed'])
			$this->output('<div class="qa-form-table-boxed">');
Scott committed
908

909
		$columns = $this->form_columns($form);
Scott committed
910

911 912
		if ($columns)
			$this->output('<table class="qa-form-'.$form['style'].'-table">');
Scott committed
913

914 915 916
		$this->form_ok($form, $columns);
		$this->form_fields($form, $columns);
		$this->form_buttons($form, $columns);
Scott committed
917

918 919
		if ($columns)
			$this->output('</table>');
Scott committed
920

921
		$this->form_hidden($form);
Scott committed
922

923 924 925
		if (@$form['boxed'])
			$this->output('</div>');
	}
Scott committed
926

927 928 929
	public function form_ok($form, $columns)
	{
		if (!empty($form['ok'])) {
Scott committed
930 931
			$this->output(
				'<tr>',
932 933
				'<td colspan="'.$columns.'" class="qa-form-'.$form['style'].'-ok">',
				$form['ok'],
Scott committed
934 935 936 937
				'</td>',
				'</tr>'
			);
		}
938
	}
Scott committed
939

940 941 942
	public function form_reorder_fields(&$form, $keys, $beforekey=null, $reorderrelative=true)
/*
	Reorder the fields of $form according to the $keys array which contains the field keys in their new order. Call
Scott committed
943
	before any fields are output. See the docs for qa_array_reorder() in util/sort.php for the other parameters.
944 945
*/
	{
Scott committed
946
		require_once QA_INCLUDE_DIR.'util/sort.php';
Scott committed
947

948 949 950
		if (is_array($form['fields']))
			qa_array_reorder($form['fields'], $keys, $beforekey, $reorderrelative);
	}
Scott committed
951

952 953 954 955 956
	public function form_fields($form, $columns)
	{
		if (!empty($form['fields'])) {
			foreach ($form['fields'] as $key => $field) {
				$this->set_context('field_key', $key);
Scott committed
957

958 959 960 961
				if (@$field['type'] == 'blank')
					$this->form_spacer($form, $columns);
				else
					$this->form_field_rows($form, $columns, $field);
Scott committed
962 963
			}

964
			$this->clear_context('field_key');
Scott committed
965
		}
966
	}
Scott committed
967

968 969 970
	public function form_field_rows($form, $columns, $field)
	{
		$style = $form['style'];
Scott committed
971

972 973 974 975
		if (isset($field['style'])) { // field has different style to most of form
			$style = $field['style'];
			$colspan = $columns;
			$columns = ($style == 'wide') ? 3 : 1;
Scott committed
976
		}
977 978
		else
			$colspan = null;
Scott committed
979

980 981 982 983 984
		$prefixed = (@$field['type'] == 'checkbox') && ($columns == 1) && !empty($field['label']);
		$suffixed = (@$field['type'] == 'select' || @$field['type'] == 'number') && $columns == 1 && !empty($field['label']) && !@$field['loose'];
		$skipdata = @$field['tight'];
		$tworows = ($columns == 1) && (!empty($field['label'])) && (!$skipdata) &&
			( (!($prefixed||$suffixed)) || (!empty($field['error'])) || (!empty($field['note'])) );
Scott committed
985

986 987 988
		if (isset($field['id'])) {
			if ($columns == 1)
				$this->output('<tbody id="'.$field['id'].'">', '<tr>');
Scott committed
989
			else
990 991 992 993
				$this->output('<tr id="'.$field['id'].'">');
		}
		else
			$this->output('<tr>');
Scott committed
994

995 996
		if ($columns > 1 || !empty($field['label']))
			$this->form_label($field, $style, $columns, $prefixed, $suffixed, $colspan);
Scott committed
997

998 999 1000 1001 1002 1003
		if ($tworows) {
			$this->output(
				'</tr>',
				'<tr>'
			);
		}
Scott committed
1004

1005 1006
		if (!$skipdata)
			$this->form_data($field, $style, $columns, !($prefixed||$suffixed), $colspan);
Scott committed
1007

1008
		$this->output('</tr>');
Scott committed
1009

1010 1011 1012
		if ($columns == 1 && isset($field['id']))
			$this->output('</tbody>');
	}
Scott committed
1013

1014 1015 1016
	public function form_label($field, $style, $columns, $prefixed, $suffixed, $colspan)
	{
		$extratags = '';
Scott committed
1017

1018 1019
		if ($columns > 1 && (@$field['type'] == 'select-radio' || @$field['rows'] > 1))
			$extratags .= ' style="vertical-align:top;"';
Scott committed
1020

1021 1022
		if (isset($colspan))
			$extratags .= ' colspan="'.$colspan.'"';
Scott committed
1023

1024
		$this->output('<td class="qa-form-'.$style.'-label"'.$extratags.'>');
Scott committed
1025

1026 1027 1028 1029
		if ($prefixed) {
			$this->output('<label>');
			$this->form_field($field, $style);
		}
Scott committed
1030

1031
		$this->output(@$field['label']);
Scott committed
1032

1033 1034
		if ($prefixed)
			$this->output('</label>');
Scott committed
1035

1036 1037 1038
		if ($suffixed) {
			$this->output('&nbsp;');
			$this->form_field($field, $style);
Scott committed
1039 1040
		}

1041 1042
		$this->output('</td>');
	}
Scott committed
1043

1044 1045 1046 1047 1048 1049
	public function form_data($field, $style, $columns, $showfield, $colspan)
	{
		if ($showfield || (!empty($field['error'])) || (!empty($field['note']))) {
			$this->output(
				'<td class="qa-form-'.$style.'-data"'.(isset($colspan) ? (' colspan="'.$colspan.'"') : '').'>'
			);
Scott committed
1050

1051 1052
			if ($showfield)
				$this->form_field($field, $style);
Scott committed
1053

1054 1055
			if (!empty($field['error'])) {
				if (@$field['note_force'])
Scott committed
1056 1057
					$this->form_note($field, $style, $columns);

1058
				$this->form_error($field, $style, $columns);
Scott committed
1059
			}
1060 1061
			elseif (!empty($field['note']))
				$this->form_note($field, $style, $columns);
Scott committed
1062

1063 1064 1065
			$this->output('</td>');
		}
	}
Scott committed
1066

1067 1068 1069
	public function form_field($field, $style)
	{
		$this->form_prefix($field, $style);
Scott committed
1070

1071
		$this->output_raw(@$field['html_prefix']);
Scott committed
1072

1073 1074 1075 1076
		switch (@$field['type']) {
			case 'checkbox':
				$this->form_checkbox($field, $style);
				break;
Scott committed
1077

1078 1079 1080
			case 'static':
				$this->form_static($field, $style);
				break;
Scott committed
1081

1082 1083 1084
			case 'password':
				$this->form_password($field, $style);
				break;
Scott committed
1085

1086 1087 1088
			case 'number':
				$this->form_number($field, $style);
				break;
Scott committed
1089

1090 1091 1092
			case 'select':
				$this->form_select($field, $style);
				break;
Scott committed
1093

1094 1095 1096
			case 'select-radio':
				$this->form_select_radio($field, $style);
				break;
Scott committed
1097

1098 1099 1100
			case 'image':
				$this->form_image($field, $style);
				break;
Scott committed
1101

1102 1103 1104
			case 'custom':
				$this->output_raw(@$field['html']);
				break;
Scott committed
1105

1106 1107 1108 1109 1110 1111
			default:
				if (@$field['type'] == 'textarea' || @$field['rows'] > 1)
					$this->form_text_multi_row($field, $style);
				else
					$this->form_text_single_row($field, $style);
				break;
Scott committed
1112 1113
		}

1114
		$this->output_raw(@$field['html_suffix']);
Scott committed
1115

1116 1117
		$this->form_suffix($field, $style);
	}
Scott committed
1118

1119 1120 1121
	public function form_reorder_buttons(&$form, $keys, $beforekey=null, $reorderrelative=true)
/*
	Reorder the buttons of $form according to the $keys array which contains the button keys in their new order. Call
Scott committed
1122
	before any buttons are output. See the docs for qa_array_reorder() in util/sort.php for the other parameters.
1123 1124
*/
	{
Scott committed
1125
		require_once QA_INCLUDE_DIR.'util/sort.php';
Scott committed
1126

1127 1128 1129
		if (is_array($form['buttons']))
			qa_array_reorder($form['buttons'], $keys, $beforekey, $reorderrelative);
	}
Scott committed
1130

1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
	public function form_buttons($form, $columns)
	{
		if (!empty($form['buttons'])) {
			$style = @$form['style'];

			if ($columns) {
				$this->output(
					'<tr>',
					'<td colspan="'.$columns.'" class="qa-form-'.$style.'-buttons">'
				);
			}
Scott committed
1142

1143 1144
			foreach ($form['buttons'] as $key => $button) {
				$this->set_context('button_key', $key);
Scott committed
1145

1146 1147 1148 1149 1150
				if (empty($button))
					$this->form_button_spacer($style);
				else {
					$this->form_button_data($button, $key, $style);
					$this->form_button_note($button, $style);
Scott committed
1151 1152 1153
				}
			}

1154
			$this->clear_context('button_key');
Scott committed
1155

1156
			if ($columns) {
Scott committed
1157
				$this->output(
1158 1159
					'</td>',
					'</tr>'
Scott committed
1160 1161 1162
				);
			}
		}
1163
	}
Scott committed
1164

1165 1166 1167
	public function form_button_data($button, $key, $style)
	{
		$baseclass = 'qa-form-'.$style.'-button qa-form-'.$style.'-button-'.$key;
Scott committed
1168

1169 1170 1171
		$this->output('<input'.rtrim(' '.@$button['tags']).' value="'.@$button['label'].'" title="'.@$button['popup'].'" type="submit"'.
			(isset($style) ? (' class="'.$baseclass.'"') : '').'/>');
	}
Scott committed
1172

1173 1174 1175 1176 1177 1178 1179 1180 1181
	public function form_button_note($button, $style)
	{
		if (!empty($button['note'])) {
			$this->output(
				'<span class="qa-form-'.$style.'-note">',
				$button['note'],
				'</span>',
				'<br/>'
			);
Scott committed
1182
		}
1183
	}
Scott committed
1184

1185 1186 1187 1188
	public function form_button_spacer($style)
	{
		$this->output('<span class="qa-form-'.$style.'-buttons-spacer">&nbsp;</span>');
	}
Scott committed
1189

1190 1191 1192 1193
	public function form_hidden($form)
	{
		$this->form_hidden_elements(@$form['hidden']);
	}
Scott committed
1194

1195 1196 1197 1198 1199
	public function form_hidden_elements($hidden)
	{
		if (!empty($hidden)) {
			foreach ($hidden as $name => $value)
				$this->output('<input type="hidden" name="'.$name.'" value="'.$value.'"/>');
Scott committed
1200
		}
1201
	}
Scott committed
1202

1203 1204 1205 1206 1207
	public function form_prefix($field, $style)
	{
		if (!empty($field['prefix']))
			$this->output('<span class="qa-form-'.$style.'-prefix">'.$field['prefix'].'</span>');
	}
Scott committed
1208

1209 1210 1211 1212 1213
	public function form_suffix($field, $style)
	{
		if (!empty($field['suffix']))
			$this->output('<span class="qa-form-'.$style.'-suffix">'.$field['suffix'].'</span>');
	}
Scott committed
1214

1215 1216 1217 1218
	public function form_checkbox($field, $style)
	{
		$this->output('<input '.@$field['tags'].' type="checkbox" value="1"'.(@$field['value'] ? ' checked' : '').' class="qa-form-'.$style.'-checkbox"/>');
	}
Scott committed
1219

1220 1221 1222 1223
	public function form_static($field, $style)
	{
		$this->output('<span class="qa-form-'.$style.'-static">'.@$field['value'].'</span>');
	}
Scott committed
1224

1225 1226 1227 1228
	public function form_password($field, $style)
	{
		$this->output('<input '.@$field['tags'].' type="password" value="'.@$field['value'].'" class="qa-form-'.$style.'-text"/>');
	}
Scott committed
1229

1230 1231 1232 1233
	public function form_number($field, $style)
	{
		$this->output('<input '.@$field['tags'].' type="text" value="'.@$field['value'].'" class="qa-form-'.$style.'-number"/>');
	}
Scott committed
1234

1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
	/**
	 * Output a <select> element. The $field array may contain the following keys:
	 *   options: (required) a key-value array containing all the options in the select.
	 *   tags: any attributes to be added to the select.
	 *   value: the selected value from the 'options' parameter.
	 *   match_by: whether to match the 'value' (default) or 'key' of each option to determine if it is to be selected.
	 */
	public function form_select($field, $style)
	{
		$this->output('<select ' . (isset($field['tags']) ? $field['tags'] : '') . ' class="qa-form-' . $style . '-select">');

		// Only match by key if it is explicitly specified. Otherwise, for backwards compatibility, match by value
		$matchbykey = isset($field['match_by']) && $field['match_by'] === 'key';

		foreach ($field['options'] as $key => $value) {
			$selected = isset($field['value']) && (
				($matchbykey && $key === $field['value']) ||
				(!$matchbykey && $value === $field['value'])
			);
			$this->output('<option value="' . $key . '"' . ($selected ? ' selected' : '') . '>' . $value . '</option>');
Scott committed
1255 1256
		}

1257 1258
		$this->output('</select>');
	}
Scott committed
1259

1260 1261 1262
	public function form_select_radio($field, $style)
	{
		$radios = 0;
Scott committed
1263

1264 1265 1266
		foreach ($field['options'] as $tag => $value) {
			if ($radios++)
				$this->output('<br/>');
Scott committed
1267

1268
			$this->output('<input '.@$field['tags'].' type="radio" value="'.$tag.'"'.(($value == @$field['value']) ? ' checked' : '').' class="qa-form-'.$style.'-radio"/> '.$value);
Scott committed
1269
		}
1270
	}
Scott committed
1271

1272 1273 1274 1275
	public function form_image($field, $style)
	{
		$this->output('<div class="qa-form-'.$style.'-image">'.@$field['html'].'</div>');
	}
Scott committed
1276

1277 1278 1279 1280
	public function form_text_single_row($field, $style)
	{
		$this->output('<input '.@$field['tags'].' type="text" value="'.@$field['value'].'" class="qa-form-'.$style.'-text"/>');
	}
Scott committed
1281

1282 1283 1284 1285
	public function form_text_multi_row($field, $style)
	{
		$this->output('<textarea '.@$field['tags'].' rows="'.(int)$field['rows'].'" cols="40" class="qa-form-'.$style.'-text">'.@$field['value'].'</textarea>');
	}
Scott committed
1286

1287 1288 1289
	public function form_error($field, $style, $columns)
	{
		$tag = ($columns > 1) ? 'span' : 'div';
Scott committed
1290

1291 1292
		$this->output('<'.$tag.' class="qa-form-'.$style.'-error">'.$field['error'].'</'.$tag.'>');
	}
Scott committed
1293

1294 1295 1296
	public function form_note($field, $style, $columns)
	{
		$tag = ($columns > 1) ? 'span' : 'div';
Scott committed
1297

1298 1299
		$this->output('<'.$tag.' class="qa-form-'.$style.'-note">'.@$field['note'].'</'.$tag.'>');
	}
Scott committed
1300

1301 1302 1303
	public function ranking($ranking)
	{
		$this->part_title($ranking);
Scott committed
1304

1305 1306 1307
		if (!isset($ranking['type']))
			$ranking['type'] = 'items';
		$class = 'qa-top-'.$ranking['type'];
Scott committed
1308

1309 1310 1311
		if (!$this->ranking_block_layout) {
			// old, less semantic table layout
			$this->ranking_table($ranking, $class);
Scott committed
1312
		}
1313 1314 1315 1316 1317 1318
		else {
			// new block layout
			foreach ($ranking['items'] as $item) {
				$this->output('<span class="qa-ranking-item '.$class.'-item">');
				$this->ranking_item($item, $class);
				$this->output('</span>');
Scott committed
1319
			}
1320
		}
Scott committed
1321

1322 1323
		$this->part_footer($ranking);
	}
Scott committed
1324

1325 1326 1327 1328 1329 1330
	public function ranking_item($item, $class, $spacer=false) // $spacer is deprecated
	{
		if (!$this->ranking_block_layout) {
			// old table layout
			$this->ranking_table_item($item, $class, $spacer);
			return;
Scott committed
1331 1332
		}

1333 1334
		if (isset($item['count']))
			$this->ranking_count($item, $class);
Scott committed
1335

1336 1337
		if (isset($item['avatar']))
			$this->avatar($item, $class);
Scott committed
1338

1339
		$this->ranking_label($item, $class);
Scott committed
1340

1341 1342 1343
		if (isset($item['score']))
			$this->ranking_score($item, $class);
	}
Scott committed
1344

1345 1346 1347 1348 1349
	public function ranking_cell($content, $class)
	{
		$tag = $this->ranking_block_layout ? 'span': 'td';
		$this->output('<'.$tag.' class="'.$class.'">' . $content . '</'.$tag.'>');
	}
Scott committed
1350

1351 1352 1353 1354
	public function ranking_count($item, $class)
	{
		$this->ranking_cell($item['count'].' &#215;', $class.'-count');
	}
Scott committed
1355

1356 1357 1358 1359
	public function ranking_label($item, $class)
	{
		$this->ranking_cell($item['label'], $class.'-label');
	}
Scott committed
1360

1361 1362 1363 1364
	public function ranking_score($item, $class)
	{
		$this->ranking_cell($item['score'], $class.'-score');
	}
Scott committed
1365

1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385
	/**
	 * @deprecated Table-based layout of users/tags is deprecated from 1.7 onwards and may be
	 * removed in a future version. Themes can switch to the new layout by setting the member
	 * variable $ranking_block_layout to false.
	 */
	public function ranking_table($ranking, $class)
	{
		$rows = min($ranking['rows'], count($ranking['items']));

		if ($rows > 0) {
			$this->output('<table class="'.$class.'-table">');
			$columns = ceil(count($ranking['items']) / $rows);

			for ($row = 0; $row < $rows; $row++) {
				$this->set_context('ranking_row', $row);
				$this->output('<tr>');

				for ($column = 0; $column < $columns; $column++) {
					$this->set_context('ranking_column', $column);
					$this->ranking_table_item(@$ranking['items'][$column*$rows+$row], $class, $column>0);
Scott committed
1386
				}
1387 1388 1389

				$this->clear_context('ranking_column');
				$this->output('</tr>');
Scott committed
1390
			}
1391 1392
			$this->clear_context('ranking_row');
			$this->output('</table>');
Scott committed
1393
		}
1394
	}
Scott committed
1395

1396 1397 1398 1399 1400 1401 1402
	/**
	 * @deprecated See ranking_table above.
	 */
	public function ranking_table_item($item, $class, $spacer)
	{
		if ($spacer)
			$this->ranking_spacer($class);
Scott committed
1403

1404 1405 1406
		if (empty($item)) {
			$this->ranking_spacer($class);
			$this->ranking_spacer($class);
Scott committed
1407

1408 1409 1410
		} else {
			if (isset($item['count']))
				$this->ranking_count($item, $class);
Scott committed
1411

1412 1413
			if (isset($item['avatar']))
				$item['label'] = $item['avatar'].' '.$item['label'];
Scott committed
1414

1415
			$this->ranking_label($item, $class);
Scott committed
1416

1417 1418
			if (isset($item['score']))
				$this->ranking_score($item, $class);
Scott committed
1419
		}
1420
	}
Scott committed
1421

1422 1423 1424 1425 1426 1427 1428
	/**
	 * @deprecated See ranking_table above.
	 */
	public function ranking_spacer($class)
	{
		$this->output('<td class="'.$class.'-spacer">&nbsp;</td>');
	}
Scott committed
1429 1430


1431 1432 1433 1434
	public function message_list_and_form($list)
	{
		if (!empty($list)) {
			$this->part_title($list);
Scott committed
1435

1436
			$this->error(@$list['error']);
Scott committed
1437

1438 1439 1440 1441 1442
			if (!empty($list['form'])) {
				$this->output('<form '.$list['form']['tags'].'>');
				unset($list['form']['tags']); // we already output the tags before the messages
				$this->message_list_form($list);
			}
Scott committed
1443

1444
			$this->message_list($list);
Scott committed
1445

1446 1447
			if (!empty($list['form'])) {
				$this->output('</form>');
Scott committed
1448 1449
			}
		}
1450
	}
Scott committed
1451

1452 1453 1454 1455 1456 1457
	public function message_list_form($list)
	{
		if (!empty($list['form'])) {
			$this->output('<div class="qa-message-list-form">');
			$this->form($list['form']);
			$this->output('</div>');
Scott committed
1458
		}
1459
	}
Scott committed
1460

1461 1462 1463 1464
	public function message_list($list)
	{
		if (isset($list['messages'])) {
			$this->output('<div class="qa-message-list" '.@$list['tags'].'>');
Scott committed
1465

1466 1467
			foreach ($list['messages'] as $message)
				$this->message_item($message);
Scott committed
1468

1469
			$this->output('</div> <!-- END qa-message-list -->', '');
Scott committed
1470
		}
1471
	}
Scott committed
1472

1473 1474 1475 1476 1477 1478 1479 1480
	public function message_item($message)
	{
		$this->output('<div class="qa-message-item" '.@$message['tags'].'>');
		$this->message_content($message);
		$this->post_avatar_meta($message, 'qa-message');
		$this->message_buttons($message);
		$this->output('</div> <!-- END qa-message-item -->', '');
	}
Scott committed
1481

1482 1483 1484 1485 1486 1487
	public function message_content($message)
	{
		if (!empty($message['content'])) {
			$this->output('<div class="qa-message-content">');
			$this->output_raw($message['content']);
			$this->output('</div>');
Scott committed
1488
		}
1489
	}
Scott committed
1490

1491 1492 1493 1494 1495 1496
	public function message_buttons($item)
	{
		if (!empty($item['form'])) {
			$this->output('<div class="qa-message-buttons">');
			$this->form($item['form']);
			$this->output('</div>');
Scott committed
1497
		}
1498
	}
Scott committed
1499

1500 1501 1502
	public function list_vote_disabled($items)
	{
		$disabled = false;
Scott committed
1503

1504 1505
		if (count($items)) {
			$disabled = true;
Scott committed
1506

1507 1508 1509
			foreach ($items as $item) {
				if (@$item['vote_on_page'] != 'disabled')
					$disabled = false;
Scott committed
1510 1511 1512
			}
		}

1513 1514
		return $disabled;
	}
Scott committed
1515

1516 1517 1518 1519
	public function q_list_and_form($q_list)
	{
		if (empty($q_list))
			return;
Scott committed
1520

1521
		$this->part_title($q_list);
Scott committed
1522

1523 1524
		if (!empty($q_list['form']))
			$this->output('<form '.$q_list['form']['tags'].'>');
Scott committed
1525

1526
		$this->q_list($q_list);
Scott committed
1527

1528 1529 1530 1531
		if (!empty($q_list['form'])) {
			unset($q_list['form']['tags']); // we already output the tags before the qs
			$this->q_list_form($q_list);
			$this->output('</form>');
Scott committed
1532 1533
		}

1534 1535
		$this->part_footer($q_list);
	}
Scott committed
1536

1537 1538 1539 1540 1541 1542
	public function q_list_form($q_list)
	{
		if (!empty($q_list['form'])) {
			$this->output('<div class="qa-q-list-form">');
			$this->form($q_list['form']);
			$this->output('</div>');
Scott committed
1543
		}
1544
	}
Scott committed
1545

1546 1547 1548 1549 1550 1551
	public function q_list($q_list)
	{
		if (isset($q_list['qs'])) {
			$this->output('<div class="qa-q-list'.($this->list_vote_disabled($q_list['qs']) ? ' qa-q-list-vote-disabled' : '').'">', '');
			$this->q_list_items($q_list['qs']);
			$this->output('</div> <!-- END qa-q-list -->', '');
Scott committed
1552
		}
1553
	}
Scott committed
1554

1555 1556 1557 1558 1559
	public function q_list_items($q_items)
	{
		foreach ($q_items as $q_item)
			$this->q_list_item($q_item);
	}
Scott committed
1560

1561 1562 1563
	public function q_list_item($q_item)
	{
		$this->output('<div class="qa-q-list-item'.rtrim(' '.@$q_item['classes']).'" '.@$q_item['tags'].'>');
Scott committed
1564

1565 1566 1567
		$this->q_item_stats($q_item);
		$this->q_item_main($q_item);
		$this->q_item_clear();
Scott committed
1568

1569 1570
		$this->output('</div> <!-- END qa-q-list-item -->', '');
	}
Scott committed
1571

1572 1573 1574
	public function q_item_stats($q_item)
	{
		$this->output('<div class="qa-q-item-stats">');
Scott committed
1575

1576 1577
		$this->voting($q_item);
		$this->a_count($q_item);
Scott committed
1578

1579 1580 1581 1582 1583 1584
		$this->output('</div>');
	}

	public function q_item_main($q_item)
	{
		$this->output('<div class="qa-q-item-main">');
Scott committed
1585

1586 1587 1588
		$this->view_count($q_item);
		$this->q_item_title($q_item);
		$this->q_item_content($q_item);
Scott committed
1589

1590 1591 1592
		$this->post_avatar_meta($q_item, 'qa-q-item');
		$this->post_tags($q_item, 'qa-q-item');
		$this->q_item_buttons($q_item);
Scott committed
1593

1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610
		$this->output('</div>');
	}

	public function q_item_clear()
	{
		$this->output(
			'<div class="qa-q-item-clear">',
			'</div>'
		);
	}

	public function q_item_title($q_item)
	{
		$this->output(
			'<div class="qa-q-item-title">',
			'<a href="'.$q_item['url'].'">'.$q_item['title'].'</a>',
			// add closed note in title
1611
			empty($q_item['closed']['state']) ? '' : ' ['.$q_item['closed']['state'].']',
1612 1613 1614 1615 1616 1617 1618 1619 1620
			'</div>'
		);
	}

	public function q_item_content($q_item)
	{
		if (!empty($q_item['content'])) {
			$this->output('<div class="qa-q-item-content">');
			$this->output_raw($q_item['content']);
Scott committed
1621 1622
			$this->output('</div>');
		}
1623
	}
Scott committed
1624

1625 1626 1627 1628 1629 1630
	public function q_item_buttons($q_item)
	{
		if (!empty($q_item['form'])) {
			$this->output('<div class="qa-q-item-buttons">');
			$this->form($q_item['form']);
			$this->output('</div>');
Scott committed
1631
		}
1632
	}
Scott committed
1633

1634 1635 1636 1637 1638 1639
	public function voting($post)
	{
		if (isset($post['vote_view'])) {
			$this->output('<div class="qa-voting '.(($post['vote_view'] == 'updown') ? 'qa-voting-updown' : 'qa-voting-net').'" '.@$post['vote_tags'].'>');
			$this->voting_inner_html($post);
			$this->output('</div>');
Scott committed
1640
		}
1641
	}
Scott committed
1642

1643 1644 1645 1646 1647 1648
	public function voting_inner_html($post)
	{
		$this->vote_buttons($post);
		$this->vote_count($post);
		$this->vote_clear();
	}
Scott committed
1649

1650 1651 1652
	public function vote_buttons($post)
	{
		$this->output('<div class="qa-vote-buttons '.(($post['vote_view'] == 'updown') ? 'qa-vote-buttons-updown' : 'qa-vote-buttons-net').'">');
Scott committed
1653

1654
		switch (@$post['vote_state'])
Scott committed
1655
		{
1656 1657 1658
			case 'voted_up':
				$this->post_hover_button($post, 'vote_up_tags', '+', 'qa-vote-one-button qa-voted-up');
				break;
Scott committed
1659

1660 1661 1662
			case 'voted_up_disabled':
				$this->post_disabled_button($post, 'vote_up_tags', '+', 'qa-vote-one-button qa-vote-up');
				break;
Scott committed
1663

1664 1665 1666
			case 'voted_down':
				$this->post_hover_button($post, 'vote_down_tags', '&ndash;', 'qa-vote-one-button qa-voted-down');
				break;
Scott committed
1667

1668 1669 1670
			case 'voted_down_disabled':
				$this->post_disabled_button($post, 'vote_down_tags', '&ndash;', 'qa-vote-one-button qa-vote-down');
				break;
Scott committed
1671

1672 1673 1674 1675
			case 'up_only':
				$this->post_hover_button($post, 'vote_up_tags', '+', 'qa-vote-first-button qa-vote-up');
				$this->post_disabled_button($post, 'vote_down_tags', '', 'qa-vote-second-button qa-vote-down');
				break;
Scott committed
1676

1677 1678 1679 1680
			case 'enabled':
				$this->post_hover_button($post, 'vote_up_tags', '+', 'qa-vote-first-button qa-vote-up');
				$this->post_hover_button($post, 'vote_down_tags', '&ndash;', 'qa-vote-second-button qa-vote-down');
				break;
Scott committed
1681

1682 1683 1684 1685 1686
			default:
				$this->post_disabled_button($post, 'vote_up_tags', '', 'qa-vote-first-button qa-vote-up');
				$this->post_disabled_button($post, 'vote_down_tags', '', 'qa-vote-second-button qa-vote-down');
				break;
		}
Scott committed
1687

1688 1689
		$this->output('</div>');
	}
Scott committed
1690

1691 1692 1693 1694
	public function vote_count($post)
	{
		// You can also use $post['upvotes_raw'], $post['downvotes_raw'], $post['netvotes_raw'] to get
		// raw integer vote counts, for graphing or showing in other non-textual ways
Scott committed
1695

1696 1697 1698 1699 1700
		$this->output('<div class="qa-vote-count '.(($post['vote_view'] == 'updown') ? 'qa-vote-count-updown' : 'qa-vote-count-net').'"'.@$post['vote_count_tags'].'>');

		if ($post['vote_view'] == 'updown') {
			$this->output_split($post['upvotes_view'], 'qa-upvote-count');
			$this->output_split($post['downvotes_view'], 'qa-downvote-count');
Scott committed
1701 1702

		}
1703 1704
		else
			$this->output_split($post['netvotes_view'], 'qa-netvote-count');
Scott committed
1705

1706 1707
		$this->output('</div>');
	}
Scott committed
1708

1709 1710 1711 1712 1713 1714 1715
	public function vote_clear()
	{
		$this->output(
			'<div class="qa-vote-clear">',
			'</div>'
		);
	}
Scott committed
1716

1717 1718 1719
	public function a_count($post)
	{
		// You can also use $post['answers_raw'] to get a raw integer count of answers
Scott committed
1720

1721 1722 1723
		$this->output_split(@$post['answers'], 'qa-a-count', 'span', 'span',
			@$post['answer_selected'] ? 'qa-a-count-selected' : (@$post['answers_raw'] ? null : 'qa-a-count-zero'));
	}
Scott committed
1724

1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736
	public function view_count($post)
	{
		// You can also use $post['views_raw'] to get a raw integer count of views

		$this->output_split(@$post['views'], 'qa-view-count');
	}

	public function avatar($item, $class, $prefix=null)
	{
		if (isset($item['avatar'])) {
			if (isset($prefix))
				$this->output($prefix);
Scott committed
1737 1738

			$this->output(
1739 1740 1741
				'<span class="'.$class.'-avatar">',
				$item['avatar'],
				'</span>'
Scott committed
1742 1743
			);
		}
1744
	}
Scott committed
1745

1746 1747 1748
	public function a_selection($post)
	{
		$this->output('<div class="qa-a-selection">');
Scott committed
1749

1750 1751 1752 1753 1754 1755
		if (isset($post['select_tags']))
			$this->post_hover_button($post, 'select_tags', '', 'qa-a-select');
		elseif (isset($post['unselect_tags']))
			$this->post_hover_button($post, 'unselect_tags', '', 'qa-a-unselect');
		elseif ($post['selected'])
			$this->output('<div class="qa-a-selected">&nbsp;</div>');
Scott committed
1756

1757 1758
		if (isset($post['select_text']))
			$this->output('<div class="qa-a-selected-text">'.@$post['select_text'].'</div>');
Scott committed
1759

1760 1761
		$this->output('</div>');
	}
Scott committed
1762

1763 1764 1765 1766 1767
	public function post_hover_button($post, $element, $value, $class)
	{
		if (isset($post[$element]))
			$this->output('<input '.$post[$element].' type="submit" value="'.$value.'" class="'.$class.'-button"/> ');
	}
Scott committed
1768

1769 1770 1771 1772 1773
	public function post_disabled_button($post, $element, $value, $class)
	{
		if (isset($post[$element]))
			$this->output('<input '.$post[$element].' type="submit" value="'.$value.'" class="'.$class.'-disabled" disabled="disabled"/> ');
	}
Scott committed
1774

1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
	public function post_avatar_meta($post, $class, $avatarprefix=null, $metaprefix=null, $metaseparator='<br/>')
	{
		$this->output('<span class="'.$class.'-avatar-meta">');
		$this->avatar($post, $class, $avatarprefix);
		$this->post_meta($post, $class, $metaprefix, $metaseparator);
		$this->output('</span>');
	}

	/**
	 * @deprecated Deprecated from 1.7; please use avatar() instead.
	 */
	public function post_avatar($post, $class, $prefix=null)
	{
		$this->avatar($post, $class, $prefix);
	}
Scott committed
1790

1791 1792 1793
	public function post_meta($post, $class, $prefix=null, $separator='<br/>')
	{
		$this->output('<span class="'.$class.'-meta">');
Scott committed
1794

1795 1796
		if (isset($prefix))
			$this->output($prefix);
Scott committed
1797

1798
		$order = explode('^', @$post['meta_order']);
Scott committed
1799

1800 1801 1802 1803 1804
		foreach ($order as $element) {
			switch ($element) {
				case 'what':
					$this->post_meta_what($post, $class);
					break;
Scott committed
1805

1806 1807 1808
				case 'when':
					$this->post_meta_when($post, $class);
					break;
Scott committed
1809

1810 1811 1812
				case 'where':
					$this->post_meta_where($post, $class);
					break;
Scott committed
1813

1814 1815 1816 1817
				case 'who':
					$this->post_meta_who($post, $class);
					break;
			}
Scott committed
1818 1819
		}

1820
		$this->post_meta_flags($post, $class);
Scott committed
1821

1822 1823
		if (!empty($post['what_2'])) {
			$this->output($separator);
Scott committed
1824 1825 1826 1827

			foreach ($order as $element) {
				switch ($element) {
					case 'what':
1828
						$this->output('<span class="'.$class.'-what">'.$post['what_2'].'</span>');
Scott committed
1829 1830 1831
						break;

					case 'when':
1832
						$this->output_split(@$post['when_2'], $class.'-when');
Scott committed
1833 1834 1835
						break;

					case 'who':
1836
						$this->output_split(@$post['who_2'], $class.'-who');
Scott committed
1837 1838 1839 1840 1841
						break;
				}
			}
		}

1842 1843
		$this->output('</span>');
	}
Scott committed
1844

1845 1846 1847 1848 1849 1850
	public function post_meta_what($post, $class)
	{
		if (isset($post['what'])) {
			$classes = $class.'-what';
			if (@$post['what_your'])
				$classes .= ' '.$class.'-what-your';
Scott committed
1851

1852 1853 1854 1855
			if (isset($post['what_url']))
				$this->output('<a href="'.$post['what_url'].'" class="'.$classes.'">'.$post['what'].'</a>');
			else
				$this->output('<span class="'.$classes.'">'.$post['what'].'</span>');
Scott committed
1856
		}
1857
	}
Scott committed
1858

1859 1860 1861 1862
	public function post_meta_when($post, $class)
	{
		$this->output_split(@$post['when'], $class.'-when');
	}
Scott committed
1863

1864 1865 1866 1867
	public function post_meta_where($post, $class)
	{
		$this->output_split(@$post['where'], $class.'-where');
	}
Scott committed
1868

1869 1870 1871 1872
	public function post_meta_who($post, $class)
	{
		if (isset($post['who'])) {
			$this->output('<span class="'.$class.'-who">');
Scott committed
1873

1874 1875
			if (strlen(@$post['who']['prefix']))
				$this->output('<span class="'.$class.'-who-pad">'.$post['who']['prefix'].'</span>');
Scott committed
1876

1877 1878
			if (isset($post['who']['data']))
				$this->output('<span class="'.$class.'-who-data">'.$post['who']['data'].'</span>');
Scott committed
1879

1880 1881
			if (isset($post['who']['title']))
				$this->output('<span class="'.$class.'-who-title">'.$post['who']['title'].'</span>');
Scott committed
1882

1883
			// You can also use $post['level'] to get the author's privilege level (as a string)
Scott committed
1884

1885 1886 1887 1888
			if (isset($post['who']['points'])) {
				$post['who']['points']['prefix'] = '('.$post['who']['points']['prefix'];
				$post['who']['points']['suffix'] .= ')';
				$this->output_split($post['who']['points'], $class.'-who-points');
Scott committed
1889 1890
			}

1891 1892
			if (strlen(@$post['who']['suffix']))
				$this->output('<span class="'.$class.'-who-pad">'.$post['who']['suffix'].'</span>');
Scott committed
1893

1894
			$this->output('</span>');
Scott committed
1895
		}
1896
	}
Scott committed
1897

1898 1899 1900 1901
	public function post_meta_flags($post, $class)
	{
		$this->output_split(@$post['flags'], $class.'-flags');
	}
Scott committed
1902

1903 1904 1905 1906 1907 1908
	public function post_tags($post, $class)
	{
		if (!empty($post['q_tags'])) {
			$this->output('<div class="'.$class.'-tags">');
			$this->post_tag_list($post, $class);
			$this->output('</div>');
Scott committed
1909
		}
1910
	}
Scott committed
1911

1912 1913 1914
	public function post_tag_list($post, $class)
	{
		$this->output('<ul class="'.$class.'-tag-list">');
Scott committed
1915

1916 1917
		foreach ($post['q_tags'] as $taghtml)
			$this->post_tag_item($taghtml, $class);
Scott committed
1918

1919 1920
		$this->output('</ul>');
	}
Scott committed
1921

1922 1923 1924 1925
	public function post_tag_item($taghtml, $class)
	{
		$this->output('<li class="'.$class.'-tag-item">'.$taghtml.'</li>');
	}
Scott committed
1926

1927 1928 1929
	public function page_links()
	{
		$page_links = @$this->content['page_links'];
Scott committed
1930

1931 1932
		if (!empty($page_links)) {
			$this->output('<div class="qa-page-links">');
Scott committed
1933

1934 1935 1936
			$this->page_links_label(@$page_links['label']);
			$this->page_links_list(@$page_links['items']);
			$this->page_links_clear();
Scott committed
1937

1938
			$this->output('</div>');
Scott committed
1939
		}
1940
	}
Scott committed
1941

1942 1943 1944 1945 1946
	public function page_links_label($label)
	{
		if (!empty($label))
			$this->output('<span class="qa-page-links-label">'.$label.'</span>');
	}
Scott committed
1947

1948 1949 1950 1951
	public function page_links_list($page_items)
	{
		if (!empty($page_items)) {
			$this->output('<ul class="qa-page-links-list">');
Scott committed
1952

1953
			$index = 0;
Scott committed
1954

1955 1956 1957
			foreach ($page_items as $page_link) {
				$this->set_context('page_index', $index++);
				$this->page_links_item($page_link);
Scott committed
1958

1959 1960
				if ($page_link['ellipsis'])
					$this->page_links_item(array('type' => 'ellipsis'));
Scott committed
1961 1962
			}

1963
			$this->clear_context('page_index');
Scott committed
1964

1965
			$this->output('</ul>');
Scott committed
1966
		}
1967
	}
Scott committed
1968

1969 1970 1971 1972 1973 1974
	public function page_links_item($page_link)
	{
		$this->output('<li class="qa-page-links-item">');
		$this->page_link_content($page_link);
		$this->output('</li>');
	}
Scott committed
1975

1976 1977 1978 1979
	public function page_link_content($page_link)
	{
		$label = @$page_link['label'];
		$url = @$page_link['url'];
Scott committed
1980

1981 1982 1983 1984
		switch ($page_link['type']) {
			case 'this':
				$this->output('<span class="qa-page-selected">'.$label.'</span>');
				break;
Scott committed
1985

1986 1987 1988
			case 'prev':
				$this->output('<a href="'.$url.'" class="qa-page-prev">&laquo; '.$label.'</a>');
				break;
Scott committed
1989

1990 1991 1992
			case 'next':
				$this->output('<a href="'.$url.'" class="qa-page-next">'.$label.' &raquo;</a>');
				break;
Scott committed
1993

1994 1995 1996 1997 1998 1999 2000
			case 'ellipsis':
				$this->output('<span class="qa-page-ellipsis">...</span>');
				break;

			default:
				$this->output('<a href="'.$url.'" class="qa-page-link">'.$label.'</a>');
				break;
Scott committed
2001
		}
2002
	}
Scott committed
2003

2004 2005 2006 2007 2008 2009 2010
	public function page_links_clear()
	{
		$this->output(
			'<div class="qa-page-links-clear">',
			'</div>'
		);
	}
Scott committed
2011

2012 2013 2014
	public function suggest_next()
	{
		$suggest = @$this->content['suggest_next'];
Scott committed
2015

2016 2017 2018
		if (!empty($suggest)) {
			$this->output('<div class="qa-suggest-next">');
			$this->output($suggest);
Scott committed
2019 2020
			$this->output('</div>');
		}
2021
	}
Scott committed
2022

2023 2024 2025 2026
	public function q_view($q_view)
	{
		if (!empty($q_view)) {
			$this->output('<div class="qa-q-view'.(@$q_view['hidden'] ? ' qa-q-view-hidden' : '').rtrim(' '.@$q_view['classes']).'"'.rtrim(' '.@$q_view['tags']).'>');
Scott committed
2027 2028

			if (isset($q_view['main_form_tags']))
2029 2030 2031
				$this->output('<form '.$q_view['main_form_tags'].'>'); // form for voting buttons

			$this->q_view_stats($q_view);
Scott committed
2032 2033

			if (isset($q_view['main_form_tags'])) {
2034
				$this->form_hidden_elements(@$q_view['voting_form_hidden']);
Scott committed
2035 2036 2037
				$this->output('</form>');
			}

2038 2039
			$this->q_view_main($q_view);
			$this->q_view_clear();
Scott committed
2040

2041
			$this->output('</div> <!-- END qa-q-view -->', '');
Scott committed
2042
		}
2043
	}
Scott committed
2044

2045 2046 2047
	public function q_view_stats($q_view)
	{
		$this->output('<div class="qa-q-view-stats">');
Scott committed
2048

2049 2050
		$this->voting($q_view);
		$this->a_count($q_view);
Scott committed
2051

2052 2053
		$this->output('</div>');
	}
Scott committed
2054

2055 2056 2057
	public function q_view_main($q_view)
	{
		$this->output('<div class="qa-q-view-main">');
Scott committed
2058

2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074
		if (isset($q_view['main_form_tags']))
			$this->output('<form '.$q_view['main_form_tags'].'>'); // form for buttons on question

		$this->view_count($q_view);
		$this->q_view_content($q_view);
		$this->q_view_extra($q_view);
		$this->q_view_follows($q_view);
		$this->q_view_closed($q_view);
		$this->post_tags($q_view, 'qa-q-view');
		$this->post_avatar_meta($q_view, 'qa-q-view');
		$this->q_view_buttons($q_view);
		$this->c_list(@$q_view['c_list'], 'qa-q-view');

		if (isset($q_view['main_form_tags'])) {
			$this->form_hidden_elements(@$q_view['buttons_form_hidden']);
			$this->output('</form>');
Scott committed
2075 2076
		}

2077 2078 2079 2080 2081 2082 2083
		$this->c_form(@$q_view['c_form']);

		$this->output('</div> <!-- END qa-q-view-main -->');
	}

	public function q_view_content($q_view)
	{
Scott committed
2084 2085 2086 2087 2088
		$content = isset($q_view['content']) ? $q_view['content'] : '';

		$this->output('<div class="qa-q-view-content">');
		$this->output_raw($content);
		$this->output('</div>');
2089
	}
Scott committed
2090

2091 2092 2093
	public function q_view_follows($q_view)
	{
		if (!empty($q_view['follows']))
Scott committed
2094
			$this->output(
2095 2096 2097
				'<div class="qa-q-view-follows">',
				$q_view['follows']['label'],
				'<a href="'.$q_view['follows']['url'].'" class="qa-q-view-follows-link">'.$q_view['follows']['title'].'</a>',
Scott committed
2098 2099
				'</div>'
			);
2100
	}
Scott committed
2101

2102 2103 2104 2105
	public function q_view_closed($q_view)
	{
		if (!empty($q_view['closed'])) {
			$haslink = isset($q_view['closed']['url']);
Scott committed
2106

2107 2108 2109 2110 2111 2112 2113 2114
			$this->output(
				'<div class="qa-q-view-closed">',
				$q_view['closed']['label'],
				($haslink ? ('<a href="'.$q_view['closed']['url'].'"') : '<span').' class="qa-q-view-closed-content">',
				$q_view['closed']['content'],
				$haslink ? '</a>' : '</span>',
				'</div>'
			);
Scott committed
2115
		}
2116
	}
Scott committed
2117

2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128
	public function q_view_extra($q_view)
	{
		if (!empty($q_view['extra'])) {
			$this->output(
				'<div class="qa-q-view-extra">',
				$q_view['extra']['label'],
				'<span class="qa-q-view-extra-content">',
				$q_view['extra']['content'],
				'</span>',
				'</div>'
			);
Scott committed
2129
		}
2130
	}
Scott committed
2131

2132 2133 2134 2135 2136 2137
	public function q_view_buttons($q_view)
	{
		if (!empty($q_view['form'])) {
			$this->output('<div class="qa-q-view-buttons">');
			$this->form($q_view['form']);
			$this->output('</div>');
Scott committed
2138
		}
2139
	}
Scott committed
2140

2141 2142 2143 2144 2145 2146 2147
	public function q_view_clear()
	{
		$this->output(
			'<div class="qa-q-view-clear">',
			'</div>'
		);
	}
Scott committed
2148

2149 2150 2151 2152
	public function a_form($a_form)
	{
		$this->output('<div class="qa-a-form"'.(isset($a_form['id']) ? (' id="'.$a_form['id'].'"') : '').
			(@$a_form['collapse'] ? ' style="display:none;"' : '').'>');
Scott committed
2153

2154 2155
		$this->form($a_form);
		$this->c_list(@$a_form['c_list'], 'qa-a-item');
Scott committed
2156

2157 2158
		$this->output('</div> <!-- END qa-a-form -->', '');
	}
Scott committed
2159

2160 2161 2162 2163
	public function a_list($a_list)
	{
		if (!empty($a_list)) {
			$this->part_title($a_list);
Scott committed
2164

2165 2166 2167
			$this->output('<div class="qa-a-list'.($this->list_vote_disabled($a_list['as']) ? ' qa-a-list-vote-disabled' : '').'" '.@$a_list['tags'].'>', '');
			$this->a_list_items($a_list['as']);
			$this->output('</div> <!-- END qa-a-list -->', '');
Scott committed
2168
		}
2169
	}
Scott committed
2170

2171 2172 2173 2174 2175
	public function a_list_items($a_items)
	{
		foreach ($a_items as $a_item)
			$this->a_list_item($a_item);
	}
Scott committed
2176

2177 2178 2179
	public function a_list_item($a_item)
	{
		$extraclass = @$a_item['classes'].($a_item['hidden'] ? ' qa-a-list-item-hidden' : ($a_item['selected'] ? ' qa-a-list-item-selected' : ''));
Scott committed
2180

2181
		$this->output('<div class="qa-a-list-item '.$extraclass.'" '.@$a_item['tags'].'>');
Scott committed
2182

2183 2184
		if (isset($a_item['main_form_tags']))
			$this->output('<form '.$a_item['main_form_tags'].'>'); // form for voting buttons
Scott committed
2185

2186
		$this->voting($a_item);
Scott committed
2187

2188 2189 2190 2191
		if (isset($a_item['main_form_tags'])) {
			$this->form_hidden_elements(@$a_item['voting_form_hidden']);
			$this->output('</form>');
		}
Scott committed
2192

2193 2194
		$this->a_item_main($a_item);
		$this->a_item_clear();
Scott committed
2195

2196 2197
		$this->output('</div> <!-- END qa-a-list-item -->', '');
	}
Scott committed
2198

2199 2200 2201
	public function a_item_main($a_item)
	{
		$this->output('<div class="qa-a-item-main">');
Scott committed
2202

2203 2204
		if (isset($a_item['main_form_tags']))
			$this->output('<form '.$a_item['main_form_tags'].'>'); // form for buttons on answer
Scott committed
2205

2206 2207 2208 2209
		if ($a_item['hidden'])
			$this->output('<div class="qa-a-item-hidden">');
		elseif ($a_item['selected'])
			$this->output('<div class="qa-a-item-selected">');
Scott committed
2210

2211 2212 2213 2214
		$this->a_selection($a_item);
		$this->error(@$a_item['error']);
		$this->a_item_content($a_item);
		$this->post_avatar_meta($a_item, 'qa-a-item');
Scott committed
2215

2216 2217
		if ($a_item['hidden'] || $a_item['selected'])
			$this->output('</div>');
Scott committed
2218

2219
		$this->a_item_buttons($a_item);
Scott committed
2220

2221
		$this->c_list(@$a_item['c_list'], 'qa-a-item');
Scott committed
2222

2223 2224 2225
		if (isset($a_item['main_form_tags'])) {
			$this->form_hidden_elements(@$a_item['buttons_form_hidden']);
			$this->output('</form>');
Scott committed
2226 2227
		}

2228
		$this->c_form(@$a_item['c_form']);
Scott committed
2229

2230 2231
		$this->output('</div> <!-- END qa-a-item-main -->');
	}
Scott committed
2232

2233 2234 2235 2236 2237 2238 2239
	public function a_item_clear()
	{
		$this->output(
			'<div class="qa-a-item-clear">',
			'</div>'
		);
	}
Scott committed
2240

2241 2242 2243 2244 2245 2246
	public function a_item_content($a_item)
	{
		$this->output('<div class="qa-a-item-content">');
		$this->output_raw($a_item['content']);
		$this->output('</div>');
	}
Scott committed
2247

2248 2249 2250 2251 2252 2253
	public function a_item_buttons($a_item)
	{
		if (!empty($a_item['form'])) {
			$this->output('<div class="qa-a-item-buttons">');
			$this->form($a_item['form']);
			$this->output('</div>');
Scott committed
2254
		}
2255
	}
Scott committed
2256

2257 2258 2259 2260
	public function c_form($c_form)
	{
		$this->output('<div class="qa-c-form"'.(isset($c_form['id']) ? (' id="'.$c_form['id'].'"') : '').
			(@$c_form['collapse'] ? ' style="display:none;"' : '').'>');
Scott committed
2261

2262
		$this->form($c_form);
Scott committed
2263

2264 2265
		$this->output('</div> <!-- END qa-c-form -->', '');
	}
Scott committed
2266

2267 2268 2269 2270 2271 2272
	public function c_list($c_list, $class)
	{
		if (!empty($c_list)) {
			$this->output('', '<div class="'.$class.'-c-list"'.(@$c_list['hidden'] ? ' style="display:none;"' : '').' '.@$c_list['tags'].'>');
			$this->c_list_items($c_list['cs']);
			$this->output('</div> <!-- END qa-c-list -->', '');
Scott committed
2273
		}
2274
	}
Scott committed
2275

2276 2277 2278 2279 2280
	public function c_list_items($c_items)
	{
		foreach ($c_items as $c_item)
			$this->c_list_item($c_item);
	}
Scott committed
2281

2282 2283 2284
	public function c_list_item($c_item)
	{
		$extraclass = @$c_item['classes'].(@$c_item['hidden'] ? ' qa-c-item-hidden' : '');
Scott committed
2285

2286
		$this->output('<div class="qa-c-list-item '.$extraclass.'" '.@$c_item['tags'].'>');
Scott committed
2287

2288 2289
		$this->c_item_main($c_item);
		$this->c_item_clear();
Scott committed
2290

2291 2292
		$this->output('</div> <!-- END qa-c-item -->');
	}
Scott committed
2293

2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309
	public function c_item_main($c_item)
	{
		$this->error(@$c_item['error']);

		if (isset($c_item['expand_tags']))
			$this->c_item_expand($c_item);
		elseif (isset($c_item['url']))
			$this->c_item_link($c_item);
		else
			$this->c_item_content($c_item);

		$this->output('<div class="qa-c-item-footer">');
		$this->post_avatar_meta($c_item, 'qa-c-item');
		$this->c_item_buttons($c_item);
		$this->output('</div>');
	}
Scott committed
2310

2311 2312 2313 2314 2315 2316
	public function c_item_link($c_item)
	{
		$this->output(
			'<a href="'.$c_item['url'].'" class="qa-c-item-link">'.$c_item['title'].'</a>'
		);
	}
Scott committed
2317

2318 2319 2320 2321 2322 2323
	public function c_item_expand($c_item)
	{
		$this->output(
			'<a href="'.$c_item['url'].'" '.$c_item['expand_tags'].' class="qa-c-item-expand">'.$c_item['title'].'</a>'
		);
	}
Scott committed
2324

2325 2326 2327 2328 2329 2330
	public function c_item_content($c_item)
	{
		$this->output('<div class="qa-c-item-content">');
		$this->output_raw($c_item['content']);
		$this->output('</div>');
	}
Scott committed
2331

2332 2333 2334 2335 2336
	public function c_item_buttons($c_item)
	{
		if (!empty($c_item['form'])) {
			$this->output('<div class="qa-c-item-buttons">');
			$this->form($c_item['form']);
Scott committed
2337 2338 2339 2340
			$this->output('</div>');
		}
	}

2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364
	public function c_item_clear()
	{
		$this->output(
			'<div class="qa-c-item-clear">',
			'</div>'
		);
	}


	public function q_title_list($q_list, $attrs=null)
/*
	Generic method to output a basic list of question links.
*/
	{
		$this->output('<ul class="qa-q-title-list">');
		foreach ($q_list as $q) {
			$this->output(
				'<li class="qa-q-title-item">',
				'<a href="' . qa_q_path_html($q['postid'], $q['title']) . '" ' . $attrs . '>' . qa_html($q['title']) . '</a>',
				'</li>'
			);
		}
		$this->output('</ul>');
	}
Scott committed
2365

2366
	public function q_ask_similar($q_list, $pretext='')
Scott committed
2367
/*
2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382
	Output block of similar questions when asking.
*/
	{
		if (!count($q_list))
			return;

		$this->output('<div class="qa-ask-similar">');

		if (strlen($pretext) > 0)
			$this->output('<p class="qa-ask-similar-title">'.$pretext.'</p>');
		$this->q_title_list($q_list, 'target="_blank"');

		$this->output('</div>');
	}
}