Permalink
Browse files

Bug fix : the pagenum id wasn't cleaned (exemple: 2 -> _2)

The about page is now cleaned.
  • Loading branch information...
1 parent 8a9a270 commit cc39477c86c5e5bd326d5dc768f8cdb128e34060 @Tpt Tpt committed Mar 31, 2012
Showing with 42 additions and 34 deletions.
  1. +3 −3 book/BookProvider.php
  2. +9 −2 book/Refresh.php
  3. +7 −29 book/formats/Epub2Generator.php
  4. +23 −0 utils/utils.php
View
@@ -394,7 +394,6 @@ public function getContent() {
$this->deprecatedNodes('font', 'span', '');
$this->cleanIds();
-
return $this->xPath->document;
}
@@ -404,11 +403,12 @@ protected function cleanIds() {
$node->setAttribute('id', str_replace(':', '_', $node->getAttribute('id')));
}
- $list = $this->xPath->query('//span[@class="pagenum" or @class="mw-headline"]');
+ $list = $this->xPath->query('//html:span[@class="pagenum" or @class="mw-headline"]');
foreach($list as $node) {
$id = $node->getAttribute('id');
- if (is_numeric($id))
+ if (is_numeric($id)) {
$node->setAttribute('id', '_' . $id);
+ }
}
}
View
@@ -55,8 +55,15 @@ protected function getAboutXhtmlWikisource() {
$content = '';
}
}
- if($content != '')
- $this->setTempFileContent('about.xhtml', str_replace('href="//', 'href="http://', $content));
+ if($content != '') {
+ $i18n = getI18n($this->lang);
+ $content = getXhtmlFromContent($this->lang, $content, $i18n['about']);
+ $document = new DOMDocument('1.0', 'UTF-8');
+ $document->loadXML($content);
+ $parser = new PageParser($document);
+ $content = $parser->getContent();
+ $this->setTempFileContent('about.xhtml', str_replace('href="//', 'href="http://', $document->saveXML()));
+ }
}
protected function setTempFileContent($name, $content) {
@@ -41,10 +41,10 @@ public function getMimeType() {
* @todo images, cover, about...
*/
public function create(Book $book) {
- $css = $this->getTempFile($book->lang, 'epub.css');
+ $css = getTempFile($book->lang, 'epub.css');
if($css != '')
$this->withCss = true;
- $this->i18n = $this->getI18n($book->lang);
+ $this->i18n = getI18n($book->lang);
setLocale(LC_TIME, $book->lang . '_' . strtoupper($book->lang));
$wsUrl = wikisourceUrl($book->lang, $book->title);
$cleaner = new BookCleanerEpub();
@@ -237,36 +237,14 @@ protected function getXhtmlAbout(Book $book) {
else
$list .= '<li>' . $name . "</li>\n";
}
- $about = $this->getTempFile($book->lang, 'about.xhtml');
+ $about = getTempFile($book->lang, 'about.xhtml');
if($about == '') {
- $about = $list;
+ $about = getXhtmlFromContent($book->lang, $list, $this->i18n['about']);
} else {
$about = str_replace('{CONTRIBUTORS}', '<ul>'.$list.'</ul>', $about);
$about = str_replace('{BOT-CONTRIBUTORS}', '<ul>'.$list.'</ul>', $about);
}
- return getXhtmlFromContent($book->lang, $about, $this->i18n['about']);
- }
-
- 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) {
- $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 $about;
}
}
@@ -409,15 +387,15 @@ protected function getEmptyDom() {
protected function encode($string) {
$search = array('@[éèêëÊË]@i','@[àâäÂÄ]@i','@[îïÎÏ]@i','@[ûùüÛÜ]@i','@[ôöÔÖ]@i','@[ç]@i','@[ ]@i','@[^a-zA-Z0-9_\.]@');
- $replace = array('e','a','i','u','o','c','_','_');
+ $replace = array('e','a','i','u','o','c','_','_');
return preg_replace($search, $replace, $string);
}
/**
* modified the XHTML
*/
protected function cleanHtml(DOMXPath $xPath) {
- $this->setPictureLinks($xPath);
+ $this->setPictureLinks($xPath);
$dom = $xPath->document;
$this->setLinks($dom);
if($this->withCss)
View
@@ -65,3 +65,26 @@ function getXhtmlFromContent($lang, $content, $title = ' ') {
}
return '<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $lang . '"><head><meta content="application/xhtml+xml;charset=UTF-8" http-equiv="content-type"/><title>' . $title . '</title></head><body>' . $content . '</body></html>';
}
+
+
+function getTempFile($lang, $name) {
+ global $wsexportConfig;
+ $path = $wsexportConfig['tempPath'].'/'.$lang.'/'.$name;
+ if(file_exists($path))
+ return file_get_contents($path);
+ else
+ return '';
+}
+
+function getI18n($lang) {
+ $content = getTempFile($lang, 'i18n');
+ if($content == '') {
+ global $wsexportConfig;
+ include $wsexportConfig['basePath'].'/book/Refresh.php';
+ $refresh = new Refresh();
+ $refresh->refresh();
+ return unserialize(getTempFile($lang, 'i18n'));
+ } else {
+ return unserialize($content);
+ }
+}

0 comments on commit cc39477

Please sign in to comment.