Skip to content

Commit 224607a

Browse files
committed
Merge pull request #25 from andreygolovin/feature/addthis-js-init-template
AddThis template and configuration
2 parents 4746ae0 + 17ff46c commit 224607a

File tree

8 files changed

+55
-32
lines changed

8 files changed

+55
-32
lines changed

Block/Social/AddThis.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Magefan\Blog\Block\Social;
4+
5+
use Magento\Store\Model\ScopeInterface;
6+
7+
class AddThis extends \Magento\Framework\View\Element\Template
8+
{
9+
public function getAddThisPubId()
10+
{
11+
return $this->_scopeConfig->getValue(
12+
'mfblog/social/add_this_pubid', ScopeInterface::SCOPE_STORE
13+
);
14+
}
15+
16+
public function getAddThisLanguage()
17+
{
18+
return $this->_scopeConfig->getValue(
19+
'mfblog/social/add_this_language', ScopeInterface::SCOPE_STORE
20+
);
21+
}
22+
23+
public function toHtml()
24+
{
25+
if (!$this->getAddThisPubId()) {
26+
return '';
27+
}
28+
29+
return parent::toHtml();
30+
}
31+
}

etc/adminhtml/system.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,15 @@
266266
<comment>E.g.: "search" will make the blog search accessible from mystore.com/{blog_route}/search/query/</comment>
267267
</field>
268268
</group>
269+
<group id="social" translate="label" type="text" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
270+
<label>Social</label>
271+
<field id="add_this_pubid" type="text" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
272+
<label>AddThis ID</label>
273+
</field>
274+
<field id="add_this_language" type="text" translate="label" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
275+
<label>AddThis Language</label>
276+
</field>
277+
</group>
269278
</section>
270279
</system>
271280
</config>

etc/config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
<author_route>author</author_route>
7272
<search_route>search</search_route>
7373
</permalink>
74+
<social>
75+
<add_this_pubid>ra-4def63cd3cf37569</add_this_pubid>
76+
<add_this_language>en</add_this_language>
77+
</social>
7478
</mfblog>
7579
</default>
7680
</config>

view/frontend/layout/blog_post_list.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
<action method="setToolbarBlockName">
3131
<argument name="name" xsi:type="string">post_list_toolbar</argument>
3232
</action>
33+
34+
<block class="Magefan\Blog\Block\Social\AddThis" name="addthis.js.init" as="addthisJs" template="Magefan_Blog::addthis-js.phtml"/>
3335
</referenceBlock>
3436
</body>
3537
</page>

view/frontend/layout/blog_post_view.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<block class="Magefan\Blog\Block\Post\View\RelatedPosts" name="blog.post.relatedposts" as="relatedposts" template="Magefan_Blog::post/view/relatedposts.phtml" />
2222
<block class="Magefan\Blog\Block\Post\View\RelatedProducts" name="blog.post.relatedproducts" as="relatedproducts" template="Magefan_Blog::post/view/relatedproducts.phtml" />
2323
<block class="Magefan\Blog\Block\Post\View\Comments" name="blog.post.comments" template="post/view/comments.phtml" />
24-
<block class="Magento\Framework\View\Element\Template" name="blog.post.js" as="js" template="Magefan_Blog::post/view/js.phtml" />
24+
<block class="Magefan\Blog\Block\Social\AddThis" name="addthis.js.init" as="addthisJs" template="Magefan_Blog::addthis-js.phtml"/>
2525
</block>
2626
</block>
2727
</referenceContainer>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script type="text/javascript">
2+
var addthis_config = {
3+
"ui_language": '<?php echo $this->getAddThisLanguage(); ?>',
4+
"data_track_clickback":false
5+
}
6+
</script>
7+
<script type="text/javascript" async src="//s7.addthis.com/js/250/addthis_widget.js#pubid=<?php echo $this->getAddThisPubId(); ?>"></script>

view/frontend/templates/post/list.phtml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,5 @@ $_postCollection = $block->getPostCollection();
3737
</div>
3838

3939
<?php echo $block->getToolbarHtml() ?>
40-
41-
<script type="text/javascript">var addthis_config = {"data_track_clickback":false};</script>
42-
<script type="text/javascript" async src="//s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4def63cd3cf37569"></script>
43-
<script type="text/javascript">
44-
var addthis_config = {
45-
ui_language: "en",
46-
data_track_clickback : false
47-
}
48-
</script>
40+
<?php echo $this->getChildHtml('addthisJs'); ?>
4941
<?php endif; ?>

view/frontend/templates/post/view/js.phtml

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)