Coder Social home page Coder Social logo

liverbool / php-socialshare Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dunglas/php-socialshare

0.0 2.0 0.0 418 KB

Server-side social networks share counts and share links retriever

Home Page: https://dunglas.fr/2014/01/introducing-the-socialshare-php-library/

License: MIT License

PHP 100.00%

php-socialshare's Introduction

PHP SocialShare

SocialShare is a PHP library allowing to retrieve the number of shares of URLs on major social networks. It is also able to generate valid sharing links.

It currently supports:

  • Facebook
  • Twitter
  • Google Plus
  • Pinterest
  • LinkedIn
  • Scoop.it!
  • StumbleUpon
  • Tumblr

Build Status SensioLabsInsight Scrutinizer Code Quality HHVM Status

Key features

  • Speed: counts are retrieved server-side and cached; no JavaScript SDK loading; no HTTP request from your visitor's browser to social networks
  • Privacy: therefore, no data from your visitors is send to social networks, their privacy is respected
  • Customization: there is no need to use official social networks buttons, you can create beautiful custom buttons displaying the number of shares

Drawbacks

For most social networks, the number of shares is retrieved through services not officially approved by social networks. These services can be shut down without warning.

Service Official way?
Facebook yes
Twitter no
Google no
LinkedIn yes
Pinterest no
Scoop.it! no
StumbleUpon no

Google returns only an estimate when there is more than 1000 shares (something like >10K). PHP Social Share converts this estimate to an integer.

Tumblr share count cannot be retrieved for an arbitrary URL, and is therefore unavailable through this library.

Installation

Use Composer to install SocialShare:

composer require dunglas/php-socialshare

Usage

Cache

SocialShare relies on the Doctrine Cache library to store data retrieved from social networks. Doctrine Cache supports a lot of caching systems including but not limited to file, Memcache, MongoDB, Redis and APC. Use the one that suit your needs.

Delayed updates

When the third parameter of the \SocialShare\SocialShare::getShares() method is set to true, the number of share counts is never retrieved from social networks: If a value is already in the cache (how old it is doesn't matter) it is used, otherwise 0 is returned

To force the update of share counts, the \SocialShare\SocialShare::update() method must be called.

Thanks to this tweak, HTTP requests retrieving shares counts from social networks will be issued after the page load. Of course, only the next visitor will see updated counts, but it allows fast pages load even in the worst case: when the data must be updated from social networks servers.

If you use PHP FPM, the call to this method should be done after the end of the network connection with the client using the fastcgi_finish_request() function.

Other social networks

You can add support for new social networks by creating a class implementing the SocialShare\Provider\ProviderInterface interface. Pull Requests are appreciated.

They are using PHP SocialShare

Credits

This library has been written by Kévin Dunglas and awesome contributors.

php-socialshare's People

Contributors

dunglas avatar stof avatar nlemoine avatar morrelinko avatar benatespina avatar dragonbe avatar neemzy avatar

Watchers

Ishmael Dos avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.