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_Confirmation
  7: {
  8:     /**
  9:      * @var array
 10:      */
 11:     protected $config = array();
 12: 
 13:     /**
 14:      * @var Quform_Form
 15:      */
 16:     protected $form;
 17: 
 18:     /**
 19:      * @param  array        $config
 20:      * @param  Quform_Form  $form
 21:      */
 22:     public function __construct(array $config, Quform_Form $form)
 23:     {
 24:         $this->setConfig($config);
 25:         $this->form = $form;
 26:     }
 27: 
 28:     /**
 29:      * Get the data for the form processor
 30:      *
 31:      * @return array
 32:      */
 33:     public function getData()
 34:     {
 35:         $data = array(
 36:             'type' => $this->config('type'),
 37:             'message' => $this->getMessage(),
 38:             'messageIcon' => $this->config('messageIcon'),
 39:             'messagePosition' => $this->config('messagePosition'),
 40:             'messageTimeout' => $this->config('messageTimeout'),
 41:             'redirectUrl' => esc_url_raw($this->getRedirectUrl()),
 42:             'redirectDelay' => $this->config('redirectDelay'),
 43:             'hideForm' => $this->config('hideForm'),
 44:             'resetForm' => $this->config('resetForm')
 45:         );
 46: 
 47:         $data = apply_filters('quform_confirmation_data', $data, $this, $this->form);
 48:         $data = apply_filters('quform_confirmation_data_'  . $this->getIdentifier(), $data, $this, $this->form);
 49: 
 50:         return $data;
 51:     }
 52: 
 53:     /**
 54:      * Get the confirmation message
 55:      *
 56:      * @return string
 57:      */
 58:     public function getMessage()
 59:     {
 60:         $message = $this->config('message');
 61: 
 62:         if ($this->config('messageAutoFormat')) {
 63:             $message = nl2br($message);
 64:         }
 65: 
 66:         $message = $this->form->replaceVariables($message, 'html');
 67:         $message = do_shortcode($message);
 68: 
 69:         if (is_admin()) {
 70:             // Filter JS in the WP admin (e.g. form preview) to avoid XSS
 71:             $message = wp_kses_post($message);
 72:         }
 73: 
 74:         $message = apply_filters('quform_confirmation_message', $message, $this, $this->form);
 75:         $message = apply_filters('quform_confirmation_message_' . $this->getIdentifier(), $message, $this, $this->form);
 76: 
 77:         return $message;
 78:     }
 79: 
 80:     /**
 81:      * Get the confirmation redirect URL
 82:      *
 83:      * @return string
 84:      */
 85:     public function getRedirectUrl()
 86:     {
 87:         $url = '';
 88: 
 89:         switch ($this->config('type')) {
 90:             case 'redirect-page':
 91:             case 'message-redirect-page':
 92:                 $post = get_post($this->config('redirectPage'));
 93: 
 94:                 if ($post instanceof WP_Post && $post->post_status == 'publish') {
 95:                     $url = get_permalink($post);
 96:                 } else {
 97:                     $url = home_url();
 98:                 }
 99: 
100:                 break;
101:             case 'redirect-url':
102:             case 'message-redirect-url':
103:                 $url = $this->form->replaceVariables($this->config('redirectUrl'), 'rawurl');
104:                 break;
105:         }
106: 
107:         if (Quform::isNonEmptyString($this->config('redirectQuery'))) {
108:             $query = explode('&', $this->config('redirectQuery'));
109: 
110:             foreach ($query as $part) {
111:                 $parameter = explode('=', $part);
112: 
113:                 if (count($parameter) == 1) {
114:                     $url = add_query_arg(
115:                         $this->form->replaceVariables($parameter[0], 'url'),
116:                         '',
117:                         $url
118:                     );
119:                 } else if (count($parameter) == 2) {
120:                     $url = add_query_arg(
121:                         $this->form->replaceVariables($parameter[0], 'url'),
122:                         $this->form->replaceVariables($parameter[1], 'url'),
123:                         $url
124:                     );
125:                 }
126:             }
127:         }
128: 
129:         $url = apply_filters('quform_confirmation_redirect_url', $url, $this, $this->form);
130:         $url = apply_filters('quform_confirmation_redirect_url_' . $this->getIdentifier(), $url, $this, $this->form);
131: 
132:         return $url;
133:     }
134: 
135:     /**
136:      * Get the confirmation unique ID
137:      *
138:      * @return string
139:      */
140:     public function getIdentifier()
141:     {
142:         return sprintf('%d_%d', $this->form->getId(), $this->config('id'));
143:     }
144: 
145:     /**
146:      * Returns the config value for the given $key
147:      *
148:      * @param   string  $key
149:      * @param   null    $default
150:      * @return  mixed   The config value or $default if not set
151:      */
152:     public function config($key, $default = null)
153:     {
154:         $value = Quform::get($this->config, $key, $default);
155: 
156:         if ($value === null) {
157:             $value = Quform::get(call_user_func(array(get_class($this), 'getDefaultConfig')), $key, $default);
158:         }
159: 
160:         return $value;
161:     }
162: 
163:     /**
164:      * Set the config value for the given $key or multiple values using an array
165:      *
166:      * @param   string|array  $key    Key or array of key/values
167:      * @param   mixed         $value  Value or null if $key is array
168:      * @return  $this
169:      */
170:     public function setConfig($key, $value = null)
171:     {
172:         if (is_array($key)) {
173:             foreach ($key as $k => $v) {
174:                 $this->config[$k] = $v;
175:             }
176:         } else {
177:             $this->config[$key] = $value;
178:         }
179: 
180:         return $this;
181:     }
182: 
183:     /**
184:      * Get the default confirmation configuration
185:      *
186:      * @param   string|null  $key  Get the config by key, if omitted the full config is returned
187:      * @return  array
188:      */
189:     public static function getDefaultConfig($key = null)
190:     {
191:         $config = apply_filters('quform_default_confirmation', array(
192:             'name' => '',
193:             'enabled' => true,
194:             'type' => 'message',
195:             'message' => '',
196:             'messageAutoFormat' => true,
197:             'messageIcon' => '',
198:             'messagePosition' => 'above',
199:             'messageTimeout' => '10',
200:             'redirectPage' => '',
201:             'redirectUrl' => '',
202:             'redirectQuery' => '',
203:             'redirectDelay' => '3',
204:             'logicAction' => true,
205:             'logicMatch' => 'all',
206:             'logicRules' => array(),
207:             'hideForm' => false,
208:             'resetForm' => ''
209:         ));
210: 
211:         if (Quform::isNonEmptyString($key)) {
212:             return Quform::get($config, $key);
213:         }
214: 
215:         return $config;
216:     }
217: }
218: 
API documentation generated by ApiGen