2017 © Pedro Peláez
 

library social-links

PHP library to generate share buttons

image

social-links/social-links

PHP library to generate share buttons

  • Monday, May 7, 2018
  • by oscarotero
  • Repository
  • 6 Watchers
  • 78 Stars
  • 80,615 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 18 Forks
  • 2 Open issues
  • 28 Versions
  • 6 % Grown

The README.md

SocialLinks

Scrutinizer Code Quality Build Status, (*1)

Created by Oscar Otero http://oscarotero.com oom@oscarotero.com, (*2)

This is a simple library to generate buttons to share an url or count the current shares using multiple providers (facebook, twitter, etc) It also generate the appropiate meta tags to insert in the <head>, (*3)

Usage

use SocialLinks\Page;

//Create a Page instance with the url information
$page = new Page([
    'url' => 'http://mypage.com',
    'title' => 'Page title',
    'text' => 'Extended page description',
    'image' => 'http://mypage.com/image.png',
    'icon' => 'http://mypage.com/favicon.png',
    'twitterUser' => '@twitterUser'
]);

//Use the properties to get the providers info, for example:
$facebookProvider = $page->facebook;

//Each provider has the following info:
$page->twitter->shareUrl; //The url to share this page  (returns null if is not available)
$page->twitter->shareCount; //The number of the current shares (returns null if is not available)

//Example
$link = '<a href="%s">%s (%s)</a>';

printf($link, $page->facebook->shareUrl, 'Share in Facebook', $page->facebook->shareCount);
printf($link, $page->twitter->shareUrl, 'Share in Twitter', $page->twitter->shareCount);
printf($link, $page->plus->shareUrl, 'Share in Google Plus', $page->plus->shareCount);
printf($link, $page->pinterest->shareUrl, 'Share in Pinterest', $page->pinterest->shareCount);
printf($link, $page->linkedin->shareUrl, 'Share in Linkedin', $page->linkedin->shareCount);
printf($link, $page->stumbleupon->shareUrl, 'Share StumbleUpon', $page->stumbleupon->shareCount);

Preload share counters

When you use, for example $page->facebook->shareCount, a request to facebook API is executed. This means that if you need also $page->linkedin->shareCount and $page->plus->shareCount, three requests are required. To improve performance, you can execute all these requests in parallel. Example:, (*4)

$page = newPage(['url' => 'http://page.com']);

//Preload the counters
$page->shareCount(['linkedin', 'facebook', 'plus']);

//Use them
echo $page->facebook->shareCount;
echo $page->linkedin->shareCount;
echo $page->plus->shareCount;

Providers supported

Name Counter
blogger -
bobrdobr -
cabozo -
chuza YES
classroom -
delicious -
digg -
email -
evernote -
facebook YES
line -
linkedin YES
liveinternet -
livejournal -
mailru YES
meneame YES
odnoklassniki YES
pinterest -
plus YES
pocket -
reddit YES
scoopit YES
sms -
stumbleupon YES
telegram -
threads -
tumblr -
twitter -
viadeo -
vk -
whatsapp -
xing YES

Generate social meta tags

You can use this library to generate also the tags for opengraph, twitter cards, etc. Example:, (*5)

//$page is the same variable than the example above

//Use magic methods (instead magic properties) to get the objects with specific metas:
$card = $page->twitterCard();

//The object is traversable:
foreach($card as $tag) {
    echo $tag;
}

//You can get each tag by it's name (without prefix)
echo $card['card']; //<meta property="twitter:card" content="Summary">

//Add/edit more metas
$card->addMeta('author', '@the_author'); //<meta property="twitter:author" content="@the_autor">

Meta supported

  • html
  • openGraph
  • twitterCard
  • schema

Usage in Symfony

There is a Symfony bundle available here: https://github.com/astina/AstinaSocialLinksBundle, (*6)

Contributions

  • All code must be PSR-1 and PSR-2 compilance. You can use this php cs-fixer
  • The providers class names must be in lowercase starting by uppercase. For example Linkedin instead LinkedIn.
  • Add the new providers to demo/index.php

Thanks to:, (*7)

  • peric For adding Email provider and some fixes
  • eusonlito For some fixes
  • perk for adding new providers

The Versions

07/05 2018

dev-master

9999999-dev https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

social facebook twitter opengraph links share buttons twittercards

16/04 2018

v1.13.2

1.13.2.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

social facebook twitter opengraph links share buttons twittercards

18/12 2017

v1.13.1

1.13.1.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

social facebook twitter opengraph links share buttons twittercards

04/09 2017

v1.13.0

1.13.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

social facebook twitter opengraph links share buttons twittercards

25/01 2017

v1.12.1

1.12.1.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

social facebook twitter opengraph links share buttons twittercards

31/12 2016

v1.12.0

1.12.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

social facebook twitter opengraph links share buttons twittercards

16/11 2016

v1.11.2

1.11.2.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

social facebook twitter opengraph links share buttons twittercards

21/10 2016

v1.11.1

1.11.1.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

social facebook twitter opengraph links share buttons twittercards

17/06 2016

v1.11.0

1.11.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

social facebook twitter opengraph links share buttons twittercards

22/04 2016

v1.10.0

1.10.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

social facebook twitter opengraph links share buttons twittercards

01/04 2016

v1.9.0

1.9.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

social facebook twitter opengraph links share buttons twittercards

09/10 2015

v1.8.1

1.8.1.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

social facebook twitter opengraph links share buttons twittercards

25/09 2015

v1.8.0

1.8.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

social facebook twitter opengraph links share buttons twittercards

13/09 2015

v1.7.0

1.7.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

social facebook twitter opengraph links share buttons twittercards

15/08 2015

v1.6.2

1.6.2.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

15/08 2015

v1.6.1

1.6.1.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

13/08 2015

v1.6.0

1.6.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

29/06 2015

v1.5.1

1.5.1.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

24/03 2015

v1.5

1.5.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

05/03 2015

v1.4.2

1.4.2.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

17/12 2014

v1.4.1

1.4.1.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

16/12 2014

v1.4.0

1.4.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

24/10 2014

v1.3.0

1.3.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

24/10 2014

v1.2.2

1.2.2.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

30/09 2014

v1.2.1

1.2.1.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

23/09 2014

v1.2.0

1.2.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

09/06 2014

v1.1

1.1.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image

07/04 2014

v1.0

1.0.0.0 https://github.com/oscarotero/social-links

PHP library to generate share buttons

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

image