
<?php
function wpctp( $text, $separator = '-' ){
	$texts = explode( " ", $text );
	$output = '';
	$space = ' ';
	$count = ( count( $texts ) - 1 );
	foreach( $texts as $key => $text ){
		$output .= 'wpctp' . $separator . $text;
		if( $key < $count ){
			$output .= $space;
		}
	}
	return $output;
}
function wpctp_e( $text, $separator = '-' ){
	$texts = explode( " ", $text );
	$output = '';
	$space = ' ';
	$count = ( count( $texts ) - 1 );
	foreach( $texts as $key => $text ){
		$output .= 'wpctp' . $separator . $text;
		if( $key < $count ){
			$output .= $space;
		}
	}
	echo $output;
}
function wpctp_get_column_class( $column ){
	switch ( (string) $column ){
		case "2":
			return wpctp( 'one-half' );
			break;
		case "3":
			return wpctp( 'one-third' );
			break;
		case "2/3":
			return wpctp( 'two-thirds' );
			break;
		case "4":
			return wpctp( 'one-fourth' );
			break;
		case "2/4":
			return wpctp( 'two-fourths' );
			break;
		case "3/4":
			return wpctp( 'three-fourths' );
			break;
		case "5":
			return wpctp( 'one-fifth' );
			break;
		case "2/5":
			return wpctp( 'two-fifths' );
			break;
		case "3/5":
			return wpctp( 'three-fifths' );
			break;
		case "4/5":
			return wpctp( 'four-fifths' );
			break;
		case "6":
			return wpctp( 'one-sixth' );
			break;
		case "2/6":
			return wpctp( 'two-sixths' );
			break;
		case "3/6":
			return wpctp( 'three-sixths' );
			break;
		case "4/6":
			return wpctp( 'four-sixths' );
			break;
		case "5/6":
			return wpctp( 'five-sixths' );
			break;
		default :
			return wpctp( 'full' );
			break;	
	}
}
function wpctp_get_template_part( $filename, $path = false ){
	if ( file_exists( WPCTP_CHILD_THEME_DIR . "/anton-widgets/$filename.php" ) ) {
		include( WPCTP_CHILD_THEME_DIR . "/anton-widgets/$filename.php" );
		return;
	}
	if ( file_exists( WPCTP_PARENT_THEME_DIR . "/anton-widgets/$filename.php" ) ) {
		include( WPCTP_PARENT_THEME_DIR . "/anton-widgets/$filename.php" );
		return;
	}
	if( $path ){
		include( $path . "/$filename.php" );
	}else{
		include( WPCTP_TEMPLATE_PATH . "/$filename.php" );
	}
}
function wpctp_checkbox_pages( $args = '' ) {
	$defaults = array(
		'depth' => 0,
		'child_of' => 0,
		'selected' => 0,
		'echo' => 1,
		'name' => 'page_id',
		'id' => '',
		'class' => '',
		'show_option_none' => '',
		'show_option_no_change' => '',
		'option_none_value' => '',
		'value_field' => 'ID',
	);
	$r = wp_parse_args( $args, $defaults );
	$pages = get_pages( $r );
	$output = '';
	if ( empty( $r['id'] ) ) {
		$r['id'] = $r['name'];
	}
	if ( ! empty( $pages ) ) {
		$class = '';
		if ( ! empty( $r['class'] ) ) {
			$class = " class='" . esc_attr( $r['class'] ) . "'";
		}
		$output = "<span " . $class . " id='" . esc_attr( $r['id'] ) . "' class='" . wpctp( 'checkbox' ) . "'>\n";
		$output .= wpctp_walk_page_checkbox_tree( $pages, $r['depth'], $r );
		$output .= "</span>\n";
	}
	$html = apply_filters( 'wpctp_checkbox_pages', $output, $r, $pages );
	if ( $r['echo'] ) {
		echo $html;
	}
	return $html;
}
function wpctp_walk_page_checkbox_tree() {
	$args = func_get_args();
	if ( empty($args[2]['walker']) ) :
		$walker = new WPCTP_Walker_Page_Checkbox;
	else :
		$walker = $args[2]['walker'];
	endif;
	return call_user_func_array(array($walker, 'walk'), $args);
}
function wpctp_pixels_css(){
	return array( 'font-size', 'border-width', 'border-top-width', 'border-bottom-width', 'border-left-width', 'border-right-width', 'width', 'height', 'padding', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right', 'margin', 'margin-top', 'margin-bottom', 'margin-left', 'margin-right' );
}
function wpctp_get_css( $properties, $value ){
	if(
		empty( $value ) && 
		in_array( $properties, array( 'border-top-color', 'border-bottom-color', 'border-left-color', 'border-right-color', 'border-color', 'background-color', 'color' ) )
	){
		#$value = 'transparent';
	}
	if( empty( $value ) ){
		return;	
	}
	if( $properties == 'background-image' ){
		return "{$properties}:url('{$value}');";
	}
	$pixels = wpctp_pixels_css();
	$default = array_merge( $pixels, array( 'font-family' ) );
	if( in_array( $properties, $pixels ) ){
		return "{$properties}:{$value}px;";
	}
	if( ! in_array( $properties, $default ) ){
		return "{$properties}:{$value};";
	}
	if( $properties == 'font-family' ){
		return "{$properties}:'{$value}';";
	}
}
function wpctp_truncate_phrase( $text, $max_characters ) {
	if ( ! $max_characters ) {
		return '';
	}
	$text = trim( $text );
	if ( mb_strlen( $text ) > $max_characters ) {
		$text = mb_substr( $text, 0, $max_characters + 1 );
		$text_trim = trim( mb_substr( $text, 0, mb_strrpos( $text, ' ' ) ) );
		$text = empty( $text_trim ) ? $text : $text_trim;
	}
	return $text;
}
function wpctp_get_the_content( $max_characters, $more_link_text = '', $stripteaser = false ) {
	$content = get_the_content( '', $stripteaser );
	$content = strip_tags( strip_shortcodes( $content ), apply_filters( 'wpctp_get_the_content_allowedtags', '<script>,<style>' ) );
	$content = trim( preg_replace( '#<(s(cript|tyle)).*?</\1>#si', '', $content ) );
	$content = wpctp_truncate_phrase( $content, $max_characters );
	if ( $more_link_text ) {
		$link   = apply_filters( 'wpctp_get_the_content_more_link', sprintf( '&#x02026; <a href="%s" class="more-link">%s</a>', get_permalink(), $more_link_text ), $more_link_text );
		$output = sprintf( '<p>%s %s</p>', $content, $link );
	} else {
		$output = sprintf( '<p>%s</p>', $content );
		$link = '';
	}
	$link = '';
	return apply_filters( 'wpctp_get_the_content', $output, $content, $link, $max_characters );
}
function wpctp_the_content( $max_characters, $more_link_text = '', $stripteaser = false ) {
	$content = wpctp_get_the_content( $max_characters, $more_link_text, $stripteaser );
	echo apply_filters( 'wpctp_the_content', $content );
}