@@ -1,36 +1,36 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class FrmDb { |
| 4 | - public $fields; |
|
| 5 | - public $forms; |
|
| 6 | - public $entries; |
|
| 7 | - public $entry_metas; |
|
| 8 | - |
|
| 9 | - public function __construct() { |
|
| 10 | - if ( ! defined('ABSPATH') ) { |
|
| 11 | - die('You are not allowed to call this page directly.'); |
|
| 12 | - } |
|
| 4 | + public $fields; |
|
| 5 | + public $forms; |
|
| 6 | + public $entries; |
|
| 7 | + public $entry_metas; |
|
| 8 | + |
|
| 9 | + public function __construct() { |
|
| 10 | + if ( ! defined('ABSPATH') ) { |
|
| 11 | + die('You are not allowed to call this page directly.'); |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | 14 | _deprecated_function( __METHOD__, '2.06', 'FrmMigrate' ); |
| 15 | - global $wpdb; |
|
| 16 | - $this->fields = $wpdb->prefix . 'frm_fields'; |
|
| 17 | - $this->forms = $wpdb->prefix . 'frm_forms'; |
|
| 18 | - $this->entries = $wpdb->prefix . 'frm_items'; |
|
| 19 | - $this->entry_metas = $wpdb->prefix . 'frm_item_metas'; |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Change array into format $wpdb->prepare can use |
|
| 15 | + global $wpdb; |
|
| 16 | + $this->fields = $wpdb->prefix . 'frm_fields'; |
|
| 17 | + $this->forms = $wpdb->prefix . 'frm_forms'; |
|
| 18 | + $this->entries = $wpdb->prefix . 'frm_items'; |
|
| 19 | + $this->entry_metas = $wpdb->prefix . 'frm_item_metas'; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Change array into format $wpdb->prepare can use |
|
| 24 | 24 | * |
| 25 | 25 | * @param array $args |
| 26 | 26 | * @param string $starts_with |
| 27 | - */ |
|
| 28 | - public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) { |
|
| 29 | - if ( empty($args) ) { |
|
| 27 | + */ |
|
| 28 | + public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) { |
|
| 29 | + if ( empty($args) ) { |
|
| 30 | 30 | // add an arg to prevent prepare from failing |
| 31 | 31 | $args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) ); |
| 32 | 32 | return; |
| 33 | - } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | $where = ''; |
| 36 | 36 | $values = array(); |
@@ -41,64 +41,64 @@ discard block |
||
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | $args = compact( 'where', 'values' ); |
| 44 | - } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | + /** |
|
| 47 | 47 | * @param array $args |
| 48 | - * @param string $base_where |
|
| 49 | - * @param string $where |
|
| 48 | + * @param string $base_where |
|
| 49 | + * @param string $where |
|
| 50 | 50 | * @param array $values |
| 51 | - */ |
|
| 52 | - public static function parse_where_from_array( $args, $base_where, &$where, &$values ) { |
|
| 53 | - $condition = ' AND'; |
|
| 54 | - if ( isset( $args['or'] ) ) { |
|
| 55 | - $condition = ' OR'; |
|
| 56 | - unset( $args['or'] ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - foreach ( $args as $key => $value ) { |
|
| 60 | - $where .= empty( $where ) ? $base_where : $condition; |
|
| 61 | - $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) ); |
|
| 62 | - if ( is_numeric( $key ) || $array_inc_null ) { |
|
| 63 | - $where .= ' ( '; |
|
| 64 | - $nested_where = ''; |
|
| 65 | - if ( $array_inc_null ) { |
|
| 66 | - foreach ( $value as $val ) { |
|
| 67 | - self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values ); |
|
| 68 | - } |
|
| 69 | - } else { |
|
| 70 | - self::parse_where_from_array( $value, '', $nested_where, $values ); |
|
| 71 | - } |
|
| 72 | - $where .= $nested_where; |
|
| 73 | - $where .= ' ) '; |
|
| 74 | - } else { |
|
| 75 | - self::interpret_array_to_sql( $key, $value, $where, $values ); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param string $key |
|
| 51 | + */ |
|
| 52 | + public static function parse_where_from_array( $args, $base_where, &$where, &$values ) { |
|
| 53 | + $condition = ' AND'; |
|
| 54 | + if ( isset( $args['or'] ) ) { |
|
| 55 | + $condition = ' OR'; |
|
| 56 | + unset( $args['or'] ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + foreach ( $args as $key => $value ) { |
|
| 60 | + $where .= empty( $where ) ? $base_where : $condition; |
|
| 61 | + $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) ); |
|
| 62 | + if ( is_numeric( $key ) || $array_inc_null ) { |
|
| 63 | + $where .= ' ( '; |
|
| 64 | + $nested_where = ''; |
|
| 65 | + if ( $array_inc_null ) { |
|
| 66 | + foreach ( $value as $val ) { |
|
| 67 | + self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values ); |
|
| 68 | + } |
|
| 69 | + } else { |
|
| 70 | + self::parse_where_from_array( $value, '', $nested_where, $values ); |
|
| 71 | + } |
|
| 72 | + $where .= $nested_where; |
|
| 73 | + $where .= ' ) '; |
|
| 74 | + } else { |
|
| 75 | + self::interpret_array_to_sql( $key, $value, $where, $values ); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param string $key |
|
| 82 | 82 | * @param string|array $value |
| 83 | - * @param string $where |
|
| 83 | + * @param string $where |
|
| 84 | 84 | * @param array $values |
| 85 | - */ |
|
| 86 | - private static function interpret_array_to_sql( $key, $value, &$where, &$values ) { |
|
| 85 | + */ |
|
| 86 | + private static function interpret_array_to_sql( $key, $value, &$where, &$values ) { |
|
| 87 | 87 | $key = trim( $key ); |
| 88 | 88 | |
| 89 | 89 | if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) { |
| 90 | - $k = explode(' ', $key); |
|
| 91 | - $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key ); |
|
| 92 | - $values[] = '%Y-%m-%d %H:%i:%s'; |
|
| 93 | - } else { |
|
| 90 | + $k = explode(' ', $key); |
|
| 91 | + $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key ); |
|
| 92 | + $values[] = '%Y-%m-%d %H:%i:%s'; |
|
| 93 | + } else { |
|
| 94 | 94 | $where .= ' ' . $key; |
| 95 | - } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | $lowercase_key = explode( ' ', strtolower( $key ) ); |
| 98 | 98 | $lowercase_key = end( $lowercase_key ); |
| 99 | 99 | |
| 100 | - if ( is_array( $value ) ) { |
|
| 101 | - // translate array of values to "in" |
|
| 100 | + if ( is_array( $value ) ) { |
|
| 101 | + // translate array of values to "in" |
|
| 102 | 102 | if ( strpos( $lowercase_key, 'like' ) !== false ) { |
| 103 | 103 | $where = preg_replace('/' . $key . '$/', '', $where); |
| 104 | 104 | $where .= '('; |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | $where .= ' in (' . self::prepare_array_values( $value, '%s' ) . ')'; |
| 117 | 117 | $values = array_merge( $values, $value ); |
| 118 | 118 | } |
| 119 | - } else if ( strpos( $lowercase_key, 'like' ) !== false ) { |
|
| 119 | + } else if ( strpos( $lowercase_key, 'like' ) !== false ) { |
|
| 120 | 120 | /** |
| 121 | 121 | * Allow string to start or end with the value |
| 122 | 122 | * If the key is like% then skip the first % for starts with |
@@ -136,9 +136,9 @@ discard block |
||
| 136 | 136 | $where .= ' %s'; |
| 137 | 137 | $values[] = $start . self::esc_like( $value ) . $end; |
| 138 | 138 | |
| 139 | - } else if ( $value === null ) { |
|
| 140 | - $where .= ' IS NULL'; |
|
| 141 | - } else { |
|
| 139 | + } else if ( $value === null ) { |
|
| 140 | + $where .= ' IS NULL'; |
|
| 141 | + } else { |
|
| 142 | 142 | // allow a - to prevent = from being added |
| 143 | 143 | if ( substr( $key, -1 ) == '-' ) { |
| 144 | 144 | $where = rtrim( $where, '-' ); |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | self::add_query_placeholder( $key, $value, $where ); |
| 150 | 150 | |
| 151 | - $values[] = $value; |
|
| 152 | - } |
|
| 153 | - } |
|
| 151 | + $values[] = $value; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | 155 | /** |
| 156 | 156 | * Add %d, or %s to query |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * @param int|string $value |
| 161 | 161 | * @param string $where |
| 162 | 162 | */ |
| 163 | - private static function add_query_placeholder( $key, $value, &$where ) { |
|
| 163 | + private static function add_query_placeholder( $key, $value, &$where ) { |
|
| 164 | 164 | if ( is_numeric( $value ) && ( strpos( $key, 'meta_value' ) === false || strpos( $key, '+0' ) !== false ) ) { |
| 165 | 165 | $where .= '%d'; |
| 166 | 166 | } else { |
@@ -168,16 +168,16 @@ discard block |
||
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * @param string $table |
|
| 171 | + /** |
|
| 172 | + * @param string $table |
|
| 173 | 173 | * @param array $where |
| 174 | 174 | * @param array $args |
| 175 | 175 | * @return int |
| 176 | - */ |
|
| 177 | - public static function get_count( $table, $where = array(), $args = array() ) { |
|
| 178 | - $count = self::get_var( $table, $where, 'COUNT(*)', $args ); |
|
| 179 | - return $count; |
|
| 180 | - } |
|
| 176 | + */ |
|
| 177 | + public static function get_count( $table, $where = array(), $args = array() ) { |
|
| 178 | + $count = self::get_var( $table, $where, 'COUNT(*)', $args ); |
|
| 179 | + return $count; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | 182 | /** |
| 183 | 183 | * @param string $table |
@@ -188,17 +188,17 @@ discard block |
||
| 188 | 188 | * @param string $type |
| 189 | 189 | * @return array|null|string|object |
| 190 | 190 | */ |
| 191 | - public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) { |
|
| 192 | - $group = ''; |
|
| 193 | - self::get_group_and_table_name( $table, $group ); |
|
| 191 | + public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) { |
|
| 192 | + $group = ''; |
|
| 193 | + self::get_group_and_table_name( $table, $group ); |
|
| 194 | 194 | self::convert_options_to_array( $args, '', $limit ); |
| 195 | 195 | |
| 196 | 196 | $query = self::generate_query_string_from_pieces( $field, $table, $where, $args ); |
| 197 | 197 | |
| 198 | 198 | $cache_key = self::generate_cache_key( $where, $args, $field, $type ); |
| 199 | 199 | $results = self::check_cache( $cache_key, $group, $query, 'get_' . $type ); |
| 200 | - return $results; |
|
| 201 | - } |
|
| 200 | + return $results; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | 203 | /** |
| 204 | 204 | * Generate a cache key from the where query, field, type, and other arguments |
@@ -224,44 +224,44 @@ discard block |
||
| 224 | 224 | return $cache_key; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * @param string $table |
|
| 229 | - * @param array $where |
|
| 227 | + /** |
|
| 228 | + * @param string $table |
|
| 229 | + * @param array $where |
|
| 230 | 230 | * @param string $field |
| 231 | 231 | * @param array $args |
| 232 | 232 | * @param string $limit |
| 233 | 233 | * @return mixed |
| 234 | - */ |
|
| 235 | - public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) { |
|
| 236 | - return self::get_var( $table, $where, $field, $args, $limit, 'col' ); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * @since 2.0 |
|
| 241 | - * @param string $table |
|
| 234 | + */ |
|
| 235 | + public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) { |
|
| 236 | + return self::get_var( $table, $where, $field, $args, $limit, 'col' ); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * @since 2.0 |
|
| 241 | + * @param string $table |
|
| 242 | 242 | * @param array $where |
| 243 | 243 | * @param string $fields |
| 244 | 244 | * @param array $args |
| 245 | 245 | * @return mixed |
| 246 | - */ |
|
| 247 | - public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) { |
|
| 248 | - $args['limit'] = 1; |
|
| 249 | - return self::get_var( $table, $where, $fields, $args, '', 'row' ); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Prepare a key/value array before DB call |
|
| 246 | + */ |
|
| 247 | + public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) { |
|
| 248 | + $args['limit'] = 1; |
|
| 249 | + return self::get_var( $table, $where, $fields, $args, '', 'row' ); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Prepare a key/value array before DB call |
|
| 254 | 254 | * |
| 255 | - * @since 2.0 |
|
| 256 | - * @param string $table |
|
| 255 | + * @since 2.0 |
|
| 256 | + * @param string $table |
|
| 257 | 257 | * @param array $where |
| 258 | 258 | * @param string $fields |
| 259 | 259 | * @param array $args |
| 260 | 260 | * @return mixed |
| 261 | - */ |
|
| 262 | - public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) { |
|
| 263 | - return self::get_var( $table, $where, $fields, $args, '', 'results' ); |
|
| 264 | - } |
|
| 261 | + */ |
|
| 262 | + public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) { |
|
| 263 | + return self::get_var( $table, $where, $fields, $args, '', 'results' ); |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | /** |
| 267 | 267 | * Check for like, not like, in, not in, =, !=, >, <, <=, >= |
@@ -298,59 +298,59 @@ discard block |
||
| 298 | 298 | return ''; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join |
|
| 303 | - * Also add the wpdb->prefix to the table if it's missing |
|
| 304 | - * |
|
| 305 | - * @param string $table |
|
| 306 | - * @param string $group |
|
| 307 | - */ |
|
| 308 | - private static function get_group_and_table_name( &$table, &$group ) { |
|
| 301 | + /** |
|
| 302 | + * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join |
|
| 303 | + * Also add the wpdb->prefix to the table if it's missing |
|
| 304 | + * |
|
| 305 | + * @param string $table |
|
| 306 | + * @param string $group |
|
| 307 | + */ |
|
| 308 | + private static function get_group_and_table_name( &$table, &$group ) { |
|
| 309 | 309 | global $wpdb, $wpmuBaseTablePrefix; |
| 310 | 310 | |
| 311 | - $table_parts = explode(' ', $table); |
|
| 312 | - $group = reset($table_parts); |
|
| 313 | - $group = str_replace( $wpdb->prefix, '', $group ); |
|
| 311 | + $table_parts = explode(' ', $table); |
|
| 312 | + $group = reset($table_parts); |
|
| 313 | + $group = str_replace( $wpdb->prefix, '', $group ); |
|
| 314 | 314 | |
| 315 | 315 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix; |
| 316 | 316 | $group = str_replace( $prefix, '', $group ); |
| 317 | 317 | |
| 318 | - if ( $group == $table ) { |
|
| 319 | - $table = $wpdb->prefix . $table; |
|
| 320 | - } |
|
| 318 | + if ( $group == $table ) { |
|
| 319 | + $table = $wpdb->prefix . $table; |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | 322 | // switch to singular group name |
| 323 | 323 | $group = rtrim( $group, 's' ); |
| 324 | - } |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) { |
|
| 327 | - if ( ! is_array($args) ) { |
|
| 326 | + private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) { |
|
| 327 | + if ( ! is_array($args) ) { |
|
| 328 | 328 | $args = array( 'order_by' => $args ); |
| 329 | - } |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - if ( ! empty( $order_by ) ) { |
|
| 332 | - $args['order_by'] = $order_by; |
|
| 333 | - } |
|
| 331 | + if ( ! empty( $order_by ) ) { |
|
| 332 | + $args['order_by'] = $order_by; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - if ( ! empty( $limit ) ) { |
|
| 336 | - $args['limit'] = $limit; |
|
| 337 | - } |
|
| 335 | + if ( ! empty( $limit ) ) { |
|
| 336 | + $args['limit'] = $limit; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - $temp_args = $args; |
|
| 340 | - foreach ( $temp_args as $k => $v ) { |
|
| 341 | - if ( $v == '' ) { |
|
| 339 | + $temp_args = $args; |
|
| 340 | + foreach ( $temp_args as $k => $v ) { |
|
| 341 | + if ( $v == '' ) { |
|
| 342 | 342 | unset( $args[ $k ] ); |
| 343 | - continue; |
|
| 344 | - } |
|
| 343 | + continue; |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | - if ( $k == 'limit' ) { |
|
| 346 | + if ( $k == 'limit' ) { |
|
| 347 | 347 | $args[ $k ] = self::esc_limit( $v ); |
| 348 | - } |
|
| 349 | - $db_name = strtoupper( str_replace( '_', ' ', $k ) ); |
|
| 350 | - if ( strpos( $v, $db_name ) === false ) { |
|
| 348 | + } |
|
| 349 | + $db_name = strtoupper( str_replace( '_', ' ', $k ) ); |
|
| 350 | + if ( strpos( $v, $db_name ) === false ) { |
|
| 351 | 351 | $args[ $k ] = $db_name . ' ' . $v; |
| 352 | - } |
|
| 353 | - } |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | 355 | // Make sure LIMIT is the last argument |
| 356 | 356 | if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) { |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | unset( $args['limit'] ); |
| 359 | 359 | $args['limit'] = $temp_limit; |
| 360 | 360 | } |
| 361 | - } |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | 363 | /** |
| 364 | 364 | * Get the associative array results for the given columns, table, and where query |
@@ -411,62 +411,62 @@ discard block |
||
| 411 | 411 | return $query; |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - /** |
|
| 415 | - * Added for < WP 4.0 compatability |
|
| 416 | - * |
|
| 417 | - * @since 2.06 |
|
| 418 | - * |
|
| 419 | - * @param string $term The value to escape |
|
| 420 | - * @return string The escaped value |
|
| 421 | - */ |
|
| 414 | + /** |
|
| 415 | + * Added for < WP 4.0 compatability |
|
| 416 | + * |
|
| 417 | + * @since 2.06 |
|
| 418 | + * |
|
| 419 | + * @param string $term The value to escape |
|
| 420 | + * @return string The escaped value |
|
| 421 | + */ |
|
| 422 | 422 | public static function esc_like( $term ) { |
| 423 | - global $wpdb; |
|
| 424 | - if ( method_exists( $wpdb, 'esc_like' ) ) { |
|
| 423 | + global $wpdb; |
|
| 424 | + if ( method_exists( $wpdb, 'esc_like' ) ) { |
|
| 425 | 425 | // WP 4.0 |
| 426 | - $term = $wpdb->esc_like( $term ); |
|
| 427 | - } else { |
|
| 428 | - $term = like_escape( $term ); |
|
| 429 | - } |
|
| 426 | + $term = $wpdb->esc_like( $term ); |
|
| 427 | + } else { |
|
| 428 | + $term = like_escape( $term ); |
|
| 429 | + } |
|
| 430 | 430 | |
| 431 | - return $term; |
|
| 432 | - } |
|
| 431 | + return $term; |
|
| 432 | + } |
|
| 433 | 433 | |
| 434 | - /** |
|
| 434 | + /** |
|
| 435 | 435 | * @since 2.06 |
| 436 | - * @param string $order_query |
|
| 437 | - */ |
|
| 436 | + * @param string $order_query |
|
| 437 | + */ |
|
| 438 | 438 | public static function esc_order( $order_query ) { |
| 439 | - if ( empty( $order_query ) ) { |
|
| 440 | - return ''; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - // remove ORDER BY before santizing |
|
| 444 | - $order_query = strtolower( $order_query ); |
|
| 445 | - if ( strpos( $order_query, 'order by' ) !== false ) { |
|
| 446 | - $order_query = str_replace( 'order by', '', $order_query ); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - $order_query = explode( ' ', trim( $order_query ) ); |
|
| 450 | - |
|
| 451 | - $order_fields = array( |
|
| 452 | - 'id', 'form_key', 'name', 'description', |
|
| 453 | - 'parent_form_id', 'logged_in', 'is_template', |
|
| 454 | - 'default_template', 'status', 'created_at', |
|
| 455 | - ); |
|
| 456 | - |
|
| 457 | - $order = trim( trim( reset( $order_query ), ',' ) ); |
|
| 458 | - if ( ! in_array( $order, $order_fields ) ) { |
|
| 459 | - return ''; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - $order_by = ''; |
|
| 463 | - if ( count( $order_query ) > 1 ) { |
|
| 439 | + if ( empty( $order_query ) ) { |
|
| 440 | + return ''; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + // remove ORDER BY before santizing |
|
| 444 | + $order_query = strtolower( $order_query ); |
|
| 445 | + if ( strpos( $order_query, 'order by' ) !== false ) { |
|
| 446 | + $order_query = str_replace( 'order by', '', $order_query ); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + $order_query = explode( ' ', trim( $order_query ) ); |
|
| 450 | + |
|
| 451 | + $order_fields = array( |
|
| 452 | + 'id', 'form_key', 'name', 'description', |
|
| 453 | + 'parent_form_id', 'logged_in', 'is_template', |
|
| 454 | + 'default_template', 'status', 'created_at', |
|
| 455 | + ); |
|
| 456 | + |
|
| 457 | + $order = trim( trim( reset( $order_query ), ',' ) ); |
|
| 458 | + if ( ! in_array( $order, $order_fields ) ) { |
|
| 459 | + return ''; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + $order_by = ''; |
|
| 463 | + if ( count( $order_query ) > 1 ) { |
|
| 464 | 464 | $order_by = end( $order_query ); |
| 465 | 465 | self::esc_order_by( $order_by ); |
| 466 | - } |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | 468 | return ' ORDER BY ' . $order . ' ' . $order_by; |
| 469 | - } |
|
| 469 | + } |
|
| 470 | 470 | |
| 471 | 471 | /** |
| 472 | 472 | * Make sure this is ordering by either ASC or DESC |
@@ -504,18 +504,18 @@ discard block |
||
| 504 | 504 | return ' LIMIT ' . $limit; |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | - /** |
|
| 508 | - * Get an array of values ready to go through $wpdb->prepare |
|
| 509 | - * @since 2.06 |
|
| 510 | - */ |
|
| 507 | + /** |
|
| 508 | + * Get an array of values ready to go through $wpdb->prepare |
|
| 509 | + * @since 2.06 |
|
| 510 | + */ |
|
| 511 | 511 | public static function prepare_array_values( $array, $type = '%s' ) { |
| 512 | 512 | $placeholders = array_fill( 0, count( $array ), $type ); |
| 513 | 513 | return implode( ', ', $placeholders ); |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - /** |
|
| 517 | - * @since 2.06 |
|
| 518 | - */ |
|
| 516 | + /** |
|
| 517 | + * @since 2.06 |
|
| 518 | + */ |
|
| 519 | 519 | public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) { |
| 520 | 520 | if ( empty( $where ) ) { |
| 521 | 521 | return ''; |
@@ -578,17 +578,17 @@ discard block |
||
| 578 | 578 | return $post; |
| 579 | 579 | } |
| 580 | 580 | |
| 581 | - /** |
|
| 582 | - * Check cache before fetching values and saving to cache |
|
| 583 | - * |
|
| 584 | - * @since 2.06 |
|
| 585 | - * |
|
| 586 | - * @param string $cache_key The unique name for this cache |
|
| 587 | - * @param string $group The name of the cache group |
|
| 588 | - * @param string $query If blank, don't run a db call |
|
| 589 | - * @param string $type The wpdb function to use with this query |
|
| 590 | - * @return mixed $results The cache or query results |
|
| 591 | - */ |
|
| 581 | + /** |
|
| 582 | + * Check cache before fetching values and saving to cache |
|
| 583 | + * |
|
| 584 | + * @since 2.06 |
|
| 585 | + * |
|
| 586 | + * @param string $cache_key The unique name for this cache |
|
| 587 | + * @param string $group The name of the cache group |
|
| 588 | + * @param string $query If blank, don't run a db call |
|
| 589 | + * @param string $type The wpdb function to use with this query |
|
| 590 | + * @return mixed $results The cache or query results |
|
| 591 | + */ |
|
| 592 | 592 | public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) { |
| 593 | 593 | $results = wp_cache_get( $cache_key, $group ); |
| 594 | 594 | if ( ! FrmAppHelper::is_empty_value( $results, false ) || empty( $query ) ) { |
@@ -643,22 +643,22 @@ discard block |
||
| 643 | 643 | return $cached; |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | - /** |
|
| 647 | - * @since 2.06 |
|
| 648 | - * @param string $cache_key |
|
| 649 | - */ |
|
| 646 | + /** |
|
| 647 | + * @since 2.06 |
|
| 648 | + * @param string $cache_key |
|
| 649 | + */ |
|
| 650 | 650 | public static function delete_cache_and_transient( $cache_key, $group = 'default' ) { |
| 651 | 651 | delete_transient( $cache_key ); |
| 652 | 652 | wp_cache_delete( $cache_key, $group ); |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | - /** |
|
| 656 | - * Delete all caching in a single group |
|
| 657 | - * |
|
| 658 | - * @since 2.06 |
|
| 659 | - * |
|
| 660 | - * @param string $group The name of the cache group |
|
| 661 | - */ |
|
| 655 | + /** |
|
| 656 | + * Delete all caching in a single group |
|
| 657 | + * |
|
| 658 | + * @since 2.06 |
|
| 659 | + * |
|
| 660 | + * @param string $group The name of the cache group |
|
| 661 | + */ |
|
| 662 | 662 | public static function cache_delete_group( $group ) { |
| 663 | 663 | $cached_keys = self::get_group_cached_keys( $group ); |
| 664 | 664 | |
@@ -12,50 +12,50 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | public static $plug_version = '2.05.05'; |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @since 1.07.02 |
|
| 17 | - * |
|
| 18 | - * @param none |
|
| 19 | - * @return string The version of this plugin |
|
| 20 | - */ |
|
| 21 | - public static function plugin_version() { |
|
| 22 | - return self::$plug_version; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public static function plugin_folder() { |
|
| 26 | - return basename(self::plugin_path()); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public static function plugin_path() { |
|
| 30 | - return dirname(dirname(dirname(__FILE__))); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public static function plugin_url() { |
|
| 34 | - //prevously FRM_URL constant |
|
| 15 | + /** |
|
| 16 | + * @since 1.07.02 |
|
| 17 | + * |
|
| 18 | + * @param none |
|
| 19 | + * @return string The version of this plugin |
|
| 20 | + */ |
|
| 21 | + public static function plugin_version() { |
|
| 22 | + return self::$plug_version; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public static function plugin_folder() { |
|
| 26 | + return basename(self::plugin_path()); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public static function plugin_path() { |
|
| 30 | + return dirname(dirname(dirname(__FILE__))); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public static function plugin_url() { |
|
| 34 | + //prevously FRM_URL constant |
|
| 35 | 35 | return plugins_url( '', self::plugin_path() . '/formidable.php' ); |
| 36 | - } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | public static function relative_plugin_url() { |
| 39 | 39 | return str_replace( array( 'https:', 'http:' ), '', self::plugin_url() ); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return string Site URL |
|
| 44 | - */ |
|
| 45 | - public static function site_url() { |
|
| 46 | - return site_url(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Get the name of this site |
|
| 51 | - * Used for [sitename] shortcode |
|
| 52 | - * |
|
| 53 | - * @since 2.0 |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 56 | - public static function site_name() { |
|
| 57 | - return get_option('blogname'); |
|
| 58 | - } |
|
| 42 | + /** |
|
| 43 | + * @return string Site URL |
|
| 44 | + */ |
|
| 45 | + public static function site_url() { |
|
| 46 | + return site_url(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Get the name of this site |
|
| 51 | + * Used for [sitename] shortcode |
|
| 52 | + * |
|
| 53 | + * @since 2.0 |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | + public static function site_name() { |
|
| 57 | + return get_option('blogname'); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | public static function make_affiliate_url( $url ) { |
| 61 | 61 | $affiliate_id = self::get_affiliate(); |
@@ -70,21 +70,21 @@ discard block |
||
| 70 | 70 | return absint( apply_filters( 'frm_affiliate_id', 0 ) ); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Get the Formidable settings |
|
| 75 | - * |
|
| 76 | - * @since 2.0 |
|
| 77 | - * |
|
| 78 | - * @param None |
|
| 79 | - * @return FrmSettings $frm_setings |
|
| 80 | - */ |
|
| 81 | - public static function get_settings() { |
|
| 82 | - global $frm_settings; |
|
| 83 | - if ( empty($frm_settings) ) { |
|
| 84 | - $frm_settings = new FrmSettings(); |
|
| 85 | - } |
|
| 86 | - return $frm_settings; |
|
| 87 | - } |
|
| 73 | + /** |
|
| 74 | + * Get the Formidable settings |
|
| 75 | + * |
|
| 76 | + * @since 2.0 |
|
| 77 | + * |
|
| 78 | + * @param None |
|
| 79 | + * @return FrmSettings $frm_setings |
|
| 80 | + */ |
|
| 81 | + public static function get_settings() { |
|
| 82 | + global $frm_settings; |
|
| 83 | + if ( empty($frm_settings) ) { |
|
| 84 | + $frm_settings = new FrmSettings(); |
|
| 85 | + } |
|
| 86 | + return $frm_settings; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | public static function get_menu_name() { |
| 90 | 90 | $frm_settings = FrmAppHelper::get_settings(); |
@@ -99,62 +99,62 @@ discard block |
||
| 99 | 99 | return ! $frm_settings->no_ips; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Show a message in place of pro features |
|
| 104 | - * |
|
| 105 | - * @since 2.0 |
|
| 106 | - */ |
|
| 102 | + /** |
|
| 103 | + * Show a message in place of pro features |
|
| 104 | + * |
|
| 105 | + * @since 2.0 |
|
| 106 | + */ |
|
| 107 | 107 | public static function update_message() { |
| 108 | 108 | _deprecated_function( __FUNCTION__, '2.0.19' ); |
| 109 | - } |
|
| 110 | - |
|
| 111 | - public static function pro_is_installed() { |
|
| 112 | - return apply_filters('frm_pro_installed', false); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Check for certain page in Formidable settings |
|
| 117 | - * |
|
| 118 | - * @since 2.0 |
|
| 119 | - * |
|
| 120 | - * @param string $page The name of the page to check |
|
| 121 | - * @return boolean |
|
| 122 | - */ |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + public static function pro_is_installed() { |
|
| 112 | + return apply_filters('frm_pro_installed', false); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Check for certain page in Formidable settings |
|
| 117 | + * |
|
| 118 | + * @since 2.0 |
|
| 119 | + * |
|
| 120 | + * @param string $page The name of the page to check |
|
| 121 | + * @return boolean |
|
| 122 | + */ |
|
| 123 | 123 | public static function is_admin_page( $page = 'formidable' ) { |
| 124 | - global $pagenow; |
|
| 124 | + global $pagenow; |
|
| 125 | 125 | $get_page = self::simple_get( 'page', 'sanitize_title' ); |
| 126 | - if ( $pagenow ) { |
|
| 126 | + if ( $pagenow ) { |
|
| 127 | 127 | return $pagenow == 'admin.php' && $get_page == $page; |
| 128 | - } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | return is_admin() && $get_page == $page; |
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Check for the form preview page |
|
| 135 | - * |
|
| 136 | - * @since 2.0 |
|
| 137 | - * |
|
| 138 | - * @param None |
|
| 139 | - * @return boolean |
|
| 140 | - */ |
|
| 141 | - public static function is_preview_page() { |
|
| 142 | - global $pagenow; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Check for the form preview page |
|
| 135 | + * |
|
| 136 | + * @since 2.0 |
|
| 137 | + * |
|
| 138 | + * @param None |
|
| 139 | + * @return boolean |
|
| 140 | + */ |
|
| 141 | + public static function is_preview_page() { |
|
| 142 | + global $pagenow; |
|
| 143 | 143 | $action = FrmAppHelper::simple_get( 'action', 'sanitize_title' ); |
| 144 | 144 | return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview'; |
| 145 | - } |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Check for ajax except the form preview page |
|
| 149 | - * |
|
| 150 | - * @since 2.0 |
|
| 151 | - * |
|
| 152 | - * @param None |
|
| 153 | - * @return boolean |
|
| 154 | - */ |
|
| 155 | - public static function doing_ajax() { |
|
| 156 | - return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page(); |
|
| 157 | - } |
|
| 147 | + /** |
|
| 148 | + * Check for ajax except the form preview page |
|
| 149 | + * |
|
| 150 | + * @since 2.0 |
|
| 151 | + * |
|
| 152 | + * @param None |
|
| 153 | + * @return boolean |
|
| 154 | + */ |
|
| 155 | + public static function doing_ajax() { |
|
| 156 | + return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page(); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | 160 | * @since 2.0.8 |
@@ -164,102 +164,102 @@ discard block |
||
| 164 | 164 | return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching']; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Check if on an admin page |
|
| 169 | - * |
|
| 170 | - * @since 2.0 |
|
| 171 | - * |
|
| 172 | - * @param None |
|
| 173 | - * @return boolean |
|
| 174 | - */ |
|
| 175 | - public static function is_admin() { |
|
| 176 | - return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX ); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Check if value contains blank value or empty array |
|
| 181 | - * |
|
| 182 | - * @since 2.0 |
|
| 183 | - * @param mixed $value - value to check |
|
| 167 | + /** |
|
| 168 | + * Check if on an admin page |
|
| 169 | + * |
|
| 170 | + * @since 2.0 |
|
| 171 | + * |
|
| 172 | + * @param None |
|
| 173 | + * @return boolean |
|
| 174 | + */ |
|
| 175 | + public static function is_admin() { |
|
| 176 | + return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX ); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Check if value contains blank value or empty array |
|
| 181 | + * |
|
| 182 | + * @since 2.0 |
|
| 183 | + * @param mixed $value - value to check |
|
| 184 | 184 | * @param string |
| 185 | - * @return boolean |
|
| 186 | - */ |
|
| 187 | - public static function is_empty_value( $value, $empty = '' ) { |
|
| 188 | - return ( is_array( $value ) && empty( $value ) ) || $value == $empty; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - public static function is_not_empty_value( $value, $empty = '' ) { |
|
| 192 | - return ! self::is_empty_value( $value, $empty ); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Get any value from the $_SERVER |
|
| 197 | - * |
|
| 198 | - * @since 2.0 |
|
| 199 | - * @param string $value |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 185 | + * @return boolean |
|
| 186 | + */ |
|
| 187 | + public static function is_empty_value( $value, $empty = '' ) { |
|
| 188 | + return ( is_array( $value ) && empty( $value ) ) || $value == $empty; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + public static function is_not_empty_value( $value, $empty = '' ) { |
|
| 192 | + return ! self::is_empty_value( $value, $empty ); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Get any value from the $_SERVER |
|
| 197 | + * |
|
| 198 | + * @since 2.0 |
|
| 199 | + * @param string $value |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | 202 | public static function get_server_value( $value ) { |
| 203 | - return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : ''; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Check for the IP address in several places |
|
| 208 | - * Used by [ip] shortcode |
|
| 209 | - * |
|
| 210 | - * @return string The IP address of the current user |
|
| 211 | - */ |
|
| 212 | - public static function get_ip_address() { |
|
| 203 | + return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : ''; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Check for the IP address in several places |
|
| 208 | + * Used by [ip] shortcode |
|
| 209 | + * |
|
| 210 | + * @return string The IP address of the current user |
|
| 211 | + */ |
|
| 212 | + public static function get_ip_address() { |
|
| 213 | 213 | $ip = ''; |
| 214 | - foreach ( array( |
|
| 215 | - 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', |
|
| 216 | - 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR', |
|
| 217 | - ) as $key ) { |
|
| 218 | - if ( ! isset( $_SERVER[ $key ] ) ) { |
|
| 219 | - continue; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) { |
|
| 223 | - $ip = trim($ip); // just to be safe |
|
| 224 | - |
|
| 225 | - if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) { |
|
| 226 | - return $ip; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - } |
|
| 214 | + foreach ( array( |
|
| 215 | + 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', |
|
| 216 | + 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR', |
|
| 217 | + ) as $key ) { |
|
| 218 | + if ( ! isset( $_SERVER[ $key ] ) ) { |
|
| 219 | + continue; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) { |
|
| 223 | + $ip = trim($ip); // just to be safe |
|
| 224 | + |
|
| 225 | + if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) { |
|
| 226 | + return $ip; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | 231 | return sanitize_text_field( $ip ); |
| 232 | - } |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) { |
|
| 235 | - if ( strpos($param, '[') ) { |
|
| 236 | - $params = explode('[', $param); |
|
| 237 | - $param = $params[0]; |
|
| 238 | - } |
|
| 234 | + public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) { |
|
| 235 | + if ( strpos($param, '[') ) { |
|
| 236 | + $params = explode('[', $param); |
|
| 237 | + $param = $params[0]; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | 240 | if ( $src == 'get' ) { |
| 241 | - $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default ); |
|
| 242 | - if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) { |
|
| 243 | - $value = stripslashes_deep( htmlspecialchars_decode( $_GET[ $param ] ) ); |
|
| 244 | - } |
|
| 241 | + $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default ); |
|
| 242 | + if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) { |
|
| 243 | + $value = stripslashes_deep( htmlspecialchars_decode( $_GET[ $param ] ) ); |
|
| 244 | + } |
|
| 245 | 245 | self::sanitize_value( $sanitize, $value ); |
| 246 | 246 | } else { |
| 247 | - $value = self::get_simple_request( array( 'type' => $src, 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) ); |
|
| 248 | - } |
|
| 247 | + $value = self::get_simple_request( array( 'type' => $src, 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) ); |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | 250 | if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) { |
| 251 | - foreach ( $params as $k => $p ) { |
|
| 252 | - if ( ! $k || ! is_array($value) ) { |
|
| 253 | - continue; |
|
| 254 | - } |
|
| 251 | + foreach ( $params as $k => $p ) { |
|
| 252 | + if ( ! $k || ! is_array($value) ) { |
|
| 253 | + continue; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - $p = trim($p, ']'); |
|
| 257 | - $value = isset( $value[ $p ] ) ? $value[ $p ] : $default; |
|
| 258 | - } |
|
| 259 | - } |
|
| 256 | + $p = trim($p, ']'); |
|
| 257 | + $value = isset( $value[ $p ] ) ? $value[ $p ] : $default; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - return $value; |
|
| 262 | - } |
|
| 261 | + return $value; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | 264 | public static function get_post_param( $param, $default = '', $sanitize = '' ) { |
| 265 | 265 | return self::get_simple_request( array( 'type' => 'post', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) ); |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) { |
| 277 | 277 | return self::get_simple_request( array( 'type' => 'get', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) ); |
| 278 | - } |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | 280 | /** |
| 281 | 281 | * Get a GET/POST/REQUEST value and sanitize it |
@@ -311,12 +311,12 @@ discard block |
||
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | /** |
| 314 | - * Preserve backslashes in a value, but make sure value doesn't get compounding slashes |
|
| 315 | - * |
|
| 316 | - * @since 2.0.8 |
|
| 317 | - * @param string $value |
|
| 318 | - * @return string $value |
|
| 319 | - */ |
|
| 314 | + * Preserve backslashes in a value, but make sure value doesn't get compounding slashes |
|
| 315 | + * |
|
| 316 | + * @since 2.0.8 |
|
| 317 | + * @param string $value |
|
| 318 | + * @return string $value |
|
| 319 | + */ |
|
| 320 | 320 | public static function preserve_backslashes( $value ) { |
| 321 | 321 | // If backslashes have already been added, don't add them again |
| 322 | 322 | if ( strpos( $value, '\\\\' ) === false ) { |
@@ -338,14 +338,14 @@ discard block |
||
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - public static function sanitize_request( $sanitize_method, &$values ) { |
|
| 342 | - $temp_values = $values; |
|
| 343 | - foreach ( $temp_values as $k => $val ) { |
|
| 344 | - if ( isset( $sanitize_method[ $k ] ) ) { |
|
| 341 | + public static function sanitize_request( $sanitize_method, &$values ) { |
|
| 342 | + $temp_values = $values; |
|
| 343 | + foreach ( $temp_values as $k => $val ) { |
|
| 344 | + if ( isset( $sanitize_method[ $k ] ) ) { |
|
| 345 | 345 | $values[ $k ] = call_user_func( $sanitize_method[ $k ], $val ); |
| 346 | - } |
|
| 347 | - } |
|
| 348 | - } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | 350 | public static function sanitize_array( &$values ) { |
| 351 | 351 | $temp_values = $values; |
@@ -469,80 +469,80 @@ discard block |
||
| 469 | 469 | ); |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | - /** |
|
| 473 | - * Used when switching the action for a bulk action |
|
| 474 | - * @since 2.0 |
|
| 475 | - */ |
|
| 476 | - public static function remove_get_action() { |
|
| 477 | - if ( ! isset($_GET) ) { |
|
| 478 | - return; |
|
| 479 | - } |
|
| 472 | + /** |
|
| 473 | + * Used when switching the action for a bulk action |
|
| 474 | + * @since 2.0 |
|
| 475 | + */ |
|
| 476 | + public static function remove_get_action() { |
|
| 477 | + if ( ! isset($_GET) ) { |
|
| 478 | + return; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - $new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' ); |
|
| 482 | - if ( ! empty( $new_action ) ) { |
|
| 481 | + $new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' ); |
|
| 482 | + if ( ! empty( $new_action ) ) { |
|
| 483 | 483 | $_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', FrmAppHelper::get_server_value( 'REQUEST_URI' ) ); |
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Check the WP query for a parameter |
|
| 489 | - * |
|
| 490 | - * @since 2.0 |
|
| 491 | - * @return string|array |
|
| 492 | - */ |
|
| 493 | - public static function get_query_var( $value, $param ) { |
|
| 494 | - if ( $value != '' ) { |
|
| 495 | - return $value; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - global $wp_query; |
|
| 499 | - if ( isset( $wp_query->query_vars[ $param ] ) ) { |
|
| 500 | - $value = $wp_query->query_vars[ $param ]; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - return $value; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * @param string $type |
|
| 508 | - */ |
|
| 509 | - public static function trigger_hook_load( $type, $object = null ) { |
|
| 510 | - // only load the form hooks once |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Check the WP query for a parameter |
|
| 489 | + * |
|
| 490 | + * @since 2.0 |
|
| 491 | + * @return string|array |
|
| 492 | + */ |
|
| 493 | + public static function get_query_var( $value, $param ) { |
|
| 494 | + if ( $value != '' ) { |
|
| 495 | + return $value; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + global $wp_query; |
|
| 499 | + if ( isset( $wp_query->query_vars[ $param ] ) ) { |
|
| 500 | + $value = $wp_query->query_vars[ $param ]; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + return $value; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * @param string $type |
|
| 508 | + */ |
|
| 509 | + public static function trigger_hook_load( $type, $object = null ) { |
|
| 510 | + // only load the form hooks once |
|
| 511 | 511 | $hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object ); |
| 512 | - if ( ! $hooks_loaded ) { |
|
| 512 | + if ( ! $hooks_loaded ) { |
|
| 513 | 513 | do_action( 'frm_load_' . $type . '_hooks' ); |
| 514 | - } |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * Check a value from a shortcode to see if true or false. |
|
| 519 | - * True when value is 1, true, 'true', 'yes' |
|
| 520 | - * |
|
| 521 | - * @since 1.07.10 |
|
| 522 | - * |
|
| 523 | - * @param string $value The value to compare |
|
| 524 | - * @return boolean True or False |
|
| 525 | - */ |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * Check a value from a shortcode to see if true or false. |
|
| 519 | + * True when value is 1, true, 'true', 'yes' |
|
| 520 | + * |
|
| 521 | + * @since 1.07.10 |
|
| 522 | + * |
|
| 523 | + * @param string $value The value to compare |
|
| 524 | + * @return boolean True or False |
|
| 525 | + */ |
|
| 526 | 526 | public static function is_true( $value ) { |
| 527 | - return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value ); |
|
| 528 | - } |
|
| 527 | + return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value ); |
|
| 528 | + } |
|
| 529 | 529 | |
| 530 | - /** |
|
| 531 | - * Used to filter shortcode in text widgets |
|
| 532 | - */ |
|
| 533 | - public static function widget_text_filter_callback( $matches ) { |
|
| 530 | + /** |
|
| 531 | + * Used to filter shortcode in text widgets |
|
| 532 | + */ |
|
| 533 | + public static function widget_text_filter_callback( $matches ) { |
|
| 534 | 534 | _deprecated_function( __METHOD__, '2.5.4' ); |
| 535 | - return do_shortcode( $matches[0] ); |
|
| 536 | - } |
|
| 535 | + return do_shortcode( $matches[0] ); |
|
| 536 | + } |
|
| 537 | 537 | |
| 538 | - public static function get_pages() { |
|
| 538 | + public static function get_pages() { |
|
| 539 | 539 | return get_posts( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'private' ), 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ) ); |
| 540 | - } |
|
| 540 | + } |
|
| 541 | 541 | |
| 542 | - public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) { |
|
| 543 | - $pages = self::get_pages(); |
|
| 542 | + public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) { |
|
| 543 | + $pages = self::get_pages(); |
|
| 544 | 544 | $selected = self::get_post_param( $field_name, $page_id, 'absint' ); |
| 545 | - ?> |
|
| 545 | + ?> |
|
| 546 | 546 | <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" class="frm-pages-dropdown"> |
| 547 | 547 | <option value=""> </option> |
| 548 | 548 | <?php foreach ( $pages as $page ) { ?> |
@@ -552,108 +552,108 @@ discard block |
||
| 552 | 552 | <?php } ?> |
| 553 | 553 | </select> |
| 554 | 554 | <?php |
| 555 | - } |
|
| 555 | + } |
|
| 556 | 556 | |
| 557 | 557 | public static function post_edit_link( $post_id ) { |
| 558 | - $post = get_post($post_id); |
|
| 559 | - if ( $post ) { |
|
| 558 | + $post = get_post($post_id); |
|
| 559 | + if ( $post ) { |
|
| 560 | 560 | $post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' ); |
| 561 | 561 | return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>'; |
| 562 | - } |
|
| 563 | - return ''; |
|
| 564 | - } |
|
| 562 | + } |
|
| 563 | + return ''; |
|
| 564 | + } |
|
| 565 | 565 | |
| 566 | 566 | public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) { |
| 567 | - ?> |
|
| 567 | + ?> |
|
| 568 | 568 | <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" <?php |
| 569 | - echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : ''; |
|
| 570 | - ?> class="frm_multiselect"> |
|
| 569 | + echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : ''; |
|
| 570 | + ?> class="frm_multiselect"> |
|
| 571 | 571 | <?php self::roles_options($capability); ?> |
| 572 | 572 | </select> |
| 573 | 573 | <?php |
| 574 | - } |
|
| 574 | + } |
|
| 575 | 575 | |
| 576 | 576 | public static function roles_options( $capability ) { |
| 577 | - global $frm_vars; |
|
| 578 | - if ( isset($frm_vars['editable_roles']) ) { |
|
| 579 | - $editable_roles = $frm_vars['editable_roles']; |
|
| 580 | - } else { |
|
| 581 | - $editable_roles = get_editable_roles(); |
|
| 582 | - $frm_vars['editable_roles'] = $editable_roles; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - foreach ( $editable_roles as $role => $details ) { |
|
| 586 | - $name = translate_user_role($details['name'] ); ?> |
|
| 577 | + global $frm_vars; |
|
| 578 | + if ( isset($frm_vars['editable_roles']) ) { |
|
| 579 | + $editable_roles = $frm_vars['editable_roles']; |
|
| 580 | + } else { |
|
| 581 | + $editable_roles = get_editable_roles(); |
|
| 582 | + $frm_vars['editable_roles'] = $editable_roles; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + foreach ( $editable_roles as $role => $details ) { |
|
| 586 | + $name = translate_user_role($details['name'] ); ?> |
|
| 587 | 587 | <option value="<?php echo esc_attr($role) ?>" <?php echo in_array($role, (array) $capability) ? ' selected="selected"' : ''; ?>><?php echo esc_attr($name) ?> </option> |
| 588 | 588 | <?php |
| 589 | - unset($role, $details); |
|
| 590 | - } |
|
| 591 | - } |
|
| 589 | + unset($role, $details); |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | 592 | |
| 593 | 593 | public static function frm_capabilities( $type = 'auto' ) { |
| 594 | - $cap = array( |
|
| 595 | - 'frm_view_forms' => __( 'View Forms and Templates', 'formidable' ), |
|
| 596 | - 'frm_edit_forms' => __( 'Add/Edit Forms and Templates', 'formidable' ), |
|
| 597 | - 'frm_delete_forms' => __( 'Delete Forms and Templates', 'formidable' ), |
|
| 598 | - 'frm_change_settings' => __( 'Access this Settings Page', 'formidable' ), |
|
| 599 | - 'frm_view_entries' => __( 'View Entries from Admin Area', 'formidable' ), |
|
| 600 | - 'frm_delete_entries' => __( 'Delete Entries from Admin Area', 'formidable' ), |
|
| 601 | - ); |
|
| 594 | + $cap = array( |
|
| 595 | + 'frm_view_forms' => __( 'View Forms and Templates', 'formidable' ), |
|
| 596 | + 'frm_edit_forms' => __( 'Add/Edit Forms and Templates', 'formidable' ), |
|
| 597 | + 'frm_delete_forms' => __( 'Delete Forms and Templates', 'formidable' ), |
|
| 598 | + 'frm_change_settings' => __( 'Access this Settings Page', 'formidable' ), |
|
| 599 | + 'frm_view_entries' => __( 'View Entries from Admin Area', 'formidable' ), |
|
| 600 | + 'frm_delete_entries' => __( 'Delete Entries from Admin Area', 'formidable' ), |
|
| 601 | + ); |
|
| 602 | 602 | |
| 603 | 603 | if ( ! self::pro_is_installed() && 'pro' != $type ) { |
| 604 | - return $cap; |
|
| 605 | - } |
|
| 604 | + return $cap; |
|
| 605 | + } |
|
| 606 | 606 | |
| 607 | - $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' ); |
|
| 608 | - $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' ); |
|
| 609 | - $cap['frm_view_reports'] = __( 'View Reports', 'formidable' ); |
|
| 610 | - $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' ); |
|
| 607 | + $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' ); |
|
| 608 | + $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' ); |
|
| 609 | + $cap['frm_view_reports'] = __( 'View Reports', 'formidable' ); |
|
| 610 | + $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' ); |
|
| 611 | 611 | |
| 612 | - return $cap; |
|
| 613 | - } |
|
| 612 | + return $cap; |
|
| 613 | + } |
|
| 614 | 614 | |
| 615 | 615 | public static function user_has_permission( $needed_role ) { |
| 616 | - if ( $needed_role == '-1' ) { |
|
| 617 | - return false; |
|
| 616 | + if ( $needed_role == '-1' ) { |
|
| 617 | + return false; |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | - // $needed_role will be equal to blank if "Logged-in users" is selected |
|
| 621 | - if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) { |
|
| 622 | - return true; |
|
| 623 | - } |
|
| 620 | + // $needed_role will be equal to blank if "Logged-in users" is selected |
|
| 621 | + if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) { |
|
| 622 | + return true; |
|
| 623 | + } |
|
| 624 | 624 | |
| 625 | - $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' ); |
|
| 626 | - foreach ( $roles as $role ) { |
|
| 625 | + $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' ); |
|
| 626 | + foreach ( $roles as $role ) { |
|
| 627 | 627 | if ( current_user_can( $role ) ) { |
| 628 | - return true; |
|
| 628 | + return true; |
|
| 629 | 629 | } |
| 630 | - if ( $role == $needed_role ) { |
|
| 631 | - break; |
|
| 630 | + if ( $role == $needed_role ) { |
|
| 631 | + break; |
|
| 632 | 632 | } |
| 633 | - } |
|
| 634 | - return false; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * Make sure administrators can see Formidable menu |
|
| 639 | - * |
|
| 640 | - * @since 2.0 |
|
| 641 | - */ |
|
| 642 | - public static function maybe_add_permissions() { |
|
| 633 | + } |
|
| 634 | + return false; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * Make sure administrators can see Formidable menu |
|
| 639 | + * |
|
| 640 | + * @since 2.0 |
|
| 641 | + */ |
|
| 642 | + public static function maybe_add_permissions() { |
|
| 643 | 643 | self::force_capability( 'frm_view_entries' ); |
| 644 | 644 | |
| 645 | - if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) { |
|
| 646 | - return; |
|
| 647 | - } |
|
| 645 | + if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) { |
|
| 646 | + return; |
|
| 647 | + } |
|
| 648 | 648 | |
| 649 | 649 | $user_id = get_current_user_id(); |
| 650 | 650 | $user = new WP_User( $user_id ); |
| 651 | - $frm_roles = self::frm_capabilities(); |
|
| 652 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 651 | + $frm_roles = self::frm_capabilities(); |
|
| 652 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
| 653 | 653 | $user->add_cap( $frm_role ); |
| 654 | - unset($frm_role, $frm_role_description); |
|
| 655 | - } |
|
| 656 | - } |
|
| 654 | + unset($frm_role, $frm_role_description); |
|
| 655 | + } |
|
| 656 | + } |
|
| 657 | 657 | |
| 658 | 658 | /** |
| 659 | 659 | * Make sure admins have permission to see the menu items |
@@ -669,28 +669,28 @@ discard block |
||
| 669 | 669 | } |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - /** |
|
| 673 | - * Check if the user has permision for action. |
|
| 674 | - * Return permission message and stop the action if no permission |
|
| 675 | - * @since 2.0 |
|
| 676 | - * @param string $permission |
|
| 677 | - */ |
|
| 672 | + /** |
|
| 673 | + * Check if the user has permision for action. |
|
| 674 | + * Return permission message and stop the action if no permission |
|
| 675 | + * @since 2.0 |
|
| 676 | + * @param string $permission |
|
| 677 | + */ |
|
| 678 | 678 | public static function permission_check( $permission, $show_message = 'show' ) { |
| 679 | - $permission_error = self::permission_nonce_error($permission); |
|
| 680 | - if ( $permission_error !== false ) { |
|
| 681 | - if ( 'hide' == $show_message ) { |
|
| 682 | - $permission_error = ''; |
|
| 683 | - } |
|
| 684 | - wp_die($permission_error); |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * Check user permission and nonce |
|
| 690 | - * @since 2.0 |
|
| 691 | - * @param string $permission |
|
| 692 | - * @return false|string The permission message or false if allowed |
|
| 693 | - */ |
|
| 679 | + $permission_error = self::permission_nonce_error($permission); |
|
| 680 | + if ( $permission_error !== false ) { |
|
| 681 | + if ( 'hide' == $show_message ) { |
|
| 682 | + $permission_error = ''; |
|
| 683 | + } |
|
| 684 | + wp_die($permission_error); |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * Check user permission and nonce |
|
| 690 | + * @since 2.0 |
|
| 691 | + * @param string $permission |
|
| 692 | + * @return false|string The permission message or false if allowed |
|
| 693 | + */ |
|
| 694 | 694 | public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) { |
| 695 | 695 | if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) { |
| 696 | 696 | $frm_settings = self::get_settings(); |
@@ -698,23 +698,23 @@ discard block |
||
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | $error = false; |
| 701 | - if ( empty($nonce_name) ) { |
|
| 702 | - return $error; |
|
| 703 | - } |
|
| 701 | + if ( empty($nonce_name) ) { |
|
| 702 | + return $error; |
|
| 703 | + } |
|
| 704 | 704 | |
| 705 | - if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) { |
|
| 706 | - $frm_settings = self::get_settings(); |
|
| 707 | - $error = $frm_settings->admin_permission; |
|
| 708 | - } |
|
| 705 | + if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) { |
|
| 706 | + $frm_settings = self::get_settings(); |
|
| 707 | + $error = $frm_settings->admin_permission; |
|
| 708 | + } |
|
| 709 | 709 | |
| 710 | - return $error; |
|
| 711 | - } |
|
| 710 | + return $error; |
|
| 711 | + } |
|
| 712 | 712 | |
| 713 | - public static function checked( $values, $current ) { |
|
| 713 | + public static function checked( $values, $current ) { |
|
| 714 | 714 | if ( self::check_selected( $values, $current ) ) { |
| 715 | - echo ' checked="checked"'; |
|
| 715 | + echo ' checked="checked"'; |
|
| 716 | 716 | } |
| 717 | - } |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | 719 | public static function check_selected( $values, $current ) { |
| 720 | 720 | $values = self::recursive_function_map( $values, 'trim' ); |
@@ -724,50 +724,50 @@ discard block |
||
| 724 | 724 | return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current ); |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | - /** |
|
| 728 | - * Check if current field option is an "other" option |
|
| 729 | - * |
|
| 730 | - * @since 2.0 |
|
| 731 | - * |
|
| 732 | - * @param string $opt_key |
|
| 733 | - * @return boolean Returns true if current field option is an "Other" option |
|
| 734 | - */ |
|
| 735 | - public static function is_other_opt( $opt_key ) { |
|
| 736 | - _deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::is_other_opt' ); |
|
| 737 | - return FrmFieldsHelper::is_other_opt( $opt_key ); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * Get value that belongs in "Other" text box |
|
| 742 | - * |
|
| 743 | - * @since 2.0 |
|
| 744 | - * |
|
| 745 | - * @param string $opt_key |
|
| 746 | - * @param array $field |
|
| 747 | - * @return string $other_val |
|
| 748 | - */ |
|
| 749 | - public static function get_other_val( $opt_key, $field, $parent = false, $pointer = false ) { |
|
| 727 | + /** |
|
| 728 | + * Check if current field option is an "other" option |
|
| 729 | + * |
|
| 730 | + * @since 2.0 |
|
| 731 | + * |
|
| 732 | + * @param string $opt_key |
|
| 733 | + * @return boolean Returns true if current field option is an "Other" option |
|
| 734 | + */ |
|
| 735 | + public static function is_other_opt( $opt_key ) { |
|
| 736 | + _deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::is_other_opt' ); |
|
| 737 | + return FrmFieldsHelper::is_other_opt( $opt_key ); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * Get value that belongs in "Other" text box |
|
| 742 | + * |
|
| 743 | + * @since 2.0 |
|
| 744 | + * |
|
| 745 | + * @param string $opt_key |
|
| 746 | + * @param array $field |
|
| 747 | + * @return string $other_val |
|
| 748 | + */ |
|
| 749 | + public static function get_other_val( $opt_key, $field, $parent = false, $pointer = false ) { |
|
| 750 | 750 | _deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::get_other_val' ); |
| 751 | 751 | return FrmFieldsHelper::get_other_val( compact( 'opt_key', 'field', 'parent', 'pointer' ) ); |
| 752 | - } |
|
| 753 | - |
|
| 754 | - /** |
|
| 755 | - * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val. |
|
| 756 | - * Intended for front-end use |
|
| 757 | - * |
|
| 758 | - * @since 2.0 |
|
| 759 | - * |
|
| 760 | - * @param array $field |
|
| 761 | - * @param boolean $other_opt |
|
| 762 | - * @param string $checked |
|
| 763 | - * @param array $args should include opt_key and field name |
|
| 764 | - * @return string $other_val |
|
| 765 | - */ |
|
| 766 | - public static function prepare_other_input( $field, &$other_opt, &$checked, $args = array() ) { |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + /** |
|
| 755 | + * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val. |
|
| 756 | + * Intended for front-end use |
|
| 757 | + * |
|
| 758 | + * @since 2.0 |
|
| 759 | + * |
|
| 760 | + * @param array $field |
|
| 761 | + * @param boolean $other_opt |
|
| 762 | + * @param string $checked |
|
| 763 | + * @param array $args should include opt_key and field name |
|
| 764 | + * @return string $other_val |
|
| 765 | + */ |
|
| 766 | + public static function prepare_other_input( $field, &$other_opt, &$checked, $args = array() ) { |
|
| 767 | 767 | _deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::prepare_other_input' ); |
| 768 | 768 | $args['field'] = $field; |
| 769 | 769 | return FrmFieldsHelper::prepare_other_input( $args, $other_opt, $checked ); |
| 770 | - } |
|
| 770 | + } |
|
| 771 | 771 | |
| 772 | 772 | public static function recursive_function_map( $value, $function ) { |
| 773 | 773 | if ( is_array( $value ) ) { |
@@ -797,24 +797,24 @@ discard block |
||
| 797 | 797 | return (bool) count( array_filter( array_keys( $array ), 'is_string' ) ); |
| 798 | 798 | } |
| 799 | 799 | |
| 800 | - /** |
|
| 801 | - * Flatten a multi-dimensional array |
|
| 802 | - */ |
|
| 800 | + /** |
|
| 801 | + * Flatten a multi-dimensional array |
|
| 802 | + */ |
|
| 803 | 803 | public static function array_flatten( $array, $keys = 'keep' ) { |
| 804 | - $return = array(); |
|
| 805 | - foreach ( $array as $key => $value ) { |
|
| 806 | - if ( is_array($value) ) { |
|
| 804 | + $return = array(); |
|
| 805 | + foreach ( $array as $key => $value ) { |
|
| 806 | + if ( is_array($value) ) { |
|
| 807 | 807 | $return = array_merge( $return, self::array_flatten( $value, $keys ) ); |
| 808 | - } else { |
|
| 808 | + } else { |
|
| 809 | 809 | if ( $keys == 'keep' ) { |
| 810 | 810 | $return[ $key ] = $value; |
| 811 | 811 | } else { |
| 812 | 812 | $return[] = $value; |
| 813 | 813 | } |
| 814 | - } |
|
| 815 | - } |
|
| 816 | - return $return; |
|
| 817 | - } |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | + return $return; |
|
| 817 | + } |
|
| 818 | 818 | |
| 819 | 819 | public static function esc_textarea( $text, $is_rich_text = false ) { |
| 820 | 820 | $safe_text = str_replace( '"', '"', $text ); |
@@ -825,38 +825,38 @@ discard block |
||
| 825 | 825 | return apply_filters( 'esc_textarea', $safe_text, $text ); |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | - /** |
|
| 829 | - * Add auto paragraphs to text areas |
|
| 830 | - * @since 2.0 |
|
| 831 | - */ |
|
| 828 | + /** |
|
| 829 | + * Add auto paragraphs to text areas |
|
| 830 | + * @since 2.0 |
|
| 831 | + */ |
|
| 832 | 832 | public static function use_wpautop( $content ) { |
| 833 | - if ( apply_filters('frm_use_wpautop', true) ) { |
|
| 834 | - $content = wpautop(str_replace( '<br>', '<br />', $content)); |
|
| 835 | - } |
|
| 836 | - return $content; |
|
| 837 | - } |
|
| 833 | + if ( apply_filters('frm_use_wpautop', true) ) { |
|
| 834 | + $content = wpautop(str_replace( '<br>', '<br />', $content)); |
|
| 835 | + } |
|
| 836 | + return $content; |
|
| 837 | + } |
|
| 838 | 838 | |
| 839 | 839 | public static function replace_quotes( $val ) { |
| 840 | - //Replace double quotes |
|
| 840 | + //Replace double quotes |
|
| 841 | 841 | $val = str_replace( array( '“', '”', '″' ), '"', $val ); |
| 842 | - //Replace single quotes |
|
| 843 | - $val = str_replace( array( '‘', '’', '′', '′', '’', '‘' ), "'", $val ); |
|
| 844 | - return $val; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - /** |
|
| 848 | - * @since 2.0 |
|
| 849 | - * @return string The base Google APIS url for the current version of jQuery UI |
|
| 850 | - */ |
|
| 851 | - public static function jquery_ui_base_url() { |
|
| 842 | + //Replace single quotes |
|
| 843 | + $val = str_replace( array( '‘', '’', '′', '′', '’', '‘' ), "'", $val ); |
|
| 844 | + return $val; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * @since 2.0 |
|
| 849 | + * @return string The base Google APIS url for the current version of jQuery UI |
|
| 850 | + */ |
|
| 851 | + public static function jquery_ui_base_url() { |
|
| 852 | 852 | $url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core', '1.11.4' ); |
| 853 | - $url = apply_filters('frm_jquery_ui_base_url', $url); |
|
| 854 | - return $url; |
|
| 855 | - } |
|
| 853 | + $url = apply_filters('frm_jquery_ui_base_url', $url); |
|
| 854 | + return $url; |
|
| 855 | + } |
|
| 856 | 856 | |
| 857 | - /** |
|
| 858 | - * @param string $handle |
|
| 859 | - */ |
|
| 857 | + /** |
|
| 858 | + * @param string $handle |
|
| 859 | + */ |
|
| 860 | 860 | public static function script_version( $handle, $default = 0 ) { |
| 861 | 861 | global $wp_scripts; |
| 862 | 862 | if ( ! $wp_scripts ) { |
@@ -878,242 +878,242 @@ discard block |
||
| 878 | 878 | |
| 879 | 879 | public static function js_redirect( $url ) { |
| 880 | 880 | return '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>'; |
| 881 | - } |
|
| 881 | + } |
|
| 882 | 882 | |
| 883 | 883 | public static function get_user_id_param( $user_id ) { |
| 884 | - if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) { |
|
| 885 | - return $user_id; |
|
| 886 | - } |
|
| 884 | + if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) { |
|
| 885 | + return $user_id; |
|
| 886 | + } |
|
| 887 | 887 | |
| 888 | 888 | $user_id = sanitize_text_field( $user_id ); |
| 889 | 889 | if ( $user_id == 'current' ) { |
| 890 | 890 | $user_id = get_current_user_id(); |
| 891 | 891 | } else { |
| 892 | - if ( is_email($user_id) ) { |
|
| 893 | - $user = get_user_by('email', $user_id); |
|
| 894 | - } else { |
|
| 895 | - $user = get_user_by('login', $user_id); |
|
| 896 | - } |
|
| 892 | + if ( is_email($user_id) ) { |
|
| 893 | + $user = get_user_by('email', $user_id); |
|
| 894 | + } else { |
|
| 895 | + $user = get_user_by('login', $user_id); |
|
| 896 | + } |
|
| 897 | 897 | |
| 898 | - if ( $user ) { |
|
| 899 | - $user_id = $user->ID; |
|
| 900 | - } |
|
| 901 | - unset($user); |
|
| 902 | - } |
|
| 898 | + if ( $user ) { |
|
| 899 | + $user_id = $user->ID; |
|
| 900 | + } |
|
| 901 | + unset($user); |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | - return $user_id; |
|
| 905 | - } |
|
| 904 | + return $user_id; |
|
| 905 | + } |
|
| 906 | 906 | |
| 907 | 907 | public static function get_file_contents( $filename, $atts = array() ) { |
| 908 | - if ( ! is_file($filename) ) { |
|
| 909 | - return false; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - extract($atts); |
|
| 913 | - ob_start(); |
|
| 914 | - include($filename); |
|
| 915 | - $contents = ob_get_contents(); |
|
| 916 | - ob_end_clean(); |
|
| 917 | - return $contents; |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * @param string $table_name |
|
| 922 | - * @param string $column |
|
| 908 | + if ( ! is_file($filename) ) { |
|
| 909 | + return false; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + extract($atts); |
|
| 913 | + ob_start(); |
|
| 914 | + include($filename); |
|
| 915 | + $contents = ob_get_contents(); |
|
| 916 | + ob_end_clean(); |
|
| 917 | + return $contents; |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * @param string $table_name |
|
| 922 | + * @param string $column |
|
| 923 | 923 | * @param int $id |
| 924 | 924 | * @param int $num_chars |
| 925 | - */ |
|
| 926 | - public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) { |
|
| 927 | - $key = ''; |
|
| 925 | + */ |
|
| 926 | + public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) { |
|
| 927 | + $key = ''; |
|
| 928 | 928 | |
| 929 | - if ( ! empty( $name ) ) { |
|
| 930 | - $key = sanitize_key($name); |
|
| 931 | - } |
|
| 929 | + if ( ! empty( $name ) ) { |
|
| 930 | + $key = sanitize_key($name); |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | 933 | if ( empty( $key ) ) { |
| 934 | - $max_slug_value = pow(36, $num_chars); |
|
| 935 | - $min_slug_value = 37; // we want to have at least 2 characters in the slug |
|
| 936 | - $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 ); |
|
| 937 | - } |
|
| 934 | + $max_slug_value = pow(36, $num_chars); |
|
| 935 | + $min_slug_value = 37; // we want to have at least 2 characters in the slug |
|
| 936 | + $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 ); |
|
| 937 | + } |
|
| 938 | 938 | |
| 939 | 939 | if ( is_numeric($key) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) { |
| 940 | 940 | $key = $key . 'a'; |
| 941 | - } |
|
| 941 | + } |
|
| 942 | 942 | |
| 943 | 943 | $key_check = FrmDb::get_var( $table_name, array( $column => $key, 'ID !' => $id ), $column ); |
| 944 | 944 | |
| 945 | - if ( $key_check || is_numeric($key_check) ) { |
|
| 946 | - $suffix = 2; |
|
| 945 | + if ( $key_check || is_numeric($key_check) ) { |
|
| 946 | + $suffix = 2; |
|
| 947 | 947 | do { |
| 948 | 948 | $alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix; |
| 949 | 949 | $key_check = FrmDb::get_var( $table_name, array( $column => $alt_post_name, 'ID !' => $id ), $column ); |
| 950 | 950 | $suffix++; |
| 951 | 951 | } while ( $key_check || is_numeric( $key_check ) ); |
| 952 | 952 | $key = $alt_post_name; |
| 953 | - } |
|
| 954 | - return $key; |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * Editing a Form or Entry |
|
| 959 | - * @param string $table |
|
| 960 | - * @return bool|array |
|
| 961 | - */ |
|
| 962 | - public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) { |
|
| 963 | - if ( ! $record ) { |
|
| 964 | - return false; |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - if ( empty($post_values) ) { |
|
| 968 | - $post_values = stripslashes_deep($_POST); |
|
| 969 | - } |
|
| 953 | + } |
|
| 954 | + return $key; |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * Editing a Form or Entry |
|
| 959 | + * @param string $table |
|
| 960 | + * @return bool|array |
|
| 961 | + */ |
|
| 962 | + public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) { |
|
| 963 | + if ( ! $record ) { |
|
| 964 | + return false; |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + if ( empty($post_values) ) { |
|
| 968 | + $post_values = stripslashes_deep($_POST); |
|
| 969 | + } |
|
| 970 | 970 | |
| 971 | 971 | $values = array( 'id' => $record->id, 'fields' => array() ); |
| 972 | 972 | |
| 973 | 973 | foreach ( array( 'name', 'description' ) as $var ) { |
| 974 | - $default_val = isset($record->{$var}) ? $record->{$var} : ''; |
|
| 974 | + $default_val = isset($record->{$var}) ? $record->{$var} : ''; |
|
| 975 | 975 | $values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' ); |
| 976 | - unset($var, $default_val); |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - $values['description'] = self::use_wpautop($values['description']); |
|
| 980 | - $frm_settings = self::get_settings(); |
|
| 981 | - $is_form_builder = self::is_admin_page('formidable' ); |
|
| 982 | - |
|
| 983 | - foreach ( (array) $fields as $field ) { |
|
| 984 | - // Make sure to filter default values (for placeholder text), but not on the form builder page |
|
| 985 | - if ( ! $is_form_builder ) { |
|
| 986 | - $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true ); |
|
| 987 | - } |
|
| 976 | + unset($var, $default_val); |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + $values['description'] = self::use_wpautop($values['description']); |
|
| 980 | + $frm_settings = self::get_settings(); |
|
| 981 | + $is_form_builder = self::is_admin_page('formidable' ); |
|
| 982 | + |
|
| 983 | + foreach ( (array) $fields as $field ) { |
|
| 984 | + // Make sure to filter default values (for placeholder text), but not on the form builder page |
|
| 985 | + if ( ! $is_form_builder ) { |
|
| 986 | + $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true ); |
|
| 987 | + } |
|
| 988 | 988 | $parent_form_id = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id; |
| 989 | 989 | self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings', 'parent_form_id' ) ); |
| 990 | - } |
|
| 990 | + } |
|
| 991 | 991 | |
| 992 | - self::fill_form_opts($record, $table, $post_values, $values); |
|
| 992 | + self::fill_form_opts($record, $table, $post_values, $values); |
|
| 993 | 993 | |
| 994 | - if ( $table == 'entries' ) { |
|
| 995 | - $values = FrmEntriesHelper::setup_edit_vars( $values, $record ); |
|
| 996 | - } else if ( $table == 'forms' ) { |
|
| 997 | - $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values ); |
|
| 998 | - } |
|
| 994 | + if ( $table == 'entries' ) { |
|
| 995 | + $values = FrmEntriesHelper::setup_edit_vars( $values, $record ); |
|
| 996 | + } else if ( $table == 'forms' ) { |
|
| 997 | + $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values ); |
|
| 998 | + } |
|
| 999 | 999 | |
| 1000 | - return $values; |
|
| 1001 | - } |
|
| 1000 | + return $values; |
|
| 1001 | + } |
|
| 1002 | 1002 | |
| 1003 | 1003 | private static function fill_field_defaults( $field, $record, array &$values, $args ) { |
| 1004 | - $post_values = $args['post_values']; |
|
| 1005 | - |
|
| 1006 | - if ( $args['default'] ) { |
|
| 1007 | - $meta_value = $field->default_value; |
|
| 1008 | - } else { |
|
| 1009 | - if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) { |
|
| 1010 | - if ( ! isset($field->field_options['custom_field']) ) { |
|
| 1011 | - $field->field_options['custom_field'] = ''; |
|
| 1012 | - } |
|
| 1004 | + $post_values = $args['post_values']; |
|
| 1005 | + |
|
| 1006 | + if ( $args['default'] ) { |
|
| 1007 | + $meta_value = $field->default_value; |
|
| 1008 | + } else { |
|
| 1009 | + if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) { |
|
| 1010 | + if ( ! isset($field->field_options['custom_field']) ) { |
|
| 1011 | + $field->field_options['custom_field'] = ''; |
|
| 1012 | + } |
|
| 1013 | 1013 | $meta_value = FrmProEntryMetaHelper::get_post_value( $record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array( 'truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field ) ); |
| 1014 | - } else { |
|
| 1014 | + } else { |
|
| 1015 | 1015 | $meta_value = FrmEntryMeta::get_meta_value( $record, $field->id ); |
| 1016 | - } |
|
| 1017 | - } |
|
| 1016 | + } |
|
| 1017 | + } |
|
| 1018 | 1018 | |
| 1019 | 1019 | $field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type; |
| 1020 | - $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value; |
|
| 1021 | - |
|
| 1022 | - $field_array = array( |
|
| 1023 | - 'id' => $field->id, |
|
| 1024 | - 'value' => $new_value, |
|
| 1025 | - 'default_value' => $field->default_value, |
|
| 1026 | - 'name' => $field->name, |
|
| 1027 | - 'description' => $field->description, |
|
| 1028 | - 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value), |
|
| 1029 | - 'options' => $field->options, |
|
| 1030 | - 'required' => $field->required, |
|
| 1031 | - 'field_key' => $field->field_key, |
|
| 1032 | - 'field_order' => $field->field_order, |
|
| 1033 | - 'form_id' => $field->form_id, |
|
| 1020 | + $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value; |
|
| 1021 | + |
|
| 1022 | + $field_array = array( |
|
| 1023 | + 'id' => $field->id, |
|
| 1024 | + 'value' => $new_value, |
|
| 1025 | + 'default_value' => $field->default_value, |
|
| 1026 | + 'name' => $field->name, |
|
| 1027 | + 'description' => $field->description, |
|
| 1028 | + 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value), |
|
| 1029 | + 'options' => $field->options, |
|
| 1030 | + 'required' => $field->required, |
|
| 1031 | + 'field_key' => $field->field_key, |
|
| 1032 | + 'field_order' => $field->field_order, |
|
| 1033 | + 'form_id' => $field->form_id, |
|
| 1034 | 1034 | 'parent_form_id' => $args['parent_form_id'], |
| 1035 | - ); |
|
| 1035 | + ); |
|
| 1036 | 1036 | |
| 1037 | - $args['field_type'] = $field_type; |
|
| 1038 | - self::fill_field_opts($field, $field_array, $args); |
|
| 1037 | + $args['field_type'] = $field_type; |
|
| 1038 | + self::fill_field_opts($field, $field_array, $args); |
|
| 1039 | 1039 | // Track the original field's type |
| 1040 | 1040 | $field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type; |
| 1041 | 1041 | |
| 1042 | - $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $values['id'], array() ); |
|
| 1042 | + $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $values['id'], array() ); |
|
| 1043 | 1043 | |
| 1044 | - if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) { |
|
| 1045 | - $field_array['unique_msg'] = ''; |
|
| 1046 | - } |
|
| 1044 | + if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) { |
|
| 1045 | + $field_array['unique_msg'] = ''; |
|
| 1046 | + } |
|
| 1047 | 1047 | |
| 1048 | - $field_array = array_merge( $field->field_options, $field_array ); |
|
| 1048 | + $field_array = array_merge( $field->field_options, $field_array ); |
|
| 1049 | 1049 | |
| 1050 | - $values['fields'][ $field->id ] = $field_array; |
|
| 1051 | - } |
|
| 1050 | + $values['fields'][ $field->id ] = $field_array; |
|
| 1051 | + } |
|
| 1052 | 1052 | |
| 1053 | 1053 | private static function fill_field_opts( $field, array &$field_array, $args ) { |
| 1054 | - $post_values = $args['post_values']; |
|
| 1055 | - $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
| 1054 | + $post_values = $args['post_values']; |
|
| 1055 | + $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
| 1056 | 1056 | |
| 1057 | - foreach ( $opt_defaults as $opt => $default_opt ) { |
|
| 1057 | + foreach ( $opt_defaults as $opt => $default_opt ) { |
|
| 1058 | 1058 | $field_array[ $opt ] = ( $post_values && isset( $post_values['field_options'][ $opt . '_' . $field->id ] ) ) ? maybe_unserialize( $post_values['field_options'][ $opt . '_' . $field->id ] ) : ( isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default_opt ); |
| 1059 | - if ( $opt == 'blank' && $field_array[ $opt ] == '' ) { |
|
| 1060 | - $field_array[ $opt ] = $args['frm_settings']->blank_msg; |
|
| 1061 | - } else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) { |
|
| 1062 | - if ( $args['field_type'] == 'captcha' ) { |
|
| 1063 | - $field_array[ $opt ] = $args['frm_settings']->re_msg; |
|
| 1064 | - } else { |
|
| 1065 | - $field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] ); |
|
| 1066 | - } |
|
| 1067 | - } |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - if ( $field_array['custom_html'] == '' ) { |
|
| 1071 | - $field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']); |
|
| 1072 | - } |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - /** |
|
| 1076 | - * @param string $table |
|
| 1077 | - */ |
|
| 1059 | + if ( $opt == 'blank' && $field_array[ $opt ] == '' ) { |
|
| 1060 | + $field_array[ $opt ] = $args['frm_settings']->blank_msg; |
|
| 1061 | + } else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) { |
|
| 1062 | + if ( $args['field_type'] == 'captcha' ) { |
|
| 1063 | + $field_array[ $opt ] = $args['frm_settings']->re_msg; |
|
| 1064 | + } else { |
|
| 1065 | + $field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] ); |
|
| 1066 | + } |
|
| 1067 | + } |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + if ( $field_array['custom_html'] == '' ) { |
|
| 1071 | + $field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']); |
|
| 1072 | + } |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + /** |
|
| 1076 | + * @param string $table |
|
| 1077 | + */ |
|
| 1078 | 1078 | private static function fill_form_opts( $record, $table, $post_values, array &$values ) { |
| 1079 | - if ( $table == 'entries' ) { |
|
| 1080 | - $form = $record->form_id; |
|
| 1079 | + if ( $table == 'entries' ) { |
|
| 1080 | + $form = $record->form_id; |
|
| 1081 | 1081 | FrmForm::maybe_get_form( $form ); |
| 1082 | - } else { |
|
| 1083 | - $form = $record; |
|
| 1084 | - } |
|
| 1082 | + } else { |
|
| 1083 | + $form = $record; |
|
| 1084 | + } |
|
| 1085 | 1085 | |
| 1086 | - if ( ! $form ) { |
|
| 1087 | - return; |
|
| 1088 | - } |
|
| 1086 | + if ( ! $form ) { |
|
| 1087 | + return; |
|
| 1088 | + } |
|
| 1089 | 1089 | |
| 1090 | - $values['form_name'] = isset($record->form_id) ? $form->name : ''; |
|
| 1090 | + $values['form_name'] = isset($record->form_id) ? $form->name : ''; |
|
| 1091 | 1091 | $values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0; |
| 1092 | 1092 | |
| 1093 | - if ( ! is_array($form->options) ) { |
|
| 1094 | - return; |
|
| 1095 | - } |
|
| 1093 | + if ( ! is_array($form->options) ) { |
|
| 1094 | + return; |
|
| 1095 | + } |
|
| 1096 | 1096 | |
| 1097 | - foreach ( $form->options as $opt => $value ) { |
|
| 1098 | - $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value; |
|
| 1099 | - } |
|
| 1097 | + foreach ( $form->options as $opt => $value ) { |
|
| 1098 | + $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value; |
|
| 1099 | + } |
|
| 1100 | 1100 | |
| 1101 | - self::fill_form_defaults($post_values, $values); |
|
| 1102 | - } |
|
| 1101 | + self::fill_form_defaults($post_values, $values); |
|
| 1102 | + } |
|
| 1103 | 1103 | |
| 1104 | - /** |
|
| 1105 | - * Set to POST value or default |
|
| 1106 | - */ |
|
| 1104 | + /** |
|
| 1105 | + * Set to POST value or default |
|
| 1106 | + */ |
|
| 1107 | 1107 | private static function fill_form_defaults( $post_values, array &$values ) { |
| 1108 | - $form_defaults = FrmFormsHelper::get_default_opts(); |
|
| 1108 | + $form_defaults = FrmFormsHelper::get_default_opts(); |
|
| 1109 | 1109 | |
| 1110 | - foreach ( $form_defaults as $opt => $default ) { |
|
| 1111 | - if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) { |
|
| 1110 | + foreach ( $form_defaults as $opt => $default ) { |
|
| 1111 | + if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) { |
|
| 1112 | 1112 | $values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default; |
| 1113 | - } |
|
| 1113 | + } |
|
| 1114 | 1114 | |
| 1115 | - unset($opt, $defaut); |
|
| 1116 | - } |
|
| 1115 | + unset($opt, $defaut); |
|
| 1116 | + } |
|
| 1117 | 1117 | |
| 1118 | 1118 | if ( ! isset( $values['custom_style'] ) ) { |
| 1119 | 1119 | $values['custom_style'] = self::custom_style_value( $post_values ); |
@@ -1122,10 +1122,10 @@ discard block |
||
| 1122 | 1122 | foreach ( array( 'before', 'after', 'submit' ) as $h ) { |
| 1123 | 1123 | if ( ! isset( $values[ $h . '_html' ] ) ) { |
| 1124 | 1124 | $values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) ); |
| 1125 | - } |
|
| 1126 | - unset($h); |
|
| 1127 | - } |
|
| 1128 | - } |
|
| 1125 | + } |
|
| 1126 | + unset($h); |
|
| 1127 | + } |
|
| 1128 | + } |
|
| 1129 | 1129 | |
| 1130 | 1130 | /** |
| 1131 | 1131 | * @since 2.2.10 |
@@ -1148,59 +1148,59 @@ discard block |
||
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | public static function insert_opt_html( $args ) { |
| 1151 | - $class = ''; |
|
| 1152 | - if ( in_array( $args['type'], array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) { |
|
| 1153 | - $class .= 'show_frm_not_email_to'; |
|
| 1154 | - } |
|
| 1155 | - ?> |
|
| 1151 | + $class = ''; |
|
| 1152 | + if ( in_array( $args['type'], array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) { |
|
| 1153 | + $class .= 'show_frm_not_email_to'; |
|
| 1154 | + } |
|
| 1155 | + ?> |
|
| 1156 | 1156 | <li> |
| 1157 | 1157 | <a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['id']) ?>" >[<?php echo esc_attr( $args['id'] ) ?>]</a> |
| 1158 | 1158 | <a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['key']) ?>" >[<?php echo esc_attr( self::truncate($args['key'], 10) ) ?>]</a> |
| 1159 | 1159 | <a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr($args['id']) ?>" ><?php echo esc_attr( self::truncate($args['name'], 60) ) ?></a> |
| 1160 | 1160 | </li> |
| 1161 | 1161 | <?php |
| 1162 | - } |
|
| 1162 | + } |
|
| 1163 | 1163 | |
| 1164 | 1164 | public static function truncate( $str, $length, $minword = 3, $continue = '...' ) { |
| 1165 | - if ( is_array( $str ) ) { |
|
| 1166 | - return ''; |
|
| 1165 | + if ( is_array( $str ) ) { |
|
| 1166 | + return ''; |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | - $length = (int) $length; |
|
| 1169 | + $length = (int) $length; |
|
| 1170 | 1170 | $str = wp_strip_all_tags( $str ); |
| 1171 | 1171 | $original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) ); |
| 1172 | 1172 | |
| 1173 | 1173 | if ( $length == 0 ) { |
| 1174 | - return ''; |
|
| 1175 | - } else if ( $length <= 10 ) { |
|
| 1174 | + return ''; |
|
| 1175 | + } else if ( $length <= 10 ) { |
|
| 1176 | 1176 | $sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) ); |
| 1177 | - return $sub . (($length < $original_len) ? $continue : ''); |
|
| 1178 | - } |
|
| 1177 | + return $sub . (($length < $original_len) ? $continue : ''); |
|
| 1178 | + } |
|
| 1179 | 1179 | |
| 1180 | - $sub = ''; |
|
| 1181 | - $len = 0; |
|
| 1180 | + $sub = ''; |
|
| 1181 | + $len = 0; |
|
| 1182 | 1182 | |
| 1183 | 1183 | $words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) ); |
| 1184 | 1184 | |
| 1185 | 1185 | foreach ( $words as $word ) { |
| 1186 | - $part = (($sub != '') ? ' ' : '') . $word; |
|
| 1186 | + $part = (($sub != '') ? ' ' : '') . $word; |
|
| 1187 | 1187 | $total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) ); |
| 1188 | - if ( $total_len > $length && str_word_count($sub) ) { |
|
| 1189 | - break; |
|
| 1190 | - } |
|
| 1188 | + if ( $total_len > $length && str_word_count($sub) ) { |
|
| 1189 | + break; |
|
| 1190 | + } |
|
| 1191 | 1191 | |
| 1192 | - $sub .= $part; |
|
| 1192 | + $sub .= $part; |
|
| 1193 | 1193 | $len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) ); |
| 1194 | 1194 | |
| 1195 | - if ( str_word_count($sub) > $minword && $total_len >= $length ) { |
|
| 1196 | - break; |
|
| 1197 | - } |
|
| 1195 | + if ( str_word_count($sub) > $minword && $total_len >= $length ) { |
|
| 1196 | + break; |
|
| 1197 | + } |
|
| 1198 | 1198 | |
| 1199 | - unset($total_len, $word); |
|
| 1200 | - } |
|
| 1199 | + unset($total_len, $word); |
|
| 1200 | + } |
|
| 1201 | 1201 | |
| 1202 | - return $sub . (($len < $original_len) ? $continue : ''); |
|
| 1203 | - } |
|
| 1202 | + return $sub . (($len < $original_len) ? $continue : ''); |
|
| 1203 | + } |
|
| 1204 | 1204 | |
| 1205 | 1205 | public static function mb_function( $function_names, $args ) { |
| 1206 | 1206 | $mb_function_name = $function_names[0]; |
@@ -1212,18 +1212,18 @@ discard block |
||
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | 1214 | public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) { |
| 1215 | - if ( empty($date) ) { |
|
| 1216 | - return $date; |
|
| 1217 | - } |
|
| 1215 | + if ( empty($date) ) { |
|
| 1216 | + return $date; |
|
| 1217 | + } |
|
| 1218 | 1218 | |
| 1219 | - if ( empty($date_format) ) { |
|
| 1220 | - $date_format = get_option('date_format'); |
|
| 1221 | - } |
|
| 1219 | + if ( empty($date_format) ) { |
|
| 1220 | + $date_format = get_option('date_format'); |
|
| 1221 | + } |
|
| 1222 | 1222 | |
| 1223 | - if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) { |
|
| 1224 | - $frmpro_settings = new FrmProSettings(); |
|
| 1225 | - $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d'); |
|
| 1226 | - } |
|
| 1223 | + if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) { |
|
| 1224 | + $frmpro_settings = new FrmProSettings(); |
|
| 1225 | + $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d'); |
|
| 1226 | + } |
|
| 1227 | 1227 | |
| 1228 | 1228 | $formatted = self::get_localized_date( $date_format, $date ); |
| 1229 | 1229 | |
@@ -1232,8 +1232,8 @@ discard block |
||
| 1232 | 1232 | $formatted .= self::add_time_to_date( $time_format, $date ); |
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | - return $formatted; |
|
| 1236 | - } |
|
| 1235 | + return $formatted; |
|
| 1236 | + } |
|
| 1237 | 1237 | |
| 1238 | 1238 | private static function add_time_to_date( $time_format, $date ) { |
| 1239 | 1239 | if ( empty( $time_format ) ) { |
@@ -1315,120 +1315,120 @@ discard block |
||
| 1315 | 1315 | ); |
| 1316 | 1316 | } |
| 1317 | 1317 | |
| 1318 | - // Pagination Methods |
|
| 1318 | + // Pagination Methods |
|
| 1319 | 1319 | |
| 1320 | - /** |
|
| 1321 | - * @param integer $current_p |
|
| 1322 | - */ |
|
| 1320 | + /** |
|
| 1321 | + * @param integer $current_p |
|
| 1322 | + */ |
|
| 1323 | 1323 | public static function get_last_record_num( $r_count, $current_p, $p_size ) { |
| 1324 | 1324 | return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) ); |
| 1325 | 1325 | } |
| 1326 | 1326 | |
| 1327 | - /** |
|
| 1328 | - * @param integer $current_p |
|
| 1329 | - */ |
|
| 1330 | - public static function get_first_record_num( $r_count, $current_p, $p_size ) { |
|
| 1331 | - if ( $current_p == 1 ) { |
|
| 1332 | - return 1; |
|
| 1333 | - } else { |
|
| 1334 | - return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 ); |
|
| 1335 | - } |
|
| 1336 | - } |
|
| 1327 | + /** |
|
| 1328 | + * @param integer $current_p |
|
| 1329 | + */ |
|
| 1330 | + public static function get_first_record_num( $r_count, $current_p, $p_size ) { |
|
| 1331 | + if ( $current_p == 1 ) { |
|
| 1332 | + return 1; |
|
| 1333 | + } else { |
|
| 1334 | + return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 ); |
|
| 1335 | + } |
|
| 1336 | + } |
|
| 1337 | 1337 | |
| 1338 | 1338 | /** |
| 1339 | 1339 | * @return array |
| 1340 | 1340 | */ |
| 1341 | 1341 | public static function json_to_array( $json_vars ) { |
| 1342 | - $vars = array(); |
|
| 1343 | - foreach ( $json_vars as $jv ) { |
|
| 1344 | - $jv_name = explode('[', $jv['name']); |
|
| 1345 | - $last = count($jv_name) - 1; |
|
| 1346 | - foreach ( $jv_name as $p => $n ) { |
|
| 1347 | - $name = trim($n, ']'); |
|
| 1348 | - if ( ! isset($l1) ) { |
|
| 1349 | - $l1 = $name; |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - if ( ! isset($l2) ) { |
|
| 1353 | - $l2 = $name; |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - if ( ! isset($l3) ) { |
|
| 1357 | - $l3 = $name; |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - $this_val = ( $p == $last ) ? $jv['value'] : array(); |
|
| 1361 | - |
|
| 1362 | - switch ( $p ) { |
|
| 1363 | - case 0: |
|
| 1364 | - $l1 = $name; |
|
| 1365 | - self::add_value_to_array( $name, $l1, $this_val, $vars ); |
|
| 1366 | - break; |
|
| 1367 | - |
|
| 1368 | - case 1: |
|
| 1369 | - $l2 = $name; |
|
| 1370 | - self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] ); |
|
| 1371 | - break; |
|
| 1372 | - |
|
| 1373 | - case 2: |
|
| 1374 | - $l3 = $name; |
|
| 1375 | - self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] ); |
|
| 1376 | - break; |
|
| 1377 | - |
|
| 1378 | - case 3: |
|
| 1379 | - $l4 = $name; |
|
| 1380 | - self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] ); |
|
| 1381 | - break; |
|
| 1382 | - } |
|
| 1383 | - |
|
| 1384 | - unset($this_val, $n); |
|
| 1385 | - } |
|
| 1386 | - |
|
| 1387 | - unset($last, $jv); |
|
| 1388 | - } |
|
| 1389 | - |
|
| 1390 | - return $vars; |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - /** |
|
| 1394 | - * @param string $name |
|
| 1395 | - * @param string $l1 |
|
| 1396 | - */ |
|
| 1397 | - public static function add_value_to_array( $name, $l1, $val, &$vars ) { |
|
| 1398 | - if ( $name == '' ) { |
|
| 1399 | - $vars[] = $val; |
|
| 1400 | - } else if ( ! isset( $vars[ $l1 ] ) ) { |
|
| 1401 | - $vars[ $l1 ] = $val; |
|
| 1402 | - } |
|
| 1403 | - } |
|
| 1342 | + $vars = array(); |
|
| 1343 | + foreach ( $json_vars as $jv ) { |
|
| 1344 | + $jv_name = explode('[', $jv['name']); |
|
| 1345 | + $last = count($jv_name) - 1; |
|
| 1346 | + foreach ( $jv_name as $p => $n ) { |
|
| 1347 | + $name = trim($n, ']'); |
|
| 1348 | + if ( ! isset($l1) ) { |
|
| 1349 | + $l1 = $name; |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + if ( ! isset($l2) ) { |
|
| 1353 | + $l2 = $name; |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + if ( ! isset($l3) ) { |
|
| 1357 | + $l3 = $name; |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + $this_val = ( $p == $last ) ? $jv['value'] : array(); |
|
| 1361 | + |
|
| 1362 | + switch ( $p ) { |
|
| 1363 | + case 0: |
|
| 1364 | + $l1 = $name; |
|
| 1365 | + self::add_value_to_array( $name, $l1, $this_val, $vars ); |
|
| 1366 | + break; |
|
| 1367 | + |
|
| 1368 | + case 1: |
|
| 1369 | + $l2 = $name; |
|
| 1370 | + self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] ); |
|
| 1371 | + break; |
|
| 1372 | + |
|
| 1373 | + case 2: |
|
| 1374 | + $l3 = $name; |
|
| 1375 | + self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] ); |
|
| 1376 | + break; |
|
| 1377 | + |
|
| 1378 | + case 3: |
|
| 1379 | + $l4 = $name; |
|
| 1380 | + self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] ); |
|
| 1381 | + break; |
|
| 1382 | + } |
|
| 1383 | + |
|
| 1384 | + unset($this_val, $n); |
|
| 1385 | + } |
|
| 1386 | + |
|
| 1387 | + unset($last, $jv); |
|
| 1388 | + } |
|
| 1389 | + |
|
| 1390 | + return $vars; |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + /** |
|
| 1394 | + * @param string $name |
|
| 1395 | + * @param string $l1 |
|
| 1396 | + */ |
|
| 1397 | + public static function add_value_to_array( $name, $l1, $val, &$vars ) { |
|
| 1398 | + if ( $name == '' ) { |
|
| 1399 | + $vars[] = $val; |
|
| 1400 | + } else if ( ! isset( $vars[ $l1 ] ) ) { |
|
| 1401 | + $vars[ $l1 ] = $val; |
|
| 1402 | + } |
|
| 1403 | + } |
|
| 1404 | 1404 | |
| 1405 | 1405 | public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) { |
| 1406 | - $tooltips = array( |
|
| 1407 | - 'action_title' => __( 'Give this action a label for easy reference.', 'formidable' ), |
|
| 1408 | - 'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <[email protected]> or [email protected]. [admin_email] is the address set in WP General Settings.', 'formidable' ), |
|
| 1409 | - 'cc' => __( 'Add CC addresses separated by a ",". FORMAT: Name <[email protected]> or [email protected].', 'formidable' ), |
|
| 1410 | - 'bcc' => __( 'Add BCC addresses separated by a ",". FORMAT: Name <[email protected]> or [email protected].', 'formidable' ), |
|
| 1411 | - 'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <[email protected]> or [email protected].', 'formidable' ), |
|
| 1412 | - 'from' => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ), |
|
| 1413 | - 'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ), |
|
| 1414 | - ); |
|
| 1415 | - |
|
| 1416 | - if ( ! isset( $tooltips[ $name ] ) ) { |
|
| 1417 | - return; |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - if ( 'open' == $class ) { |
|
| 1421 | - echo ' frm_help"'; |
|
| 1422 | - } else { |
|
| 1423 | - echo ' class="frm_help"'; |
|
| 1424 | - } |
|
| 1406 | + $tooltips = array( |
|
| 1407 | + 'action_title' => __( 'Give this action a label for easy reference.', 'formidable' ), |
|
| 1408 | + 'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <[email protected]> or [email protected]. [admin_email] is the address set in WP General Settings.', 'formidable' ), |
|
| 1409 | + 'cc' => __( 'Add CC addresses separated by a ",". FORMAT: Name <[email protected]> or [email protected].', 'formidable' ), |
|
| 1410 | + 'bcc' => __( 'Add BCC addresses separated by a ",". FORMAT: Name <[email protected]> or [email protected].', 'formidable' ), |
|
| 1411 | + 'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <[email protected]> or [email protected].', 'formidable' ), |
|
| 1412 | + 'from' => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ), |
|
| 1413 | + 'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ), |
|
| 1414 | + ); |
|
| 1415 | + |
|
| 1416 | + if ( ! isset( $tooltips[ $name ] ) ) { |
|
| 1417 | + return; |
|
| 1418 | + } |
|
| 1419 | + |
|
| 1420 | + if ( 'open' == $class ) { |
|
| 1421 | + echo ' frm_help"'; |
|
| 1422 | + } else { |
|
| 1423 | + echo ' class="frm_help"'; |
|
| 1424 | + } |
|
| 1425 | 1425 | |
| 1426 | 1426 | echo ' title="' . esc_attr( $tooltips[ $name ] ); |
| 1427 | 1427 | |
| 1428 | - if ( 'open' != $class ) { |
|
| 1429 | - echo '"'; |
|
| 1430 | - } |
|
| 1431 | - } |
|
| 1428 | + if ( 'open' != $class ) { |
|
| 1429 | + echo '"'; |
|
| 1430 | + } |
|
| 1431 | + } |
|
| 1432 | 1432 | |
| 1433 | 1433 | /** |
| 1434 | 1434 | * Add the current_page class to that page in the form nav |
@@ -1444,35 +1444,35 @@ discard block |
||
| 1444 | 1444 | } |
| 1445 | 1445 | } |
| 1446 | 1446 | |
| 1447 | - /** |
|
| 1448 | - * Prepare and json_encode post content |
|
| 1449 | - * |
|
| 1450 | - * @since 2.0 |
|
| 1451 | - * |
|
| 1452 | - * @param array $post_content |
|
| 1453 | - * @return string $post_content ( json encoded array ) |
|
| 1454 | - */ |
|
| 1455 | - public static function prepare_and_encode( $post_content ) { |
|
| 1456 | - //Loop through array to strip slashes and add only the needed ones |
|
| 1447 | + /** |
|
| 1448 | + * Prepare and json_encode post content |
|
| 1449 | + * |
|
| 1450 | + * @since 2.0 |
|
| 1451 | + * |
|
| 1452 | + * @param array $post_content |
|
| 1453 | + * @return string $post_content ( json encoded array ) |
|
| 1454 | + */ |
|
| 1455 | + public static function prepare_and_encode( $post_content ) { |
|
| 1456 | + //Loop through array to strip slashes and add only the needed ones |
|
| 1457 | 1457 | foreach ( $post_content as $key => $val ) { |
| 1458 | 1458 | // Replace problematic characters (like ") |
| 1459 | 1459 | $val = str_replace( '"', '"', $val ); |
| 1460 | 1460 | |
| 1461 | 1461 | self::prepare_action_slashes( $val, $key, $post_content ); |
| 1462 | - unset( $key, $val ); |
|
| 1463 | - } |
|
| 1462 | + unset( $key, $val ); |
|
| 1463 | + } |
|
| 1464 | 1464 | |
| 1465 | - // json_encode the array |
|
| 1466 | - $post_content = json_encode( $post_content ); |
|
| 1465 | + // json_encode the array |
|
| 1466 | + $post_content = json_encode( $post_content ); |
|
| 1467 | 1467 | |
| 1468 | - // add extra slashes for \r\n since WP strips them |
|
| 1468 | + // add extra slashes for \r\n since WP strips them |
|
| 1469 | 1469 | $post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content ); |
| 1470 | 1470 | |
| 1471 | - // allow for " |
|
| 1472 | - $post_content = str_replace( '"', '\\"', $post_content ); |
|
| 1471 | + // allow for " |
|
| 1472 | + $post_content = str_replace( '"', '\\"', $post_content ); |
|
| 1473 | 1473 | |
| 1474 | - return $post_content; |
|
| 1475 | - } |
|
| 1474 | + return $post_content; |
|
| 1475 | + } |
|
| 1476 | 1476 | |
| 1477 | 1477 | private static function prepare_action_slashes( $val, $key, &$post_content ) { |
| 1478 | 1478 | if ( ! isset( $post_content[ $key ] ) ) { |
@@ -1494,64 +1494,64 @@ discard block |
||
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | 1496 | public static function maybe_json_decode( $string ) { |
| 1497 | - if ( is_array($string) ) { |
|
| 1498 | - return $string; |
|
| 1499 | - } |
|
| 1497 | + if ( is_array($string) ) { |
|
| 1498 | + return $string; |
|
| 1499 | + } |
|
| 1500 | 1500 | |
| 1501 | - $new_string = json_decode($string, true); |
|
| 1502 | - if ( function_exists('json_last_error') ) { |
|
| 1501 | + $new_string = json_decode($string, true); |
|
| 1502 | + if ( function_exists('json_last_error') ) { |
|
| 1503 | 1503 | // php 5.3+ |
| 1504 | - if ( json_last_error() == JSON_ERROR_NONE ) { |
|
| 1505 | - $string = $new_string; |
|
| 1506 | - } |
|
| 1507 | - } else if ( isset($new_string) ) { |
|
| 1504 | + if ( json_last_error() == JSON_ERROR_NONE ) { |
|
| 1505 | + $string = $new_string; |
|
| 1506 | + } |
|
| 1507 | + } else if ( isset($new_string) ) { |
|
| 1508 | 1508 | // php < 5.3 fallback |
| 1509 | - $string = $new_string; |
|
| 1510 | - } |
|
| 1511 | - return $string; |
|
| 1512 | - } |
|
| 1513 | - |
|
| 1514 | - /** |
|
| 1515 | - * @since 1.07.10 |
|
| 1516 | - * |
|
| 1517 | - * @param string $post_type The name of the post type that may need to be highlighted |
|
| 1518 | - * echo The javascript to open and highlight the Formidable menu |
|
| 1519 | - */ |
|
| 1509 | + $string = $new_string; |
|
| 1510 | + } |
|
| 1511 | + return $string; |
|
| 1512 | + } |
|
| 1513 | + |
|
| 1514 | + /** |
|
| 1515 | + * @since 1.07.10 |
|
| 1516 | + * |
|
| 1517 | + * @param string $post_type The name of the post type that may need to be highlighted |
|
| 1518 | + * echo The javascript to open and highlight the Formidable menu |
|
| 1519 | + */ |
|
| 1520 | 1520 | public static function maybe_highlight_menu( $post_type ) { |
| 1521 | - global $post; |
|
| 1521 | + global $post; |
|
| 1522 | 1522 | |
| 1523 | - if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) { |
|
| 1524 | - return; |
|
| 1525 | - } |
|
| 1523 | + if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) { |
|
| 1524 | + return; |
|
| 1525 | + } |
|
| 1526 | 1526 | |
| 1527 | - if ( is_object($post) && $post->post_type != $post_type ) { |
|
| 1528 | - return; |
|
| 1529 | - } |
|
| 1527 | + if ( is_object($post) && $post->post_type != $post_type ) { |
|
| 1528 | + return; |
|
| 1529 | + } |
|
| 1530 | 1530 | |
| 1531 | - self::load_admin_wide_js(); |
|
| 1532 | - echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>'; |
|
| 1533 | - } |
|
| 1531 | + self::load_admin_wide_js(); |
|
| 1532 | + echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>'; |
|
| 1533 | + } |
|
| 1534 | 1534 | |
| 1535 | - /** |
|
| 1536 | - * Load the JS file on non-Formidable pages in the admin area |
|
| 1537 | - * @since 2.0 |
|
| 1538 | - */ |
|
| 1535 | + /** |
|
| 1536 | + * Load the JS file on non-Formidable pages in the admin area |
|
| 1537 | + * @since 2.0 |
|
| 1538 | + */ |
|
| 1539 | 1539 | public static function load_admin_wide_js( $load = true ) { |
| 1540 | - $version = FrmAppHelper::plugin_version(); |
|
| 1540 | + $version = FrmAppHelper::plugin_version(); |
|
| 1541 | 1541 | wp_register_script( 'formidable_admin_global', FrmAppHelper::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version ); |
| 1542 | 1542 | |
| 1543 | - wp_localize_script( 'formidable_admin_global', 'frmGlobal', array( |
|
| 1543 | + wp_localize_script( 'formidable_admin_global', 'frmGlobal', array( |
|
| 1544 | 1544 | 'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ), |
| 1545 | - 'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ), |
|
| 1545 | + 'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ), |
|
| 1546 | 1546 | 'url' => FrmAppHelper::plugin_url(), |
| 1547 | 1547 | 'loading' => __( 'Loading…' ), |
| 1548 | 1548 | 'nonce' => wp_create_nonce( 'frm_ajax' ), |
| 1549 | - ) ); |
|
| 1549 | + ) ); |
|
| 1550 | 1550 | |
| 1551 | 1551 | if ( $load ) { |
| 1552 | 1552 | wp_enqueue_script( 'formidable_admin_global' ); |
| 1553 | 1553 | } |
| 1554 | - } |
|
| 1554 | + } |
|
| 1555 | 1555 | |
| 1556 | 1556 | /** |
| 1557 | 1557 | * @since 2.0.9 |
@@ -1560,9 +1560,9 @@ discard block |
||
| 1560 | 1560 | wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() ); |
| 1561 | 1561 | } |
| 1562 | 1562 | |
| 1563 | - /** |
|
| 1564 | - * @param string $location |
|
| 1565 | - */ |
|
| 1563 | + /** |
|
| 1564 | + * @param string $location |
|
| 1565 | + */ |
|
| 1566 | 1566 | public static function localize_script( $location ) { |
| 1567 | 1567 | $ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' ); |
| 1568 | 1568 | $ajax_url = apply_filters( 'frm_ajax_url', $ajax_url ); |
@@ -1618,83 +1618,83 @@ discard block |
||
| 1618 | 1618 | } |
| 1619 | 1619 | } |
| 1620 | 1620 | |
| 1621 | - /** |
|
| 1621 | + /** |
|
| 1622 | 1622 | * echo the message on the plugins listing page |
| 1623 | - * @since 1.07.10 |
|
| 1624 | - * |
|
| 1625 | - * @param float $min_version The version the add-on requires |
|
| 1626 | - */ |
|
| 1623 | + * @since 1.07.10 |
|
| 1624 | + * |
|
| 1625 | + * @param float $min_version The version the add-on requires |
|
| 1626 | + */ |
|
| 1627 | 1627 | public static function min_version_notice( $min_version ) { |
| 1628 | - $frm_version = self::plugin_version(); |
|
| 1628 | + $frm_version = self::plugin_version(); |
|
| 1629 | 1629 | |
| 1630 | - // check if Formidable meets minimum requirements |
|
| 1631 | - if ( version_compare($frm_version, $min_version, '>=') ) { |
|
| 1632 | - return; |
|
| 1633 | - } |
|
| 1630 | + // check if Formidable meets minimum requirements |
|
| 1631 | + if ( version_compare($frm_version, $min_version, '>=') ) { |
|
| 1632 | + return; |
|
| 1633 | + } |
|
| 1634 | 1634 | |
| 1635 | - $wp_list_table = _get_list_table('WP_Plugins_List_Table'); |
|
| 1635 | + $wp_list_table = _get_list_table('WP_Plugins_List_Table'); |
|
| 1636 | 1636 | echo '<tr class="plugin-update-tr active"><th colspan="' . absint( $wp_list_table->get_column_count() ) . '" class="check-column plugin-update colspanchange"><div class="update-message">' . |
| 1637 | - __( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) . |
|
| 1638 | - '</div></td></tr>'; |
|
| 1639 | - } |
|
| 1640 | - |
|
| 1641 | - public static function locales( $type = 'date' ) { |
|
| 1642 | - $locales = array( |
|
| 1643 | - 'en' => __( 'English', 'formidable' ), '' => __( 'English/Western', 'formidable' ), |
|
| 1644 | - 'af' => __( 'Afrikaans', 'formidable' ), 'sq' => __( 'Albanian', 'formidable' ), |
|
| 1645 | - 'ar' => __( 'Arabic', 'formidable' ), 'hy' => __( 'Armenian', 'formidable' ), |
|
| 1646 | - 'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ), |
|
| 1647 | - 'bs' => __( 'Bosnian', 'formidable' ), 'bg' => __( 'Bulgarian', 'formidable' ), |
|
| 1648 | - 'ca' => __( 'Catalan', 'formidable' ), 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ), |
|
| 1649 | - 'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ), |
|
| 1650 | - 'hr' => __( 'Croatian', 'formidable' ), 'cs' => __( 'Czech', 'formidable' ), |
|
| 1651 | - 'da' => __( 'Danish', 'formidable' ), 'nl' => __( 'Dutch', 'formidable' ), |
|
| 1652 | - 'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ), |
|
| 1653 | - 'et' => __( 'Estonian', 'formidable' ), 'fo' => __( 'Faroese', 'formidable' ), |
|
| 1654 | - 'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ), |
|
| 1655 | - 'fi' => __( 'Finnish', 'formidable' ), 'fr' => __( 'French', 'formidable' ), |
|
| 1656 | - 'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ), |
|
| 1657 | - 'de' => __( 'German', 'formidable' ), 'de-AT' => __( 'German/Austria', 'formidable' ), |
|
| 1658 | - 'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ), |
|
| 1659 | - 'he' => __( 'Hebrew', 'formidable' ), 'iw' => __( 'Hebrew', 'formidable' ), |
|
| 1660 | - 'hi' => __( 'Hindi', 'formidable' ), 'hu' => __( 'Hungarian', 'formidable' ), |
|
| 1661 | - 'is' => __( 'Icelandic', 'formidable' ), 'id' => __( 'Indonesian', 'formidable' ), |
|
| 1662 | - 'it' => __( 'Italian', 'formidable' ), 'ja' => __( 'Japanese', 'formidable' ), |
|
| 1663 | - 'ko' => __( 'Korean', 'formidable' ), 'lv' => __( 'Latvian', 'formidable' ), |
|
| 1664 | - 'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ), |
|
| 1665 | - 'no' => __( 'Norwegian', 'formidable' ), 'pl' => __( 'Polish', 'formidable' ), |
|
| 1666 | - 'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ), |
|
| 1667 | - 'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ), |
|
| 1668 | - 'ru' => __( 'Russian', 'formidable' ), 'sr' => __( 'Serbian', 'formidable' ), |
|
| 1669 | - 'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ), |
|
| 1670 | - 'sl' => __( 'Slovenian', 'formidable' ), 'es' => __( 'Spanish', 'formidable' ), |
|
| 1671 | - 'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ), |
|
| 1672 | - 'ta' => __( 'Tamil', 'formidable' ), 'th' => __( 'Thai', 'formidable' ), |
|
| 1673 | - 'tu' => __( 'Turkish', 'formidable' ), 'tr' => __( 'Turkish', 'formidable' ), |
|
| 1674 | - 'uk' => __( 'Ukranian', 'formidable' ), 'vi' => __( 'Vietnamese', 'formidable' ), |
|
| 1675 | - ); |
|
| 1676 | - |
|
| 1677 | - if ( $type == 'captcha' ) { |
|
| 1678 | - // remove the languages unavailable for the captcha |
|
| 1679 | - $unset = array( |
|
| 1680 | - '', 'af', 'sq', 'hy', 'az', 'eu', 'bs', |
|
| 1681 | - 'zh-HK', 'eo', 'et', 'fo', 'fr-CH', |
|
| 1682 | - 'he', 'is', 'ms', 'sr-SR', 'ta', 'tu', |
|
| 1683 | - ); |
|
| 1684 | - } else { |
|
| 1685 | - // remove the languages unavailable for the datepicker |
|
| 1686 | - $unset = array( |
|
| 1687 | - 'en', 'fil', 'fr-CA', 'de-AT', 'de-AT', |
|
| 1688 | - 'de-CH', 'iw', 'hi', 'pt', 'pt-PT', |
|
| 1689 | - 'es-419', 'tr', |
|
| 1690 | - ); |
|
| 1691 | - } |
|
| 1692 | - |
|
| 1693 | - $locales = array_diff_key($locales, array_flip($unset)); |
|
| 1694 | - $locales = apply_filters('frm_locales', $locales); |
|
| 1695 | - |
|
| 1696 | - return $locales; |
|
| 1697 | - } |
|
| 1637 | + __( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) . |
|
| 1638 | + '</div></td></tr>'; |
|
| 1639 | + } |
|
| 1640 | + |
|
| 1641 | + public static function locales( $type = 'date' ) { |
|
| 1642 | + $locales = array( |
|
| 1643 | + 'en' => __( 'English', 'formidable' ), '' => __( 'English/Western', 'formidable' ), |
|
| 1644 | + 'af' => __( 'Afrikaans', 'formidable' ), 'sq' => __( 'Albanian', 'formidable' ), |
|
| 1645 | + 'ar' => __( 'Arabic', 'formidable' ), 'hy' => __( 'Armenian', 'formidable' ), |
|
| 1646 | + 'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ), |
|
| 1647 | + 'bs' => __( 'Bosnian', 'formidable' ), 'bg' => __( 'Bulgarian', 'formidable' ), |
|
| 1648 | + 'ca' => __( 'Catalan', 'formidable' ), 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ), |
|
| 1649 | + 'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ), |
|
| 1650 | + 'hr' => __( 'Croatian', 'formidable' ), 'cs' => __( 'Czech', 'formidable' ), |
|
| 1651 | + 'da' => __( 'Danish', 'formidable' ), 'nl' => __( 'Dutch', 'formidable' ), |
|
| 1652 | + 'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ), |
|
| 1653 | + 'et' => __( 'Estonian', 'formidable' ), 'fo' => __( 'Faroese', 'formidable' ), |
|
| 1654 | + 'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ), |
|
| 1655 | + 'fi' => __( 'Finnish', 'formidable' ), 'fr' => __( 'French', 'formidable' ), |
|
| 1656 | + 'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ), |
|
| 1657 | + 'de' => __( 'German', 'formidable' ), 'de-AT' => __( 'German/Austria', 'formidable' ), |
|
| 1658 | + 'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ), |
|
| 1659 | + 'he' => __( 'Hebrew', 'formidable' ), 'iw' => __( 'Hebrew', 'formidable' ), |
|
| 1660 | + 'hi' => __( 'Hindi', 'formidable' ), 'hu' => __( 'Hungarian', 'formidable' ), |
|
| 1661 | + 'is' => __( 'Icelandic', 'formidable' ), 'id' => __( 'Indonesian', 'formidable' ), |
|
| 1662 | + 'it' => __( 'Italian', 'formidable' ), 'ja' => __( 'Japanese', 'formidable' ), |
|
| 1663 | + 'ko' => __( 'Korean', 'formidable' ), 'lv' => __( 'Latvian', 'formidable' ), |
|
| 1664 | + 'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ), |
|
| 1665 | + 'no' => __( 'Norwegian', 'formidable' ), 'pl' => __( 'Polish', 'formidable' ), |
|
| 1666 | + 'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ), |
|
| 1667 | + 'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ), |
|
| 1668 | + 'ru' => __( 'Russian', 'formidable' ), 'sr' => __( 'Serbian', 'formidable' ), |
|
| 1669 | + 'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ), |
|
| 1670 | + 'sl' => __( 'Slovenian', 'formidable' ), 'es' => __( 'Spanish', 'formidable' ), |
|
| 1671 | + 'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ), |
|
| 1672 | + 'ta' => __( 'Tamil', 'formidable' ), 'th' => __( 'Thai', 'formidable' ), |
|
| 1673 | + 'tu' => __( 'Turkish', 'formidable' ), 'tr' => __( 'Turkish', 'formidable' ), |
|
| 1674 | + 'uk' => __( 'Ukranian', 'formidable' ), 'vi' => __( 'Vietnamese', 'formidable' ), |
|
| 1675 | + ); |
|
| 1676 | + |
|
| 1677 | + if ( $type == 'captcha' ) { |
|
| 1678 | + // remove the languages unavailable for the captcha |
|
| 1679 | + $unset = array( |
|
| 1680 | + '', 'af', 'sq', 'hy', 'az', 'eu', 'bs', |
|
| 1681 | + 'zh-HK', 'eo', 'et', 'fo', 'fr-CH', |
|
| 1682 | + 'he', 'is', 'ms', 'sr-SR', 'ta', 'tu', |
|
| 1683 | + ); |
|
| 1684 | + } else { |
|
| 1685 | + // remove the languages unavailable for the datepicker |
|
| 1686 | + $unset = array( |
|
| 1687 | + 'en', 'fil', 'fr-CA', 'de-AT', 'de-AT', |
|
| 1688 | + 'de-CH', 'iw', 'hi', 'pt', 'pt-PT', |
|
| 1689 | + 'es-419', 'tr', |
|
| 1690 | + ); |
|
| 1691 | + } |
|
| 1692 | + |
|
| 1693 | + $locales = array_diff_key($locales, array_flip($unset)); |
|
| 1694 | + $locales = apply_filters('frm_locales', $locales); |
|
| 1695 | + |
|
| 1696 | + return $locales; |
|
| 1697 | + } |
|
| 1698 | 1698 | |
| 1699 | 1699 | /** |
| 1700 | 1700 | * Prepare and save settings in styles and actions |
@@ -1725,19 +1725,19 @@ discard block |
||
| 1725 | 1725 | return FrmDb::save_json_post( $settings ); |
| 1726 | 1726 | } |
| 1727 | 1727 | |
| 1728 | - /** |
|
| 1729 | - * Check cache before fetching values and saving to cache |
|
| 1730 | - * |
|
| 1731 | - * @since 2.0 |
|
| 1728 | + /** |
|
| 1729 | + * Check cache before fetching values and saving to cache |
|
| 1730 | + * |
|
| 1731 | + * @since 2.0 |
|
| 1732 | 1732 | * @deprecated 2.06 |
| 1733 | - * |
|
| 1734 | - * @param string $cache_key The unique name for this cache |
|
| 1735 | - * @param string $group The name of the cache group |
|
| 1736 | - * @param string $query If blank, don't run a db call |
|
| 1737 | - * @param string $type The wpdb function to use with this query |
|
| 1738 | - * @return mixed $results The cache or query results |
|
| 1739 | - */ |
|
| 1740 | - public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) { |
|
| 1733 | + * |
|
| 1734 | + * @param string $cache_key The unique name for this cache |
|
| 1735 | + * @param string $group The name of the cache group |
|
| 1736 | + * @param string $query If blank, don't run a db call |
|
| 1737 | + * @param string $type The wpdb function to use with this query |
|
| 1738 | + * @return mixed $results The cache or query results |
|
| 1739 | + */ |
|
| 1740 | + public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) { |
|
| 1741 | 1741 | _deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ ); |
| 1742 | 1742 | return FrmDb::check_cache( $cache_key, $group, $query, $type, $time ); |
| 1743 | 1743 | } |
@@ -1765,32 +1765,32 @@ discard block |
||
| 1765 | 1765 | return FrmDb::get_group_cached_keys( $group ); |
| 1766 | 1766 | } |
| 1767 | 1767 | |
| 1768 | - /** |
|
| 1769 | - * @since 2.0 |
|
| 1768 | + /** |
|
| 1769 | + * @since 2.0 |
|
| 1770 | 1770 | * @deprecated 2.06 |
| 1771 | - * @return mixed The cached value or false |
|
| 1772 | - */ |
|
| 1771 | + * @return mixed The cached value or false |
|
| 1772 | + */ |
|
| 1773 | 1773 | public static function check_cache_and_transient( $cache_key ) { |
| 1774 | 1774 | _deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ ); |
| 1775 | 1775 | return FrmDb::check_cache( $cache_key ); |
| 1776 | - } |
|
| 1776 | + } |
|
| 1777 | 1777 | |
| 1778 | - /** |
|
| 1779 | - * @since 2.0 |
|
| 1778 | + /** |
|
| 1779 | + * @since 2.0 |
|
| 1780 | 1780 | * @deprecated 2.06 |
| 1781 | - * @param string $cache_key |
|
| 1782 | - */ |
|
| 1781 | + * @param string $cache_key |
|
| 1782 | + */ |
|
| 1783 | 1783 | public static function delete_cache_and_transient( $cache_key, $group = 'default' ) { |
| 1784 | 1784 | _deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ ); |
| 1785 | 1785 | FrmDb::delete_cache_and_transient( $cache_key, $group ); |
| 1786 | 1786 | } |
| 1787 | 1787 | |
| 1788 | - /** |
|
| 1789 | - * @since 2.0 |
|
| 1788 | + /** |
|
| 1789 | + * @since 2.0 |
|
| 1790 | 1790 | * @deprecated 2.06 |
| 1791 | - * |
|
| 1792 | - * @param string $group The name of the cache group |
|
| 1793 | - */ |
|
| 1791 | + * |
|
| 1792 | + * @param string $group The name of the cache group |
|
| 1793 | + */ |
|
| 1794 | 1794 | public static function cache_delete_group( $group ) { |
| 1795 | 1795 | _deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ ); |
| 1796 | 1796 | FrmDb::cache_delete_group( $group ); |