<?php
#FB Recommendations Feed for CMS - CMS Made Simple
#(c)2011 by Oliver Seddon (oliver@threefold.co.uk)
#This project's homepage is: http://dev.cmsmadesimple.org/projects/fbrecommends
#
#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 fbrecommends {
	var $recommend_domain;
	var $recommend_action;
	var $recommend_id;
	var $recommend_scheme;
	var $recommend_header;
	var $recommend_height;
	var $recommend_linktarget;
	var $recommend_age;
	var $recommend_ref;
	var $recommend_width;
	  
	function __constructor($recommend_domain = '', $recommend_action = 'likes, recommends', $recommend_width = '300', $recommend_height = '300', $recommend_age = '0', $recommend_scheme = 'light', $recommend_header = 'true', $recommend_id = 'true', $recommend_linktarget = 'true', $recommend_ref = 'true'){	
		$this->fbrecommends($recommend_domain, $recommend_action, $recommend_width, $recommend_height, $recommend_age, $recommend_scheme, $recommend_header, $recommend_id, $recommend_linktarget, $recommend_ref);
	}
	 
	function fbrecommends($recommend_domain, $recommend_action, $recommend_width, $recommend_height, $recommend_age, $recommend_scheme, $recommend_header, $recommend_id, $recommend_linktarget, $recommend_ref) {
		$this->recommend_domain = $recommend_domain;
		$this->recommend_action = $recommend_action;
		$this->recommend_width = $recommend_width;
		$this->recommend_height = $recommend_height;
		$this->recommend_age = $recommend_age;
		$this->recommend_scheme = $recommend_scheme;
		$this->recommend_header = $recommend_header;
		$this->recommend_id = $recommend_id;
		$this->recommend_linktarget = $recommend_linktarget;
		$this->recommend_ref = $recommend_ref;
	
		if(strlen($recommend_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-activity" data-site="'. $recommend_domain .'" data-action="'. $recommend_action .'" data-width="'. $recommend_width .'" data-height="'. $recommend_height .'" data-max-age="'. $recommend_age .'" data-colorscheme="'. $recommend_scheme .'" data-header="'. $recommend_header .'" data-app-id="'. $recommend_id .'" data-linktarget="'. $recommend_linktarget .'" data-ref="'. $recommend_ref .'"></div>';
		}
	}
	
	function showDebugInfo() {
		echo "<ul><li><strong>recommend_domain:</strong> $this->recommend_domain</li>\n";
		echo "<li><strong>recommend_action:</strong> $this->recommend_action</li>\n";
		echo "<li><strong>recommend_width:</strong> $this->recommend_width</li>\n";
		echo "<li><strong>recommend_height:</strong> $this->recommend_height</li>\n";
		echo "<li><strong>recommend_age:</strong> $this->recommend_age</li>\n";
		echo "<li><strong>recommend_scheme:</strong> $this->recommend_scheme</li>\n";
		echo "<li><strong>recommend_header:</strong> $this->recommend_header</li>\n";
		echo "<li><strong>recommend_id:</strong> $this->recommend_id</li>\n";
		echo "<li><strong>recommend_linktarget:</strong> $this->recommend_linktarget</li>\n";
		echo "<li><strong>recommend_ref:</strong> $this->recommend_ref</li>\n";
		echo "</ul>\n";
	}
}



function smarty_cms_function_fbrecommends($params, &$smarty) {
	$gCms = cmsms();
	$config =& $gCms->GetConfig();
	
	$debug = isset($params['debug']) ? $params['debug']:'false';
	$recommend_domain = isset($params['recommend_domain']) ? $params['recommend_domain']:'';
	$recommend_action = isset($params['recommend_action']) ? $params['recommend_action']:'likes, recommends';
	$recommend_width = isset($params['recommend_width']) ? $params['recommend_width']:'300';
	$recommend_height = isset($params['recommend_height']) ? $params['recommend_height']:'300';
	$recommend_age = isset($params['recommend_age']) ? $params['recommend_age']:'0';
	$recommend_scheme = isset($params['recommend_scheme']) ? $params['recommend_scheme']:'light';
	$recommend_header = isset($params['recommend_header']) ? $params['recommend_header']:'true';
	$recommend_id = isset($params['recommend_id']) ? $params['recommend_id']:'true';
	$recommend_linktarget = isset($params['recommend_linktarget']) ? $params['recommend_linktarget']:'true';
	$recommend_ref = isset($params['recommend_ref']) ? $params['recommend_ref']:'true';
	
	$fbrecommends = new fbrecommends($recommend_domain, $recommend_action, $recommend_width, $recommend_height, $recommend_age, $recommend_colour, $recommend_header, $recommend_id, $recommend_linktarget, $recommend_ref);
	
	if($debug != 'false') {
		$fbrecommends->showDebuginfo();
	}
}


function smarty_cms_help_function_fbrecommends() {
?>
<h3>What does this do?</h3>
<p>The Recommendations feed displays the most recommended content on your site, using actions (such as likes) by your friends and other people. It is different from the Activity feed which displays recent actions on your site.</p>
<h3>How do I use it?</h3>
<p>Just insert the tag into your template/page like <code>{fbrecommends recommend_domain='developers.facebook.com'}</code>.</p>
<h3>What parameters does it take?</h3>
<ul>
<li><tt>recommend_domain='developers.facebook.com'</tt> - The domain you want to show activity for.</li>
<li><em>(optional)</em> <tt>recommend_action='likes, recommends'</tt> - A comma seperatedlist of actions to show activities for, options are . Default is "likes, recommends".</li>
<li><em>(optional)</em> <tt>recommend_width='300'</tt> - The pixel width of the plugin. Default is "300".</li>
<li><em>(optional)</em> <tt>recommend_height='300'</tt> - The pixel height of the plugin. Default is "300".</li>
<li><em>(optional)</em> <tt>recommend_age='0'</tt> - The oldest an item can be in days. Maximum is 180. Default is "0".</li>
<li><em>(optional)</em> <tt>recommend_scheme='light'</tt> - The colour scheme used by the plugin. Can be "light" or "dark". Default is "light".</li>
<li><em>(optional)</em> <tt>recommend_header='light'</tt> - Show the Recent Activity header above the feed. Can be "true" or "false". Default is "true".</li>
<li><em>(optional)</em> <tt>recommend_id=''</tt> - Display all actions associated with this app ID. This is usually inferred from the app ID you use to initiate the [JavaScript SDK].</li>
<li><em>(optional)</em> <tt>recommend_linktarget='_blank'</tt> - Determines what happens when people click on the links in the feed. Can be any of the standard HTML target values. Default is "_blank".</li>
<li><em>(optional)</em> <tt>recommend_ref=''</tt> - A label for tracking referrals which must be less than 50 characters and can contain alphanumeric characters and some punctuation (currently +/=-.:_).</li>
<li><em>(optional)</em> <tt>debug='false'</tt> - Enable debug mode. Default is false.</li>
</ul>

<?php
}

function smarty_cms_about_function_fbrecommends() {
?>
	<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
}
?>