forked from jakejackson1/formidable-pro-pdf-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf-custom-display.php
104 lines (83 loc) · 2.6 KB
/
pdf-custom-display.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
<?php
/*
* Securly allow the shortcode [pdf] to be used in custom displays
*/
add_filter( 'frm_display_entry_content', 'FP_Custom_Display::entries_content', 10, 6 );
class FP_Custom_Display
{
private static function format_attrs($attrs)
{
$attr_return = array();
$attr_array = explode(' ', trim($attrs));
foreach($attr_array as $attr)
{
if(strlen($attr) > 0 && strpos($attr, '=') !== false)
{
$attr_block = explode('=', $attr);
$attr_return[$attr_block[0]] = str_replace('"', '', str_replace("'", '', $attr_block[1]));
}
}
return $attr_return;
}
public static function entries_content($new_content, $entry, $shortcodes, $display, $show, $odd)
{
/*
* Get the form/entry ID
*/
$form_id = $entry->form_id;
$lead_id = $entry->id;
/*
* Do a search for our specific shortcode
*/
$pdf_shortcode_search = preg_match_all('/\[pdf( (.+?))?\]((.+?)\[\/pdf\])?/', $new_content, $results);
if($pdf_shortcode_search !== false)
{
/*
* We have a match
* Loop through the results and generate the correct link
*/
foreach($results[0] as $key => $string)
{
$template = $download = $text = false;
/*
* Check if any attributes are avaliable
*/
if(strlen($results[1][$key]) > 0)
{
extract(self::format_attrs($results[1][$key]));
}
/*
* Check if there is defined URL text
*/
if(strlen($results[4][$key]) > 0)
{
$text = $results[4][$key];
}
if($template === false)
{
global $fppdf;
/*
* No template used. Get the first template file found in config
*/
$all_indexes = $fppdf->check_configuration($form_id);
$index = $all_indexes[0];
$template = $fppdf->get_template($form_id);
}
if($text === false)
{
$text = 'View PDF';
}
$nonce = wp_create_nonce('fppdf_' . $form_id . $lead_id. $template);
/*
* Build URL
*/
$url = '<a href="'. site_url() . '/?pdf=1&fid='.$form_id.'&lid='.$lead_id.'&template='.$template .'&nonce='. $nonce ;
$url .= ($download !== false) ? '&download=1' : '';
$url .= ($language !== false) ? '&lang=' . $language : '';
$url .= '">'. $text . '</a>';
$new_content = str_replace($string, $url, $new_content);
}
}
return $new_content;
}
}