1: <?php
2:
3: 4: 5:
6: abstract class Quform_Admin_Page
7: {
8: const BAD_REQUEST = 1;
9:
10: const NO_PERMISSION = 2;
11:
12: const NONCE_CHECK_FAILED = 3;
13:
14: 15: 16: 17: 18:
19: protected $template;
20:
21: 22: 23: 24: 25:
26: protected $view;
27:
28: 29: 30:
31: protected $viewFactory;
32:
33: 34: 35: 36: 37:
38: protected $messages = array();
39:
40: 41: 42:
43: protected $repository;
44:
45: 46: 47: 48:
49: public function __construct(Quform_ViewFactory $viewFactory, Quform_Repository $repository)
50: {
51: $this->viewFactory = $viewFactory;
52: $this->repository = $repository;
53: }
54:
55: 56: 57: 58: 59:
60: public function bootstrap()
61: {
62: $this->init();
63:
64: $this->view = $this->viewFactory->create($this->template, array('page' => $this));
65:
66: return $this;
67: }
68:
69: 70: 71: 72: 73:
74: public function init()
75: {
76:
77: }
78:
79: 80: 81:
82: public function enqueueAssets()
83: {
84: $this->enqueueStyles();
85: $this->enqueueScripts();
86: }
87:
88: 89: 90:
91: protected function enqueueStyles()
92: {
93: wp_enqueue_style('qfb-fontello', Quform::url('fonts/fontello/css/qfb-icons.css'), array(), QUFORM_VERSION);
94:
95: $loadLegacyIcons = false;
96:
97: if (defined('QUFORM_MAILCHIMP_VERSION') && version_compare(QUFORM_MAILCHIMP_VERSION, '1.2.0', '<=')) {
98: $loadLegacyIcons = true;
99: }
100:
101: if (defined('QUFORM_ZAPIER_VERSION') && version_compare(QUFORM_ZAPIER_VERSION, '1.0.3', '<=')) {
102: $loadLegacyIcons = true;
103: }
104:
105: if (apply_filters('quform_load_legacy_icons', $loadLegacyIcons)) {
106: wp_enqueue_style('material-icons-legacy-quform', Quform::adminUrl('fonts/material-icons.legacy.min.css'), array(), QUFORM_VERSION);
107: }
108:
109: wp_enqueue_style('material-icons-quform', Quform::adminUrl('fonts/material-icons.min.css'), array(), QUFORM_VERSION);
110: wp_enqueue_style('quform-admin', Quform::adminUrl('css/admin.min.css'), array(), QUFORM_VERSION);
111:
112: if (is_rtl()) {
113: wp_enqueue_style('quform-rtl', Quform::adminUrl('css/rtl.min.css'), array(), QUFORM_VERSION);
114: }
115: }
116:
117: 118: 119:
120: protected function enqueueScripts()
121: {
122: wp_enqueue_script('jquery-scroll-to', Quform::url('js/jquery.scrollTo.min.js'), array('jquery'), '2.1.2', true);
123: wp_enqueue_script('quform-core', Quform::adminUrl('js/core.min.js'), array('jquery'), QUFORM_VERSION, true);
124:
125: wp_localize_script('quform-core', 'quformCoreL10n', array(
126: 'ajaxUrl' => admin_url('admin-ajax.php'),
127: 'pluginUrl' => Quform::url(),
128: 'adminImagesUrl' => Quform::adminUrl('images/'),
129: 'ajaxError' => __('Ajax error', 'quform'),
130: 'thisFieldIsRequired' => __('This field is required', 'quform'),
131: 'invalidEmailAddress' => __('Invalid email address', 'quform'),
132: 'selectImage' => __('Select Image', 'quform'),
133: 'select' => __('Select', 'quform'),
134: 'noResultsFound' => __('No results found.', 'quform'),
135: 'searchingDots' => __('Searching...', 'quform'),
136: 'errorLoading' => __('The results could not be loaded.', 'quform'),
137:
138: 'inputTooShort' => __('Please enter %s or more characters.', 'quform'),
139: 'removeAllItems' => __('Remove all items', 'quform')
140: ));
141: }
142:
143: 144: 145: 146: 147:
148: public function process()
149: {
150:
151: }
152:
153: 154: 155: 156: 157:
158: protected function getAdminTitle()
159: {
160: return '';
161: }
162:
163: 164: 165: 166: 167: 168:
169: public function setAdminTitle($adminTitle)
170: {
171: $title = $this->getAdminTitle();
172:
173: if (Quform::isNonEmptyString($title)) {
174:
175: $adminTitle = sprintf(__('%1$s ‹ %2$s — WordPress', 'quform'), esc_html($title), esc_html(get_bloginfo('name')));
176: }
177:
178: return $adminTitle;
179: }
180:
181: 182: 183: 184: 185:
186: public function display()
187: {
188: return $this->view->render();
189: }
190:
191: 192: 193: 194: 195: 196: 197:
198: public function addMessage($type, $message = '')
199: {
200: if (is_array($type)) {
201: return $this->addMessage($type['type'], $type['message']);
202: } else {
203: $message = array('type' => $type, 'message' => $message);
204: $this->messages[] = $message;
205: }
206:
207: return $this;
208: }
209:
210: 211: 212: 213: 214:
215: public function getMessages()
216: {
217: return $this->messages;
218: }
219:
220: 221: 222: 223: 224:
225: public function getMessagesHtml()
226: {
227: $output = '';
228:
229: if (count($this->getMessages())) {
230: $output .= '<div id="qfb-page-messages" class="qfb-page-messages">';
231:
232: foreach ($this->getMessages() as $message) {
233: $output .= '<div class="qfb-message-box qfb-message-box-' . $message['type'] . '"><div class="qfb-message-box-inner">' . $message['message'] . '</div></div>';
234: }
235:
236: $output .= '</div>';
237: }
238:
239: return $output;
240: }
241:
242: 243: 244: 245: 246: 247: 248:
249: public function getNavHtml(array $currentForm = null, array $extra = array())
250: {
251: $links = array(
252: array(
253: 'cap' => 'quform_view_dashboard',
254: 'href' => admin_url('admin.php?page=quform.dashboard'),
255: 'class' => 'dashboard',
256: 'icon' => '<i class="qfb-mdi qfb-mdi-dashboard"></i>',
257: 'text' => __('Dashboard', 'quform')
258: ),
259: array(
260: 'cap' => 'quform_list_forms',
261: 'href' => admin_url('admin.php?page=quform.forms'),
262: 'class' => 'forms',
263: 'icon' => '<i class="qfb-mdi qfb-mdi-view_stream"></i>',
264: 'text' => __('Forms', 'quform')
265: ),
266: array(
267: 'cap' => 'quform_view_entries',
268: 'href' => admin_url('admin.php?page=quform.entries'),
269: 'class' => 'entries',
270: 'icon' => '<i class="qfb-mdi qfb-mdi-message"></i>',
271: 'text' => __('Entries', 'quform')
272: ),
273: array(
274: 'cap' => 'quform_view_tools',
275: 'href' => admin_url('admin.php?page=quform.tools'),
276: 'class' => 'tools',
277: 'icon' => '<i class="qfb-mdi qfb-mdi-build"></i>',
278: 'text' => __('Tools', 'quform')
279: ),
280: array(
281: 'cap' => 'quform_settings',
282: 'href' => admin_url('admin.php?page=quform.settings'),
283: 'class' => 'settings',
284: 'icon' => '<i class="qfb-mdi qfb-mdi-settings"></i>',
285: 'text' => __('Settings', 'quform')
286: ),
287: array(
288: 'cap' => 'quform_help',
289: 'href' => admin_url('admin.php?page=quform.help'),
290: 'class' => 'help',
291: 'icon' => '<i class="qfb-mdi qfb-mdi-help_outline"></i>',
292: 'text' => __('Help', 'quform')
293: )
294: );
295:
296: $visible = array();
297: foreach ($links as $link) {
298: if (current_user_can($link['cap'])) {
299: $visible[] = $link;
300: }
301: }
302:
303: if ( ! count($visible)) {
304: return '';
305: }
306:
307: $currentUserId = get_current_user_id();
308: $userOrderBy = get_user_meta($currentUserId, 'quform_forms_order_by', true);
309: $userOrder = get_user_meta($currentUserId, 'quform_forms_order', true);
310:
311: $forms = $this->repository->getForms(array(
312: 'orderby' => in_array($userOrderBy, array('id', 'name', 'entries', 'active', 'created_at', 'updated_at')) ? $userOrderBy : 'updated_at',
313: 'order' => in_array($userOrder, array('asc', 'desc')) ? strtoupper($userOrder) : 'DESC',
314: 'limit' => 50
315: ));
316:
317: ob_start();
318: ?>
319: <div id="qfb-nav" class="qfb-cf">
320: <?php
321: printf(
322: '<a class="qfb-logo"%s></a>',
323: current_user_can('quform_view_dashboard') ? sprintf(' href="%s"', esc_url(admin_url('admin.php?page=quform.dashboard'))) : ''
324: );
325: ?>
326:
327: <?php echo $this->getExtraHtml(10, $extra); ?>
328:
329: <div class="qfb-nav-item qfb-nav-item-menu">
330: <a class="qfb-nav-item-link qfb-nav-popup-trigger"><i class="qfb-icon qfb-icon-bars"></i></a>
331: <div class="qfb-nav-popup-content">
332: <ul class="qfb-nav-menu">
333: <?php
334: foreach ($visible as $item) {
335: echo '<li class="qfb-page-' . esc_attr($item['class']) . '"><a href="' . esc_url($item['href']) . '">' . $item['icon'] . ' <span>' . esc_html($item['text']) . '</span></a></li>';
336: }
337: ?>
338: </ul>
339: </div>
340: </div>
341:
342: <?php echo $this->getExtraHtml(20, $extra); ?>
343:
344: <?php if (current_user_can('quform_view_entries') || current_user_can('quform_edit_forms')) : ?>
345:
346: <div class="qfb-nav-item qfb-nav-item-form-switcher">
347: <a class="qfb-nav-item-link qfb-nav-popup-trigger"><i class="qfb-icon qfb-icon-folder-open-o"></i></a>
348: <div class="qfb-form-switcher qfb-nav-popup-content">
349: <ul class="qfb-nav-menu qfb-cf">
350: <?php
351: if (is_array($currentForm) && ! empty($currentForm['id'])) {
352: echo $this->getFormSwitcherItemHtml($currentForm, true);
353: }
354:
355: foreach ($forms as $form) {
356: if (is_array($currentForm) && ! empty($currentForm['id']) && $form['id'] == $currentForm['id']) {
357: continue;
358: }
359:
360: echo $this->getFormSwitcherItemHtml($form);
361: }
362: ?>
363: <li class="qfb-cf qfb-form-switcher-add-form-button"><?php printf('<a href="%s">%s</a>', esc_url(admin_url('admin.php?page=quform.forms&sp=add')), esc_html__('Add New', 'quform')); ?></li>
364: </ul>
365: </div>
366: </div>
367:
368: <?php endif; ?>
369:
370: <?php echo $this->getExtraHtml(30, $extra); ?>
371:
372: <?php if (current_user_can('quform_add_forms')) : ?>
373: <div class="qfb-nav-item qfb-nav-item-add">
374: <a class="qfb-nav-item-link" title="<?php esc_attr_e('Create a new form', 'quform'); ?>" href="<?php echo esc_url(admin_url('admin.php?page=quform.forms&sp=add')); ?>"><i class="qfb-mdi qfb-mdi-add_circle"></i></a>
375: </div>
376: <?php endif; ?>
377:
378: <?php echo $this->getExtraHtml(40, $extra); ?>
379:
380: <div class="qfb-nav-item qfb-nav-item-right qfb-nav-item-help">
381: <a class="qfb-nav-item-link qfb-nav-popup-trigger"><i class="qfb-icon qfb-icon-question"></i></a>
382: <div class="qfb-nav-popup-content">
383: <ul class="qfb-nav-menu qfb-cf">
384: <li class="qfb-cf"><a href="https://support.themecatcher.net/" target="_blank"><i class="qfb-icon qfb-icon-life-ring"></i><?php esc_html_e('Visit help site', 'quform'); ?></a></li>
385: <li class="qfb-cf"><a href="https://support.themecatcher.net/quform-wordpress-v2" target="_blank"><i class="qfb-icon qfb-icon-book"></i><?php esc_html_e('View documentation', 'quform'); ?></a></li>
386: <li class="qfb-cf"><a href="https://support.themecatcher.net/forums" target="_blank"><i class="qfb-icon qfb-icon-comments"></i><?php esc_html_e('Support forum', 'quform'); ?></a></li>
387: <li class="qfb-cf"><a href="https://www.youtube.com/channel/UCoyKi9_M7ECFYK-w7ZqNMVg" target="_blank"><i class="qfb-icon qfb-icon-play"></i><?php esc_html_e('Video tutorials', 'quform'); ?></a></li>
388: </ul>
389: </div>
390:
391: </div>
392:
393: <?php echo $this->getExtraHtml(50, $extra); ?>
394:
395: </div>
396: <?php
397:
398: return ob_get_clean();
399: }
400:
401: 402: 403: 404: 405: 406: 407:
408: protected function getFormSwitcherItemHtml(array $form, $highlight = false)
409: {
410: $name = Quform::isNonEmptyString($form['name']) ? $form['name'] : __('(no title)', 'quform');
411:
412: if ($this instanceof Quform_Admin_Page_Entries_List ||
413: $this instanceof Quform_Admin_Page_Entries_View ||
414: $this instanceof Quform_Admin_Page_Entries_Edit ||
415: ! current_user_can('quform_edit_forms')
416: ) {
417: $linkUrl = sprintf(admin_url('admin.php?page=quform.entries&id=%d'), $form['id']);
418: } else {
419: $linkUrl = sprintf(admin_url('admin.php?page=quform.forms&sp=edit&id=%d'), $form['id']);
420: }
421:
422: $output = sprintf('<li class="qfb-cf%s">', $highlight ? ' qfb-highlight' : '');
423: $output .= sprintf('<a title="%s" href="%s">', Quform::escape($name), esc_url($linkUrl));
424: $output .= Quform::escape($name);
425: $output .= '<span class="qfb-fade-overflow"></span></a>';
426:
427: $output .= '<span class="qfb-form-switcher-icons">';
428:
429: if (current_user_can('quform_view_entries')) {
430: $output .= sprintf('<a href="%s"><i title="%s" class="qfb-mdi qfb-mdi-chat"></i></a>', esc_url(admin_url('admin.php?page=quform.entries&id=' . $form['id'])), esc_attr__('View Entries', 'quform'));
431: }
432:
433: if (current_user_can('quform_edit_forms')) {
434: $output .= sprintf('<a href="%s"><i title="%s" class="qfb-icon qfb-icon-pencil"></i></a>', esc_url(admin_url('admin.php?page=quform.forms&sp=edit&id=' . $form['id'])), esc_attr__('Edit', 'quform'));
435: }
436:
437: $output .= '</span>';
438:
439: $output .= '</li>';
440:
441: return $output;
442: }
443:
444: 445: 446: 447: 448: 449: 450:
451: protected function getExtraHtml($index, array $extra)
452: {
453: ob_start();
454:
455: if (isset($extra[$index])) {
456: echo $extra[$index];
457: }
458:
459: do_action('quform_admin_nav', $index, $this);
460:
461: return ob_get_clean();
462: }
463: }
464: