你能帮我解决这个问题吗:
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>);
});