<?php
#FB Like Box for CMS - CMS Made Simple
#(c)2011 by Oliver Seddon (oliver@threefold.co.uk)
#This project's homepage is: http://dev.cmsmadesimple.org/projects/fblikebox
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

class fblikebox {
	var $likebox_domain;
	var $likebox_width;
	var $likebox_height;
	var $likebox_header;
	var $likebox_faces;
	var $likebox_posts;
	var $likebox_scheme;
	var $likebox_border;
	var $likebox_forcewall;
	  
	function __constructor($likebox_domain = '', $likebox_width = '300', $likebox_height = 'standard', $likebox_header = 'true', $likebox_faces = 'false', $likebox_posts = 'false', $likebox_scheme = 'light', $likebox_border = 'true', $likebox_forcewall = 'false'){	
		$this->fblikebox($likebox_domain, $likebox_width, $likebox_height, $likebox_header, $like_faces, $like_share, $like_scheme, $likebox_border, $likebox_forcewall);
	}
	 
	function fblikebox($likebox_domain, $like_width, $likebox_height, $likebox_header, $like_faces, $likebox_posts, $likebox_scheme, $likebox_border, $likebox_forcewall) {
		$this->likebox_domain = $likebox_domain;
		$this->likebox_width = $likebox_width;
		$this->likebox_height = $likebox_height;
		$this->likebox_header = $likebox_header;
		$this->likebox_faces = $likebox_faces;
		$this->likebox_posts = $likebox_posts;
		$this->like_scheme = $likebox_scheme;
		$this->likebox_border = $likebox_border;
		$this->likebox_forcewall = $likebox_forcewall;
	
		if(strlen($likebox_domain) == '0') {
			// domain not specified
			$this->showError(1);
			return false;
		} else {
			echo '<div id="fb-root"></div>
			<script>
				(function(d, s, id) {
					var js, fjs = d.getElementsByTagName(s)[0];
					if (d.getElementById(id)) return;
					js = d.createElement(s); js.id = id;
					js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.0";
					fjs.parentNode.insertBefore(js, fjs);
				}(document, \'script\', \'facebook-jssdk\'));
			</script>

			<div class="fb-like-box" data-href="'. $likebox_domain .'" data-width="'. $likebox_width .'" data-height="'. $likebox_height .'" data-colorscheme="'. $likebox_scheme .'" data-show-faces="'. $likebox_faces .'" data-header="'. $likebox_header .'" data-stream="'. $likebox_posts .'" data-show-border="'. $likebox_border .'" data-force-wall="'. $likebox_forcewall .'"></div>';
		}
	}
	
	function showDebugInfo() {
		echo "<ul><li><strong>likebox_domain:</strong> $this->likebox_domain</li>\n";
		echo "<ul><li><strong>likebox_width:</strong> $this->likebox_width</li>\n";
		echo "<li><strong>likebox_height:</strong> $this->likebox_height</li>\n";
		echo "<li><strong>likebox_header:</strong> $this->likebox_header</li>\n";
		echo "<li><strong>likebox_faces:</strong> $this->likebox_faces</li>\n";
		echo "<li><strong>likebox_posts:</strong> $this->likebox_posts</li>\n";
		echo "<li><strong>like_scheme:</strong> $this->likebox_scheme</li>\n";
		echo "<li><strong>likebox_border:</strong> $this->likebox_border</li>\n";
		echo "<li><strong>likebox_forcewall:</strong> $this->likebox_forcewall</li>\n";
		echo "</ul>\n";
	}
}


function smarty_cms_function_fblikebox($params, &$smarty) {
	$gCms = cmsms();
	$config =& $gCms->GetConfig();
	
	$debug = isset($params['debug']) ? $params['debug']:'false';
	$likebox_domain = isset($params['likebox_domain']) ? $params['likebox_domain']:'';
	$likebox_width = isset($params['likebox_width']) ? $params['likebox_width']:'300';
	$likebox_height = isset($params['likebox_height']) ? $params['likebox_height']:'standard';
	$likebox_header = isset($params['likebox_header']) ? $params['likebox_header']:'true';
	$likebox_faces = isset($params['likebox_faces']) ? $params['likebox_faces']:'true';
	$likebox_posts = isset($params['likebox_posts']) ? $params['likebox_posts']:'false';
	$likebox_scheme = isset($params['likebox_scheme']) ? $params['likebox_scheme']:'light';
	$likebox_border = isset($params['likebox_border']) ? $params['likebox_border']:'true';
	$likebox_forcewall = isset($params['likebox_forcewall']) ? $params['likebox_forcewall']:'false';
	
	$fblikebox = new fblikebox($likebox_domain, $likebox_width, $likebox_height, $likebox_header, $likebox_faces, $likebox_posts, $likebox_scheme, $likebox_border, $likebox_forcewall);
	
	if($debug != 'false') {
		$fblikebox->showDebuginfo();
	}
}


function smarty_cms_help_function_fblikebox() {
?>
<h3>What does this do?</h3>
<p>The Like Box is a special version of the Like Button designed only for Facebook Pages. It allows admins to promote their Pages and embed a simple feed of content from a Page into other sites.</p>
<h3>How do I use it?</h3>
<p>Just insert the tag into your template/page like <code>{fblikebox like_domain='https://www.facebook.com/FacebookDevelopers'}</code>.</p>
<h3>What parameters does it take?</h3>
<ul>
<li><tt>likebox_domain='https://www.facebook.com/FacebookDevelopers'</tt> - The absolute URL of the Facebook Page that will be liked.</li>
<li><em>(optional)</em> <tt>likebox_width='300'</tt> - The width of the plugin in pixels. Minimum is 292. Default is "300".</li>
<li><em>(optional)</em> <tt>likebox_height='standard'</tt> - The height of the plugin in pixels. The default height varies based on number of faces to display, and whether the stream is displayed. With stream set to true and 10 photos displayed (via show_faces) the default height is 556px. With stream and show_faces both false, the default height is 63px.</li>
<li><em>(optional)</em> <tt>likebox_header='true'</tt> - Specifies whether to display the Facebook header at the top of the plugin. Default is "true".</li>
<li><em>(optional)</em> <tt>likebox_faces='false'</tt> - Specifies whether to display profile photos below the button (standard layout only). Default is "true".</li>
<li><em>(optional)</em> <tt>likebox_posts='false'</tt> - Specifies whether to display a stream of the latest posts by the Page. Default is "false".</li>
<li><em>(optional)</em> <tt>likebox_scheme='light'</tt> - The color scheme used by the plugin for any text outside of the button itself. Can be "light" or "dark". Default is "light".</li>
<li><em>(optional)</em> <tt>likebox_border='light'</tt> - Specifies whether or not to show a border around the plugin. Default is "true".</li>
<li><em>(optional)</em> <tt>likebox_forcewall='false'</tt> - For "place" Pages (Pages that have a physical location that can be used with check-ins), this specifies whether the stream contains posts by the Page or just check-ins from friends. Default is "false".</li>
<li><em>(optional)</em> <tt>debug='false'</tt> - Enable debug mode. Default is false.</li>
</ul>

<?php
}

function smarty_cms_about_function_fblikebox() {
?>
	<p><strong>Author:</strong> Oliver Seddon <a href=\"mailto:oliver@threefold.co.uk\">oliver@threefold.co.uk</a><br /><br /></p>
    <p>Version 1.0<br /><br /></p>
    <p>Change History:<br />
    1.0 - Alpha version released.</p>
<?php
}
?>