-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqa-theme-base.php
2547 lines (2049 loc) · 67.4 KB
/
qa-theme-base.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
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
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../');
exit;
}
/*
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.
*/
class qa_html_theme_base
{
public $template;
public $content;
public $rooturl;
public $request;
public $isRTL; // (boolean) whether text direction is Right-To-Left
protected $minifyHtml; // (boolean) whether to indent the HTML
protected $indent = 0;
protected $lines = 0;
protected $context = array();
// whether to use new block layout in rankings (true) or fall back to tables (false)
protected $ranking_block_layout = false;
// theme 'slug' to use as CSS class
protected $theme;
/**
* Initialize the object and assign local variables.
* @param $template
* @param $content
* @param $rooturl
* @param $request
*/
public function __construct($template, $content, $rooturl, $request)
{
/**
* 410 response handler
* get current full url
* fetch users inserted urls and expode into urls array
* check if current url exsit in users 410 urls response 410 and exit
*/
if (qa_opt('qa410_urls')){
$actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$urls=explode(",",qa_html(qa_opt('qa410_urls')));
foreach ($urls as $key => $value) {
if ($actual_link==trim($value)){
header("HTTP/1.0 410 Gone");
}
}
}
$this->template = $template;
$this->content = $content;
$this->rooturl = $rooturl;
$this->request = $request;
$this->isRTL = isset($content['direction']) && $content['direction'] === 'rtl';
$this->minifyHtml = !empty($content['options']['minify_html']);
}
/**
* @deprecated PHP4-style constructor deprecated from 1.7; please use proper `__construct`
* function instead.
* @param $template
* @param $content
* @param $rooturl
* @param $request
*/
public function qa_html_theme_base($template, $content, $rooturl, $request)
{
self::__construct($template, $content, $rooturl, $request);
}
/**
* 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.
* @param $elements
*/
public function output_array($elements)
{
foreach ($elements as $element) {
$line = str_replace('/>', '>', $element);
if ($this->minifyHtml) {
if (strlen($line))
echo $line . "\n";
} else {
$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)) . $line . "\n";
if ($delta > 0) {
$this->indent += $delta;
}
}
$this->lines++;
}
}
/**
* Output each passed parameter on a separate line - see output_array() comments.
*/
public function output() // other parameters picked up via func_get_args()
{
$args = func_get_args();
$this->output_array($args);
}
/**
* 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.
* @param $html
*/
public function output_raw($html)
{
if (strlen($html))
echo str_repeat("\t", max(0, $this->indent)) . $html . "\n";
}
/**
* 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.
* @param $parts
* @param $class
* @param string $outertag
* @param string $innertag
* @param string $extraclass
*/
public function output_split($parts, $class, $outertag = 'span', $innertag = 'span', $extraclass = null)
{
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 . '>'
);
}
/**
* Set some context, which be accessed via $this->context for a function to know where it's being used on the page.
* @param $key
* @param $value
*/
public function set_context($key, $value)
{
$this->context[$key] = $value;
}
/**
* Clear some context (used at the end of the appropriate loop).
* @param $key
*/
public function clear_context($key)
{
unset($this->context[$key]);
}
/**
* Reorder the parts of the page according to the $parts array which contains part keys in their new order. Call this
* before main_parts(). See the docs for qa_array_reorder() in util/sort.php for the other parameters.
* @param $parts
* @param string $beforekey
* @param bool $reorderrelative
*/
public function reorder_parts($parts, $beforekey = null, $reorderrelative = true)
{
require_once QA_INCLUDE_DIR . 'util/sort.php';
qa_array_reorder($this->content, $parts, $beforekey, $reorderrelative);
}
/**
* Output the widgets (as provided in $this->content['widgets']) for $region and $place.
* @param $region
* @param $place
*/
public function widgets($region, $place)
{
$widgetsHere = isset($this->content['widgets'][$region][$place]) ? $this->content['widgets'][$region][$place] : array();
if (is_array($widgetsHere) && count($widgetsHere) > 0) {
$this->output('<div class="qa-widgets-' . $region . ' qa-widgets-' . $region . '-' . $place . '">');
foreach ($widgetsHere 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>', '');
}
}
/**
* 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()
{
// abstract method
}
/**
* Post-output cleanup. For now, check that the indenting ended right, and if not, output a warning in an HTML comment.
*/
public function finish()
{
if ($this->indent !== 0 && !$this->minifyHtml) {
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";
}
}
// 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 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...
public function doctype()
{
$this->output('<!DOCTYPE html>');
}
public function html()
{
$attribution = '<!-- Powered by Question2Answer - http://www.question2answer.org/ -->';
$extratags = isset($this->content['html_tags']) ? $this->content['html_tags'] : '';
$this->output(
'<html ' . $extratags . '>',
$attribution
);
$this->head();
$this->body();
$this->output(
$attribution,
'</html>'
);
}
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>');
}
public function head_title()
{
$pagetitle = strlen($this->request) ? strip_tags(@$this->content['title']) : '';
$headtitle = (strlen($pagetitle) ? "$pagetitle - " : '') . $this->content['site_title'];
$this->output('<title>' . $headtitle . '</title>');
}
public function head_metas()
{
if (strlen(@$this->content['description'])) {
$this->output('<meta name="description" content="' . $this->content['description'] . '"/>');
}
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'] . '" />');
}
}
}
public function head_script()
{
if (isset($this->content['script'])) {
foreach ($this->content['script'] as $scriptline) {
$this->output_raw($scriptline);
}
}
}
public function head_css()
{
$this->output('<link rel="stylesheet" href="' . $this->rooturl . $this->css_name() . '"/>');
if (isset($this->content['css_src'])) {
foreach ($this->content['css_src'] as $css_src) {
$this->output('<link rel="stylesheet" href="' . $css_src . '"/>');
}
}
if (!empty($this->content['notices'])) {
$this->output(
'<style>',
'.qa-body-js-on .qa-notice {display:none;}',
'</style>'
);
}
}
public function css_name()
{
return 'qa-styles.css?' . QA_VERSION;
}
public function head_lines()
{
if (isset($this->content['head_lines'])) {
foreach ($this->content['head_lines'] as $line) {
$this->output_raw($line);
}
}
}
public function head_custom()
{
// abstract method
}
public function body()
{
$this->output('<body');
$this->body_tags();
$this->output('>');
$this->body_script();
$this->body_header();
$this->body_content();
$this->body_footer();
$this->body_hidden();
$this->output('</body>');
}
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>');
}
public function waiting_template()
{
$this->output('<span id="qa-waiting-template" class="qa-waiting">...</span>');
}
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>'
);
}
public function body_header()
{
if (isset($this->content['body_header'])) {
$this->output_raw($this->content['body_header']);
}
}
public function body_footer()
{
if (isset($this->content['body_footer'])) {
$this->output_raw($this->content['body_footer']);
}
}
public function body_content()
{
$this->body_prefix();
$this->notices();
$this->output('<div class="qa-body-wrapper">', '');
$this->widgets('full', 'top');
$this->header();
$this->widgets('full', 'high');
$this->sidepanel();
$this->main();
$this->widgets('full', 'low');
$this->footer();
$this->widgets('full', 'bottom');
$this->output('</div> <!-- END body-wrapper -->');
$this->body_suffix();
}
public function body_tags()
{
$class = 'qa-template-' . qa_html($this->template);
$class .= empty($this->theme) ? '' : ' qa-theme-' . qa_html($this->theme);
if (isset($this->content['categoryids'])) {
foreach ($this->content['categoryids'] as $categoryid) {
$class .= ' qa-category-' . qa_html($categoryid);
}
}
$this->output('class="' . $class . ' qa-body-js-off"');
}
public function body_prefix()
{
// abstract method
}
public function body_suffix()
{
// abstract method
}
public function notices()
{
if (!empty($this->content['notices'])) {
foreach ($this->content['notices'] as $notice) {
$this->notice($notice);
}
}
}
public function notice($notice)
{
$this->output('<div class="qa-notice" id="' . $notice['id'] . '">');
if (isset($notice['form_tags']))
$this->output('<form ' . $notice['form_tags'] . '>');
$this->output_raw($notice['content']);
$this->output('<input ' . $notice['close_tags'] . ' type="submit" value="X" class="qa-notice-close-button"/> ');
if (isset($notice['form_tags'])) {
$this->form_hidden_elements(@$notice['form_hidden']);
$this->output('</form>');
}
$this->output('</div>');
}
public function header()
{
$this->output('<div class="qa-header">');
$this->logo();
$this->nav_user_search();
$this->nav_main_sub();
$this->header_clear();
$this->output('</div> <!-- END qa-header -->', '');
}
public function nav_user_search()
{
$this->nav('user');
$this->search();
}
public function nav_main_sub()
{
$this->nav('main');
$this->nav('sub');
}
public function logo()
{
$this->output(
'<div class="qa-logo">',
$this->content['logo'],
'</div>'
);
}
public function search()
{
$search = $this->content['search'];
$this->output(
'<div class="qa-search">',
'<form ' . $search['form_tags'] . '>',
@$search['form_extra']
);
$this->search_field($search);
$this->search_button($search);
$this->output(
'</form>',
'</div>'
);
}
public function search_field($search)
{
$this->output('<input type="text" ' . $search['field_tags'] . ' value="' . @$search['value'] . '" class="qa-search-field"/>');
}
public function search_button($search)
{
$this->output('<input type="submit" value="' . $search['button_label'] . '" class="qa-search-button"/>');
}
public function nav($navtype, $level = null)
{
$navigation = @$this->content['navigation'][$navtype];
if ($navtype == 'user' || isset($navigation)) {
$this->output('<div class="qa-nav-' . $navtype . '">');
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;
}
}
$this->set_context('nav_type', $navtype);
$this->nav_list($navigation, 'nav-' . $navtype, $level);
$this->nav_clear($navtype);
$this->clear_context('nav_type');
$this->output('</div>');
}
}
public function nav_list($navigation, $class, $level = null)
{
$this->output('<ul class="qa-' . $class . '-list' . (isset($level) ? (' qa-' . $class . '-list-' . $level) : '') . '">');
$index = 0;
foreach ($navigation as $key => $navlink) {
$this->set_context('nav_key', $key);
$this->set_context('nav_index', $index++);
$this->nav_item($key, $navlink, $class, $level);
}
$this->clear_context('nav_key');
$this->clear_context('nav_index');
$this->output('</ul>');
}
public function nav_clear($navtype)
{
$this->output(
'<div class="qa-nav-' . $navtype . '-clear">',
'</div>'
);
}
public function nav_item($key, $navlink, $class, $level = null)
{
$suffix = strtr($key, array( // map special character in navigation key
'$' => '',
'/' => '-',
));
$this->output('<li class="qa-' . $class . '-item' . (@$navlink['opposite'] ? '-opp' : '') .
(@$navlink['state'] ? (' qa-' . $class . '-' . $navlink['state']) : '') . ' qa-' . $class . '-' . $suffix . '">');
$this->nav_link($navlink, $class);
$subnav = isset($navlink['subnav']) ? $navlink['subnav'] : array();
if (is_array($subnav) && count($subnav) > 0) {
$this->nav_list($subnav, $class, 1 + $level);
}
$this->output('</li>');
}
public function nav_link($navlink, $class)
{
if (isset($navlink['url'])) {
$this->output(
'<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>'
);
} 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>'
);
}
if (strlen(@$navlink['note']))
$this->output('<span class="qa-' . $class . '-note">' . $navlink['note'] . '</span>');
}
public function logged_in()
{
$this->output_split(@$this->content['loggedin'], 'qa-logged-in', 'div');
}
public function header_clear()
{
$this->output(
'<div class="qa-header-clear">',
'</div>'
);
}
public function sidepanel()
{
$this->output('<div class="qa-sidepanel">');
$this->widgets('side', 'top');
$this->sidebar();
$this->widgets('side', 'high');
$this->widgets('side', 'low');
$this->output_raw(@$this->content['sidepanel']);
$this->feed();
$this->widgets('side', 'bottom');
$this->output('</div>', '');
}
public function sidebar()
{
$sidebar = @$this->content['sidebar'];
if (!empty($sidebar)) {
$this->output('<div class="qa-sidebar">');
$this->output_raw($sidebar);
$this->output('</div>', '');
}
}
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>');
}
}
public function main()
{
$content = $this->content;
$hidden = !empty($content['hidden']) ? ' qa-main-hidden' : '';
$extratags = isset($this->content['main_tags']) ? $this->content['main_tags'] : '';
$this->output('<div class="qa-main' . $hidden . '"' . $extratags . '>');
$this->widgets('main', 'top');
$this->page_title_error();
$this->widgets('main', 'high');
$this->main_parts($content);
$this->widgets('main', 'low');
$this->page_links();
$this->suggest_next();
$this->widgets('main', 'bottom');
$this->output('</div> <!-- END qa-main -->', '');
}
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'] . '>');
$this->output('<div class="qa-main-heading">');
$this->favorite();
$this->output('<h1>');
$this->title();
$this->output('</h1>');
$this->output('</div>');
if (isset($favorite)) {
$formhidden = isset($favorite['form_hidden']) ? $favorite['form_hidden'] : null;
$this->form_hidden_elements($formhidden);
$this->output('</form>');
}
}
if (isset($this->content['success']))
$this->success($this->content['success']);
if (isset($this->content['error']))
$this->error($this->content['error']);
}
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>');
}
}
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'])) {
$this->output(
$url ? '<a href="' . $url . '">' : '',
$this->content['title'],
$url ? '</a>' : ''
);
}
// add closed note in title
if (!empty($q_view['closed']['state']))
$this->output(' [' . $q_view['closed']['state'] . ']');
}
public function favorite_inner_html($favorite)
{
$this->favorite_button(@$favorite['favorite_add_tags'], 'qa-favorite');
$this->favorite_button(@$favorite['favorite_remove_tags'], 'qa-unfavorite');
}
public function favorite_button($tags, $class)
{
if (isset($tags))
$this->output('<input ' . $tags . ' type="submit" value="" class="' . $class . '-button"/> ');
}
public function error($error)
{
if (strlen($error)) {
$this->output(
'<div class="qa-error">',
$error,
'</div>'
);
}
}
public function success($message)
{
if (strlen($message)) {
$this->output(
'<div class="qa-success">',
$message,
'</div>'
);
}
}
public function main_parts($content)
{
foreach ($content as $key => $part) {
$this->set_context('part', $key);
$this->main_part($key, $part);
}
$this->clear_context('part');
}
public function main_part($key, $part)
{
$isRanking = strpos($key, 'ranking') === 0;
$partdiv = (
strpos($key, 'custom') === 0 ||
strpos($key, 'form') === 0 ||
strpos($key, 'q_list') === 0 ||
(strpos($key, 'q_view') === 0 && !isset($this->content['form_q_edit'])) ||
strpos($key, 'a_form') === 0 ||
strpos($key, 'a_list') === 0 ||
$isRanking ||
strpos($key, 'message_list') === 0 ||
strpos($key, 'nav_list') === 0
);
if ($partdiv) {
$class = 'qa-part-' . strtr($key, '_', '-');
if ($isRanking)
$class .= ' qa-ranking-' . $part['type'] . '-' . (isset($part['sort']) ? $part['sort'] : 'points');
// help target CSS to page parts
$this->output('<div class="' . $class . '">');
}
if (strpos($key, 'custom') === 0)
$this->output_raw($part);
elseif (strpos($key, 'form') === 0)
$this->form($part);
elseif (strpos($key, 'q_list') === 0)
$this->q_list_and_form($part);
elseif (strpos($key, 'q_view') === 0)
$this->q_view($part);
elseif (strpos($key, 'a_form') === 0)
$this->a_form($part);
elseif (strpos($key, 'a_list') === 0)
$this->a_list($part);
elseif (strpos($key, 'ranking') === 0)
$this->ranking($part);
elseif (strpos($key, 'message_list') === 0)
$this->message_list_and_form($part);
elseif (strpos($key, 'nav_list') === 0) {
$this->part_title($part);
$this->nav_list($part['nav'], $part['type'], 1);
}
if ($partdiv)
$this->output('</div>');
}
public function footer()
{
$this->output('<div class="qa-footer">');
$this->nav('footer');
$this->attribution();
$this->footer_clear();
$this->output('</div> <!-- END qa-footer -->', '');
}
public function attribution()
{
// Hi there. I'd really appreciate you displaying this link on your Q2A site. Thank you - Gideon
$this->output(
'<div class="qa-attribution">',
'Powered by <a href="http://www.question2answer.org/">Question2Answer</a>',
'</div>'
);
}
public function footer_clear()
{
$this->output(
'<div class="qa-footer-clear">',
'</div>'
);
}
public function section($title)
{
$this->part_title(array('title' => $title));
}
public function part_title($part)
{
if (strlen(@$part['title']) || strlen(@$part['title_tags']))
$this->output('<h2' . rtrim(' ' . @$part['title_tags']) . '>' . @$part['title'] . '</h2>');
}
public function part_footer($part)
{
if (isset($part['footer']))
$this->output($part['footer']);
}
public function form($form)
{
if (!empty($form)) {
$this->part_title($form);
if (isset($form['tags']))
$this->output('<form ' . $form['tags'] . '>');
$this->form_body($form);
if (isset($form['tags']))
$this->output('</form>');
}
}
public function form_columns($form)
{
if (isset($form['ok']) || !empty($form['fields']))
$columns = ($form['style'] == 'wide') ? 2 : 1;
else
$columns = 0;
return $columns;
}
public function form_spacer($form, $columns)
{
$this->output(
'<tr>',
'<td colspan="' . $columns . '" class="qa-form-' . $form['style'] . '-spacer">',
' ',
'</td>',
'</tr>'
);
}