<?php
function smarty_function_get_content($params, &$smarty) {
	//
	clearstatcache();
	$content = array();
	$content_dir = "data/".$params['content_dir']."/";
	$include = explode("|", $params['include']);
	$exclude = explode("|", $params['exclude']);
	$from = $params['from'];
	$sort_by = ($params['sort_by']) ? $params['sort_by'] : "index";
	$show_past = $params['show_past'];
	$items = $params['items'];
	
	//
	$page_start = $pp*$items;
	srand(time());
	
	//
	$dir = APPLICATION_PATH.$content_dir;
	if ($handle = opendir($dir)) {
	    while (false !== ($file = readdir($handle))) {
	        if (!is_dir($dir.$file) && substr($file, 0, 1) != ".") {
				require($dir.$file);
				foreach($my_content as $key => $value) {
					$my_content[$key] = stripslashes($my_content[$key]);
				}
				$my_search = explode("|", $my_content[$from]);
	        	$unique = rand(0, 1000000);
	        	if(in_array("All", $include) || (array_intersect($my_search, $include) && !array_intersect($my_search, $exclude))) {
					if($show_past == "true") {
						$content[$my_content[$sort_by]] = $my_content;
					} else {
						if(strtotime($my_content['date'])-time() > 0) {
							$content[$my_content[$sort_by]] = $my_content;
						}
					}
				}
	        }
	    }
	    closedir($handle);
	    //debug::show($content, "");
	    if($sort_by == "index") {
	    	asort($content);
	    } else {
	    	sort($content);
	    }
	    
	    if($items) {
	    	$items = ("default") ? PREFS_GLOBAL_PAGE_LIMIT : $items;
			$pages = ceil(count($content)/$items);
			$content = array_slice($content, $page_start, $items);
	    }
	    
	    //
	    $smarty->assign("testimonial_image", $testimonial_image);
	    $smarty->assign("testimonial_text", $testimonial_text);
		$smarty->assign("pages", $pages);
	    $smarty->assign("content", $content);
	}
}
?>