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