From 32a102a289099008097beea6cd8571014ce489d5 Mon Sep 17 00:00:00 2001 From: Joachim Happel Date: Fri, 24 May 2024 00:11:49 +0200 Subject: [PATCH] add tullu lisense --- post-to-liascript-shortcode-button.php | 60 +++++++++++++++++++++----- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/post-to-liascript-shortcode-button.php b/post-to-liascript-shortcode-button.php index 687462b..4b60095 100644 --- a/post-to-liascript-shortcode-button.php +++ b/post-to-liascript-shortcode-button.php @@ -33,15 +33,53 @@ class PostToLiaScriptShortcodeButton { $title = get_the_title($post->ID); $content = apply_filters('the_content', $post->post_content); + + // Get the license terms + $terms = wp_get_post_terms($post->ID, 'license'); + if (!empty($terms) && !is_wp_error($terms)) { + $term = $terms[0]; + $license = $term->name; + $license_url = term_description($term->term_id); + $license_icon_url = "https://mirrors.creativecommons.org/presskit/buttons/88x31/png/" . str_replace("cc-", "", $term->slug) . ".png"; + } else { + // Default values if no license term is found + $license = "No License"; + $license_url = "#"; + $license_icon_url = "#"; + } + // Get author and site information + $post_author_id = $post->post_author; + $post_author_name = get_the_author_meta('display_name', $post_author_id); + $post_author_url = get_author_posts_url($post_author_id); + $home_url = home_url(); + $blogname = get_bloginfo('name'); + $post_url = get_permalink($post->ID); + + // License HTML snippet + $license_html = " +
+ + {$license} + +
+ Weiternutzung als OER ausdrücklich erlaubt: Dieses OER ist - sofern dies bei Teilinhalten nicht anders angegeben - lizenziert unter + {$license}. + Nennung gemäß TULLU-Regel bitte wie folgt:
+ + {$title} ({$blogname}) + von , + Lizenz: {$license} + . +
"; + + $license_markdown = "\n\n---\n\n### OER-Lizenz\n\n". + "Dieses Werk ist - sofern Inhalte nicht anders gekennzeichnet - lizenziert unter". + "\n[$title]($post_url)\n[$license]($license_url) [$post_author_name]($post_author_url)/[$blogname]($home_url)"; // Convert content to Markdown - $markdownContent = $this->convert_to_markdown($content); + $markdownContent = $this->convert_to_markdown($content).$license_markdown; - // Append TULLU license - $license = "\n\n---\n\n" . "This work is licensed under the TULLU rule. For more information, visit https://open-educational-resources.de/oer-tullu-regel/"; - - $markdownContent .= $license; // Convert Markdown content to gzip Base64 $contentHash = $this->create_gzip_base64_data($markdownContent); @@ -54,18 +92,18 @@ class PostToLiaScriptShortcodeButton { esc_html($atts['label']) ); - return $link; + return $license_html.$link; } return ''; } private function convert_to_markdown($content) { - $parsedown = new Parsedown(); - $html = $parsedown->text($content); - $converter = new HtmlConverter(); - $markdown = $converter->convert($html); - $markdown = strip_tags($markdown); + #$parsedown = new Parsedown(); + #$contenthtml = $parsedown->text($content); + $converter = new HtmlConverter(array('strip_tags' => true)); + $markdown = $converter->convert($content); + # $markdown = strip_tags($markdown); return $markdown; }