<commit_before><?php
include '/home/natelev/www/static/core_web.php';
$postDir='entries';
function getPostList(){
    /*
     * Creates a list of files in the working directory, sorts
     * and reverses the list, and returns it.  Intended for working
     * with blog posts stored as text files with date-coded filenames
     */
    $avoid = avoidFiles();
    $posts = array();
    $handler = opendir("entries");
    $i = 0;
    while ($file = readdir($handler)){
      // if file isn't this directory or its parent, add it to the results
      if (  !in_array($file, $avoid) ){
            $posts[] = $file;
            $i++;
      }

    }
    
    sort($posts);
    $posts = array_reverse($posts);
    
    return $posts;
}

function retrievePost($node){
    /*
     * Retrieves the post (file) received as an argument
     * and adds appropriate formatting for it to be displayed.
     * Designed for use with plaintext blog posts with the format
     * 
     * TITLE
     * DISPLAY DATE
     * TAGS
     * FEED DATESTAMP
     * CONTENT
     * 
     */
    if (file_exists("entries/$node")){
    	$file = fopen("entries/$node", 'r');
    	$title = rtrim(fgets($file));
    	$date = rtrim(fgets($file));
        $tags = rtrim(fgets($file));
        $datestamp = fgets($file);
    	/*** return the current line ***/
    	echo '<h3><a href="post.php?node='.$node.'" >'.$title."</a></h3>\n";
    	echo "<h4>".$date."</h4>\n";
    	while(!feof($file)){
        	echo "<p>".rtrim(fgets($file), "\n"). "</p>\n";
    	}
        echo "<h5><i>Tags: ".$tags."</i></h5>\n";

    	fclose($file);
    }
    else{
	include "/home/natelev/www/static/template_error.php";
    }
}

function checkInventory(){
    /*
     * Checks the number of files in the current directory and
     * compares it to how many are listed in the current inventory.
     * If the number doesn't match, it returns False.
     */
    
    if ( ! file_exists('inventory.html') ){
        return False;
    }
    
    $existing = count( getPostList() );

    $inventory = 'inventory.html';
    $recorded = count(file($inventory));
    if ( $recorded == $existing ){
        return True;
    }
    
    return False;
    
}

function regenInventory(){
    /*
     * Regenerates the inventory file
     */
    $inventory = fopen('inventory.html', 'w');
    
    $avoid = avoidFiles();
    $handler = opendir('./');
    
    $posts = getPostList();
    
    foreach( $posts as $input ){
        $file = fopen("entries/$input", 'r');
        $title = rtrim(fgets($file));
        $date = rtrim(fgets($file));
        $tags = rtrim(fgets($file));
        fclose($file);
        $item = '<li><a href="post.php?node='.$input.'">'.$title.'</a><i> - '.$tags.'</i></li>'."\n";
        fwrite($inventory, $item);

    }
    
    fclose($inventory);
}

function RandomLine($filename) {
    /*<commit_msg>now ACTUALLY uses unified data format for posts<commit_after><?php
include '/home/natelev/www/static/core_web.php';
$postDir='entries';
class postObj {
    /*
     * Defines a data object to
     * contain a post as it is
     * read from a file. 
     */
     public $title, $tags, $date, $datestamp, $content;
     
     public function __construct($nodefile){
         /*
          * Reads in a nodefile and returns a data object
          * containing all of the data from it
          */
         $file = fopen($nodefile, 'r');
         $this->title = rtrim(fgets($file), "\n");
         $this->date = rtrim(fgets($file), "\n");
         $this->tags = rtrim(fgets($file), "\n");
         $this->datestamp = rtrim(fgets($file), "\n");         
         $contents='';
         
         while(!feof($file)){
            $contents .= "<p>".rtrim(fgets($file), "\n"). "</p>\n";
         }
         
         $this->content = $contents;
         
         fclose($file);
         
         
     }
 }
function getPostList(){
    /*
     * Creates a list of files in the working directory, sorts
     * and reverses the list, and returns it.  Intended for working
     * with blog posts stored as text files with date-coded filenames
     */
    $avoid = avoidFiles();
    $posts = array();
    $handler = opendir("entries");
    $i = 0;
    while ($file = readdir($handler)){
      // if file isn't this directory or its parent, add it to the results
      if (  !in_array($file, $avoid) ){
            $posts[] = $file;
            $i++;
      }

    }
    
    sort($posts);
    $posts = array_reverse($posts);
    
    return $posts;
}

function retrievePost($node){
    /*
     * Retrieves the post (file) received as an argument
     * and adds appropriate formatting for it to be displayed.
     * Designed for use with plaintext blog posts with the format
     * 
     * TITLE
     * DISPLAY DATE
     * TAGS
     * FEED DATESTAMP
     * CONTENT
     * 
     */
    if (file_exists("entries/$node")){
        $postData = new postObj("entries/$node");
        
    	$title = $postData->title;
    	$date = $postData->date;
        $tags = $postData->tags;
        $datestamp = $postData->datestamp;
    	/*** return the current line ***/
    	echo '<h3><a href="post.php?node='.$node.'" >'.$title."</a></h3>\n";
    	echo "<h4>".$date."</h4>\n";
    	
        echo $postData->content;
        
        echo "<h5><i>Tags: ".$tags."</i></h5>\n";

    }
    else{
	include "/home/natelev/www/static/template_error.php";
    }
}

function checkInventory(){
    /*
     * Checks the number of files in the current directory and
     * compares it to how many are listed in the current inventory.
     * If the number doesn't match, it returns False.
     */
    
    if ( ! file_exists('inventory.html') ){
        return False;
    }
    
    $existing = count( getPostList() );

    $inventory = 'inventory.html';
    $recorded = count(file($inventory));
    if ( $recorded == $existing ){
        return True;
    }
    
    return False;
    
}

function regenInventory(){
    /*
     * Regenerates the inventory file
     */
    $inventory = fopen('inventory.html', 'w');
    
    $avoid = avoidFiles();
    $handler = opendir('./');
    
    $posts = getPostList();
    
    foreach( $posts as $input ){
        
        $postData = new postObj("entries/$input");
        
        $title = $postData->title;
        $date = $postData->date;
        $tags = $postData->tags;

        $item = '<li><a href="post.php?node='.$input.'">'.$title.'</a><i> - '.$tags.'</i></li>'."\n";
        fwrite($inventory, $item);

    }
    
    fclose($inventory);
}

function RandomLine($filename) {
    /*
{'fraction_non_alphanumeric': 0.16481001068213033, 'fraction_numerical': 0.0021364260643979855, 'mean_word_length': 2.091509433962264, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '1418009', 'n_tokens_mistral': 2129, 'n_tokens_neox': 2095, 'n_words': 526}