@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class FrmStyle { |
| 3 | - public $number = false; // Unique ID number of the current instance. |
|
| 3 | + public $number = false; // Unique ID number of the current instance. |
|
| 4 | 4 | public $id = 0; // the id of the post |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -13,9 +13,9 @@ discard block |
||
| 13 | 13 | public function get_new() { |
| 14 | 14 | $this->id = 0; |
| 15 | 15 | |
| 16 | - $max_slug_value = pow(36, 6); |
|
| 16 | + $max_slug_value = pow( 36, 6 ); |
|
| 17 | 17 | $min_slug_value = 37; // we want to have at least 2 characters in the slug |
| 18 | - $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 ); |
|
| 18 | + $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 ); |
|
| 19 | 19 | |
| 20 | 20 | $style = array( |
| 21 | 21 | 'post_type' => FrmStylesController::$post_type, |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | public function update( $id = 'default' ) { |
| 42 | 42 | $all_instances = $this->get_all(); |
| 43 | 43 | |
| 44 | - if ( empty($id) ) { |
|
| 44 | + if ( empty( $id ) ) { |
|
| 45 | 45 | $new_style = (array) $this->get_new(); |
| 46 | 46 | $all_instances[] = $new_style; |
| 47 | 47 | } |
@@ -49,15 +49,15 @@ discard block |
||
| 49 | 49 | $action_ids = array(); |
| 50 | 50 | |
| 51 | 51 | foreach ( $all_instances as $number => $new_instance ) { |
| 52 | - $new_instance = stripslashes_deep( (array) $new_instance); |
|
| 52 | + $new_instance = stripslashes_deep( (array) $new_instance ); |
|
| 53 | 53 | $this->id = $new_instance['ID']; |
| 54 | - if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) { |
|
| 55 | - $all_instances[ $number ] = $new_instance; |
|
| 54 | + if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { |
|
| 55 | + $all_instances[$number] = $new_instance; |
|
| 56 | 56 | |
| 57 | - if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) { |
|
| 57 | + if ( $new_instance['menu_order'] && $_POST && empty( $_POST['prev_menu_order'] ) && isset( $_POST['frm_style_setting']['menu_order'] ) ) { |
|
| 58 | 58 | // this style was set to default, so remove default setting on previous default style |
| 59 | 59 | $new_instance['menu_order'] = 0; |
| 60 | - $action_ids[] = $this->save($new_instance); |
|
| 60 | + $action_ids[] = $this->save( $new_instance ); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // don't continue if not saving this style |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | $new_instance['post_title'] = sanitize_text_field( $_POST['frm_style_setting']['post_title'] ); |
| 68 | 68 | $new_instance['post_content'] = $_POST['frm_style_setting']['post_content']; |
| 69 | 69 | $new_instance['post_type'] = FrmStylesController::$post_type; |
| 70 | - $new_instance['post_status'] = 'publish'; |
|
| 70 | + $new_instance['post_status'] = 'publish'; |
|
| 71 | 71 | $new_instance['menu_order'] = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0; |
| 72 | 72 | |
| 73 | - if ( empty($id) ) { |
|
| 73 | + if ( empty( $id ) ) { |
|
| 74 | 74 | $new_instance['post_name'] = $new_instance['post_title']; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -79,19 +79,19 @@ discard block |
||
| 79 | 79 | foreach ( $default_settings as $setting => $default ) { |
| 80 | 80 | if ( strpos( $setting, 'color' ) !== false || in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ) ) ) { |
| 81 | 81 | //if is a color |
| 82 | - $new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] ); |
|
| 83 | - } else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][ $setting ] ) ) { |
|
| 84 | - $new_instance['post_content'][ $setting ] = 0; |
|
| 82 | + $new_instance['post_content'][$setting] = str_replace( '#', '', $new_instance['post_content'][$setting] ); |
|
| 83 | + } else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][$setting] ) ) { |
|
| 84 | + $new_instance['post_content'][$setting] = 0; |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - $all_instances[ $number ] = $new_instance; |
|
| 88 | + $all_instances[$number] = $new_instance; |
|
| 89 | 89 | |
| 90 | - $action_ids[] = $this->save($new_instance); |
|
| 90 | + $action_ids[] = $this->save( $new_instance ); |
|
| 91 | 91 | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - $this->save_settings($all_instances); |
|
| 94 | + $this->save_settings( $all_instances ); |
|
| 95 | 95 | |
| 96 | 96 | return $action_ids; |
| 97 | 97 | } |
@@ -100,31 +100,31 @@ discard block |
||
| 100 | 100 | * Create static css file |
| 101 | 101 | */ |
| 102 | 102 | public function save_settings( $styles ) { |
| 103 | - $filename = FrmAppHelper::plugin_path() .'/css/custom_theme.css.php'; |
|
| 104 | - update_option( 'frm_last_style_update', date('njGi') ); |
|
| 103 | + $filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php'; |
|
| 104 | + update_option( 'frm_last_style_update', date( 'njGi' ) ); |
|
| 105 | 105 | |
| 106 | - if ( ! is_file($filename) ) { |
|
| 106 | + if ( ! is_file( $filename ) ) { |
|
| 107 | 107 | return; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | $defaults = $this->get_defaults(); |
| 111 | 111 | $uploads = wp_upload_dir(); |
| 112 | - $target_path = $uploads['basedir'] .'/formidable'; |
|
| 113 | - $needed_dirs = array( $target_path, $target_path .'/css' ); |
|
| 112 | + $target_path = $uploads['basedir'] . '/formidable'; |
|
| 113 | + $needed_dirs = array( $target_path, $target_path . '/css' ); |
|
| 114 | 114 | $dirs_exist = true; |
| 115 | 115 | |
| 116 | 116 | $saving = true; |
| 117 | - $css = '/* '. __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) .' */'. "\n"; |
|
| 117 | + $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n"; |
|
| 118 | 118 | |
| 119 | 119 | ob_start(); |
| 120 | 120 | $frm_style = $this; |
| 121 | - include($filename); |
|
| 121 | + include( $filename ); |
|
| 122 | 122 | $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) ); |
| 123 | 123 | ob_end_clean(); |
| 124 | 124 | |
| 125 | 125 | $access_type = get_filesystem_method(); |
| 126 | 126 | if ( $access_type === 'direct' ) { |
| 127 | - $creds = request_filesystem_credentials( site_url() .'/wp-admin/', '', false, false, array() ); |
|
| 127 | + $creds = request_filesystem_credentials( site_url() . '/wp-admin/', '', false, false, array() ); |
|
| 128 | 128 | } else { |
| 129 | 129 | $creds = $this->get_ftp_creds( $access_type ); |
| 130 | 130 | } |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | if ( $dirs_exist ) { |
| 140 | 140 | global $wp_filesystem; |
| 141 | 141 | |
| 142 | - $chmod_dir = defined('FS_CHMOD_DIR') ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 ); |
|
| 143 | - $chmod_file = defined('FS_CHMOD_FILE') ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
|
| 142 | + $chmod_dir = defined( 'FS_CHMOD_DIR' ) ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 ); |
|
| 143 | + $chmod_file = defined( 'FS_CHMOD_FILE' ) ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
|
| 144 | 144 | |
| 145 | 145 | // Create the directories if need be: |
| 146 | 146 | foreach ( $needed_dirs as $_dir ) { |
@@ -150,33 +150,33 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $index_path = $target_path .'/index.php'; |
|
| 153 | + $index_path = $target_path . '/index.php'; |
|
| 154 | 154 | $wp_filesystem->put_contents( $index_path, "<?php\n// Silence is golden.\n?>", $chmod_file ); |
| 155 | 155 | |
| 156 | 156 | // only write the file if the folders exist |
| 157 | 157 | if ( $dirs_exist ) { |
| 158 | - $css_file = $target_path .'/css/formidablepro.css'; |
|
| 158 | + $css_file = $target_path . '/css/formidablepro.css'; |
|
| 159 | 159 | $wp_filesystem->put_contents( $css_file, $css, $chmod_file ); |
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - update_option('frmpro_css', $css); |
|
| 164 | + update_option( 'frmpro_css', $css ); |
|
| 165 | 165 | |
| 166 | - delete_transient('frmpro_css'); |
|
| 167 | - set_transient('frmpro_css', $css); |
|
| 166 | + delete_transient( 'frmpro_css' ); |
|
| 167 | + set_transient( 'frmpro_css', $css ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | private function get_ftp_creds( $type ) { |
| 171 | 171 | $credentials = get_option( 'ftp_credentials', array( 'hostname' => '', 'username' => '' ) ); |
| 172 | 172 | |
| 173 | - $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : $credentials['hostname']; |
|
| 174 | - $credentials['username'] = defined('FTP_USER') ? FTP_USER : $credentials['username']; |
|
| 175 | - $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : ''; |
|
| 173 | + $credentials['hostname'] = defined( 'FTP_HOST' ) ? FTP_HOST : $credentials['hostname']; |
|
| 174 | + $credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : $credentials['username']; |
|
| 175 | + $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : ''; |
|
| 176 | 176 | |
| 177 | 177 | // Check to see if we are setting the public/private keys for ssh |
| 178 | - $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : ''; |
|
| 179 | - $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : ''; |
|
| 178 | + $credentials['public_key'] = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : ''; |
|
| 179 | + $credentials['private_key'] = defined( 'FTP_PRIKEY' ) ? FTP_PRIKEY : ''; |
|
| 180 | 180 | |
| 181 | 181 | // Sanitize the hostname, Some people might pass in odd-data: |
| 182 | 182 | $credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] ); //Strip any schemes off |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | public function destroy( $id ) { |
| 221 | - return wp_delete_post($id); |
|
| 221 | + return wp_delete_post( $id ); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | public function get_one() { |
@@ -232,19 +232,19 @@ discard block |
||
| 232 | 232 | return $style; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - $style = get_post($this->id); |
|
| 235 | + $style = get_post( $this->id ); |
|
| 236 | 236 | |
| 237 | 237 | if ( ! $style ) { |
| 238 | 238 | return $style; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
| 241 | + $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content ); |
|
| 242 | 242 | |
| 243 | 243 | $default_values = $this->get_defaults(); |
| 244 | 244 | |
| 245 | 245 | // fill default values |
| 246 | - $style->post_content = $this->override_defaults($style->post_content); |
|
| 247 | - $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
| 246 | + $style->post_content = $this->override_defaults( $style->post_content ); |
|
| 247 | + $style->post_content = wp_parse_args( $style->post_content, $default_values ); |
|
| 248 | 248 | |
| 249 | 249 | return $style; |
| 250 | 250 | } |
@@ -258,21 +258,21 @@ discard block |
||
| 258 | 258 | 'order' => $order, |
| 259 | 259 | ); |
| 260 | 260 | |
| 261 | - $temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts'); |
|
| 261 | + $temp_styles = FrmAppHelper::check_cache( serialize( $post_atts ), 'frm_styles', $post_atts, 'get_posts' ); |
|
| 262 | 262 | |
| 263 | - if ( empty($temp_styles) ) { |
|
| 263 | + if ( empty( $temp_styles ) ) { |
|
| 264 | 264 | global $wpdb; |
| 265 | 265 | // make sure there wasn't a conflict with the query |
| 266 | - $query = $wpdb->prepare('SELECT * FROM '. $wpdb->posts .' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish'); |
|
| 267 | - $temp_styles = FrmAppHelper::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results'); |
|
| 266 | + $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' ); |
|
| 267 | + $temp_styles = FrmAppHelper::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' ); |
|
| 268 | 268 | |
| 269 | - if ( empty($temp_styles) ) { |
|
| 269 | + if ( empty( $temp_styles ) ) { |
|
| 270 | 270 | // create a new style if there are none |
| 271 | 271 | $new = $this->get_new(); |
| 272 | 272 | $new->post_title = $new->post_name = __( 'Formidable Style', 'formidable' ); |
| 273 | 273 | $new->menu_order = 1; |
| 274 | - $new = $this->save( (array) $new); |
|
| 275 | - $this->update('default'); |
|
| 274 | + $new = $this->save( (array) $new ); |
|
| 275 | + $this->update( 'default' ); |
|
| 276 | 276 | |
| 277 | 277 | $post_atts['include'] = $new; |
| 278 | 278 | |
@@ -296,25 +296,25 @@ discard block |
||
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
| 299 | + $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content ); |
|
| 300 | 300 | |
| 301 | 301 | // fill default values |
| 302 | - $style->post_content = $this->override_defaults($style->post_content); |
|
| 303 | - $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
| 302 | + $style->post_content = $this->override_defaults( $style->post_content ); |
|
| 303 | + $style->post_content = wp_parse_args( $style->post_content, $default_values ); |
|
| 304 | 304 | |
| 305 | - $styles[ $style->ID ] = $style; |
|
| 305 | + $styles[$style->ID] = $style; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | if ( ! $default_style ) { |
| 309 | - $default_style = reset($styles); |
|
| 310 | - $styles[ $default_style->ID ]->menu_order = 1; |
|
| 309 | + $default_style = reset( $styles ); |
|
| 310 | + $styles[$default_style->ID]->menu_order = 1; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | return $styles; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | public function get_default_style( $styles = null ) { |
| 317 | - if ( ! isset($styles) ) { |
|
| 317 | + if ( ! isset( $styles ) ) { |
|
| 318 | 318 | $styles = $this->get_all( 'menu_order', 'DESC', 1 ); |
| 319 | 319 | } |
| 320 | 320 | |
@@ -326,24 +326,24 @@ discard block |
||
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | public function override_defaults( $settings ) { |
| 329 | - if ( ! is_array($settings) ) { |
|
| 329 | + if ( ! is_array( $settings ) ) { |
|
| 330 | 330 | return $settings; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height']; |
|
| 333 | + $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height']; |
|
| 334 | 334 | |
| 335 | - if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) { |
|
| 335 | + if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) { |
|
| 336 | 336 | $settings['form_desc_size'] = $settings['description_font_size']; |
| 337 | 337 | $settings['form_desc_color'] = $settings['description_color']; |
| 338 | 338 | $settings['title_color'] = $settings['label_color']; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) { |
|
| 341 | + if ( ! isset( $settings['section_color'] ) && isset( $settings['label_color'] ) ) { |
|
| 342 | 342 | $settings['section_color'] = $settings['label_color']; |
| 343 | 343 | $settings['section_border_color'] = $settings['border_color']; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) { |
|
| 346 | + if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) { |
|
| 347 | 347 | $settings['submit_hover_bg_color'] = $settings['submit_bg_color']; |
| 348 | 348 | $settings['submit_hover_color'] = $settings['submit_text_color']; |
| 349 | 349 | $settings['submit_hover_border_color'] = $settings['submit_border_color']; |
@@ -485,7 +485,7 @@ discard block |
||
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
| 488 | - return 'frm_style_setting'. ( empty($post_field) ? '' : '['. $post_field .']' ) .'[' . $field_name . ']'; |
|
| 488 | + return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']'; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | public static function get_bold_options() { |