Beispiel #1
0
function qa_has_custom_home()
{
    return qa_opt('show_custom_home') || array_search('', qa_get_request_map()) !== false;
}
Beispiel #2
0
function qa_admin_is_slug_reserved($requestpart)
{
    $requestpart = trim(strtolower($requestpart));
    $routing = qa_page_routing();
    if (isset($routing[$requestpart]) || isset($routing[$requestpart . '/']) || is_numeric($requestpart)) {
        return true;
    }
    $pathmap = qa_get_request_map();
    foreach ($pathmap as $mappedrequest) {
        if (trim(strtolower($mappedrequest)) == $requestpart) {
            return true;
        }
    }
    switch ($requestpart) {
        case '':
        case 'qa':
        case 'feed':
        case 'install':
        case 'url':
        case 'image':
        case 'ajax':
            return true;
    }
    $pagemodules = qa_load_modules_with('page', 'match_request');
    foreach ($pagemodules as $pagemodule) {
        if ($pagemodule->match_request($requestpart)) {
            return true;
        }
    }
    return false;
}
Beispiel #3
0
function qa_path($request, $params = null, $rooturl = null, $neaturls = null, $anchor = null)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    if (!isset($neaturls)) {
        require_once QA_INCLUDE_DIR . 'qa-app-options.php';
        $neaturls = qa_opt('neat_urls');
    }
    if (!isset($rooturl)) {
        $rooturl = qa_path_to_root();
    }
    $url = $rooturl . (empty($rooturl) || substr($rooturl, -1) == '/' ? '' : '/');
    $paramsextra = '';
    $requestparts = explode('/', $request);
    $pathmap = qa_get_request_map();
    if (isset($pathmap[$requestparts[0]])) {
        $newpart = $pathmap[$requestparts[0]];
        if (strlen($newpart)) {
            $requestparts[0] = $newpart;
        } elseif (count($requestparts) == 1) {
            array_shift($requestparts);
        }
    }
    foreach ($requestparts as $index => $requestpart) {
        $requestparts[$index] = urlencode($requestpart);
    }
    $requestpath = implode('/', $requestparts);
    switch ($neaturls) {
        case QA_URL_FORMAT_INDEX:
            if (!empty($request)) {
                $url .= 'index.php/' . $requestpath;
            }
            break;
        case QA_URL_FORMAT_NEAT:
            $url .= $requestpath;
            break;
        case QA_URL_FORMAT_PARAM:
            if (!empty($request)) {
                $paramsextra = '?qa=' . $requestpath;
            }
            break;
        default:
            $url .= 'index.php';
        case QA_URL_FORMAT_PARAMS:
            if (!empty($request)) {
                foreach ($requestparts as $partindex => $requestpart) {
                    $paramsextra .= (strlen($paramsextra) ? '&' : '?') . 'qa' . ($partindex ? '_' . $partindex : '') . '=' . $requestpart;
                }
            }
            break;
    }
    if (isset($params)) {
        foreach ($params as $key => $value) {
            $paramsextra .= (strlen($paramsextra) ? '&' : '?') . urlencode($key) . '=' . urlencode((string) $value);
        }
    }
    return $url . $paramsextra . (empty($anchor) ? '' : '#' . urlencode($anchor));
}
Beispiel #4
0
 function qa_index_set_request()
 {
     if (qa_to_override(__FUNCTION__)) {
         $args = func_get_args();
         return qa_call_override(__FUNCTION__, $args);
     }
     $relativedepth = 0;
     if (isset($_GET['qa-rewrite'])) {
         // URLs rewritten by .htaccess
         $urlformat = QA_URL_FORMAT_NEAT;
         $requestparts = explode('/', qa_gpc_to_string($_GET['qa-rewrite']));
         unset($_GET['qa-rewrite']);
         if (!empty($_SERVER['REQUEST_URI'])) {
             // workaround for the fact that Apache unescapes characters while rewriting
             $origpath = $_SERVER['REQUEST_URI'];
             $_GET = array();
             $questionpos = strpos($origpath, '?');
             if (is_numeric($questionpos)) {
                 $params = explode('&', substr($origpath, $questionpos + 1));
                 foreach ($params as $param) {
                     if (preg_match('/^([^\\=]*)(\\=(.*))?$/', $param, $matches)) {
                         $argument = strtr(urldecode($matches[1]), '.', '_');
                         // simulate PHP's $_GET behavior
                         $_GET[$argument] = qa_string_to_gpc(urldecode(@$matches[3]));
                     }
                 }
                 $origpath = substr($origpath, 0, $questionpos);
             }
             // Generally we assume that $_GET['qa-rewrite'] has the right path depth, but this won't be the case if there's
             // a & or # somewhere in the middle of the path, due to apache unescaping. So we make a special case for that.
             $keepparts = count($requestparts);
             $requestparts = explode('/', urldecode($origpath));
             // new request calculated from $_SERVER['REQUEST_URI']
             for ($part = count($requestparts) - 1; $part >= 0; $part--) {
                 if (is_numeric(strpos($requestparts[$part], '&')) || is_numeric(strpos($requestparts[$part], '#'))) {
                     $keepparts += count($requestparts) - $part - 1;
                     // this is how many parts we lost
                     break;
                 }
             }
             $requestparts = array_slice($requestparts, -$keepparts);
             // remove any irrelevant parts from the beginning
         }
         $relativedepth = count($requestparts);
     } elseif (isset($_GET['qa'])) {
         if (strpos($_GET['qa'], '/') === false) {
             $urlformat = empty($_SERVER['REQUEST_URI']) || strpos($_SERVER['REQUEST_URI'], '/index.php') !== false ? QA_URL_FORMAT_SAFEST : QA_URL_FORMAT_PARAMS;
             $requestparts = array(qa_gpc_to_string($_GET['qa']));
             for ($part = 1; $part < 10; $part++) {
                 if (isset($_GET['qa_' . $part])) {
                     $requestparts[] = qa_gpc_to_string($_GET['qa_' . $part]);
                     unset($_GET['qa_' . $part]);
                 }
             }
         } else {
             $urlformat = QA_URL_FORMAT_PARAM;
             $requestparts = explode('/', qa_gpc_to_string($_GET['qa']));
         }
         unset($_GET['qa']);
     } else {
         $phpselfunescaped = strtr($_SERVER['PHP_SELF'], '+', ' ');
         // seems necessary, and plus does not work with this scheme
         $indexpath = '/index.php/';
         $indexpos = strpos($phpselfunescaped, $indexpath);
         if (is_numeric($indexpos)) {
             $urlformat = QA_URL_FORMAT_INDEX;
             $requestparts = explode('/', substr($phpselfunescaped, $indexpos + strlen($indexpath)));
             $relativedepth = 1 + count($requestparts);
         } else {
             $urlformat = null;
             // at home page so can't identify path type
             $requestparts = array();
         }
     }
     foreach ($requestparts as $part => $requestpart) {
         // remove any blank parts
         if (!strlen($requestpart)) {
             unset($requestparts[$part]);
         }
     }
     reset($requestparts);
     $key = key($requestparts);
     $replacement = array_search(@$requestparts[$key], qa_get_request_map());
     if ($replacement !== false) {
         $requestparts[$key] = $replacement;
     }
     qa_set_request(implode('/', $requestparts), $relativedepth > 1 ? str_repeat('../', $relativedepth - 1) : './', $urlformat);
 }
Beispiel #5
0
 function qa_index_set_request()
 {
     if (qa_to_override(__FUNCTION__)) {
         $args = func_get_args();
         return qa_call_override(__FUNCTION__, $args);
     }
     $relativedepth = 0;
     if (isset($_GET['qa-rewrite'])) {
         // URLs rewritten by .htaccess
         $urlformat = QA_URL_FORMAT_NEAT;
         $requestparts = explode('/', qa_gpc_to_string($_GET['qa-rewrite']));
         unset($_GET['qa-rewrite']);
         $relativedepth = count($requestparts);
         // Workaround for fact that Apache unescapes characters while rewriting, based on assumption that $_GET['qa-rewrite'] has
         // right path depth, which is true do long as there are only escaped characters in the last part of the path
         if (!empty($_SERVER['REQUEST_URI'])) {
             $origpath = $_SERVER['REQUEST_URI'];
             $_GET = array();
             $questionpos = strpos($origpath, '?');
             if (is_numeric($questionpos)) {
                 $params = explode('&', substr($origpath, $questionpos + 1));
                 foreach ($params as $param) {
                     if (preg_match('/^([^\\=]*)(\\=(.*))?$/', $param, $matches)) {
                         $_GET[urldecode($matches[1])] = qa_string_to_gpc(urldecode(@$matches[3]));
                     }
                 }
                 $origpath = substr($origpath, 0, $questionpos);
             }
             $requestparts = array_slice(explode('/', urldecode($origpath)), -count($requestparts));
         }
     } elseif (isset($_GET['qa'])) {
         if (strpos($_GET['qa'], '/') === false) {
             $urlformat = empty($_SERVER['REQUEST_URI']) || strpos($_SERVER['REQUEST_URI'], '/index.php') !== false ? QA_URL_FORMAT_SAFEST : QA_URL_FORMAT_PARAMS;
             $requestparts = array(qa_gpc_to_string($_GET['qa']));
             for ($part = 1; $part < 10; $part++) {
                 if (isset($_GET['qa_' . $part])) {
                     $requestparts[] = qa_gpc_to_string($_GET['qa_' . $part]);
                     unset($_GET['qa_' . $part]);
                 }
             }
         } else {
             $urlformat = QA_URL_FORMAT_PARAM;
             $requestparts = explode('/', qa_gpc_to_string($_GET['qa']));
         }
         unset($_GET['qa']);
     } else {
         $phpselfunescaped = strtr($_SERVER['PHP_SELF'], '+', ' ');
         // seems necessary, and plus does not work with this scheme
         $indexpath = '/index.php/';
         $indexpos = strpos($phpselfunescaped, $indexpath);
         if (is_numeric($indexpos)) {
             $urlformat = QA_URL_FORMAT_INDEX;
             $requestparts = explode('/', substr($phpselfunescaped, $indexpos + strlen($indexpath)));
             $relativedepth = 1 + count($requestparts);
         } else {
             $urlformat = null;
             // at home page so can't identify path type
             $requestparts = array();
         }
     }
     foreach ($requestparts as $part => $requestpart) {
         // remove any blank parts
         if (!strlen($requestpart)) {
             unset($requestparts[$part]);
         }
     }
     reset($requestparts);
     $key = key($requestparts);
     $replacement = array_search(@$requestparts[$key], qa_get_request_map());
     if ($replacement !== false) {
         $requestparts[$key] = $replacement;
     }
     qa_set_request(implode('/', $requestparts), $relativedepth > 1 ? str_repeat('../', $relativedepth - 1) : './', $urlformat);
 }
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();
    $requestlower = qa_request();
    $navpages = qa_db_get_pending_result('navpages');
    $widgets = qa_db_get_pending_result('widgets');
    if (isset($categoryids) && !is_array($categoryids)) {
        // accept old-style parameter
        $categoryids = array($categoryids);
    }
    $lastcategoryid = count($categoryids) ? end($categoryids) : null;
    $charset = 'utf-8';
    $qa_content = array('content_type' => 'text/html; charset=' . $charset, 'charset' => $charset, 'direction' => qa_opt('site_text_direction'), 'site_title' => qa_html(qa_opt('site_title')), 'head_lines' => array(), 'navigation' => array('user' => array(), 'main' => array(), 'footer' => array('feedback' => array('url' => qa_path_html('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')) {
        $qa_content['body_footer'] = qa_opt('custom_footer');
    }
    if (isset($categoryids)) {
        $qa_content['categoryids'] = $categoryids;
    }
    foreach ($navpages as $page) {
        if ($page['nav'] == 'B') {
            qa_navigation_add_page($qa_content['navigation']['main'], $page);
        }
    }
    if (qa_opt('nav_home') && qa_opt('show_custom_home')) {
        $qa_content['navigation']['main']['$'] = array('url' => qa_path_html(''), 'label' => qa_lang_html('main/nav_home'));
    }
    if (qa_opt('nav_activity')) {
        $qa_content['navigation']['main']['activity'] = array('url' => qa_path_html('activity'), 'label' => qa_lang_html('main/nav_activity'));
    }
    $hascustomhome = qa_has_custom_home();
    if (qa_opt($hascustomhome ? 'nav_qa_not_home' : 'nav_qa_is_home')) {
        $qa_content['navigation']['main'][$hascustomhome ? 'qa' : '$'] = array('url' => qa_path_html($hascustomhome ? 'qa' : ''), 'label' => qa_lang_html('main/nav_qa'));
    }
    if (qa_opt('nav_questions')) {
        $qa_content['navigation']['main']['questions'] = array('url' => qa_path_html('questions'), 'label' => qa_lang_html('main/nav_qs'));
    }
    if (qa_opt('nav_hot')) {
        $qa_content['navigation']['main']['hot'] = array('url' => qa_path_html('hot'), 'label' => qa_lang_html('main/nav_hot'));
    }
    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_using_tags() && qa_opt('nav_tags')) {
        $qa_content['navigation']['main']['tag'] = array('url' => qa_path_html('tags'), '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 (qa_opt('nav_users')) {
        $qa_content['navigation']['main']['user'] = array('url' => qa_path_html('users'), 'label' => qa_lang_html('main/nav_users'), '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_ask') && qa_user_maximum_permit_error('permit_post_q') != 'level') {
        $qa_content['navigation']['main']['ask'] = array('url' => qa_path_html('ask', qa_using_categories() && strlen($lastcategoryid) ? array('cat' => $lastcategoryid) : null), 'label' => qa_lang_html('main/nav_ask'));
    }
    if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN || !qa_user_maximum_permit_error('permit_moderate') || !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/'));
    }
    $qa_content['search'] = array('form_tags' => 'method="get" action="' . qa_path_html('search') . '"', 'form_extra' => qa_path_form_html('search'), 'title' => qa_lang_html('main/search_title'), '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('F' => 'full', 'M' => 'main', 'S' => 'side');
    $placecodes = array('T' => 'top', 'H' => 'high', 'L' => 'low', 'B' => 'bottom');
    foreach ($widgets as $widget) {
        if (is_numeric(strpos(',' . $widget['tags'] . ',', ',' . $qa_template . ',')) || is_numeric(strpos(',' . $widget['tags'] . ',', ',all,'))) {
            // see if it has been selected for display on this template
            $region = @$regioncodes[substr($widget['place'], 0, 1)];
            $place = @$placecodes[substr($widget['place'], 1, 2)];
            if (isset($region) && isset($place)) {
                // check 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')) {
                    $qa_content['widgets'][$region][$place][] = $module;
                }
                // if module loaded and happy to be displayed here, tell theme about it
            }
        }
    }
    $logoshow = qa_opt('logo_show');
    $logourl = qa_opt('logo_url');
    $logowidth = qa_opt('logo_width');
    $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>';
    }
    $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, ''));
    $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));
        $qa_content['navigation']['user']['updates'] = array('url' => qa_path_html('updates'), 'label' => qa_lang_html('main/nav_updates'));
        if (!empty($userlinks['logout'])) {
            $qa_content['navigation']['user']['logout'] = array('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)) {
                $loginmodules = qa_load_modules_with('login', 'match_source');
                foreach ($loginmodules as $module) {
                    if ($module->match_source($source) && method_exists($module, 'logout_html')) {
                        ob_start();
                        $module->logout_html(qa_path('logout', array(), qa_opt('site_url')));
                        $qa_content['navigation']['user']['logout'] = array('label' => ob_get_clean());
                    }
                }
            }
        }
        $notices = qa_db_get_pending_result('notices');
        foreach ($notices as $notice) {
            $qa_content['notices'][] = qa_notice_form($notice['noticeid'], qa_viewer_html($notice['content'], $notice['format']), $notice);
        }
    } else {
        require_once QA_INCLUDE_DIR . 'util/string.php';
        if (!QA_FINAL_EXTERNAL_USERS) {
            $loginmodules = qa_load_modules_with('login', 'login_html');
            foreach ($loginmodules as $tryname => $module) {
                ob_start();
                $module->login_html(isset($topath) ? qa_opt('site_url') . $topath : qa_path($request, $_GET, qa_opt('site_url')), 'menu');
                $label = ob_get_clean();
                if (strlen($label)) {
                    $qa_content['navigation']['user'][implode('-', qa_string_to_words($tryname))] = array('label' => $label);
                }
            }
        }
        if (!empty($userlinks['login'])) {
            $qa_content['navigation']['user']['login'] = array('url' => qa_html(@$userlinks['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 (qa_opt('show_notice_visitor') && !isset($topath) && !isset($_COOKIE['qa_noticed'])) {
            $qa_content['notices'][] = qa_notice_form('visitor', qa_opt('notice_visitor'));
        }
    } else {
        setcookie('qa_noticed', 1, time() + 86400 * 3650, '/', QA_COOKIE_DOMAIN);
        // don't show first-time notice if a user has logged in
        if (qa_opt('show_notice_welcome') && qa_get_logged_in_flags() & QA_USER_FLAGS_WELCOME_NOTICE) {
            if ($requestlower != 'confirm' && $requestlower != 'account') {
                // let people finish registering in peace
                $qa_content['notices'][] = qa_notice_form('welcome', qa_opt('notice_welcome'));
            }
        }
    }
    $qa_content['script_rel'] = array('qa-content/jquery-1.11.3.min.js');
    $qa_content['script_rel'][] = 'qa-content/qa-page.js?' . QA_VERSION;
    if ($voting) {
        $qa_content['error'] = @$qa_page_error_html;
    }
    $qa_content['script_var'] = array('qa_root' => qa_path_to_root(), 'qa_request' => $request);
    return $qa_content;
}