forked from jakejackson1/formidable-pro-pdf-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf-settings.php
226 lines (183 loc) · 7.07 KB
/
pdf-settings.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
<?php
/**
* Plugin: Formidable Pro PDF Extended
* File: settings.php
*
* Handles the Formidable Pro Settings page in Wordpress
*/
class FPPDF_Settings {
/*
* Check if we're on the settings page
*/
public static function settings_page() {
/*
* Initialise Formidable Settings Page
*/
if ( rgget('page') == 'formidable-settings' ) {
/*
* Add Formidable Settings Page
*/
add_filter( 'frm_add_settings_section', 'FPPDF_Settings::add_settings_page' );
}
}
public static function add_settings_page( $sections ) {
$sections['PDF'] = array(
'class' => 'FPPDF_Settings',
'function' => 'fppdf_settings_page'
);
return $sections;
}
private static function run_setting_routing() {
/*
* Check if we need to redeploy default PDF templates/styles to the theme folder
*/
if( FP_PDF_DEPLOY === true && rgpost('fp_pdf_deploy') &&
( wp_verify_nonce($_POST['fp_pdf_deploy_nonce'],'fp_pdf_deploy_nonce_action') || wp_verify_nonce($_GET['_wpnonce'],'pdf-extended-filesystem') ) ) {
if(rgpost('upgrade'))
{
/*
* Deploy new template styles
* If we get false returned Wordpress is trying to get
* access details to update files so don't display anything.
*/
if(self::deploy() === false)
{
return true;
}
}
elseif(rgpost('font-initialise'))
{
}
/*elseif(rgpost('cancel'))
{
update_option('gf_pdf_extended_deploy', 'yes');
}*/
}
/*
* If the user hasn't requested deployment and there is a _wpnonce check which one it is
* and call appropriate function
*/
if(isset($_GET['_wpnonce']))
{
/*
* Check if we want to copy the theme files
*/
if(wp_verify_nonce($_GET['_wpnonce'], 'fppdfe_sync_now') )
{
$themes = get_option('fppdfe_switch_theme');
if(isset($themes['old']) && isset($themes['new']) && FPPDF_InstallUpdater::do_theme_switch($themes['old'], $themes['new']) === false)
{
return true;
}
}
}
}
/*
* Shows the GF PDF Extended settings page
*/
public static function fppdf_settings_page() {
/*
* Run the page's configuration/routing options
*/
if ( self::run_setting_routing() === true ) {
return;
}
/*
* Show any messages the plugin might have called
* Because we had to run inside the settings page to correctly display the FTP credential form admin_notices was already called.
* To get around this we can recall it here.
*/
do_action('fppdfe_notices');
/*
* Show the settings page deployment form
*/
?>
<div id="fppdfextended-setting" class="PDF_settings tabs-panel">
<div class="leftcolumn">
<?php
if(FP_PDF_DEPLOY === true)
{
?>
<h2>Initialise Plugin</h2>
<p>Fresh installations and users who have just upgraded will need to initialise Formidable Pro PDF Extended to ensure it works correctly.</p>
<p>Initialisation does a number of important things, including:</p>
<ol>
<li><strong>Fresh Installation</strong>: Copies all the required template and configuration files to a folder called FORMIDABLE_PDF_TEMPLATES in your active theme's directory.<br />
<strong>Upgrading</strong>: Copies the latest default templates and template.css file to the FORMIDABLE_PDF_TEMPLATES folder. <strong>If you modified these files please back them up before re-initialising as they will be removed</strong>.
</li>
<li>Unzips the mPDF package</li>
<li>Installs any fonts found in the FORMIDABLE_PDF_TEMPLATES/fonts/ folder</li>
</ol>
<?php wp_nonce_field('fp_pdf_deploy_nonce_action','fp_pdf_deploy_nonce'); ?>
<input type="hidden" name="fp_pdf_deploy" value="1">
<?php
/*
* Remove the cancel feature for the moment
*
if(get_option('gf_pdf_extended_deploy') == 'no') { ?>
<input type="submit" value="Cancel Deployment" class="button" id="cancelupgrade" name="cancel">
<?php } */ ?>
<input type="submit" value="Initialise Plugin" class="button" id="plugin-initialise" name="plugin-initialise">
<input type="submit" value="Initialise Fonts Only" class="button" id="font-initialise" name="font-initialise">
<?php } ?>
</div>
<div class="rightcolumn">
<h2>Welcome to Formidable Pro PDF Extended Beta!</h2>
<p>Your one of the very first to try Formidable Pro PDF Extended but keep in mind, with great power comes great responsibility... This software may contain bugs that weren't picked up during initial development (which is why we are having an open beta). It <strong>should not be used on a production server</strong>.</p>
<p>If you have any issues using the software, find a bug or have an idea to make the plugin even better then please <a href="http://formidablepropdfextended.com/support/formidable-pro-pdf-extended/beta-feedbackbug-reports/">head to our support forum</a> and start a new topic. If you don't report it then we can't fix it! </p>
</div>
<?php
}
/*
* Deploy the latest template files
*/
public static function ajax_deploy()
{
/* check nonce and permission */
if ( ! wp_verify_nonce( $_POST['nonce'], 'fppdfe_nonce' ) || !current_user_can('frm_edit_forms') )
{
print json_encode(array('error' => 'Access denied. Failed to initialise fonts.'));
}
$results = FPPDF_InstallUpdater::pdf_extended_activate();
/*
* Capture the notices generated if there is an error and display it to the user
*/
if($results !== true)
{
ob_start();
do_action('fppdfe_notices');
$message = ob_get_contents();
ob_end_clean();
print json_encode(array('error' => $message));
} else {
print json_encode( array( 'message' => self::pdf_deploy_success() ) );
}
exit;
}
public static function pdf_deploy_success() {
$msg = '<div id="fppdfe_message" class="updated"><p>';
$msg .= __( 'You\'ve successfully initialised Formidable Pro PDF Extended.', 'ffpdf' );
$msg .= '</p></div>';
return $msg;
}
public static function initialise_fonts() {
/* check nonce and permission */
if ( ! wp_verify_nonce( $_POST['nonce'], 'fppdfe_nonce' ) || !current_user_can('frm_edit_forms') )
{
print json_encode(array('error' => 'Access denied. Failed to initialise fonts.'));
}
/*
* We only want to reinitialise the font files and configuration
*/
FPPDF_InstallUpdater::initialise_fonts();
/*
* Output the message back to the user
*/
ob_start();
do_action('fppdfe_notices');
$message = ob_get_contents();
ob_end_clean();
print json_encode(array('message' => $message));
exit;
}
}