Class \Scrivo\SocialMedia\SocialMediaShareButtons

Implmentation of the most usefull social share buttons using their own API.

All buttons are implemented as iframe elements so they will keep working correctly when reloaded with AJAX using different parameter values.

Note that this is not an attempt to create a uniform interface for different social media buttons, but simply a convenient way to output them using PHP. The parameters that are used by the buttons are still those as defined by the original API and therfore differ: (Facebook uses href, Twitter and LinkedIn use data-url, Titter uses data-count and LinkedIn uses data-counter, etc.).

Defined in: SocialMedia/SocialMediaShareButtons.php.


Constructor summary

Attr. Name / Description
public

SocialMediaShareButtons($url, $locale)

Construct a ShareButtons object.

Member summary

Attr. Type Name Description
private string $locale The locale to use for the buttons.
private string $url The URL to share.

Method summary

Attr. Type Name / Description
private string

getDataParameters($param)

Collect only the parameters that have keys starting with "data-" and contain a value.

public string

getFacebookLikeButton($param)

Get the HTML for a Facebook like button.

private string

getIFrame($src, $width, $height)

Get HTML code for the iframe that hosts the button.

public string

getLinkedInShareButton($param)

Get the HTML for a LinkedIn share button.

public string

getTwitterTweetButton($param)

Get the HTML for a Twitter tweet button.

private string

jsContent($data)

Construct a javascript source string for an iframe.

 


Constructor

public SocialMediaShareButtons(string $url, string $locale="nl_NL")

Construct a ShareButtons object.

Using this object you can conveniently print share buttons on your site, all using the same URL for sharing and using the same locale.

Parameters:

Type Name Def. Description
string $url

The URL to share.

string $locale "nl_NL"

The locale to use for the buttons.


Members


				
private string $locale

The locale to use for the buttons.

Inital value: "nl_NL"


				
private string $url

The URL to share.

Inital value: "http://www.scrivo.nl"


Methods

private string getDataParameters(array $param)

Collect only the parameters that have keys starting with "data-" and contain a value.

Encode these and return them as a parameter string.

Parameters:

Type Name Def. Description
array $param

A set of button parameters.

Returns:

string Collect only the parameters that have keys starting with "data-" and contain a value.

public string getFacebookLikeButton(array $param)

Get the HTML for a Facebook like button.

$sb = new SocialMediaShareButtons( "http://www.scrivo.nl/index.php?p=1093657");

echo $sb->getFacebookLikeButton(array( "action"=>"recommend", "width"=>"125px"));

Parameters:

Type Name Def. Description
array $param

A set of button parameters. For possible parameter names and values see the Facebook site.

Returns:

string Get the HTML for a Facebook like button.

private string getIFrame(string $src, string $width, string $height)

Get HTML code for the iframe that hosts the button.

Parameters:

Type Name Def. Description
string $src

The value for the iframe src parameter.

string $width

The CSS width of the iframe.

string $height

The CSS height of the iframe.

Returns:

string Get HTML code for the iframe that hosts the button.

public string getLinkedInShareButton(array $param)

Get the HTML for a LinkedIn share button.

$sb = new SocialMediaShareButtons( "http://www.scrivo.nl/index.php?p=1093657");

echo $sb->getLinkedInShareButton(array("width" => "95px"));

Parameters:

Type Name Def. Description
array $param

A set of button parameters. For possible parameter names and values see the LinkedIn site.

Returns:

string Get the HTML for a LinkedIn share button.

public string getTwitterTweetButton(array $param)

Get the HTML for a Twitter tweet button.

$sb = new SocialMediaShareButtons( "http://www.scrivo.nl/index.php?p=1093657");

$sb->getTwitterTweetButton(array("width" => "95px"));

Parameters:

Type Name Def. Description
array $param

A set of button parameters. For possible parameter names and values see the Twitter site.

Returns:

string Get the HTML for a Twitter tweet button.

private string jsContent(string $data)

Construct a javascript source string for an iframe.

For instance: "javascript: '\'t stoepje'".

Parameters:

Type Name Def. Description
string $data

The HTML data to display.

Returns:

string Construct a javascript source string for an iframe.


Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013