From 7db79a93a3c7bb8873cbfb73cc0ce797925187bb Mon Sep 17 00:00:00 2001 From: Myron Turner Date: Tue, 31 Jan 2023 15:48:50 -0600 Subject: [PATCH 1/7] Possible fix for issue #37 --- action.php | 2 +- plugin.info.txt | 2 +- version | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/action.php b/action.php index e0bc97d..6bc6ed3 100644 --- a/action.php +++ b/action.php @@ -101,7 +101,7 @@ function prevent_cache(&$event) { if(!$this->helper) { $this->helper = $this->loadHelper('epub', true); } - if (!$this->helper->is_inCache($INFO['id'])) return; //cache set in syntax.php + if (isset($INFO['id']) && !$this->helper->is_inCache($INFO['id'])) return; //cache set in syntax.php $event->preventDefault(); } diff --git a/plugin.info.txt b/plugin.info.txt index 681541a..e5970ac 100644 --- a/plugin.info.txt +++ b/plugin.info.txt @@ -1,7 +1,7 @@ base epub author Myron Turner email turnermm02@shaw.ca -date 2022-10-05 +date 2023-01-31 name epub desc Ebook creator url http://www.dokuwiki.org/plugin:epub diff --git a/version b/version index 60efa24..f9f0423 100644 --- a/version +++ b/version @@ -1,2 +1,2 @@ -master_22-Oct_05-09_43 +issue-#37-fix_23-Jan_31-15_36 From efb37efe7c465870ff2e9f6f240c3d8b6b62fed0 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 6 Sep 2024 12:54:02 +0000 Subject: [PATCH 2/7] Change imports from Dokuwiki to new syntax Before the deprecation log had this message: require_once() is deprecated --- action.php | 12 +++++++----- scripts/css2.php | 13 +++++-------- syntax.php | 9 ++++++--- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/action.php b/action.php index 6bc6ed3..44e750b 100644 --- a/action.php +++ b/action.php @@ -1,12 +1,14 @@ */ -if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../../').'/'); -if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching) -if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT',1); // we gzip ourself here -if(!defined('EPUB_DIR')) define('EPUB_DIR',realpath(dirname(__FILE__).'/../').'/'); -if(!defined('DOKU_TPL')) define('DOKU_TPL', DOKU_BASE.'lib/tpl/'.$conf['template'].'/'); -if(!defined('DOKU_TPLINC')) define('DOKU_TPLINC', DOKU_INC.'lib/tpl/'.$conf['template'].'/'); -require_once(DOKU_INC.'inc/init.php'); - +use dokuwiki\Cache\Cache; +use dokuwiki\Extension\ActionPlugin; +use dokuwiki\Extension\Event; +use dokuwiki\Extension\EventHandler; +use dokuwiki\StyleUtils; // ---------------------- functions ------------------------------ diff --git a/syntax.php b/syntax.php index fcef3b3..3fd80eb 100644 --- a/syntax.php +++ b/syntax.php @@ -1,8 +1,11 @@ Date: Fri, 6 Sep 2024 12:56:44 +0000 Subject: [PATCH 3/7] Add "url" key to arrays created on the fly Before the missing "url" key led to the following error messages: 2024-09-06 11:20:05 /var/www/html/dokuwiki/lib/plugins/epub/renderer.php(337) E_WARNING: Undefined array key "url" 0 /var/www/html/dokuwiki/lib/plugins/epub/renderer.php(337): dokuwiki\ErrorHandler::errorHandler(2, 'Undefined array...', '/var/www/html/d...', 337) 1 /var/www/html/dokuwiki/lib/plugins/epub/renderer.php(271): renderer_plugin_epub->local_name(Array, '') 2 /var/www/html/dokuwiki/lib/plugins/epub/renderer.php(145): renderer_plugin_epub->_formatLink(Array) 3 /var/www/html/dokuwiki/inc/parser/xhtml.php(1891): renderer_plugin_epub->_media('Video/felix_rec...', 'felix_recording...', 'center', NULL, NULL, 'cache', true) 4 /var/www/html/dokuwiki/inc/parser/xhtml.php(1203): Doku_Renderer_xhtml->_getMediaLinkConf('felix:recording...', '', 'center', NULL, NULL, 'cache', true) 5 /var/www/html/dokuwiki/lib/plugins/epub/scripts/ebook.php(56): Doku_Renderer_xhtml->internalmedia('felix:recording...', '', 'center', NULL, NULL, 'cache', 'details') 6 /var/www/html/dokuwiki/lib/plugins/epub/scripts/ebook.php(187): epub_creator->create(':felix:exploiti...') 7 {main} 2024-09-06 11:20:05 /var/www/html/dokuwiki/lib/plugins/epub/renderer.php(340) E_WARNING: Undefined array key "url" 0 /var/www/html/dokuwiki/lib/plugins/epub/renderer.php(340): dokuwiki\ErrorHandler::errorHandler(2, 'Undefined array...', '/var/www/html/d...', 340) 1 /var/www/html/dokuwiki/lib/plugins/epub/renderer.php(271): renderer_plugin_epub->local_name(Array, '') 2 /var/www/html/dokuwiki/lib/plugins/epub/renderer.php(145): renderer_plugin_epub->_formatLink(Array) 3 /var/www/html/dokuwiki/inc/parser/xhtml.php(1891): renderer_plugin_epub->_media('Video/felix_rec...', 'felix_recording...', 'center', NULL, NULL, 'cache', true) 4 /var/www/html/dokuwiki/inc/parser/xhtml.php(1203): Doku_Renderer_xhtml->_getMediaLinkConf('felix:recording...', '', 'center', NULL, NULL, 'cache', true) 5 /var/www/html/dokuwiki/lib/plugins/epub/scripts/ebook.php(56): Doku_Renderer_xhtml->internalmedia('felix:recording...', '', 'center', NULL, NULL, 'cache', 'details') 6 /var/www/html/dokuwiki/lib/plugins/epub/scripts/ebook.php(187): epub_creator->create(':felix:exploiti...') 7 {main} 2024-09-06 11:20:05 /var/www/html/dokuwiki/lib/plugins/epub/renderer.php(312) E_WARNING: Undefined array key "url" 0 /var/www/html/dokuwiki/lib/plugins/epub/renderer.php(312): dokuwiki\ErrorHandler::errorHandler(2, 'Undefined array...', '/var/www/html/d...', 312) 1 /var/www/html/dokuwiki/lib/plugins/epub/renderer.php(285): renderer_plugin_epub->set_footnote(Array, 'https://...') 2 /var/www/html/dokuwiki/lib/plugins/epub/renderer.php(145): renderer_plugin_epub->_formatLink(Array) 3 /var/www/html/dokuwiki/inc/parser/xhtml.php(1891): renderer_plugin_epub->_media('Video/felix_rec...', 'felix_recording...', 'center', NULL, NULL, 'cache', true) 4 /var/www/html/dokuwiki/inc/parser/xhtml.php(1203): Doku_Renderer_xhtml->_getMediaLinkConf('felix:recording...', '', 'center', NULL, NULL, 'cache', true) 5 /var/www/html/dokuwiki/lib/plugins/epub/scripts/ebook.php(56): Doku_Renderer_xhtml->internalmedia('felix:recording...', '', 'center', NULL, NULL, 'cache', 'details') 6 /var/www/html/dokuwiki/lib/plugins/epub/scripts/ebook.php(187): epub_creator->create(':felix:exploiti...') 7 {main} --- renderer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/renderer.php b/renderer.php index 15bdff2..b0e4e83 100644 --- a/renderer.php +++ b/renderer.php @@ -128,18 +128,18 @@ function _media ($src, $title=NULL, $align=NULL, $width=NULL, $mpfile = str_replace('Audio/',"",$src); $display_name = $title; $title = $mpfile; - $out .= $this->_formatLink( array('class'=>'media mediafile mf_mp3','title'=>$title,'name'=>$title, 'display'=>$display_name) ) ."\n

"; + $out .= $this->_formatLink( array('class'=>'media mediafile mf_mp3','title'=>$title,'name'=>$title, 'display'=>$display_name, 'url'=>'') ) ."\n

"; } } else if(strpos($mtype[1],'video') !== false) { if($this->video_link) $out .= '

' ;//$out .= '
' ; $out .= $this->set_video($src,$mtype,$title) ; if($this->video_link) { - list($title,$rest) = explode('(', $title); + list($title,$rest) = array_pad(explode('(', $title), 2, ''); $mpfile = str_replace('Video/',"",$src); $display_name = $title; $title = $mpfile; - $out .= $this->_formatLink( array('class'=>'media mediafile mf_mp4','title'=>$title,'name'=>$title, 'display'=>$display_name) ) ."\n

"; + $out .= $this->_formatLink( array('class'=>'media mediafile mf_mp4','title'=>$title,'name'=>$title, 'display'=>$display_name, 'url'=>'') ) ."\n

"; } } else { From 9fb378fd18769a75b3022ce27156864be092830f Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 6 Sep 2024 13:09:06 +0000 Subject: [PATCH 4/7] Fix Undefined array key list($vara,$varb) receives an array that it assignes to the variables. If it's too few it's a problem. Now array_pad expands the array if it hasn't enough members with empty strings to the correct size: list($file,$rest) = array_pad(explode('|',$file), 2, ''); --- renderer.php | 4 ++-- syntax.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/renderer.php b/renderer.php index b0e4e83..5c756ae 100644 --- a/renderer.php +++ b/renderer.php @@ -180,7 +180,7 @@ function is_image($link,&$type) { $mime_type = mimetype($link['title']); if(!$mime_type[1] ) { - list($url,$rest) = explode('?', $link['url']); + list($url,$rest) = array_pad(explode('?', $link['url']), 2,''); $mime_type = mimetype($url); if(!$mime_type[1]) { $mime_type = mimetype($rest); @@ -333,7 +333,7 @@ function smiley($smiley) { function local_name($link,&$orig="", &$frag ="") { $base_name= basename($link['url']); $title = $link['title']? ltrim($link['title'],':'): ""; - list($starturl,$frag) = explode('#',$link['url']); + list($starturl,$frag) = array_pad(explode('#',$link['url']), 2, ''); if ($title) { $name = $title; } diff --git a/syntax.php b/syntax.php index 3fd80eb..2892b9f 100644 --- a/syntax.php +++ b/syntax.php @@ -86,7 +86,7 @@ function render($mode, Doku_Renderer $renderer, $data) { for($i=0;$i Date: Fri, 6 Sep 2024 13:11:54 +0000 Subject: [PATCH 5/7] Fix a strange Error that has to do with user styles --- scripts/css2.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/css2.php b/scripts/css2.php index a936f49..837018b 100644 --- a/scripts/css2.php +++ b/scripts/css2.php @@ -66,9 +66,9 @@ function epub_css_out($path){ } // load user styles - if(isset($config_cascade['userstyle'][$mediatype])){ - $files[$config_cascade['userstyle'][$mediatype]] = DOKU_BASE; - } + #if(isset($config_cascade['userstyle'][$mediatype])){ + # $files[$config_cascade['userstyle'][$mediatype]] = DOKU_BASE; + #} // load files $css = ""; From 4787ee84a3d90940d29cf670a1d913fdb25412de Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 6 Sep 2024 13:14:49 +0000 Subject: [PATCH 6/7] Fix Error Illegal offset type Before if haystack was an empty string the type error was produced when looking for '*'. Now with the size check it handles correctly, that in empty string is no '*' --- scripts/epub_utils.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/epub_utils.php b/scripts/epub_utils.php index da99f7b..e838a93 100644 --- a/scripts/epub_utils.php +++ b/scripts/epub_utils.php @@ -616,7 +616,10 @@ function epub_save_namespace($ns="") { function epub_checkfor_ns($name, &$pages, &$titles) { $name = rtrim($name); - $n = strrpos($name,'*',-1); + $n = false; + if (strlen($n) > 0){ + $n = strrpos($name,'*',-1); + } if(!$n) return; array_shift($pages); // remove namespace id: namespace:* From cb98edcd6f769363a8eb23390b9b72065277c81e Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 6 Sep 2024 13:17:21 +0000 Subject: [PATCH 7/7] Fix Warning when cover_png is undefined Before this error was produced: 2024-09-06 10:28:31 /var/www/html/dokuwiki/lib/plugins/epub/scripts/epub_utils.php(53) E_WARNING: Undefined variable $cover_png #0 /var/www/html/dokuwiki/lib/plugins/epub/scripts/epub_utils.php(53): dokuwiki\ErrorHandler::errorHandler(2, 'Undefined varia...', '/var/www/html/d...', 53) #1 /var/www/html/dokuwiki/lib/plugins/epub/scripts/ebook.php(169): epub_opf_header(true) #2 {main} Now cover_png is simply declared empty. --- scripts/epub_utils.php | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/epub_utils.php b/scripts/epub_utils.php index e838a93..c76a973 100644 --- a/scripts/epub_utils.php +++ b/scripts/epub_utils.php @@ -31,6 +31,7 @@ function epub_opf_header($user_title) { } } + $cover_png = ""; if(!$user_title) { $cover_png=''. "\n"; }