<?php

/**
 * Snippet to implement a share buttons using font awesome.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package clearFusionCMS\module\social
 * @copyright Copyright (c) 2014 - 2016 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

/** @var $tplEngine cfTemplateEngine */

if(isset($networks)) {
	if($networks == 'all')
		$networks = 'facebook,gplus,linkedin,twitter,pinterest,buffer';

	$networks = preg_split('/\s*,\s*/', $networks);

	$self = urlencode($tplEngine->controller->getRequest()->getSelf(true));
	$title = urlencode($tplEngine->controller->pageData['title'] . ' ');
	$image = isset($image) ? $image : (isset($tplEngine->controller->pageData['customfields']['social_image']) ? $tplEngine->controller->pageData['customfields']['social_image'] : null);

	$tplEngine->getCodeBuffer()->bufferBodyJS('system/modules/social/js/share.js');
	echo '<ul class="cfSocialShare">';
	foreach($networks as $network) {
		switch($network) {
			case 'facebook':
				echo '<li><a href="https://www.facebook.com/sharer/sharer.php?u=' . $self . '" class="fa fa-facebook" title="' . __('Share on Facebook', 'social') . '" rel="nofollow"></a></li>';
				break;
			case 'gplus':
				echo '<li><a href="https://plus.google.com/share?url=' . $title . $self . '" class="fa fa-google-plus" title="' . __('Share on Google Plus', 'social') . '" rel="nofollow"></a></li>';
				break;
			case 'linkedin':
				echo '<li><a href="http://www.linkedin.com/shareArticle?mini=true&url=' . $self . '&amp;title=' . $title . '" class="fa fa-linkedin" title="' . __('Share on LinkedIn', 'social') . '" rel="nofollow"></a></li>';
				break;
			case 'twitter':
				echo '<li><a href="https://twitter.com/intent/tweet/?url=' . $self . '&content=' . $title . '" class="fa fa-twitter" title="' . __('Share on Twitter', 'social') . '" rel="nofollow"></a></li>';
				break;
			case 'pinterest':
				echo '<li><a href="http://pinterest.com/pin/create/button/?url=' . $self . ($image ? '&amp;media=' . $image : '') . '&amp;description=' . $title . '" class="fa fa-pinterest" title="' . __('Share on Pinterest', 'social') . '" rel="nofollow"></a></li>';
				break;
			case 'buffer':
				echo '<li><a href="http://bufferapp.com/add" title="' . __('Share via Buffer', 'social') . '" data-url="' . $self . '" data-count="vertical" rel="nofollow" class="ion-social-buffer-outline"></a></div>';
				break;
		}
	}
	echo '</ul>';
}
