Skip to content

Instantly share code, notes, and snippets.

@q2amarket
Last active January 2, 2016 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save q2amarket/8258201 to your computer and use it in GitHub Desktop.
Save q2amarket/8258201 to your computer and use it in GitHub Desktop.
Override main() function to display question view page content only for looged in user for defined category. If condition fails than we will throw error message and provide login link to user for better usability.
<?php
/*
* Q2A Market Block Category Content for Loggedin user
*
*
* @author Q2A Market
* @category Hook
* @Version: 1.00
* @author URL: http://www.q2amarket.com
*
* @Q2A Version 1.6+
*
* Usage: Chnage the first child with yoru cateogry
*/
function main()
{
$content=$this->content;
/**
*
* for better understanding what $content holds
*
* Do:
* echo '<pre>', print_r($content), '</pre>';
* or
* echo '<pre>', var_dump($content), '</pre>';
*
*/
$this->output('<div class="qa-main'.(@$this->content['hidden'] ? ' qa-main-hidden' : '').'">');
// set condition to set categoryname/categoryid
// also check if user logged in or not
if((@$content['q_view']['raw']['categoryname'] !== 'The first child') || qa_is_logged_in()) {
$this->widgets('main', 'top');
$this->page_title_error();
$this->widgets('main', 'high');
/*if (isset($content['main_form_tags']))
$this->output('<form '.$content['main_form_tags'].'>');*/
$this->main_parts($content);
/*if (isset($content['main_form_tags']))
$this->output('</form>');*/
$this->widgets('main', 'low');
$this->page_links();
$this->suggest_next();
$this->widgets('main', 'bottom');
} else {
// throw error message if condition fails
// also provide login url for usability
$this->output('<div class="qa-error">Please <a href="'.qa_opt('site_url').'?qa=login">Login</a> to view content</div>');
} // end condition here
$this->output('</div> <!-- END qa-main -->', '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment