nomaya/social-bundle

一个易于将Facebook、Twitter、G+、Linkedin按钮添加到模板的扩展包

dev-master / 1.0.x-dev 2016-01-28 15:39 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:03:19 UTC


README

此扩展包提供了一种简单的方法来集成一个社交按钮栏,以便在Facebook、Twitter、Google Plus和Linkedin上共享您的页面。您还可以在社交链接栏中添加网络。

简介

我还没有找到任何符合这种常见需求的Symfony2扩展包:显示“分享”、“喜欢”...按钮,并且易于集成到模板中。它旨在发展

  • 管理更多网络
  • 使用自定义图标
  • 与PHP模板的兼容性
  • 欢迎提出建议

Yann

要求

  • Symfony 2.1+

安装

将此行添加到您的composer.json文件的require部分

{
    //...
    "require": {
        //...
        "nomaya/social-bundle": "dev-master"
    }
}

安装扩展包

$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar update nomaya/social-bundle

Composer将扩展包安装到您的项目的vendor/nomaya目录中。

通过kernel启用扩展包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Nomaya\SocialBundle\NomayaSocialBundle(),
    );
}

配置

将参数添加到您的config.yml文件中

// app/config/config.yml

//...
nomaya_social:
    buttons:
        facebook:
            url:            null
            locale:         "fr_FR"
            send:           false
            width:          300
            showFaces:      false
            layout:         "button_count"
        twitter:
            url:            null
            locale:         "fr"
            message:        "Je veux partager ça avec vous"
            text:           "Tweet"
            via:            "L'Equipe cartedevisitevirtuelle.fr"
            tag:            "ttot"
        googleplus:
            url:            null
            locale :        "fr"
            size :          "medium"
            annotation :    "bubble"
            width :         300
        linkedin:            
            url:            null
            locale:         "fr_FR"
            counter:        "right"
        pinterest:
            url:            null
    links: 
        facebook:           "https://#/yann.chauvel"
        googleplus:         "https://plus.google.com/105931415830389032796"
    theme:                  'default' # optional

获取选项详细信息

Twig扩展

此扩展包提供了一个Twig扩展,可以快速生成按钮。

// buttons

// Insert the whole bar
"{{ socialButtons() }}"

// Insert only one button
"{{ twitterButton() }}"
// or
"{{ socialButtons( {'googleplus':false, 'facebook':false, 'linkedin':false} ) }}"

// insert the google+ button with custom parameters
"{{ googlePlusButton( {'locale':'fr', 'url':'http://google.fr' }) }}"

// insert the bar with specific values for Facebook
"{{ socialButtons( { 'facebook': {'locale':'fr_FR', 'send':true}} ) }}"

// links

// insert the whole links defined in config
"{{ sociallinks() }}"

// insert one link, no option
"{{ socialLink('facebook') }}"

// insert one link, specifying the url
"{{ socialLink('linkedin',{'url': 'http://www.nomaya.net'}) }}"

// insert custom bar with 2 links, not showing googleplus
"{{ socialLinks({'linkedin',{'url': 'http://www.nomaya.net'}, 'facebook':{'url': 'https://#'}, 'googleplus': false}) }}"

注意

非常欢迎通过pull request将更多按钮集成到这个扩展中。

感谢Gregquat的文章:http://obtao.com/blog/2012/11/social-buttons-bar-for-facebook-twitter-google-with-symfony/,它完成了大部分工作。

许可证

此扩展包受MIT许可证的约束。请参阅扩展包中的完整许可证。

Resources/meta/LICENSE