<commit_before><?php
/*
* Static resources/methods to be used inside your theme
* Example usage: 
*   Utils::post_thumbnail('full', 'class'); 
*/
class Utils{
	/* 
	* Check the current post for the existence of a short code 
	*/
	static function has_shortcode($shortcode = '') {
		
		$post_to_check = get_post(get_the_ID());
		
		// false because we have to search through the post content first
		$found = false;
		
		// if no short code was provided, return false
		if (!$shortcode) {
			return $found;
		}
		// check the post content for the short code
		if ( stripos($post_to_check->post_content, '[' . $shortcode) !== false ) {
			// we have found the short code
			$found = true;
		}
		
		// return our final results
		return $found;
	}

	/*
	* Return details about the last JSON error
	*/
	static function json_error(){
		switch (json_last_error()) {
			case JSON_ERROR_NONE:
				echo ' - No errors';
			break;
			case JSON_ERROR_DEPTH:
				echo ' - Maximum stack depth exceeded';
			break;
			case JSON_ERROR_STATE_MISMATCH:
				echo ' - Underflow or the modes mismatch';
			break;
			case JSON_ERROR_CTRL_CHAR:
				echo ' - Unexpected control character found';
			break;
			case JSON_ERROR_SYNTAX:
				echo ' - Syntax error, malformed JSON';
			break;
			case JSON_ERROR_UTF8:
				echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
			break;
			default:
				echo ' - Unknown error';
			break;
		}
	}

	/*
	* Generate a slug from string (lowercase and '-' as separator)
	*/

	static function generate_slug($s = ""){
		return strtolower(str_replace(" ", "-", $s));
	}

	/* 
	* Nice arrays
	*
	* This function will print out a nicely formatted array
	*/
	static function print_pre($s = "") {
		echo '<pre>';
		print_r( $s );
		echo '</pre>';
	}

	/* 
	* A smart way to get the post thumbnail
	* 
	* If found, the function will retur the post thumbnail, 
	* else it will return the first image attached to the post
	*/
	static function post_thumbnail($size = 'thumbnail', $class = ''){
		if ( has_post_thumbnail() ) { 
			echo "<aside class='entry-thumbnail'><a href='".get_permalink()."' class='$class' title='".get_the_title()."' rel='canonical'>";
			the_post_thumbnail($size);
			echo "</a></aside>";
		} else {
			$attachments = get_posts( array(
				'post_type' => 'attachment',
				'numberposts'     => 1,
				'post_parent' => get_the_ID(),
				'exclude'     => get_post_thumbnail_id()
			) );

			if ( $attachments ) {
				foreach ( $attachments as $attachment ) {
					$href = wp_get_attachment_image_src( $attachment->ID, $size);
				}
				echo "<aside class='entry-thumbnail'><a class='default $class' href='".get_permalink()."' title='".get_the_title()."' rel='canonical'>";
				echo "<img src='".$href[0]."' alt='".get_the_title()."'/>"; 
				echo "</a></aside>";
			}
		}
	}

	/* 
	* Prints out the current post metadata
	* 
	*/
	static function post_meta(){
		?>
		<aside class='aside meta'>
			Posted on <?php the_time(get_option('date_format')); ?> in <?php the_category(', '); ?> <?php the_tags(' &#8226; Talking about ', ', '); ?> &#8226; <a href='#comments'><?php comments_number('No Comments :(', 'One Comment', '% Comments' ); ?></a> &#8226; <a title="Permalink to <?php the_title_attribute(); ?>" href="<?php the_permalink(); ?>">Permalink</a> 
		</aside>
		<?php
	}

	/* 
	* Get a custom length excerpt
	*/
	static function custom_excerpt($s, $length){
		$temp = substr(strip_tags($s), 0, $length);
		if(strlen(strip_tags( $s ) ) > $length) $temp .= "&#0133;";
		return $temp; 
	}

	/*
	* Get a list of related posts based on common tags and categories
	* 
	* @param id : the id of the post
	*/
	static function related_posts($id){
		$categories = get_the_category($id);
		$tags = get_the_tags($id);
		if ($categories || $tags) {
			$category_ids = array();
			if($categories) foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
		 <commit_msg>Added function to print post attachments.<commit_after><?php
/*
* Static resources/methods to be used inside your theme
* Example usage: 
*   Utils::post_thumbnail('full', 'class'); 
*/
class Utils{
	/* 
	* Check the current post for the existence of a short code 
	*/
	static function has_shortcode($shortcode = '') {
		
		$post_to_check = get_post(get_the_ID());
		
		// false because we have to search through the post content first
		$found = false;
		
		// if no short code was provided, return false
		if (!$shortcode) {
			return $found;
		}
		// check the post content for the short code
		if ( stripos($post_to_check->post_content, '[' . $shortcode) !== false ) {
			// we have found the short code
			$found = true;
		}
		
		// return our final results
		return $found;
	}

	/*
	* Return details about the last JSON error
	*/
	static function json_error(){
		switch (json_last_error()) {
			case JSON_ERROR_NONE:
				echo ' - No errors';
			break;
			case JSON_ERROR_DEPTH:
				echo ' - Maximum stack depth exceeded';
			break;
			case JSON_ERROR_STATE_MISMATCH:
				echo ' - Underflow or the modes mismatch';
			break;
			case JSON_ERROR_CTRL_CHAR:
				echo ' - Unexpected control character found';
			break;
			case JSON_ERROR_SYNTAX:
				echo ' - Syntax error, malformed JSON';
			break;
			case JSON_ERROR_UTF8:
				echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
			break;
			default:
				echo ' - Unknown error';
			break;
		}
	}

	/*
	* Generate a slug from string (lowercase and '-' as separator)
	*/

	static function generate_slug($s = ""){
		return strtolower(str_replace(" ", "-", $s));
	}

	/* 
	* Nice arrays
	*
	* This function will print out a nicely formatted array
	*/
	static function print_pre($s = "") {
		echo '<pre>';
		print_r( $s );
		echo '</pre>';
	}

	/* 
	* A smart way to get the post thumbnail
	* 
	* If found, the function will retur the post thumbnail, 
	* else it will return the first image attached to the post
	*/
	static function post_thumbnail($size = 'thumbnail', $class = ''){
		if ( has_post_thumbnail() ) { 
			echo "<aside class='entry-thumbnail'><a href='".get_permalink()."' class='$class' title='".get_the_title()."' rel='canonical'>";
			the_post_thumbnail($size);
			echo "</a></aside>";
		} else {
			$attachments = get_posts( array(
				'post_type' => 'attachment',
				'numberposts'     => 1,
				'post_parent' => get_the_ID(),
				'exclude'     => get_post_thumbnail_id()
			) );

			if ( $attachments ) {
				foreach ( $attachments as $attachment ) {
					$href = wp_get_attachment_image_src( $attachment->ID, $size);
				}
				echo "<aside class='entry-thumbnail'><a class='default $class' href='".get_permalink()."' title='".get_the_title()."' rel='canonical'>";
				echo "<img src='".$href[0]."' alt='".get_the_title()."'/>"; 
				echo "</a></aside>";
			}
		}
	}

	/* 
	* Prints out the current post metadata
	* 
	*/
	static function post_meta(){
		?>
		<aside class='aside meta'>
			Posted on <?php the_time(get_option('date_format')); ?> in <?php the_category(', '); ?> <?php the_tags(' &#8226; Talking about ', ', '); ?> &#8226; <a href='#comments'><?php comments_number('No Comments :(', 'One Comment', '% Comments' ); ?></a> &#8226; <a title="Permalink to <?php the_title_attribute(); ?>" href="<?php the_permalink(); ?>">Permalink</a> 
		</aside>
		<?php
	}

	/* 
	* Prints out the current post attachments
	* 
	*/
	static function post_attachments($title = '', $class = ''){
		$attachments = get_posts(array(	
			'post_type' => 'attachment',
			'numberposts'     => -1,
			'post_parent' => get_the_ID()
		));
		$custom_fields = get_post_custom();
		$url = $custom_fields['url'];
		$github = $custom_fields['github'];

		if ( $attachments ) {
			echo "<h3>$title</h3>";
			foreach ( $attachments as $attachment ) {
				$href = wp_get_attachment_image_src( $attachment->ID, 'thumbnail'); 
				$full = wp_get_attachment_image_src( $attachment->ID, 'full');
				echo "<a class='$class' href='".$full[0]."' target=\"_blank\" rel=\"lightbox\">";
				echo "<img src='".$href[0]."' alt='".get_the_title()."'/>"; 
				echo "</a>";
			}
		}
	}

	/* 
	* Get a custom length excerpt
	*/
	static function custom_excerpt($s, $length){
		$temp = substr(strip_tags($s), 0, $length);
		if(strlen(strip_tags( $s ) ) > $length) $temp .= "&#0133;";
		return $temp; 
	}

	/*
	* Get a list of related posts based on common tags and categories
	* 
	* @param id : the id of the post
	*/
	static function related_posts($id){
		$categories = get_the_category($id);
		$tags = get_the_tags($id);
		if ($categories || $tags) {
			$category_ids = array();
			if($categories) foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
		 
{'fraction_non_alphanumeric': 0.16391740685200137, 'fraction_numerical': 0.0054216172568923755, 'mean_word_length': 3.4992215879605606, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5843145', 'n_tokens_mistral': 3351, 'n_tokens_neox': 2891, 'n_words': 787}