<?php

////////////////////////////////////////////////////////////////////////////////
//
// File:	function.IndexFollow.php
// Project:	Meta Robots plugin for CMS Made Simple
// Version:	1.0
// Licence:	Free software under the GNU General Public License
// Web:		http://dev.cmsmadesimple.org/projects/indexfollow
// Created:	20130222, v1.0, Magal Hezi
//
////////////////////////////////////////////////////////////////////////////////

function smarty_cms_function_IndexFollow($params, &$smarty) {
	
	$data_field = isset($params['field']) ? $params['field'] : 'extra1';
	
	$contentobj = cms_utils::get_current_content();
	$extra1_values = '';
	if (is_object($contentobj))
	{
   		$extra1_values = cms_htmlentities($contentobj->GetPropertyValue($data_field));
	}

if (isset($extra1_values) && !empty($extra1_values)){
$pieces = explode(",", $extra1_values);
$totlapieces = count($pieces);
switch ($totlapieces) {
   case 1:
   		 $data_index = "1";
		 $data_follow = "1";
         $data_days = '<meta name="revisit-after" content="' . $pieces[0] . ' days">';
         break;
   case 2:
         $data_index = $pieces[0];
		 $data_follow = $pieces[1];
         $data_days = '';
         break;
   case 3:
         $data_index = $pieces[0];
		 $data_follow = $pieces[1];
         $data_days = '<meta name="revisit-after" content="' . $pieces[2] . ' days">';
         break;
	}
}
else
{
	$data_index = "1";
	$data_follow = "1";
	$data_days = '';
}
	$gCms = cmsms();

/*
	$data_index= isset($params['index']) ? trim($params['index']) : "1";
	$data_follow= isset($params['follow']) ? trim($params['follow']) : "1";
	$data_days = isset($params['days']) ? '<meta name="revisit-after" content="' . trim($params['days']) . ' days">' : "";
*/
	
	if ($data_index == 1){
		$data_index = "index";
	}
	else
	{
		$data_index = "noindex";
	}
	
	if ($data_follow == 1){
		$data_follow = "follow";
	}
	else
	{
		$data_follow = "nofollow";
	}

	$lang = isset($params['lang']) ? trim($params['lang']) : "en_US";

	$result = "";
	$result .= '<!-- Start IndexFollow plugin -->' . PHP_EOL;
	$result .= '<meta name="robots" content="'.$data_index.','.$data_follow.'">' . PHP_EOL;
	$result .= '<meta name ="GOOGLEBOT" content="'.$data_index.','.$data_follow.'">' . PHP_EOL;
	$result .= $data_days. PHP_EOL;
	$result .= '<!-- End IndexFollow plugin -->';

	return $result;

}

function smarty_cms_help_function_IndexFollow() {
	?>
	<h3>What does this do?</h3>
	<p>This CMSMS IndexFollow plugin lets a user add the meta robots tag to their pages and change individual page's settings in no time.</p>
<h3>How do I use it?</h3>
	<p>Insert the tag <code>{IndexFollow}</code> into the &quot;head&quot; section of your <strong style="text-decoration:underline;">template</strong> (case sensitive). </p>
	<h3>What parameters does it take?	</h3>
	<p>By Default this plugin will have the page Indexed and Followed and if you want to change that for a specific page all you have to do is Change the EXTRA1 field in the Options Tab of your page. This allows you to have the default parameters always on unless you wish to do otherwise!</p>
	<p>If your EXTRA1 field is already occupied or You wish to assign a custom named Content block to control this plugin, simply add the Parameter field=&quot;name&quot; to the tag. <code>{IndexFollow field='custom_field'}</code></p>
   <p>&nbsp;</p>
	<table width="300" border="0" cellspacing="1" cellpadding="1">
	  <tr>
	    <td><img src="http://www.magalhezi.com/uploads/images/extra1field.jpg" height="315" /></td>
	    <td><iframe width="560" height="315" src="http://www.youtube.com/embed/sOGL8KcF7bg" frameborder="0" allowfullscreen></iframe></td>
      </tr>
</table>
	<p>&nbsp;</p>
	<p>Remember:</p>
	<ol>
	  <li>By default Index and Follow	are ON</li>
	  <li>&quot;0&quot; = OFF</li>
	  <li>&quot;1&quot; = ON</li>
	  <li>Separate values with comma &quot;0,1,14&quot;</li>
	  <li>First value = index (0 or 1)</li>
	  <li>Second value = follow (0 or 1)</li>
	  <li>Third value = days (any number)</li>
	  <li>To set only the days and leaving the rest to index, then input only 1 value (14)</li>
	  <li>By Default no days are setup</li>
</ol>
<h3>Example? Insert the following in your EXTRA1 field:</h3>
<ul>
  <li><code>14</code>
    <ul>
      <li>&lt;meta name=&quot;robots&quot; content=&quot;index,  follow&quot;&gt;</li>
      <li>&lt;meta name=&quot;revisit-after&quot; content=&quot;14  days&quot;&gt;      </li>
    </ul>
  </li>
  <li><code>0,1</code>
    <ul>
      
      <li>&lt;meta name=&quot;robots&quot; content=&quot;noindex,  follow&quot;&gt;</li>
    </ul>
  </li>
  <li><code>0,1,14</code>
    <ul>
      <li>&lt;meta name=&quot;robots&quot; content=&quot;noindex,  follow&quot;&gt;</li>
      <li>&lt;meta name=&quot;revisit-after&quot; content=&quot;14  days&quot;&gt;</li>
    </ul>
</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>
	<?php
}

function smarty_cms_about_function_IndexFollow() {
	?>
<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/indexfollow" 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/indexfollow" 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/indexfollow" 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
}
?>
