PHPackages                             claudye/socialsharer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. claudye/socialsharer

ActiveLibrary

claudye/socialsharer
====================

PHP package for generating social share links.

12744PHP

Since Dec 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Claudye/socialsharer)[ Packagist](https://packagist.org/packages/claudye/socialsharer)[ RSS](/packages/claudye-socialsharer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

### Introduction

[](#introduction)

PHP package to share links on social networks in a simple and fast way.

### Features

[](#features)

- Share on all social networks (sms, copy-paste, gmail etc.)
- Share on specially on some networks like whatsapp, facebook
- Support JavaScript Sharing API
- Ability to style the buttons as desired.

### Installation

[](#installation)

- First you need to have [composer](https://getcomposer.org/download/) installed
- Go to the root of your project
- Open your terminal and type `composer require claudye/socialsharer:dev-master` to install the sharer If no error appears, it means you have successfully installed the **Socialsharer**

### Use

[](#use)

Include composer class autoload file where you want to use socialsharer or anywhere composer can load our classes.

Ex: (To be adapted according to your case) require **DIR**.'/vendor/autoload.php';

#### Create meta tag

[](#create-meta-tag)

Start using Socialsharer

```
use Claudye\Socialsharer\Sharer;
$metabuilder = Sharer::url($url); // $url the url you want share

```

This url method return an instance of `\Claudye\Socialsharer\MetaBuilder;` you can append others methods as :

```
$metabuilder->title($title); //$title the title you want share
$metabuilder->description($description) // $description that you want share
$metabuilder->meta($porperty, $content)

```

The `\Claudye\Socialsharer\MetaBuilder` class let you to build your meta tag dynamically with the `meta($porperty, $content)` method

The first argument `$porperty` is the name of the meta, the second argument `$content` is the meta tag content

Ex:

```
$metabuilder = new MetaBuilder();
$metabuilder->meta('og:image','image.png') // let you to create a html tag like this :

```

You can create many tag by calling this meta as you want

#### Create social sharer link

[](#create-social-sharer-link)

Once you have created the meta tags, you can freely create your social media sharing links (SMS, Facebook, Whatsapp, etc.)

The most important button is the global share button. With it, your users can easily share your links on all natively supported platforms

##### Create the global button

[](#create-the-global-button)

```
$all = Sharer::all();

```

With this you instantiate a button creation

Tripycally this method returns an instance of `Claudye\Socialsharer\All` which allows you to build your button as you wish. You can modify its content or add an hhtml attribute to customize its appearance as you wish:

```
$all->addContent('Share on social media');
$add->addAttribute('class','btn my-btn-class');
$add->addAttribute('id','my-btn-id');

```

That's all, now you can display your share button by these ways:

```
echo $all->display();
echo $all ;

```

You can create the button and at the same time add the html attributes like this

`Sharer::all('content', ['class'=>'your-class', 'id'=>'btn-id'])` without calling the `addContent()` and `addAttribute()` methods

#### Supported networks

[](#supported-networks)

For the moment although the all method can allow you to share via SMS, copy and paste, Facebook, Share on Twitter etc, Linkedin, ... we also have other specific methods such: `facebook()`, `whatsapp()` which can allow you to share on these networks easily. These methods accept the same arguments as the method. `Sharer::all()`

`Sharer::facebook('icon Facebook')`, allows you to generate the share link on facebook

`Sharer::whatsapp('icon, Whatsapp)`, allows you to share on whatsapp with several people

#### Enabling Sharing

[](#enabling-sharing)

After creating the links, two more steps are required or one is essential.

For link sharing to be functional, we must import our script and place it before the end of the body tag of your page to be shared.

```
$scriptsOfSharer = Sharer::scripts();
echo $scriptsOfSharer or echo Sharer::scripts();

```

For social networks and robots to display the title, description and image of your page directly on their networks, you must display the meta tags that you have just created in the header of your page.

```
$metaTags = Sharer::createMeta();
echo $metaTags ou echo Sharer::createMeta();

```

### Example

[](#example)

```
