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

I want to add a new button near: hide, edit, etc... i questions, comments and answers. The problem is that I've already been looking in the file qa-theme-base.php and haven't found anything. I've seen the function q_view_main which calls q_view_buttons. From there on, I'm lost.

I've read the buttons HTML and thei're real HTML inputs, but I would like to make just a simple link with the same style. Is that possible?

EDIT: I already know hot to show the button. But I would like to know how to redirect each button to a specific page. Ex:

index.php/post/"postid"

And replace "postid" by the ID of the post.

by
I'd like to know how to add a new button.

1 Answer

+2 votes
by
 
Best answer

In your qa-plugin.php file, you can check the appropriate POST variable (from your button name), and then perform a redirect if appropriate. The functions in qa-base.php will help you. For compatibility make sure you use a button name which will be unique to your plugin.

by
I haven't though about that. Thanks. :)
by
edited by
Is Q2A hidding PHP errors? Because I do that, and I only get a blank screen.
This is the redirect code:

if (qa_clicked('doreportq') && qa_get_logged_in_userid() != null){
        qa_redirect("report/".(integer)qa_get('reported_postid'));
}

EDIT: The problem is in qa_get_logged_in_userid() != null, but I don't know why. Anyway, that isn't very important. However, the redirect function just adds the URL to the end of the current page, doesn't really redirects! :S
by
have you tried:

qa_redirect("/report/".(integer)qa_get('reported_postid'));

?  Just a guess, but the preceding front slash will probably make it a proper redirect.
by
Is the same thing. The page still doesn't redirects.
Probable reason: Because of the "nice URL's", the browser is treating the page as if it was on a sub-folder, so when the links are only relative-paths, it just works with them from the current folder.
Possible Solution: Get the base URL for Q2A installation. For this I used qa_path(), but is formed a weird URL:
 -> http://localhost/question2answer/index.php/index.php/index.php/report/
From this calling:
qa_redirect(qa_path("/report/".qa_get('reported_postid')));

Any suggestions? :S
by
edited by
what about just:

header('Location: /report/'.qa_get('reported_postid'));

?

That's all qa_redirect is doing anyway...
by
You said it. The header would have the same result, bacause it's what Q2A sends to the browser when redirecting, an header. I used qa_path because I thought it would generate a full URL. :(
by
That's hard to believe... on my site, when I do:

header('Location: /questions');

in the admin (I have a php entry plugin), it redirects me to mysite.com/questions
by
Sorry, edited my above comment... it should be:

header('Location: /report/'.qa_get('reported_postid'));
by
That happens on your site like that because your Q2A installation seems to be in the root of your site. But that may not be the case, which means that it brings compatibility issues. That's one of the reasons why we should not use relative URLs in our links. For example, when I build a PHP application, I build always a static class to create predefined or custom links more easily, so when I change something in the structure of the site, I usually only have to change the code of that class. I just would like to know if there is a way to know the Q2A installation URL.

Anyway, thanks for the effort. :)
by
What about:

global $qa_root_url_relative;
qa_redirect($qa_root_url_relative.'report/'.qa_get('reported_postid'));

?
by
Just add's the index.php before the report. Is the same. :S
by
Okay, what about:

$dir = dirname(str_replace($_SERVER['DOCUMENT_ROOT'],'',QA_BASE_DIR));
qa_redirect($dir.'report/'.qa_get('reported_postid'));

?
by
If you want to redirect to a particular page in your Q2A installation, just use qa_redirect(...) with the Q2A request for that page. This will take care of creating the relative path for the chosen URL type. For example:

qa_redirect('admin/lists');
qa_redirect('7185/layer-question');
by
As I said, that doesn't work. With the exactily same code you gave me, it produces the following URL:
question2answer/index.php/89/index.php/admin/lists

The most strange is that even if I put the full addresss in the code, like:
qa_redirect('http://localhost/question2answer/index.php/report/2');

It add's it to the end of the current address. :S
If it matters, I'm using the latest version of Q2A and FF6.0
It's the first time something like this happens to me. Usually, the full address works. :S
by
maybe it's a problem with .htaccess?
by
Maybe. But I didn't change the .htaccess, so it's exactly the same that comes with Q2A.
by
That's weird. How about:

qa_redirect('admin/lists', null, qa_opt('site_url'));

That will create an HTTP Location: redirection header with an absolute instead of relative URL, which perhaps Firefox 6 prefers.
...