View Single Post
Old 04-15-2009, 11:34 AM   #8
DigitalFeonix
Junior Member
DigitalFeonix began at the beginning.
 
DigitalFeonix's Avatar
 
Posts: 8
Karma: 10
Join Date: Dec 2008
Device: Sony PRS-505
Essentially the script takes three arguments; a site, a story id and an output format. I slurp the whole story into an associative array - using htmlpurifier as it's brought in - and output using the desired format.

For epub the .opf is created using this

PHP Code:
/******************************************************************************
    CONTENT.OPF
******************************************************************************/

// create info for XML
$manifest   '';
$spine      '';

for (
$i=1;$i<=$story['chapter_count'];$i++)
{
    
$id sprintf('%03d'$i);

    
$manifest  .= '        <item id="chapter-' $id '" href="chapter-' $id '.xhtml" media-type="application/xhtml+xml"/>' "\n";
    
$spine     .= '        <itemref idref="chapter-' $id '"/>' "\n";
}

$story_title $story['title'];

// add the OPF info
$opf = <<<EOM
<{$qm}xml version="1.0"{$qm}>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="bookid" version="2.0">
    <metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
        <dc:title>
{$story_title}</dc:title>
        <dc:identifier id="bookid">urn:uuid:
{$UID}</dc:identifier>
        <dc:language>en</dc:language> 
        <dc:creator>
{$story['author']}</dc:creator>
        <dc:publisher>DigitalFeonix</dc:publisher> 
        <dc:rights>Public Domain</dc:rights> 
        <dc:subject>FanFiction</dc:subject>
    </metadata>
    <manifest>
        <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
        <item id="cover" href="cover.xhtml" media-type="application/xhtml+xml"/>
{$manifest}
        <item id="backcover" href="backcover.xhtml" media-type="application/xhtml+xml"/>
    </manifest>
    <spine toc="ncx">
        <itemref idref="cover"/>
{$spine}
        <itemref idref="backcover"/>
    </spine>
</package>

EOM;

$epub->add_file($opf'OEBPS/content.opf'$tstamp); 
and the toc is created using
PHP Code:
/******************************************************************************
    TOC.NCX
******************************************************************************/

// create info for XML
$navpoint   '';

for (
$i=1;$i<=$story['chapter_count'];$i++)
{
    
$id     sprintf('%03d'$i);
    
$iplus  $i 1;

    
$chapter_title $story['chapters'][$i]['title'];

    
$navpoint  .= <<<EOM
        <navPoint id="navpoint-{$iplus}" playOrder="{$iplus}">
            <navLabel>
                <text>
{$chapter_title}</text>
            </navLabel>
            <content src="chapter-
{$id}.xhtml"/>
        </navPoint>

EOM;
}

$iplus $i 1;

//
$toc = <<<EOM
<{$qm}xml version="1.0" encoding="UTF-8" {$qm}>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
    <head>
        <meta name="dtb:uid" content="
{$UID}"/>
        <meta name="dtb:depth" content="1"/>
        <meta name="dtb:totalPageCount" content="0"/>
        <meta name="dtb:maxPageNumber" content="0"/>
    </head>
    <docTitle>
        <text>
{$story_title}</text>
    </docTitle>
    <docAuthor>
        <text>
{$story['author']}</text>
    </docAuthor>
    <navMap>
        <navPoint id="navpoint-1" playOrder="1">
            <navLabel>
                <text>Cover</text>
            </navLabel>
            <content src="cover.xhtml"/>
        </navPoint>
{$navpoint}
        <navPoint id="navpoint-
{$iplus}" playOrder="{$iplus}">
            <navLabel>
                <text>Backcover</text>
            </navLabel>
            <content src="backcover.xhtml"/>
        </navPoint>
    </navMap>
</ncx>

EOM;

$epub->add_file($toc'OEBPS/toc.ncx'$tstamp); 
The .oeb script takes the same associative array and outputs the flat .oeb file with the mime wrapping, building the .opf part the same way. This .oeb script was intended to create files suitable for upload to the eBookwise personal content server.
DigitalFeonix is offline   Reply With Quote