コード例 #1
0
ファイル: default.php プロジェクト: ronkeizer/question2answer
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
//	Determine whether path begins with qa or not (question and answer listing can be accessed either way)
$requestparts = explode('/', qa_request());
$explicitqa = strtolower($requestparts[0]) == 'qa';
if ($explicitqa) {
    $slugs = array_slice($requestparts, 1);
} elseif (strlen($requestparts[0])) {
    $slugs = $requestparts;
} else {
    $slugs = array();
}
$countslugs = count($slugs);
//	Get list of questions, other bits of information that might be useful
$userid = qa_get_logged_in_userid();
list($questions1, $questions2, $categories, $categoryid, $custompage) = qa_db_select_with_pending(qa_db_qs_selectspec($userid, 'created', 0, $slugs, null, false, false, qa_opt_if_loaded('page_size_activity')), qa_db_recent_a_qs_selectspec($userid, 0, $slugs), qa_db_category_nav_selectspec($slugs, false, false, true), $countslugs ? qa_db_slugs_to_category_id_selectspec($slugs) : null, $countslugs == 1 && !$explicitqa ? qa_db_page_full_selectspec($slugs[0], false) : null);
//	First, if this matches a custom page, return immediately with that page's content
if (isset($custompage) && !($custompage['flags'] & QA_PAGE_FLAGS_EXTERNAL)) {
    qa_set_template('custom-' . $custompage['pageid']);
    $qa_content = qa_content_prepare();
    $level = qa_get_logged_in_level();
    if (!qa_permit_value_error($custompage['permit'], $userid, $level, qa_get_logged_in_flags()) || !isset($custompage['permit'])) {
        $qa_content['title'] = qa_html($custompage['heading']);
        $qa_content['custom'] = $custompage['content'];
        if ($level >= QA_USER_LEVEL_ADMIN) {
            $qa_content['navigation']['sub'] = array('admin/pages' => array('label' => qa_lang('admin/edit_custom_page'), 'url' => qa_path_html('admin/pages', array('edit' => $custompage['pageid']))));
        }
    } else {
        $qa_content['error'] = qa_lang_html('users/no_permission');
    }
    return $qa_content;
コード例 #2
0
 for ($attempt = 0; $attempt < 100; $attempt++) {
     switch ($attempt) {
         case 0:
             $inslug = qa_post_text('slug');
             if (!isset($inslug)) {
                 $inslug = implode('-', qa_string_to_words($inname));
             }
             break;
         case 1:
             $inslug = qa_lang_sub('admin/page_default_slug', $inslug);
             break;
         default:
             $inslug = qa_lang_sub('admin/page_default_slug', $attempt - 1);
             break;
     }
     list($matchcategoryid, $matchpage) = qa_db_select_with_pending(qa_db_slugs_to_category_id_selectspec($inslug), qa_db_page_full_selectspec($inslug, false));
     if (empty($inslug)) {
         $errors['slug'] = qa_lang('main/field_required');
     } elseif (qa_strlen($inslug) > QA_DB_MAX_CAT_PAGE_TAGS_LENGTH) {
         $errors['slug'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TAGS_LENGTH);
     } elseif (preg_match('/[\\+\\/]/', $inslug)) {
         $errors['slug'] = qa_lang_sub('admin/slug_bad_chars', '+ /');
     } elseif (qa_admin_is_slug_reserved($inslug)) {
         $errors['slug'] = qa_lang('admin/slug_reserved');
     } elseif (isset($matchpage) && $matchpage['pageid'] != @$editpage['pageid']) {
         $errors['slug'] = qa_lang('admin/page_already_used');
     } elseif (isset($matchcategoryid)) {
         $errors['slug'] = qa_lang('admin/category_already_used');
     } else {
         unset($errors['slug']);
     }
コード例 #3
0
         $inslug = qa_post_text('slug');
         if (!isset($inslug)) {
             $inslug = implode('-', qa_string_to_words($inname));
         }
         break;
     case 1:
         $inslug = qa_lang_sub('admin/category_default_slug', $inslug);
         break;
     default:
         $inslug = qa_lang_sub('admin/category_default_slug', $attempt - 1);
         break;
 }
 $matchcategoryid = qa_db_category_slug_to_id($inparentid, $inslug);
 // query against DB since MySQL ignores accents, etc...
 if (!isset($inparentid)) {
     $matchpage = qa_db_single_select(qa_db_page_full_selectspec($inslug, false));
 } else {
     $matchpage = null;
 }
 if (empty($inslug)) {
     $errors['slug'] = qa_lang('main/field_required');
 } elseif (qa_strlen($inslug) > QA_DB_MAX_CAT_PAGE_TAGS_LENGTH) {
     $errors['slug'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TAGS_LENGTH);
 } elseif (preg_match('/[\\+\\/]/', $inslug)) {
     $errors['slug'] = qa_lang_sub('admin/slug_bad_chars', '+ /');
 } elseif (!isset($inparentid) && qa_admin_is_slug_reserved($inslug)) {
     // only top level is a problem
     $errors['slug'] = qa_lang('admin/slug_reserved');
 } elseif (isset($matchcategoryid) && strcmp($matchcategoryid, @$editcategory['categoryid'])) {
     $errors['slug'] = qa_lang('admin/category_already_used');
 } elseif (isset($matchpage)) {
コード例 #4
0
qa_report_event('page_enter', qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), array('params' => $_SERVER['QUERY_STRING'], 'path' => $_SERVER['SCRIPT_NAME']));
require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
require_once QA_INCLUDE_DIR . 'qa-app-format.php';
//	Determine whether path begins with qa or not (question and answer listing can be accessed either way)
$explicitqa = $qa_request_lc_parts[0] == 'qa';
if ($explicitqa) {
    $slugs = array_slice($qa_request_parts, 1);
} elseif (strlen($qa_request_parts[0])) {
    // $qa_request_parts[0] always present so we need to check its length
    $slugs = $qa_request_parts;
} else {
    $slugs = array();
}
$countslugs = count($slugs);
//	Get list of questions, other bits of information that might be
@(list($questions1, $questions2, $categories, $categoryid, $custompage) = qa_db_select_with_pending(qa_db_qs_selectspec($qa_login_userid, 'created', 0, $slugs), qa_db_recent_a_qs_selectspec($qa_login_userid, 0, $slugs), qa_db_category_nav_selectspec($slugs, false), $countslugs ? qa_db_slugs_to_category_id_selectspec($slugs) : null, $countslugs == 1 && !$explicitqa ? qa_db_page_full_selectspec($slugs[0], false) : null));
//	First, if this matches a custom page, return immediately with that page's content
if (isset($custompage) && !($custompage['flags'] & QA_PAGE_FLAGS_EXTERNAL)) {
    $qa_template = 'custom';
    $qa_content = qa_content_prepare();
    $qa_content['title'] = qa_html($custompage['heading']);
    $qa_content['custom'] = $custompage['content'];
    if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
        $qa_content['navigation']['sub'] = array('admin/pages' => array('label' => qa_lang('admin/edit_custom_page'), 'url' => qa_path_html('admin/pages', array('edit' => $custompage['pageid']))));
    }
    return $qa_content;
}
//	Then, see if we should redirect because the 'qa' page is the same as the home page
if ($explicitqa && !qa_is_http_post() && !qa_has_custom_home()) {
    qa_redirect(qa_category_path_request($categories, $categoryid), $_GET);
}