| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 5 | 2 | |
| 6 | 3 | class FrmStyle { |
| 7 | 4 | public $number = false; // Unique ID number of the current instance. |
| 8 | 5 | public $id = 0; // the id of the post |
| @@ -13,11 +10,8 @@ | ||
| 13 | 10 | public function __construct( $id = 0 ) { |
| 14 | 11 | $this->id = $id; |
| 15 | 12 | } |
| 16 | 13 | |
| 17 | - /** | |
| 18 | - * @return stdClass | |
| 19 | - */ | |
| 20 | 14 | public function get_new() { |
| 21 | 15 | $this->id = 0; |
| 22 | 16 | |
| 23 | 17 | $max_slug_value = 2147483647; |
| @@ -36,33 +30,20 @@ | ||
| 36 | 30 | |
| 37 | 31 | return (object) $style; |
| 38 | 32 | } |
| 39 | 33 | |
| 40 | - /** | |
| 41 | - * @param array $settings | |
| 42 | - * @return int|WP_Error | |
| 43 | - */ | |
| 44 | 34 | public function save( $settings ) { |
| 45 | 35 | return FrmDb::save_settings( $settings, 'frm_styles' ); |
| 46 | 36 | } |
| 47 | 37 | |
| 48 | - /** | |
| 49 | - * @return void | |
| 50 | - */ | |
| 51 | 38 | public function duplicate( $id ) { |
| 52 | - // Duplicating is a pro feature. This is handled in FrmProStyle::duplicate instead. | |
| 39 | + // duplicating is a pro feature | |
| 53 | 40 | } |
| 54 | 41 | |
| 55 | - /** | |
| 56 | - * Handle save actions in the visual styler edit page. | |
| 57 | - * | |
| 58 | - * @param mixed $id | |
| 59 | - * @return array<int|WP_Error> | |
| 60 | - */ | |
| 61 | 42 | public function update( $id = 'default' ) { |
| 62 | 43 | $all_instances = $this->get_all(); |
| 63 | 44 | |
| 64 | - if ( ! $id ) { | |
| 45 | + if ( empty( $id ) ) { | |
| 65 | 46 | $new_style = (array) $this->get_new(); |
| 66 | 47 | $all_instances[] = $new_style; |
| 67 | 48 | } |
| 68 | 49 | |
| @@ -70,33 +51,31 @@ | ||
| 70 | 51 | |
| 71 | 52 | foreach ( $all_instances as $number => $new_instance ) { |
| 72 | 53 | $new_instance = (array) $new_instance; |
| 73 | 54 | $this->id = $new_instance['ID']; |
| 55 | + if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { | |
| 56 | + $all_instances[ $number ] = $new_instance; | |
| 74 | 57 | |
| 75 | - if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 76 | - // Don't continue if not saving this style. | |
| 58 | + if ( $new_instance['menu_order'] && $_POST && empty( $_POST['prev_menu_order'] ) && isset( $_POST['frm_style_setting']['menu_order'] ) ) { | |
| 59 | + // this style was set to default, so remove default setting on previous default style | |
| 60 | + $new_instance['menu_order'] = 0; | |
| 61 | + $action_ids[] = $this->save( $new_instance ); | |
| 62 | + } | |
| 63 | + | |
| 64 | + // don't continue if not saving this style | |
| 77 | 65 | continue; |
| 78 | 66 | } |
| 79 | 67 | |
| 80 | - // Custom CSS is no longer used from the default style, but it is still checked if the Global Setting is missing. | |
| 81 | - // Preserve the previous value in case Custom CSS has not been saved as a Global Setting yet. | |
| 82 | - $custom_css = isset( $new_instance['post_content']['custom_css'] ) ? $new_instance['post_content']['custom_css'] : ''; | |
| 68 | + $new_instance['post_title'] = isset( $_POST['frm_style_setting']['post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) ) : ''; | |
| 83 | 69 | |
| 84 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 85 | - if ( ! empty( $_POST['frm_style_setting']['post_title'] ) ) { | |
| 86 | - // The nonce check happens in FrmStylesController::save_style before this is called. | |
| 87 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 88 | - $new_instance['post_title'] = sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) ); | |
| 89 | - } | |
| 90 | - | |
| 91 | - $new_instance['post_content'] = isset( $_POST['frm_style_setting']['post_content'] ) ? $this->sanitize_post_content( wp_unslash( $_POST['frm_style_setting']['post_content'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing | |
| 92 | - $new_instance['post_content']['custom_css'] = $custom_css; | |
| 93 | - unset( $custom_css ); | |
| 94 | - | |
| 70 | + // Don't wp_unslash yet since it removes backslashes. | |
| 71 | + $new_instance['post_content'] = isset( $_POST['frm_style_setting']['post_content'] ) ? $_POST['frm_style_setting']['post_content'] : ''; // WPCS: sanitization ok. | |
| 72 | + FrmAppHelper::sanitize_value( 'wp_kses_post', $new_instance['post_content'] ); | |
| 95 | 73 | $new_instance['post_type'] = FrmStylesController::$post_type; |
| 96 | 74 | $new_instance['post_status'] = 'publish'; |
| 75 | + $new_instance['menu_order'] = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0; | |
| 97 | 76 | |
| 98 | - if ( ! $id ) { | |
| 77 | + if ( empty( $id ) ) { | |
| 99 | 78 | $new_instance['post_name'] = $new_instance['post_title']; |
| 100 | 79 | } |
| 101 | 80 | |
| 102 | 81 | $default_settings = $this->get_defaults(); |
| @@ -106,22 +85,22 @@ | ||
| 106 | 85 | $new_instance['post_content'][ $setting ] = $default; |
| 107 | 86 | } |
| 108 | 87 | |
| 109 | 88 | if ( $this->is_color( $setting ) ) { |
| 110 | - $color_val = $new_instance['post_content'][ $setting ]; | |
| 111 | - if ( $color_val !== '' && false !== strpos( $color_val, 'rgb' ) ) { | |
| 112 | - // Maybe sanitize if invalid rgba value is entered. | |
| 113 | - $this->maybe_sanitize_rgba_value( $color_val ); | |
| 114 | - } | |
| 115 | - $new_instance['post_content'][ $setting ] = str_replace( '#', '', $color_val ); | |
| 116 | - } elseif ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ), true ) && ! isset( $new_instance['post_content'][ $setting ] ) ) { | |
| 89 | + $new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] ); | |
| 90 | + } elseif ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) | |
| 91 | + && ! isset( $new_instance['post_content'][ $setting ] ) | |
| 92 | + ) { | |
| 117 | 93 | $new_instance['post_content'][ $setting ] = 0; |
| 118 | - } elseif ( $setting === 'font' ) { | |
| 94 | + } elseif ( $setting == 'font' ) { | |
| 119 | 95 | $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] ); |
| 120 | 96 | } |
| 121 | 97 | } |
| 122 | 98 | |
| 99 | + $all_instances[ $number ] = $new_instance; | |
| 100 | + | |
| 123 | 101 | $action_ids[] = $this->save( $new_instance ); |
| 102 | + | |
| 124 | 103 | } |
| 125 | 104 | |
| 126 | 105 | $this->save_settings(); |
| 127 | 106 | |
| @@ -128,238 +107,18 @@ | ||
| 128 | 107 | return $action_ids; |
| 129 | 108 | } |
| 130 | 109 | |
| 131 | 110 | /** |
| 132 | - * Sanitize custom color values and convert it to valid one filling missing values. | |
| 133 | - * | |
| 134 | - * @since 5.3.2 | |
| 135 | - * | |
| 136 | - * @param string $color_val, The color value, by reference. | |
| 137 | - * @return void | |
| 138 | - */ | |
| 139 | - private function maybe_sanitize_rgba_value( &$color_val ) { | |
| 140 | - if ( preg_match( '/(rgb|rgba)\(/', $color_val ) !== 1 ) { | |
| 141 | - return; | |
| 142 | - } | |
| 143 | - | |
| 144 | - $color_val = trim( $color_val ); | |
| 145 | - $color_val = ltrim( $color_val, '(' ); // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces. | |
| 146 | - $patterns = array( '/rgba\((\s*\d+\s*,){3}[[0-1]\.]+\)/', '/rgb\((\s*\d+\s*,){2}\s*[\d]+\)/' ); | |
| 147 | - foreach ( $patterns as $pattern ) { | |
| 148 | - if ( preg_match( $pattern, $color_val ) === 1 ) { | |
| 149 | - return; | |
| 150 | - } | |
| 151 | - } | |
| 152 | - | |
| 153 | - // Remove all leading ')' braces, then add one back. This way there's always a single brace. | |
| 154 | - $color_val = rtrim( $color_val, ')' ); | |
| 155 | - $color_val .= ')'; | |
| 156 | - | |
| 157 | - $color_rgba = substr( $color_val, strpos( $color_val, '(' ) + 1, strlen( $color_val ) - strpos( $color_val, '(' ) - 2 ); | |
| 158 | - $color_rgba = trim( $color_rgba, '()' ); // Remove any excessive braces from the rgba like rgba((. | |
| 159 | - $length_of_color_codes = strpos( $color_val, '(' ); | |
| 160 | - $new_color_values = array(); | |
| 161 | - | |
| 162 | - // replace empty values by 0 or 1 (if alpha position). | |
| 163 | - foreach ( explode( ',', $color_rgba ) as $index => $value ) { | |
| 164 | - $new_value = null; | |
| 165 | - $value_is_empty_string = '' === trim( $value ) || '' === $value; | |
| 166 | - | |
| 167 | - if ( 3 === $length_of_color_codes || ( $index !== $length_of_color_codes - 1 ) ) { | |
| 168 | - // Insert a value for r, g, or b. | |
| 169 | - if ( $value < 0 ) { | |
| 170 | - $new_value = 0; | |
| 171 | - } elseif ( $value > 255 ) { | |
| 172 | - $new_value = 255; | |
| 173 | - } elseif ( $value_is_empty_string ) { | |
| 174 | - $new_value = 0; | |
| 175 | - } else { | |
| 176 | - $new_value = absint( $value ); | |
| 177 | - } | |
| 178 | - } else { | |
| 179 | - // Insert a value for alpha. | |
| 180 | - if ( $value_is_empty_string ) { | |
| 181 | - $new_value = 4 === $length_of_color_codes ? 1 : 0; | |
| 182 | - } elseif ( $value > 1 || $value < 0 ) { | |
| 183 | - $new_value = 1; | |
| 184 | - } else { | |
| 185 | - $new_value = floatval( $value ); | |
| 186 | - } | |
| 187 | - } | |
| 188 | - | |
| 189 | - $new_color_values[] = null === $new_value ? $value : $new_value; | |
| 190 | - } | |
| 191 | - | |
| 192 | - // add more 0s and 1 (if alpha position) if needed. | |
| 193 | - $missing_values = $length_of_color_codes - count( $new_color_values ); | |
| 194 | - if ( $missing_values > 1 ) { | |
| 195 | - $insert_values = array_fill( 0, $missing_values - 1, 0 ); | |
| 196 | - $last_value = 4 === $length_of_color_codes ? 1 : 0; | |
| 197 | - array_push( $insert_values, $last_value ); | |
| 198 | - } elseif ( $missing_values === 1 ) { | |
| 199 | - $insert_values = 4 === $length_of_color_codes ? array( 1 ) : array( 0 ); | |
| 200 | - } | |
| 201 | - if ( ! empty( $insert_values ) ) { | |
| 202 | - $new_color_values = array_merge( $new_color_values, $insert_values ); | |
| 203 | - } | |
| 204 | - | |
| 205 | - $new_color = implode( ',', $new_color_values ); | |
| 206 | - $prefix = substr( $color_val, 0, strpos( $color_val, '(' ) + 1 ); | |
| 207 | - $prefix = rtrim( $prefix, '(' ) . '('; // Limit the number of opening braces after rgb/rgba. There should only be one. | |
| 208 | - $new_color = $prefix . $new_color . ')'; | |
| 209 | - | |
| 210 | - $color_val = $new_color; | |
| 211 | - } | |
| 212 | - | |
| 213 | - /** | |
| 214 | - * Unslash everything in post_content but custom_css | |
| 215 | - * | |
| 216 | - * @since 5.0.13 | |
| 217 | - * | |
| 218 | - * @param array $settings | |
| 219 | - * @return array | |
| 220 | - */ | |
| 221 | - private function unslash_post_content( $settings ) { | |
| 222 | - $custom_css = isset( $settings['custom_css'] ) ? $settings['custom_css'] : ''; | |
| 223 | - $settings = wp_unslash( $settings ); | |
| 224 | - $settings['custom_css'] = $custom_css; | |
| 225 | - return $settings; | |
| 226 | - } | |
| 227 | - | |
| 228 | - /** | |
| 229 | - * @since 5.0.13 | |
| 230 | - * | |
| 231 | - * @param array $settings | |
| 232 | - * @return array | |
| 233 | - */ | |
| 234 | - public function sanitize_post_content( $settings ) { | |
| 235 | - $defaults = $this->get_defaults(); | |
| 236 | - $valid_keys = array_keys( $defaults ); | |
| 237 | - $sanitized_settings = array(); | |
| 238 | - foreach ( $valid_keys as $key ) { | |
| 239 | - if ( isset( $settings[ $key ] ) ) { | |
| 240 | - $sanitized_settings[ $key ] = sanitize_textarea_field( $settings[ $key ] ); | |
| 241 | - } else { | |
| 242 | - $sanitized_settings[ $key ] = $defaults[ $key ]; | |
| 243 | - } | |
| 244 | - | |
| 245 | - if ( 'custom_css' !== $key ) { | |
| 246 | - $sanitized_settings[ $key ] = $this->strip_invalid_characters( $sanitized_settings[ $key ] ); | |
| 247 | - } | |
| 248 | - } | |
| 249 | - return $sanitized_settings; | |
| 250 | - } | |
| 251 | - | |
| 252 | - /** | |
| 253 | - * Remove any characters that should not be used in CSS. | |
| 254 | - * | |
| 255 | - * @since 6.2.3 | |
| 256 | - * | |
| 257 | - * @param string $setting | |
| 258 | - * @return string | |
| 259 | - */ | |
| 260 | - private function strip_invalid_characters( $setting ) { | |
| 261 | - $characters_to_remove = array( '{', '}', ';', '[', ']' ); | |
| 262 | - | |
| 263 | - // RGB is handled instead in self::maybe_sanitize_rgba_value. | |
| 264 | - if ( 0 !== strpos( $setting, 'rgb' ) ) { | |
| 265 | - $setting = $this->maybe_fix_braces( $setting, $characters_to_remove ); | |
| 266 | - } | |
| 267 | - | |
| 268 | - return str_replace( $characters_to_remove, '', $setting ); | |
| 269 | - } | |
| 270 | - | |
| 271 | - /** | |
| 272 | - * @since 6.2.3 | |
| 273 | - * | |
| 274 | - * @param string $setting | |
| 275 | - * @param array $characters_to_remove | |
| 276 | - * @return string | |
| 277 | - */ | |
| 278 | - private function maybe_fix_braces( $setting, &$characters_to_remove ) { | |
| 279 | - $number_of_opening_braces = substr_count( $setting, '(' ); | |
| 280 | - $number_of_closing_braces = substr_count( $setting, ')' ); | |
| 281 | - | |
| 282 | - if ( $number_of_opening_braces === $number_of_closing_braces ) { | |
| 283 | - return $this->trim_braces( $setting ); | |
| 284 | - } | |
| 285 | - | |
| 286 | - if ( $this->should_remove_every_brace( $setting ) ) { | |
| 287 | - // Add to $characters_to_remove to remove when str_replace is called. | |
| 288 | - array_push( $characters_to_remove, '(', ')' ); | |
| 289 | - return $setting; | |
| 290 | - } | |
| 291 | - | |
| 292 | - return $this->trim_braces( $setting ); | |
| 293 | - } | |
| 294 | - | |
| 295 | - /** | |
| 296 | - * @since 6.2.3 | |
| 297 | - * | |
| 298 | - * @param string $input | |
| 299 | - * @return string | |
| 300 | - */ | |
| 301 | - private function trim_braces( $input ) { | |
| 302 | - $output = $input; | |
| 303 | - // Remove any ( from the start of the string as no CSS values expect at the first character. | |
| 304 | - if ( $output ) { | |
| 305 | - if ( in_array( $output[0], array( '(', ')' ), true ) ) { | |
| 306 | - $output = ltrim( $output, '()' ); | |
| 307 | - } | |
| 308 | - } | |
| 309 | - // Remove extra braces from the end. | |
| 310 | - if ( in_array( substr( $output, -1 ), array( '(', ')' ), true ) ) { | |
| 311 | - $output = rtrim( $output, '()' ); | |
| 312 | - if ( false !== strpos( $output, '(' ) ) { | |
| 313 | - $output .= ')'; | |
| 314 | - } | |
| 315 | - } | |
| 316 | - return $output; | |
| 317 | - } | |
| 318 | - | |
| 319 | - /** | |
| 320 | - * @since 6.2.3 | |
| 321 | - * | |
| 322 | - * @param string $setting | |
| 323 | - * @return bool | |
| 324 | - */ | |
| 325 | - private function should_remove_every_brace( $setting ) { | |
| 326 | - if ( 0 === strpos( trim( $setting, '()' ), 'calc' ) ) { | |
| 327 | - // Support calc() sizes. We do not want to remove all braces when calc is used. | |
| 328 | - return false; | |
| 329 | - } | |
| 330 | - | |
| 331 | - // Matches hex values but also checks for unexpected ( and ). | |
| 332 | - $looks_like_a_hex_value = preg_match( '/^(?:\()?(?!#?[a-fA-F0-9]*[^\(#\)\da-fA-F])[a-fA-F0-9\(\)]*(?:\))?$/', $setting ); | |
| 333 | - if ( $looks_like_a_hex_value ) { | |
| 334 | - return true; | |
| 335 | - } | |
| 336 | - | |
| 337 | - // Matches size values but also checks for unexpected ( and ). | |
| 338 | - // This is case insensitive so it will catch PX, PT, etc, as well. | |
| 339 | - $looks_like_a_size = preg_match( '/\(?[+-]?\d*\.?\d+(?:px|%|em|rem|ex|pt|pc|mm|cm|in)\)?/i', $setting ); | |
| 340 | - if ( $looks_like_a_size ) { | |
| 341 | - return true; | |
| 342 | - } | |
| 343 | - | |
| 344 | - return false; | |
| 345 | - } | |
| 346 | - | |
| 347 | - /** | |
| 348 | 111 | * @since 3.01.01 |
| 349 | - * | |
| 350 | - * @param string $setting | |
| 351 | - * @return bool | |
| 352 | 112 | */ |
| 353 | 113 | private function is_color( $setting ) { |
| 354 | 114 | $extra_colors = array( 'error_bg', 'error_border', 'error_text' ); |
| 355 | - return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors, true ); | |
| 115 | + | |
| 116 | + return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors ); | |
| 356 | 117 | } |
| 357 | 118 | |
| 358 | 119 | /** |
| 359 | 120 | * @since 3.01.01 |
| 360 | - * | |
| 361 | - * @return array | |
| 362 | 121 | */ |
| 363 | 122 | public function get_color_settings() { |
| 364 | 123 | $defaults = $this->get_defaults(); |
| 365 | 124 | $settings = array_keys( $defaults ); |
| @@ -367,15 +126,13 @@ | ||
| 367 | 126 | return array_filter( $settings, array( $this, 'is_color' ) ); |
| 368 | 127 | } |
| 369 | 128 | |
| 370 | 129 | /** |
| 371 | - * Create static CSS file and update the CSS transient alternative. | |
| 372 | - * | |
| 373 | - * @return void | |
| 130 | + * Create static css file | |
| 374 | 131 | */ |
| 375 | 132 | public function save_settings() { |
| 376 | 133 | $filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php'; |
| 377 | - update_option( 'frm_last_style_update', gmdate( 'njGi' ) ); | |
| 134 | + update_option( 'frm_last_style_update', date( 'njGi' ) ); | |
| 378 | 135 | |
| 379 | 136 | if ( ! is_file( $filename ) ) { |
| 380 | 137 | return; |
| 381 | 138 | } |
| @@ -381,9 +138,10 @@ | ||
| 381 | 138 | } |
| 382 | 139 | |
| 383 | 140 | $this->clear_cache(); |
| 384 | 141 | |
| 385 | - $css = $this->get_css_content( $filename ); | |
| 142 | + $css = $this->get_css_content( $filename ); | |
| 143 | + | |
| 386 | 144 | $create_file = new FrmCreateFile( |
| 387 | 145 | array( |
| 388 | 146 | 'file_name' => FrmStylesController::get_file_name(), |
| 389 | 147 | 'new_file_path' => FrmAppHelper::plugin_path() . '/css', |
| @@ -394,12 +152,8 @@ | ||
| 394 | 152 | update_option( 'frmpro_css', $css, 'no' ); |
| 395 | 153 | set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS ); |
| 396 | 154 | } |
| 397 | 155 | |
| 398 | - /** | |
| 399 | - * @param string $filename | |
| 400 | - * @return string | |
| 401 | - */ | |
| 402 | 156 | private function get_css_content( $filename ) { |
| 403 | 157 | $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n"; |
| 404 | 158 | |
| 405 | 159 | $saving = true; |
| @@ -405,18 +159,15 @@ | ||
| 405 | 159 | $saving = true; |
| 406 | 160 | $frm_style = $this; |
| 407 | 161 | |
| 408 | 162 | ob_start(); |
| 409 | - include $filename; | |
| 163 | + include( $filename ); | |
| 410 | 164 | $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) ); |
| 411 | 165 | ob_end_clean(); |
| 412 | 166 | |
| 413 | - return FrmStylesController::replace_relative_url( $css ); | |
| 167 | + return $css; | |
| 414 | 168 | } |
| 415 | 169 | |
| 416 | - /** | |
| 417 | - * @return void | |
| 418 | - */ | |
| 419 | 170 | private function clear_cache() { |
| 420 | 171 | $default_post_atts = array( |
| 421 | 172 | 'post_type' => FrmStylesController::$post_type, |
| 422 | 173 | 'post_status' => 'publish', |
| @@ -424,31 +175,19 @@ | ||
| 424 | 175 | 'orderby' => 'title', |
| 425 | 176 | 'order' => 'ASC', |
| 426 | 177 | ); |
| 427 | 178 | |
| 428 | - FrmDb::delete_cache_and_transient( json_encode( $default_post_atts ), 'frm_styles' ); | |
| 179 | + FrmDb::delete_cache_and_transient( serialize( $default_post_atts ), 'frm_styles' ); | |
| 429 | 180 | FrmDb::cache_delete_group( 'frm_styles' ); |
| 430 | 181 | FrmDb::delete_cache_and_transient( 'frmpro_css' ); |
| 431 | 182 | } |
| 432 | 183 | |
| 433 | - /** | |
| 434 | - * Delete a style by its post ID. | |
| 435 | - * | |
| 436 | - * @param int $id | |
| 437 | - * @return WP_Post|false|null | |
| 438 | - */ | |
| 439 | 184 | public function destroy( $id ) { |
| 440 | - if ( $id === $this->get_default_style()->ID ) { | |
| 441 | - return false; | |
| 442 | - } | |
| 443 | 185 | return wp_delete_post( $id ); |
| 444 | 186 | } |
| 445 | 187 | |
| 446 | - /** | |
| 447 | - * @return WP_Post|stdClass | |
| 448 | - */ | |
| 449 | 188 | public function get_one() { |
| 450 | - if ( 'default' === $this->id ) { | |
| 189 | + if ( 'default' == $this->id ) { | |
| 451 | 190 | $style = $this->get_default_style(); |
| 452 | 191 | if ( $style ) { |
| 453 | 192 | $this->id = $style->ID; |
| 454 | 193 | } else { |
| @@ -474,14 +213,8 @@ | ||
| 474 | 213 | |
| 475 | 214 | return $style; |
| 476 | 215 | } |
| 477 | 216 | |
| 478 | - /** | |
| 479 | - * @param string $orderby | |
| 480 | - * @param string $order | |
| 481 | - * @param int $limit | |
| 482 | - * @return array | |
| 483 | - */ | |
| 484 | 217 | public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) { |
| 485 | 218 | $post_atts = array( |
| 486 | 219 | 'post_type' => FrmStylesController::$post_type, |
| 487 | 220 | 'post_status' => 'publish', |
| @@ -489,9 +222,9 @@ | ||
| 489 | 222 | 'orderby' => $orderby, |
| 490 | 223 | 'order' => $order, |
| 491 | 224 | ); |
| 492 | 225 | |
| 493 | - $temp_styles = FrmDb::check_cache( json_encode( $post_atts ), 'frm_styles', $post_atts, 'get_posts' ); | |
| 226 | + $temp_styles = FrmDb::check_cache( serialize( $post_atts ), 'frm_styles', $post_atts, 'get_posts' ); | |
| 494 | 227 | |
| 495 | 228 | if ( empty( $temp_styles ) ) { |
| 496 | 229 | global $wpdb; |
| 497 | 230 | // make sure there wasn't a conflict with the query |
| @@ -546,11 +279,8 @@ | ||
| 546 | 279 | |
| 547 | 280 | return $styles; |
| 548 | 281 | } |
| 549 | 282 | |
| 550 | - /** | |
| 551 | - * @param array|null $styles | |
| 552 | - */ | |
| 553 | 283 | public function get_default_style( $styles = null ) { |
| 554 | 284 | if ( ! isset( $styles ) ) { |
| 555 | 285 | $styles = $this->get_all( 'menu_order', 'DESC', 1 ); |
| 556 | 286 | } |
| @@ -561,12 +291,8 @@ | ||
| 561 | 291 | } |
| 562 | 292 | } |
| 563 | 293 | } |
| 564 | 294 | |
| 565 | - /** | |
| 566 | - * @param mixed $settings | |
| 567 | - * @return mixed | |
| 568 | - */ | |
| 569 | 295 | public function override_defaults( $settings ) { |
| 570 | 296 | if ( ! is_array( $settings ) ) { |
| 571 | 297 | return $settings; |
| 572 | 298 | } |
| @@ -596,11 +322,8 @@ | ||
| 596 | 322 | |
| 597 | 323 | return apply_filters( 'frm_override_default_styles', $settings ); |
| 598 | 324 | } |
| 599 | 325 | |
| 600 | - /** | |
| 601 | - * @return array | |
| 602 | - */ | |
| 603 | 326 | public function get_defaults() { |
| 604 | 327 | $defaults = array( |
| 605 | 328 | 'theme_css' => 'ui-lightness', |
| 606 | 329 | 'theme_name' => 'UI Lightness', |
| @@ -613,22 +336,21 @@ | ||
| 613 | 336 | 'fieldset_color' => '000000', |
| 614 | 337 | 'fieldset_padding' => '0 0 15px 0', |
| 615 | 338 | 'fieldset_bg_color' => '', |
| 616 | 339 | |
| 617 | - 'title_size' => '40px', | |
| 340 | + 'title_size' => '20px', | |
| 618 | 341 | 'title_color' => '444444', |
| 619 | 342 | 'title_margin_top' => '10px', |
| 620 | - 'title_margin_bottom' => '60px', | |
| 343 | + 'title_margin_bottom' => '10px', | |
| 621 | 344 | 'form_desc_size' => '14px', |
| 622 | 345 | 'form_desc_color' => '666666', |
| 623 | 346 | 'form_desc_margin_top' => '10px', |
| 624 | 347 | 'form_desc_margin_bottom' => '25px', |
| 625 | - 'form_desc_padding' => '0', | |
| 626 | 348 | |
| 627 | - 'font' => '', | |
| 628 | - 'font_size' => '15px', | |
| 629 | - 'label_color' => '3f4b5b', | |
| 630 | - 'weight' => 'normal', | |
| 349 | + 'font' => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif', | |
| 350 | + 'font_size' => '14px', | |
| 351 | + 'label_color' => '444444', | |
| 352 | + 'weight' => 'bold', | |
| 631 | 353 | 'position' => 'none', |
| 632 | 354 | 'align' => 'left', |
| 633 | 355 | 'width' => '150px', |
| 634 | 356 | 'required_color' => 'B94A48', |
| @@ -651,9 +373,9 @@ | ||
| 651 | 373 | 'field_margin' => '20px', |
| 652 | 374 | 'field_weight' => 'normal', |
| 653 | 375 | 'text_color' => '555555', |
| 654 | 376 | //'border_color_hv' => 'cccccc', |
| 655 | - 'border_color' => 'BFC3C8', | |
| 377 | + 'border_color' => 'cccccc', | |
| 656 | 378 | 'field_border_width' => '1px', |
| 657 | 379 | 'field_border_style' => 'solid', |
| 658 | 380 | |
| 659 | 381 | 'bg_color' => 'ffffff', |
| @@ -681,9 +403,9 @@ | ||
| 681 | 403 | 'section_color' => '444444', |
| 682 | 404 | 'section_weight' => 'bold', |
| 683 | 405 | 'section_pad' => '15px 0 3px 0', |
| 684 | 406 | 'section_mar_top' => '15px', |
| 685 | - 'section_mar_bottom' => '30px', | |
| 407 | + 'section_mar_bottom' => '12px', | |
| 686 | 408 | 'section_bg_color' => '', |
| 687 | 409 | 'section_border_color' => 'e8e8e8', |
| 688 | 410 | 'section_border_width' => '2px', |
| 689 | 411 | 'section_border_style' => 'solid', |
| @@ -690,23 +412,22 @@ | ||
| 690 | 412 | 'section_border_loc' => '-top', |
| 691 | 413 | 'collapse_icon' => '6', |
| 692 | 414 | 'collapse_pos' => 'after', |
| 693 | 415 | 'repeat_icon' => '1', |
| 694 | - 'repeat_icon_color' => 'ffffff', | |
| 695 | 416 | |
| 696 | 417 | 'submit_style' => false, |
| 697 | - 'submit_font_size' => '15px', | |
| 418 | + 'submit_font_size' => '14px', | |
| 698 | 419 | 'submit_width' => 'auto', |
| 699 | 420 | 'submit_height' => 'auto', |
| 700 | - 'submit_bg_color' => '579AF6', | |
| 701 | - 'submit_border_color' => '579AF6', | |
| 421 | + 'submit_bg_color' => 'ffffff', | |
| 422 | + 'submit_border_color' => 'cccccc', | |
| 702 | 423 | 'submit_border_width' => '1px', |
| 703 | - 'submit_text_color' => 'ffffff', | |
| 424 | + 'submit_text_color' => '444444', | |
| 704 | 425 | 'submit_weight' => 'normal', |
| 705 | 426 | 'submit_border_radius' => '4px', |
| 706 | 427 | 'submit_bg_img' => '', |
| 707 | 428 | 'submit_margin' => '10px', |
| 708 | - 'submit_padding' => '10px 20px', | |
| 429 | + 'submit_padding' => '6px 11px', | |
| 709 | 430 | 'submit_shadow_color' => 'eeeeee', |
| 710 | 431 | 'submit_hover_bg_color' => 'efefef', |
| 711 | 432 | 'submit_hover_color' => '444444', |
| 712 | 433 | 'submit_hover_border_color' => 'cccccc', |
| @@ -726,15 +447,15 @@ | ||
| 726 | 447 | 'success_font_size' => '14px', |
| 727 | 448 | |
| 728 | 449 | 'important_style' => false, |
| 729 | 450 | |
| 730 | - 'progress_bg_color' => 'eaeaea', | |
| 451 | + 'progress_bg_color' => 'dddddd', | |
| 731 | 452 | 'progress_active_color' => 'ffffff', |
| 732 | - 'progress_active_bg_color' => '579AF6', | |
| 733 | - 'progress_color' => '3f4b5b', | |
| 734 | - 'progress_border_color' => 'E5E5E5', | |
| 453 | + 'progress_active_bg_color' => '008ec2', | |
| 454 | + 'progress_color' => 'ffffff', | |
| 455 | + 'progress_border_color' => 'dfdfdf', | |
| 735 | 456 | 'progress_border_size' => '2px', |
| 736 | - 'progress_size' => '24px', | |
| 457 | + 'progress_size' => '30px', | |
| 737 | 458 | |
| 738 | 459 | 'custom_css' => '', |
| 739 | 460 | ); |
| 740 | 461 | |
| @@ -740,22 +461,12 @@ | ||
| 740 | 461 | |
| 741 | 462 | return apply_filters( 'frm_default_style_settings', $defaults ); |
| 742 | 463 | } |
| 743 | 464 | |
| 744 | - /** | |
| 745 | - * Get a name attribute value for a style setting input. | |
| 746 | - * | |
| 747 | - * @param string $field_name | |
| 748 | - * @param string $post_field | |
| 749 | - * @return string | |
| 750 | - */ | |
| 751 | 465 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
| 752 | 466 | return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']'; |
| 753 | 467 | } |
| 754 | 468 | |
| 755 | - /** | |
| 756 | - * @return array | |
| 757 | - */ | |
| 758 | 469 | public static function get_bold_options() { |
| 759 | 470 | return array( |
| 760 | 471 | 100 => 100, |
| 761 | 472 | 200 => 200, |
| @@ -769,12 +480,9 @@ | ||
| 769 | 480 | ); |
| 770 | 481 | } |
| 771 | 482 | |
| 772 | 483 | /** |
| 773 | - * Don't let imbalanced font families ruin the whole stylesheet. | |
| 774 | - * | |
| 775 | - * @param string $value | |
| 776 | - * @return string | |
| 484 | + * Don't let imbalanced font families ruin the whole stylesheet | |
| 777 | 485 | */ |
| 778 | 486 | public function force_balanced_quotation( $value ) { |
| 779 | 487 | $balanced_characters = array( '"', "'" ); |
| 780 | 488 | foreach ( $balanced_characters as $char ) { |
| @@ -779,18 +487,12 @@ | ||
| 779 | 487 | $balanced_characters = array( '"', "'" ); |
| 780 | 488 | foreach ( $balanced_characters as $char ) { |
| 781 | 489 | $char_count = substr_count( $value, $char ); |
| 782 | 490 | $is_balanced = $char_count % 2 == 0; |
| 783 | - | |
| 784 | - if ( $is_balanced ) { | |
| 785 | - continue; | |
| 786 | - } | |
| 787 | - | |
| 788 | - if ( $value && $char === $value[ strlen( $value ) - 1 ] ) { | |
| 789 | - $value = $char . $value; | |
| 790 | - } else { | |
| 491 | + if ( ! $is_balanced ) { | |
| 791 | 492 | $value .= $char; |
| 792 | 493 | } |
| 793 | 494 | } |
| 495 | + | |
| 794 | 496 | return $value; |
| 795 | 497 | } |
| 796 | 498 | } |