add tullu lisense

This commit is contained in:
Joachim Happel 2024-05-24 00:11:49 +02:00
parent 3f5ae8aa00
commit 32a102a289

View file

@ -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 = "
<div class='oer-cc-licensebox'>
<a href='{$license_url}'>
<img decoding='async' src='{$license_icon_url}' alt='{$license}'>
</a>
<br>
Weiternutzung als OER ausdrücklich erlaubt: Dieses OER ist - sofern dies bei Teilinhalten nicht anders angegeben - lizenziert unter
<a href='{$license_url}' rel='license' target='_blank'>{$license}</a>.
Nennung gemäß <a href='https://open-educational-resources.de/oer-tullu-regel/'>TULLU-Regel</a> bitte wie folgt:<br>
<i>
<span xmlns:dct='http://purl.org/dc/terms/' property='dct:title'><a href='{$post_url}' xmlns:cc='http://creativecommons.org/ns#' rel='cc:attributionURL dct:creator'>{$title}</a> (<a href='{$home_url}' xmlns:cc='http://creativecommons.org/ns#' rel='cc:attributionURL dct:publisher'><em>{$blogname}</em></a>)</span>
von <span xmlns:cc='http://creativecommons.org/ns#' property='cc:attributionName dct:author'><a href='{$post_author_url}' rel='tag'>{$post_author_name}</a></span>,
Lizenz: <a href='{$license_url}' target='_blank'>{$license}</a>
</i>.
</div>";
$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;
}