2017 © Pedro Peláez
 

library shareable-link

Conveniently generate shareable URLs for various social media websites

image

imliam/shareable-link

Conveniently generate shareable URLs for various social media websites

  • Thursday, June 28, 2018
  • by ImLiam
  • Repository
  • 1 Watchers
  • 3 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Shareable Links

Introduction

Conveniently generate shareable URLs for a variety of different social media websites, using the syntax each uses for their own links., (*1)

Installation

You can install this package with Composer using the following command:, (*2)

composer require imliam/shareable-link:^1.0.0

Example Usage

$url = new \ImLiam\ShareableLink('http://example.com/', 'Example Site');

// Alternatively, with the helper function:
// shareable_link('http://example.com/', 'Example Site');

echo $url->facebook;
// https://www.facebook.com/dialog/share?app_id=ABC123&href=https://example.com/&display=page&title=Example+Site

echo $url->twitter;
// https://twitter.com/intent/tweet?url=https://example.com/&text=Example+Site

echo $url->whatsapp;
// https://wa.me/?text=Example+Site+https%3A%2F%2Fexample.com%2F

echo $url->linkedin;
// https://www.linkedin.com/shareArticle?mini=true&url=https://example.com/&summary=Example+Site

echo $url->pinterest;
// https://pinterest.com/pin/create/button/?media=&url=https://example.com/&description=Example+Site

echo $url->google;
// https://plus.google.com/share?url=https://example.com/

A link shareable through Facebook requires an app ID from the platform. By default, this will attempt to be obtained through a FACEBOOK_APP_ID environment variable. However, if this environment variable does not exist, or you need to pass through different app IDs for different URLs, you can pass one through explicitly to the getFacebookUrl() method., (*3)

$url = new \ImLiam\ShareableLink('http://example.com/', 'Example Site');

putenv('FACEBOOK_APP_ID=ABC123');

echo $url->facebook;
// https://www.facebook.com/dialog/share?app_id=ABC123&href=https://example.com/&display=page&title=Example+Site

echo $url->getFacebookUrl('XYZ789');
// https://www.facebook.com/dialog/share?app_id=XYZ789&href=https://example.com/&display=page&title=Example+Site

Laravel Model Trait

If you're using Laravel and want to be able to use these methods directly from an Eloquent model as a convenient method, you can simply create one., (*4)

The advantage of this is that you get full control over the URL and title you want to be used while still keeping a fluent syntax., (*5)

class News extends Model
{
    public function getShareUrlAttribute(): \ImLiam\ShareableLink
    {
        $url = route('news.show', $this->slug);

        return new \ImLiam\ShareableLink($url, $this->title);
    }
}

You can then proceed to use the pseudo-attribute method as you would use the normal class., (*6)

$news->share_url->twitter;

Credits

The Versions

28/06 2018

dev-master

9999999-dev

Conveniently generate shareable URLs for various social media websites

  Sources   Download

MIT

The Requires

  • php ^7.2

 

The Development Requires

28/06 2018

v1.0.1

1.0.1.0

Conveniently generate shareable URLs for various social media websites

  Sources   Download

MIT

The Requires

  • php ^7.2

 

The Development Requires

28/06 2018

v1.0.0

1.0.0.0

Conveniently generate shareable URLs for various social media websites

  Sources   Download

MIT

The Requires

  • php ^7.2

 

The Development Requires