function qa_wall_error_html($fromuserid, $touserid, $touserflags)
{
    require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    if (!QA_FINAL_EXTERNAL_USERS && qa_opt('allow_user_walls')) {
        if ($touserflags & QA_USER_FLAGS_NO_WALL_POSTS && !(isset($fromuserid) && $fromuserid == $touserid)) {
            return qa_lang_html('profile/post_wall_blocked');
        } else {
            switch (qa_user_permit_error('permit_post_wall', QA_LIMIT_WALL_POSTS)) {
                case 'limit':
                    return qa_lang_html('profile/post_wall_limit');
                    break;
                case 'login':
                    return qa_insert_login_links(qa_lang_html('profile/post_wall_must_login'), qa_request());
                    break;
                case 'confirm':
                    return qa_insert_login_links(qa_lang_html('profile/post_wall_must_confirm'), qa_request());
                    break;
                case 'approve':
                    return qa_lang_html('profile/post_wall_must_be_approved');
                    break;
                case false:
                    return false;
                    break;
            }
        }
    }
    return qa_lang_html('users/no_permission');
}
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     /*
     $requestparts=qa_request_parts();
     $requestlower=strtolower(qa_request());
     $firstlower=strtolower($requestparts[0]);
     $routing=qa_page_routing();
     // unanswered & questions pages may contain categories.
     unset($routing['activity/']);
     unset($routing['unanswered/']);
     unset($routing['questions/']);
     if ( (isset($routing[$requestlower])) or (isset($routing[$firstlower.'/'])) or (is_numeric($requestparts[0])) )
     	return;
     	
     $explicitqa=(strtolower($requestparts[0])=='qa' or strtolower($requestparts[0])=='unanswered' or strtolower($requestparts[0])=='questions' or strtolower($requestparts[0])=='activity');
     
     if ($explicitqa)
     	$slugs=array_slice($requestparts, 1);
     elseif (strlen($requestparts[0]))
     	$slugs=$requestparts;
     else
     	$slugs=array();
     */
     $slugs = useo_get_current_category_slug();
     $countslugs = count($slugs);
     list($categories, $categoryid) = qa_db_select_with_pending(qa_db_category_nav_selectspec($slugs, false, false, true), $countslugs ? qa_db_slugs_to_category_id_selectspec($slugs) : null);
     if ($countslugs && isset($categoryid)) {
         /*
         $categoryid is current categories ID
         $backpath = implode('/', array_reverse($slugs));
         echo "countslugs: <pre>"; var_dump($countslugs); echo "</pre>";
         $fullcategory=qa_db_select_with_pending(qa_db_full_category_selectspec($categoryid, true));
         echo "fullcategory: <pre>"; var_dump($fullcategory); echo "</pre>";
         
         echo "categoryid: <pre>"; var_dump($categoryid); echo "</pre>";
         echo "slugs: <pre>"; var_dump($slugs); echo "</pre>";
         echo "template: <pre>"; var_dump($template); echo "</pre>";
         echo "request: <pre>"; var_dump($request); echo "</pre>";
         */
         require_once QA_INCLUDE_DIR . 'qa-db-metas.php';
         $description = qa_db_categorymeta_get($categoryid, 'useo_cat_description');
         if (!qa_opt('useo_cat_desc_format')) {
             $description = qa_html($description);
         }
         $editurlhtml = qa_path_html('category-edit/' . $categoryid);
         $allowediting = !qa_user_permit_error('useo_cat_desc_permit_edit');
         if (strlen($description)) {
             echo '<SPAN CLASS="entry-content qa-category-description">';
             echo $description;
             echo '</SPAN>';
             if ($allowediting) {
                 echo ' - <A HREF="' . $editurlhtml . '">edit</A>';
             }
         } elseif ($allowediting) {
             echo '<A HREF="' . $editurlhtml . '">' . qa_lang_html('useo/create_desc_link') . '</A>';
         }
     }
 }
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-users.php';
     $allowEdit = !qa_user_permit_error('fb_share_permit_edit');
     $parts = explode('/', qa_self_html());
     if ($allowEdit && $parts[2] == qa_get_logged_in_handle()) {
         $appid = qa_opt('fb_app_id');
         $secret = qa_opt('fb_app_secret');
         $fb = new Facebook\Facebook(['app_id' => $appid, 'app_secret' => $secret, 'default_graph_version' => 'v2.4']);
         $helper = $fb->getRedirectLoginHelper();
         $permissions = ['email', 'publish_actions'];
         $callback = 'http://nathorr.com/qeta/fb-share/' . qa_get_logged_in_handle() . '/';
         $loginUrl = $helper->getLoginUrl($callback, $permissions);
         echo '<a href="' . $loginUrl . '"><img src="http://oi57.tinypic.com/f1xlbt.jpg"></a>';
     }
 }
 function doctype()
 {
     qa_html_theme_base::doctype();
     if (qa_opt('cp_enable') && ($this->template == 'ask' || isset($this->content['q_list']) || isset($this->content['q_view']))) {
         global $qa_request;
         global $wiki_enable;
         if ($this->template == 'ask' && !qa_user_permit_error('permit_post_q') && !qa_opt('site_maintenance') && qa_permit_check('permit_create_cp')) {
             $this->content['form']['tags'] .= ' onSubmit="pollSubmit(event)"';
             $this->content['form']['fields'][] = array('label' => qa_lang('cp/checkbox_text'), 'tags' => 'NAME="cp_community" ID="cp_community"', 'type' => 'checkbox', 'value' => qa_post_text('cp_community') ? 1 : 0);
         }
         if (isset($this->content['q_view'])) {
             $qid = $this->content['q_view']['raw']['postid'];
             $author = $this->content['q_view']['raw']['userid'];
             if (!isset($wiki_enable)) {
                 $result = qa_db_query_sub('SELECT * FROM ^postmeta WHERE meta_key=$ AND post_id=#', 'is_community', $qid);
                 $wiki_enable = $result->num_rows > 0;
             }
             if ($wiki_enable) {
                 // is a community post
                 $this->content['title'] .= ' ' . qa_lang('cp/question_title');
                 // $this->content['q_view']['content'] = @$this->content['q_view']['content'].'<div id="qa-wiki-div">'.$this->getPollDiv($qid,qa_get_logged_in_userid()).'</div>';
                 $this->content['q_view']['main_form_tags'] = @$this->content['q_view']['main_form_tags'] . ' class="qa-community-posts"';
                 // print_r($this->content['q_view']['form']['buttons']);
                 if (isset($this->content['q_view']['form']['buttons']['edit'])) {
                     $this->content['q_view']['form']['buttons']['edit']['label'] = qa_lang_html('cp/contribute');
                     $this->content['q_view']['form']['buttons']['edit']['popup'] = qa_lang_html('cp/contribute_description');
                 }
                 unset($this->content['q_view']['form']['buttons']['answer']);
                 unset($this->content['q_view']['form']['buttons']['comment']);
                 unset($this->content['a_form']);
                 unset($this->content['c_form']);
             }
         }
         if (isset($this->content['q_list'])) {
             $wiki_array = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^postmeta WHERE meta_key=$', 'is_community'));
             foreach ($wiki_array as $q) {
                 $wiki[(int) $q['post_id']] = $q['meta_value'];
             }
             foreach ($this->content['q_list']['qs'] as $idx => $question) {
                 if (isset($wiki[$question['raw']['postid']])) {
                     $this->content['q_list']['qs'][$idx]['title'] .= ' ' . qa_lang('cp/question_title');
                 }
             }
         }
     }
 }
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     require_once QA_INCLUDE_DIR . 'qa-db-metas.php';
     $parts = explode('/', $request);
     $tag = $parts[1];
     $description = qa_db_tagmeta_get($tag, 'description');
     if (!qa_opt('useo_tag_desc_sidebar_html')) {
         $description = qa_html($description);
     }
     $editurlhtml = qa_path_html('tag-edit/' . $tag);
     $allowediting = !qa_user_permit_error('useo_tag_desc_permit_edit');
     if (strlen($description)) {
         echo '<SPAN CLASS="entry-content qa-tag-description">';
         echo $description;
         echo '</SPAN>';
         if ($allowediting) {
             echo ' - <A HREF="' . $editurlhtml . '">edit</A>';
         }
     } elseif ($allowediting) {
         echo '<A HREF="' . $editurlhtml . '">' . qa_lang_html('useo/create_desc_link') . '</A>';
     }
 }
 function process_request($request)
 {
     $parts = explode('/', $request);
     $tag = $parts[1];
     $qa_content = qa_content_prepare();
     $qa_content['title'] = qa_lang_html_sub('useo/edit_desc_for_x', qa_html($tag));
     if (qa_user_permit_error('useo_tag_desc_permit_edit')) {
         $qa_content['error'] = qa_lang_html('users/no_permission');
         return $qa_content;
     }
     require_once QA_INCLUDE_DIR . 'qa-db-metas.php';
     if (qa_clicked('dosave')) {
         require_once QA_INCLUDE_DIR . 'qa-util-string.php';
         $taglc = qa_strtolower($tag);
         qa_db_tagmeta_set($taglc, 'title', qa_post_text('tagtitle'));
         qa_db_tagmeta_set($taglc, 'description', qa_post_text('tagdesc'));
         qa_db_tagmeta_set($taglc, 'icon', qa_post_text('tagicon'));
         qa_redirect('tag/' . $tag);
     }
     $qa_content['form'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array(array('label' => 'Title:', 'type' => 'text', 'rows' => 2, 'tags' => 'NAME="tagtitle" ID="tagtitle"', 'value' => qa_html(qa_db_tagmeta_get($tag, 'title'))), array('label' => 'Description:', 'type' => 'text', 'rows' => 4, 'tags' => 'NAME="tagdesc" ID="tagdesc"', 'value' => qa_html(qa_db_tagmeta_get($tag, 'description'))), array('label' => 'Icon image:', 'type' => 'text', 'rows' => 1, 'tags' => 'NAME="tagicon" ID="tagicon"', 'value' => qa_html(qa_db_tagmeta_get($tag, 'icon')))), 'buttons' => array(array('tags' => 'NAME="dosave"', 'label' => qa_lang_html('useo/save_desc_button'))));
     $qa_content['focusid'] = 'tagdesc';
     return $qa_content;
 }
 function process_request($request)
 {
     $parts = explode('/', $request);
     $categoryid = $parts[1];
     $fullcategory = qa_db_select_with_pending(qa_db_full_category_selectspec($categoryid, true));
     $slugs = explode('/', $fullcategory['backpath']);
     $new_request = implode('/', array_reverse($slugs));
     $qa_content = qa_content_prepare();
     $qa_content['title'] = qa_lang_html_sub('useo/edit_desc_for_x', qa_html($fullcategory['title']));
     if (qa_user_permit_error('useo_cat_desc_permit_edit')) {
         $qa_content['error'] = qa_lang_html('users/no_permission');
         return $qa_content;
     }
     require_once QA_INCLUDE_DIR . 'qa-db-metas.php';
     if (qa_clicked('dosave')) {
         require_once QA_INCLUDE_DIR . 'qa-util-string.php';
         qa_db_categorymeta_set($categoryid, 'useo_cat_title', qa_post_text('useo_cat_title'));
         qa_db_categorymeta_set($categoryid, 'useo_cat_description', qa_post_text('useo_cat_description'));
         qa_redirect($new_request);
     }
     $qa_content['form'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array(array('label' => 'Link Title:', 'type' => 'text', 'rows' => 2, 'tags' => 'NAME="useo_cat_title" ID="useo_cat_title"', 'value' => qa_html(qa_db_categorymeta_get($categoryid, 'useo_cat_title'))), array('label' => 'Description:', 'type' => 'text', 'rows' => 4, 'tags' => 'NAME="useo_cat_description" ID="useo_cat_description"', 'value' => qa_html(qa_db_categorymeta_get($categoryid, 'useo_cat_description')))), 'buttons' => array(array('tags' => 'NAME="dosave"', 'label' => qa_lang_html('useo/save_desc_button'))));
     $qa_content['focusid'] = 'tagtitle';
     return $qa_content;
 }
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
//	Find queued questions, answers, comments
$userid = qa_get_logged_in_userid();
list($queuedquestions, $queuedanswers, $queuedcomments) = qa_db_select_with_pending(qa_db_qs_selectspec($userid, 'created', 0, null, null, 'Q_QUEUED', true), qa_db_recent_a_qs_selectspec($userid, 0, null, null, 'A_QUEUED', true), qa_db_recent_c_qs_selectspec($userid, 0, null, null, 'C_QUEUED', true));
//	Check admin privileges (do late to allow one DB query)
if (qa_user_maximum_permit_error('permit_moderate')) {
    $qa_content = qa_content_prepare();
    $qa_content['error'] = qa_lang_html('users/no_permission');
    return $qa_content;
}
//	Check to see if any were approved/rejected here
$pageerror = qa_admin_check_clicks();
//	Combine sets of questions and remove those this user has no permission to moderate
$questions = qa_any_sort_by_date(array_merge($queuedquestions, $queuedanswers, $queuedcomments));
if (qa_user_permit_error('permit_moderate')) {
    // if user not allowed to moderate all posts
    foreach ($questions as $index => $question) {
        if (qa_user_post_permit_error('permit_moderate', $question)) {
            unset($questions[$index]);
        }
    }
}
//	Get information for users
$usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions));
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('admin/recent_approve_title');
$qa_content['error'] = isset($pageerror) ? $pageerror : qa_admin_page_error();
$qa_content['q_list'] = array('form' => array('tags' => 'method="post" action="' . qa_self_html() . '"', 'hidden' => array('code' => qa_get_form_security_code('admin/click'))), 'qs' => array());
if (count($questions)) {
     }
 }
 if (qa_opt('allow_private_messages')) {
     qa_db_user_set_flag($userid, QA_USER_FLAGS_NO_MESSAGES, !$inmessages);
 }
 if (qa_opt('allow_user_walls')) {
     qa_db_user_set_flag($userid, QA_USER_FLAGS_NO_WALL_POSTS, !$inwallposts);
 }
 if (qa_opt('mailing_enabled')) {
     qa_db_user_set_flag($userid, QA_USER_FLAGS_NO_MAILINGS, !$inmailings);
 }
 qa_db_user_set_flag($userid, QA_USER_FLAGS_SHOW_AVATAR, $inavatar == 'uploaded');
 qa_db_user_set_flag($userid, QA_USER_FLAGS_SHOW_GRAVATAR, $inavatar == 'gravatar');
 if (is_array(@$_FILES['file']) && $_FILES['file']['size']) {
     require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
     switch (qa_user_permit_error(null, QA_LIMIT_UPLOADS)) {
         case 'limit':
             $errors['avatar'] = qa_lang('main/upload_limit');
             break;
         default:
             $errors['avatar'] = qa_lang('users/no_permission');
             break;
         case false:
             qa_limits_increment($userid, QA_LIMIT_UPLOADS);
             $toobig = qa_image_file_too_big($_FILES['file']['tmp_name'], qa_opt('avatar_store_size'));
             if ($toobig) {
                 $errors['avatar'] = qa_lang_sub('main/image_too_big_x_pc', (int) ($toobig * 100));
             } elseif (!qa_set_user_avatar($userid, file_get_contents($_FILES['file']['tmp_name']), $useraccount['avatarblobid'])) {
                 $errors['avatar'] = qa_lang_sub('main/image_not_read', implode(', ', qa_gd_image_formats()));
             }
             break;
function qa_wall_posts_add_rules($usermessages, $start)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    $userid = qa_get_logged_in_userid();
    $userdeleteall = !(qa_user_permit_error('permit_hide_show') || qa_user_permit_error('permit_delete_hidden'));
    // reuse "Hiding or showing any post" and "Deleting hidden posts" permissions
    $userrecent = $start == 0 && isset($userid);
    // User can delete all of the recent messages they wrote on someone's wall...
    foreach ($usermessages as $key => $message) {
        if ($message['fromuserid'] != $userid) {
            $userrecent = false;
        }
        // ... until we come across one that they didn't write (which could be a reply)
        $usermessages[$key]['deleteable'] = $message['touserid'] == $userid || $userrecent && $message['fromuserid'] == $userid || $userdeleteall;
        // if the user has enough permissions  to delete from any wall
    }
    return $usermessages;
}
    qa_redirect('users');
}
if (!isset($loginuserid)) {
    $qa_content = qa_content_prepare();
    $qa_content['error'] = qa_insert_login_links(qa_lang_html('misc/message_must_login'), qa_request());
    return $qa_content;
}
//	Find the user profile and questions and answers for this handle
list($toaccount, $torecent, $fromrecent) = qa_db_select_with_pending(qa_db_user_account_selectspec($handle, false), qa_db_recent_messages_selectspec($loginuserid, true, $handle, false), qa_db_recent_messages_selectspec($handle, false, $loginuserid, true));
//	Check the user exists and work out what can and can't be set (if not using single sign-on)
if (!qa_opt('allow_private_messages') || !is_array($toaccount) || $toaccount['flags'] & QA_USER_FLAGS_NO_MESSAGES) {
    return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
}
//	Check that we have permission and haven't reached the limit
$errorhtml = null;
switch (qa_user_permit_error(null, QA_LIMIT_MESSAGES)) {
    case 'limit':
        $errorhtml = qa_lang_html('misc/message_limit');
        break;
    case false:
        break;
    default:
        $errorhtml = qa_lang_html('users/no_permission');
        break;
}
if (isset($errorhtml)) {
    $qa_content = qa_content_prepare();
    $qa_content['error'] = $errorhtml;
    return $qa_content;
}
//	Process sending a message to user
             $qa_content['form_profile']['fields']['level']['type'] = 'select';
             $leveloptions = array(QA_USER_LEVEL_BASIC, QA_USER_LEVEL_EXPERT, QA_USER_LEVEL_EDITOR, QA_USER_LEVEL_MODERATOR, QA_USER_LEVEL_ADMIN, QA_USER_LEVEL_SUPER);
             foreach ($leveloptions as $leveloption) {
                 if ($leveloption <= $maxlevelassign) {
                     $qa_content['form_profile']['fields']['level']['options'][$leveloption] = qa_html(qa_user_level_string($leveloption));
                 }
             }
         }
         $qa_content['form_profile']['buttons'] = array('save' => array('tags' => 'onClick="qa_show_waiting_after(this, false);"', 'label' => qa_lang_html('users/save_user')), 'cancel' => array('tags' => 'NAME="docancel"', 'label' => qa_lang_html('main/cancel_button')));
         $qa_content['form_profile']['hidden'] = array('dosave' => '1');
     } else {
         $qa_content['form_profile']['buttons'] = array('edit' => array('tags' => 'NAME="doedit"', 'label' => qa_lang_html('users/edit_user_button')));
         if (isset($maxlevelassign) && $useraccount['level'] < QA_USER_LEVEL_MODERATOR) {
             if ($useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED) {
                 $qa_content['form_profile']['buttons']['unblock'] = array('tags' => 'NAME="dounblock"', 'label' => qa_lang_html('users/unblock_user_button'));
                 if (count($questions) && !qa_user_permit_error('permit_hide_show')) {
                     $qa_content['form_profile']['buttons']['hideall'] = array('tags' => 'NAME="dohideall" onClick="qa_show_waiting_after(this, false);"', 'label' => qa_lang_html('users/hide_all_user_button'));
                 }
                 if ($loginlevel >= QA_USER_LEVEL_ADMIN) {
                     $qa_content['form_profile']['buttons']['delete'] = array('tags' => 'NAME="dodelete" onClick="qa_show_waiting_after(this, false);"', 'label' => qa_lang_html('users/delete_user_button'));
                 }
             } else {
                 $qa_content['form_profile']['buttons']['block'] = array('tags' => 'NAME="doblock"', 'label' => qa_lang_html('users/block_user_button'));
             }
         }
     }
 }
 if (!is_array($qa_content['form_profile']['fields']['removeavatar'])) {
     unset($qa_content['form_profile']['fields']['removeavatar']);
 }
 $qa_content['raw']['account'] = $useraccount;
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/
require_once QA_INCLUDE_DIR . 'qa-app-users.php';
require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
//	First check whether the person has permission to do this
if (!qa_user_permit_error('permit_post_a', QA_LIMIT_ANSWERS)) {
    require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
    require_once QA_INCLUDE_DIR . 'qa-app-captcha.php';
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    require_once QA_INCLUDE_DIR . 'qa-app-post-create.php';
    require_once QA_INCLUDE_DIR . 'qa-app-cookies.php';
    require_once QA_INCLUDE_DIR . 'qa-page-question-view.php';
    require_once QA_INCLUDE_DIR . 'qa-page-question-submit.php';
    //	Load relevant information about this question and check it exists
    $usecaptcha = qa_user_use_captcha();
    $questionid = qa_post_text('a_questionid');
    $userid = qa_get_logged_in_userid();
    list($question, $childposts) = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $questionid), qa_db_full_child_posts_selectspec($userid, $questionid));
    if (@$question['basetype'] == 'Q' && !isset($question['closedbyid'])) {
        $answers = qa_page_q_load_as($question, $childposts);
        //	Try to create the new answer
Exemple #14
0
function qa_user_moderation_reason($userlevel = null)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    $reason = false;
    if (!isset($userlevel)) {
        $userlevel = qa_get_logged_in_level();
    }
    if ($userlevel < QA_USER_LEVEL_EXPERT && qa_user_permit_error('permit_moderate')) {
        $userid = qa_get_logged_in_userid();
        if (isset($userid)) {
            if (qa_opt('moderate_users') && qa_opt('moderate_unapproved') && $userlevel < QA_USER_LEVEL_APPROVED) {
                $reason = 'approve';
            } elseif (qa_opt('confirm_user_emails') && qa_opt('moderate_unconfirmed') && !(qa_get_logged_in_flags() & QA_USER_FLAGS_EMAIL_CONFIRMED)) {
                $reason = 'confirm';
            } elseif (qa_opt('moderate_by_points') && qa_get_logged_in_points() < qa_opt('moderate_points_limit')) {
                $reason = 'points';
            }
        } elseif (qa_opt('moderate_anon_post')) {
            $reason = 'login';
        }
    }
    return $reason;
}
function qa_get_vote_view($basetype, $full = false, $enabledif = true)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    $disabledsuffix = '';
    if ($basetype == 'Q') {
        $view = qa_opt('voting_on_qs');
        if (!($enabledif && ($full || !qa_opt('voting_on_q_page_only')))) {
            $disabledsuffix = '-disabled-page';
        } elseif (qa_user_permit_error('permit_vote_q') == 'level') {
            $disabledsuffix = '-disabled-level';
        } elseif (qa_user_permit_error('permit_vote_down') == 'level') {
            $disabledsuffix = '-uponly-level';
        }
    } elseif ($basetype == 'A') {
        $view = qa_opt('voting_on_as');
        if (!$enabledif) {
            $disabledsuffix = '-disabled-page';
        } elseif (qa_user_permit_error('permit_vote_a') == 'level') {
            $disabledsuffix = '-disabled-level';
        } elseif (qa_user_permit_error('permit_vote_down') == 'level') {
            $disabledsuffix = '-uponly-level';
        }
    } else {
        $view = false;
    }
    return $view ? (qa_opt('votes_separated') ? 'updown' : 'net') . $disabledsuffix : false;
}
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
//	Find recently hidden questions, answers, comments
$userid = qa_get_logged_in_userid();
list($hiddenquestions, $hiddenanswers, $hiddencomments) = qa_db_select_with_pending(qa_db_qs_selectspec($userid, 'created', 0, null, null, 'Q_HIDDEN', true), qa_db_recent_a_qs_selectspec($userid, 0, null, null, 'A_HIDDEN', true), qa_db_recent_c_qs_selectspec($userid, 0, null, null, 'C_HIDDEN', true));
//	Check admin privileges (do late to allow one DB query)
if (qa_user_maximum_permit_error('permit_hide_show') && qa_user_maximum_permit_error('permit_delete_hidden')) {
    $qa_content = qa_content_prepare();
    $qa_content['error'] = qa_lang_html('users/no_permission');
    return $qa_content;
}
//	Check to see if any have been reshown or deleted
$pageerror = qa_admin_check_clicks();
//	Combine sets of questions and remove those this user has no permissions for
$questions = qa_any_sort_by_date(array_merge($hiddenquestions, $hiddenanswers, $hiddencomments));
if (qa_user_permit_error('permit_hide_show') && qa_user_permit_error('permit_delete_hidden')) {
    // not allowed to see all hidden posts
    foreach ($questions as $index => $question) {
        if (qa_user_post_permit_error('permit_hide_show', $question) && qa_user_post_permit_error('permit_delete_hidden', $question)) {
            unset($questions[$index]);
        }
    }
}
//	Get information for users
$usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions));
//	Create list of actual hidden postids and see which ones have dependents
$qhiddenpostid = array();
foreach ($questions as $key => $question) {
    $qhiddenpostid[$key] = isset($question['opostid']) ? $question['opostid'] : $question['postid'];
}
$dependcounts = qa_db_postids_count_dependents($qhiddenpostid);
Exemple #17
0
function qa_get_vote_view($postorbasetype, $full = false, $enabledif = true)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    // The 'level' and 'approve' permission errors are taken care of by disabling the voting buttons.
    // Others are reported to the user after they click, in qa_vote_error_html(...)
    if (is_array($postorbasetype)) {
        // deal with dual-use parameter
        $basetype = $postorbasetype['basetype'];
        $post = $postorbasetype;
    } else {
        $basetype = $postorbasetype;
        $post = null;
    }
    $disabledsuffix = '';
    if ($basetype == 'Q' || $basetype == 'A') {
        $view = $basetype == 'A' ? qa_opt('voting_on_as') : qa_opt('voting_on_qs');
        if (!($enabledif && ($basetype == 'A' || $full || !qa_opt('voting_on_q_page_only')))) {
            $disabledsuffix = '-disabled-page';
        } else {
            if ($basetype == 'A') {
                $permiterror = isset($post) ? qa_user_post_permit_error('permit_vote_a', $post) : qa_user_permit_error('permit_vote_a');
            } else {
                $permiterror = isset($post) ? qa_user_post_permit_error('permit_vote_q', $post) : qa_user_permit_error('permit_vote_q');
            }
            if ($permiterror == 'level') {
                $disabledsuffix = '-disabled-level';
            } elseif ($permiterror == 'approve') {
                $disabledsuffix = '-disabled-approve';
            } else {
                $permiterrordown = isset($post) ? qa_user_post_permit_error('permit_vote_down', $post) : qa_user_permit_error('permit_vote_down');
                if ($permiterrordown == 'level') {
                    $disabledsuffix = '-uponly-level';
                } elseif ($permiterrordown == 'approve') {
                    $disabledsuffix = '-uponly-approve';
                }
            }
        }
    } else {
        $view = false;
    }
    return $view ? (qa_opt('votes_separated') ? 'updown' : 'net') . $disabledsuffix : false;
}
Exemple #18
0
$in = array();
$followpostid = qa_get('follow');
$in['categoryid'] = qa_get_category_field_value('category');
if (!isset($in['categoryid'])) {
    $in['categoryid'] = qa_get('cat');
}
$userid = qa_get_logged_in_userid();
@(list($categories, $followanswer, $completetags) = qa_db_select_with_pending(qa_db_category_nav_selectspec($in['categoryid'], true), isset($followpostid) ? qa_db_full_post_selectspec($userid, $followpostid) : null, qa_db_popular_tags_selectspec(0, QA_DB_RETRIEVE_COMPLETE_TAGS)));
if (!isset($categories[$in['categoryid']])) {
    $in['categoryid'] = null;
}
if (@$followanswer['basetype'] != 'A') {
    $followanswer = null;
}
//	Check for permission error
$permiterror = qa_user_permit_error('permit_post_q', qa_is_http_post() ? QA_LIMIT_QUESTIONS : null);
// only check rate limit later on
if ($permiterror) {
    $qa_content = qa_content_prepare();
    switch ($permiterror) {
        case 'login':
            $qa_content['error'] = qa_insert_login_links(qa_lang_html('question/ask_must_login'), qa_request(), isset($followpostid) ? array('follow' => $followpostid) : null);
            break;
        case 'confirm':
            $qa_content['error'] = qa_insert_login_links(qa_lang_html('question/ask_must_confirm'), qa_request(), isset($followpostid) ? array('follow' => $followpostid) : null);
            break;
        case 'limit':
            $qa_content['error'] = qa_lang_html('question/ask_limit');
            break;
        default:
            $qa_content['error'] = qa_lang_html('users/no_permission');
        //	Add the answer to the list
        $qa_content['a_list']['as'][] = $a_view;
    }
}
qa_sort_by($qa_content['a_list']['as'], 'priority');
$countanswers = $question['acount'];
if ($countanswers == 1) {
    $qa_content['a_list']['title'] = qa_lang_html('question/1_answer_title');
} else {
    $qa_content['a_list']['title'] = qa_lang_html_sub('question/x_answers_title', $countanswers);
}
//	Prepare content for form to add an answer
if ($formtype == 'a_add') {
    // Form for adding answers
    $answerform = null;
    switch (qa_user_permit_error('permit_post_a')) {
        case 'login':
            $answerform = array('style' => 'tall', 'title' => qa_insert_login_links(qa_lang_html('question/answer_must_login'), $qa_request));
            break;
        case 'confirm':
            $answerform = array('style' => 'tall', 'title' => qa_insert_login_links(qa_lang_html('question/answer_must_confirm'), $qa_request));
            break;
        case false:
            $editorname = isset($ineditor) ? $ineditor : qa_opt('editor_for_as');
            $editor = qa_load_editor(@$incontent, @$informat, $editorname);
            $answerform = array('title' => qa_lang_html('question/your_answer_title'), 'style' => 'tall', 'fields' => array('content' => array_merge($editor->get_field($qa_content, @$incontent, @$informat, 'content', 12, $formrequested), array('error' => qa_html(@$errors['content'])))), 'buttons' => array('answer' => array('tags' => 'NAME="doansweradd"', 'label' => qa_lang_html('question/add_answer_button'))), 'hidden' => array('editor' => qa_html($editorname)));
            if ($formrequested) {
                // only show cancel button if user explicitly requested the form
                $answerform['buttons']['cancel'] = array('tags' => 'NAME="docancel"', 'label' => qa_lang_html('main/cancel_button'));
            }
            qa_set_up_notify_fields($qa_content, $answerform['fields'], 'A', qa_get_logged_in_email(), isset($innotify) ? $innotify : qa_opt('notify_users_default'), @$inemail, @$errors['email']);
function qa_upload_file($localfilename, $sourcefilename, $maxfilesize = null, $onlyimage = false, $imagemaxwidth = null, $imagemaxheight = null)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    $result = array();
    //	Check per-user upload limits
    require_once QA_INCLUDE_DIR . 'qa-app-users.php';
    require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
    switch (qa_user_permit_error(null, QA_LIMIT_UPLOADS)) {
        case 'limit':
            $result['error'] = qa_lang('main/upload_limit');
            return $result;
        case false:
            qa_limits_increment(qa_get_logged_in_userid(), QA_LIMIT_UPLOADS);
            break;
        default:
            $result['error'] = qa_lang('users/no_permission');
            return $result;
    }
    //	Check the uploaded file is not too large
    $filesize = filesize($localfilename);
    if (isset($maxfilesize)) {
        $maxfilesize = min($maxfilesize, qa_get_max_upload_size());
    } else {
        $maxfilesize = qa_get_max_upload_size();
    }
    if ($filesize <= 0 || $filesize > $maxfilesize) {
        // if file was too big for PHP, $filesize will be zero
        $result['error'] = qa_lang_sub('main/max_upload_size_x', number_format($maxfilesize / 1048576, 1) . 'MB');
        return $result;
    }
    //	Find out what type of source file was uploaded and if appropriate, check it's an image and get preliminary size measure
    $pathinfo = pathinfo($sourcefilename);
    $format = strtolower(@$pathinfo['extension']);
    $isimage = $format == 'png' || $format == 'gif' || $format == 'jpeg' || $format == 'jpg';
    // allowed image extensions
    if ($isimage) {
        $imagesize = @getimagesize($localfilename);
        if (is_array($imagesize)) {
            $result['width'] = $imagesize[0];
            $result['height'] = $imagesize[1];
            switch ($imagesize['2']) {
                // reassign format based on actual content, if we can
                case IMAGETYPE_GIF:
                    $format = 'gif';
                    break;
                case IMAGETYPE_JPEG:
                    $format = 'jpeg';
                    break;
                case IMAGETYPE_PNG:
                    $format = 'png';
                    break;
            }
        }
    }
    $result['format'] = $format;
    if ($onlyimage) {
        if (!$isimage || !is_array($imagesize)) {
            $result['error'] = qa_lang_sub('main/image_not_read', 'GIF, JPG, PNG');
            return $result;
        }
    }
    //	Read in the raw file contents
    $content = file_get_contents($localfilename);
    //	If appropriate, get more accurate image size and apply constraints to it
    require_once QA_INCLUDE_DIR . 'qa-util-image.php';
    if ($isimage && qa_has_gd_image()) {
        $image = @imagecreatefromstring($content);
        if (is_resource($image)) {
            $result['width'] = $width = imagesx($image);
            $result['height'] = $height = imagesy($image);
            if (isset($imagemaxwidth) || isset($imagemaxheight)) {
                if (qa_image_constrain($width, $height, isset($imagemaxwidth) ? $imagemaxwidth : $width, isset($imagemaxheight) ? $imagemaxheight : $height)) {
                    qa_gd_image_resize($image, $width, $height);
                    if (is_resource($image)) {
                        $content = qa_gd_image_jpeg($image);
                        $result['format'] = $format = 'jpeg';
                        $result['width'] = $width;
                        $result['height'] = $height;
                    }
                }
            }
            if (is_resource($image)) {
                // might have been lost
                imagedestroy($image);
            }
        }
    }
    //	Create the blob and return
    require_once QA_INCLUDE_DIR . 'qa-app-blobs.php';
    $userid = qa_get_logged_in_userid();
    $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
    $result['blobid'] = qa_create_blob($content, $format, $sourcefilename, $userid, $cookieid, qa_remote_ip_address());
    if (!isset($result['blobid'])) {
        $result['error'] = qa_lang('main/general_error');
        return $result;
    }
    $result['bloburl'] = qa_get_blob_url($result['blobid'], true);
    return $result;
}
    $qa_content = qa_content_prepare();
    $qa_content['error'] = qa_insert_login_links(qa_lang_html('misc/message_must_login'), $qa_request);
    return $qa_content;
}
//	Find the user profile and questions and answers for this handle
$useraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($handle, false));
//	Check the user exists and work out what can and can't be set (if not using single sign-on)
if (!is_array($useraccount) || $useraccount['flags'] & QA_USER_FLAGS_NO_MESSAGES) {
    return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
}
//	Process sending a message to user
$messagesent = false;
if (qa_post_text('domessage')) {
    //	Check that we haven't been blocked on volume
    $errorhtml = null;
    switch (qa_user_permit_error(null, 'M')) {
        case 'limit':
            $errorhtml = qa_lang_html('misc/message_limit');
            break;
        case false:
            break;
        default:
            $errorhtml = qa_lang_html('users/no_permission');
            break;
    }
    if (isset($errorhtml)) {
        $qa_content = qa_content_prepare();
        $qa_content['error'] = $errorhtml;
        return $qa_content;
    }
    //	Proceed...
function qa_get_request_content()
{
    $qa_content = qa_get_request_content_base();
    // displays signature form in user profile
    $qa_request = strtolower(qa_request());
    $reqs = explode('/', $qa_request);
    if ($reqs[0] == 'user') {
        // permissions
        if (isset($qa_content['form_profile']['fields']['permits'])) {
            $ov = $qa_content['form_profile']['fields']['permits']['value'];
            $ov = str_replace('[profile/signature_allow]', qa_lang('signature_plugin/signature_allow'), $ov);
            $ov = str_replace('[profile/signature_edit_allow]', qa_lang('signature_plugin/signature_edit_allow'), $ov);
            $qa_content['form_profile']['fields']['permits']['value'] = $ov;
        }
        $qa_content['user_signature_form'] = array();
        $userid = @$qa_content['raw']['userid'];
        if (!$userid) {
            return $qa_content;
        }
        $handles = qa_userids_to_handles(array($userid));
        $handle = $handles[$userid];
        if (qa_get_logged_in_handle() == $handle && !qa_user_permit_error('signature_allow') || !qa_user_permit_error('signature_edit_allow')) {
            $ok = null;
            $formats = qa_list_modules('editor');
            $format = qa_opt('signatures_format');
            $editorname = $formats[$format];
            if (!strlen($editorname)) {
                $editorname = qa_lang_html('admin/basic_editor');
            }
            $editor = qa_load_editor('', '', $editorname);
            qa_db_query_sub('CREATE TABLE IF NOT EXISTS ^usersignatures (' . 'userid INT(11) NOT NULL,' . 'signature VARCHAR (1000) DEFAULT \'\',' . 'format VARCHAR (20) DEFAULT \'\',' . 'id INT(11) NOT NULL AUTO_INCREMENT,' . 'UNIQUE (userid),' . 'PRIMARY KEY (id)' . ') ENGINE=MyISAM DEFAULT CHARSET=utf8');
            if (qa_clicked('signature_save')) {
                if (strlen(qa_post_text('signature_text')) > qa_opt('signatures_length')) {
                    $error = 'Max possible signature length is 1000 characters';
                } else {
                    $readdata = $editor->read_post('signature_text');
                    $informat = $readdata['format'];
                    $incontent = qa_post_text('signature_text');
                    qa_db_query_sub('INSERT INTO ^usersignatures (userid,signature,format) VALUES (#,$,$) ON DUPLICATE KEY UPDATE signature=$,format=$', $userid, $incontent, $informat, $incontent, $informat);
                    $ok = 'Signature Saved.';
                }
            }
            $content = qa_db_read_one_assoc(qa_db_query_sub('SELECT BINARY signature AS signature,format FROM ^usersignatures WHERE userid=#', $userid), true);
            $field = qa_editor_load_field($editor, $qa_content, $content['signature'], $content['format'], 'signature_text', 12, false);
            $field['label'] = qa_lang_html('signature_plugin/signature');
            $fields['content'] = $field;
            if (!$editorname || $editorname == 'Markdown Editor') {
                $fields['elCount'] = array('label' => '<div id="elCount">' . qa_opt('signatures_length') . '</div>', 'type' => 'static');
            }
            $form = array('ok' => $ok && !isset($error) ? $ok : null, 'error' => @$error, 'style' => 'tall', 'title' => '<a name="signature_text"></a>' . qa_lang_html('signature_plugin/signature'), 'tags' => 'action="' . qa_self_html() . '#signature_text" method="POST"', 'fields' => $fields, 'buttons' => array(array('label' => qa_lang_html('main/save_button'), 'tags' => 'NAME="signature_save"')), 'hidden' => array('editor' => qa_html($editorname), 'dosavesig' => '1'));
            $qa_content['user_signature_form'] = $form;
        } else {
            if (qa_opt('signatures_profile_enable')) {
                $content = qa_db_read_one_assoc(qa_db_query_sub('SELECT BINARY signature as signature, format FROM ^usersignatures WHERE userid=#', $userid), true);
                if (!$content) {
                    return $qa_content;
                }
                $informat = $content['format'];
                $viewer = qa_load_viewer($content['signature'], $informat);
                global $options;
                $signature = qa_viewer_html($content['signature'], $informat, array('blockwordspreg' => @$options['blockwordspreg'], 'showurllinks' => @$options['showurllinks'], 'linksnewwindow' => @$options['linksnewwindow']));
                $fields[] = array('label' => qa_opt('signatures_header') . $signature . qa_opt('signatures_footer'), 'type' => 'static');
                $qa_content['user_signature_form'] = array('title' => 'Signature', 'fields' => $fields, 'style' => 'tall');
            }
        }
    }
    return $qa_content;
}
function qa_flag_error_html($post, $userid, $topage)
{
    require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
    require_once QA_INCLUDE_DIR . 'qa-app-options.php';
    require_once QA_INCLUDE_DIR . 'qa-app-users.php';
    if (is_array($post) && qa_opt('flagging_of_posts') && (!isset($post['userid']) || !isset($userid) || $post['userid'] != $userid)) {
        switch (qa_user_permit_error('permit_flag', 'F')) {
            case 'login':
                return qa_insert_login_links(qa_lang_html('question/flag_must_login'), $topage);
                break;
            case 'confirm':
                return qa_insert_login_links(qa_lang_html('question/flag_must_confirm'), $topage);
                break;
            case 'limit':
                return qa_lang_html('question/flag_limit');
                break;
            default:
                return qa_lang_html('users/no_permission');
                break;
            case false:
                return false;
        }
    } else {
        return qa_lang_html('question/flag_not_allowed');
    }
    // flagging option should not have been presented
}
function qa_admin_sub_navigation()
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    $navigation = array();
    $level = qa_get_logged_in_level();
    if ($level >= QA_USER_LEVEL_ADMIN) {
        $navigation['admin/general'] = array('label' => qa_lang_html('admin/general_title'), 'url' => qa_path_html('admin/general'));
        $navigation['admin/emails'] = array('label' => qa_lang_html('admin/emails_title'), 'url' => qa_path_html('admin/emails'));
        $navigation['admin/users'] = array('label' => qa_lang_html('admin/users_title'), 'url' => qa_path_html('admin/users'), 'selected_on' => array('admin/users$', 'admin/userfields$', 'admin/usertitles$'));
        if ($level >= QA_USER_LEVEL_SUPER) {
            $navigation['admin/layout'] = array('label' => qa_lang_html('admin/layout_title'), 'url' => qa_path_html('admin/layout'));
        }
        $navigation['admin/posting'] = array('label' => qa_lang_html('admin/posting_title'), 'url' => qa_path_html('admin/posting'));
        $navigation['admin/viewing'] = array('label' => qa_lang_html('admin/viewing_title'), 'url' => qa_path_html('admin/viewing'));
        $navigation['admin/lists'] = array('label' => qa_lang_html('admin/lists_title'), 'url' => qa_path_html('admin/lists'));
        if (qa_using_categories()) {
            $navigation['admin/categories'] = array('label' => qa_lang_html('admin/categories_title'), 'url' => qa_path_html('admin/categories'));
        }
        $navigation['admin/permissions'] = array('label' => qa_lang_html('admin/permissions_title'), 'url' => qa_path_html('admin/permissions'));
        if ($level >= QA_USER_LEVEL_SUPER) {
            $navigation['admin/pages'] = array('label' => qa_lang_html('admin/pages_title'), 'url' => qa_path_html('admin/pages'));
        }
        $navigation['admin/feeds'] = array('label' => qa_lang_html('admin/feeds_title'), 'url' => qa_path_html('admin/feeds'));
        $navigation['admin/points'] = array('label' => qa_lang_html('admin/points_title'), 'url' => qa_path_html('admin/points'));
        $navigation['admin/spam'] = array('label' => qa_lang_html('admin/spam_title'), 'url' => qa_path_html('admin/spam'));
        if ($level >= QA_USER_LEVEL_SUPER) {
            $navigation['admin/stats'] = array('label' => qa_lang_html('admin/stats_title'), 'url' => qa_path_html('admin/stats'));
        }
        if (!QA_FINAL_EXTERNAL_USERS) {
            $navigation['admin/mailing'] = array('label' => qa_lang_html('admin/mailing_title'), 'url' => qa_path_html('admin/mailing'));
        }
        if ($level >= QA_USER_LEVEL_SUPER) {
            $navigation['admin/plugins'] = array('label' => qa_lang_html('admin/plugins_title'), 'url' => qa_path_html('admin/plugins'));
        }
    }
    if (!qa_user_maximum_permit_error('permit_moderate')) {
        $count = qa_user_permit_error('permit_moderate') ? null : qa_opt('cache_queuedcount');
        // if only in some categories don't show cached count
        $navigation['admin/moderate'] = array('label' => qa_lang_html('admin/moderate_title') . ($count ? ' (' . $count . ')' : ''), 'url' => qa_path_html('admin/moderate'));
    }
    if (qa_opt('flagging_of_posts') && !qa_user_maximum_permit_error('permit_hide_show')) {
        $count = qa_user_permit_error('permit_hide_show') ? null : qa_opt('cache_flaggedcount');
        // if only in some categories don't show cached count
        $navigation['admin/flagged'] = array('label' => qa_lang_html('admin/flagged_title') . ($count ? ' (' . $count . ')' : ''), 'url' => qa_path_html('admin/flagged'));
    }
    if (!qa_user_maximum_permit_error('permit_hide_show') || !qa_user_maximum_permit_error('permit_delete_hidden')) {
        $navigation['admin/hidden'] = array('label' => qa_lang_html('admin/hidden_title'), 'url' => qa_path_html('admin/hidden'));
    }
    if (!QA_FINAL_EXTERNAL_USERS && qa_opt('moderate_users') && $level >= QA_USER_LEVEL_MODERATOR) {
        $count = qa_opt('cache_uapprovecount');
        $navigation['admin/approve'] = array('label' => qa_lang_html('admin/approve_users_title') . ($count ? ' (' . $count . ')' : ''), 'url' => qa_path_html('admin/approve'));
    }
    return $navigation;
}
function qa_page_q_edit_q_submit($question, $answers, $commentsfollows, $closepost, &$in, &$errors)
{
    $in = array();
    if ($question['editable']) {
        $in['title'] = qa_post_text('q_title');
        qa_get_post_content('q_editor', 'q_content', $in['editor'], $in['content'], $in['format'], $in['text']);
        $in['extra'] = qa_opt('extra_field_active') ? qa_post_text('q_extra') : null;
    }
    if ($question['retagcatable']) {
        if (qa_using_tags()) {
            $in['tags'] = qa_get_tags_field_value('q_tags');
        }
        if (qa_using_categories()) {
            $in['categoryid'] = qa_get_category_field_value('q_category');
        }
    }
    if (array_key_exists('categoryid', $in)) {
        // need to check if we can move it to that category, and if we need moderation
        $categories = qa_db_select_with_pending(qa_db_category_nav_selectspec($in['categoryid'], true));
        $categoryids = array_keys(qa_category_path($categories, $in['categoryid']));
        $userlevel = qa_user_level_for_categories($categoryids);
    } else {
        $userlevel = null;
    }
    if ($question['isbyuser']) {
        $in['name'] = qa_post_text('q_name');
        $in['notify'] = qa_post_text('q_notify') ? true : false;
        $in['email'] = qa_post_text('q_email');
    }
    if (!qa_user_post_permit_error('permit_edit_silent', $question)) {
        $in['silent'] = qa_post_text('q_silent');
    }
    // here the $in array only contains values for parts of the form that were displayed, so those are only ones checked by filters
    $errors = array();
    if (!qa_check_form_security_code('edit-' . $question['postid'], qa_post_text('code'))) {
        $errors['page'] = qa_lang_html('misc/form_security_again');
    } else {
        $in['queued'] = qa_opt('moderate_edited_again') && qa_user_moderation_reason($userlevel);
        $filtermodules = qa_load_modules_with('filter', 'filter_question');
        foreach ($filtermodules as $filtermodule) {
            $oldin = $in;
            $filtermodule->filter_question($in, $errors, $question);
            if ($question['editable']) {
                qa_update_post_text($in, $oldin);
            }
        }
        if (array_key_exists('categoryid', $in) && strcmp($in['categoryid'], $question['categoryid'])) {
            if (qa_user_permit_error('permit_post_q', null, $userlevel)) {
                $errors['categoryid'] = qa_lang_html('question/category_ask_not_allowed');
            }
        }
        if (empty($errors)) {
            $userid = qa_get_logged_in_userid();
            $handle = qa_get_logged_in_handle();
            $cookieid = qa_cookie_get();
            // now we fill in the missing values in the $in array, so that we have everything we need for qa_question_set_content()
            // we do things in this way to avoid any risk of a validation failure on elements the user can't see (e.g. due to admin setting changes)
            if (!$question['editable']) {
                $in['title'] = $question['title'];
                $in['content'] = $question['content'];
                $in['format'] = $question['format'];
                $in['text'] = qa_viewer_text($in['content'], $in['format']);
                $in['extra'] = $question['extra'];
            }
            if (!isset($in['tags'])) {
                $in['tags'] = qa_tagstring_to_tags($question['tags']);
            }
            if (!array_key_exists('categoryid', $in)) {
                $in['categoryid'] = $question['categoryid'];
            }
            if (!isset($in['silent'])) {
                $in['silent'] = false;
            }
            $setnotify = $question['isbyuser'] ? qa_combine_notify_email($question['userid'], $in['notify'], $in['email']) : $question['notify'];
            qa_question_set_content($question, $in['title'], $in['content'], $in['format'], $in['text'], qa_tags_to_tagstring($in['tags']), $setnotify, $userid, $handle, $cookieid, $in['extra'], @$in['name'], $in['queued'], $in['silent']);
            if (qa_using_categories() && strcmp($in['categoryid'], $question['categoryid'])) {
                qa_question_set_category($question, $in['categoryid'], $userid, $handle, $cookieid, $answers, $commentsfollows, $closepost, $in['silent']);
            }
            return true;
        }
    }
    return false;
}
function qa_page_q_add_c_form(&$qa_content, $questionid, $parentid, $formid, $usecaptcha, $in, $errors, $loadfocusnow)
{
    switch (qa_user_permit_error('permit_post_c')) {
        case 'login':
            $form = array('title' => qa_insert_login_links(qa_lang_html('question/comment_must_login'), qa_request()));
            break;
        case 'confirm':
            $form = array('title' => qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), qa_request()));
            break;
        case 'limit':
            $form = array('title' => qa_lang_html('question/comment_limit'));
            break;
        default:
            $form = array('title' => qa_lang_html('users/no_permission'));
            break;
        case false:
            $prefix = 'c' . $parentid . '_';
            $editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_cs');
            $editor = qa_load_editor(@$in['content'], @$in['format'], $editorname);
            if (method_exists($editor, 'update_script')) {
                $updatescript = $editor->update_script($prefix . 'content');
            } else {
                $updatescript = '';
            }
            $custom = qa_opt('show_custom_comment') ? trim(qa_opt('custom_comment')) : '';
            $form = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '" NAME="c_form_' . qa_html($parentid) . '"', 'title' => qa_lang_html($questionid == $parentid ? 'question/your_comment_q' : 'question/your_comment_a'), 'fields' => array('custom' => array('type' => 'custom', 'note' => $custom), 'content' => array_merge(qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], $prefix . 'content', 4, $loadfocusnow, $loadfocusnow), array('error' => qa_html(@$errors['content'])))), 'buttons' => array('comment' => array('tags' => 'onClick="' . $updatescript . ' return qa_submit_comment(' . qa_js($questionid) . ', ' . qa_js($parentid) . ', this);"', 'label' => qa_lang_html('question/add_comment_button')), 'cancel' => array('tags' => 'NAME="docancel"', 'label' => qa_lang_html('main/cancel_button'))), 'hidden' => array($prefix . 'editor' => qa_html($editorname), $prefix . 'doadd' => '1'));
            if (!strlen($custom)) {
                unset($form['fields']['custom']);
            }
            qa_set_up_notify_fields($qa_content, $form['fields'], 'C', qa_get_logged_in_email(), isset($in['notify']) ? $in['notify'] : qa_opt('notify_users_default'), $in['email'], @$errors['email'], $prefix);
            $onloads = array();
            if ($usecaptcha) {
                $userid = qa_get_logged_in_userid();
                $captchaloadscript = qa_set_up_captcha_field($qa_content, $form['fields'], $errors, qa_insert_login_links(qa_lang_html(isset($userid) ? 'misc/captcha_confirm_fix' : 'misc/captcha_login_fix')));
                if (strlen($captchaloadscript)) {
                    $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_show=function() { ' . $captchaloadscript . ' }';
                }
            }
            if (!$loadfocusnow) {
                if (method_exists($editor, 'load_script')) {
                    $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_load=function() { ' . $editor->load_script($prefix . 'content') . ' }';
                }
                if (method_exists($editor, 'focus_script')) {
                    $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_focus=function() { ' . $editor->focus_script($prefix . 'content') . ' }';
                }
                $form['buttons']['cancel']['tags'] .= ' onClick="return qa_toggle_element()"';
            }
            if (count($onloads)) {
                $qa_content['script_onloads'][] = $onloads;
            }
    }
    $form['id'] = $formid;
    $form['collapse'] = !$loadfocusnow;
    $form['style'] = 'tall';
    return $form;
}
Exemple #27
0
function qa_admin_single_click($postid, $action)
{
    require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
    $post = qa_post_get_full($postid);
    if (isset($post)) {
        $userid = qa_get_logged_in_userid();
        $queued = substr($post['type'], 1) == '_QUEUED';
        switch ($action) {
            case 'approve':
                if ($queued && !qa_user_permit_error('permit_moderate')) {
                    qa_post_set_hidden($postid, false, $userid);
                    return true;
                }
                break;
            case 'reject':
                if ($queued && !qa_user_permit_error('permit_moderate')) {
                    qa_post_set_hidden($postid, true, $userid);
                    return true;
                }
                break;
            case 'hide':
                if (!$queued && !qa_user_permit_error('permit_hide_show')) {
                    qa_post_set_hidden($postid, true, $userid);
                    return true;
                }
                break;
            case 'reshow':
                if ($post['hidden'] && !qa_user_permit_error('permit_hide_show')) {
                    qa_post_set_hidden($postid, false, $userid);
                    return true;
                }
                break;
            case 'delete':
                if ($post['hidden'] && !qa_user_permit_error('permit_delete_hidden')) {
                    qa_post_delete($postid);
                    return true;
                }
                break;
            case 'clearflags':
                require_once QA_INCLUDE_DIR . 'qa-app-votes.php';
                if (!qa_user_permit_error('permit_hide_show')) {
                    qa_flags_clear_all($post, $userid, qa_get_logged_in_handle(), null);
                    return true;
                }
                break;
        }
    }
    return false;
}
 if ($userediting) {
     if (qa_opt('avatar_allow_gravatar') && $useraccount['flags'] & QA_USER_FLAGS_SHOW_GRAVATAR || qa_opt('avatar_allow_upload') && $useraccount['flags'] & QA_USER_FLAGS_SHOW_AVATAR && isset($useraccount['avatarblobid'])) {
         $qa_content['form_profile']['fields']['removeavatar'] = array('type' => 'checkbox', 'label' => qa_lang_html('users/remove_avatar'), 'tags' => 'name="removeavatar"');
     }
     $qa_content['form_profile']['buttons'] = array('save' => array('tags' => 'onclick="qa_show_waiting_after(this, false);"', 'label' => qa_lang_html('users/save_user')), 'cancel' => array('tags' => 'name="docancel"', 'label' => qa_lang_html('main/cancel_button')));
     $qa_content['form_profile']['hidden'] = array('dosave' => '1', 'code' => qa_get_form_security_code('user-edit-' . $handle));
 } elseif ($usereditbutton) {
     $qa_content['form_profile']['buttons'] = array();
     if ($approvebutton) {
         $qa_content['form_profile']['buttons']['approve'] = array('tags' => 'name="doapprove"', 'label' => qa_lang_html('users/approve_user_button'));
     }
     $qa_content['form_profile']['buttons']['edit'] = array('tags' => 'name="doedit"', 'label' => qa_lang_html('users/edit_user_button'));
     if (isset($maxlevelassign) && $useraccount['level'] < QA_USER_LEVEL_MODERATOR) {
         if ($useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED) {
             $qa_content['form_profile']['buttons']['unblock'] = array('tags' => 'name="dounblock"', 'label' => qa_lang_html('users/unblock_user_button'));
             if (!qa_user_permit_error('permit_hide_show')) {
                 $qa_content['form_profile']['buttons']['hideall'] = array('tags' => 'name="dohideall" onclick="qa_show_waiting_after(this, false);"', 'label' => qa_lang_html('users/hide_all_user_button'));
             }
             if ($loginlevel >= QA_USER_LEVEL_ADMIN) {
                 $qa_content['form_profile']['buttons']['delete'] = array('tags' => 'name="dodelete" onclick="qa_show_waiting_after(this, false);"', 'label' => qa_lang_html('users/delete_user_button'));
             }
         } else {
             $qa_content['form_profile']['buttons']['block'] = array('tags' => 'name="doblock"', 'label' => qa_lang_html('users/block_user_button'));
         }
         $qa_content['form_profile']['hidden'] = array('code' => qa_get_form_security_code('user-' . $handle));
     }
 } elseif (isset($loginuserid) && $loginuserid == $userid) {
     $qa_content['form_profile']['buttons'] = array('account' => array('tags' => 'name="doaccount"', 'label' => qa_lang_html('users/edit_profile')));
 }
 if (!is_array($qa_content['form_profile']['fields']['removeavatar'])) {
     unset($qa_content['form_profile']['fields']['removeavatar']);
    $in['email'] = qa_post_text('email');
    $in['queued'] = qa_user_moderation_reason($userlevel) ? true : false;
    qa_get_post_content('editor', 'content', $in['editor'], $in['content'], $in['format'], $in['text']);
    $errors = array();
    if (!qa_check_form_security_code('ask', qa_post_text('code'))) {
        $errors['page'] = qa_lang_html('misc/form_security_again');
    } else {
        $filtermodules = qa_load_modules_with('filter', 'filter_question');
        foreach ($filtermodules as $filtermodule) {
            $oldin = $in;
            $filtermodule->filter_question($in, $errors, null);
            qa_update_post_text($in, $oldin);
        }
        if (qa_using_categories() && count($categories) && !qa_opt('allow_no_category') && !isset($in['categoryid'])) {
            $errors['categoryid'] = qa_lang_html('question/category_required');
        } elseif (qa_user_permit_error('permit_post_q', null, $userlevel)) {
            $errors['categoryid'] = qa_lang_html('question/category_ask_not_allowed');
        }
        if ($captchareason) {
            require_once 'qa-app-captcha.php';
            qa_captcha_validate_post($errors);
        }
        if (empty($errors)) {
            $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
            // create a new cookie if necessary
            $questionid = qa_question_create($followanswer, $userid, qa_get_logged_in_handle(), $cookieid, $in['title'], $in['content'], $in['format'], $in['text'], qa_tags_to_tagstring($in['tags']), $in['notify'], $in['email'], $in['categoryid'], $in['extra'], $in['queued'], $in['name']);
            qa_redirect(qa_q_request($questionid, $in['title']));
            // our work is done here
        }
    }
}
function qa_get_vote_view($basetype, $full = false, $enabledif = true)
{
    $disabledsuffix = '';
    if ($basetype == 'Q') {
        $view = qa_opt('voting_on_qs');
        if (qa_user_permit_error('permit_vote_q') == 'level') {
            $disabledsuffix = '-disabled-level';
        } elseif (!($enabledif && ($full || !qa_opt('voting_on_q_page_only')))) {
            $disabledsuffix = '-disabled-page';
        }
    } elseif ($basetype == 'A') {
        $view = qa_opt('voting_on_as');
        if (qa_user_permit_error('permit_vote_a') == 'level') {
            $disabledsuffix = '-disabled-level';
        } elseif (!$enabledif) {
            $disabledsuffix = '-disabled-page';
        }
    } else {
        $view = false;
    }
    return $view ? (qa_opt('votes_separated') ? 'updown' : 'net') . $disabledsuffix : false;
}