@@ -3,7 +3,7 @@ |
||
| 3 | 3 | class FrmDefPostAction extends FrmFormAction { |
| 4 | 4 | public function __construct() { |
| 5 | 5 | $action_ops = FrmFormAction::default_action_opts(); |
| 6 | - $action_ops['classes'] = 'ab-icon frm_dashicon_font dashicons-before'; |
|
| 6 | + $action_ops['classes'] = 'ab-icon frm_dashicon_font dashicons-before'; |
|
| 7 | 7 | |
| 8 | 8 | parent::__construct( 'wppost', __( 'Create Post', 'formidable' ), $action_ops ); |
| 9 | 9 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! $item_ids ) { |
| 4 | - return; |
|
| 4 | + return; |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | // fetch 20 posts at a time rather than loading the entire table into memory |
@@ -45,6 +45,6 @@ discard block |
||
| 45 | 45 | <?php } ?> |
| 46 | 46 | </form> |
| 47 | 47 | <?php |
| 48 | - unset( $fields ); |
|
| 48 | + unset( $fields ); |
|
| 49 | 49 | } |
| 50 | 50 | } |
@@ -181,13 +181,13 @@ |
||
| 181 | 181 | ), |
| 182 | 182 | ); |
| 183 | 183 | $random = rand( 0, count( $tips ) - 1 ); |
| 184 | - $tip = $tips[ $random ]; |
|
| 184 | + $tip = $tips[$random]; |
|
| 185 | 185 | $tip['num'] = $random; |
| 186 | 186 | return $tip; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | public static function get_random_tip( $tips ) { |
| 190 | 190 | $random = rand( 0, count( $tips ) - 1 ); |
| 191 | - return $tips[ $random ]; |
|
| 191 | + return $tips[$random]; |
|
| 192 | 192 | } |
| 193 | 193 | } |
@@ -308,7 +308,7 @@ |
||
| 308 | 308 | * |
| 309 | 309 | * @since 2.02.05 |
| 310 | 310 | * @param string $key |
| 311 | - * @param int|string $value |
|
| 311 | + * @param string $value |
|
| 312 | 312 | * @param string $where |
| 313 | 313 | */ |
| 314 | 314 | private static function add_query_placeholder( $key, $value, &$where ) { |
@@ -1,31 +1,31 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class FrmDb { |
| 4 | - public $fields; |
|
| 5 | - public $forms; |
|
| 6 | - public $entries; |
|
| 7 | - public $entry_metas; |
|
| 4 | + public $fields; |
|
| 5 | + public $forms; |
|
| 6 | + public $entries; |
|
| 7 | + public $entry_metas; |
|
| 8 | 8 | |
| 9 | - public function __construct() { |
|
| 9 | + public function __construct() { |
|
| 10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | 11 | die( 'You are not allowed to call this page directly.' ); |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | _deprecated_function( __METHOD__, '2.05.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 ' ) { |
|
| 27 | + */ |
|
| 28 | + public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) { |
|
| 29 | 29 | if ( empty( $args ) ) { |
| 30 | 30 | // add an arg to prevent prepare from failing |
| 31 | 31 | $args = array( |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | 'values' => array( 1 ), |
| 34 | 34 | ); |
| 35 | 35 | return; |
| 36 | - } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | $where = ''; |
| 39 | 39 | $values = array(); |
@@ -44,20 +44,20 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $args = compact( 'where', 'values' ); |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | + /** |
|
| 50 | 50 | * @param array $args |
| 51 | - * @param string $base_where |
|
| 52 | - * @param string $where |
|
| 51 | + * @param string $base_where |
|
| 52 | + * @param string $where |
|
| 53 | 53 | * @param array $values |
| 54 | - */ |
|
| 55 | - public static function parse_where_from_array( $args, $base_where, &$where, &$values ) { |
|
| 56 | - $condition = ' AND'; |
|
| 57 | - if ( isset( $args['or'] ) ) { |
|
| 58 | - $condition = ' OR'; |
|
| 59 | - unset( $args['or'] ); |
|
| 60 | - } |
|
| 54 | + */ |
|
| 55 | + public static function parse_where_from_array( $args, $base_where, &$where, &$values ) { |
|
| 56 | + $condition = ' AND'; |
|
| 57 | + if ( isset( $args['or'] ) ) { |
|
| 58 | + $condition = ' OR'; |
|
| 59 | + unset( $args['or'] ); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | foreach ( $args as $key => $value ) { |
| 63 | 63 | $where .= empty( $where ) ? $base_where : $condition; |
@@ -84,28 +84,28 @@ discard block |
||
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @param string $key |
|
| 87 | + /** |
|
| 88 | + * @param string $key |
|
| 89 | 89 | * @param string|array $value |
| 90 | - * @param string $where |
|
| 90 | + * @param string $where |
|
| 91 | 91 | * @param array $values |
| 92 | - */ |
|
| 93 | - private static function interpret_array_to_sql( $key, $value, &$where, &$values ) { |
|
| 92 | + */ |
|
| 93 | + private static function interpret_array_to_sql( $key, $value, &$where, &$values ) { |
|
| 94 | 94 | $key = trim( $key ); |
| 95 | 95 | |
| 96 | 96 | if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) { |
| 97 | 97 | $k = explode( ' ', $key ); |
| 98 | - $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key ); |
|
| 99 | - $values[] = '%Y-%m-%d %H:%i:%s'; |
|
| 100 | - } else { |
|
| 98 | + $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key ); |
|
| 99 | + $values[] = '%Y-%m-%d %H:%i:%s'; |
|
| 100 | + } else { |
|
| 101 | 101 | $where .= ' ' . $key; |
| 102 | - } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | $lowercase_key = explode( ' ', strtolower( $key ) ); |
| 105 | 105 | $lowercase_key = end( $lowercase_key ); |
| 106 | 106 | |
| 107 | - if ( is_array( $value ) ) { |
|
| 108 | - // translate array of values to "in" |
|
| 107 | + if ( is_array( $value ) ) { |
|
| 108 | + // translate array of values to "in" |
|
| 109 | 109 | if ( strpos( $lowercase_key, 'like' ) !== false ) { |
| 110 | 110 | $where = preg_replace( '/' . $key . '$/', '', $where ); |
| 111 | 111 | $where .= '('; |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | $where .= ' in (' . self::prepare_array_values( $value, '%s' ) . ')'; |
| 124 | 124 | $values = array_merge( $values, $value ); |
| 125 | 125 | } |
| 126 | - } else if ( strpos( $lowercase_key, 'like' ) !== false ) { |
|
| 126 | + } else if ( strpos( $lowercase_key, 'like' ) !== false ) { |
|
| 127 | 127 | /** |
| 128 | 128 | * Allow string to start or end with the value |
| 129 | 129 | * If the key is like% then skip the first % for starts with |
@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | $where .= ' %s'; |
| 144 | 144 | $values[] = $start . self::esc_like( $value ) . $end; |
| 145 | 145 | |
| 146 | - } else if ( $value === null ) { |
|
| 147 | - $where .= ' IS NULL'; |
|
| 148 | - } else { |
|
| 146 | + } else if ( $value === null ) { |
|
| 147 | + $where .= ' IS NULL'; |
|
| 148 | + } else { |
|
| 149 | 149 | // allow a - to prevent = from being added |
| 150 | 150 | if ( substr( $key, -1 ) == '-' ) { |
| 151 | 151 | $where = rtrim( $where, '-' ); |
@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | self::add_query_placeholder( $key, $value, $where ); |
| 157 | 157 | |
| 158 | - $values[] = $value; |
|
| 159 | - } |
|
| 160 | - } |
|
| 158 | + $values[] = $value; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | 162 | /** |
| 163 | 163 | * Add %d, or %s to query |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param int|string $value |
| 168 | 168 | * @param string $where |
| 169 | 169 | */ |
| 170 | - private static function add_query_placeholder( $key, $value, &$where ) { |
|
| 170 | + private static function add_query_placeholder( $key, $value, &$where ) { |
|
| 171 | 171 | if ( is_numeric( $value ) && ( strpos( $key, 'meta_value' ) === false || strpos( $key, '+0' ) !== false ) ) { |
| 172 | 172 | $value = $value + 0; // switch string to number |
| 173 | 173 | $where .= is_float( $value ) ? '%f' : '%d'; |
@@ -176,16 +176,16 @@ discard block |
||
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * @param string $table |
|
| 179 | + /** |
|
| 180 | + * @param string $table |
|
| 181 | 181 | * @param array $where |
| 182 | 182 | * @param array $args |
| 183 | 183 | * @return int |
| 184 | - */ |
|
| 185 | - public static function get_count( $table, $where = array(), $args = array() ) { |
|
| 186 | - $count = self::get_var( $table, $where, 'COUNT(*)', $args ); |
|
| 187 | - return $count; |
|
| 188 | - } |
|
| 184 | + */ |
|
| 185 | + public static function get_count( $table, $where = array(), $args = array() ) { |
|
| 186 | + $count = self::get_var( $table, $where, 'COUNT(*)', $args ); |
|
| 187 | + return $count; |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | 191 | * @param string $table |
@@ -196,17 +196,17 @@ discard block |
||
| 196 | 196 | * @param string $type |
| 197 | 197 | * @return array|null|string|object |
| 198 | 198 | */ |
| 199 | - public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) { |
|
| 200 | - $group = ''; |
|
| 201 | - self::get_group_and_table_name( $table, $group ); |
|
| 199 | + public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) { |
|
| 200 | + $group = ''; |
|
| 201 | + self::get_group_and_table_name( $table, $group ); |
|
| 202 | 202 | self::convert_options_to_array( $args, '', $limit ); |
| 203 | 203 | |
| 204 | 204 | $query = self::generate_query_string_from_pieces( $field, $table, $where, $args ); |
| 205 | 205 | |
| 206 | 206 | $cache_key = self::generate_cache_key( $where, $args, $field, $type ); |
| 207 | 207 | $results = self::check_cache( $cache_key, $group, $query, 'get_' . $type ); |
| 208 | - return $results; |
|
| 209 | - } |
|
| 208 | + return $results; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | 212 | * Generate a cache key from the where query, field, type, and other arguments |
@@ -232,44 +232,44 @@ discard block |
||
| 232 | 232 | return $cache_key; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - /** |
|
| 236 | - * @param string $table |
|
| 237 | - * @param array $where |
|
| 235 | + /** |
|
| 236 | + * @param string $table |
|
| 237 | + * @param array $where |
|
| 238 | 238 | * @param string $field |
| 239 | 239 | * @param array $args |
| 240 | 240 | * @param string $limit |
| 241 | 241 | * @return mixed |
| 242 | - */ |
|
| 243 | - public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) { |
|
| 244 | - return self::get_var( $table, $where, $field, $args, $limit, 'col' ); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * @since 2.0 |
|
| 249 | - * @param string $table |
|
| 242 | + */ |
|
| 243 | + public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) { |
|
| 244 | + return self::get_var( $table, $where, $field, $args, $limit, 'col' ); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * @since 2.0 |
|
| 249 | + * @param string $table |
|
| 250 | 250 | * @param array $where |
| 251 | 251 | * @param string $fields |
| 252 | 252 | * @param array $args |
| 253 | 253 | * @return mixed |
| 254 | - */ |
|
| 255 | - public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) { |
|
| 256 | - $args['limit'] = 1; |
|
| 257 | - return self::get_var( $table, $where, $fields, $args, '', 'row' ); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Prepare a key/value array before DB call |
|
| 254 | + */ |
|
| 255 | + public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) { |
|
| 256 | + $args['limit'] = 1; |
|
| 257 | + return self::get_var( $table, $where, $fields, $args, '', 'row' ); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Prepare a key/value array before DB call |
|
| 262 | 262 | * |
| 263 | - * @since 2.0 |
|
| 264 | - * @param string $table |
|
| 263 | + * @since 2.0 |
|
| 264 | + * @param string $table |
|
| 265 | 265 | * @param array $where |
| 266 | 266 | * @param string $fields |
| 267 | 267 | * @param array $args |
| 268 | 268 | * @return mixed |
| 269 | - */ |
|
| 270 | - public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) { |
|
| 271 | - return self::get_var( $table, $where, $fields, $args, '', 'results' ); |
|
| 272 | - } |
|
| 269 | + */ |
|
| 270 | + public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) { |
|
| 271 | + return self::get_var( $table, $where, $fields, $args, '', 'results' ); |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | 274 | /** |
| 275 | 275 | * Check for like, not like, in, not in, =, !=, >, <, <=, >= |
@@ -306,56 +306,56 @@ discard block |
||
| 306 | 306 | return ''; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join |
|
| 311 | - * Also add the wpdb->prefix to the table if it's missing |
|
| 312 | - * |
|
| 313 | - * @param string $table |
|
| 314 | - * @param string $group |
|
| 315 | - */ |
|
| 316 | - private static function get_group_and_table_name( &$table, &$group ) { |
|
| 309 | + /** |
|
| 310 | + * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join |
|
| 311 | + * Also add the wpdb->prefix to the table if it's missing |
|
| 312 | + * |
|
| 313 | + * @param string $table |
|
| 314 | + * @param string $group |
|
| 315 | + */ |
|
| 316 | + private static function get_group_and_table_name( &$table, &$group ) { |
|
| 317 | 317 | global $wpdb, $wpmuBaseTablePrefix; |
| 318 | 318 | |
| 319 | 319 | $table_parts = explode( ' ', $table ); |
| 320 | 320 | $group = reset( $table_parts ); |
| 321 | - $group = str_replace( $wpdb->prefix, '', $group ); |
|
| 321 | + $group = str_replace( $wpdb->prefix, '', $group ); |
|
| 322 | 322 | |
| 323 | 323 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix; |
| 324 | 324 | $group = str_replace( $prefix, '', $group ); |
| 325 | 325 | |
| 326 | - if ( $group == $table ) { |
|
| 327 | - $table = $wpdb->prefix . $table; |
|
| 328 | - } |
|
| 326 | + if ( $group == $table ) { |
|
| 327 | + $table = $wpdb->prefix . $table; |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | 330 | // switch to singular group name |
| 331 | 331 | $group = rtrim( $group, 's' ); |
| 332 | - } |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) { |
|
| 334 | + private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) { |
|
| 335 | 335 | if ( ! is_array( $args ) ) { |
| 336 | 336 | $args = array( 'order_by' => $args ); |
| 337 | - } |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if ( ! empty( $order_by ) ) { |
|
| 340 | - $args['order_by'] = $order_by; |
|
| 341 | - } |
|
| 339 | + if ( ! empty( $order_by ) ) { |
|
| 340 | + $args['order_by'] = $order_by; |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - if ( ! empty( $limit ) ) { |
|
| 344 | - $args['limit'] = $limit; |
|
| 345 | - } |
|
| 343 | + if ( ! empty( $limit ) ) { |
|
| 344 | + $args['limit'] = $limit; |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - $temp_args = $args; |
|
| 348 | - foreach ( $temp_args as $k => $v ) { |
|
| 349 | - if ( $v == '' ) { |
|
| 347 | + $temp_args = $args; |
|
| 348 | + foreach ( $temp_args as $k => $v ) { |
|
| 349 | + if ( $v == '' ) { |
|
| 350 | 350 | unset( $args[ $k ] ); |
| 351 | - continue; |
|
| 352 | - } |
|
| 351 | + continue; |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | - $db_name = strtoupper( str_replace( '_', ' ', $k ) ); |
|
| 355 | - if ( strpos( $v, $db_name ) === false ) { |
|
| 354 | + $db_name = strtoupper( str_replace( '_', ' ', $k ) ); |
|
| 355 | + if ( strpos( $v, $db_name ) === false ) { |
|
| 356 | 356 | $args[ $k ] = $db_name . ' ' . $v; |
| 357 | - } |
|
| 358 | - } |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | 360 | // Make sure LIMIT is the last argument |
| 361 | 361 | if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) { |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | unset( $args['limit'] ); |
| 364 | 364 | $args['limit'] = $temp_limit; |
| 365 | 365 | } |
| 366 | - } |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | 368 | /** |
| 369 | 369 | * Get the associative array results for the given columns, table, and where query |
@@ -435,25 +435,25 @@ discard block |
||
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - /** |
|
| 439 | - * Added for < WP 4.0 compatability |
|
| 440 | - * |
|
| 441 | - * @since 2.05.06 |
|
| 442 | - * |
|
| 443 | - * @param string $term The value to escape |
|
| 444 | - * @return string The escaped value |
|
| 445 | - */ |
|
| 438 | + /** |
|
| 439 | + * Added for < WP 4.0 compatability |
|
| 440 | + * |
|
| 441 | + * @since 2.05.06 |
|
| 442 | + * |
|
| 443 | + * @param string $term The value to escape |
|
| 444 | + * @return string The escaped value |
|
| 445 | + */ |
|
| 446 | 446 | public static function esc_like( $term ) { |
| 447 | - global $wpdb; |
|
| 448 | - if ( method_exists( $wpdb, 'esc_like' ) ) { |
|
| 447 | + global $wpdb; |
|
| 448 | + if ( method_exists( $wpdb, 'esc_like' ) ) { |
|
| 449 | 449 | // WP 4.0 |
| 450 | - $term = $wpdb->esc_like( $term ); |
|
| 451 | - } else { |
|
| 452 | - $term = like_escape( $term ); |
|
| 453 | - } |
|
| 450 | + $term = $wpdb->esc_like( $term ); |
|
| 451 | + } else { |
|
| 452 | + $term = like_escape( $term ); |
|
| 453 | + } |
|
| 454 | 454 | |
| 455 | - return $term; |
|
| 456 | - } |
|
| 455 | + return $term; |
|
| 456 | + } |
|
| 457 | 457 | |
| 458 | 458 | /** |
| 459 | 459 | * @since 2.05.06 |
@@ -523,10 +523,10 @@ discard block |
||
| 523 | 523 | return ' LIMIT ' . $limit; |
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - /** |
|
| 527 | - * Get an array of values ready to go through $wpdb->prepare |
|
| 528 | - * @since 2.05.06 |
|
| 529 | - */ |
|
| 526 | + /** |
|
| 527 | + * Get an array of values ready to go through $wpdb->prepare |
|
| 528 | + * @since 2.05.06 |
|
| 529 | + */ |
|
| 530 | 530 | public static function prepare_array_values( $array, $type = '%s' ) { |
| 531 | 531 | $placeholders = array_fill( 0, count( $array ), $type ); |
| 532 | 532 | return implode( ', ', $placeholders ); |
@@ -597,17 +597,17 @@ discard block |
||
| 597 | 597 | return $post; |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | - /** |
|
| 601 | - * Check cache before fetching values and saving to cache |
|
| 602 | - * |
|
| 603 | - * @since 2.05.06 |
|
| 604 | - * |
|
| 605 | - * @param string $cache_key The unique name for this cache |
|
| 606 | - * @param string $group The name of the cache group |
|
| 607 | - * @param string $query If blank, don't run a db call |
|
| 608 | - * @param string $type The wpdb function to use with this query |
|
| 609 | - * @return mixed $results The cache or query results |
|
| 610 | - */ |
|
| 600 | + /** |
|
| 601 | + * Check cache before fetching values and saving to cache |
|
| 602 | + * |
|
| 603 | + * @since 2.05.06 |
|
| 604 | + * |
|
| 605 | + * @param string $cache_key The unique name for this cache |
|
| 606 | + * @param string $group The name of the cache group |
|
| 607 | + * @param string $query If blank, don't run a db call |
|
| 608 | + * @param string $type The wpdb function to use with this query |
|
| 609 | + * @return mixed $results The cache or query results |
|
| 610 | + */ |
|
| 611 | 611 | public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) { |
| 612 | 612 | $results = wp_cache_get( $cache_key, $group ); |
| 613 | 613 | if ( ! FrmAppHelper::is_empty_value( $results, false ) || empty( $query ) ) { |
@@ -671,13 +671,13 @@ discard block |
||
| 671 | 671 | wp_cache_delete( $cache_key, $group ); |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | - /** |
|
| 675 | - * Delete all caching in a single group |
|
| 676 | - * |
|
| 677 | - * @since 2.05.06 |
|
| 678 | - * |
|
| 679 | - * @param string $group The name of the cache group |
|
| 680 | - */ |
|
| 674 | + /** |
|
| 675 | + * Delete all caching in a single group |
|
| 676 | + * |
|
| 677 | + * @since 2.05.06 |
|
| 678 | + * |
|
| 679 | + * @param string $group The name of the cache group |
|
| 680 | + */ |
|
| 681 | 681 | public static function cache_delete_group( $group ) { |
| 682 | 682 | $cached_keys = self::get_group_cached_keys( $group ); |
| 683 | 683 | |
@@ -293,8 +293,8 @@ discard block |
||
| 293 | 293 | ); |
| 294 | 294 | |
| 295 | 295 | $where_is = strtolower( $where_is ); |
| 296 | - if ( isset( $switch_to[ $where_is ] ) ) { |
|
| 297 | - return ' ' . $switch_to[ $where_is ]; |
|
| 296 | + if ( isset( $switch_to[$where_is] ) ) { |
|
| 297 | + return ' ' . $switch_to[$where_is]; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | // > and < need a little more work since we don't want them switched to >= and <= |
@@ -347,13 +347,13 @@ discard block |
||
| 347 | 347 | $temp_args = $args; |
| 348 | 348 | foreach ( $temp_args as $k => $v ) { |
| 349 | 349 | if ( $v == '' ) { |
| 350 | - unset( $args[ $k ] ); |
|
| 350 | + unset( $args[$k] ); |
|
| 351 | 351 | continue; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | $db_name = strtoupper( str_replace( '_', ' ', $k ) ); |
| 355 | 355 | if ( strpos( $v, $db_name ) === false ) { |
| 356 | - $args[ $k ] = $db_name . ' ' . $v; |
|
| 356 | + $args[$k] = $db_name . ' ' . $v; |
|
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | |
@@ -424,13 +424,13 @@ discard block |
||
| 424 | 424 | private static function esc_query_args( &$args ) { |
| 425 | 425 | foreach ( $args as $param => $value ) { |
| 426 | 426 | if ( $param == 'order_by' ) { |
| 427 | - $args[ $param ] = self::esc_order( $value ); |
|
| 427 | + $args[$param] = self::esc_order( $value ); |
|
| 428 | 428 | } elseif ( $param == 'limit' ) { |
| 429 | - $args[ $param ] = self::esc_limit( $value ); |
|
| 429 | + $args[$param] = self::esc_limit( $value ); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - if ( $args[ $param ] == '' ) { |
|
| 433 | - unset( $args[ $param ] ); |
|
| 432 | + if ( $args[$param] == '' ) { |
|
| 433 | + unset( $args[$param] ); |
|
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | } |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | $limit = explode( ',', trim( $limit ) ); |
| 516 | 516 | foreach ( $limit as $k => $l ) { |
| 517 | 517 | if ( is_numeric( $l ) ) { |
| 518 | - $limit[ $k ] = $l; |
|
| 518 | + $limit[$k] = $l; |
|
| 519 | 519 | } |
| 520 | 520 | } |
| 521 | 521 | |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | */ |
| 647 | 647 | public static function add_key_to_group_cache( $key, $group ) { |
| 648 | 648 | $cached = self::get_group_cached_keys( $group ); |
| 649 | - $cached[ $key ] = $key; |
|
| 649 | + $cached[$key] = $key; |
|
| 650 | 650 | wp_cache_set( 'cached_keys', $cached, $group, 300 ); |
| 651 | 651 | } |
| 652 | 652 | |
@@ -1082,7 +1082,8 @@ |
||
| 1082 | 1082 | private static function maybe_get_form_to_show( $id ) { |
| 1083 | 1083 | $form = false; |
| 1084 | 1084 | |
| 1085 | - if ( ! empty( $id ) ) { // no form id or key set |
|
| 1085 | + if ( ! empty( $id ) ) { |
|
| 1086 | +// no form id or key set |
|
| 1086 | 1087 | $form = FrmForm::getOne( $id ); |
| 1087 | 1088 | if ( ! $form || $form->parent_form_id || $form->status == 'trash' ) { |
| 1088 | 1089 | $form = false; |
@@ -800,6 +800,7 @@ discard block |
||
| 800 | 800 | /** |
| 801 | 801 | * Get an array of the helper shortcodes to display in the customization panel |
| 802 | 802 | * @since 2.0.6 |
| 803 | + * @param boolean $settings_tab |
|
| 803 | 804 | */ |
| 804 | 805 | private static function get_shortcode_helpers( $settings_tab ) { |
| 805 | 806 | $entry_shortcodes = array( |
@@ -875,6 +876,9 @@ discard block |
||
| 875 | 876 | return $content; |
| 876 | 877 | } |
| 877 | 878 | |
| 879 | + /** |
|
| 880 | + * @param boolean $entry |
|
| 881 | + */ |
|
| 878 | 882 | private static function get_entry_by_param( &$entry ) { |
| 879 | 883 | if ( ! $entry || ! is_object( $entry ) ) { |
| 880 | 884 | if ( ! $entry || ! is_numeric( $entry ) ) { |
@@ -1198,6 +1202,9 @@ discard block |
||
| 1198 | 1202 | return $form; |
| 1199 | 1203 | } |
| 1200 | 1204 | |
| 1205 | + /** |
|
| 1206 | + * @param string $id |
|
| 1207 | + */ |
|
| 1201 | 1208 | private static function maybe_get_form_to_show( $id ) { |
| 1202 | 1209 | $form = false; |
| 1203 | 1210 | |
@@ -1597,6 +1604,7 @@ discard block |
||
| 1597 | 1604 | |
| 1598 | 1605 | /** |
| 1599 | 1606 | * @since 2.0.8 |
| 1607 | + * @param string $content |
|
| 1600 | 1608 | */ |
| 1601 | 1609 | private static function maybe_minimize_form( $atts, &$content ) { |
| 1602 | 1610 | // check if minimizing is turned on |
@@ -1664,6 +1672,7 @@ discard block |
||
| 1664 | 1672 | /** |
| 1665 | 1673 | * @deprecated 3.0 |
| 1666 | 1674 | * @codeCoverageIgnore |
| 1675 | + * @param string $field |
|
| 1667 | 1676 | */ |
| 1668 | 1677 | private static function edit_in_place_value( $field ) { |
| 1669 | 1678 | _deprecated_function( __METHOD__, '3.0' ); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | global $frm_vars; |
| 65 | 65 | |
| 66 | 66 | $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
| 67 | - $action = empty( $values ) ? FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ) : $values[ $action ]; |
|
| 67 | + $action = empty( $values ) ? FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ) : $values[$action]; |
|
| 68 | 68 | |
| 69 | 69 | if ( $action == 'create' ) { |
| 70 | 70 | self::create( $values ); |
@@ -404,11 +404,11 @@ discard block |
||
| 404 | 404 | ), |
| 405 | 405 | ); |
| 406 | 406 | |
| 407 | - if ( ! isset( $available_status[ $status ] ) ) { |
|
| 407 | + if ( ! isset( $available_status[$status] ) ) { |
|
| 408 | 408 | return; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - FrmAppHelper::permission_check( $available_status[ $status ]['permission'] ); |
|
| 411 | + FrmAppHelper::permission_check( $available_status[$status]['permission'] ); |
|
| 412 | 412 | |
| 413 | 413 | $params = FrmForm::list_page_params(); |
| 414 | 414 | |
@@ -416,8 +416,8 @@ discard block |
||
| 416 | 416 | check_admin_referer( $status . '_form_' . $params['id'] ); |
| 417 | 417 | |
| 418 | 418 | $count = 0; |
| 419 | - if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) { |
|
| 420 | - $count++; |
|
| 419 | + if ( FrmForm::set_status( $params['id'], $available_status[$status]['new_status'] ) ) { |
|
| 420 | + $count ++; |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | $form_type = FrmAppHelper::get_simple_request( array( |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count ); |
| 429 | 429 | $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' ); |
| 430 | 430 | |
| 431 | - $message = $available_status[ $status ]['message']; |
|
| 431 | + $message = $available_status[$status]['message']; |
|
| 432 | 432 | |
| 433 | 433 | self::display_forms_list( $params, $message ); |
| 434 | 434 | } |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | $count = 0; |
| 440 | 440 | foreach ( $ids as $id ) { |
| 441 | 441 | if ( FrmForm::trash( $id ) ) { |
| 442 | - $count++; |
|
| 442 | + $count ++; |
|
| 443 | 443 | } |
| 444 | 444 | } |
| 445 | 445 | |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | |
| 463 | 463 | $count = 0; |
| 464 | 464 | if ( FrmForm::destroy( $params['id'] ) ) { |
| 465 | - $count++; |
|
| 465 | + $count ++; |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | foreach ( $ids as $id ) { |
| 478 | 478 | $d = FrmForm::destroy( $id ); |
| 479 | 479 | if ( $d ) { |
| 480 | - $count++; |
|
| 480 | + $count ++; |
|
| 481 | 481 | } |
| 482 | 482 | } |
| 483 | 483 | |
@@ -949,8 +949,8 @@ discard block |
||
| 949 | 949 | $path = untrailingslashit( trim( $path ) ); |
| 950 | 950 | $templates = glob( $path . '/*.php' ); |
| 951 | 951 | |
| 952 | - for ( $i = count( $templates ) - 1; $i >= 0; $i-- ) { |
|
| 953 | - $filename = str_replace( '.php', '', str_replace( $path . '/', '', $templates[ $i ] ) ); |
|
| 952 | + for ( $i = count( $templates ) - 1; $i >= 0; $i -- ) { |
|
| 953 | + $filename = str_replace( '.php', '', str_replace( $path . '/', '', $templates[$i] ) ); |
|
| 954 | 954 | $template_query = array( 'form_key' => $filename ); |
| 955 | 955 | if ( $template ) { |
| 956 | 956 | $template_query['is_template'] = 1; |
@@ -968,7 +968,7 @@ discard block |
||
| 968 | 968 | $values['default_template'] = 1; |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | - include( $templates[ $i ] ); |
|
| 971 | + include( $templates[$i] ); |
|
| 972 | 972 | |
| 973 | 973 | //get updated form |
| 974 | 974 | if ( isset( $form ) && ! empty( $form ) ) { |
@@ -1003,7 +1003,7 @@ discard block |
||
| 1003 | 1003 | add_filter( 'frm_validate_form', 'FrmFormsController::json_error' ); |
| 1004 | 1004 | } else { |
| 1005 | 1005 | $vars = FrmAppHelper::json_to_array( $json_vars ); |
| 1006 | - $action = $vars[ $action ]; |
|
| 1006 | + $action = $vars[$action]; |
|
| 1007 | 1007 | unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] ); |
| 1008 | 1008 | $_REQUEST = array_merge( $_REQUEST, $vars ); |
| 1009 | 1009 | $_POST = array_merge( $_POST, $_REQUEST ); |
@@ -1078,7 +1078,7 @@ discard block |
||
| 1078 | 1078 | $actions = array(); |
| 1079 | 1079 | foreach ( $frm_vars['forms_loaded'] as $form ) { |
| 1080 | 1080 | if ( is_object( $form ) ) { |
| 1081 | - $actions[ $form->id ] = $form->name; |
|
| 1081 | + $actions[$form->id] = $form->name; |
|
| 1082 | 1082 | } |
| 1083 | 1083 | unset( $form ); |
| 1084 | 1084 | } |
@@ -1289,8 +1289,8 @@ discard block |
||
| 1289 | 1289 | private static function get_saved_errors( $form, $params ) { |
| 1290 | 1290 | global $frm_vars; |
| 1291 | 1291 | |
| 1292 | - if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][ $form->id ] ) ) { |
|
| 1293 | - $errors = $frm_vars['created_entries'][ $form->id ]['errors']; |
|
| 1292 | + if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][$form->id] ) ) { |
|
| 1293 | + $errors = $frm_vars['created_entries'][$form->id]['errors']; |
|
| 1294 | 1294 | } else { |
| 1295 | 1295 | $errors = array(); |
| 1296 | 1296 | } |
@@ -1302,7 +1302,7 @@ discard block |
||
| 1302 | 1302 | */ |
| 1303 | 1303 | public static function just_created_entry( $form_id ) { |
| 1304 | 1304 | global $frm_vars; |
| 1305 | - return ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0; |
|
| 1305 | + return ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][$form_id] ) && isset( $frm_vars['created_entries'][$form_id]['entry_id'] ) ) ? $frm_vars['created_entries'][$form_id]['entry_id'] : 0; |
|
| 1306 | 1306 | } |
| 1307 | 1307 | |
| 1308 | 1308 | /** |
@@ -1310,7 +1310,7 @@ discard block |
||
| 1310 | 1310 | */ |
| 1311 | 1311 | private static function get_confirmation_method( $atts ) { |
| 1312 | 1312 | $opt = 'success_action'; |
| 1313 | - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message'; |
|
| 1313 | + $method = ( isset( $atts['form']->options[$opt] ) && ! empty( $atts['form']->options[$opt] ) ) ? $atts['form']->options[$opt] : 'message'; |
|
| 1314 | 1314 | $method = apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' ); |
| 1315 | 1315 | |
| 1316 | 1316 | if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) { |
@@ -1323,7 +1323,7 @@ discard block |
||
| 1323 | 1323 | public static function maybe_trigger_redirect( $form, $params, $args ) { |
| 1324 | 1324 | if ( ! isset( $params['id'] ) ) { |
| 1325 | 1325 | global $frm_vars; |
| 1326 | - $params['id'] = $frm_vars['created_entries'][ $form->id ]['entry_id']; |
|
| 1326 | + $params['id'] = $frm_vars['created_entries'][$form->id]['entry_id']; |
|
| 1327 | 1327 | } |
| 1328 | 1328 | |
| 1329 | 1329 | $conf_method = self::get_confirmation_method( array( |
@@ -1363,7 +1363,7 @@ discard block |
||
| 1363 | 1363 | |
| 1364 | 1364 | $opt = ( ! isset( $args['action'] ) || $args['action'] == 'create' ) ? 'success' : 'edit'; |
| 1365 | 1365 | $args['success_opt'] = $opt; |
| 1366 | - if ( $args['conf_method'] == 'page' && is_numeric( $args['form']->options[ $opt . '_page_id' ] ) ) { |
|
| 1366 | + if ( $args['conf_method'] == 'page' && is_numeric( $args['form']->options[$opt . '_page_id'] ) ) { |
|
| 1367 | 1367 | self::load_page_after_submit( $args ); |
| 1368 | 1368 | } elseif ( $args['conf_method'] == 'redirect' ) { |
| 1369 | 1369 | self::redirect_after_submit( $args ); |
@@ -1378,8 +1378,8 @@ discard block |
||
| 1378 | 1378 | private static function load_page_after_submit( $args ) { |
| 1379 | 1379 | global $post; |
| 1380 | 1380 | $opt = $args['success_opt']; |
| 1381 | - if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) { |
|
| 1382 | - $page = get_post( $args['form']->options[ $opt . '_page_id' ] ); |
|
| 1381 | + if ( ! $post || $args['form']->options[$opt . '_page_id'] != $post->ID ) { |
|
| 1382 | + $page = get_post( $args['form']->options[$opt . '_page_id'] ); |
|
| 1383 | 1383 | $old_post = $post; |
| 1384 | 1384 | $post = $page; |
| 1385 | 1385 | $content = apply_filters( 'frm_content', $page->post_content, $args['form'], $args['entry_id'] ); |
@@ -1397,11 +1397,11 @@ discard block |
||
| 1397 | 1397 | add_filter( 'frm_use_wpautop', '__return_false' ); |
| 1398 | 1398 | |
| 1399 | 1399 | $opt = $args['success_opt']; |
| 1400 | - $success_url = trim( $args['form']->options[ $opt . '_url' ] ); |
|
| 1400 | + $success_url = trim( $args['form']->options[$opt . '_url'] ); |
|
| 1401 | 1401 | $success_url = apply_filters( 'frm_content', $success_url, $args['form'], $args['entry_id'] ); |
| 1402 | 1402 | $success_url = do_shortcode( $success_url ); |
| 1403 | 1403 | |
| 1404 | - $success_msg = isset( $args['form']->options[ $opt . '_msg' ] ) ? $args['form']->options[ $opt . '_msg' ] : __( 'Please wait while you are redirected.', 'formidable' ); |
|
| 1404 | + $success_msg = isset( $args['form']->options[$opt . '_msg'] ) ? $args['form']->options[$opt . '_msg'] : __( 'Please wait while you are redirected.', 'formidable' ); |
|
| 1405 | 1405 | |
| 1406 | 1406 | $redirect_msg = self::get_redirect_message( $success_url, $success_msg, $args ); |
| 1407 | 1407 | |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class FrmFormsController { |
| 4 | 4 | |
| 5 | - public static function menu() { |
|
| 5 | + public static function menu() { |
|
| 6 | 6 | $menu_label = __( 'Forms', 'formidable' ); |
| 7 | 7 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 8 | 8 | $menu_label .= ' (Lite)'; |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | add_submenu_page( 'formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' ); |
| 11 | 11 | |
| 12 | 12 | self::maybe_load_listing_hooks(); |
| 13 | - } |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | 15 | public static function maybe_load_listing_hooks() { |
| 16 | 16 | $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
@@ -24,13 +24,13 @@ discard block |
||
| 24 | 24 | add_filter( 'manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' ); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - public static function head() { |
|
| 27 | + public static function head() { |
|
| 28 | 28 | wp_enqueue_script( 'formidable-editinplace' ); |
| 29 | 29 | |
| 30 | - if ( wp_is_mobile() ) { |
|
| 31 | - wp_enqueue_script( 'jquery-touch-punch' ); |
|
| 32 | - } |
|
| 33 | - } |
|
| 30 | + if ( wp_is_mobile() ) { |
|
| 31 | + wp_enqueue_script( 'jquery-touch-punch' ); |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | public static function register_widgets() { |
| 36 | 36 | require_once( FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php' ); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | public static function new_form( $values = array() ) { |
| 62 | 62 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 63 | 63 | |
| 64 | - global $frm_vars; |
|
| 64 | + global $frm_vars; |
|
| 65 | 65 | |
| 66 | 66 | $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
| 67 | 67 | $action = empty( $values ) ? FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ) : $values[ $action ]; |
@@ -72,17 +72,17 @@ discard block |
||
| 72 | 72 | } else if ( $action == 'new' ) { |
| 73 | 73 | $frm_field_selection = FrmField::field_selection(); |
| 74 | 74 | $values = FrmFormsHelper::setup_new_vars( $values ); |
| 75 | - $id = FrmForm::create( $values ); |
|
| 75 | + $id = FrmForm::create( $values ); |
|
| 76 | 76 | $form = FrmForm::getOne( $id ); |
| 77 | 77 | |
| 78 | 78 | self::create_default_email_action( $form ); |
| 79 | 79 | |
| 80 | 80 | $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
| 81 | 81 | |
| 82 | - $values['id'] = $id; |
|
| 82 | + $values['id'] = $id; |
|
| 83 | 83 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' ); |
| 84 | - } |
|
| 85 | - } |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * Create the default email action |
@@ -91,41 +91,41 @@ discard block |
||
| 91 | 91 | * |
| 92 | 92 | * @param object $form |
| 93 | 93 | */ |
| 94 | - private static function create_default_email_action( $form ) { |
|
| 95 | - $create_email = apply_filters( 'frm_create_default_email_action', true, $form ); |
|
| 94 | + private static function create_default_email_action( $form ) { |
|
| 95 | + $create_email = apply_filters( 'frm_create_default_email_action', true, $form ); |
|
| 96 | 96 | |
| 97 | - if ( $create_email ) { |
|
| 98 | - $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
| 99 | - $action_control->create( $form->id ); |
|
| 100 | - } |
|
| 101 | - } |
|
| 97 | + if ( $create_email ) { |
|
| 98 | + $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
| 99 | + $action_control->create( $form->id ); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | public static function create( $values = array() ) { |
| 104 | 104 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 105 | 105 | |
| 106 | - global $frm_vars; |
|
| 107 | - if ( empty( $values ) ) { |
|
| 108 | - $values = $_POST; |
|
| 109 | - } |
|
| 106 | + global $frm_vars; |
|
| 107 | + if ( empty( $values ) ) { |
|
| 108 | + $values = $_POST; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - //Set radio button and checkbox meta equal to "other" value |
|
| 112 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
| 113 | - $values = FrmProEntry::mod_other_vals( $values, 'back' ); |
|
| 114 | - } |
|
| 111 | + //Set radio button and checkbox meta equal to "other" value |
|
| 112 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
| 113 | + $values = FrmProEntry::mod_other_vals( $values, 'back' ); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 117 | 117 | |
| 118 | - if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) { |
|
| 119 | - $frm_settings = FrmAppHelper::get_settings(); |
|
| 120 | - $errors = array( 'form' => $frm_settings->admin_permission ); |
|
| 121 | - } else { |
|
| 118 | + if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) { |
|
| 119 | + $frm_settings = FrmAppHelper::get_settings(); |
|
| 120 | + $errors = array( 'form' => $frm_settings->admin_permission ); |
|
| 121 | + } else { |
|
| 122 | 122 | $errors = FrmForm::validate( $values ); |
| 123 | - } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | if ( count( $errors ) > 0 ) { |
| 126 | - $hide_preview = true; |
|
| 126 | + $hide_preview = true; |
|
| 127 | 127 | $frm_field_selection = FrmField::field_selection(); |
| 128 | - $form = FrmForm::getOne( $id ); |
|
| 128 | + $form = FrmForm::getOne( $id ); |
|
| 129 | 129 | $fields = FrmField::get_all_for_form( $id ); |
| 130 | 130 | |
| 131 | 131 | $values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true ); |
@@ -133,30 +133,30 @@ discard block |
||
| 133 | 133 | $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
| 134 | 134 | |
| 135 | 135 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' ); |
| 136 | - } else { |
|
| 137 | - FrmForm::update( $id, $values, true ); |
|
| 136 | + } else { |
|
| 137 | + FrmForm::update( $id, $values, true ); |
|
| 138 | 138 | $url = admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . $id ); |
| 139 | 139 | die( FrmAppHelper::js_redirect( $url ) ); // WPCS: XSS ok. |
| 140 | - } |
|
| 141 | - } |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - public static function edit( $values = false ) { |
|
| 143 | + public static function edit( $values = false ) { |
|
| 144 | 144 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 145 | 145 | |
| 146 | 146 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 147 | 147 | return self::get_edit_vars( $id ); |
| 148 | - } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - public static function settings( $id = false, $message = '' ) { |
|
| 150 | + public static function settings( $id = false, $message = '' ) { |
|
| 151 | 151 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 152 | 152 | |
| 153 | 153 | if ( ! $id || ! is_numeric( $id ) ) { |
| 154 | 154 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 155 | - } |
|
| 155 | + } |
|
| 156 | 156 | return self::get_settings_vars( $id, array(), $message ); |
| 157 | - } |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - public static function update_settings() { |
|
| 159 | + public static function update_settings() { |
|
| 160 | 160 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 161 | 161 | |
| 162 | 162 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
@@ -170,39 +170,39 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | FrmForm::update( $id, $_POST ); |
| 172 | 172 | |
| 173 | - $message = __( 'Settings Successfully Updated', 'formidable' ); |
|
| 173 | + $message = __( 'Settings Successfully Updated', 'formidable' ); |
|
| 174 | 174 | return self::get_settings_vars( $id, array(), $message ); |
| 175 | - } |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | 177 | public static function update( $values = array() ) { |
| 178 | 178 | if ( empty( $values ) ) { |
| 179 | - $values = $_POST; |
|
| 180 | - } |
|
| 179 | + $values = $_POST; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - //Set radio button and checkbox meta equal to "other" value |
|
| 183 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
| 184 | - $values = FrmProEntry::mod_other_vals( $values, 'back' ); |
|
| 185 | - } |
|
| 182 | + //Set radio button and checkbox meta equal to "other" value |
|
| 183 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
| 184 | + $values = FrmProEntry::mod_other_vals( $values, 'back' ); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - $errors = FrmForm::validate( $values ); |
|
| 188 | - $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' ); |
|
| 189 | - if ( $permission_error !== false ) { |
|
| 190 | - $errors['form'] = $permission_error; |
|
| 191 | - } |
|
| 187 | + $errors = FrmForm::validate( $values ); |
|
| 188 | + $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' ); |
|
| 189 | + if ( $permission_error !== false ) { |
|
| 190 | + $errors['form'] = $permission_error; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 194 | 194 | |
| 195 | 195 | if ( count( $errors ) > 0 ) { |
| 196 | - return self::get_edit_vars( $id, $errors ); |
|
| 196 | + return self::get_edit_vars( $id, $errors ); |
|
| 197 | 197 | } else { |
| 198 | - FrmForm::update( $id, $values ); |
|
| 199 | - $message = __( 'Form was Successfully Updated', 'formidable' ); |
|
| 200 | - if ( defined( 'DOING_AJAX' ) ) { |
|
| 198 | + FrmForm::update( $id, $values ); |
|
| 199 | + $message = __( 'Form was Successfully Updated', 'formidable' ); |
|
| 200 | + if ( defined( 'DOING_AJAX' ) ) { |
|
| 201 | 201 | wp_die( esc_html( $message ) ); |
| 202 | - } |
|
| 202 | + } |
|
| 203 | 203 | return self::get_edit_vars( $id, array(), $message ); |
| 204 | - } |
|
| 205 | - } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * Redirect to the url for creating from a template |
@@ -224,30 +224,30 @@ discard block |
||
| 224 | 224 | wp_die(); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - public static function duplicate() { |
|
| 227 | + public static function duplicate() { |
|
| 228 | 228 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 229 | 229 | |
| 230 | 230 | $params = FrmForm::list_page_params(); |
| 231 | - $form = FrmForm::duplicate( $params['id'], $params['template'], true ); |
|
| 232 | - $message = $params['template'] ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' ); |
|
| 233 | - if ( $form ) { |
|
| 231 | + $form = FrmForm::duplicate( $params['id'], $params['template'], true ); |
|
| 232 | + $message = $params['template'] ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' ); |
|
| 233 | + if ( $form ) { |
|
| 234 | 234 | return self::get_edit_vars( $form, array(), $message, true ); |
| 235 | - } else { |
|
| 235 | + } else { |
|
| 236 | 236 | return self::display_forms_list( $params, __( 'There was a problem creating the new template.', 'formidable' ) ); |
| 237 | - } |
|
| 238 | - } |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - public static function page_preview() { |
|
| 240 | + public static function page_preview() { |
|
| 241 | 241 | $params = FrmForm::list_page_params(); |
| 242 | - if ( ! $params['form'] ) { |
|
| 243 | - return; |
|
| 244 | - } |
|
| 242 | + if ( ! $params['form'] ) { |
|
| 243 | + return; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - $form = FrmForm::getOne( $params['form'] ); |
|
| 246 | + $form = FrmForm::getOne( $params['form'] ); |
|
| 247 | 247 | if ( $form ) { |
| 248 | 248 | return self::show_form( $form->id, '', true, true ); |
| 249 | 249 | } |
| 250 | - } |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | 252 | /** |
| 253 | 253 | * @since 3.0 |
@@ -256,11 +256,11 @@ discard block |
||
| 256 | 256 | echo self::page_preview(); // WPCS: XSS ok. |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - public static function preview() { |
|
| 260 | - do_action( 'frm_wp' ); |
|
| 259 | + public static function preview() { |
|
| 260 | + do_action( 'frm_wp' ); |
|
| 261 | 261 | |
| 262 | - global $frm_vars; |
|
| 263 | - $frm_vars['preview'] = true; |
|
| 262 | + global $frm_vars; |
|
| 263 | + $frm_vars['preview'] = true; |
|
| 264 | 264 | |
| 265 | 265 | self::load_wp(); |
| 266 | 266 | |
@@ -370,22 +370,22 @@ discard block |
||
| 370 | 370 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' ); |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - public static function untrash() { |
|
| 373 | + public static function untrash() { |
|
| 374 | 374 | self::change_form_status( 'untrash' ); |
| 375 | - } |
|
| 375 | + } |
|
| 376 | 376 | |
| 377 | 377 | public static function bulk_untrash( $ids ) { |
| 378 | 378 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 379 | 379 | |
| 380 | - $count = FrmForm::set_status( $ids, 'published' ); |
|
| 380 | + $count = FrmForm::set_status( $ids, 'published' ); |
|
| 381 | 381 | |
| 382 | 382 | $message = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 ); |
| 383 | - return $message; |
|
| 384 | - } |
|
| 383 | + return $message; |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | - public static function trash() { |
|
| 386 | + public static function trash() { |
|
| 387 | 387 | self::change_form_status( 'trash' ); |
| 388 | - } |
|
| 388 | + } |
|
| 389 | 389 | |
| 390 | 390 | /** |
| 391 | 391 | * @param string $status |
@@ -436,12 +436,12 @@ discard block |
||
| 436 | 436 | public static function bulk_trash( $ids ) { |
| 437 | 437 | FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 438 | 438 | |
| 439 | - $count = 0; |
|
| 440 | - foreach ( $ids as $id ) { |
|
| 441 | - if ( FrmForm::trash( $id ) ) { |
|
| 442 | - $count++; |
|
| 443 | - } |
|
| 444 | - } |
|
| 439 | + $count = 0; |
|
| 440 | + foreach ( $ids as $id ) { |
|
| 441 | + if ( FrmForm::trash( $id ) ) { |
|
| 442 | + $count++; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | 445 | |
| 446 | 446 | $current_page = FrmAppHelper::get_simple_request( array( |
| 447 | 447 | 'param' => 'form_type', |
@@ -449,63 +449,63 @@ discard block |
||
| 449 | 449 | ) ); |
| 450 | 450 | $message = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">', '</a>' ); |
| 451 | 451 | |
| 452 | - return $message; |
|
| 453 | - } |
|
| 452 | + return $message; |
|
| 453 | + } |
|
| 454 | 454 | |
| 455 | - public static function destroy() { |
|
| 455 | + public static function destroy() { |
|
| 456 | 456 | FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 457 | 457 | |
| 458 | 458 | $params = FrmForm::list_page_params(); |
| 459 | 459 | |
| 460 | - //check nonce url |
|
| 460 | + //check nonce url |
|
| 461 | 461 | check_admin_referer( 'destroy_form_' . $params['id'] ); |
| 462 | 462 | |
| 463 | - $count = 0; |
|
| 464 | - if ( FrmForm::destroy( $params['id'] ) ) { |
|
| 465 | - $count++; |
|
| 466 | - } |
|
| 463 | + $count = 0; |
|
| 464 | + if ( FrmForm::destroy( $params['id'] ) ) { |
|
| 465 | + $count++; |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | 468 | $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); |
| 469 | 469 | |
| 470 | 470 | self::display_forms_list( $params, $message ); |
| 471 | - } |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | 473 | public static function bulk_destroy( $ids ) { |
| 474 | 474 | FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 475 | 475 | |
| 476 | - $count = 0; |
|
| 477 | - foreach ( $ids as $id ) { |
|
| 478 | - $d = FrmForm::destroy( $id ); |
|
| 479 | - if ( $d ) { |
|
| 480 | - $count++; |
|
| 481 | - } |
|
| 482 | - } |
|
| 476 | + $count = 0; |
|
| 477 | + foreach ( $ids as $id ) { |
|
| 478 | + $d = FrmForm::destroy( $id ); |
|
| 479 | + if ( $d ) { |
|
| 480 | + $count++; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | 483 | |
| 484 | 484 | $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); |
| 485 | 485 | |
| 486 | - return $message; |
|
| 487 | - } |
|
| 486 | + return $message; |
|
| 487 | + } |
|
| 488 | 488 | |
| 489 | - private static function delete_all() { |
|
| 490 | - //check nonce url |
|
| 489 | + private static function delete_all() { |
|
| 490 | + //check nonce url |
|
| 491 | 491 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
| 492 | - if ( $permission_error !== false ) { |
|
| 492 | + if ( $permission_error !== false ) { |
|
| 493 | 493 | self::display_forms_list( array(), '', array( $permission_error ) ); |
| 494 | - return; |
|
| 495 | - } |
|
| 494 | + return; |
|
| 495 | + } |
|
| 496 | 496 | |
| 497 | 497 | $count = FrmForm::scheduled_delete( time() ); |
| 498 | 498 | $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); |
| 499 | 499 | |
| 500 | 500 | self::display_forms_list( array(), $message ); |
| 501 | - } |
|
| 501 | + } |
|
| 502 | 502 | |
| 503 | 503 | /** |
| 504 | - * Inserts Formidable button |
|
| 505 | - * Hook exists since 2.5.0 |
|
| 506 | - * |
|
| 507 | - * @since 2.0.15 |
|
| 508 | - */ |
|
| 504 | + * Inserts Formidable button |
|
| 505 | + * Hook exists since 2.5.0 |
|
| 506 | + * |
|
| 507 | + * @since 2.0.15 |
|
| 508 | + */ |
|
| 509 | 509 | public static function insert_form_button() { |
| 510 | 510 | if ( current_user_can( 'frm_view_forms' ) ) { |
| 511 | 511 | $menu_name = FrmAppHelper::get_menu_name(); |
@@ -516,45 +516,45 @@ discard block |
||
| 516 | 516 | } |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | - public static function insert_form_popup() { |
|
| 519 | + public static function insert_form_popup() { |
|
| 520 | 520 | $page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) ); |
| 521 | 521 | if ( ! in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ) ) { |
| 522 | - return; |
|
| 523 | - } |
|
| 522 | + return; |
|
| 523 | + } |
|
| 524 | 524 | |
| 525 | - FrmAppHelper::load_admin_wide_js(); |
|
| 525 | + FrmAppHelper::load_admin_wide_js(); |
|
| 526 | 526 | |
| 527 | - $shortcodes = array( |
|
| 527 | + $shortcodes = array( |
|
| 528 | 528 | 'formidable' => array( |
| 529 | 529 | 'name' => __( 'Form', 'formidable' ), |
| 530 | 530 | 'label' => __( 'Insert a Form', 'formidable' ), |
| 531 | 531 | ), |
| 532 | - ); |
|
| 532 | + ); |
|
| 533 | 533 | |
| 534 | 534 | $shortcodes = apply_filters( 'frm_popup_shortcodes', $shortcodes ); |
| 535 | 535 | |
| 536 | 536 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php' ); |
| 537 | - } |
|
| 537 | + } |
|
| 538 | 538 | |
| 539 | - public static function get_shortcode_opts() { |
|
| 539 | + public static function get_shortcode_opts() { |
|
| 540 | 540 | FrmAppHelper::permission_check( 'frm_view_forms' ); |
| 541 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
| 541 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
| 542 | 542 | |
| 543 | 543 | $shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' ); |
| 544 | 544 | if ( empty( $shortcode ) ) { |
| 545 | - wp_die(); |
|
| 546 | - } |
|
| 545 | + wp_die(); |
|
| 546 | + } |
|
| 547 | 547 | |
| 548 | 548 | echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">'; |
| 549 | 549 | echo '<input type="radio" name="frmsc" value="' . esc_attr( $shortcode ) . '" id="sc-' . esc_attr( $shortcode ) . '" class="frm_hidden" />'; |
| 550 | 550 | |
| 551 | - $form_id = ''; |
|
| 552 | - $opts = array(); |
|
| 551 | + $form_id = ''; |
|
| 552 | + $opts = array(); |
|
| 553 | 553 | switch ( $shortcode ) { |
| 554 | - case 'formidable': |
|
| 555 | - $opts = array( |
|
| 554 | + case 'formidable': |
|
| 555 | + $opts = array( |
|
| 556 | 556 | 'form_id' => 'id', |
| 557 | - //'key' => ', |
|
| 557 | + //'key' => ', |
|
| 558 | 558 | 'title' => array( |
| 559 | 559 | 'val' => 1, |
| 560 | 560 | 'label' => __( 'Display form title', 'formidable' ), |
@@ -567,8 +567,8 @@ discard block |
||
| 567 | 567 | 'val' => 1, |
| 568 | 568 | 'label' => __( 'Minimize form HTML', 'formidable' ), |
| 569 | 569 | ), |
| 570 | - ); |
|
| 571 | - } |
|
| 570 | + ); |
|
| 571 | + } |
|
| 572 | 572 | $opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode ); |
| 573 | 573 | |
| 574 | 574 | if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) { |
@@ -579,38 +579,38 @@ discard block |
||
| 579 | 579 | |
| 580 | 580 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' ); |
| 581 | 581 | |
| 582 | - echo '</div>'; |
|
| 582 | + echo '</div>'; |
|
| 583 | 583 | |
| 584 | - wp_die(); |
|
| 585 | - } |
|
| 584 | + wp_die(); |
|
| 585 | + } |
|
| 586 | 586 | |
| 587 | 587 | public static function display_forms_list( $params = array(), $message = '', $errors = array() ) { |
| 588 | - FrmAppHelper::permission_check( 'frm_view_forms' ); |
|
| 588 | + FrmAppHelper::permission_check( 'frm_view_forms' ); |
|
| 589 | 589 | |
| 590 | - global $wpdb, $frm_vars; |
|
| 590 | + global $wpdb, $frm_vars; |
|
| 591 | 591 | |
| 592 | 592 | if ( empty( $params ) ) { |
| 593 | 593 | $params = FrmForm::list_page_params(); |
| 594 | - } |
|
| 594 | + } |
|
| 595 | 595 | |
| 596 | - $wp_list_table = new FrmFormsListHelper( compact( 'params' ) ); |
|
| 596 | + $wp_list_table = new FrmFormsListHelper( compact( 'params' ) ); |
|
| 597 | 597 | |
| 598 | - $pagenum = $wp_list_table->get_pagenum(); |
|
| 598 | + $pagenum = $wp_list_table->get_pagenum(); |
|
| 599 | 599 | |
| 600 | - $wp_list_table->prepare_items(); |
|
| 600 | + $wp_list_table->prepare_items(); |
|
| 601 | 601 | |
| 602 | - $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
| 603 | - if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
| 602 | + $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
| 603 | + if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
| 604 | 604 | wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) ); |
| 605 | - die(); |
|
| 606 | - } |
|
| 605 | + die(); |
|
| 606 | + } |
|
| 607 | 607 | |
| 608 | 608 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php' ); |
| 609 | - } |
|
| 609 | + } |
|
| 610 | 610 | |
| 611 | 611 | public static function get_columns( $columns ) { |
| 612 | - $columns['cb'] = '<input type="checkbox" />'; |
|
| 613 | - $columns['id'] = 'ID'; |
|
| 612 | + $columns['cb'] = '<input type="checkbox" />'; |
|
| 613 | + $columns['id'] = 'ID'; |
|
| 614 | 614 | |
| 615 | 615 | $type = FrmAppHelper::get_simple_request( array( |
| 616 | 616 | 'param' => 'form_type', |
@@ -618,18 +618,18 @@ discard block |
||
| 618 | 618 | 'default' => 'published', |
| 619 | 619 | ) ); |
| 620 | 620 | |
| 621 | - if ( 'template' == $type ) { |
|
| 622 | - $columns['name'] = __( 'Template Name', 'formidable' ); |
|
| 623 | - $columns['type'] = __( 'Type', 'formidable' ); |
|
| 624 | - $columns['form_key'] = __( 'Key', 'formidable' ); |
|
| 625 | - } else { |
|
| 626 | - $columns['name'] = __( 'Form Title', 'formidable' ); |
|
| 627 | - $columns['entries'] = __( 'Entries', 'formidable' ); |
|
| 628 | - $columns['form_key'] = __( 'Key', 'formidable' ); |
|
| 629 | - $columns['shortcode'] = __( 'Shortcodes', 'formidable' ); |
|
| 630 | - } |
|
| 621 | + if ( 'template' == $type ) { |
|
| 622 | + $columns['name'] = __( 'Template Name', 'formidable' ); |
|
| 623 | + $columns['type'] = __( 'Type', 'formidable' ); |
|
| 624 | + $columns['form_key'] = __( 'Key', 'formidable' ); |
|
| 625 | + } else { |
|
| 626 | + $columns['name'] = __( 'Form Title', 'formidable' ); |
|
| 627 | + $columns['entries'] = __( 'Entries', 'formidable' ); |
|
| 628 | + $columns['form_key'] = __( 'Key', 'formidable' ); |
|
| 629 | + $columns['shortcode'] = __( 'Shortcodes', 'formidable' ); |
|
| 630 | + } |
|
| 631 | 631 | |
| 632 | - $columns['created_at'] = __( 'Date', 'formidable' ); |
|
| 632 | + $columns['created_at'] = __( 'Date', 'formidable' ); |
|
| 633 | 633 | |
| 634 | 634 | add_screen_option( 'per_page', array( |
| 635 | 635 | 'label' => __( 'Forms', 'formidable' ), |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | 'option' => 'formidable_page_formidable_per_page', |
| 638 | 638 | ) ); |
| 639 | 639 | |
| 640 | - return $columns; |
|
| 640 | + return $columns; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | public static function get_sortable_columns() { |
@@ -665,34 +665,34 @@ discard block |
||
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | public static function save_per_page( $save, $option, $value ) { |
| 668 | - if ( $option == 'formidable_page_formidable_per_page' ) { |
|
| 669 | - $save = (int) $value; |
|
| 670 | - } |
|
| 671 | - return $save; |
|
| 672 | - } |
|
| 668 | + if ( $option == 'formidable_page_formidable_per_page' ) { |
|
| 669 | + $save = (int) $value; |
|
| 670 | + } |
|
| 671 | + return $save; |
|
| 672 | + } |
|
| 673 | 673 | |
| 674 | 674 | private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { |
| 675 | - global $frm_vars; |
|
| 675 | + global $frm_vars; |
|
| 676 | 676 | |
| 677 | - $form = FrmForm::getOne( $id ); |
|
| 678 | - if ( ! $form ) { |
|
| 679 | - wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) ); |
|
| 680 | - } |
|
| 677 | + $form = FrmForm::getOne( $id ); |
|
| 678 | + if ( ! $form ) { |
|
| 679 | + wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) ); |
|
| 680 | + } |
|
| 681 | 681 | |
| 682 | - if ( $form->parent_form_id ) { |
|
| 682 | + if ( $form->parent_form_id ) { |
|
| 683 | 683 | wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form->parent_form_id ) ) . '">', '</a>' ) ); |
| 684 | - } |
|
| 684 | + } |
|
| 685 | 685 | |
| 686 | 686 | $frm_field_selection = FrmField::field_selection(); |
| 687 | 687 | $fields = FrmField::get_all_for_form( $form->id ); |
| 688 | 688 | |
| 689 | - // Automatically add end section fields if they don't exist (2.0 migration) |
|
| 690 | - $reset_fields = false; |
|
| 691 | - FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields ); |
|
| 689 | + // Automatically add end section fields if they don't exist (2.0 migration) |
|
| 690 | + $reset_fields = false; |
|
| 691 | + FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields ); |
|
| 692 | 692 | |
| 693 | - if ( $reset_fields ) { |
|
| 694 | - $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' ); |
|
| 695 | - } |
|
| 693 | + if ( $reset_fields ) { |
|
| 694 | + $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' ); |
|
| 695 | + } |
|
| 696 | 696 | |
| 697 | 697 | unset( $end_section_values, $last_order, $open, $reset_fields ); |
| 698 | 698 | |
@@ -700,30 +700,30 @@ discard block |
||
| 700 | 700 | $values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true, array(), $args ); |
| 701 | 701 | $values['fields'] = $fields; |
| 702 | 702 | |
| 703 | - $edit_message = __( 'Form was Successfully Updated', 'formidable' ); |
|
| 704 | - if ( $form->is_template && $message == $edit_message ) { |
|
| 705 | - $message = __( 'Template was Successfully Updated', 'formidable' ); |
|
| 706 | - } |
|
| 703 | + $edit_message = __( 'Form was Successfully Updated', 'formidable' ); |
|
| 704 | + if ( $form->is_template && $message == $edit_message ) { |
|
| 705 | + $message = __( 'Template was Successfully Updated', 'formidable' ); |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | 708 | $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
| 709 | 709 | |
| 710 | - if ( $form->default_template ) { |
|
| 710 | + if ( $form->default_template ) { |
|
| 711 | 711 | wp_die( esc_html__( 'That template cannot be edited', 'formidable' ) ); |
| 712 | 712 | } elseif ( defined( 'DOING_AJAX' ) ) { |
| 713 | - wp_die(); |
|
| 714 | - } else if ( $create_link ) { |
|
| 713 | + wp_die(); |
|
| 714 | + } else if ( $create_link ) { |
|
| 715 | 715 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' ); |
| 716 | - } else { |
|
| 716 | + } else { |
|
| 717 | 717 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' ); |
| 718 | - } |
|
| 719 | - } |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | 720 | |
| 721 | 721 | public static function get_settings_vars( $id, $errors = array(), $message = '' ) { |
| 722 | 722 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 723 | 723 | |
| 724 | - global $frm_vars; |
|
| 724 | + global $frm_vars; |
|
| 725 | 725 | |
| 726 | - $form = FrmForm::getOne( $id ); |
|
| 726 | + $form = FrmForm::getOne( $id ); |
|
| 727 | 727 | |
| 728 | 728 | $fields = FrmField::get_all_for_form( $id ); |
| 729 | 729 | $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true ); |
@@ -734,17 +734,17 @@ discard block |
||
| 734 | 734 | |
| 735 | 735 | self::clean_submit_html( $values ); |
| 736 | 736 | |
| 737 | - $action_controls = FrmFormActionsController::get_form_actions(); |
|
| 737 | + $action_controls = FrmFormActionsController::get_form_actions(); |
|
| 738 | 738 | |
| 739 | 739 | $sections = apply_filters( 'frm_add_form_settings_section', array(), $values ); |
| 740 | - $pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"'; |
|
| 740 | + $pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"'; |
|
| 741 | 741 | |
| 742 | 742 | $styles = apply_filters( 'frm_get_style_opts', array() ); |
| 743 | 743 | |
| 744 | 744 | $first_h3 = 'frm_first_h3'; |
| 745 | 745 | |
| 746 | 746 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' ); |
| 747 | - } |
|
| 747 | + } |
|
| 748 | 748 | |
| 749 | 749 | /** |
| 750 | 750 | * Replace old Submit Button href with new href to avoid errors in Chrome |
@@ -759,10 +759,10 @@ discard block |
||
| 759 | 759 | } |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - public static function mb_tags_box( $form_id, $class = '' ) { |
|
| 762 | + public static function mb_tags_box( $form_id, $class = '' ) { |
|
| 763 | 763 | $fields = FrmField::get_all_for_form( $form_id, '', 'include' ); |
| 764 | - $linked_forms = array(); |
|
| 765 | - $col = 'one'; |
|
| 764 | + $linked_forms = array(); |
|
| 765 | + $col = 'one'; |
|
| 766 | 766 | $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false; |
| 767 | 767 | |
| 768 | 768 | $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() ); |
@@ -771,7 +771,7 @@ discard block |
||
| 771 | 771 | $entry_shortcodes = self::get_shortcode_helpers( $settings_tab ); |
| 772 | 772 | |
| 773 | 773 | include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' ); |
| 774 | - } |
|
| 774 | + } |
|
| 775 | 775 | |
| 776 | 776 | /** |
| 777 | 777 | * Get an array of the options to display in the advanced tab |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | '' => '', |
| 813 | 813 | 'siteurl' => __( 'Site URL', 'formidable' ), |
| 814 | 814 | 'sitename' => __( 'Site Name', 'formidable' ), |
| 815 | - ); |
|
| 815 | + ); |
|
| 816 | 816 | |
| 817 | 817 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 818 | 818 | unset( $entry_shortcodes['post_id'] ); |
@@ -859,21 +859,21 @@ discard block |
||
| 859 | 859 | wp_die(); |
| 860 | 860 | } |
| 861 | 861 | |
| 862 | - public static function filter_content( $content, $form, $entry = false ) { |
|
| 862 | + public static function filter_content( $content, $form, $entry = false ) { |
|
| 863 | 863 | self::get_entry_by_param( $entry ); |
| 864 | - if ( ! $entry ) { |
|
| 865 | - return $content; |
|
| 866 | - } |
|
| 864 | + if ( ! $entry ) { |
|
| 865 | + return $content; |
|
| 866 | + } |
|
| 867 | 867 | |
| 868 | - if ( is_object( $form ) ) { |
|
| 869 | - $form = $form->id; |
|
| 870 | - } |
|
| 868 | + if ( is_object( $form ) ) { |
|
| 869 | + $form = $form->id; |
|
| 870 | + } |
|
| 871 | 871 | |
| 872 | - $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form ); |
|
| 873 | - $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes ); |
|
| 872 | + $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form ); |
|
| 873 | + $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes ); |
|
| 874 | 874 | |
| 875 | - return $content; |
|
| 876 | - } |
|
| 875 | + return $content; |
|
| 876 | + } |
|
| 877 | 877 | |
| 878 | 878 | private static function get_entry_by_param( &$entry ) { |
| 879 | 879 | if ( ! $entry || ! is_object( $entry ) ) { |
@@ -885,66 +885,66 @@ discard block |
||
| 885 | 885 | } |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | - public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
|
| 889 | - return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes ); |
|
| 890 | - } |
|
| 888 | + public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
|
| 889 | + return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes ); |
|
| 890 | + } |
|
| 891 | 891 | |
| 892 | - public static function process_bulk_form_actions( $errors ) { |
|
| 893 | - if ( ! $_REQUEST ) { |
|
| 894 | - return $errors; |
|
| 895 | - } |
|
| 892 | + public static function process_bulk_form_actions( $errors ) { |
|
| 893 | + if ( ! $_REQUEST ) { |
|
| 894 | + return $errors; |
|
| 895 | + } |
|
| 896 | 896 | |
| 897 | 897 | $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' ); |
| 898 | - if ( $bulkaction == -1 ) { |
|
| 898 | + if ( $bulkaction == -1 ) { |
|
| 899 | 899 | $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' ); |
| 900 | - } |
|
| 900 | + } |
|
| 901 | 901 | |
| 902 | - if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) { |
|
| 903 | - FrmAppHelper::remove_get_action(); |
|
| 902 | + if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) { |
|
| 903 | + FrmAppHelper::remove_get_action(); |
|
| 904 | 904 | |
| 905 | - $bulkaction = str_replace( 'bulk_', '', $bulkaction ); |
|
| 906 | - } |
|
| 905 | + $bulkaction = str_replace( 'bulk_', '', $bulkaction ); |
|
| 906 | + } |
|
| 907 | 907 | |
| 908 | 908 | $ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' ); |
| 909 | - if ( empty( $ids ) ) { |
|
| 910 | - $errors[] = __( 'No forms were specified', 'formidable' ); |
|
| 911 | - return $errors; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
|
| 915 | - if ( $permission_error !== false ) { |
|
| 916 | - $errors[] = $permission_error; |
|
| 917 | - return $errors; |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - if ( ! is_array( $ids ) ) { |
|
| 921 | - $ids = explode( ',', $ids ); |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - switch ( $bulkaction ) { |
|
| 925 | - case 'delete': |
|
| 926 | - $message = self::bulk_destroy( $ids ); |
|
| 909 | + if ( empty( $ids ) ) { |
|
| 910 | + $errors[] = __( 'No forms were specified', 'formidable' ); |
|
| 911 | + return $errors; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
|
| 915 | + if ( $permission_error !== false ) { |
|
| 916 | + $errors[] = $permission_error; |
|
| 917 | + return $errors; |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + if ( ! is_array( $ids ) ) { |
|
| 921 | + $ids = explode( ',', $ids ); |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + switch ( $bulkaction ) { |
|
| 925 | + case 'delete': |
|
| 926 | + $message = self::bulk_destroy( $ids ); |
|
| 927 | 927 | break; |
| 928 | - case 'trash': |
|
| 929 | - $message = self::bulk_trash( $ids ); |
|
| 928 | + case 'trash': |
|
| 929 | + $message = self::bulk_trash( $ids ); |
|
| 930 | 930 | break; |
| 931 | - case 'untrash': |
|
| 932 | - $message = self::bulk_untrash( $ids ); |
|
| 933 | - } |
|
| 931 | + case 'untrash': |
|
| 932 | + $message = self::bulk_untrash( $ids ); |
|
| 933 | + } |
|
| 934 | 934 | |
| 935 | - if ( isset( $message ) && ! empty( $message ) ) { |
|
| 935 | + if ( isset( $message ) && ! empty( $message ) ) { |
|
| 936 | 936 | echo '<div id="message" class="updated frm_updated_message">' . FrmAppHelper::kses( $message, array( 'a' ) ) . '</div>'; // WPCS: XSS ok. |
| 937 | - } |
|
| 937 | + } |
|
| 938 | 938 | |
| 939 | - return $errors; |
|
| 940 | - } |
|
| 939 | + return $errors; |
|
| 940 | + } |
|
| 941 | 941 | |
| 942 | 942 | /** |
| 943 | 943 | * @deprecated 1.07.05 |
| 944 | 944 | * @codeCoverageIgnore |
| 945 | 945 | */ |
| 946 | - public static function add_default_templates( $path, $default = true, $template = true ) { |
|
| 947 | - _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' ); |
|
| 946 | + public static function add_default_templates( $path, $default = true, $template = true ) { |
|
| 947 | + _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' ); |
|
| 948 | 948 | |
| 949 | 949 | $path = untrailingslashit( trim( $path ) ); |
| 950 | 950 | $templates = glob( $path . '/*.php' ); |
@@ -952,130 +952,130 @@ discard block |
||
| 952 | 952 | for ( $i = count( $templates ) - 1; $i >= 0; $i-- ) { |
| 953 | 953 | $filename = str_replace( '.php', '', str_replace( $path . '/', '', $templates[ $i ] ) ); |
| 954 | 954 | $template_query = array( 'form_key' => $filename ); |
| 955 | - if ( $template ) { |
|
| 956 | - $template_query['is_template'] = 1; |
|
| 957 | - } |
|
| 958 | - if ( $default ) { |
|
| 959 | - $template_query['default_template'] = 1; |
|
| 960 | - } |
|
| 955 | + if ( $template ) { |
|
| 956 | + $template_query['is_template'] = 1; |
|
| 957 | + } |
|
| 958 | + if ( $default ) { |
|
| 959 | + $template_query['default_template'] = 1; |
|
| 960 | + } |
|
| 961 | 961 | $form = FrmForm::getAll( $template_query, '', 1 ); |
| 962 | 962 | |
| 963 | - $values = FrmFormsHelper::setup_new_vars(); |
|
| 964 | - $values['form_key'] = $filename; |
|
| 965 | - $values['is_template'] = $template; |
|
| 966 | - $values['status'] = 'published'; |
|
| 967 | - if ( $default ) { |
|
| 968 | - $values['default_template'] = 1; |
|
| 969 | - } |
|
| 963 | + $values = FrmFormsHelper::setup_new_vars(); |
|
| 964 | + $values['form_key'] = $filename; |
|
| 965 | + $values['is_template'] = $template; |
|
| 966 | + $values['status'] = 'published'; |
|
| 967 | + if ( $default ) { |
|
| 968 | + $values['default_template'] = 1; |
|
| 969 | + } |
|
| 970 | 970 | |
| 971 | - include( $templates[ $i ] ); |
|
| 971 | + include( $templates[ $i ] ); |
|
| 972 | 972 | |
| 973 | - //get updated form |
|
| 973 | + //get updated form |
|
| 974 | 974 | if ( isset( $form ) && ! empty( $form ) ) { |
| 975 | - $old_id = $form->id; |
|
| 975 | + $old_id = $form->id; |
|
| 976 | 976 | $form = FrmForm::getOne( $form->id ); |
| 977 | - } else { |
|
| 978 | - $old_id = false; |
|
| 977 | + } else { |
|
| 978 | + $old_id = false; |
|
| 979 | 979 | $form = FrmForm::getAll( $template_query, '', 1 ); |
| 980 | - } |
|
| 980 | + } |
|
| 981 | 981 | |
| 982 | - if ( $form ) { |
|
| 982 | + if ( $form ) { |
|
| 983 | 983 | do_action( 'frm_after_duplicate_form', $form->id, (array) $form, array( 'old_id' => $old_id ) ); |
| 984 | - } |
|
| 985 | - } |
|
| 986 | - } |
|
| 984 | + } |
|
| 985 | + } |
|
| 986 | + } |
|
| 987 | 987 | |
| 988 | - public static function route() { |
|
| 988 | + public static function route() { |
|
| 989 | 989 | $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
| 990 | - $vars = array(); |
|
| 990 | + $vars = array(); |
|
| 991 | 991 | if ( isset( $_POST['frm_compact_fields'] ) ) { |
| 992 | 992 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 993 | 993 | |
| 994 | 994 | $json_vars = htmlspecialchars_decode( nl2br( stripslashes( str_replace( '"', '\\\"', $_POST['frm_compact_fields'] ) ) ) ); |
| 995 | 995 | $json_vars = json_decode( $json_vars, true ); |
| 996 | 996 | if ( empty( $json_vars ) ) { |
| 997 | - // json decoding failed so we should return an error message |
|
| 997 | + // json decoding failed so we should return an error message |
|
| 998 | 998 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 999 | - if ( 'edit' == $action ) { |
|
| 1000 | - $action = 'update'; |
|
| 1001 | - } |
|
| 999 | + if ( 'edit' == $action ) { |
|
| 1000 | + $action = 'update'; |
|
| 1001 | + } |
|
| 1002 | 1002 | |
| 1003 | 1003 | add_filter( 'frm_validate_form', 'FrmFormsController::json_error' ); |
| 1004 | - } else { |
|
| 1004 | + } else { |
|
| 1005 | 1005 | $vars = FrmAppHelper::json_to_array( $json_vars ); |
| 1006 | - $action = $vars[ $action ]; |
|
| 1006 | + $action = $vars[ $action ]; |
|
| 1007 | 1007 | unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] ); |
| 1008 | 1008 | $_REQUEST = array_merge( $_REQUEST, $vars ); |
| 1009 | 1009 | $_POST = array_merge( $_POST, $_REQUEST ); |
| 1010 | - } |
|
| 1011 | - } else { |
|
| 1010 | + } |
|
| 1011 | + } else { |
|
| 1012 | 1012 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 1013 | - if ( isset( $_REQUEST['delete_all'] ) ) { |
|
| 1014 | - // override the action for this page |
|
| 1015 | - $action = 'delete_all'; |
|
| 1016 | - } |
|
| 1017 | - } |
|
| 1013 | + if ( isset( $_REQUEST['delete_all'] ) ) { |
|
| 1014 | + // override the action for this page |
|
| 1015 | + $action = 'delete_all'; |
|
| 1016 | + } |
|
| 1017 | + } |
|
| 1018 | 1018 | |
| 1019 | 1019 | add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' ); |
| 1020 | - FrmAppHelper::trigger_hook_load( 'form' ); |
|
| 1020 | + FrmAppHelper::trigger_hook_load( 'form' ); |
|
| 1021 | 1021 | |
| 1022 | - switch ( $action ) { |
|
| 1023 | - case 'new': |
|
| 1022 | + switch ( $action ) { |
|
| 1023 | + case 'new': |
|
| 1024 | 1024 | return self::new_form( $vars ); |
| 1025 | - case 'create': |
|
| 1026 | - case 'edit': |
|
| 1027 | - case 'update': |
|
| 1028 | - case 'duplicate': |
|
| 1029 | - case 'trash': |
|
| 1030 | - case 'untrash': |
|
| 1031 | - case 'destroy': |
|
| 1032 | - case 'delete_all': |
|
| 1033 | - case 'settings': |
|
| 1034 | - case 'update_settings': |
|
| 1025 | + case 'create': |
|
| 1026 | + case 'edit': |
|
| 1027 | + case 'update': |
|
| 1028 | + case 'duplicate': |
|
| 1029 | + case 'trash': |
|
| 1030 | + case 'untrash': |
|
| 1031 | + case 'destroy': |
|
| 1032 | + case 'delete_all': |
|
| 1033 | + case 'settings': |
|
| 1034 | + case 'update_settings': |
|
| 1035 | 1035 | return self::$action( $vars ); |
| 1036 | - default: |
|
| 1036 | + default: |
|
| 1037 | 1037 | do_action( 'frm_form_action_' . $action ); |
| 1038 | 1038 | if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) { |
| 1039 | - return; |
|
| 1040 | - } |
|
| 1039 | + return; |
|
| 1040 | + } |
|
| 1041 | 1041 | |
| 1042 | 1042 | $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' ); |
| 1043 | - if ( $action == -1 ) { |
|
| 1043 | + if ( $action == -1 ) { |
|
| 1044 | 1044 | $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' ); |
| 1045 | - } |
|
| 1045 | + } |
|
| 1046 | 1046 | |
| 1047 | 1047 | if ( strpos( $action, 'bulk_' ) === 0 ) { |
| 1048 | - FrmAppHelper::remove_get_action(); |
|
| 1049 | - return self::list_form(); |
|
| 1050 | - } |
|
| 1048 | + FrmAppHelper::remove_get_action(); |
|
| 1049 | + return self::list_form(); |
|
| 1050 | + } |
|
| 1051 | 1051 | |
| 1052 | - return self::display_forms_list(); |
|
| 1053 | - } |
|
| 1054 | - } |
|
| 1052 | + return self::display_forms_list(); |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | 1055 | |
| 1056 | - public static function json_error( $errors ) { |
|
| 1057 | - $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' ); |
|
| 1058 | - return $errors; |
|
| 1059 | - } |
|
| 1056 | + public static function json_error( $errors ) { |
|
| 1057 | + $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' ); |
|
| 1058 | + return $errors; |
|
| 1059 | + } |
|
| 1060 | 1060 | |
| 1061 | 1061 | |
| 1062 | - /* FRONT-END FORMS */ |
|
| 1063 | - public static function admin_bar_css() { |
|
| 1062 | + /* FRONT-END FORMS */ |
|
| 1063 | + public static function admin_bar_css() { |
|
| 1064 | 1064 | if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
| 1065 | - return; |
|
| 1066 | - } |
|
| 1065 | + return; |
|
| 1066 | + } |
|
| 1067 | 1067 | |
| 1068 | 1068 | add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' ); |
| 1069 | 1069 | FrmAppHelper::load_font_style(); |
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | 1072 | public static function admin_bar_configure() { |
| 1073 | - global $frm_vars; |
|
| 1073 | + global $frm_vars; |
|
| 1074 | 1074 | if ( empty( $frm_vars['forms_loaded'] ) ) { |
| 1075 | - return; |
|
| 1076 | - } |
|
| 1075 | + return; |
|
| 1076 | + } |
|
| 1077 | 1077 | |
| 1078 | - $actions = array(); |
|
| 1078 | + $actions = array(); |
|
| 1079 | 1079 | foreach ( $frm_vars['forms_loaded'] as $form ) { |
| 1080 | 1080 | if ( is_object( $form ) ) { |
| 1081 | 1081 | $actions[ $form->id ] = $form->name; |
@@ -1126,18 +1126,18 @@ discard block |
||
| 1126 | 1126 | } |
| 1127 | 1127 | } |
| 1128 | 1128 | |
| 1129 | - //formidable shortcode |
|
| 1129 | + //formidable shortcode |
|
| 1130 | 1130 | public static function get_form_shortcode( $atts ) { |
| 1131 | - global $frm_vars; |
|
| 1131 | + global $frm_vars; |
|
| 1132 | 1132 | if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) { |
| 1133 | - $sc = '[formidable'; |
|
| 1133 | + $sc = '[formidable'; |
|
| 1134 | 1134 | if ( ! empty( $atts ) ) { |
| 1135 | 1135 | foreach ( $atts as $k => $v ) { |
| 1136 | 1136 | $sc .= ' ' . $k . '="' . esc_attr( $v ) . '"'; |
| 1137 | 1137 | } |
| 1138 | 1138 | } |
| 1139 | 1139 | return $sc . ']'; |
| 1140 | - } |
|
| 1140 | + } |
|
| 1141 | 1141 | |
| 1142 | 1142 | $shortcode_atts = shortcode_atts( array( |
| 1143 | 1143 | 'id' => '', |
@@ -1152,30 +1152,30 @@ discard block |
||
| 1152 | 1152 | ), $atts ); |
| 1153 | 1153 | do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts ); |
| 1154 | 1154 | |
| 1155 | - return self::show_form( |
|
| 1156 | - $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], |
|
| 1157 | - $shortcode_atts['description'], $atts |
|
| 1158 | - ); |
|
| 1159 | - } |
|
| 1155 | + return self::show_form( |
|
| 1156 | + $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], |
|
| 1157 | + $shortcode_atts['description'], $atts |
|
| 1158 | + ); |
|
| 1159 | + } |
|
| 1160 | 1160 | |
| 1161 | - public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) { |
|
| 1162 | - if ( empty( $id ) ) { |
|
| 1163 | - $id = $key; |
|
| 1164 | - } |
|
| 1161 | + public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) { |
|
| 1162 | + if ( empty( $id ) ) { |
|
| 1163 | + $id = $key; |
|
| 1164 | + } |
|
| 1165 | 1165 | |
| 1166 | - $form = self::maybe_get_form_to_show( $id ); |
|
| 1167 | - if ( ! $form ) { |
|
| 1168 | - return __( 'Please select a valid form', 'formidable' ); |
|
| 1169 | - } |
|
| 1166 | + $form = self::maybe_get_form_to_show( $id ); |
|
| 1167 | + if ( ! $form ) { |
|
| 1168 | + return __( 'Please select a valid form', 'formidable' ); |
|
| 1169 | + } |
|
| 1170 | 1170 | |
| 1171 | 1171 | FrmAppController::maybe_update_styles(); |
| 1172 | 1172 | |
| 1173 | 1173 | add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' ); |
| 1174 | - FrmAppHelper::trigger_hook_load( 'form', $form ); |
|
| 1174 | + FrmAppHelper::trigger_hook_load( 'form', $form ); |
|
| 1175 | 1175 | |
| 1176 | - $form = apply_filters( 'frm_pre_display_form', $form ); |
|
| 1176 | + $form = apply_filters( 'frm_pre_display_form', $form ); |
|
| 1177 | 1177 | |
| 1178 | - $frm_settings = FrmAppHelper::get_settings(); |
|
| 1178 | + $frm_settings = FrmAppHelper::get_settings(); |
|
| 1179 | 1179 | |
| 1180 | 1180 | if ( self::is_viewable_draft_form( $form ) ) { |
| 1181 | 1181 | // don't show a draft form on a page |
@@ -1197,7 +1197,7 @@ discard block |
||
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | return $form; |
| 1200 | - } |
|
| 1200 | + } |
|
| 1201 | 1201 | |
| 1202 | 1202 | private static function maybe_get_form_to_show( $id ) { |
| 1203 | 1203 | $form = false; |
@@ -1226,21 +1226,21 @@ discard block |
||
| 1226 | 1226 | return $form->logged_in && get_current_user_id() && isset( $form->options['logged_in_role'] ) && $form->options['logged_in_role'] != '' && ! FrmAppHelper::user_has_permission( $form->options['logged_in_role'] ); |
| 1227 | 1227 | } |
| 1228 | 1228 | |
| 1229 | - public static function get_form( $form, $title, $description, $atts = array() ) { |
|
| 1229 | + public static function get_form( $form, $title, $description, $atts = array() ) { |
|
| 1230 | 1230 | ob_start(); |
| 1231 | 1231 | |
| 1232 | 1232 | do_action( 'frm_before_get_form', $atts ); |
| 1233 | 1233 | |
| 1234 | - self::get_form_contents( $form, $title, $description, $atts ); |
|
| 1234 | + self::get_form_contents( $form, $title, $description, $atts ); |
|
| 1235 | 1235 | self::enqueue_scripts( FrmForm::get_params( $form ) ); |
| 1236 | 1236 | |
| 1237 | - $contents = ob_get_contents(); |
|
| 1238 | - ob_end_clean(); |
|
| 1237 | + $contents = ob_get_contents(); |
|
| 1238 | + ob_end_clean(); |
|
| 1239 | 1239 | |
| 1240 | 1240 | self::maybe_minimize_form( $atts, $contents ); |
| 1241 | 1241 | |
| 1242 | - return $contents; |
|
| 1243 | - } |
|
| 1242 | + return $contents; |
|
| 1243 | + } |
|
| 1244 | 1244 | |
| 1245 | 1245 | public static function enqueue_scripts( $params ) { |
| 1246 | 1246 | do_action( 'frm_enqueue_form_scripts', $params ); |
@@ -1580,10 +1580,10 @@ discard block |
||
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | 1582 | public static function defer_script_loading( $tag, $handle ) { |
| 1583 | - if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) { |
|
| 1584 | - $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag ); |
|
| 1583 | + if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) { |
|
| 1584 | + $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag ); |
|
| 1585 | 1585 | } |
| 1586 | - return $tag; |
|
| 1586 | + return $tag; |
|
| 1587 | 1587 | } |
| 1588 | 1588 | |
| 1589 | 1589 | public static function footer_js( $location = 'footer' ) { |
@@ -281,6 +281,7 @@ |
||
| 281 | 281 | * @param string|array $where |
| 282 | 282 | * @param string $order_by |
| 283 | 283 | * @param string $limit |
| 284 | + * @param boolean $unique |
|
| 284 | 285 | */ |
| 285 | 286 | private static function get_ids_query( $where, $order_by, $limit, $unique, $args, array &$query ) { |
| 286 | 287 | global $wpdb; |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | if ( ( is_array( $meta_value ) && empty( $meta_value ) ) || ( ! is_array( $meta_value ) && trim( $meta_value ) == '' ) ) { |
| 122 | 122 | // remove blank fields |
| 123 | - unset( $values[ $field_id ] ); |
|
| 123 | + unset( $values[$field_id] ); |
|
| 124 | 124 | } else { |
| 125 | 125 | // if value exists, then update it |
| 126 | 126 | self::update_entry_meta( $entry_id, $field_id, '', $meta_value ); |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public static function get_meta_value( $entry, $field_id ) { |
| 186 | 186 | if ( isset( $entry->metas ) ) { |
| 187 | - return isset( $entry->metas[ $field_id ] ) ? $entry->metas[ $field_id ] : false; |
|
| 187 | + return isset( $entry->metas[$field_id] ) ? $entry->metas[$field_id] : false; |
|
| 188 | 188 | } else { |
| 189 | 189 | return self::get_entry_meta_by_field( $entry->id, $field_id ); |
| 190 | 190 | } |
@@ -202,8 +202,8 @@ discard block |
||
| 202 | 202 | $cached = FrmDb::check_cache( $entry_id, 'frm_entry' ); |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) { |
|
| 206 | - $result = $cached->metas[ $field_id ]; |
|
| 205 | + if ( $cached && isset( $cached->metas ) && isset( $cached->metas[$field_id] ) ) { |
|
| 206 | + $result = $cached->metas[$field_id]; |
|
| 207 | 207 | return stripslashes_deep( $result ); |
| 208 | 208 | } |
| 209 | 209 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | foreach ( $values as $k => $v ) { |
| 247 | - $values[ $k ] = maybe_unserialize( $v ); |
|
| 247 | + $values[$k] = maybe_unserialize( $v ); |
|
| 248 | 248 | unset( $k, $v ); |
| 249 | 249 | } |
| 250 | 250 | |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | foreach ( $results as $k => $result ) { |
| 303 | - $results[ $k ]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) ); |
|
| 303 | + $results[$k]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) ); |
|
| 304 | 304 | unset( $k, $result ); |
| 305 | 305 | } |
| 306 | 306 | |
@@ -5,23 +5,23 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | class FrmEntryMeta { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * @param string $meta_key |
|
| 10 | - */ |
|
| 8 | + /** |
|
| 9 | + * @param string $meta_key |
|
| 10 | + */ |
|
| 11 | 11 | public static function add_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) { |
| 12 | - global $wpdb; |
|
| 12 | + global $wpdb; |
|
| 13 | 13 | |
| 14 | - if ( FrmAppHelper::is_empty_value( $meta_value ) ) { |
|
| 15 | - // don't save blank fields |
|
| 16 | - return 0; |
|
| 17 | - } |
|
| 14 | + if ( FrmAppHelper::is_empty_value( $meta_value ) ) { |
|
| 15 | + // don't save blank fields |
|
| 16 | + return 0; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - $new_values = array( |
|
| 19 | + $new_values = array( |
|
| 20 | 20 | 'meta_value' => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ), |
| 21 | - 'item_id' => $entry_id, |
|
| 22 | - 'field_id' => $field_id, |
|
| 21 | + 'item_id' => $entry_id, |
|
| 22 | + 'field_id' => $field_id, |
|
| 23 | 23 | 'created_at' => current_time( 'mysql', 1 ), |
| 24 | - ); |
|
| 24 | + ); |
|
| 25 | 25 | |
| 26 | 26 | self::set_value_before_save( $new_values ); |
| 27 | 27 | $new_values = apply_filters( 'frm_add_entry_meta', $new_values ); |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | $id = 0; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - return $id; |
|
| 40 | - } |
|
| 39 | + return $id; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * @param int $entry_id |
@@ -48,18 +48,18 @@ discard block |
||
| 48 | 48 | * @return bool|false|int |
| 49 | 49 | */ |
| 50 | 50 | public static function update_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) { |
| 51 | - if ( ! $field_id ) { |
|
| 52 | - return false; |
|
| 53 | - } |
|
| 51 | + if ( ! $field_id ) { |
|
| 52 | + return false; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - global $wpdb; |
|
| 55 | + global $wpdb; |
|
| 56 | 56 | |
| 57 | 57 | $values = array( |
| 58 | 58 | 'item_id' => $entry_id, |
| 59 | 59 | 'field_id' => $field_id, |
| 60 | 60 | ); |
| 61 | 61 | $where_values = $values; |
| 62 | - $values['meta_value'] = $meta_value; |
|
| 62 | + $values['meta_value'] = $meta_value; |
|
| 63 | 63 | self::set_value_before_save( $values ); |
| 64 | 64 | $values = apply_filters( 'frm_update_entry_meta', $values ); |
| 65 | 65 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | self::clear_cache(); |
| 73 | 73 | |
| 74 | 74 | return $wpdb->update( $wpdb->prefix . 'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values ); |
| 75 | - } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * @since 3.0 |
@@ -101,14 +101,14 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | public static function update_entry_metas( $entry_id, $values ) { |
| 104 | - global $wpdb; |
|
| 104 | + global $wpdb; |
|
| 105 | 105 | |
| 106 | 106 | $prev_values = FrmDb::get_col( $wpdb->prefix . 'frm_item_metas', array( |
| 107 | 107 | 'item_id' => $entry_id, |
| 108 | 108 | 'field_id !' => 0, |
| 109 | 109 | ), 'field_id' ); |
| 110 | 110 | |
| 111 | - foreach ( $values as $field_id => $meta_value ) { |
|
| 111 | + foreach ( $values as $field_id => $meta_value ) { |
|
| 112 | 112 | $field = false; |
| 113 | 113 | if ( ! empty( $field_id ) ) { |
| 114 | 114 | $field = FrmField::getOne( $field_id ); |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | // Delete any leftovers |
| 152 | 152 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) ); // WPCS: unprepared SQL ok. |
| 153 | 153 | self::clear_cache(); |
| 154 | - } |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | public static function duplicate_entry_metas( $old_id, $new_id ) { |
| 157 | 157 | $metas = self::get_entry_meta_info( $old_id ); |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | public static function delete_entry_meta( $entry_id, $field_id ) { |
| 166 | - global $wpdb; |
|
| 166 | + global $wpdb; |
|
| 167 | 167 | self::clear_cache(); |
| 168 | 168 | return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id ) ); |
| 169 | - } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | 171 | /** |
| 172 | 172 | * Clear entry meta caching |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | public static function get_entry_meta_by_field( $entry_id, $field_id ) { |
| 194 | - global $wpdb; |
|
| 194 | + global $wpdb; |
|
| 195 | 195 | |
| 196 | 196 | if ( is_object( $entry_id ) ) { |
| 197 | 197 | $entry = $entry_id; |
@@ -205,89 +205,89 @@ discard block |
||
| 205 | 205 | if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) { |
| 206 | 206 | $result = $cached->metas[ $field_id ]; |
| 207 | 207 | return stripslashes_deep( $result ); |
| 208 | - } |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | 210 | $get_table = $wpdb->prefix . 'frm_item_metas'; |
| 211 | 211 | $query = array( 'item_id' => $entry_id ); |
| 212 | 212 | if ( is_numeric( $field_id ) ) { |
| 213 | 213 | $query['field_id'] = $field_id; |
| 214 | - } else { |
|
| 214 | + } else { |
|
| 215 | 215 | $get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id'; |
| 216 | 216 | $query['fi.field_key'] = $field_id; |
| 217 | - } |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | 219 | $result = FrmDb::get_var( $get_table, $query, 'meta_value' ); |
| 220 | 220 | $result = maybe_unserialize( $result ); |
| 221 | 221 | $result = stripslashes_deep( $result ); |
| 222 | 222 | |
| 223 | - return $result; |
|
| 224 | - } |
|
| 223 | + return $result; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) { |
|
| 226 | + public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) { |
|
| 227 | 227 | $defaults = array( |
| 228 | 228 | 'value' => false, |
| 229 | 229 | 'unique' => false, |
| 230 | 230 | 'stripslashes' => true, |
| 231 | 231 | 'is_draft' => false, |
| 232 | 232 | ); |
| 233 | - $args = wp_parse_args( $args, $defaults ); |
|
| 233 | + $args = wp_parse_args( $args, $defaults ); |
|
| 234 | 234 | |
| 235 | - $query = array(); |
|
| 235 | + $query = array(); |
|
| 236 | 236 | self::meta_field_query( $field_id, $order, $limit, $args, $query ); |
| 237 | 237 | $query = implode( ' ', $query ); |
| 238 | 238 | |
| 239 | 239 | $cache_key = 'entry_metas_for_field_' . $field_id . $order . $limit . maybe_serialize( $args ); |
| 240 | 240 | $values = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_col' ); |
| 241 | 241 | |
| 242 | - if ( ! $args['stripslashes'] ) { |
|
| 243 | - return $values; |
|
| 244 | - } |
|
| 242 | + if ( ! $args['stripslashes'] ) { |
|
| 243 | + return $values; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | 246 | foreach ( $values as $k => $v ) { |
| 247 | 247 | $values[ $k ] = maybe_unserialize( $v ); |
| 248 | 248 | unset( $k, $v ); |
| 249 | - } |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | 251 | return stripslashes_deep( $values ); |
| 252 | - } |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * @param string $order |
|
| 256 | - * @param string $limit |
|
| 257 | - */ |
|
| 254 | + /** |
|
| 255 | + * @param string $order |
|
| 256 | + * @param string $limit |
|
| 257 | + */ |
|
| 258 | 258 | private static function meta_field_query( $field_id, $order, $limit, $args, array &$query ) { |
| 259 | - global $wpdb; |
|
| 260 | - $query[] = 'SELECT'; |
|
| 261 | - $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value'; |
|
| 259 | + global $wpdb; |
|
| 260 | + $query[] = 'SELECT'; |
|
| 261 | + $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value'; |
|
| 262 | 262 | $query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas em '; |
| 263 | 263 | |
| 264 | - if ( ! $args['is_draft'] ) { |
|
| 264 | + if ( ! $args['is_draft'] ) { |
|
| 265 | 265 | $query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)'; |
| 266 | - } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | 268 | if ( is_numeric( $field_id ) ) { |
| 269 | 269 | $query[] = $wpdb->prepare( 'WHERE em.field_id=%d', $field_id ); |
| 270 | 270 | } else { |
| 271 | 271 | $query[] = $wpdb->prepare( 'LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id ); |
| 272 | - } |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - if ( ! $args['is_draft'] ) { |
|
| 275 | - $query[] = 'AND e.is_draft=0'; |
|
| 276 | - } |
|
| 274 | + if ( ! $args['is_draft'] ) { |
|
| 275 | + $query[] = 'AND e.is_draft=0'; |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - if ( $args['value'] ) { |
|
| 278 | + if ( $args['value'] ) { |
|
| 279 | 279 | $query[] = $wpdb->prepare( ' AND meta_value=%s', $args['value'] ); |
| 280 | - } |
|
| 281 | - $query[] = $order . $limit; |
|
| 282 | - } |
|
| 280 | + } |
|
| 281 | + $query[] = $order . $limit; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | 284 | public static function get_entry_meta_info( $entry_id ) { |
| 285 | 285 | return FrmDb::get_results( 'frm_item_metas', array( 'item_id' => $entry_id ) ); |
| 286 | - } |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | 288 | public static function getAll( $where = array(), $order_by = '', $limit = '', $stripslashes = false ) { |
| 289 | - global $wpdb; |
|
| 290 | - $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key, |
|
| 289 | + global $wpdb; |
|
| 290 | + $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key, |
|
| 291 | 291 | fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options |
| 292 | 292 | FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id' . |
| 293 | 293 | FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
@@ -305,9 +305,9 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | return $results; |
| 308 | - } |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) { |
|
| 310 | + public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) { |
|
| 311 | 311 | $defaults = array( |
| 312 | 312 | 'is_draft' => false, |
| 313 | 313 | 'user_id' => '', |
@@ -315,22 +315,22 @@ discard block |
||
| 315 | 315 | ); |
| 316 | 316 | $args = wp_parse_args( $args, $defaults ); |
| 317 | 317 | |
| 318 | - $query = array(); |
|
| 318 | + $query = array(); |
|
| 319 | 319 | self::get_ids_query( $where, $order_by, $limit, $unique, $args, $query ); |
| 320 | 320 | $query = implode( ' ', $query ); |
| 321 | 321 | |
| 322 | 322 | $cache_key = 'ids_' . maybe_serialize( $where ) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize( $args ); |
| 323 | 323 | return FrmDb::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_var' : 'get_col' ) ); |
| 324 | - } |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - /** |
|
| 327 | - * @param string|array $where |
|
| 328 | - * @param string $order_by |
|
| 329 | - * @param string $limit |
|
| 330 | - */ |
|
| 326 | + /** |
|
| 327 | + * @param string|array $where |
|
| 328 | + * @param string $order_by |
|
| 329 | + * @param string $limit |
|
| 330 | + */ |
|
| 331 | 331 | private static function get_ids_query( $where, $order_by, $limit, $unique, $args, array &$query ) { |
| 332 | - global $wpdb; |
|
| 333 | - $query[] = 'SELECT'; |
|
| 332 | + global $wpdb; |
|
| 333 | + $query[] = 'SELECT'; |
|
| 334 | 334 | |
| 335 | 335 | $defaults = array( 'return_parent_id' => false ); |
| 336 | 336 | $args = array_merge( $defaults, $args ); |
@@ -345,30 +345,30 @@ discard block |
||
| 345 | 345 | |
| 346 | 346 | $query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)'; |
| 347 | 347 | if ( is_array( $where ) ) { |
| 348 | - if ( ! $args['is_draft'] ) { |
|
| 349 | - $where['e.is_draft'] = 0; |
|
| 350 | - } else if ( $args['is_draft'] == 1 ) { |
|
| 351 | - $where['e.is_draft'] = 1; |
|
| 352 | - } |
|
| 348 | + if ( ! $args['is_draft'] ) { |
|
| 349 | + $where['e.is_draft'] = 0; |
|
| 350 | + } else if ( $args['is_draft'] == 1 ) { |
|
| 351 | + $where['e.is_draft'] = 1; |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | 354 | if ( ! empty( $args['user_id'] ) ) { |
| 355 | - $where['e.user_id'] = $args['user_id']; |
|
| 356 | - } |
|
| 355 | + $where['e.user_id'] = $args['user_id']; |
|
| 356 | + } |
|
| 357 | 357 | $query[] = FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
| 358 | 358 | |
| 359 | 359 | if ( $args['group_by'] ) { |
| 360 | 360 | $query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] ); |
| 361 | 361 | } |
| 362 | - return; |
|
| 363 | - } |
|
| 362 | + return; |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | 365 | $draft_where = ''; |
| 366 | 366 | $user_where = ''; |
| 367 | - if ( ! $args['is_draft'] ) { |
|
| 367 | + if ( ! $args['is_draft'] ) { |
|
| 368 | 368 | $draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 0 ); |
| 369 | - } else if ( $args['is_draft'] == 1 ) { |
|
| 369 | + } else if ( $args['is_draft'] == 1 ) { |
|
| 370 | 370 | $draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 ); |
| 371 | - } |
|
| 371 | + } |
|
| 372 | 372 | |
| 373 | 373 | if ( ! empty( $args['user_id'] ) ) { |
| 374 | 374 | $user_where = $wpdb->prepare( ' AND e.user_id=%d', $args['user_id'] ); |
@@ -377,56 +377,56 @@ discard block |
||
| 377 | 377 | if ( strpos( $where, ' GROUP BY ' ) ) { |
| 378 | 378 | // don't inject WHERE filtering after GROUP BY |
| 379 | 379 | $parts = explode( ' GROUP BY ', $where ); |
| 380 | - $where = $parts[0]; |
|
| 381 | - $where .= $draft_where . $user_where; |
|
| 380 | + $where = $parts[0]; |
|
| 381 | + $where .= $draft_where . $user_where; |
|
| 382 | 382 | $where .= ' GROUP BY ' . $parts[1]; |
| 383 | - } else { |
|
| 384 | - $where .= $draft_where . $user_where; |
|
| 385 | - } |
|
| 383 | + } else { |
|
| 384 | + $where .= $draft_where . $user_where; |
|
| 385 | + } |
|
| 386 | 386 | |
| 387 | 387 | // The query has already been prepared |
| 388 | 388 | $query[] = FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
| 389 | - } |
|
| 389 | + } |
|
| 390 | 390 | |
| 391 | - public static function search_entry_metas( $search, $field_id = '', $operator ) { |
|
| 391 | + public static function search_entry_metas( $search, $field_id = '', $operator ) { |
|
| 392 | 392 | $cache_key = 'search_' . maybe_serialize( $search ) . $field_id . $operator; |
| 393 | 393 | $results = wp_cache_get( $cache_key, 'frm_entry' ); |
| 394 | - if ( false !== $results ) { |
|
| 395 | - return $results; |
|
| 396 | - } |
|
| 394 | + if ( false !== $results ) { |
|
| 395 | + return $results; |
|
| 396 | + } |
|
| 397 | 397 | |
| 398 | - global $wpdb; |
|
| 398 | + global $wpdb; |
|
| 399 | 399 | if ( is_array( $search ) ) { |
| 400 | - $where = ''; |
|
| 400 | + $where = ''; |
|
| 401 | 401 | foreach ( $search as $field => $value ) { |
| 402 | 402 | if ( $value <= 0 || ! in_array( $field, array( 'year', 'month', 'day' ) ) ) { |
| 403 | - continue; |
|
| 404 | - } |
|
| 403 | + continue; |
|
| 404 | + } |
|
| 405 | 405 | |
| 406 | - switch ( $field ) { |
|
| 407 | - case 'year': |
|
| 406 | + switch ( $field ) { |
|
| 407 | + case 'year': |
|
| 408 | 408 | $value = '%' . $value; |
| 409 | 409 | break; |
| 410 | - case 'month': |
|
| 411 | - $value .= '%'; |
|
| 410 | + case 'month': |
|
| 411 | + $value .= '%'; |
|
| 412 | 412 | break; |
| 413 | - case 'day': |
|
| 413 | + case 'day': |
|
| 414 | 414 | $value = '%' . $value . '%'; |
| 415 | - } |
|
| 415 | + } |
|
| 416 | 416 | $where .= $wpdb->prepare( ' meta_value ' . $operator . ' %s and', $value ); // WPCS: unprepared SQL ok. |
| 417 | - } |
|
| 417 | + } |
|
| 418 | 418 | $where .= $wpdb->prepare( ' field_id=%d', $field_id ); |
| 419 | 419 | $query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmDb::prepend_and_or_where( ' WHERE ', $where ); |
| 420 | - } else { |
|
| 420 | + } else { |
|
| 421 | 421 | if ( $operator == 'LIKE' ) { |
| 422 | - $search = '%' . $search . '%'; |
|
| 422 | + $search = '%' . $search . '%'; |
|
| 423 | 423 | } |
| 424 | 424 | $query = $wpdb->prepare( "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id ); // WPCS: unprepared SQL ok. |
| 425 | - } |
|
| 425 | + } |
|
| 426 | 426 | |
| 427 | 427 | $results = $wpdb->get_col( $query, 0 ); // WPCS: unprepared SQL ok. |
| 428 | 428 | FrmDb::set_cache( $cache_key, $results, 'frm_entry' ); |
| 429 | 429 | |
| 430 | - return $results; |
|
| 431 | - } |
|
| 430 | + return $results; |
|
| 431 | + } |
|
| 432 | 432 | } |
@@ -31,6 +31,10 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | protected $option_label = ''; |
| 33 | 33 | |
| 34 | + /** |
|
| 35 | + * @param string $option_key |
|
| 36 | + * @param string $option |
|
| 37 | + */ |
|
| 34 | 38 | public function __construct( $option_key, $option, $args = array() ) { |
| 35 | 39 | $this->option_key = $option_key; |
| 36 | 40 | $this->option = $option; |
@@ -75,7 +75,7 @@ |
||
| 75 | 75 | /** |
| 76 | 76 | * FrmFieldValueSelector constructor |
| 77 | 77 | * |
| 78 | - * @param int|string $field_id |
|
| 78 | + * @param integer $field_id |
|
| 79 | 79 | */ |
| 80 | 80 | public function __construct( $field_id, $args ) { |
| 81 | 81 | $this->set_html_name( $args ); |
@@ -180,6 +180,7 @@ discard block |
||
| 180 | 180 | * |
| 181 | 181 | * @param int $id |
| 182 | 182 | * @param array $values |
| 183 | + * @param string $update_type |
|
| 183 | 184 | * @return boolean|int $query_results |
| 184 | 185 | */ |
| 185 | 186 | private static function update_entry( $id, $values, $update_type ) { |
@@ -563,6 +564,9 @@ discard block |
||
| 563 | 564 | return $new_values; |
| 564 | 565 | } |
| 565 | 566 | |
| 567 | + /** |
|
| 568 | + * @param string $name |
|
| 569 | + */ |
|
| 566 | 570 | private static function get_entry_value( $values, $name, $default ) { |
| 567 | 571 | return isset( $values[ $name ] ) ? $values[ $name ] : $default; |
| 568 | 572 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist ); |
| 74 | 74 | $field_metas = array(); |
| 75 | 75 | foreach ( $metas as $meta ) { |
| 76 | - $field_metas[ $meta->field_id ] = $meta->meta_value; |
|
| 76 | + $field_metas[$meta->field_id] = $meta->meta_value; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | // If prev entry is empty and current entry is not, they are not duplicates |
@@ -310,19 +310,19 @@ discard block |
||
| 310 | 310 | $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) ); |
| 311 | 311 | foreach ( $metas as $meta_val ) { |
| 312 | 312 | if ( $meta_val->item_id == $entry->id ) { |
| 313 | - $entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
|
| 313 | + $entry->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value ); |
|
| 314 | 314 | if ( $include_key ) { |
| 315 | - $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ]; |
|
| 315 | + $entry->metas[$meta_val->field_key] = $entry->metas[$meta_val->field_id]; |
|
| 316 | 316 | } |
| 317 | 317 | continue; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | // include sub entries in an array |
| 321 | - if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) { |
|
| 322 | - $entry->metas[ $meta_val->field_id ] = array(); |
|
| 321 | + if ( ! isset( $entry_metas[$meta_val->field_id] ) ) { |
|
| 322 | + $entry->metas[$meta_val->field_id] = array(); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - $entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value ); |
|
| 325 | + $entry->metas[$meta_val->field_id][] = maybe_unserialize( $meta_val->meta_value ); |
|
| 326 | 326 | |
| 327 | 327 | unset( $meta_val ); |
| 328 | 328 | } |
@@ -412,15 +412,15 @@ discard block |
||
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | foreach ( $metas as $m_key => $meta_val ) { |
| 415 | - if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
| 415 | + if ( ! isset( $entries[$meta_val->item_id] ) ) { |
|
| 416 | 416 | continue; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
| 420 | - $entries[ $meta_val->item_id ]->metas = array(); |
|
| 419 | + if ( ! isset( $entries[$meta_val->item_id]->metas ) ) { |
|
| 420 | + $entries[$meta_val->item_id]->metas = array(); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
|
| 423 | + $entries[$meta_val->item_id]->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value ); |
|
| 424 | 424 | |
| 425 | 425 | unset( $m_key, $meta_val ); |
| 426 | 426 | } |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | private static function get_entry_value( $values, $name, $default ) { |
| 571 | - return isset( $values[ $name ] ) ? $values[ $name ] : $default; |
|
| 571 | + return isset( $values[$name] ) ? $values[$name] : $default; |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
@@ -6,11 +6,11 @@ discard block |
||
| 6 | 6 | class FrmEntry { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * Create a new entry |
|
| 10 | - * |
|
| 11 | - * @param array $values |
|
| 12 | - * @return int | boolean $entry_id |
|
| 13 | - */ |
|
| 9 | + * Create a new entry |
|
| 10 | + * |
|
| 11 | + * @param array $values |
|
| 12 | + * @return int | boolean $entry_id |
|
| 13 | + */ |
|
| 14 | 14 | public static function create( $values ) { |
| 15 | 15 | $entry_id = self::create_entry( $values, 'standard' ); |
| 16 | 16 | |
@@ -18,12 +18,12 @@ discard block |
||
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | - * Create a new entry with some differences depending on type |
|
| 22 | - * |
|
| 23 | - * @param array $values |
|
| 24 | - * @param string $type |
|
| 25 | - * @return int | boolean $entry_id |
|
| 26 | - */ |
|
| 21 | + * Create a new entry with some differences depending on type |
|
| 22 | + * |
|
| 23 | + * @param array $values |
|
| 24 | + * @param string $type |
|
| 25 | + * @return int | boolean $entry_id |
|
| 26 | + */ |
|
| 27 | 27 | private static function create_entry( $values, $type ) { |
| 28 | 28 | $new_values = self::before_insert_entry_in_database( $values, $type ); |
| 29 | 29 | |
@@ -37,10 +37,10 @@ discard block |
||
| 37 | 37 | return $entry_id; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * check for duplicate entries created in the last minute |
|
| 42 | - * @return boolean |
|
| 43 | - */ |
|
| 40 | + /** |
|
| 41 | + * check for duplicate entries created in the last minute |
|
| 42 | + * @return boolean |
|
| 43 | + */ |
|
| 44 | 44 | public static function is_duplicate( $new_values, $values ) { |
| 45 | 45 | $duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values ); |
| 46 | 46 | |
@@ -48,55 +48,55 @@ discard block |
||
| 48 | 48 | return false; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - $check_val = $new_values; |
|
| 51 | + $check_val = $new_values; |
|
| 52 | 52 | $check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) ); |
| 53 | 53 | |
| 54 | 54 | unset( $check_val['created_at'], $check_val['updated_at'] ); |
| 55 | 55 | unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] ); |
| 56 | 56 | |
| 57 | - if ( $new_values['item_key'] == $new_values['name'] ) { |
|
| 57 | + if ( $new_values['item_key'] == $new_values['name'] ) { |
|
| 58 | 58 | unset( $check_val['name'] ); |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - global $wpdb; |
|
| 61 | + global $wpdb; |
|
| 62 | 62 | $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) ); |
| 63 | 63 | |
| 64 | 64 | if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) { |
| 65 | - return false; |
|
| 66 | - } |
|
| 65 | + return false; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $is_duplicate = false; |
|
| 69 | - foreach ( $entry_exists as $entry_exist ) { |
|
| 70 | - $is_duplicate = true; |
|
| 68 | + $is_duplicate = false; |
|
| 69 | + foreach ( $entry_exists as $entry_exist ) { |
|
| 70 | + $is_duplicate = true; |
|
| 71 | 71 | |
| 72 | - //add more checks here to make sure it's a duplicate |
|
| 72 | + //add more checks here to make sure it's a duplicate |
|
| 73 | 73 | $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist ); |
| 74 | - $field_metas = array(); |
|
| 75 | - foreach ( $metas as $meta ) { |
|
| 74 | + $field_metas = array(); |
|
| 75 | + foreach ( $metas as $meta ) { |
|
| 76 | 76 | $field_metas[ $meta->field_id ] = $meta->meta_value; |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - // If prev entry is empty and current entry is not, they are not duplicates |
|
| 80 | - $filtered_vals = array_filter( $values['item_meta'] ); |
|
| 81 | - if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) { |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 79 | + // If prev entry is empty and current entry is not, they are not duplicates |
|
| 80 | + $filtered_vals = array_filter( $values['item_meta'] ); |
|
| 81 | + if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) { |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | $diff = array_diff_assoc( $field_metas, array_map( 'maybe_serialize', $values['item_meta'] ) ); |
| 86 | - foreach ( $diff as $field_id => $meta_value ) { |
|
| 86 | + foreach ( $diff as $field_id => $meta_value ) { |
|
| 87 | 87 | if ( ! empty( $meta_value ) ) { |
| 88 | - $is_duplicate = false; |
|
| 89 | - continue; |
|
| 90 | - } |
|
| 91 | - } |
|
| 88 | + $is_duplicate = false; |
|
| 89 | + continue; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - if ( $is_duplicate ) { |
|
| 93 | + if ( $is_duplicate ) { |
|
| 94 | 94 | break; |
| 95 | - } |
|
| 96 | - } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - return $is_duplicate; |
|
| 99 | - } |
|
| 98 | + return $is_duplicate; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * Determine if an entry needs to be checked as a possible duplicate |
@@ -141,32 +141,32 @@ discard block |
||
| 141 | 141 | $new_values['updated_at'] = $new_values['created_at']; |
| 142 | 142 | |
| 143 | 143 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values ); |
| 144 | - if ( ! $query_results ) { |
|
| 145 | - return false; |
|
| 146 | - } |
|
| 144 | + if ( ! $query_results ) { |
|
| 145 | + return false; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - $entry_id = $wpdb->insert_id; |
|
| 148 | + $entry_id = $wpdb->insert_id; |
|
| 149 | 149 | |
| 150 | - global $frm_vars; |
|
| 150 | + global $frm_vars; |
|
| 151 | 151 | if ( ! isset( $frm_vars['saved_entries'] ) ) { |
| 152 | - $frm_vars['saved_entries'] = array(); |
|
| 153 | - } |
|
| 154 | - $frm_vars['saved_entries'][] = (int) $entry_id; |
|
| 152 | + $frm_vars['saved_entries'] = array(); |
|
| 153 | + } |
|
| 154 | + $frm_vars['saved_entries'][] = (int) $entry_id; |
|
| 155 | 155 | |
| 156 | 156 | FrmEntryMeta::duplicate_entry_metas( $id, $entry_id ); |
| 157 | 157 | self::clear_cache(); |
| 158 | 158 | |
| 159 | 159 | do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) ); |
| 160 | - return $entry_id; |
|
| 161 | - } |
|
| 160 | + return $entry_id; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | /** |
| 164 | - * Update an entry (not via XML) |
|
| 165 | - * |
|
| 166 | - * @param int $id |
|
| 167 | - * @param array $values |
|
| 168 | - * @return boolean|int $update_results |
|
| 169 | - */ |
|
| 164 | + * Update an entry (not via XML) |
|
| 165 | + * |
|
| 166 | + * @param int $id |
|
| 167 | + * @param array $values |
|
| 168 | + * @return boolean|int $update_results |
|
| 169 | + */ |
|
| 170 | 170 | public static function update( $id, $values ) { |
| 171 | 171 | $update_results = self::update_entry( $id, $values, 'standard' ); |
| 172 | 172 | |
@@ -174,14 +174,14 @@ discard block |
||
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
| 177 | - * Update an entry with some differences depending on the update type |
|
| 178 | - * |
|
| 179 | - * @since 2.0.16 |
|
| 180 | - * |
|
| 181 | - * @param int $id |
|
| 182 | - * @param array $values |
|
| 183 | - * @return boolean|int $query_results |
|
| 184 | - */ |
|
| 177 | + * Update an entry with some differences depending on the update type |
|
| 178 | + * |
|
| 179 | + * @since 2.0.16 |
|
| 180 | + * |
|
| 181 | + * @param int $id |
|
| 182 | + * @param array $values |
|
| 183 | + * @return boolean|int $query_results |
|
| 184 | + */ |
|
| 185 | 185 | private static function update_entry( $id, $values, $update_type ) { |
| 186 | 186 | global $wpdb; |
| 187 | 187 | |
@@ -200,14 +200,14 @@ discard block |
||
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | public static function destroy( $id ) { |
| 203 | - global $wpdb; |
|
| 204 | - $id = (int) $id; |
|
| 203 | + global $wpdb; |
|
| 204 | + $id = (int) $id; |
|
| 205 | 205 | |
| 206 | 206 | $entry = self::getOne( $id ); |
| 207 | - if ( ! $entry ) { |
|
| 208 | - $result = false; |
|
| 209 | - return $result; |
|
| 210 | - } |
|
| 207 | + if ( ! $entry ) { |
|
| 208 | + $result = false; |
|
| 209 | + return $result; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | 212 | do_action( 'frm_before_destroy_entry', $id, $entry ); |
| 213 | 213 | |
@@ -216,18 +216,18 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | self::clear_cache(); |
| 218 | 218 | |
| 219 | - return $result; |
|
| 220 | - } |
|
| 219 | + return $result; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | 222 | public static function update_form( $id, $value, $form_id ) { |
| 223 | - global $wpdb; |
|
| 223 | + global $wpdb; |
|
| 224 | 224 | $form_id = isset( $value ) ? $form_id : null; |
| 225 | 225 | $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) ); |
| 226 | 226 | if ( $result ) { |
| 227 | 227 | self::clear_cache(); |
| 228 | 228 | } |
| 229 | - return $result; |
|
| 230 | - } |
|
| 229 | + return $result; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | 232 | /** |
| 233 | 233 | * Clear entry caching |
@@ -269,19 +269,19 @@ discard block |
||
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | public static function getOne( $id, $meta = false ) { |
| 272 | - global $wpdb; |
|
| 272 | + global $wpdb; |
|
| 273 | 273 | |
| 274 | - $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
|
| 274 | + $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
|
| 275 | 275 | LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE "; |
| 276 | 276 | |
| 277 | 277 | $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s'; |
| 278 | - $query_args = array( $id ); |
|
| 279 | - $query = $wpdb->prepare( $query, $query_args ); // WPCS: unprepared SQL ok. |
|
| 278 | + $query_args = array( $id ); |
|
| 279 | + $query = $wpdb->prepare( $query, $query_args ); // WPCS: unprepared SQL ok. |
|
| 280 | 280 | |
| 281 | - if ( ! $meta ) { |
|
| 281 | + if ( ! $meta ) { |
|
| 282 | 282 | $entry = FrmDb::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' ); |
| 283 | 283 | return stripslashes_deep( $entry ); |
| 284 | - } |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | 286 | $entry = FrmDb::check_cache( $id, 'frm_entry' ); |
| 287 | 287 | if ( $entry !== false ) { |
@@ -292,69 +292,69 @@ discard block |
||
| 292 | 292 | $entry = self::get_meta( $entry ); |
| 293 | 293 | |
| 294 | 294 | return stripslashes_deep( $entry ); |
| 295 | - } |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | 297 | public static function get_meta( $entry ) { |
| 298 | - if ( ! $entry ) { |
|
| 299 | - return $entry; |
|
| 300 | - } |
|
| 298 | + if ( ! $entry ) { |
|
| 299 | + return $entry; |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - global $wpdb; |
|
| 302 | + global $wpdb; |
|
| 303 | 303 | $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id', array( |
| 304 | 304 | 'item_id' => $entry->id, |
| 305 | 305 | 'field_id !' => 0, |
| 306 | 306 | ), 'field_id, meta_value, field_key, item_id' ); |
| 307 | 307 | |
| 308 | - $entry->metas = array(); |
|
| 308 | + $entry->metas = array(); |
|
| 309 | 309 | |
| 310 | 310 | $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) ); |
| 311 | - foreach ( $metas as $meta_val ) { |
|
| 312 | - if ( $meta_val->item_id == $entry->id ) { |
|
| 311 | + foreach ( $metas as $meta_val ) { |
|
| 312 | + if ( $meta_val->item_id == $entry->id ) { |
|
| 313 | 313 | $entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
| 314 | 314 | if ( $include_key ) { |
| 315 | 315 | $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ]; |
| 316 | 316 | } |
| 317 | - continue; |
|
| 318 | - } |
|
| 317 | + continue; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - // include sub entries in an array |
|
| 320 | + // include sub entries in an array |
|
| 321 | 321 | if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) { |
| 322 | 322 | $entry->metas[ $meta_val->field_id ] = array(); |
| 323 | - } |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | 325 | $entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value ); |
| 326 | 326 | |
| 327 | 327 | unset( $meta_val ); |
| 328 | - } |
|
| 328 | + } |
|
| 329 | 329 | unset( $metas ); |
| 330 | 330 | |
| 331 | 331 | FrmDb::set_cache( $entry->id, $entry, 'frm_entry' ); |
| 332 | 332 | |
| 333 | - return $entry; |
|
| 334 | - } |
|
| 333 | + return $entry; |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - /** |
|
| 337 | - * @param string $id |
|
| 338 | - */ |
|
| 336 | + /** |
|
| 337 | + * @param string $id |
|
| 338 | + */ |
|
| 339 | 339 | public static function exists( $id ) { |
| 340 | - global $wpdb; |
|
| 340 | + global $wpdb; |
|
| 341 | 341 | |
| 342 | - if ( FrmDb::check_cache( $id, 'frm_entry' ) ) { |
|
| 343 | - $exists = true; |
|
| 344 | - return $exists; |
|
| 345 | - } |
|
| 342 | + if ( FrmDb::check_cache( $id, 'frm_entry' ) ) { |
|
| 343 | + $exists = true; |
|
| 344 | + return $exists; |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | 347 | if ( is_numeric( $id ) ) { |
| 348 | - $where = array( 'id' => $id ); |
|
| 349 | - } else { |
|
| 350 | - $where = array( 'item_key' => $id ); |
|
| 351 | - } |
|
| 348 | + $where = array( 'id' => $id ); |
|
| 349 | + } else { |
|
| 350 | + $where = array( 'item_key' => $id ); |
|
| 351 | + } |
|
| 352 | 352 | $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where ); |
| 353 | 353 | |
| 354 | 354 | return ( $id && $id > 0 ); |
| 355 | - } |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
|
| 357 | + public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
|
| 358 | 358 | global $wpdb; |
| 359 | 359 | |
| 360 | 360 | $limit = FrmDb::esc_limit( $limit ); |
@@ -362,21 +362,21 @@ discard block |
||
| 362 | 362 | $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form; |
| 363 | 363 | $entries = wp_cache_get( $cache_key, 'frm_entry' ); |
| 364 | 364 | |
| 365 | - if ( false === $entries ) { |
|
| 366 | - $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
|
| 365 | + if ( false === $entries ) { |
|
| 366 | + $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
|
| 367 | 367 | $table = $wpdb->prefix . 'frm_items it '; |
| 368 | 368 | |
| 369 | - if ( $inc_form ) { |
|
| 370 | - $fields = 'it.*, fr.name as form_name,fr.form_key as form_key'; |
|
| 371 | - $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id '; |
|
| 372 | - } |
|
| 369 | + if ( $inc_form ) { |
|
| 370 | + $fields = 'it.*, fr.name as form_name,fr.form_key as form_key'; |
|
| 371 | + $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id '; |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) { |
|
| 375 | - // sort by a requested field |
|
| 376 | - $field_id = (int) $order_matches[1]; |
|
| 374 | + if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) { |
|
| 375 | + // sort by a requested field |
|
| 376 | + $field_id = (int) $order_matches[1]; |
|
| 377 | 377 | $fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id; |
| 378 | 378 | unset( $order_matches, $field_id ); |
| 379 | - } |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | 381 | // prepare the query |
| 382 | 382 | $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
@@ -385,45 +385,45 @@ discard block |
||
| 385 | 385 | unset( $query ); |
| 386 | 386 | |
| 387 | 387 | FrmDb::set_cache( $cache_key, $entries, 'frm_entry' ); |
| 388 | - } |
|
| 388 | + } |
|
| 389 | 389 | |
| 390 | - if ( ! $meta || ! $entries ) { |
|
| 390 | + if ( ! $meta || ! $entries ) { |
|
| 391 | 391 | return stripslashes_deep( $entries ); |
| 392 | - } |
|
| 392 | + } |
|
| 393 | 393 | unset( $meta ); |
| 394 | 394 | |
| 395 | 395 | if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) { |
| 396 | 396 | $where = array( 'it.form_id' => substr( $where, 11 ) ); |
| 397 | - } |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | - $meta_where = array( 'field_id !' => 0 ); |
|
| 399 | + $meta_where = array( 'field_id !' => 0 ); |
|
| 400 | 400 | if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) { |
| 401 | - $meta_where['fi.form_id'] = $where['it.form_id']; |
|
| 402 | - } else { |
|
| 403 | - $meta_where['item_id'] = array_keys( $entries ); |
|
| 404 | - } |
|
| 401 | + $meta_where['fi.form_id'] = $where['it.form_id']; |
|
| 402 | + } else { |
|
| 403 | + $meta_where['item_id'] = array_keys( $entries ); |
|
| 404 | + } |
|
| 405 | 405 | |
| 406 | - $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' ); |
|
| 406 | + $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' ); |
|
| 407 | 407 | |
| 408 | - unset( $meta_where ); |
|
| 408 | + unset( $meta_where ); |
|
| 409 | 409 | |
| 410 | - if ( ! $metas ) { |
|
| 410 | + if ( ! $metas ) { |
|
| 411 | 411 | return stripslashes_deep( $entries ); |
| 412 | - } |
|
| 412 | + } |
|
| 413 | 413 | |
| 414 | - foreach ( $metas as $m_key => $meta_val ) { |
|
| 415 | - if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
| 416 | - continue; |
|
| 417 | - } |
|
| 414 | + foreach ( $metas as $m_key => $meta_val ) { |
|
| 415 | + if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
| 416 | + continue; |
|
| 417 | + } |
|
| 418 | 418 | |
| 419 | - if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
| 419 | + if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
| 420 | 420 | $entries[ $meta_val->item_id ]->metas = array(); |
| 421 | - } |
|
| 421 | + } |
|
| 422 | 422 | |
| 423 | 423 | $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
| 424 | 424 | |
| 425 | 425 | unset( $m_key, $meta_val ); |
| 426 | - } |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | 428 | if ( ! FrmAppHelper::prevent_caching() ) { |
| 429 | 429 | foreach ( $entries as $entry ) { |
@@ -433,30 +433,30 @@ discard block |
||
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | return stripslashes_deep( $entries ); |
| 436 | - } |
|
| 436 | + } |
|
| 437 | 437 | |
| 438 | - // Pagination Methods |
|
| 439 | - public static function getRecordCount( $where = '' ) { |
|
| 440 | - global $wpdb; |
|
| 438 | + // Pagination Methods |
|
| 439 | + public static function getRecordCount( $where = '' ) { |
|
| 440 | + global $wpdb; |
|
| 441 | 441 | $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; |
| 442 | 442 | |
| 443 | 443 | if ( is_numeric( $where ) ) { |
| 444 | - $table_join = 'frm_items'; |
|
| 445 | - $where = array( 'form_id' => $where ); |
|
| 446 | - } |
|
| 444 | + $table_join = 'frm_items'; |
|
| 445 | + $where = array( 'form_id' => $where ); |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | - if ( is_array( $where ) ) { |
|
| 449 | - $count = FrmDb::get_count( $table_join, $where ); |
|
| 450 | - } else { |
|
| 448 | + if ( is_array( $where ) ) { |
|
| 449 | + $count = FrmDb::get_count( $table_join, $where ); |
|
| 450 | + } else { |
|
| 451 | 451 | $cache_key = 'count_' . maybe_serialize( $where ); |
| 452 | 452 | $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmDb::prepend_and_or_where( ' WHERE ', $where ); |
| 453 | 453 | $count = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_var' ); |
| 454 | - } |
|
| 454 | + } |
|
| 455 | 455 | |
| 456 | - return $count; |
|
| 457 | - } |
|
| 456 | + return $count; |
|
| 457 | + } |
|
| 458 | 458 | |
| 459 | - public static function getPageCount( $p_size, $where = '' ) { |
|
| 459 | + public static function getPageCount( $p_size, $where = '' ) { |
|
| 460 | 460 | $p_size = (int) $p_size; |
| 461 | 461 | $count = 1; |
| 462 | 462 | if ( $p_size ) { |
@@ -467,16 +467,16 @@ discard block |
||
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | return $count; |
| 470 | - } |
|
| 470 | + } |
|
| 471 | 471 | |
| 472 | 472 | /** |
| 473 | - * Prepare the data before inserting it into the database |
|
| 474 | - * |
|
| 475 | - * @since 2.0.16 |
|
| 476 | - * @param array $values |
|
| 477 | - * @param string $type |
|
| 478 | - * @return array $new_values |
|
| 479 | - */ |
|
| 473 | + * Prepare the data before inserting it into the database |
|
| 474 | + * |
|
| 475 | + * @since 2.0.16 |
|
| 476 | + * @param array $values |
|
| 477 | + * @param string $type |
|
| 478 | + * @return array $new_values |
|
| 479 | + */ |
|
| 480 | 480 | private static function before_insert_entry_in_database( &$values, $type ) { |
| 481 | 481 | |
| 482 | 482 | self::sanitize_entry_post( $values ); |
@@ -491,13 +491,13 @@ discard block |
||
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | /** |
| 494 | - * Create an entry and perform after create actions |
|
| 495 | - * |
|
| 496 | - * @since 2.0.16 |
|
| 497 | - * @param array $values |
|
| 498 | - * @param array $new_values |
|
| 499 | - * @return boolean|int $entry_id |
|
| 500 | - */ |
|
| 494 | + * Create an entry and perform after create actions |
|
| 495 | + * |
|
| 496 | + * @since 2.0.16 |
|
| 497 | + * @param array $values |
|
| 498 | + * @param array $new_values |
|
| 499 | + * @return boolean|int $entry_id |
|
| 500 | + */ |
|
| 501 | 501 | private static function continue_to_create_entry( $values, $new_values ) { |
| 502 | 502 | $entry_id = self::insert_entry_into_database( $new_values ); |
| 503 | 503 | if ( ! $entry_id ) { |
@@ -509,37 +509,37 @@ discard block |
||
| 509 | 509 | return $entry_id; |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | - /** |
|
| 513 | - * Sanitize the POST values before we use them |
|
| 514 | - * |
|
| 515 | - * @since 2.0 |
|
| 516 | - * @param array $values The POST values by reference |
|
| 517 | - */ |
|
| 518 | - public static function sanitize_entry_post( &$values ) { |
|
| 519 | - $sanitize_method = array( |
|
| 520 | - 'form_id' => 'absint', |
|
| 521 | - 'frm_action' => 'sanitize_title', |
|
| 522 | - 'form_key' => 'sanitize_title', |
|
| 523 | - 'item_key' => 'sanitize_title', |
|
| 524 | - 'item_name' => 'sanitize_text_field', |
|
| 525 | - 'frm_saving_draft' => 'absint', |
|
| 526 | - 'is_draft' => 'absint', |
|
| 527 | - 'post_id' => 'absint', |
|
| 528 | - 'parent_item_id' => 'absint', |
|
| 529 | - 'created_at' => 'sanitize_text_field', |
|
| 530 | - 'updated_at' => 'sanitize_text_field', |
|
| 531 | - ); |
|
| 532 | - |
|
| 533 | - FrmAppHelper::sanitize_request( $sanitize_method, $values ); |
|
| 534 | - } |
|
| 512 | + /** |
|
| 513 | + * Sanitize the POST values before we use them |
|
| 514 | + * |
|
| 515 | + * @since 2.0 |
|
| 516 | + * @param array $values The POST values by reference |
|
| 517 | + */ |
|
| 518 | + public static function sanitize_entry_post( &$values ) { |
|
| 519 | + $sanitize_method = array( |
|
| 520 | + 'form_id' => 'absint', |
|
| 521 | + 'frm_action' => 'sanitize_title', |
|
| 522 | + 'form_key' => 'sanitize_title', |
|
| 523 | + 'item_key' => 'sanitize_title', |
|
| 524 | + 'item_name' => 'sanitize_text_field', |
|
| 525 | + 'frm_saving_draft' => 'absint', |
|
| 526 | + 'is_draft' => 'absint', |
|
| 527 | + 'post_id' => 'absint', |
|
| 528 | + 'parent_item_id' => 'absint', |
|
| 529 | + 'created_at' => 'sanitize_text_field', |
|
| 530 | + 'updated_at' => 'sanitize_text_field', |
|
| 531 | + ); |
|
| 532 | + |
|
| 533 | + FrmAppHelper::sanitize_request( $sanitize_method, $values ); |
|
| 534 | + } |
|
| 535 | 535 | |
| 536 | 536 | /** |
| 537 | - * Prepare the new values for inserting into the database |
|
| 538 | - * |
|
| 539 | - * @since 2.0.16 |
|
| 540 | - * @param array $values |
|
| 541 | - * @return array $new_values |
|
| 542 | - */ |
|
| 537 | + * Prepare the new values for inserting into the database |
|
| 538 | + * |
|
| 539 | + * @since 2.0.16 |
|
| 540 | + * @param array $values |
|
| 541 | + * @return array $new_values |
|
| 542 | + */ |
|
| 543 | 543 | private static function package_entry_data( &$values ) { |
| 544 | 544 | global $wpdb; |
| 545 | 545 | |
@@ -592,34 +592,34 @@ discard block |
||
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | /** |
| 595 | - * Get the is_draft value for a new entry |
|
| 596 | - * |
|
| 597 | - * @since 2.0.16 |
|
| 598 | - * @param array $values |
|
| 599 | - * @return int |
|
| 600 | - */ |
|
| 595 | + * Get the is_draft value for a new entry |
|
| 596 | + * |
|
| 597 | + * @since 2.0.16 |
|
| 598 | + * @param array $values |
|
| 599 | + * @return int |
|
| 600 | + */ |
|
| 601 | 601 | private static function get_is_draft_value( $values ) { |
| 602 | 602 | return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0; |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
| 606 | - * Get the created_at value for a new entry |
|
| 607 | - * |
|
| 608 | - * @since 2.0.16 |
|
| 609 | - * @param array $values |
|
| 610 | - * @return string |
|
| 611 | - */ |
|
| 606 | + * Get the created_at value for a new entry |
|
| 607 | + * |
|
| 608 | + * @since 2.0.16 |
|
| 609 | + * @param array $values |
|
| 610 | + * @return string |
|
| 611 | + */ |
|
| 612 | 612 | private static function get_created_at( $values ) { |
| 613 | 613 | return self::get_entry_value( $values, 'created_at', current_time( 'mysql', 1 ) ); |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
| 617 | - * Get the updated_at value for a new entry |
|
| 618 | - * |
|
| 619 | - * @since 2.0.16 |
|
| 620 | - * @param array $values |
|
| 621 | - * @return string |
|
| 622 | - */ |
|
| 617 | + * Get the updated_at value for a new entry |
|
| 618 | + * |
|
| 619 | + * @since 2.0.16 |
|
| 620 | + * @param array $values |
|
| 621 | + * @return string |
|
| 622 | + */ |
|
| 623 | 623 | private static function get_updated_at( $values ) { |
| 624 | 624 | if ( isset( $values['updated_at'] ) ) { |
| 625 | 625 | $updated_at = $values['updated_at']; |
@@ -631,12 +631,12 @@ discard block |
||
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | /** |
| 634 | - * Get the description value for a new entry |
|
| 635 | - * |
|
| 636 | - * @since 2.0.16 |
|
| 637 | - * @param array $values |
|
| 638 | - * @return string |
|
| 639 | - */ |
|
| 634 | + * Get the description value for a new entry |
|
| 635 | + * |
|
| 636 | + * @since 2.0.16 |
|
| 637 | + * @param array $values |
|
| 638 | + * @return string |
|
| 639 | + */ |
|
| 640 | 640 | private static function get_entry_description( $values ) { |
| 641 | 641 | if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) { |
| 642 | 642 | $description = maybe_serialize( $values['description'] ); |
@@ -651,12 +651,12 @@ discard block |
||
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | /** |
| 654 | - * Get the user_id value for a new entry |
|
| 655 | - * |
|
| 656 | - * @since 2.0.16 |
|
| 657 | - * @param array $values |
|
| 658 | - * @return int |
|
| 659 | - */ |
|
| 654 | + * Get the user_id value for a new entry |
|
| 655 | + * |
|
| 656 | + * @since 2.0.16 |
|
| 657 | + * @param array $values |
|
| 658 | + * @return int |
|
| 659 | + */ |
|
| 660 | 660 | private static function get_entry_user_id( $values ) { |
| 661 | 661 | if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) { |
| 662 | 662 | $user_id = $values['frm_user_id']; |
@@ -669,12 +669,12 @@ discard block |
||
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
| 672 | - * Insert new entry into the database |
|
| 673 | - * |
|
| 674 | - * @since 2.0.16 |
|
| 675 | - * @param array $new_values |
|
| 676 | - * @return int | boolean $entry_id |
|
| 677 | - */ |
|
| 672 | + * Insert new entry into the database |
|
| 673 | + * |
|
| 674 | + * @since 2.0.16 |
|
| 675 | + * @param array $new_values |
|
| 676 | + * @return int | boolean $entry_id |
|
| 677 | + */ |
|
| 678 | 678 | private static function insert_entry_into_database( $new_values ) { |
| 679 | 679 | global $wpdb; |
| 680 | 680 | |
@@ -690,11 +690,11 @@ discard block |
||
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | /** |
| 693 | - * Add the new entry to global $frm_vars |
|
| 694 | - * |
|
| 695 | - * @since 2.0.16 |
|
| 696 | - * @param int $entry_id |
|
| 697 | - */ |
|
| 693 | + * Add the new entry to global $frm_vars |
|
| 694 | + * |
|
| 695 | + * @since 2.0.16 |
|
| 696 | + * @param int $entry_id |
|
| 697 | + */ |
|
| 698 | 698 | private static function add_new_entry_to_frm_vars( $entry_id ) { |
| 699 | 699 | global $frm_vars; |
| 700 | 700 | |
@@ -706,12 +706,12 @@ discard block |
||
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | /** |
| 709 | - * Add entry metas, if there are any |
|
| 710 | - * |
|
| 711 | - * @since 2.0.16 |
|
| 712 | - * @param array $values |
|
| 713 | - * @param int $entry_id |
|
| 714 | - */ |
|
| 709 | + * Add entry metas, if there are any |
|
| 710 | + * |
|
| 711 | + * @since 2.0.16 |
|
| 712 | + * @param array $values |
|
| 713 | + * @param int $entry_id |
|
| 714 | + */ |
|
| 715 | 715 | private static function maybe_add_entry_metas( $values, $entry_id ) { |
| 716 | 716 | if ( isset( $values['item_meta'] ) ) { |
| 717 | 717 | FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] ); |
@@ -719,12 +719,12 @@ discard block |
||
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | /** |
| 722 | - * Trigger frm_after_create_entry hooks |
|
| 723 | - * |
|
| 724 | - * @since 2.0.16 |
|
| 725 | - * @param int $entry_id |
|
| 726 | - * @param array $new_values |
|
| 727 | - */ |
|
| 722 | + * Trigger frm_after_create_entry hooks |
|
| 723 | + * |
|
| 724 | + * @since 2.0.16 |
|
| 725 | + * @param int $entry_id |
|
| 726 | + * @param array $new_values |
|
| 727 | + */ |
|
| 728 | 728 | private static function after_entry_created_actions( $entry_id, $values, $new_values ) { |
| 729 | 729 | // this is a child entry |
| 730 | 730 | $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' ); |
@@ -734,13 +734,13 @@ discard block |
||
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | /** |
| 737 | - * Actions to perform immediately after an entry is inserted in the frm_items database |
|
| 738 | - * |
|
| 739 | - * @since 2.0.16 |
|
| 740 | - * @param array $values |
|
| 741 | - * @param array $new_values |
|
| 742 | - * @param int $entry_id |
|
| 743 | - */ |
|
| 737 | + * Actions to perform immediately after an entry is inserted in the frm_items database |
|
| 738 | + * |
|
| 739 | + * @since 2.0.16 |
|
| 740 | + * @param array $values |
|
| 741 | + * @param array $new_values |
|
| 742 | + * @param int $entry_id |
|
| 743 | + */ |
|
| 744 | 744 | private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) { |
| 745 | 745 | |
| 746 | 746 | self::add_new_entry_to_frm_vars( $entry_id ); |
@@ -753,14 +753,14 @@ discard block |
||
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | /** |
| 756 | - * Perform some actions right before updating an entry |
|
| 757 | - * |
|
| 758 | - * @since 2.0.16 |
|
| 759 | - * @param int $id |
|
| 760 | - * @param array $values |
|
| 761 | - * @param string $update_type |
|
| 762 | - * @return boolean $update |
|
| 763 | - */ |
|
| 756 | + * Perform some actions right before updating an entry |
|
| 757 | + * |
|
| 758 | + * @since 2.0.16 |
|
| 759 | + * @param int $id |
|
| 760 | + * @param array $values |
|
| 761 | + * @param string $update_type |
|
| 762 | + * @return boolean $update |
|
| 763 | + */ |
|
| 764 | 764 | private static function before_update_entry( $id, &$values, $update_type ) { |
| 765 | 765 | $update = true; |
| 766 | 766 | |
@@ -778,13 +778,13 @@ discard block |
||
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | /** |
| 781 | - * Package the entry data for updating |
|
| 782 | - * |
|
| 783 | - * @since 2.0.16 |
|
| 784 | - * @param int $id |
|
| 785 | - * @param array $values |
|
| 786 | - * @return array $new_values |
|
| 787 | - */ |
|
| 781 | + * Package the entry data for updating |
|
| 782 | + * |
|
| 783 | + * @since 2.0.16 |
|
| 784 | + * @param int $id |
|
| 785 | + * @param array $values |
|
| 786 | + * @return array $new_values |
|
| 787 | + */ |
|
| 788 | 788 | private static function package_entry_to_update( $id, $values ) { |
| 789 | 789 | global $wpdb; |
| 790 | 790 | |
@@ -818,14 +818,14 @@ discard block |
||
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | /** |
| 821 | - * Perform some actions right after updating an entry |
|
| 822 | - * |
|
| 823 | - * @since 2.0.16 |
|
| 824 | - * @param boolean|int $query_results |
|
| 825 | - * @param int $id |
|
| 826 | - * @param array $values |
|
| 827 | - * @param array $new_values |
|
| 828 | - */ |
|
| 821 | + * Perform some actions right after updating an entry |
|
| 822 | + * |
|
| 823 | + * @since 2.0.16 |
|
| 824 | + * @param boolean|int $query_results |
|
| 825 | + * @param int $id |
|
| 826 | + * @param array $values |
|
| 827 | + * @param array $new_values |
|
| 828 | + */ |
|
| 829 | 829 | private static function after_update_entry( $query_results, $id, $values, $new_values ) { |
| 830 | 830 | if ( $query_results ) { |
| 831 | 831 | self::clear_cache(); |
@@ -847,13 +847,13 @@ discard block |
||
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | /** |
| 850 | - * Create entry from an XML import |
|
| 851 | - * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.) |
|
| 852 | - * |
|
| 853 | - * @since 2.0.16 |
|
| 854 | - * @param array $values |
|
| 855 | - * @return int | boolean $entry_id |
|
| 856 | - */ |
|
| 850 | + * Create entry from an XML import |
|
| 851 | + * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.) |
|
| 852 | + * |
|
| 853 | + * @since 2.0.16 |
|
| 854 | + * @param array $values |
|
| 855 | + * @return int | boolean $entry_id |
|
| 856 | + */ |
|
| 857 | 857 | public static function create_entry_from_xml( $values ) { |
| 858 | 858 | $entry_id = self::create_entry( $values, 'xml' ); |
| 859 | 859 | |
@@ -861,26 +861,26 @@ discard block |
||
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | /** |
| 864 | - * Update entry from an XML import |
|
| 865 | - * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
|
| 866 | - * |
|
| 867 | - * @since 2.0.16 |
|
| 868 | - * @param int $id |
|
| 869 | - * @param array $values |
|
| 870 | - * @return int | boolean $updated |
|
| 871 | - */ |
|
| 864 | + * Update entry from an XML import |
|
| 865 | + * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
|
| 866 | + * |
|
| 867 | + * @since 2.0.16 |
|
| 868 | + * @param int $id |
|
| 869 | + * @param array $values |
|
| 870 | + * @return int | boolean $updated |
|
| 871 | + */ |
|
| 872 | 872 | public static function update_entry_from_xml( $id, $values ) { |
| 873 | 873 | $updated = self::update_entry( $id, $values, 'xml' ); |
| 874 | 874 | |
| 875 | 875 | return $updated; |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | - /** |
|
| 879 | - * @param string $key |
|
| 880 | - * @return int entry_id |
|
| 881 | - */ |
|
| 878 | + /** |
|
| 879 | + * @param string $key |
|
| 880 | + * @return int entry_id |
|
| 881 | + */ |
|
| 882 | 882 | public static function get_id_by_key( $key ) { |
| 883 | - $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) ); |
|
| 884 | - return $entry_id; |
|
| 885 | - } |
|
| 883 | + $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) ); |
|
| 884 | + return $entry_id; |
|
| 885 | + } |
|
| 886 | 886 | } |