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_Forms_List extends Quform_Admin_Page
  7: {
  8:     /**
  9:      * @var Quform_ScriptLoader
 10:      */
 11:     protected $scriptLoader;
 12: 
 13:     /**
 14:      * @var Quform_Form_List_Table
 15:      */
 16:     protected $table;
 17: 
 18:     /**
 19:      * @param  Quform_ViewFactory      $viewFactory
 20:      * @param  Quform_Repository       $repository
 21:      * @param  Quform_ScriptLoader     $scriptLoader
 22:      * @param  Quform_Form_List_Table  $table
 23:      */
 24:     public function __construct(Quform_ViewFactory $viewFactory, Quform_Repository $repository,
 25:                                 Quform_ScriptLoader $scriptLoader, Quform_Form_List_Table $table)
 26:     {
 27:         parent::__construct($viewFactory, $repository);
 28: 
 29:         $this->scriptLoader = $scriptLoader;
 30:         $this->table = $table;
 31:     }
 32: 
 33:     public function init()
 34:     {
 35:         $this->template = QUFORM_TEMPLATE_PATH .  '/admin/forms/list.php';
 36:     }
 37: 
 38:     protected function enqueueScripts()
 39:     {
 40:         parent::enqueueScripts();
 41: 
 42:         wp_enqueue_script('quform-forms', Quform::adminUrl('js/forms.list.min.js'), array('jquery'), QUFORM_VERSION, true);
 43: 
 44:         wp_localize_script('quform-forms', 'quformFormsListL10n', array(
 45:             'singleConfirmDelete' => __('Are you sure you want to delete this form? All saved settings, elements and entries for this form will be lost and this cannot be undone.', 'quform'),
 46:             'pluralConfirmDelete' => __('Are you sure you want to delete these forms? All saved settings, elements and entries for these forms will be lost and this cannot be undone.', 'quform'),
 47:             'saveFormsTableSettingsNonce' => wp_create_nonce('quform_save_forms_table_settings'),
 48:             'addFormNonce' => wp_create_nonce('quform_add_form'),
 49:             'errorAddingForm' => __('An error occurred adding the form', 'quform')
 50:         ));
 51:     }
 52: 
 53:     /**
 54:      * Process this page and send data to the view
 55:      */
 56:     public function process()
 57:     {
 58:         if ( ! current_user_can('quform_list_forms')) {
 59:             wp_die(__( 'You do not have sufficient permissions to access this page.', 'quform'), 403);
 60:         }
 61: 
 62:         $this->processActions();
 63: 
 64:         $this->addPageMessages();
 65: 
 66:         $this->table->prepare_items();
 67: 
 68:         $perPage = get_user_meta(get_current_user_id(), 'quform_forms_per_page', true);
 69:         if ( ! is_numeric($perPage)) {
 70:             $perPage = 20;
 71:         }
 72: 
 73:         $this->view->with(array(
 74:             'table' => $this->table,
 75:             'perPage' => $perPage
 76:         ));
 77: 
 78:         add_filter('removable_query_args', array($this, 'removableQueryArgs'));
 79:     }
 80: 
 81:     /**
 82:      * Process actions on the form list
 83:      */
 84:     protected function processActions()
 85:     {
 86:         $nonce = Quform::get($_GET, '_wpnonce');
 87:         $action = null;
 88:         $ids = array();
 89: 
 90:         if (isset($_GET['id'])) {
 91:             $action = Quform::get($_GET, 'action');
 92:             $ids = (int) $_GET['id'];
 93:         } elseif (isset($_GET['ids'])) {
 94:             $action = $this->getBulkAction();
 95:             $ids = (array) Quform::get($_GET, 'ids');
 96:             $ids = array_map('intval', $ids);
 97:         } elseif (isset($_GET['delete_all'])) {
 98:             $action = 'delete_all';
 99:         }
100: 
101:         if ($action == null) {
102:             if (Quform::get($_GET, '_wp_http_referer')) {
103:                 wp_safe_redirect(esc_url_raw(remove_query_arg(array('_wp_http_referer', '_wpnonce'), wp_unslash($_SERVER['REQUEST_URI']))));
104:                 exit;
105:             }
106: 
107:             return;
108:         }
109: 
110:         do_action('quform_pre_process_forms_list_action', $action, $ids);
111: 
112:         $returnUrl = remove_query_arg(array('action', 'action2', 'id', 'ids', 'activated', 'deactivated', 'duplicated', 'trashed', 'restored', 'deleted', 'error'), wp_get_referer());
113: 
114:         switch ($action) {
115:             case 'activate':
116:                 $result = $this->processActivateAction($ids, $nonce);
117:                 $returnUrl = add_query_arg($result, $returnUrl);
118:                 break;
119:             case 'deactivate':
120:                 $result = $this->processDeactivateAction($ids, $nonce);
121:                 $returnUrl = add_query_arg($result, $returnUrl);
122:                 break;
123:             case 'duplicate':
124:                 $result = $this->processDuplicateAction($ids, $nonce);
125:                 $returnUrl = add_query_arg($result, $returnUrl);
126:                 break;
127:             case 'trash':
128:                 $result = $this->processTrashAction($ids, $nonce);
129:                 $returnUrl = add_query_arg($result, $returnUrl);
130:                 break;
131:             case 'untrash':
132:                 $result = $this->processUntrashAction($ids, $nonce);
133:                 $returnUrl = add_query_arg($result, $returnUrl);
134:                 break;
135:             case 'delete':
136:                 $result = $this->processDeleteAction($ids, $nonce);
137:                 $returnUrl = add_query_arg($result, $returnUrl);
138:                 break;
139:             case 'delete_all':
140:                 $ids = $this->repository->getTrashedFormIds();
141:                 $result = $this->processDeleteAction($ids, $nonce);
142:                 $returnUrl = add_query_arg($result, $returnUrl);
143:                 break;
144:         }
145: 
146:         wp_safe_redirect(esc_url_raw($returnUrl));
147:         exit;
148:     }
149: 
150:     /**
151:      * Process activating forms
152:      *
153:      * @param   int|array  $ids    The form ID or array of IDs
154:      * @param   string     $nonce  The nonce to check for validity
155:      * @return  array              The result message
156:      */
157:     protected function processActivateAction($ids, $nonce)
158:     {
159:         if (is_array($ids)) {
160:             $nonceAction = 'bulk-qfb-forms';
161:         } else {
162:             $nonceAction = 'quform_activate_form_' . $ids;
163:             $ids = array($ids);
164:         }
165: 
166:         if ( ! $nonce ||  ! count($ids)) {
167:             return array('error' => self::BAD_REQUEST);
168:         }
169: 
170:         if ( ! current_user_can('quform_edit_forms')) {
171:             return array('error' => self::NO_PERMISSION);
172:         }
173: 
174:         if ( ! wp_verify_nonce($nonce, $nonceAction)) {
175:             return array('error' => self::NONCE_CHECK_FAILED);
176:         }
177: 
178:         $count = $this->repository->activateForms($ids);
179: 
180:         $this->scriptLoader->handleActivateForms($ids);
181: 
182:         return array('activated' => $count);
183:     }
184: 
185:     /**
186:      * Process deactivating forms
187:      *
188:      * @param   int|array  $ids    The form ID or array of IDs
189:      * @param   string     $nonce  The nonce to check for validity
190:      * @return  array              The result message
191:      */
192:     protected function processDeactivateAction($ids, $nonce)
193:     {
194:         if (is_array($ids)) {
195:             $nonceAction = 'bulk-qfb-forms';
196:         } else {
197:             $nonceAction = 'quform_deactivate_form_' . $ids;
198:             $ids = array($ids);
199:         }
200: 
201:         if ( ! $nonce ||  ! count($ids)) {
202:             return array('error' => self::BAD_REQUEST);
203:         }
204: 
205:         if ( ! current_user_can('quform_edit_forms')) {
206:             return array('error' => self::NO_PERMISSION);
207:         }
208: 
209:         if ( ! wp_verify_nonce($nonce, $nonceAction)) {
210:             return array('error' => self::NONCE_CHECK_FAILED);
211:         }
212: 
213:         $count = $this->repository->deactivateForms($ids);
214: 
215:         $this->scriptLoader->handleDeactivateForms($ids);
216: 
217:         return array('deactivated' => $count);
218:     }
219: 
220:     /**
221:      * Process duplicating forms
222:      *
223:      * @param   int|array  $ids    The form ID or array of IDs
224:      * @param   string     $nonce  The nonce to check for validity
225:      * @return  array              The result message
226:      */
227:     protected function processDuplicateAction($ids, $nonce)
228:     {
229:         if (is_array($ids)) {
230:             $nonceAction = 'bulk-qfb-forms';
231:         } else {
232:             $nonceAction = 'quform_duplicate_form_' . $ids;
233:             $ids = array($ids);
234:         }
235: 
236:         if ( ! $nonce ||  ! count($ids)) {
237:             return array('error' => self::BAD_REQUEST);
238:         }
239: 
240:         if ( ! current_user_can('quform_add_forms')) {
241:             return array('error' => self::NO_PERMISSION);
242:         }
243: 
244:         if ( ! wp_verify_nonce($nonce, $nonceAction)) {
245:             return array('error' => self::NONCE_CHECK_FAILED);
246:         }
247: 
248:         $newIds = $this->repository->duplicateForms($ids);
249: 
250:         $this->scriptLoader->handleDuplicateForms($newIds);
251: 
252:         return array('duplicated' => count($newIds));
253:     }
254: 
255:     /**
256:      * Process trashing forms
257:      *
258:      * @param   int|array  $ids    The form ID or array of IDs
259:      * @param   string     $nonce  The nonce to check for validity
260:      * @return  array              The result message
261:      */
262:     protected function processTrashAction($ids, $nonce)
263:     {
264:         if (is_array($ids)) {
265:             $nonceAction = 'bulk-qfb-forms';
266:         } else {
267:             $nonceAction = 'quform_trash_form_' . $ids;
268:             $ids = array($ids);
269:         }
270: 
271:         if ( ! $nonce || ! count($ids)) {
272:             return array('error' => self::BAD_REQUEST);
273:         }
274: 
275:         if ( ! current_user_can('quform_delete_forms')) {
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->trashForms($ids);
284: 
285:         $this->scriptLoader->handleTrashForms($ids);
286: 
287:         return array('trashed' => $count);
288:     }
289: 
290:     /**
291:      * Process un-trashing forms
292:      *
293:      * @param   int|array  $ids    The form ID or array of IDs
294:      * @param   string     $nonce  The nonce to check for validity
295:      * @return  array              The result message
296:      */
297:     protected function processUntrashAction($ids, $nonce)
298:     {
299:         if (is_array($ids)) {
300:             $nonceAction = 'bulk-qfb-forms';
301:         } else {
302:             $nonceAction = 'quform_untrash_form_' . $ids;
303:             $ids = array($ids);
304:         }
305: 
306:         if ( ! $nonce || ! count($ids)) {
307:             return array('error' => self::BAD_REQUEST);
308:         }
309: 
310:         if ( ! current_user_can('quform_delete_forms')) {
311:             return array('error' => self::NO_PERMISSION);
312:         }
313: 
314:         if ( ! wp_verify_nonce($nonce, $nonceAction)) {
315:             return array('error' => self::NONCE_CHECK_FAILED);
316:         }
317: 
318:         $count = $this->repository->untrashForms($ids);
319: 
320:         $this->scriptLoader->handleUntrashForms($ids);
321: 
322:         return array('untrashed' => $count);
323:     }
324: 
325:     /**
326:      * Process deleting forms
327:      *
328:      * @param   int|array  $ids    The form ID or array of IDs
329:      * @param   string     $nonce  The nonce to check for validity
330:      * @return  array              The result message
331:      */
332:     protected function processDeleteAction($ids, $nonce)
333:     {
334:         if (is_array($ids)) {
335:             $nonceAction = 'bulk-qfb-forms';
336:         } else {
337:             $nonceAction = 'quform_delete_form_' . $ids;
338:             $ids = array($ids);
339:         }
340: 
341:         if ( ! $nonce || ! count($ids)) {
342:             return array('error' => self::BAD_REQUEST);
343:         }
344: 
345:         if ( ! current_user_can('quform_delete_forms')) {
346:             return array('error' => self::NO_PERMISSION);
347:         }
348: 
349:         if ( ! wp_verify_nonce($nonce, $nonceAction)) {
350:             return array('error' => self::NONCE_CHECK_FAILED);
351:         }
352: 
353:         $count = $this->repository->deleteForms($ids);
354: 
355:         return array('deleted' => $count);
356:     }
357: 
358:     /**
359:      * @return string|null
360:      */
361:     protected function getBulkAction()
362:     {
363:         $action = null;
364: 
365:         $a1 = Quform::get($_GET, 'action', '-1');
366:         $a2 = Quform::get($_GET, 'action2', '-1');
367: 
368:         if ($a1 != '-1') {
369:             $action = $a1;
370:         } elseif ($a2 != '-1') {
371:             $action = $a2;
372:         }
373: 
374:         return $action;
375:     }
376: 
377:     /**
378:      * Add messages to the page based on the query vars
379:      */
380:     protected function addPageMessages()
381:     {
382:         $activated = (int) Quform::get($_GET, 'activated');
383:         if ($activated > 0) {
384:             /* translators: %s: the number of forms */
385:             $this->addMessage('success', sprintf(_n('%s form activated', '%s forms activated', $activated, 'quform'), number_format_i18n($activated)));
386:         }
387: 
388:         $deactivated = (int) Quform::get($_GET, 'deactivated');
389:         if ($deactivated > 0) {
390:             /* translators: %s: the number of forms */
391:             $this->addMessage('success', sprintf(_n('%s form deactivated', '%s forms deactivated', $deactivated, 'quform'), number_format_i18n($deactivated)));
392:         }
393: 
394:         $duplicated = (int) Quform::get($_GET, 'duplicated');
395:         if ($duplicated > 0) {
396:             /* translators: %s: the number of forms */
397:             $this->addMessage('success', sprintf(_n('%s form duplicated', '%s forms duplicated', $duplicated, 'quform'), number_format_i18n($duplicated)));
398:         }
399: 
400:         $trashed = (int) Quform::get($_GET, 'trashed');
401:         if ($trashed > 0) {
402:             /* translators: %s: the number of forms */
403:             $this->addMessage('success', sprintf(_n('%s form moved to the Trash', '%s forms moved to the Trash', $trashed, 'quform'), number_format_i18n($trashed)));
404:         }
405: 
406:         $untrashed = (int) Quform::get($_GET, 'untrashed');
407:         if ($untrashed > 0) {
408:             /* translators: %s: the number of forms */
409:             $this->addMessage('success', sprintf(_n('%s form restored', '%s forms restored', $untrashed, 'quform'), number_format_i18n($untrashed)));
410:         }
411: 
412:         $deleted = (int) Quform::get($_GET, 'deleted');
413:         if ($deleted > 0) {
414:             /* translators: %s: the number of forms */
415:             $this->addMessage('success', sprintf(_n('%s form deleted', '%s forms deleted', $deleted, 'quform'), number_format_i18n($deleted)));
416:         }
417: 
418:         switch ((int) Quform::get($_GET, 'error')) {
419:             case self::BAD_REQUEST:
420:                 $this->addMessage('error', __('Bad request.', 'quform'));
421:                 break;
422:             case self::NO_PERMISSION:
423:                 $this->addMessage('error', __('You do not have permission to do this.', 'quform'));
424:                 break;
425:             case self::NONCE_CHECK_FAILED:
426:                 $this->addMessage('error', __('Nonce check failed.', 'quform'));
427:                 break;
428:         }
429:     }
430: 
431:     /**
432:      * Additional query arguments that can be hidden by history.replaceState
433:      *
434:      * @param   array  $args
435:      * @return  array
436:      */
437:     public function removableQueryArgs($args)
438:     {
439:         $args[] = 'deactivated';
440:         $args[] = 'duplicated';
441: 
442:         return $args;
443:     }
444: 
445:     /**
446:      * Get the HTML for the admin navigation menu
447:      *
448:      * @param   array|null  $currentForm  The data for the current form (if any)
449:      * @param   array       $extra        Extra HTML to add to the nav, the array key is the hook position
450:      * @return  string
451:      */
452:     public function getNavHtml(array $currentForm = null, array $extra = array())
453:     {
454:         $extra[40] = sprintf('<div class="qfb-nav-item qfb-nav-page-info"><i class="qfb-nav-page-icon qfb-mdi qfb-mdi-view_stream"></i><span class="qfb-nav-page-title">%s</span></div>', esc_html__('Forms', 'quform'));
455:         $extra[50] = '<div class="qfb-nav-item qfb-nav-item-right"><a id="qfb-show-forms-table-settings" class="qfb-nav-item-link"><i class="qfb-mdi qfb-mdi-settings"></i></a></div>';
456: 
457:         return parent::getNavHtml($currentForm, $extra);
458:     }
459: }
460: 
API documentation generated by ApiGen