Git Product home page Git Product logo

phpmobi's Introduction

phpMobi file generator

phpMobi is a php script that can generate .mobi files from valid html files. While this was meant as an experiment, this tool works quite well and can be used to generate mobipocket files from most news articles.

IMPORTANT: Do NOT use this on a public web server: most of it was coded in a weekend, with no testing and no special attention to security. Also, as no official documentation for the MOBI file format is available, there will be some bugs/problems in the generated files, but it works for relatively simple documents on the Kindle previewer and the Kindle 3.

MobiPocket is an eBook format created by Mobipocket SA. This tool also uses a php readability port made by Keyvan Minoukadeh.

Code sample

See index.php for an example of using this program.

Sending an online article as a download:

//Create the MOBI object
$mobi = new MOBI();

//Set the content provider
$content = new OnlineArticle("URL");
$mobi->setContentProvider($content);

//Get title and make it a 12 character long url-safe filename
$title = $mobi->getTitle();
if($title === false)
	$title = "file";

$title = urlencode(str_replace(" ", "_", strtolower(substr($title, 0, 12))));

//Send the mobi file as download
$mobi->download($title.".mobi");

Using a previously generated/downloaded html file (will not download any images!):

$data = "<html>...</html>";
$options = array(
	"title" => "Local document",
  	"author" => "Author name",
  	"subject" => "Subject"
);

//Create the MOBI object
$mobi = new MOBI();

//Set the data
$mobi->setData($data);
$mobi->setOptions($options);

//Save the mobi file locally
$mobi->save($options["title"].".mobi");

Implementation

This code was implemented while reverse-engineering the MobiPocket format. Therefore this code absolutely isn't optimized for speed, but rather for easy changes, as getting it to produce valid files was quite fiddly.

Features

Modular content provider system: Adding a new data source can be done by extending the ContentProvider class. See the OnlineArticle class for a simple but complete implementation of such a system.

Image support: By default, the online article downloader (and any other content provider that supports images) will download images and integrate them into the mobi file.

Partial UTF-8 support: In practice UTF-8 just works, but there are some unhandled corner cases (see missing features).

Missing Features

Compression: This won't be implemented (or if it is, only to serve as a reference of the format).

Different eBook types: MobiPocket supports other formats/layouts, such as newspaper-like formats. At the moment only the book layout has been implemented.

Full UTF-8 support: UTF-8 should work most of the time (it worked every time I tested it), but there might be some problems when the character is split over two "records".

License

This code is released under the Apache license (version 2.0)

phpmobi's People

Contributors

raiju avatar dawsong avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.