Download the PHP package kudashevs/laravel-share-buttons without Composer
On this page you can find all versions of the php package kudashevs/laravel-share-buttons. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kudashevs/laravel-share-buttons
More information about kudashevs/laravel-share-buttons
Files in kudashevs/laravel-share-buttons
Package laravel-share-buttons
Short Description A laravel social media share buttons package.
License MIT
Homepage https://github.com/kudashevs/laravel-share-buttons
Informations about the package laravel-share-buttons
Laravel Share Buttons
This Laravel package provides the possibility to generate share links (social media share buttons) for your site in a flexible and convenient way within seconds. The package was originated from the Laravel Share.
Available services
- X (formerly Twitter)
- Telegram
- Hacker News
- VKontakte
- Evernote
- Skype
- Copy the link
- Mail the link
Installation
You can install the package via composer:
If you don't use auto-discovery just add a ShareButtonsServiceProvider to the config/app.php
By default, the ShareButtons
class instance is bound to the sharebuttons
alias. You might want to add a
ShareButtonsFacade::class
to the aliases, too.
Don't forget to publish the configuration file and assets. The configuration file is required.
In case of a major change, it is recommended to back up your config file and republish a new one from scratch.
You can customize the process of publishing assets. If you want to limit the type of assets, you can use the --tag
option
with one of the following tags: config
, js
(all js files), vanilla
, jquery
, css
.
Assets
By default, this package relies on the Font Awesome
icons. The buttons' interactivity is implemented in two
different ways (via Vanilla JS
and jQuery
). However, you can use any custom fonts, icons, or JavaScript.
Font Awesome and default styles
To enable Font Awesome icons, use the code sample below in your template. For further information on how to use Font Awesome, please read the introduction.
To enable the default styles, you should publish the assets tagged as css
(the command will create a resources/css/share-buttons.css
file). After publishing,
you can copy this file to your public/css
folder and use it directly by applying the code sample below. Or you can integrate the css file into your assets compilation flow.
JavaScript
To enable interaction on social media buttons with JavaScript, you should publish the assets tagged as vanilla
(the command will create a resources/js/share-buttons.js
file).
After publishing, you can copy this file to your public/js
folder and use it directly by applying the code sample below. Or you can integrate this file into your assets compilation flow.
jQuery
To enable interaction on social media buttons with jQuery, you should publish the assets tagged as jquery
(the command will create a resources/js/share-buttons.jquery.js
file).
After publishing, you can copy this file to your public/js
folder and use it directly by applying the code sample below. Or you can integrate this file into your assets compilation flow.
Usage
Let's take a look at a short usage example (you can find a detailed usage example in the corresponding section).
The code above will result into the following HTML code:
Fluent interface
The ShareButtons
instance provides a fluent interface. The fluent interface is a pattern based on method chaining.
To start a method chaining you just need to use one of the methods listed below (the starting point).
Add buttons
To generate a single social media button, you just need to add one of the following methods to the method chaining. Each method accepts an array of options (more information about these options in the local options section).
These methods are a part of the fluent interface. Therefore, to create multiple social media share buttons you just need to chain them.
Getting share buttons
You can use a ShareButtons instance as a string or cast it to a string to get ready-to-use HTML code. However, this is not the best way. If you want to be clear in your intentions, use one of the methods that return generated HTML code. These methods are:
Getting raw links
Sometimes, you may only want the raw links without any HTML. In such a case, just use the getRawLinks
method.
Parameters
There is the possibility of providing different options to style and decorate the resulting HTML code at different levels.
Global options
Every time a chaining method is called, it accepts several arguments, including a page URL (depending on the method), a page title, and an array of options. These options are global because they change the representation of all share buttons. These options are:
Local options
Any of the share button methods, that generates a button, accepts several arguments. These options are local because they will be applied to a specific element only. The local options have a higher priority. Therefore, they will overwrite the global options if there is any overlap. At the moment, the package supports the following local options:
Configuration
The configuration settings are located in the config/share-buttons.php
file.
Representation section
This section contains settings related to the "container" in which the social media buttons will be displayed.
Share buttons section
Each social media share button has its own individual configuration settings.
note: a text value might contain a url
element, which will be replaced by the page url while processing.
Templates section
Each share button has a corresponding link template. A template contains several elements that will be substituted with
data from different arguments and options. The format of these elements depends on the templater
setting. By default,
these elements are:
Templaters section
For processing different templates and substitute elements in them, the package uses templaters (template engines). By default, these options are optional (if no value provided, the default templater will be used).
A detailed usage example
To summarize all of the information from above, let's take a look at a real-life example. We begin with one of the methods
that start the fluent interface, and we provide some global options. Then, we add some specific methods that generate social
media share buttons. At this step, we can provide any local options, as it is done in the linkedin()
method. Finally,
we finish the fluent interface chain with one of the methods that return the resulting HTML code.
The code above will result into the following HTML code:
Testing
If you want to make sure that everything works as expected, you can run unit tests provided with the package.
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see the License file for more information.