【问题标题】:How to do the share extension to show the http shares and not the https?如何进行共享扩展以显示 http 共享而不是 https?
【发布时间】:2016-03-12 12:23:56
【问题描述】:

我在 Facebook 对象调试器上有这种情况:

这个是如果我输入http链接

这个是 https 链接

我的joomla扩展的代码是:

<?php

/*------------------------------------------------------------------------
# mod_ofblikebutton - Optimized Facebook Like Button
#    ------------------------------------------------------------------------

# author:    Optimized Sense
# copyright: Copyright (C) 2013 http://www.o-sense.com. All Rights Reserved.
# @license: http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://www.o-sense.com
# Technical Support:  http://www.o-sense.com/contact-us/support-inquiries.html
-------------------------------------------------------------------------*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
class oFBLikeButton{
    function getData(&$params ){        
        $oFBLinkTitle   = 'O-Sense';
        $oFBLink    = 'http://www.o-sense.com';
        //$oFBLinkImg = 'http://www.o-sense.com/osensecopy.png';
        //$oFlink   = $params->get('olink');///
        $oFBLink = JURI::current();
        $oFshowSend = $params->get('oshowSend');///
        $oFstyle    = $params->get('ostyle');
        $oFwidth    = $params->get('owidth', '400');///
        $oFfaces    = $params->get('ofaces');///        
        $oFfont = $params->get('ofont');///
        $oFcolor    = $params->get('ocolor');///
        $oFverb = $params->get('overb');///
        $oFsource   = $params->get('osource');///
        $oFlang     = $params->get('olang');///
        if($oFfaces == '1'){
            $oFfaces    = 'true';
        }else{
            $oFfaces    = 'false';
        }
        if($oFshowSend == '1'){
            $oFshowSend = 'true';
        }else{
            $oFshowSend = 'false';
        }
        $data ='';
        if($oFsource == '1'){
            //HTML5 

            $app = JFactory::getApplication();

            $menu = $app->getMenu();

            $lang = JFactory::getLanguage();
            $fburl = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 

            if($fburl == 'https://www.atlantotec.com/de/' || $fburl == 'https://www.atlantotec.com' || $fburl == 'https://www.atlantotec.com/de')

            {
                $pageurl = 'http://www.atlantotec.com/de/';
                $spageurl = 'https://www.atlantotec.com/de/';

            } else { 

                $finalurls = explode('/',$_SERVER['REQUEST_URI']);
                $urls = '';
                foreach ($finalurls as $finalurl){

                    if($finalurl != ''){

                        $urls .= '/'.$finalurl;

                    }

                }

                if ($lang->getTag() == 'it-IT') {
                    $pageurl = 'http://'.$_SERVER['HTTP_HOST'].$urls;

                    $spageurl = 'https://'.$_SERVER['HTTP_HOST'].$urls;
                } else {
                    $pageurl = 'http://'.$_SERVER['HTTP_HOST'].$urls;

                    $spageurl = 'https://'.$_SERVER['HTTP_HOST'].$urls;

                }

            }
            $data = '<div id="fb-root"></div>

<script>(function(d, s, id) {

  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5&appId=541263185976160";

  fjs.parentNode.insertBefore(js, fjs);
}(document, \'script\', \'facebook-jssdk\'));</script>';

            $data = $data . '<div class="fb-like" data-href="'.$pageurl.'" data-layout="button_count" data-action="like" data-show-faces="true" data-share="true"></div>';

            /*$url = 'http://api.facebook.com/restserver.php?method=links.getStats&urls='.$pageurl.','.$spageurl;

            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            $retrun = curl_exec($ch);
            curl_close($ch);
            $oXML = new SimpleXMLElement($retrun);
            $total_count=0;

            foreach($oXML->link_stat as $link_stat){

                //if($total_count != $link_stat->total_count || $total_count ==0)

                $total_count += $link_stat->total_count; 

            }*/

            /*$data = '<div class="fb-like" data-href="'.$spageurl.'" data-layout="button" data-action="like" data-show-faces="false" data-share="true"></div>';

            $data = '<div id="fb-root"></div><script language="javascript" type="text/javascript">(function(d, s, id) {  var js, fjs = d.getElementsByTagName(s)[0];  if (d.getElementById(id)) {return;}  js = d.createElement(s); js.id = id;  js.src = "//connect.facebook.net/'.$oFlang.'/all.js#xfbml=1";  fjs.parentNode.insertBefore(js, fjs);}(document, \'script\', \'facebook-jssdk\'));</script>';

            $data = $data.'<script language="javascript" type="text/javascript">//<![CDATA[ 
                                                                                           document.write(\'<div class="fb-like" data-href="'.$pageurl.'" data-width="'.$oFwidth.'" data-colorscheme="'.$oFcolor.'" data-show-faces="'.$oFfaces.'" data-send="'.$oFshowSend.'" data-font="'.$oFfont.'" data-action="'.$oFverb.'" data-layout="button"></div><div class="pluginCountButton pluginCountNum"><div class="pluginCountButtonNub"><s></s><i></i></div><span id="fb-count">'.$total_count.'</span></div> \'); 
                                                                                           //]]>
            </script>              <div style="display:none; position: relative; height: 15px; width: 100%; font-size: 10px; color: #808080; font-weight: normal; font-family: \'lucida grande\',tahoma,verdana,arial,sans-serif; line-height: 1.28; text-align: right; direction: ltr;"><a href="'.$pageurl.'" target="_blank" style="color: #808080;"> <img alt="OSense" src="'.$oFBLinkImg.'" style="visibility:visible; zoom: 1; opacity: 1; vertical-align: text-top;" />  '.$oFBLinkTitle.'</a></div>';*/

            /*$data = $data.'<script language="javascript" type="text/javascript">//<![CDATA[ 
                                                                                           document.write(\'<div class="fb-like" data-href="'.$spageurl.'" data-width="'.$oFwidth.'" data-colorscheme="'.$oFcolor.'" data-show-faces="'.$oFfaces.'" data-send="'.$oFshowSend.'" data-font="'.$oFfont.'" data-action="'.$oFverb.'" data-layout="'.$oFstyle.'"></div> \'); 

               //]]>

            </script>              <div style="display:none; position: relative; height: 15px; width: 100%; font-size: 10px; color: #808080; font-weight: normal; font-family: \'lucida grande\',tahoma,verdana,arial,sans-serif; line-height: 1.28; text-align: right; direction: ltr;"><a href="'.$spageurl.'" target="_blank" style="color: #808080;"> <img alt="OSense" src="'.$oFBLinkImg.'" style="visibility:visible; zoom: 1; opacity: 1; vertical-align: text-top;" />  '.$oFBLinkTitle.'</a></div>';*/

        }else if($oFsource == '2'){
            //XFBML
            $data = '<div id="fb-root"></div><script language="javascript" type="text/javascript">(function(d, s, id) {  var js, fjs = d.getElementsByTagName(s)[0];  if (d.getElementById(id)) {return;}  js = d.createElement(s); js.id = id;  js.src = "//connect.facebook.net/'.$oFlang.'/all.js#xfbml=1";  fjs.parentNode.insertBefore(js, fjs);}(document, \'script\', \'facebook-jssdk\'));</script>';

            $data = $data.'<script language="javascript" type="text/javascript">//<![CDATA[ 
               document.write(\'<fb:like href="'.$oFlink.'" width="'.$oFwidth.'" colorscheme="'.$oFcolor.'" show_faces="'.$oFfaces.'" font="'.$oFfont.'" send="'.$oFshowSend.'" layout="'.$oFstyle.'" action="'.$oFverb.'"></fb:like> \'); 

               //]]>
            </script>           <div style="display:none; position: relative; height: 15px; width: 100%; font-size: 10px; color: #808080; font-weight: normal; font-family: \'lucida grande\',tahoma,verdana,arial,sans-serif; line-height: 1.28; text-align: right; direction: ltr;"><a href="'.$oFBLink.'" target="_blank" style="color: #808080;"> <img alt="OSense" src="'.$oFBLinkImg.'" style="visibility:visible; zoom: 1; opacity: 1; vertical-align: text-top;" />  '.$oFBLinkTitle.'</a></div>';
        }else { 
            //iFrame            

            $oFsource   ="http://www.facebook.com/plugins/like.php?locale=".$oFlang."&amp;href=".$oFlink."&amp;width=".$oFwidth .
                    "&amp;colorscheme=".$oFcolor."&amp;show_faces=".$oFfaces .

                    "&amp;send=".$oFshowSend."&amp;layout=".$oFstyle."&amp;font=".$oFfont."&amp;action=".$oFverb."&amp;height=26";

            $data = '<iframe src="'.$oFsource.'" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:'.$oFwidth.'px; height:26px;" allowTransparency="true"></iframe>      <div style="display:none; position: relative; height: 15px; width: 100%; font-size: 10px; color: #808080; font-weight: normal; font-family: \'lucida grande\',tahoma,verdana,arial,sans-serif; line-height: 1.28; text-align: right; direction: ltr;"><a href="'.$oFBLink.'" target="_blank" style="color: #808080;"> <img alt="OSense" src="'.$oFBLinkImg.'" style="visibility:visible; zoom: 1; opacity: 1; vertical-align: text-top;" />  '.$oFBLinkTitle.'</a></div>';

        }


        return $data;

    }
}

.httaccess 代码是:

RewriteEngine on
Options +FollowSymLinks

#
# HTTPS Redirect

RewriteCond %{HTTP_HOST} !^www\.atlantotec\.com$
RewriteRule ^(.*)$ https://www.atlantotec.com/$1 [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^(.*)=it$ http://www.atlantotec.com/it/$1 [R,NC]
RewriteRule ^(.*)=de$ http://www.atlantotec.com/de/$1 [R,NC]
RewriteRule ^(.*)=en$ http://www.atlantotec.com/en/$1 [R,NC]

我想做的是分享http链接并显示来自http链接的分享,此时我可以分享http链接,但我看到了https分享。

在 Facebook 对象调试器中,您可以查看如果我检查 http 链接,我会看到 https 共享,如果我检查 https 链接,我会看到 http 共享。

我已经删除了规范标签,但如果你认为这是一个选项,它就不起作用了。

那么如何分享http,看到http分享不是https呢?

【问题讨论】:

    标签: php facebook joomla meta-tags joomla-extensions


    【解决方案1】:

    我刚刚检查了您的网站,您网站的主要问题是您正在从 http 重定向到 https,但是 og:url 设置为 http:// 版本。检查 HTML 代码,您将看到:

    <meta property="og:url" content="http://www.[yourdomain].com"/>
    

    这让 Facebook 感到困惑,当您处于 http 模式时,您应该将 og:url 设为 http,而当您处于 https 模式时,您应该将 og:url 设为 https。

    PS:我仍然在代码中看到这个...

    <link href="/de/" rel="canonical" />
    

    ...但我不认为这是有害的。

    【讨论】:

    • 我的网站现在只处于 https 模式。并且我想分享http模式并在网站上展示http模式。我希望 facebook 仅将我视为 http 模式。
    • @focusoft:如果您的网站自动将所有内容重定向到 HTTPS,但您希望 Facebook 使用您的 URL 的 HTTP 版本——那么当 FB 抓取工具请求它们时,您不能自动重定向到 HTTPS,但让它从 HTTP URL 读取必要的元数据。 FB Scaper can be identified by its User Agent - 因此在 HTTP->HTTPS 重写中添加一个例外。
    • @CBroe 你的意思是在 .httaccess 中添加一个规则?
    • 如果你的重定向在那里配置,那么是的。
    • 我会尝试,如果它有效,我会告诉你。我编辑问题,我也会添加实际的 .httaccess 代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多