<?php
if ( ! function_exists( 'disect_it' ) ) :
/**
 * Prints out the content of a variable wrapped in <pre> elements.
 * For development and debugging use
*/
function disect_it( $var = NULL, $exit = true, $comment = false ){
	
	if ( $comment ) {echo '<!--';}
	
	if ( $var !== NULL ){
		echo '<pre>';
		var_dump( $var );
		echo '</pre>';
	} else {
		echo '<strong>ERROR:</strong> You must pass a variable as argument to the <code>disect_it()</code> function.';
	}
	
	if ( $comment ) {echo '-->';}
	if ( $exit ) {exit();}
}
endif;


if ( ! function_exists( 'franz_substr' ) ) :
/**
 * Truncate a string by specified length
*/
function franz_substr( $string, $start = 0, $length = '', $suffix = '' ){
	
	if ( $length == '' ) return $string;
	
	if ( strlen( $string ) > $length ) {
		$trunc_string = substr( $string, $start, $length ) . $suffix;
	} else {
		$trunc_string = $string;	
	}
	return apply_filters( 'franz_substr', $trunc_string, $string, $start, $length, $suffix );
}
endif;


if ( ! function_exists( 'franz_truncate_words' ) ) :
/**
 * Truncate a string by specified word count
 *
 * @param string $string The string to be truncated
 * @param int $word_count The number of words to keep
 * @param string $suffix Optional, string to be appended to truncated string
 * @return string $trunc_string The truncated string
 *
 * @package Franz Josef
 * @since 1.6
*/
function franz_truncate_words( $string, $word_count, $suffix = '...' ){
   $string_array = explode( ' ', $string );
   $trunc_string = $string;
   if ( count ( $string_array ) > $word_count && $word_count > 0 )
      $trunc_string = implode( ' ', array_slice( $string_array, 0, $word_count ) ) . $suffix;
	  
   return apply_filters( 'franz_truncate_words', $trunc_string, $string, $word_count, $suffix );
}
endif;


if ( ! function_exists( 'franz_remove_anonymous_object_filter' ) ) :
/**
 * Remove an anonymous object filter.
 *
 * @param  string $tag    Hook name.
 * @param  string $class  Class name
 * @param  string $method Method name
 * @return void
 */
function franz_remove_anonymous_object_filter( $tag, $class, $method ){
	$filters = $GLOBALS['wp_filter'][ $tag ];

	if ( empty ( $filters ) ) return;

	foreach ( $filters as $priority => $filter ) {
		foreach ( $filter as $identifier => $function )	{
			if ( is_array( $function) && is_a( $function['function'][0], $class ) && $method === $function['function'][1] ) {
				remove_filter( $tag, array ( $function['function'][0], $method ), $priority );
			}
		}
	}
}
endif;