Plugin Directory

Changeset 3338231


Ignore:
Timestamp:
08/02/2025 12:33:02 PM (8 months ago)
Author:
vernissaria
Message:

Update to version 1.3.5 - Added QR print functionality, updated screenshots and settings

Location:
vernissaria-qr
Files:
8 added
7 edited

Legend:

Unmodified
Added
Removed
  • vernissaria-qr/trunk/includes/qr-settings.php

    r3334711 r3338231  
    5353}
    5454add_action('admin_enqueue_scripts', 'vernissaria_register_admin_assets');
     55
     56/**
     57 * Enqueue print functionality scripts and styles
     58 */
     59function vernissaria_enqueue_print_assets($hook) {
     60    if ($hook !== 'settings_page_vernissaria-qr') {
     61        return;
     62    }
     63   
     64    wp_enqueue_script(
     65        'vernissaria-qr-print',
     66        VERNISSARIA_QR_URL . 'assets/js/qr-print.js',
     67        array('jquery'),
     68        '1.0.0',
     69        true
     70    );
     71   
     72    wp_localize_script('vernissaria-qr-print', 'vernissaria_ajax', array(
     73        'ajax_url' => admin_url('admin-ajax.php'),
     74        'nonce' => wp_create_nonce('vernissaria_qr_print_nonce'),
     75    ));
     76   
     77    wp_enqueue_style(
     78        'vernissaria-qr-print',
     79        VERNISSARIA_QR_URL . 'assets/css/qr-print.css',
     80        array(),
     81        '1.0.0'
     82    );
     83}
     84add_action('admin_enqueue_scripts', 'vernissaria_enqueue_print_assets');
     85
     86/**
     87 * Handle AJAX PDF generation
     88 */
     89function vernissaria_handle_pdf_generation() {
     90    // Verify nonce
     91    if (!wp_verify_nonce($_POST['nonce'], 'vernissaria_qr_print_nonce')) {
     92        wp_die('Security check failed');
     93    }
     94   
     95    // Check permissions
     96    if (!current_user_can('manage_options')) {
     97        wp_die('Insufficient permissions');
     98    }
     99   
     100    $qr_size = sanitize_text_field($_POST['qr_size']);
     101    $paper_size = sanitize_text_field($_POST['paper_size']);
     102    $domain = vernissaria_get_current_domain();
     103   
     104    // Validate inputs
     105    if (!in_array($qr_size, ['small', 'medium', 'large'])) {
     106        wp_send_json_error('Invalid QR size selected');
     107    }
     108   
     109    if (!in_array($paper_size, ['A4', 'Letter'])) {
     110        wp_send_json_error('Invalid paper size selected');
     111    }
     112   
     113    try {
     114        // Call the API
     115        $api_url = get_option('vernissaria_api_url', 'https://vernissaria.qraft.link');
     116        $response = vernissaria_call_pdf_api($api_url, $domain, $qr_size, $paper_size);
     117       
     118        if (!$response['success']) {
     119            wp_send_json_error($response['message']);
     120        }
     121       
     122        // Download and save PDF
     123        $pdf_data = vernissaria_download_and_save_pdf($response['data']);
     124       
     125        if (!$pdf_data) {
     126            wp_send_json_error('Failed to download and save PDF file');
     127        }
     128       
     129        wp_send_json_success(array_merge($response['data'], $pdf_data));
     130       
     131    } catch (Exception $e) {
     132        wp_send_json_error('Error generating PDF: ' . $e->getMessage());
     133    }
     134}
     135add_action('wp_ajax_generate_qr_pdf', 'vernissaria_handle_pdf_generation');
     136
     137/**
     138 * Call PDF generation API
     139 */
     140function vernissaria_call_pdf_api($api_url, $domain, $qr_size, $paper_size) {
     141    $endpoint = rtrim($api_url, '/') . '/pdf/generate';
     142   
     143    $body = json_encode(array(
     144        'domain' => $domain,
     145        'qr_size' => $qr_size,
     146        'paper_size' => $paper_size
     147    ));
     148   
     149    $args = array(
     150        'method' => 'POST',
     151        'body' => $body,
     152        'headers' => array(
     153            'Content-Type' => 'application/json',
     154            'Accept' => 'application/json'
     155        ),
     156        'timeout' => 30
     157    );
     158   
     159    $response = wp_remote_request($endpoint, $args);
     160   
     161    if (is_wp_error($response)) {
     162        throw new Exception('API connection failed: ' . $response->get_error_message());
     163    }
     164   
     165    $response_code = wp_remote_retrieve_response_code($response);
     166    $response_body = wp_remote_retrieve_body($response);
     167   
     168    if ($response_code !== 200) {
     169        throw new Exception('API returned error code: ' . $response_code);
     170    }
     171   
     172    $data = json_decode($response_body, true);
     173   
     174    if (!$data) {
     175        throw new Exception('Invalid API response format');
     176    }
     177   
     178    if (!$data['success']) {
     179        return array(
     180            'success' => false,
     181            'message' => isset($data['message']) ? $data['message'] : 'Unknown API error'
     182        );
     183    }
     184   
     185    return $data;
     186}
     187
     188/**
     189 * Download and save PDF to media library
     190 */
     191function vernissaria_download_and_save_pdf($pdf_info) {
     192    $pdf_url = $pdf_info['pdf_url'];
     193    $filename = basename(parse_url($pdf_url, PHP_URL_PATH));
     194   
     195    // Download the PDF
     196    $response = wp_remote_get($pdf_url, array(
     197        'timeout' => 60
     198    ));
     199   
     200    if (is_wp_error($response)) {
     201        return false;
     202    }
     203   
     204    $pdf_content = wp_remote_retrieve_body($response);
     205   
     206    if (empty($pdf_content)) {
     207        return false;
     208    }
     209   
     210    // Save to media library
     211    $upload_dir = wp_upload_dir();
     212    $file_path = $upload_dir['path'] . '/' . $filename;
     213    $file_url = $upload_dir['url'] . '/' . $filename;
     214   
     215    if (!file_put_contents($file_path, $pdf_content)) {
     216        return false;
     217    }
     218   
     219    // Create attachment
     220    $attachment = array(
     221        'guid' => $file_url,
     222        'post_mime_type' => 'application/pdf',
     223        'post_title' => 'Vernissaria QR Codes PDF - ' . date('Y-m-d H:i:s'),
     224        'post_content' => '',
     225        'post_status' => 'inherit'
     226    );
     227   
     228    $attachment_id = wp_insert_attachment($attachment, $file_path);
     229   
     230    if (!$attachment_id) {
     231        return false;
     232    }
     233   
     234    // Generate attachment metadata
     235    require_once(ABSPATH . 'wp-admin/includes/image.php');
     236    $attachment_data = wp_generate_attachment_metadata($attachment_id, $file_path);
     237    wp_update_attachment_metadata($attachment_id, $attachment_data);
     238   
     239    return array(
     240        'local_file_path' => $file_path,
     241        'local_file_url' => $file_url,
     242        'attachment_id' => $attachment_id,
     243        'media_library_url' => admin_url('post.php?post=' . $attachment_id . '&action=edit'),
     244        'filename' => $filename
     245    );
     246}
     247
     248/**
     249 * Get current domain
     250 */
     251function vernissaria_get_current_domain() {
     252    $site_url = get_site_url();
     253    $parsed_url = parse_url($site_url);
     254    return $parsed_url['host'];
     255}
    55256
    56257/**
     
    284485
    285486/**
    286  * Render settings page
     487 * Render print settings tab content
     488 */
     489function vernissaria_render_print_tab() {
     490    $domain = vernissaria_get_current_domain();
     491    ?>
     492    <div class="vernissaria-print-section">
     493        <h3><?php echo esc_html__('Generate Printable QR Codes PDF', 'vernissaria-qr'); ?></h3>
     494        <p><?php echo sprintf(esc_html__('Generate a PDF containing all QR codes for your domain: %s', 'vernissaria-qr'), '<strong>' . esc_html($domain) . '</strong>'); ?></p>
     495       
     496        <div id="vernissaria-print-messages" class="notice" style="display:none;">
     497            <p id="vernissaria-print-message-text"></p>
     498        </div>
     499       
     500        <table class="form-table">
     501            <tr>
     502                <th scope="row"><?php echo esc_html__('QR Code Size', 'vernissaria-qr'); ?></th>
     503                <td>
     504                    <select id="vernissaria-qr-size" name="qr_size">
     505                        <option value="small"><?php echo esc_html__('Small', 'vernissaria-qr'); ?></option>
     506                        <option value="medium" selected><?php echo esc_html__('Medium', 'vernissaria-qr'); ?></option>
     507                        <option value="large"><?php echo esc_html__('Large', 'vernissaria-qr'); ?></option>
     508                    </select>
     509                    <p class="description"><?php echo esc_html__('Select the size of QR codes in the PDF', 'vernissaria-qr'); ?></p>
     510                </td>
     511            </tr>
     512            <tr>
     513                <th scope="row"><?php echo esc_html__('Paper Size', 'vernissaria-qr'); ?></th>
     514                <td>
     515                    <select id="vernissaria-paper-size" name="paper_size">
     516                        <option value="A4" selected><?php echo esc_html__('A4', 'vernissaria-qr'); ?></option>
     517                        <option value="Letter"><?php echo esc_html__('Letter', 'vernissaria-qr'); ?></option>
     518                    </select>
     519                    <p class="description"><?php echo esc_html__('Select the paper size for printing', 'vernissaria-qr'); ?></p>
     520                </td>
     521            </tr>
     522        </table>
     523       
     524        <div class="vernissaria-print-actions">
     525            <button type="button" id="vernissaria-generate-pdf" class="button button-primary">
     526                <span class="button-text"><?php echo esc_html__('Generate PDF', 'vernissaria-qr'); ?></span>
     527                <span class="spinner" style="display:none;"></span>
     528            </button>
     529        </div>
     530       
     531        <div id="vernissaria-pdf-result" class="vernissaria-pdf-result" style="display:none;">
     532            <div class="pdf-info">
     533                <h4><?php echo esc_html__('PDF Generated Successfully!', 'vernissaria-qr'); ?></h4>
     534                <p><?php echo esc_html__('Your printable QR codes PDF has been generated and saved to your media library.', 'vernissaria-qr'); ?></p>
     535                <div class="pdf-details">
     536                    <p><strong><?php echo esc_html__('File:', 'vernissaria-qr'); ?></strong> <span id="pdf-filename"></span></p>
     537                    <p><strong><?php echo esc_html__('QR Codes:', 'vernissaria-qr'); ?></strong> <span id="pdf-qr-count"></span></p>
     538                    <p><strong><?php echo esc_html__('Expires:', 'vernissaria-qr'); ?></strong> <span id="pdf-expires"></span></p>
     539                </div>
     540                <div class="pdf-actions">
     541                    <a href="#" id="pdf-download-link" class="button button-secondary" target="_blank">
     542                        <?php echo esc_html__('Download PDF', 'vernissaria-qr'); ?>
     543                    </a>
     544                    <a href="#" id="pdf-media-link" class="button" target="_blank">
     545                        <?php echo esc_html__('View in Media Library', 'vernissaria-qr'); ?>
     546                    </a>
     547                </div>
     548            </div>
     549        </div>
     550    </div>
     551    <?php
     552}
     553
     554/**
     555 * Render settings page with tabs
    287556 */
    288557function vernissaria_render_settings_page() {
     
    290559        return;
    291560    }
     561   
     562    // Get active tab
     563    $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'general';
    292564   
    293565    // Verify nonce for settings-updated parameter
     
    299571    }
    300572   
    301     // Show settings saved message
    302     if ($settings_updated) {
     573    // Show settings saved message only on general tab
     574    if ($settings_updated && $active_tab === 'general') {
    303575        add_settings_error(
    304576            'vernissaria_messages',
     
    314586    <div class="wrap">
    315587        <h1><?php echo esc_html(get_admin_page_title()); ?></h1>
    316         <form action="options.php" method="post">
    317             <?php
    318             settings_fields('vernissaria_settings');
    319             do_settings_sections('vernissaria_settings');
    320             submit_button(__('Save Settings', 'vernissaria-qr'));
    321             ?>
    322         </form>
     588       
     589        <h2 class="nav-tab-wrapper">
     590            <a href="?page=vernissaria-qr&tab=general"
     591               class="nav-tab <?php echo $active_tab == 'general' ? 'nav-tab-active' : ''; ?>">
     592                <?php echo esc_html__('General Settings', 'vernissaria-qr'); ?>
     593            </a>
     594            <a href="?page=vernissaria-qr&tab=print"
     595               class="nav-tab <?php echo $active_tab == 'print' ? 'nav-tab-active' : ''; ?>">
     596                <?php echo esc_html__('Print QR Codes', 'vernissaria-qr'); ?>
     597            </a>
     598        </h2>
     599       
     600        <?php if ($active_tab == 'general'): ?>
     601            <form action="options.php" method="post">
     602                <?php
     603                settings_fields('vernissaria_settings');
     604                do_settings_sections('vernissaria_settings');
     605                submit_button(__('Save Settings', 'vernissaria-qr'));
     606                ?>
     607            </form>
     608        <?php elseif ($active_tab == 'print'): ?>
     609            <?php vernissaria_render_print_tab(); ?>
     610        <?php endif; ?>
    323611    </div>
    324612    <?php
  • vernissaria-qr/trunk/readme.txt

    r3334711 r3338231  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 1.3.4
     6Stable tag: 1.3.5
    77Requires PHP: 7.2
    88License: GPLv2 or later
     
    1818
    1919* **Automatic QR Code Generation**: Automatically creates QR codes when posts/pages are published
    20 * ** Record Artwork Details**: Document Dimensions and Year
     20* **QR Code Printing**: Generate printable PDFs containing all QR codes for your domain
     21* **Record Artwork Details**: Document Dimensions and Year
    2122* **Visitor Analytics**: Track scans, unique visitors, devices and browsers
    2223* **Custom Post Type Support**: Enable QR codes for any post type
     
    3435* Exhibitions analyzing visitor patterns
    3536* Digital catalogs with scan analytics
     37* Printing QR codes for physical artwork labels
    3638
    3739= Shortcode Usage =
     
    6163QR codes are automatically generated when you publish or update posts. You can find the QR code in the "Artwork Details" meta box on the post edit screen.
    6264
     65= How do I print QR codes? =
     66
     67Go to Settings → Vernissaria QR → Print QR Codes tab. Select your preferred QR size and paper format, then click "Generate PDF" to create a printable document with all your QR codes.
     68
    6369= Can I use this plugin for non-art content? =
    6470
     
    86922. QR code meta box on post edit screen
    87933. QR code statistics displayed using shortcode
    88 4. Settings page
    89 5. Article list view with scan counts
     944. Settings page - General Settings tab
     955. Settings page with new Print QR Codes tab
     966. Article list view with scan counts
    9097
    9198== Changelog ==
     99
     100= 1.3.5 =
     101* Added QR Code Printing Feature: New "Print QR Codes" tab in settings page
     102* Generate printable PDF containing all QR codes for your domain
     103* Configurable QR size options (Small, Medium, Large)
     104* Configurable paper size options (A4, Letter)
     105* Automatic PDF download and WordPress media library integration
     106* Settings page UI improved with tabbed interface
    92107
    93108= 1.3.4 =
     
    118133== Upgrade Notice ==
    119134
     135= 1.3.5 =
     136New QR code printing feature allows you to generate professional PDFs with all your QR codes for printing and physical display. Update recommended for all users.
     137
    120138= 1.3.0 =
    121139This version adds significant improvements to analytics and visualization. Update recommended for all users.
  • vernissaria-qr/trunk/vernissaria-qr.php

    r3334711 r3338231  
    44 * Plugin URI: https://github.com/Clustmart/vernissaria-qr
    55 * Description: Generate QR codes for artworks and display statistics for visitor engagement.
    6  * Version: 1.3.4
     6 * Version: 1.3.5
    77 * Author: Vernissaria
    88 * Author URI: https://vernissaria.de
     
    1818
    1919// Define plugin constants
    20 define('VERNISSARIA_QR_VERSION', '1.3.4');
     20define('VERNISSARIA_QR_VERSION', '1.3.5');
    2121define('VERNISSARIA_QR_PATH', plugin_dir_path(__FILE__));
    2222define('VERNISSARIA_QR_URL', plugin_dir_url(__FILE__));
Note: See TracChangeset for help on using the changeset viewer.