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 form for unpaired tags, to help keep
* track of indenting, although its actual output converts these to for W3C validation.
* @param $elements
*/
public function output_array($elements)
{
foreach ($elements as $element) {
$element = (string)$element;
$line = str_replace('/>', '>', $element);
if ($this->minifyHtml) {
if (strlen($line))
echo $line . "\n";
} else {
$delta = 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((string)$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('
');
foreach ($widgetsHere as $module) {
$this->output('
', '');
}
}
/**
* 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 "\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
, q_list() outputs
, etc...
public function doctype()
{
$this->output('');
}
public function html()
{
$attribution = '';
$extratags = isset($this->content['html_tags']) ? $this->content['html_tags'] : '';
$this->output(
'',
$attribution
);
$this->head();
$this->body();
$this->output(
$attribution,
''
);
}
public function head()
{
$this->output(
'',
''
);
$this->head_title();
$this->head_metas();
$this->head_css();
$this->head_links();
$this->head_lines();
$this->head_script();
$this->head_custom();
$this->output('');
}
public function head_title()
{
$pagetitle = strlen($this->request) ? strip_tags($this->content['title'] ?? '') : '';
$headtitle = (strlen($pagetitle) ? "$pagetitle - " : '') . $this->content['site_title'];
$this->output('' . $headtitle . '');
}
public function head_metas()
{
if (strlen($this->content['description'] ?? '')) {
$this->output('');
}
if (strlen($this->content['keywords'] ?? '')) {
// as far as I know, meta keywords have zero effect on search rankings or listings
$this->output('');
}
}
public function head_links()
{
if (isset($this->content['canonical'])) {
$this->output('');
}
if (isset($this->content['feed']['url'])) {
$this->output('');
}
// 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('');
}
}
}
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('');
if (isset($this->content['css_src'])) {
foreach ($this->content['css_src'] as $css_src) {
$this->output('');
}
}
if (!empty($this->content['notices'])) {
$this->output(
''
);
}
}
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_tags();
$this->output('>');
$this->body_script();
$this->body_header();
$this->body_content();
$this->body_footer();
$this->body_hidden();
$this->output('');
}
public function body_hidden()
{
$this->output('
');
$this->waiting_template();
$this->output('
');
}
public function waiting_template()
{
$this->output('...');
}
public function body_script()
{
$this->output(
''
);
}
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();
$extratags = isset($this->content['wrapper_tags']) ? $this->content['wrapper_tags'] : '';
$this->output('
', '');
}
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(
'
',
$this->content['logo'],
'
'
);
}
public function search()
{
$search = $this->content['search'];
$this->output(
'
',
'',
'
'
);
}
public function search_field($search)
{
$this->output('');
}
public function search_button($search)
{
$this->output('');
}
public function nav($navtype, $level = null)
{
$navigation = @$this->content['navigation'][$navtype];
if ($navtype == 'user' || isset($navigation)) {
$this->output('
');
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('
');
}
}
public function nav_list($navigation, $class, $level = null)
{
$this->output('
');
}
public function footer()
{
$this->output(' ', '');
}
public function attribution()
{
// Hi there. I'd really appreciate you displaying this link on your Q2A site. Thank you - Gideon
$this->output(
'
'
);
}
public function footer_clear()
{
$this->output(
''
);
}
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('
' . ($part['title'] ?? '') . '
');
}
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('');
}
}
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(
'
',
'
',
' ',
'
',
'
'
);
}
public function form_body($form)
{
if (@$form['boxed'])
$this->output('
');
$columns = $this->form_columns($form);
if ($columns)
$this->output('
');
$this->form_ok($form, $columns);
$this->form_fields($form, $columns);
$this->form_buttons($form, $columns);
if ($columns)
$this->output('
');
$this->form_hidden($form);
if (@$form['boxed'])
$this->output('
');
}
public function form_ok($form, $columns)
{
if (!empty($form['ok'])) {
$this->output(
'
',
'
',
$form['ok'],
'
',
'
'
);
}
}
/**
* Reorder the fields of $form according to the $keys array which contains the field keys in their new order. Call
* before any fields are output. See the docs for qa_array_reorder() in util/sort.php for the other parameters.
* @param $form
* @param $keys
* @param mixed $beforekey
* @param bool $reorderrelative
*/
public function form_reorder_fields(&$form, $keys, $beforekey = null, $reorderrelative = true)
{
require_once QA_INCLUDE_DIR . 'util/sort.php';
if (is_array($form['fields']))
qa_array_reorder($form['fields'], $keys, $beforekey, $reorderrelative);
}
public function form_fields($form, $columns)
{
if (!empty($form['fields'])) {
foreach ($form['fields'] as $key => $field) {
$this->set_context('field_key', $key);
if (@$field['type'] == 'blank')
$this->form_spacer($form, $columns);
else
$this->form_field_rows($form, $columns, $field);
}
$this->clear_context('field_key');
}
}
public function form_field_rows($form, $columns, $field)
{
$style = $form['style'];
if (isset($field['style'])) { // field has different style to most of form
$style = $field['style'];
$colspan = $columns;
$columns = ($style == 'wide') ? 2 : 1;
} else
$colspan = null;
$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'])));
if (isset($field['id'])) {
if ($columns == 1)
$this->output('', '
');
else
$this->output('
');
} else
$this->output('
');
if ($columns > 1 || !empty($field['label']))
$this->form_label($field, $style, $columns, $prefixed, $suffixed, $colspan);
if ($tworows) {
$this->output(
'
');
if ($columns == 1 && isset($field['id']))
$this->output('');
}
public function form_label($field, $style, $columns, $prefixed, $suffixed, $colspan)
{
$extratags = '';
if ($columns > 1 && (@$field['type'] == 'select-radio' || @$field['rows'] > 1))
$extratags .= ' style="vertical-align:top;"';
if (isset($colspan))
$extratags .= ' colspan="' . $colspan . '"';
$this->output('
');
if ($prefixed) {
$this->output('');
if ($suffixed) {
$this->output(' ');
$this->form_field($field, $style);
}
$this->output('
');
}
public function form_data($field, $style, $columns, $showfield, $colspan)
{
if ($showfield || (!empty($field['error'])) || (!empty($field['note']))) {
$this->output(
'
'
);
if ($showfield)
$this->form_field($field, $style);
if (!empty($field['error'])) {
if (@$field['note_force'])
$this->form_note($field, $style, $columns);
$this->form_error($field, $style, $columns);
} elseif (!empty($field['note']))
$this->form_note($field, $style, $columns);
$this->output('
');
}
}
public function form_field($field, $style)
{
$this->form_prefix($field, $style);
$this->output_raw(@$field['html_prefix']);
switch (@$field['type']) {
case 'checkbox':
$this->form_checkbox($field, $style);
break;
case 'static':
$this->form_static($field, $style);
break;
case 'password':
$this->form_password($field, $style);
break;
case 'number':
$this->form_number($field, $style);
break;
case 'file':
$this->form_file($field, $style);
break;
case 'select':
$this->form_select($field, $style);
break;
case 'select-radio':
$this->form_select_radio($field, $style);
break;
case 'image':
$this->form_image($field, $style);
break;
case 'custom':
$this->output_raw(@$field['html']);
break;
default:
if (@$field['type'] == 'textarea' || @$field['rows'] > 1)
$this->form_text_multi_row($field, $style);
else
$this->form_text_single_row($field, $style);
break;
}
$this->output_raw(@$field['html_suffix']);
$this->form_suffix($field, $style);
}
/**
* Reorder the buttons of $form according to the $keys array which contains the button keys in their new order. Call
* before any buttons are output. See the docs for qa_array_reorder() in util/sort.php for the other parameters.
* @param $form
* @param $keys
* @param mixed $beforekey
* @param bool $reorderrelative
*/
public function form_reorder_buttons(&$form, $keys, $beforekey = null, $reorderrelative = true)
{
require_once QA_INCLUDE_DIR . 'util/sort.php';
if (is_array($form['buttons']))
qa_array_reorder($form['buttons'], $keys, $beforekey, $reorderrelative);
}
public function form_buttons($form, $columns)
{
if (!empty($form['buttons'])) {
$style = @$form['style'];
if ($columns) {
$this->output(
'
',
'
'
);
}
foreach ($form['buttons'] as $key => $button) {
$this->set_context('button_key', $key);
if (empty($button))
$this->form_button_spacer($style);
else {
$this->form_button_data($button, $key, $style);
$this->form_button_note($button, $style);
}
}
$this->clear_context('button_key');
if ($columns) {
$this->output(
'
',
'
'
);
}
}
}
public function form_button_data($button, $key, $style)
{
$baseclass = 'qa-form-' . $style . '-button qa-form-' . $style . '-button-' . $key;
$this->output('');
}
public function form_button_note($button, $style)
{
if (!empty($button['note'])) {
$this->output(
'',
$button['note'],
'',
' '
);
}
}
public function form_button_spacer($style)
{
$this->output('');
}
public function form_hidden($form)
{
$this->form_hidden_elements(@$form['hidden']);
}
public function form_hidden_elements($hidden)
{
if (empty($hidden))
return;
foreach ($hidden as $name => $value) {
if (is_array($value)) {
// new method of outputting tags
$this->output('');
} else {
// old method
$this->output('');
}
}
}
public function form_prefix($field, $style)
{
if (!empty($field['prefix']))
$this->output('' . $field['prefix'] . '');
}
public function form_suffix($field, $style)
{
if (!empty($field['suffix']))
$this->output('' . $field['suffix'] . '');
}
public function form_checkbox($field, $style)
{
$this->output('');
}
public function form_static($field, $style)
{
$this->output('' . @$field['value'] . '');
}
public function form_password($field, $style)
{
$this->output('');
}
public function form_number($field, $style)
{
$this->output('');
}
public function form_file($field, $style)
{
$this->output('');
}
/**
* Output a