<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#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; either version 2 of the License, or
#(at your option) any later version.
#
#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, Boston, MA  02111-1307  USA

function smarty_cms_function_random_blob($params, &$smarty) {
	$blobs = HtmlBlobOperations::LoadHtmlBlobs();	
  
  if (!isset($params['prefix'])) {
    return "Random Blob Error: no prefix defined";
  } else {

    $random_blobs = array();
  

  
    foreach ($blobs as $one) {
      if (preg_match("/^".$params['prefix']."/", $one->name)) {
        $random_blobs[] = $one;
      }
    }
    
    srand((float)microtime() * 1000000);
    shuffle($random_blobs);

    return $random_blobs[0]->content;
  }

}

function smarty_cms_help_function_random_blob() {
	?>
	<h3>What does this do?</h3>
	<p>Returns a random blob which name starts with <em>prefix</em></p>
	<h3>How do I use it?</h3>
	<p>Just insert the tag into your template/page like: <code>{random_blob prefix="random_"}</code>.</p>
  <p>The tag just picks one blob which name starts with <em>random_</em></p>
	<h3>What parameters does it take?</h3>
	<ul>
		<li><em>(required)</em>prefix - prefix of the html blob's name</li>
	</ul>
	</p>
	<?php
}

function smarty_cms_about_function_random_blob() {
	?>
	<p>Author: Alexander Rehbeino&lt;mail@nogga.net&gt;</p>
	<p>Version: 1.0</p>
	<p>
	Change History:<br/>
	1.0 : First edition
	</p>
	<?php
}
?>