Exemple #1
0
function StoreAsPRC($title, $rawData)
{
    // echo "<h1>$title</h1>\n<pre>$rawData\n</pre>\n"; return;
    global $SavedPDB, $UncompressedDoc, $TargetType, $CompressWarningDisplayed;
    $fileName = preg_replace('/[^-a-zA-Z_0-9]/', '_', $title);
    if (!isset($SavedPDB) || !is_array($SavedPDB)) {
        $SavedPDB = array();
        session_register('SavedPDB');
    }
    $SavedInfo['Title'] = $title;
    $SavedInfo['Type'] = $TargetType;
    $SavedInfo['Time'] = time();
    if ($TargetType == 'DOC') {
        if (isset($UncompressedDoc) && $UncompressedDoc) {
            $prc = new PalmDoc($title, false);
        } else {
            $prc = new PalmDoc($title);
        }
        $prc->AddDocText($rawData);
        if (!isset($CompressWarningDisplayed)) {
            $WarningTime = '';
            if (count($prc->Records) > 5) {
                $WarningTime = 'a bit';
            }
            if (count($prc->Records) > 10) {
                $WarningTime = 'a while';
            }
            if (count($prc->Records) > 15) {
                $WarningTime = 'a long time';
            }
            if (count($prc->Records) > 25) {
                $WarningTime = 'a very long time';
            }
            if (count($prc->Records) > 40) {
                $WarningTime = 'enough time to write a poem';
            }
            if (count($prc->Records) > 60) {
                $WarningTime = 'enough time for you learn a new hobby';
            }
            if (count($prc->Records) > 100) {
                $WarningTime = 'so long that PHP will likely time out and ' . 'kill this conversion';
            }
            if ($WarningTime != '') {
                ShowStatus("Compressing the DOC.\nThis could take " . $WarningTime . '.');
            }
            $CompressWarningDisplayed = true;
        }
    } elseif ($TargetType == 'SmallBASIC') {
        $prc = new PalmSmallBASIC($title);
        $result = $prc->ConvertFromText($rawData);
        if (is_array($result)) {
            ShowError('Error converting the file.  The section "' . $result[1] . '" is too big.  It must be broken into ' . 'multiple sections for the conversion to work.');
            return;
        }
    }
    ob_start();
    $prc->WriteToStdout();
    $prc = ob_get_contents();
    ob_end_clean();
    $SavedInfo['Data'] = $prc;
    $key = $fileName;
    $num = 1;
    while (isset($SavedPDB[$key])) {
        $num++;
        $key = $fileName . '-' . $num;
    }
    $SavedPDB[$key] = $SavedInfo;
}