Skip to content

Commit

Permalink
Correct documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
raiju committed Aug 19, 2012
1 parent 44dff3c commit 68ab4b1
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions MOBIClass/MOBIFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class MOBIFile extends ContentProvider {
private $parts = array();
private $images = array();

/**
* Get the text data (the "html" code)
*/
public function getTextData(){
$prefix = "<html><head><guide><reference title='CONTENT' type='toc' filepos=0000000000 /></guide></head><body>";

Expand All @@ -31,6 +34,11 @@ public function getTextData(){
return $prefix.$toc.$title.$text.$suffix;
}

/**
* Generate the body's text and the chapter entries
* @return array($string, $entries) $string is the html data, $entries
* contains the level, the title and the position of the titles.
*/
public function generateText(){
$str = "";
$entries = array();
Expand All @@ -42,11 +50,11 @@ public function generateText(){
$str .= "<p>".$data."</p>";
break;
case self::H2:
$entries[] = array("level" => 2, "length" => strlen($str), "title" => $data);
$entries[] = array("level" => 2, "position" => strlen($str), "title" => $data);
$str .= "<h2>".$data."</h2>";
break;
case self::H3:
$entries[] = array("level" => 3, "length" => strlen($str), "title" => $data);
$entries[] = array("level" => 3, "position" => strlen($str), "title" => $data);
$str .= "<h3>".$data."</h3>";
break;
case self::IMAGE:
Expand All @@ -57,21 +65,32 @@ public function generateText(){
return array($str, $entries);
}

/**
* Generate a TOC
* @param $entries The entries array generated by generateText
* @param $base The zero position
*/
public function generateTOC($entries, $base = 0){
$toc = "<h2>Contents</h2>";
$toc .= "<blockquote><table summary='Table of Contents'><col/><tbody>";
for($i = 0, $len = sizeof($entries); $i < $len; $i++){
$entry = $entries[$i];
$pos = str_pad($entry["length"]+$base, 10, "0", STR_PAD_LEFT);
$pos = str_pad($entry["position"]+$base, 10, "0", STR_PAD_LEFT);
$toc .= "<tr><td><a filepos='".$pos."'>".$entry["title"]."</a></td></tr>";
}
return $toc."</tbody></b></table></blockquote>";
}

/**
* Get the file records of the images
*/
public function getImages(){
return $this->images;
}

/**
* Get the metadata
*/
public function getMetaData(){
return $this->settings;
}
Expand Down

0 comments on commit 68ab4b1

Please sign in to comment.