Git Product home page Git Product logo

social-share's Introduction

Share

Share links with Laravel

This is a fork of John's share for Laravel 4.

Services available

  • Blogger : blogger
  • Digg : digg
  • Email : email
  • Evernote : evernote
  • Facebook : facebook
  • Gmail : gmail
  • LinkedIn : linkedin
  • Pinterest : pinterest
  • Reddit : reddit
  • Scoop.it : scoopit
  • Telegram.me : telegramMe
  • Tumblr : tumblr
  • Twitter : twitter
  • vk.com : vk

Installation

Install Composer dependency into your project

composer require chencha/share

Usage

Get a link (example with Twitter)

Route::get('/', function()
{
	return Share::load('http://www.example.com', 'My example')->twitter();
});

Returns a string :

https://twitter.com/intent/tweet?url=http%3A%2F%2Fwww.example.com&text=Link+description

Get many links

Route::get('/', function()
{
	return Share::load('http://www.example.com', 'Link description')->services('facebook', 'twitter');
});

Returns an array :

{
    "twitter" : "https://twitter.com/intent/tweet?url=http%3A%2F%2Fwww.example.com&text=Link+description",
    "facebook" : "https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.example.com&title=Link+description"
}

Get ALL the links

Route::get('/', function()
{
	return Share::load('http://www.example.com', 'Link description')->services();
});

Returns an array of results for all defined services.

Customization

Publish the package config:

php artisan vendor:publish --provider='Chencha\Share\ShareServiceProvider'

Add a new service in config/social-share.php:

'mynewservice' => [ 'view' => 'share.mynewservice' ]

Add Blade templating code in share.mynewservice view file to generate a URL for mynewservice. You have access to:

  • service - the service definition (shown above).
  • sep - separator used between parameters, defaults to '&'. Configurable as social-share.separator.
  • url - the URL being shared.
  • title - the title being shared.
  • media - media link being shared.

Example:

https://mynewservice.example.com?url={{ rawurlencode($url) }}<?php echo $sep; ?>title={{ rawurlencode("Check this out! $title. See it here: $url") }}

Another example for the email service. Change the service config to be [ 'view' => 'whatever' ] and put this in the view file:

mailto:?subject={{ rawurlencode("Wow, check this: $title") }}<?php echo $sep; ?>body={{ rawurlencode("Check this out! $title. See it here: $url") }}

Localizing? Easy, use Laravel's trans() call:

mailto:?subject={{ rawurlencode(trans('share.email-subject', compact('url', 'title', 'media'))) }}<?php echo $sep ?>body={{ rawurlencode(trans('share.email-body', compact('url', 'title', 'media'))) }}

Create a file at resources/lang/en/share.php with your choice of subject and body. URLs arguably have a maximum length of 2000 characters.

Notice the use of . It's the only way to print out an unencoded ampersand (if configured that way).

Upgrades

When the package is upgraded, changes to the config and views should be republished into your project:

php artisan vendor:publish --provider='Chencha\Share\ShareServiceProvider'

Use source control to work out what has changed if you have customized the files.

social-share's People

Contributors

daisuanmung avatar datashaman avatar dependabot[bot] avatar ibrahim-mubarak avatar laravel-shift avatar prodeveloper avatar shanmuga3 avatar shaydy95 avatar the94air avatar thegr8dev 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  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

social-share's Issues

Customise this package for blogger

Hello there,

This provider give bunch of social media code. but some of them are missing like i want to socialise to blogger.
So you only need to change your config file in your laravel folder.

  1. Add below code for blogger in this fie config/social-share.php
    'blogger' => [ 'uri' => 'https://www.blogger.com/blog_this.pyra' ,'urlName' => 'u','titleName' => 'n'],
  2. and add route file for this.
    Route::get('bloggerShare/{name}', function($name)
    {
    $var = Share::load(url()->previous(), $name)->blogger();
    return redirect($var);
    })->name('bloggerShare');

That's it,Hope you understand.

Laravel 7.0

Would it be possible to update this package to support the newly released Laravel 7?

Thanks!

The 5.4.1 tag is not accessible trough packagist.org / composer

According to the packagist.org the latest version of the package is 5.4.0.

However here in GitHub you have the 5.4.1 version.

So composer require / composer install results in:

- Installing chencha/share (5.4.0): Downloading (100%)

And as you are well aware (I assume) without the (5.4.1) fix for the array_get() helper, the package is not really usable in Laravel 6.x..

Maybe the the webhook to sync with packagist.org got removed or something like this? Is it possible for you to check it or manually sync it with packagist?

Thanks, Martin

Class 'Share' not found

Hi,

This works perfectly on my localserver but the class somehow can't be found on the remote server. I checked the log file and it says:

local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class 'Share' not found in /var/www/laravel/app/Http/Controllers/BlogController.php:24

I however have added this line to my BlogController.php:
use Share;

Service provider:
Chencha\Share\ShareServiceProvider::class,

Alias:
'Share' => Chencha\Share\ShareFacade::class,

I've been googling for whole day long but couldn't really sort it out. There are quite a few people referring the capitalisation issue. Have given it a try but had no luck. Could you please help me out?

That would be really appreicated.

How do you make it work in a controller?

Hello,

I start in Laravel and I try to make social-share work. But impossible to get there.

I always have the error Non-static method Chencha\Share\Share::load() should not be called statically

Here's what I do in my controller

public function share()
    {
        $test = Share::load(url('/'), 'Description de test')->twitter();
        return $test;
    }

In my controller show

return view('posts.postWork', [
            'work' => $work,
            'share' => $this->share()
        ]);

Class 'Arr' not found error with laravel 7.0

I have updated my laravel application to laravel 7.0 and seems this package does not working with laravel 7.0. as it is mentioned in issue #52 I changed the chencha/share version to dev-master in my composer.json file:
"chencha/share": "dev-master"
but I am facing with this problem when I want to use the functions of this package:
image
by the way I have to say that this package worked as expected for me in laravel 6.0 and now the problem has arraised in laravel 7.0.
and moreover I have tried deleting vendor folder and reinstalling composer and updating that again and again but no changes.
can any one help with this?

Non-static Method ErrorException

I am getting this error

Non-static method Chencha\Share\Share::load() should not be called statically, assuming $this from incompatible context

what to do

mailto example in docs misses :

The mailto example on this page misses a ":" and should also have rawurlencode instead of urlencode

mailto?subject={{ urlencode("Wow, check this: $title") }}body={{ urlencode("Check this out! $title. See it here: $url") }}

Like this:
mailto:?subject={{ rawurlencode("Wow, check this: $title") }}body={{ rawurlencode("Check this out! $title. See it here: $url") }}

With missing ":" it does not work and the rawurlencode removed the ugly "+" symbolds in text.

Facebook link not well formatted

Hi,

I am trying to use your package in order to create a Facebook share button, but it seems that the link is not well formatted. Perhaps Facebook changed some of the previous functionalities. I tried with other services, like twitter, and it works fine. Could you take a look and see if there is a quick solution for this issue?

Best regards!

This package in not installing in laravel 7

Problem 1
- Installation request for chencha/share ^5.4 -> satisfiable by chencha/share[5.4.0].
- Conclusion: remove laravel/framework v7.16.1
- Conclusion: don't install laravel/framework v7.16.1
- chencha/share 5.4.0 requires illuminate/support ^5.0|^6.0

Please update it for laravel new version.

Share an image with Twitter

Hi,
Can you please tell me if this is possible to add some code to share an image with twitter?

I already tried to change code in social-share.php file with these examples :
'twitter' => [ 'uri' => 'https://twitter.com/intent/tweet', 'titleName' => 'text', 'mediaName' => 'media' ]
'twitter' => [ 'uri' => 'https://twitter.com/intent/tweet', 'titleName' => 'text', 'mediaName' => 'media_id' ]
'twitter' => [ 'uri' => 'https://twitter.com/intent/tweet', 'titleName' => 'text', 'mediaName' => 'picture' ]

But nothing works.

Thank you!

Non-static method Chencha\Share\Share::load() should not be called statically

Hello,

When I'm using this library, I got this error:
Non-static method Chencha\Share\Share::load() should not be called statically

My code:

$socials = Share::load(route('post.show', [$post]), $post->tagline)
                    ->services('facebook', 'linkedin', 'telegram', 'twitter', 'email');

dd($socials); exit;

I'm using Laravel 6.4

Thanks

Not working

Facebook share is not working.
and google share does not takes the link. It just shows the share page with no pre-added content (the url we want to share)

Issue in default.blade.php on Laravel 6

I have been using this plugin for quite some time on Laravel 5, I have decided to move project to Laravel 6 and upgraded Chencha/Share plugin to 5.4. I am now getting the following issue
"Undefined index: uri (View: /home/vagrant/Code/vendor/chencha/share/src/views/default.blade.php):line1"

Looking at default.blade.php I can see that the issue is the first {{$service['uri'] }}, silencing that out makes everything working fine again:
{{ **@$service['uri']** }}?{{ isset($service['urlName']) ? $service['urlName'] : 'url' }}={{ rawurlencode($url) }}<?php if(isset($title) && !empty($title)) { ?><?php echo $sep; ?>{{ isset($service['titleName']) ? $service['titleName'] : 'title' }}={{ rawurlencode($title) }}<?php } ?><?php if(isset($service['mediaName']) && !empty($media)) { ?><?php echo $sep; ?>{{ $service['mediaName'] }}={{ rawurlencode($media) }}<?php } ?><?php if (!empty($service['extra'])) { ?><?php echo $sep; ?><?php echo http_build_query($service['extra'], null, $sep, PHP_QUERY_RFC3986) ?><?php } ?>

Why do I get this error? Am I missing something or is this an issue with the package?

Download via composer doesn't work

Hey,

if I do : composer require chencha/share it says that my composer.json gets updated and the package is downloaded. After adding :

    Chencha\Share\ShareServiceProvider::class,

and Alias:
'Share' => Chencha\Share\ShareFacade::class,

I only get the error with the service provider:

(1/1) FatalErrorException
Class 'Chencha\Share\ShareServiceProvider' not found

Do you know something about that? I also tried a dump-autolaod after process but that haven't solved the problem. I would manually download the files but I don't know where I need to put all the files..
The config file in the config folder, the views in the views of course but where shall I put the Chencha/Share files?

Documentation Improvement

Hello, I used this package yesterday, and I feel like the documentation can be improved. I want to ask if I can work on the documentation improvement @datashaman

BTW, thank you for creating this.

Can't install on clean Laravel 6

I'm unable to install this package on a clean Laravel 6 installation.
Has anyone else had this issue?

@datashaman @ibrahim-mubarak #35

composer require chencha/share
Using version ^5.2 for chencha/share
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install chencha/share 5.2.1
    - Conclusion: remove laravel/framework v6.0.3
    - Installation request for chencha/share ^5.2 -> satisfiable by chencha/share[5.2.0, 5.2.1].
    - Conclusion: don't install laravel/framework v6.0.3
    - chencha/share 5.2.0 requires illuminate/support ^5.0 -> satisfiable by illuminate/support[5.0.x-dev, 5.1.x-dev, 5.2.x-dev, 5.3.x-dev, 5.4.x-dev, 5.5.x-dev, 5.6.x-dev, 5.7.17, 5.7.18, 5.7.19, 5.7.x-dev, 5.8.x-dev, v5.0.0, v5.0.22, v5.0.25, v5.0.26, v5.0.28, v5.0.33, v5.0.4, v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34, v5.5.35, v5.5.36, v5.5.37, v5.5.39, v5.5.40, v5.5.41, v5.5.43, v5.5.44, v5.6.0, v5.6.1, v5.6.10, v5.6.11, v5.6.12, v5.6.13, v5.6.14, v5.6.15, v5.6.16, v5.6.17, v5.6.19, v5.6.2, v5.6.20, v5.6.21, v5.6.22, v5.6.23, v5.6.24, v5.6.25, v5.6.26, v5.6.27, v5.6.28, v5.6.29, v5.6.3, v5.6.30, v5.6.31, v5.6.32, v5.6.33, v5.6.34, v5.6.35, v5.6.36, v5.6.37, v5.6.38, v5.6.39, v5.6.4, v5.6.5, v5.6.6, v5.6.7, v5.6.8, v5.6.9, v5.7.0, v5.7.1, v5.7.10, v5.7.11, v5.7.15, v5.7.2, v5.7.20, v5.7.21, v5.7.22, v5.7.23, v5.7.26, v5.7.27, v5.7.28, v5.7.3, v5.7.4, v5.7.5, v5.7.6, v5.7.7, v5.7.8, v5.7.9, v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.4, v5.8.8, v5.8.9].

how to use it in blade template.

I used the example in the controller and is not giving me any error: return view('static.index')->withSharelinks($sharelinks);

On the other hand I dont know the way I have to use the information in blade template. My idea is to pass the array:

{
    "gplus" : "https://plus.google.com/share?url=http%3A%2F%2Fwww.example.com",
    "twitter" : "https://twitter.com/intent/tweet?url=http%3A%2F%2Fwww.example.com&text=Link+description",
    "facebook" : "https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.example.com&title=Link+description"
}

, any help appreciated.

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.