@@ -308,7 +308,7 @@ |
||
| 308 | 308 | * |
| 309 | 309 | * @since 2.02.05 |
| 310 | 310 | * @param string $key |
| 311 | - * @param int|string $value |
|
| 311 | + * @param string $value |
|
| 312 | 312 | * @param string $where |
| 313 | 313 | */ |
| 314 | 314 | private static function add_query_placeholder( $key, $value, &$where ) { |
@@ -1,66 +1,66 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class FrmDb { |
| 4 | - var $fields; |
|
| 5 | - var $forms; |
|
| 6 | - var $entries; |
|
| 7 | - var $entry_metas; |
|
| 8 | - |
|
| 9 | - public function __construct() { |
|
| 10 | - if ( ! defined('ABSPATH') ) { |
|
| 11 | - die('You are not allowed to call this page directly.'); |
|
| 12 | - } |
|
| 13 | - |
|
| 14 | - global $wpdb; |
|
| 15 | - $this->fields = $wpdb->prefix . 'frm_fields'; |
|
| 16 | - $this->forms = $wpdb->prefix . 'frm_forms'; |
|
| 17 | - $this->entries = $wpdb->prefix . 'frm_items'; |
|
| 18 | - $this->entry_metas = $wpdb->prefix . 'frm_item_metas'; |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function upgrade( $old_db_version = false ) { |
|
| 22 | - do_action( 'frm_before_install' ); |
|
| 23 | - |
|
| 24 | - global $wpdb; |
|
| 25 | - //$frm_db_version is the version of the database we're moving to |
|
| 26 | - $frm_db_version = FrmAppHelper::$db_version; |
|
| 27 | - $old_db_version = (float) $old_db_version; |
|
| 28 | - if ( ! $old_db_version ) { |
|
| 29 | - $old_db_version = get_option('frm_db_version'); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - if ( $frm_db_version != $old_db_version ) { |
|
| 4 | + var $fields; |
|
| 5 | + var $forms; |
|
| 6 | + var $entries; |
|
| 7 | + var $entry_metas; |
|
| 8 | + |
|
| 9 | + public function __construct() { |
|
| 10 | + if ( ! defined('ABSPATH') ) { |
|
| 11 | + die('You are not allowed to call this page directly.'); |
|
| 12 | + } |
|
| 13 | + |
|
| 14 | + global $wpdb; |
|
| 15 | + $this->fields = $wpdb->prefix . 'frm_fields'; |
|
| 16 | + $this->forms = $wpdb->prefix . 'frm_forms'; |
|
| 17 | + $this->entries = $wpdb->prefix . 'frm_items'; |
|
| 18 | + $this->entry_metas = $wpdb->prefix . 'frm_item_metas'; |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function upgrade( $old_db_version = false ) { |
|
| 22 | + do_action( 'frm_before_install' ); |
|
| 23 | + |
|
| 24 | + global $wpdb; |
|
| 25 | + //$frm_db_version is the version of the database we're moving to |
|
| 26 | + $frm_db_version = FrmAppHelper::$db_version; |
|
| 27 | + $old_db_version = (float) $old_db_version; |
|
| 28 | + if ( ! $old_db_version ) { |
|
| 29 | + $old_db_version = get_option('frm_db_version'); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + if ( $frm_db_version != $old_db_version ) { |
|
| 33 | 33 | // update rewrite rules for views and other custom post types |
| 34 | 34 | flush_rewrite_rules(); |
| 35 | 35 | |
| 36 | 36 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 37 | 37 | |
| 38 | - $this->create_tables(); |
|
| 39 | - $this->migrate_data($frm_db_version, $old_db_version); |
|
| 38 | + $this->create_tables(); |
|
| 39 | + $this->migrate_data($frm_db_version, $old_db_version); |
|
| 40 | 40 | |
| 41 | - /***** SAVE DB VERSION *****/ |
|
| 42 | - update_option('frm_db_version', $frm_db_version); |
|
| 41 | + /***** SAVE DB VERSION *****/ |
|
| 42 | + update_option('frm_db_version', $frm_db_version); |
|
| 43 | 43 | |
| 44 | - /**** ADD/UPDATE DEFAULT TEMPLATES ****/ |
|
| 45 | - FrmXMLController::add_default_templates(); |
|
| 46 | - } |
|
| 44 | + /**** ADD/UPDATE DEFAULT TEMPLATES ****/ |
|
| 45 | + FrmXMLController::add_default_templates(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - do_action('frm_after_install'); |
|
| 48 | + do_action('frm_after_install'); |
|
| 49 | 49 | |
| 50 | - /**** update the styling settings ****/ |
|
| 50 | + /**** update the styling settings ****/ |
|
| 51 | 51 | if ( is_admin() && function_exists( 'get_filesystem_method' ) ) { |
| 52 | 52 | $frm_style = new FrmStyle(); |
| 53 | 53 | $frm_style->update( 'default' ); |
| 54 | 54 | } |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - public function collation() { |
|
| 58 | - global $wpdb; |
|
| 59 | - if ( ! $wpdb->has_cap( 'collation' ) ) { |
|
| 60 | - return ''; |
|
| 61 | - } |
|
| 57 | + public function collation() { |
|
| 58 | + global $wpdb; |
|
| 59 | + if ( ! $wpdb->has_cap( 'collation' ) ) { |
|
| 60 | + return ''; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $charset_collate = ''; |
|
| 63 | + $charset_collate = ''; |
|
| 64 | 64 | if ( ! empty( $wpdb->charset ) ) { |
| 65 | 65 | $charset_collate .= ' DEFAULT CHARACTER SET ' . $wpdb->charset; |
| 66 | 66 | } |
@@ -69,14 +69,14 @@ discard block |
||
| 69 | 69 | $charset_collate .= ' COLLATE ' . $wpdb->collate; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - return $charset_collate; |
|
| 73 | - } |
|
| 72 | + return $charset_collate; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - private function create_tables() { |
|
| 76 | - $charset_collate = $this->collation(); |
|
| 77 | - $sql = array(); |
|
| 75 | + private function create_tables() { |
|
| 76 | + $charset_collate = $this->collation(); |
|
| 77 | + $sql = array(); |
|
| 78 | 78 | |
| 79 | - /* Create/Upgrade Fields Table */ |
|
| 79 | + /* Create/Upgrade Fields Table */ |
|
| 80 | 80 | $sql[] = 'CREATE TABLE ' . $this->fields . ' ( |
| 81 | 81 | id int(11) NOT NULL auto_increment, |
| 82 | 82 | field_key varchar(100) default NULL, |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | UNIQUE KEY field_key (field_key) |
| 96 | 96 | )'; |
| 97 | 97 | |
| 98 | - /* Create/Upgrade Forms Table */ |
|
| 98 | + /* Create/Upgrade Forms Table */ |
|
| 99 | 99 | $sql[] = 'CREATE TABLE ' . $this->forms . ' ( |
| 100 | 100 | id int(11) NOT NULL auto_increment, |
| 101 | 101 | form_key varchar(100) default NULL, |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | UNIQUE KEY form_key (form_key) |
| 114 | 114 | )'; |
| 115 | 115 | |
| 116 | - /* Create/Upgrade Items Table */ |
|
| 116 | + /* Create/Upgrade Items Table */ |
|
| 117 | 117 | $sql[] = 'CREATE TABLE ' . $this->entries . ' ( |
| 118 | 118 | id int(11) NOT NULL auto_increment, |
| 119 | 119 | item_key varchar(100) default NULL, |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | UNIQUE KEY item_key (item_key) |
| 137 | 137 | )'; |
| 138 | 138 | |
| 139 | - /* Create/Upgrade Meta Table */ |
|
| 139 | + /* Create/Upgrade Meta Table */ |
|
| 140 | 140 | $sql[] = 'CREATE TABLE ' . $this->entry_metas . ' ( |
| 141 | 141 | id int(11) NOT NULL auto_increment, |
| 142 | 142 | meta_value longtext default NULL, |
@@ -148,43 +148,43 @@ discard block |
||
| 148 | 148 | KEY item_id (item_id) |
| 149 | 149 | )'; |
| 150 | 150 | |
| 151 | - foreach ( $sql as $q ) { |
|
| 151 | + foreach ( $sql as $q ) { |
|
| 152 | 152 | if ( function_exists( 'dbDelta' ) ) { |
| 153 | 153 | dbDelta( $q . $charset_collate . ';' ); |
| 154 | 154 | } else { |
| 155 | 155 | global $wpdb; |
| 156 | 156 | $wpdb->query( $q . $charset_collate ); |
| 157 | 157 | } |
| 158 | - unset($q); |
|
| 159 | - } |
|
| 160 | - } |
|
| 158 | + unset($q); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * @param integer $frm_db_version |
|
| 162 | + /** |
|
| 163 | + * @param integer $frm_db_version |
|
| 164 | 164 | * @param int $old_db_version |
| 165 | - */ |
|
| 165 | + */ |
|
| 166 | 166 | private function migrate_data( $frm_db_version, $old_db_version ) { |
| 167 | 167 | $migrations = array( 4, 6, 11, 16, 17, 23, 25 ); |
| 168 | - foreach ( $migrations as $migration ) { |
|
| 169 | - if ( $frm_db_version >= $migration && $old_db_version < $migration ) { |
|
| 168 | + foreach ( $migrations as $migration ) { |
|
| 169 | + if ( $frm_db_version >= $migration && $old_db_version < $migration ) { |
|
| 170 | 170 | $function_name = 'migrate_to_' . $migration; |
| 171 | - $this->$function_name(); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - } |
|
| 171 | + $this->$function_name(); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Change array into format $wpdb->prepare can use |
|
| 176 | + /** |
|
| 177 | + * Change array into format $wpdb->prepare can use |
|
| 178 | 178 | * |
| 179 | 179 | * @param array $args |
| 180 | 180 | * @param string $starts_with |
| 181 | - */ |
|
| 182 | - public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) { |
|
| 183 | - if ( empty($args) ) { |
|
| 181 | + */ |
|
| 182 | + public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) { |
|
| 183 | + if ( empty($args) ) { |
|
| 184 | 184 | // add an arg to prevent prepare from failing |
| 185 | 185 | $args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) ); |
| 186 | 186 | return; |
| 187 | - } |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | 189 | $where = ''; |
| 190 | 190 | $values = array(); |
@@ -195,64 +195,64 @@ discard block |
||
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | $args = compact( 'where', 'values' ); |
| 198 | - } |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - /** |
|
| 200 | + /** |
|
| 201 | 201 | * @param array $args |
| 202 | - * @param string $base_where |
|
| 203 | - * @param string $where |
|
| 202 | + * @param string $base_where |
|
| 203 | + * @param string $where |
|
| 204 | 204 | * @param array $values |
| 205 | - */ |
|
| 206 | - public static function parse_where_from_array( $args, $base_where, &$where, &$values ) { |
|
| 207 | - $condition = ' AND'; |
|
| 208 | - if ( isset( $args['or'] ) ) { |
|
| 209 | - $condition = ' OR'; |
|
| 210 | - unset( $args['or'] ); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - foreach ( $args as $key => $value ) { |
|
| 214 | - $where .= empty( $where ) ? $base_where : $condition; |
|
| 215 | - $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) ); |
|
| 216 | - if ( is_numeric( $key ) || $array_inc_null ) { |
|
| 217 | - $where .= ' ( '; |
|
| 218 | - $nested_where = ''; |
|
| 219 | - if ( $array_inc_null ) { |
|
| 220 | - foreach ( $value as $val ) { |
|
| 221 | - self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values ); |
|
| 222 | - } |
|
| 223 | - } else { |
|
| 224 | - self::parse_where_from_array( $value, '', $nested_where, $values ); |
|
| 225 | - } |
|
| 226 | - $where .= $nested_where; |
|
| 227 | - $where .= ' ) '; |
|
| 228 | - } else { |
|
| 229 | - self::interpret_array_to_sql( $key, $value, $where, $values ); |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * @param string $key |
|
| 205 | + */ |
|
| 206 | + public static function parse_where_from_array( $args, $base_where, &$where, &$values ) { |
|
| 207 | + $condition = ' AND'; |
|
| 208 | + if ( isset( $args['or'] ) ) { |
|
| 209 | + $condition = ' OR'; |
|
| 210 | + unset( $args['or'] ); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + foreach ( $args as $key => $value ) { |
|
| 214 | + $where .= empty( $where ) ? $base_where : $condition; |
|
| 215 | + $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) ); |
|
| 216 | + if ( is_numeric( $key ) || $array_inc_null ) { |
|
| 217 | + $where .= ' ( '; |
|
| 218 | + $nested_where = ''; |
|
| 219 | + if ( $array_inc_null ) { |
|
| 220 | + foreach ( $value as $val ) { |
|
| 221 | + self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values ); |
|
| 222 | + } |
|
| 223 | + } else { |
|
| 224 | + self::parse_where_from_array( $value, '', $nested_where, $values ); |
|
| 225 | + } |
|
| 226 | + $where .= $nested_where; |
|
| 227 | + $where .= ' ) '; |
|
| 228 | + } else { |
|
| 229 | + self::interpret_array_to_sql( $key, $value, $where, $values ); |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * @param string $key |
|
| 236 | 236 | * @param string|array $value |
| 237 | - * @param string $where |
|
| 237 | + * @param string $where |
|
| 238 | 238 | * @param array $values |
| 239 | - */ |
|
| 240 | - private static function interpret_array_to_sql( $key, $value, &$where, &$values ) { |
|
| 239 | + */ |
|
| 240 | + private static function interpret_array_to_sql( $key, $value, &$where, &$values ) { |
|
| 241 | 241 | $key = trim( $key ); |
| 242 | 242 | |
| 243 | 243 | if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) { |
| 244 | - $k = explode(' ', $key); |
|
| 245 | - $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key ); |
|
| 246 | - $values[] = '%Y-%m-%d %H:%i:%s'; |
|
| 247 | - } else { |
|
| 244 | + $k = explode(' ', $key); |
|
| 245 | + $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key ); |
|
| 246 | + $values[] = '%Y-%m-%d %H:%i:%s'; |
|
| 247 | + } else { |
|
| 248 | 248 | $where .= ' ' . $key; |
| 249 | - } |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | 251 | $lowercase_key = explode( ' ', strtolower( $key ) ); |
| 252 | 252 | $lowercase_key = end( $lowercase_key ); |
| 253 | 253 | |
| 254 | - if ( is_array( $value ) ) { |
|
| 255 | - // translate array of values to "in" |
|
| 254 | + if ( is_array( $value ) ) { |
|
| 255 | + // translate array of values to "in" |
|
| 256 | 256 | if ( strpos( $lowercase_key, 'like' ) !== false ) { |
| 257 | 257 | $where = preg_replace('/' . $key . '$/', '', $where); |
| 258 | 258 | $where .= '('; |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $where .= ' in (' . FrmAppHelper::prepare_array_values( $value, '%s' ) . ')'; |
| 271 | 271 | $values = array_merge( $values, $value ); |
| 272 | 272 | } |
| 273 | - } else if ( strpos( $lowercase_key, 'like' ) !== false ) { |
|
| 273 | + } else if ( strpos( $lowercase_key, 'like' ) !== false ) { |
|
| 274 | 274 | /** |
| 275 | 275 | * Allow string to start or end with the value |
| 276 | 276 | * If the key is like% then skip the first % for starts with |
@@ -290,9 +290,9 @@ discard block |
||
| 290 | 290 | $where .= ' %s'; |
| 291 | 291 | $values[] = $start . FrmAppHelper::esc_like( $value ) . $end; |
| 292 | 292 | |
| 293 | - } else if ( $value === null ) { |
|
| 294 | - $where .= ' IS NULL'; |
|
| 295 | - } else { |
|
| 293 | + } else if ( $value === null ) { |
|
| 294 | + $where .= ' IS NULL'; |
|
| 295 | + } else { |
|
| 296 | 296 | // allow a - to prevent = from being added |
| 297 | 297 | if ( substr( $key, -1 ) == '-' ) { |
| 298 | 298 | $where = rtrim( $where, '-' ); |
@@ -302,9 +302,9 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | self::add_query_placeholder( $key, $value, $where ); |
| 304 | 304 | |
| 305 | - $values[] = $value; |
|
| 306 | - } |
|
| 307 | - } |
|
| 305 | + $values[] = $value; |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | 309 | /** |
| 310 | 310 | * Add %d, or %s to query |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * @param int|string $value |
| 315 | 315 | * @param string $where |
| 316 | 316 | */ |
| 317 | - private static function add_query_placeholder( $key, $value, &$where ) { |
|
| 317 | + private static function add_query_placeholder( $key, $value, &$where ) { |
|
| 318 | 318 | if ( is_numeric( $value ) && strpos( $key, 'meta_value' ) === false ) { |
| 319 | 319 | $where .= '%d'; |
| 320 | 320 | } else { |
@@ -322,16 +322,16 @@ discard block |
||
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - /** |
|
| 326 | - * @param string $table |
|
| 325 | + /** |
|
| 326 | + * @param string $table |
|
| 327 | 327 | * @param array $where |
| 328 | 328 | * @param array $args |
| 329 | 329 | * @return int |
| 330 | - */ |
|
| 331 | - public static function get_count( $table, $where = array(), $args = array() ) { |
|
| 332 | - $count = self::get_var( $table, $where, 'COUNT(*)', $args ); |
|
| 333 | - return $count; |
|
| 334 | - } |
|
| 330 | + */ |
|
| 331 | + public static function get_count( $table, $where = array(), $args = array() ) { |
|
| 332 | + $count = self::get_var( $table, $where, 'COUNT(*)', $args ); |
|
| 333 | + return $count; |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | 336 | /** |
| 337 | 337 | * @param string $table |
@@ -342,56 +342,56 @@ discard block |
||
| 342 | 342 | * @param string $type |
| 343 | 343 | * @return array|null|string|object |
| 344 | 344 | */ |
| 345 | - public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) { |
|
| 346 | - $group = ''; |
|
| 347 | - self::get_group_and_table_name( $table, $group ); |
|
| 345 | + public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) { |
|
| 346 | + $group = ''; |
|
| 347 | + self::get_group_and_table_name( $table, $group ); |
|
| 348 | 348 | self::convert_options_to_array( $args, '', $limit ); |
| 349 | 349 | |
| 350 | 350 | $query = self::generate_query_string_from_pieces( $field, $table, $where, $args ); |
| 351 | 351 | |
| 352 | 352 | $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field . '_' . $type, ' WHERE' ) ); |
| 353 | 353 | $results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_' . $type ); |
| 354 | - return $results; |
|
| 355 | - } |
|
| 354 | + return $results; |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * @param string $table |
|
| 359 | - * @param array $where |
|
| 357 | + /** |
|
| 358 | + * @param string $table |
|
| 359 | + * @param array $where |
|
| 360 | 360 | * @param string $field |
| 361 | 361 | * @param array $args |
| 362 | 362 | * @param string $limit |
| 363 | 363 | * @return mixed |
| 364 | - */ |
|
| 365 | - public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) { |
|
| 366 | - return self::get_var( $table, $where, $field, $args, $limit, 'col' ); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @since 2.0 |
|
| 371 | - * @param string $table |
|
| 364 | + */ |
|
| 365 | + public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) { |
|
| 366 | + return self::get_var( $table, $where, $field, $args, $limit, 'col' ); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @since 2.0 |
|
| 371 | + * @param string $table |
|
| 372 | 372 | * @param array $where |
| 373 | 373 | * @param string $fields |
| 374 | 374 | * @param array $args |
| 375 | 375 | * @return mixed |
| 376 | - */ |
|
| 377 | - public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) { |
|
| 378 | - $args['limit'] = 1; |
|
| 379 | - return self::get_var( $table, $where, $fields, $args, '', 'row' ); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Prepare a key/value array before DB call |
|
| 376 | + */ |
|
| 377 | + public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) { |
|
| 378 | + $args['limit'] = 1; |
|
| 379 | + return self::get_var( $table, $where, $fields, $args, '', 'row' ); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Prepare a key/value array before DB call |
|
| 384 | 384 | * |
| 385 | - * @since 2.0 |
|
| 386 | - * @param string $table |
|
| 385 | + * @since 2.0 |
|
| 386 | + * @param string $table |
|
| 387 | 387 | * @param array $where |
| 388 | 388 | * @param string $fields |
| 389 | 389 | * @param array $args |
| 390 | 390 | * @return mixed |
| 391 | - */ |
|
| 392 | - public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) { |
|
| 393 | - return self::get_var( $table, $where, $fields, $args, '', 'results' ); |
|
| 394 | - } |
|
| 391 | + */ |
|
| 392 | + public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) { |
|
| 393 | + return self::get_var( $table, $where, $fields, $args, '', 'results' ); |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | 396 | /** |
| 397 | 397 | * Check for like, not like, in, not in, =, !=, >, <, <=, >= |
@@ -428,59 +428,59 @@ discard block |
||
| 428 | 428 | return ''; |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - /** |
|
| 432 | - * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join |
|
| 433 | - * Also add the wpdb->prefix to the table if it's missing |
|
| 434 | - * |
|
| 435 | - * @param string $table |
|
| 436 | - * @param string $group |
|
| 437 | - */ |
|
| 438 | - private static function get_group_and_table_name( &$table, &$group ) { |
|
| 431 | + /** |
|
| 432 | + * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join |
|
| 433 | + * Also add the wpdb->prefix to the table if it's missing |
|
| 434 | + * |
|
| 435 | + * @param string $table |
|
| 436 | + * @param string $group |
|
| 437 | + */ |
|
| 438 | + private static function get_group_and_table_name( &$table, &$group ) { |
|
| 439 | 439 | global $wpdb, $wpmuBaseTablePrefix; |
| 440 | 440 | |
| 441 | - $table_parts = explode(' ', $table); |
|
| 442 | - $group = reset($table_parts); |
|
| 443 | - $group = str_replace( $wpdb->prefix, '', $group ); |
|
| 441 | + $table_parts = explode(' ', $table); |
|
| 442 | + $group = reset($table_parts); |
|
| 443 | + $group = str_replace( $wpdb->prefix, '', $group ); |
|
| 444 | 444 | |
| 445 | 445 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix; |
| 446 | 446 | $group = str_replace( $prefix, '', $group ); |
| 447 | 447 | |
| 448 | - if ( $group == $table ) { |
|
| 449 | - $table = $wpdb->prefix . $table; |
|
| 450 | - } |
|
| 448 | + if ( $group == $table ) { |
|
| 449 | + $table = $wpdb->prefix . $table; |
|
| 450 | + } |
|
| 451 | 451 | |
| 452 | 452 | // switch to singular group name |
| 453 | 453 | $group = rtrim( $group, 's' ); |
| 454 | - } |
|
| 454 | + } |
|
| 455 | 455 | |
| 456 | - private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) { |
|
| 457 | - if ( ! is_array($args) ) { |
|
| 456 | + private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) { |
|
| 457 | + if ( ! is_array($args) ) { |
|
| 458 | 458 | $args = array( 'order_by' => $args ); |
| 459 | - } |
|
| 459 | + } |
|
| 460 | 460 | |
| 461 | - if ( ! empty( $order_by ) ) { |
|
| 462 | - $args['order_by'] = $order_by; |
|
| 463 | - } |
|
| 461 | + if ( ! empty( $order_by ) ) { |
|
| 462 | + $args['order_by'] = $order_by; |
|
| 463 | + } |
|
| 464 | 464 | |
| 465 | - if ( ! empty( $limit ) ) { |
|
| 466 | - $args['limit'] = $limit; |
|
| 467 | - } |
|
| 465 | + if ( ! empty( $limit ) ) { |
|
| 466 | + $args['limit'] = $limit; |
|
| 467 | + } |
|
| 468 | 468 | |
| 469 | - $temp_args = $args; |
|
| 470 | - foreach ( $temp_args as $k => $v ) { |
|
| 471 | - if ( $v == '' ) { |
|
| 469 | + $temp_args = $args; |
|
| 470 | + foreach ( $temp_args as $k => $v ) { |
|
| 471 | + if ( $v == '' ) { |
|
| 472 | 472 | unset( $args[ $k ] ); |
| 473 | - continue; |
|
| 474 | - } |
|
| 473 | + continue; |
|
| 474 | + } |
|
| 475 | 475 | |
| 476 | - if ( $k == 'limit' ) { |
|
| 476 | + if ( $k == 'limit' ) { |
|
| 477 | 477 | $args[ $k ] = FrmAppHelper::esc_limit( $v ); |
| 478 | - } |
|
| 479 | - $db_name = strtoupper( str_replace( '_', ' ', $k ) ); |
|
| 480 | - if ( strpos( $v, $db_name ) === false ) { |
|
| 478 | + } |
|
| 479 | + $db_name = strtoupper( str_replace( '_', ' ', $k ) ); |
|
| 480 | + if ( strpos( $v, $db_name ) === false ) { |
|
| 481 | 481 | $args[ $k ] = $db_name . ' ' . $v; |
| 482 | - } |
|
| 483 | - } |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | 484 | |
| 485 | 485 | // Make sure LIMIT is the last argument |
| 486 | 486 | if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) { |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | unset( $args['limit'] ); |
| 489 | 489 | $args['limit'] = $temp_limit; |
| 490 | 490 | } |
| 491 | - } |
|
| 491 | + } |
|
| 492 | 492 | |
| 493 | 493 | /** |
| 494 | 494 | * Get the associative array results for the given columns, table, and where query |
@@ -541,31 +541,31 @@ discard block |
||
| 541 | 541 | return $query; |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - public function uninstall() { |
|
| 544 | + public function uninstall() { |
|
| 545 | 545 | if ( ! current_user_can( 'administrator' ) ) { |
| 546 | - $frm_settings = FrmAppHelper::get_settings(); |
|
| 547 | - wp_die($frm_settings->admin_permission); |
|
| 548 | - } |
|
| 546 | + $frm_settings = FrmAppHelper::get_settings(); |
|
| 547 | + wp_die($frm_settings->admin_permission); |
|
| 548 | + } |
|
| 549 | 549 | |
| 550 | - global $wpdb, $wp_roles; |
|
| 550 | + global $wpdb, $wp_roles; |
|
| 551 | 551 | |
| 552 | 552 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); |
| 553 | 553 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); |
| 554 | 554 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); |
| 555 | 555 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); |
| 556 | 556 | |
| 557 | - delete_option('frm_options'); |
|
| 558 | - delete_option('frm_db_version'); |
|
| 557 | + delete_option('frm_options'); |
|
| 558 | + delete_option('frm_db_version'); |
|
| 559 | 559 | |
| 560 | - //delete roles |
|
| 561 | - $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 562 | - $roles = get_editable_roles(); |
|
| 563 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 564 | - foreach ( $roles as $role => $details ) { |
|
| 565 | - $wp_roles->remove_cap( $role, $frm_role ); |
|
| 566 | - unset($role, $details); |
|
| 567 | - } |
|
| 568 | - unset($frm_role, $frm_role_description); |
|
| 560 | + //delete roles |
|
| 561 | + $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 562 | + $roles = get_editable_roles(); |
|
| 563 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 564 | + foreach ( $roles as $role => $details ) { |
|
| 565 | + $wp_roles->remove_cap( $role, $frm_role ); |
|
| 566 | + unset($role, $details); |
|
| 567 | + } |
|
| 568 | + unset($frm_role, $frm_role_description); |
|
| 569 | 569 | } |
| 570 | 570 | unset($roles, $frm_roles); |
| 571 | 571 | |
@@ -589,9 +589,9 @@ discard block |
||
| 589 | 589 | |
| 590 | 590 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) ); |
| 591 | 591 | |
| 592 | - do_action('frm_after_uninstall'); |
|
| 593 | - return true; |
|
| 594 | - } |
|
| 592 | + do_action('frm_after_uninstall'); |
|
| 593 | + return true; |
|
| 594 | + } |
|
| 595 | 595 | |
| 596 | 596 | /** |
| 597 | 597 | * Migrate old styling settings. If sites are using the old |
@@ -630,150 +630,150 @@ discard block |
||
| 630 | 630 | } |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | - /** |
|
| 634 | - * Change field size from character to pixel -- Multiply by 9 |
|
| 635 | - */ |
|
| 636 | - private function migrate_to_17() { |
|
| 637 | - global $wpdb; |
|
| 633 | + /** |
|
| 634 | + * Change field size from character to pixel -- Multiply by 9 |
|
| 635 | + */ |
|
| 636 | + private function migrate_to_17() { |
|
| 637 | + global $wpdb; |
|
| 638 | 638 | $pixel_conversion = 9; |
| 639 | 639 | |
| 640 | - // Get query arguments |
|
| 640 | + // Get query arguments |
|
| 641 | 641 | $field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' ); |
| 642 | 642 | $query = array( 'type' => $field_types, 'field_options like' => 's:4:"size";', 'field_options not like' => 's:4:"size";s:0:' ); |
| 643 | 643 | |
| 644 | - // Get results |
|
| 644 | + // Get results |
|
| 645 | 645 | $fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' ); |
| 646 | 646 | |
| 647 | - $updated = 0; |
|
| 648 | - foreach ( $fields as $f ) { |
|
| 649 | - $f->field_options = maybe_unserialize($f->field_options); |
|
| 650 | - if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) { |
|
| 651 | - continue; |
|
| 652 | - } |
|
| 647 | + $updated = 0; |
|
| 648 | + foreach ( $fields as $f ) { |
|
| 649 | + $f->field_options = maybe_unserialize($f->field_options); |
|
| 650 | + if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) { |
|
| 651 | + continue; |
|
| 652 | + } |
|
| 653 | 653 | |
| 654 | 654 | $f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] ); |
| 655 | - $f->field_options['size'] .= 'px'; |
|
| 656 | - $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) ); |
|
| 657 | - if ( $u ) { |
|
| 658 | - $updated++; |
|
| 659 | - } |
|
| 660 | - unset($f); |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - // Change the characters in widgets to pixels |
|
| 664 | - $widgets = get_option('widget_frm_show_form'); |
|
| 665 | - if ( empty($widgets) ) { |
|
| 666 | - return; |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - $widgets = maybe_unserialize($widgets); |
|
| 670 | - foreach ( $widgets as $k => $widget ) { |
|
| 671 | - if ( ! is_array($widget) || ! isset($widget['size']) ) { |
|
| 672 | - continue; |
|
| 673 | - } |
|
| 655 | + $f->field_options['size'] .= 'px'; |
|
| 656 | + $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) ); |
|
| 657 | + if ( $u ) { |
|
| 658 | + $updated++; |
|
| 659 | + } |
|
| 660 | + unset($f); |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + // Change the characters in widgets to pixels |
|
| 664 | + $widgets = get_option('widget_frm_show_form'); |
|
| 665 | + if ( empty($widgets) ) { |
|
| 666 | + return; |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + $widgets = maybe_unserialize($widgets); |
|
| 670 | + foreach ( $widgets as $k => $widget ) { |
|
| 671 | + if ( ! is_array($widget) || ! isset($widget['size']) ) { |
|
| 672 | + continue; |
|
| 673 | + } |
|
| 674 | 674 | $size = round( $pixel_conversion * (int) $widget['size'] ); |
| 675 | - $size .= 'px'; |
|
| 675 | + $size .= 'px'; |
|
| 676 | 676 | $widgets[ $k ]['size'] = $size; |
| 677 | - } |
|
| 678 | - update_option('widget_frm_show_form', $widgets); |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * Migrate post and email notification settings into actions |
|
| 683 | - */ |
|
| 684 | - private function migrate_to_16() { |
|
| 685 | - global $wpdb; |
|
| 686 | - |
|
| 687 | - $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' ); |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * Old email settings format: |
|
| 691 | - * email_to: Email or field id |
|
| 692 | - * also_email_to: array of fields ids |
|
| 693 | - * reply_to: Email, field id, 'custom' |
|
| 694 | - * cust_reply_to: string |
|
| 695 | - * reply_to_name: field id, 'custom' |
|
| 696 | - * cust_reply_to_name: string |
|
| 697 | - * plain_text: 0|1 |
|
| 698 | - * email_message: string or '' |
|
| 699 | - * email_subject: string or '' |
|
| 700 | - * inc_user_info: 0|1 |
|
| 701 | - * update_email: 0, 1, 2 |
|
| 702 | - * |
|
| 703 | - * Old autoresponder settings format: |
|
| 704 | - * auto_responder: 0|1 |
|
| 705 | - * ar_email_message: string or '' |
|
| 706 | - * ar_email_to: field id |
|
| 707 | - * ar_plain_text: 0|1 |
|
| 708 | - * ar_reply_to_name: string |
|
| 709 | - * ar_reply_to: string |
|
| 710 | - * ar_email_subject: string |
|
| 711 | - * ar_update_email: 0, 1, 2 |
|
| 712 | - * |
|
| 713 | - * New email settings: |
|
| 714 | - * post_content: json settings |
|
| 715 | - * post_title: form id |
|
| 716 | - * post_excerpt: message |
|
| 717 | - * |
|
| 718 | - */ |
|
| 719 | - |
|
| 720 | - foreach ( $forms as $form ) { |
|
| 677 | + } |
|
| 678 | + update_option('widget_frm_show_form', $widgets); |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * Migrate post and email notification settings into actions |
|
| 683 | + */ |
|
| 684 | + private function migrate_to_16() { |
|
| 685 | + global $wpdb; |
|
| 686 | + |
|
| 687 | + $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' ); |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * Old email settings format: |
|
| 691 | + * email_to: Email or field id |
|
| 692 | + * also_email_to: array of fields ids |
|
| 693 | + * reply_to: Email, field id, 'custom' |
|
| 694 | + * cust_reply_to: string |
|
| 695 | + * reply_to_name: field id, 'custom' |
|
| 696 | + * cust_reply_to_name: string |
|
| 697 | + * plain_text: 0|1 |
|
| 698 | + * email_message: string or '' |
|
| 699 | + * email_subject: string or '' |
|
| 700 | + * inc_user_info: 0|1 |
|
| 701 | + * update_email: 0, 1, 2 |
|
| 702 | + * |
|
| 703 | + * Old autoresponder settings format: |
|
| 704 | + * auto_responder: 0|1 |
|
| 705 | + * ar_email_message: string or '' |
|
| 706 | + * ar_email_to: field id |
|
| 707 | + * ar_plain_text: 0|1 |
|
| 708 | + * ar_reply_to_name: string |
|
| 709 | + * ar_reply_to: string |
|
| 710 | + * ar_email_subject: string |
|
| 711 | + * ar_update_email: 0, 1, 2 |
|
| 712 | + * |
|
| 713 | + * New email settings: |
|
| 714 | + * post_content: json settings |
|
| 715 | + * post_title: form id |
|
| 716 | + * post_excerpt: message |
|
| 717 | + * |
|
| 718 | + */ |
|
| 719 | + |
|
| 720 | + foreach ( $forms as $form ) { |
|
| 721 | 721 | if ( $form->is_template && $form->default_template ) { |
| 722 | 722 | // don't migrate the default templates since the email will be added anyway |
| 723 | 723 | continue; |
| 724 | 724 | } |
| 725 | 725 | |
| 726 | - // Format form options |
|
| 727 | - $form_options = maybe_unserialize($form->options); |
|
| 726 | + // Format form options |
|
| 727 | + $form_options = maybe_unserialize($form->options); |
|
| 728 | 728 | |
| 729 | - // Migrate settings to actions |
|
| 730 | - FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); |
|
| 731 | - } |
|
| 732 | - } |
|
| 729 | + // Migrate settings to actions |
|
| 730 | + FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); |
|
| 731 | + } |
|
| 732 | + } |
|
| 733 | 733 | |
| 734 | - private function migrate_to_11() { |
|
| 735 | - global $wpdb; |
|
| 734 | + private function migrate_to_11() { |
|
| 735 | + global $wpdb; |
|
| 736 | 736 | |
| 737 | - $forms = FrmDb::get_results( $this->forms, array(), 'id, options'); |
|
| 737 | + $forms = FrmDb::get_results( $this->forms, array(), 'id, options'); |
|
| 738 | 738 | |
| 739 | - $sending = __( 'Sending', 'formidable' ); |
|
| 739 | + $sending = __( 'Sending', 'formidable' ); |
|
| 740 | 740 | $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif'; |
| 741 | - $old_default_html = <<<DEFAULT_HTML |
|
| 741 | + $old_default_html = <<<DEFAULT_HTML |
|
| 742 | 742 | <div class="frm_submit"> |
| 743 | 743 | [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button] |
| 744 | 744 | <input type="submit" value="[button_label]" [button_action] /> |
| 745 | 745 | <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" /> |
| 746 | 746 | </div> |
| 747 | 747 | DEFAULT_HTML; |
| 748 | - unset($sending, $img); |
|
| 748 | + unset($sending, $img); |
|
| 749 | 749 | |
| 750 | - $new_default_html = FrmFormsHelper::get_default_html('submit'); |
|
| 751 | - $draft_link = FrmFormsHelper::get_draft_link(); |
|
| 750 | + $new_default_html = FrmFormsHelper::get_default_html('submit'); |
|
| 751 | + $draft_link = FrmFormsHelper::get_draft_link(); |
|
| 752 | 752 | foreach ( $forms as $form ) { |
| 753 | - $form->options = maybe_unserialize($form->options); |
|
| 754 | - if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) { |
|
| 755 | - continue; |
|
| 756 | - } |
|
| 753 | + $form->options = maybe_unserialize($form->options); |
|
| 754 | + if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) { |
|
| 755 | + continue; |
|
| 756 | + } |
|
| 757 | 757 | |
| 758 | - if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |
|
| 759 | - $form->options['submit_html'] = $new_default_html; |
|
| 758 | + if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |
|
| 759 | + $form->options['submit_html'] = $new_default_html; |
|
| 760 | 760 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 761 | 761 | } else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) { |
| 762 | 762 | $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] ); |
| 763 | 763 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 764 | - } |
|
| 765 | - unset($form); |
|
| 766 | - } |
|
| 767 | - unset($forms); |
|
| 768 | - } |
|
| 764 | + } |
|
| 765 | + unset($form); |
|
| 766 | + } |
|
| 767 | + unset($forms); |
|
| 768 | + } |
|
| 769 | 769 | |
| 770 | - private function migrate_to_6() { |
|
| 771 | - global $wpdb; |
|
| 770 | + private function migrate_to_6() { |
|
| 771 | + global $wpdb; |
|
| 772 | 772 | |
| 773 | 773 | $no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) ); |
| 774 | 774 | $fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' ); |
| 775 | 775 | |
| 776 | - $default_html = <<<DEFAULT_HTML |
|
| 776 | + $default_html = <<<DEFAULT_HTML |
|
| 777 | 777 | <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]"> |
| 778 | 778 | <label class="frm_pos_[label_position]">[field_name] |
| 779 | 779 | <span class="frm_required">[required_label]</span> |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | </div> |
| 784 | 784 | DEFAULT_HTML; |
| 785 | 785 | |
| 786 | - $old_default_html = <<<DEFAULT_HTML |
|
| 786 | + $old_default_html = <<<DEFAULT_HTML |
|
| 787 | 787 | <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]"> |
| 788 | 788 | <label class="frm_pos_[label_position]">[field_name] |
| 789 | 789 | <span class="frm_required">[required_label]</span> |
@@ -793,25 +793,25 @@ discard block |
||
| 793 | 793 | </div> |
| 794 | 794 | DEFAULT_HTML; |
| 795 | 795 | |
| 796 | - $new_default_html = FrmFieldsHelper::get_default_html('text'); |
|
| 797 | - foreach ( $fields as $field ) { |
|
| 798 | - $field->field_options = maybe_unserialize($field->field_options); |
|
| 796 | + $new_default_html = FrmFieldsHelper::get_default_html('text'); |
|
| 797 | + foreach ( $fields as $field ) { |
|
| 798 | + $field->field_options = maybe_unserialize($field->field_options); |
|
| 799 | 799 | if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) { |
| 800 | - $field->field_options['custom_html'] = $new_default_html; |
|
| 800 | + $field->field_options['custom_html'] = $new_default_html; |
|
| 801 | 801 | $wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) ); |
| 802 | - } |
|
| 803 | - unset($field); |
|
| 804 | - } |
|
| 805 | - unset($default_html, $old_default_html, $fields); |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - private function migrate_to_4() { |
|
| 809 | - global $wpdb; |
|
| 802 | + } |
|
| 803 | + unset($field); |
|
| 804 | + } |
|
| 805 | + unset($default_html, $old_default_html, $fields); |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + private function migrate_to_4() { |
|
| 809 | + global $wpdb; |
|
| 810 | 810 | $user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) ); |
| 811 | - foreach ( $user_ids as $user_id ) { |
|
| 811 | + foreach ( $user_ids as $user_id ) { |
|
| 812 | 812 | $wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) ); |
| 813 | - } |
|
| 814 | - } |
|
| 813 | + } |
|
| 814 | + } |
|
| 815 | 815 | |
| 816 | 816 | public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) { |
| 817 | 817 | _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' ); |
@@ -7,8 +7,8 @@ discard block |
||
| 7 | 7 | var $entry_metas; |
| 8 | 8 | |
| 9 | 9 | public function __construct() { |
| 10 | - if ( ! defined('ABSPATH') ) { |
|
| 11 | - die('You are not allowed to call this page directly.'); |
|
| 10 | + if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | + die( 'You are not allowed to call this page directly.' ); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | global $wpdb; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | $frm_db_version = FrmAppHelper::$db_version; |
| 27 | 27 | $old_db_version = (float) $old_db_version; |
| 28 | 28 | if ( ! $old_db_version ) { |
| 29 | - $old_db_version = get_option('frm_db_version'); |
|
| 29 | + $old_db_version = get_option( 'frm_db_version' ); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | if ( $frm_db_version != $old_db_version ) { |
@@ -36,16 +36,16 @@ discard block |
||
| 36 | 36 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 37 | 37 | |
| 38 | 38 | $this->create_tables(); |
| 39 | - $this->migrate_data($frm_db_version, $old_db_version); |
|
| 39 | + $this->migrate_data( $frm_db_version, $old_db_version ); |
|
| 40 | 40 | |
| 41 | 41 | /***** SAVE DB VERSION *****/ |
| 42 | - update_option('frm_db_version', $frm_db_version); |
|
| 42 | + update_option( 'frm_db_version', $frm_db_version ); |
|
| 43 | 43 | |
| 44 | 44 | /**** ADD/UPDATE DEFAULT TEMPLATES ****/ |
| 45 | 45 | FrmXMLController::add_default_templates(); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - do_action('frm_after_install'); |
|
| 48 | + do_action( 'frm_after_install' ); |
|
| 49 | 49 | |
| 50 | 50 | /**** update the styling settings ****/ |
| 51 | 51 | if ( is_admin() && function_exists( 'get_filesystem_method' ) ) { |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | global $wpdb; |
| 156 | 156 | $wpdb->query( $q . $charset_collate ); |
| 157 | 157 | } |
| 158 | - unset($q); |
|
| 158 | + unset( $q ); |
|
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * @param string $starts_with |
| 181 | 181 | */ |
| 182 | 182 | public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) { |
| 183 | - if ( empty($args) ) { |
|
| 183 | + if ( empty( $args ) ) { |
|
| 184 | 184 | // add an arg to prevent prepare from failing |
| 185 | 185 | $args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) ); |
| 186 | 186 | return; |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | $key = trim( $key ); |
| 242 | 242 | |
| 243 | 243 | if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) { |
| 244 | - $k = explode(' ', $key); |
|
| 244 | + $k = explode( ' ', $key ); |
|
| 245 | 245 | $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key ); |
| 246 | 246 | $values[] = '%Y-%m-%d %H:%i:%s'; |
| 247 | 247 | } else { |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | if ( is_array( $value ) ) { |
| 255 | 255 | // translate array of values to "in" |
| 256 | 256 | if ( strpos( $lowercase_key, 'like' ) !== false ) { |
| 257 | - $where = preg_replace('/' . $key . '$/', '', $where); |
|
| 257 | + $where = preg_replace( '/' . $key . '$/', '', $where ); |
|
| 258 | 258 | $where .= '('; |
| 259 | 259 | $start = true; |
| 260 | 260 | foreach ( $value as $v ) { |
@@ -415,8 +415,8 @@ discard block |
||
| 415 | 415 | ); |
| 416 | 416 | |
| 417 | 417 | $where_is = strtolower( $where_is ); |
| 418 | - if ( isset( $switch_to[ $where_is ] ) ) { |
|
| 419 | - return ' ' . $switch_to[ $where_is ]; |
|
| 418 | + if ( isset( $switch_to[$where_is] ) ) { |
|
| 419 | + return ' ' . $switch_to[$where_is]; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | // > and < need a little more work since we don't want them switched to >= and <= |
@@ -438,8 +438,8 @@ discard block |
||
| 438 | 438 | private static function get_group_and_table_name( &$table, &$group ) { |
| 439 | 439 | global $wpdb, $wpmuBaseTablePrefix; |
| 440 | 440 | |
| 441 | - $table_parts = explode(' ', $table); |
|
| 442 | - $group = reset($table_parts); |
|
| 441 | + $table_parts = explode( ' ', $table ); |
|
| 442 | + $group = reset( $table_parts ); |
|
| 443 | 443 | $group = str_replace( $wpdb->prefix, '', $group ); |
| 444 | 444 | |
| 445 | 445 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix; |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) { |
| 457 | - if ( ! is_array($args) ) { |
|
| 457 | + if ( ! is_array( $args ) ) { |
|
| 458 | 458 | $args = array( 'order_by' => $args ); |
| 459 | 459 | } |
| 460 | 460 | |
@@ -469,16 +469,16 @@ discard block |
||
| 469 | 469 | $temp_args = $args; |
| 470 | 470 | foreach ( $temp_args as $k => $v ) { |
| 471 | 471 | if ( $v == '' ) { |
| 472 | - unset( $args[ $k ] ); |
|
| 472 | + unset( $args[$k] ); |
|
| 473 | 473 | continue; |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | if ( $k == 'limit' ) { |
| 477 | - $args[ $k ] = FrmAppHelper::esc_limit( $v ); |
|
| 477 | + $args[$k] = FrmAppHelper::esc_limit( $v ); |
|
| 478 | 478 | } |
| 479 | 479 | $db_name = strtoupper( str_replace( '_', ' ', $k ) ); |
| 480 | 480 | if ( strpos( $v, $db_name ) === false ) { |
| 481 | - $args[ $k ] = $db_name . ' ' . $v; |
|
| 481 | + $args[$k] = $db_name . ' ' . $v; |
|
| 482 | 482 | } |
| 483 | 483 | } |
| 484 | 484 | |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | |
| 506 | 506 | $query = self::generate_query_string_from_pieces( $columns, $table, $where ); |
| 507 | 507 | |
| 508 | - $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . $columns . '_results_ARRAY_A' , ' WHERE' ) ); |
|
| 508 | + $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . $columns . '_results_ARRAY_A', ' WHERE' ) ); |
|
| 509 | 509 | $results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_associative_results' ); |
| 510 | 510 | |
| 511 | 511 | return $results; |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | public function uninstall() { |
| 545 | 545 | if ( ! current_user_can( 'administrator' ) ) { |
| 546 | 546 | $frm_settings = FrmAppHelper::get_settings(); |
| 547 | - wp_die($frm_settings->admin_permission); |
|
| 547 | + wp_die( $frm_settings->admin_permission ); |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | global $wpdb, $wp_roles; |
@@ -554,8 +554,8 @@ discard block |
||
| 554 | 554 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); |
| 555 | 555 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); |
| 556 | 556 | |
| 557 | - delete_option('frm_options'); |
|
| 558 | - delete_option('frm_db_version'); |
|
| 557 | + delete_option( 'frm_options' ); |
|
| 558 | + delete_option( 'frm_db_version' ); |
|
| 559 | 559 | |
| 560 | 560 | //delete roles |
| 561 | 561 | $frm_roles = FrmAppHelper::frm_capabilities(); |
@@ -563,11 +563,11 @@ discard block |
||
| 563 | 563 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
| 564 | 564 | foreach ( $roles as $role => $details ) { |
| 565 | 565 | $wp_roles->remove_cap( $role, $frm_role ); |
| 566 | - unset($role, $details); |
|
| 566 | + unset( $role, $details ); |
|
| 567 | 567 | } |
| 568 | - unset($frm_role, $frm_role_description); |
|
| 568 | + unset( $frm_role, $frm_role_description ); |
|
| 569 | 569 | } |
| 570 | - unset($roles, $frm_roles); |
|
| 570 | + unset( $roles, $frm_roles ); |
|
| 571 | 571 | |
| 572 | 572 | // delete actions, views, and styles |
| 573 | 573 | |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | |
| 590 | 590 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) ); |
| 591 | 591 | |
| 592 | - do_action('frm_after_uninstall'); |
|
| 592 | + do_action( 'frm_after_uninstall' ); |
|
| 593 | 593 | return true; |
| 594 | 594 | } |
| 595 | 595 | |
@@ -646,8 +646,8 @@ discard block |
||
| 646 | 646 | |
| 647 | 647 | $updated = 0; |
| 648 | 648 | foreach ( $fields as $f ) { |
| 649 | - $f->field_options = maybe_unserialize($f->field_options); |
|
| 650 | - if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) { |
|
| 649 | + $f->field_options = maybe_unserialize( $f->field_options ); |
|
| 650 | + if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) { |
|
| 651 | 651 | continue; |
| 652 | 652 | } |
| 653 | 653 | |
@@ -655,27 +655,27 @@ discard block |
||
| 655 | 655 | $f->field_options['size'] .= 'px'; |
| 656 | 656 | $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) ); |
| 657 | 657 | if ( $u ) { |
| 658 | - $updated++; |
|
| 658 | + $updated ++; |
|
| 659 | 659 | } |
| 660 | - unset($f); |
|
| 660 | + unset( $f ); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | // Change the characters in widgets to pixels |
| 664 | - $widgets = get_option('widget_frm_show_form'); |
|
| 665 | - if ( empty($widgets) ) { |
|
| 664 | + $widgets = get_option( 'widget_frm_show_form' ); |
|
| 665 | + if ( empty( $widgets ) ) { |
|
| 666 | 666 | return; |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | - $widgets = maybe_unserialize($widgets); |
|
| 669 | + $widgets = maybe_unserialize( $widgets ); |
|
| 670 | 670 | foreach ( $widgets as $k => $widget ) { |
| 671 | - if ( ! is_array($widget) || ! isset($widget['size']) ) { |
|
| 671 | + if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) { |
|
| 672 | 672 | continue; |
| 673 | 673 | } |
| 674 | 674 | $size = round( $pixel_conversion * (int) $widget['size'] ); |
| 675 | 675 | $size .= 'px'; |
| 676 | - $widgets[ $k ]['size'] = $size; |
|
| 676 | + $widgets[$k]['size'] = $size; |
|
| 677 | 677 | } |
| 678 | - update_option('widget_frm_show_form', $widgets); |
|
| 678 | + update_option( 'widget_frm_show_form', $widgets ); |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | /** |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | // Format form options |
| 727 | - $form_options = maybe_unserialize($form->options); |
|
| 727 | + $form_options = maybe_unserialize( $form->options ); |
|
| 728 | 728 | |
| 729 | 729 | // Migrate settings to actions |
| 730 | 730 | FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | private function migrate_to_11() { |
| 735 | 735 | global $wpdb; |
| 736 | 736 | |
| 737 | - $forms = FrmDb::get_results( $this->forms, array(), 'id, options'); |
|
| 737 | + $forms = FrmDb::get_results( $this->forms, array(), 'id, options' ); |
|
| 738 | 738 | |
| 739 | 739 | $sending = __( 'Sending', 'formidable' ); |
| 740 | 740 | $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif'; |
@@ -745,13 +745,13 @@ discard block |
||
| 745 | 745 | <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" /> |
| 746 | 746 | </div> |
| 747 | 747 | DEFAULT_HTML; |
| 748 | - unset($sending, $img); |
|
| 748 | + unset( $sending, $img ); |
|
| 749 | 749 | |
| 750 | - $new_default_html = FrmFormsHelper::get_default_html('submit'); |
|
| 750 | + $new_default_html = FrmFormsHelper::get_default_html( 'submit' ); |
|
| 751 | 751 | $draft_link = FrmFormsHelper::get_draft_link(); |
| 752 | 752 | foreach ( $forms as $form ) { |
| 753 | - $form->options = maybe_unserialize($form->options); |
|
| 754 | - if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) { |
|
| 753 | + $form->options = maybe_unserialize( $form->options ); |
|
| 754 | + if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) { |
|
| 755 | 755 | continue; |
| 756 | 756 | } |
| 757 | 757 | |
@@ -762,9 +762,9 @@ discard block |
||
| 762 | 762 | $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] ); |
| 763 | 763 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 764 | 764 | } |
| 765 | - unset($form); |
|
| 765 | + unset( $form ); |
|
| 766 | 766 | } |
| 767 | - unset($forms); |
|
| 767 | + unset( $forms ); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | private function migrate_to_6() { |
@@ -793,16 +793,16 @@ discard block |
||
| 793 | 793 | </div> |
| 794 | 794 | DEFAULT_HTML; |
| 795 | 795 | |
| 796 | - $new_default_html = FrmFieldsHelper::get_default_html('text'); |
|
| 796 | + $new_default_html = FrmFieldsHelper::get_default_html( 'text' ); |
|
| 797 | 797 | foreach ( $fields as $field ) { |
| 798 | - $field->field_options = maybe_unserialize($field->field_options); |
|
| 798 | + $field->field_options = maybe_unserialize( $field->field_options ); |
|
| 799 | 799 | if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) { |
| 800 | 800 | $field->field_options['custom_html'] = $new_default_html; |
| 801 | 801 | $wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) ); |
| 802 | 802 | } |
| 803 | - unset($field); |
|
| 803 | + unset( $field ); |
|
| 804 | 804 | } |
| 805 | - unset($default_html, $old_default_html, $fields); |
|
| 805 | + unset( $default_html, $old_default_html, $fields ); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | private function migrate_to_4() { |
@@ -820,6 +820,6 @@ discard block |
||
| 820 | 820 | |
| 821 | 821 | public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) { |
| 822 | 822 | _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' ); |
| 823 | - return self::get_results( $table, $args, $fields, compact('order_by', 'limit') ); |
|
| 823 | + return self::get_results( $table, $args, $fields, compact( 'order_by', 'limit' ) ); |
|
| 824 | 824 | } |
| 825 | 825 | } |
@@ -2,109 +2,109 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class FrmXMLController { |
| 4 | 4 | |
| 5 | - public static function menu() { |
|
| 5 | + public static function menu() { |
|
| 6 | 6 | add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' ); |
| 7 | - } |
|
| 7 | + } |
|
| 8 | 8 | |
| 9 | - public static function add_default_templates() { |
|
| 9 | + public static function add_default_templates() { |
|
| 10 | 10 | if ( ! function_exists( 'libxml_disable_entity_loader' ) ) { |
| 11 | - // XML import is not enabled on your server |
|
| 12 | - return; |
|
| 13 | - } |
|
| 11 | + // XML import is not enabled on your server |
|
| 12 | + return; |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - $set_err = libxml_use_internal_errors(true); |
|
| 16 | - $loader = libxml_disable_entity_loader( true ); |
|
| 15 | + $set_err = libxml_use_internal_errors(true); |
|
| 16 | + $loader = libxml_disable_entity_loader( true ); |
|
| 17 | 17 | |
| 18 | 18 | $files = apply_filters( 'frm_default_templates_files', array( FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml' ) ); |
| 19 | 19 | |
| 20 | - foreach ( (array) $files as $file ) { |
|
| 21 | - FrmXMLHelper::import_xml($file); |
|
| 22 | - unset($file); |
|
| 23 | - } |
|
| 24 | - /* |
|
| 20 | + foreach ( (array) $files as $file ) { |
|
| 21 | + FrmXMLHelper::import_xml($file); |
|
| 22 | + unset($file); |
|
| 23 | + } |
|
| 24 | + /* |
|
| 25 | 25 | if(is_wp_error($result)) |
| 26 | 26 | $errors[] = $result->get_error_message(); |
| 27 | 27 | else if($result) |
| 28 | 28 | $message = $result; |
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | - unset( $files ); |
|
| 31 | + unset( $files ); |
|
| 32 | 32 | |
| 33 | - libxml_use_internal_errors( $set_err ); |
|
| 34 | - libxml_disable_entity_loader( $loader ); |
|
| 35 | - } |
|
| 33 | + libxml_use_internal_errors( $set_err ); |
|
| 34 | + libxml_disable_entity_loader( $loader ); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - public static function route() { |
|
| 38 | - $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
| 37 | + public static function route() { |
|
| 38 | + $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
| 39 | 39 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 40 | 40 | if ( $action == 'import_xml' ) { |
| 41 | - return self::import_xml(); |
|
| 41 | + return self::import_xml(); |
|
| 42 | 42 | } else if ( $action == 'export_xml' ) { |
| 43 | - return self::export_xml(); |
|
| 44 | - } else { |
|
| 45 | - if ( apply_filters( 'frm_xml_route', true, $action ) ) { |
|
| 46 | - return self::form(); |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public static function form( $errors = array(), $message = '' ) { |
|
| 43 | + return self::export_xml(); |
|
| 44 | + } else { |
|
| 45 | + if ( apply_filters( 'frm_xml_route', true, $action ) ) { |
|
| 46 | + return self::form(); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public static function form( $errors = array(), $message = '' ) { |
|
| 52 | 52 | $where = array( |
| 53 | 53 | 'status' => array( null, '', 'published' ), |
| 54 | 54 | ); |
| 55 | 55 | $forms = FrmForm::getAll( $where, 'name' ); |
| 56 | 56 | |
| 57 | - $export_types = apply_filters( 'frm_xml_export_types', |
|
| 58 | - array( 'forms' => __( 'Forms', 'formidable' ), 'items' => __( 'Entries', 'formidable' ) ) |
|
| 59 | - ); |
|
| 57 | + $export_types = apply_filters( 'frm_xml_export_types', |
|
| 58 | + array( 'forms' => __( 'Forms', 'formidable' ), 'items' => __( 'Entries', 'formidable' ) ) |
|
| 59 | + ); |
|
| 60 | 60 | |
| 61 | - $export_format = apply_filters( 'frm_export_formats', array( |
|
| 62 | - 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ), |
|
| 61 | + $export_format = apply_filters( 'frm_export_formats', array( |
|
| 62 | + 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ), |
|
| 63 | 63 | 'csv' => array( 'name' => 'CSV', 'support' => 'items', 'count' => 'single' ), |
| 64 | - ) ); |
|
| 64 | + ) ); |
|
| 65 | 65 | |
| 66 | 66 | include( FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php' ); |
| 67 | - } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public static function import_xml() { |
|
| 70 | - $errors = array(); |
|
| 71 | - $message = ''; |
|
| 69 | + public static function import_xml() { |
|
| 70 | + $errors = array(); |
|
| 71 | + $message = ''; |
|
| 72 | 72 | |
| 73 | - $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce'); |
|
| 74 | - if ( $permission_error !== false ) { |
|
| 75 | - $errors[] = $permission_error; |
|
| 76 | - self::form($errors); |
|
| 77 | - return; |
|
| 78 | - } |
|
| 73 | + $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce'); |
|
| 74 | + if ( $permission_error !== false ) { |
|
| 75 | + $errors[] = $permission_error; |
|
| 76 | + self::form($errors); |
|
| 77 | + return; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) { |
|
| 81 | - $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
|
| 82 | - self::form($errors); |
|
| 83 | - return; |
|
| 84 | - } |
|
| 80 | + if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) { |
|
| 81 | + $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
|
| 82 | + self::form($errors); |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - $file = $_FILES['frm_import_file']['tmp_name']; |
|
| 86 | + $file = $_FILES['frm_import_file']['tmp_name']; |
|
| 87 | 87 | |
| 88 | - if ( ! is_uploaded_file( $file ) ) { |
|
| 89 | - unset($file); |
|
| 90 | - $errors[] = __( 'The file does not exist, please try again.', 'formidable' ); |
|
| 91 | - self::form($errors); |
|
| 92 | - return; |
|
| 93 | - } |
|
| 88 | + if ( ! is_uploaded_file( $file ) ) { |
|
| 89 | + unset($file); |
|
| 90 | + $errors[] = __( 'The file does not exist, please try again.', 'formidable' ); |
|
| 91 | + self::form($errors); |
|
| 92 | + return; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); |
|
| 95 | + //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); |
|
| 96 | 96 | |
| 97 | - $export_format = apply_filters('frm_export_formats', array( |
|
| 97 | + $export_format = apply_filters('frm_export_formats', array( |
|
| 98 | 98 | 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ), |
| 99 | 99 | ) ); |
| 100 | 100 | |
| 101 | - $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION)); |
|
| 102 | - if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) { |
|
| 103 | - // allow other file types to be imported |
|
| 101 | + $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION)); |
|
| 102 | + if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) { |
|
| 103 | + // allow other file types to be imported |
|
| 104 | 104 | do_action( 'frm_before_import_' . $file_type ); |
| 105 | - return; |
|
| 106 | - } |
|
| 107 | - unset($file_type); |
|
| 105 | + return; |
|
| 106 | + } |
|
| 107 | + unset($file_type); |
|
| 108 | 108 | |
| 109 | 109 | if ( ! function_exists( 'libxml_disable_entity_loader' ) ) { |
| 110 | 110 | $errors[] = __( 'XML import is not enabled on your server.', 'formidable' ); |
@@ -123,145 +123,145 @@ discard block |
||
| 123 | 123 | libxml_use_internal_errors( $set_err ); |
| 124 | 124 | libxml_disable_entity_loader( $loader ); |
| 125 | 125 | |
| 126 | - self::form($errors, $message); |
|
| 127 | - } |
|
| 126 | + self::form($errors, $message); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - public static function export_xml() { |
|
| 130 | - $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
|
| 131 | - if ( ! empty($error) ) { |
|
| 132 | - wp_die( $error ); |
|
| 133 | - } |
|
| 129 | + public static function export_xml() { |
|
| 130 | + $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
|
| 131 | + if ( ! empty($error) ) { |
|
| 132 | + wp_die( $error ); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | $ids = FrmAppHelper::get_post_param( 'frm_export_forms', array() ); |
| 136 | 136 | $type = FrmAppHelper::get_post_param( 'type', array() ); |
| 137 | 137 | $format = FrmAppHelper::get_post_param( 'format', 'xml', 'sanitize_title' ); |
| 138 | 138 | |
| 139 | - if ( ! headers_sent() && ! $type ) { |
|
| 140 | - wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) ); |
|
| 141 | - die(); |
|
| 142 | - } |
|
| 139 | + if ( ! headers_sent() && ! $type ) { |
|
| 140 | + wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) ); |
|
| 141 | + die(); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - if ( $format == 'xml' ) { |
|
| 145 | - self::generate_xml($type, compact('ids')); |
|
| 144 | + if ( $format == 'xml' ) { |
|
| 145 | + self::generate_xml($type, compact('ids')); |
|
| 146 | 146 | } if ( $format == 'csv' ) { |
| 147 | 147 | self::generate_csv( compact('ids') ); |
| 148 | - } else { |
|
| 148 | + } else { |
|
| 149 | 149 | do_action( 'frm_export_format_' . $format, compact('ids') ); |
| 150 | - } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - wp_die(); |
|
| 153 | - } |
|
| 152 | + wp_die(); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | 155 | public static function generate_xml( $type, $args = array() ) { |
| 156 | - global $wpdb; |
|
| 156 | + global $wpdb; |
|
| 157 | 157 | |
| 158 | - self::prepare_types_array( $type ); |
|
| 158 | + self::prepare_types_array( $type ); |
|
| 159 | 159 | |
| 160 | - $tables = array( |
|
| 160 | + $tables = array( |
|
| 161 | 161 | 'items' => $wpdb->prefix . 'frm_items', |
| 162 | 162 | 'forms' => $wpdb->prefix . 'frm_forms', |
| 163 | - 'posts' => $wpdb->posts, |
|
| 164 | - 'styles' => $wpdb->posts, |
|
| 165 | - 'actions' => $wpdb->posts, |
|
| 166 | - ); |
|
| 163 | + 'posts' => $wpdb->posts, |
|
| 164 | + 'styles' => $wpdb->posts, |
|
| 165 | + 'actions' => $wpdb->posts, |
|
| 166 | + ); |
|
| 167 | 167 | |
| 168 | 168 | $defaults = array( 'ids' => false ); |
| 169 | - $args = wp_parse_args( $args, $defaults ); |
|
| 169 | + $args = wp_parse_args( $args, $defaults ); |
|
| 170 | 170 | |
| 171 | - $sitename = sanitize_key( get_bloginfo( 'name' ) ); |
|
| 171 | + $sitename = sanitize_key( get_bloginfo( 'name' ) ); |
|
| 172 | 172 | |
| 173 | - if ( ! empty( $sitename ) ) { |
|
| 173 | + if ( ! empty( $sitename ) ) { |
|
| 174 | 174 | $sitename .= '.'; |
| 175 | 175 | } |
| 176 | - $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml'; |
|
| 176 | + $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml'; |
|
| 177 | 177 | |
| 178 | - header( 'Content-Description: File Transfer' ); |
|
| 179 | - header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
| 180 | - header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
|
| 178 | + header( 'Content-Description: File Transfer' ); |
|
| 179 | + header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
| 180 | + header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
|
| 181 | 181 | |
| 182 | - //make sure ids are numeric |
|
| 183 | - if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) { |
|
| 184 | - $args['ids'] = array_filter( $args['ids'], 'is_numeric' ); |
|
| 185 | - } |
|
| 182 | + //make sure ids are numeric |
|
| 183 | + if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) { |
|
| 184 | + $args['ids'] = array_filter( $args['ids'], 'is_numeric' ); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - $records = array(); |
|
| 187 | + $records = array(); |
|
| 188 | 188 | |
| 189 | 189 | foreach ( $type as $tb_type ) { |
| 190 | - $where = array(); |
|
| 190 | + $where = array(); |
|
| 191 | 191 | $join = ''; |
| 192 | - $table = $tables[ $tb_type ]; |
|
| 192 | + $table = $tables[ $tb_type ]; |
|
| 193 | 193 | |
| 194 | 194 | $select = $table . '.id'; |
| 195 | - $query_vars = array(); |
|
| 195 | + $query_vars = array(); |
|
| 196 | 196 | |
| 197 | - switch ( $tb_type ) { |
|
| 198 | - case 'forms': |
|
| 199 | - //add forms |
|
| 200 | - if ( $args['ids'] ) { |
|
| 197 | + switch ( $tb_type ) { |
|
| 198 | + case 'forms': |
|
| 199 | + //add forms |
|
| 200 | + if ( $args['ids'] ) { |
|
| 201 | 201 | $where[] = array( 'or' => 1, $table . '.id' => $args['ids'], $table . '.parent_form_id' => $args['ids'] ); |
| 202 | - } else { |
|
| 202 | + } else { |
|
| 203 | 203 | $where[ $table . '.status !' ] = 'draft'; |
| 204 | - } |
|
| 205 | - break; |
|
| 206 | - case 'actions': |
|
| 204 | + } |
|
| 205 | + break; |
|
| 206 | + case 'actions': |
|
| 207 | 207 | $select = $table . '.ID'; |
| 208 | 208 | $where['post_type'] = FrmFormActionsController::$action_post_type; |
| 209 | - if ( ! empty($args['ids']) ) { |
|
| 209 | + if ( ! empty($args['ids']) ) { |
|
| 210 | 210 | $where['menu_order'] = $args['ids']; |
| 211 | - } |
|
| 212 | - break; |
|
| 213 | - case 'items': |
|
| 214 | - //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)"; |
|
| 215 | - if ( $args['ids'] ) { |
|
| 211 | + } |
|
| 212 | + break; |
|
| 213 | + case 'items': |
|
| 214 | + //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)"; |
|
| 215 | + if ( $args['ids'] ) { |
|
| 216 | 216 | $where[ $table . '.form_id' ] = $args['ids']; |
| 217 | - } |
|
| 218 | - break; |
|
| 219 | - case 'styles': |
|
| 220 | - // Loop through all exported forms and get their selected style IDs |
|
| 217 | + } |
|
| 218 | + break; |
|
| 219 | + case 'styles': |
|
| 220 | + // Loop through all exported forms and get their selected style IDs |
|
| 221 | 221 | $frm_style = new FrmStyle(); |
| 222 | 222 | $default_style = $frm_style->get_default_style(); |
| 223 | - $form_ids = $args['ids']; |
|
| 224 | - $style_ids = array(); |
|
| 225 | - foreach ( $form_ids as $form_id ) { |
|
| 226 | - $form_data = FrmForm::getOne( $form_id ); |
|
| 227 | - // For forms that have not been updated while running 2.0, check if custom_style is set |
|
| 228 | - if ( isset( $form_data->options['custom_style'] ) ) { |
|
| 223 | + $form_ids = $args['ids']; |
|
| 224 | + $style_ids = array(); |
|
| 225 | + foreach ( $form_ids as $form_id ) { |
|
| 226 | + $form_data = FrmForm::getOne( $form_id ); |
|
| 227 | + // For forms that have not been updated while running 2.0, check if custom_style is set |
|
| 228 | + if ( isset( $form_data->options['custom_style'] ) ) { |
|
| 229 | 229 | if ( $form_data->options['custom_style'] == 1 ) { |
| 230 | 230 | $style_ids[] = $default_style->ID; |
| 231 | 231 | } else { |
| 232 | 232 | $style_ids[] = $form_data->options['custom_style']; |
| 233 | 233 | } |
| 234 | - } |
|
| 235 | - unset( $form_id, $form_data ); |
|
| 236 | - } |
|
| 234 | + } |
|
| 235 | + unset( $form_id, $form_data ); |
|
| 236 | + } |
|
| 237 | 237 | $select = $table . '.ID'; |
| 238 | - $where['post_type'] = 'frm_styles'; |
|
| 239 | - |
|
| 240 | - // Only export selected styles |
|
| 241 | - if ( ! empty( $style_ids ) ) { |
|
| 242 | - $where['ID'] = $style_ids; |
|
| 243 | - } |
|
| 244 | - break; |
|
| 245 | - default: |
|
| 238 | + $where['post_type'] = 'frm_styles'; |
|
| 239 | + |
|
| 240 | + // Only export selected styles |
|
| 241 | + if ( ! empty( $style_ids ) ) { |
|
| 242 | + $where['ID'] = $style_ids; |
|
| 243 | + } |
|
| 244 | + break; |
|
| 245 | + default: |
|
| 246 | 246 | $select = $table . '.ID'; |
| 247 | - $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)'; |
|
| 248 | - $where['pm.meta_key'] = 'frm_form_id'; |
|
| 249 | - |
|
| 250 | - if ( empty($args['ids']) ) { |
|
| 251 | - $where['pm.meta_value >'] = 1; |
|
| 252 | - } else { |
|
| 253 | - $where['pm.meta_value'] = $args['ids']; |
|
| 254 | - } |
|
| 255 | - break; |
|
| 256 | - } |
|
| 247 | + $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)'; |
|
| 248 | + $where['pm.meta_key'] = 'frm_form_id'; |
|
| 249 | + |
|
| 250 | + if ( empty($args['ids']) ) { |
|
| 251 | + $where['pm.meta_value >'] = 1; |
|
| 252 | + } else { |
|
| 253 | + $where['pm.meta_value'] = $args['ids']; |
|
| 254 | + } |
|
| 255 | + break; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | 258 | $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select ); |
| 259 | - unset($tb_type); |
|
| 260 | - } |
|
| 259 | + unset($tb_type); |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | 262 | echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo('charset') ) . "\" ?>\n"; |
| 263 | 263 | include( FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php' ); |
| 264 | - } |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | private static function prepare_types_array( &$type ) { |
| 267 | 267 | $type = (array) $type; |
@@ -342,14 +342,14 @@ discard block |
||
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
| 345 | - * Get the fields that should be included in the CSV export |
|
| 346 | - * |
|
| 347 | - * @since 2.0.19 |
|
| 348 | - * |
|
| 349 | - * @param int $form_id |
|
| 350 | - * @param object $form |
|
| 351 | - * @return array $csv_fields |
|
| 352 | - */ |
|
| 345 | + * Get the fields that should be included in the CSV export |
|
| 346 | + * |
|
| 347 | + * @since 2.0.19 |
|
| 348 | + * |
|
| 349 | + * @param int $form_id |
|
| 350 | + * @param object $form |
|
| 351 | + * @return array $csv_fields |
|
| 352 | + */ |
|
| 353 | 353 | private static function get_fields_for_csv_export( $form_id, $form ) { |
| 354 | 354 | // Phase frm_csv_field_ids out by 2.01.05 |
| 355 | 355 | $csv_field_ids = apply_filters( 'frm_csv_field_ids', '', $form_id, array( 'form' => $form ) ); |
@@ -379,16 +379,16 @@ discard block |
||
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | public static function allow_mime( $mimes ) { |
| 382 | - if ( ! isset( $mimes['csv'] ) ) { |
|
| 383 | - // allow csv files |
|
| 384 | - $mimes['csv'] = 'text/csv'; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - if ( ! isset( $mimes['xml'] ) ) { |
|
| 388 | - // allow xml |
|
| 389 | - $mimes['xml'] = 'text/xml'; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $mimes; |
|
| 393 | - } |
|
| 382 | + if ( ! isset( $mimes['csv'] ) ) { |
|
| 383 | + // allow csv files |
|
| 384 | + $mimes['csv'] = 'text/csv'; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + if ( ! isset( $mimes['xml'] ) ) { |
|
| 388 | + // allow xml |
|
| 389 | + $mimes['xml'] = 'text/xml'; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $mimes; |
|
| 393 | + } |
|
| 394 | 394 | } |
@@ -12,14 +12,14 @@ discard block |
||
| 12 | 12 | return; |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | - $set_err = libxml_use_internal_errors(true); |
|
| 15 | + $set_err = libxml_use_internal_errors( true ); |
|
| 16 | 16 | $loader = libxml_disable_entity_loader( true ); |
| 17 | 17 | |
| 18 | 18 | $files = apply_filters( 'frm_default_templates_files', array( FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml' ) ); |
| 19 | 19 | |
| 20 | 20 | foreach ( (array) $files as $file ) { |
| 21 | - FrmXMLHelper::import_xml($file); |
|
| 22 | - unset($file); |
|
| 21 | + FrmXMLHelper::import_xml( $file ); |
|
| 22 | + unset( $file ); |
|
| 23 | 23 | } |
| 24 | 24 | /* |
| 25 | 25 | if(is_wp_error($result)) |
@@ -70,41 +70,41 @@ discard block |
||
| 70 | 70 | $errors = array(); |
| 71 | 71 | $message = ''; |
| 72 | 72 | |
| 73 | - $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce'); |
|
| 73 | + $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' ); |
|
| 74 | 74 | if ( $permission_error !== false ) { |
| 75 | 75 | $errors[] = $permission_error; |
| 76 | - self::form($errors); |
|
| 76 | + self::form( $errors ); |
|
| 77 | 77 | return; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) { |
|
| 80 | + if ( ! isset( $_FILES ) || ! isset( $_FILES['frm_import_file'] ) || empty( $_FILES['frm_import_file']['name'] ) || (int) $_FILES['frm_import_file']['size'] < 1 ) { |
|
| 81 | 81 | $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
| 82 | - self::form($errors); |
|
| 82 | + self::form( $errors ); |
|
| 83 | 83 | return; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | $file = $_FILES['frm_import_file']['tmp_name']; |
| 87 | 87 | |
| 88 | 88 | if ( ! is_uploaded_file( $file ) ) { |
| 89 | - unset($file); |
|
| 89 | + unset( $file ); |
|
| 90 | 90 | $errors[] = __( 'The file does not exist, please try again.', 'formidable' ); |
| 91 | - self::form($errors); |
|
| 91 | + self::form( $errors ); |
|
| 92 | 92 | return; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); |
| 96 | 96 | |
| 97 | - $export_format = apply_filters('frm_export_formats', array( |
|
| 97 | + $export_format = apply_filters( 'frm_export_formats', array( |
|
| 98 | 98 | 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ), |
| 99 | 99 | ) ); |
| 100 | 100 | |
| 101 | - $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION)); |
|
| 102 | - if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) { |
|
| 101 | + $file_type = strtolower( pathinfo( $_FILES['frm_import_file']['name'], PATHINFO_EXTENSION ) ); |
|
| 102 | + if ( $file_type != 'xml' && isset( $export_format[$file_type] ) ) { |
|
| 103 | 103 | // allow other file types to be imported |
| 104 | 104 | do_action( 'frm_before_import_' . $file_type ); |
| 105 | 105 | return; |
| 106 | 106 | } |
| 107 | - unset($file_type); |
|
| 107 | + unset( $file_type ); |
|
| 108 | 108 | |
| 109 | 109 | if ( ! function_exists( 'libxml_disable_entity_loader' ) ) { |
| 110 | 110 | $errors[] = __( 'XML import is not enabled on your server.', 'formidable' ); |
@@ -123,12 +123,12 @@ discard block |
||
| 123 | 123 | libxml_use_internal_errors( $set_err ); |
| 124 | 124 | libxml_disable_entity_loader( $loader ); |
| 125 | 125 | |
| 126 | - self::form($errors, $message); |
|
| 126 | + self::form( $errors, $message ); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | public static function export_xml() { |
| 130 | 130 | $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
| 131 | - if ( ! empty($error) ) { |
|
| 131 | + if ( ! empty( $error ) ) { |
|
| 132 | 132 | wp_die( $error ); |
| 133 | 133 | } |
| 134 | 134 | |
@@ -142,11 +142,11 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | if ( $format == 'xml' ) { |
| 145 | - self::generate_xml($type, compact('ids')); |
|
| 145 | + self::generate_xml( $type, compact( 'ids' ) ); |
|
| 146 | 146 | } if ( $format == 'csv' ) { |
| 147 | - self::generate_csv( compact('ids') ); |
|
| 147 | + self::generate_csv( compact( 'ids' ) ); |
|
| 148 | 148 | } else { |
| 149 | - do_action( 'frm_export_format_' . $format, compact('ids') ); |
|
| 149 | + do_action( 'frm_export_format_' . $format, compact( 'ids' ) ); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | wp_die(); |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | foreach ( $type as $tb_type ) { |
| 190 | 190 | $where = array(); |
| 191 | 191 | $join = ''; |
| 192 | - $table = $tables[ $tb_type ]; |
|
| 192 | + $table = $tables[$tb_type]; |
|
| 193 | 193 | |
| 194 | 194 | $select = $table . '.id'; |
| 195 | 195 | $query_vars = array(); |
@@ -200,20 +200,20 @@ discard block |
||
| 200 | 200 | if ( $args['ids'] ) { |
| 201 | 201 | $where[] = array( 'or' => 1, $table . '.id' => $args['ids'], $table . '.parent_form_id' => $args['ids'] ); |
| 202 | 202 | } else { |
| 203 | - $where[ $table . '.status !' ] = 'draft'; |
|
| 203 | + $where[$table . '.status !'] = 'draft'; |
|
| 204 | 204 | } |
| 205 | 205 | break; |
| 206 | 206 | case 'actions': |
| 207 | 207 | $select = $table . '.ID'; |
| 208 | 208 | $where['post_type'] = FrmFormActionsController::$action_post_type; |
| 209 | - if ( ! empty($args['ids']) ) { |
|
| 209 | + if ( ! empty( $args['ids'] ) ) { |
|
| 210 | 210 | $where['menu_order'] = $args['ids']; |
| 211 | 211 | } |
| 212 | 212 | break; |
| 213 | 213 | case 'items': |
| 214 | 214 | //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)"; |
| 215 | 215 | if ( $args['ids'] ) { |
| 216 | - $where[ $table . '.form_id' ] = $args['ids']; |
|
| 216 | + $where[$table . '.form_id'] = $args['ids']; |
|
| 217 | 217 | } |
| 218 | 218 | break; |
| 219 | 219 | case 'styles': |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)'; |
| 248 | 248 | $where['pm.meta_key'] = 'frm_form_id'; |
| 249 | 249 | |
| 250 | - if ( empty($args['ids']) ) { |
|
| 250 | + if ( empty( $args['ids'] ) ) { |
|
| 251 | 251 | $where['pm.meta_value >'] = 1; |
| 252 | 252 | } else { |
| 253 | 253 | $where['pm.meta_value'] = $args['ids']; |
@@ -255,11 +255,11 @@ discard block |
||
| 255 | 255 | break; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select ); |
|
| 259 | - unset($tb_type); |
|
| 258 | + $records[$tb_type] = FrmDb::get_col( $table . $join, $where, $select ); |
|
| 259 | + unset( $tb_type ); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo('charset') ) . "\" ?>\n"; |
|
| 262 | + echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo( 'charset' ) ) . "\" ?>\n"; |
|
| 263 | 263 | include( FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php' ); |
| 264 | 264 | } |
| 265 | 265 | |
@@ -297,10 +297,10 @@ discard block |
||
| 297 | 297 | $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' ); |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - set_time_limit(0); //Remove time limit to execute this function |
|
| 301 | - $mem_limit = str_replace('M', '', ini_get('memory_limit')); |
|
| 300 | + set_time_limit( 0 ); //Remove time limit to execute this function |
|
| 301 | + $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) ); |
|
| 302 | 302 | if ( (int) $mem_limit < 256 ) { |
| 303 | - ini_set('memory_limit', '256M'); |
|
| 303 | + ini_set( 'memory_limit', '256M' ); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | global $wpdb; |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | $no_export_fields = FrmField::no_save_fields(); |
| 371 | 371 | foreach ( $csv_fields as $k => $f ) { |
| 372 | 372 | if ( in_array( $f->type, $no_export_fields ) ) { |
| 373 | - unset( $csv_fields[ $k ] ); |
|
| 373 | + unset( $csv_fields[$k] ); |
|
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | } |
@@ -10,41 +10,41 @@ discard block |
||
| 10 | 10 | <?php |
| 11 | 11 | |
| 12 | 12 | } else if ( $field['type'] == 'radio' ) { |
| 13 | - $read_only = false; |
|
| 13 | + $read_only = false; |
|
| 14 | 14 | if ( FrmField::is_read_only( $field ) && ! FrmAppHelper::is_admin() ) { |
| 15 | - $read_only = true; ?> |
|
| 15 | + $read_only = true; ?> |
|
| 16 | 16 | <input type="hidden" value="<?php echo esc_attr( $field['value'] ) ?>" name="<?php echo esc_attr( $field_name ) ?>" /> |
| 17 | 17 | <?php |
| 18 | - } |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) { |
|
| 20 | + if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) { |
|
| 21 | 21 | do_action( 'frm_after_checkbox', array( 'field' => $field, 'field_name' => $field_name, 'type' => $field['type'] ) ); |
| 22 | - } else if ( is_array($field['options']) ) { |
|
| 23 | - foreach ( $field['options'] as $opt_key => $opt ) { |
|
| 22 | + } else if ( is_array($field['options']) ) { |
|
| 23 | + foreach ( $field['options'] as $opt_key => $opt ) { |
|
| 24 | 24 | if ( isset( $atts ) && isset( $atts['opt'] ) && ( $atts['opt'] != $opt_key ) ) { |
| 25 | - continue; |
|
| 26 | - } |
|
| 25 | + continue; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field); |
|
| 29 | - $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); ?> |
|
| 28 | + $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field); |
|
| 29 | + $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); ?> |
|
| 30 | 30 | <div class="<?php echo esc_attr( apply_filters( 'frm_radio_class', 'frm_radio', $field, $field_val ) ) ?>"><?php |
| 31 | 31 | |
| 32 | 32 | if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) { |
| 33 | 33 | ?><label for="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php |
| 34 | - } |
|
| 35 | - $checked = FrmAppHelper::check_selected($field['value'], $field_val) ? 'checked="checked" ' : ' '; |
|
| 34 | + } |
|
| 35 | + $checked = FrmAppHelper::check_selected($field['value'], $field_val) ? 'checked="checked" ' : ' '; |
|
| 36 | 36 | |
| 37 | - $other_opt = false; |
|
| 38 | - $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field_name', 'opt_key', 'field' ), $other_opt, $checked ); |
|
| 39 | - ?> |
|
| 37 | + $other_opt = false; |
|
| 38 | + $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field_name', 'opt_key', 'field' ), $other_opt, $checked ); |
|
| 39 | + ?> |
|
| 40 | 40 | <input type="radio" name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ) ?>" value="<?php echo esc_attr( $field_val ) ?>" <?php |
| 41 | - echo $checked; |
|
| 42 | - do_action('frm_field_input_html', $field); |
|
| 41 | + echo $checked; |
|
| 42 | + do_action('frm_field_input_html', $field); |
|
| 43 | 43 | ?>/><?php |
| 44 | 44 | |
| 45 | 45 | if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) { |
| 46 | 46 | echo ' ' . $opt . '</label>'; |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | FrmFieldsHelper::include_other_input( array( |
| 50 | 50 | 'other_opt' => $other_opt, 'read_only' => $read_only, |
@@ -53,58 +53,58 @@ discard block |
||
| 53 | 53 | 'html_id' => $html_id, 'opt_key' => $opt_key, |
| 54 | 54 | ) ); |
| 55 | 55 | |
| 56 | - unset( $other_opt, $other_args ); |
|
| 56 | + unset( $other_opt, $other_args ); |
|
| 57 | 57 | ?></div> |
| 58 | 58 | <?php |
| 59 | - } |
|
| 60 | - } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | } else if ( $field['type'] == 'select' ) { |
| 62 | 62 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/front-end/dropdown-field.php' ); |
| 63 | 63 | } else if ( $field['type'] == 'checkbox' ) { |
| 64 | - $checked_values = $field['value']; |
|
| 65 | - $read_only = false; |
|
| 64 | + $checked_values = $field['value']; |
|
| 65 | + $read_only = false; |
|
| 66 | 66 | |
| 67 | 67 | if ( FrmField::is_read_only( $field ) && ! FrmAppHelper::is_admin() ) { |
| 68 | - $read_only = true; |
|
| 69 | - if ( $checked_values ) { |
|
| 70 | - foreach ( (array) $checked_values as $checked_value ) { ?> |
|
| 68 | + $read_only = true; |
|
| 69 | + if ( $checked_values ) { |
|
| 70 | + foreach ( (array) $checked_values as $checked_value ) { ?> |
|
| 71 | 71 | <input type="hidden" value="<?php echo esc_attr( $checked_value ) ?>" name="<?php echo esc_attr( $field_name ) ?>[]" /> |
| 72 | 72 | <?php |
| 73 | - } |
|
| 74 | - } else { ?> |
|
| 73 | + } |
|
| 74 | + } else { ?> |
|
| 75 | 75 | <input type="hidden" value="" name="<?php echo esc_attr( $field_name ) ?>[]" /> |
| 76 | 76 | <?php |
| 77 | - } |
|
| 78 | - } |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) { |
|
| 80 | + if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) { |
|
| 81 | 81 | do_action( 'frm_after_checkbox', array( 'field' => $field, 'field_name' => $field_name, 'type' => $field['type'] ) ); |
| 82 | - } else if ( $field['options'] ) { |
|
| 83 | - foreach ( $field['options'] as $opt_key => $opt ) { |
|
| 84 | - if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key) ) { |
|
| 85 | - continue; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field); |
|
| 89 | - $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); |
|
| 90 | - $checked = FrmAppHelper::check_selected($checked_values, $field_val) ? ' checked="checked"' : ''; |
|
| 91 | - |
|
| 92 | - // Check if other opt, and get values for other field if needed |
|
| 93 | - $other_opt = false; |
|
| 82 | + } else if ( $field['options'] ) { |
|
| 83 | + foreach ( $field['options'] as $opt_key => $opt ) { |
|
| 84 | + if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key) ) { |
|
| 85 | + continue; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field); |
|
| 89 | + $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); |
|
| 90 | + $checked = FrmAppHelper::check_selected($checked_values, $field_val) ? ' checked="checked"' : ''; |
|
| 91 | + |
|
| 92 | + // Check if other opt, and get values for other field if needed |
|
| 93 | + $other_opt = false; |
|
| 94 | 94 | $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field', 'field_name', 'opt_key' ), $other_opt, $checked ); |
| 95 | 95 | |
| 96 | - ?> |
|
| 96 | + ?> |
|
| 97 | 97 | <div class="<?php echo esc_attr( apply_filters( 'frm_checkbox_class', 'frm_checkbox', $field, $field_val ) ) ?>" id="frm_checkbox_<?php echo esc_attr( $field['id'] ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php |
| 98 | 98 | |
| 99 | - if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) { |
|
| 100 | - ?><label for="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php |
|
| 101 | - } |
|
| 99 | + if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) { |
|
| 100 | + ?><label for="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - ?><input type="checkbox" name="<?php echo esc_attr( $field_name ) ?>[<?php echo ( $other_opt ? esc_attr( $opt_key ) : '' ) ?>]" id="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>" value="<?php echo esc_attr( $field_val ) ?>" <?php echo $checked ?> <?php do_action('frm_field_input_html', $field) ?> /><?php |
|
| 103 | + ?><input type="checkbox" name="<?php echo esc_attr( $field_name ) ?>[<?php echo ( $other_opt ? esc_attr( $opt_key ) : '' ) ?>]" id="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>" value="<?php echo esc_attr( $field_val ) ?>" <?php echo $checked ?> <?php do_action('frm_field_input_html', $field) ?> /><?php |
|
| 104 | 104 | |
| 105 | - if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) { |
|
| 105 | + if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) { |
|
| 106 | 106 | echo ' ' . $opt . '</label>'; |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | FrmFieldsHelper::include_other_input( array( |
| 110 | 110 | 'other_opt' => $other_opt, 'read_only' => $read_only, |
@@ -113,17 +113,17 @@ discard block |
||
| 113 | 113 | 'html_id' => $html_id, 'opt_key' => $opt_key, |
| 114 | 114 | ) ); |
| 115 | 115 | |
| 116 | - unset( $other_opt, $other_args, $checked ); |
|
| 116 | + unset( $other_opt, $other_args, $checked ); |
|
| 117 | 117 | |
| 118 | - ?></div> |
|
| 118 | + ?></div> |
|
| 119 | 119 | <?php |
| 120 | - } |
|
| 121 | - } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | 122 | } else if ( $field['type'] == 'captcha' && ! FrmAppHelper::is_admin() ) { |
| 123 | - $frm_settings = FrmAppHelper::get_settings(); |
|
| 124 | - if ( ! empty($frm_settings->pubkey) ) { |
|
| 125 | - FrmFieldsHelper::display_recaptcha($field); |
|
| 126 | - } |
|
| 123 | + $frm_settings = FrmAppHelper::get_settings(); |
|
| 124 | + if ( ! empty($frm_settings->pubkey) ) { |
|
| 125 | + FrmFieldsHelper::display_recaptcha($field); |
|
| 126 | + } |
|
| 127 | 127 | } else { |
| 128 | 128 | do_action( 'frm_form_fields', $field, $field_name, compact( 'errors', 'html_id' ) ); |
| 129 | 129 | do_action( 'frm_form_field_' . $field['type'], $field, $field_name, compact( 'errors', 'html_id' ) ); |
@@ -1,12 +1,12 @@ discard block |
||
| 1 | 1 | <?php if ( in_array( $field['type'], array( 'email', 'url', 'text' ) ) ) { ?> |
| 2 | -<input type="<?php echo ( $frm_settings->use_html || $field['type'] == 'password' ) ? $field['type'] : 'text'; ?>" id="<?php echo esc_attr( $html_id ) ?>" name="<?php echo esc_attr( $field_name ) ?>" value="<?php echo esc_attr( $field['value'] ) ?>" <?php do_action('frm_field_input_html', $field) ?>/> |
|
| 2 | +<input type="<?php echo ( $frm_settings->use_html || $field['type'] == 'password' ) ? $field['type'] : 'text'; ?>" id="<?php echo esc_attr( $html_id ) ?>" name="<?php echo esc_attr( $field_name ) ?>" value="<?php echo esc_attr( $field['value'] ) ?>" <?php do_action( 'frm_field_input_html', $field ) ?>/> |
|
| 3 | 3 | <?php } else if ( $field['type'] == 'textarea' ) { ?> |
| 4 | 4 | <textarea name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>" <?php |
| 5 | 5 | if ( $field['max'] ) { |
| 6 | 6 | echo 'rows="' . esc_attr( $field['max'] ) . '" '; |
| 7 | 7 | } |
| 8 | -do_action('frm_field_input_html', $field); |
|
| 9 | -?>><?php echo FrmAppHelper::esc_textarea($field['value']) ?></textarea> |
|
| 8 | +do_action( 'frm_field_input_html', $field ); |
|
| 9 | +?>><?php echo FrmAppHelper::esc_textarea( $field['value'] ) ?></textarea> |
|
| 10 | 10 | <?php |
| 11 | 11 | |
| 12 | 12 | } else if ( $field['type'] == 'radio' ) { |
@@ -17,29 +17,29 @@ discard block |
||
| 17 | 17 | <?php |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) { |
|
| 20 | + if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' ) { |
|
| 21 | 21 | do_action( 'frm_after_checkbox', array( 'field' => $field, 'field_name' => $field_name, 'type' => $field['type'] ) ); |
| 22 | - } else if ( is_array($field['options']) ) { |
|
| 22 | + } else if ( is_array( $field['options'] ) ) { |
|
| 23 | 23 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 24 | 24 | if ( isset( $atts ) && isset( $atts['opt'] ) && ( $atts['opt'] != $opt_key ) ) { |
| 25 | 25 | continue; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field); |
|
| 29 | - $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); ?> |
|
| 28 | + $field_val = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field ); |
|
| 29 | + $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field ); ?> |
|
| 30 | 30 | <div class="<?php echo esc_attr( apply_filters( 'frm_radio_class', 'frm_radio', $field, $field_val ) ) ?>"><?php |
| 31 | 31 | |
| 32 | 32 | if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) { |
| 33 | 33 | ?><label for="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php |
| 34 | 34 | } |
| 35 | - $checked = FrmAppHelper::check_selected($field['value'], $field_val) ? 'checked="checked" ' : ' '; |
|
| 35 | + $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? 'checked="checked" ' : ' '; |
|
| 36 | 36 | |
| 37 | 37 | $other_opt = false; |
| 38 | 38 | $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field_name', 'opt_key', 'field' ), $other_opt, $checked ); |
| 39 | 39 | ?> |
| 40 | 40 | <input type="radio" name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ) ?>" value="<?php echo esc_attr( $field_val ) ?>" <?php |
| 41 | 41 | echo $checked; |
| 42 | - do_action('frm_field_input_html', $field); |
|
| 42 | + do_action( 'frm_field_input_html', $field ); |
|
| 43 | 43 | ?>/><?php |
| 44 | 44 | |
| 45 | 45 | if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) { |
@@ -77,17 +77,17 @@ discard block |
||
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) { |
|
| 80 | + if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' ) { |
|
| 81 | 81 | do_action( 'frm_after_checkbox', array( 'field' => $field, 'field_name' => $field_name, 'type' => $field['type'] ) ); |
| 82 | 82 | } else if ( $field['options'] ) { |
| 83 | 83 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 84 | - if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key) ) { |
|
| 84 | + if ( isset( $atts ) && isset( $atts['opt'] ) && ( $atts['opt'] != $opt_key ) ) { |
|
| 85 | 85 | continue; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field); |
|
| 89 | - $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); |
|
| 90 | - $checked = FrmAppHelper::check_selected($checked_values, $field_val) ? ' checked="checked"' : ''; |
|
| 88 | + $field_val = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field ); |
|
| 89 | + $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field ); |
|
| 90 | + $checked = FrmAppHelper::check_selected( $checked_values, $field_val ) ? ' checked="checked"' : ''; |
|
| 91 | 91 | |
| 92 | 92 | // Check if other opt, and get values for other field if needed |
| 93 | 93 | $other_opt = false; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | ?><label for="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - ?><input type="checkbox" name="<?php echo esc_attr( $field_name ) ?>[<?php echo ( $other_opt ? esc_attr( $opt_key ) : '' ) ?>]" id="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>" value="<?php echo esc_attr( $field_val ) ?>" <?php echo $checked ?> <?php do_action('frm_field_input_html', $field) ?> /><?php |
|
| 103 | + ?><input type="checkbox" name="<?php echo esc_attr( $field_name ) ?>[<?php echo ( $other_opt ? esc_attr( $opt_key ) : '' ) ?>]" id="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>" value="<?php echo esc_attr( $field_val ) ?>" <?php echo $checked ?> <?php do_action( 'frm_field_input_html', $field ) ?> /><?php |
|
| 104 | 104 | |
| 105 | 105 | if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) { |
| 106 | 106 | echo ' ' . $opt . '</label>'; |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | } else if ( $field['type'] == 'captcha' && ! FrmAppHelper::is_admin() ) { |
| 123 | 123 | $frm_settings = FrmAppHelper::get_settings(); |
| 124 | - if ( ! empty($frm_settings->pubkey) ) { |
|
| 125 | - FrmFieldsHelper::display_recaptcha($field); |
|
| 124 | + if ( ! empty( $frm_settings->pubkey ) ) { |
|
| 125 | + FrmFieldsHelper::display_recaptcha( $field ); |
|
| 126 | 126 | } |
| 127 | 127 | } else { |
| 128 | 128 | do_action( 'frm_form_fields', $field, $field_name, compact( 'errors', 'html_id' ) ); |
@@ -1,17 +1,17 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $read_only = false; |
| 4 | -if ( isset($field['post_field']) && $field['post_field'] == 'post_category' && FrmAppHelper::pro_is_installed() ) { |
|
| 4 | +if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' && FrmAppHelper::pro_is_installed() ) { |
|
| 5 | 5 | echo FrmProPost::get_category_dropdown( $field, array( 'location' => 'front', 'name' => $field_name, 'id' => $html_id ) ); |
| 6 | 6 | } else { |
| 7 | 7 | if ( FrmAppHelper::pro_is_installed() && FrmField::is_read_only( $field ) ) { |
| 8 | 8 | $read_only = true; |
| 9 | 9 | |
| 10 | 10 | echo FrmProDropdownFieldsController::get_hidden_fields_with_readonly_values( $field, $field_name, $html_id ); ?> |
| 11 | - <select <?php do_action('frm_field_input_html', $field) ?>> <?php |
|
| 11 | + <select <?php do_action( 'frm_field_input_html', $field ) ?>> <?php |
|
| 12 | 12 | |
| 13 | 13 | } else { ?> |
| 14 | - <select name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>" <?php do_action('frm_field_input_html', $field) ?>> |
|
| 14 | + <select name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>" <?php do_action( 'frm_field_input_html', $field ) ?>> |
|
| 15 | 15 | <?php } |
| 16 | 16 | |
| 17 | 17 | $other_opt = $other_checked = false; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | } |
| 27 | 27 | } |
| 28 | 28 | ?> |
| 29 | - <option value="<?php echo esc_attr($field_val) ?>" <?php echo $selected ? ' selected="selected"' : ''; ?><?php echo ( FrmFieldsHelper::is_other_opt( $opt_key ) ) ? ' class="frm_other_trigger"' : '';?>><?php echo esc_html( $opt == '' ? ' ' : $opt ); ?></option> |
|
| 29 | + <option value="<?php echo esc_attr( $field_val ) ?>" <?php echo $selected ? ' selected="selected"' : ''; ?><?php echo ( FrmFieldsHelper::is_other_opt( $opt_key ) ) ? ' class="frm_other_trigger"' : ''; ?>><?php echo esc_html( $opt == '' ? ' ' : $opt ); ?></option> |
|
| 30 | 30 | <?php |
| 31 | 31 | } ?> |
| 32 | 32 | </select> |
@@ -1,14 +1,14 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( isset($field['post_field']) && $field['post_field'] == 'post_category' && FrmAppHelper::pro_is_installed() ) { |
|
| 3 | +if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' && FrmAppHelper::pro_is_installed() ) { |
|
| 4 | 4 | echo FrmProPost::get_category_dropdown( $field, array( 'name' => $field_name, 'id' => 'placeholder_id', 'location' => 'form_builder' ) ); |
| 5 | 5 | } else { ?> |
| 6 | 6 | <select name="<?php echo esc_attr( $field_name ) . ( FrmField::is_option_true( $field, 'multiple' ) ? '[]' : '' ); ?>" <?php |
| 7 | 7 | echo FrmField::is_option_true( $field, 'size' ) ? 'class="auto_width"' : ''; |
| 8 | 8 | echo FrmField::is_option_true( $field, 'multiple' ) ? ' multiple="multiple"' : ''; ?> > |
| 9 | 9 | <?php foreach ( $field['options'] as $opt_key => $opt ) { |
| 10 | - $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field); |
|
| 11 | - $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); |
|
| 10 | + $field_val = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field ); |
|
| 11 | + $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field ); |
|
| 12 | 12 | $selected = ( $field['default_value'] == $field_val || FrmFieldsHelper::get_other_val( array( 'opt_key', 'field' ) ) ) ? ' selected="selected"' : ''; ?> |
| 13 | 13 | <option value="<?php echo esc_attr( $field_val ) ?>"<?php echo $selected ?>><?php echo esc_html( $opt ) ?> </option> |
| 14 | 14 | <?php } ?> |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | <?php |
| 27 | 27 | |
| 28 | 28 | if ( ! isset( $field['post_field'] ) || ! in_array( $field['post_field'], array( 'post_category' ) ) ) { ?> |
| 29 | - <?php do_action('frm_add_multiple_opts_labels', $field); ?> |
|
| 30 | - <ul id="frm_field_<?php echo esc_attr( $field['id'] ) ?>_opts" class="frm_sortable_field_opts<?php echo ( count($field['options']) > 10 ) ? ' frm_field_opts_list' : ''; ?>"> |
|
| 31 | - <?php FrmFieldsHelper::show_single_option($field); ?> |
|
| 29 | + <?php do_action( 'frm_add_multiple_opts_labels', $field ); ?> |
|
| 30 | + <ul id="frm_field_<?php echo esc_attr( $field['id'] ) ?>_opts" class="frm_sortable_field_opts<?php echo ( count( $field['options'] ) > 10 ) ? ' frm_field_opts_list' : ''; ?>"> |
|
| 31 | + <?php FrmFieldsHelper::show_single_option( $field ); ?> |
|
| 32 | 32 | </ul> |
| 33 | 33 | <?php |
| 34 | 34 | } ?> |
@@ -3,32 +3,32 @@ |
||
| 3 | 3 | <?php } else if ( $field['type'] == 'textarea' ) { ?> |
| 4 | 4 | <textarea name="<?php echo esc_attr( $field_name ) ?>" <?php |
| 5 | 5 | echo ( FrmField::is_option_true( $field, 'size' ) ) ? esc_attr( 'style="width:' . $field['size'] . ( is_numeric( $field['size'] ) ? 'px' : '' ) . ';"' ) : ''; |
| 6 | - ?> rows="<?php echo esc_attr( $field['max'] ); ?>" id="<?php echo esc_attr( $html_id ) ?>" class="dyn_default_value"><?php echo FrmAppHelper::esc_textarea(force_balance_tags($field['default_value'])); ?></textarea> |
|
| 6 | + ?> rows="<?php echo esc_attr( $field['max'] ); ?>" id="<?php echo esc_attr( $html_id ) ?>" class="dyn_default_value"><?php echo FrmAppHelper::esc_textarea(force_balance_tags($field['default_value'])); ?></textarea> |
|
| 7 | 7 | |
| 8 | 8 | <?php |
| 9 | 9 | |
| 10 | 10 | } else if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
| 11 | - $field['default_value'] = maybe_unserialize($field['default_value']); |
|
| 12 | - if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) { |
|
| 11 | + $field['default_value'] = maybe_unserialize($field['default_value']); |
|
| 12 | + if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) { |
|
| 13 | 13 | do_action( 'frm_after_checkbox', array( 'field' => $field, 'field_name' => $field_name, 'type' => $field['type'] ) ); |
| 14 | - } else { |
|
| 15 | - do_action('frm_add_multiple_opts_labels', $field); ?> |
|
| 14 | + } else { |
|
| 15 | + do_action('frm_add_multiple_opts_labels', $field); ?> |
|
| 16 | 16 | <ul id="frm_field_<?php echo esc_attr( $field['id'] ) ?>_opts" class="frm_sortable_field_opts frm_clear<?php echo (count($field['options']) > 10) ? ' frm_field_opts_list' : ''; ?>"> |
| 17 | 17 | <?php include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' ); ?> |
| 18 | 18 | </ul> |
| 19 | 19 | <?php |
| 20 | - } |
|
| 20 | + } |
|
| 21 | 21 | } else if ( $field['type'] == 'select' ) { |
| 22 | 22 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/dropdown-field.php' ); |
| 23 | 23 | } else if ( $field['type'] == 'captcha' ) { |
| 24 | 24 | if ( empty($frm_settings->pubkey) ) { ?> |
| 25 | 25 | <div class="howto frm_no_captcha_text"><?php printf(__( 'Your captcha will not appear on your form until you %1$sset up%2$s the Site and Secret Keys', 'formidable' ), '<a href="?page=formidable-settings">', '</a>') ?></div> |
| 26 | 26 | <?php |
| 27 | - } ?> |
|
| 27 | + } ?> |
|
| 28 | 28 | <img src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/recaptcha.png' ) ?>" class="recaptcha_placeholder" alt="reCaptcha"/> |
| 29 | 29 | <input type="hidden" name="<?php echo esc_attr( $field_name ) ?>" value="1" /> |
| 30 | 30 | <?php |
| 31 | 31 | } else { |
| 32 | - do_action( 'frm_display_added_fields', $field ); |
|
| 32 | + do_action( 'frm_display_added_fields', $field ); |
|
| 33 | 33 | do_action( 'frm_display_added_' . $field['type'] . '_field', $field ); |
| 34 | 34 | } |
@@ -3,17 +3,17 @@ discard block |
||
| 3 | 3 | <?php } else if ( $field['type'] == 'textarea' ) { ?> |
| 4 | 4 | <textarea name="<?php echo esc_attr( $field_name ) ?>" <?php |
| 5 | 5 | echo ( FrmField::is_option_true( $field, 'size' ) ) ? esc_attr( 'style="width:' . $field['size'] . ( is_numeric( $field['size'] ) ? 'px' : '' ) . ';"' ) : ''; |
| 6 | - ?> rows="<?php echo esc_attr( $field['max'] ); ?>" id="<?php echo esc_attr( $html_id ) ?>" class="dyn_default_value"><?php echo FrmAppHelper::esc_textarea(force_balance_tags($field['default_value'])); ?></textarea> |
|
| 6 | + ?> rows="<?php echo esc_attr( $field['max'] ); ?>" id="<?php echo esc_attr( $html_id ) ?>" class="dyn_default_value"><?php echo FrmAppHelper::esc_textarea( force_balance_tags( $field['default_value'] ) ); ?></textarea> |
|
| 7 | 7 | |
| 8 | 8 | <?php |
| 9 | 9 | |
| 10 | 10 | } else if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
| 11 | - $field['default_value'] = maybe_unserialize($field['default_value']); |
|
| 12 | - if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) { |
|
| 11 | + $field['default_value'] = maybe_unserialize( $field['default_value'] ); |
|
| 12 | + if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' ) { |
|
| 13 | 13 | do_action( 'frm_after_checkbox', array( 'field' => $field, 'field_name' => $field_name, 'type' => $field['type'] ) ); |
| 14 | 14 | } else { |
| 15 | - do_action('frm_add_multiple_opts_labels', $field); ?> |
|
| 16 | - <ul id="frm_field_<?php echo esc_attr( $field['id'] ) ?>_opts" class="frm_sortable_field_opts frm_clear<?php echo (count($field['options']) > 10) ? ' frm_field_opts_list' : ''; ?>"> |
|
| 15 | + do_action( 'frm_add_multiple_opts_labels', $field ); ?> |
|
| 16 | + <ul id="frm_field_<?php echo esc_attr( $field['id'] ) ?>_opts" class="frm_sortable_field_opts frm_clear<?php echo ( count( $field['options'] ) > 10 ) ? ' frm_field_opts_list' : ''; ?>"> |
|
| 17 | 17 | <?php include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' ); ?> |
| 18 | 18 | </ul> |
| 19 | 19 | <?php |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | } else if ( $field['type'] == 'select' ) { |
| 22 | 22 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/dropdown-field.php' ); |
| 23 | 23 | } else if ( $field['type'] == 'captcha' ) { |
| 24 | - if ( empty($frm_settings->pubkey) ) { ?> |
|
| 25 | - <div class="howto frm_no_captcha_text"><?php printf(__( 'Your captcha will not appear on your form until you %1$sset up%2$s the Site and Secret Keys', 'formidable' ), '<a href="?page=formidable-settings">', '</a>') ?></div> |
|
| 24 | + if ( empty( $frm_settings->pubkey ) ) { ?> |
|
| 25 | + <div class="howto frm_no_captcha_text"><?php printf( __( 'Your captcha will not appear on your form until you %1$sset up%2$s the Site and Secret Keys', 'formidable' ), '<a href="?page=formidable-settings">', '</a>' ) ?></div> |
|
| 26 | 26 | <?php |
| 27 | 27 | } ?> |
| 28 | 28 | <img src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/recaptcha.png' ) ?>" class="recaptcha_placeholder" alt="reCaptcha"/> |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined('ABSPATH') ) { |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | 3 | die( 'You are not allowed to call this page directly.' ); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | static $transient_size = 200; |
| 9 | 9 | |
| 10 | 10 | public static function field_selection() { |
| 11 | - $fields = apply_filters('frm_available_fields', array( |
|
| 11 | + $fields = apply_filters( 'frm_available_fields', array( |
|
| 12 | 12 | 'text' => __( 'Single Line Text', 'formidable' ), |
| 13 | 13 | 'textarea' => __( 'Paragraph Text', 'formidable' ), |
| 14 | 14 | 'checkbox' => __( 'Checkboxes', 'formidable' ), |
@@ -17,13 +17,13 @@ discard block |
||
| 17 | 17 | 'email' => __( 'Email Address', 'formidable' ), |
| 18 | 18 | 'url' => __( 'Website/URL', 'formidable' ), |
| 19 | 19 | 'captcha' => __( 'reCAPTCHA', 'formidable' ), |
| 20 | - )); |
|
| 20 | + ) ); |
|
| 21 | 21 | |
| 22 | 22 | return $fields; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public static function pro_field_selection() { |
| 26 | - return apply_filters('frm_pro_available_fields', array( |
|
| 26 | + return apply_filters( 'frm_pro_available_fields', array( |
|
| 27 | 27 | 'end_divider' => array( |
| 28 | 28 | 'name' => __( 'End Section', 'formidable' ), |
| 29 | 29 | 'switch_from' => 'divider', |
@@ -48,36 +48,36 @@ discard block |
||
| 48 | 48 | 'tag' => __( 'Tags', 'formidable' ), |
| 49 | 49 | 'credit_card' => __( 'Credit Card', 'formidable' ), |
| 50 | 50 | 'address' => __( 'Address', 'formidable' ), |
| 51 | - )); |
|
| 51 | + ) ); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | public static function create( $values, $return = true ) { |
| 55 | 55 | global $wpdb, $frm_duplicate_ids; |
| 56 | 56 | |
| 57 | 57 | $new_values = array(); |
| 58 | - $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
| 58 | + $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name']; |
|
| 59 | 59 | $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
| 60 | 60 | |
| 61 | 61 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
| 62 | - $new_values[ $col ] = $values[ $col ]; |
|
| 62 | + $new_values[$col] = $values[$col]; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $new_values['options'] = $values['options']; |
| 66 | 66 | |
| 67 | - $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
| 68 | - $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
| 69 | - $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
| 67 | + $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null; |
|
| 68 | + $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0; |
|
| 69 | + $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null; |
|
| 70 | 70 | $new_values['field_options'] = $values['field_options']; |
| 71 | - $new_values['created_at'] = current_time('mysql', 1); |
|
| 71 | + $new_values['created_at'] = current_time( 'mysql', 1 ); |
|
| 72 | 72 | |
| 73 | 73 | if ( isset( $values['id'] ) ) { |
| 74 | - $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
|
| 75 | - $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
| 74 | + $frm_duplicate_ids[$values['field_key']] = $new_values['field_key']; |
|
| 75 | + $new_values = apply_filters( 'frm_duplicated_field', $new_values ); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | foreach ( $new_values as $k => $v ) { |
| 79 | 79 | if ( is_array( $v ) ) { |
| 80 | - $new_values[ $k ] = serialize( $v ); |
|
| 80 | + $new_values[$k] = serialize( $v ); |
|
| 81 | 81 | } |
| 82 | 82 | unset( $k, $v ); |
| 83 | 83 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | if ( $query_results ) { |
| 100 | 100 | if ( isset( $values['id'] ) ) { |
| 101 | - $frm_duplicate_ids[ $values['id'] ] = $new_id; |
|
| 101 | + $frm_duplicate_ids[$values['id']] = $new_id; |
|
| 102 | 102 | } |
| 103 | 103 | return $new_id; |
| 104 | 104 | } else { |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
| 114 | 114 | |
| 115 | 115 | foreach ( (array) $fields as $field ) { |
| 116 | - $new_key = ($copy_keys) ? $field->field_key : ''; |
|
| 117 | - if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
| 118 | - $new_key = rtrim($new_key, 2); |
|
| 116 | + $new_key = ( $copy_keys ) ? $field->field_key : ''; |
|
| 117 | + if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) { |
|
| 118 | + $new_key = rtrim( $new_key, 2 ); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $values = array(); |
@@ -138,11 +138,11 @@ discard block |
||
| 138 | 138 | $values['form_id'] = $new_repeat_form_id; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $values = apply_filters('frm_duplicated_field', $values); |
|
| 142 | - $new_id = self::create($values); |
|
| 143 | - $frm_duplicate_ids[ $field->id ] = $new_id; |
|
| 144 | - $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
| 145 | - unset($field); |
|
| 141 | + $values = apply_filters( 'frm_duplicated_field', $values ); |
|
| 142 | + $new_id = self::create( $values ); |
|
| 143 | + $frm_duplicate_ids[$field->id] = $new_id; |
|
| 144 | + $frm_duplicate_ids[$field->field_key] = $new_id; |
|
| 145 | + unset( $field ); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id ); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if ( isset($values['required']) ) { |
|
| 158 | + if ( isset( $values['required'] ) ) { |
|
| 159 | 159 | $values['required'] = (int) $values['required']; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | // serialize array values |
| 169 | 169 | foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) { |
| 170 | - if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) { |
|
| 171 | - $values[ $opt ] = serialize( $values[ $opt ] ); |
|
| 170 | + if ( isset( $values[$opt] ) && is_array( $values[$opt] ) ) { |
|
| 171 | + $values[$opt] = serialize( $values[$opt] ); |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | |
@@ -178,13 +178,13 @@ discard block |
||
| 178 | 178 | if ( isset( $values['form_id'] ) ) { |
| 179 | 179 | $form_id = absint( $values['form_id'] ); |
| 180 | 180 | } else { |
| 181 | - $field = self::getOne($id); |
|
| 181 | + $field = self::getOne( $id ); |
|
| 182 | 182 | if ( $field ) { |
| 183 | 183 | $form_id = $field->form_id; |
| 184 | 184 | } |
| 185 | - unset($field); |
|
| 185 | + unset( $field ); |
|
| 186 | 186 | } |
| 187 | - unset($values); |
|
| 187 | + unset( $values ); |
|
| 188 | 188 | |
| 189 | 189 | if ( $query_results ) { |
| 190 | 190 | wp_cache_delete( $id, 'frm_field' ); |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | FrmAppHelper::cache_delete_group( 'frm_field' ); |
| 239 | 239 | |
| 240 | - $form = FrmForm::getOne($form_id); |
|
| 240 | + $form = FrmForm::getOne( $form_id ); |
|
| 241 | 241 | if ( $form && $form->parent_form_id ) { |
| 242 | 242 | self::delete_form_transient( $form->parent_form_id ); |
| 243 | 243 | } |
@@ -259,16 +259,16 @@ discard block |
||
| 259 | 259 | |
| 260 | 260 | global $wpdb; |
| 261 | 261 | |
| 262 | - $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
| 262 | + $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s'; |
|
| 263 | 263 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); |
| 264 | 264 | |
| 265 | 265 | $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
| 266 | 266 | |
| 267 | - if ( empty($results) ) { |
|
| 267 | + if ( empty( $results ) ) { |
|
| 268 | 268 | return $results; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - if ( is_numeric($id) ) { |
|
| 271 | + if ( is_numeric( $id ) ) { |
|
| 272 | 272 | FrmAppHelper::set_cache( $results->field_key, $results, 'frm_field' ); |
| 273 | 273 | } else if ( $results ) { |
| 274 | 274 | FrmAppHelper::set_cache( $results->id, $results, 'frm_field' ); |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | self::prepare_options( $results ); |
| 278 | 278 | |
| 279 | - return stripslashes_deep($results); |
|
| 279 | + return stripslashes_deep( $results ); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -309,20 +309,20 @@ discard block |
||
| 309 | 309 | continue; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - $fields[ $result->id ] = $result; |
|
| 313 | - $count++; |
|
| 312 | + $fields[$result->id] = $result; |
|
| 313 | + $count ++; |
|
| 314 | 314 | if ( $limit == 1 ) { |
| 315 | 315 | $fields = $result; |
| 316 | 316 | break; |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - if ( ! empty($limit) && $count >= $limit ) { |
|
| 319 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
| 320 | 320 | break; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - unset($result); |
|
| 323 | + unset( $result ); |
|
| 324 | 324 | } |
| 325 | - return stripslashes_deep($fields); |
|
| 325 | + return stripslashes_deep( $fields ); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | self::$use_cache = false; |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
| 332 | 332 | $results = self::getAll( $where, 'field_order', $limit ); |
| 333 | 333 | self::$use_cache = true; |
| 334 | - self::include_sub_fields($results, $inc_sub, $type); |
|
| 334 | + self::include_sub_fields( $results, $inc_sub, $type ); |
|
| 335 | 335 | |
| 336 | 336 | return $results; |
| 337 | 337 | } |
@@ -343,15 +343,15 @@ discard block |
||
| 343 | 343 | |
| 344 | 344 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
| 345 | 345 | if ( ! empty( $results ) ) { |
| 346 | - if ( empty($limit) ) { |
|
| 346 | + if ( empty( $limit ) ) { |
|
| 347 | 347 | return $results; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | $fields = array(); |
| 351 | 351 | $count = 0; |
| 352 | 352 | foreach ( $results as $result ) { |
| 353 | - $fields[ $result->id ] = $result; |
|
| 354 | - if ( ! empty($limit) && $count >= $limit ) { |
|
| 353 | + $fields[$result->id] = $result; |
|
| 354 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
| 355 | 355 | break; |
| 356 | 356 | } |
| 357 | 357 | } |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | |
| 370 | 370 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
| 371 | 371 | |
| 372 | - if ( empty($limit) ) { |
|
| 372 | + if ( empty( $limit ) ) { |
|
| 373 | 373 | self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
| 374 | 374 | } |
| 375 | 375 | |
@@ -398,22 +398,22 @@ discard block |
||
| 398 | 398 | $form_fields = $results; |
| 399 | 399 | $index_offset = 1; |
| 400 | 400 | foreach ( $form_fields as $k => $field ) { |
| 401 | - if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
| 401 | + if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) { |
|
| 402 | 402 | continue; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | if ( $type == 'all' ) { |
| 406 | 406 | $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
| 407 | 407 | } else { |
| 408 | - $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
| 408 | + $sub_fields = self::get_all_types_in_form( $field->form_id, $type ); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - if ( ! empty($sub_fields) ) { |
|
| 411 | + if ( ! empty( $sub_fields ) ) { |
|
| 412 | 412 | $index = $k + $index_offset; |
| 413 | 413 | $index_offset += count( $sub_fields ); |
| 414 | - array_splice($results, $index, 0, $sub_fields); |
|
| 414 | + array_splice( $results, $index, 0, $sub_fields ); |
|
| 415 | 415 | } |
| 416 | - unset($field, $sub_fields); |
|
| 416 | + unset( $field, $sub_fields ); |
|
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | 419 | |
@@ -421,9 +421,9 @@ discard block |
||
| 421 | 421 | $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id; |
| 422 | 422 | if ( self::$use_cache ) { |
| 423 | 423 | // make sure old cache doesn't get saved as a transient |
| 424 | - $results = wp_cache_get($cache_key, 'frm_field'); |
|
| 424 | + $results = wp_cache_get( $cache_key, 'frm_field' ); |
|
| 425 | 425 | if ( false !== $results ) { |
| 426 | - return stripslashes_deep($results); |
|
| 426 | + return stripslashes_deep( $results ); |
|
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | 429 | |
@@ -448,16 +448,16 @@ discard block |
||
| 448 | 448 | $order_by = ' ORDER BY ' . $order_by; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - $limit = FrmAppHelper::esc_limit($limit); |
|
| 451 | + $limit = FrmAppHelper::esc_limit( $limit ); |
|
| 452 | 452 | |
| 453 | 453 | $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
| 454 | 454 | $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
| 455 | 455 | |
| 456 | - if ( is_array($where) ) { |
|
| 456 | + if ( is_array( $where ) ) { |
|
| 457 | 457 | $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type ); |
| 458 | 458 | } else { |
| 459 | 459 | // if the query is not an array, then it has already been prepared |
| 460 | - $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
| 460 | + $query .= FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
| 461 | 461 | |
| 462 | 462 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
| 463 | 463 | $results = $wpdb->$function_name( $query ); |
@@ -480,9 +480,9 @@ discard block |
||
| 480 | 480 | FrmAppHelper::set_cache( $result->id, $result, 'frm_field' ); |
| 481 | 481 | FrmAppHelper::set_cache( $result->field_key, $result, 'frm_field' ); |
| 482 | 482 | |
| 483 | - $results[ $r_key ]->field_options = maybe_unserialize( $result->field_options ); |
|
| 484 | - $results[ $r_key ]->options = maybe_unserialize( $result->options ); |
|
| 485 | - $results[ $r_key ]->default_value = maybe_unserialize( $result->default_value ); |
|
| 483 | + $results[$r_key]->field_options = maybe_unserialize( $result->field_options ); |
|
| 484 | + $results[$r_key]->options = maybe_unserialize( $result->options ); |
|
| 485 | + $results[$r_key]->default_value = maybe_unserialize( $result->default_value ); |
|
| 486 | 486 | |
| 487 | 487 | unset( $r_key, $result ); |
| 488 | 488 | } |
@@ -501,8 +501,8 @@ discard block |
||
| 501 | 501 | private static function prepare_options( &$results ) { |
| 502 | 502 | $results->field_options = maybe_unserialize( $results->field_options ); |
| 503 | 503 | |
| 504 | - $results->options = maybe_unserialize($results->options); |
|
| 505 | - $results->default_value = maybe_unserialize($results->default_value); |
|
| 504 | + $results->options = maybe_unserialize( $results->options ); |
|
| 505 | + $results->default_value = maybe_unserialize( $results->default_value ); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | |
| 530 | 530 | if ( count( $next_fields ) >= self::$transient_size ) { |
| 531 | 531 | // if this transient is full, check for another |
| 532 | - $next++; |
|
| 532 | + $next ++; |
|
| 533 | 533 | self::get_next_transient( $fields, $base_name, $next ); |
| 534 | 534 | } |
| 535 | 535 | } |
@@ -555,14 +555,14 @@ discard block |
||
| 555 | 555 | return; |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - $next++; |
|
| 558 | + $next ++; |
|
| 559 | 559 | } |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | public static function getIds( $where = '', $order_by = '', $limit = '' ) { |
| 563 | 563 | _deprecated_function( __FUNCTION__, '2.0' ); |
| 564 | 564 | global $wpdb; |
| 565 | - if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) { |
|
| 565 | + if ( ! empty( $order_by ) && ! strpos( $order_by, 'ORDER BY' ) !== false ) { |
|
| 566 | 566 | $order_by = ' ORDER BY ' . $order_by; |
| 567 | 567 | } |
| 568 | 568 | |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | |
| 573 | 573 | $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col'; |
| 574 | 574 | $cache_key = 'getIds_' . maybe_serialize( $where ) . $order_by . $limit; |
| 575 | - $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); |
|
| 575 | + $results = FrmAppHelper::check_cache( $cache_key, 'frm_field', $query, $method ); |
|
| 576 | 576 | |
| 577 | 577 | return $results; |
| 578 | 578 | } |
@@ -603,8 +603,8 @@ discard block |
||
| 603 | 603 | $is_multi_value_field = ( |
| 604 | 604 | $field['type'] == 'checkbox' || |
| 605 | 605 | $field['type'] == 'address' || |
| 606 | - ( $field['type'] == 'data' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) || |
|
| 607 | - ( $field['type'] == 'lookup' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) || |
|
| 606 | + ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'checkbox' ) || |
|
| 607 | + ( $field['type'] == 'lookup' && isset( $field['data_type'] ) && $field['data_type'] == 'checkbox' ) || |
|
| 608 | 608 | self::is_multiple_select( $field ) |
| 609 | 609 | ); |
| 610 | 610 | |
@@ -629,9 +629,9 @@ discard block |
||
| 629 | 629 | */ |
| 630 | 630 | public static function is_multiple_select( $field ) { |
| 631 | 631 | if ( is_array( $field ) ) { |
| 632 | - return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select') ) ); |
|
| 632 | + return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select' ) ) ); |
|
| 633 | 633 | } else { |
| 634 | - return self::is_option_true( $field, 'multiple' ) && ( ( $field->type == 'select' || ( $field->type == 'data' && isset($field->field_options['data_type'] ) && $field->field_options['data_type'] == 'select') ) ); |
|
| 634 | + return self::is_option_true( $field, 'multiple' ) && ( ( $field->type == 'select' || ( $field->type == 'data' && isset( $field->field_options['data_type'] ) && $field->field_options['data_type'] == 'select' ) ) ); |
|
| 635 | 635 | } |
| 636 | 636 | } |
| 637 | 637 | |
@@ -678,23 +678,23 @@ discard block |
||
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | public static function is_option_true_in_array( $field, $option ) { |
| 681 | - return isset( $field[ $option ] ) && $field[ $option ]; |
|
| 681 | + return isset( $field[$option] ) && $field[$option]; |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | public static function is_option_true_in_object( $field, $option ) { |
| 685 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ]; |
|
| 685 | + return isset( $field->field_options[$option] ) && $field->field_options[$option]; |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | public static function is_option_empty_in_array( $field, $option ) { |
| 689 | - return ! isset( $field[ $option ] ) || empty( $field[ $option ] ); |
|
| 689 | + return ! isset( $field[$option] ) || empty( $field[$option] ); |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | public static function is_option_empty_in_object( $field, $option ) { |
| 693 | - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] ); |
|
| 693 | + return ! isset( $field->field_options[$option] ) || empty( $field->field_options[$option] ); |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | public static function is_option_value_in_object( $field, $option ) { |
| 697 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != ''; |
|
| 697 | + return isset( $field->field_options[$option] ) && $field->field_options[$option] != ''; |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | /** |
@@ -710,11 +710,11 @@ discard block |
||
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | public static function get_option_in_array( $field, $option ) { |
| 713 | - return $field[ $option ]; |
|
| 713 | + return $field[$option]; |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | public static function get_option_in_object( $field, $option ) { |
| 717 | - return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : ''; |
|
| 717 | + return isset( $field->field_options[$option] ) ? $field->field_options[$option] : ''; |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmField { |
| 7 | - static $use_cache = true; |
|
| 7 | + static $use_cache = true; |
|
| 8 | 8 | static $transient_size = 200; |
| 9 | 9 | |
| 10 | 10 | public static function field_selection() { |
@@ -51,39 +51,39 @@ discard block |
||
| 51 | 51 | )); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public static function create( $values, $return = true ) { |
|
| 55 | - global $wpdb, $frm_duplicate_ids; |
|
| 54 | + public static function create( $values, $return = true ) { |
|
| 55 | + global $wpdb, $frm_duplicate_ids; |
|
| 56 | 56 | |
| 57 | - $new_values = array(); |
|
| 58 | - $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
| 57 | + $new_values = array(); |
|
| 58 | + $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
| 59 | 59 | $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
| 60 | 60 | |
| 61 | 61 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
| 62 | 62 | $new_values[ $col ] = $values[ $col ]; |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - $new_values['options'] = $values['options']; |
|
| 65 | + $new_values['options'] = $values['options']; |
|
| 66 | 66 | |
| 67 | - $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
| 68 | - $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
| 69 | - $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
| 70 | - $new_values['field_options'] = $values['field_options']; |
|
| 71 | - $new_values['created_at'] = current_time('mysql', 1); |
|
| 67 | + $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
| 68 | + $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
| 69 | + $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
| 70 | + $new_values['field_options'] = $values['field_options']; |
|
| 71 | + $new_values['created_at'] = current_time('mysql', 1); |
|
| 72 | 72 | |
| 73 | 73 | if ( isset( $values['id'] ) ) { |
| 74 | 74 | $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
| 75 | - $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
| 76 | - } |
|
| 75 | + $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | foreach ( $new_values as $k => $v ) { |
| 79 | - if ( is_array( $v ) ) { |
|
| 79 | + if ( is_array( $v ) ) { |
|
| 80 | 80 | $new_values[ $k ] = serialize( $v ); |
| 81 | 81 | } |
| 82 | - unset( $k, $v ); |
|
| 83 | - } |
|
| 82 | + unset( $k, $v ); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - //if(isset($values['id']) and is_numeric($values['id'])) |
|
| 86 | - // $new_values['id'] = $values['id']; |
|
| 85 | + //if(isset($values['id']) and is_numeric($values['id'])) |
|
| 86 | + // $new_values['id'] = $values['id']; |
|
| 87 | 87 | |
| 88 | 88 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values ); |
| 89 | 89 | $new_id = 0; |
@@ -104,22 +104,22 @@ discard block |
||
| 104 | 104 | } else { |
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) { |
|
| 110 | - global $frm_duplicate_ids; |
|
| 109 | + public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) { |
|
| 110 | + global $frm_duplicate_ids; |
|
| 111 | 111 | |
| 112 | 112 | $where = array( array( 'or' => 1, 'fi.form_id' => $old_form_id, 'fr.parent_form_id' => $old_form_id ) ); |
| 113 | 113 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
| 114 | 114 | |
| 115 | - foreach ( (array) $fields as $field ) { |
|
| 116 | - $new_key = ($copy_keys) ? $field->field_key : ''; |
|
| 117 | - if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
| 118 | - $new_key = rtrim($new_key, 2); |
|
| 119 | - } |
|
| 115 | + foreach ( (array) $fields as $field ) { |
|
| 116 | + $new_key = ($copy_keys) ? $field->field_key : ''; |
|
| 117 | + if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
| 118 | + $new_key = rtrim($new_key, 2); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - $values = array(); |
|
| 122 | - FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key ); |
|
| 121 | + $values = array(); |
|
| 122 | + FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key ); |
|
| 123 | 123 | |
| 124 | 124 | // If this is a repeating section, create new form |
| 125 | 125 | if ( self::is_repeating_field( $field ) ) { |
@@ -138,16 +138,16 @@ discard block |
||
| 138 | 138 | $values['form_id'] = $new_repeat_form_id; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $values = apply_filters('frm_duplicated_field', $values); |
|
| 142 | - $new_id = self::create($values); |
|
| 143 | - $frm_duplicate_ids[ $field->id ] = $new_id; |
|
| 144 | - $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
| 145 | - unset($field); |
|
| 146 | - } |
|
| 147 | - } |
|
| 141 | + $values = apply_filters('frm_duplicated_field', $values); |
|
| 142 | + $new_id = self::create($values); |
|
| 143 | + $frm_duplicate_ids[ $field->id ] = $new_id; |
|
| 144 | + $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
| 145 | + unset($field); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | 149 | public static function update( $id, $values ) { |
| 150 | - global $wpdb; |
|
| 150 | + global $wpdb; |
|
| 151 | 151 | |
| 152 | 152 | $id = absint( $id ); |
| 153 | 153 | |
@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id ); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if ( isset($values['required']) ) { |
|
| 159 | - $values['required'] = (int) $values['required']; |
|
| 160 | - } |
|
| 158 | + if ( isset($values['required']) ) { |
|
| 159 | + $values['required'] = (int) $values['required']; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | 162 | self::preserve_format_option_backslashes( $values ); |
| 163 | 163 | |
@@ -174,41 +174,41 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) ); |
| 176 | 176 | |
| 177 | - $form_id = 0; |
|
| 177 | + $form_id = 0; |
|
| 178 | 178 | if ( isset( $values['form_id'] ) ) { |
| 179 | - $form_id = absint( $values['form_id'] ); |
|
| 179 | + $form_id = absint( $values['form_id'] ); |
|
| 180 | 180 | } else { |
| 181 | - $field = self::getOne($id); |
|
| 182 | - if ( $field ) { |
|
| 183 | - $form_id = $field->form_id; |
|
| 184 | - } |
|
| 185 | - unset($field); |
|
| 186 | - } |
|
| 187 | - unset($values); |
|
| 181 | + $field = self::getOne($id); |
|
| 182 | + if ( $field ) { |
|
| 183 | + $form_id = $field->form_id; |
|
| 184 | + } |
|
| 185 | + unset($field); |
|
| 186 | + } |
|
| 187 | + unset($values); |
|
| 188 | 188 | |
| 189 | 189 | if ( $query_results ) { |
| 190 | - wp_cache_delete( $id, 'frm_field' ); |
|
| 191 | - if ( $form_id ) { |
|
| 192 | - self::delete_form_transient( $form_id ); |
|
| 193 | - } |
|
| 194 | - } |
|
| 190 | + wp_cache_delete( $id, 'frm_field' ); |
|
| 191 | + if ( $form_id ) { |
|
| 192 | + self::delete_form_transient( $form_id ); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - return $query_results; |
|
| 197 | - } |
|
| 196 | + return $query_results; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | /** |
| 200 | - * Keep backslashes in the phone format option |
|
| 201 | - * |
|
| 202 | - * @since 2.0.8 |
|
| 203 | - * @param $values array - pass by reference |
|
| 204 | - */ |
|
| 200 | + * Keep backslashes in the phone format option |
|
| 201 | + * |
|
| 202 | + * @since 2.0.8 |
|
| 203 | + * @param $values array - pass by reference |
|
| 204 | + */ |
|
| 205 | 205 | private static function preserve_format_option_backslashes( &$values ) { |
| 206 | 206 | if ( isset( $values['field_options']['format'] ) ) { |
| 207 | 207 | $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] ); |
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - public static function destroy( $id ) { |
|
| 211 | + public static function destroy( $id ) { |
|
| 212 | 212 | global $wpdb; |
| 213 | 213 | |
| 214 | 214 | do_action( 'frm_before_destroy_field', $id ); |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) ); |
| 225 | 225 | return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) ); |
| 226 | - } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | 228 | public static function delete_form_transient( $form_id ) { |
| 229 | 229 | $form_id = absint( $form_id ); |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | FrmAppHelper::cache_delete_group( 'frm_field' ); |
| 239 | 239 | |
| 240 | - $form = FrmForm::getOne($form_id); |
|
| 241 | - if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) { |
|
| 242 | - self::delete_form_transient( $form->parent_form_id ); |
|
| 243 | - } |
|
| 244 | - } |
|
| 240 | + $form = FrmForm::getOne($form_id); |
|
| 241 | + if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) { |
|
| 242 | + self::delete_form_transient( $form->parent_form_id ); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | 247 | * If $field is numeric, get the field object |
@@ -257,131 +257,131 @@ discard block |
||
| 257 | 257 | return; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - global $wpdb; |
|
| 260 | + global $wpdb; |
|
| 261 | 261 | |
| 262 | - $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
| 262 | + $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
| 263 | 263 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); |
| 264 | 264 | |
| 265 | - $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
|
| 265 | + $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
|
| 266 | 266 | |
| 267 | - if ( empty($results) ) { |
|
| 268 | - return $results; |
|
| 269 | - } |
|
| 267 | + if ( empty($results) ) { |
|
| 268 | + return $results; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - if ( is_numeric($id) ) { |
|
| 271 | + if ( is_numeric($id) ) { |
|
| 272 | 272 | FrmAppHelper::set_cache( $results->field_key, $results, 'frm_field' ); |
| 273 | - } else if ( $results ) { |
|
| 273 | + } else if ( $results ) { |
|
| 274 | 274 | FrmAppHelper::set_cache( $results->id, $results, 'frm_field' ); |
| 275 | - } |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | 277 | self::prepare_options( $results ); |
| 278 | 278 | |
| 279 | - return stripslashes_deep($results); |
|
| 280 | - } |
|
| 279 | + return stripslashes_deep($results); |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - /** |
|
| 283 | - * Get the field type by key or id |
|
| 284 | - * @param int|string The field id or key |
|
| 282 | + /** |
|
| 283 | + * Get the field type by key or id |
|
| 284 | + * @param int|string The field id or key |
|
| 285 | 285 | * @param mixed $col The name of the column in the fields database table |
| 286 | - */ |
|
| 287 | - public static function &get_type( $id, $col = 'type' ) { |
|
| 288 | - $field = FrmAppHelper::check_cache( $id, 'frm_field' ); |
|
| 289 | - if ( $field ) { |
|
| 290 | - $type = $field->{$col}; |
|
| 291 | - } else { |
|
| 292 | - $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col ); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - return $type; |
|
| 296 | - } |
|
| 286 | + */ |
|
| 287 | + public static function &get_type( $id, $col = 'type' ) { |
|
| 288 | + $field = FrmAppHelper::check_cache( $id, 'frm_field' ); |
|
| 289 | + if ( $field ) { |
|
| 290 | + $type = $field->{$col}; |
|
| 291 | + } else { |
|
| 292 | + $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col ); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + return $type; |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | 298 | public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) { |
| 299 | - if ( ! $form_id ) { |
|
| 300 | - return array(); |
|
| 301 | - } |
|
| 299 | + if ( ! $form_id ) { |
|
| 300 | + return array(); |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | 303 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_sub, 'inc_repeat' => $inc_sub ) ); |
| 304 | 304 | if ( ! empty( $results ) ) { |
| 305 | - $fields = array(); |
|
| 306 | - $count = 0; |
|
| 307 | - foreach ( $results as $result ) { |
|
| 308 | - if ( $type != $result->type ) { |
|
| 309 | - continue; |
|
| 310 | - } |
|
| 305 | + $fields = array(); |
|
| 306 | + $count = 0; |
|
| 307 | + foreach ( $results as $result ) { |
|
| 308 | + if ( $type != $result->type ) { |
|
| 309 | + continue; |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | 312 | $fields[ $result->id ] = $result; |
| 313 | - $count++; |
|
| 314 | - if ( $limit == 1 ) { |
|
| 315 | - $fields = $result; |
|
| 316 | - break; |
|
| 317 | - } |
|
| 313 | + $count++; |
|
| 314 | + if ( $limit == 1 ) { |
|
| 315 | + $fields = $result; |
|
| 316 | + break; |
|
| 317 | + } |
|
| 318 | 318 | |
| 319 | - if ( ! empty($limit) && $count >= $limit ) { |
|
| 320 | - break; |
|
| 321 | - } |
|
| 319 | + if ( ! empty($limit) && $count >= $limit ) { |
|
| 320 | + break; |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - unset($result); |
|
| 324 | - } |
|
| 325 | - return stripslashes_deep($fields); |
|
| 326 | - } |
|
| 323 | + unset($result); |
|
| 324 | + } |
|
| 325 | + return stripslashes_deep($fields); |
|
| 326 | + } |
|
| 327 | 327 | |
| 328 | - self::$use_cache = false; |
|
| 328 | + self::$use_cache = false; |
|
| 329 | 329 | |
| 330 | 330 | $where = array( 'fi.form_id' => (int) $form_id, 'fi.type' => $type ); |
| 331 | 331 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
| 332 | 332 | $results = self::getAll( $where, 'field_order', $limit ); |
| 333 | - self::$use_cache = true; |
|
| 334 | - self::include_sub_fields($results, $inc_sub, $type); |
|
| 333 | + self::$use_cache = true; |
|
| 334 | + self::include_sub_fields($results, $inc_sub, $type); |
|
| 335 | 335 | |
| 336 | - return $results; |
|
| 337 | - } |
|
| 336 | + return $results; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | 339 | public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) { |
| 340 | - if ( ! (int) $form_id ) { |
|
| 341 | - return array(); |
|
| 342 | - } |
|
| 340 | + if ( ! (int) $form_id ) { |
|
| 341 | + return array(); |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | 344 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
| 345 | 345 | if ( ! empty( $results ) ) { |
| 346 | - if ( empty($limit) ) { |
|
| 346 | + if ( empty($limit) ) { |
|
| 347 | 347 | return $results; |
| 348 | - } |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | - $fields = array(); |
|
| 351 | - $count = 0; |
|
| 352 | - foreach ( $results as $result ) { |
|
| 350 | + $fields = array(); |
|
| 351 | + $count = 0; |
|
| 352 | + foreach ( $results as $result ) { |
|
| 353 | 353 | $fields[ $result->id ] = $result; |
| 354 | - if ( ! empty($limit) && $count >= $limit ) { |
|
| 355 | - break; |
|
| 356 | - } |
|
| 357 | - } |
|
| 354 | + if ( ! empty($limit) && $count >= $limit ) { |
|
| 355 | + break; |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | 359 | return $fields; |
| 360 | - } |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - self::$use_cache = false; |
|
| 362 | + self::$use_cache = false; |
|
| 363 | 363 | |
| 364 | 364 | $where = array( 'fi.form_id' => absint( $form_id ) ); |
| 365 | 365 | self::maybe_include_repeating_fields( $inc_repeat, $where ); |
| 366 | 366 | $results = self::getAll( $where, 'field_order', $limit ); |
| 367 | 367 | |
| 368 | - self::$use_cache = true; |
|
| 368 | + self::$use_cache = true; |
|
| 369 | 369 | |
| 370 | 370 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
| 371 | 371 | |
| 372 | - if ( empty($limit) ) { |
|
| 372 | + if ( empty($limit) ) { |
|
| 373 | 373 | self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
| 374 | - } |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | 376 | return $results; |
| 377 | - } |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | 379 | /** |
| 380 | - * If repeating fields should be included, adjust $where accordingly |
|
| 381 | - * |
|
| 382 | - * @param string $inc_repeat |
|
| 383 | - * @param array $where - pass by reference |
|
| 384 | - */ |
|
| 380 | + * If repeating fields should be included, adjust $where accordingly |
|
| 381 | + * |
|
| 382 | + * @param string $inc_repeat |
|
| 383 | + * @param array $where - pass by reference |
|
| 384 | + */ |
|
| 385 | 385 | private static function maybe_include_repeating_fields( $inc_repeat, &$where ) { |
| 386 | 386 | if ( $inc_repeat == 'include' ) { |
| 387 | 387 | $form_id = $where['fi.form_id']; |
@@ -392,77 +392,77 @@ discard block |
||
| 392 | 392 | |
| 393 | 393 | public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) { |
| 394 | 394 | if ( 'include' != $inc_embed || empty( $results ) ) { |
| 395 | - return; |
|
| 396 | - } |
|
| 395 | + return; |
|
| 396 | + } |
|
| 397 | 397 | |
| 398 | - $form_fields = $results; |
|
| 398 | + $form_fields = $results; |
|
| 399 | 399 | $index_offset = 1; |
| 400 | - foreach ( $form_fields as $k => $field ) { |
|
| 401 | - if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
| 402 | - continue; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - if ( $type == 'all' ) { |
|
| 406 | - $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
|
| 407 | - } else { |
|
| 408 | - $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - if ( ! empty($sub_fields) ) { |
|
| 400 | + foreach ( $form_fields as $k => $field ) { |
|
| 401 | + if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
| 402 | + continue; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + if ( $type == 'all' ) { |
|
| 406 | + $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
|
| 407 | + } else { |
|
| 408 | + $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + if ( ! empty($sub_fields) ) { |
|
| 412 | 412 | $index = $k + $index_offset; |
| 413 | 413 | $index_offset += count( $sub_fields ); |
| 414 | 414 | array_splice($results, $index, 0, $sub_fields); |
| 415 | - } |
|
| 416 | - unset($field, $sub_fields); |
|
| 417 | - } |
|
| 418 | - } |
|
| 415 | + } |
|
| 416 | + unset($field, $sub_fields); |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | 420 | public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) { |
| 421 | 421 | $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id; |
| 422 | - if ( self::$use_cache ) { |
|
| 423 | - // make sure old cache doesn't get saved as a transient |
|
| 424 | - $results = wp_cache_get($cache_key, 'frm_field'); |
|
| 425 | - if ( false !== $results ) { |
|
| 426 | - return stripslashes_deep($results); |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - global $wpdb; |
|
| 431 | - |
|
| 432 | - if ( $blog_id && is_multisite() ) { |
|
| 433 | - global $wpmuBaseTablePrefix; |
|
| 434 | - if ( $wpmuBaseTablePrefix ) { |
|
| 422 | + if ( self::$use_cache ) { |
|
| 423 | + // make sure old cache doesn't get saved as a transient |
|
| 424 | + $results = wp_cache_get($cache_key, 'frm_field'); |
|
| 425 | + if ( false !== $results ) { |
|
| 426 | + return stripslashes_deep($results); |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + global $wpdb; |
|
| 431 | + |
|
| 432 | + if ( $blog_id && is_multisite() ) { |
|
| 433 | + global $wpmuBaseTablePrefix; |
|
| 434 | + if ( $wpmuBaseTablePrefix ) { |
|
| 435 | 435 | $prefix = $wpmuBaseTablePrefix . $blog_id . '_'; |
| 436 | - } else { |
|
| 437 | - $prefix = $wpdb->get_blog_prefix( $blog_id ); |
|
| 438 | - } |
|
| 436 | + } else { |
|
| 437 | + $prefix = $wpdb->get_blog_prefix( $blog_id ); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | 440 | $table_name = $prefix . 'frm_fields'; |
| 441 | 441 | $form_table_name = $prefix . 'frm_forms'; |
| 442 | 442 | } else { |
| 443 | 443 | $table_name = $wpdb->prefix . 'frm_fields'; |
| 444 | 444 | $form_table_name = $wpdb->prefix . 'frm_forms'; |
| 445 | - } |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | 447 | if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) { |
| 448 | 448 | $order_by = ' ORDER BY ' . $order_by; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - $limit = FrmAppHelper::esc_limit($limit); |
|
| 451 | + $limit = FrmAppHelper::esc_limit($limit); |
|
| 452 | 452 | |
| 453 | - $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
|
| 454 | - $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
|
| 453 | + $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
|
| 454 | + $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
|
| 455 | 455 | |
| 456 | - if ( is_array($where) ) { |
|
| 457 | - $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type ); |
|
| 456 | + if ( is_array($where) ) { |
|
| 457 | + $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type ); |
|
| 458 | 458 | } else { |
| 459 | 459 | // if the query is not an array, then it has already been prepared |
| 460 | - $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
| 460 | + $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
| 461 | 461 | |
| 462 | 462 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
| 463 | 463 | $results = $wpdb->$function_name( $query ); |
| 464 | - } |
|
| 465 | - unset( $where ); |
|
| 464 | + } |
|
| 465 | + unset( $where ); |
|
| 466 | 466 | |
| 467 | 467 | self::format_field_results( $results ); |
| 468 | 468 | |
@@ -561,21 +561,21 @@ discard block |
||
| 561 | 561 | |
| 562 | 562 | public static function getIds( $where = '', $order_by = '', $limit = '' ) { |
| 563 | 563 | _deprecated_function( __FUNCTION__, '2.0' ); |
| 564 | - global $wpdb; |
|
| 565 | - if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) { |
|
| 564 | + global $wpdb; |
|
| 565 | + if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) { |
|
| 566 | 566 | $order_by = ' ORDER BY ' . $order_by; |
| 567 | - } |
|
| 567 | + } |
|
| 568 | 568 | |
| 569 | 569 | $query = 'SELECT fi.id FROM ' . $wpdb->prefix . 'frm_fields fi ' . |
| 570 | 570 | 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON fi.form_id=fr.id' . |
| 571 | 571 | FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
| 572 | 572 | |
| 573 | - $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col'; |
|
| 573 | + $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col'; |
|
| 574 | 574 | $cache_key = 'getIds_' . maybe_serialize( $where ) . $order_by . $limit; |
| 575 | - $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); |
|
| 575 | + $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); |
|
| 576 | 576 | |
| 577 | - return $results; |
|
| 578 | - } |
|
| 577 | + return $results; |
|
| 578 | + } |
|
| 579 | 579 | |
| 580 | 580 | public static function is_no_save_field( $type ) { |
| 581 | 581 | return in_array( $type, self::no_save_fields() ); |
@@ -718,8 +718,8 @@ discard block |
||
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
| 721 | - * @since 2.0.09 |
|
| 722 | - */ |
|
| 721 | + * @since 2.0.09 |
|
| 722 | + */ |
|
| 723 | 723 | public static function is_repeating_field( $field ) { |
| 724 | 724 | if ( is_array( $field ) ) { |
| 725 | 725 | $is_repeating_field = ( 'divider' == $field['type'] ); |
@@ -729,14 +729,14 @@ discard block |
||
| 729 | 729 | return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) ); |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | - /** |
|
| 733 | - * @param string $key |
|
| 734 | - * @return int field id |
|
| 735 | - */ |
|
| 732 | + /** |
|
| 733 | + * @param string $key |
|
| 734 | + * @return int field id |
|
| 735 | + */ |
|
| 736 | 736 | public static function get_id_by_key( $key ) { |
| 737 | - $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) ); |
|
| 738 | - return $id; |
|
| 739 | - } |
|
| 737 | + $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) ); |
|
| 738 | + return $id; |
|
| 739 | + } |
|
| 740 | 740 | |
| 741 | 741 | /** |
| 742 | 742 | * @param string $id |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | * @uses api_request() |
| 71 | 71 | * |
| 72 | 72 | * @param array $_transient_data Update array build by WordPress. |
| 73 | - * @return array Modified update array with custom plugin data. |
|
| 73 | + * @return stdClass Modified update array with custom plugin data. |
|
| 74 | 74 | */ |
| 75 | 75 | public function check_update( $_transient_data ) { |
| 76 | 76 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $this->version = $_api_data['version']; |
| 44 | 44 | $this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false; |
| 45 | 45 | |
| 46 | - $frm_edd_plugin_data[ $this->slug ] = $this->api_data; |
|
| 46 | + $frm_edd_plugin_data[$this->slug] = $this->api_data; |
|
| 47 | 47 | |
| 48 | 48 | // Set up hooks. |
| 49 | 49 | $this->init(); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $_transient_data = new stdClass; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) { |
|
| 86 | + if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[$this->name] ) && false === $this->wp_override ) { |
|
| 87 | 87 | return $_transient_data; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | $version_info->plugin = $this->name; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - $_transient_data->response[ $this->name ] = $version_info; |
|
| 100 | + $_transient_data->response[$this->name] = $version_info; |
|
| 101 | 101 | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $_transient_data->last_checked = time(); |
| 105 | - $_transient_data->checked[ $this->name ] = $this->version; |
|
| 105 | + $_transient_data->checked[$this->name] = $this->version; |
|
| 106 | 106 | |
| 107 | 107 | } |
| 108 | 108 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | wp_die( __( 'You do not have permission to install plugin updates', 'formidable' ), __( 'Error', 'formidable' ), array( 'response' => 403 ) ); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - $data = $frm_edd_plugin_data[ $_REQUEST['slug'] ]; |
|
| 248 | + $data = $frm_edd_plugin_data[$_REQUEST['slug']]; |
|
| 249 | 249 | $cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_version_info' ); |
| 250 | 250 | $version_info = get_transient( $cache_key ); |
| 251 | 251 | |
@@ -29,19 +29,19 @@ discard block |
||
| 29 | 29 | public $re_multi; |
| 30 | 30 | |
| 31 | 31 | public function __construct() { |
| 32 | - if ( ! defined('ABSPATH') ) { |
|
| 33 | - die('You are not allowed to call this page directly.'); |
|
| 32 | + if ( ! defined( 'ABSPATH' ) ) { |
|
| 33 | + die( 'You are not allowed to call this page directly.' ); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - $settings = get_transient($this->option_name); |
|
| 36 | + $settings = get_transient( $this->option_name ); |
|
| 37 | 37 | |
| 38 | - if ( ! is_object($settings) ) { |
|
| 39 | - $settings = $this->translate_settings($settings); |
|
| 38 | + if ( ! is_object( $settings ) ) { |
|
| 39 | + $settings = $this->translate_settings( $settings ); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | foreach ( $settings as $setting_name => $setting ) { |
| 43 | 43 | $this->{$setting_name} = $setting; |
| 44 | - unset($setting_name, $setting); |
|
| 44 | + unset( $setting_name, $setting ); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | $this->set_default_options(); |
@@ -49,24 +49,24 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | private function translate_settings( $settings ) { |
| 51 | 51 | if ( $settings ) { //workaround for W3 total cache conflict |
| 52 | - return unserialize(serialize($settings)); |
|
| 52 | + return unserialize( serialize( $settings ) ); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - $settings = get_option($this->option_name); |
|
| 56 | - if ( is_object($settings) ) { |
|
| 57 | - set_transient($this->option_name, $settings); |
|
| 55 | + $settings = get_option( $this->option_name ); |
|
| 56 | + if ( is_object( $settings ) ) { |
|
| 57 | + set_transient( $this->option_name, $settings ); |
|
| 58 | 58 | return $settings; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // If unserializing didn't work |
| 62 | 62 | if ( $settings ) { //workaround for W3 total cache conflict |
| 63 | - $settings = unserialize(serialize($settings)); |
|
| 63 | + $settings = unserialize( serialize( $settings ) ); |
|
| 64 | 64 | } else { |
| 65 | 65 | $settings = $this; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - update_option($this->option_name, $settings); |
|
| 69 | - set_transient($this->option_name, $settings); |
|
| 68 | + update_option( $this->option_name, $settings ); |
|
| 69 | + set_transient( $this->option_name, $settings ); |
|
| 70 | 70 | |
| 71 | 71 | return $settings; |
| 72 | 72 | } |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | private function set_default_options() { |
| 102 | 102 | $this->fill_recaptcha_settings(); |
| 103 | 103 | |
| 104 | - if ( ! isset($this->load_style) ) { |
|
| 105 | - if ( ! isset($this->custom_style) ) { |
|
| 104 | + if ( ! isset( $this->load_style ) ) { |
|
| 105 | + if ( ! isset( $this->custom_style ) ) { |
|
| 106 | 106 | $this->custom_style = true; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -112,16 +112,16 @@ discard block |
||
| 112 | 112 | $this->fill_with_defaults(); |
| 113 | 113 | |
| 114 | 114 | if ( is_multisite() && is_admin() ) { |
| 115 | - $mu_menu = get_site_option('frm_admin_menu_name'); |
|
| 116 | - if ( $mu_menu && ! empty($mu_menu) ) { |
|
| 115 | + $mu_menu = get_site_option( 'frm_admin_menu_name' ); |
|
| 116 | + if ( $mu_menu && ! empty( $mu_menu ) ) { |
|
| 117 | 117 | $this->menu = $mu_menu; |
| 118 | 118 | $this->mu_menu = 1; |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - $frm_roles = FrmAppHelper::frm_capabilities('pro'); |
|
| 122 | + $frm_roles = FrmAppHelper::frm_capabilities( 'pro' ); |
|
| 123 | 123 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
| 124 | - if ( ! isset($this->$frm_role) ) { |
|
| 124 | + if ( ! isset( $this->$frm_role ) ) { |
|
| 125 | 125 | $this->$frm_role = 'administrator'; |
| 126 | 126 | } |
| 127 | 127 | } |
@@ -131,9 +131,9 @@ discard block |
||
| 131 | 131 | $settings = $this->default_options(); |
| 132 | 132 | |
| 133 | 133 | foreach ( $settings as $setting => $default ) { |
| 134 | - if ( isset( $params[ 'frm_' . $setting ] ) ) { |
|
| 135 | - $this->{$setting} = $params[ 'frm_' . $setting ]; |
|
| 136 | - } else if ( ! isset($this->{$setting}) ) { |
|
| 134 | + if ( isset( $params['frm_' . $setting] ) ) { |
|
| 135 | + $this->{$setting} = $params['frm_' . $setting]; |
|
| 136 | + } else if ( ! isset( $this->{$setting}) ) { |
|
| 137 | 137 | $this->{$setting} = $default; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $this->{$setting} = $default; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - unset($setting, $default); |
|
| 144 | + unset( $setting, $default ); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
@@ -149,23 +149,23 @@ discard block |
||
| 149 | 149 | $privkey = ''; |
| 150 | 150 | $re_lang = ''; |
| 151 | 151 | |
| 152 | - if ( ! isset($this->pubkey) ) { |
|
| 152 | + if ( ! isset( $this->pubkey ) ) { |
|
| 153 | 153 | // get the options from the database |
| 154 | - $recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha'); |
|
| 155 | - $this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : ''; |
|
| 156 | - $privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey; |
|
| 157 | - $re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang; |
|
| 154 | + $recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' ); |
|
| 155 | + $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : ''; |
|
| 156 | + $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey; |
|
| 157 | + $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - if ( ! isset($this->re_msg) || empty($this->re_msg) ) { |
|
| 160 | + if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) { |
|
| 161 | 161 | $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' ); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - if ( ! isset($this->privkey) ) { |
|
| 164 | + if ( ! isset( $this->privkey ) ) { |
|
| 165 | 165 | $this->privkey = $privkey; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if ( ! isset($this->re_lang) ) { |
|
| 168 | + if ( ! isset( $this->re_lang ) ) { |
|
| 169 | 169 | $this->re_lang = $re_lang; |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -176,24 +176,24 @@ discard block |
||
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | public function update( $params ) { |
| 179 | - $this->fill_with_defaults($params); |
|
| 180 | - $this->update_settings($params); |
|
| 179 | + $this->fill_with_defaults( $params ); |
|
| 180 | + $this->update_settings( $params ); |
|
| 181 | 181 | |
| 182 | 182 | if ( $this->mu_menu ) { |
| 183 | - update_site_option('frm_admin_menu_name', $this->menu); |
|
| 184 | - } else if ( current_user_can('administrator') ) { |
|
| 185 | - update_site_option('frm_admin_menu_name', false); |
|
| 183 | + update_site_option( 'frm_admin_menu_name', $this->menu ); |
|
| 184 | + } else if ( current_user_can( 'administrator' ) ) { |
|
| 185 | + update_site_option( 'frm_admin_menu_name', false ); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - $this->update_roles($params); |
|
| 188 | + $this->update_roles( $params ); |
|
| 189 | 189 | |
| 190 | 190 | do_action( 'frm_update_settings', $params ); |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | private function update_settings( $params ) { |
| 194 | - $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0; |
|
| 194 | + $this->mu_menu = isset( $params['frm_mu_menu'] ) ? $params['frm_mu_menu'] : 0; |
|
| 195 | 195 | |
| 196 | - $this->pubkey = trim($params['frm_pubkey']); |
|
| 196 | + $this->pubkey = trim( $params['frm_pubkey'] ); |
|
| 197 | 197 | $this->privkey = $params['frm_privkey']; |
| 198 | 198 | $this->re_lang = $params['frm_re_lang']; |
| 199 | 199 | $this->re_multi = isset( $params['frm_re_multi'] ) ? $params['frm_re_multi'] : 0; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | $this->load_style = $params['frm_load_style']; |
| 202 | 202 | $this->preview_page_id = (int) $params['frm-preview-page-id']; |
| 203 | 203 | |
| 204 | - $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0; |
|
| 204 | + $this->use_html = isset( $params['frm_use_html'] ) ? $params['frm_use_html'] : 0; |
|
| 205 | 205 | //$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0; |
| 206 | 206 | $this->jquery_css = isset( $params['frm_jquery_css'] ) ? absint( $params['frm_jquery_css'] ) : 0; |
| 207 | 207 | $this->accordion_js = isset( $params['frm_accordion_js'] ) ? absint( $params['frm_accordion_js'] ) : 0; |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | $frm_roles = FrmAppHelper::frm_capabilities(); |
| 214 | 214 | $roles = get_editable_roles(); |
| 215 | 215 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
| 216 | - $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' ); |
|
| 216 | + $this->$frm_role = (array) ( isset( $params[$frm_role] ) ? $params[$frm_role] : 'administrator' ); |
|
| 217 | 217 | |
| 218 | 218 | // Make sure administrators always have permissions |
| 219 | 219 | if ( ! in_array( 'administrator', $this->$frm_role ) ) { |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | foreach ( $roles as $role => $details ) { |
| 224 | - if ( in_array($role, $this->$frm_role) ) { |
|
| 224 | + if ( in_array( $role, $this->$frm_role ) ) { |
|
| 225 | 225 | $wp_roles->add_cap( $role, $frm_role ); |
| 226 | 226 | } else { |
| 227 | 227 | $wp_roles->remove_cap( $role, $frm_role ); |
@@ -233,10 +233,10 @@ discard block |
||
| 233 | 233 | public function store() { |
| 234 | 234 | // Save the posted value in the database |
| 235 | 235 | |
| 236 | - update_option('frm_options', $this); |
|
| 236 | + update_option( 'frm_options', $this ); |
|
| 237 | 237 | |
| 238 | - delete_transient('frm_options'); |
|
| 239 | - set_transient('frm_options', $this); |
|
| 238 | + delete_transient( 'frm_options' ); |
|
| 239 | + set_transient( 'frm_options', $this ); |
|
| 240 | 240 | |
| 241 | 241 | do_action( 'frm_store_settings' ); |
| 242 | 242 | } |
@@ -48,7 +48,8 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | private function translate_settings( $settings ) { |
| 51 | - if ( $settings ) { //workaround for W3 total cache conflict |
|
| 51 | + if ( $settings ) { |
|
| 52 | +//workaround for W3 total cache conflict |
|
| 52 | 53 | return unserialize(serialize($settings)); |
| 53 | 54 | } |
| 54 | 55 | |
@@ -59,7 +60,8 @@ discard block |
||
| 59 | 60 | } |
| 60 | 61 | |
| 61 | 62 | // If unserializing didn't work |
| 62 | - if ( $settings ) { //workaround for W3 total cache conflict |
|
| 63 | + if ( $settings ) { |
|
| 64 | +//workaround for W3 total cache conflict |
|
| 63 | 65 | $settings = unserialize(serialize($settings)); |
| 64 | 66 | } else { |
| 65 | 67 | $settings = $this; |
@@ -1,242 +1,242 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class FrmSettings { |
| 4 | - public $option_name = 'frm_options'; |
|
| 5 | - public $menu; |
|
| 6 | - public $mu_menu; |
|
| 7 | - public $preview_page_id; |
|
| 8 | - public $use_html; |
|
| 9 | - public $jquery_css; |
|
| 10 | - public $accordion_js; |
|
| 11 | - |
|
| 12 | - public $success_msg; |
|
| 13 | - public $blank_msg; |
|
| 14 | - public $unique_msg; |
|
| 15 | - public $invalid_msg; |
|
| 16 | - public $failed_msg; |
|
| 17 | - public $submit_value; |
|
| 18 | - public $login_msg; |
|
| 19 | - public $admin_permission; |
|
| 20 | - |
|
| 21 | - public $email_to; |
|
| 22 | - public $load_style; |
|
| 23 | - public $custom_style; |
|
| 24 | - |
|
| 25 | - public $pubkey; |
|
| 26 | - public $privkey; |
|
| 27 | - public $re_lang; |
|
| 28 | - public $re_msg; |
|
| 4 | + public $option_name = 'frm_options'; |
|
| 5 | + public $menu; |
|
| 6 | + public $mu_menu; |
|
| 7 | + public $preview_page_id; |
|
| 8 | + public $use_html; |
|
| 9 | + public $jquery_css; |
|
| 10 | + public $accordion_js; |
|
| 11 | + |
|
| 12 | + public $success_msg; |
|
| 13 | + public $blank_msg; |
|
| 14 | + public $unique_msg; |
|
| 15 | + public $invalid_msg; |
|
| 16 | + public $failed_msg; |
|
| 17 | + public $submit_value; |
|
| 18 | + public $login_msg; |
|
| 19 | + public $admin_permission; |
|
| 20 | + |
|
| 21 | + public $email_to; |
|
| 22 | + public $load_style; |
|
| 23 | + public $custom_style; |
|
| 24 | + |
|
| 25 | + public $pubkey; |
|
| 26 | + public $privkey; |
|
| 27 | + public $re_lang; |
|
| 28 | + public $re_msg; |
|
| 29 | 29 | public $re_multi; |
| 30 | 30 | |
| 31 | - public function __construct() { |
|
| 32 | - if ( ! defined('ABSPATH') ) { |
|
| 33 | - die('You are not allowed to call this page directly.'); |
|
| 34 | - } |
|
| 31 | + public function __construct() { |
|
| 32 | + if ( ! defined('ABSPATH') ) { |
|
| 33 | + die('You are not allowed to call this page directly.'); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - $settings = get_transient($this->option_name); |
|
| 36 | + $settings = get_transient($this->option_name); |
|
| 37 | 37 | |
| 38 | - if ( ! is_object($settings) ) { |
|
| 39 | - $settings = $this->translate_settings($settings); |
|
| 40 | - } |
|
| 38 | + if ( ! is_object($settings) ) { |
|
| 39 | + $settings = $this->translate_settings($settings); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - foreach ( $settings as $setting_name => $setting ) { |
|
| 43 | - $this->{$setting_name} = $setting; |
|
| 44 | - unset($setting_name, $setting); |
|
| 45 | - } |
|
| 42 | + foreach ( $settings as $setting_name => $setting ) { |
|
| 43 | + $this->{$setting_name} = $setting; |
|
| 44 | + unset($setting_name, $setting); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - $this->set_default_options(); |
|
| 48 | - } |
|
| 47 | + $this->set_default_options(); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | private function translate_settings( $settings ) { |
| 51 | - if ( $settings ) { //workaround for W3 total cache conflict |
|
| 52 | - return unserialize(serialize($settings)); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - $settings = get_option($this->option_name); |
|
| 56 | - if ( is_object($settings) ) { |
|
| 57 | - set_transient($this->option_name, $settings); |
|
| 58 | - return $settings; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // If unserializing didn't work |
|
| 62 | - if ( $settings ) { //workaround for W3 total cache conflict |
|
| 63 | - $settings = unserialize(serialize($settings)); |
|
| 64 | - } else { |
|
| 65 | - $settings = $this; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - update_option($this->option_name, $settings); |
|
| 69 | - set_transient($this->option_name, $settings); |
|
| 70 | - |
|
| 71 | - return $settings; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @return array |
|
| 76 | - */ |
|
| 51 | + if ( $settings ) { //workaround for W3 total cache conflict |
|
| 52 | + return unserialize(serialize($settings)); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + $settings = get_option($this->option_name); |
|
| 56 | + if ( is_object($settings) ) { |
|
| 57 | + set_transient($this->option_name, $settings); |
|
| 58 | + return $settings; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // If unserializing didn't work |
|
| 62 | + if ( $settings ) { //workaround for W3 total cache conflict |
|
| 63 | + $settings = unserialize(serialize($settings)); |
|
| 64 | + } else { |
|
| 65 | + $settings = $this; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + update_option($this->option_name, $settings); |
|
| 69 | + set_transient($this->option_name, $settings); |
|
| 70 | + |
|
| 71 | + return $settings; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @return array |
|
| 76 | + */ |
|
| 77 | 77 | public function default_options() { |
| 78 | - return array( |
|
| 79 | - 'menu' => apply_filters( 'frm_default_menu', __( 'Forms', 'formidable' ) ), |
|
| 80 | - 'mu_menu' => 0, |
|
| 81 | - 'preview_page_id' => 0, |
|
| 82 | - 'use_html' => true, |
|
| 83 | - 'jquery_css' => false, |
|
| 84 | - 'accordion_js' => false, |
|
| 78 | + return array( |
|
| 79 | + 'menu' => apply_filters( 'frm_default_menu', __( 'Forms', 'formidable' ) ), |
|
| 80 | + 'mu_menu' => 0, |
|
| 81 | + 'preview_page_id' => 0, |
|
| 82 | + 'use_html' => true, |
|
| 83 | + 'jquery_css' => false, |
|
| 84 | + 'accordion_js' => false, |
|
| 85 | 85 | |
| 86 | 86 | 're_multi' => 0, |
| 87 | 87 | |
| 88 | - 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ), |
|
| 89 | - 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ), |
|
| 90 | - 'unique_msg' => __( 'This value must be unique.', 'formidable' ), |
|
| 91 | - 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ), |
|
| 92 | - 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ), |
|
| 93 | - 'submit_value' => __( 'Submit', 'formidable' ), |
|
| 94 | - 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ), |
|
| 95 | - 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ), |
|
| 88 | + 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ), |
|
| 89 | + 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ), |
|
| 90 | + 'unique_msg' => __( 'This value must be unique.', 'formidable' ), |
|
| 91 | + 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ), |
|
| 92 | + 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ), |
|
| 93 | + 'submit_value' => __( 'Submit', 'formidable' ), |
|
| 94 | + 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ), |
|
| 95 | + 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ), |
|
| 96 | 96 | |
| 97 | - 'email_to' => '[admin_email]', |
|
| 98 | - ); |
|
| 99 | - } |
|
| 97 | + 'email_to' => '[admin_email]', |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | private function set_default_options() { |
| 102 | - $this->fill_recaptcha_settings(); |
|
| 103 | - |
|
| 104 | - if ( ! isset($this->load_style) ) { |
|
| 105 | - if ( ! isset($this->custom_style) ) { |
|
| 106 | - $this->custom_style = true; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $this->load_style = 'all'; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - $this->fill_with_defaults(); |
|
| 113 | - |
|
| 114 | - if ( is_multisite() && is_admin() ) { |
|
| 115 | - $mu_menu = get_site_option('frm_admin_menu_name'); |
|
| 116 | - if ( $mu_menu && ! empty($mu_menu) ) { |
|
| 117 | - $this->menu = $mu_menu; |
|
| 118 | - $this->mu_menu = 1; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $frm_roles = FrmAppHelper::frm_capabilities('pro'); |
|
| 123 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 124 | - if ( ! isset($this->$frm_role) ) { |
|
| 125 | - $this->$frm_role = 'administrator'; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 102 | + $this->fill_recaptcha_settings(); |
|
| 103 | + |
|
| 104 | + if ( ! isset($this->load_style) ) { |
|
| 105 | + if ( ! isset($this->custom_style) ) { |
|
| 106 | + $this->custom_style = true; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $this->load_style = 'all'; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + $this->fill_with_defaults(); |
|
| 113 | + |
|
| 114 | + if ( is_multisite() && is_admin() ) { |
|
| 115 | + $mu_menu = get_site_option('frm_admin_menu_name'); |
|
| 116 | + if ( $mu_menu && ! empty($mu_menu) ) { |
|
| 117 | + $this->menu = $mu_menu; |
|
| 118 | + $this->mu_menu = 1; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $frm_roles = FrmAppHelper::frm_capabilities('pro'); |
|
| 123 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 124 | + if ( ! isset($this->$frm_role) ) { |
|
| 125 | + $this->$frm_role = 'administrator'; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | public function fill_with_defaults( $params = array() ) { |
| 131 | - $settings = $this->default_options(); |
|
| 131 | + $settings = $this->default_options(); |
|
| 132 | 132 | |
| 133 | - foreach ( $settings as $setting => $default ) { |
|
| 133 | + foreach ( $settings as $setting => $default ) { |
|
| 134 | 134 | if ( isset( $params[ 'frm_' . $setting ] ) ) { |
| 135 | 135 | $this->{$setting} = $params[ 'frm_' . $setting ]; |
| 136 | - } else if ( ! isset($this->{$setting}) ) { |
|
| 137 | - $this->{$setting} = $default; |
|
| 138 | - } |
|
| 136 | + } else if ( ! isset($this->{$setting}) ) { |
|
| 137 | + $this->{$setting} = $default; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | if ( $setting == 'menu' && empty( $this->{$setting} ) ) { |
| 141 | 141 | $this->{$setting} = $default; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - unset($setting, $default); |
|
| 145 | - } |
|
| 146 | - } |
|
| 144 | + unset($setting, $default); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - private function fill_recaptcha_settings() { |
|
| 149 | - $privkey = ''; |
|
| 148 | + private function fill_recaptcha_settings() { |
|
| 149 | + $privkey = ''; |
|
| 150 | 150 | $re_lang = ''; |
| 151 | 151 | |
| 152 | - if ( ! isset($this->pubkey) ) { |
|
| 153 | - // get the options from the database |
|
| 154 | - $recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha'); |
|
| 155 | - $this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : ''; |
|
| 156 | - $privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey; |
|
| 157 | - $re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang; |
|
| 158 | - } |
|
| 152 | + if ( ! isset($this->pubkey) ) { |
|
| 153 | + // get the options from the database |
|
| 154 | + $recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha'); |
|
| 155 | + $this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : ''; |
|
| 156 | + $privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey; |
|
| 157 | + $re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - if ( ! isset($this->re_msg) || empty($this->re_msg) ) { |
|
| 161 | - $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' ); |
|
| 162 | - } |
|
| 160 | + if ( ! isset($this->re_msg) || empty($this->re_msg) ) { |
|
| 161 | + $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' ); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - if ( ! isset($this->privkey) ) { |
|
| 165 | - $this->privkey = $privkey; |
|
| 166 | - } |
|
| 164 | + if ( ! isset($this->privkey) ) { |
|
| 165 | + $this->privkey = $privkey; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - if ( ! isset($this->re_lang) ) { |
|
| 169 | - $this->re_lang = $re_lang; |
|
| 170 | - } |
|
| 171 | - } |
|
| 168 | + if ( ! isset($this->re_lang) ) { |
|
| 169 | + $this->re_lang = $re_lang; |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - public function validate( $params, $errors ) { |
|
| 174 | - return apply_filters( 'frm_validate_settings', $errors, $params ); |
|
| 175 | - } |
|
| 173 | + public function validate( $params, $errors ) { |
|
| 174 | + return apply_filters( 'frm_validate_settings', $errors, $params ); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | 177 | public function update( $params ) { |
| 178 | - $this->fill_with_defaults($params); |
|
| 179 | - $this->update_settings($params); |
|
| 178 | + $this->fill_with_defaults($params); |
|
| 179 | + $this->update_settings($params); |
|
| 180 | 180 | |
| 181 | - if ( $this->mu_menu ) { |
|
| 182 | - update_site_option('frm_admin_menu_name', $this->menu); |
|
| 183 | - } else if ( current_user_can('administrator') ) { |
|
| 184 | - update_site_option('frm_admin_menu_name', false); |
|
| 185 | - } |
|
| 181 | + if ( $this->mu_menu ) { |
|
| 182 | + update_site_option('frm_admin_menu_name', $this->menu); |
|
| 183 | + } else if ( current_user_can('administrator') ) { |
|
| 184 | + update_site_option('frm_admin_menu_name', false); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - $this->update_roles($params); |
|
| 187 | + $this->update_roles($params); |
|
| 188 | 188 | |
| 189 | - do_action( 'frm_update_settings', $params ); |
|
| 190 | - } |
|
| 189 | + do_action( 'frm_update_settings', $params ); |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | 192 | private function update_settings( $params ) { |
| 193 | - $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0; |
|
| 193 | + $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0; |
|
| 194 | 194 | |
| 195 | - $this->pubkey = trim($params['frm_pubkey']); |
|
| 196 | - $this->privkey = $params['frm_privkey']; |
|
| 197 | - $this->re_lang = $params['frm_re_lang']; |
|
| 195 | + $this->pubkey = trim($params['frm_pubkey']); |
|
| 196 | + $this->privkey = $params['frm_privkey']; |
|
| 197 | + $this->re_lang = $params['frm_re_lang']; |
|
| 198 | 198 | $this->re_multi = isset( $params['frm_re_multi'] ) ? $params['frm_re_multi'] : 0; |
| 199 | 199 | |
| 200 | - $this->load_style = $params['frm_load_style']; |
|
| 201 | - $this->preview_page_id = (int) $params['frm-preview-page-id']; |
|
| 200 | + $this->load_style = $params['frm_load_style']; |
|
| 201 | + $this->preview_page_id = (int) $params['frm-preview-page-id']; |
|
| 202 | 202 | |
| 203 | - $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0; |
|
| 204 | - //$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0; |
|
| 203 | + $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0; |
|
| 204 | + //$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0; |
|
| 205 | 205 | $this->jquery_css = isset( $params['frm_jquery_css'] ) ? absint( $params['frm_jquery_css'] ) : 0; |
| 206 | 206 | $this->accordion_js = isset( $params['frm_accordion_js'] ) ? absint( $params['frm_accordion_js'] ) : 0; |
| 207 | - } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | 209 | private function update_roles( $params ) { |
| 210 | - global $wp_roles; |
|
| 210 | + global $wp_roles; |
|
| 211 | 211 | |
| 212 | - $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 213 | - $roles = get_editable_roles(); |
|
| 214 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 215 | - $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' ); |
|
| 212 | + $frm_roles = FrmAppHelper::frm_capabilities(); |
|
| 213 | + $roles = get_editable_roles(); |
|
| 214 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 215 | + $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' ); |
|
| 216 | 216 | |
| 217 | - // Make sure administrators always have permissions |
|
| 218 | - if ( ! in_array( 'administrator', $this->$frm_role ) ) { |
|
| 217 | + // Make sure administrators always have permissions |
|
| 218 | + if ( ! in_array( 'administrator', $this->$frm_role ) ) { |
|
| 219 | 219 | array_push( $this->$frm_role, 'administrator' ); |
| 220 | - } |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - foreach ( $roles as $role => $details ) { |
|
| 223 | - if ( in_array($role, $this->$frm_role) ) { |
|
| 224 | - $wp_roles->add_cap( $role, $frm_role ); |
|
| 225 | - } else { |
|
| 226 | - $wp_roles->remove_cap( $role, $frm_role ); |
|
| 227 | - } |
|
| 228 | - } |
|
| 222 | + foreach ( $roles as $role => $details ) { |
|
| 223 | + if ( in_array($role, $this->$frm_role) ) { |
|
| 224 | + $wp_roles->add_cap( $role, $frm_role ); |
|
| 225 | + } else { |
|
| 226 | + $wp_roles->remove_cap( $role, $frm_role ); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | 229 | } |
| 230 | - } |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | 232 | public function store() { |
| 233 | - // Save the posted value in the database |
|
| 233 | + // Save the posted value in the database |
|
| 234 | 234 | |
| 235 | - update_option('frm_options', $this); |
|
| 235 | + update_option('frm_options', $this); |
|
| 236 | 236 | |
| 237 | - delete_transient('frm_options'); |
|
| 238 | - set_transient('frm_options', $this); |
|
| 237 | + delete_transient('frm_options'); |
|
| 238 | + set_transient('frm_options', $this); |
|
| 239 | 239 | |
| 240 | - do_action( 'frm_store_settings' ); |
|
| 241 | - } |
|
| 240 | + do_action( 'frm_store_settings' ); |
|
| 241 | + } |
|
| 242 | 242 | } |