Changeset 3338231
- Timestamp:
- 08/02/2025 12:33:02 PM (8 months ago)
- Location:
- vernissaria-qr
- Files:
-
- 8 added
- 7 edited
-
assets/Screenshot-1.png (modified) (previous)
-
assets/Screenshot-4.png (modified) (previous)
-
assets/Screenshot-5.png (modified) (previous)
-
assets/Screenshot-6.png (added)
-
assets/banner-772x250.png (modified) (previous)
-
trunk/assets/Screenshot-1.png (added)
-
trunk/assets/Screenshot-2.png (added)
-
trunk/assets/Screenshot-3.png (added)
-
trunk/assets/Screenshot-4.png (added)
-
trunk/assets/Screenshot-5.png (added)
-
trunk/assets/css/qr-print.css (added)
-
trunk/assets/js/qr-print.js (added)
-
trunk/includes/qr-settings.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (6 diffs)
-
trunk/vernissaria-qr.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vernissaria-qr/trunk/includes/qr-settings.php
r3334711 r3338231 53 53 } 54 54 add_action('admin_enqueue_scripts', 'vernissaria_register_admin_assets'); 55 56 /** 57 * Enqueue print functionality scripts and styles 58 */ 59 function 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 } 84 add_action('admin_enqueue_scripts', 'vernissaria_enqueue_print_assets'); 85 86 /** 87 * Handle AJAX PDF generation 88 */ 89 function 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 } 135 add_action('wp_ajax_generate_qr_pdf', 'vernissaria_handle_pdf_generation'); 136 137 /** 138 * Call PDF generation API 139 */ 140 function 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 */ 191 function 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 */ 251 function vernissaria_get_current_domain() { 252 $site_url = get_site_url(); 253 $parsed_url = parse_url($site_url); 254 return $parsed_url['host']; 255 } 55 256 56 257 /** … … 284 485 285 486 /** 286 * Render settings page 487 * Render print settings tab content 488 */ 489 function 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 287 556 */ 288 557 function vernissaria_render_settings_page() { … … 290 559 return; 291 560 } 561 562 // Get active tab 563 $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'general'; 292 564 293 565 // Verify nonce for settings-updated parameter … … 299 571 } 300 572 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') { 303 575 add_settings_error( 304 576 'vernissaria_messages', … … 314 586 <div class="wrap"> 315 587 <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; ?> 323 611 </div> 324 612 <?php -
vernissaria-qr/trunk/readme.txt
r3334711 r3338231 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 1.3. 46 Stable tag: 1.3.5 7 7 Requires PHP: 7.2 8 8 License: GPLv2 or later … … 18 18 19 19 * **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 21 22 * **Visitor Analytics**: Track scans, unique visitors, devices and browsers 22 23 * **Custom Post Type Support**: Enable QR codes for any post type … … 34 35 * Exhibitions analyzing visitor patterns 35 36 * Digital catalogs with scan analytics 37 * Printing QR codes for physical artwork labels 36 38 37 39 = Shortcode Usage = … … 61 63 QR 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. 62 64 65 = How do I print QR codes? = 66 67 Go 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 63 69 = Can I use this plugin for non-art content? = 64 70 … … 86 92 2. QR code meta box on post edit screen 87 93 3. QR code statistics displayed using shortcode 88 4. Settings page 89 5. Article list view with scan counts 94 4. Settings page - General Settings tab 95 5. Settings page with new Print QR Codes tab 96 6. Article list view with scan counts 90 97 91 98 == 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 92 107 93 108 = 1.3.4 = … … 118 133 == Upgrade Notice == 119 134 135 = 1.3.5 = 136 New 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 120 138 = 1.3.0 = 121 139 This version adds significant improvements to analytics and visualization. Update recommended for all users. -
vernissaria-qr/trunk/vernissaria-qr.php
r3334711 r3338231 4 4 * Plugin URI: https://github.com/Clustmart/vernissaria-qr 5 5 * Description: Generate QR codes for artworks and display statistics for visitor engagement. 6 * Version: 1.3. 46 * Version: 1.3.5 7 7 * Author: Vernissaria 8 8 * Author URI: https://vernissaria.de … … 18 18 19 19 // Define plugin constants 20 define('VERNISSARIA_QR_VERSION', '1.3. 4');20 define('VERNISSARIA_QR_VERSION', '1.3.5'); 21 21 define('VERNISSARIA_QR_PATH', plugin_dir_path(__FILE__)); 22 22 define('VERNISSARIA_QR_URL', plugin_dir_url(__FILE__));
Note: See TracChangeset
for help on using the changeset viewer.