Coder Social home page Coder Social logo

social-links's Introduction

SocialLinks

Scrutinizer Code Quality Build Status

Created by Oscar Otero http://oscarotero.com [email protected]

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>

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:

$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 -
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:

//$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

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:

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

social-links's People

Contributors

aschempp avatar bresam avatar eusonlito avatar felcerreia avatar g-rodigy avatar jedkirby avatar joehobson avatar loleksy avatar metallizzer avatar oscarotero avatar perk11 avatar peter279k avatar serpentblade avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

social-links's Issues

Composer issues

Hello,

I have tried to install this package via composer same as
composer required oscarotero/social-links
and in my composer.json I have tried

"oscarotero/social-links": "dev-master"

In both cases I got this error

  Problem 1
    - The requested package oscarotero/social-links could not be found in any version, there may be a typo in the package name.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

In my composer.json I have "minimum-stability": "dev",

Can someone help me please?

Thank you in advance!

PHP version issue

For a new project with symfony 2.7 I wanted to use your social-links library, but there is an Issue in your code, so I cannot use it.

Symfony 2.7 requres "php": ">=5.3.3", and in your composer.json:
"require": {
"php": ">=5.3.0"
},

But in you Page.php you are using the php 5.4 shorthand for array() like:
...
protected $providers = [];
...
$data = [];
...

Please update your code to valid php 5.3 or change your requirements in composer.json. PHP 5.3 is still supported by the most frameworks / server, so using shorthand code would not work on the most environments yet.

VK share wrong parameters

$page = new SocialLinks\Page([
	'url' =>  'http://mysite.com',
	'title' => 'title,
	'text' => 'text'
]);
$page->vk->shareUrl 
// return like http://vk.com/share.php?url=http://mysite.com&description=text&image=

The share url has wrong GET params:
don't contain 'title' and parameter 'description' not supported vk

Facebook Graph API response error

Base issue : FB provider always returns zero.

Hi when I am testing Facebook Provider URL builder
http://graph.facebook.com/?id=http://www.staderochelais.com/

I am getting this response :
{
"error": {
"message": "(#4) Application request limit reached",
"type": "OAuthException",
"is_transient": true,
"code": 4,
"fbtrace_id": "AzxA48LyH/z"
}
}

I just don't get how it works on the demo page.
Am I missing something ?

Is it schedule to be able to configure Facebook App credentials in order to get share count using OAuth tokens ?

Thx

Laravel 7 Support

Getting following errors while installing it to laravel 7, i'm using php 7.4.2

image

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.