<?php
#CMS - CMS Made Simple
#
# Type:		Tag
# Name:		loremipsum
# Purpose:	Populate content with a random text generated by lipsum.com.
# Version:	1.0
# Date:		30 Januar 2013
# Author:	Tomáš Havlas (tomas.havlas)
# Link:		NA
# Example:	{lipsum}
#
#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; version 2 of the License
#
#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, lipsumBoston, MA  02111-1307  USA

function smarty_cms_function_loremipsum($params, &$smarty) {
  // TODO: maybe add some cache

  $amount = isset($params['amount']) ? intval($params['amount']) : 1;
  $what = isset($params['what']) ? $params['what'] : 'paras';
  $start = isset($params['start']) ? intval($params['start']) : 1;

  $output = '<!-- Lorem Ipsum Start --> ';
  $output .= (string)simplexml_load_file("http://www.lipsum.com/feed/xml?amount=$amount&what=$what&start=$start")->lipsum;
	$output .= '<!-- Lorem Ipsum End -->';

	return $output;
}

function smarty_cms_help_function_loremipsum() {
?>
<h3>What does this do?</h3>
<p>This tag populates content with a given number (up to ten) of Lorem Ipsum paragraphs.</p>

<h3>How do I use it?</h3>
<p>Just insert the tag in your content textarea or template:<br /><br />
<code>{loremipsum amount=2}</code>

<h3>What parameters does it take?</h3>
<p>
  Defaultly generates one paragraph of text starting with phrase Lorem ipsum dolor sit amet.
  <ul>
    <li><em>(optional)</em> <tt>what</tt> - What to generate: paras, words, bytes or lists.</li>
    <li><em>(optional)</em> <tt>amount</tt> - How much of paragraphs/words/bytes/lists you want.</li>
    <li><em>(optional)</em> <tt>start</tt> - Should generated text begin width <em>Lorem ipsum dolor sit amet...</em>.</li>
  </ul>
</p>
<?php
}

function smarty_cms_about_function_loremipsum() {
?>
<p>Author: Tomáš Havlas (tomas.havlas)</p>
<p>Version: 1.0</p>
<p>Change History:<br />
1.0 - Initial release<br />
</p>
<?php
}
?>
