Overview

Namespaces

  • None
  • Quform
    • Traduttore_Registry

Classes

  • Quform
  • Quform_Admin_InsertForm
  • Quform_Admin_Page
  • Quform_Admin_Page_Controller
  • Quform_Admin_Page_Dashboard
  • Quform_Admin_Page_Entries
  • Quform_Admin_Page_Entries_Edit
  • Quform_Admin_Page_Entries_List
  • Quform_Admin_Page_Entries_View
  • Quform_Admin_Page_Factory
  • Quform_Admin_Page_Forms_Add
  • Quform_Admin_Page_Forms_Edit
  • Quform_Admin_Page_Forms_List
  • Quform_Admin_Page_Help
  • Quform_Admin_Page_Preview
  • Quform_Admin_Page_Settings
  • Quform_Admin_Page_Tools
  • Quform_Admin_Page_Tools_ExportEntries
  • Quform_Admin_Page_Tools_ExportForm
  • Quform_Admin_Page_Tools_Home
  • Quform_Admin_Page_Tools_ImportForm
  • Quform_Admin_Page_Tools_Migrate
  • Quform_Admin_Page_Tools_Uninstall
  • Quform_Api
  • Quform_Block
  • Quform_Builder
  • Quform_Captcha
  • Quform_ClassLoader
  • Quform_Confirmation
  • Quform_Container
  • Quform_Dashboard_Widget
  • Quform_Dispatcher
  • Quform_Element
  • Quform_Element_Captcha
  • Quform_Element_Checkbox
  • Quform_Element_Column
  • Quform_Element_Container
  • Quform_Element_Container_Iterator
  • Quform_Element_Date
  • Quform_Element_Email
  • Quform_Element_Factory
  • Quform_Element_Field
  • Quform_Element_File
  • Quform_Element_Group
  • Quform_Element_Hidden
  • Quform_Element_Honeypot
  • Quform_Element_Html
  • Quform_Element_Multi
  • Quform_Element_Multiselect
  • Quform_Element_Name
  • Quform_Element_Page
  • Quform_Element_Password
  • Quform_Element_Radio
  • Quform_Element_Recaptcha
  • Quform_Element_Row
  • Quform_Element_Select
  • Quform_Element_Submit
  • Quform_Element_Text
  • Quform_Element_Textarea
  • Quform_Element_Time
  • Quform_Entry_Controller
  • Quform_Entry_Exporter
  • Quform_Entry_List_Settings
  • Quform_Entry_List_Table
  • Quform_Entry_Processor
  • Quform_Entry_UserSearcher
  • Quform_Filter_Abstract
  • Quform_Filter_Alpha
  • Quform_Filter_AlphaNumeric
  • Quform_Filter_Digits
  • Quform_Filter_Regex
  • Quform_Filter_Static
  • Quform_Filter_StripTags
  • Quform_Filter_Trim
  • Quform_Form
  • Quform_Form_Controller
  • Quform_Form_Exporter
  • Quform_Form_Factory
  • Quform_Form_Importer
  • Quform_Form_Iterator
  • Quform_Form_List_Settings
  • Quform_Form_List_Table
  • Quform_Form_Processor
  • Quform_License
  • Quform_Migrator
  • Quform_NonceRefresher
  • Quform_Notification
  • Quform_Notification_Resender
  • Quform_Options
  • Quform_Permissions
  • Quform_Repository
  • Quform_ScriptLoader
  • Quform_Session
  • Quform_Settings
  • Quform_Shortcode
  • Quform_Themes
  • Quform_TokenReplacer
  • Quform_Toolbar
  • Quform_Translations
  • Quform_Updater
  • Quform_Upgrader
  • Quform_Uploader
  • Quform_Validator_Abstract
  • Quform_Validator_Alpha
  • Quform_Validator_AlphaNumeric
  • Quform_Validator_Array
  • Quform_Validator_Captcha
  • Quform_Validator_Date
  • Quform_Validator_Digits
  • Quform_Validator_Duplicate
  • Quform_Validator_Email
  • Quform_Validator_FileUpload
  • Quform_Validator_GreaterThan
  • Quform_Validator_Honeypot
  • Quform_Validator_Identical
  • Quform_Validator_InArray
  • Quform_Validator_Length
  • Quform_Validator_LessThan
  • Quform_Validator_Recaptcha
  • Quform_Validator_Regex
  • Quform_Validator_Required
  • Quform_Validator_Static
  • Quform_Validator_Time
  • Quform_View
  • Quform_ViewFactory
  • Quform_Widget_Form
  • Quform_Widget_Popup

Interfaces

  • Quform_Attachable
  • Quform_Element_Editable
  • Quform_Filter_Interface
  • Quform_Validator_Interface

Constants

  • Quform\Traduttore_Registry\TRANSIENT_KEY_PLUGIN
  • Quform\Traduttore_Registry\TRANSIENT_KEY_THEME

Functions

  • Quform\Traduttore_Registry\add_project
  • Quform\Traduttore_Registry\clean_translations_cache
  • Quform\Traduttore_Registry\get_available_locales
  • Quform\Traduttore_Registry\get_installed_translations
  • Quform\Traduttore_Registry\get_translations
  • Quform\Traduttore_Registry\register_clean_translations_cache
  • Quform\Traduttore_Registry\sanitize_date
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: /**
  4:  * @copyright Copyright (c) 2009-2022 ThemeCatcher (https://www.themecatcher.net)
  5:  */
  6: class Quform_Admin_Page_Entries_List extends Quform_Admin_Page_Entries
  7: {
  8:     /**
  9:      * @var Quform_Form_Factory
 10:      */
 11:     protected $formFactory;
 12: 
 13:     /**
 14:      * @var Quform_Options
 15:      */
 16:     protected $options;
 17: 
 18:     /**
 19:      * @param  Quform_ViewFactory       $viewFactory
 20:      * @param  Quform_Repository        $repository
 21:      * @param  Quform_Form_Factory      $formFactory
 22:      * @param  Quform_Options           $options
 23:      */
 24:     public function __construct(Quform_ViewFactory $viewFactory, Quform_Repository $repository,
 25:                                 Quform_Form_Factory $formFactory, Quform_Options $options)
 26:     {
 27:         parent::__construct($viewFactory, $repository);
 28: 
 29:         $this->formFactory = $formFactory;
 30:         $this->options = $options;
 31:     }
 32: 
 33:     public function init()
 34:     {
 35:         $this->template = QUFORM_TEMPLATE_PATH . '/admin/entries/list.php';
 36:     }
 37: 
 38:     /**
 39:      * Enqueue the page styles
 40:      */
 41:     protected function enqueueStyles()
 42:     {
 43:         wp_enqueue_style('qtip2', Quform::url('css/jquery.qtip.min.css'), array(), '3.0.4');
 44:         wp_enqueue_style('spectrum', Quform::adminUrl('css/spectrum.min.css'), array(), '1.8.1');
 45: 
 46:         parent::enqueueStyles();
 47:     }
 48: 
 49:     /**
 50:      * Enqueue the page scripts
 51:      */
 52:     protected function enqueueScripts()
 53:     {
 54:         wp_enqueue_script('jeditable', Quform::adminUrl('js/jquery.jeditable.min.js'), array('jquery'), '2.0.19', true);
 55:         wp_enqueue_script('qtip2', Quform::url('js/jquery.qtip.min.js'), array('jquery'), '3.0.4', true);
 56:         wp_enqueue_script('spectrum', Quform::adminUrl('js/spectrum.min.js'), array(), '1.8.1', true);
 57: 
 58:         parent::enqueueScripts();
 59: 
 60:         wp_enqueue_script('sortablejs', Quform::adminUrl('js/Sortable.min.js'), array(), '1.15.7', true);
 61:         wp_enqueue_script('quform-entries-list', Quform::adminUrl('js/entries.list.min.js'), array('jquery', 'sortablejs'), QUFORM_VERSION, true);
 62: 
 63:         wp_localize_script('quform-entries-list', 'quformEntriesListL10n', array(
 64:             'singleDeleteEntryMessage' => __('Are you sure you want to delete this entry? All data for this entry will be lost and this cannot be undone.', 'quform'),
 65:             'pluralDeleteEntryMessage' => __('Are you sure you want to delete these entries? All data for these entries will be lost and this cannot be undone.', 'quform'),
 66:             'saveEntriesTableSettingsNonce' => wp_create_nonce('quform_save_entries_table_settings'),
 67:             'entryLabelEditHtml' => $this->getEntryLabelEditHtml()
 68:         ));
 69:     }
 70: 
 71:     /**
 72:      * Process this page and send data to the view
 73:      */
 74:     public function process()
 75:     {
 76:         if ( ! current_user_can('quform_view_entries')) {
 77:             wp_die(__( 'You do not have sufficient permissions to access this page.', 'quform'), 403);
 78:         }
 79: 
 80:         // Deal with read/unread/delete actions
 81:         $this->processActions();
 82: 
 83:         if (isset($_GET['id']) && Quform::isNonEmptyString($_GET['id'])) {
 84:             $config = $this->repository->getConfig((int) $_GET['id']);
 85: 
 86:             if ($config === null) {
 87:                 wp_die(esc_html__('The form could not be found. Perhaps it was deleted?', 'quform'));
 88:             }
 89:         } else {
 90:             $defaultId = (int) apply_filters('quform_entries_default_form_id', 0);
 91:             $config = $defaultId > 0 ? $this->repository->getConfig($defaultId) : null;
 92: 
 93:             if ($config === null) {
 94:                 $config = $this->repository->firstConfig();
 95:             }
 96: 
 97:             if ($config === null) {
 98:                 // There are no forms, redirect
 99:                 wp_safe_redirect(admin_url('admin.php?page=quform.forms'));
100:                 exit;
101:             }
102:         }
103: 
104:         $config['environment'] = 'listEntry';
105: 
106:         $form = $this->formFactory->create($config);
107: 
108:         $this->addPageMessages();
109: 
110:         $table = new Quform_Entry_List_Table($this, $form, $this->repository, $this->options);
111:         $table->prepare_items();
112: 
113:         $perPage = get_user_meta(get_current_user_id(), 'quform_entries_per_page', true);
114:         if ( ! is_numeric($perPage)) {
115:             $perPage = 20;
116:         }
117: 
118:         $this->view->with(array(
119:             'form' => $form,
120:             'table' => $table,
121:             'perPage' => $perPage,
122:             'labels' => $this->repository->getFormEntryLabels($form->getId())
123:         ));
124: 
125:         add_filter('removable_query_args', array($this, 'removableQueryArgs'));
126:     }
127: 
128:     protected function processActions()
129:     {
130:         $nonce = Quform::get($_GET, '_wpnonce');
131:         $action = null;
132:         $ids = array();
133: 
134:         if (isset($_GET['eid'])) {
135:             $action = Quform::get($_GET, 'action');
136:             $ids = (int) $_GET['eid'];
137:         } elseif (isset($_GET['eids'])) {
138:             $action = $this->getBulkAction();
139:             $ids = (array) Quform::get($_GET, 'eids');
140:             $ids = array_map('intval', $ids);
141:         } elseif (isset($_GET['delete_all'])) {
142:             $action = 'delete_all';
143:         }
144: 
145:         if ($action == null) {
146:             if (Quform::get($_GET, '_wp_http_referer')) {
147:                 wp_safe_redirect(esc_url_raw(remove_query_arg(array('_wp_http_referer', '_wpnonce'), wp_unslash($_SERVER['REQUEST_URI']))));
148:                 exit;
149:             }
150: 
151:             return;
152:         }
153: 
154:         do_action('quform_pre_process_entries_list_action', $action, $ids);
155: 
156:         $returnUrl = remove_query_arg(array('action', 'action2', 'eid', 'eids', 'read', 'unread', 'trashed', 'deleted', 'error'), wp_get_referer());
157: 
158:         switch ($action) {
159:             case 'read':
160:                 $result = $this->processReadAction($ids, $nonce);
161:                 $returnUrl = add_query_arg($result, $returnUrl);
162:                 break;
163:             case 'unread':
164:                 $result = $this->processUnreadAction($ids, $nonce);
165:                 $returnUrl = add_query_arg($result, $returnUrl);
166:                 break;
167:             case 'trash':
168:                 $result = $this->processTrashAction($ids, $nonce);
169:                 $returnUrl = add_query_arg($result, $returnUrl);
170:                 break;
171:             case 'untrash':
172:                 $result = $this->processUntrashAction($ids, $nonce);
173:                 $returnUrl = add_query_arg($result, $returnUrl);
174:                 break;
175:             case 'delete':
176:                 $result = $this->processDeleteAction($ids, $nonce);
177:                 $returnUrl = add_query_arg($result, $returnUrl);
178:                 break;
179:             case 'delete_all':
180:                 $ids = $this->repository->getEntryIdsByStatus((int) Quform::get($_GET, 'id'), 'trash');
181:                 $result = $this->processDeleteAction($ids, $nonce);
182:                 $returnUrl = add_query_arg($result, $returnUrl);
183:                 break;
184:         }
185: 
186:         wp_safe_redirect(esc_url_raw($returnUrl));
187:         exit;
188:     }
189: 
190:     /**
191:      * Process marking entries as read
192:      *
193:      * @param   int|array  $entryIds
194:      * @param   string     $nonce
195:      * @return  array      The result message
196:      */
197:     protected function processReadAction($entryIds, $nonce)
198:     {
199:         if (is_array($entryIds)) {
200:             $nonceAction = 'bulk-qfb-entries';
201:         } else {
202:             $nonceAction = 'quform_read_entry_' . $entryIds;
203:             $entryIds = array($entryIds);
204:         }
205: 
206:         if ( ! $nonce || ! count($entryIds)) {
207:             return array('error' => self::BAD_REQUEST);
208:         }
209: 
210:         if ( ! current_user_can('quform_view_entries')) {
211:             return array('error' => self::NO_PERMISSION);
212:         }
213: 
214:         if ( ! wp_verify_nonce($nonce, $nonceAction)) {
215:             return array('error' => self::NONCE_CHECK_FAILED);
216:         }
217: 
218:         $count = $this->repository->readEntries($entryIds);
219: 
220:         return array('read' => $count);
221:     }
222: 
223:     /**
224:      * Process marking entries as unread
225:      *
226:      * @param   int|array  $entryIds
227:      * @param   string     $nonce
228:      * @return  array      The result message
229:      */
230:     protected function processUnreadAction($entryIds, $nonce)
231:     {
232:         if (is_array($entryIds)) {
233:             $nonceAction = 'bulk-qfb-entries';
234:         } else {
235:             $nonceAction = 'quform_unread_entry_' . $entryIds;
236:             $entryIds = array($entryIds);
237:         }
238: 
239:         if ( ! $nonce || ! count($entryIds)) {
240:             return array('error' => self::BAD_REQUEST);
241:         }
242: 
243:         if ( ! current_user_can('quform_view_entries')) {
244:             return array('error' => self::NO_PERMISSION);
245:         }
246: 
247:         if ( ! wp_verify_nonce($nonce, $nonceAction)) {
248:             return array('error' => self::NONCE_CHECK_FAILED);
249:         }
250: 
251:         $count = $this->repository->unreadEntries($entryIds);
252: 
253:         return array('unread' => $count);
254:     }
255: 
256:     /**
257:      * Process trashing entries
258:      *
259:      * @param   int|array  $entryIds
260:      * @param   string     $nonce
261:      * @return  array      The result message
262:      */
263:     protected function processTrashAction($entryIds, $nonce)
264:     {
265:         if (is_array($entryIds)) {
266:             $nonceAction = 'bulk-qfb-entries';
267:         } else {
268:             $nonceAction = 'quform_trash_entry_' . $entryIds;
269:             $entryIds = array($entryIds);
270:         }
271: 
272:         if ( ! $nonce || ! count($entryIds)) {
273:             return array('error' => self::BAD_REQUEST);
274:         }
275: 
276:         if ( ! current_user_can('quform_delete_entries')) {
277:             return array('error' => self::NO_PERMISSION);
278:         }
279: 
280:         if ( ! wp_verify_nonce($nonce, $nonceAction)) {
281:             return array('error' => self::NONCE_CHECK_FAILED);
282:         }
283: 
284:         $count = $this->repository->trashEntries($entryIds);
285: 
286:         return array('trashed' => $count);
287:     }
288: 
289:     /**
290:      * Process trashing entries
291:      *
292:      * @param   int|array  $entryIds
293:      * @param   string     $nonce
294:      * @return  array      The result message
295:      */
296:     protected function processUntrashAction($entryIds, $nonce)
297:     {
298:         if (is_array($entryIds)) {
299:             $nonceAction = 'bulk-qfb-entries';
300:         } else {
301:             $nonceAction = 'quform_untrash_entry_' . $entryIds;
302:             $entryIds = array($entryIds);
303:         }
304: 
305:         if ( ! $nonce || ! count($entryIds)) {
306:             return array('error' => self::BAD_REQUEST);
307:         }
308: 
309:         if ( ! current_user_can('quform_delete_entries')) {
310:             return array('error' => self::NO_PERMISSION);
311:         }
312: 
313:         if ( ! wp_verify_nonce($nonce, $nonceAction)) {
314:             return array('error' => self::NONCE_CHECK_FAILED);
315:         }
316: 
317:         $count = $this->repository->untrashEntries($entryIds);
318: 
319:         return array('untrashed' => $count);
320:     }
321: 
322:     /**
323:      * Process deleting entries
324:      *
325:      * @param   int|array  $entryIds
326:      * @param   string     $nonce
327:      * @return  array      The result message
328:      */
329:     protected function processDeleteAction($entryIds, $nonce)
330:     {
331:         if (is_array($entryIds)) {
332:             $nonceAction = 'bulk-qfb-entries';
333:         } else {
334:             $nonceAction = 'quform_delete_entry_' . $entryIds;
335:             $entryIds = array($entryIds);
336:         }
337: 
338:         if ( ! $nonce || ! count($entryIds)) {
339:             return array('error' => self::BAD_REQUEST);
340:         }
341: 
342:         if ( ! current_user_can('quform_delete_entries')) {
343:             return array('error' => self::NO_PERMISSION);
344:         }
345: 
346:         if ( ! wp_verify_nonce($nonce, $nonceAction)) {
347:             return array('error' => self::NONCE_CHECK_FAILED);
348:         }
349: 
350:         $count = $this->repository->deleteEntries($entryIds);
351: 
352:         return array('deleted' => $count);
353:     }
354: 
355:     /**
356:      * Get the name of the bulk action
357:      *
358:      * @return string|null
359:      */
360:     protected function getBulkAction()
361:     {
362:         $action = null;
363: 
364:         $a1 = Quform::get($_GET, 'action', '-1');
365:         $a2 = Quform::get($_GET, 'action2', '-1');
366: 
367:         if ($a1 != '-1') {
368:             $action = $a1;
369:         } elseif ($a2 != '-1') {
370:             $action = $a2;
371:         }
372: 
373:         return $action;
374:     }
375: 
376:     /**
377:      * Add messages to the page based on the query vars
378:      */
379:     protected function addPageMessages()
380:     {
381:         $read = (int) Quform::get($_GET, 'read');
382:         if ($read > 0) {
383:             /* translators: %s: the number of entries */
384:             $this->addMessage('success', sprintf(_n('%s entry marked as read', '%s entries marked as read', $read, 'quform'), number_format_i18n($read)));
385:         }
386: 
387:         $unread = (int) Quform::get($_GET, 'unread');
388:         if ($unread > 0) {
389:             /* translators: %s: the number of entries */
390:             $this->addMessage('success', sprintf(_n('%s entry marked as unread', '%s entries marked as unread', $unread, 'quform'), number_format_i18n($unread)));
391:         }
392: 
393:         $trashed = (int) Quform::get($_GET, 'trashed');
394:         if ($trashed > 0) {
395:             /* translators: %s: the number of entries */
396:             $this->addMessage('success', sprintf(_n('%s entry moved to the Trash', '%s entries moved to the Trash', $trashed, 'quform'), number_format_i18n($trashed)));
397:         }
398: 
399:         $untrashed = (int) Quform::get($_GET, 'untrashed');
400:         if ($untrashed > 0) {
401:             /* translators: %s: the number of entries */
402:             $this->addMessage('success', sprintf(_n('%s entry restored', '%s entries restored', $untrashed, 'quform'), number_format_i18n($untrashed)));
403:         }
404: 
405:         $deleted = (int) Quform::get($_GET, 'deleted');
406:         if ($deleted > 0) {
407:             /* translators: %s: the number of entries */
408:             $this->addMessage('success', sprintf(_n('%s entry deleted', '%s entries deleted', $deleted, 'quform'), number_format_i18n($deleted)));
409:         }
410: 
411:         switch ((int) Quform::get($_GET, 'error')) {
412:             case self::BAD_REQUEST:
413:                 $this->addMessage('error', __('Bad request.', 'quform'));
414:                 break;
415:             case self::NO_PERMISSION:
416:                 $this->addMessage('error', __('You do not have permission to do this.', 'quform'));
417:                 break;
418:             case self::NONCE_CHECK_FAILED:
419:                 $this->addMessage('error', __('Nonce check failed.', 'quform'));
420:                 break;
421:         }
422:     }
423: 
424:     /**
425:      * Additional query arguments that can be hidden by history.replaceState
426:      *
427:      * @param   array  $args
428:      * @return  array
429:      */
430:     public function removableQueryArgs($args)
431:     {
432:         $args[] = 'read';
433:         $args[] = 'unread';
434: 
435:         return $args;
436:     }
437: 
438:     /**
439:      * Get the HTML for the admin navigation menu
440:      *
441:      * @param   array|null  $currentForm  The data for the current form (if any)
442:      * @param   array       $extra        Extra HTML to add to the nav, the array key is the hook position
443:      * @return  string
444:      */
445:     public function getNavHtml(?array $currentForm = null, array $extra = array())
446:     {
447:         $extra[40] = sprintf(
448:             '<div class="qfb-nav-item qfb-nav-page-info"><i class="qfb-nav-page-icon qfb-mdi qfb-mdi-message"></i><span class="qfb-nav-page-title">%s</span></div>',
449:             /* translators: %s: the form name */
450:             Quform::escape(sprintf(__('Entries for %s', 'quform'), $currentForm['name']))
451:         );
452: 
453:         $extra[50] = '<div class="qfb-nav-item qfb-nav-item-right"><a id="qfb-show-entries-table-settings" class="qfb-nav-item-link"><i class="qfb-mdi qfb-mdi-settings"></i></a></div>';
454: 
455:         return parent::getNavHtml($currentForm, $extra);
456:     }
457: 
458:     /**
459:      * Get the HTML for an entry label for the entry label settings
460:      *
461:      * @param   array|null  $label
462:      * @return  string
463:      */
464:     public function getEntryLabelEditHtml(?array $label = null)
465:     {
466:         $output = sprintf(
467:             '<div class="qfb-entry-label-edit qfb-cf"%s%s>',
468:             is_array($label) ? sprintf(' data-label="%s"', Quform::escape(wp_json_encode($label))) : '',
469:             is_array($label) ? sprintf(' style="background-color: %s;"', Quform::escape($label['color'])) : ''
470:         );
471: 
472:         $output .= sprintf(
473:             '<span class="qfb-entry-label-edit-name" title="%s">%s</span>',
474:             esc_attr__('Click to edit name', 'quform'),
475:             is_array($label) ? Quform::escape($label['name']) : ''
476:         );
477: 
478:         $output .= '<div class="qfb-entry-label-edit-actions">';
479:         $output .= '<span class="qfb-entry-label-edit-action-color"><i class="qfb-mdi qfb-mdi-format_color_fill"></i></span>';
480:         $output .= '<span class="qfb-entry-label-edit-action-duplicate"><i class="qfb-mdi qfb-mdi-content_copy"></i></span>';
481:         $output .= '<span class="qfb-entry-label-edit-action-remove"><i class="qfb-icon qfb-icon-trash"></i></span>';
482:         $output .= '</div></div>';
483: 
484:         return $output;
485:     }
486: }
487: 
API documentation generated by ApiGen