• <?php

    /*

    Plugin Name: Random Line

    Description: Выводит случайный блок "Форматированный" из указанного поста. Блок появляется в случайном месте при прокрутке страницы и исчезает через 5 секунд.

    Version: 1.0

    Author: Onik Artushyan

    */

    add_action('admin_menu', function() {

        add_menu_page('Random Line Settings', 'Random Line', 'manage_options', 'random-line-settings', function() {

            if (!current_user_can('manage_options')) return;

            if (isset($_POST['random_line_post_id'])) update_option('random_line_post_id', sanitize_text_field($_POST['random_line_post_id']));

            echo '<div class="wrap"><h1>Random Line Settings</h1>

                  <form method="post"><label for="random_line_post_id">ID поста:</label>

                  <input type="number" id="random_line_post_id" name="random_line_post_id" value="' . esc_attr(get_option('random_line_post_id', 1)) . '">

                  ' . submit_button() . '</form></div>';

        }, 'dashicons-text', 100);

    });

    add_shortcode('random_line', function() {

        $post = get_post(get_option('random_line_post_id', 1));

        if ($post && preg_match_all('/<pre.*?>(.*?)<\/pre>/s', $post->post_content, $matches)) {

            $blocks = array_filter(array_map('trim', $matches[1]));

            if (!empty($blocks)) {

                $random_block = strip_tags($blocks[array_rand($blocks)]);

                return '<div class="random-line">' . esc_html($random_block) . '</div>';

            }

        }

        return '';

    });

    add_action('wp_head', function() {

        echo '<style>

            .random-line {

                position: fixed;

                background: #e3f2fd;

                padding: 10px;

                border-radius: 5px;

                box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);

                z-index: 9999;

                animation: fadeInOut 5s ease-in-out;

                display: none;

            }

            @keyframes fadeInOut {

                0%, 100% { opacity: 0; }

                20%, 80% { opacity: 1; }

            }

        </style>';

    });

    add_action('wp_footer', function() {

        echo '<script>

            document.addEventListener("DOMContentLoaded", function() {

                setTimeout(function() {

                    var line = document.querySelector(".random-line");

                    if (line) {

                        line.style.top = Math.random() * 80 + 10 + "%";

                        line.style.left = Math.random() * 80 + 10 + "%";

                        line.style.display = "block";

                        setTimeout(function() { line.style.display = "none"; }, 5000);

                    }

                }, 2000);

            });

        </script>';

    });

    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter onikart

    (@onikart)

    <?php

    /*

    Plugin Name: QRPage

    Description: Генерирует QR-код для текущей страницы в виде изображения. Использует библиотеку QRCode.js.

    Version: 1.0

    Author: Onik Artushyan

    */

    function qrpage_shortcode() {

        wp_enqueue_script('qrcode', 'https://cdn.jsdelivr.net/npm/qrcode/build/qrcode.min.js', array(), null, true);

        return '<div id="qr-code"></div>

                <script>

                    document.addEventListener("DOMContentLoaded", function() {

                        const url = window.location.href;

                        if (url) {

                            const encodedUrl = encodeURIComponent(url); // Кодируем URL

                            QRCode.toDataURL(encodedUrl, { errorCorrectionLevel: "H" }, function (error, url) {

                                if (error) {

                                    console.error("Ошибка при генерации QR-кода:", error);

                                } else {

                                    const img = document.createElement("img");

                                    img.src = url;

                                    img.alt = "QR Code";

                                    document.getElementById("qr-code").appendChild(img);

                                }

                            });

                        } else {

                            console.error("URL текущей страницы не определён.");

                        }

                    });

                </script>';

    }

    add_shortcode('qrpage', 'qrpage_shortcode');

    ?>
    Thread Starter onikart

    (@onikart)

    <?php
    /*
    Plugin Name: QRPage
    Description: Генерирует QR-код для текущей страницы в виде изображения. Использует библиотеку QRCode.js.
    Version: 1.0
    Author: Ваше имя
    */

    // Регистрация шорткода [qrpage]
    function register_qrpage_shortcode() {
    add_shortcode('qrpage', 'generate_qr_container');
    }
    add_action('init', 'register_qrpage_shortcode');

    // Основная функция генерации QR-кода
    function generate_qr_container() {
    enqueue_qrcode_library();
    return create_qr_template();
    }

    // Подключение скрипта QRCode.js
    function enqueue_qrcode_library() {
    wp_enqueue_script(
    'qrcode-script',
    'https://cdn.jsdelivr.net/npm/qrcode/build/qrcode.min.js',
    array(),
    null,
    true
    );
    }

    // Генерация HTML-шаблона и скрипта
    function create_qr_template() {
    return '
    <div class="qr-container" id="qr-code-container"></div>
    <script>
    (function() {
    const container = document.getElementById("qr-code-container");
    const currentUrl = window.location.href;

    if (!currentUrl) {
    console.warn("Не удалось получить URL страницы");
    return;
    }

    const qrOptions = {
    errorCorrectionLevel: "H",
    margin: 2,
    width: 256
    };

    try {
    QRCode.toDataURL(
    encodeURIComponent(currentUrl),
    qrOptions,
    (error, dataUrl) => {
    if (error) throw error;

    const qrImage = new Image();
    qrImage.className = "qr-image";
    qrImage.src = dataUrl;
    qrImage.alt = "QR-код текущей страницы";

    container.appendChild(qrImage);
    }
    );
    } catch (error) {
    console.error("Ошибка генерации QR-кода:", error);
    container.innerHTML = "Ошибка загрузки QR-кода";
    }
    })();
    </script>
    ';
    }
    ?>
    Thread Starter onikart

    (@onikart)

    <?php
    /*
    Plugin Name: Random Line
    Description: Выводит случайный блок "Форматированный" из указанного поста. Блок появляется в случайном месте при прокрутке страницы и исчезает через 5 секунд.
    Version: 1.0
    Author: Ваше имя
    */

    // Добавляем страницу настроек в админке
    add_action('admin_menu', function() {
    add_menu_page(
    'Random Line Settings',
    'Random Line',
    'manage_options',
    'random-line-settings',
    function() {
    if (!current_user_can('manage_options')) return;
    if (isset($_POST['random_line_post_id'])) {
    update_option('random_line_post_id', sanitize_text_field($_POST['random_line_post_id']));
    }
    ?>
    <div class="wrap">
    <h1 class="wp-heading-inline">🎲 Random Line Settings</h1>
    <hr class="wp-header-end">
    <form method="post" class="card" style="max-width: 400px; padding: 20px;">
    <div class="form-field">
    <label for="random_line_post_id" style="display: block; margin-bottom: 8px; font-weight: 500;">
    📌 ID поста:
    </label>
    <input
    type="number"
    id="random_line_post_id"
    name="random_line_post_id"
    value="<?php echo esc_attr(get_option('random_line_post_id', 1)); ?>"
    class="regular-text"
    style="padding: 8px; width: 100%;"
    >
    </div>
    <?php submit_button('💾 Сохранить настройки'); ?>
    </form>
    </div>
    <?php
    },
    'dashicons-randomize',
    100
    );
    });

    // Вывод случайного блока "Форматированный" на фронтенде
    add_shortcode('random_line', function() {
    $post = get_post(get_option('random_line_post_id', 1));
    if ($post && preg_match_all('/<pre.*?>(.*?)<\/pre>/s', $post->post_content, $matches)) {
    $blocks = array_filter(array_map('trim', $matches[1]));
    if (!empty($blocks)) {
    $random_block = strip_tags($blocks[array_rand($blocks)]);
    return '<div class="random-line-box"><div class="glow"></div>' . esc_html($random_block) . '</div>';
    }
    }
    return '';
    });

    // Стили и скрипты для плагина
    add_action('wp_head', function() {
    echo '<style>
    .random-line-box {
    position: fixed;
    background: linear-gradient(145deg, #ffffff, #f8f9fe);
    padding: 1.2rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    animation: floatInOut 5s cubic-bezier(0.4, 0, 0.2, 1);
    display: none;
    border: 1px solid rgba(200, 200, 255, 0.3);
    font-family: "Courier New", monospace;
    font-size: 1.1em;
    backdrop-filter: blur(4px);
    transform: translate(-50%, -50%);
    }

    .glow {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    box-shadow: 0 0 15px rgba(100, 150, 255, 0.2);
    top: 0;
    left: 0;
    opacity: 0;
    animation: pulseGlow 2s infinite;
    }

    @keyframes floatInOut {
    0%, 100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.95);
    }
    20%, 80% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    }
    }

    @keyframes pulseGlow {
    50% { opacity: 0.4; }
    }
    </style>';
    });

    add_action('wp_footer', function() {
    Thread Starter onikart

    (@onikart)

    /*

    echo ' <script>

            document.addEventListener("DOMContentLoaded", function() {

                setTimeout(function() {

                    const line = document.querySelector(".random-line-box");

                    if (line) {

                        const viewportHeight = window.innerHeight;

                        const viewportWidth = window.innerWidth;

                        line.style.top = Math.random() * (viewportHeight - 100) + 50 + "px";

                        line.style.left = Math.random() * (viewportWidth - 200) + 100 + "px";

                        line.style.display = "block";

                        setTimeout(() => {

                            line.style.opacity = "0";

                            setTimeout(() => line.remove(), 1000);

                        }, 4500);

                    }

                }, 2000);

            });

        </script>

        ';

    });

    */
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this review.