diff --git a/README.md b/README.md
index c25611f5..9e59173d 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,8 @@ Wikisource export is a tool for exporting Wikisource page in many format like ep
Installation
============
-You have only to download the files and use it with PHP 5.3 or more and for ODT export with XLS.
+You have to download the files and use it with PHP 5.3 or more and for ODT export with XLS.
+You have to create a temp folder in the root of directories.
Composition
===========
diff --git a/book/Book.php b/book/Book.php
index eb0172a3..717320c7 100644
--- a/book/Book.php
+++ b/book/Book.php
@@ -48,4 +48,9 @@ class Book extends Page {
* @type array
*/
public $pictures = array();
+
+ /**
+ * list of contributors of the book array('PSEUDO' => array('flags' => array(), 'count' => integer))
+ */
+ public $credits = array();
}
diff --git a/book/BookProvider.php b/book/BookProvider.php
index f3a3418b..2b02638a 100644
--- a/book/BookProvider.php
+++ b/book/BookProvider.php
@@ -91,7 +91,7 @@ public function get($title, $isMetadata = false) {
$this->curl_async->waitForKey($keyCreditImage);
}
- $credit_html = $this->mergeCredit();
+ $book->credits = $this->mergeCredit();
}
$book->pictures = $pictures;
@@ -271,10 +271,7 @@ protected function mergeCredit() {
}
}
uasort($credit, "cmp_credit");
- $html = "
\n";
- foreach ($credit as $name => $value)
- $html .= "\t- " . $name . "
\n";
- $this->book->credits_html = $html;
+ return $credit;
}
}
@@ -390,11 +387,14 @@ protected function deprecatedNodes($oldName, $newName, $style) {
$nodes = $this->xPath->query('//html:' . $oldName); //The getElementsByTagName doesn't find all tags
foreach($nodes as $oldNode) {
$newNode = $this->xPath->document->createElement($newName);
- foreach($oldNode->childNodes as $child){
+ foreach($oldNode->childNodes as $child) {
$newNode->appendChild($child);
}
- foreach($oldNode->attributes as $attrName => $attrNode) {
- $newNode->setAttribute($attrName, $attrNode);
+ foreach($oldNode->attributes as $attribute) {
+ if($attribute->name == 'value')
+ $newNode->nodeValue = $attribute->value;
+ else
+ $newNode->setAttribute($attribute->name, $attribute->value);
}
$newNode->setAttribute('style', $style . ' ' . $newNode->getAttribute('style'));
$oldNode->parentNode->replaceChild($newNode, $oldNode);
diff --git a/book/Refresh.php b/book/Refresh.php
new file mode 100644
index 00000000..9463a962
--- /dev/null
+++ b/book/Refresh.php
@@ -0,0 +1,61 @@
+api = new Api($lang);
+ $this->lang = $this->api->lang;
+
+ global $wsexportConfig;
+ if(@mkdir($wsexportConfig['tempPath'].'/'.$this->lang)) {}
+
+ $this->getI18n();
+ $this->getEpubCssWikisource();
+ $this->getAboutXhtmlWikisource();
+ }
+
+ protected function getI18n() {
+ global $wsexportConfig;
+ $ini = parse_ini_file($wsexportConfig['basePath'] . '/book/i18n.ini');
+ try {
+ $response = $this->api->get('http://' . $this->lang . '.wikisource.org/w/index.php?title=MediaWiki:Wsexport_i18n.ini&action=raw&ctype=text/plain');
+ $temp = parse_ini_string($response);
+ if($ini != false)
+ $ini = array_merge($ini, $temp);
+ } catch(Exception $e) {
+ }
+ $this->setTempFileContent('i18n', serialize($ini));
+ }
+
+ protected function getEpubCssWikisource() {
+ try {
+ $content = $this->api->get('http://' . $this->lang . '.wikisource.org/w/index.php?title=MediaWiki:Epub.css&action=raw&ctype=text/css');
+ if($content != '')
+ $this->setTempFileContent('epub.css', $content);
+ } catch(Exception $e) {
+ }
+ }
+
+ protected function getAboutXhtmlWikisource() {
+ try {
+ $content = $this->api->get('http://' . $this->lang . '.wikisource.org/w/index.php?title=MediaWiki:Wsexport_about&action=render');
+ if($content != '')
+ $this->setTempFileContent('about.xhtml', $content);
+ } catch(Exception $e) {
+ }
+ }
+
+ protected function setTempFileContent($name, $content) {
+ global $wsexportConfig;
+ return file_put_contents($wsexportConfig['tempPath'].'/'.$this->lang.'/'.$name, $content);
+ }
+}
+
diff --git a/book/formats/Epub2Generator.php b/book/formats/Epub2Generator.php
index 8861bcda..fa42ccf5 100644
--- a/book/formats/Epub2Generator.php
+++ b/book/formats/Epub2Generator.php
@@ -42,7 +42,7 @@ public function getMimeType() {
* @todo images, cover, about...
*/
public function create(Book $book) {
- $css = $this->getCssWikisource($book->lang);
+ $css = $this->getTempFile($book->lang, 'epub.css');
$this->i18n = $this->getI18n($book->lang);
setLocale(LC_TIME, $book->lang . '_' . strtoupper($book->lang));
$wsUrl = wikisourceUrl($book->lang, $book->title);
@@ -58,6 +58,7 @@ public function create(Book $book) {
if($book->cover != '')
$zip->addContentFile('OPS/cover.xhtml', $this->getXhtmlCover($book));
$zip->addContentFile('OPS/title.xhtml', $this->getXhtmlTitle($book));
+ $zip->addContentFile('OPS/about.xhtml', $this->getXhtmlAbout($book));
$zip->addFile(dirname(__FILE__).'/images/Accueil_scribe.png', 'OPS/Accueil_scribe.png');
$zip->addContentFile('OPS/' . $book->title . '.xhtml', $book->content->saveXML());
if(!empty($book->chapters)) {
@@ -132,8 +133,8 @@ protected function getOpfContent(Book $book, $wsUrl) {
}
if($this->withCss)
$content.= ' ';
- //$content.= ' //TODO: about...
- $content.= '
+ $content.= '
+
';
if($book->cover != '')
$content.= '';
@@ -144,8 +145,8 @@ protected function getOpfContent(Book $book, $wsUrl) {
$content.= '';
}
}
- //$content.= '
- $content.= '
+ $content.= '
+
';
if($book->cover != '')
$content.= '';
@@ -156,8 +157,8 @@ protected function getOpfContent(Book $book, $wsUrl) {
if(isset($book->chapters[0])) {
$content.= '';
}
- //$content.= '
- $content.= '
+ $content.= '
+
';
return $content;
}
@@ -193,13 +194,13 @@ protected function getNcxToc(Book $book) {
$order++;
}
}
- /* $content.= '
+ $content.= '
' . $this->i18n['about'] . '
- */
- $content.= '
+
+
';
return $content;
}
@@ -250,6 +251,27 @@ protected function getXhtmlTitle(Book $book) {
return $content;
}
+ protected function getXhtmlAbout(Book $book) {
+ $list = '';
+ foreach($book->credits as $name => $value)
+ $list .= '- ' . $name . "
\n";
+ $about = $this->getTempFile($book->lang, 'about.xhtml');
+ if($about == '')
+ $about = $list;
+ else
+ $about = str_replace('{CONTRIBUTORS}', '', $about);
+ $content = '
+
+
+
+ ' . $this->i18n['about'] . '
+
+
+ ' . $about . '
+ ';
+ return $content;
+ }
+
protected function encodeTitles(Book $book) {
$this->linksList[] = $book->title . '.xhtml';
foreach($book->chapters as $chapter) {
@@ -355,26 +377,26 @@ protected function setCssLink(DOMDocument $dom) {
$node->appendChild($link);
}
- protected function getCssWikisource($lang) {
- try {
- $api = new Api($lang);
- return $api->get('http://' . $lang . '.wikisource.org/w/index.php?title=MediaWiki:Epub.css&action=raw&ctype=text/css');
- } catch(Exception $e) {
+ protected function getTempFile($lang, $name) {
+ global $wsexportConfig;
+ $path = $wsexportConfig['tempPath'].'/'.$lang.'/'.$name;
+ if(file_exists($path))
+ return file_get_contents($path);
+ else
return '';
- }
}
protected function getI18n($lang) {
- $ini = parse_ini_file(dirname(__FILE__) . '/i18n.ini');
- try {
- $api = new Api($lang);
- $response = $api->get('http://' . $lang . '.wikisource.org/w/index.php?title=MediaWiki:Wsexport_i18n.ini&action=raw&ctype=text/plain');
- $temp = parse_ini_string($response);
- if($ini != false)
- $ini = array_merge($ini, $temp);
- } catch(Exception $e) {
+ $content = $this->getTempFile($lang, 'i18n');
+ if($content == '') {
+ global $wsexportConfig;
+ include $wsexportConfig['basePath'].'/book/Refresh.php';
+ $refresh = new Refresh();
+ $refresh->refresh();
+ return unserialize($this->getTempFile($lang, 'i18n'));
+ } else {
+ return unserialize($content);
}
- return $ini;
}
}
diff --git a/book/formats/i18n.ini b/book/i18n.ini
similarity index 99%
rename from book/formats/i18n.ini
rename to book/i18n.ini
index b7ba4db4..85303d2b 100644
--- a/book/formats/i18n.ini
+++ b/book/i18n.ini
@@ -2,3 +2,4 @@ title_page = "Title page"
cover = "Cover"
exported_from_wikisource_the = "Exported from Wikisource the %d"
about = "About"
+
diff --git a/book/init.php b/book/init.php
index 62f08d3a..cb36c93a 100644
--- a/book/init.php
+++ b/book/init.php
@@ -4,6 +4,9 @@
* @copyright 2011 Thomas Pellissier Tanon
* @licence http://www.gnu.org/licenses/gpl.html GNU General Public Licence
*/
+global $wsexportConfig;
+$basePath = $wsexportConfig['basePath'];
+
include($basePath . '/utils/utils.php');
include($basePath . '/utils/HttpException.php');
include($basePath . '/utils/Api.php');
diff --git a/http/book.php b/http/book.php
index dc21ddc7..b455d5f5 100644
--- a/http/book.php
+++ b/http/book.php
@@ -1,8 +1,18 @@
'..',
+ 'tempPath' => '../temp'
+);
+
include('../book/init.php');
try {
+ if(isset($_GET['refresh'])) {
+ include $wsexportConfig['basePath'].'/book/Refresh.php';
+ $refresh = new Refresh();
+ $refresh->refresh();
+ exit();
+ }
if(!isset($_GET['page']) || $_GET['page'] == '')
include 'help/book.php';
$title = htmlspecialchars(urldecode($_GET['page']));