tmukherjee13/yii2-socialshare

Social share widget for the Yii2 Framework

Installs: 24

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 1

Type:yii2-extension

2.0.0 2019-09-26 09:31 UTC

This package is auto-updated.

Last update: 2024-10-28 22:39:43 UTC


README

This widget adds share links for social networks.

Latest Stable Version Latest Unstable Version License

It supports from the box

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

Installation

Run command

composer require tmukherjee13/yii2-socialshare

or add

"tmukherjee13/yii2-socialshare": "1.*"

to the require section of your composer.json.

Add 'SocialShare' component to application config

'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 ...
        ]
    ],
]

In this component you need to add and configure social network classes

Component configuration properties

Social network class configuration properties

Using

You should use the widget for adding the share links on page

    <?= \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)
    ]) ?>

Widget configuration properties

What if i want to add a new social network?

You must create class and extend it from bl\socialShare\base\SocialNetwork abstract class

use bl\socialShare\base\SocialNetwork;

class LinkedIn extends SocialNetwork
{

}

and implement the method getLink()

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

this method must initialize route to the social network and return initLink() method with $component argument

/**
 * @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);
}

UPDATE

This fork fixes the conflict of using Object in classes since in PHP 7.2 Object is a reserved keyword.

Other extensions

yii2-social-networks - this widget adds links to social networks