Problem war beim Kopieren das unicode Zeichen erzeugt wurden (Hier der Beitrag).
Problem war unter:
- MyBB Version: 1.8.38
- PHP Version: 8.3.12
- SQL Engine: MySQLi 8.0.40
Link zum Plugin
Hier die Angepasste Datei
Problem war unter:
- MyBB Version: 1.8.38
- PHP Version: 8.3.12
- SQL Engine: MySQLi 8.0.40
Link zum Plugin
Hier die Angepasste Datei
Inhalt anzeigen
Komplette Datei
Code:
<?php
/**
* MyBB 1.8
* Copy PHP CODE
* Author: JLP423
* http://mybb.vn
*
* Ma Ni - unicode fix
*
**/
global $mybb, $templatelist;
if (isset($templatelist)) {
$templatelist .= ',copyphpcode_js';
}
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.");
}
function copyphpcode_info()
{
return array(
"name" => "Copy PHP CODE",
"description" => "Adds the ability to copy text to clipboard with a tooltip for [PHP],[CODE], and [QUOTE] blocks.",
"website" => "https://mybb.vn",
"author" => "JLP423",
"authorsite" => "https://mybb.vn",
"version" => "2.1",
"codename" => "copyphpcode",
"compatibility" => "18*"
);
}
function copyphpcode_install()
{
global $db, $mybb;
//Build settings
$query = $db->simple_select("settinggroups", "COUNT(*) as counts");
$dorder = $db->fetch_field($query, 'counts') + 1;
$groupid = $db->insert_query('settinggroups', array(
'name' => 'copyphpcode',
'title' => 'Copy PHP CODE',
'description' => 'Adds the ability to copy text to clipboard with a tooltip for [PHP],[CODE], and [QUOTE] blocks.',
'disporder' => $dorder,
'isdefault' => '0'
));
$dorder_set = 0;
$new_setting[] = array(
'name' => 'copyphpcode_button_text',
'title' => 'Button Text',
'description' => 'The text you want for your copy button',
'optionscode' => 'text',
'value' => 'Copy',
'disporder' => ++$dorder_set,
'gid' => $groupid
);
$new_setting[] = array(
'name' => 'copyphpcode_button_style',
'title' => 'Button Style',
'description' => 'Stylize your copy button',
'optionscode' => 'textarea',
'value' => '
background-color: #333;
color: #0078d7;
padding: 6px 12px; /* Adjust padding to make the tooltip shorter */
font-size: 14px; /* Adjust font size */
border-radius: 4px;
max-width: 200px; /* Limit the width of the tooltip */;
',
'disporder' => ++$dorder_set,
'gid' => $groupid
);
$new_setting[] = array(
'name' => 'copyphpcode_tooltip_text',
'title' => 'Tooltip Text',
'description' => 'The text you want to show as tool tip',
'optionscode' => 'text',
'value' => 'Copied!',
'disporder' => ++$dorder_set,
'gid' => $groupid
);
$new_setting[] = array(
'name' => 'copyphpcode_tooltip_style',
'title' => 'Tooltip Style',
'description' => 'Stylize your tooltip',
'optionscode' => 'textarea',
'value' => '
position: fixed;
background-color: #333;
color: #ff00ff;
padding: 6px 12px; /* Adjust padding to make the tooltip shorter */
font-size: 14px; /* Adjust font size */
border-radius: 4px;
bottom: 20px;
margin-bottom: 3px;
left: 50%;
transform: translateX(-50%);
max-width: 200px; /* Limit the width of the tooltip */;
',
'disporder' => ++$dorder_set,
'gid' => $groupid
);
$db->insert_query_multiple("settings", $new_setting);
rebuild_settings();
//Build templates
$template = array();
$template['copyphpcode_js'] = '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\', function() {
async function copyTextToClipboard(textToCopy) {
try {
// Bereinige den Text
const sanitizedText = textToCopy.replace(/\\u00a0/g, \' \').replace(/\\r?\\n/g, \'\\n\');
if (navigator?.clipboard?.writeText) {
// Use Clipboard API if available
await navigator.clipboard.writeText(sanitizedText);
console.log(\'Text copied to clipboard using Clipboard API:\', sanitizedText);
showTooltip(\'Text copied to clipboard\');
} else if (document.execCommand) {
// Fallback to document.execCommand(\'copy\') method
const textArea = document.createElement(\'textarea\');
textArea.value = sanitizedText;
document.body.appendChild(textArea);
textArea.select();
document.execCommand(\'copy\');
document.body.removeChild(textArea);
console.log(\'Text copied to clipboard using document.execCommand:\', sanitizedText);
showTooltip(\'Text copied to clipboard\');
} else {
throw new Error(\'Clipboard API and document.execCommand are not supported in this browser.\');
}
} catch (err) {
console.error(\'Failed to copy text: \', err);
showTooltip(\'Failed to copy text\');
}
}
function showTooltip(message, button) {
const tooltip = document.createElement(\'div\');
tooltip.className = \'copyTooltip\';
tooltip.textContent = message;
const buttonRect = button.getBoundingClientRect();
tooltip.style.bottom = window.innerHeight - buttonRect.top + \'px\';
tooltip.style.left = buttonRect.left + buttonRect.width / 2 + \'px\';
document.body.appendChild(tooltip);
setTimeout(() => {
tooltip.remove();
}, 500); // Remove the tooltip after 0.5 seconds
}
// Get references to all elements with class "copyButton"
const copyButtons = document.querySelectorAll(\'.copyButton\');
const buttons = document.querySelectorAll(\'.copyButton\');
buttons.forEach(button => {
button.textContent = "{$button_text}";
});
// Add event listeners to all copy buttons
copyButtons.forEach(function(button, index) {
button.addEventListener(\'click\', function() {
const textToCopy = document.querySelectorAll(\'.textToCopy\')[index].innerText;
copyTextToClipboard(textToCopy);
showTooltip(\'{$tooltip_text}\', button);
});
});
});
</script>
<style>
.copyTooltip {
{$tooltip_style}
}
.copyButton {
{$button_style}
}
</style>';
// Insert the templates into the database.
foreach($template as $title => $template_new){
$template = array('title' => $db->escape_string($title), 'template' => $db->escape_string($template_new), 'sid' => '-1', 'dateline' => TIME_NOW, 'version' => '1800');
$db->insert_query('templates', $template);
}
}
function copyphpcode_is_installed()
{
global $db;
$query = $db->simple_select("settinggroups", "COUNT(*) as counts", "name = 'copyphpcode'");
$rows = $db->fetch_field($query, 'counts');
return ($rows > 0);
}
function copyphpcode_uninstall()
{
global $db;
//Remove templates
$templates = array('copyphpcode_js');
foreach($templates as $template) {
$db->delete_query('templates', "title = '{$template}'");
}
//Remove settings
$query = $db->simple_select('settinggroups', 'gid', 'name = "copyphpcode"');
$groupid = $db->fetch_field($query, 'gid');
$db->delete_query('settings','gid = "'.$groupid.'"');
$db->delete_query('settinggroups','gid = "'.$groupid.'"');
rebuild_settings();
}
function copyphpcode_activate()
{
include_once MYBB_ROOT.'inc/adminfunctions_templates.php';
find_replace_templatesets("mycode_php", "#".preg_quote('</div><div class="body">')."#i", '<button class="copyButton"></button></div><div class="body textToCopy">');
find_replace_templatesets("mycode_code", "#".preg_quote('</div><div class="body" dir="ltr">')."#i", ' <button class="copyButton"></button></div><div class="body textToCopy" dir="ltr">');
find_replace_templatesets("mycode_quote_post", "#".preg_quote('</cite>{$message}')."#i", ' <button class="copyButton"></button></cite><div class="textToCopy">{$message}</div>');
find_replace_templatesets("headerinclude", "#".preg_quote('{$stylesheets}')."#i", '{$stylesheets}{$copyphpcode}');
}
function copyphpcode_deactivate()
{
include_once MYBB_ROOT."inc/adminfunctions_templates.php";
find_replace_templatesets("mycode_php", "#".preg_quote('<button class="copyButton"></button></div><div class="body textToCopy">')."#i", '</div><div class="body">');
find_replace_templatesets("mycode_code", "#".preg_quote(' <button class="copyButton"></button></div><div class="body textToCopy" dir="ltr">')."#i", '</div><div class="body" dir="ltr">');
find_replace_templatesets("mycode_quote_post", "#".preg_quote(' <button class="copyButton"></button></cite><div class="textToCopy">{$message}</div>')."#i", '</cite>{$message}');
find_replace_templatesets("headerinclude", "#".preg_quote('{$copyphpcode}')."#i", '');
}
$plugins->add_hook('global_start', 'copyphpcode_add_script');
function copyphpcode_add_script()
{
global $templates, $copyphpcode, $tooltip_style, $tooltip_text, $button_style, $button_text, $mybb;
if (!isset($templates)) return;
$button_text = htmlspecialchars_uni($mybb->settings['copyphpcode_button_text']);
$button_style = strip_tags($mybb->settings['copyphpcode_button_style']);
$tooltip_style = strip_tags($mybb->settings['copyphpcode_tooltip_style']);
$tooltip_text = htmlspecialchars_uni($mybb->settings['copyphpcode_tooltip_text']);
$copyphpcode = $templates->get("copyphpcode_js");
eval("\$copyphpcode = \"{$copyphpcode}\";");
}
Galerie

RSS-Synchronisation