diff options
author | Yaco <franco@reevo.org> | 2023-06-21 15:25:10 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2023-06-21 15:25:10 -0300 |
commit | 8dd9860a813421fa2e215b0291d888a636ff36f9 (patch) | |
tree | a93c13cd1669ae270c53914fee0cd39995e0ec16 | |
parent | a84342d6d07a1af2bd58b759f624fe88723185cc (diff) |
actualiza plugin de blog y agrega plugin de meta
19 files changed, 445 insertions, 21 deletions
diff --git a/platform/www/conf/local.php b/platform/www/conf/local.php index 1bce6c7..02d9b84 100644 --- a/platform/www/conf/local.php +++ b/platform/www/conf/local.php @@ -3,7 +3,7 @@ * Dokuwiki's Main Configuration File - Local Settings * Auto-generated by config plugin * Run for user: admin - * Date: Sat, 29 Oct 2022 19:28:07 -0300 + * Date: Wed, 14 Jun 2023 14:32:18 -0300 */ $conf['title'] = 'The Acervus Project'; diff --git a/platform/www/conf/local.php.bak.php b/platform/www/conf/local.php.bak.php index 643d9e4..5274331 100644 --- a/platform/www/conf/local.php.bak.php +++ b/platform/www/conf/local.php.bak.php @@ -3,7 +3,7 @@ * Dokuwiki's Main Configuration File - Local Settings * Auto-generated by config plugin * Run for user: admin - * Date: Tue, 13 Sep 2022 18:26:55 -0300 + * Date: Wed, 14 Jun 2023 12:05:14 -0300 */ $conf['title'] = 'The Acervus Project'; @@ -21,8 +21,13 @@ $conf['mailfrom'] = 'info@acerv.us'; $conf['updatecheck'] = 0; $conf['userewrite'] = '1'; $conf['plugin']['authldap']['attributes'] = array(); -$conf['plugin']['mdpage']['flavor'] = 'markdown-extra'; -$conf['plugin']['mdpage']['markdown_default'] = 1; +$conf['plugin']['blog']['sortorder'] = 'ascending'; +$conf['plugin']['include']['showfooter'] = 0; +$conf['plugin']['include']['showdate'] = 0; +$conf['plugin']['include']['showuser'] = 0; +$conf['plugin']['include']['showcomments'] = 0; +$conf['plugin']['include']['showlinkbacks'] = 0; +$conf['plugin']['include']['showtags'] = 0; $conf['plugin']['pageredirect']['show_note'] = 0; $conf['plugin']['translation']['translations'] = 'en es'; $conf['plugin']['translation']['display'] = 'langcode,name'; @@ -32,4 +37,6 @@ $conf['plugin']['translation']['copytrans'] = 1; $conf['tpl']['acervus']['numberedHeading'] = 1; $conf['tpl']['acervus']['tocPosition'] = 'dokuwiki'; $conf['tpl']['acervus']['footer'] = 'footer'; +$conf['plugin']['mdpage']['flavor'] = 'markdown-extra'; +$conf['plugin']['mdpage']['markdown_default'] = '1'; $conf['plugin']['fastwiki']['save'] = '1'; diff --git a/platform/www/conf/plugins.local.php b/platform/www/conf/plugins.local.php index 4f256a9..61e3661 100644 --- a/platform/www/conf/plugins.local.php +++ b/platform/www/conf/plugins.local.php @@ -6,3 +6,4 @@ * NOTE: Plugins will not be added to this file unless there is a need to override a default setting. Plugins are * enabled by default. */ +$plugins['blog.old'] = 0; diff --git a/platform/www/conf/plugins.local.php.bak b/platform/www/conf/plugins.local.php.bak index e510413..a3f474b 100644 --- a/platform/www/conf/plugins.local.php.bak +++ b/platform/www/conf/plugins.local.php.bak @@ -6,4 +6,4 @@ * NOTE: Plugins will not be added to this file unless there is a need to override a default setting. Plugins are * enabled by default. */ -$plugins['markdowku'] = 0; +$plugins['meta.old'] = 0; diff --git a/platform/www/lib/plugins/blog/action.php b/platform/www/lib/plugins/blog/action.php index 61ffd9e..2328399 100644 --- a/platform/www/lib/plugins/blog/action.php +++ b/platform/www/lib/plugins/blog/action.php @@ -88,8 +88,7 @@ class action_plugin_blog extends DokuWiki_Action_Plugin { global $ID, $INFO; $ns = cleanID($_REQUEST['ns']); - $title = str_replace(':', '', $_REQUEST['title']); - $ID = $this->_newEntryID($ns, $title); + $ID = $this->_newEntryID($ns, $_REQUEST['title']); $INFO = pageinfo(); // check if we are allowed to create this file @@ -210,6 +209,7 @@ class action_plugin_blog extends DokuWiki_Action_Plugin { ); } $pre = strftime($dateprefix); + $title = str_replace([':', ';', '#', '&', '%', '/', '\\', '?'], '', $title); return cleanID(($ns ? $ns.':' : '').$pre.$title); } diff --git a/platform/www/lib/plugins/blog/helper.php b/platform/www/lib/plugins/blog/helper.php index 9dd8b9a..f29dc7b 100644 --- a/platform/www/lib/plugins/blog/helper.php +++ b/platform/www/lib/plugins/blog/helper.php @@ -70,7 +70,7 @@ class helper_plugin_blog extends DokuWiki_Plugin { // skip drafts unless for users with create priviledge $meta = p_get_metadata($id, '', false); - $draft = ($meta['type'] == 'draft'); + $draft = isset($meta['type']) && ($meta['type'] == 'draft'); if ($draft && ($perm < AUTH_CREATE)) continue; // filter by author diff --git a/platform/www/lib/plugins/blog/lang/ca/lang.php b/platform/www/lib/plugins/blog/lang/ca/lang.php new file mode 100644 index 0000000..9acf319 --- /dev/null +++ b/platform/www/lib/plugins/blog/lang/ca/lang.php @@ -0,0 +1,30 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Marc Zulet <marczulet@gmail.com> + */ +$lang['blog'] = 'Bloc'; +$lang['older'] = 'Entrades anteriors'; +$lang['newer'] = 'Entrades noves'; +$lang['newentry'] = 'Nova entrada al bloc:'; +$lang['missing_includeplugin'] = 'El plugin Include ha d\'estar instal·lat perquè el bloc funcioni correctament.'; +$lang['missing_pagelistplugin'] = 'El plugin Pagelist ha d\'estar instal·lat perquè funcionin els llistats d\'arxiu.'; +$lang['missing_tagplugin'] = 'El plugin Tag ha d\'estar instal·lat perquè funcionin les etiquetes.'; +$lang['autoarchive'] = '%1$d Publicació(ns) de %2$s %3$s'; +$lang['month_01'] = 'Gener'; +$lang['month_02'] = 'Febrer'; +$lang['month_03'] = 'Març'; +$lang['month_04'] = 'Abril'; +$lang['month_05'] = 'Maig'; +$lang['month_06'] = 'Juny'; +$lang['month_07'] = 'Juliol'; +$lang['month_08'] = 'Agost'; +$lang['month_09'] = 'Setembre'; +$lang['month_10'] = 'Octubre'; +$lang['month_11'] = 'Novembre'; +$lang['month_12'] = 'Desembre'; +$lang['entries'] = 'entrades'; +$lang['entry'] = 'entrada'; +$lang['archive_title'] = 'Històric'; diff --git a/platform/www/lib/plugins/blog/lang/ca/settings.php b/platform/www/lib/plugins/blog/lang/ca/settings.php new file mode 100644 index 0000000..0f9a49d --- /dev/null +++ b/platform/www/lib/plugins/blog/lang/ca/settings.php @@ -0,0 +1,27 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Marc Zulet <marczulet@gmail.com> + */ +$lang['namespace'] = 'namespace predeterminat per al bloc'; +$lang['formposition'] = 'posició del formulari de nova entrada'; +$lang['formposition_o_top'] = 'amunt'; +$lang['formposition_o_bottom'] = 'avall'; +$lang['formposition_o_none'] = 'cap'; +$lang['newentrytitle'] = 'títol del formulari de nova entrada'; +$lang['dateprefix'] = 'afegir un prefix de data a les publicacions noves'; +$lang['sortkey'] = 'ordenar entrades per'; +$lang['sortkey_o_cdate'] = 'data de creació'; +$lang['sortkey_o_mdate'] = 'data de modificació'; +$lang['sortkey_o_pagename'] = 'nom de la pàgina'; +$lang['sortkey_o_id'] = 'ID de la pàgina'; +$lang['sortkey_o_title'] = 'títol'; +$lang['sortorder'] = 'ordre'; +$lang['sortorder_o_ascending'] = 'ascendent'; +$lang['sortorder_o_descending'] = 'descendent'; +$lang['excluded_pages'] = 'exclou determinades pàgines de la llista de blocs (es requereix una expressió regular)'; +$lang['showhistogram'] = 'Mostra l\'histograma en la representació de l\'arxiu'; +$lang['max_months'] = 'Màxim de mesos per mostrar a l\'histograma'; +$lang['histogram_height'] = 'Alçada de l\'histograma (en píxels)'; diff --git a/platform/www/lib/plugins/blog/lang/es/lang.php b/platform/www/lib/plugins/blog/lang/es/lang.php index 68ef65a..6eba94a 100644 --- a/platform/www/lib/plugins/blog/lang/es/lang.php +++ b/platform/www/lib/plugins/blog/lang/es/lang.php @@ -2,8 +2,9 @@ /** * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) - * - * @author Herman Fabián Sandoval Manrique <hfsandovalm@emzac.com> + * + * @author Marc Zulet <marczulet@gmail.com> + * @author Herman Fabián Sandoval Manrique <hfsandovalm@emzac.com> * @author r0sk <r0sk10@gmail.com> */ $lang['blog'] = 'Blog'; @@ -13,6 +14,7 @@ $lang['newentry'] = 'Nueva entrada en el blog:'; $lang['missing_includeplugin'] = 'El plugin Include debe estar instalado para que el blog funcione.'; $lang['missing_pagelistplugin'] = 'El plugin Pagelist debe estar instalado para que funcionen los listados de archivo.'; $lang['missing_tagplugin'] = 'El plugin Tag debe estar instalado para que funcionen los tags.'; +$lang['autoarchive'] = '%1$d Entrada(s) de %2$s %3$s'; $lang['month_01'] = 'Enero'; $lang['month_02'] = 'Febrero'; $lang['month_03'] = 'Marzo'; diff --git a/platform/www/lib/plugins/blog/lang/es/settings.php b/platform/www/lib/plugins/blog/lang/es/settings.php index d86f15a..05d62f0 100644 --- a/platform/www/lib/plugins/blog/lang/es/settings.php +++ b/platform/www/lib/plugins/blog/lang/es/settings.php @@ -2,8 +2,9 @@ /** * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) - * - * @author Herman Fabián Sandoval Manrique <hfsandovalm@emzac.com> + * + * @author Marc Zulet <marczulet@gmail.com> + * @author Herman Fabián Sandoval Manrique <hfsandovalm@emzac.com> * @author r0sk <r0sk10@gmail.com> */ $lang['namespace'] = 'namespace predeterminado para el blog'; @@ -12,6 +13,7 @@ $lang['formposition_o_top'] = 'arriba'; $lang['formposition_o_bottom'] = 'abajo'; $lang['formposition_o_none'] = 'ninguna'; $lang['newentrytitle'] = 'título del formulario de nueva entrada'; +$lang['dateprefix'] = 'prefijar la fecha a los ID de entradas nuevas'; $lang['sortkey'] = 'ordenar entradas por'; $lang['sortkey_o_cdate'] = 'fecha de creación'; $lang['sortkey_o_mdate'] = 'fecha de modificación'; @@ -21,3 +23,7 @@ $lang['sortkey_o_title'] = 'título'; $lang['sortorder'] = 'ordenamiento'; $lang['sortorder_o_ascending'] = 'ascendente'; $lang['sortorder_o_descending'] = 'descendente'; +$lang['excluded_pages'] = 'excluir ciertas páginas de la lista de blogs (se requiere una expresión regular)'; +$lang['showhistogram'] = 'Mostrar histograma en la página del archivo'; +$lang['max_months'] = 'Máximo de meses para mostrar en el histograma'; +$lang['histogram_height'] = 'Altura del histograma (en píxeles)'; diff --git a/platform/www/lib/plugins/blog/lang/pt-br/lang.php b/platform/www/lib/plugins/blog/lang/pt-br/lang.php index bd219ba..a163727 100644 --- a/platform/www/lib/plugins/blog/lang/pt-br/lang.php +++ b/platform/www/lib/plugins/blog/lang/pt-br/lang.php @@ -3,6 +3,7 @@ /** * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * + * @author Felipo Antonoff <contato@codemarket.com.br> * @author Flávio Roberto Santos <flavio.barata@gmail.com> * @author Samory Pereira Santos <samory.santos@gmail.com> */ @@ -13,6 +14,7 @@ $lang['newentry'] = 'Novo registro do blog:'; $lang['missing_includeplugin'] = 'O plugin Inlude deve estar instalado para que o blog funcione.'; $lang['missing_pagelistplugin'] = 'O plugin Pagelist deve estar instalado para que a listagem de arquivo funcione,'; $lang['missing_tagplugin'] = 'O plugin Tag deve estar instalado para usar refinamentos de etiquetagem.'; +$lang['autoarchive'] = '%1$d Postagem(s) para %2$s %3$s'; $lang['month_01'] = 'Janeiro'; $lang['month_02'] = 'Fevereiro'; $lang['month_03'] = 'Março'; diff --git a/platform/www/lib/plugins/blog/lang/vi/lang.php b/platform/www/lib/plugins/blog/lang/vi/lang.php new file mode 100644 index 0000000..a397709 --- /dev/null +++ b/platform/www/lib/plugins/blog/lang/vi/lang.php @@ -0,0 +1,30 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Minh <phandinhminh@protonmail.ch> + */ +$lang['blog'] = 'Blog'; +$lang['older'] = 'Những bài viết cũ hơn'; +$lang['newer'] = 'Những bài viết mới hơn'; +$lang['newentry'] = 'Mục blog mới:'; +$lang['missing_includeplugin'] = 'Tiện ích Plugin \'Bao gồm\' phải được cài đặt để blog hoạt động.'; +$lang['missing_pagelistplugin'] = 'Tiện ích Plugin \'Danh sách trang\' phải được cài đặt để danh sách lưu trữ hoạt động.'; +$lang['missing_tagplugin'] = 'Tiện ích Plugin \'Tag\' phải được cài đặt để sử dụng sàng lọc Tag.'; +$lang['autoarchive'] = '%1$d (các) bài đăng cho %2$s %3$s'; +$lang['month_01'] = 'Tháng Một'; +$lang['month_02'] = 'Tháng Hai'; +$lang['month_03'] = 'Tháng Ba'; +$lang['month_04'] = 'Tháng Tư'; +$lang['month_05'] = 'Tháng Năm'; +$lang['month_06'] = 'Tháng Sáu'; +$lang['month_07'] = 'Tháng Bảy'; +$lang['month_08'] = 'Tháng Tám'; +$lang['month_09'] = 'Tháng Chín'; +$lang['month_10'] = 'Tháng Mười'; +$lang['month_11'] = 'Tháng Mười Một'; +$lang['month_12'] = 'Tháng Mười Hai'; +$lang['entries'] = 'các mục bài viết'; +$lang['entry'] = 'nhập'; +$lang['archive_title'] = 'Lịch sử Blog'; diff --git a/platform/www/lib/plugins/blog/lang/vi/settings.php b/platform/www/lib/plugins/blog/lang/vi/settings.php new file mode 100644 index 0000000..a0b7d49 --- /dev/null +++ b/platform/www/lib/plugins/blog/lang/vi/settings.php @@ -0,0 +1,27 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Minh <phandinhminh@protonmail.ch> + */ +$lang['namespace'] = 'không gian tên namespace mặc định cho blog'; +$lang['formposition'] = 'vị trí của mẫu nhập mới'; +$lang['formposition_o_top'] = 'đầu'; +$lang['formposition_o_bottom'] = 'cuối'; +$lang['formposition_o_none'] = 'trống'; +$lang['newentrytitle'] = 'tiêu đề của mẫu nhập mới'; +$lang['dateprefix'] = 'ngày tiền tố cho ID mục nhập mới'; +$lang['sortkey'] = 'sắp xếp các bài đăng blog theo'; +$lang['sortkey_o_cdate'] = 'ngày tạo'; +$lang['sortkey_o_mdate'] = 'ngày chỉnh sửa'; +$lang['sortkey_o_pagename'] = 'tên trang'; +$lang['sortkey_o_id'] = 'ID trang'; +$lang['sortkey_o_title'] = 'tiêu đề'; +$lang['sortorder'] = 'sắp xếp vị trí'; +$lang['sortorder_o_ascending'] = 'tăng dần'; +$lang['sortorder_o_descending'] = 'giảm dần'; +$lang['excluded_pages'] = 'loại trừ một số trang nhất định khỏi danh sách blog (yêu cầu diễn đạt thông thường)'; +$lang['showhistogram'] = 'Hiển thị biểu đồ trên báo cáo kết xuất lưu trữ'; +$lang['max_months'] = 'Số tháng tối đa để hiển thị trong biểu đồ'; +$lang['histogram_height'] = 'Chiều cao của biểu đồ (tính bằng pixel)'; diff --git a/platform/www/lib/plugins/blog/manager.dat b/platform/www/lib/plugins/blog/manager.dat deleted file mode 100644 index 1eadc20..0000000 --- a/platform/www/lib/plugins/blog/manager.dat +++ /dev/null @@ -1,2 +0,0 @@ -downloadurl=https://github.com/dokufreaks/plugin-blog/archive/master.zip -installed=Sat, 19 Mar 2022 15:05:39 +0000 diff --git a/platform/www/lib/plugins/blog/plugin.info.txt b/platform/www/lib/plugins/blog/plugin.info.txt index 73bd83c..8f35668 100644 --- a/platform/www/lib/plugins/blog/plugin.info.txt +++ b/platform/www/lib/plugins/blog/plugin.info.txt @@ -2,7 +2,7 @@ base blog author Michael Hamann, Michael Klier, Gina Haeussge email michael@content-space.de -date 2022-02-20 +date 2023-01-12 name Blog desc Use DokuWiki as blogging tool. (previous authors: Esther Brunner) url https://www.dokuwiki.org/plugin:blog diff --git a/platform/www/lib/plugins/blog/syntax/blog.php b/platform/www/lib/plugins/blog/syntax/blog.php index 2ca56d8..fd934a0 100644 --- a/platform/www/lib/plugins/blog/syntax/blog.php +++ b/platform/www/lib/plugins/blog/syntax/blog.php @@ -22,11 +22,11 @@ class syntax_plugin_blog_blog extends DokuWiki_Syntax_Plugin { global $ID; $match = substr($match, 7, -2); // strip {{blog> from start and }} from end - list($match, $flags) = explode('&', $match, 2); + list($match, $flags) = array_pad(explode('&', $match, 2), 2, null); $flags = explode('&', $flags); array_unshift($flags, 'link'); // always make the first header of a blog entry a permalink (unless nolink is set) - list($match, $refine) = explode(' ', $match, 2); - list($ns, $num) = explode('?', $match, 2); + list($match, $refine) = array_pad(explode(' ', $match, 2), 2, null); + list($ns, $num) = array_pad(explode('?', $match, 2), 2, null); if (!is_numeric($num)) { if (is_numeric($ns)) { @@ -46,9 +46,11 @@ class syntax_plugin_blog_blog extends DokuWiki_Syntax_Plugin { } function render($mode, Doku_Renderer $renderer, $data) { + global $INPUT; + list($ns, $num, $flags, $refine) = $data; - $first = $_REQUEST['first']; + $first = $INPUT->int('first'); if (!is_numeric($first)) $first = 0; // get the blog entries for our namespace @@ -121,9 +123,9 @@ class syntax_plugin_blog_blog extends DokuWiki_Syntax_Plugin { // now include the blog entries foreach ($entries as $entry) { if ($mode == 'xhtml' || $mode == 'code') { - if(auth_quickaclcheck($entry['id']) >= AUTH_READ) { + if(isset($entry['id']) && (auth_quickaclcheck($entry['id']) >= AUTH_READ)) { // prevent blog include loops - if(!$this->included_pages[$entry['id']]) { + if(!array_key_exists($entry['id'], $this->included_pages) || !$this->included_pages[$entry['id']]) { $this->included_pages[$entry['id']] = true; $renderer->nest($include->_get_instructions($entry['id'], '', 'page', $clevel, $include_flags)); $this->included_pages[$entry['id']] = false; diff --git a/platform/www/lib/plugins/meta/_test/rendering.test.php b/platform/www/lib/plugins/meta/_test/rendering.test.php new file mode 100644 index 0000000..3c39613 --- /dev/null +++ b/platform/www/lib/plugins/meta/_test/rendering.test.php @@ -0,0 +1,80 @@ +<?php +// must be run within Dokuwiki +if (!defined('DOKU_INC')) die(); + +/** + * Test cases for the meta plugin + */ +class plugin_meta_rendering_test extends DokuWikiTest { + + public function setUp() : void { + $this->pluginsEnabled[] = 'meta'; + parent::setUp(); + } + + public function test_meta_description() { + $text = "My page content"; + saveWikiText('description_test', $text, 'Created'); + self::assertEquals($text, p_get_metadata('description_test', 'description abstract', METADATA_RENDER_UNLIMITED)); + + $text .= DOKU_LF . '~~META:description abstract=My abstract~~'; + + saveWikiText('description_test', $text, 'Added meta'); + + self::assertEquals('My abstract', p_get_metadata('description_test', 'description abstract', METADATA_RENDER_UNLIMITED)); + + $text .= DOKU_LF . '~~META:description foobar=bar~~'; + saveWikiText('description_test', $text, 'Updated meta'); + self::assertEquals('My abstract', p_get_metadata('description_test', 'description abstract', METADATA_RENDER_UNLIMITED)); + self::assertEquals('bar', p_get_metadata('description_test', 'description foobar', METADATA_RENDER_UNLIMITED)); + } + + public function test_meta_description_with_persistent_description() { + $text = "My page content"; + $id = 'description_test'; + saveWikiText($id, $text, 'Created'); + self::assertEquals($text, p_get_metadata($id, 'description abstract', METADATA_RENDER_UNLIMITED)); + + p_set_metadata($id, array('description' => array('abstract' => 'Persistent description')), false, true); + self::assertEquals('Persistent description', p_get_metadata($id, 'description abstract', METADATA_RENDER_UNLIMITED)); + + $text .= DOKU_LF . '~~META:description abstract=My abstract~~'; + + saveWikiText($id, $text, 'Added meta'); + + self::assertEquals('My abstract', p_get_metadata($id, 'description abstract', METADATA_RENDER_UNLIMITED)); + + $text .= DOKU_LF . '~~META:description foobar=bar~~'; + saveWikiText($id, $text, 'Updated meta'); + self::assertEquals('My abstract', p_get_metadata($id, 'description abstract', METADATA_RENDER_UNLIMITED)); + self::assertEquals('bar', p_get_metadata($id, 'description foobar', METADATA_RENDER_UNLIMITED)); + } + + public function test_relation_references_with_link() { + $text = "My page with a [[link_target|Link]]."; + $id = "source"; + + saveWikiText($id, $text, 'Created'); + + self::assertEquals(array('link_target' => false), p_get_metadata($id, 'relation references', METADATA_RENDER_UNLIMITED)); + + $text .= DOKU_LF. "~~META:relation references=foo~~"; + saveWikiText($id, $text, 'Updated'); + + self::assertEquals(array('foo' => false, 'link_target' => false), p_get_metadata($id, 'relation references', METADATA_RENDER_UNLIMITED)); + } + + public function test_relation_references_without_link() { + $text = "My page without a link."; + $id = "source"; + + saveWikiText($id, $text, 'Created'); + + self::assertEquals(null, p_get_metadata($id, 'relation references', METADATA_RENDER_UNLIMITED)); + + $text .= DOKU_LF . "~~META:relation references=foo~~"; + saveWikiText($id, $text, 'Updated'); + + self::assertEquals(array('foo' => false), p_get_metadata($id, 'relation references', METADATA_RENDER_UNLIMITED)); + } +} diff --git a/platform/www/lib/plugins/meta/plugin.info.txt b/platform/www/lib/plugins/meta/plugin.info.txt new file mode 100644 index 0000000..b1e63e4 --- /dev/null +++ b/platform/www/lib/plugins/meta/plugin.info.txt @@ -0,0 +1,7 @@ +base meta +author Michael Hamann +email michael@content-space.de +date 2021-10-16 +name Meta plugin +desc Set Metadata for the current page. (previous authors: Esther Brunner, Gina Häußge, Michael Klier) +url https://www.dokuwiki.org/plugin:meta diff --git a/platform/www/lib/plugins/meta/syntax.php b/platform/www/lib/plugins/meta/syntax.php new file mode 100644 index 0000000..733e5b5 --- /dev/null +++ b/platform/www/lib/plugins/meta/syntax.php @@ -0,0 +1,205 @@ +<?php +/** + * Meta Plugin: Sets metadata for the current page + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Esther Brunner <wikidesign@gmail.com> + */ +if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +/** + * All DokuWiki plugins to extend the parser/rendering mechanism + * need to inherit from this class + */ +class syntax_plugin_meta extends DokuWiki_Syntax_Plugin +{ + function getType() + { + return 'substition'; + } + + function getSort() + { + return 99; + } + + function connectTo($mode) + { + $this->Lexer->addSpecialPattern('~~META:.*?~~',$mode,'plugin_meta'); + } + + /** + * Handle the match + */ + public function handle($match, $state, $pos, Doku_Handler $handler) + { + // strip ~~META: from start and ~~ from end + $match = substr($match,7,-2); + + $data = array(); + $pairs = explode('&', $match); + foreach ($pairs as $pair) { + list($key, $value) = explode('=', $pair, 2); + list($key, $subkey) = explode(' ', $key, 2); + if (trim($subkey)) { + $data[trim($key)][trim($subkey)] = trim($value); + } else { + $data[trim($key)] = trim($value); + } + } + $data = array_change_key_case($data, CASE_LOWER); + + return $data; + } + + /** + * Create output + */ + public function render($mode, Doku_Renderer $renderer, $data) + { + if ($mode == 'xthml') { + // don't output anything + return true; + } elseif ($mode == 'metadata') { + /** @var Doku_Renderer_metadata $renderer */ + + // do some validation / conversion for date metadata + if (isset($data['date'])) { + if (is_array($data['date'])) { + foreach ($data['date'] as $key => $date) { + $date = $this->convertDate(trim($date)); + if (!$date) { + unset($data['date'][$key]); + } else { + $data['date'][$key] = $date; + } + } + } else { + unset($data['date']); + } + } + + // now merge the arrays + $protected = array('description', 'date', 'contributor'); + foreach ($data as $key => $value) { + + // be careful with sub-arrays of $meta['relation'] + if ($key == 'relation') { + foreach ($value as $subkey => $subvalue) { + if ($subkey == 'media') { + $renderer->meta[$key][$subkey][cleanID($subvalue)] = @file_exists(mediaFN($subvalue)); + } elseif ($subkey == 'firstimage') { + /* The metadata renderer overrides the first image value with its internal value at the end. + Therefore the only thing we can do is setting this internal value by calling _firstimage. + This fails if there has already been a first image saved. */ + $renderer->_firstimage($subvalue); + } else { + // for everything else assume that we have a page id + $renderer->meta[$key][$subkey][cleanID($subvalue)] = page_exists($subvalue); + } + } + } elseif (in_array($key, $protected)) { + // be careful with some sensitive arrays of $meta + if (is_array($renderer->meta) && is_array($value) && array_key_exists($key, $renderer->meta)) { + $renderer->meta[$key] = array_merge($renderer->meta[$key], (array)$value); + } else { + $renderer->meta[$key] = $value; + } + } else { + // no special treatment for the rest + $renderer->meta[$key] = $value; + } + } + } + } + + /** + * converts YYYY-MM-DD[ hh:mm:ss][ -> [YYYY-MM-DD ]hh:mm:ss] to PHP timestamps + */ + private function convertDate($date) + { + list($start, $end) = explode('->', $date, 2); + + if (!$end) { + // single date + list($date, $time) = explode(' ', trim($start), 2); + if (!preg_match('/\d{4}\-\d{2}\-\d{2}/', $date)) { + return false; + } + $time = $this->autocompleteTime($time); + return strtotime($date.' '.$time); + } else { + // duration + + // start + list($startdate, $starttime) = explode(' ', trim($start), 2); + $startdate = $this->autocompleteDate($startdate); + if (!$startdate) { + return false; + } + $starttime = $this->autocompleteTime($starttime); + + // end + list($enddate, $endtime) = explode(' ', trim($end), 2); + if (!trim($endtime)) { + // only time given + $end_date = $this->autocompleteDate($enddate, true); + if (!$end_date) { + $endtime = $this->autocompleteTime($enddate, true); + $enddate = $startdate; + } else { + // only date given + $enddate = $end_date; + $endtime = '23:59:59'; + } + } else { + $enddate = $this->autocompleteDate($enddate, true); + if (!$enddate) { + $enddate = $startdate; + } + $endtime = $this->autocompleteTime($endtime, true); + } + + $start = strtotime($startdate.' '.$starttime); + $end = strtotime($enddate.' '.$endtime); + if (!$start || !$end) { + return false; + } + return array('start' => $start, 'end' => $end); + } + } + + private function autocompleteDate($date, $end=false) + { + if (!preg_match('/^\d{4}\-\d{2}\-\d{2}$/', $date)) { + if (preg_match('/^\d{4}\-\d{2}$/', $date)) { + // we don't know which month + return ($end) ? $date.'-28' : $date.'-01'; + } elseif (preg_match('/^\d{4}$/', $date)) { + return ($end) ? $date.'-12-31' : $date.'-01-01'; + } else { + return false; + } + } else { + return $date; + } + } + + private function autocompleteTime($time, $end=false) + { + if (!preg_match('/^\d{2}:\d{2}:\d{2}$/', $time)) { + if (preg_match('/^\d{2}:\d{2}$/', $time)) { + return ($end) ? $time.':59' : $time.':00'; + } elseif (preg_match('/^\d{2}$/', $time)) { + return ($end) ? $time.':59:59': $time.':00:00'; + } else { + return ($end) ? '23:59:59' : '00:00:00'; + } + } else { + return $time; + } + } +} +// vim:ts=4:sw=4:et:enc=utf-8: |