2017 © Pedro Peláez
 

yii2-extension yii2-socialshare

Yii2 Social Link Sharer Extension

image

alkurn/yii2-socialshare

Yii2 Social Link Sharer Extension

  • Wednesday, August 16, 2017
  • by ganesh.alkurn
  • Repository
  • 1 Watchers
  • 0 Stars
  • 85 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 25 % Grown

The README.md

yii2-socialshare

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Yii2 Social Link Sharer, (*2)

Built using Bootstrap Social and Font Awesome , two very cool projects ! Please keep in mind that this is a work in progress., (*3)

Install

The preferred way of installing is through composer, (*4)

    composer require --prefer-dist alkurn/yii2-socialshare "dev-master"

OR add to composer.json, (*5)

    "alkurn/yii2-socialshare": "dev-master"

Example usage :

    use alkurn\socialshare\Share;

By default you can run the widget with no configuration parameters, (*6)

    echo Share::widget();

this will produce an unordered list "ul" tag like, (*7)

    <ul>
        <li><a>....</a></li>
        <li><a>....</a></li>
        <li><a>....</a></li>
    </ul>

Changing the layout of the widget

    echo Share::widget([
        'type' => 'small',
        'tag' => 'div',
        'template' => '<div>{button}</div>',
    ]);

The output of this will be something similar to :, (*8)

    <div>
        <div><a> .... </a></div>
        <div><a> .... </a></div>
        <div><a> .... </a></div>
    </div>

The shared URL

By default the widget set's the URL to the current route, you can change that as needed by using the "url" property., (*9)

    echo Share::widget([
        'url' => 'http://www.domain.com',
    ]);

Or, (*10)

    echo Share::widget([
        'url' => Url::to(['site/index'] , TRUE),
    ]);

Don't forget to require the helper library Url and to use the second parameter of the method for the full URL to the page., (*11)

    use yii\helpers\Url;

The shared data

By default the widget pass to social network only URL. Some networks, for example Pinterest, allow pass title, description and image. You can change that as needed by using the "title", "description" or "image" properties., (*12)

    echo Share::widget([
        'title' => 'Some title',
        'description' => 'Some description',
        'image' => '/path-to-some-image.jpg',
    ]);

Attributes of main container

You can add or change attributes of the main container using the htmlOptions property. By default the main container has an id attribute similar to #w0, you can change that if you want., (*13)

    echo Share::widget([
        'htmlOptions' => [
            'id' => 'new-id',
            'class' => 'my-class',
        ],
    ]);

Widget button types

The widget provides to types of buttons small (icon only) large (icon + text), (*14)

    echo Share::widget([
        'type' => Share::TYPE_SMALL
    ]);
    echo Share::widget([
        'type' => Share::TYPE_LARGE
    ]);

The default text for the large buttons is "Share on NETWORK", where NETWORK is the name of the social network ex : Facebook. You can change the default text by using the "text" property of the widget., (*15)

    echo Share::widget([
        'text' => 'Click to share on {network}',
    ]);

Networks

Currently the widget provides 6 buttons Facebook Google Plus Twitter Pinterest Linkedin Vk odnoklassniki, (*16)

Including only some networks

For some reason you may need to include only some networks. In order to do that you can use the "include" property of the widget, (*17)

    echo Share::widget([
        'include' => ['network1', 'network2']
    ]);

Presented social networks will be shown in that order in which you put them., (*18)

Excluding some networks

For some reason you may need to exclude one or more networks. In order to do that you can use the "exclude" property of the widget, (*19)

    echo Share::widget([
        'exclude' => ['network1', 'network2']
    ]);

Contributions

Contributions are most welcomed, just fork modify and submit a pull request., (*20)

The Versions

16/08 2017

dev-master

9999999-dev

Yii2 Social Link Sharer Extension

  Sources   Download

MIT

The Requires

 

social yii2 widget share