Changeset 3361739
- Timestamp:
- 09/15/2025 11:53:20 AM (7 months ago)
- Location:
- firmafy
- Files:
-
- 12 edited
- 1 copied
-
tags/1.3.3 (copied) (copied from firmafy/trunk)
-
tags/1.3.3/firmafy.php (modified) (2 diffs)
-
tags/1.3.3/includes/class-firmafy-admin-settings.php (modified) (1 diff)
-
tags/1.3.3/includes/class-helpers-firmafy.php (modified) (3 diffs)
-
tags/1.3.3/includes/forms/class-woocommerce.php (modified) (3 diffs)
-
tags/1.3.3/readme.txt (modified) (4 diffs)
-
tags/1.3.3/vendor/composer/installed.php (modified) (2 diffs)
-
trunk/firmafy.php (modified) (2 diffs)
-
trunk/includes/class-firmafy-admin-settings.php (modified) (1 diff)
-
trunk/includes/class-helpers-firmafy.php (modified) (3 diffs)
-
trunk/includes/forms/class-woocommerce.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/vendor/composer/installed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
firmafy/tags/1.3.3/firmafy.php
r3350127 r3361739 4 4 * Plugin URI: https://firmafy.com 5 5 * Description: Validate legally your forms in WordPress. 6 * Version: 1.3. 26 * Version: 1.3.3 7 7 * Author: Firmafy 8 8 * Author URI: https://firmafy.com … … 24 24 defined( 'ABSPATH' ) || die( 'No script kiddies please!' ); 25 25 26 define( 'FIRMAFY_VERSION', '1.3. 2' );26 define( 'FIRMAFY_VERSION', '1.3.3' ); 27 27 define( 'FIRMAFY_PLUGIN', __FILE__ ); 28 28 define( 'FIRMAFY_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); -
firmafy/tags/1.3.3/includes/class-firmafy-admin-settings.php
r3350127 r3361739 566 566 <select name="firmafy_options[woocommerce_when]" id="woocommerce_when"> 567 567 <option value="new_order" <?php selected( $woocommerce_when, 'new_order' ); ?>><?php esc_html_e( 'After a new order is created', 'firmafy' ); ?></option> 568 <option value=" payment_complete" <?php selected( $woocommerce_when, 'payment_complete' ); ?>><?php esc_html_e( 'After the order is paid', 'firmafy' ); ?></option>568 <option value="status_processing" <?php selected( $woocommerce_when, 'status_processing' ); ?>><?php esc_html_e( 'When the order status is processing', 'firmafy' ); ?></option> 569 569 </select> 570 570 <?php -
firmafy/tags/1.3.3/includes/class-helpers-firmafy.php
r3350127 r3361739 305 305 } 306 306 307 $temp_content_pre .= get_the_content( '', false, $template_id ); 308 309 // Replace merge vars for values. 310 $secure_mode = isset( $settings['secure_mode'] ) && 'yes' === $settings['secure_mode'] ? true : false; 311 // Prevents conflict with web sytles. 312 if ( $secure_mode ) { 313 $template_content = $temp_content_pre; 314 } else { 315 $template_content = apply_filters( 'the_content', $temp_content_pre ); 316 } 317 318 foreach ( $merge_vars as $variable ) { 319 if ( isset( $variable['name'] ) ) { 320 $value = is_array( $variable['value'] ) ? implode( ', ', $variable['value'] ) : $variable['value']; 321 $template_content = str_replace( '{' . $variable['name'] . '}', $value, $template_content ); 322 if ( self::signer_tags( $variable['name'] ) && 'nif' === $variable['name'] ) { 323 $signer[ $variable['name'] ] = str_replace( '.', '', $variable['value'] ); 324 } elseif ( self::signer_tags( $variable['name'] ) ) { 325 $signer[ $variable['name'] ] = $variable['value']; 326 } 327 } 328 } 329 $notification = isset( $settings['notification'] ) ? (array) $settings['notification'] : $settings['email']; 330 $signer['type_notifications'] = implode( ',', $notification ); 331 332 // Replace tags. 333 $template_content = self::replace_tags( $template_content, $template_id, $entry_id ); 334 335 // Process images. 336 $template_content = self::process_images( $template_content ); 337 338 // Generates PDF. 339 $filename = 'firmafy-' . sanitize_title( get_bloginfo( 'name' ) ); 340 $filename .= '-' . sanitize_title( get_the_title( $template_id ) ); 341 $filename .= '-' . gmdate( 'Y-m-d-H-i' ) . '.pdf'; 342 343 $content = '<html>'; 344 $content .= '<head>'; 345 $content .= '<style>'; 346 347 // Prepare Font family tag ready to replace. 348 $body_replace_tags = array( 349 'font-family: "{{fontFamily}}", sans-serif !important;', 350 ); 351 352 // Prepare for the PDF background. 353 if ( ! empty( $pdf_background ) ) { 354 $body_replace_tags[] = 'background-image: url(' . $pdf_background . '); background-size: cover; background-position: center; background-repeat: no-repeat;'; 355 } 356 357 // Append the body CSS. 358 $content .= 'body { ' . implode( ' ', $body_replace_tags ) . ' }'; 359 360 // Gets Template Style. 361 $template_css_file = get_template_directory() . '/style.css'; 362 if ( file_exists( $template_css_file ) ) { 363 $content .= file_get_contents( $template_css_file ); 364 } 365 366 // Gets Template Child Style. 367 $template_css_file = get_stylesheet_directory() . '/style.css'; 368 if ( file_exists( $template_css_file ) ) { 369 $content .= file_get_contents( $template_css_file ); 370 } 371 372 // Gets the custom PDF styles. 373 $template_pdf_css_file = FIRMAFY_PLUGIN_PATH . 'assets/pdf.css'; 374 if ( file_exists( $template_pdf_css_file ) ) { 375 $content .= file_get_contents( $template_css_file ); 376 } 377 378 // Get the Gutenberg styles. 379 $content .= self::get_gutenberg_css(); 380 381 // Append the line height to the style (only for p tags). 382 $line_height = ! empty( $settings['line_height'] ) ? $settings['line_height'] : '16'; 383 384 $content .= 'p.firmafy-lh { line-height: ' . $line_height . 'px; }'; 385 $content .= '</style>'; 386 $content .= '</head>'; 387 $content .= '<body>'; 388 $content .= $template_content; 389 $content .= '</body>'; 390 $content .= '</html>'; 391 392 // Creates PDF. 393 try { 394 // Define the options. 395 $options = new Options(); 396 $options->set( 'isHtml5ParserEnabled', true ); // Enable HTML5 parser. 397 $options->set( 'isRemoteEnabled', true ); // Enable remote file access. 398 $options->set( 'isFontSubsettingEnabled', true ); 399 400 // Initialize the Dompdf instance. 401 $dompdf = new Dompdf( $options ); 402 403 // Check if selected font is custom or not. If is custom, we must add the full path. 404 if ( self::font_is_custom( $font ) ) { 405 $custom_font = self::get_custom_pdf_font( $font ); 406 407 if ( ! empty( $custom_font ) ) { 408 foreach( $custom_font as $pdf_font ) { 409 $dompdf->getFontMetrics()->registerFont( $pdf_font[0], $pdf_font[1] ); 410 } 411 } else { 412 $font = 'helvetica'; 413 } 414 } 415 416 // Set the font. 417 $content = str_replace( '{{fontFamily}}', ucfirst( $font ), $content ); 418 419 // Setup the paper size and orientation. 420 $dompdf->setPaper( 'A4', 'portrait' ); 421 422 // Load HTML content. 423 $dompdf->loadHtml( $content ); 424 425 // Render the HTML to PDF. 426 $dompdf->render(); 427 428 // Check if logo is configured. 429 $logo_path = ! empty( $settings['pdf_logo'] ) 430 ? self::attachment_url_to_path( $settings['pdf_logo'] ) 431 : ''; 432 433 if ( $logo_path ) { 434 $dompdf->getCanvas()->page_script( function ( $pageNumber, $pageCount, $canvas, $fontMetrics ) use ( $logo_path ) { 435 if ( file_exists( $logo_path ) ) { 436 $canvas->image( $logo_path, 30, 10, 0, 35 ); 437 } 438 }); 439 } 440 441 // Output the generated PDF. 442 $pdf_content = $dompdf->output(); 443 } catch ( Exception $e ) { //phpcs:ignore 444 error_log( 'Unexpected Error!<br>Can not load PDF this time! ' . $e->getMessage() ); 445 } 446 447 $token = self::login(); 448 $final_signers = self::check_signers( $settings, $force_signers, $signer ); 449 450 // Sends to Firmafy. 451 $query = array( 452 'id_show' => $id_show, 453 'subject' => get_the_title( $template_id ), 454 'token' => isset( $token['data'] ) ? $token['data'] : '', 455 'signer' => wp_json_encode( $final_signers ), 456 'pdf_name' => $filename, 457 'pdf_base64' => chunk_split( base64_encode( $pdf_content ) ), 458 ); 459 460 $result_api = self::api_post( $settings, 'request', $query ); 461 462 if ( 'error' === $result_api['status'] ) { 463 $result_api['message'] = isset( $result_api['data'] ) ? $result_api['data'] : ''; 464 } else { 465 $result_api['id'] = isset( $result_api['data'] ) ? $result_api['data'] : ''; 466 } 467 468 return $result_api; 469 } 470 471 /** 472 * Get final signers 473 * 474 * @param array $settings Settings. 475 * @param array $force_signers Force signers. 476 * @param array $signer Signer. 477 * @return array 478 */ 479 private static function check_signers( $settings, $force_signers, $signer ) { 307 480 if ( isset( $settings['signers'] ) ) { 308 481 $company_signers = $settings['signers']; … … 330 503 } 331 504 } 332 333 $temp_content_pre .= get_the_content( '', false, $template_id ); 334 335 // Replace merge vars for values. 336 $secure_mode = isset( $settings['secure_mode'] ) && 'yes' === $settings['secure_mode'] ? true : false; 337 // Prevents conflict with web sytles. 338 if ( $secure_mode ) { 339 $template_content = $temp_content_pre; 340 } else { 341 $template_content = apply_filters( 'the_content', $temp_content_pre ); 342 } 343 344 foreach ( $merge_vars as $variable ) { 345 if ( isset( $variable['name'] ) ) { 346 $value = is_array( $variable['value'] ) ? implode( ', ', $variable['value'] ) : $variable['value']; 347 $template_content = str_replace( '{' . $variable['name'] . '}', $value, $template_content ); 348 if ( self::signer_tags( $variable['name'] ) && 'nif' === $variable['name'] ) { 349 $signer[ $variable['name'] ] = str_replace( '.', '', $variable['value'] ); 350 } elseif ( self::signer_tags( $variable['name'] ) ) { 351 $signer[ $variable['name'] ] = $variable['value']; 352 } 353 } 354 } 355 $notification = isset( $settings['notification'] ) ? (array) $settings['notification'] : $settings['email']; 356 $signer['type_notifications'] = implode( ',', $notification ); 357 358 // Replace tags. 359 $template_content = self::replace_tags( $template_content, $template_id, $entry_id ); 360 361 // Process images. 362 $template_content = self::process_images( $template_content ); 363 364 // Generates PDF. 365 $filename = 'firmafy-' . sanitize_title( get_bloginfo( 'name' ) ); 366 $filename .= '-' . sanitize_title( get_the_title( $template_id ) ); 367 $filename .= '-' . gmdate( 'Y-m-d-H-i' ) . '.pdf'; 368 369 $content = '<html>'; 370 $content .= '<head>'; 371 $content .= '<style>'; 372 373 // Prepare Font family tag ready to replace. 374 $body_replace_tags = array( 375 'font-family: "{{fontFamily}}", sans-serif !important;', 376 ); 377 378 // Prepare for the PDF background. 379 if ( ! empty( $pdf_background ) ) { 380 $body_replace_tags[] = 'background-image: url(' . $pdf_background . '); background-size: cover; background-position: center; background-repeat: no-repeat;'; 381 } 382 383 // Append the body CSS. 384 $content .= 'body { ' . implode( ' ', $body_replace_tags ) . ' }'; 385 386 // Gets Template Style. 387 $template_css_file = get_template_directory() . '/style.css'; 388 if ( file_exists( $template_css_file ) ) { 389 $content .= file_get_contents( $template_css_file ); 390 } 391 392 // Gets Template Child Style. 393 $template_css_file = get_stylesheet_directory() . '/style.css'; 394 if ( file_exists( $template_css_file ) ) { 395 $content .= file_get_contents( $template_css_file ); 396 } 397 398 // Gets the custom PDF styles. 399 $template_pdf_css_file = FIRMAFY_PLUGIN_PATH . 'assets/pdf.css'; 400 if ( file_exists( $template_pdf_css_file ) ) { 401 $content .= file_get_contents( $template_css_file ); 402 } 403 404 // Get the Gutenberg styles. 405 $content .= self::get_gutenberg_css(); 406 407 // Append the line height to the style (only for p tags). 408 $line_height = ! empty( $settings['line_height'] ) ? $settings['line_height'] : '16'; 409 410 $content .= 'p.firmafy-lh { line-height: ' . $line_height . 'px; }'; 411 $content .= '</style>'; 412 $content .= '</head>'; 413 $content .= '<body>'; 414 $content .= $template_content; 415 $content .= '</body>'; 416 $content .= '</html>'; 417 418 // Creates PDF. 419 try { 420 // Define the options. 421 $options = new Options(); 422 $options->set( 'isHtml5ParserEnabled', true ); // Enable HTML5 parser. 423 $options->set( 'isRemoteEnabled', true ); // Enable remote file access. 424 $options->set( 'isFontSubsettingEnabled', true ); 425 426 // Initialize the Dompdf instance. 427 $dompdf = new Dompdf( $options ); 428 429 // Check if selected font is custom or not. If is custom, we must add the full path. 430 if ( self::font_is_custom( $font ) ) { 431 $custom_font = self::get_custom_pdf_font( $font ); 432 433 if ( ! empty( $custom_font ) ) { 434 foreach( $custom_font as $pdf_font ) { 435 $dompdf->getFontMetrics()->registerFont( $pdf_font[0], $pdf_font[1] ); 436 } 437 } else { 438 $font = 'helvetica'; 439 } 440 } 441 442 // Set the font. 443 $content = str_replace( '{{fontFamily}}', ucfirst( $font ), $content ); 444 445 // Setup the paper size and orientation. 446 $dompdf->setPaper( 'A4', 'portrait' ); 447 448 // Load HTML content. 449 $dompdf->loadHtml( $content ); 450 451 // Render the HTML to PDF. 452 $dompdf->render(); 453 454 // Check if logo is configured. 455 $logo_path = ! empty( $settings['pdf_logo'] ) 456 ? self::attachment_url_to_path( $settings['pdf_logo'] ) 457 : ''; 458 459 if ( $logo_path ) { 460 $dompdf->getCanvas()->page_script( function ( $pageNumber, $pageCount, $canvas, $fontMetrics ) use ( $logo_path ) { 461 if ( file_exists( $logo_path ) ) { 462 $canvas->image( $logo_path, 30, 10, 0, 35 ); 463 } 464 }); 465 } 466 467 // Output the generated PDF. 468 $pdf_content = $dompdf->output(); 469 } catch ( Exception $e ) { //phpcs:ignore 470 error_log( 'Unexpected Error!<br>Can not load PDF this time! ' . $e->getMessage() ); 471 } 472 473 $token = self::login(); 474 $final_signers = ! empty( $company_signers ) ? array_merge( array( $signer ), $company_signers ) : array( $signer ); 475 476 // Sends to Firmafy. 477 $query = array( 478 'id_show' => $id_show, 479 'subject' => get_the_title( $template_id ), 480 'token' => isset( $token['data'] ) ? $token['data'] : '', 481 'signer' => wp_json_encode( $final_signers ), 482 'pdf_name' => $filename, 483 'pdf_base64' => chunk_split( base64_encode( $pdf_content ) ), 484 ); 485 486 $result_api = self::api_post( $settings, 'request', $query ); 487 488 if ( 'error' === $result_api['status'] ) { 489 $result_api['message'] = isset( $result_api['data'] ) ? $result_api['data'] : ''; 490 } else { 491 $result_api['id'] = isset( $result_api['data'] ) ? $result_api['data'] : ''; 492 } 493 494 return $result_api; 505 $final_signers = array( $signer ); 506 if ( empty( $company_signers ) ) { 507 return $final_signers; 508 } 509 foreach ( $company_signers as $company_signer ) { 510 if ( empty( $company_signer['nif'] ) ) { 511 continue; 512 } 513 $final_signers[] = $company_signer; 514 } 515 return $final_signers; 495 516 } 496 517 … … 688 709 * 689 710 * @param string $font Font to get. 690 * @return string711 * @return array 691 712 */ 692 713 public static function get_custom_pdf_font( $font ) { -
firmafy/tags/1.3.3/includes/forms/class-woocommerce.php
r3350127 r3361739 37 37 if ( 'yes' === $firmafy_woocommerce ) { 38 38 $firmafy_woo_when = isset( $this->settings['woocommerce_when'] ) ? $this->settings['woocommerce_when'] : 'new_order'; 39 add_action( 'woocommerce_' . $firmafy_woo_when, array( $this, 'process_entry' ), 10, 2 ); 39 if ( 'new_order' === $firmafy_woo_when ) { 40 add_action( 'woocommerce_new_order', array( $this, 'process_entry' ), 10, 2 ); 41 } else { 42 add_action( 'woocommerce_order_status_processing', array( $this, 'process_entry' ), 10, 2 ); 43 } 40 44 41 45 // EU VAT. … … 169 173 170 174 $firmafy_options = get_post_meta( $product_id, 'firmafy', true ); 171 172 if ( empty( $firmafy_options ) ) { 175 if ( empty( $firmafy_options['template'] ) ) { 173 176 continue; 174 177 } 175 $template_id = isset( $firmafy_options['template'] ) ? $firmafy_options['template'] : 0;178 $template_id = isset( $firmafy_options['template'] ) ? (int) $firmafy_options['template'] : 0; 176 179 unset( $firmafy_options['template'] ); 180 181 if ( empty( $template_id ) ) { 182 continue; 183 } 177 184 178 185 $merge_vars = array(); … … 198 205 $order_msg .= ' ' . $response_result['data']; 199 206 } else { 200 $order_msg = __( 'Order sent correctly to Firmafy', 'firmafy' ); 207 $order_msg = __( 'Order sent correctly to Firmafy with template:', 'firmafy' ); 208 $order_msg .= ' ' . get_the_title( $template_id ); 201 209 $order->add_meta_data( '_firmafy_csv', $response_result['data'], true ); 202 210 $order->add_meta_data( '_firmafy_status', 'PENDIENTE', true ); -
firmafy/tags/1.3.3/readme.txt
r3350127 r3361739 5 5 Requires PHP: 5.6 6 6 Tested up to: 6.8 7 Stable tag: 1.3. 28 Version: 1.3. 27 Stable tag: 1.3.3 8 Version: 1.3.3 9 9 License: GPL2 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 11 12 Validate legaly your forms created with main plugins in the market.12 Legally validate your forms or orders securely and confidently. 13 13 14 14 == Description == … … 18 18 And the signed document will have full legal validity. 19 19 20 Firmafy is an advanced electronic signature system that collects 6 evi cendes to guarantee the signatory identity and the signed document validity.20 Firmafy is an advanced electronic signature system that collects 6 evidences to guarantee the signatory identity and the signed document validity. 21 21 22 The document is generated as a result of the data inserted by your clients in your WordPress form .22 The document is generated as a result of the data inserted by your clients in your WordPress form or an order in your WooCommerce Shop. 23 23 24 24 Firmafy connects with the most popular and reliable WordPress form plugins: … … 43 43 44 44 Please, watch this video with to know what's Firmafy: 45 [youtube https://www.youtube.com/watch?v= PbC-KIEw-4M]45 [youtube https://www.youtube.com/watch?v=p5iWroU3ih4] 46 46 47 47 And watch this video with the step by step to step for the setup: … … 106 106 107 107 == Changelog == 108 = 1.3.3 = 109 * Fixed: Option to define when to sign the order in processing status. 110 * Fixed: Don't send settings signer if does not have NIF. 111 * Fixed: Don't send sign product if does not have template. 112 108 113 = 1.3.2 = 109 114 * Added action hook to the webhook response. -
firmafy/tags/1.3.3/vendor/composer/installed.php
r3350127 r3361739 2 2 'root' => array( 3 3 'name' => '__root__', 4 'pretty_version' => '1.3. 2',5 'version' => '1.3. 2.0',6 'reference' => ' 555440e5b6529acb04e261e9b3d40f168483d6c1',4 'pretty_version' => '1.3.3', 5 'version' => '1.3.3.0', 6 'reference' => 'd88d1c8157069c211cb93a9302f2403ac5a9b4f4', 7 7 'type' => 'library', 8 8 'install_path' => __DIR__ . '/../../', … … 12 12 'versions' => array( 13 13 '__root__' => array( 14 'pretty_version' => '1.3. 2',15 'version' => '1.3. 2.0',16 'reference' => ' 555440e5b6529acb04e261e9b3d40f168483d6c1',14 'pretty_version' => '1.3.3', 15 'version' => '1.3.3.0', 16 'reference' => 'd88d1c8157069c211cb93a9302f2403ac5a9b4f4', 17 17 'type' => 'library', 18 18 'install_path' => __DIR__ . '/../../', -
firmafy/trunk/firmafy.php
r3350127 r3361739 4 4 * Plugin URI: https://firmafy.com 5 5 * Description: Validate legally your forms in WordPress. 6 * Version: 1.3. 26 * Version: 1.3.3 7 7 * Author: Firmafy 8 8 * Author URI: https://firmafy.com … … 24 24 defined( 'ABSPATH' ) || die( 'No script kiddies please!' ); 25 25 26 define( 'FIRMAFY_VERSION', '1.3. 2' );26 define( 'FIRMAFY_VERSION', '1.3.3' ); 27 27 define( 'FIRMAFY_PLUGIN', __FILE__ ); 28 28 define( 'FIRMAFY_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); -
firmafy/trunk/includes/class-firmafy-admin-settings.php
r3350127 r3361739 566 566 <select name="firmafy_options[woocommerce_when]" id="woocommerce_when"> 567 567 <option value="new_order" <?php selected( $woocommerce_when, 'new_order' ); ?>><?php esc_html_e( 'After a new order is created', 'firmafy' ); ?></option> 568 <option value=" payment_complete" <?php selected( $woocommerce_when, 'payment_complete' ); ?>><?php esc_html_e( 'After the order is paid', 'firmafy' ); ?></option>568 <option value="status_processing" <?php selected( $woocommerce_when, 'status_processing' ); ?>><?php esc_html_e( 'When the order status is processing', 'firmafy' ); ?></option> 569 569 </select> 570 570 <?php -
firmafy/trunk/includes/class-helpers-firmafy.php
r3350127 r3361739 305 305 } 306 306 307 $temp_content_pre .= get_the_content( '', false, $template_id ); 308 309 // Replace merge vars for values. 310 $secure_mode = isset( $settings['secure_mode'] ) && 'yes' === $settings['secure_mode'] ? true : false; 311 // Prevents conflict with web sytles. 312 if ( $secure_mode ) { 313 $template_content = $temp_content_pre; 314 } else { 315 $template_content = apply_filters( 'the_content', $temp_content_pre ); 316 } 317 318 foreach ( $merge_vars as $variable ) { 319 if ( isset( $variable['name'] ) ) { 320 $value = is_array( $variable['value'] ) ? implode( ', ', $variable['value'] ) : $variable['value']; 321 $template_content = str_replace( '{' . $variable['name'] . '}', $value, $template_content ); 322 if ( self::signer_tags( $variable['name'] ) && 'nif' === $variable['name'] ) { 323 $signer[ $variable['name'] ] = str_replace( '.', '', $variable['value'] ); 324 } elseif ( self::signer_tags( $variable['name'] ) ) { 325 $signer[ $variable['name'] ] = $variable['value']; 326 } 327 } 328 } 329 $notification = isset( $settings['notification'] ) ? (array) $settings['notification'] : $settings['email']; 330 $signer['type_notifications'] = implode( ',', $notification ); 331 332 // Replace tags. 333 $template_content = self::replace_tags( $template_content, $template_id, $entry_id ); 334 335 // Process images. 336 $template_content = self::process_images( $template_content ); 337 338 // Generates PDF. 339 $filename = 'firmafy-' . sanitize_title( get_bloginfo( 'name' ) ); 340 $filename .= '-' . sanitize_title( get_the_title( $template_id ) ); 341 $filename .= '-' . gmdate( 'Y-m-d-H-i' ) . '.pdf'; 342 343 $content = '<html>'; 344 $content .= '<head>'; 345 $content .= '<style>'; 346 347 // Prepare Font family tag ready to replace. 348 $body_replace_tags = array( 349 'font-family: "{{fontFamily}}", sans-serif !important;', 350 ); 351 352 // Prepare for the PDF background. 353 if ( ! empty( $pdf_background ) ) { 354 $body_replace_tags[] = 'background-image: url(' . $pdf_background . '); background-size: cover; background-position: center; background-repeat: no-repeat;'; 355 } 356 357 // Append the body CSS. 358 $content .= 'body { ' . implode( ' ', $body_replace_tags ) . ' }'; 359 360 // Gets Template Style. 361 $template_css_file = get_template_directory() . '/style.css'; 362 if ( file_exists( $template_css_file ) ) { 363 $content .= file_get_contents( $template_css_file ); 364 } 365 366 // Gets Template Child Style. 367 $template_css_file = get_stylesheet_directory() . '/style.css'; 368 if ( file_exists( $template_css_file ) ) { 369 $content .= file_get_contents( $template_css_file ); 370 } 371 372 // Gets the custom PDF styles. 373 $template_pdf_css_file = FIRMAFY_PLUGIN_PATH . 'assets/pdf.css'; 374 if ( file_exists( $template_pdf_css_file ) ) { 375 $content .= file_get_contents( $template_css_file ); 376 } 377 378 // Get the Gutenberg styles. 379 $content .= self::get_gutenberg_css(); 380 381 // Append the line height to the style (only for p tags). 382 $line_height = ! empty( $settings['line_height'] ) ? $settings['line_height'] : '16'; 383 384 $content .= 'p.firmafy-lh { line-height: ' . $line_height . 'px; }'; 385 $content .= '</style>'; 386 $content .= '</head>'; 387 $content .= '<body>'; 388 $content .= $template_content; 389 $content .= '</body>'; 390 $content .= '</html>'; 391 392 // Creates PDF. 393 try { 394 // Define the options. 395 $options = new Options(); 396 $options->set( 'isHtml5ParserEnabled', true ); // Enable HTML5 parser. 397 $options->set( 'isRemoteEnabled', true ); // Enable remote file access. 398 $options->set( 'isFontSubsettingEnabled', true ); 399 400 // Initialize the Dompdf instance. 401 $dompdf = new Dompdf( $options ); 402 403 // Check if selected font is custom or not. If is custom, we must add the full path. 404 if ( self::font_is_custom( $font ) ) { 405 $custom_font = self::get_custom_pdf_font( $font ); 406 407 if ( ! empty( $custom_font ) ) { 408 foreach( $custom_font as $pdf_font ) { 409 $dompdf->getFontMetrics()->registerFont( $pdf_font[0], $pdf_font[1] ); 410 } 411 } else { 412 $font = 'helvetica'; 413 } 414 } 415 416 // Set the font. 417 $content = str_replace( '{{fontFamily}}', ucfirst( $font ), $content ); 418 419 // Setup the paper size and orientation. 420 $dompdf->setPaper( 'A4', 'portrait' ); 421 422 // Load HTML content. 423 $dompdf->loadHtml( $content ); 424 425 // Render the HTML to PDF. 426 $dompdf->render(); 427 428 // Check if logo is configured. 429 $logo_path = ! empty( $settings['pdf_logo'] ) 430 ? self::attachment_url_to_path( $settings['pdf_logo'] ) 431 : ''; 432 433 if ( $logo_path ) { 434 $dompdf->getCanvas()->page_script( function ( $pageNumber, $pageCount, $canvas, $fontMetrics ) use ( $logo_path ) { 435 if ( file_exists( $logo_path ) ) { 436 $canvas->image( $logo_path, 30, 10, 0, 35 ); 437 } 438 }); 439 } 440 441 // Output the generated PDF. 442 $pdf_content = $dompdf->output(); 443 } catch ( Exception $e ) { //phpcs:ignore 444 error_log( 'Unexpected Error!<br>Can not load PDF this time! ' . $e->getMessage() ); 445 } 446 447 $token = self::login(); 448 $final_signers = self::check_signers( $settings, $force_signers, $signer ); 449 450 // Sends to Firmafy. 451 $query = array( 452 'id_show' => $id_show, 453 'subject' => get_the_title( $template_id ), 454 'token' => isset( $token['data'] ) ? $token['data'] : '', 455 'signer' => wp_json_encode( $final_signers ), 456 'pdf_name' => $filename, 457 'pdf_base64' => chunk_split( base64_encode( $pdf_content ) ), 458 ); 459 460 $result_api = self::api_post( $settings, 'request', $query ); 461 462 if ( 'error' === $result_api['status'] ) { 463 $result_api['message'] = isset( $result_api['data'] ) ? $result_api['data'] : ''; 464 } else { 465 $result_api['id'] = isset( $result_api['data'] ) ? $result_api['data'] : ''; 466 } 467 468 return $result_api; 469 } 470 471 /** 472 * Get final signers 473 * 474 * @param array $settings Settings. 475 * @param array $force_signers Force signers. 476 * @param array $signer Signer. 477 * @return array 478 */ 479 private static function check_signers( $settings, $force_signers, $signer ) { 307 480 if ( isset( $settings['signers'] ) ) { 308 481 $company_signers = $settings['signers']; … … 330 503 } 331 504 } 332 333 $temp_content_pre .= get_the_content( '', false, $template_id ); 334 335 // Replace merge vars for values. 336 $secure_mode = isset( $settings['secure_mode'] ) && 'yes' === $settings['secure_mode'] ? true : false; 337 // Prevents conflict with web sytles. 338 if ( $secure_mode ) { 339 $template_content = $temp_content_pre; 340 } else { 341 $template_content = apply_filters( 'the_content', $temp_content_pre ); 342 } 343 344 foreach ( $merge_vars as $variable ) { 345 if ( isset( $variable['name'] ) ) { 346 $value = is_array( $variable['value'] ) ? implode( ', ', $variable['value'] ) : $variable['value']; 347 $template_content = str_replace( '{' . $variable['name'] . '}', $value, $template_content ); 348 if ( self::signer_tags( $variable['name'] ) && 'nif' === $variable['name'] ) { 349 $signer[ $variable['name'] ] = str_replace( '.', '', $variable['value'] ); 350 } elseif ( self::signer_tags( $variable['name'] ) ) { 351 $signer[ $variable['name'] ] = $variable['value']; 352 } 353 } 354 } 355 $notification = isset( $settings['notification'] ) ? (array) $settings['notification'] : $settings['email']; 356 $signer['type_notifications'] = implode( ',', $notification ); 357 358 // Replace tags. 359 $template_content = self::replace_tags( $template_content, $template_id, $entry_id ); 360 361 // Process images. 362 $template_content = self::process_images( $template_content ); 363 364 // Generates PDF. 365 $filename = 'firmafy-' . sanitize_title( get_bloginfo( 'name' ) ); 366 $filename .= '-' . sanitize_title( get_the_title( $template_id ) ); 367 $filename .= '-' . gmdate( 'Y-m-d-H-i' ) . '.pdf'; 368 369 $content = '<html>'; 370 $content .= '<head>'; 371 $content .= '<style>'; 372 373 // Prepare Font family tag ready to replace. 374 $body_replace_tags = array( 375 'font-family: "{{fontFamily}}", sans-serif !important;', 376 ); 377 378 // Prepare for the PDF background. 379 if ( ! empty( $pdf_background ) ) { 380 $body_replace_tags[] = 'background-image: url(' . $pdf_background . '); background-size: cover; background-position: center; background-repeat: no-repeat;'; 381 } 382 383 // Append the body CSS. 384 $content .= 'body { ' . implode( ' ', $body_replace_tags ) . ' }'; 385 386 // Gets Template Style. 387 $template_css_file = get_template_directory() . '/style.css'; 388 if ( file_exists( $template_css_file ) ) { 389 $content .= file_get_contents( $template_css_file ); 390 } 391 392 // Gets Template Child Style. 393 $template_css_file = get_stylesheet_directory() . '/style.css'; 394 if ( file_exists( $template_css_file ) ) { 395 $content .= file_get_contents( $template_css_file ); 396 } 397 398 // Gets the custom PDF styles. 399 $template_pdf_css_file = FIRMAFY_PLUGIN_PATH . 'assets/pdf.css'; 400 if ( file_exists( $template_pdf_css_file ) ) { 401 $content .= file_get_contents( $template_css_file ); 402 } 403 404 // Get the Gutenberg styles. 405 $content .= self::get_gutenberg_css(); 406 407 // Append the line height to the style (only for p tags). 408 $line_height = ! empty( $settings['line_height'] ) ? $settings['line_height'] : '16'; 409 410 $content .= 'p.firmafy-lh { line-height: ' . $line_height . 'px; }'; 411 $content .= '</style>'; 412 $content .= '</head>'; 413 $content .= '<body>'; 414 $content .= $template_content; 415 $content .= '</body>'; 416 $content .= '</html>'; 417 418 // Creates PDF. 419 try { 420 // Define the options. 421 $options = new Options(); 422 $options->set( 'isHtml5ParserEnabled', true ); // Enable HTML5 parser. 423 $options->set( 'isRemoteEnabled', true ); // Enable remote file access. 424 $options->set( 'isFontSubsettingEnabled', true ); 425 426 // Initialize the Dompdf instance. 427 $dompdf = new Dompdf( $options ); 428 429 // Check if selected font is custom or not. If is custom, we must add the full path. 430 if ( self::font_is_custom( $font ) ) { 431 $custom_font = self::get_custom_pdf_font( $font ); 432 433 if ( ! empty( $custom_font ) ) { 434 foreach( $custom_font as $pdf_font ) { 435 $dompdf->getFontMetrics()->registerFont( $pdf_font[0], $pdf_font[1] ); 436 } 437 } else { 438 $font = 'helvetica'; 439 } 440 } 441 442 // Set the font. 443 $content = str_replace( '{{fontFamily}}', ucfirst( $font ), $content ); 444 445 // Setup the paper size and orientation. 446 $dompdf->setPaper( 'A4', 'portrait' ); 447 448 // Load HTML content. 449 $dompdf->loadHtml( $content ); 450 451 // Render the HTML to PDF. 452 $dompdf->render(); 453 454 // Check if logo is configured. 455 $logo_path = ! empty( $settings['pdf_logo'] ) 456 ? self::attachment_url_to_path( $settings['pdf_logo'] ) 457 : ''; 458 459 if ( $logo_path ) { 460 $dompdf->getCanvas()->page_script( function ( $pageNumber, $pageCount, $canvas, $fontMetrics ) use ( $logo_path ) { 461 if ( file_exists( $logo_path ) ) { 462 $canvas->image( $logo_path, 30, 10, 0, 35 ); 463 } 464 }); 465 } 466 467 // Output the generated PDF. 468 $pdf_content = $dompdf->output(); 469 } catch ( Exception $e ) { //phpcs:ignore 470 error_log( 'Unexpected Error!<br>Can not load PDF this time! ' . $e->getMessage() ); 471 } 472 473 $token = self::login(); 474 $final_signers = ! empty( $company_signers ) ? array_merge( array( $signer ), $company_signers ) : array( $signer ); 475 476 // Sends to Firmafy. 477 $query = array( 478 'id_show' => $id_show, 479 'subject' => get_the_title( $template_id ), 480 'token' => isset( $token['data'] ) ? $token['data'] : '', 481 'signer' => wp_json_encode( $final_signers ), 482 'pdf_name' => $filename, 483 'pdf_base64' => chunk_split( base64_encode( $pdf_content ) ), 484 ); 485 486 $result_api = self::api_post( $settings, 'request', $query ); 487 488 if ( 'error' === $result_api['status'] ) { 489 $result_api['message'] = isset( $result_api['data'] ) ? $result_api['data'] : ''; 490 } else { 491 $result_api['id'] = isset( $result_api['data'] ) ? $result_api['data'] : ''; 492 } 493 494 return $result_api; 505 $final_signers = array( $signer ); 506 if ( empty( $company_signers ) ) { 507 return $final_signers; 508 } 509 foreach ( $company_signers as $company_signer ) { 510 if ( empty( $company_signer['nif'] ) ) { 511 continue; 512 } 513 $final_signers[] = $company_signer; 514 } 515 return $final_signers; 495 516 } 496 517 … … 688 709 * 689 710 * @param string $font Font to get. 690 * @return string711 * @return array 691 712 */ 692 713 public static function get_custom_pdf_font( $font ) { -
firmafy/trunk/includes/forms/class-woocommerce.php
r3350127 r3361739 37 37 if ( 'yes' === $firmafy_woocommerce ) { 38 38 $firmafy_woo_when = isset( $this->settings['woocommerce_when'] ) ? $this->settings['woocommerce_when'] : 'new_order'; 39 add_action( 'woocommerce_' . $firmafy_woo_when, array( $this, 'process_entry' ), 10, 2 ); 39 if ( 'new_order' === $firmafy_woo_when ) { 40 add_action( 'woocommerce_new_order', array( $this, 'process_entry' ), 10, 2 ); 41 } else { 42 add_action( 'woocommerce_order_status_processing', array( $this, 'process_entry' ), 10, 2 ); 43 } 40 44 41 45 // EU VAT. … … 169 173 170 174 $firmafy_options = get_post_meta( $product_id, 'firmafy', true ); 171 172 if ( empty( $firmafy_options ) ) { 175 if ( empty( $firmafy_options['template'] ) ) { 173 176 continue; 174 177 } 175 $template_id = isset( $firmafy_options['template'] ) ? $firmafy_options['template'] : 0;178 $template_id = isset( $firmafy_options['template'] ) ? (int) $firmafy_options['template'] : 0; 176 179 unset( $firmafy_options['template'] ); 180 181 if ( empty( $template_id ) ) { 182 continue; 183 } 177 184 178 185 $merge_vars = array(); … … 198 205 $order_msg .= ' ' . $response_result['data']; 199 206 } else { 200 $order_msg = __( 'Order sent correctly to Firmafy', 'firmafy' ); 207 $order_msg = __( 'Order sent correctly to Firmafy with template:', 'firmafy' ); 208 $order_msg .= ' ' . get_the_title( $template_id ); 201 209 $order->add_meta_data( '_firmafy_csv', $response_result['data'], true ); 202 210 $order->add_meta_data( '_firmafy_status', 'PENDIENTE', true ); -
firmafy/trunk/readme.txt
r3350127 r3361739 5 5 Requires PHP: 5.6 6 6 Tested up to: 6.8 7 Stable tag: 1.3. 28 Version: 1.3. 27 Stable tag: 1.3.3 8 Version: 1.3.3 9 9 License: GPL2 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 11 12 Validate legaly your forms created with main plugins in the market.12 Legally validate your forms or orders securely and confidently. 13 13 14 14 == Description == … … 18 18 And the signed document will have full legal validity. 19 19 20 Firmafy is an advanced electronic signature system that collects 6 evi cendes to guarantee the signatory identity and the signed document validity.20 Firmafy is an advanced electronic signature system that collects 6 evidences to guarantee the signatory identity and the signed document validity. 21 21 22 The document is generated as a result of the data inserted by your clients in your WordPress form .22 The document is generated as a result of the data inserted by your clients in your WordPress form or an order in your WooCommerce Shop. 23 23 24 24 Firmafy connects with the most popular and reliable WordPress form plugins: … … 43 43 44 44 Please, watch this video with to know what's Firmafy: 45 [youtube https://www.youtube.com/watch?v= PbC-KIEw-4M]45 [youtube https://www.youtube.com/watch?v=p5iWroU3ih4] 46 46 47 47 And watch this video with the step by step to step for the setup: … … 106 106 107 107 == Changelog == 108 = 1.3.3 = 109 * Fixed: Option to define when to sign the order in processing status. 110 * Fixed: Don't send settings signer if does not have NIF. 111 * Fixed: Don't send sign product if does not have template. 112 108 113 = 1.3.2 = 109 114 * Added action hook to the webhook response. -
firmafy/trunk/vendor/composer/installed.php
r3350127 r3361739 2 2 'root' => array( 3 3 'name' => '__root__', 4 'pretty_version' => '1.3. 2',5 'version' => '1.3. 2.0',6 'reference' => ' 555440e5b6529acb04e261e9b3d40f168483d6c1',4 'pretty_version' => '1.3.3', 5 'version' => '1.3.3.0', 6 'reference' => 'd88d1c8157069c211cb93a9302f2403ac5a9b4f4', 7 7 'type' => 'library', 8 8 'install_path' => __DIR__ . '/../../', … … 12 12 'versions' => array( 13 13 '__root__' => array( 14 'pretty_version' => '1.3. 2',15 'version' => '1.3. 2.0',16 'reference' => ' 555440e5b6529acb04e261e9b3d40f168483d6c1',14 'pretty_version' => '1.3.3', 15 'version' => '1.3.3.0', 16 'reference' => 'd88d1c8157069c211cb93a9302f2403ac5a9b4f4', 17 17 'type' => 'library', 18 18 'install_path' => __DIR__ . '/../../',
Note: See TracChangeset
for help on using the changeset viewer.