<commit_before><?php
require('fpdf.php');

class PDF extends FPDF
{
    public $sourcefilename = '';
// Page header
    function Header()
    {
        // Logo
        // $this->Image('logo.png',10,6,30);
        // Arial bold 15
        $this->SetFont('Arial','B',15);
        // Move to the right
        $this->Cell(80);
        // Title
        $this->Cell(30,10,'Title',1,0,'C');
        // Line break
        $this->Ln(20);
    }

// Page footer
    function Footer()
    {
        // Position at 1.5 cm from bottom
        $this->SetY(-15);
        // Arial italic 8
        $this->SetFont('Arial','I',8);
        // Filename - Left justify
        $this->Cell(0,10,basename($this->sourcefilename),0,0,'L');
        // Page number - Right Justify
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'R');
    }
}

// A PHP5 compatible clone of PHP7's dirname function
function dirname_r($path, $count=1){
    if ($count > 1){
        return dirname(dirname_r($path, --$count));
    }else{
        return dirname($path);
    }
}

// Recursively archive/zip a collection
function Zip($source, $destination)
{
    if (!extension_loaded('zip') || !file_exists($source)) {
        return false;
    }

    $zip = new ZipArchive();
    if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
        return false;
    }

    $source = str_replace('\\', '/', realpath($source));

    if (is_dir($source) === true) {
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);

        foreach ($files as $file) {
            $file = str_replace('\\', '/', $file);

            // Ignore "." and ".." folders
            if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..')))
                continue;

            $file = realpath($file);

            if (is_dir($file) === true) {
                $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
            } else if (is_file($file) === true) {
                $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
            }
        }
    } else if (is_file($source) === true) {
        $zip->addFromString(basename($source), file_get_contents($source));
    }

    return $zip->close();
}


// Recursively generate PDF of a collection
function generatePDF($source, $destination, $recipient)
{
    $pdf = new PDF();
    $pdf->SetAutoPageBreak(false);
    $pdf->AliasNbPages();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->MultiCell(180,10,'This archive has been provided to '.$recipient.' under the following conditions: '.ACCESS_CONDITIONS);

    // Lets not recurse the entire collection!
    $source .= '/large';
    $source = str_replace('\\', '/', realpath($source));

    if (is_dir($source) === true) {
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
        // Sort our files, by filename
        $sorted_files = iterator_to_array($files);
        sort($sorted_files, SORT_NATURAL);
        foreach ($sorted_files as $file) {
            $pdf->sourcefilename = $file;
            $file = str_replace('\\', '/', $file);

            // Ignore "." and ".." folders
            if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..')))
                continue;

            $file = realpath($file);

            if (is_file($file) === true) {
                $pdf->AddPage();
                $pdf->Image($file);
            }
        }
    } else if (is_file($source) === true) {
        $pdf->AddPage();
        $pdf->Image($file);
    }

    if ((defined('DADS_DEBUG') && 1 == DADS_DEBUG))
    {
        $pdf->Output("I");
    } else<commit_msg>PDF output will be landscape, or portrait, depending on the source image<commit_after><?php
require('fpdf.php');

class PDF extends FPDF
{
    public $sourcefilename = '';
// Page header
    function Header()
    {
        // Logo
        // $this->Image('logo.png',10,6,30);
        // Arial bold 15
        $this->SetFont('Arial','B',15);
        // Move to the right
        $this->Cell(80);
        // Title
        $this->Cell(30,10,'Title',1,0,'C');
        // Line break
        $this->Ln(20);
    }

// Page footer
    function Footer()
    {
        // Position at 1.5 cm from bottom
        $this->SetY(-15);
        // Arial italic 8
        $this->SetFont('Arial','I',8);
        // Filename - Left justify
        $this->Cell(0,10,basename($this->sourcefilename),0,0,'L');
        // Page number - Right Justify
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'R');
    }
}

// A PHP5 compatible clone of PHP7's dirname function
function dirname_r($path, $count=1){
    if ($count > 1){
        return dirname(dirname_r($path, --$count));
    }else{
        return dirname($path);
    }
}

// Recursively archive/zip a collection
function Zip($source, $destination)
{
    if (!extension_loaded('zip') || !file_exists($source)) {
        return false;
    }

    $zip = new ZipArchive();
    if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
        return false;
    }

    $source = str_replace('\\', '/', realpath($source));

    if (is_dir($source) === true) {
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);

        foreach ($files as $file) {
            $file = str_replace('\\', '/', $file);

            // Ignore "." and ".." folders
            if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..')))
                continue;

            $file = realpath($file);

            if (is_dir($file) === true) {
                $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
            } else if (is_file($file) === true) {
                $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
            }
        }
    } else if (is_file($source) === true) {
        $zip->addFromString(basename($source), file_get_contents($source));
    }

    return $zip->close();
}


function pushImage($pdf, $file)
{
    // Should the page orientation be Landscape, or portrait?
    list($width, $height) = getimagesize($file);

    if ($width > $height)
    {
            $pdf->Addpage ('L');
    }
        else
        {
            $pdf->Addpage ('P');
        }
    $pdf->Image($file);
}

// Recursively generate PDF of a collection
function generatePDF($source, $destination, $recipient)
{
    $pdf = new PDF();
    $pdf->SetAutoPageBreak(false);
    $pdf->AliasNbPages();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->MultiCell(180,10,'This archive has been provided to '.$recipient.' under the following conditions: '.ACCESS_CONDITIONS);

    // Lets not recurse the entire collection!
    $source .= '/large';
    $source = str_replace('\\', '/', realpath($source));

    if (is_dir($source) === true) {
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
        // Sort our files, by filename
        $sorted_files = iterator_to_array($files);
        sort($sorted_files, SORT_NATURAL);
        foreach ($sorted_files as $file) {
            $pdf->sourcefilename = $file;
            $file = str_replace('\\', '/', $file);

            // Ignore "." and ".." folders
            if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..')))
                continue;

            $file = realpath($file);

            if (is_file($file) === true) {
                pushImage($pdf, $file);
            }
        }
    } else if (is_file($source) === true) {
        pushImage($pdf, $file);
    }

    if ((defined('DADS_DEBUG') && 1 == DADS_DEBUG))
    {
        $pdf->Output("I");
    } else
{'fraction_non_alphanumeric': 0.18475073313782991, 'fraction_numerical': 0.012495218666326661, 'mean_word_length': 2.2561228725612286, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '2430424', 'n_tokens_mistral': 2542, 'n_tokens_neox': 2421, 'n_words': 505}