<?php

////////////////////////////////////////////////////////////////////////////////
//
// File:	function.PinterestShareDialog.php
// Project:	Pinterest Bookmarking plugin for CMS Made Simple
// Version:	1.0
// Licence:	Free software under the GNU General Public License
// Created:	20131024, v1.0, Magal Hezi
//
////////////////////////////////////////////////////////////////////////////////

function smarty_cms_function_PinterestShareDialog($params, &$smarty) {

	$gCms = cmsms();
	$text = isset($params['text']) ? trim($params['text']) : '<img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It"/>';
	$class = isset($params['class']) ? 'class="' . trim($params['class']) . '" ' : "";
    $descr = isset($params['descr']) ? trim($params['descr']) . '...' : "";
	$media = isset($params['media']) ? trim($params['media']) : "http://farm8.staticflickr.com/7027/6851755809_df5b2051c9_z.jpg"; 
	$custom_url = isset($params['custom_url']) ? trim($params['custom_url']) : ""; 

	if ($custom_url != "") {
		$url = $custom_url;
	} else {
		$url = curPageURL();
	}	
	
	$result = "";
	$result .= '<!-- Start Pinterest dialog -->' . PHP_EOL;
	$result .= '<a href="';
	$result .= 'http://pinterest.com/pin/create/button/?url='.urlencode($url);
	$result .= '&media='.urlencode($media);
	$result .= '&description='.urlencode($descr).'"';
	$result .= '" '.$class.' count-layout="horizontal" target="_blank">';
	$result .= $text;
	$result .= '</a>';
	$result .= '<!-- End Pinterest dialog -->';

	return $result;

}

function smarty_cms_help_function_PinterestShareDialog() {
	?>
	<h3>What does this do?</h3>
	<p>Add a Pinterest button or widget to your website.<br />
    Pin It button: Invite people to pin things from your website.
	</p>
<h3>How do I use it?</h3>
	<p>Insert the tag <code>{PinterestShareDialog}</code> into your template or page (case sensitive).</p>
	<p>To ensure that web-designers have maximum control over customization, if you want to style the plugin's output, feel free to use additional external CSS rules in conjunction with the <code>class</code> parameter.</p>
<p>Alternatively, you can always use the <code>custom_url</code> parameters to set manually (or pass them via smarty) the url and title values of the current page without self detection functionality.</p>
<p>here is an example of mixed code:</p>
<p>{PinterestShareDialog class='clsPin' custom_url=$canonical text='&lt;img src=&quot;images/share_pt.gif&quot; width=&quot;19&quot; height=&quot;19&quot;&gt;' media=$media descr=$pagedescription}</p>
	<h3>What parameters does it take?	</h3>
	<ul>
<li><em>(optional)</em> <code>text</code>
  <ul>
    <li>The default icon for Pinterest is: <code><img src="http://assets.pinterest.com/images/PinExt.png"/></code></li>
  </ul>
</li>
<ul>
    <li>To change the default icon there are two options. 
      <ul>
        <li>to add your own image use the following
          <ul>
            <li><code>{PinterestShareDialog text='&lt;img src=&quot;images/share_pt.gif&quot; width=&quot;19&quot; height=&quot;19&quot;&gt;'}</code></li>
          </ul>
        </li>
        <li>to add text instead use:
          <ul>
            <li><code>{PinterestShareDialog text='Pin it'}</code><br />
              <br />
            </li>
          </ul>
        </li>
      </ul>
    </li>
</ul>
		<li><em>(optional)</em> <code>class</code></li>
        <ul>
          <li>Populates the "<code>class</code>" attribute of the link, set the CSS class name</li>
          <li>E.g. <code>{PinterestShareDialog class="MyCssClassName"}<br />
            <br />
          </code></li>
        </ul>
      <li><em>(optional)</em> <code>media</code></li>
		<ul>
			<li>Media is the URL of the image you want to share(pin) representing this page or product</li>
			<li>If you don't set the media item, the default image will be placed<br />
<img src="http://farm8.staticflickr.com/7027/6851755809_df5b2051c9_z.jpg" width="100"/></li>
			<li>E.g.<code>{PinterestShareDialog media="http://farm8.staticflickr.com/7027/6851755809_df5b2051c9_z.jpg"}</code><br />
			  <br />
			</li>
		</ul>
		<li><em>(optional) </em>descr
		  <ul>
		    <li>descr is the description of what you are sharing (pinning)</li>
	      </ul>
		</li>
		<ul>
			<li>no default value</li>
			<li>E.g. <code>{PinterestShareDialog descr=$pagedescription}</code><br />
			  <br />
			</li>
		</ul>
<li><em>(optional)</em> <code>custom_url</code></li>
		<ul>
			<li>Set manually the <strong>complete</strong> url of the current page without self detection functionality</li>
			<li>Simply specify the URL of your  page in the custom_url parameter of the button.</li>
			<li>E.g. <code>{PinterestShareDialog custom_url="http://www.domain.ext/my/current/page"}</code></li>
		</ul>
        <p>
<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_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-follow" data-href="http://www.facebook.com/MagalFreelanceWebDeveloper" data-show-faces="true" data-font="segoe ui" data-width="460"></div>
</p>
</ul>
	<?php
}

function smarty_cms_about_function_PinterestShareDialog() {
	?>
<p>Author: <a href="http://www.facebook.com/MagalFreelanceWebDeveloper">Magal Hezi</a></p>
<p>Version: 1.0</p>
	<p>Update: Check for updates for this plugin at the <a href="http://dev.cmsmadesimple.org/projects/likebutton" target="_blank">CMS Made Simple Forge page</a></p>
	<p>Feature Requests: If you want to add others social bookmarking services or functionality, please let me know by opening a new feature request in the dedicated <strong>Feature Requests tab</strong> of the <a href="http://dev.cmsmadesimple.org/projects/likebutton" target="_blank">CMS Made Simple Forge page</a> for this plugin</p>
	<p>Bugs: If you want to submit a new bug, please let me know by opening a new bug in the dedicated <strong>Bug Tracker tab</strong> of the <a href="http://dev.cmsmadesimple.org/projects/likebutton" target="_blank">CMS Made Simple Forge page</a> for this plugin</p>
	<p>Licence: Free software under the GNU General Public License</p>
	<p>Change History:</p>
	<ul>
<li>Version 1.0</li>
		<ul>
			<li>First release</li>
		</ul>
	</ul>
	<?php
}
?>
