Jump to content

Release: social buttons


Frank Vèssia
 Share

Recommended Posts

I modified a well done module (thanks to almonk) that shows up facebook like button to obtain a more complete set of social buttons that i always use for my sites.

This module can shows facebook, twitter and google+ buttons.

Example:

<?
       $like = $modules->get('SocialBlock'); 

       //$like->fbEnabled ='false';  to hidden a button (fbEnabled|twEnabled|gEnabled)

$like->fbwidth = '110';
$like->fburl = 'http://www.yoursite.com/page/';

$like->twtext = $page->title;
$like->twvia = 'yoursitename';
$like->twlang = 'italian';

       $like->gsize = 'small';

echo $like->render();
?>	

Module code:

<?php

class SocialBlock extends WireData implements Module {

public static function getModuleInfo() {

	return array(
		'title' => 'Social Networks buttons', 
		'version' => 006, 
		'summary' => 'Display Facebook/Twitter/Google+ buttons on your Processwire site.',
		'href' => 'http://www.complementaryart.com',
		'singular' => false, 
		'autoload' => false, 
		);
}

public function init() {
	$this->set('fbEnabled', 'true');
	$this->set('fburl', '');
	$this->set('fblayout', 'button_count');
	$this->set('fbshowFaces', 'false');
	$this->set('fbcolorscheme', 'light');
	$this->set('fbwidth', '150');
	$this->set('fbheight', '20');
	$this->set('fbfont', 'Arial');

	$this->set('twEnabled', 'true');
	$this->set('twurl', '');
	$this->set('twtext', '');
	$this->set('twcount', 'horizontal');
	$this->set('twvia', '');
	$this->set('twlang', 'english');

	$this->set('gEnabled', 'true');
	$this->set('gsize', 'medium');
	$this->set('gcount', 'true');
}

public function ___render() {

	$social = "";

	if ($this->fbEnabled){

		if(!$this->fburl) $this->fburl = $page->url;

		// Build the iframe
		$social .= '<iframe src="http://www.facebook.com/plugins/like.php?href='.$this->fburl.'&layout='.$this->fblayout.'&show_faces='.$this->fbshowFaces.'&width='.$this->fbwidth.'&action=like&font='.$this->fbfont.'&colorscheme='.$this->fbcolorscheme.'&height='.$this->fbheight.'" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:'.$this->fbwidth.'px; height:'.$this->fbheight.'px;" allowtransparency="true"></iframe>';
	}

	if ($this->twEnabled){

		if(!$this->twurl) $this->twurl = $page->url;

		$social .= '<a href="http://twitter.com/share" class="twitter-share-button" data-url="'.$this->twurl.'" data-text="'.$this->twtext.'" data-count="'.$this->twcount.'" data-via="'.$this->twvia.'" data-lang="'.$this->twlang.'">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>';
	}

	if ($this->gEnabled){

	  	$social .= '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script><g:plusone size="'.$this->gsize.'" count="'.$this->gcount.'"></g:plusone>';
	}
	return $social;
}
}

SocialBlock.module

Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...