<?php
/*
 * This file is part of Web Pro Manager.
 * 
 * Web Pro Manager 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 3 of the License, or
 * (at your option) any later version.
 * 
 * Web Pro Manager 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 Web Pro Manager.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @author The Web Pro Miami, Inc. <info@thewebpro.com>
 * @copyright The Web Pro Miami, Inc. <info@thewebpro.com>, http://www.thewebpro.com/
 * @license http://www.gnu.org/licenses/gpl.html GNU GPL
 * @package WebProManager
*/

// Receives text string, returns formatted string (unspecified HTML removed, HTML line breaks added, optional: double spacing converted to single)
function nMakePresentable($nTextToFormat,$nAllowDoubleSpacing="1",$nRemoveCR="1"){
	$nAllowedTags = "<h1><b><i><a><ul><li><pre><hr><blockquote><img><em><strong>";
	$nFormattedText = strip_tags(stripslashes($nTextToFormat),$nAllowedTags);
	if($nRemoveCR){ $nFormattedText = str_replace("\r","",$nFormattedText); } else { $nFormattedText = str_replace("\r","<BR>",$nFormattedText); }
	$nFormattedText = str_replace("\n","<BR>",$nFormattedText);
	if(!$nAllowDoubleSpacing){ $nFormattedText = str_replace("<BR><BR>","<BR>",$nFormattedText); }
	return $nFormattedText;
}
?>
<?php
// Receives text string, returns truncated string (allows only x words, with max. y chars, truncates rest and adds closer)
function nTruncateText($nTextToTruncate,$nWordCountAllowed,$nMaxChars,$nCloser="..."){
	$nWordCount = 0;
	$nTruncatedText = $nTextToTruncate;
	$nAddCloser=0;
	if(strlen($nTruncatedText)>$nMaxChars){
		$nTruncatedText = trim(substr($nTruncatedText,0,$nMaxChars));
		$nAddCloser=1;
	}
	$nTextARRAY = explode(" ",$nTruncatedText);
	if(count($nTextARRAY)>$nWordCountAllowed){
		$nTruncatedText="";
		foreach($nTextARRAY as $nWord){
			$nWordCount++;
			if($nWordCount<=$nWordCountAllowed){
				$nTruncatedText.="$nWord ";
			}
		}
		$nAddCloser=1;
	}
	if($nAddCloser){ $nTruncatedText.=$nCloser; }
	return $nTruncatedText;
}
?>
