<?php

/**
 * Snippet to implement a pinterest button.
 *
 * 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) 2012 - 2013 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

/** @var $tplEngine cfTemplateEngine */

$desc = urlencode(isset($desc) ? $desc : 'Pin this page');
$link = urlencode(isset($link) ? $link : $tplEngine->controller->getRequest()->getSelf(true));
$bookmarklet = isset($bookmark) && $bookmark == 'bookmarklet' ? 'bookmarklet' : 'button';

// If media given
if(isset($media)) {
	// If not an abs media url
	if(!preg_match('#^https?://#', $media))
		$media = $tplEngine->controller->getRequest()->getBasePath(true) . ltrim($media, '/');
	$media = '&amp;media=' . urlencode($media);
}
else
	$media = '';

echo "<div class=\"cfSocialPinterest\"><a href=\"http://pinterest.com/pin/create/$bookmarklet/?url=$link&amp;description=$desc$media\" class=\"pin-it-button\" count-layout=\"vertical\"><img style=\"border: none\" src=\"//assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /></a></div>";
$tplEngine->getCodeBuffer()->requireCore()->bufferHeadJS('system/modules/social/js/social.js');
