1: <?php
2:
3: 4: 5:
6: class Quform_Admin_InsertForm
7: {
8: 9: 10:
11: protected $repository;
12:
13: 14: 15:
16: protected $options;
17:
18: 19: 20:
21: protected $printedAssets = false;
22:
23: 24: 25: 26:
27: public function __construct(Quform_Repository $repository, Quform_Options $options)
28: {
29: $this->repository = $repository;
30: $this->options = $options;
31: }
32:
33: 34: 35:
36: public function registerScripts()
37: {
38: wp_register_style('quform-insert-form', Quform::adminUrl('css/insert-form.min.css'), array(), QUFORM_VERSION);
39: }
40:
41: 42: 43:
44: public function button()
45: {
46: if ( ! $this->options->get('insertFormButton') || ! current_user_can('quform_list_forms')) {
47: return;
48: }
49:
50:
51: if (isset($_GET['page']) && $_GET['page'] == 'quform.forms') {
52: return;
53: }
54:
55: if ( ! $this->printedAssets) {
56: wp_print_styles('quform-insert-form');
57: $this->printedAssets = true;
58: }
59:
60: printf(
61: '<button type="button" class="button qfb-insert-form-trigger" onclick="%s" data-l10n="%s"><span></span>%s</button>',
62: sprintf("!function(o){window.quformInsertForm?window.quformInsertForm.loadPopup():jQuery.getScript('%s',function(){window.quformInsertForm.init(o)})}(this);", esc_js(esc_url(Quform::adminUrl('js/insert-form.min.js')))),
63: Quform::escape(wp_json_encode(array(
64: 'ajaxUrl' => admin_url('admin-ajax.php'),
65: 'selectForm' => __('Please select a form first', 'quform'),
66: 'couldNotSendToEditor' => __('The shortcode could not be sent to the editor, please copy it from the preview area and paste it into the editor', 'quform')
67: ))),
68: esc_html__('Add Form', 'quform')
69: );
70: }
71:
72: 73: 74:
75: public function display()
76: {
77: $orderBy = get_user_meta(get_current_user_id(), 'quform_forms_order_by', true);
78: $order = get_user_meta(get_current_user_id(), 'quform_forms_order', true);
79: $forms = $this->repository->formsToSelectArray(null, $orderBy, $order);
80: ?>
81: <div class="qfb-popup qfb-insert-form-popup">
82: <div class="qfb-popup-content">
83: <span class="qfb-insert-form-cancel"><span></span></span>
84: <div class="qfb-settings-heading"><?php esc_html_e('Insert a form', 'quform'); ?></div>
85: <?php if (count($forms)) : ?>
86: <div class="qfb-sub-setting">
87: <select id="qfb-insert-form-id">
88: <option value=""><?php esc_html_e('Select a form', 'quform'); ?></option>
89: <?php foreach ($forms as $id => $name) : ?>
90: <option value="<?php echo Quform::escape($id); ?>"><?php echo Quform::escape($name); ?></option>
91: <?php endforeach; ?>
92: </select>
93: </div>
94: <div class="qfb-sub-setting">
95: <div class="qfb-sub-setting-label">
96: <label for="qfb-insert-form-show-title"><?php esc_html_e('Show form title', 'quform'); ?></label>
97: </div>
98: <div class="qfb-sub-setting-inner">
99: <div class="qfb-sub-setting-input">
100: <input type="checkbox" id="qfb-insert-form-show-title" class="qfb-mini-toggle" checked>
101: <label for="qfb-insert-form-show-title"></label>
102: </div>
103: </div>
104: </div>
105: <div class="qfb-sub-setting">
106: <div class="qfb-sub-setting-label">
107: <label for="qfb-insert-form-show-description"><?php esc_html_e('Show form description', 'quform'); ?></label>
108: </div>
109: <div class="qfb-sub-setting-inner">
110: <div class="qfb-sub-setting-input">
111: <input type="checkbox" id="qfb-insert-form-show-description" class="qfb-mini-toggle" checked>
112: <label for="qfb-insert-form-show-description"></label>
113: </div>
114: </div>
115: </div>
116: <div class="qfb-sub-setting">
117: <div class="qfb-sub-setting-label">
118: <label for="qfb-insert-form-popup"><?php esc_html_e('Popup form', 'quform'); ?></label>
119: </div>
120: <div class="qfb-sub-setting-inner">
121: <div class="qfb-sub-setting-input">
122: <input type="checkbox" id="qfb-insert-form-popup" class="qfb-mini-toggle">
123: <label for="qfb-insert-form-popup"></label>
124: </div>
125: </div>
126: </div>
127: <div class="qfb-sub-setting">
128: <div class="qfb-sub-setting-label">
129: <label for="qfb-insert-form-content"><?php esc_html_e('Content', 'quform'); ?></label>
130: </div>
131: <div class="qfb-sub-setting-inner">
132: <div class="qfb-sub-setting-input">
133: <textarea id="qfb-insert-form-content"></textarea>
134: <p class="qfb-description"><?php esc_html_e('The text or HTML to trigger the popup, shortcodes can also be used.', 'quform'); ?></p>
135: </div>
136: </div>
137: </div>
138: <div class="qfb-sub-setting">
139: <div class="qfb-sub-setting-label">
140: <label for="qfb-insert-form-width"><?php esc_html_e('Width (optional)', 'quform'); ?></label>
141: </div>
142: <div class="qfb-sub-setting-inner">
143: <div class="qfb-sub-setting-input">
144: <input type="text" id="qfb-insert-form-width">
145: <p class="qfb-description"><?php esc_html_e('The width of the popup, any CSS width or number is accepted.', 'quform'); ?></p>
146: </div>
147: </div>
148: </div>
149: <div class="qfb-sub-setting">
150: <div class="qfb-sub-setting-label">
151: <label for="qfb-insert-form-options"><?php esc_html_e('Options (optional)', 'quform'); ?></label>
152: </div>
153: <div class="qfb-sub-setting-inner">
154: <div class="qfb-sub-setting-input">
155: <input type="text" id="qfb-insert-form-options">
156: <p class="qfb-description">
157: <?php
158: printf(
159:
160: esc_html__('JSON encoded options to pass to the popup script, %1$sexamples%2$s.', 'quform'),
161: '<a href="https://support.themecatcher.net/quform-wordpress-v2/guides/customization/popup-script-options" target="_blank">',
162: '</a>'
163: );
164: ?>
165: </p>
166: </div>
167: </div>
168: </div>
169: <div class="qfb-insert-form-button-wrap qfb-cf">
170: <button type="button" class="button button-primary qfb-insert-form-go"><?php esc_html_e('Insert', 'quform'); ?></button>
171: </div>
172: <div class="qfb-insert-form-preview">
173: <p><?php esc_html_e('If you are having trouble inserting the form, copy and paste the code below into the page content.', 'quform'); ?></p>
174: <input type="text" id="qfb-insert-form-preview" readonly>
175: </div>
176: <?php else : ?>
177: <?php
178: if (current_user_can('quform_add_forms')) {
179:
180: printf(esc_html__('No forms found, %1$sclick here to create one%2$s.', 'quform'), '<a href="' . esc_url(admin_url('admin.php?page=quform.forms&sp=add')) . '">', '</a>');
181: } else {
182: esc_html_e('No forms found.', 'quform');
183: }
184: ?>
185: <?php endif; ?>
186: </div>
187: <div class="qfb-popup-overlay"></div>
188: </div>
189: <?php
190: wp_die();
191: }
192: }
193: