Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
643 views
in Q2A Core by
please can can anyone tell me how to prevent users or anonoymouse users editing their questions , i want only admins to have this previlege , please help me i searched a lot of about that but no result.
by
Good One . Making one plugin would help in this case .

2 Answers

0 votes
by
I want this too..
+1 vote
by
edited by

1) Hack example (qa-include/qa-theme-base.php).

function q_view_buttons($q_view) {
    // Add [start]
    if (!empty($q_view['form'])) {
        if(qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) {
            $form = &$q_view['form'];
            if(isset($form['buttons'])) {
                $buttons = &$form['buttons'];
                if(isset($buttons['edit']))
                    unset($buttons['edit']);
            }
        }
    }
    // Add [end]

    if (!empty($q_view['form'])) {
        $this->output('<div class="qa-q-view-buttons">');
        $this->form($q_view['form']);
        $this->output('</div>');
    }
}

...

function a_item_buttons($a_item) {
    // Add [start]
    if (!empty($a_item['form'])) {
        if(qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) {
            $form = &$a_item['form'];
            if(isset($form['buttons'])) {
                $buttons = &$form['buttons'];
                if(isset($buttons['edit']))
                    unset($buttons['edit']);
            }
        }
    }
    // Add [end]

    if (!empty($a_item['form'])) {
        $this->output('<div class="qa-a-item-buttons">');
        $this->form($a_item['form']);
        $this->output('</div>');
    }
}

...

function c_item_buttons($c_item) {
    // Add [start]
    if (!empty($c_item['form'])) {
        if(qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) {
            $form = &$c_item['form'];
            if(isset($form['buttons'])) {
                $buttons = &$form['buttons'];
                if(isset($buttons['edit']))
                    unset($buttons['edit']);
            }
        }
    }
    // Add [end]

    if (!empty($c_item['form'])) {
    $this->output('<div class="qa-c-item-buttons">');
    $this->form($c_item['form']);
    $this->output('</div>');
    }
}

2) Plugin example:

// Add [start]
function q_view_buttons($q_view) {
    if (!empty($q_view['form'])) {
        if(qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) {
            $form = &$q_view['form'];
            if(isset($form['buttons'])) {
                $buttons = &$form['buttons'];
                if(isset($buttons['edit']))
                    unset($buttons['edit']);
            }
        }
    }
    qa_html_theme_base::q_view_buttons($q_view);
}
function a_item_buttons($a_item) {
    if (!empty($a_item['form'])) {
        if(qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) {
            $form = &$a_item['form'];
            if(isset($form['buttons'])) {
                $buttons = &$form['buttons'];
                if(isset($buttons['edit']))
                    unset($buttons['edit']);
            }
        }
    }
    qa_html_theme_base::a_item_buttons($a_item);
}
function c_item_buttons($c_item) {
    if (!empty($c_item['form'])) {
        if(qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) {
            $form = &$c_item['form'];
            if(isset($form['buttons'])) {
                $buttons = &$form['buttons'];
                if(isset($buttons['edit']))
                    unset($buttons['edit']);
            }
        }
    }
    qa_html_theme_base::c_item_buttons($c_item);
}
// Add [end]

Note:

This logic has been considered Ajax. If you do the same thing (changes of array data) in another layer functions, it may not work correctly. If you hack application layer functions, it will be processed more smart.

by
Where to put all those lines
by
1) > Edit your qa-include/qa-theme-base.php directly.
2) > Add layer plugin including those lines.
    http://www.question2answer.org/layers.php
    You can make it if you imitate qa-plugin/mouseover-layer.
    Copy qa-plugin.php and qa-mouseover-layer.php.
Example:
<?php
class qa_html_theme_layer extends qa_html_theme_base {
  // Add upper lines.
}

Welcome to the Q&A site for Question2Answer.

If you have a question about Q2A, please ask here, in English.

To report a bug, please create a new issue on Github or ask a question here with the bug tag.

If you just want to try Q2A, please use the demo site.

Categories

...