2017 © Pedro Peláez
 

library social-links

Provide social network url for sharing.

image

rezozero/social-links

Provide social network url for sharing.

  • Monday, July 16, 2018
  • by ambroisemaupate
  • Repository
  • 3 Watchers
  • 10 Stars
  • 380 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 9 Versions
  • 70 % Grown

The README.md

Social links

License Version, (*1)

Examples using Font awesome and bootstrap, (*2)

Usage

Install SocialLinks using Composer, (*3)

composer require rezozero/social-links

Configure your SocialLinks instance with your data source and some output settings. Load fontawesome CSS (base, regular and brands minimum) files in your HTML page., (*4)

// Construct a new SocialLinks
$share = new \RZ\SocialLinks\SocialLinks(array(
    'url' => 'http://www.rezo-zero.com',
    'title' => 'REZO ZERO website homepage',
    // Optional image source url for pinterest. must be at least 200px by 200px, if you intent to use for facebook
    'imageUrl' => 'http://www.rezo-zero.com/templates/rezo-zero/img/apple-icon.png',
    // Optional status for overriding title for twitter, whatsapp and emails body
    'status' => 'Hey! Look at this awesome website.'
));

// Set link class prefix
$share->setClassPrefix('social-link');

// Set social icons class prefix
// Use fa for Font Awesome or an
// other for a custom icon set.
$share->setIconPrefix('fa');

// Optional:
// Set link additional classes, for example
// to add "btn" bootstrap classes.
$share->setLinkClasses('btn btn-default');

Single Url

echo $share->getUrl('twitter');

// https://twitter.com/intent/tweet?text=Hey%21%20Look%20at%20this%20awesome%20website.%20%E2%80%94%20http%3A%2F%2Fwww.rezo-zero.com
$share->setClassPrefix('social-link');
$share->setIconPrefix('fa');
echo $share->getLink('facebook', $share->getIcon('facebook'));

// <a class="social-link social-link-facebook" target="_blank" rel="nofollow" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.rezo-zero.com"><i class="social-link-icon fa fa-brands fa-square-facebook"></i><span class="social-link-name">Facebook</span></a>
$share->setClassPrefix('social-link');
$share->setIconPrefix('fa');
echo $share->getLink('facebook', $share->getUseSVG('facebook'));

// <a class="social-link social-link-facebook" target="_blank" rel="nofollow" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.rezo-zero.com"><svg class="social-link-icon fa fa-brands fa-square-facebook"><use xlink:href="#fa-facebook"></use></svg><span class="social-link-name">Facebook</span></a>

Without icons:, (*5)

echo $share->getLinks(array('facebook', 'twitter', 'linked-in'));

With <i> icons:, (*6)

echo $share->getLinksWithIcon(array('facebook', 'twitter', 'linked-in'));

With <svg> icons:, (*7)

echo $share->getLinksWithSVG(array('facebook', 'twitter', 'linked-in'));

You also can choose a not empty separator, i.e. a dash:, (*8)

echo $share->getLinksWithIcon(array('facebook', 'twitter', 'linked-in'), ' - ');

Available networks

  • delicious
  • digg
  • email
  • evernote
  • facebook (sharer by default, or /dialog/feed if you provide a facebookAppId), if you use default font-awesome icon prefix, icon class will be facebook-official. It’s still facebook for SVG icons or non font-awesome prefix.
  • friendfeed
  • google
  • google-plus
  • linked-in
  • newsvine
  • pinterest
  • pocket
  • reddit
  • scoop-it
  • slashdot
  • stumbleupon
  • tumblr
  • twitter
  • whatsapp

Twig extension

$twig->addExtension(new \RZ\SocialLinks\Twig\SocialLinksExtension());

SocialLinksExtension Twig extension introduces 3 new filters to be able to generate your social links without any PHP code., (*9)

  • social_links
  • icon_social_links
  • svg_social_links
  • tweet_links

First you’ll need to gather your social data in an associative array or simply set a string variable (it will be used as the URL)., (*10)

{% set social_data = {
    'url': 'http://www.rezo-zero.com',
    'title': 'REZO ZERO website homepage',
} %}
{# or #}
{% set social_data = 'http://www.rezo-zero.com' %}

Then, you can use one of the 3 SocialLinks filters with or without optional arguments. Selected networks can be set using an array or a simple string., (*11)

<nav class="social-links">
    {{ social_data|social_links(['facebook', 'twitter']) }}
</nav>

<nav class="social-links">
    {{ social_data|social_links('twitter') }}
</nav>

<nav class="social-links">
    {{ social_data|icon_social_links(
        ['facebook', 'twitter'], 
        'icon-prefix', 
        'class-prefix', 
        'link-classes', 
        'Share on %s'
    ) }}
</nav>

Bonus: tweet_links is a Twig filter to parse your tweets contents., (*12)

Translate share action label

We introduced shareActionLabel argument to provide title for accessibility on your social links. You can override it in your own Twig template to change the title and translate it:, (*13)

<nav class="social-links">
    {{ social_data|icon_social_links(
        ['facebook', 'twitter'], 
        'icon-prefix', 
        'class-prefix', 
        'link-classes', 
        ('share_on_%s'|trans)
    ) }}
</nav>

The Versions

16/07 2018

dev-master

9999999-dev

Provide social network url for sharing.

  Sources   Download

MIT

The Requires

 

16/07 2018

v1.3.0

1.3.0.0

Provide social network url for sharing.

  Sources   Download

MIT

The Requires

 

19/06 2018

v1.2.1

1.2.1.0

Provide social network url for sharing.

  Sources   Download

MIT

The Requires

 

19/06 2018

dev-develop

dev-develop

Provide social network url for sharing.

  Sources   Download

MIT

The Requires

 

19/06 2018

v1.2.0

1.2.0.0

Provide social network url for sharing.

  Sources   Download

MIT

The Requires

 

09/05 2017

v1.1.0

1.1.0.0

Provide social network url for sharing.

  Sources   Download

MIT

The Requires

 

27/12 2016

v1.0.0

1.0.0.0

Provide social network url for sharing.

  Sources   Download

MIT

22/03 2016

v0.1.1

0.1.1.0

Provide social network url for sharing.

  Sources   Download

MIT

16/01 2016

v0.1.0

0.1.0.0

Provide social network url for sharing.

  Sources   Download

MIT