0

これについて私を助けてもらえますか:

class Custom_View_Helper_AddThis extends Zend_View_Helper_Abstract
{

    static $instances = 0;

    /**
     * @var Zend_View_Interface 
     */
    public $view;

    /**
     *  Return AddThis social sharin toolkit
     *  @param $url uri of page to share
     *  @param $title title of page
     *  @param $anews render social addthis at the end of the news
     *  @return void
     */
    public function addThis($url = null, $title = null, $anews = false) {
        $domain = 'http://' . $_SERVER['HTTP_HOST'] . '/';
        $link = $domain . $url;
        $html = <<<EOT
        <!-- AddThis Button BEGIN -->
        <div class="addthis_toolbox addthis_default_style" addthis:url="$link" addthis:title="$title">
        <a class="addthis_button_linkedin_counter"></a>
        </div>
        <!-- AddThis Button END -->
EOT;
        $html2 = sprintf('
        <div class="addthis_toolbox addthis_default_style" addthis:url="%s" addthis:title="%s">
        <a class="vl addthis_button_google_plusone" g:plusone:size="tall"></a>
        </div>', $link, $title);

        $tracking = "
        var addthis_config = {
            data_ga_property: 'UA-XXXXXXXX-X',
            data_ga_social: true
        };" . PHP_EOL;

        $src = "//s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4f94ba586f83fcc8";
        self::$instances += 1;
        $mscript = $this->view->HeadScript();
        if (self::$instances == 1) {
            $mscript->appendScript($tracking);
            if ($anews) {
                $mscript->appendScript('
                $(document).ready(function(){
                  $("#social_link").append('. $html2 .');
                });
                ');
            }
            $mscript->appendFile($src);
        }
        return $html;
    }

    /**
     * Sets the view field 
     * @param $view Zend_View_Interface
     */
    public function setView(Zend_View_Interface $view) {
        $this->view = $view;
    }
}

ソーシャル共有プラグインを生成する zend プロジェクトのビュー ヘルパーを作成したいと考えています。

最初のアイコンとリンクは適切に設定されますが、jQuery 関数に送信されるアイコンとリンクが機能せず、firebug コンソールで無効な XML タグ構文が表示されます。私は何度も何度も試しましたが、何もうまくいかないようです。

ここで生成されたjavascript

 $(document).ready(function(){
$("#social_link").html(
<div class="addthis_toolbox addthis_default_style" addthis:url="http://ayaou//news/bonjour-ayaou" addthis:title="Bonjour Ayaou">
<a class="vl addthis_button_tweet" tw:count="vertical"></a>
<a class="vl addthis_button_google_plusone" g:plusone:size="tall"></a>
<a class="addthis_button_facebook_like" fb:like:layout="button_count"
fb:like:action="recommend"></a>
<a class="addthis_button_facebook_send"></a>
</div>);
}); 
4

1 に答える 1

0

わかりました、コードを単純で重複した html コードに変更しました。

于 2012-04-27T14:28:01.300 に答える