-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.php
97 lines (77 loc) · 2.79 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
$urlDemo = false;
if(isset($_GET["download"])){
//Only need to include the MOBI file, all other files are included automatically
include("MOBIClass/MOBI.php");
if($urlDemo){
//Set the url (note that this file isn't created for eBook viewing, it's just
//to demonstrate that you can give (almost) any news article and get it working on
//your eBook reader)
$url = "http://thetricky.net/mySQL/GROUP%20BY%20vs%20ORDER%20BY";
$recognize = false;
//Create the mobi object
$mobi = new MOBI();
//Find and set the content handler
$content = null;
if($recognize){ //Pass through to right handler
$content = RecognizeURL::GetContentHandler($url);
}
if($content == null){ //If handler not found or if the recognition was turned off
$content = new OnlineArticle($url);
}
$mobi->setContentProvider($content);
//Get title and make it a 12 character long 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");
die;
}else{
//Create the mobi object
$mobi = new MOBI();
$content = new MOBIFile();
$content->set("title", "My first eBook");
$content->set("author", "Me");
$content->appendChapterTitle("Introduction");
for($i = 0, $lenI = rand(5, 10); $i < $lenI; $i++){
$content->appendParagraph("P".($i+1));
}
//Based on PHP's imagecreatetruecolor help paage
$im = imagecreatetruecolor(220, 200);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 10, 5, 5, 'A Simple Text String', $text_color);
imagestring($im, 5, 15, 75, 'A Simple Text String', $text_color);
imagestring($im, 3, 25, 125, 'A Simple Text String', $text_color);
imagestring($im, 2, 10, 155, 'A Simple Text String', $text_color);
$content->appendImage($im);
imagedestroy($im);
$content->appendPageBreak();
for($i = 0, $lenI = rand(10, 15); $i < $lenI; $i++){
$content->appendChapterTitle(($i+1).". Chapter ".($i+1));
for($j = 0, $lenJ = rand(20, 40); $j < $lenJ; $j++){
$content->appendParagraph("P".($i+1).".".($j+1)." TEXT TEXT TEXT");
}
$content->appendPageBreak();
}
$mobi->setContentProvider($content);
//Get title and make it a 12 character long 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");
die;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sample</title>
</head>
<body>
<a href='index.php?download'>Download</a>
</body>
</html>