Location: PHPKode > projects > CenterFlow > app/vendors/kaanon.php
<?

/**
 * Mimics javascript var x = document.height || document.getHeight || 600 functionality
 * @author Kaanon MacFarlane
 *
 * This will move through the parameters until one is not false. If it gets through all of them,
 * it will just return false;
 * $x = @ifsetor($Y, $Z, $A, $B);
 */
function ifsetor()
{
	$numargs = func_num_args();
	$i = 0;
	while($i < $numargs)
	{
		$current_arg = func_get_arg($i);
		if(is_bool($current_arg))
		{
			if ($current_arg)
			return $current_arg;
		}
		else if(!empty($current_arg) || is_array($current_arg) || is_object($current_arg) || $current_arg === 0)
		{
			return $current_arg;
		}
		$i++;
	}
	return false;
}

if(!function_exists('generate_random_char'))
{
	function generate_random_char()
	{
		$chars = range('a', 'z');
		mt_srand((double)microtime() * 1000000);
		return $chars[mt_rand(0,25)];
	}
}

function print_k($obj,$return = false,$title= NULL)
{
	//If text is passed as the second parameter, use it for the title
	if(is_string($return))
	{
		$title = $return;
		$return = false;
	}
	$txt = '';
	//If a title is pass print it.
	if($title != NULL)
	{
		$txt = "<h3>$title</h3>\n";
	}

	$txt .="<pre>\n";
	$txt.=print_r($obj,true);
	$txt.="</pre>";

	if($return)
	{
		return $txt;
	}
	print $txt;
}
/**
 * strips tags from text that are not considered safe
 * @author Scott Roach
 * @param string | array $str
 * @param string  $tags allowable tags
 * @return string | array
 */
function safe_tags($str, $tags = array('hr', 'br', 'b', 'i', 'u', 'em', 'strong', 'p', 'a','li'))
{
	$tags = is_array($tags) ? array() : $tags; // make sure an array is passed
	$parse_links = false;

	// sort the array desc because the regex needs br(break) to be before b(bold)
	rsort($tags);

	$allowed_tags = '<' . implode('><', $tags) . '>';
	if(is_array($str))
	{
		foreach($str as $key => $val)
		{
			$str[$key] = safe_tags($val,$tags);
		}
	}
	elseif (is_scalar($str))
	{
		$str = strip_tags($str, $allowed_tags);
		$key = array_search('a', $tags);
		if($key)
		{
			$parse_links = true;
			unset($tags[$key]);
		}

		$matches = implode('|', $tags);
		$str = preg_replace('/<(' . $matches . ')([^>\/]+)?( \/)?>/i', '<$1$3>', $str);
		$str = $parse_links ? preg_replace('/<a([^>]+)?(href=("|\')?(.+?)(\3|\s))([^>]+)?>/i', '<a $2>', $str) : $str;
	}
	return $str;
}

/**
 * Reverses the nl2br function
 * @author Anders Norrbring
 * @param html string $text
 * @return text string
 */
function br2nl($text)
{
    return  preg_replace('/<br\\\\s*?\\/??>/i', "\\n", $text);
}


function multiline($str)
{
	$lines = explode("\n",$str);
	return (count($lines) > 1);
}
Return current item: CenterFlow