black-lamp / yii2-socialshare

Yii2 框架的社交分享小部件

安装: 784

依赖: 0

建议: 0

安全: 0

星标: 3

关注者: 9

分支: 1

开放性问题: 0

类型:yii2-extension

1.8.1 2017-02-28 08:50 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:37:00 UTC


README

此小部件为社交网络添加分享链接。

Latest Stable Version Latest Unstable Version License

它支持以下社交网络:

  • VK
  • Facebook
  • Twitter
  • Google+
  • LinkedIn
  • Pinterest
  • Telegram
  • Viber
  • WhatsApp
  • Gmail

安装

运行命令

composer require black-lamp/yii2-socialshare

或者

"black-lamp/yii2-socialshare": "1.*.*"

将其添加到 composer.json 的 require 部分。

将 'SocialShare' 组件添加到应用配置

'components' => [
    // ...
    'socialShare' => [
        'class' => bl\socialShare\SocialShare::className(),
        'defaultIcons' => true,
        'attributes' => [
            'class' => 'social-btn'
        ],
        'networks' => [
            'facebook' => [
                'class' => bl\socialShare\classes\Facebook::className(),
                'label' => 'Facebook'
            ],
            'twitter' => [
                'class' => bl\socialShare\classes\Twitter::className(),
                'label' => 'Twitter',
                // custom option for Twitter class
                'account' => 'twitterAccount'
            ],
            'googlePlus' => [
                'class' => bl\socialShare\classes\GooglePlus::className(),
                'label' => 'Google+'
            ],
            'vk' => [
                'class' => bl\socialShare\classes\Vkontakte::className(),
                'label' => 'vk'
            ],
            // other social networks ...
        ]
    ],
]

在此组件中,您需要添加并配置社交网络类

组件配置属性

社交网络类配置属性

使用方法

您应该在页面上使用小部件添加分享链接

    <?= \bl\socialShare\widgets\SocialShareWidget::widget([
        'componentId' => 'socialShare',
        'url' => Url::toRoute(['site/index'], true),
        'title' => 'Black Lamp - digital agancy',
        'description' => 'Black Lamp provides a comprehensive range of services for development...',
        'image' => Url::toRoute(['/logo.png'], true)
    ]) ?>

小部件配置属性

如果我想要添加新的社交网络怎么办?

您必须创建类,并从 bl\socialShare\base\SocialNetwork 抽象类继承

use bl\socialShare\base\SocialNetwork;

class LinkedIn extends SocialNetwork
{

}

并实现方法 getLink()

class LinkedIn extends bl\socialShare\base\SocialNetwork
{
    /**
     * @inheritdoc
     */
    public function getLink($url, $title, $description, $image, $component)
    {
    }
}

此方法必须初始化到社交网络的路线,并返回带有 $component 参数的 initLink() 方法

/**
 * @inheritdoc
 */
public function getLink($url, $title, $description, $image, $component)
{
    $this->_route = "https://www.linkedin.com/shareArticle?mini=true"
                    ."&url=$url"
                    ."&title=$title"
                    ."&summary=$description";
                    
    return $this->initLink($component);
}

其他扩展

yii2-social-networks - 此小部件为社交网络添加链接