1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-11-27 11:22:17 -05:00

Big changes for epub export. Now possible to do it from a tag, a category and a search. Also, improved ebook rendering.

This commit is contained in:
tcit 2014-04-25 16:20:25 +02:00
parent 72a857158c
commit 7ec445b06e
4 changed files with 45 additions and 20 deletions

View File

@ -1137,35 +1137,51 @@ class Poche
*/ */
public function createEpub() { public function createEpub() {
if (isset($_GET['epub']) && isset($_GET['id'])) { switch ($_GET['method']) {
if ($_GET['id'] == "all") { // we put all entries in the file case 'id':
$entries = $this->store->retrieveAll($this->user->getId());
}
else { // we put only one entry in the file
$entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT); $entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT);
$entry = $this->store->retrieveOneById($entryID, $this->user->getId()); $entry = $this->store->retrieveOneById($entryID, $this->user->getId());
$entries = array($entry); $entries = array($entry);
break;
case 'all':
$entries = $this->store->retrieveAll($this->user->getId());
break;
case 'tag':
$tag = filter_var($_GET['tag'],FILTER_SANITIZE_STRING);
$tags_id = $this->store->retrieveAllTags($this->user->getId(),$tag);
$tag_id = $tags_id[0]["id"]; // we take the first result, which is supposed to match perfectly. There must be a workaround.
$entries = $this->store->retrieveEntriesByTag($tag_id,$this->user->getId());
break;
case 'category':
$category = filter_var($_GET['category'],FILTER_SANITIZE_STRING);
$entries = $this->store->getEntriesByView($category,$this->user->getId());
break;
case 'search':
$search = filter_var($_GET['search'],FILTER_SANITIZE_STRING);
$entries = $this->store->search($search,$this->user->getId());
break;
case 'default':
die(_('Uh, there is a problem while generating epub.'));
} }
}
$content_start = $content_start =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n" . "<!DOCTYPE html>\n"
. " \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" . "<html>\n"
. "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" . "<head>\n"
. "<head>"
. "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"
. "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\" />\n" . "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\" />\n"
. "<title>Test Book</title>\n" . "<title>wallabag article</title>\n"
. "</head>\n" . "</head>\n"
. "<body>\n"; . "<body>\n";
$bookEnd = "</body>\n</html>\n"; $bookEnd = "</body>\n</html>\n";
$log = new Logger($entryID, TRUE); $log = new Logger("wallabag", TRUE);
$fileDir = CACHE; $fileDir = CACHE;
$book = new EPub(); $book = new EPub(EPub::BOOK_VERSION_EPUB3);
$log->logLine("new EPub()"); $log->logLine("new EPub()");
$log->logLine("EPub class version: " . EPub::VERSION); $log->logLine("EPub class version: " . EPub::VERSION);
$log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION); $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION);
@ -1186,6 +1202,10 @@ class Poche
$book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP"); $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP");
$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"; $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";
$log->logLine("Add Cover Image");
$book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png");
$cover = $content_start . "<h1>My articles on wallabag</h1>\n<h2>As seen on : http://$_SERVER[HTTP_HOST]</h2>\n" . $bookEnd; $cover = $content_start . "<h1>My articles on wallabag</h1>\n<h2>As seen on : http://$_SERVER[HTTP_HOST]</h2>\n" . $bookEnd;
$book->addChapter("Notices", "Cover.html", $cover); $book->addChapter("Notices", "Cover.html", $cover);
$book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE); $book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE);
@ -1193,7 +1213,7 @@ class Poche
foreach ($entries as $entry) { foreach ($entries as $entry) {
$tags = $this->store->retrieveTagsByEntry($entry['id']); $tags = $this->store->retrieveTagsByEntry($entry['id']);
foreach ($tags as $tag) { foreach ($tags as $tag) {
$book->setSubject($tag); $book->setSubject($tag['value']);
} }
$log->logLine("Set up parameters"); $log->logLine("Set up parameters");
@ -1201,11 +1221,11 @@ class Poche
$chapter = $content_start . $entry['content'] . $bookEnd; $chapter = $content_start . $entry['content'] . $bookEnd;
$book->addChapter("Chapter " . $entry['id'] . ": " . $entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD);
} }
if (true) { if (DEBUG_POCHE) {
$epuplog = $book->getLog(); $epuplog = $book->getLog();
$book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // generation log $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // generation log
// Only used in case we need to debug EPub.php. // Only used in case we need to debug EPub.php.

View File

@ -126,7 +126,7 @@
<p><a href="?export" target="_blank">{% trans "Click here" %}</a> {% trans "to export your wallabag data." %}</p> <p><a href="?export" target="_blank">{% trans "Click here" %}</a> {% trans "to export your wallabag data." %}</p>
<h2>Fancy a ebook ?</h2> <h2>Fancy a ebook ?</h2>
Click on <a href="./?epub&amp;id=all" title="Generate ePub">this link</a> to get all your articles in one ebook (ePub). Click on <a href="./?epub&amp;method=all" title="Generate ePub">this link</a> to get all your articles in one ebook (ePub).
<h2>{% trans "Cache" %}</h2> <h2>{% trans "Cache" %}</h2>
<p><a href="?empty-cache">{% trans "Click here" %}</a> {% trans "to delete cache." %}</p> <p><a href="?empty-cache">{% trans "Click here" %}</a> {% trans "to delete cache." %}</p>

View File

@ -57,6 +57,11 @@
{% endfor %} {% endfor %}
</div> </div>
{% 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 %} {% 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 %}
{% if tag %}<a title="{% trans "Download the articles from this tag in an epub" %}" href="./?epub&amp;method=tag&amp;tag={{ tag.value }}">{% trans "Download the articles from this tag in an epub" %}</a>
{% elseif search_term is defined %}<a title="{% trans "Download the articles from this search in an epub" %}" href="./?epub&amp;method=search&amp;search={{ search_term }}">{% trans "Download the articles from this search in an epub" %}</a>
{% else %}<a title="{% trans "Download the articles from this category in an epub" %}" href="./?epub&amp;method=category&amp;category={{ view }}">{% trans "Download the articles from this category in an epub" %}</a>{% endif %}
{% endif %} {% endif %}
{{ block('pager') }} {{ block('pager') }}
{% endblock %} {% endblock %}

View File

@ -16,7 +16,7 @@
{% if constant('SHARE_SHAARLI') == 1 %}<li><a href="{{ constant('SHAARLI_URL') }}/index.php?post={{ entry.url|url_encode }}&amp;title={{ entry.title|url_encode }}" target="_blank" class="tool shaarli" title="{% trans "shaarli" %}"><span>{% trans "shaarli" %}</span></a></li>{% endif %} {% if constant('SHARE_SHAARLI') == 1 %}<li><a href="{{ constant('SHAARLI_URL') }}/index.php?post={{ entry.url|url_encode }}&amp;title={{ entry.title|url_encode }}" target="_blank" class="tool shaarli" title="{% trans "shaarli" %}"><span>{% trans "shaarli" %}</span></a></li>{% endif %}
{% 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 %} {% 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 %}
{% 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 %} {% 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 %}
<li><a href="./?epub&amp;id={{ entry.id|e }}" title="Generate epub file">EPUB</a></li> <li><a href="./?epub&amp;method=id&amp;id={{ entry.id|e }}" title="Generate epub file">EPUB</a></li>
<li><a href="mailto:hello@wallabag.org?subject=Wrong%20display%20in%20wallabag&amp;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> <li><a href="mailto:hello@wallabag.org?subject=Wrong%20display%20in%20wallabag&amp;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>
</ul> </ul>
</div> </div>