diff options
author | tcit <tcit@tcit.fr> | 2014-04-25 16:20:25 +0200 |
---|---|---|
committer | tcit <tcit@tcit.fr> | 2014-04-25 16:20:25 +0200 |
commit | 7ec445b06e05d8caa5219c5802007d897c48ab4e (patch) | |
tree | ebd94986e35dd01b4b6d94dbce590e585f179e2c | |
parent | 72a857158c187206dae2eed08143d5743322cb0c (diff) | |
download | wallabag-7ec445b06e05d8caa5219c5802007d897c48ab4e.tar.gz wallabag-7ec445b06e05d8caa5219c5802007d897c48ab4e.tar.zst wallabag-7ec445b06e05d8caa5219c5802007d897c48ab4e.zip |
Big changes for epub export. Now possible to do it from a tag, a category and a search. Also, improved ebook rendering.
-rwxr-xr-x | inc/poche/Poche.class.php | 56 | ||||
-rwxr-xr-x | themes/baggy/config.twig | 2 | ||||
-rwxr-xr-x | themes/baggy/home.twig | 5 | ||||
-rwxr-xr-x | themes/baggy/view.twig | 2 |
4 files changed, 45 insertions, 20 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index e5539468..c476df3e 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -1136,36 +1136,52 @@ class Poche | |||
1136 | * handle epub | 1136 | * handle epub |
1137 | */ | 1137 | */ |
1138 | public function createEpub() { | 1138 | public function createEpub() { |
1139 | 1139 | ||
1140 | if (isset($_GET['epub']) && isset($_GET['id'])) { | 1140 | switch ($_GET['method']) { |
1141 | if ($_GET['id'] == "all") { // we put all entries in the file | 1141 | case 'id': |
1142 | $entries = $this->store->retrieveAll($this->user->getId()); | ||
1143 | } | ||
1144 | else { // we put only one entry in the file | ||
1145 | $entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT); | 1142 | $entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT); |
1146 | $entry = $this->store->retrieveOneById($entryID, $this->user->getId()); | 1143 | $entry = $this->store->retrieveOneById($entryID, $this->user->getId()); |
1147 | $entries = array($entry); | 1144 | $entries = array($entry); |
1148 | } | 1145 | break; |
1146 | case 'all': | ||
1147 | $entries = $this->store->retrieveAll($this->user->getId()); | ||
1148 | break; | ||
1149 | case 'tag': | ||
1150 | $tag = filter_var($_GET['tag'],FILTER_SANITIZE_STRING); | ||
1151 | $tags_id = $this->store->retrieveAllTags($this->user->getId(),$tag); | ||
1152 | $tag_id = $tags_id[0]["id"]; // we take the first result, which is supposed to match perfectly. There must be a workaround. | ||
1153 | $entries = $this->store->retrieveEntriesByTag($tag_id,$this->user->getId()); | ||
1154 | break; | ||
1155 | case 'category': | ||
1156 | $category = filter_var($_GET['category'],FILTER_SANITIZE_STRING); | ||
1157 | $entries = $this->store->getEntriesByView($category,$this->user->getId()); | ||
1158 | break; | ||
1159 | case 'search': | ||
1160 | $search = filter_var($_GET['search'],FILTER_SANITIZE_STRING); | ||
1161 | $entries = $this->store->search($search,$this->user->getId()); | ||
1162 | break; | ||
1163 | case 'default': | ||
1164 | die(_('Uh, there is a problem while generating epub.')); | ||
1165 | |||
1149 | } | 1166 | } |
1167 | |||
1150 | $content_start = | 1168 | $content_start = |
1151 | "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" | 1169 | "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" |
1152 | . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n" | 1170 | . "<!DOCTYPE html>\n" |
1153 | . " \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" | 1171 | . "<html>\n" |
1154 | . "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" | 1172 | . "<head>\n" |
1155 | . "<head>" | ||
1156 | . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" | ||
1157 | . "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\" />\n" | 1173 | . "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\" />\n" |
1158 | . "<title>Test Book</title>\n" | 1174 | . "<title>wallabag article</title>\n" |
1159 | . "</head>\n" | 1175 | . "</head>\n" |
1160 | . "<body>\n"; | 1176 | . "<body>\n"; |
1161 | 1177 | ||
1162 | $bookEnd = "</body>\n</html>\n"; | 1178 | $bookEnd = "</body>\n</html>\n"; |
1163 | 1179 | ||
1164 | $log = new Logger($entryID, TRUE); | 1180 | $log = new Logger("wallabag", TRUE); |
1165 | $fileDir = CACHE; | 1181 | $fileDir = CACHE; |
1166 | 1182 | ||
1167 | 1183 | ||
1168 | $book = new EPub(); | 1184 | $book = new EPub(EPub::BOOK_VERSION_EPUB3); |
1169 | $log->logLine("new EPub()"); | 1185 | $log->logLine("new EPub()"); |
1170 | $log->logLine("EPub class version: " . EPub::VERSION); | 1186 | $log->logLine("EPub class version: " . EPub::VERSION); |
1171 | $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION); | 1187 | $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION); |
@@ -1186,6 +1202,10 @@ class Poche | |||
1186 | $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP"); | 1202 | $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP"); |
1187 | 1203 | ||
1188 | $cssData = "body {\n margin-left: .5em;\n margin-right: .5em;\n text-align: justify;\n}\n\np {\n font-family: serif;\n font-size: 10pt;\n text-align: justify;\n text-indent: 1em;\n margin-top: 0px;\n margin-bottom: 1ex;\n}\n\nh1, h2 {\n font-family: sans-serif;\n font-style: italic;\n text-align: center;\n background-color: #6b879c;\n color: white;\n width: 100%;\n}\n\nh1 {\n margin-bottom: 2px;\n}\n\nh2 {\n margin-top: -2px;\n margin-bottom: 2px;\n}\n"; | 1204 | $cssData = "body {\n margin-left: .5em;\n margin-right: .5em;\n text-align: justify;\n}\n\np {\n font-family: serif;\n font-size: 10pt;\n text-align: justify;\n text-indent: 1em;\n margin-top: 0px;\n margin-bottom: 1ex;\n}\n\nh1, h2 {\n font-family: sans-serif;\n font-style: italic;\n text-align: center;\n background-color: #6b879c;\n color: white;\n width: 100%;\n}\n\nh1 {\n margin-bottom: 2px;\n}\n\nh2 {\n margin-top: -2px;\n margin-bottom: 2px;\n}\n"; |
1205 | |||
1206 | $log->logLine("Add Cover Image"); | ||
1207 | $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png"); | ||
1208 | |||
1189 | $cover = $content_start . "<h1>My articles on wallabag</h1>\n<h2>As seen on : http://$_SERVER[HTTP_HOST]</h2>\n" . $bookEnd; | 1209 | $cover = $content_start . "<h1>My articles on wallabag</h1>\n<h2>As seen on : http://$_SERVER[HTTP_HOST]</h2>\n" . $bookEnd; |
1190 | $book->addChapter("Notices", "Cover.html", $cover); | 1210 | $book->addChapter("Notices", "Cover.html", $cover); |
1191 | $book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE); | 1211 | $book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE); |
@@ -1193,7 +1213,7 @@ class Poche | |||
1193 | foreach ($entries as $entry) { | 1213 | foreach ($entries as $entry) { |
1194 | $tags = $this->store->retrieveTagsByEntry($entry['id']); | 1214 | $tags = $this->store->retrieveTagsByEntry($entry['id']); |
1195 | foreach ($tags as $tag) { | 1215 | foreach ($tags as $tag) { |
1196 | $book->setSubject($tag); | 1216 | $book->setSubject($tag['value']); |
1197 | } | 1217 | } |
1198 | 1218 | ||
1199 | $log->logLine("Set up parameters"); | 1219 | $log->logLine("Set up parameters"); |
@@ -1201,11 +1221,11 @@ class Poche | |||
1201 | 1221 | ||
1202 | 1222 | ||
1203 | $chapter = $content_start . $entry['content'] . $bookEnd; | 1223 | $chapter = $content_start . $entry['content'] . $bookEnd; |
1204 | $book->addChapter("Chapter " . $entry['id'] . ": " . $entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); | 1224 | $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); |
1205 | } | 1225 | } |
1206 | 1226 | ||
1207 | 1227 | ||
1208 | if (true) { | 1228 | if (DEBUG_POCHE) { |
1209 | $epuplog = $book->getLog(); | 1229 | $epuplog = $book->getLog(); |
1210 | $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // generation log | 1230 | $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // generation log |
1211 | // Only used in case we need to debug EPub.php. | 1231 | // Only used in case we need to debug EPub.php. |
diff --git a/themes/baggy/config.twig b/themes/baggy/config.twig index f43f6d01..1b8b8648 100755 --- a/themes/baggy/config.twig +++ b/themes/baggy/config.twig | |||
@@ -126,7 +126,7 @@ | |||
126 | <p><a href="?export" target="_blank">{% trans "Click here" %}</a> {% trans "to export your wallabag data." %}</p> | 126 | <p><a href="?export" target="_blank">{% trans "Click here" %}</a> {% trans "to export your wallabag data." %}</p> |
127 | 127 | ||
128 | <h2>Fancy a ebook ?</h2> | 128 | <h2>Fancy a ebook ?</h2> |
129 | Click on <a href="./?epub&id=all" title="Generate ePub">this link</a> to get all your articles in one ebook (ePub). | 129 | Click on <a href="./?epub&method=all" title="Generate ePub">this link</a> to get all your articles in one ebook (ePub). |
130 | 130 | ||
131 | <h2>{% trans "Cache" %}</h2> | 131 | <h2>{% trans "Cache" %}</h2> |
132 | <p><a href="?empty-cache">{% trans "Click here" %}</a> {% trans "to delete cache." %}</p> | 132 | <p><a href="?empty-cache">{% trans "Click here" %}</a> {% trans "to delete cache." %}</p> |
diff --git a/themes/baggy/home.twig b/themes/baggy/home.twig index 5dd91307..301f353a 100755 --- a/themes/baggy/home.twig +++ b/themes/baggy/home.twig | |||
@@ -57,6 +57,11 @@ | |||
57 | {% endfor %} | 57 | {% endfor %} |
58 | </div> | 58 | </div> |
59 | {% if view == 'home' %}{% if nb_results > 1 %}<a title="{% trans "Mark all the entries as read" %}" href="./?action=archive_all">{{ "Mark all the entries as read" }}</a>{% endif %}{% endif %} | 59 | {% if view == 'home' %}{% if nb_results > 1 %}<a title="{% trans "Mark all the entries as read" %}" href="./?action=archive_all">{{ "Mark all the entries as read" }}</a>{% endif %}{% endif %} |
60 | |||
61 | {% if tag %}<a title="{% trans "Download the articles from this tag in an epub" %}" href="./?epub&method=tag&tag={{ tag.value }}">{% trans "Download the articles from this tag in an epub" %}</a> | ||
62 | {% elseif search_term is defined %}<a title="{% trans "Download the articles from this search in an epub" %}" href="./?epub&method=search&search={{ search_term }}">{% trans "Download the articles from this search in an epub" %}</a> | ||
63 | {% else %}<a title="{% trans "Download the articles from this category in an epub" %}" href="./?epub&method=category&category={{ view }}">{% trans "Download the articles from this category in an epub" %}</a>{% endif %} | ||
64 | |||
60 | {% endif %} | 65 | {% endif %} |
61 | {{ block('pager') }} | 66 | {{ block('pager') }} |
62 | {% endblock %} | 67 | {% endblock %} |
diff --git a/themes/baggy/view.twig b/themes/baggy/view.twig index 0dff4e27..af97407d 100755 --- a/themes/baggy/view.twig +++ b/themes/baggy/view.twig | |||
@@ -16,7 +16,7 @@ | |||
16 | {% if constant('SHARE_SHAARLI') == 1 %}<li><a href="{{ constant('SHAARLI_URL') }}/index.php?post={{ entry.url|url_encode }}&title={{ entry.title|url_encode }}" target="_blank" class="tool shaarli" title="{% trans "shaarli" %}"><span>{% trans "shaarli" %}</span></a></li>{% endif %} | 16 | {% if constant('SHARE_SHAARLI') == 1 %}<li><a href="{{ constant('SHAARLI_URL') }}/index.php?post={{ entry.url|url_encode }}&title={{ entry.title|url_encode }}" target="_blank" class="tool shaarli" title="{% trans "shaarli" %}"><span>{% trans "shaarli" %}</span></a></li>{% endif %} |
17 | {% if constant('FLATTR') == 1 %}{% if flattr.status == constant('FLATTRABLE') %}<li><a href="http://flattr.com/submit/auto?url={{ entry.url }}" class="tool flattr icon icon-flattr" target="_blank" title="{% trans "flattr" %}"><span>{% trans "flattr" %}</span></a></li>{% elseif flattr.status == constant('FLATTRED') %}<li><a href="{{ flattr.flattrItemURL }}" class="tool flattr icon icon-flattr" target="_blank" title="{% trans "flattr" %}"><span>{% trans "flattr" %}</span> ({{ flattr.numflattrs }})</a></li>{% endif %}{% endif %} | 17 | {% if constant('FLATTR') == 1 %}{% if flattr.status == constant('FLATTRABLE') %}<li><a href="http://flattr.com/submit/auto?url={{ entry.url }}" class="tool flattr icon icon-flattr" target="_blank" title="{% trans "flattr" %}"><span>{% trans "flattr" %}</span></a></li>{% elseif flattr.status == constant('FLATTRED') %}<li><a href="{{ flattr.flattrItemURL }}" class="tool flattr icon icon-flattr" target="_blank" title="{% trans "flattr" %}"><span>{% trans "flattr" %}</span> ({{ flattr.numflattrs }})</a></li>{% endif %}{% endif %} |
18 | {% if constant('SHOW_PRINTLINK') == 1 %}<li><a title="{% trans "Print" %}" class="tool icon icon-print" href="javascript: window.print();"><span>{% trans "Print" %}</span></a></li>{% endif %} | 18 | {% if constant('SHOW_PRINTLINK') == 1 %}<li><a title="{% trans "Print" %}" class="tool icon icon-print" href="javascript: window.print();"><span>{% trans "Print" %}</span></a></li>{% endif %} |
19 | <li><a href="./?epub&id={{ entry.id|e }}" title="Generate epub file">EPUB</a></li> | 19 | <li><a href="./?epub&method=id&id={{ entry.id|e }}" title="Generate epub file">EPUB</a></li> |
20 | <li><a href="mailto:hello@wallabag.org?subject=Wrong%20display%20in%20wallabag&body={{ entry.url|url_encode }}" title="{% trans "Does this article appear wrong?" %}" class="tool bad-display icon icon-delete"><span>{% trans "Does this article appear wrong?" %}</span></a></li> | 20 | <li><a href="mailto:hello@wallabag.org?subject=Wrong%20display%20in%20wallabag&body={{ entry.url|url_encode }}" title="{% trans "Does this article appear wrong?" %}" class="tool bad-display icon icon-delete"><span>{% trans "Does this article appear wrong?" %}</span></a></li> |
21 | </ul> | 21 | </ul> |
22 | </div> | 22 | </div> |