qa-theme.php 19.8 KB
Newer Older
Scott committed
1 2
<?php
/*
3 4 5
	Snow Theme for Question2Answer Package
	Copyright (C) 2014 Q2A Market <http://www.q2amarket.com>

Scott committed
6 7 8
	File:           qa-theme.php
	Version:        Snow 1.4
	Description:    Q2A theme class
9 10 11 12 13 14 15 16 17 18

	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 3 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.
Scott committed
19
*/
Scott committed
20 21

/**
22
 * Snow theme HTML customizations
Scott committed
23 24 25 26 27 28 29
 *
 * @author Q2A Market <http://www.q2amarket.com>
 * @copyright (c) 2014, Q2A Market
 * @license http://www.gnu.org/copyleft/gpl.html
 */
class qa_html_theme extends qa_html_theme_base
{
30 31
	protected $theme = 'snowflat';

32 33 34
	// use local font files instead of Google Fonts
	private $localfonts = true;

pupi1985 committed
35
	// theme subdirectories
36 37
	private $js_dir = 'js';
	private $icon_url = 'images/icons';
38 39

	private $fixed_topbar = false;
40
	private $welcome_widget_class = 'wet-asphalt';
41
	private $ask_search_box_class = 'turquoise';
42
	// Size of the user avatar in the navigation bar
43
	private $nav_bar_avatar_size = 52;
44

45
	// use new block layout in rankings
46 47
	protected $ranking_block_layout = true;

Scott committed
48 49 50 51 52
	/**
	 * Adding aditional meta for responsive design
	 */
	public function head_metas()
	{
Scott committed
53
		$this->output('<meta name="viewport" content="width=device-width, initial-scale=1"/>');
54
		parent::head_metas();
Scott committed
55 56 57 58 59 60 61
	}

	/**
	 * Adding theme stylesheets
	 */
	public function head_css()
	{
62
		// add RTL CSS file
63
		if ($this->isRTL)
Scott committed
64
			$this->content['css_src'][] = $this->rooturl . 'qa-styles-rtl.css?' . QA_VERSION;
65

66 67 68
		if ($this->localfonts) {
			// add Ubuntu font locally (inlined for speed)
			$this->output_array(array(
Scott committed
69 70
				"<style>",
				"@font-face {",
Félicie committed
71
				" font-family: "Roboto","Lucida Grande","DejaVu Sans","Bitstream Vera Sans",Verdana,Arial,sans-serif; font-weight: normal; font-style: normal;",
Scott committed
72 73 74 75
				" src: local('Ubuntu'),",
				"  url('{$this->rooturl}fonts/ubuntu-regular.woff2') format('woff2'), url('{$this->rooturl}fonts/ubuntu-regular.woff') format('woff');",
				"}",
				"@font-face {",
Félicie committed
76
				" font-family: "Roboto","Lucida Grande","DejaVu Sans","Bitstream Vera Sans",Verdana,Arial,sans-serif; font-weight: bold; font-style: normal;",
Scott committed
77 78 79 80
				" src: local('Ubuntu Bold'), local('Ubuntu-Bold'),",
				"  url('{$this->rooturl}fonts/ubuntu-bold.woff2') format('woff2'), url('{$this->rooturl}fonts/ubuntu-bold.woff') format('woff');",
				"}",
				"@font-face {",
Félicie committed
81
				" font-family: "Roboto","Lucida Grande","DejaVu Sans","Bitstream Vera Sans",Verdana,Arial,sans-serif; font-weight: normal; font-style: italic;",
Scott committed
82 83 84 85
				" src: local('Ubuntu Italic'), local('Ubuntu-Italic'),",
				"  url('{$this->rooturl}fonts/ubuntu-italic.woff2') format('woff2'), url('{$this->rooturl}fonts/ubuntu-italic.woff') format('woff');",
				"}",
				"@font-face {",
Félicie committed
86
				" font-family: "Roboto","Lucida Grande","DejaVu Sans","Bitstream Vera Sans",Verdana,Arial,sans-serif; font-weight: bold; font-style: italic;",
Scott committed
87 88 89 90
				" src: local('Ubuntu Bold Italic'), local('Ubuntu-BoldItalic'),",
				"  url('{$this->rooturl}fonts/ubuntu-bold-italic.woff2') format('woff2'), url('{$this->rooturl}fonts/ubuntu-bold-italic.woff') format('woff');",
				"}",
				"</style>",
91 92 93 94 95 96
			));
		}
		else {
			// add Ubuntu font CSS file from Google Fonts
			$this->content['css_src'][] = 'https://fonts.googleapis.com/css?family=Ubuntu:400,400i,700,700i';
		}
Scott committed
97

98
		parent::head_css();
Scott committed
99 100

		// output some dynamic CSS inline
101
		$this->head_inline_css();
Scott committed
102 103 104 105 106 107 108
	}

	/**
	 * Adding theme javascripts
	 */
	public function head_script()
	{
109
		$jsUrl = $this->rooturl . $this->js_dir . '/snow-core.js?' . QA_VERSION;
Scott committed
110 111
		$this->content['script'][] = '<script src="' . $jsUrl . '"></script>';

112
		parent::head_script();
Scott committed
113 114 115 116 117 118 119
	}

	/**
	 * Adding point count for logged in user
	 */
	public function logged_in()
	{
120
		parent::logged_in();
121 122 123 124
		if (qa_is_logged_in()) {
			$userpoints = qa_get_logged_in_points();
			$pointshtml = $userpoints == 1
				? qa_lang_html_sub('main/1_point', '1', '1')
Scott committed
125
				: qa_html(qa_format_number($userpoints))
126 127 128
			;
			$this->output('<div class="qam-logged-in-points">' . $pointshtml . '</div>');
		}
Scott committed
129 130 131
	}

	/**
132
	 * Adding body class dynamically. Override needed to add class on admin/approve-users page
Scott committed
133 134 135 136
	 */
	public function body_tags()
	{
		$class = 'qa-template-' . qa_html($this->template);
137
		$class .= empty($this->theme) ? '' : ' qa-theme-' . qa_html($this->theme);
Scott committed
138 139

		if (isset($this->content['categoryids'])) {
Scott committed
140
			foreach ($this->content['categoryids'] as $categoryid) {
Scott committed
141
				$class .= ' qa-category-' . qa_html($categoryid);
Scott committed
142
			}
Scott committed
143 144
		}

Scott committed
145
		// add class if admin/approve-users page
146
		if ($this->template === 'admin' && qa_request_part(1) === 'approve')
Scott committed
147 148
			$class .= ' qam-approve-users';

149 150
		if ($this->fixed_topbar)
			$class .= ' qam-body-fixed';
Scott committed
151 152 153 154 155

		$this->output('class="' . $class . ' qa-body-js-off"');
	}

	/**
156
	 * Login form for user dropdown menu.
Scott committed
157 158 159 160 161 162
	 */
	public function nav_user_search()
	{
		// outputs login form if user not logged in
		$this->output('<div class="qam-account-items-wrapper">');

Scott committed
163
		$this->qam_user_account();
Scott committed
164 165 166 167

		$this->output('<div class="qam-account-items clearfix">');

		if (!qa_is_logged_in()) {
168 169
			if (isset($this->content['navigation']['user']['login']) && !QA_FINAL_EXTERNAL_USERS) {
				$login = $this->content['navigation']['user']['login'];
170 171
				$emailOnly = qa_opt('allow_login_email_only');
				$inputType = $emailOnly ? 'email' : 'text';
Scott committed
172
				$this->output(
173
					'<form action="' . $login['url'] . '" method="post">',
174
						'<input type="' . $inputType . '" name="emailhandle" dir="auto" placeholder="' . trim(qa_lang_html($emailOnly ? 'users/email_label' : 'users/email_handle_label'), ':') . '"/>',
Scott committed
175 176
						'<input type="password" name="password" dir="auto" placeholder="' . trim(qa_lang_html('users/password_label'), ':') . '"/>',
						'<div><input type="checkbox" name="remember" id="qam-rememberme" value="1"/>',
177
						'<label for="qam-rememberme">' . qa_lang_html('users/remember') . '</label></div>',
Scott committed
178 179
						'<input type="hidden" name="code" value="' . qa_html(qa_get_form_security_code('login')) . '"/>',
						'<input type="submit" value="' . $login['label'] . '" class="qa-form-tall-button qa-form-tall-button-login" name="dologin"/>',
180
					'</form>'
Scott committed
181
				);
182 183 184

				// remove regular navigation link to log in page
				unset($this->content['navigation']['user']['login']);
Scott committed
185 186 187
			}
		}

188
		$this->nav('user');
Scott committed
189 190 191 192 193
		$this->output('</div> <!-- END qam-account-items -->');
		$this->output('</div> <!-- END qam-account-items-wrapper -->');
	}

	/**
194
	 * Modify markup for topbar.
Scott committed
195 196 197 198 199
	 */
	public function nav_main_sub()
	{
		$this->output('<div class="qam-main-nav-wrapper clearfix">');
		$this->output('<div class="sb-toggle-left qam-menu-toggle"><i class="icon-th-list"></i></div>');
Scott committed
200
		$this->nav_user_search();
Scott committed
201 202 203 204 205 206 207
		$this->logo();
		$this->nav('main');
		$this->output('</div> <!-- END qam-main-nav-wrapper -->');
		$this->nav('sub');
	}

	/**
208
	 * Remove the '-' from the note for the category page (notes).
209 210
	 * @param array $navlink
	 * @param string $class
Scott committed
211 212 213
	 */
	public function nav_link($navlink, $class)
	{
214
		if (isset($navlink['note']) && !empty($navlink['note'])) {
215
			$search = array(' - <', '> - ');
Scott committed
216
			$replace = array(' <', '> ');
217
			$navlink['note'] = str_replace($search, $replace, $navlink['note']);
Scott committed
218
		}
219
		parent::nav_link($navlink, $class);
Scott committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
	}

	/**
	 * Rearranges the layout:
	 * - Swaps the <tt>main()</tt> and <tt>sidepanel()</tt> functions
	 * - Moves the header and footer functions outside qa-body-wrapper
	 * - Keeps top/high and low/bottom widgets separated
	 */
	public function body_content()
	{
		$this->body_prefix();
		$this->notices();

		$this->widgets('full', 'top');
		$this->header();

236 237
		$extratags = isset($this->content['wrapper_tags']) ? $this->content['wrapper_tags'] : '';
		$this->output('<div class="qa-body-wrapper"' . $extratags . '>', '');
Scott committed
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
		$this->widgets('full', 'high');

		$this->output('<div class="qa-main-wrapper">', '');
		$this->main();
		$this->sidepanel();
		$this->output('</div> <!-- END main-wrapper -->');

		$this->widgets('full', 'low');
		$this->output('</div> <!-- END body-wrapper -->');

		$this->footer();

		$this->body_suffix();
	}

	/**
	 * Header in full width top bar
	 */
	public function header()
	{
258
		$class = $this->fixed_topbar ? ' fixed' : '';
Scott committed
259

Scott committed
260 261
		$this->output('<div id="qam-topbar" class="clearfix' . $class . '">');

Scott committed
262
		$this->nav_main_sub();
263
		$this->output('</div> <!-- END qam-topbar -->');
Scott committed
264

265
		$this->output($this->ask_button());
Scott committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279
		$this->qam_search('the-top', 'the-top-search');
	}

	/**
	 * Footer in full width bottom bar
	 */
	public function footer()
	{
		$this->output('<div class="qam-footer-box">');

		$this->output('<div class="qam-footer-row">');
		$this->widgets('full', 'bottom');
		$this->output('</div> <!-- END qam-footer-row -->');

280
		parent::footer();
281
		$this->output('</div> <!-- END qam-footer-box -->');
Scott committed
282 283
	}

284 285 286 287 288 289 290 291 292 293 294 295 296 297
	/**
	 * Adds placeholder "Search..." for search box
	 */
	public function search_field($search)
	{
		$this->output(
			sprintf('<input type="text" placeholder="%s..." %s value="%s" class="qa-search-field"/>',
				$search['button_label'],
				$search['field_tags'],
				isset($search['value']) ? $search['value'] : ''
			)
		);
	}

Scott committed
298 299 300 301 302
	/**
	 * Overridden to customize layout and styling
	 */
	public function sidepanel()
	{
303 304 305 306 307
		// remove sidebar for user profile pages
		if ($this->template == 'user')
			return;

		$this->output('<div id="qam-sidepanel-toggle"><i class="icon-left-open-big"></i></div>');
Félicie committed
308
		// $this->output('<div class="qa-sidepanel" id="qam-sidepanel-mobile">');
309 310 311 312 313
		$this->qam_search();
		$this->widgets('side', 'top');
		$this->sidebar();
		$this->widgets('side', 'high');
		$this->widgets('side', 'low');
Félicie committed
314 315
		// if (isset($this->content['sidepanel']))
		// 	$this->output_raw($this->content['sidepanel']);
316 317
		$this->feed();
		$this->widgets('side', 'bottom');
Félicie committed
318
		// $this->output('</div> <!-- qa-sidepanel -->', '');
Scott committed
319 320 321
	}

	/**
322
	 * Allow alternate sidebar color.
Scott committed
323 324 325
	 */
	public function sidebar()
	{
326 327 328
		if (isset($this->content['sidebar'])) {
			$sidebar = $this->content['sidebar'];
			if (!empty($sidebar)) {
329
				$this->output('<div class="qa-sidebar ' . $this->welcome_widget_class . '">');
330
				$this->output_raw($sidebar);
331
				$this->output('</div> <!-- qa-sidebar -->', '');
332
			}
Scott committed
333 334 335 336
		}
	}

	/**
337
	 * Add close icon
Scott committed
338 339 340 341
	 * @param array $q_item
	 */
	public function q_item_title($q_item)
	{
pupi1985 committed
342
		$closedText = qa_lang('main/closed');
343 344
		$imgHtml = empty($q_item['closed'])
			? ''
Scott committed
345
			: '<img src="' . $this->rooturl . $this->icon_url . '/closed-q-list.png" class="qam-q-list-close-icon" alt="' . $closedText . '" title="' . $closedText . '"/>';
346

Scott committed
347
		$this->output(
348 349 350 351 352
			'<div class="qa-q-item-title">',
			// add closed note in title
			$imgHtml,
			'<a href="' . $q_item['url'] . '">' . $q_item['title'] . '</a>',
			'</div>'
Scott committed
353 354 355 356
		);
	}

	/**
357
	 * Add RSS feeds icon
Scott committed
358
	 */
359
	public function favorite()
Scott committed
360
	{
361
		parent::favorite();
Scott committed
362

Scott committed
363
		// RSS feed link in title
364 365 366 367
		if (isset($this->content['feed']['url'])) {
			$feed = $this->content['feed'];
			$label = isset($feed['label']) ? $feed['label'] : '';
			$this->output('<a href="' . $feed['url'] . '" title="' . $label . '"><i class="icon-rss qam-title-rss"></i></a>');
Scott committed
368
		}
369 370 371 372 373 374 375 376
	}

	/**
	 * Add closed icon for closed questions
	 */
	public function title()
	{
		$q_view = isset($this->content['q_view']) ? $this->content['q_view'] : null;
Scott committed
377

Scott committed
378 379 380 381
		// link title where appropriate
		$url = isset($q_view['url']) ? $q_view['url'] : false;

		// add closed image
pupi1985 committed
382
		$closedText = qa_lang('main/closed');
383 384
		$imgHtml = empty($q_view['closed'])
			? ''
Scott committed
385
			: '<img src="' . $this->rooturl . $this->icon_url . '/closed-q-view.png" class="qam-q-view-close-icon" alt="' . $closedText . '" width="24" height="24" title="' . $closedText . '"/>';
386

Scott committed
387 388
		if (isset($this->content['title'])) {
			$this->output(
389 390 391 392
				$imgHtml,
				$url ? '<a href="' . $url . '">' : '',
				$this->content['title'],
				$url ? '</a>' : ''
Scott committed
393 394 395 396 397
			);
		}
	}

	/**
398
	 * Add view counter to question list
Scott committed
399 400 401
	 * @param array $q_item
	 */
	public function q_item_stats($q_item)
402
	{
Scott committed
403 404 405 406
		$this->output('<div class="qa-q-item-stats">');

		$this->voting($q_item);
		$this->a_count($q_item);
407
		parent::view_count($q_item);
Scott committed
408 409 410 411 412 413

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

	/**
	 * Prevent display view counter on usual place
414
	 * @param array $q_item
Scott committed
415
	 */
416 417 418 419
	public function view_count($q_item)
	{
		// do nothing
	}
Scott committed
420 421

	/**
422
	 * Add view counter to question view
423
	 * @param array $q_view
Scott committed
424 425 426 427 428 429 430
	 */
	public function q_view_stats($q_view)
	{
		$this->output('<div class="qa-q-view-stats">');

		$this->voting($q_view);
		$this->a_count($q_view);
431
		parent::view_count($q_view);
Scott committed
432 433 434 435 436

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

	/**
437
	 * Modify user whometa, move to top
438
	 * @param array $q_view
Scott committed
439 440 441 442 443
	 */
	public function q_view_main($q_view)
	{
		$this->output('<div class="qa-q-view-main">');

444
		if (isset($q_view['main_form_tags'])) {
Scott committed
445
			$this->output('<form ' . $q_view['main_form_tags'] . '>'); // form for buttons on question
446
		}
Scott committed
447 448 449 450 451 452 453 454 455 456 457

		$this->post_avatar_meta($q_view, 'qa-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->q_view_buttons($q_view);

		if (isset($q_view['main_form_tags'])) {
458 459
			if (isset($q_view['buttons_form_hidden']))
				$this->form_hidden_elements($q_view['buttons_form_hidden']);
Scott committed
460 461 462
			$this->output('</form>');
		}

463
		$this->c_list(isset($q_view['c_list']) ? $q_view['c_list'] : null, 'qa-q-view');
464
		$this->c_form(isset($q_view['c_form']) ? $q_view['c_form'] : null);
Scott committed
465 466 467 468

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

469 470 471 472 473 474
	/**
	 * Hide votes when zero
	 * @param  array $post
	 */
	public function vote_count($post)
	{
475
		if ($post['raw']['basetype'] === 'C' && $post['raw']['netvotes'] == 0) {
476 477 478 479 480 481
			$post['netvotes_view']['data'] = '';
		}

		parent::vote_count($post);
	}

Scott committed
482
	/**
483
	 * Move user whometa to top in answer
484
	 * @param array $a_item
Scott committed
485 486 487 488 489
	 */
	public function a_item_main($a_item)
	{
		$this->output('<div class="qa-a-item-main">');

490
		if (isset($a_item['main_form_tags'])) {
Scott committed
491
			$this->output('<form ' . $a_item['main_form_tags'] . '>'); // form for buttons on answer
492 493 494
		}

		$this->post_avatar_meta($a_item, 'qa-a-item');
Scott committed
495 496

		if ($a_item['hidden'])
497
			$this->output('<div class="qa-a-item-hidden">');
Scott committed
498
		elseif ($a_item['selected'])
499
			$this->output('<div class="qa-a-item-selected">');
Scott committed
500 501

		$this->a_selection($a_item);
502 503
		if (isset($a_item['error']))
			$this->error($a_item['error']);
Scott committed
504 505
		$this->a_item_content($a_item);

506
		if ($a_item['hidden'] || $a_item['selected'])
Scott committed
507 508 509 510 511
			$this->output('</div>');

		$this->a_item_buttons($a_item);

		if (isset($a_item['main_form_tags'])) {
512 513
			if (isset($a_item['buttons_form_hidden']))
				$this->form_hidden_elements($a_item['buttons_form_hidden']);
Scott committed
514 515 516
			$this->output('</form>');
		}

517
		$this->c_list(isset($a_item['c_list']) ? $a_item['c_list'] : null, 'qa-a-item');
518
		$this->c_form(isset($a_item['c_form']) ? $a_item['c_form'] : null);
Scott committed
519 520 521 522

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

523
	/**
524
	 * Remove comment voting here
525 526 527 528 529 530 531 532 533 534 535 536 537 538
	 * @param array $c_item
	 */
	public function c_list_item($c_item)
	{
		$extraclass = @$c_item['classes'] . (@$c_item['hidden'] ? ' qa-c-item-hidden' : '');

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

		$this->c_item_main($c_item);
		$this->c_item_clear();

		$this->output('</div> <!-- END qa-c-item -->');
	}

Scott committed
539
	/**
540
	 * Move user whometa to top in comment, add comment voting back in
541
	 * @param array $c_item
Scott committed
542 543 544 545 546
	 */
	public function c_item_main($c_item)
	{
		$this->post_avatar_meta($c_item, 'qa-c-item');

547 548
		if (isset($c_item['error']))
			$this->error($c_item['error']);
Scott committed
549

550 551 552 553
		if (isset($c_item['main_form_tags'])) {
			$this->output('<form ' . $c_item['main_form_tags'] . '>'); // form for comment voting buttons
		}

554 555
		$this->voting($c_item);

556 557 558 559 560 561 562 563 564
		if (isset($c_item['main_form_tags'])) {
			$this->form_hidden_elements(@$c_item['voting_form_hidden']);
			$this->output('</form>');
		}

		if (isset($c_item['main_form_tags'])) {
			$this->output('<form ' . $c_item['main_form_tags'] . '>'); // form for buttons on comment
		}

Scott committed
565 566 567 568 569 570 571 572 573 574
		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->c_item_buttons($c_item);
		$this->output('</div>');
575 576 577 578 579

		if (isset($c_item['main_form_tags'])) {
			$this->form_hidden_elements(@$c_item['buttons_form_hidden']);
			$this->output('</form>');
		}
Scott committed
580 581 582 583 584 585 586 587 588 589 590 591 592 593
	}

	/**
	 * Q2A Market attribution.
	 * I'd really appreciate you displaying this link on your Q2A site. Thank you - Jatin
	 */
	public function attribution()
	{
		// floated right
		$this->output(
			'<div class="qa-attribution">',
			'Snow Theme by <a href="http://www.q2amarket.com">Q2A Market</a>',
			'</div>'
		);
594
		parent::attribution();
Scott committed
595 596
	}

Scott committed
597 598 599 600 601 602 603 604
	/**
	 * User account navigation item. This will return based on login information.
	 * If user is logged in, it will populate user avatar and account links.
	 * If user is guest, it will populate login form and registration link.
	 */
	private function qam_user_account()
	{
		if (qa_is_logged_in()) {
605
			// get logged-in user avatar
Scott committed
606 607 608
			$handle = qa_get_logged_in_user_field('handle');
			$toggleClass = 'qam-logged-in';

609
			if (QA_FINAL_EXTERNAL_USERS)
610
				$tobar_avatar = qa_get_external_avatar_html(qa_get_logged_in_user_field('userid'), $this->nav_bar_avatar_size, true);
Scott committed
611 612 613 614 615 616 617 618
			else {
				$tobar_avatar = qa_get_user_avatar_html(
					qa_get_logged_in_user_field('flags'),
					qa_get_logged_in_user_field('email'),
					$handle,
					qa_get_logged_in_user_field('avatarblobid'),
					qa_get_logged_in_user_field('avatarwidth'),
					qa_get_logged_in_user_field('avatarheight'),
619
					$this->nav_bar_avatar_size,
Scott committed
620 621 622 623
					false
				);
			}

624 625 626
			$avatar = strip_tags($tobar_avatar, '<img>');
			if (!empty($avatar))
				$handle = '';
627
		}
628 629
		else {
			// display login icon and label
Scott committed
630 631
			$handle = $this->content['navigation']['user']['login']['label'];
			$toggleClass = 'qam-logged-out';
632
			$avatar = '<i class="icon-key qam-auth-key"></i>';
Scott committed
633 634 635
		}

		// finally output avatar with div tag
636
		$handleBlock = empty($handle) ? '' : '<div class="qam-account-handle">' . qa_html($handle) . '</div>';
Scott committed
637 638
		$this->output(
			'<div id="qam-account-toggle" class="' . $toggleClass . '">',
639 640
			$avatar,
			$handleBlock,
Scott committed
641 642 643 644
			'</div>'
		);
	}

Scott committed
645
	/**
646
	 * Add search-box wrapper with extra class for color scheme
Scott committed
647 648
	 * @param string $addon_class
	 * @param string $ids
Scott committed
649
	 */
pupi1985 committed
650
	private function qam_search($addon_class = null, $ids = null)
Scott committed
651
	{
pupi1985 committed
652
		$id = isset($ids) ? ' id="' . $ids . '"' : '';
Scott committed
653

pupi1985 committed
654
		$this->output('<div class="qam-search ' . $this->ask_search_box_class . ' ' . $addon_class . '"' . $id . '>');
655
		$this->search();
Scott committed
656 657 658 659 660
		$this->output('</div>');
	}


	/**
661
	 * Dynamic CSS based on options and other interaction with Q2A.
Scott committed
662 663 664 665
	 * @return string The CSS code
	 */
	private function head_inline_css()
	{
Scott committed
666 667
		$css = array('<style>');

668
		if (!qa_is_logged_in())
Scott committed
669
			$css[] = '.qa-nav-user { margin: 0 !important; }';
Scott committed
670 671

		if (qa_request_part(1) !== qa_get_logged_in_handle()) {
Scott committed
672 673 674 675 676 677 678
			$css[] = '@media (max-width: 979px) {';
			$css[] = ' body.qa-template-user.fixed, body[class*="qa-template-user-"].fixed { padding-top: 118px !important; }';
			$css[] = ' body.qa-template-users.fixed { padding-top: 95px !important; }';
			$css[] = '}';
			$css[] = '@media (min-width: 980px) {';
			$css[] = ' body.qa-template-users.fixed { padding-top: 105px !important;}';
			$css[] = '}';
Scott committed
679
		}
680

Scott committed
681 682 683
		$css[] = '</style>';

		$this->output_array($css);
Scott committed
684 685
	}

686 687 688 689 690 691
	/**
	 * Custom ask button for medium and small screen
	 * @return string Ask button html markup
	 */
	private function ask_button()
	{
692 693 694 695 696 697 698 699 700
		return
			'<div class="qam-ask-search-box">' .
			'<div class="qam-ask-mobile">' .
			'<a href="' . qa_path('ask', null, qa_path_to_root()) . '" class="' . $this->ask_search_box_class . '">' .
			qa_lang_html('main/nav_ask') .
			'</a>' .
			'</div>' .
			'<div class="qam-search-mobile ' . $this->ask_search_box_class . '" id="qam-search-mobile">' .
			'</div>' .
701
			'</div>';
702
	}
Scott committed
703
}