} if ($Stored) { $pdb = new PalmDoc("Stored Bookmark Test"); } else { $pdb = new PalmDoc("Embedded Bookmark Test"); } if ($Stored) { $ThisTest = "stored"; $OtherTest = "embedded"; $UcFirst = "Stored"; } else { $ThisTest = "embedded"; $OtherTest = "stored"; $UcFirst = "Embedded"; } $pdb->AddText("This is a test file to see if {$ThisTest} " . "bookmarks are recognized by a document reader. To determine if " . "{$OtherTest} bookmarks are supported, you'll need to use the " . "other bookmark test, which is available from " . "https://github.com/fidian/php-pdb (in the examples)." . "To figure out if it worked, look for the bookmark list in this " . "document reader. If it has a bookmark named \"{$UcFirst} " . "Bookmark\", then it worked. If not, then this document reader " . "doesn't support {$ThisTest} style bookmarks.\n\n" . "This document was automatically generated using the PHP-PDB " . "library -- a free, GPL'd PHP library that manipulates PDB " . "files. Feel free to give it a look at\n" . "https://github.com/fidian/php-pdb\n\n"); // Add the bookmark if ($Stored) { $pdb->AddBookmark("Stored Bookmark"); } else { $pdb->AddText("*Embedded Bookmark\n"); } $pdb->AddText("This is where \"{$UcFirst} Bookmark\" should " . "take you, if this document reader properly supports {$ThisTest} " . "bookmarks.\n\n" . "Don't forget to see if your document reader supports {$OtherTest} " . "style bookmarks!\n\n"); $pdb->AddText("Have a GREAT day!\n\n"); if (!$Stored) { $pdb->AddText("This next part is needed by the document " . "reader to detect where embedded bookmarks are located. If " . "you plan on generating documents with embedded bookmarks, " . "you just need to add the special character (I'm using an " . "asterisk -- the star thing) at the beginning of the line and " . "the rest of the line becomes the bookmark. Then, you just " . "include \"<X>\" at the end of your document (replacing the X " . "with the character you picked) to tell the doc reader which " . "character you used to define bookmarks, like what I have at " . "the end of this one.\n\n" . "Please note: Aportis will use the special character if it " . "appears anywhere inside the file, so try to pick a character " . "that is not in the text you are converting into a doc " . "file:\n\n" . "<*>"); } else { $pdb->AddText("This is just some garbage that should fill " . "the screen so that when you jump to the stored bookmark, the " . "message saying that you are in the right spot should be " . "immediately at the top. If this text is not there, and if " . "you use a small font, you may see it in the middle or closer " . "to the bottom. This is annoying, and to keep things simple, " . "I just add this filler material at the bottom."); } $pdb->DownloadPDB("bookmark_" . $ThisTest . ".pdb"); // END HERE
function DocTest($IsCompressed) { $d = new PalmDoc('Title Goes Here', $IsCompressed); $text = "Mary had a little lamb,\n" . "little lamb,\n" . "little lamb.\n" . "Mary had a little lamb,\n" . "its fleece as white as snow.\n" . "\n" . "It followed her to school one day,\n" . "school one day,\n" . "school one day.\n" . "It followed her to school one day.\n" . "and I hope this doc text test works well.\n" . "\n" . "(Yeah, I know. It does not rhyme.)\n"; // Just in case the file is edited and the newlines are changed a bit. $text = str_replace("\r\n", "\n", $text); $text = str_replace("\r", "\n", $text); $text = explode("\n", $text); $newText = ''; foreach ($text as $t) { trim($t); $newText .= $t . "\n"; } $d->AddText($newText); return GenerateMd5($d); }
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->AddText($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 == 'zTXT') { $prc = new PalmzTXT($title); $prc->AddText($rawData); } 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; }