Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
674 views
in Plugins by
is there a way to make a categorie +18 so people needs click on somthing befor entering the question
by
i need this too but not as u need i need hidden category from user and moderator can see this category only :)

2 Answers

0 votes
by
I asked that question, you can see answer to it here http://www.question2answer.org/qa/3069/adult-only-category?show=3069#q3069
0 votes
by
edited by

I have successfully implemented the feature similar to this. To do this open the file qa-include\qa-theme-base.php and 

replace the 

public function head_custom()

{

// abstract method

}

with this:

public function head_custom()

{

function adultmatch($censoredwords, $ourpage)

{

    foreach($censoredwords as $censored){

        if (strpos($ourpage, $censored) !== false) {

            return true;

        }

    }

    return false;

}

// let's get the tags of the question page

if ( $this->template=='question')

 { $adult_tags=$this->content['q_view']['raw']['tags']; }

 else $adult_tags ="not-a-page";

 // let's get the page title of the of the question, category or tag page

 $adulttitle = strlen($this->request) ? strip_tags(@$this->content['title']) : '';

 // the list of the tags or censored words in the titles of the questions, categories or tags. If you set "sex", the script will also match all the words having the fragment of "sex" - like "sexual" or "homosexual"

 $adultwords = array('adult-only','sex','masturb','lesbian','porn');

 // let's check if there are any censored words in the tags or in the title of the question, category or tag page

if (adultmatch($adultwords, $adult_tags) OR adultmatch($adultwords, $adulttitle ))   

{

echo '<link href="https://yourwebsite.com/adult/age-verification.css" rel="stylesheet">

<script src="https://yourwebsite.com/adult/jquery.cookie.min.js"></script>

<script src="https://yourwebsite.com/adult/age-verification.js"></script>';

}

}

To get these three javascript and CSS files mentioned above, download from here:

  • age-verification.css and age-verification.js from here
  • jquery.cookie.js from here

Upload them to the directory "adult" mentioned above or change it to any other name but don't forget to edit the code respectively.

The provided age-verification.js script is coded silly, so you should make some changes:

replace this

// Question Content

var content_heading = $('<h2>Are you 21 or older?</h2>');

var content_buttons = $('<nav><ul><li><a href="#nothing" class="av_btn av_go" rel="yes">Yes</a></li><li><a href="#nothing" class="av_btn av_no" rel="no">No</a></li></nav>);

var content_text = $('<p>You must verify that you are 21 years of age or older to enter this site.</p>');

to this

// Question Content

var content_heading = $('<h2>Are you 21 or older?</h2>');

var content_buttons = $('<nav><ul><li><a href="#nothing" class="av_btn av_go" rel="yes">Yes</a></li><li><a href="javascript:history.back()" class="av_btn av_no" rel="no">No</a></li></nav>);

var content_text = $('<p>You must verify that you are 21 years of age or older to enter this site.</p>');

How this works:

The script is set to search for some specific words from the defined list (you can see them written in red in my example) in the tags of the question and additionally in the title of the question, category or tag page. So you should mark all the adult questions with some specific tags like "adult-only" or "sex" or you can edit the code adding as many censored words as you wish to the list. 

When someone visits such a page, javascript gets triggered asking if they are old enough. It they confirm, a cookie lasting for 30 days is saved so the same visitor would not be asked to confirm his/her age for any other adult questions.

...