Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+5 votes
1.2k views
in Q2A Core by

I have universal site and i need +18 (adult) category and if you want to access this category you need to confirm that you older than 18 years old like redtube.com. It's possible to do that ?

Thanks for answers.

http://paveiksleliu-talpinimas.kar.lt/p/red.png

2 Answers

0 votes
by
 
Best answer
You'd need to do some code customization to do that - no easy fix I'm afraid.

You could intercept requests to pages with this content, and redirect to a page that shows this confirmation. When people confirm, set a cookie, and then don't intercept in future if that cookie is set.

You'll also need to filter out questions (answers/comments/activity/etc...) from this category in the general listing pages, if the cookie isn't set.
asked Nov 2, 2010 in Q2A Core by Will be in version 1.4?
+2 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.

...