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

I have been trying to use the Social Share Plugin. When I ask to share a question, it shares an incorrect link.

It shares

site_url/my_post_number/my_question

instead of

site_url/index.php/my_post_number/my_question

I believe that the problem is in this line

$page_url      = urlencode(qa_opt('site_url').$request);

since  qa_opt('site_url') does not include the index.php, since my site is like "/index.php/123/why-do-birds-sing" . Is this the possible problem? What is the correct way to correct it? Is there a more robust way to deal with that?

I also have a similar problem when the plugin is loading the images

url('.qa_opt('site_url').'qa-plugin/'.SOCIAL_SHARE_PLUGIN_DIR_NAME.'/images/ma_share_buttons_full_em.png);

From:

        $style_common = ' .qa-sss-buttons .qa-sss-final .qa-sss-img-fb, .qa-sss-buttons .qa-sss-final .qa-sss-img-tw, .qa-sss-buttons .qa-sss-final .qa-sss-img-gp, .qa-sss-buttons .qa-sss-final .qa-sss-img-li, .qa-sss-buttons .qa-sss-final  .qa-sss-img-re, .qa-sss-buttons .qa-sss-final  .qa-sss-img-em {background-image: url('.qa_opt('site_url').'qa-plugin/'.SOCIAL_SHARE_PLUGIN_DIR_NAME.'/images/ma_share_buttons_full_em.png); background-repeat: no-repeat; overflow: hidden; background-color: transparent; width: 16px; height: 16px; display: inline-block; text-indent: -999em; outline: none;} .qa-sss-buttons .qa-sss-final {float: left;} .qa-sss-widget { margin-top: 0 !important; height: auto !important; } .qa-sss-widfinal a{ margin-right: 3px; } ';

 

Is there a way to correct it?

Q2A version: 1.7.0

1 Answer

+1 vote
by
selected by
 
Best answer

I don't know much about the plugin but based on the snippets you pasted probably you'd be better using the qa_q_path function instead of urlencode(qa_opt('site_url').$request);

You will need the question id but you can get it almost from any place (e.g.: the qa_content array). If you don't have the title, you could input an empty string. Just make sure the third parameter is set to true:

qa_q_path($questionid, '', true);

I don't know how SOCIAL_SHARE_PLUGIN_DIR_NAME is being assigned but if that's in a layer you should use QA_HTML_THEME_LAYER_URLTOROOT more or less this way:

{background-image: url('.QA_HTML_THEME_LAYER_URLTOROOT.'/images/ma_sh

Again, I have not tested any of this stuff.

by
Thank you very much! The first part I replaced qa_opt('site_url') by 'qa'. I was not able to manage qa_q_path. I tried $questionid=qa_request_part(0). The second part worked like a charm!
by
Regarding qa_q_path I mean something like this:

$page_url = qa_q_path($qa_content['q_view']['raw']['postid'], '', true);
by
Thank you again!  I am getting the following error ($qa_content is defined):

Notice: Undefined variable: qa_content in /var/www/html/qa-include/qa-base.php(572) : eval()'d code on line 37

This is a function inside the layer:

    function q_view_buttons($q_view)
    {
        if ((int)qa_opt(qa_sss_opt::BUTTON_STATUS)) {
                        $page_url = qa_q_path($qa_content['q_view']['raw']['postid'], '', true);
            $page_title = urlencode($q_view['raw']['title']);
            $social_button = ami_generate_social_buttons(array(
                    '{{page_url}}'   => $page_url ,
                    '{{page_title}}' => $page_title ,
                ), $this->template );
            $this->output($social_button) ;
        }
        qa_html_theme_base::q_view_buttons($q_view);
    }
by
In a layer? I searched that urlencode code literally and got this match only: https://github.com/amiyasahu/q2a-social-share/blob/b5e088f873a81426e218e526ea9047b226bf6a34/qa-social-share-widget.php#L17

The other one you seem to be talking about in your last comment is indeed in a layer but it is not exactly the one you mentioned in your question: https://github.com/amiyasahu/q2a-social-share/blob/c4cdb8010f41bce62706ef3ea98fedd29b7a314b/qa-social-share-layer.php#L24

When you're in a layer you need to access the content array this way:

$this->content

Because you don't have the $qa_content variable
by
Thank you again! It is working now (:-). I really appreciate your help!
Sorry about the confusion. Yes, I realized later that when I posed initial question, I was dealing with the wrong place. I am really sorry about that!
...