<?php
#FB Follow Button for CMS - CMS Made Simple
#(c)2011 by Oliver Seddon (oliver@threefold.co.uk)
#This project's homepage is: http://dev.cmsmadesimple.org/projects/fbfollow
#
#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 fbfollow {
	var $follow_domain;
	var $follow_scheme;
	var $follow_kid;
	var $follow_layout;
	var $follow_faces;
	var $follow_width;
	  
	function __constructor($follow_domain = '', $follow_scheme = 'light', $follow_kid = 'false', $follow_layout = 'standard', $follow_faces = 'false', $follow_width = ''){	
		$this->fbfollow($follow_domain, $follow_scheme, $follow_kid, $follow_layout, $follow_faces, $follow_width);
	}
	 
	function fbfollow($follow_domain, $follow_scheme, $follow_kid, $follow_layout, $follow_faces, $follow_width) {
		$this->follow_domain = $follow_domain;
		$this->follow_scheme = $follow_scheme;
		$this->follow_kid = $follow_kid;
		$this->follow_layout = $follow_layout;
		$this->follow_faces = $follow_faces;
		$this->follow_width = $follow_width;
	
		if(strlen($follow_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-follow" data-href="'. $follow_domain .'" data-colorscheme="'. $follow_scheme .'" data-kid-directed-site="'. $follow_kid .'" data-layout="'. $follow_layout .'" data-show-faces="'. $follow_faces .'" data-width="'. $follow_width .'"></div>';
		}
	}
	
	function showDebugInfo() {
		echo "<ul><li><strong>follow_domain:</strong> $this->follow_domain</li>\n";
		echo "<ul><li><strong>follow_scheme:</strong> $this->follow_scheme</li>\n";
		echo "<ul><li><strong>follow_kid:</strong> $this->follow_kid</li>\n";
		echo "<ul><li><strong>follow_layout:</strong> $this->follow_layout</li>\n";
		echo "<ul><li><strong>follow_faces:</strong> $this->follow_faces</li>\n";
		echo "<ul><li><strong>follow_width:</strong> $this->follow_width</li>\n";
		echo "</ul>\n";
	}
}


function smarty_cms_function_fbfollow($params, &$smarty) {
	$gCms = cmsms();
	$config =& $gCms->GetConfig();
	
	$debug = isset($params['debug']) ? $params['debug']:'false';
	$follow_domain = isset($params['follow_domain']) ? $params['follow_domain']:'';
	$follow_scheme = isset($params['follow_scheme']) ? $params['follow_scheme']:'';
	$follow_kid = isset($params['follow_kid']) ? $params['follow_kid']:'';
	$follow_layout = isset($params['follow_layout']) ? $params['follow_layout']:'';
	$follow_faces = isset($params['follow_faces']) ? $params['follow_faces']:'';
	$follow_width = isset($params['follow_width']) ? $params['follow_width']:'';
	
	$fbfollow = new fbfollow($follow_domain, $follow_scheme, $follow_kid, $follow_layout, $follow_faces, $follow_width);
	
	if($debug != 'false') {
		$fbfollow->showDebuginfo();
	}
}


function smarty_cms_help_function_fbfollow() {
?>
<h3>What does this do?</h3>
<p>The Follow button lets people subscribe to the public updates of others on Facebook.</p>
<h3>How do I use it?</h3>
<p>Just insert the tag into your template/page like <code>{fbfollow follow_domain='https://www.facebook.com/zuck'}</code>.</p>
<h3>What parameters does it take?</h3>
<ul>
<li><tt>follow_domain='https://www.facebook.com/zuck'</tt> - The Facebook.com profile URL of the user to follow.</li>
<li><em>(optional)</em> <tt>follow_scheme='light'</tt> - The color scheme used by the plugin. Can be "light" or "dark". Default is "light".</li>
<li><em>(optional)</em> <tt>follow_kid='false'</tt> - If your web site or online service, or a portion of your service, is directed to children under 13 you must enable this. Default is "false".</li>
<li><em>(optional)</em> <tt>follow_layout='standard'</tt> - Selects one of the different layouts that are available for the plugin. Can be one of "standard", "button_count", or "box_count". See the FAQ for more details. Default is "standard".</li>
<li><em>(optional)</em> <tt>follow_faces='false'</tt> - Specifies whether to display profile photos below the button (standard layout only). You must not enable this on child-directed sites. Default is "false".</li>
<li><em>(optional)</em> <tt>follow_width=''</tt> - The width of the plugin. The layout you choose affects the minimum and default widths you can use.</li>
<li><em>(optional)</em> <tt>debug='false'</tt> - Enable debug mode. Default is "false".</li>
</ul>

<?php
}

function smarty_cms_about_function_fbfollow() {
?>
	<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.<br />
    1.1 - Bug fix.<br />
    1.2 - Bug fix.</p>
<?php
}
?>