Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
766 views
in Q2A Core by
I'm looking to hack to make new posts hidden initially until an admin/mod unhides if not spam. Which files would i need to edit and how?

I realise it's not ideal to hack core files, but until this becomes part of the code I absoultely need it!

2 Answers

0 votes
by

This is possible without "hacking" by creating an event plugin. See here for details.

You just need to hook into the q_post event and change the question's type from 'Q' to 'Q_HIDDEN'.

by
Thanks. Are there any examples of simple event plugins that I can modify to do this?
by
I believe there is a logging plugin included by default, which just logs activities to a table. The answer from gidgreen (Q2A developer) on this question may also help: http://www.question2answer.org/qa/6363/do-event-modules-in-1-4-run-before-the-content-is-displayed
by
I think this is beyond me, i'm not sure how i would create this event plugin and hook it in.
As a quick fix (yeah hack :-( ) i've manually set the type to Q-HIDDEN in qa-db-post-create.php
+1 vote
by
Something like this:

<?php

    class hidden_post_check {
        
        function process_event($event, $userid, $handle, $cookieid, $params) {
            
            switch ($event) {

                // when a new question, answer or comment is created. The $params array contains full information about the new post, including its ID in $params['postid'] and textual content in $params['text'].
                case 'q_post':
                    $this->hide_post('Q',$params);
                    break;
                case 'a_post':
                    $this->hide_post('A',$params);
                    break;
                case 'c_post':
                    $this->hide_post('C',$params);
                    break;
            }
        }
        
        function hide_post($type,$params) {
            $type = $type.'_HIDDEN';
            qa_db_query_sub(
                'UPDATE ^posts SET type=$ WHERE postid=#',
                $type,$params['postid']
            );
        }
    }
by
Thanks! So i create a new plugin folder, put that code inside (eg) qa-event-hide.php, modify qa-plugin.php to mention qa-event-hide.php... then how to i get it to use this plugin?
by
It should use it automatically... make sure the module type is 'event'
by
Many thanks it works :-)
by
Just discovered that when a user with level 0 (checked in db) posts a question, it shows the question posted as greyed out/hidden  (and is marked as Q_HIDDEN in db), but displays a "reshow" link under it. If I click that (logged in as that user) it unhides it?
My config is set that mods/admins can hide/unhide. But this is a level 0 user?
by
Any ideas on this?
I think the problem is the reshow link seems to be viewable by all users, whatever level.
It only happens as the post just submitted is then viewable by that user. If the user navigates away from that page, then as the post is hidden, they can't access it.
...