-
Notifications
You must be signed in to change notification settings - Fork 0
/
fluentforms-pdf.php
137 lines (112 loc) · 4.47 KB
/
fluentforms-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
<?php
/**
* Plugin Name: Fluent Forms PDF Generator
* Plugin URI: https://wpmanageninja.com/downloads/fluentform-pro-add-on/
* Description: Download entries as pdf with multiple template.
* Author: WPManageNinja LLC
* Author URI: https://wpmanageninja.com
* Version: 1.0.1
* Text Domain: fluentform-pdf
* Domain Path: /assets/languages
*/
/**
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright 2019 WPManageNinja LLC. All rights reserved.
*/
defined('ABSPATH') or die;
define('FLUENTFORM_PDF_VERSION', '1.0.1');
define('FLUENTFORM_PDF_PATH', plugin_dir_path(__FILE__));
define('FLUENTFORM_PDF_URL', plugin_dir_url(__FILE__));
class FluentFormPdf
{
public function boot()
{
if (!defined('FLUENTFORM')) {
return $this->injectDependency();
}
$this->includeFiles();
if (function_exists('wpFluentForm')) {
return $this->registerHooks(wpFluentForm());
}
}
protected function includeFiles()
{
require_once FLUENTFORM_PDF_PATH . 'Classes/Controller/AvailableOptions.php';
require_once FLUENTFORM_PDF_PATH . 'Classes/Controller/FontManager.php';
require_once FLUENTFORM_PDF_PATH . 'Classes/Controller/GlobalPdfManager.php';
require_once FLUENTFORM_PDF_PATH . 'Classes/Templates/TemplateManager.php';
require_once FLUENTFORM_PDF_PATH . 'Classes/Templates/GeneralTemplate.php';
require_once FLUENTFORM_PDF_PATH . 'Classes/Templates/InvoiceTemplate.php';
}
protected function registerHooks($fluentForm)
{
new \FluentFormPdf\Classes\Controller\GlobalPdfManager($fluentForm);
}
/**
* Notify the user about the FluentForm dependency and instructs to install it.
*/
protected function injectDependency()
{
add_action('admin_notices', function () {
$pluginInfo = $this->getFluentFormInstallationDetails();
$class = 'notice notice-error';
$install_url_text = 'Click Here to Install the Plugin';
if ($pluginInfo->action == 'activate') {
$install_url_text = 'Click Here to Activate the Plugin';
}
$message = 'FluentForm pdf Add-On Requires Fluent Forms Plugin, ';
$message .= '<b><a href="' .$pluginInfo->url . '">' . $install_url_text . '</a></b>';
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), $message);
});
}
protected function getFluentFormInstallationDetails()
{
$activation = (object) [
'action' => 'install',
'url' => ''
];
$allPlugins = get_plugins();
if (isset($allPlugins['fluentform/fluentform.php'])) {
$url = wp_nonce_url(
self_admin_url('plugins.php?action=activate&plugin=fluentform/fluentform.php'),
'activate-plugin_fluentform/fluentform.php'
);
$activation->action = 'activate';
} else {
$api = (object) ['slug' => 'fluentform'];
$url = wp_nonce_url(
self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug),
'install-plugin_' . $api->slug
);
}
$activation->url = $url;
return $activation;
}
}
add_action('plugins_loaded', function () {
load_plugin_textdomain(
'fluentform-pdf', false, basename(dirname(__FILE__)) . 'assets/languages'
);
(new FluentFormPdf())->boot();
});
register_activation_hook(__FILE__, function () {
require_once FLUENTFORM_PDF_PATH . '/Classes/Controller/Activator.php';
\FluentFormPdf\Classes\Controller\Activator::activate();
});
register_deactivation_hook( __FILE__, function () {
require_once FLUENTFORM_PDF_PATH . '/Classes/Controller/Activator.php';
\FluentFormPdf\Classes\Controller\Activator::deactivate();
});