PHP Socializer

PHP Socializer is intended to make adding social sharing buttons more enjoyable. It includes Google Analytics hooks to enable tracking of share activity. It is able to combine, compress & cache the JavaScript for multiple buttons.

Core Features

  • Buttons' JavaScript is loaded only after the page has been rendered, which prevents latency between your visitor & the buttons' providers from affecting percieved site performace.
  • If desired, PHP Socializer will hide buttons until they're fully rendered, fading them in with CSS3 transitions if available in the visitors browser, falling back to JavaScript animation otherwise
  • JavaScript can be either output on a per-button basis, or combined & output in one inline block.
  • With a little extra work, PHP Socializer can combine, minify & cache the javascript, only recomputing it if changes are made to the given manager's options

Service Support

PHP Socializer currently supports Twitter, Facebook, Google Plus, LinkedIn, StumbleUpon, GitHub, Pinterest and Flattr buttons.

Basic Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* Somehere in your config */
use COI\Social;
 
// Create a manager for the Twitter, Google+ & LinkedIn button set
new Social\Manager(array(
    'twitter' => new Social\Twitter(array(
        'username' => 'pagesofinterest',
    )),
    'googleplus' => new Social\GooglePlus(array(
        'size' => 'medium'
    )),
    'linkedIn' => new Social\LinkedIn()
), array(
    'fadeIn' => 400
));
 
/* Where the buttons should be displayed */
echo $socialManager->render(array(
    // These options override those used in the manager initialisation above
    'url' => 'http://pagesofinterest.net/',
    'title' => 'Pages of Interest', 
));
 
/* In your footer, just above the closing <body> tag */
// Output the <script> with src pointing to the combined, compressed & cached JavaScript
echo COI\Social\Manager::combinedJavaScript(array(
    'compression' => 'booster',
    'cacheDirectory' => '/var/www/pagesofinterest.net/public/js/php-socializer',
    'publicCacheDirectory' => '/js/php-socializer'));

To get started with PHP Socializer, download it from GitHub.

View On GitHub