<commit_before><?php
/**
 * Provides a consistent interface for
 * accessing posts or articles with multiple methods
 * of displaying and managing the contained data.
 *
 * @author <NAME> <<EMAIL>>
 */


/**
 * Includes the inherited dataMonger class
 */
include_once 'class_dataMonger.php';
/**
* Contains everything to do with retrieving and outputting
* posts in multiple forms.  Is capable of retrieving posts stored
* in .json format (preferred when available) as well as plaintext
* (file syntax described below in constructor).
* 
* Contains functions to output the post data in html format
* for displaying to a page, and atom format for use in generating
* an atom feed.
*/
class article extends dataMonger{
	
	/**
	 * Reads and parses a post file and creates an instance
	 * of the class with the post data. Capable of managing
	 * posts in json and plaintext, but prefers json if
	 * a json file exists for the requested post.
	 * 
	 * @param nodefile (string) - a yyyy.mm.dd string of a nodefile
	 */
	public function __construct($nodefile){

		/* Handles the case where the post file does not exist
		 * at all by pre-setting all the fields to a failure state.
		 * This also safely handles any case where the data in a post
		 * doesn't contain all of the expected fields in a typical way.
		 */
		
		$this->container['title'] = "Oops! Post Not Found!";
		$this->container['date'] = "";
		$this->container['tags'] = "";
		$this->container['datestamp'] = "";
		$this->container['link'] = '/blog';
		$this->container['content'] = '<p>Sorry, the post you were looking for could not be found.  If you think it should be here, try browsing by title.  Otherwise, <a href="blog/index.php">return to blog home.</a></p>'."\n".'<p>Think you were looking for something else? <a href="'.getConfigOption('site_domain').'">visit site home</a>.</p>';
			
		if (file_exists("$nodefile.json")){
			$jsoncontents = file_get_contents("$nodefile.json");
			
			// Directly read data into the class
			$this->container = json_decode($jsoncontents, True);
			
			// Reformat and add data that the class relies on
			
			// Implode the array of lines for the content into a string
			$this->container['content'] = implode( $this->container['content'] );
			// Add the web url for the post
			$this->container['link'] = getConfigOption('site_domain').'/blog/read/'.basename($nodefile, '.json').'.htm';
			
		}
		/*<commit_msg>add formatting flexibility, genericize link generation<commit_after><?php
/**
 * Provides a consistent interface for
 * accessing posts or articles with multiple methods
 * of displaying and managing the contained data.
 *
 * @author <NAME> <<EMAIL>>
 */


/**
 * Includes the inherited dataMonger class
 */
include_once 'class_dataMonger.php';
/**
* Contains everything to do with retrieving and outputting
* posts in multiple forms.  Is capable of retrieving posts stored
* in .json format (preferred when available) as well as plaintext
* (file syntax described below in constructor).
* 
* Contains functions to output the post data in html format
* for displaying to a page, and atom format for use in generating
* an atom feed.
*/
class article extends dataMonger{
	
	/**
	 * Reads and parses a post file and creates an instance
	 * of the class with the post data. Capable of managing
	 * posts in json and plaintext, but prefers json if
	 * a json file exists for the requested post.
	 * 
	 * @param nodefile (string) - a yyyy.mm.dd string of a nodefile
	 */
	public function __construct($nodefile, $bloguri){

		/* Handles the case where the post file does not exist
		 * at all by pre-setting all the fields to a failure state.
		 * This also safely handles any case where the data in a post
		 * doesn't contain all of the expected fields in a typical way.
		 */
		
		$this->container['title'] = "Oops! Post Not Found!";
		$this->container['date'] = "";
		$this->container['tags'] = "";
		$this->container['datestamp'] = "";
		$this->container['link'] = '/'.$bloguri;
		$this->container['content'] = '<p>Sorry, the post you were looking for could not be found.  If you think it should be here, try browsing by title.  Otherwise, <a href="blog/index.php">return to blog home.</a></p>'."\n".'<p>Think you were looking for something else? <a href="'.getConfigOption('site_domain').'">visit site home</a>.</p>';
			
		if (file_exists("$nodefile.json")){
			$jsoncontents = file_get_contents("$nodefile.json");
			
			// Directly read data into the class
			$this->container = json_decode($jsoncontents, True);
			
			// Reformat and add data that the class relies on
			
			// Implode the array of lines for the content into a string
			if ( is_array( $this->container['content'] ) )
				$this->container['content'] = implode( $this->container['content'] );

			// Add the web url for the post
			if ( is_array( $this->container['tags'] ) )
				$this->container['tags'] = implode( ', ', $this->container['tags'] );

			$this->container['link'] = getConfigOption('site_domain').'/'.$bloguri.'/index.php?id=post&node='.basename($nodefile, '.json');
			
		}
		/*
{'fraction_non_alphanumeric': 0.1279275733123401, 'fraction_numerical': 0.0, 'mean_word_length': 3.7230483271375463, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 49, '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': '2725500', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1438, 'n_words': 577}