Commit ac597698 by Scott

Coding style (qa-page.php, app/page.php)

parent d6aa8810
...@@ -20,790 +20,809 @@ ...@@ -20,790 +20,809 @@
More about this license: http://www.question2answer.org/license.php 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 if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../'); header('Location: ../');
exit; exit;
}
require_once QA_INCLUDE_DIR . 'app/cookies.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
require_once QA_INCLUDE_DIR . 'app/users.php';
require_once QA_INCLUDE_DIR . 'app/options.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
/**
* Standard database failure handler function which bring up the install/repair/upgrade page
*/
function qa_page_db_fail_handler($type, $errno = null, $error = null, $query = null)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$pass_failure_type = $type;
$pass_failure_errno = $errno;
$pass_failure_error = $error;
$pass_failure_query = $query;
require_once QA_INCLUDE_DIR . 'qa-install.php';
qa_exit('error');
}
/**
* Queue any pending requests which are required independent of which page will be shown
*/
function qa_page_queue_pending()
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
qa_preload_options();
$loginuserid = qa_get_logged_in_userid();
if (isset($loginuserid)) {
if (!QA_FINAL_EXTERNAL_USERS)
qa_db_queue_pending_select('loggedinuser', qa_db_user_account_selectspec($loginuserid, true));
qa_db_queue_pending_select('notices', qa_db_user_notices_selectspec($loginuserid));
qa_db_queue_pending_select('favoritenonqs', qa_db_user_favorite_non_qs_selectspec($loginuserid));
qa_db_queue_pending_select('userlimits', qa_db_user_limits_selectspec($loginuserid));
qa_db_queue_pending_select('userlevels', qa_db_user_levels_selectspec($loginuserid, true));
} }
require_once QA_INCLUDE_DIR.'app/cookies.php'; qa_db_queue_pending_select('iplimits', qa_db_ip_limits_selectspec(qa_remote_ip_address()));
require_once QA_INCLUDE_DIR.'app/format.php'; qa_db_queue_pending_select('navpages', qa_db_pages_selectspec(array('B', 'M', 'O', 'F')));
require_once QA_INCLUDE_DIR.'app/users.php'; qa_db_queue_pending_select('widgets', qa_db_widgets_selectspec());
require_once QA_INCLUDE_DIR.'app/options.php'; }
require_once QA_INCLUDE_DIR.'db/selects.php';
function qa_page_db_fail_handler($type, $errno=null, $error=null, $query=null) /**
/* * Check the page state parameter and then remove it from the $_GET array
Standard database failure handler function which bring up the install/repair/upgrade page */
*/ function qa_load_state()
{ {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } global $qa_state;
$pass_failure_type=$type;
$pass_failure_errno=$errno;
$pass_failure_error=$error;
$pass_failure_query=$query;
require_once QA_INCLUDE_DIR.'qa-install.php'; $qa_state = qa_get('state');
unset($_GET['state']); // to prevent being passed through on forms
}
qa_exit('error');
}
/**
* If no user is logged in, call through to the login modules to see if they want to log someone in
*/
function qa_check_login_modules()
{
if (!QA_FINAL_EXTERNAL_USERS && !qa_is_logged_in()) {
$loginmodules = qa_load_modules_with('login', 'check_login');
function qa_page_queue_pending() foreach ($loginmodules as $loginmodule) {
/* $loginmodule->check_login();
Queue any pending requests which are required independent of which page will be shown if (qa_is_logged_in()) // stop and reload page if it worked
*/ qa_redirect(qa_request(), $_GET);
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
qa_preload_options();
$loginuserid=qa_get_logged_in_userid();
if (isset($loginuserid)) {
if (!QA_FINAL_EXTERNAL_USERS)
qa_db_queue_pending_select('loggedinuser', qa_db_user_account_selectspec($loginuserid, true));
qa_db_queue_pending_select('notices', qa_db_user_notices_selectspec($loginuserid));
qa_db_queue_pending_select('favoritenonqs', qa_db_user_favorite_non_qs_selectspec($loginuserid));
qa_db_queue_pending_select('userlimits', qa_db_user_limits_selectspec($loginuserid));
qa_db_queue_pending_select('userlevels', qa_db_user_levels_selectspec($loginuserid, true));
} }
qa_db_queue_pending_select('iplimits', qa_db_ip_limits_selectspec(qa_remote_ip_address()));
qa_db_queue_pending_select('navpages', qa_db_pages_selectspec(array('B', 'M', 'O', 'F')));
qa_db_queue_pending_select('widgets', qa_db_widgets_selectspec());
} }
}
function qa_load_state() /**
/* * React to any of the common buttons on a page for voting, favorites and closing a notice
Check the page state parameter and then remove it from the $_GET array * If the user has Javascript on, these should come through Ajax rather than here.
*/ */
{ function qa_check_page_clicks()
global $qa_state; {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$qa_state=qa_get('state');
unset($_GET['state']); // to prevent being passed through on forms
}
global $qa_page_error_html;
function qa_check_login_modules() if (qa_is_http_post()) {
/* foreach ($_POST as $field => $value) {
If no user is logged in, call through to the login modules to see if they want to log someone in if (strpos($field, 'vote_') === 0) { // voting...
*/ @list($dummy, $postid, $vote, $anchor) = explode('_', $field);
{
if ((!QA_FINAL_EXTERNAL_USERS) && !qa_is_logged_in()) {
$loginmodules=qa_load_modules_with('login', 'check_login');
foreach ($loginmodules as $loginmodule) {
$loginmodule->check_login();
if (qa_is_logged_in()) // stop and reload page if it worked
qa_redirect(qa_request(), $_GET);
}
}
}
if (isset($postid) && isset($vote)) {
if (!qa_check_form_security_code('vote', qa_post_text('code')))
$qa_page_error_html = qa_lang_html('misc/form_security_again');
function qa_check_page_clicks() else {
/* require_once QA_INCLUDE_DIR . 'app/votes.php';
React to any of the common buttons on a page for voting, favorites and closing a notice require_once QA_INCLUDE_DIR . 'db/selects.php';
If the user has Javascript on, these should come through Ajax rather than here.
*/
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
global $qa_page_error_html; $userid = qa_get_logged_in_userid();
if (qa_is_http_post()) $post = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid));
foreach ($_POST as $field => $value) { $qa_page_error_html = qa_vote_error_html($post, $vote, $userid, qa_request());
if (strpos($field, 'vote_')===0) { // voting...
@list($dummy, $postid, $vote, $anchor)=explode('_', $field);
if (isset($postid) && isset($vote)) { if (!$qa_page_error_html) {
if (!qa_check_form_security_code('vote', qa_post_text('code'))) qa_vote_set($post, $userid, qa_get_logged_in_handle(), qa_cookie_get(), $vote);
$qa_page_error_html=qa_lang_html('misc/form_security_again'); qa_redirect(qa_request(), $_GET, null, null, $anchor);
else {
require_once QA_INCLUDE_DIR.'app/votes.php';
require_once QA_INCLUDE_DIR.'db/selects.php';
$userid=qa_get_logged_in_userid();
$post=qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid));
$qa_page_error_html=qa_vote_error_html($post, $vote, $userid, qa_request());
if (!$qa_page_error_html) {
qa_vote_set($post, $userid, qa_get_logged_in_handle(), qa_cookie_get(), $vote);
qa_redirect(qa_request(), $_GET, null, null, $anchor);
}
break;
} }
break;
} }
}
} elseif (strpos($field, 'favorite_')===0) { // favorites... } elseif (strpos($field, 'favorite_') === 0) { // favorites...
@list($dummy, $entitytype, $entityid, $favorite)=explode('_', $field); @list($dummy, $entitytype, $entityid, $favorite) = explode('_', $field);
if (isset($entitytype) && isset($entityid) && isset($favorite)) { if (isset($entitytype) && isset($entityid) && isset($favorite)) {
if (!qa_check_form_security_code('favorite-'.$entitytype.'-'.$entityid, qa_post_text('code'))) if (!qa_check_form_security_code('favorite-' . $entitytype . '-' . $entityid, qa_post_text('code')))
$qa_page_error_html=qa_lang_html('misc/form_security_again'); $qa_page_error_html = qa_lang_html('misc/form_security_again');
else { else {
require_once QA_INCLUDE_DIR.'app/favorites.php'; require_once QA_INCLUDE_DIR . 'app/favorites.php';
qa_user_favorite_set(qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), $entitytype, $entityid, $favorite); qa_user_favorite_set(qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), $entitytype, $entityid, $favorite);
qa_redirect(qa_request(), $_GET); qa_redirect(qa_request(), $_GET);
}
} }
}
} elseif (strpos($field, 'notice_')===0) { // notices... } elseif (strpos($field, 'notice_') === 0) { // notices...
@list($dummy, $noticeid)=explode('_', $field); @list($dummy, $noticeid) = explode('_', $field);
if (isset($noticeid)) {
if (!qa_check_form_security_code('notice-'.$noticeid, qa_post_text('code')))
$qa_page_error_html=qa_lang_html('misc/form_security_again');
else { if (isset($noticeid)) {
if ($noticeid=='visitor') if (!qa_check_form_security_code('notice-' . $noticeid, qa_post_text('code')))
setcookie('qa_noticed', 1, time()+86400*3650, '/', QA_COOKIE_DOMAIN, (bool)ini_get('session.cookie_secure'), true); $qa_page_error_html = qa_lang_html('misc/form_security_again');
elseif ($noticeid=='welcome') { else {
require_once QA_INCLUDE_DIR.'db/users.php'; if ($noticeid == 'visitor')
qa_db_user_set_flag(qa_get_logged_in_userid(), QA_USER_FLAGS_WELCOME_NOTICE, false); setcookie('qa_noticed', 1, time() + 86400 * 3650, '/', QA_COOKIE_DOMAIN, (bool)ini_get('session.cookie_secure'), true);
} else { elseif ($noticeid == 'welcome') {
require_once QA_INCLUDE_DIR.'db/notices.php'; require_once QA_INCLUDE_DIR . 'db/users.php';
qa_db_usernotice_delete(qa_get_logged_in_userid(), $noticeid); qa_db_user_set_flag(qa_get_logged_in_userid(), QA_USER_FLAGS_WELCOME_NOTICE, false);
}
qa_redirect(qa_request(), $_GET); } else {
require_once QA_INCLUDE_DIR . 'db/notices.php';
qa_db_usernotice_delete(qa_get_logged_in_userid(), $noticeid);
} }
qa_redirect(qa_request(), $_GET);
} }
} }
} }
}
} }
}
/** /**
* Run the appropriate qa-page-*.php file for this request and return back the $qa_content it passed * Run the appropriate qa-page-*.php file for this request and return back the $qa_content it passed
*/ */
function qa_get_request_content() function qa_get_request_content()
{ {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$requestlower = strtolower(qa_request()); $requestlower = strtolower(qa_request());
$requestparts = qa_request_parts(); $requestparts = qa_request_parts();
$firstlower = strtolower($requestparts[0]); $firstlower = strtolower($requestparts[0]);
$routing = qa_page_routing(); $routing = qa_page_routing();
if (isset($routing[$requestlower])) { if (isset($routing[$requestlower])) {
qa_set_template($firstlower); qa_set_template($firstlower);
$qa_content = require QA_INCLUDE_DIR.$routing[$requestlower]; $qa_content = require QA_INCLUDE_DIR . $routing[$requestlower];
} elseif (isset($routing[$firstlower.'/'])) { } elseif (isset($routing[$firstlower . '/'])) {
qa_set_template($firstlower); qa_set_template($firstlower);
$qa_content = require QA_INCLUDE_DIR.$routing[$firstlower.'/']; $qa_content = require QA_INCLUDE_DIR . $routing[$firstlower . '/'];
} elseif (is_numeric($requestparts[0])) { } elseif (is_numeric($requestparts[0])) {
qa_set_template('question'); qa_set_template('question');
$qa_content = require QA_INCLUDE_DIR.'pages/question.php'; $qa_content = require QA_INCLUDE_DIR . 'pages/question.php';
} else { } else {
qa_set_template(strlen($firstlower) ? $firstlower : 'qa'); // will be changed later qa_set_template(strlen($firstlower) ? $firstlower : 'qa'); // will be changed later
$qa_content = require QA_INCLUDE_DIR.'pages/default.php'; // handles many other pages, including custom pages and page modules $qa_content = require QA_INCLUDE_DIR . 'pages/default.php'; // handles many other pages, including custom pages and page modules
} }
if ($firstlower == 'admin') { if ($firstlower == 'admin') {
$_COOKIE['qa_admin_last'] = $requestlower; // for navigation tab now... $_COOKIE['qa_admin_last'] = $requestlower; // for navigation tab now...
setcookie('qa_admin_last', $_COOKIE['qa_admin_last'], 0, '/', QA_COOKIE_DOMAIN, (bool)ini_get('session.cookie_secure'), true); // ...and in future setcookie('qa_admin_last', $_COOKIE['qa_admin_last'], 0, '/', QA_COOKIE_DOMAIN, (bool)ini_get('session.cookie_secure'), true); // ...and in future
} }
if (isset($qa_content)) if (isset($qa_content))
qa_set_form_security_key(); qa_set_form_security_key();
return $qa_content; return $qa_content;
} }
/** /**
* Output the $qa_content via the theme class after doing some pre-processing, mainly relating to Javascript * Output the $qa_content via the theme class after doing some pre-processing, mainly relating to Javascript
*/ */
function qa_output_content($qa_content) function qa_output_content($qa_content)
{ {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
global $qa_template; global $qa_template;
$requestlower = strtolower(qa_request()); $requestlower = strtolower(qa_request());
// Set appropriate selected flags for navigation (not done in qa_content_prepare() since it also applies to sub-navigation) // Set appropriate selected flags for navigation (not done in qa_content_prepare() since it also applies to sub-navigation)
foreach ($qa_content['navigation'] as $navtype => $navigation) { foreach ($qa_content['navigation'] as $navtype => $navigation) {
if (!is_array($navigation) || $navtype == 'cat') { if (!is_array($navigation) || $navtype == 'cat') {
continue; continue;
} }
foreach ($navigation as $navprefix => $navlink) { foreach ($navigation as $navprefix => $navlink) {
$selected =& $qa_content['navigation'][$navtype][$navprefix]['selected']; $selected =& $qa_content['navigation'][$navtype][$navprefix]['selected'];
if (isset($navlink['selected_on'])) { if (isset($navlink['selected_on'])) {
// match specified paths // match specified paths
foreach ($navlink['selected_on'] as $path) { foreach ($navlink['selected_on'] as $path) {
if (strpos($requestlower.'$', $path) === 0) if (strpos($requestlower . '$', $path) === 0)
$selected = true; $selected = true;
}
}
elseif ($requestlower === $navprefix || $requestlower.'$' === $navprefix) {
// exact match for array key
$selected = true;
} }
} elseif ($requestlower === $navprefix || $requestlower . '$' === $navprefix) {
// exact match for array key
$selected = true;
} }
} }
}
// Slide down notifications // Slide down notifications
if (!empty($qa_content['notices']))
foreach ($qa_content['notices'] as $notice) {
$qa_content['script_onloads'][]=array(
"qa_reveal(document.getElementById(".qa_js($notice['id'])."), 'notice');",
);
}
// Handle maintenance mode
if (qa_opt('site_maintenance') && ($requestlower!='login')) {
if (qa_get_logged_in_level()>=QA_USER_LEVEL_ADMIN) {
if (!isset($qa_content['error']))
$qa_content['error']=strtr(qa_lang_html('admin/maintenance_admin_only'), array(
'^1' => '<a href="'.qa_path_html('admin/general').'">',
'^2' => '</a>',
));
} else { if (!empty($qa_content['notices']))
$qa_content=qa_content_prepare(); foreach ($qa_content['notices'] as $notice) {
$qa_content['error']=qa_lang_html('misc/site_in_maintenance'); $qa_content['script_onloads'][] = array(
} "qa_reveal(document.getElementById(" . qa_js($notice['id']) . "), 'notice');",
);
} }
// Handle new users who must confirm their email now, or must be approved before continuing // Handle maintenance mode
$userid=qa_get_logged_in_userid();
if (isset($userid) && ($requestlower!='confirm') && ($requestlower!='account')) {
$flags=qa_get_logged_in_flags();
if ( ($flags & QA_USER_FLAGS_MUST_CONFIRM) && (!($flags & QA_USER_FLAGS_EMAIL_CONFIRMED)) && qa_opt('confirm_user_emails') ) {
$qa_content=qa_content_prepare();
$qa_content['title']=qa_lang_html('users/confirm_title');
$qa_content['error']=strtr(qa_lang_html('users/confirm_required'), array(
'^1' => '<a href="'.qa_path_html('confirm').'">',
'^2' => '</a>',
));
} elseif ( ($flags & QA_USER_FLAGS_MUST_APPROVE) && (qa_get_logged_in_level()<QA_USER_LEVEL_APPROVED) && qa_opt('moderate_users') ) { if (qa_opt('site_maintenance') && ($requestlower != 'login')) {
$qa_content=qa_content_prepare(); if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
$qa_content['title']=qa_lang_html('users/approve_title'); if (!isset($qa_content['error']))
$qa_content['error']=strtr(qa_lang_html('users/approve_required'), array( $qa_content['error'] = strtr(qa_lang_html('admin/maintenance_admin_only'), array(
'^1' => '<a href="'.qa_path_html('account').'">', '^1' => '<a href="' . qa_path_html('admin/general') . '">',
'^2' => '</a>', '^2' => '</a>',
)); ));
}
}
// Combine various Javascript elements in $qa_content into single array for theme layer
$script = array('<script>');
if (isset($qa_content['script_var']))
foreach ($qa_content['script_var'] as $var => $value)
$script[] = 'var '.$var.' = '.qa_js($value).';';
if (isset($qa_content['script_lines']))
foreach ($qa_content['script_lines'] as $scriptlines) {
$script[] = '';
$script = array_merge($script, $scriptlines);
}
$script[] = '</script>';
if (isset($qa_content['script_rel'])) { } else {
$uniquerel = array_unique($qa_content['script_rel']); // remove any duplicates $qa_content = qa_content_prepare();
foreach ($uniquerel as $script_rel) $qa_content['error'] = qa_lang_html('misc/site_in_maintenance');
$script[] = '<script src="'.qa_html(qa_path_to_root().$script_rel).'"></script>';
} }
}
if (isset($qa_content['script_src'])) { // Handle new users who must confirm their email now, or must be approved before continuing
$uniquesrc = array_unique($qa_content['script_src']); // remove any duplicates
foreach ($uniquesrc as $script_src) $userid = qa_get_logged_in_userid();
$script[] = '<script src="'.qa_html($script_src).'"></script>'; if (isset($userid) && $requestlower != 'confirm' && $requestlower != 'account') {
$flags = qa_get_logged_in_flags();
if (($flags & QA_USER_FLAGS_MUST_CONFIRM) && !($flags & QA_USER_FLAGS_EMAIL_CONFIRMED) && qa_opt('confirm_user_emails')) {
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('users/confirm_title');
$qa_content['error'] = strtr(qa_lang_html('users/confirm_required'), array(
'^1' => '<a href="' . qa_path_html('confirm') . '">',
'^2' => '</a>',
));
} elseif (($flags & QA_USER_FLAGS_MUST_APPROVE) && qa_get_logged_in_level() < QA_USER_LEVEL_APPROVED && qa_opt('moderate_users')) {
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('users/approve_title');
$qa_content['error'] = strtr(qa_lang_html('users/approve_required'), array(
'^1' => '<a href="' . qa_path_html('account') . '">',
'^2' => '</a>',
));
} }
}
if (isset($qa_content['focusid'])) // Combine various Javascript elements in $qa_content into single array for theme layer
$qa_content['script_onloads'][] = array(
'$(' . qa_js('#'.$qa_content['focusid']) . ').focus();',
);
// JS onloads must come after jQuery is loaded $script = array('<script>');
$script[] = '<script>';
if (isset($qa_content['script_onloads'])) {
$script[] = '$(window).load(function() {';
foreach ($qa_content['script_onloads'] as $scriptonload) { if (isset($qa_content['script_var']))
foreach ((array)$scriptonload as $scriptline) foreach ($qa_content['script_var'] as $var => $value)
$script[] = "\t".$scriptline; $script[] = 'var ' . $var . ' = ' . qa_js($value) . ';';
}
$script[] = '});'; if (isset($qa_content['script_lines']))
foreach ($qa_content['script_lines'] as $scriptlines) {
$script[] = '';
$script = array_merge($script, $scriptlines);
} }
$script[] = '</script>';
$qa_content['script'] = $script;
// Load the appropriate theme class and output the page $script[] = '</script>';
$tmpl = substr($qa_template, 0, 7) == 'custom-' ? 'custom' : $qa_template; if (isset($qa_content['script_rel'])) {
$themeclass = qa_load_theme_class(qa_get_site_theme(), $tmpl, $qa_content, qa_request()); $uniquerel = array_unique($qa_content['script_rel']); // remove any duplicates
$themeclass->initialize(); foreach ($uniquerel as $script_rel)
$script[] = '<script src="' . qa_html(qa_path_to_root() . $script_rel) . '"></script>';
}
header('Content-type: '.$qa_content['content_type']); if (isset($qa_content['script_src'])) {
$uniquesrc = array_unique($qa_content['script_src']); // remove any duplicates
foreach ($uniquesrc as $script_src)
$script[] = '<script src="' . qa_html($script_src) . '"></script>';
}
$themeclass->doctype(); if (isset($qa_content['focusid'])) {
$themeclass->html(); $qa_content['script_onloads'][] = array(
$themeclass->finish(); '$(' . qa_js('#' . $qa_content['focusid']) . ').focus();',
);
} }
// JS onloads must come after jQuery is loaded
function qa_do_content_stats($qa_content) $script[] = '<script>';
/* if (isset($qa_content['script_onloads'])) {
Update any statistics required by the fields in $qa_content, and return true if something was done $script[] = '$(window).load(function() {';
*/
{ foreach ($qa_content['script_onloads'] as $scriptonload) {
if (isset($qa_content['inc_views_postid'])) { foreach ((array)$scriptonload as $scriptline)
require_once QA_INCLUDE_DIR.'db/hotness.php'; $script[] = "\t" . $scriptline;
qa_db_hotness_update($qa_content['inc_views_postid'], null, true);
return true;
} }
return false; $script[] = '});';
} }
$script[] = '</script>';
$qa_content['script'] = $script;
// Other functions which might be called from anywhere // Load the appropriate theme class and output the page
function qa_page_routing() $tmpl = substr($qa_template, 0, 7) == 'custom-' ? 'custom' : $qa_template;
/* $themeclass = qa_load_theme_class(qa_get_site_theme(), $tmpl, $qa_content, qa_request());
Return an array of the default Q2A requests and which qa-page-*.php file implements them $themeclass->initialize();
If the key of an element ends in /, it should be used for any request with that key as its prefix
*/
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
return array(
'account' => 'pages/account.php',
'activity/' => 'pages/activity.php',
'admin/' => 'pages/admin/admin-default.php',
'admin/approve' => 'pages/admin/admin-approve.php',
'admin/categories' => 'pages/admin/admin-categories.php',
'admin/flagged' => 'pages/admin/admin-flagged.php',
'admin/hidden' => 'pages/admin/admin-hidden.php',
'admin/layoutwidgets' => 'pages/admin/admin-widgets.php',
'admin/moderate' => 'pages/admin/admin-moderate.php',
'admin/pages' => 'pages/admin/admin-pages.php',
'admin/plugins' => 'pages/admin/admin-plugins.php',
'admin/points' => 'pages/admin/admin-points.php',
'admin/recalc' => 'pages/admin/admin-recalc.php',
'admin/stats' => 'pages/admin/admin-stats.php',
'admin/userfields' => 'pages/admin/admin-userfields.php',
'admin/usertitles' => 'pages/admin/admin-usertitles.php',
'answers/' => 'pages/answers.php',
'ask' => 'pages/ask.php',
'categories/' => 'pages/categories.php',
'comments/' => 'pages/comments.php',
'confirm' => 'pages/confirm.php',
'favorites' => 'pages/favorites.php',
'favorites/questions' => 'pages/favorites-list.php',
'favorites/users' => 'pages/favorites-list.php',
'favorites/tags' => 'pages/favorites-list.php',
'feedback' => 'pages/feedback.php',
'forgot' => 'pages/forgot.php',
'hot/' => 'pages/hot.php',
'ip/' => 'pages/ip.php',
'login' => 'pages/login.php',
'logout' => 'pages/logout.php',
'messages/' => 'pages/messages.php',
'message/' => 'pages/message.php',
'questions/' => 'pages/questions.php',
'register' => 'pages/register.php',
'reset' => 'pages/reset.php',
'search' => 'pages/search.php',
'tag/' => 'pages/tag.php',
'tags' => 'pages/tags.php',
'unanswered/' => 'pages/unanswered.php',
'unsubscribe' => 'pages/unsubscribe.php',
'updates' => 'pages/updates.php',
'user/' => 'pages/user.php',
'users' => 'pages/users.php',
'users/blocked' => 'pages/users-blocked.php',
'users/new' => 'pages/users-newest.php',
'users/special' => 'pages/users-special.php',
);
}
header('Content-type: ' . $qa_content['content_type']);
function qa_set_template($template) $themeclass->doctype();
/* $themeclass->html();
Sets the template which should be passed to the theme class, telling it which type of page it's displaying $themeclass->finish();
*/ }
{
global $qa_template;
$qa_template=$template;
}
function qa_content_prepare($voting=false, $categoryids=null) /**
/* * Update any statistics required by the fields in $qa_content, and return true if something was done
Start preparing theme content in global $qa_content variable, with or without $voting support, */
in the context of the categories in $categoryids (if not null) function qa_do_content_stats($qa_content)
*/ {
{ if (isset($qa_content['inc_views_postid'])) {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } require_once QA_INCLUDE_DIR . 'db/hotness.php';
qa_db_hotness_update($qa_content['inc_views_postid'], null, true);
global $qa_template, $qa_page_error_html; return true;
}
if (QA_DEBUG_PERFORMANCE) { return false;
global $qa_usage; }
$qa_usage->mark('control');
}
// Other functions which might be called from anywhere
/**
* Return an array of the default Q2A requests and which qa-page-*.php file implements them
* If the key of an element ends in /, it should be used for any request with that key as its prefix
*/
function qa_page_routing()
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
return array(
'account' => 'pages/account.php',
'activity/' => 'pages/activity.php',
'admin/' => 'pages/admin/admin-default.php',
'admin/approve' => 'pages/admin/admin-approve.php',
'admin/categories' => 'pages/admin/admin-categories.php',
'admin/flagged' => 'pages/admin/admin-flagged.php',
'admin/hidden' => 'pages/admin/admin-hidden.php',
'admin/layoutwidgets' => 'pages/admin/admin-widgets.php',
'admin/moderate' => 'pages/admin/admin-moderate.php',
'admin/pages' => 'pages/admin/admin-pages.php',
'admin/plugins' => 'pages/admin/admin-plugins.php',
'admin/points' => 'pages/admin/admin-points.php',
'admin/recalc' => 'pages/admin/admin-recalc.php',
'admin/stats' => 'pages/admin/admin-stats.php',
'admin/userfields' => 'pages/admin/admin-userfields.php',
'admin/usertitles' => 'pages/admin/admin-usertitles.php',
'answers/' => 'pages/answers.php',
'ask' => 'pages/ask.php',
'categories/' => 'pages/categories.php',
'comments/' => 'pages/comments.php',
'confirm' => 'pages/confirm.php',
'favorites' => 'pages/favorites.php',
'favorites/questions' => 'pages/favorites-list.php',
'favorites/users' => 'pages/favorites-list.php',
'favorites/tags' => 'pages/favorites-list.php',
'feedback' => 'pages/feedback.php',
'forgot' => 'pages/forgot.php',
'hot/' => 'pages/hot.php',
'ip/' => 'pages/ip.php',
'login' => 'pages/login.php',
'logout' => 'pages/logout.php',
'messages/' => 'pages/messages.php',
'message/' => 'pages/message.php',
'questions/' => 'pages/questions.php',
'register' => 'pages/register.php',
'reset' => 'pages/reset.php',
'search' => 'pages/search.php',
'tag/' => 'pages/tag.php',
'tags' => 'pages/tags.php',
'unanswered/' => 'pages/unanswered.php',
'unsubscribe' => 'pages/unsubscribe.php',
'updates' => 'pages/updates.php',
'user/' => 'pages/user.php',
'users' => 'pages/users.php',
'users/blocked' => 'pages/users-blocked.php',
'users/new' => 'pages/users-newest.php',
'users/special' => 'pages/users-special.php',
);
}
/**
* Sets the template which should be passed to the theme class, telling it which type of page it's displaying
*/
function qa_set_template($template)
{
global $qa_template;
$qa_template = $template;
}
/**
* Start preparing theme content in global $qa_content variable, with or without $voting support,
* in the context of the categories in $categoryids (if not null)
*/
function qa_content_prepare($voting=false, $categoryids=null)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
global $qa_template, $qa_page_error_html;
if (QA_DEBUG_PERFORMANCE) {
global $qa_usage;
$qa_usage->mark('control');
}
$request=qa_request(); $request = qa_request();
$requestlower=qa_request(); $requestlower = qa_request();
$navpages=qa_db_get_pending_result('navpages'); $navpages = qa_db_get_pending_result('navpages');
$widgets=qa_db_get_pending_result('widgets'); $widgets = qa_db_get_pending_result('widgets');
if (isset($categoryids) && !is_array($categoryids)) // accept old-style parameter if (isset($categoryids) && !is_array($categoryids)) // accept old-style parameter
$categoryids=array($categoryids); $categoryids = array($categoryids);
$lastcategoryid=count($categoryids) ? end($categoryids) : null; $lastcategoryid = count($categoryids) ? end($categoryids) : null;
$charset = 'utf-8'; $charset = 'utf-8';
$language = qa_opt('site_language'); $language = qa_opt('site_language');
$language = empty($language) ? 'en' : qa_html($language); $language = empty($language) ? 'en' : qa_html($language);
$qa_content=array( $qa_content = array(
'content_type' => 'text/html; charset='.$charset, 'content_type' => 'text/html; charset=' . $charset,
'charset' => $charset, 'charset' => $charset,
'language' => $language, 'language' => $language,
'direction' => qa_opt('site_text_direction'), 'direction' => qa_opt('site_text_direction'),
'options' => array( 'options' => array(
'minify_html' => qa_opt('minify_html'), 'minify_html' => qa_opt('minify_html'),
), ),
'site_title' => qa_html(qa_opt('site_title')), 'site_title' => qa_html(qa_opt('site_title')),
'html_tags' => 'lang="' . $language . '"', 'html_tags' => 'lang="' . $language . '"',
'head_lines' => array(), 'head_lines' => array(),
'navigation' => array( 'navigation' => array(
'user' => array(), 'user' => array(),
'main' => array(), 'main' => array(),
'footer' => array( 'footer' => array(
'feedback' => array( 'feedback' => array(
'url' => qa_path_html('feedback'), 'url' => qa_path_html('feedback'),
'label' => qa_lang_html('main/nav_feedback'), 'label' => qa_lang_html('main/nav_feedback'),
),
), ),
), ),
'sidebar' => qa_opt('show_custom_sidebar') ? qa_opt('custom_sidebar') : null, ),
'sidepanel' => qa_opt('show_custom_sidepanel') ? qa_opt('custom_sidepanel') : null,
'widgets' => array(),
);
// add meta description if we're on the home page
if ($request === '' || $request === array_search('', qa_get_request_map())) {
$qa_content['description'] = qa_html(qa_opt('home_description'));
}
if (qa_opt('show_custom_in_head'))
$qa_content['head_lines'][]=qa_opt('custom_in_head');
if (qa_opt('show_custom_header'))
$qa_content['body_header']=qa_opt('custom_header');
if (qa_opt('show_custom_footer')) 'sidebar' => qa_opt('show_custom_sidebar') ? qa_opt('custom_sidebar') : null,
$qa_content['body_footer']=qa_opt('custom_footer'); 'sidepanel' => qa_opt('show_custom_sidepanel') ? qa_opt('custom_sidepanel') : null,
'widgets' => array(),
);
if (isset($categoryids)) // add meta description if we're on the home page
$qa_content['categoryids']=$categoryids; if ($request === '' || $request === array_search('', qa_get_request_map())) {
$qa_content['description'] = qa_html(qa_opt('home_description'));
}
foreach ($navpages as $page) if (qa_opt('show_custom_in_head'))
if ($page['nav']=='B') $qa_content['head_lines'][] = qa_opt('custom_in_head');
qa_navigation_add_page($qa_content['navigation']['main'], $page);
if (qa_opt('nav_home') && qa_opt('show_custom_home')) if (qa_opt('show_custom_header'))
$qa_content['navigation']['main']['$']=array( $qa_content['body_header'] = qa_opt('custom_header');
'url' => qa_path_html(''),
'label' => qa_lang_html('main/nav_home'),
);
if (qa_opt('nav_activity')) if (qa_opt('show_custom_footer'))
$qa_content['navigation']['main']['activity']=array( $qa_content['body_footer'] = qa_opt('custom_footer');
'url' => qa_path_html('activity'),
'label' => qa_lang_html('main/nav_activity'),
);
$hascustomhome=qa_has_custom_home(); if (isset($categoryids))
$qa_content['categoryids'] = $categoryids;
if (qa_opt($hascustomhome ? 'nav_qa_not_home' : 'nav_qa_is_home')) foreach ($navpages as $page) {
$qa_content['navigation']['main'][$hascustomhome ? 'qa' : '$']=array( if ($page['nav'] == 'B')
'url' => qa_path_html($hascustomhome ? 'qa' : ''), qa_navigation_add_page($qa_content['navigation']['main'], $page);
'label' => qa_lang_html('main/nav_qa'), }
);
if (qa_opt('nav_questions')) if (qa_opt('nav_home') && qa_opt('show_custom_home')) {
$qa_content['navigation']['main']['questions']=array( $qa_content['navigation']['main']['$'] = array(
'url' => qa_path_html('questions'), 'url' => qa_path_html(''),
'label' => qa_lang_html('main/nav_qs'), 'label' => qa_lang_html('main/nav_home'),
); );
}
if (qa_opt('nav_hot')) if (qa_opt('nav_activity')) {
$qa_content['navigation']['main']['hot']=array( $qa_content['navigation']['main']['activity'] = array(
'url' => qa_path_html('hot'), 'url' => qa_path_html('activity'),
'label' => qa_lang_html('main/nav_hot'), 'label' => qa_lang_html('main/nav_activity'),
); );
}
if (qa_opt('nav_unanswered')) $hascustomhome = qa_has_custom_home();
$qa_content['navigation']['main']['unanswered']=array(
'url' => qa_path_html('unanswered'),
'label' => qa_lang_html('main/nav_unanswered'),
);
if (qa_using_tags() && qa_opt('nav_tags')) if (qa_opt($hascustomhome ? 'nav_qa_not_home' : 'nav_qa_is_home')) {
$qa_content['navigation']['main']['tag']=array( $qa_content['navigation']['main'][$hascustomhome ? 'qa' : '$'] = array(
'url' => qa_path_html('tags'), 'url' => qa_path_html($hascustomhome ? 'qa' : ''),
'label' => qa_lang_html('main/nav_tags'), 'label' => qa_lang_html('main/nav_qa'),
'selected_on' => array('tags$', 'tag/'), );
); }
if (qa_using_categories() && qa_opt('nav_categories')) if (qa_opt('nav_questions')) {
$qa_content['navigation']['main']['categories']=array( $qa_content['navigation']['main']['questions'] = array(
'url' => qa_path_html('categories'), 'url' => qa_path_html('questions'),
'label' => qa_lang_html('main/nav_categories'), 'label' => qa_lang_html('main/nav_qs'),
'selected_on' => array('categories$', 'categories/'), );
); }
if (qa_opt('nav_users')) if (qa_opt('nav_hot')) {
$qa_content['navigation']['main']['user']=array( $qa_content['navigation']['main']['hot'] = array(
'url' => qa_path_html('users'), 'url' => qa_path_html('hot'),
'label' => qa_lang_html('main/nav_users'), 'label' => qa_lang_html('main/nav_hot'),
'selected_on' => array('users$', 'users/', 'user/'), );
); }
// Only the 'level' permission error prevents the menu option being shown - others reported on qa-page-ask.php if (qa_opt('nav_unanswered')) {
$qa_content['navigation']['main']['unanswered'] = array(
'url' => qa_path_html('unanswered'),
'label' => qa_lang_html('main/nav_unanswered'),
);
}
if (qa_opt('nav_ask') && (qa_user_maximum_permit_error('permit_post_q')!='level')) if (qa_using_tags() && qa_opt('nav_tags')) {
$qa_content['navigation']['main']['ask']=array( $qa_content['navigation']['main']['tag'] = array(
'url' => qa_path_html('ask', (qa_using_categories() && strlen($lastcategoryid)) ? array('cat' => $lastcategoryid) : null), 'url' => qa_path_html('tags'),
'label' => qa_lang_html('main/nav_ask'), 'label' => qa_lang_html('main/nav_tags'),
); 'selected_on' => array('tags$', 'tag/'),
);
}
if (qa_using_categories() && qa_opt('nav_categories')) {
$qa_content['navigation']['main']['categories'] = array(
'url' => qa_path_html('categories'),
'label' => qa_lang_html('main/nav_categories'),
'selected_on' => array('categories$', 'categories/'),
);
}
if ( if (qa_opt('nav_users')) {
(qa_get_logged_in_level()>=QA_USER_LEVEL_ADMIN) || $qa_content['navigation']['main']['user'] = array(
(!qa_user_maximum_permit_error('permit_moderate')) || 'url' => qa_path_html('users'),
(!qa_user_maximum_permit_error('permit_hide_show')) || 'label' => qa_lang_html('main/nav_users'),
(!qa_user_maximum_permit_error('permit_delete_hidden')) 'selected_on' => array('users$', 'users/', 'user/'),
) );
$qa_content['navigation']['main']['admin']=array( }
'url' => qa_path_html('admin'),
'label' => qa_lang_html('main/nav_admin'),
'selected_on' => array('admin/'),
);
// Only the 'level' permission error prevents the menu option being shown - others reported on qa-page-ask.php
$qa_content['search']=array( if (qa_opt('nav_ask') && qa_user_maximum_permit_error('permit_post_q') != 'level') {
'form_tags' => 'method="get" action="'.qa_path_html('search').'"', $qa_content['navigation']['main']['ask'] = array(
'form_extra' => qa_path_form_html('search'), 'url' => qa_path_html('ask', (qa_using_categories() && strlen($lastcategoryid)) ? array('cat' => $lastcategoryid) : null),
'title' => qa_lang_html('main/search_title'), 'label' => qa_lang_html('main/nav_ask'),
'field_tags' => 'name="q"',
'button_label' => qa_lang_html('main/search_button'),
); );
}
if (!qa_opt('feedback_enabled'))
unset($qa_content['navigation']['footer']['feedback']);
foreach ($navpages as $page)
if ( ($page['nav']=='M') || ($page['nav']=='O') || ($page['nav']=='F') )
qa_navigation_add_page($qa_content['navigation'][($page['nav']=='F') ? 'footer' : 'main'], $page);
$regioncodes=array( if (
'F' => 'full', qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN ||
'M' => 'main', !qa_user_maximum_permit_error('permit_moderate') ||
'S' => 'side', !qa_user_maximum_permit_error('permit_hide_show') ||
!qa_user_maximum_permit_error('permit_delete_hidden')
) {
$qa_content['navigation']['main']['admin'] = array(
'url' => qa_path_html('admin'),
'label' => qa_lang_html('main/nav_admin'),
'selected_on' => array('admin/'),
); );
}
$placecodes=array( $qa_content['search'] = array(
'T' => 'top', 'form_tags' => 'method="get" action="' . qa_path_html('search') . '"',
'H' => 'high', 'form_extra' => qa_path_form_html('search'),
'L' => 'low', 'title' => qa_lang_html('main/search_title'),
'B' => 'bottom', 'field_tags' => 'name="q"',
); 'button_label' => qa_lang_html('main/search_button'),
);
if (!qa_opt('feedback_enabled'))
unset($qa_content['navigation']['footer']['feedback']);
foreach ($navpages as $page) {
if ($page['nav'] == 'M' || $page['nav'] == 'O' || $page['nav'] == 'F') {
$loc = ($page['nav'] == 'F') ? 'footer' : 'main';
qa_navigation_add_page($qa_content['navigation'][$loc], $page);
}
}
foreach ($widgets as $widget) { $regioncodes = array(
$tagstring = ',' . $widget['tags'] . ','; 'F' => 'full',
if (strpos($tagstring, ",$qa_template,") !== false || strpos($tagstring, ',all,') !== false) { 'M' => 'main',
// widget has been selected for display on this template 'S' => 'side',
$region = @$regioncodes[substr($widget['place'], 0, 1)]; );
$place = @$placecodes[substr($widget['place'], 1, 2)];
$placecodes = array(
if (isset($region) && isset($place)) { 'T' => 'top',
// region/place codes recognized 'H' => 'high',
$module = qa_load_module('widget', $widget['title']); 'L' => 'low',
'B' => 'bottom',
if ( );
isset($module) &&
method_exists($module, 'allow_template') && foreach ($widgets as $widget) {
$module->allow_template((substr($qa_template, 0, 7) == 'custom-') ? 'custom' : $qa_template) && $tagstring = ',' . $widget['tags'] . ',';
method_exists($module, 'allow_region') && if (strpos($tagstring, ",$qa_template,") !== false || strpos($tagstring, ',all,') !== false) {
$module->allow_region($region) && // widget has been selected for display on this template
method_exists($module, 'output_widget') $region = @$regioncodes[substr($widget['place'], 0, 1)];
) { $place = @$placecodes[substr($widget['place'], 1, 2)];
// if module loaded and happy to be displayed here, tell theme about it
$qa_content['widgets'][$region][$place][] = $module; if (isset($region) && isset($place)) {
} // region/place codes recognized
$module = qa_load_module('widget', $widget['title']);
if (
isset($module) &&
method_exists($module, 'allow_template') &&
$module->allow_template((substr($qa_template, 0, 7) == 'custom-') ? 'custom' : $qa_template) &&
method_exists($module, 'allow_region') &&
$module->allow_region($region) &&
method_exists($module, 'output_widget')
) {
// if module loaded and happy to be displayed here, tell theme about it
$qa_content['widgets'][$region][$place][] = $module;
} }
} }
} }
}
$logoshow=qa_opt('logo_show'); $logoshow = qa_opt('logo_show');
$logourl=qa_opt('logo_url'); $logourl = qa_opt('logo_url');
$logowidth=qa_opt('logo_width'); $logowidth = qa_opt('logo_width');
$logoheight=qa_opt('logo_height'); $logoheight = qa_opt('logo_height');
if ($logoshow) {
$qa_content['logo'] = '<a href="' . qa_path_html('') . '" class="qa-logo-link" title="' . qa_html(qa_opt('site_title')) . '">' .
'<img src="' . qa_html(is_numeric(strpos($logourl, '://')) ? $logourl : qa_path_to_root() . $logourl) . '"' .
($logowidth ? (' width="' . $logowidth . '"') : '') . ($logoheight ? (' height="' . $logoheight . '"') : '') .
' border="0" alt="' . qa_html(qa_opt('site_title')) . '"/></a>';
} else {
$qa_content['logo'] = '<a href="' . qa_path_html('') . '" class="qa-logo-link">' . qa_html(qa_opt('site_title')) . '</a>';
}
if ($logoshow) $topath = qa_get('to'); // lets user switch between login and register without losing destination page
$qa_content['logo']='<a href="'.qa_path_html('').'" class="qa-logo-link" title="'.qa_html(qa_opt('site_title')).'">'.
'<img src="'.qa_html(is_numeric(strpos($logourl, '://')) ? $logourl : qa_path_to_root().$logourl).'"'.
($logowidth ? (' width="'.$logowidth.'"') : '').($logoheight ? (' height="'.$logoheight.'"') : '').
' border="0" alt="'.qa_html(qa_opt('site_title')).'"/></a>';
else
$qa_content['logo']='<a href="'.qa_path_html('').'" class="qa-logo-link">'.qa_html(qa_opt('site_title')).'</a>';
$topath=qa_get('to'); // lets user switch between login and register without losing destination page $userlinks = qa_get_login_links(qa_path_to_root(), isset($topath) ? $topath : qa_path($request, $_GET, ''));
$userlinks=qa_get_login_links(qa_path_to_root(), isset($topath) ? $topath : qa_path($request, $_GET, '')); $qa_content['navigation']['user'] = array();
$qa_content['navigation']['user']=array(); if (qa_is_logged_in()) {
$qa_content['loggedin'] = qa_lang_html_sub_split('main/logged_in_x', QA_FINAL_EXTERNAL_USERS
? qa_get_logged_in_user_html(qa_get_logged_in_user_cache(), qa_path_to_root(), false)
: qa_get_one_user_html(qa_get_logged_in_handle(), false)
);
if (qa_is_logged_in()) { $qa_content['navigation']['user']['updates'] = array(
$qa_content['loggedin']=qa_lang_html_sub_split('main/logged_in_x', QA_FINAL_EXTERNAL_USERS 'url' => qa_path_html('updates'),
? qa_get_logged_in_user_html(qa_get_logged_in_user_cache(), qa_path_to_root(), false) 'label' => qa_lang_html('main/nav_updates'),
: qa_get_one_user_html(qa_get_logged_in_handle(), false) );
);
$qa_content['navigation']['user']['updates']=array( if (!empty($userlinks['logout']))
'url' => qa_path_html('updates'), $qa_content['navigation']['user']['logout'] = array(
'label' => qa_lang_html('main/nav_updates'), 'url' => qa_html(@$userlinks['logout']),
'label' => qa_lang_html('main/nav_logout'),
); );
if (!empty($userlinks['logout'])) if (!QA_FINAL_EXTERNAL_USERS) {
$qa_content['navigation']['user']['logout']=array( $source = qa_get_logged_in_source();
'url' => qa_html(@$userlinks['logout']),
'label' => qa_lang_html('main/nav_logout'),
);
if (!QA_FINAL_EXTERNAL_USERS) {
$source=qa_get_logged_in_source();
if (strlen($source)) { if (strlen($source)) {
$loginmodules=qa_load_modules_with('login', 'match_source'); $loginmodules = qa_load_modules_with('login', 'match_source');
foreach ($loginmodules as $module) foreach ($loginmodules as $module)
if ($module->match_source($source) && method_exists($module, 'logout_html')) { if ($module->match_source($source) && method_exists($module, 'logout_html')) {
ob_start(); ob_start();
$module->logout_html(qa_path('logout', array(), qa_opt('site_url'))); $module->logout_html(qa_path('logout', array(), qa_opt('site_url')));
$qa_content['navigation']['user']['logout']=array('label' => ob_get_clean()); $qa_content['navigation']['user']['logout'] = array('label' => ob_get_clean());
} }
}
} }
}
$notices=qa_db_get_pending_result('notices'); $notices = qa_db_get_pending_result('notices');
foreach ($notices as $notice) foreach ($notices as $notice)
$qa_content['notices'][]=qa_notice_form($notice['noticeid'], qa_viewer_html($notice['content'], $notice['format']), $notice); $qa_content['notices'][] = qa_notice_form($notice['noticeid'], qa_viewer_html($notice['content'], $notice['format']), $notice);
} else { } else {
require_once QA_INCLUDE_DIR.'util/string.php'; require_once QA_INCLUDE_DIR . 'util/string.php';
if (!QA_FINAL_EXTERNAL_USERS) { if (!QA_FINAL_EXTERNAL_USERS) {
$loginmodules=qa_load_modules_with('login', 'login_html'); $loginmodules = qa_load_modules_with('login', 'login_html');
foreach ($loginmodules as $tryname => $module) { foreach ($loginmodules as $tryname => $module) {
ob_start(); ob_start();
$module->login_html(isset($topath) ? (qa_opt('site_url').$topath) : qa_path($request, $_GET, qa_opt('site_url')), 'menu'); $module->login_html(isset($topath) ? (qa_opt('site_url') . $topath) : qa_path($request, $_GET, qa_opt('site_url')), 'menu');
$label=ob_get_clean(); $label = ob_get_clean();
if (strlen($label)) if (strlen($label))
$qa_content['navigation']['user'][implode('-', qa_string_to_words($tryname))]=array('label' => $label); $qa_content['navigation']['user'][implode('-', qa_string_to_words($tryname))] = array('label' => $label);
}
} }
}
if (!empty($userlinks['login'])) if (!empty($userlinks['login'])) {
$qa_content['navigation']['user']['login']=array( $qa_content['navigation']['user']['login'] = array(
'url' => qa_html(@$userlinks['login']), 'url' => qa_html(@$userlinks['login']),
'label' => qa_lang_html('main/nav_login'), 'label' => qa_lang_html('main/nav_login'),
); );
if (!empty($userlinks['register']))
$qa_content['navigation']['user']['register']=array(
'url' => qa_html(@$userlinks['register']),
'label' => qa_lang_html('main/nav_register'),
);
} }
if (QA_FINAL_EXTERNAL_USERS || !qa_is_logged_in()) { if (!empty($userlinks['register'])) {
if (qa_opt('show_notice_visitor') && (!isset($topath)) && (!isset($_COOKIE['qa_noticed']))) $qa_content['navigation']['user']['register'] = array(
$qa_content['notices'][]=qa_notice_form('visitor', qa_opt('notice_visitor')); 'url' => qa_html(@$userlinks['register']),
'label' => qa_lang_html('main/nav_register'),
);
}
}
} else { if (QA_FINAL_EXTERNAL_USERS || !qa_is_logged_in()) {
setcookie('qa_noticed', 1, time()+86400*3650, '/', QA_COOKIE_DOMAIN, (bool)ini_get('session.cookie_secure'), true); // don't show first-time notice if a user has logged in if (qa_opt('show_notice_visitor') && (!isset($topath)) && (!isset($_COOKIE['qa_noticed'])))
$qa_content['notices'][] = qa_notice_form('visitor', qa_opt('notice_visitor'));
if (qa_opt('show_notice_welcome') && (qa_get_logged_in_flags() & QA_USER_FLAGS_WELCOME_NOTICE) ) } else {
if ( ($requestlower!='confirm') && ($requestlower!='account') ) // let people finish registering in peace setcookie('qa_noticed', 1, time() + 86400 * 3650, '/', QA_COOKIE_DOMAIN, (bool)ini_get('session.cookie_secure'), true); // don't show first-time notice if a user has logged in
$qa_content['notices'][]=qa_notice_form('welcome', qa_opt('notice_welcome'));
}
$qa_content['script_rel']=array('qa-content/jquery-1.11.3.min.js'); if (qa_opt('show_notice_welcome') && (qa_get_logged_in_flags() & QA_USER_FLAGS_WELCOME_NOTICE))
$qa_content['script_rel'][]='qa-content/qa-page.js?'.QA_VERSION; if (($requestlower != 'confirm') && ($requestlower != 'account')) // let people finish registering in peace
$qa_content['notices'][] = qa_notice_form('welcome', qa_opt('notice_welcome'));
}
if ($voting) $qa_content['script_rel'] = array('qa-content/jquery-1.11.3.min.js');
$qa_content['error']=@$qa_page_error_html; $qa_content['script_rel'][] = 'qa-content/qa-page.js?' . QA_VERSION;
$qa_content['script_var']=array( if ($voting)
'qa_root' => qa_path_to_root(), $qa_content['error'] = @$qa_page_error_html;
'qa_request' => $request,
);
return $qa_content; $qa_content['script_var'] = array(
} 'qa_root' => qa_path_to_root(),
'qa_request' => $request,
);
return $qa_content;
}
function qa_get_start()
/*
Get the start parameter which should be used, as constrained by the setting in qa-config.php
*/
{
return min(max(0, (int)qa_get('start')), QA_MAX_LIMIT_START);
}
/**
* Get the start parameter which should be used, as constrained by the setting in qa-config.php
*/
function qa_get_start()
{
return min(max(0, (int)qa_get('start')), QA_MAX_LIMIT_START);
}
function qa_get_state()
/* /**
Get the state parameter which should be used, as set earlier in qa_load_state() * Get the state parameter which should be used, as set earlier in qa_load_state()
*/ */
{ function qa_get_state()
global $qa_state; {
return $qa_state; global $qa_state;
} return $qa_state;
}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/qa-page.php File: qa-include/qa-page.php
Description: Routing and utility functions for page requests Description: Initialization for page requests
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
...@@ -20,51 +20,46 @@ ...@@ -20,51 +20,46 @@
More about this license: http://www.question2answer.org/license.php 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 if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../'); header('Location: ../');
exit; exit;
} }
require_once QA_INCLUDE_DIR.'app/page.php'; require_once QA_INCLUDE_DIR . 'app/page.php';
// Below are the steps that actually execute for this file - all the above are function definitions // Below are the steps that actually execute for this file - all the above are function definitions
global $qa_usage; global $qa_usage;
qa_report_process_stage('init_page'); qa_report_process_stage('init_page');
qa_db_connect('qa_page_db_fail_handler'); qa_db_connect('qa_page_db_fail_handler');
qa_page_queue_pending(); qa_page_queue_pending();
qa_load_state(); qa_load_state();
qa_check_login_modules(); qa_check_login_modules();
if (QA_DEBUG_PERFORMANCE) if (QA_DEBUG_PERFORMANCE)
$qa_usage->mark('setup'); $qa_usage->mark('setup');
qa_check_page_clicks();
$qa_content = qa_get_request_content(); qa_check_page_clicks();
if (is_array($qa_content)) { $qa_content = qa_get_request_content();
if (QA_DEBUG_PERFORMANCE)
$qa_usage->mark('view');
qa_output_content($qa_content); if (is_array($qa_content)) {
if (QA_DEBUG_PERFORMANCE)
if (QA_DEBUG_PERFORMANCE) $qa_usage->mark('view');
$qa_usage->mark('theme');
if (qa_do_content_stats($qa_content) && QA_DEBUG_PERFORMANCE) qa_output_content($qa_content);
$qa_usage->mark('stats');
if (QA_DEBUG_PERFORMANCE) if (QA_DEBUG_PERFORMANCE)
$qa_usage->output(); $qa_usage->mark('theme');
}
qa_db_disconnect(); if (qa_do_content_stats($qa_content) && QA_DEBUG_PERFORMANCE)
$qa_usage->mark('stats');
if (QA_DEBUG_PERFORMANCE)
$qa_usage->output();
}
/* qa_db_disconnect();
Omit PHP closing tag to help avoid accidental output
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment