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

Hi everybody,

I did ad-hoc code to modify question2answer, after few days hard worked, I almost get things i need. This is my site: http://www.tenkana.x10.mx

One more thing I want is a simple news module. I dont want to integrate with WP or any CMS for some reasons so I decided to use Xpression news (Xnews). This is a simple news software and it is said that integrating with existing website is very simple with Xnews. I tried to integrate Xnews module to Question2Answer for days but cannot make it done so I post my problem here for some help.

First, I describle what I have done to integrate Xnews with Question2Answer.

1. my QA site is located at localhost/qa. I extract Xnews into this directory and call it from question2answer.

2. in qa-include i create file named qa-page-news.php. Here are the code inside:

    if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
        header('Location: ../');
        exit;
    }
    
    require_once QA_INCLUDE_DIR.'qa-app-format.php';
    $template="Lite";
    $qa_content=qa_content_prepare();    
    
    require_once 'xnews/news.php'; // code to extract content from xnews
    $qa_content['custom'] = $xout;
    
    return $qa_content;

3. Next, I modify a bit in qa-page.php:

- Add one more line in to $qa_routing array as below:

        'feedback' => QA_INCLUDE_DIR.'qa-page-feedback.php',
        'news' => QA_INCLUDE_DIR.'qa-page-news.php', // define new page for news

- Add pieces of code at 'include the appropriate PHP file for the page in the request' like this:

} elseif ( ($qa_request_lc_parts[0]=='user') && strlen(@$qa_request_parts[1]) ) {
            $pass_handle=$qa_request_parts[1]; // effectively a parameter that is passed to file
            $qa_template='user';
            $qa_content=require QA_INCLUDE_DIR.'qa-page-user.php';
    
        }
        /*-- My code added here --*/
        elseif ( ($qa_request_lc_parts[0]=='news') && strlen(@$qa_request_parts[1]) ) {
            $pass_handle=$qa_request_parts[1]; // effectively a parameter that is passed to file
            $qa_template='news';
            $qa_content=require QA_INCLUDE_DIR.'qa-page-news.php';    
        }

That's enough for now to review what have been done. Everything seems to work well when i request http://localhost/qa/index.php?qa=news from browser. Here are the image of my news page:

But i got problem when I click on Xnews category of the news or comments link o any link on the news page. It is redirected me to home page of question2answer. I guess that I need to change something around

else {
        $phpselfunescaped=strtr($_SERVER['PHP_SELF'], '+', ' '); // seems necessary, and plus does not work with this scheme
        $indexpath='/index.php/';
        $indexpos=strpos($phpselfunescaped, $indexpath);
       
        if (is_numeric($indexpos)) {
            $qa_used_url_format=QA_URL_FORMAT_INDEX;
            $requestparts=explode('/', substr($phpselfunescaped, $indexpos+strlen($indexpath)));
            $relativedepth=1+count($requestparts);
            $rootpath=substr($phpselfunescaped, 0, $indexpos);
    
        } else {
            $qa_used_url_format=null; // at home page so can't identify path type
            $requestparts=array();
        }
    }

in qa-index.php. However, I can not point out what i need to change and how. I tried hard someways couple of days, but I am stuck now.

Anybody can give me solution? or any clue?

I appreciate for any help. Thank you so much.

Please log in or register to answer this question.

...