forked from andrewklimek/formidable-pro-pdf-extended
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpdf.php
760 lines (632 loc) · 24.1 KB
/
pdf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
<?php
/*
Plugin Name: Formidable Pro PDF Extended
Plugin URI: https://github.com/andrewklimek/formidable-pro-pdf-extended
Description: Formidable Pro PDF Extended allows you to save/view/download a PDF from the front- and back-end, and automate PDF creation on form submission.
Version: 2.0.1
Author: Blue Liquid Designs, Andrew J Klimek
Author URI: https://github.com/andrewklimek/formidable-pro-pdf-extended
Text Domain: ffpdf
------------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/*
* Define our constants
*/
if(!defined('FP_PDF_EXTENDED_VERSION')) define('FP_PDF_EXTENDED_VERSION', '1.7.0');
if(!defined('FP_PDF_EXTENDED_SUPPORTED_VERSION')) define('FP_PDF_EXTENDED_SUPPORTED_VERSION', '2.0' );
if(!defined('FP_PDF_EXTENDED_WP_SUPPORTED_VERSION')) define('FP_PDF_EXTENDED_WP_SUPPORTED_VERSION', '3.6');
if(!defined('FP_PDF_PLUGIN_DIR')) define('FP_PDF_PLUGIN_DIR', plugin_dir_path( __FILE__ ));
if(!defined('FP_PDF_PLUGIN_URL')) define('FP_PDF_PLUGIN_URL', plugin_dir_url( __FILE__ ));
if(!defined('FP_PDF_SETTINGS_URL')) define("FP_PDF_SETTINGS_URL", site_url() .'/wp-admin/admin.php?page=formidable-settings#PDF_settings');
if(!defined('FP_PDF_SAVE_FOLDER')) define('FP_PDF_SAVE_FOLDER', 'FORMIDABLE_PDF_TEMPLATES');
if(!defined('FP_PDF_SAVE_LOCATION')) define('FP_PDF_SAVE_LOCATION', get_stylesheet_directory().'/'.FP_PDF_SAVE_FOLDER.'/output/');
if(!defined('FP_PDF_FONT_LOCATION')) define('FP_PDF_FONT_LOCATION', get_stylesheet_directory().'/'.FP_PDF_SAVE_FOLDER.'/fonts/');
if(!defined('FP_PDF_TEMPLATE_LOCATION')) define('FP_PDF_TEMPLATE_LOCATION', get_stylesheet_directory().'/'.FP_PDF_SAVE_FOLDER.'/');
if(!defined('FP_PDF_TEMPLATE_URL_LOCATION')) define('FP_PDF_TEMPLATE_URL_LOCATION', get_stylesheet_directory_uri().'/'. FP_PDF_SAVE_FOLDER .'/');
if(!defined('FP_PDF_EXTENDED_PLUGIN_BASENAME')) define('FP_PDF_EXTENDED_PLUGIN_BASENAME', plugin_basename(__FILE__));
/*
* Do we need to deploy template files this edition? If yes set to true.
*/
if(!defined('FP_PDF_DEPLOY')) define('FP_PDF_DEPLOY', false);
/*
* Include the core files
*/
include FP_PDF_PLUGIN_DIR . 'pdf-common.php';
include FP_PDF_PLUGIN_DIR . 'pdf-configuration-indexer.php';
include FP_PDF_PLUGIN_DIR . 'installation-update-manager.php';
include FP_PDF_PLUGIN_DIR . 'pdf-render.php';
include FP_PDF_PLUGIN_DIR . 'pdf-settings.php';
include FP_PDF_PLUGIN_DIR . 'pdf-entry-detail.php';
include FP_PDF_PLUGIN_DIR . 'pdf-custom-display.php';
/*
* Initiate the class after Formidable Pro has been loaded using the init hook.
*/
add_action( 'init', 'FPPDF_Core::pdf_init' );
add_action( 'admin_init', 'FPPDF_Core::admin_init' );
/*
* Add settings page AJAX listeners
*/
add_action( 'wp_ajax_fppdfe_initialise', 'FPPDF_Settings::ajax_deploy' );
add_action( 'wp_ajax_fppdfe_initialise_font', 'FPPDF_Settings::initialise_fonts' );
class FPPDF_Core extends FPPDFGenerator
{
private $render;
/*
* Run public initialisation function
*/
public static function pdf_init()
{
/*
* Check if Formidable Pro is installed before we continue
* Include common functions for test
*/
if ( FPPDF_Common::is_formidable_supported( FP_PDF_EXTENDED_SUPPORTED_VERSION ) === false ) {
add_action( 'after_plugin_row_' . FP_PDF_EXTENDED_PLUGIN_BASENAME, 'FPPDF_Common::display_compatibility_error' );
return;
} else if ( FPPDF_Common::is_wordpress_supported( FP_PDF_EXTENDED_WP_SUPPORTED_VERSION ) === false ) {
add_action( 'after_plugin_row_' . FP_PDF_EXTENDED_PLUGIN_BASENAME, 'FPPDF_Common::display_wp_compatibility_error' );
return;
}
//else {
// add_action( 'after_plugin_row_' . FP_PDF_EXTENDED_PLUGIN_BASENAME, 'FPPDF_Core::add_documentation_byline' );
//}
/*
* As it's called inside a undefined function we need to globalise the $fppdf namespace
*/
global $fppdf;
$fppdf = new FPPDF_Core();
/*
* Some functions require the Wordpress Admin area to be fully loaded before we do any processing
*/
add_action( 'wp_loaded', 'FPPDF_Core::fully_loaded_admin' );
}
/*
* Only run in the admin area
*/
public static function admin_init()
{
wp_enqueue_script('fppdfe_admin', FP_PDF_PLUGIN_URL . 'js/admin.js', array('jquery'), '1', true);
wp_localize_script( 'fppdfe_admin', 'FPPDFE', array(
'nonce' => wp_create_nonce( 'fppdfe_nonce' )
) );
wp_enqueue_style('fppdfe_admin', FP_PDF_PLUGIN_URL . 'css/admin.css');
}
public function __construct()
{
/*
* Set up the PDF configuration and indexer
* Accessed through $this->configuration and $this->index.
*/
parent::__construct();
/*
* Add our installation/file handling hooks
*/
add_action( 'admin_init', 'FPPDF_Core::gfe_admin_init', 9 );
add_action( 'after_switch_theme', 'FPPDF_InstallUpdater::fp_pdf_on_switch_theme', 10, 2 );
register_activation_hook( __FILE__, 'FPPDF_InstallUpdater::install' );
/*
* Add our main hooks if the system is installed correctly
*/
if(FPPDF_Common::is_fully_installed() === false)
{
return;
}
add_action('frm_edit_entry_sidebar', array($this, 'detail_pdf_link'), 10, 1);
add_action('frm_show_entry_sidebar', array($this, 'detail_pdf_link'), 10, 1);
add_action('frm_row_actions', array($this, 'pdf_link'), 10, 2);
add_action('wp', array($this, 'process_exterior_pages'));
/*
* Register render class
*/
$this->render = new FPPDFRender();
/*
* Run PDF generate / email code based on version
*/
add_filter( 'frm_notification_attachment', 'FPPDF_Core::create_and_attach_pdf', 10, 3 );
}
/*
* Do processes that require Wordpress Admin to be fully loaded
*/
public static function fully_loaded_admin()
{
/*
* Check if the user has switched themes and they haven't yet prompt user to copy over directory structure
* If the plugin has just initialised we won't check for a theme swap as initialisation will reset this value
*/
if(!filter_input(INPUT_POST,'upgrade'))
{
FPPDF_InstallUpdater::check_theme_switch();
}
}
/**
* Check to see if Formidable Pro is actually installed
*/
public static function gfe_admin_init() {
/*
* Check if database plugin version matches current plugin version and updates if needed
*/
if(get_option('fp_pdf_extended_version') != FP_PDF_EXTENDED_VERSION)
{
update_option('fp_pdf_extended_version', FP_PDF_EXTENDED_VERSION);
if( FP_PDF_EXTENDED_VERSION < 1.7 )
{
update_option('fp_pdf_extended_deploy', 'no');
/* redirect */
Header('Location: '.FP_PDF_SETTINGS_URL);
exit;
}
}
/*
* Check if GF PDF Extended is correctly installed. If not we'll run the installer.
*/
$theme_switch = get_option('gfpdfe_switch_theme');
if( ( ( get_option('fp_pdf_extended_installed') != 'installed' ) || ( ! is_dir(FP_PDF_TEMPLATE_LOCATION)) ) && ( ! filter_input(INPUT_POST,'upgrade') && ( empty( $theme_switch['old'] ) ) ) ) {
/*
* Prompt user to initialise plugin
*/
add_action( 'admin_notices', 'FPPDF_InstallUpdater::FP_PDF_not_deployed_fresh' );
} else {
/**
* Check if deployed new template files after update
*/
if( (get_option('FP_PDF_extended_deploy') == 'no' && !filter_input(INPUT_POST,'upgrade') && FP_PDF_DEPLOY === true) || (file_exists(FP_PDF_PLUGIN_DIR .'mPDF.zip') && !filter_input(INPUT_POST,'upgrade') ) ) {
/*show warning message */
add_action('admin_notices', array("FPPDF_InstallUpdater", "FP_PDF_not_deployed"));
}
}
FPPDF_Settings::settings_page();
}
function detail_pdf_link($record) {
/*
* Get the template name
* Class: PDFGenerator
* File: pdf-configuration-indexer.php
*/
global $fppdf;
$form_id = $record->form_id;
$lead_id = $record->id;
$templates = $this->get_template($form_id, true);
/* exit early if templates not found */
if($templates === false)
{
return;
}
?>
<div class="postbox fppdfe">
<h3 class="hndle"><span>PDFs</span></h3>
<div class="inside">
<?php
if(is_array($templates))
{
?>
<?php foreach($templates as $id => $val):
$name = $fppdf->get_pdf_name($id, $form_id, $lead_id);
$aid = (int) $id + 1;
?>
<div class="detailed_pdf">
<span><?php
echo $name;
$url = home_url() .'/?pdf=1&aid='. $aid .'&fid=' . $form_id . '&lid=' . $lead_id . '&template=' . $val['template'];
?></span>
<a href="<?php echo $url; ?>" target="_blank" class="button">View</a>
<a href="<?php echo $url.'&download=1'; ?>" target="_blank" class="button">Download</a></div>
<?php endforeach; ?>
<?php
}
elseif($templates !== false)
{
$url = home_url() .'/?pdf=1&fid=' . $form_id . '&lid=' . $lead_id . '&template=' . $templates;
?>
PDF: <a href="<?php echo $url; ?>" target="_blank" class="button">View</a>
<a href="<?php echo $url.'&download=1'; ?>" onclick="var url='<?php echo $url.'&download=1'; ?>'; window.open (url); return false;" class="button">Download</a>
<?php
}
?>
</div>
</div>
<?php
}
function pdf_link($actions, $entry) {
/*
* Get the template name
* Class: PDFGenerator
* File: pdf-configuration-indexer.php
*/
$form_id = $entry->form_id;
$lead_id = $entry->id;
global $fppdf;
$templates = $this->get_template($form_id, true);
/* exit early if templates not found */
if($templates === false)
{
return $actions;
}
if(is_array($templates))
{
ob_start();
?>
<span class="fp_has_submenu">
<a target="" href="#" title="View PDF configured for this form" onclick="return false" class="">View PDFs</a>
<div class="fp_submenu">
<ul>
<?php foreach($templates as $id => $t):
$name = $fppdf->get_pdf_name($id, $form_id, $lead_id);
$aid = (int) $id + 1;
?>
<li class="">
<a target="_blank" href="<?php echo home_url(); ?>/?pdf=1&aid=<?php echo $aid; ?>&fid=<?php echo $form_id; ?>&lid=<?php echo $lead_id; ?>&template=<?php echo $t['template']; ?>"><?php echo $name; ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
</span>
<?php
$actions['pdf'] = ob_get_contents();
ob_end_clean();
}
else
{
ob_start();
?>
<a target="_blank" href="<?php echo home_url(); ?>/?pdf=1&fid=<?php echo $form_id; ?>&lid=<?php echo $lead_id; ?>&template=<?php echo $templates; ?>"> View PDF</a>
<?php
$actions['pdf'] = ob_get_contents();
ob_end_clean();
}
return $actions;
}
/*
* Handle incoming routes
* Look for $_GET['pdf'] variable, authenticate user and generate/display PDF
*/
function process_exterior_pages() {
global $wpdb;
/*
* As far as I can tell, all 3 $_GET variables are needed to proceed, not just 'pdf
*/
if ( empty($_GET['pdf']) || empty($_GET['fid']) || empty($_GET['lid']) )
{
return;
}
$form_id = (int) $_GET['fid'];
$lead_id = (int) $_GET['lid'];
$ip = FPPDF_Common::getRealIpAddr();
/*
* Get the template name
* Class: PDFGenerator
* File: pdf-configuration-indexer.php
*/
$template = $this->get_template($form_id);
/*
* Before setting up PDF options we will check if a configuration is found
* If not, we will set up defaults defined in configuration.php
*/
$index = $this->check_configuration($form_id, $template);
/*
* Run if user is not logged in
*/
if(!is_user_logged_in() && empty($_GET['nonce']))
{
/*
* Check the lead is in the database and the IP address matches (little security booster)
*/
$form_entries = $wpdb->get_var("SELECT count(*) FROM `{$wpdb->prefix}frm_items` WHERE form_id={$form_id} AND id={$lead_id} AND ip='{$ip}'");
if($form_entries == 0 && $this->configuration[$index]['access'] !== 'all')
{
auth_redirect();
}
}
elseif(isset($_GET['nonce']))
{
/*
* Using the custom display, which needs PDFs to be public
* If nonce matches then we will display the results
*/
$user_template = $_GET['template'];
$nonce = $_GET['nonce'];
if ( ! wp_verify_nonce( $nonce, 'fppdf_' . $form_id . $lead_id. $user_template ) ) {
/*
* Failed
*/
exit('Access to PDF Denied');
}
}
else
{
/*
* Ensure logged in users have the correct privilages
*/
if(!current_user_can('frm_view_entries'))
{
/*
* User doesn't have the correct access privilages
* Let's check if they are assigned to the form
*/
$user_logged_entries = $wpdb->get_var("SELECT count(*) FROM `{$wpdb->prefix}frm_items` WHERE form_id={$form_id} AND id={$lead_id} AND user_id=". get_current_user_id() );
/*
* Failed again.
* One last check against the IP
* If it matches the record then we will show the PDF
*/
if($user_logged_entries == 0)
{
$form_entries = $wpdb->get_var("SELECT count(*) FROM `{$wpdb->prefix}frm_items` WHERE form_id={$form_id} AND id={$lead_id} AND ip='{$ip}'");
if($form_entries == 0 && $this->configuration[$index]['access'] !== 'all')
{
/*
* Don't show the PDF
*/
return;
}
}
}
/*
* Because this user is logged in with the correct access
* we will allow a template to be shown by setting the template variable
*/
if( (isset($_GET['template'])) && ($template != $_GET['template']) && (substr($_GET['template'], -4) == '.php') )
{
$template = $_GET['template'];
}
}
$pdf_arguments = $this->generate_pdf_parameters($index, $form_id, $lead_id, $template);
/*
* Add output to arguments
*/
$output = 'view';
if(isset($_GET['download']))
{
$output = 'download';
}
$pdf_arguments['output'] = $output;
$this->render->PDF_Generator($form_id, $lead_id, $pdf_arguments);
exit();
}
public static function create_and_attach_pdf( $attachments, $form, $args ) {
$notification = self::do_notification($attachments, $form, $args);
return $notification;
}
/*
* Handles the Formidable Pro notification logic
*/
public static function do_notification($attachments, $form, $args)
{
/*
* Allow the template/function access to these variables
*/
global $fppdf, $form_id, $lead_id;
$notification_name = (isset($args['email_key'])) ? $args['email_key'] : '';
/*
* Set data used to determine if PDF needs to be created and attached to notification
* Don't change anything here.
*/
$form_id = $form->id;
$lead_id = apply_filters('fppdfe_lead_id', $args['entry']->id, $form, $args, $fppdf); /* allow premium plugins to override the lead ID */
$folder_id = $form_id.$lead_id.'/';
/*
* Before setting up PDF options we will check if a configuration is found
* If not, we will set up defaults defined in configuration.php
*/
$fppdf->check_configuration($form_id);
/*
* Check if form is in configuration
*/
if(!$config = $fppdf->get_config($form_id))
{
return $notification;
}
/*
* To have our configuration indexes so loop through the PDF template configuration
* and generate and attach PDF files.
*/
foreach($config as $index)
{
$template = (isset($fppdf->configuration[$index]['template'])) ? $fppdf->configuration[$index]['template'] : '';
/* Get notifications user wants PDF attached to and check if the correct notifications hook is running */
$notifications = $fppdf->get_form_notifications( $form, $index, $args );
/*
* Premium plugin filter
* Allows manual override of the notification
* Allows the multi-report plugin to automate PDFs based on weekly/fortnightly/monthly basis
* Only allow boolean to be returned
*/
$notification_override = (bool) apply_filters('gfpdfe_notification_override', false, $notification_name, $attachments, $form, $args, $fppdf);
if ($fppdf->check_notification($notification_name, $notifications) || $notification_override === true)
{
$pdf_arguments = $fppdf->generate_pdf_parameters($index, $form_id, $lead_id, $template);
/* generate and save default PDF */
$filename = $fppdf->render->PDF_Generator($form_id, $lead_id, $pdf_arguments);
$attachments[] = $filename;
}
}
return $attachments;
}
/*
* Check if name in notification_name String/Array matches value in $notifcations array
*/
public function check_notification($notification_name, $notifications)
{
if(is_array($notification_name))
{
foreach($notification_name as $name)
{
if(in_array($name, $notifications))
{
return true;
}
}
}
else
{
if(in_array($notification_name, $notifications))
{
return true;
}
}
return false;
}
public static function get_form_notifications( $form, $index, $args ) {
global $fppdf;
/*
* Check if notification field even exists
*/
if(!isset($fppdf->configuration[$index]['notifications']))
{
return array();
}
/*
* Get this notification id
*/
$this_notification = $args['email_key'];
$new_notifications = array();
/*
* If notifications is true the user wants to attach the PDF to all notifications
*/
if ( $fppdf->configuration[ $index ]['notifications'] === true ) {
$new_notifications[] = $this_notification;
} else {
foreach ( (array) $fppdf->configuration[ $index ]['notifications'] as $name ) {
if ( $name == $this_notification ) {
$new_notifications[] = $name;
}
}
}
return $new_notifications;
}
/*
* Generate PDF parameters to pass to the PDF renderer
* $index Integer The configuration index number
*/
private function generate_pdf_parameters($index, $form_id, $lead_id, $template = '')
{
$pdf_name = !empty($this->configuration[$index]['filename']) ? FPPDF_Common::validate_pdf_name($this->configuration[$index]['filename'], $form_id, $lead_id) : FPPDF_Common::get_pdf_filename($form_id, $lead_id);
$template = !empty($template) ? $template : $this->get_template($index);
$pdf_size = (isset($this->configuration[$index]['pdf_size']) && (is_array($this->configuration[$index]['pdf_size']) || strlen($this->configuration[$index]['pdf_size']) > 0)) ? $this->configuration[$index]['pdf_size'] : self::$default['pdf_size'];
$orientation = !empty($this->configuration[$index]['orientation']) ? $this->configuration[$index]['orientation'] : self::$default['orientation'];
$security = !empty($this->configuration[$index]['security']) ? $this->configuration[$index]['security'] : self::$default['security'];
$premium = !empty($this->configuration[$index]['premium']) ? true: false;
/*
* Validate privileges
* If blank and security is true then set privileges to all
*/
$privileges = (isset($this->configuration[$index]['pdf_privileges'])) ? $this->validate_privileges($this->configuration[$index]['pdf_privileges']) : $this->validate_privileges('');
$pdf_password = (isset($this->configuration[$index]['pdf_password'])) ? FPPDF_Common::do_mergetags($this->configuration[$index]['pdf_password'], $form_id, $lead_id) : '';
$master_password = (isset($this->configuration[$index]['pdf_master_password'])) ? FPPDF_Common::do_mergetags($this->configuration[$index]['pdf_master_password'], $form_id, $lead_id) : '';
$rtl = (isset($this->configuration[$index]['rtl'])) ? $this->configuration[$index]['rtl'] : false;
/* added in v3.4.0 */
$pdfa1b = !empty($this->configuration[$index]['pdfa1b']) ? true : false;
/* added in v3.4.0 */
$pdfx1a = !empty($this->configuration[$index]['pdfx1a']) ? true : false;
/*
* Run the options through filters
*/
$pdf_name = apply_filters('fppdf_pdf_name', $pdf_name, $form_id, $lead_id);
$template = apply_filters('fppdf_template', $template, $form_id, $lead_id);
$orientation = apply_filters('fppdf_orientation', $orientation, $form_id, $lead_id);
$security = apply_filters('fppdf_security', $security, $form_id, $lead_id);
$privileges = apply_filters('fppdf_privilages', $privileges, $form_id, $lead_id);
$pdf_password = apply_filters('fppdf_password', $pdf_password, $form_id, $lead_id);
$master_password = apply_filters('fppdf_master_password', $master_password, $form_id, $lead_id);
$rtl = apply_filters('fppdf_rtl', $rtl, $form_id, $lead_id);
$pdf_arguments = array(
'pdfname' => $pdf_name,
'template' => $template,
'pdf_size' => $pdf_size, /* set to one of the following, or array - in millimeters */
'orientation' => $orientation, /* landscape or portrait */
'security' => $security, /* true or false. if true the security settings below will be applied. Default false. */
'pdf_password' => $pdf_password, /* set a password to view the PDF */
'pdf_privileges' => $privileges, /* assign user privliages to the PDF */
'pdf_master_password' => $master_password, /* set a master password to the PDF can't be modified without it */
'rtl' => $rtl,
'premium' => $premium,
'pdfa1b' => $pdfa1b,
'pdfx1a' => $pdfx1a,
);
return $pdf_arguments;
}
/*
* Checks if a configuration index is found
* If not, we will set up defaults defined in configuration.php if they exist
*/
public static function check_configuration($form_id, $template = '')
{
// error_log("pdf.php 0");
global $fp_pdf_default_configuration, $fppdf;
/*
* Check if configuration index already defined
*/
if(empty($fppdf->index[$form_id]))
{
// error_log("pdf.php 1");
/*
* Check if a default configuration is defined
*/
if(is_array($fp_pdf_default_configuration) && sizeof($fp_pdf_default_configuration) > 0 && FPPDF_SET_DEFAULT_TEMPLATE === true)
{
// error_log("pdf.php 2");
/*
* Add form_id to the defualt configuration
*/
$default_configuration = array_merge($fp_pdf_default_configuration, array('form_id' => $form_id));
/*
* There is no configuration index and there is a default index so add the defaults to this form's configuration
*/
$fppdf->configuration[] = $default_configuration;
/* get the id of the newly added configuration */
end($fppdf->configuration);
$index = key($fppdf->configuration);
/* now add to the index */
$fppdf->assign_index($form_id, $index);
}
}
else
{
// error_log("pdf.php 3");
/* if there are multiple indexes for a form we will look for the one with the matching template */
if(sizeof($fppdf->index[$form_id]) > 1 && $template )
{
// error_log("pdf.php 4");
/*
* Check if $_GET['aid'] present which will give us the index when multi templates assigned
*/
if( !empty($_GET['aid']) )
{
$aid = (int) $_GET['aid'] - 1;
if(isset($fppdf->index[$form_id][$aid]))
{
// error_log("pdf.php 5");
return $fppdf->index[$form_id][$aid];
}
}
// error_log("pdf.php 6");
/*
* If aid not present we'll match against the template
* This is usually the case when using a user-generated link
*/
$index = false;
foreach($fppdf->index[$form_id] as $i)
{
if(isset($fppdf->configuration[$i]['template']) && $fppdf->configuration[$i]['template'] == $template)
{
// error_log("pdf.php 7");
/* matched by template */
return $i;
}
}
}
// error_log("pdf.php 8");
// poo($fppdf->index[$form_id], '$fppdf->index[$form_id]');
/* there aren't multiples so just return first node */
return $fppdf->index[$form_id][0];
}
return $index;
}
}